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

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

/branches/htmlform

Added missing index and footer templates
Update default CSS with definitions for footer, alternate-row colours
Have main.cgi look for a template matching $webvar{action}
Convert main summary page content to template
See #3.

File size: 2.0 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( &printHeader &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 printHeader {
29  my $title = shift;
30  print "Content-type: text/html\n\n";
31# This doesn't work well.  Must investigate.
32#  my $realm = shift;
33#  print qq(WWW-Authenticate: Basic realm="$realm"\n) if $realm;
34  open FILE, "../header.inc"
35        or carp $!;
36  my $html = join('',<FILE>);
37  close FILE;
38
39  $html =~ s/\$\$TITLE\$\$/$title/;
40# Necessary for mangling arbitrary bits of the header
41  my $i=0;
42  while (defined(my $param = shift)) {
43    $html =~ s/\$\$EXTRA$i\$\$/$param/g;
44    $i++;
45  }
46  print $html;
47}
48
49sub printError($)
50{
51        my $errStr = $_[0];
52        print qq(
53        <center><p class="regular"> $errStr </p>
54        <input type="button" value="Back" onclick="history.go(-1)">
55        </center>
56        );
57}
58
59sub printAndExit($)
60{
61        my $errStr = $_[0];
62        print qq(
63        <center><p class="regular"> $errStr </p>
64        <input type="button" value="Back" onclick="history.go(-1)">
65        </center>
66        );
67        print "<br>would print footer but already dun gone and shot(self->foot)\n";
68        exit(0);
69}
70
71# needs a reference to the webvar hash.
72# takes out backticks and single quotes
73sub cleanInput($)
74{
75        my $hashRef = $_[0];
76
77        foreach my $key (keys %$hashRef) 
78        {
79                $hashRef->{$key} =~ s/`/\\`/g;
80                $hashRef->{$key} =~ s/'/\'/g;
81        }
82}
83
84# undoes clean input.  takes a string as an arg.
85sub desanitize($)
86{
87        my $string = $_[0];
88        $string =~ s/\\`/`/g;
89        $string =~ s/\\'/'/g;
90        return $string;
91}
92
93# indicate that the module loaded okay.
941;
Note: See TracBrowser for help on using the repository browser.