/[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.9 - (show annotations)
Thu Jul 19 11:19:02 2001 UTC (22 years, 10 months ago) by ravilov
Branch: MAIN
Changes since 1.8: +3 -0 lines
Added a new link to the index header - "Back".

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 include_once( "$phormationdir/dbi.php" );
28
29 // these variables will be preserved, as long as makephself is used to
30 // construct the URLs
31 $sessionvars[] = "pagenum";
32 $sessionvars[] = "sort";
33 $sessionvars[] = "action";
34 $sessionvars[] = "record_id";
35
36
37 // this function constructs a URL for the display table page, and
38 // automatically adds the variables listed above, so that they are preserved.
39 function makephpself( $params ) {
40 global $PHP_SELF;
41 global $sessionvars;
42
43 //echo $params . "<BR>";
44
45 for( $i = 0; !empty( $sessionvars[$i] ); $i++ ) {
46 $varname = $sessionvars[$i];
47 global $$varname;
48 }
49
50 $pairs = split( "&", $params );
51 for( $i = 0; !empty( $pairs[$i] ); $i++ ) {
52 $varname = strtok( $pairs[$i], "=" );
53 $value = strtok( "=" );
54 //echo "Var = $varname, Value = $value <BR>";
55 $vars[$varname] = $value;
56 }
57
58 $url = $PHP_SELF . "?";
59 for( $i = 0; !empty( $sessionvars[$i] ); $i++ ) {
60 $varname = $sessionvars[$i];
61 if( $vars[ $varname ] != "" ) {
62 $url .= $varname . '=' . $vars[ $varname ] . '&';
63 } else if( $$varname != "" ) {
64 $url .= $varname . '=' . $$varname . '&';
65 }
66 }
67 return( $url );
68 }
69
70 function displayresult( $result, $fields, $names, $params )
71 {
72 global $INDEXCOLOUR1, $INDEXCOLOUR2, $TABLEHEADERCOLOUR, $pagenum;
73 global $phormationdir;
74
75 $editfield = $params["editfield"];
76 $key = $params["key"];
77 $title = $params["title"];
78 $editlink = $params["editlink"];
79 if (strchr($editlink,'?')) {
80 $editlink.="&";
81 } else {
82 $editlink.="?";
83 }
84 $pagelength = $params["pagelength"];
85
86 $colour[0] = empty( $INDEXCOLOUR1 ) ? "#e6e6e6" : $INDEXCOLOUR1;
87 $colour[1] = empty( $INDEXCOLOUR2 ) ? "#d0d0d0" : $INDEXCOLOUR2;
88 $tableheadercol = empty( $TABLEHEADERCOLOUR ) ? "#a0a0e0" : $TABLEHEADERCOLOUR;
89 $numrows = dbi_numrows( $result );
90 if( $numrows == 0 ) {
91 echo "There are <B>no records</B> in the database. Click <B>Create New Record</B> to add records.<P>";
92 return;
93 }
94
95 if( empty( $pagenum ) ) {
96 $pagenum = 0;
97 }
98 if( empty( $pagelength ) ) {
99 $pagelength = 200;
100 }
101
102 $startrecord = $pagelength * $pagenum;
103 $endrecord = min( $pagelength * ( $pagenum + 1 ) - 1, $numrows - 1 );
104 $numpages = ceil( $numrows / $pagelength );
105 if( $pagenum > 0 ) {
106 echo '<a href="' . makephpself( "pagenum=" . ($pagenum - 1) ) . '">Previous Page</A> - ';
107 } else {
108 echo 'Previous Page - ';
109 }
110 echo 'Viewing records ' . ( $startrecord + 1 ) . ' to ' . ( $endrecord + 1 ) ;
111 echo ' of ' . $numrows . ' (Page ' . ( $pagenum + 1 ) . ' of ' . $numpages . ')';
112 if( $pagenum < $numpages - 1 ) {
113 echo ' - <a href="' . makephpself( "pagenum=" . ($pagenum + 1) ) . '">Next Page</A>';
114 } else {
115 echo ' - Next Page';
116 }
117 echo '<P>';
118
119 echo '<TABLE BORDER=0 CELLSPACING=1 CELLPADDING=3 BGCOLOR="' . $tableheadercol .'" FGCOLOR="#FFFFFF">';
120 echo '<TH bgcolor="#ffffff">&nbsp;</TH>';
121 echo '<TH bgcolor="#ffffff">&nbsp;</TH>';
122 for( $i = 0; ! empty( $names[$i] ); $i += 1 ) {
123 if ( empty ( $fields[$i] ) ) continue;
124 echo '<TH bgcolor=' . $tableheadercol . '><A HREF="' . makephpself( "pagenum=0&sort=" . $fields[$i] ) . '">' . $names[$i] . '</A></TH>';
125 }
126 $row = 0;
127 for( $i = $startrecord; $i <= $endrecord; $i += 1 ) {
128 $array = dbi_fetch_array( $result, $i );
129 echo "<TR BGCOLOR=" . $colour[ $i % 2 ] . ">";
130 echo '<TD bgcolor="#ffffff">';
131 echo '<a href="' . makephpself( "action=delete&record_id=" . $array[$key] ) . '" onClick="return confirmdelete()">';
132 echo '<img src="' . $phormationdir . '/delete.gif" alt="delete record" border="0"></a></TD>';
133 echo '<TD bgcolor="#ffffff"><a href="' . $editlink . 'record_id=' . $array[$key] . '">';
134 echo '<img src="' . $phormationdir . '/edit.gif" alt="edit record" border="0"></a></TD>';
135 for( $j = 0; ! empty( $names[$j] ); $j += 1 ) {
136 if ( empty ( $fields[$j] ) ) continue;
137 echo "<TD>\n";
138 $vals = array();
139 $flds = split(",", $fields[$j]);
140 while (list($k, $v) = each($flds)) {
141 $x = $array[trim($v)];
142 if (!$x) $x = $array[$j + 1];
143 array_push($vals, $x);
144 }
145 $vals = implode(", ", $vals);
146 $vals = htmlspecialchars($vals);
147 if (!empty($params["display_hook"]))
148 $vals = $params["display_hook"]($fields[$j], $vals);
149 if (!$vals) $vals = "&nbsp;";
150 echo "$vals</TD>\n";
151 }
152 echo "</TR>\n";
153 }
154 echo "</TABLE>\n";
155 }
156
157
158 function table_index( $fields, $names, $params )
159 {
160 global $conn, $sort, $action, $record_id;
161
162 // get params
163 $title = $params["title"];
164
165 if( $action == "delete" ) {
166 // if a record should be deleted
167 if( !empty( $params["predelete_hook"] ) ) {
168 // call the hook function if it exists,
169 $params["predelete_hook"]( $record_id );
170 }
171 $query = $params["delquery"] . "'" . $record_id . "'";
172 dbi_exec( $conn, $query );
173 header( "Location: " . makephpself( 'action=nothing' ) );
174 return;
175 }
176
177 ?>
178 <HTML>
179 <HEAD>
180 <TITLE><? echo $title ?></TITLE>
181 </HEAD>
182 <BODY BGCOLOR="#FFFFFF" LINK="#000090" VLINK="#000090" ALINK="#FF0000" >
183 <script type="text/javascript">
184 <!-- // begin
185 function confirmdelete() {
186 $result = confirm( "Do you really want to delete this record?" );
187 if( $result ) {
188 document.location.replace( "<? echo makephpself( 'action=delete&record_id=' . $record_id ) ?>" );
189 } else {
190 return false;
191 }
192 }
193 // end -->
194 </script>
195 <h1><? echo $title ?></h1>
196 <?
197 if( function_exists( html_before_table ) ) {
198 html_before_table();
199 }
200 if( ! empty( $params["maindesc"] ) ) {
201 echo '<a href="' . $params["mainlink"] . '">' . $params["maindesc"] . '</A> - ';
202 }
203 if( ! empty( $params["backdesc"] ) ) {
204 echo '<a href="' . $params["backlink"] . '">' . $params["backdesc"] . '</A> - ';
205 }
206 if( ! empty( $params["searchdesc"] ) ) {
207 echo '<a href="' . $params["searchlink"] . '">' . $params["searchdesc"] . '</A> - ';
208 }
209 echo '<a href="' . $params["newlink"] . '">Create New Record</A>';
210 if( !empty( $params["addmultiplelink"] ) ) {
211 echo ' - <a href="' . $params["addmultiplelink"] . '">Create Several Records</A>';
212 }
213 if (!empty($params["back"])) {
214 echo ' - <a href="'.$params["back"].'">Back to Index</a>';
215 }
216 echo "<P>";
217 echo $params["instr"];
218
219 if( $sort == "" ) {
220 $sortfield = $params["defaultsort"];
221 } else {
222 $sortfield = $sort;
223 }
224 $query = $params["query"] . " order by $sortfield";
225 $result = dbi_exec( $conn, $query );
226 if( ! $result ) {
227 echo "Error executing database query.<BR>";
228 dbi_error( $conn );
229 return;
230 }
231 displayresult( $result, $fields, $names, $params );
232 ?>
233 </BODY>
234 </HTML>
235 <?
236 }
237 ?>

  ViewVC Help
Powered by ViewVC 1.1.26