

#!/usr/bin/perl -w use CGI qw(:standard -debug); use CGI::Carp qw(fatalsToBrowser); ########### Credits ################# # Script written by R. Todd Vandenbark ##################################### # -------------------------------------- # takes input from "../newOrg.html", # checks it and adds info to # list of Greek organizations # -------------------------------------- #----------- define variables ---------- my $form; # input form my $orgName; # organization name my $contfn; # contact first name my $contln; # contact last name my $cphone; # contact phone my $contem; # contact email my @errstr=""; # error string # --------- initialize error flags ---- $badOrg=0; $badfirst=0; $badlast=0; $badphone=0; $badem=0; $error=0; # --- Greek org file ---------- my $outfile = "../../org.txt"; # --- get and clean input ---- $form = "newOrg.html"; $orgName = param("orgName"); chomp $orgName; $orgName = &cleaninput($orgName); $contfn = param("contactFirstName"); chomp $contfn; $contfn = &cleaninput($contfn); $contln = param("contactLastName"); chomp $contln; $contln = &cleaninput($contln); $cphone = param("cphone"); chomp $cphone; $cphone = &cleaninput($cphone); $contem = param("contactEmail"); chomp $contem; $contem = &cleaninput($contem); # ----- check names ------- $badfirst = &ckname($contfn); $badlast = &ckname($contln); # ------ check phone ------- if ($cphone !~ /^\(?\d{3}[)-]? \d{3}[-]?\d{4}$/x) { $badphone=1; $error++; push (@errstr, "phone ");} # ------ check org --------- if ($orgName !~ /^[\w]+[ -]?\w*[ -]?\w*$/i) { $badOrg=1; $error++; push (@errstr, "org ");} # ------ check email ------ if ($contem !~ /^[\w.]+@\w[\w.-]+\w\.[A-Za-z]{2,4}$/) { $badem=1; $error++; push (@errstr, "email ");} # ----- process & output results ---- if (!$error) { &addinfo(); $title = "Add contact successful"; $subtitle = 'New contact information:'; $content = '
Organization: ' . $orgName . '
' .
'Contact: ' . $contfn . ' ' . $contln . '
' .
'email: ' . $contem . '
' .
'Phone: ' . $cphone . '
Please '. ''. ' go back and try again
'. "Invalid $errors
"; } &pgprint(); # ------------ subroutines used ----------- sub cleaninput { my $string = $_[0]; $string =~ s/<([^>]|\n)*>//g ; # strip HTML $string =~ s/^\s+// ; # strip leading spaces $string =~ s/\s+$// ; # strip trailing spaces return $string; } sub ckname { my $input = $_[0]; my $result=0; # returns bad/good name result if ($input !~ /^[\w]+[ -]?\w*$/i) { $result=1; $error++;} push (@errstr, $input); return $result; } sub addinfo { open (OUT, ">>$outfile") || die "Can't open $outfile: $!\n"; my $fullname = "$contfn $contln"; @tmpout = ($orgName,$fullname,$contem,$cphone); my $string = join (":", @tmpout); print (OUT "$string\n") || die "Can't append $string to $outfile: $!\n"; close OUT; } sub pgprint { $logo = '