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

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

<?
<dbconnect>

  if ($id) {
    $query = sprintf ("SELECT * FROM organisation WHERE id = %d", $id);
    $sth = pg_exec ($dbh, $query) or die_query("Cannot issue query!", $query);

    if (pg_NumRows ($sth) > 0) {
      $row = pg_fetch_array ($sth, 0);

      printf ("<h3>%s</h3>", $row['name']);
      printf ("\n<blockquote>\n%s\n</blockquote>\n", ereg_replace ("\n", "<br>", $row['address']));

      if ($row['email']) { printf ("<br>E-Mail: %s", $row['email']); }
      if ($row['phone']) { printf ("<br>Phone: %s", $row['phone']); }
      if ($row['comment']) {
<protect>
      printf ("\n<blockquote>\n%s\n</blockquote>\n", ereg_replace ("\n\n", "<p>", $row['comment']));
</protect>
      }
    } else {
      echo "<h3>No id given!</h3>";
    }

    $query = sprintf ("SELECT id,name,status "
		     ."FROM component "
		     ."WHERE owner = %d "
		     ."ORDER BY name", $id);
    $sth = pg_exec ($dbh, $query) or die_query("Cannot issue query!", $query);

    if (pg_NumRows ($sth) > 0) {
      echo "<h3>Components owned</h3>\n";
    }

    for ($nr=0; $nr < pg_NumRows ($sth); $nr++) {
      $row = pg_fetch_array ($sth, $nr);
      printf ("<br><a href=\"component.php?id=%d\">%s</a> %s",
	      $row['id'], $row['name'], $row['status']);
    }

    $query = sprintf ("SELECT id,name,status "
		     ."FROM compound "
		     ."WHERE location = %d "
		     ."ORDER BY name", $id);
    $sth = pg_exec ($dbh, $query) or die_query("Cannot issue query!", $query);

    if (pg_NumRows ($sth) > 0) {
      echo "<h3>Compounds hosted</h3>\n";
    }

    for ($nr=0; $nr < pg_NumRows ($sth); $nr++) {
      $row = pg_fetch_array ($sth, $nr);
      printf ("<br><a href=\"compound.php?id=%d\">%s</a> %s",
	      $row['id'], $row['name'], $row['status']);
    }


  }
?>

</page>

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