#the dumb terminal webmysql module #mt 16/11/2003 2.4 added parseFragmentToString package DTWebMySQL::General; BEGIN { use Exporter(); use DTWebMySQL::Main; @ISA = qw(Exporter); @EXPORT = qw(getData replace parsePage parseFragmentToString); } ############################################################################################################### sub getData{ #gets cgi form data into a hash #foreach (keys %ENV){print STDERR "$_ = $ENV{$_}\n";} my $cgi = CGI::new(); foreach($cgi -> param()){ $form{$_} = $cgi -> param($_); #print STDERR "$_ = $form{$_}\n"; } return 1; } ############################################################################################################### sub replace{ #make sure we dont get any undefined values when replacing template placeholders if(defined($form{$_[0]})){return $form{$_[0]};} #return hash value else{ print STDERR "$0: $_[0] is undefined in placeholder replace\n"; return ""; #return nothing } } ############################################################################################################### sub parsePage{ #displays a html page my $page = shift; my $ignoreError = shift; if($error && !$ignoreError){ #an error has not been encountered and we are not ignoring it $page = "error"; print STDERR "$0: $error\n"; #log this error too } if(open(TEMPLATE, "){ #read the file a line at a time $_ =~ s//\n\t/; $_ =~ s//$ENV{'SCRIPT_NAME'}/g; #replace the name for this script $_ =~ s//$ENV{'HTTP_HOST'}/g; #replace webserver name $_ =~ s//$error/g; #replace the error message $_ =~ s//$version/g; #replace version number $_ =~ s//&replace($1)/eg; #replace the placeholders in the template $_ =~ s||

\n
© Dumb Terminal Creations
\n|; print; } close(TEMPLATE); } else{ print << "(NO TEMPLATE)"; Could not open HTML template: webmysql-$version/templates/$page.html (NO TEMPLATE) } } ############################################################################################################### sub parseFragmentToString{ #save a html fragment to a string my $page = shift; my $string = "\n"; if(open(TEMPLATE, "){ #read the file a line at a time $_ =~ s//$ENV{'SCRIPT_NAME'}/g; #replace the name for this script $_ =~ s//$ENV{'HTTP_HOST'}/g; #replace webserver name $_ =~ s//$error/g; #replace the error message $_ =~ s//$version/g; #replace version number $_ =~ s//&replace($1)/eg; #replace the placeholders in the template $string .= $_ } close(TEMPLATE); } else{$error = "Cant open HTML fragment: $page";} return $string; } ############################################################################### return 1; END {}