#!/usr/bin/perl use Msql; require "/usr/httpd/support/cgi-lib.pl"; &ReadParse(); unless ($dbh = Msql->Connect("", "itvs")) { die; } unless (defined($VALUES{"id"})) { $id = &getid; } else { $id = $VALUES{"id"}; $query1 = "DELETE FROM hbg WHERE id=$id"; unless ($check = $dbh->Query($query1)) { print "Content-type: text/html\n\n Delete Failed:

$query1 \n"; exit; } } foreach $name (keys(%VALUES)) { $VALUES{$name} = &sanitize($VALUES{$name}); } require "timelocal.pl"; if ($VALUES{'eventposteddate'} =~ /(\d+)\/(\d+)\/(\d+)/) { ($month, $mday, $year) = ($1, $2, $3); $newpostdate = &timelocal(0,0,0,$mday,($month-1),$year); } else { $newpostdate = $^T; } if ($VALUES{'eventdate'} =~ /(\d+)\/(\d+)\/(\d+)/) { ($month, $mday, $year) = ($1, $2, $3); $neweventdate = &timelocal(0,0,0,$mday,($month-1),$year); } else { $neweventdate = 0; } # $ENV{"MINERA_DEBUG"} = "query:api"; $query = ("INSERT into hbg (region, citystate, eventdate, postdate, title, organization, description, contact, address, phone, fax, email, id) VALUES ('$VALUES{'eventarea'}', '$VALUES{'eventcity'}', $neweventdate, $newpostdate, '$VALUES{'eventtitle'}', '$VALUES{'eventorganization'}', '$VALUES{'eventdescription'}', '$VALUES{'eventcontact'}', '$VALUES{'eventaddress'}', '$VALUES{'eventphone'}', '$VALUES{'eventfax'}', '$VALUES{'eventemail'}', $id)"); unless ($check = $dbh->Query($query)) { print "Content-type: text/html\n\n Failed:

$query \n"; exit; } #print "Content-type: text/html\n\nSuccess: $query\n"; if ($VALUES{'FLAG'} eq "admin") { print "Location: http://www.itvs.org/programs/babyg/adminevents.cgi\n\n"; } else { print "Location: http://www.itvs.org/programs/babyg/eventframe.html\n\n"; } exit; sub getid { $idfile = "/u6/itvs/programs/babyg/eventnumber"; local($oldid); &lockfile("$idfile.lock"); open(IDNO, "$idfile"); $oldid = ; close(IDNO); $oldid++; open(IDNO, ">$idfile"); print(IDNO "$oldid\n"); close(IDNO); &unlockfile("$idfile.lock"); return($oldid); } ################################################################ # LOCKFILE # use flock to lock a file against other writers # from for flock $LOCK_EX = 2; sub lockfile { local($file) = $_[0]; flock($file, $LOCK_EX); } ################################################################ # UNLOCKFILE # use flock to unlock a file previously locked against other writers # from for flock $LOCK_UN = 8; sub unlockfile { local($file) = $_[0]; flock($file, $LOCK_UN); } ################################################################ # fixnewlines # changes multi-platform newline characters into one single-line string. sub fixnewlines { local ($t) = $_[0]; $* = 1; # multi-line string matching $t =~ s/\r\n/\n/g; # \r and \n are unix-specific $t =~ tr/\r/\n/s; $t =~ s/\n/ /g; return ($t); } ################################################################ # keepnewlines # translates newline characters into
's sub keepnewlines { local ($t) = $_[0]; $* = 1; # multi-line string matching $t =~ s/\r\n/\n/g; # \r and \n are unix-specific $t =~ tr/\r/\n/s; $t =~ s/\n/
/g; return ($t); } ################################################################ # sanitize # changes html markup into escape characters and guards against # other special characters sub sanitize { local ($it) = $_[0]; $it =~ s/\&/\&\;/g; $it =~ s//\>\;/g; $it =~ s/\"/\"\;/g; $it =~ tr/\'/\xA7/; return ($it); }