Ignore:
Timestamp:
05/14/13 18:10:22 (11 years ago)
Author:
Kris Deugau
Message:

/branches/stable

Merge /trunk r517 (merge /branches/htmlform)
Conflicts all resolved towards /trunk.
Fix a minor syntax error with "while (@data..." -> "while (my @data..."
(may cause merge conflicts later)

Location:
branches/stable
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/stable

  • branches/stable/cgi-bin/newcity.cgi

    r445 r593  
    1313use warnings;
    1414#use CGI::Carp qw(fatalsToBrowser);
     15use CGI::Simple;
     16use HTML::Template;
    1517use DBI;
    16 use CommonWeb qw(:ALL);
    1718#use POSIX qw(ceil);
    1819use NetAddr::IP;
     
    3536}
    3637
    37 my %webvar = parse_post();
    38 cleanInput(\%webvar);
     38# Set up the CGI object...
     39my $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)
     45my %webvar = $q->Vars;
    3946
    4047my ($dbh,$errstr) = connectDB_My;
    4148my $sth;
    4249
     50$ENV{HTML_TEMPLATE_ROOT} = '../templates';
     51
     52my $page = HTML::Template->new(filename => "newcity.tmpl");
     53
     54if ($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
    4374print "Content-type: text/html\n\n";
    4475
    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 }
     76print $page->output;
    6277
    6378finish($dbh);
     79
Note: See TracChangeset for help on using the changeset viewer.