/[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.1.1.1 - (show annotations) (vendor branch)
Fri Jan 26 17:53:58 2001 UTC (23 years, 4 months ago) by dpavlin
Branch: dbp
CVS Tags: alpha
Changes since 1.1: +0 -0 lines
alpha

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( "$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 $pagelength = $params["pagelength"];
80
81 $colour[0] = empty( $INDEXCOLOUR1 ) ? "#e6e6e6" : $INDEXCOLOUR1;
82 $colour[1] = empty( $INDEXCOLOUR2 ) ? "#d0d0d0" : $INDEXCOLOUR2;
83 $tableheadercol = empty( $TABLEHEADERCOLOUR ) ? "#a0a0e0" : $TABLEHEADERCOLOUR;
84 $numrows = dbi_numrows( $result );
85 if( $numrows == 0 ) {
86 echo "There are <B>no records</B> in the database. Click <B>Create New Record</B> to add records.<P>";
87 return;
88 }
89
90 if( empty( $pagenum ) ) {
91 $pagenum = 0;
92 }
93 if( empty( $pagelength ) ) {
94 $pagelength = 200;
95 }
96
97 $startrecord = $pagelength * $pagenum;
98 $endrecord = min( $pagelength * ( $pagenum + 1 ) - 1, $numrows - 1 );
99 $numpages = ceil( $numrows / $pagelength );
100 if( $pagenum > 0 ) {
101 echo '<a href="' . makephpself( "pagenum=" . ($pagenum - 1) ) . '">Previous Page</A> - ';
102 } else {
103 echo 'Previous Page - ';
104 }
105 echo 'Viewing records ' . ( $startrecord + 1 ) . ' to ' . ( $endrecord + 1 ) ;
106 echo ' of ' . $numrows . ' (Page ' . ( $pagenum + 1 ) . ' of ' . $numpages . ')';
107 if( $pagenum < $numpages - 1 ) {
108 echo ' - <a href="' . makephpself( "pagenum=" . ($pagenum + 1) ) . '">Next Page</A>';
109 } else {
110 echo ' - Next Page';
111 }
112 echo '<P>';
113
114 echo '<TABLE BORDER=0 CELLSPACING=1 CELLPADDING=3 BGCOLOR="' . $tableheadercol .'" FGCOLOR="#FFFFFF">';
115 echo '<TH bgcolor="#ffffff">&nbsp;</TH>';
116 echo '<TH bgcolor="#ffffff">&nbsp;</TH>';
117 for( $i = 0; ! empty( $names[$i] ); $i += 1 ) {
118 echo '<TH bgcolor=' . $tableheadercol . '><A HREF="' . makephpself( "pagenum=0&sort=" . $fields[$i] ) . '">' . $names[$i] . '</A></TH>';
119 }
120 $row = 0;
121 for( $i = $startrecord; $i <= $endrecord; $i += 1 ) {
122 $array = dbi_fetch_array( $result, $i );
123 echo "<TR BGCOLOR=" . $colour[ $i % 2 ] . ">";
124 echo '<TD bgcolor="#ffffff">';
125 echo '<a href="' . makephpself( "action=delete&record_id=" . $array[$key] ) . '" onClick="return confirmdelete()">';
126 echo '<img src="' . $phormationdir . '/delete.gif" alt="delete record" border="0"></a></TD>';
127 echo '<TD bgcolor="#ffffff"><a href="' . $editlink . '?record_id=' . $array[$key] . '">';
128 echo '<img src="' . $phormationdir . '/edit.gif" alt="edit record" border="0"></a></TD>';
129 for( $j = 0; ! empty( $fields[$j] ); $j += 1 ) {
130 echo "<TD>\n";
131 if( empty( $array[ $fields[$j]] ) ) {
132 echo "&nbsp;";
133 } else {
134 echo $array[$fields[$j]];
135 }
136 echo "</TD>\n";
137 }
138 echo "</TR>\n";
139 }
140 echo "</TABLE>\n";
141 }
142
143
144 function table_index( $fields, $names, $params )
145 {
146 global $conn, $sort, $action, $record_id;
147
148 // get params
149 $title = $params["title"];
150
151 if( $action == "delete" ) {
152 // if a record should be deleted
153 if( !empty( $params["predelete_hook"] ) ) {
154 // call the hook function if it exists,
155 $params["predelete_hook"]( $record_id );
156 }
157 $query = $params["delquery"] . $record_id;
158 dbi_exec( $conn, $query );
159 header( "Location: " . makephpself( 'action=nothing' ) );
160 return;
161 }
162
163 ?>
164 <HTML>
165 <HEAD>
166 <TITLE><? echo $title ?></TITLE>
167 </HEAD>
168 <BODY BGCOLOR="#FFFFFF" LINK="#000090" VLINK="#000090" ALINK="#FF0000" >
169 <script>
170 function confirmdelete() {
171 $result = confirm( "Do you really want to delete this record?" );
172 if( $result ) {
173 document.location.replace( "<? echo makephpself( 'action=delete&record_id=' . $record_id ) ?>" );
174 } else {
175 return false;
176 }
177 }
178 </script>
179 <h1><? echo $title ?></h1>
180 <?
181 if( function_exists( html_before_table ) ) {
182 html_before_table();
183 }
184 if( ! empty( $params["maindesc"] ) ) {
185 echo '<a href="' . $params["mainlink"] . '">' . $params["maindesc"] . '</A> - ';
186 }
187 if( ! empty( $params["backdesc"] ) ) {
188 echo '<a href="' . $params["backlink"] . '">' . $params["backdesc"] . '</A> - ';
189 }
190 if( ! empty( $params["searchdesc"] ) ) {
191 echo '<a href="' . $params["searchlink"] . '">' . $params["searchdesc"] . '</A> - ';
192 }
193 echo '<a href="' . $params["newlink"] . '">Create New Record</A>';
194 if( !empty( $params["addmultiplelink"] ) ) {
195 echo ' - <a href="' . $params["addmultiplelink"] . '">Create Several Records</A>';
196 }
197 echo "<P>";
198 echo $params["instr"];
199
200 if( $sort == "" ) {
201 $sortfield = $params["defaultsort"];
202 } else {
203 $sortfield = $sort;
204 }
205 $query = $params["query"] . " order by $sortfield";
206 $result = dbi_exec( $conn, $query );
207 if( ! $result ) {
208 echo "Error executing database query.<BR>";
209 dbi_error( $conn );
210 return;
211 }
212 displayresult( $result, $fields, $names, $params );
213 ?>
214 </BODY>
215 </HTML>
216 <?
217 }
218 ?>

  ViewVC Help
Powered by ViewVC 1.1.26