<?php
/* editcust.php
** Show customer data in form for editing.
*****
** SVN revision info
** $Date: 2010-05-11 18:56:06 +0000 (Tue, 11 May 2010) $
** SVN revision $Rev: 398 $
** Last update by $Author: kdeugau $
*****
** Copyright (C) 2006 - Kris Deugau
*/
?>
<html><head>
<title>[IPDB admin] Edit customer data for rWHOIS export</title>
</head>
<body>
<h2>Edit customer data for rWHOIS export</h2>
<a href="/ip/cgi-bin/admin.cgi">Back</a> to admin<br>
<a href="/ip/cgi-bin/list-cust.php">Back</a> to WHOIS customer list
<form action=updatecust.php method=post>
<?
  $db_conn = pg_connect("dbname=ipdb user=ipdb password=ipdbpwd host=ipdb-db");

  if (!$db_conn) {
    echo ("<H1>Failed connection to db ipdb.  Can't continue.</H1>");
    echo "db err: ". pg_last_error() ."\n";
    exit;
  }

// snag form data into local vars.  Not being excessively paranoid because we're
// buried deep and this is a hack anyway.
  $newcust = $_REQUEST['newcust'];
  $custid = $_REQUEST['custid'];

  if ($newcust==1) {
    echo "New customer.  Creating blank record in the database...\n";
    $qu = pg_exec ($db_conn, "INSERT INTO customers (custid) VALUES ('$custid')");
  }

  $qu = pg_exec ($db_conn, "SELECT * FROM customers WHERE custid='$custid'");
  if (!$qu) {
    echo "DB error - select on customers.  Save this page and tell Kris.<BR>";
  }

  $data = pg_fetch_array($qu, 0);

  echo "<table border=2 cellpadding=2>".
	"<tr><td align=right>CustID</td><td>$data[0]<input type=hidden name=custid value=$data[0]></td></tr>\n".
	"<tr><td>Name</td><td><input name=name value=\"$data[1]\"></td></tr>\n".
	"<tr><td>Street address</td><td><input name=addr1 value=\"$data[2]\"></td></tr>\n".
	"<tr><td>Address 2</td><td><input name=addr2 value=\"$data[3]\"></td></tr>\n".
	"<tr><td>City</td><td><input name=city value=\"$data[4]\"></td></tr>\n".
	"<tr><td>Province</td><td><input name=prov value=\"$data[5]\"></td></tr>\n".
	"<tr><td>Country</td><td><input name=country value=\"$data[6]\"></td></tr>\n".
	"<tr><td>Postal code</td><td><input name=pocode value=\"$data[7]\"></td></tr>\n".
	"<tr><td>Phone</td><td><input name=phone value=\"$data[8]\"></td></tr>\n".
	"<tr><td>Tech handle</td><td><input name=tech value=\"$data[9]\"></td></tr>\n".
	"<tr><td>Abuse handle</td><td><input name=abuse value=\"$data[10]\"></td></tr>\n".
	"<tr><td>Admin handle</td><td><input name=admin value=\"$data[11]\"></td></tr>\n".
	"<tr><td>Default rDNS</td><td><input name=rdns value=\"$data[12]\"></td></tr>\n".
	"<tr><td>\"Special\"</td><td><textarea name=special rows=4 cols=40>$data[13]</textarea></td></tr>\n".
	'<tr><td colspan=2 align=center><input type=submit value="Add/update customer data"></td></tr>'.
	"\n</table></form><br>\n";

?>
<h3>Explanation for "Special" field:</h3>
This is the field I've mangled into providing a custom WHOIS netname identifier for blocks tagged "SWIP".
It may be removed later.
<p>It's formatted like this, one line for each custom net name:
<pre>NetName[CIDR block]: NET-NAME</pre>
Example:
<pre>NetName209.91.133.0/24: CYBERSUDBURY-1</pre>
Note:
<li>Spacing is important - there should only be ONE space, in between the colon and the net name.
<li>The CIDR block name nust include all four octets - no short forms are accepted.
<li>Net names must be all uppercase, and consist only of A-Z, 0-9, and - (same as for SWIPed net names).
</body>
</html>
