Changeset 459 for branches/htmlform


Ignore:
Timestamp:
08/04/10 16:08:41 (14 years ago)
Author:
Kris Deugau
Message:

/branches/htmlform

Convert "new city" miniscript and page to template, move the "reload
parent" JavaScript fragment into widgets.js. See #3.
Update calls from assign.tmpl and admin.cgi to point to newcity.cgi.

Location:
branches/htmlform
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • branches/htmlform/cgi-bin/admin.cgi

    r449 r459  
    224224$cities
    225225</select>
    226 &nbsp;<a href="javascript:popNotes('/ip/newcity.html')">Add new location</a>
     226&nbsp;<a href="javascript:popNotes('/ip/cgi-bin/newcity.cgi')">Add new location</a>
    227227</td>
    228228</tr>
  • branches/htmlform/cgi-bin/newcity.cgi

    r447 r459  
    1414#use CGI::Carp qw(fatalsToBrowser);
    1515use CGI::Simple;
     16use HTML::Template;
    1617use DBI;
    17 use CommonWeb qw(:ALL);
     18#use CommonWeb qw(:ALL);
    1819#use POSIX qw(ceil);
    1920use NetAddr::IP;
     
    4849my $sth;
    4950
     51$ENV{HTML_TEMPLATE_ROOT} = '../templates';
     52
     53my $page = HTML::Template->new(filename => "newcity.tmpl");
     54
     55if ($webvar{city}) {
     56  if ($webvar{pop} eq 'on') {
     57    $sth = $dbh->prepare("insert into cities (city,routing) values (?,'y')");
     58  } else {
     59    $sth = $dbh->prepare("insert into cities (city,routing) values (?,'n')");
     60  }
     61##fixme:  don't allow duplicate cities
     62  $sth->execute($webvar{city});
     63  $page->param(city => $webvar{city});
     64  if ($sth->err) {
     65    $page->param(err => $sth->errstr);
     66    my $msg = "$authuser could not add city '$webvar{city}' to database: ".$sth->errstr;
     67    mailNotify($dbh, 'f:nci', "IPDB city add failure", $msg);
     68    syslog "err", $msg;
     69  } else {
     70    syslog "notice", "$authuser added city/location '$webvar{pop}'".
     71        (($webvar{pop} eq 'on') ? ' as POP location' : '');
     72  }
     73}
     74
    5075print "Content-type: text/html\n\n";
    5176
    52 if ($webvar{pop} eq 'on') {
    53   $sth = $dbh->prepare("insert into cities (city,routing) values ('$webvar{city}','y')");
    54 } else {
    55   $sth = $dbh->prepare("insert into cities (city,routing) values ('$webvar{city}','n')");
    56 }
    57 $sth->execute;
    58 
    59 if ($sth->err) {
    60   print "Error adding city to database: ".$sth->errstr;
    61   mailNotify($dbh, 'f:nci', "IPDB city add failure",
    62         "$authuser could not add city '$webvar{city}' to database: ".$sth->errstr);
    63   syslog "err", "$authuser could not add city '$webvar{city}' to database: ".$sth->errstr;
    64 } else {
    65   print "City added.  Closing this window should refresh the page.";
    66   syslog "notice", "$authuser added city/location '$webvar{pop}'".
    67         (($webvar{pop} eq 'on') ? ' as POP location' : '');
    68 }
     77print $page->output;
    6978
    7079finish($dbh);
     80
  • branches/htmlform/templates/assign.tmpl

    r458 r459  
    2727        <option><TMPL_VAR NAME=city></option></TMPL_LOOP>
    2828</select>
    29 &nbsp;<a href="javascript:popNotes('/ip/newcity.html')">Add new location</a>
     29&nbsp;<a href="javascript:popNotes('/ip/cgi-bin/newcity.cgi')">Add new location</a>
    3030</td>
    3131</tr>
  • branches/htmlform/templates/widgets.js

    r451 r459  
    1111        window.open(page, "IPDB_notes", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=400,height=300");
    1212}
     13function redoParent() {
     14        opener.location.reload(true);
     15}
Note: See TracChangeset for help on using the changeset viewer.