Index: /branches/htmlform/cgi-bin/admin.cgi
===================================================================
--- /branches/htmlform/cgi-bin/admin.cgi	(revision 458)
+++ /branches/htmlform/cgi-bin/admin.cgi	(revision 459)
@@ -224,5 +224,5 @@
 $cities
 </select>
-&nbsp;<a href="javascript:popNotes('/ip/newcity.html')">Add new location</a>
+&nbsp;<a href="javascript:popNotes('/ip/cgi-bin/newcity.cgi')">Add new location</a>
 </td>
 </tr>
Index: /branches/htmlform/cgi-bin/newcity.cgi
===================================================================
--- /branches/htmlform/cgi-bin/newcity.cgi	(revision 458)
+++ /branches/htmlform/cgi-bin/newcity.cgi	(revision 459)
@@ -14,6 +14,7 @@
 #use CGI::Carp qw(fatalsToBrowser);
 use CGI::Simple;
+use HTML::Template;
 use DBI;
-use CommonWeb qw(:ALL);
+#use CommonWeb qw(:ALL);
 #use POSIX qw(ceil);
 use NetAddr::IP;
@@ -48,23 +49,32 @@
 my $sth;
 
+$ENV{HTML_TEMPLATE_ROOT} = '../templates';
+
+my $page = HTML::Template->new(filename => "newcity.tmpl");
+
+if ($webvar{city}) {
+  if ($webvar{pop} eq 'on') {
+    $sth = $dbh->prepare("insert into cities (city,routing) values (?,'y')");
+  } else {
+    $sth = $dbh->prepare("insert into cities (city,routing) values (?,'n')");
+  }
+##fixme:  don't allow duplicate cities
+  $sth->execute($webvar{city});
+  $page->param(city => $webvar{city});
+  if ($sth->err) {
+    $page->param(err => $sth->errstr);
+    my $msg = "$authuser could not add city '$webvar{city}' to database: ".$sth->errstr;
+    mailNotify($dbh, 'f:nci', "IPDB city add failure", $msg);
+    syslog "err", $msg;
+  } else {
+    syslog "notice", "$authuser added city/location '$webvar{pop}'".
+	(($webvar{pop} eq 'on') ? ' as POP location' : '');
+  }
+}
+
 print "Content-type: text/html\n\n";
 
-if ($webvar{pop} eq 'on') {
-  $sth = $dbh->prepare("insert into cities (city,routing) values ('$webvar{city}','y')");
-} else {
-  $sth = $dbh->prepare("insert into cities (city,routing) values ('$webvar{city}','n')");
-}
-$sth->execute;
-
-if ($sth->err) {
-  print "Error adding city to database: ".$sth->errstr;
-  mailNotify($dbh, 'f:nci', "IPDB city add failure",
-	"$authuser could not add city '$webvar{city}' to database: ".$sth->errstr);
-  syslog "err", "$authuser could not add city '$webvar{city}' to database: ".$sth->errstr;
-} else {
-  print "City added.  Closing this window should refresh the page.";
-  syslog "notice", "$authuser added city/location '$webvar{pop}'".
-	(($webvar{pop} eq 'on') ? ' as POP location' : '');
-}
+print $page->output;
 
 finish($dbh);
+
Index: /branches/htmlform/templates/assign.tmpl
===================================================================
--- /branches/htmlform/templates/assign.tmpl	(revision 458)
+++ /branches/htmlform/templates/assign.tmpl	(revision 459)
@@ -27,5 +27,5 @@
 	<option><TMPL_VAR NAME=city></option></TMPL_LOOP>
 </select>
-&nbsp;<a href="javascript:popNotes('/ip/newcity.html')">Add new location</a>
+&nbsp;<a href="javascript:popNotes('/ip/cgi-bin/newcity.cgi')">Add new location</a>
 </td>
 </tr>
Index: /branches/htmlform/templates/newcity.tmpl
===================================================================
--- /branches/htmlform/templates/newcity.tmpl	(revision 459)
+++ /branches/htmlform/templates/newcity.tmpl	(revision 459)
@@ -0,0 +1,31 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
+<html>
+<head>
+	<title>IP Database - Add new city</title>
+	<link rel="stylesheet" type="text/css" href="/ip/ipdb.css">
+	<link rel="stylesheet" type="text/css" href="/ip/local.css">
+	<script src="/ip/templates/widgets.js" type="text/javascript"></script>
+</head>
+
+<body onUnload="redoParent()">
+<TMPL_IF city>
+<div style="padding=3px;">
+<TMPL_IF err>
+Error adding city <TMPL_VAR NAME=city> to database: <TMPL_VAR NAME=err>
+<TMPL_ELSE>
+City <TMPL_VAR NAME=city> added.  Closing this window should refresh the page.
+</TMPL_IF>
+</div>
+<TMPL_ELSE>
+<form action="newcity.cgi" method="POST">
+<fieldset><legend></legend>
+<table>
+<tr class="color1"><td>Enter new city:</td><td><input name="city"></td></tr>
+<tr class="color2"><td>POP site?</td><td><input type=checkbox name="pop"></td></tr>
+<tr class="color1"><td colspan=2 align=center><input type=submit value="Add city"></td></tr>
+</table>
+</fieldset>
+</form>
+</TMPL_IF>
+</body>
+</html>
Index: /branches/htmlform/templates/widgets.js
===================================================================
--- /branches/htmlform/templates/widgets.js	(revision 458)
+++ /branches/htmlform/templates/widgets.js	(revision 459)
@@ -11,2 +11,5 @@
 	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");
 }
+function redoParent() {
+	opener.location.reload(true);
+}
