/[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.14 - (show annotations)
Mon Sep 17 11:37:54 2001 UTC (22 years, 7 months ago) by ravilov
Branch: MAIN
CVS Tags: HEAD
Changes since 1.13: +4 -4 lines
Fixed makephpself() (now it doesn't append an extra "&")

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 = array();
61 for( $i = 0; !empty( $sessionvars[$i] ); $i++ ) {
62 $varname = $sessionvars[$i];
63 if( $vars[ $varname ] != "" ) {
64 array_push( $url, $varname . '=' . $vars[ $varname ] );
65 } else if( $$varname != "" ) {
66 array_push( $url, $varname . '=' . $$varname );
67 }
68 }
69 return( $PHP_SELF . "?" . implode( "&amp;", $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 = 0; $i < $numrows; $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 = 0; $i < count( $rows ); $i++ ) {
126 if ( empty( $rows[$i][$params["quickjump"]] ) ) continue;
127 $url = "#".sprintf( "%03d", $i );
128 if ( $i < $startrecord || $i > $endrecord )
129 $url = makephpself( "pagenum=".intval( $i / $pagelength ) ) . $url;
130 array_push($tmp, '<OPTION VALUE="' . $url . '">' .
131 HTMLSpecialChars( $rows[$i][$params["quickjump"]] ) . '</OPTION>');
132 }
133 if ( count( $tmp ) > 0 ) {
134 array_unshift( $tmp, "<OPTION VALUE=\"\">&nbsp;</OPTION>" );
135 echo "\n<FORM><SMALL><FONT FACE=\"sans-serif\">QuickJump:</FONT> <SELECT STYLE=\"font-size:12px\" ONCHANGE=\"if(this.value)self.location.href=this.value;\">\n" . implode("\n", $tmp) . "</SELECT></FORM></SMALL>";
136 }
137 }
138 echo '<P>';
139
140 echo '<TABLE BORDER=0 CELLSPACING=1 CELLPADDING=3 BGCOLOR="' . $tableheadercol .'" FGCOLOR="#FFFFFF">';
141 echo '<TH bgcolor="#ffffff">&nbsp;</TH>';
142 echo '<TH bgcolor="#ffffff">&nbsp;</TH>';
143 for( $i = 0; ! empty( $names[$i] ); $i += 1 ) {
144 if ( empty ( $fields[$i] ) ) continue;
145 echo '<TH bgcolor=' . $tableheadercol . '><A HREF="' . makephpself( "pagenum=0&sort=" . $fields[$i] ) . '">' . $names[$i] . '</A></TH>';
146 }
147 $row = 0;
148 for( $i = $startrecord; $i <= $endrecord; $i += 1 ) {
149 $array = $rows[$i];
150 echo "<TR BGCOLOR=" . $colour[ $i % 2 ] . ">";
151 echo '<TD bgcolor="#ffffff" VALIGN=top>';
152 echo '<a href="' . makephpself( "action=delete&record_id=" . $array[$key] ) . '" onClick="return confirmdelete()">';
153 echo '<img src="' . $phormationdir . '/delete.gif" alt="delete" border="0"></a></TD>';
154 echo '<TD bgcolor="#ffffff" VALIGN=top><a href="' . $editlink . 'record_id=' . $array[$key] . '">';
155 echo '<img src="' . $phormationdir . '/edit.gif" alt="edit" border="0"></a></TD>';
156 for( $j = 0; ! empty( $names[$j] ); $j += 1 ) {
157 if ( empty ( $fields[$j] ) ) continue;
158 echo "<TD VALIGN=top>\n";
159 if ($params["quickjump"] && $j == 0) echo '<A NAME="' . sprintf("%03d", $i) . '"></A>';
160 $vals = array();
161 $flds = split(",", $fields[$j]);
162 while (list($k, $v) = each($flds)) {
163 $x = $array[trim($v)];
164 # if (!$x) $x = $array[$j + 1];
165 array_push($vals, $x);
166 }
167 $vals = implode(", ", $vals);
168 if ($phescape) $vals = htmlspecialchars($vals);
169 if (!empty($params["display_hook"]))
170 $vals = $params["display_hook"]($fields[$j], $vals);
171 if ($vals == "") $vals = "&nbsp;";
172 echo "$vals</TD>\n";
173 }
174 echo "</TR>\n";
175 }
176 echo "</TABLE>\n";
177 }
178
179
180 function table_index( $fields, $names, $params )
181 {
182 global $conn, $sort, $action, $record_id;
183
184 // get params
185 $title = $params["title"];
186 $charset = $params["charset"];
187
188 if( $action == "delete" ) {
189 // if a record should be deleted
190 if( !empty( $params["predelete_hook"] ) ) {
191 // call the hook function if it exists,
192 $params["predelete_hook"]( $record_id );
193 }
194 $query = $params["delquery"] . "'" . $record_id . "'";
195 dbi_exec( $conn, $query );
196 header( "Location: " . makephpself( 'action=nothing' ) );
197 return;
198 }
199
200 ?>
201 <HTML>
202 <HEAD>
203 <? if ($charset): ?><META HTTP-EQUIV="Content-Type" CONTENT="text/html;charset=<? echo $charset ?>"><? endif; ?>
204 <TITLE><? echo $title ?></TITLE>
205 </HEAD>
206 <BODY BGCOLOR="#FFFFFF" LINK="#000090" VLINK="#000090" ALINK="#FF0000" >
207 <script type="text/javascript">
208 <!-- // begin
209 function confirmdelete() {
210 $result = confirm( "Do you really want to delete this record?" );
211 if( $result ) {
212 document.location.replace( "<? echo makephpself( 'action=delete&record_id=' . $record_id ) ?>" );
213 } else {
214 return false;
215 }
216 }
217 // end -->
218 </script>
219 <h1><?= $title ?></h1>
220 <?
221 if( function_exists( html_before_table ) ) {
222 html_before_table();
223 }
224 if( ! empty( $params["maindesc"] ) ) {
225 echo '<a href="' . $params["mainlink"] . '">' . $params["maindesc"] . '</A> - ';
226 }
227 if( ! empty( $params["backdesc"] ) ) {
228 echo '<a href="' . $params["backlink"] . '">' . $params["backdesc"] . '</A> - ';
229 }
230 if( ! empty( $params["searchdesc"] ) ) {
231 echo '<a href="' . $params["searchlink"] . '">' . $params["searchdesc"] . '</A> - ';
232 }
233 echo '<a href="' . $params["newlink"] . '">Create New Record</A>';
234 if( !empty( $params["addmultiplelink"] ) ) {
235 echo ' - <a href="' . $params["addmultiplelink"] . '">Create Several Records</A>';
236 }
237 if (!empty($params["back"])) {
238 echo ' - <a href="'.$params["back"].'">Back to Index</a>';
239 }
240 echo "<P>";
241 echo $params["instr"];
242
243 if( $sort == "" ) {
244 $sortfield = $params["defaultsort"];
245 } else {
246 $sortfield = $sort;
247 }
248 $query = $params["query"] . " order by $sortfield";
249 $result = dbi_exec( $conn, $query );
250 if( ! $result ) {
251 echo "Error executing database query.<BR>";
252 dbi_error( $conn );
253 return;
254 }
255 displayresult( $result, $fields, $names, $params );
256 ?>
257 </BODY>
258 </HTML>
259 <?
260 }
261 ?>

  ViewVC Help
Powered by ViewVC 1.1.26