Display the compound and usage as well, if the component is screwed
authorJoey Schulze <joey@infodrom.org>
Thu, 7 Oct 2004 09:05:56 +0000 (09:05 +0000)
committerJoey Schulze <joey@infodrom.org>
Thu, 7 Oct 2004 09:05:56 +0000 (09:05 +0000)
into something else.

src/InfoCon/hwdb/components.wml

index 9ea0e4b..bd02baf 100644 (file)
@@ -8,6 +8,22 @@
 <?
 <dbconnect>
 
+  function get_usage ($dbh, $component)
+  {
+    $query = sprintf ("SELECT compound,usage,name FROM screw,compound "
+                    ."WHERE compound = id AND component = %d AND endtime is NULL "
+                    ."ORDER BY starttime DESC LIMIT 1", $component);
+    $sth = pg_exec ($dbh, $query) or die_query("Cannot query for current usage!");
+    if (pg_NumRows ($sth) > 0) {
+      $row = pg_fetch_array ($sth, 0);
+      if ($row['usage']) {
+        return sprintf ("%s [%s]", $row['name'], $row['usage']);
+      } else {
+        return $row['name'];
+      }
+    }
+  }
+
    $query = "SELECT component.id,component.name,serno,types.name as type "
           ."FROM component,types "
           ."WHERE hwtype = types.id ";
 
    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) "
+     $use = get_usage ($dbh, $row['id']);
+
+     if ($use) {
+       if ($row['serno']) {
+         $usage = sprintf (" (%s, %s)", $row['serno'], $use);
+       } else {
+         $usage = sprintf (" (%s)", $use);
+       }
+     } else {
+       if ($row['serno']) {
+         $usage = sprintf (" (%s)", $row['serno']);
+       } else {
+         $usage = '';
+       }
+     }
+
+     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']);
+           $row['type'], $row['id'], $row['name'], $usage, $row['id']);
    }
 ?>