Changeset 517 for trunk/cgi-bin/newcity.cgi
- Timestamp:
- 10/18/12 16:53:10 (12 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
-
Property svn:mergeinfo
set to
/branches/htmlform merged eligible
-
Property svn:mergeinfo
set to
-
trunk/cgi-bin/newcity.cgi
r431 r517 13 13 use warnings; 14 14 #use CGI::Carp qw(fatalsToBrowser); 15 use CGI::Simple; 16 use HTML::Template; 15 17 use DBI; 16 use CommonWeb qw(:ALL);17 18 #use POSIX qw(ceil); 18 19 use NetAddr::IP; … … 35 36 } 36 37 37 my %webvar = parse_post(); 38 cleanInput(\%webvar); 38 # Set up the CGI object... 39 my $q = new CGI::Simple; 40 # ... and get query-string params as well as POST params if necessary 41 $q->parse_query_string; 42 43 # Convenience; saves changing all references to %webvar 44 ##fixme: tweak for handling <select multiple='y' size=3> (list with multiple selection) 45 my %webvar = $q->Vars; 39 46 40 47 my ($dbh,$errstr) = connectDB_My; 41 48 my $sth; 42 49 50 $ENV{HTML_TEMPLATE_ROOT} = '../templates'; 51 52 my $page = HTML::Template->new(filename => "newcity.tmpl"); 53 54 if ($webvar{city}) { 55 if ($webvar{pop} eq 'on') { 56 $sth = $dbh->prepare("insert into cities (city,routing) values (?,'y')"); 57 } else { 58 $sth = $dbh->prepare("insert into cities (city,routing) values (?,'n')"); 59 } 60 ##fixme: don't allow duplicate cities 61 $sth->execute($webvar{city}); 62 $page->param(city => $webvar{city}); 63 if ($sth->err) { 64 $page->param(err => $sth->errstr); 65 my $msg = "$authuser could not add city '$webvar{city}' to database: ".$sth->errstr; 66 mailNotify($dbh, 'f:nci', "IPDB city add failure", $msg); 67 syslog "err", $msg; 68 } else { 69 syslog "notice", "$authuser added city/location '$webvar{pop}'". 70 (($webvar{pop} eq 'on') ? ' as POP location' : ''); 71 } 72 } 73 43 74 print "Content-type: text/html\n\n"; 44 75 45 if ($webvar{pop} eq 'on') { 46 $sth = $dbh->prepare("insert into cities (city,routing) values ('$webvar{city}','y')"); 47 } else { 48 $sth = $dbh->prepare("insert into cities (city,routing) values ('$webvar{city}','n')"); 49 } 50 $sth->execute; 51 52 if ($sth->err) { 53 print "Error adding city to database: ".$sth->errstr; 54 mailNotify($dbh, 'f:nci', "IPDB city add failure", 55 "$authuser could not add city '$webvar{city}' to database: ".$sth->errstr); 56 syslog "err", "$authuser could not add city '$webvar{city}' to database: ".$sth->errstr; 57 } else { 58 print "City added. Closing this window should refresh the page."; 59 syslog "notice", "$authuser added city/location '$webvar{pop}'". 60 (($webvar{pop} eq 'on') ? ' as POP location' : ''); 61 } 76 print $page->output; 62 77 63 78 finish($dbh); 79
Note:
See TracChangeset
for help on using the changeset viewer.