line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
############################################################################## |
2
|
|
|
|
|
|
|
# DBI web interface Version 0.10 # |
3
|
|
|
|
|
|
|
# Copyright 1999 James Furness furn@base6.com # |
4
|
|
|
|
|
|
|
# Created 01/05/99 Last Modified 01/05/99 # |
5
|
|
|
|
|
|
|
############################################################################## |
6
|
|
|
|
|
|
|
# COPYRIGHT NOTICE # |
7
|
|
|
|
|
|
|
# Copyright 1999 James Furness . All Rights Reserved. # |
8
|
|
|
|
|
|
|
# # |
9
|
|
|
|
|
|
|
# This module is free software; it may be used freely and redistributed # |
10
|
|
|
|
|
|
|
# for free providing this copyright header remains part of the module. You # |
11
|
|
|
|
|
|
|
# may not charge for the redistribution of this module. Selling this code # |
12
|
|
|
|
|
|
|
# without James Furness' written permission is expressly forbidden. # |
13
|
|
|
|
|
|
|
# # |
14
|
|
|
|
|
|
|
# This module may not be modified without first notifying James Furness # |
15
|
|
|
|
|
|
|
# (This is to enable me to track modifications). In all # |
16
|
|
|
|
|
|
|
# cases this copyright header should remain fully intact in all # |
17
|
|
|
|
|
|
|
# modifications. # |
18
|
|
|
|
|
|
|
# # |
19
|
|
|
|
|
|
|
# This code is provided on an "As Is" basis, without warranty, expressed or # |
20
|
|
|
|
|
|
|
# implied. The author disclaims all warranties with regard to this software, # |
21
|
|
|
|
|
|
|
# including all implied warranties of merchantability and fitness, in no # |
22
|
|
|
|
|
|
|
# event shall the author, James Furness be liable for any special, indirect # |
23
|
|
|
|
|
|
|
# or consequential damages or any damages whatsoever including but not # |
24
|
|
|
|
|
|
|
# limited to loss of use, data or profits. By using this module you agree to # |
25
|
|
|
|
|
|
|
# indemnify James Furness from any liability that might arise from it's use. # |
26
|
|
|
|
|
|
|
# Should this code prove defective, you assume the cost of any and all # |
27
|
|
|
|
|
|
|
# necessary repairs, servicing, correction and any other costs arising # |
28
|
|
|
|
|
|
|
# directly or indrectly from it's use. # |
29
|
|
|
|
|
|
|
# # |
30
|
|
|
|
|
|
|
# This copyright notice must remain fully intact at all times. # |
31
|
|
|
|
|
|
|
# Use of this program or its output constitutes acceptance of these terms. # |
32
|
|
|
|
|
|
|
# # |
33
|
|
|
|
|
|
|
# Parts of this module are based upon mysql-lib.pl by Ron Crisco. # |
34
|
|
|
|
|
|
|
############################################################################## |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
package DBIx::HTMLinterface; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=pod |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head1 NAME |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
DBIx::HTMLinterface - Class for creating a CGI interface to a database |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head1 SYNOPSIS |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
use CGI; |
47
|
|
|
|
|
|
|
use DBI; |
48
|
|
|
|
|
|
|
use DBIx::HTMLinterface; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
$cgi = new CGI; |
51
|
|
|
|
|
|
|
$dbh = DBI->connect("DBI:mysql:[DATABASE]:[HOSTNAME]","[USERNAME]","[PASSWORD]") ); |
52
|
|
|
|
|
|
|
$DBinterface = new DBIx::HTMLinterface ($cgi, $dbh, "[INFOTABLE NAME]"); |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# Below here is only executed if a HTMLinterface action was not taken, so print a menu |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
print $cgi->header; |
57
|
|
|
|
|
|
|
print "Add\n "; |
58
|
|
|
|
|
|
|
print "Search\n"; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=head1 DESCRIPTION |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
The C class allows a CGI interface to a database. |
63
|
|
|
|
|
|
|
It enables a CGI interface to a database to be created, supporting record addition, |
64
|
|
|
|
|
|
|
modification, deletion and searching. It provides a user friendly interface with |
65
|
|
|
|
|
|
|
descriptions of fields provided. The field descriptions along with information on |
66
|
|
|
|
|
|
|
whether the field is visible, hidden or excluded are extracted from a table, allowing |
67
|
|
|
|
|
|
|
easy modification and addition of fields and tables without having to edit code. |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head2 Features |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=over 4 |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=item Simple database administration |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
Forms are created automatically on demand, SQL statements are generated as needed and processed. |
76
|
|
|
|
|
|
|
The module contains enough autonomy to potentially run with only wrapper perl code placed around |
77
|
|
|
|
|
|
|
it. |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=item Full form configuration |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
Forms can be modified to add descriptions and extra information to fields, making it easy to change |
82
|
|
|
|
|
|
|
output without having to edit code. |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=item Control |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
Extensive callback procedures and configuration options allow output, password protection and logging |
87
|
|
|
|
|
|
|
to be configured as desired. |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=item Full HTML customisation |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
HTML output and table formats can be customised easily by the user. |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=back |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=cut |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
$| = 1; # Flush all buffers |
98
|
|
|
|
|
|
|
require 5.004; # Require at least perl 5.004 |
99
|
|
|
|
|
|
|
|
100
|
1
|
|
|
1
|
|
2088
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
35
|
|
101
|
1
|
|
|
1
|
|
5
|
use vars qw($VERSION); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
46
|
|
102
|
1
|
|
|
1
|
|
2094
|
use CGI; |
|
1
|
|
|
|
|
18852
|
|
|
1
|
|
|
|
|
5
|
|
103
|
1
|
|
|
1
|
|
9681
|
use DBI; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
$VERSION = '0.11'; |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
108
|
|
|
|
|
|
|
# Class constructors/destructors |
109
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
110
|
|
|
|
|
|
|
=pod |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 METHODS |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head2 Main Methods |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=over 4 |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=item B<$DBinterface = new DBIx::HTMLinterface (>I I I I<[Suppress paramcheck]>B<);> |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Constructs a new C object. You must pass a reference |
121
|
|
|
|
|
|
|
to a CGI object which will be used to get the script's parameters and a |
122
|
|
|
|
|
|
|
database handle (Returned from a Cconnect> function) which will |
123
|
|
|
|
|
|
|
be used to communicate with the database. The third parameter defines the |
124
|
|
|
|
|
|
|
name of the I which is used to determine hidden/excluded fields, |
125
|
|
|
|
|
|
|
field names and descriptions as described below in B. After |
126
|
|
|
|
|
|
|
initialisation, the CGI object is checked for a 'HTMLinterface-action' parameter. |
127
|
|
|
|
|
|
|
If this is present, control is taken from the script and the specified action |
128
|
|
|
|
|
|
|
is performed on the specified table. This parameter is set when an action which |
129
|
|
|
|
|
|
|
requires further processing is in progress. |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
The final parameter, suppress paramcheck, is optional and when set to 1 will |
132
|
|
|
|
|
|
|
cause the script NOT to perform the parameter check. You MUST then call the |
133
|
|
|
|
|
|
|
check_params function in your code or forms will not work. Overriding |
134
|
|
|
|
|
|
|
the script in this way is not recommended unless necessary for error handler |
135
|
|
|
|
|
|
|
or security check handler setting. |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=cut |
138
|
|
|
|
|
|
|
sub new |
139
|
|
|
|
|
|
|
{ |
140
|
|
|
|
|
|
|
my $proto = shift; |
141
|
|
|
|
|
|
|
my $class = ref($proto) || $proto; |
142
|
|
|
|
|
|
|
my $cgipkg = shift; |
143
|
|
|
|
|
|
|
my $dbihdl = shift; |
144
|
|
|
|
|
|
|
my $infotbl = shift; |
145
|
|
|
|
|
|
|
my $suppresscheck = shift || 0; |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
my $self = bless {}, $class; |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
$self->{CGI} = $cgipkg; # CGI package |
150
|
|
|
|
|
|
|
$self->{DBH} = $dbihdl; # DBI database handle |
151
|
|
|
|
|
|
|
$self->{ITABLE} = $infotbl; # Info Table name |
152
|
|
|
|
|
|
|
$self->{ERRHDL} = undef; # Error handler |
153
|
|
|
|
|
|
|
$self->{LOGFILE} = undef; # Log file |
154
|
|
|
|
|
|
|
$self->{LOGCALLBACK} = undef; # Logging callback function |
155
|
|
|
|
|
|
|
$self->{PRINTHEADER} = undef; # HTML header |
156
|
|
|
|
|
|
|
$self->{PRINTFOOTER} = undef; # HTML footer |
157
|
|
|
|
|
|
|
$self->{USEGMTTIME} = 1; # Use GMT time or local time |
158
|
|
|
|
|
|
|
$self->{TIMEMOD} = 0; # Add or subtract time |
159
|
|
|
|
|
|
|
$self->{ACCESSCALLBACK} = undef; # Security check callback |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
if ($suppresscheck != 1) { |
162
|
|
|
|
|
|
|
$self->check_params; |
163
|
|
|
|
|
|
|
} |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
return $self; |
166
|
|
|
|
|
|
|
} |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
sub DESTROY { } |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
########################################################################## |
171
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
172
|
|
|
|
|
|
|
# User-called functions |
173
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=pod |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=back |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=head2 Optional Methods |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
Optional methods which can be called to directly jump to a script function, |
182
|
|
|
|
|
|
|
for example to directly initiate a delete or modify on a record. |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=over 4 |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=cut |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=item B B<();> |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
# Check form parameters |
191
|
|
|
|
|
|
|
$DBinterface->check_params; |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
Causes the HTMLinterface-action parameter to be rechecked. If it contains |
194
|
|
|
|
|
|
|
the value 'add','modify','delete' or 'search', the respective function |
195
|
|
|
|
|
|
|
will be called ('exec_add','exec_modify','exec_delete' or 'exec_search'). |
196
|
|
|
|
|
|
|
this function is essential to the correct functioning of the interfaces |
197
|
|
|
|
|
|
|
with two and three part forms, and is called automatically when a |
198
|
|
|
|
|
|
|
HTMLinterface object is created, unless the 'suppress paramcheck' parameter |
199
|
|
|
|
|
|
|
is set to 1. |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
=cut |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
sub check_params { |
204
|
|
|
|
|
|
|
my $self = shift; |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
if ($self->{CGI}->param("HTMLinterface-action") eq "add") { |
207
|
|
|
|
|
|
|
$self->exec_add; |
208
|
|
|
|
|
|
|
exit; |
209
|
|
|
|
|
|
|
} elsif ($self->{CGI}->param("HTMLinterface-action") eq "modify") { |
210
|
|
|
|
|
|
|
$self->exec_modify; |
211
|
|
|
|
|
|
|
exit; |
212
|
|
|
|
|
|
|
} elsif ($self->{CGI}->param("HTMLinterface-action") eq "delete") { |
213
|
|
|
|
|
|
|
$self->exec_delete; |
214
|
|
|
|
|
|
|
exit; |
215
|
|
|
|
|
|
|
} elsif ($self->{CGI}->param("HTMLinterface-action") eq "search") { |
216
|
|
|
|
|
|
|
$self->exec_search; |
217
|
|
|
|
|
|
|
exit; |
218
|
|
|
|
|
|
|
} |
219
|
|
|
|
|
|
|
} |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
=item B B<();> |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
# Now set the 'HTMLinterface-table' parameter so the script knows |
224
|
|
|
|
|
|
|
# what table to deal with |
225
|
|
|
|
|
|
|
$cgi->param(-name=>'HTMLinterface-table',-value=>'mytable'); |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
# Now call the function |
228
|
|
|
|
|
|
|
$DBinterface->exec_search; |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
Searches the table named in the CGI parameter 'HTMLinterface-table'. |
231
|
|
|
|
|
|
|
The user will be presented with a blank form with the fields of the table. |
232
|
|
|
|
|
|
|
They press submit to search the table (Wildcards can be used). They are then |
233
|
|
|
|
|
|
|
returned a table with a modify and delete button and the fields for each |
234
|
|
|
|
|
|
|
record found. |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
=cut |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
sub exec_search { |
239
|
|
|
|
|
|
|
my $self = shift; |
240
|
|
|
|
|
|
|
my $table = $self->{CGI}->param("HTMLinterface-table"); |
241
|
|
|
|
|
|
|
#TODO: Lousy hack? |
242
|
|
|
|
|
|
|
my ($tablename, $name, $label, $lookup, $extrahash, $hidden, $exclude, |
243
|
|
|
|
|
|
|
$additionalwhere) = _getTableInfoHash($self, $table); |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
# Check access privs |
246
|
|
|
|
|
|
|
$self->_checkAccess; |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
if ($self->{CGI}->param('post')) { |
249
|
|
|
|
|
|
|
my ($i, $j, %types, %params, $pri, $cursor, $sql, @row, $val, $numcols, |
250
|
|
|
|
|
|
|
@fielddesc, @fieldtypes, @primary_keys, $content); |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
$self->_printHeader("Search Results", ""); |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
$numcols = 0; |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
# Now look up primary key fields and field types... |
257
|
|
|
|
|
|
|
my ($desc_cursor) = $self->_execSql ("describe $table"); |
258
|
|
|
|
|
|
|
while (@fielddesc = $desc_cursor->fetchrow) { |
259
|
|
|
|
|
|
|
$numcols++; |
260
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
# Stuff the paramaters into a hash before we delete them |
262
|
|
|
|
|
|
|
$params{$fielddesc[0]} = $self->{CGI}->param($fielddesc[0]); |
263
|
|
|
|
|
|
|
$types{$fielddesc[0]} = $fielddesc[1]; |
264
|
|
|
|
|
|
|
if ($fielddesc[3] eq "PRI") { |
265
|
|
|
|
|
|
|
push @primary_keys, $fielddesc[0]; |
266
|
|
|
|
|
|
|
} |
267
|
|
|
|
|
|
|
} |
268
|
|
|
|
|
|
|
$desc_cursor->finish; |
269
|
|
|
|
|
|
|
$numcols += 2; # Add Modify and Delete cols |
270
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
# now we execute the SQL, and return a list of matches |
272
|
|
|
|
|
|
|
$cursor = $self->_execSql($self->_selectSql($table, $additionalwhere)); |
273
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
# delete the current params so they don't get incorporated in the forms |
275
|
|
|
|
|
|
|
$self->{CGI}->delete_all; |
276
|
|
|
|
|
|
|
$self->_startTable($numcols, "Search Results"); |
277
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
# now print header row |
279
|
|
|
|
|
|
|
$self->_printStartTableRow(); |
280
|
|
|
|
|
|
|
$self->_printTableHeaderCell("Modify"); |
281
|
|
|
|
|
|
|
$self->_printTableHeaderCell("Delete"); |
282
|
|
|
|
|
|
|
for ($i=0; $i < $cursor->{NUM_OF_FIELDS}; $i++) { |
283
|
|
|
|
|
|
|
$self->_printTableHeaderCell("$cursor->{NAME}->[$i]"); |
284
|
|
|
|
|
|
|
} |
285
|
|
|
|
|
|
|
$self->_printEndTableRow(); |
286
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
while (@row = $cursor->fetchrow_array) { |
288
|
|
|
|
|
|
|
$self->_printStartTableRow(); |
289
|
|
|
|
|
|
|
|
290
|
|
|
|
|
|
|
# now print the Modify Form |
291
|
|
|
|
|
|
|
print $self->{CGI}->startform; |
292
|
|
|
|
|
|
|
$content = ""; |
293
|
|
|
|
|
|
|
# Print the primary keys |
294
|
|
|
|
|
|
|
for ($i=0; $i < $cursor->{NUM_OF_FIELDS}; $i++) { |
295
|
|
|
|
|
|
|
foreach $pri (@primary_keys) { |
296
|
|
|
|
|
|
|
if ($pri eq $cursor->{NAME}->[$i]) { |
297
|
|
|
|
|
|
|
print "{NAME}->[$i]\" VALUE=\"$row[$i]\">"; |
298
|
|
|
|
|
|
|
} |
299
|
|
|
|
|
|
|
} |
300
|
|
|
|
|
|
|
} |
301
|
|
|
|
|
|
|
# Print state tracking elements |
302
|
|
|
|
|
|
|
print $self->{CGI}->hidden(-name => 'HTMLinterface-action', value => 'modify'); |
303
|
|
|
|
|
|
|
print $self->{CGI}->hidden(-name => 'HTMLinterface-table', value => $table); |
304
|
|
|
|
|
|
|
$self->_printHidden; # Print any hidden elements necessary |
305
|
|
|
|
|
|
|
$self->_printTableCell ($self->{CGI}->submit('Modify')); |
306
|
|
|
|
|
|
|
print $self->{CGI}->endform; |
307
|
|
|
|
|
|
|
|
308
|
|
|
|
|
|
|
# now print the Delete Form |
309
|
|
|
|
|
|
|
print $self->{CGI}->startform; |
310
|
|
|
|
|
|
|
$content = ""; |
311
|
|
|
|
|
|
|
# Print the primary keys |
312
|
|
|
|
|
|
|
for ($i=0; $i < $cursor->{NUM_OF_FIELDS}; $i++) { |
313
|
|
|
|
|
|
|
foreach $pri (@primary_keys) { |
314
|
|
|
|
|
|
|
if ($pri eq $cursor->{NAME}->[$i]) { |
315
|
|
|
|
|
|
|
print "{NAME}->[$i]\" VALUE=\"$row[$i]\">"; |
316
|
|
|
|
|
|
|
} |
317
|
|
|
|
|
|
|
} |
318
|
|
|
|
|
|
|
} |
319
|
|
|
|
|
|
|
# Print state tracking elements |
320
|
|
|
|
|
|
|
print $self->{CGI}->hidden(-name => 'HTMLinterface-action', value => 'delete'); |
321
|
|
|
|
|
|
|
print $self->{CGI}->hidden(-name => 'HTMLinterface-table', value => $table); |
322
|
|
|
|
|
|
|
$self->_printHidden; # Print any hidden elements necessary |
323
|
|
|
|
|
|
|
$self->_printTableCell ($self->{CGI}->submit('Delete')); |
324
|
|
|
|
|
|
|
print $self->{CGI}->endform; |
325
|
|
|
|
|
|
|
|
326
|
|
|
|
|
|
|
# now print the fields |
327
|
|
|
|
|
|
|
for ($i=0; $i < $cursor->{NUM_OF_FIELDS}; $i++) { |
328
|
|
|
|
|
|
|
my $pos = 0; |
329
|
|
|
|
|
|
|
$val = $row[$i]; |
330
|
|
|
|
|
|
|
$val =~ s/&/&/g; |
331
|
|
|
|
|
|
|
$val =~ s/</g; |
332
|
|
|
|
|
|
|
$val =~ s/>/>/g; |
333
|
|
|
|
|
|
|
|
334
|
|
|
|
|
|
|
# Don't print the whole of the text fields |
335
|
|
|
|
|
|
|
if ($types{$cursor->{NAME}->[$i]} =~ "text") { |
336
|
|
|
|
|
|
|
my ($search) = ""; |
337
|
|
|
|
|
|
|
|
338
|
|
|
|
|
|
|
if ($search = $params{$cursor->{NAME}->[$i]}) { |
339
|
|
|
|
|
|
|
$search =~ s/&/&/g; |
340
|
|
|
|
|
|
|
$search =~ s/</g; |
341
|
|
|
|
|
|
|
$search =~ s/>/>/g; |
342
|
|
|
|
|
|
|
|
343
|
|
|
|
|
|
|
# Make wildcards work in highlight |
344
|
|
|
|
|
|
|
$search =~ s/_/(.)/g; |
345
|
|
|
|
|
|
|
$search =~ s/%/(.*)/g; |
346
|
|
|
|
|
|
|
|
347
|
|
|
|
|
|
|
# This chunk borrowed from plan_search.pl by Richard Smith :p |
348
|
|
|
|
|
|
|
|
349
|
|
|
|
|
|
|
# Find our search string in the field |
350
|
|
|
|
|
|
|
$pos = index(lc($val), lc($search)); |
351
|
|
|
|
|
|
|
|
352
|
|
|
|
|
|
|
# Grab the string for 100 characters before it |
353
|
|
|
|
|
|
|
$pos = $pos - 100; |
354
|
|
|
|
|
|
|
if ($pos < 0) { |
355
|
|
|
|
|
|
|
$pos = 0; |
356
|
|
|
|
|
|
|
} |
357
|
|
|
|
|
|
|
} |
358
|
|
|
|
|
|
|
my ($subtext) = substr($val, $pos, 300); |
359
|
|
|
|
|
|
|
|
360
|
|
|
|
|
|
|
# Change the search string to bold in the part of the string we're showing |
361
|
|
|
|
|
|
|
if ($search ne "") { $subtext =~ s/($search)/$1<\/b>/gi; } |
362
|
|
|
|
|
|
|
|
363
|
|
|
|
|
|
|
if (length($val) > 300) { # Show truncation marks if too long |
364
|
|
|
|
|
|
|
if ($pos < 1) { |
365
|
|
|
|
|
|
|
$val = $subtext . "..."; |
366
|
|
|
|
|
|
|
} else { |
367
|
|
|
|
|
|
|
$val = "..." . $subtext . "..."; |
368
|
|
|
|
|
|
|
} |
369
|
|
|
|
|
|
|
} else { |
370
|
|
|
|
|
|
|
$val = $subtext; |
371
|
|
|
|
|
|
|
} |
372
|
|
|
|
|
|
|
} |
373
|
|
|
|
|
|
|
$self->_printTableCell ("$val "); |
374
|
|
|
|
|
|
|
} |
375
|
|
|
|
|
|
|
$self->_printEndTableRow(); |
376
|
|
|
|
|
|
|
} |
377
|
|
|
|
|
|
|
$self->_endTable(); |
378
|
|
|
|
|
|
|
$self->_printFooter; |
379
|
|
|
|
|
|
|
exit; |
380
|
|
|
|
|
|
|
} else { |
381
|
|
|
|
|
|
|
# give them the form |
382
|
|
|
|
|
|
|
$self->_form($table,"search","Search $tablename","Search $tablename\n- Use the % character to match any number of characters (Even none).\n
- Use the _ character to match any one character.\n
- A % is automatically appended to all strings.\n
- You can enter just a normal wildcard character with no special meaning by typing a \\ before it, i.e \\% or \\_.
- Leave this form blank to show EVERYTHING.
" . $self->{CGI}->submit('Submit') . " " . $self->{CGI}->reset('Reset') . "\n","nodefaults",""); |
383
|
|
|
|
|
|
|
exit; |
384
|
|
|
|
|
|
|
} |
385
|
|
|
|
|
|
|
} |
386
|
|
|
|
|
|
|
|
387
|
|
|
|
|
|
|
=item B B<();> |
388
|
|
|
|
|
|
|
|
389
|
|
|
|
|
|
|
# Assume $cgi->param has been set to indicate the primary keys |
390
|
|
|
|
|
|
|
# for the table being modified, i.e 'Primary Key Name' = 'Primary |
391
|
|
|
|
|
|
|
# Key Value' |
392
|
|
|
|
|
|
|
|
393
|
|
|
|
|
|
|
# Now set the 'HTMLinterface-table' parameter so the script knows |
394
|
|
|
|
|
|
|
# what table to deal with |
395
|
|
|
|
|
|
|
$cgi->param(-name=>'HTMLinterface-table',-value=>'mytable'); |
396
|
|
|
|
|
|
|
|
397
|
|
|
|
|
|
|
# Now call the function |
398
|
|
|
|
|
|
|
$DBinterface->exec_modify; |
399
|
|
|
|
|
|
|
|
400
|
|
|
|
|
|
|
Modifies a record from the table named in the CGI parameter 'HTMLinterface-table' |
401
|
|
|
|
|
|
|
where the CGI parameters which have the same name as a table column. For example |
402
|
|
|
|
|
|
|
for a table called 'data' with an 'ID' column containing the primary keys for |
403
|
|
|
|
|
|
|
that table, set the 'HTMLinterface-table' parameter to 'data' and set the 'ID' |
404
|
|
|
|
|
|
|
parameter to the ID number of the record you want to modify. The user will then |
405
|
|
|
|
|
|
|
be presented with a form containing the data in the table for them to modify. |
406
|
|
|
|
|
|
|
They then press submit to commit the data |
407
|
|
|
|
|
|
|
|
408
|
|
|
|
|
|
|
=cut |
409
|
|
|
|
|
|
|
sub exec_modify { |
410
|
|
|
|
|
|
|
my $self = shift; |
411
|
|
|
|
|
|
|
|
412
|
|
|
|
|
|
|
# Check access privs |
413
|
|
|
|
|
|
|
$self->_checkAccess; |
414
|
|
|
|
|
|
|
|
415
|
|
|
|
|
|
|
# Execute the modify if the user already has the form else give the user the form |
416
|
|
|
|
|
|
|
if ($self->{CGI}->param('post')) { |
417
|
|
|
|
|
|
|
$self->_modifyRecord($self->{CGI}->param("HTMLinterface-table")); |
418
|
|
|
|
|
|
|
} else { |
419
|
|
|
|
|
|
|
$self->_form($self->{CGI}->param("HTMLinterface-table"),"modify","Modify Record","Modify Record","","fill_from_table"); |
420
|
|
|
|
|
|
|
} |
421
|
|
|
|
|
|
|
} |
422
|
|
|
|
|
|
|
|
423
|
|
|
|
|
|
|
=item B B<();> |
424
|
|
|
|
|
|
|
|
425
|
|
|
|
|
|
|
# Now set the 'HTMLinterface-table' parameter so the script knows |
426
|
|
|
|
|
|
|
# what table to deal with |
427
|
|
|
|
|
|
|
$cgi->param(-name=>'HTMLinterface-table',-value=>'mytable'); |
428
|
|
|
|
|
|
|
|
429
|
|
|
|
|
|
|
# Now call the function |
430
|
|
|
|
|
|
|
$DBinterface->exec_add; |
431
|
|
|
|
|
|
|
|
432
|
|
|
|
|
|
|
Adds a record to the table named in the CGI parameter 'HTMLinterface-table'. |
433
|
|
|
|
|
|
|
The user will be presented with a empty form containing just the defaults for |
434
|
|
|
|
|
|
|
the values of that table (Defined in the SQL). They then press submit to commit |
435
|
|
|
|
|
|
|
the data to the table. |
436
|
|
|
|
|
|
|
|
437
|
|
|
|
|
|
|
=cut |
438
|
|
|
|
|
|
|
sub exec_add { |
439
|
|
|
|
|
|
|
my $self = shift; |
440
|
|
|
|
|
|
|
|
441
|
|
|
|
|
|
|
# Check access privs |
442
|
|
|
|
|
|
|
$self->_checkAccess; |
443
|
|
|
|
|
|
|
|
444
|
|
|
|
|
|
|
if ($self->{CGI}->param('post')) { |
445
|
|
|
|
|
|
|
$self->_insertRecord($self->{CGI}->param("HTMLinterface-table")); |
446
|
|
|
|
|
|
|
} else { |
447
|
|
|
|
|
|
|
$self->_form($self->{CGI}->param("HTMLinterface-table"),"add","Add Record","Add Record","",""); |
448
|
|
|
|
|
|
|
} |
449
|
|
|
|
|
|
|
} |
450
|
|
|
|
|
|
|
|
451
|
|
|
|
|
|
|
=item B B<();> |
452
|
|
|
|
|
|
|
|
453
|
|
|
|
|
|
|
# Assume $cgi->param has been set to indicate the primary keys |
454
|
|
|
|
|
|
|
# for the table being modified, i.e 'Primary Key Name' = 'Primary |
455
|
|
|
|
|
|
|
# Key Value' |
456
|
|
|
|
|
|
|
|
457
|
|
|
|
|
|
|
# Now set the 'HTMLinterface-table' parameter so the script knows |
458
|
|
|
|
|
|
|
# what table to deal with |
459
|
|
|
|
|
|
|
$cgi->param(-name=>'HTMLinterface-table',-value=>'mytable'); |
460
|
|
|
|
|
|
|
|
461
|
|
|
|
|
|
|
# Now call the function |
462
|
|
|
|
|
|
|
$DBinterface->exec_delete; |
463
|
|
|
|
|
|
|
|
464
|
|
|
|
|
|
|
Deletes a record from the table named in the CGI parameter 'HTMLinterface-table' |
465
|
|
|
|
|
|
|
where the CGI parameters which have the same name as a table column. For example |
466
|
|
|
|
|
|
|
for a table called 'data' with an 'ID' column containing the primary keys for |
467
|
|
|
|
|
|
|
that table, set the 'HTMLinterface-table' parameter to 'data' and set the 'ID' |
468
|
|
|
|
|
|
|
parameter to the ID number of the record you want to delete. |
469
|
|
|
|
|
|
|
|
470
|
|
|
|
|
|
|
This function will output a confirmation page requiring users to confirm the delete |
471
|
|
|
|
|
|
|
or press their browser's back button to cancel. To skip confirmation, set the 'confirm' |
472
|
|
|
|
|
|
|
parameter to 'Y'. |
473
|
|
|
|
|
|
|
|
474
|
|
|
|
|
|
|
=cut |
475
|
|
|
|
|
|
|
sub exec_delete { |
476
|
|
|
|
|
|
|
my $self = shift; |
477
|
|
|
|
|
|
|
|
478
|
|
|
|
|
|
|
# Check access privs |
479
|
|
|
|
|
|
|
$self->_checkAccess; |
480
|
|
|
|
|
|
|
|
481
|
|
|
|
|
|
|
# Delete the record |
482
|
|
|
|
|
|
|
$self->_deleteRecord($self->{CGI}->param("HTMLinterface-table")); |
483
|
|
|
|
|
|
|
} |
484
|
|
|
|
|
|
|
|
485
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
486
|
|
|
|
|
|
|
# General support functions |
487
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
488
|
|
|
|
|
|
|
=pod |
489
|
|
|
|
|
|
|
|
490
|
|
|
|
|
|
|
=back |
491
|
|
|
|
|
|
|
|
492
|
|
|
|
|
|
|
=head2 Optional Customisation Methods |
493
|
|
|
|
|
|
|
|
494
|
|
|
|
|
|
|
Optional methods which can be called to alter the behaviour of the script |
495
|
|
|
|
|
|
|
or enable features such as logging. |
496
|
|
|
|
|
|
|
|
497
|
|
|
|
|
|
|
=over 4 |
498
|
|
|
|
|
|
|
|
499
|
|
|
|
|
|
|
=cut |
500
|
|
|
|
|
|
|
|
501
|
|
|
|
|
|
|
=item B B<(>IB<);> |
502
|
|
|
|
|
|
|
|
503
|
|
|
|
|
|
|
sub log_callback { |
504
|
|
|
|
|
|
|
my $description = shift; |
505
|
|
|
|
|
|
|
my $sql = shift; |
506
|
|
|
|
|
|
|
|
507
|
|
|
|
|
|
|
open (LOG,">>$logfile") |
508
|
|
|
|
|
|
|
print LOG "$description (Executing $sql)"; |
509
|
|
|
|
|
|
|
close(LOG); |
510
|
|
|
|
|
|
|
} |
511
|
|
|
|
|
|
|
$DBinterface = new DBIx::HTMLinterface ($cgi, $dbh, $table, 1); |
512
|
|
|
|
|
|
|
$DBinterface->set_logcallback(\&log_callback); |
513
|
|
|
|
|
|
|
$DBinterface->check_params(); |
514
|
|
|
|
|
|
|
|
515
|
|
|
|
|
|
|
Enables logging of SQL changes to the database via the user |
516
|
|
|
|
|
|
|
defined routine. The first parameter passed is a description, |
517
|
|
|
|
|
|
|
such as 'Record added to mytable' and the second parameter is |
518
|
|
|
|
|
|
|
the SQL statement which was used. |
519
|
|
|
|
|
|
|
|
520
|
|
|
|
|
|
|
NOTE: check_params() MUST be called or HTMLinterface will not function correctly. |
521
|
|
|
|
|
|
|
|
522
|
|
|
|
|
|
|
=cut |
523
|
|
|
|
|
|
|
sub set_logcallback { |
524
|
|
|
|
|
|
|
# $self &callback; |
525
|
|
|
|
|
|
|
$_[0]->{LOGCALLBACK} = $_[1]; |
526
|
|
|
|
|
|
|
} |
527
|
|
|
|
|
|
|
|
528
|
|
|
|
|
|
|
=item B B<(>IB<);> |
529
|
|
|
|
|
|
|
$DBinterface = new DBIx::HTMLinterface ($cgi, $dbh, $table, 1); |
530
|
|
|
|
|
|
|
$DBinterface->set_logfile("/usr/local/logs/mydb-log"); |
531
|
|
|
|
|
|
|
$DBinterface->check_params(); |
532
|
|
|
|
|
|
|
|
533
|
|
|
|
|
|
|
Enables logging of SQL changes to the database automatically |
534
|
|
|
|
|
|
|
without providing a callback. The script will open the file |
535
|
|
|
|
|
|
|
specified, with no locking (Althoughthis might be added in |
536
|
|
|
|
|
|
|
future). The file must be writeable to the CGI, on UNIX you |
537
|
|
|
|
|
|
|
normally need to I. However this may |
538
|
|
|
|
|
|
|
differ depending on your system and what operating system |
539
|
|
|
|
|
|
|
you have. |
540
|
|
|
|
|
|
|
|
541
|
|
|
|
|
|
|
NOTE: check_params() MUST be called or HTMLinterface will not function correctly. |
542
|
|
|
|
|
|
|
|
543
|
|
|
|
|
|
|
=cut |
544
|
|
|
|
|
|
|
sub set_logfile { |
545
|
|
|
|
|
|
|
# $self $logfile; |
546
|
|
|
|
|
|
|
$_[0]->{LOGFILE} = $_[1]; |
547
|
|
|
|
|
|
|
} |
548
|
|
|
|
|
|
|
|
549
|
|
|
|
|
|
|
# Internal function to log output if logging is enabled |
550
|
|
|
|
|
|
|
sub _logEvent { |
551
|
|
|
|
|
|
|
my $self = shift; |
552
|
|
|
|
|
|
|
my $cmd = shift; |
553
|
|
|
|
|
|
|
my $sql = shift; |
554
|
|
|
|
|
|
|
my $logfile = undef; |
555
|
|
|
|
|
|
|
|
556
|
|
|
|
|
|
|
# If we have a callback, use it |
557
|
|
|
|
|
|
|
if (defined $self->{LOGCALLBACK}) { |
558
|
|
|
|
|
|
|
&{$self->{LOGCALLBACK}} ($cmd, $sql); |
559
|
|
|
|
|
|
|
return; |
560
|
|
|
|
|
|
|
|
561
|
|
|
|
|
|
|
# Else output to a logfile ourselves |
562
|
|
|
|
|
|
|
} elsif (defined $self->{LOGFILE}) { |
563
|
|
|
|
|
|
|
$logfile = $self->{LOGFILE}; |
564
|
|
|
|
|
|
|
|
565
|
|
|
|
|
|
|
# Else forget logging |
566
|
|
|
|
|
|
|
} else { |
567
|
|
|
|
|
|
|
return; |
568
|
|
|
|
|
|
|
|
569
|
|
|
|
|
|
|
} |
570
|
|
|
|
|
|
|
|
571
|
|
|
|
|
|
|
# Get and format the time |
572
|
|
|
|
|
|
|
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime(time); |
573
|
|
|
|
|
|
|
if ($sec < 10) { $sec = "0$sec"; } |
574
|
|
|
|
|
|
|
if ($min < 10) { $min = "0$min"; } |
575
|
|
|
|
|
|
|
if ($hour < 10) { $hour = "0$hour"; } |
576
|
|
|
|
|
|
|
if ($mon < 10) { $mon = "0$mon"; } |
577
|
|
|
|
|
|
|
if ($mday < 10) { $mday = "0$mday"; } |
578
|
|
|
|
|
|
|
my (@months) = ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"); |
579
|
|
|
|
|
|
|
my ($cur_date) = "[" . $mday . "/" . $months[$mon] . "/" . $year . ":" . $hour . ":" . $min . ":" . $sec . " +0000]"; |
580
|
|
|
|
|
|
|
|
581
|
|
|
|
|
|
|
# Open the logfile for append |
582
|
|
|
|
|
|
|
if (! open(LOG,">>$logfile")) { |
583
|
|
|
|
|
|
|
# Send warnings to the browser and STDERR on failure |
584
|
|
|
|
|
|
|
warn ("Unable to open logfile $logfile for append ($!)"); |
585
|
|
|
|
|
|
|
print "WARNING: Unable to open logfile $logfile for append ($!)"; |
586
|
|
|
|
|
|
|
return; |
587
|
|
|
|
|
|
|
} |
588
|
|
|
|
|
|
|
|
589
|
|
|
|
|
|
|
# Print to the logfile |
590
|
|
|
|
|
|
|
print LOG "$cur_date $cmd" . ($sql ne "" ? " SQL: '$sql'" : "") . "\n"; |
591
|
|
|
|
|
|
|
|
592
|
|
|
|
|
|
|
# Close the logfile |
593
|
|
|
|
|
|
|
close (LOG); |
594
|
|
|
|
|
|
|
} |
595
|
|
|
|
|
|
|
|
596
|
|
|
|
|
|
|
=item B B<(>IB<);> |
597
|
|
|
|
|
|
|
|
598
|
|
|
|
|
|
|
sub errorhandler { |
599
|
|
|
|
|
|
|
my $errstr = shift; |
600
|
|
|
|
|
|
|
|
601
|
|
|
|
|
|
|
print "Fatal Error"; |
602
|
|
|
|
|
|
|
print $errstr; |
603
|
|
|
|
|
|
|
|
604
|
|
|
|
|
|
|
exit; |
605
|
|
|
|
|
|
|
} |
606
|
|
|
|
|
|
|
$DBinterface = new DBIx::HTMLinterface ($cgi, $dbh, $table, 1); |
607
|
|
|
|
|
|
|
$DBinterface->set_errorhandler(\&errorhandler); |
608
|
|
|
|
|
|
|
$DBinterface->check_params(); |
609
|
|
|
|
|
|
|
|
610
|
|
|
|
|
|
|
Transfers error handling in the script from the I procedure |
611
|
|
|
|
|
|
|
to the subroutine passed as the argument. The errorhandling routine |
612
|
|
|
|
|
|
|
should not return, and should terminate the program after the error |
613
|
|
|
|
|
|
|
has been output. |
614
|
|
|
|
|
|
|
|
615
|
|
|
|
|
|
|
NOTE: check_params() MUST be called or HTMLinterface will not function correctly. |
616
|
|
|
|
|
|
|
|
617
|
|
|
|
|
|
|
=cut |
618
|
|
|
|
|
|
|
sub set_errhandler { |
619
|
|
|
|
|
|
|
# $self &errorhandler; |
620
|
|
|
|
|
|
|
$_[0]->{ERRHDL} = $_[1]; |
621
|
|
|
|
|
|
|
} |
622
|
|
|
|
|
|
|
|
623
|
|
|
|
|
|
|
=item B |
624
|
|
|
|
|
|
|
|
625
|
|
|
|
|
|
|
sub checkaccess { |
626
|
|
|
|
|
|
|
if ($cgi->param("password") eq "letmein") { # Example security check |
627
|
|
|
|
|
|
|
return; # Valid password - return to allow function to continue |
628
|
|
|
|
|
|
|
} else { |
629
|
|
|
|
|
|
|
die ("Incorrect password"); # Incorrect - die to stop execution |
630
|
|
|
|
|
|
|
} |
631
|
|
|
|
|
|
|
} |
632
|
|
|
|
|
|
|
$DBinterface = new DBIx::HTMLinterface ($cgi, $dbh, $table, 1); |
633
|
|
|
|
|
|
|
$DBinterface->set_accesscallback(\&errorhandler); |
634
|
|
|
|
|
|
|
$DBinterface->check_params(); |
635
|
|
|
|
|
|
|
|
636
|
|
|
|
|
|
|
Enables a security check function to approve or deny access. The function is |
637
|
|
|
|
|
|
|
called before changes to the database are made. The function should return to |
638
|
|
|
|
|
|
|
allow an action to complete or die to terminate the program and prevent access. |
639
|
|
|
|
|
|
|
|
640
|
|
|
|
|
|
|
NOTE: check_params() MUST be called or HTMLinterface will not function correctly. |
641
|
|
|
|
|
|
|
|
642
|
|
|
|
|
|
|
=cut |
643
|
|
|
|
|
|
|
sub set_accesscallback { |
644
|
|
|
|
|
|
|
my $self = shift; |
645
|
|
|
|
|
|
|
my $callback = shift; |
646
|
|
|
|
|
|
|
|
647
|
|
|
|
|
|
|
$self->{ACCESSCALLBACK} = $callback; |
648
|
|
|
|
|
|
|
} |
649
|
|
|
|
|
|
|
|
650
|
|
|
|
|
|
|
# Internal function to call the user defined security check |
651
|
|
|
|
|
|
|
sub _checkAccess { |
652
|
|
|
|
|
|
|
my $self = shift; |
653
|
|
|
|
|
|
|
my $callback = $self->{ACCESSCALLBACK}; |
654
|
|
|
|
|
|
|
|
655
|
|
|
|
|
|
|
if (ref($callback) eq 'CODE') { |
656
|
|
|
|
|
|
|
&$callback(); # nicer to perl 5.003 users |
657
|
|
|
|
|
|
|
} |
658
|
|
|
|
|
|
|
} |
659
|
|
|
|
|
|
|
|
660
|
|
|
|
|
|
|
# Internal function to output errors and exit the program |
661
|
|
|
|
|
|
|
sub _die { |
662
|
|
|
|
|
|
|
my $self = shift; |
663
|
|
|
|
|
|
|
my $errstr = shift; |
664
|
|
|
|
|
|
|
|
665
|
|
|
|
|
|
|
if (defined $self->{ERRHDL}) { |
666
|
|
|
|
|
|
|
&{$self->{ERRHDL}} ($errstr); |
667
|
|
|
|
|
|
|
} |
668
|
|
|
|
|
|
|
|
669
|
|
|
|
|
|
|
# Call die whether or not the user defined error handler has been called |
670
|
|
|
|
|
|
|
# - the error is fatal and we should not get here if the user defined |
671
|
|
|
|
|
|
|
# handler operates correctly anyway. |
672
|
|
|
|
|
|
|
die $errstr; |
673
|
|
|
|
|
|
|
} |
674
|
|
|
|
|
|
|
|
675
|
|
|
|
|
|
|
=item B B<(>IB<,> I |
676
|
|
|
|
|
|
|
|
677
|
|
|
|
|
|
|
$DBinterface->set_timezone(1, 0); # Set time to GMT +0000 |
678
|
|
|
|
|
|
|
$DBinterface->set_timezone(0, -5); # Set time to server time -0500 |
679
|
|
|
|
|
|
|
$DBinterface->set_timezone(1, -8); # Set time to GMT -0800 |
680
|
|
|
|
|
|
|
$DBinterface->set_timezone(0, 2); # Set time to server time +0200 |
681
|
|
|
|
|
|
|
|
682
|
|
|
|
|
|
|
Changes the time zone used for timestamps inserted into database records. The |
683
|
|
|
|
|
|
|
first parameter specifies whether to use GMT time or to use the server time, |
684
|
|
|
|
|
|
|
i.e the computer running this script's internal clock. The second parameter |
685
|
|
|
|
|
|
|
allows time to be added or subtracted in hours. |
686
|
|
|
|
|
|
|
|
687
|
|
|
|
|
|
|
=cut |
688
|
|
|
|
|
|
|
sub set_timezone { |
689
|
|
|
|
|
|
|
# $self $usegmttime; |
690
|
|
|
|
|
|
|
$_[0]->{USEGMTTIME} = $_[1]; |
691
|
|
|
|
|
|
|
# $self $timemod; |
692
|
|
|
|
|
|
|
$_[0]->{TIMEMOD} = $_[2]; |
693
|
|
|
|
|
|
|
} |
694
|
|
|
|
|
|
|
|
695
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
696
|
|
|
|
|
|
|
# HTML formatting functions |
697
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
698
|
|
|
|
|
|
|
=pod |
699
|
|
|
|
|
|
|
|
700
|
|
|
|
|
|
|
=back |
701
|
|
|
|
|
|
|
|
702
|
|
|
|
|
|
|
=head2 Optional HTML Customisation Methods |
703
|
|
|
|
|
|
|
|
704
|
|
|
|
|
|
|
=over 4 |
705
|
|
|
|
|
|
|
|
706
|
|
|
|
|
|
|
=item Future Additions |
707
|
|
|
|
|
|
|
|
708
|
|
|
|
|
|
|
In a later version, callbacks to print table cells, start and finish tables, |
709
|
|
|
|
|
|
|
print form fields, print back links and add user defined form parameters to |
710
|
|
|
|
|
|
|
allow state keeping such as password protection etc. |
711
|
|
|
|
|
|
|
|
712
|
|
|
|
|
|
|
=item B |
713
|
|
|
|
|
|
|
|
714
|
|
|
|
|
|
|
sub printheader { |
715
|
|
|
|
|
|
|
my $title = shift; |
716
|
|
|
|
|
|
|
my $headtext = shift; |
717
|
|
|
|
|
|
|
|
718
|
|
|
|
|
|
|
print $cgi->start_html(-title=>"$title_txt"); |
719
|
|
|
|
|
|
|
|
720
|
|
|
|
|
|
|
if ($headtext ne "") { |
721
|
|
|
|
|
|
|
print $cgi->h3($headtext); |
722
|
|
|
|
|
|
|
} |
723
|
|
|
|
|
|
|
} |
724
|
|
|
|
|
|
|
$DBinterface->set_printheader(\&printheader); |
725
|
|
|
|
|
|
|
|
726
|
|
|
|
|
|
|
Transfers the header HTML outputting function to a user defined function |
727
|
|
|
|
|
|
|
to allow HTML customisation. |
728
|
|
|
|
|
|
|
|
729
|
|
|
|
|
|
|
=cut |
730
|
|
|
|
|
|
|
sub set_printheader { |
731
|
|
|
|
|
|
|
# $self &printheader; |
732
|
|
|
|
|
|
|
$_[0]->{PRINTHEADER} = $_[1]; |
733
|
|
|
|
|
|
|
} |
734
|
|
|
|
|
|
|
|
735
|
|
|
|
|
|
|
# Internal function to start the output in the user's desired style |
736
|
|
|
|
|
|
|
sub _printHeader { |
737
|
|
|
|
|
|
|
my $self = shift; |
738
|
|
|
|
|
|
|
my $title = shift; |
739
|
|
|
|
|
|
|
my $headtext = shift; |
740
|
|
|
|
|
|
|
my ($package, $filename, $line) = caller(); |
741
|
|
|
|
|
|
|
|
742
|
|
|
|
|
|
|
print $self->{CGI}->header; |
743
|
|
|
|
|
|
|
|
744
|
|
|
|
|
|
|
if (defined $self->{PRINTHEADER}) { |
745
|
|
|
|
|
|
|
&{$self->{PRINTHEADER}} ($title, $headtext); |
746
|
|
|
|
|
|
|
} else { |
747
|
|
|
|
|
|
|
print $self->{CGI}->start_html(-title=>"$title", |
748
|
|
|
|
|
|
|
-bgcolor=>"#FFFFFF", |
749
|
|
|
|
|
|
|
-text=>"#000077" |
750
|
|
|
|
|
|
|
); |
751
|
|
|
|
|
|
|
if ($headtext ne "") { |
752
|
|
|
|
|
|
|
print $self->{CGI}->h3($headtext); |
753
|
|
|
|
|
|
|
} |
754
|
|
|
|
|
|
|
} |
755
|
|
|
|
|
|
|
|
756
|
|
|
|
|
|
|
print "\n\n\n"; |
757
|
|
|
|
|
|
|
} |
758
|
|
|
|
|
|
|
|
759
|
|
|
|
|
|
|
=item B |
760
|
|
|
|
|
|
|
|
761
|
|
|
|
|
|
|
sub printfooter { |
762
|
|
|
|
|
|
|
print $cgi->end_html; |
763
|
|
|
|
|
|
|
} |
764
|
|
|
|
|
|
|
$DBinterface->set_printfooter(\&printfooter); |
765
|
|
|
|
|
|
|
|
766
|
|
|
|
|
|
|
Transfers the footer HTML outputting function to a user defined function |
767
|
|
|
|
|
|
|
to allow HTML customisation. |
768
|
|
|
|
|
|
|
|
769
|
|
|
|
|
|
|
=cut |
770
|
|
|
|
|
|
|
sub set_printfooter { |
771
|
|
|
|
|
|
|
# $self &printfooter; |
772
|
|
|
|
|
|
|
$_[0]->{PRINTFOOTER} = $_[1]; |
773
|
|
|
|
|
|
|
} |
774
|
|
|
|
|
|
|
|
775
|
|
|
|
|
|
|
# Internal function to end the output in the user's desired style |
776
|
|
|
|
|
|
|
sub _printFooter { |
777
|
|
|
|
|
|
|
my $self = shift; |
778
|
|
|
|
|
|
|
|
779
|
|
|
|
|
|
|
if (defined $self->{PRINTFOOTER}) { |
780
|
|
|
|
|
|
|
&{$self->{PRINTFOOTER}}; |
781
|
|
|
|
|
|
|
} else { |
782
|
|
|
|
|
|
|
print " |