/[corp_html]/back/phormation/displaytable.php
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /back/phormation/displaytable.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.12 - (show annotations)
Thu Sep 6 15:55:55 2001 UTC (22 years, 8 months ago) by ravilov
Branch: MAIN
Changes since 1.11: +1 -1 lines
Added an autodate widget. Minor bugfixes.

1 <?
2 /*
3 * Phormation
4 * - A library of PHP code to make development of database-driven
5 * html forms easy and quick
6 *
7 * Copyright (C) 2000 Jason D. Hildebrand
8 * PeaceWorks Computer Consulting
9 *
10 * jason@peaceworks.ca
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
25 */
26
27 if (!isset($phescape)) $phescape = true;
28
29 include_once( "$phormationdir/dbi.php" );
30
31 // these variables will be preserved, as long as makephself is used to
32 // construct the URLs
33 $sessionvars[] = "pagenum";
34 $sessionvars[] = "sort";
35 $sessionvars[] = "action";
36 $sessionvars[] = "record_id";
37
38
39 // this function constructs a URL for the display table page, and
40 // automatically adds the variables listed above, so that they are preserved.
41 function makephpself( $params ) {
42 global $PHP_SELF;
43 global $sessionvars;
44
45 //echo $params . "<BR>";
46
47 for( $i = 0; !empty( $sessionvars[$i] ); $i++ ) {
48 $varname = $sessionvars[$i];
49 global $$varname;
50 }
51
52 $pairs = split( "&", $params );
53 for( $i = 0; !empty( $pairs[$i] ); $i++ ) {
54 $varname = strtok( $pairs[$i], "=" );
55 $value = strtok( "=" );
56 //echo "Var = $varname, Value = $value <BR>";
57 $vars[$varname] = $value;
58 }
59
60 $url = $PHP_SELF . "?";
61 for( $i = 0; !empty( $sessionvars[$i] ); $i++ ) {
62 $varname = $sessionvars[$i];
63 if( $vars[ $varname ] != "" ) {
64 $url .= $varname . '=' . $vars[ $varname ] . '&';
65 } else if( $$varname != "" ) {
66 $url .= $varname . '=' . $$varname . '&';
67 }
68 }
69 return( $url );
70 }
71
72 function displayresult( $result, $fields, $names, $params )
73 {
74 global $INDEXCOLOUR1, $INDEXCOLOUR2, $TABLEHEADERCOLOUR, $pagenum;
75 global $phormationdir;
76
77 $editfield = $params["editfield"];
78 $key = $params["key"];
79 $title = $params["title"];
80 $editlink = $params["editlink"];
81 if (strchr($editlink,'?')) {
82 $editlink.="&";
83 } else {
84 $editlink.="?";
85 }
86 $pagelength = $params["pagelength"];
87
88 $colour[0] = empty( $INDEXCOLOUR1 ) ? "#e6e6e6" : $INDEXCOLOUR1;
89 $colour[1] = empty( $INDEXCOLOUR2 ) ? "#d0d0d0" : $INDEXCOLOUR2;
90 $tableheadercol = empty( $TABLEHEADERCOLOUR ) ? "#a0a0e0" : $TABLEHEADERCOLOUR;
91 $numrows = dbi_numrows( $result );
92 if( $numrows == 0 ) {
93 echo "There are <B>no records</B> in the database. Click <B>Create New Record</B> to add records.<P>";
94 return;
95 }
96
97 if( empty( $pagenum ) ) {
98 $pagenum = 0;
99 }
100 if( empty( $pagelength ) ) {
101 $pagelength = 200;
102 }
103
104 $startrecord = $pagelength * $pagenum;
105 $endrecord = min( $pagelength * ( $pagenum + 1 ) - 1, $numrows - 1 );
106 $numpages = ceil( $numrows / $pagelength );
107
108 $rows = array();
109 for ($i = $startrecord; $i <= $endrecord; $i++) $rows[$i] = dbi_fetch_array($result, $i);
110
111 if( $pagenum > 0 ) {
112 echo '<a href="' . makephpself( "pagenum=" . ($pagenum - 1) ) . '">Previous Page</A> - ';
113 } else {
114 echo 'Previous Page - ';
115 }
116 echo 'Viewing records ' . ( $startrecord + 1 ) . ' to ' . ( $endrecord + 1 ) ;
117 echo ' of ' . $numrows . ' (Page ' . ( $pagenum + 1 ) . ' of ' . $numpages . ')';
118 if( $pagenum < $numpages - 1 ) {
119 echo ' - <a href="' . makephpself( "pagenum=" . ($pagenum + 1) ) . '">Next Page</A>';
120 } else {
121 echo ' - Next Page';
122 }
123 if ($params["quickjump"]) {
124 $tmp = array();
125 for( $i = $startrecord; $i <= $endrecord; $i += 1 ) {
126 if (empty($rows[$i][$params["quickjump"]])) continue;
127 array_push($tmp, '<OPTION VALUE="#' . sprintf("%03d", $i) . '">' .
128 HTMLSpecialChars($rows[$i][$params["quickjump"]]) . '</OPTION>');
129 }
130 if (count($tmp) > 0) {
131 array_unshift($tmp, "<OPTION VALUE=\"\">&nbsp;</OPTION>");
132 echo "\n<FORM><SMALL><FONT FACE=\"sans-serif\">QuickJump:</FONT> <SELECT STYLE=\"font-size:12px\" ONCHANGE=\"if(this.value)location.href=this.value;\">" . implode("", $tmp) . "</SELECT></FORM></SMALL>";
133 }
134 }
135 echo '<P>';
136
137 echo '<TABLE BORDER=0 CELLSPACING=1 CELLPADDING=3 BGCOLOR="' . $tableheadercol .'" FGCOLOR="#FFFFFF">';
138 echo '<TH bgcolor="#ffffff">&nbsp;</TH>';
139 echo '<TH bgcolor="#ffffff">&nbsp;</TH>';
140 for( $i = 0; ! empty( $names[$i] ); $i += 1 ) {
141 if ( empty ( $fields[$i] ) ) continue;
142 echo '<TH bgcolor=' . $tableheadercol . '><A HREF="' . makephpself( "pagenum=0&sort=" . $fields[$i] ) . '">' . $names[$i] . '</A></TH>';
143 }
144 $row = 0;
145 for( $i = $startrecord; $i <= $endrecord; $i += 1 ) {
146 $array = $rows[$i];
147 echo "<TR BGCOLOR=" . $colour[ $i % 2 ] . ">";
148 echo '<TD bgcolor="#ffffff" VALIGN=top>';
149 echo '<a href="' . makephpself( "action=delete&record_id=" . $array[$key] ) . '" onClick="return confirmdelete()">';
150 echo '<img src="' . $phormationdir . '/delete.gif" alt="delete record" border="0"></a></TD>';
151 echo '<TD bgcolor="#ffffff" VALIGN=top><a href="' . $editlink . 'record_id=' . $array[$key] . '">';
152 echo '<img src="' . $phormationdir . '/edit.gif" alt="edit record" border="0"></a></TD>';
153 for( $j = 0; ! empty( $names[$j] ); $j += 1 ) {
154 if ( empty ( $fields[$j] ) ) continue;
155 echo "<TD VALIGN=top>\n";
156 if ($params["quickjump"] && $j == 0) echo '<A NAME="' . sprintf("%03d", $i) . '"></A>';
157 $vals = array();
158 $flds = split(",", $fields[$j]);
159 while (list($k, $v) = each($flds)) {
160 $x = $array[trim($v)];
161 # if (!$x) $x = $array[$j + 1];
162 array_push($vals, $x);
163 }
164 $vals = implode(", ", $vals);
165 if ($phescape) $vals = htmlspecialchars($vals);
166 if (!empty($params["display_hook"]))
167 $vals = $params["display_hook"]($fields[$j], $vals);
168 if ($vals == "") $vals = "&nbsp;";
169 echo "$vals</TD>\n";
170 }
171 echo "</TR>\n";
172 }
173 echo "</TABLE>\n";
174 }
175
176
177 function table_index( $fields, $names, $params )
178 {
179 global $conn, $sort, $action, $record_id;
180
181 // get params
182 $title = $params["title"];
183 $charset = $params["charset"];
184
185 if( $action == "delete" ) {
186 // if a record should be deleted
187 if( !empty( $params["predelete_hook"] ) ) {
188 // call the hook function if it exists,
189 $params["predelete_hook"]( $record_id );
190 }
191 $query = $params["delquery"] . "'" . $record_id . "'";
192 dbi_exec( $conn, $query );
193 header( "Location: " . makephpself( 'action=nothing' ) );
194 return;
195 }
196
197 ?>
198 <HTML>
199 <HEAD>
200 <? if ($charset): ?><META HTTP-EQUIV="Content-Type" CONTENT="text/html;charset=<? echo $charset ?>"><? endif; ?>
201 <TITLE><? echo $title ?></TITLE>
202 </HEAD>
203 <BODY BGCOLOR="#FFFFFF" LINK="#000090" VLINK="#000090" ALINK="#FF0000" >
204 <script type="text/javascript">
205 <!-- // begin
206 function confirmdelete() {
207 $result = confirm( "Do you really want to delete this record?" );
208 if( $result ) {
209 document.location.replace( "<? echo makephpself( 'action=delete&record_id=' . $record_id ) ?>" );
210 } else {
211 return false;
212 }
213 }
214 // end -->
215 </script>
216 <h1><?= $title ?></h1>
217 <?
218 if( function_exists( html_before_table ) ) {
219 html_before_table();
220 }
221 if( ! empty( $params["maindesc"] ) ) {
222 echo '<a href="' . $params["mainlink"] . '">' . $params["maindesc"] . '</A> - ';
223 }
224 if( ! empty( $params["backdesc"] ) ) {
225 echo '<a href="' . $params["backlink"] . '">' . $params["backdesc"] . '</A> - ';
226 }
227 if( ! empty( $params["searchdesc"] ) ) {
228 echo '<a href="' . $params["searchlink"] . '">' . $params["searchdesc"] . '</A> - ';
229 }
230 echo '<a href="' . $params["newlink"] . '">Create New Record</A>';
231 if( !empty( $params["addmultiplelink"] ) ) {
232 echo ' - <a href="' . $params["addmultiplelink"] . '">Create Several Records</A>';
233 }
234 if (!empty($params["back"])) {
235 echo ' - <a href="'.$params["back"].'">Back to Index</a>';
236 }
237 echo "<P>";
238 echo $params["instr"];
239
240 if( $sort == "" ) {
241 $sortfield = $params["defaultsort"];
242 } else {
243 $sortfield = $sort;
244 }
245 $query = $params["query"] . " order by $sortfield";
246 $result = dbi_exec( $conn, $query );
247 if( ! $result ) {
248 echo "Error executing database query.<BR>";
249 dbi_error( $conn );
250 return;
251 }
252 displayresult( $result, $fields, $names, $params );
253 ?>
254 </BODY>
255 </HTML>
256 <?
257 }
258 ?>

  ViewVC Help
Powered by ViewVC 1.1.26