#include <infocon.style>
#include "hwdb.inc"
#include "form.inc"

<page func=InfoCon title="Hardware Database">

<?
<dbconnect>

  if ($_GET[id]) {
    $query = sprintf ("SELECT * FROM component WHERE id = %d", $_GET[id]);
    $sth = pg_exec ($dbh, $query) or die("Cannot issue query!");

    if (pg_NumRows ($sth) > 0) {
      $row = pg_fetch_array ($sth, 0);
      $foo = explode (" ", $row['starttime']);
      $row['starttime'] = $foo[0];
      # list($row['starttime']) = explode (" ", $row['starttime']);
      if ($row['endtime']) {
        $foo = explode (" ", $row['endtime']);
        $row['endtime'] = $foo[0];
        # list($row['endtime']) = explode (" ", $row['endtime']);
      }
    }
  }
?>

<form method=post action=update.php>
<input type=hidden name=formtype value="component">
<input type=hidden name=id value="<? echo $_GET[id]; ?>">
<center><table cellpadding=0 cellspacing=1>

<row_input	name=name
		title="<b>Component</b>"
		value="<? echo $row['name']; ?>"
		>
<row_input	name=serno
		title="<b>S/N</b>"
		value="<? echo $row['serno']; ?>"
		>
<row_input	name=price
		title="<b>Price</b>"
		value="<? echo $row['price']; ?>"
		>
<?
    $query = "SELECT id,name FROM types ORDER BY name";
    $sth = pg_exec ($dbh, $query) or die_query("Cannot issue query!");
    $row_select_keys = array();
    $row_select_values = array();
    if (pg_NumRows ($sth) > 0) {
	for ($nr=0; $nr < pg_NumRows ($sth); $nr++) {
	    $srow = pg_fetch_array ($sth, $nr);
	    $row_select_keys[] = $srow['id'];
	    $row_select_values[] = $srow['name'];
	}
    }
?>
<row_select	name=hwtype
		title="<b>Type</b>"
		selected="$row['hwtype']"
		>
<?
    $query = "SELECT id,name FROM compound ORDER BY name";
    $sth = pg_exec ($dbh, $query) or die_query("Cannot issue query!");
    $row_select_keys = array(0);
    $row_select_values = array('none');
    if (pg_NumRows ($sth) > 0) {
	for ($nr=0; $nr < pg_NumRows ($sth); $nr++) {
	    $srow = pg_fetch_array ($sth, $nr);
	    $row_select_keys[] = $srow['id'];
	    $row_select_values[] = $srow['name'];
	}
    }
    $query = sprintf ("SELECT compound,usage FROM screw "
		     ."WHERE component = %d AND endtime is NULL "
		     ."ORDER BY starttime DESC LIMIT 1", $row['id']);
    $sth = pg_exec ($dbh, $query) or die_query("Cannot issue query!");
    if (pg_NumRows ($sth) > 0) {
      $srow = pg_fetch_array ($sth, 0);
    } else {
      $srow['compound'] = 0;
    }

?>
<row_select	name=compound
		title="<b>Compound</b>"
		selected="$srow['compound']"
		>
<row_input	name=usage
		title="<b>Usage</b>"
		value="<? echo $srow['usage']; ?>"
		>
<?
    $query = "SELECT id,name FROM organisation ORDER BY name";
    $sth = pg_exec ($dbh, $query) or die_query("Cannot issue query!");
    $row_select_keys = array();
    $row_select_values = array();
    if (pg_NumRows ($sth) > 0) {
	for ($nr=0; $nr < pg_NumRows ($sth); $nr++) {
	    $srow = pg_fetch_array ($sth, $nr);
	    $row_select_keys[] = $srow['id'];
	    $row_select_values[] = $srow['name'];
	}
    }
?>
<row_select	name=owner
		title="<b>Owner</b>"
		selected="$row['owner']"
		>
<?
  $row_select_keys = array('in use','defunct','unused');
  $row_select_values = array('in use','defunct','unused');
?>
<row_select	name=status
		title="<b>Status</b>"
		selected="$row['status']"
		>
<row_input	name=starttime
		title="<b>Start time</b>"
		value="<? echo $row['starttime']; ?>"
		>
<row_input	name=endtime
		title="<b>End time</b>"
		value="<? echo $row['endtime']; ?>"
		>
<row_textarea	name=comment
		title="<b>Comment</b>"
		value="<? echo $row['comment']; ?>"
		rows=7
		>


<row_submit>

</table></center></form>

</page>

# Local variables:
# mode: text
# mode: auto-fill
# end:
