source: branches/htmlform/cgi-bin/CommonWeb.pm @ 479

Last change on this file since 479 was 479, checked in by Kris Deugau, 11 years ago

/branches/htmlform

Convert initial DB connection error output to a sane page. Could arguably provide
space for this (and other) errors on all normal pages. (See #3).
This allows us to:

  • Remove editError sub in main.cgi
  • Remove printHeader sub in CommonWeb?.pm (see #15, #26)

Removed duplicate "exit if we get this far"
Tweak IPDB::finish so it doesn't spit a fatal error when called with a null database handle

File size: 1.4 KB
Line 
1# ipdb/cgi-bin/CommonWeb.pm
2###
3# SVN revision info
4# $Date$
5# SVN revision $Rev$
6# Last update by $Author$
7###
8
9package CommonWeb;
10
11use strict;             
12use warnings;
13use Exporter;
14use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
15
16$VERSION     = 1.00;
17@ISA         = qw(Exporter);
18@EXPORT_OK      = qw( &printError &printAndExit &desanitize &cleanInput &desanitize);
19
20@EXPORT      = (); #export nothing by default
21%EXPORT_TAGS = ( ALL => [qw( &printHeader &printError
22                                &printAndExit &desanitize &cleanInput )],
23                 lean    => [qw( &printHeader &printError
24                                &printAndExit &cleanInput )]
25                );
26
27
28sub printError($)
29{
30        my $errStr = $_[0];
31        print qq(
32        <center><p class="regular"> $errStr </p>
33        <input type="button" value="Back" onclick="history.go(-1)">
34        </center>
35        );
36}
37
38sub printAndExit($)
39{
40        my $errStr = $_[0];
41        print qq(
42        <center><p class="regular"> $errStr </p>
43        <input type="button" value="Back" onclick="history.go(-1)">
44        </center>
45        );
46        print "<br>would print footer but already dun gone and shot(self->foot)\n";
47        exit(0);
48}
49
50# needs a reference to the webvar hash.
51# takes out backticks and single quotes
52sub cleanInput($)
53{
54        my $hashRef = $_[0];
55
56        foreach my $key (keys %$hashRef) 
57        {
58                $hashRef->{$key} =~ s/`/\\`/g;
59                $hashRef->{$key} =~ s/'/\'/g;
60        }
61}
62
63# undoes clean input.  takes a string as an arg.
64sub desanitize($)
65{
66        my $string = $_[0];
67        $string =~ s/\\`/`/g;
68        $string =~ s/\\'/'/g;
69        return $string;
70}
71
72# indicate that the module loaded okay.
731;
Note: See TracBrowser for help on using the repository browser.