/[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

Annotation of /back/phormation/displaytable.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.5 - (hide annotations)
Thu Jul 5 13:24:11 2001 UTC (22 years, 11 months ago) by ravilov
Branch: MAIN
Changes since 1.4: +1 -1 lines
Added validation for mydata widget. Minor bug fixes.

1 dpavlin 1.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 dpavlin 1.3 include_once( "$phormationdir/dbi.php" );
28 dpavlin 1.1
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 dpavlin 1.2 if (strchr($editlink,'?')) {
80     $editlink.="&";
81     } else {
82     $editlink.="?";
83     }
84 dpavlin 1.1 $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 ravilov 1.4 if ( empty ( $fields[$i] ) ) continue;
124 dpavlin 1.1 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 dpavlin 1.2 echo '<TD bgcolor="#ffffff"><a href="' . $editlink . 'record_id=' . $array[$key] . '">';
134 dpavlin 1.1 echo '<img src="' . $phormationdir . '/edit.gif" alt="edit record" border="0"></a></TD>';
135 ravilov 1.4 for( $j = 0; ! empty( $names[$j] ); $j += 1 ) {
136     if ( empty ( $fields[$j] ) ) continue;
137 dpavlin 1.1 echo "<TD>\n";
138 ravilov 1.4 $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 dpavlin 1.1 }
145 ravilov 1.4 $vals = implode(", ", $vals);
146     echo empty($vals) ? "&nbsp;" : $vals;
147 dpavlin 1.1 echo "</TD>\n";
148     }
149     echo "</TR>\n";
150     }
151     echo "</TABLE>\n";
152     }
153    
154    
155     function table_index( $fields, $names, $params )
156     {
157     global $conn, $sort, $action, $record_id;
158    
159     // get params
160     $title = $params["title"];
161    
162     if( $action == "delete" ) {
163     // if a record should be deleted
164     if( !empty( $params["predelete_hook"] ) ) {
165     // call the hook function if it exists,
166     $params["predelete_hook"]( $record_id );
167     }
168 ravilov 1.5 $query = $params["delquery"] . "'" . $record_id . "'";
169 dpavlin 1.1 dbi_exec( $conn, $query );
170     header( "Location: " . makephpself( 'action=nothing' ) );
171     return;
172     }
173    
174     ?>
175     <HTML>
176     <HEAD>
177     <TITLE><? echo $title ?></TITLE>
178     </HEAD>
179     <BODY BGCOLOR="#FFFFFF" LINK="#000090" VLINK="#000090" ALINK="#FF0000" >
180 ravilov 1.4 <script type="text/javascript">
181     <!-- // begin
182 dpavlin 1.1 function confirmdelete() {
183     $result = confirm( "Do you really want to delete this record?" );
184     if( $result ) {
185     document.location.replace( "<? echo makephpself( 'action=delete&record_id=' . $record_id ) ?>" );
186     } else {
187     return false;
188     }
189     }
190 ravilov 1.4 // end -->
191 dpavlin 1.1 </script>
192     <h1><? echo $title ?></h1>
193     <?
194     if( function_exists( html_before_table ) ) {
195     html_before_table();
196     }
197     if( ! empty( $params["maindesc"] ) ) {
198     echo '<a href="' . $params["mainlink"] . '">' . $params["maindesc"] . '</A> - ';
199     }
200     if( ! empty( $params["backdesc"] ) ) {
201     echo '<a href="' . $params["backlink"] . '">' . $params["backdesc"] . '</A> - ';
202     }
203     if( ! empty( $params["searchdesc"] ) ) {
204     echo '<a href="' . $params["searchlink"] . '">' . $params["searchdesc"] . '</A> - ';
205     }
206     echo '<a href="' . $params["newlink"] . '">Create New Record</A>';
207     if( !empty( $params["addmultiplelink"] ) ) {
208     echo ' - <a href="' . $params["addmultiplelink"] . '">Create Several Records</A>';
209     }
210     echo "<P>";
211     echo $params["instr"];
212    
213     if( $sort == "" ) {
214     $sortfield = $params["defaultsort"];
215     } else {
216     $sortfield = $sort;
217     }
218     $query = $params["query"] . " order by $sortfield";
219     $result = dbi_exec( $conn, $query );
220     if( ! $result ) {
221     echo "Error executing database query.<BR>";
222     dbi_error( $conn );
223     return;
224     }
225     displayresult( $result, $fields, $names, $params );
226     ?>
227     </BODY>
228     </HTML>
229     <?
230     }
231     ?>

  ViewVC Help
Powered by ViewVC 1.1.26