#!/usr/bin/perl -w package Net4Base; use 5.004; use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $Version ); use strict; # Restrict unsafe variables, references, barewords use Carp; use Net4Constants; use CGI; @ISA = qw(Exporter); @EXPORT = qw(); @EXPORT_OK = qw(1); %EXPORT_TAGS = (all => [@EXPORT_OK]); ####################################################################### # GetTextFile # # This subroutine will retrieve a text file from disk and return it ####################################################################### sub GetTextFile { my ($filename) = @_; my (@text, $text); open(FH, "<$filename") or return ("no") ; if (wantarray) { @text = ; chomp @text; } else { local $/ = undef; $text = ; } close FH; return wantarray ? @text : $text; } sub LogError { my($err_msg) = @_; my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time()); $mon++; #open (FH, ">>$Error_File") || print "CAN'T OPEN $Error_File\n"; #print FH "$ENV{'REMOTE_HOST'} - [$mon/$mday/$year:$hour:$min:$sec - $ENV{'SCRIPT_FILENAME'} - $ENV{'HTTP_USER_AGENT'} - $err_msg $CallingFile $LineNumber\n"; #close(FH); return 1; } sub PrintInTemplate { my ($html) = @_; my $obj=CGI->new(); print $obj->header(); print $html; } sub Exit { $ENV{"MOD_PERL"} ? Apache->exit : exit 0; return 1; } ######################################################### # Replace Tag and create new one # sub replaceTagsforTableReports { my ($FH,$i,%myin) = @_; my $text = $FH; foreach (keys %myin) { if($i eq "last") { $text =~ s/\Q##$_##\E/$myin{$_}/; } else { $text =~ s/\Q##$_##\E/$myin{$_}##$_##/; } } return $text; } #END replaceTagsforTableReports ####################################################################### # ReplaceTags # sub ReplaceTags { my ($FH, %myin) = @_; my $text = $FH; foreach (keys %myin) { if (/DROP_DOWN/) { if (! defined $_) { next; } $text =~ s/value\=\"$myin{$_}\"/selected value\=\"$myin{$_}\"/; } elsif (/RADIO_CHOICE/) { if (! defined $myin{$_}) { next; } $text =~ s/value\=\"$myin{$_}\"/checked value\=\"$myin{$_}\"/; } elsif (/CHECK_BOX/) { if (! defined $myin{$_}) { next; } $text =~ s/name\=\"$myin{$_}\"/checked name\=\"$myin{$_}\"/; } else { $text =~ s/\Q##$_##\E/$myin{$_}/g; } } return $text; } #END ReplaceTags #*********************************************** # To make the values as a row on html and alter the back ground color of row. sub renderTableInAlternateRows { my @elements = @_; my $color = shift(@elements); my $row = "" : " '#999999' > " ; my $start = ""; my $end = ""; map { $row .= "$start $_ $end"; } @elements; $row .= ""; return $row; } #*********************************************** # To make the values as a header on html sub makeTableHeader { my @elements = @_; my $header = ""; my $start = " "; my $end = ""; map { $header .= "$start $_ $end"; } @elements; $header .= ""; return $header; } sub IsEmailAddressValid { (($_[0] =~ /[^\w.+@-]/) || ($_[0] =~ /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/) || ($_[0] !~ /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/) ) ? return 0 : return 1; } __END__