/[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.2 - (hide annotations)
Mon Jul 2 12:11:47 2001 UTC (22 years, 11 months ago) by dpavlin
Branch: MAIN
Changes since 1.1: +6 -1 lines
edit link can now have parametras

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

  ViewVC Help
Powered by ViewVC 1.1.26