--- /dev/null
+#include <infocon.style>
+#include "hwdb.inc"
+
+<page func=InfoCon title="Hardware Database">
+
+<h3>Component Detail</h3>
+
+<?
+<dbconnect>
+
+ if ($id) {
+ $fields = array ('component.id',
+ 'component.name',
+ 'serno',
+ 'price',
+ 'hwtype',
+ 'types.name as type',
+ 'owner as orgid',
+ 'organisation.name as owner',
+ 'starttime', 'endtime',
+ 'status',
+ 'component.comment'
+ );
+ $query = sprintf ("SELECT %s "
+ ."FROM component,types,organisation "
+ ."WHERE hwtype = types.id "
+ ."AND organisation.id = component.owner "
+ ."AND component.id = %d", implode (",", $fields), $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 ("<br>Name: <a href=\"edit_component.php3?id=%d\">%s</a>", $row['id'], $row['name']);
+ printf ("<br>Type: <a href=\"components.php3?type=%d\">%s</a>", $row['hwtype'], $row['type']);
+ printf ("<br>S/N: %s", $row['serno']);
+ if ($row['price'] > 0) {
+ printf ("<br>Price: %s", $row['price']);
+ } else {
+ printf ("<br>Price: n/a");
+ }
+ printf ("<br>Owner: <a href=\"organisation.php3?id=%d\">%s</a>", $row['orgid'], $row['owner']);
+ $start = explode (" ", $row['starttime']);
+ printf ("<br>Begin: %s", $start[0]);
+ if ($row['endtime']) {
+ $end = explode (" ", $row['endtime']);
+ printf ("<br>End: %s", $end[0]);
+ } else {
+ printf ("<br>End:");
+ }
+ printf ("<br>Status: %s", $row['status']);
+ 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 starttime,endtime,name "
+ ."FROM screw,compound "
+ ."WHERE component = %d AND compound = id "
+ ."ORDER BY starttime", $id);
+ $sth = pg_exec ($dbh, $query) or die_query("Cannot issue query!", $query);
+
+ if (pg_NumRows ($sth) > 0) {
+ echo "<h3>Use History</h3>\n";
+ }
+
+ for ($nr=0; $nr < pg_NumRows ($sth); $nr++) {
+ $row = pg_fetch_array ($sth, $nr);
+ $start = explode (" ", $row['starttime']);
+ if ($row['endtime']) {
+ $end = explode (" ", $row['endtime']);
+ } else {
+ $end = array ('today');
+ }
+ printf ("<br>%s - %s: %s", $start[0], $end[0], $row['name']);
+ }
+ }
+?>
+
+</page>
+
+# Local variables:
+# mode: text
+# mode: auto-fill
+# end:
--- /dev/null
+#include <infocon.style>
+#include "hwdb.inc"
+
+<page func=InfoCon title="Hardware Database">
+
+<h3>Available Components</h3>
+
+<?
+<dbconnect>
+
+ $query = "SELECT component.id,component.name,serno,types.name as type "
+ ."FROM component,types "
+ ."WHERE hwtype = types.id ";
+ if ($type) {
+ $query .= sprintf ("AND hwtype = %d ", $type);
+ }
+ $query .= "ORDER BY type,name";
+ $sth = pg_exec ($dbh, $query) or die_query("Cannot issue query!", $query);
+
+ for ($nr=0; $nr < pg_NumRows ($sth); $nr++) {
+ $row = pg_fetch_array ($sth, $nr);
+ printf ("<br>%s <a href=\"component.php3?id=%d\">%s</a> (%s) "
+ ."[<a href=\"edit_component.php3?id=%d\">Edit</a>]\n",
+ $row['type'], $row['id'], $row['name'], $row['serno'], $row['id']);
+ }
+?>
+
+</page>
+
+# Local variables:
+# mode: text
+# mode: auto-fill
+# end:
--- /dev/null
+#include <infocon.style>
+#include "hwdb.inc"
+
+<page func=InfoCon title="Hardware Database">
+
+<?
+<dbconnect>
+
+ if ($id) {
+ $query = sprintf ("SELECT *,organisation.name as organisation "
+ ."FROM compound,organisation "
+ ."WHERE location = organisation.id AND compound.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>Compound %s</h3>", $row['name']);
+ if ($row['hostname']) { printf ("<br>Hostname: %s", $row['hostname']); }
+ if ($row['ip']) { printf ("<br>IP Addr: %s", $row['ip']); }
+ if ($row['ident']) { printf ("<br>Ident: %s", $row['ident']); }
+ printf ("<br>Location: <a href=\"organisation.php3?id=%d\">%s</a>",
+ $row['location'], $row['organisation']);
+ printf ("<br>Status: %s", $row['status']);
+ 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 component.name,component,screw.starttime,types.name as type "
+ ."FROM screw,component,types "
+ ."WHERE compound = %d AND component = component.id "
+ ."AND screw.endtime IS NULL "
+ ."AND types.id = hwtype "
+ ."ORDER BY types.name,component.name,screw.starttime", $id);
+ $sth = pg_exec ($dbh, $query) or die_query("Cannot issue query!", $query);
+
+ if (pg_NumRows ($sth) > 0) {
+ echo "<h3>Components</h3>\n";
+ }
+
+ for ($nr=0; $nr < pg_NumRows ($sth); $nr++) {
+ $row = pg_fetch_array ($sth, $nr);
+ $start = explode (" ", $row['starttime']);
+ printf ("<br>%s <a href=\"component.php3?id=%d\">%s</a> since %s",
+ $row['type'], $row['component'], $row['name'], $start[0]);
+ }
+
+
+ }
+?>
+
+</page>
+
+# Local variables:
+# mode: text
+# mode: auto-fill
+# end:
--- /dev/null
+#include <infocon.style>
+#include "hwdb.inc"
+
+<page func=InfoCon title="Hardware Database">
+
+<h3>Available Compounds</h3>
+
+<?
+<dbconnect>
+
+ $query = "SELECT compound.id,compound.name,organisation.name as position "
+ ."FROM compound,organisation "
+ ."WHERE location = organisation.id "
+ ."ORDER BY name";
+ $sth = pg_exec ($dbh, $query) or die_query("Cannot issue query!", $query);
+
+ for ($nr=0; $nr < pg_NumRows ($sth); $nr++) {
+ $row = pg_fetch_array ($sth, $nr);
+ printf ("<br><a href=\"compound.php3?id=%d\">%s</a> (%s) "
+ ."[<a href=\"edit_compound.php3?id=%d\">Edit</a>]\n",
+ $row['id'], $row['name'], $row['position'], $row['id']);
+ }
+?>
+
+</page>
+
+# Local variables:
+# mode: text
+# mode: auto-fill
+# end:
--- /dev/null
+#include <infocon.style>
+#include "hwdb.inc"
+#include "form.inc"
+
+<page func=InfoCon title="Hardware Database">
+
+<?
+<dbconnect>
+
+ if ($id) {
+ $query = sprintf ("SELECT * FROM component WHERE id = %d", $id);
+ $sth = pg_exec ($dbh, $query) or die("Cannot issue query!");
+
+ if (pg_NumRows ($sth) > 0) {
+ $row = pg_fetch_array ($sth, 0);
+ }
+ }
+?>
+
+<form method=post action=update.php3>
+<input type=hidden name=formtype value="component">
+<input type=hidden name=id value="<? echo $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 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']"
+ >
+<?
+ $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:
--- /dev/null
+#include <infocon.style>
+#include "hwdb.inc"
+#include "form.inc"
+
+<page func=InfoCon title="Hardware Database">
+
+<?
+<dbconnect>
+
+ if ($id) {
+ $query = sprintf ("SELECT * FROM compound WHERE id = %d", $id);
+ $sth = pg_exec ($dbh, $query) or die("Cannot issue query!");
+
+ if (pg_NumRows ($sth) > 0) {
+ $row = pg_fetch_array ($sth, 0);
+ }
+ }
+?>
+
+<form method=post action=update.php3>
+<input type=hidden name=formtype value="compound">
+<input type=hidden name=id value="<? echo $id; ?>">
+<center><table cellpadding=0 cellspacing=1>
+
+<row_input name=name
+ title="<b>Compound</b>"
+ value="<? echo $row['name']; ?>"
+ >
+<row_input name=hostname
+ title="<b>Hostname</b>"
+ value="<? echo $row['hostname']; ?>"
+ >
+<row_input name=ip
+ title="<b>IP</b>"
+ value="<? echo $row['ip']; ?>"
+ >
+<row_input name=ident
+ title="<b>Ident</b>"
+ value="<? echo $row['ident']; ?>"
+ >
+<?
+ $query = "SELECT id,name FROM organisation ORDER BY name";
+ $sth = pg_exec ($dbh, $query) or die_query("Cannot issue query!");
+ if (pg_NumRows ($sth) > 0) {
+ $row_select_keys = array();
+ $row_select_values = array();
+
+ 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=location
+ title="<b>Location</b>"
+ selected="$row['location']"
+ >
+<?
+ $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_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:
--- /dev/null
+#include <infocon.style>
+#include "hwdb.inc"
+#include "form.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("Cannot issue query!");
+
+ if (pg_NumRows ($sth) > 0) {
+ $row = pg_fetch_array ($sth, 0);
+ }
+ }
+?>
+
+<form method=post action=update.php3>
+<input type=hidden name=formtype value="organisation">
+<input type=hidden name=id value="<? echo $id; ?>">
+<center><table cellpadding=0 cellspacing=1>
+
+<row_input name=name
+ title="<b>Organisation</b>"
+ value="<? echo $row['name']; ?>"
+ >
+<row_input name=email
+ title="<b>E-Mail</b>"
+ value="<? echo $row['email']; ?>"
+ >
+<row_input name=phone
+ title="<b>Phone</b>"
+ value="<? echo $row['phone']; ?>"
+ >
+
+<row_textarea name=address
+ title="<b>Address</b>"
+ value="<? echo $row['address']; ?>"
+ rows=4
+ >
+<row_textarea name=comment
+ title="<b>Comment</b>"
+ value="<? echo $row['comment']; ?>"
+ rows=7
+ >
+
+
+<row_submit>
+
+</table></center></form>
+
+<p>Please add all additional phone and fax numbers to the address.</p>
+
+</page>
+
+# Local variables:
+# mode: text
+# mode: auto-fill
+# end:
--- /dev/null
+#include <infocon.style>
+#include "hwdb.inc"
+#include "form.inc"
+
+<page func=InfoCon title="Hardware Database">
+
+<?
+<dbconnect>
+
+ if ($id) {
+ $query = sprintf ("SELECT * FROM types WHERE id = %d", $id);
+ $sth = pg_exec ($dbh, $query) or die("Cannot issue query!");
+
+ if (pg_NumRows ($sth) > 0) {
+ $row = pg_fetch_array ($sth, 0);
+ }
+ }
+?>
+
+<form method=post action=update.php3>
+<input type=hidden name=formtype value="type">
+<input type=hidden name=id value="<? echo $id; ?>">
+<center><table cellpadding=0 cellspacing=1>
+
+<row_input name=name
+ title="<b>Type</b>"
+ value="<? echo $row['name']; ?>"
+ >
+
+<row_submit>
+
+</table></center></form>
+
+</page>
+
+# Local variables:
+# mode: text
+# mode: auto-fill
+# end:
--- /dev/null
+<define-tag dbconnect>
+ $dbh = pg_pconnect ("<dbhost>", "<dbport>", "<hwdbname>")
+ or die("Unable to connect to SQL server");
+</define-tag>
+
+<?
+ function die_query ($msg, $query)
+ {
+ printf ("<h3>Error! The following query caused a problem:</h3><pre>\n%s\n</pre>\n",
+ $query);
+ die ($msg);
+ }
+?>
--- /dev/null
+#include <infocon.style>
+#include "hwdb.inc"
+
+<page func=InfoCon title="Hardware Database">
+
+<h3>Available Compound Hardware</h3>
+
+<?
+<dbconnect>
+
+ $query = "SELECT id,name FROM compound ORDER BY name";
+ $sth = pg_exec ($dbh, $query) or die_query("Cannot issue query!", $query);
+
+ for ($nr=0; $nr < pg_NumRows ($sth); $nr++) {
+ $row = pg_fetch_array ($sth, $nr);
+ printf ("<br><a href=\"list_compound.php3?id=%d\">%s</a>\n", $row['id'], $row['name']);
+ }
+?>
+
+</page>
+
+# Local variables:
+# mode: text
+# mode: auto-fill
+# end:
--- /dev/null
+#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.php3?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.php3?id=%d\">%s</a> %s",
+ $row['id'], $row['name'], $row['status']);
+ }
+
+
+ }
+?>
+
+</page>
+
+# Local variables:
+# mode: text
+# mode: auto-fill
+# end:
--- /dev/null
+#include <infocon.style>
+#include "hwdb.inc"
+
+<page func=InfoCon title="Hardware Database">
+
+<h3>Registered Organisations</h3>
+
+<?
+<dbconnect>
+
+ $query = "SELECT id,name FROM organisation ORDER BY name";
+ $sth = pg_exec ($dbh, $query) or die_query("Cannot issue query!", $query);
+
+ for ($nr=0; $nr < pg_NumRows ($sth); $nr++) {
+ $row = pg_fetch_array ($sth, $nr);
+ printf ("<br><a href=\"organisation.php3?id=%d\">%s</a> "
+ ."[<a href=\"edit_organisation.php3?id=%d\">Edit</a>]\n",
+ $row['id'], $row['name'], $row['id']);
+ }
+?>
+
+</page>
+
+# Local variables:
+# mode: text
+# mode: auto-fill
+# end:
--- /dev/null
+CREATE TABLE types (
+ id SERIAL NOT NULL,
+ name TEXT NOT NULL DEFAULT ''
+);
+CREATE UNIQUE INDEX "types_id" on "types" using btree ( "id" );
+REVOKE ALL on "types" from PUBLIC;
+GRANT ALL on "types" to "www-data";
+GRANT ALL on "types" to "joey";
+REVOKE ALL on "types_id_seq" from PUBLIC;
+GRANT ALL on "types_id_seq" to "www-data";
+GRANT ALL on "types_id_seq" to "joey";
+
+
+CREATE TABLE organisation (
+ id SERIAL NOT NULL,
+ name TEXT NOT NULL DEFAULT '',
+ address TEXT NOT NULL DEFAULT '',
+ email TEXT NOT NULL DEFAULT '',
+ phone TEXT NOT NULL DEFAULT '',
+ comment TEXT NOT NULL DEFAULT ''
+);
+CREATE UNIQUE INDEX "organisation_id" on "organisation" using btree ( "id" );
+CREATE INDEX "organisation_name" on "organisation" using btree ( "name" );
+REVOKE ALL on "organisation" from PUBLIC;
+GRANT ALL on "organisation" to "www-data";
+GRANT ALL on "organisation" to "joey";
+REVOKE ALL on "organisation_id_seq" from PUBLIC;
+GRANT ALL on "organisation_id_seq" to "www-data";
+GRANT ALL on "organisation_id_seq" to "joey";
+
+
+CREATE TABLE component (
+ id SERIAL NOT NULL,
+ serno TEXT NOT NULL DEFAULT '',
+ name TEXT NOT NULL DEFAULT '',
+ price NUMERIC(10,2),
+ owner INT4 NOT NULL references organisation(id) on delete cascade,
+ hwtype INT4 NOT NULL references types(id) on delete cascade,
+ starttime timestamp with time zone DEFAULT '1980-01-01 00:00:00+01'::timestamp with time zone NOT NULL,
+ endtime timestamp with time zone DEFAULT NULL with time zone,
+ status CHAR(10) NOT NULL DEFAULT 'in use',
+ comment TEXT NOT NULL DEFAULT ''
+);
+CREATE UNIQUE INDEX "component_id" on "component" using btree ( "id" );
+CREATE UNIQUE INDEX "component_serno" on "component" using btree ( "serno" );
+CREATE UNIQUE INDEX "component_name" on "component" using btree ( "name" );
+REVOKE ALL on "component" from PUBLIC;
+GRANT ALL on "component" to "www-data";
+GRANT ALL on "component" to "joey";
+REVOKE ALL on "component_id_seq" from PUBLIC;
+GRANT ALL on "component_id_seq" to "www-data";
+GRANT ALL on "component_id_seq" to "joey";
+
+
+CREATE TABLE compound (
+ id SERIAL NOT NULL,
+ name TEXT NOT NULL DEFAULT '',
+ hostname TEXT NOT NULL DEFAULT '',
+ ip TEXT NOT NULL DEFAULT '',
+ ident TEXT NOT NULL DEFAULT '',
+ location INT4 NOT NULL references organisation(id) on delete cascade,
+ status CHAR(10) NOT NULL DEFAULT 'in use',
+ comment TEXT NOT NULL DEFAULT ''
+);
+CREATE UNIQUE INDEX "compound_id" on "compound" using btree ( "id" );
+CREATE UNIQUE INDEX "compound_name" on "compound" using btree ( "name" );
+REVOKE ALL on "compound" from PUBLIC;
+GRANT ALL on "compound" to "www-data";
+GRANT ALL on "compound" to "joey";
+REVOKE ALL on "compound_id_seq" from PUBLIC;
+GRANT ALL on "compound_id_seq" to "www-data";
+GRANT ALL on "compound_id_seq" to "joey";
+
+
+CREATE TABLE screw (
+ component INT4 NOT NULL references component(id) on delete cascade,
+ compound INT4 NOT NULL references compound(id) on delete cascade,
+ starttime timestamp with time zone DEFAULT '1980-01-01 00:00:00+01'::timestamp with time zone NOT NULL,
+ endtime timestamp with time zone DEFAULT NULL
+);
+CREATE INDEX "screw_component" on "screw" using btree ( "component" );
+CREATE INDEX "screw_compound" on "screw" using btree ( "compound" );
+REVOKE ALL on "screw" from PUBLIC;
+GRANT ALL on "screw" to "www-data";
+GRANT ALL on "screw" to "joey";
--- /dev/null
+<strong>Menu</strong><br>
+
+ <menu-item base=index text=Konto href=index.php3><br>
+
+<p><line height=2>
+
+<p><strong>List</strong><br>
+
+ <a href="organisations.php3">Organisations</a><br>
+ <a href="compounds.php3">Compounds</a><br>
+ <a href="components.php3">Components</a><br>
+ <a href="types.php3">Types</a><br>
+
+<p><line height=2>
+
+<p><strong>New</strong><br>
+
+ <a href="edit_organisation.php3">Organisation</a><br>
+ <a href="edit_compound.php3">Compound</a><br>
+ <a href="edit_component.php3">Component</a><br>
+ <a href="edit_type.php3">Type</a><br>
+
+<p><line height=2>
+
+#include "../functions.inc" prefix="../"
+
+# Local variables:
+# mode: indented-text
+# mode: auto-fill
+# mode: iso-accents
+# end:
--- /dev/null
+#include <infocon.style>
+#include "hwdb.inc"
+
+<page func=InfoCon title="Hardware Database">
+
+<h3>Available Types</h3>
+
+<?
+<dbconnect>
+
+ $query = "SELECT id,name FROM types ORDER BY name";
+ $sth = pg_exec ($dbh, $query) or die_query("Cannot issue query!", $query);
+
+ for ($nr=0; $nr < pg_NumRows ($sth); $nr++) {
+ $row = pg_fetch_array ($sth, $nr);
+ printf ("<br><a href=\"components.php3?type=%d\">%s</a> "
+ ."[<a href=\"edit_type.php3?id=%d\">Edit</a>]\n",
+ $row['id'], $row['name'], $row['id']);
+ }
+?>
+
+</page>
+
+# Local variables:
+# mode: text
+# mode: auto-fill
+# end:
--- /dev/null
+#include <infocon.style>
+#include "hwdb.inc"
+
+<page func=InfoCon title="Hardware Database">
+
+<?
+<dbconnect>
+
+ if ($formtype == "organisation") {
+ if ($id) {
+ $query = sprintf ("UPDATE organisation SET name='%s',address='%s',email='%s',phone='%s',comment='%s' "
+ ."WHERE id = %d",
+ addslashes ($name),
+ addslashes ($address),
+ addslashes ($email),
+ addslashes ($phone),
+ addslashes ($comment),
+ $id);
+ } else {
+ $query = sprintf ("INSERT INTO organisation (name,address,email,phone,comment) "
+ ."VALUES ('%s','%s','%s','%s','%s')",
+ addslashes ($name),
+ addslashes ($address),
+ addslashes ($email),
+ addslashes ($phone),
+ addslashes ($comment));
+ }
+ $sth = pg_exec ($dbh, $query) or die_query("Cannot update the database!", $query);
+ } elseif ($formtype == "compound") {
+ if ($id) {
+ $query = sprintf ("UPDATE compound SET name='%s',hostname='%s',ip='%s',ident='%s',"
+ ."location=%d,status='%s',comment='%s' "
+ ."WHERE id = %d",
+ addslashes ($name),
+ addslashes ($hostname),
+ addslashes ($ip),
+ addslashes ($ident),
+ $location,
+ addslashes ($status),
+ addslashes ($comment),
+ $id);
+ } else {
+ $query = sprintf ("INSERT INTO compound (name,hostname,ip,ident,location,status,comment) "
+ ."VALUES ('%s','%s','%s','%s',%d,'%s','%s')",
+ addslashes ($name),
+ addslashes ($hostname),
+ addslashes ($ip),
+ addslashes ($ident),
+ $location,
+ addslashes ($status),
+ addslashes ($comment));
+ }
+ $sth = pg_exec ($dbh, $query) or die_query("Cannot update the database!", $query);
+ } elseif ($formtype == "component") {
+ if ($endtime == '') {
+ $endtime = 'NULL';
+ } else {
+ $endtime = "'".addslashes($endtime)."'";
+ }
+ if ($id) {
+ $query = sprintf ("UPDATE component SET name='%s',serno='%s',starttime='%s',endtime=%s,"
+ ."owner=%d,hwtype=%d,price=%s,status='%s',comment='%s' "
+ ."WHERE id = %d",
+ addslashes ($name),
+ addslashes ($serno),
+ addslashes ($starttime),
+ $endtime,
+ $owner,
+ $hwtype,
+ addslashes ($price),
+ addslashes ($status),
+ addslashes ($comment),
+ $id);
+ $sth = pg_exec ($dbh, $query) or die_query("Cannot update the database!", $query);
+ } else {
+ $query = sprintf ("INSERT INTO component (name,serno,starttime,endtime,owner,hwtype,price,status,comment) "
+ ."VALUES ('%s','%s','%s',%s,%d,%d,%s,'%s','%s')",
+ addslashes ($name),
+ addslashes ($serno),
+ addslashes ($starttime),
+ $endtime,
+ $owner,
+ $hwtype,
+ addslashes ($price),
+ addslashes ($status),
+ addslashes ($comment));
+ $sth = pg_exec ($dbh, $query) or die_query("Cannot update the database!", $query);
+ if ($compound != 0) {
+ $query = sprintf ("SELECT id FROM component WHERE oid = %d", pg_getlastoid ($sth));
+ if (pg_NumRows ($sth) > 0) {
+ $row = pg_fetch_array ($sth, 0);
+ $id = $row['id'];
+ } else {
+ $id = 0;
+ }
+ }
+ }
+
+ if ($compound != 0) {
+ $query = sprintf ("SELECT oid,compound FROM screw "
+ ."WHERE component = %d AND endtime is NULL "
+ ."ORDER BY starttime DESC LIMIT 1", $id);
+ $sth = pg_exec ($dbh, $query) or die_query("Cannot issue query!");
+ if (pg_NumRows ($sth) > 0) {
+ $row = pg_fetch_array ($sth, 0);
+ if ($row['compound'] != $compound) {
+ $query = sprintf ("UPDATE screw SET endtime = now() WHERE oid = %d", $row['oid']);
+ $sth = pg_exec ($dbh, $query) or die_query("Cannot update component history!");
+
+ $query = sprintf ("INSERT INTO screw (component,compound,starttime) "
+ ."VALUES (%d,%d,now())", $id, $compound);
+ $sth = pg_exec ($dbh, $query) or die_query("Cannot update component history!");
+ }
+ } else {
+ $query = sprintf ("INSERT INTO screw (component,compound,starttime) "
+ ."VALUES (%d,%d,now())", $id, $compound);
+ $sth = pg_exec ($dbh, $query) or die_query("Cannot update component history!");
+ }
+
+ }
+ } elseif ($formtype == "type") {
+ if ($id) {
+ $query = sprintf ("UPDATE types SET name='%s' WHERE id = %d",
+ addslashes ($name),
+ $id);
+ } else {
+ $query = sprintf ("INSERT INTO types (name) VALUES ('%s')",
+ addslashes ($name));
+ }
+ $sth = pg_exec ($dbh, $query) or die_query("Cannot update the database!", $query);
+ }
+
+ if ($error == "") {
+ echo "<h3>Successfully updated.</h3>";
+ } else {
+ printf ("<h3>Not successfully updated.</h3>\n%s", $error);
+ }
+?>
+
+</page>
+
+# Local variables:
+# mode: text
+# mode: auto-fill
+# end: