"Fossies" - the Fresh Open Source Software Archive

Member "webmysql-2.7/cgi-bin/webmysql-2.7/DTWebMySQL/General.pm" (12 Feb 2008, 3140 Bytes) of package /linux/www/old/webmysql-2.7.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Perl source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "General.pm" see the Fossies "Dox" file reference documentation.

    1 #the dumb terminal webmysql module
    2 #mt 16/11/2003 2.4  added parseFragmentToString
    3 package DTWebMySQL::General;
    4 BEGIN {
    5    use Exporter();
    6     use DTWebMySQL::Main;
    7     @ISA = qw(Exporter);
    8    @EXPORT = qw(getData replace parsePage parseFragmentToString);
    9 }
   10 ###############################################################################################################
   11 sub getData{    #gets cgi form data into a hash
   12     #foreach (keys %ENV){print STDERR "$_ = $ENV{$_}\n";}
   13     my $cgi = CGI::new();
   14     foreach($cgi -> param()){
   15         $form{$_} = $cgi -> param($_);
   16         #print STDERR "$_ = $form{$_}\n";
   17     }
   18     return 1;
   19 }
   20 ###############################################################################################################
   21 sub replace{    #make sure we dont get any undefined values when replacing template placeholders
   22     if(defined($form{$_[0]})){return $form{$_[0]};} #return hash value
   23     else{
   24         print STDERR "$0: $_[0] is undefined in placeholder replace\n";
   25         return "";  #return nothing
   26     }
   27 }
   28 ###############################################################################################################
   29 sub parsePage{  #displays a html page
   30     my $page = shift;
   31     my $ignoreError = shift;
   32     if($error && !$ignoreError){    #an error has not been encountered and we are not ignoring it
   33         $page = "error";
   34         print STDERR "$0: $error\n";    #log this error too
   35     }
   36     if(open(TEMPLATE, "<templates/$page.html")){
   37         while(<TEMPLATE>){  #read the file a line at a time
   38             $_ =~ s/<html>/<html>\n\t<!-- Template: $page.html -->/;
   39             $_ =~ s/<!--self-->/$ENV{'SCRIPT_NAME'}/g;  #replace the name for this script
   40             $_ =~ s/<!--server-->/$ENV{'HTTP_HOST'}/g;  #replace webserver name
   41             $_ =~ s/<!--error-->/$error/g;  #replace the error message
   42             $_ =~ s/<!--version-->/$version/g;  #replace version number
   43             $_ =~ s/<!--(\w+)-->/&replace($1)/eg;   #replace the placeholders in the template
   44          $_ =~ s|</body>|<br><br>\n<div align="center"><font size="2">&copy; <a href="http://www.thedumbterminal.co.uk" target="_blank">Dumb Terminal Creations</a></font></div>\n</body>|;
   45             print;
   46         }
   47         close(TEMPLATE);
   48     }
   49     else{
   50         print << "(NO TEMPLATE)";
   51 <html>
   52     <body>
   53         Could not open HTML template: webmysql-$version/templates/$page.html
   54     </body>
   55 </html>
   56 (NO TEMPLATE)
   57     }
   58 }
   59 ###############################################################################################################
   60 sub parseFragmentToString{  #save a html fragment to a string
   61     my $page = shift;
   62     my $string = "<!-- Template: $page.html -->\n";
   63     if(open(TEMPLATE, "<templates/$page.html")){
   64         while(<TEMPLATE>){  #read the file a line at a time
   65             $_ =~ s/<!--self-->/$ENV{'SCRIPT_NAME'}/g;  #replace the name for this script
   66             $_ =~ s/<!--server-->/$ENV{'HTTP_HOST'}/g;  #replace webserver name
   67             $_ =~ s/<!--error-->/$error/g;  #replace the error message
   68             $_ =~ s/<!--version-->/$version/g;  #replace version number
   69             $_ =~ s/<!--(\w+)-->/&replace($1)/eg;   #replace the placeholders in the template
   70             $string .= $_
   71         }
   72         close(TEMPLATE);
   73     }
   74     else{$error = "Cant open HTML fragment: $page";}
   75     return $string;
   76 }
   77 ###############################################################################
   78 return 1;
   79 END {}
   80