<?php
/* list-cust.php
** List customer data in customers table, and allow editing, adding.  Delete
** is sort of a null action and might Break Things.
*****
** SVN revision info
** $Date: 2010-02-19 17:59:27 +0000 (Fri, 19 Feb 2010) $
** SVN revision $Rev: 393 $
** Last update by $Author: kdeugau $
*****
** Copyright (C) 2006 - Kris Deugau
*/
?>
<html><head>
<title>[IPDB admin] Customer data for rWHOIS export</title>
</head>
<body>
<h2>Customer data for rWHOIS export</h2>
<a href="/ip/cgi-bin/admin.cgi">Back</a> to admin
<p><li>Click the CustID to edit information
<li>Enter information below to add a new entry - it's best if this is done **BEFORE** flipping the "SWIP" option
on the netblock.
<form action=editcust.php method=POST>
CustID:<input name=custid>
<input type=submit value="Go to edit page for new customer">
<input type=hidden name=newcust value=1>
</form>
<?
  $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;
  }

  $qu = pg_exec ($db_conn, "SELECT * FROM customers order by custid");

  if (!$qu) {
    echo "DB error - select on customers.  Save this page and tell Kris.<BR>";
  }

  print "<br>".pg_NumRows($qu)." customers.\n";

  echo "<table border=2 cellpadding=2>";
  echo "<tr><td width=150>CustID<br>(Click to update)</td>".
       "<td>Name</td>".
       "<td>Street address</td>".
       "<td>Address 2<br>(if needed)</td>".
       "<td>City</td>".
       "<td>Province</td>".
       "<td>Country</td>".
       "<td>Postal code</td>".
       "<td>Phone</td>".
       "<td>Tech handle</td>".
       "<td>Abuse handle</td>".
       "<td>Admin handle</td>".
       "<td>Default rDNS<br>(not used)</td>".
       "<td>\"Special\"</td></tr>\n";

  $row = 0;
  for ($row=0; $row < pg_NumRows($qu); $row++) {
    $data = pg_fetch_array($qu, $row);
    echo '<tr><td><a href="editcust.php?custid='.$data[0].'&newcust=0">'.$data[0]."</a> &nbsp; ".
	'<a href="updatecust.php?custid='.$data[0].'&deletecust=1">(delete)</a></td>'.
	"<td>$data[1]</td>".
	"<td>$data[2]</td>".
	"<td>$data[3]</td>".
	"<td>$data[4]</td>".
	"<td>$data[5]</td>".
	"<td>$data[6]</td>".
	"<td>$data[7]</td>".
	"<td>$data[8]</td>".
	"<td>$data[9]</td>".
	"<td>$data[10]</td>".
	"<td>$data[11]</td>".
	"<td>$data[12]</td>".
	"<td>$data[13]</td></tr>\n";
  }
  echo "</table><br>\n";

?>
</body>
</html>
