<html><head><title>Manual munging for allocated blocks</title></head><body>
<?php
/* edit-alloc.php
** Quick hack to allow manual editing of data in postgres:ipdb:allocations table
** 07/13/2004 kdeugau@vianet
*/
//  include '../header.inc';

  print "<a href=manual.htm>Manual munging</a><br>\n";

  $dbh = pg_connect("dbname=ipdb user=ipdb password=ipdbpwd");

/* Since there are so many records in this table, we'll only display 50 at a time.
** We want to remember where we were without complex CGI variable-passing or other
** headaches, so we just stuff it in the db.  <g>
*/

  if (!isset($ofs)) {
    $qu = pg_exec($dbh, "select * from temp");
    if (pg_NumRows($qu) == 0) {
      print "Using default limit";
      $ofs = 0;
    } else {
      $data = pg_fetch_array($qu, 0);
      $ofs = $data[0];
      print "Limit $ofs found";
    }
  } else {
    print "Passed limit $ofs in CGI<br>\n";
    $qu = pg_exec("delete from temp");
    $qu = pg_exec("insert into temp values ($ofs)");
  }

?>
<table>
<form action="add-alloc.php" method=POST>
<tr><td>CIDR route:</td><td><input name=cidr></td></tr>
<tr><td>CustID:</td><td><input name=custid></td></tr>
<td>Alloc type:</td><td><input name=alloctype value=cn></td></tr>
<td>City:</td><td><input name=city></td></tr>
<td>Description:</td><td><input name=desc></td></tr>
<td>Notes:</td><td><input name=notes></td></tr>
<tr><td colspan=2><input type=submit value="Add entry"></td></tr>
</form>
</table>

<?
  $qu = pg_exec($dbh, "select count(*) from allocations");
  $data = pg_fetch_array($qu,0);
  $nrows = $data[0];

  $ofnum = (integer) ($nrows / 50);
  for ($i=0; $i<=$ofnum; $i++) {
    print '<a href="edit-alloc.php?ofs='. ($i*50) .'">'."$i</a> - ";
  }
?>

<table border=1 cellspacing=2>
<tr><td>CIDR allocation</td><td>CustID</td><td>Alloc type</td><td>City</td><td>Description</td><td>Notes</td></tr>
<?
  $qu = pg_exec($dbh, "select * from allocations order by cidr limit 50 offset $ofs");

  $row = 0;
  for ($row=0; $row < pg_NumRows($qu); $row++) {
    $data = pg_fetch_array($qu, $row);
    print "<form action=upd-alloc.php method=POST>".
	"<tr><td>$data[0]<input type=hidden name=cidr value='$data[0]'></td>".
	"<td><input name=custid value='$data[1]' size=15></td>".
	"<td><input name=alloctype value='$data[2]' size=5></td>".
	"<td><input name=city value='$data[3]'></td>".
	"<td><input name=desc value='$data[4]'></td>".
	"<td><input name=notes value='$data[5]'></td>".
	"<td><input type=submit value='Update'></td></tr></form>\n";
  }
?>
</table>
<?
//  include '../footer.inc';
?>
</body></html>
