Display outdated (and removed) components as well, moving the display
authorJoey Schulze <joey@infodrom.org>
Thu, 7 Oct 2004 09:17:41 +0000 (09:17 +0000)
committerJoey Schulze <joey@infodrom.org>
Thu, 7 Oct 2004 09:17:41 +0000 (09:17 +0000)
routine into a function of its own.

src/InfoCon/hwdb/compound.wml

index c497010..eb9cd44 100644 (file)
@@ -6,6 +6,29 @@
 <?
 <dbconnect>
 
+  function display_components ($headline, $sth);
+  {
+    if (pg_NumRows ($sth) > 0) {
+      printf ("<h3>%s</h3>\n", $headline);
+    }
+
+    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']);
+       printf ("<br>%s <a href=\"component.php3?id=%d\">%s</a> %s &mdash; %s",
+               $row['type'], $row['component'], $row['name'], $start[0], $end[0]);
+      } else {
+       printf ("<br>%s <a href=\"component.php3?id=%d\">%s</a> since %s",
+               $row['type'], $row['component'], $row['name'], $start[0]);
+      }
+      if ($row['usage']) {
+        printf (" (%s)", $row['usage']);
+      }
+    }
+  }
+
   if ($id) {
     $fields = array ('compound.name',
                     'compound.hostname',
                     ."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);
+    display_components ("Components", $sth);
 
-    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']);
-      if ($row['endtime']) {
-        $end = explode (" ", $row['endtime']);
-       printf ("<br>%s <a href=\"component.php3?id=%d\">%s</a> %s &mdash; %s",
-               $row['type'], $row['component'], $row['name'], $start[0], $end[0]);
-      } else {
-       printf ("<br>%s <a href=\"component.php3?id=%d\">%s</a> since %s",
-               $row['type'], $row['component'], $row['name'], $start[0]);
-      }
-      if ($row['usage']) {
-        printf (" (%s)", $row['usage']);
-      }
-    }
-
-
+    $query = sprintf ("SELECT component.name,component,screw.starttime,screw.endtime,types.name as type,usage "
+                    ."FROM screw,component,types "
+                    ."WHERE compound = %d AND component = component.id "
+                    ."AND screw.endtime IS NOT 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);
+    display_components ("Outdated Components", $sth);
   }
 ?>