Index: trunk/ippMonitor/raw/czartool_labels.php
===================================================================
--- trunk/ippMonitor/raw/czartool_labels.php	(revision 28625)
+++ trunk/ippMonitor/raw/czartool_labels.php	(revision 28705)
@@ -3,10 +3,13 @@
 include 'site.php';
 
-$ID = checkID ();
+$ID = checkID();
 
 // require an explicit project
 if (! $ID['proj']) { projectform ($ID); }
 
-$db = dbconnect($ID['proj']);
+//$db = dbconnect($ID['proj']);
+$czardb = dbconnect("czardb"); // HACK to connect to czarDb 
+$gpc1db = dbconnect($ID['proj']);
+
 $PATH = getenv("PATH");
 putenv("PATH=$BINDIR:$PATH");
@@ -17,5 +20,5 @@
 
 if ($ID['menu']) {$myMenu = $ID['menu'];}
-else {$myMenu = "ipp.czartool.dat";}
+else {$myMenu = "ipp.imfiles.dat";}
 
 menu($myMenu, 'Czartool', 'ipp.css', $ID['link'], $ID['proj']);
@@ -35,10 +38,11 @@
 
 if ($revertStage != "" && $revertMode != "" && $revertServer != "" )
-    exec("czartool_revert.pl -s $revertServer -t $revertStage -o $revertMode", $revertOnOff, $status);
+exec("czartool_revert.pl -s $revertServer -t $revertStage -o $revertMode", $revertOnOff, $status);
 
 $debug = 0;
 
-exec("czartool_getLabels.pl -s stdscience", $stdsLabels, $status);
-exec("czartool_getLabels.pl -s distribution", $distLabels, $status);
+$stdsLabels = getLabels($czardb, "stdscience");
+$distLabels = getLabels($czardb, "distribution");
+$pubLabels = getLabels($czardb, "publishing");
 
 if ($debug) {
@@ -50,5 +54,17 @@
 
 $states=array("full","new","drop","wait");
-$stages=array("chip","camera","fake","warp","stack","diff","magic","destreak","dist");
+$stages=array("chip","cam","fake","warp","stack","diff","magic","magicDS","dist");
+$servers=array(
+        "addstar",
+        "cleanup",
+        "detrend",
+        "distribution",
+        "pstamp",
+        "update",
+        "publishing",
+        "registration",
+        "replication",
+        "stdscience",
+        "summitcopy");
 
 // set up the form
@@ -59,15 +75,25 @@
 echo "<input type=\"hidden\" name=\"menu\" value=\"$menu\">\n";
 echo "</form>\n";
-$stateChosen = 0;
-foreach ($states as &$state) {
-
-    if ($userSelection == $state) {
-        showAllLabels($pass, $proj, $db, $stdsLabels, $distLabels, $stages, $states, $state);
-        $stateChosen=1;
-        break;
-    }
-}
-
-if (!$stateChosen) showOneLabel($pass, $proj, $db, $userSelection, $stages, $states);
+$lastUpdateTime = getLastUpdateTime($czardb);
+echo "<p  align=\"center\"> Current status of pantasks servers and stdscience labels (any faults are shown in parentheses)<br>";
+echo "NOTE: This data is good as of: $lastUpdateTime </p>";
+
+createLabelsTable($pass, $proj, $czardb, $stdsLabels, $distLabels, $pubLabels, $stages, $states, "new");
+
+echo "<table>\n";
+echo "<tr>\n";
+echo "<td style=\"width: 50%;\">\n";
+
+$today = date("Y-m-d");                         // 03.10.01
+showSummitData($gpc1db, $today);
+
+echo "</td>\n";
+echo "<td> \n";
+
+createServersTable($pass, $proj,$czardb, $servers);
+
+echo "</td?\n";
+echo "</tr>\n";
+echo "</table>\n";
 
 menu_end();
@@ -76,10 +102,245 @@
 ###########################################################################
 #
-# Checks one label and prints results in a table
-#
-###########################################################################
-function showOneLabel($pass, $proj, $db, $label, $stages, $states) {
-
-    echo "<p> Current status for label '$label' (any faults are shown in parentheses) </p>";
+# Checks summitExp table agains rawExp table 
+#
+###########################################################################
+function showSummitData($gpc1db, $date) {
+
+    echo "<p> Status of summit data since $date:</p>";
+
+
+    $sql = "SELECT DISTINCT exp_type FROM summitExp WHERE dateobs > '$date'";
+
+    $qry = $gpc1db->query($sql);
+    if (dberror($qry)) {
+        echo "<b>error reading newExp table</b><br>\n";
+        echo "<br><small><b> table query : $sql </b></small><br>\n";
+        menu_end();
+    }
+
+    // set up the table
+    echo "<table class=list>\n";
+    echo "<tr><td></td>\n";
+    write_header_cell ("list", "Exposure type");
+    write_header_cell ("list", "At summit");
+    write_header_cell ("list", "Registered at MHPCC");
+
+    $msg = "No science images taken since $date";
+
+    // list the results
+    while ($qry->fetchInto($expType)) {
+
+        $sql = "SELECT COUNT(*) FROM summitExp WHERE dateobs > '$date' AND exp_type = '$expType[0]'";
+        $qry2 = $gpc1db->query($sql);
+        $qry2->fetchInto($summit);
+        $sql = "SELECT COUNT(*) FROM summitExp JOIN rawExp ON summitExp.exp_name = rawExp.exp_name WHERE summitExp.dateobs > '$date' AND summitExp.exp_type = '$expType[0]'";
+        $qry2 = $gpc1db->query($sql);
+        $qry2->fetchInto($mhpcc);
+
+        $class = "list";
+        echo "<tr><td></td>\n";
+
+        if ($expType[0] == "OBJECT") {
+            if ($summit[0] == $mhpcc[0]) $msg = "All science exposures taken since $date have been registered at MHPCC";
+            else $msg = "Warning: Not all science exposures taken since $date have been registered at MHPCC";
+        }
+
+        write_table_cell ($class, '%s', "", $expType[0]);
+        write_table_cell ($class, '%d', "", $summit[0]);
+        write_table_cell ($class, '%d', $link, $mhpcc[0]);
+        echo "</tr>\n";
+    }
+
+    echo "</table>\n";
+
+    echo "<p> $msg </p>";
+
+}
+
+###########################################################################
+#
+# Gets labels for this server
+#
+###########################################################################
+function getLabels($db, $server) {
+
+    $sql = "SELECT label FROM current_labels WHERE server LIKE '$server'";
+    if ($debug) {echo "$sql<br>";}
+
+    $qry = $db->query($sql);
+    if (dberror($qry)) {echo "<b>error with $sql </b><br>\n";}
+    while ($qry->fetchInto($row)) {
+
+        $labels[] = $row[0];
+    }
+
+    return $labels;
+}
+
+###########################################################################
+#
+# Creates table for all labels showing all stages for given 'state'
+#
+###########################################################################
+function createLabelsTable($pass, $proj, $db, $stdsLabels, $distLabels, $pubLabels, $stages, $states, $selectedState) {
+
+    // set up table columns
+    $class = "list";
+    echo "<table class=$class >\n";
+    echo "<tr><td></td>\n";
+
+    write_header_cell($class, "");
+    write_header_cell($class, "");
+    write_header_cell($class, "Reverts:");
+    foreach ($stages as &$stage) {
+
+        $revertOnOff=array();
+        if ($stage == "destreak" or $stage == "dist") $server = "distribution";
+        else $server = "stdscience";
+        $reverting = getRevertStatus($db, $stage);
+        $link = "czartool_labels.php?pass=" . $pass . "&proj=" . $proj . "&server=" . $server . "&stage=" . $stage . "&revert=";
+        if(!$reverting) {$label =  "Start";$link = $link . "on";}
+        if($reverting) {$label = "Stop";$link = $link . "off";}
+        unset($reverting);
+        write_table_cell($class, '%s', $link, $label);
+    }
+
+    echo "</tr>\n";
+    echo "<tr><td></td>\n";
+    write_header_cell($class, "label");
+    write_header_cell($class, "distributing?");
+    write_header_cell($class, "publishing?");
+    foreach ($stages as &$stage) write_header_cell($class, $stage);
+
+    echo "</tr>\n";
+    echo "<tr><td></td>\n";
+
+    // write rows
+    foreach ($stdsLabels as &$stdsLabel) {
+
+        $distributing = false;
+        $publishing = false;
+        foreach ($distLabels as &$distLabel) {
+
+            if ($stdsLabel == $distLabel) { $distributing = true; break;}
+        }
+        foreach ($pubLabels as &$pubLabel) {
+
+            if ($stdsLabel == $pubLabel) { $publishing = true; break;}
+        }
+
+        // create link to label summary page for each label
+        //$link = "czartool_labels.php?pass=" . $pass . "&proj=" . $proj . "&selection=" . $stdsLabel;
+        $link = "";
+        $defaultlink = "czartool_labels.php?pass=" . $pass . "&proj=" . $proj;
+
+        echo "<tr><td></td>\n";
+        write_table_cell($class, '%s', $link, $stdsLabel);
+        write_table_cell($class, '%s', "", $distributing ? "yes" : "NO");
+        write_table_cell($class, '%s', "", $publishing ? "yes" : "NO");
+
+        $str = "";
+        $anyFaults = false; 
+
+        $link = "chipProcessedImfile_failure.php?pass=" . $pass . "&proj=" . $proj . "&chipRun.label=" . $stdsLabel . "&chipRun.state=new";
+        getStateAndFaults($db, $stdsLabel, $selectedState, "chip", $str, $anyFaults);
+        write_table_cell($class, '%s', $anyFaults ? $link : "", $str);
+
+        $link = "camProcessedExp_failure.php?pass=" . $pass . "&proj=" . $proj . "&camRun.label=" . $stdsLabel . "&camRun.state=new";
+        getStateAndFaults($db, $stdsLabel, $selectedState, "cam", $str, $anyFaults);
+        write_table_cell($class, '%s',  $anyFaults ? $link : "", $str);
+
+        $link = $defaultlink;
+        getStateAndFaults($db, $stdsLabel, $selectedState, "fake", $str, $anyFaults);
+        write_table_cell($class, '%s',  $anyFaults ? $link : "", $str);
+
+        $link = "warpFailedSkyfiles.php?pass=" . $pass . "&proj=" . $proj . "&warpRun.label=" . $stdsLabel . "&warpRun.state=new";
+        getStateAndFaults($db, $stdsLabel, $selectedState, "warp", $str, $anyFaults);
+        write_table_cell($class, '%s',  $anyFaults ? $link : "",  $str);
+
+        $link = "stackFailedSkyfile.php?pass=" . $pass . "&proj=" . $proj . "&stackRun.label=" . $stdsLabel . "&stackRun.state=new";
+        getStateAndFaults($db, $stdsLabel, $selectedState, "stack", $str, $anyFaults);
+        write_table_cell($class, '%s',  $anyFaults ? $link : "", $str);
+
+        $link = "diffFailedSkyfile.php?pass=" . $pass . "&proj=" . $proj . "&diffRun.label=" . $stdsLabel . "&diffRun.state=new";
+        getStateAndFaults($db, $stdsLabel, $selectedState, "diff", $str, $anyFaults);
+        write_table_cell($class, '%s',  $anyFaults ? $link : "",  $str);
+
+        $link = $defaultlink;
+        getStateAndFaults($db, $stdsLabel, $selectedState, "magic", $str, $anyFaults);
+        write_table_cell($class, '%s',  $anyFaults ? $link : "", $str);
+
+        $link = $defaultlink;
+        getStateAndFaults($db, $stdsLabel, $selectedState, "magicDS", $str, $anyFaults);
+        write_table_cell($class, '%s',  $anyFaults ? $link : "", $str);
+
+        $link = $defaultlink;
+        getStateAndFaults($db, $stdsLabel, $selectedState, "dist", $str, $anyFaults);
+        write_table_cell($class, '%s',  $anyFaults ? $link : "", $str);
+
+        echo "</tr>\n";
+    }
+
+    echo "</tr>\n";
+    echo "</table>\n";
+
+    echo "<p> - Click on a fault to find logfile<br>";
+    echo "- Click on column header to turn reverts on or off </p>";
+}
+
+###########################################################################
+#
+# Returns whether this stage is reverting or not
+#
+###########################################################################
+function getRevertStatus($db, $stage) {
+
+    $anyFaults = false;
+    $sql = "SELECT reverting FROM $stage ORDER BY timestamp DESC LIMIT 1";
+    if ($debug) {echo "$sql<br>";}
+
+    $qry = $db->query($sql);
+    if (dberror($qry)) {echo "<b>error with $sql </b><br>\n";}
+    $qry->fetchInto($row);
+
+    return $row[0];
+}
+
+###########################################################################
+#
+# Returns state and fault-count (if new) as a string
+#
+###########################################################################
+function getStateAndFaults($db, $label, $state, $stage, &$str, &$anyFaults) {
+
+    $anyFaults = false;
+    $sql = "SELECT pending, faults FROM $stage WHERE label LIKE '$label' ORDER BY timestamp DESC LIMIT 1";
+    if ($debug) {echo "$sql<br>";}
+
+    $qry = $db->query($sql);
+    if (dberror($qry)) {echo "<b>error with $sql </b><br>\n";}
+    $qry->fetchInto($row);
+
+    $pending = $row[0];
+    $faults = $row[1];
+
+    $str = "$pending";
+
+    if ($state == "new") {
+
+        if ($faults > 0) {
+
+            $str = $str."(".$faults.")";
+            $anyFaults = true;
+        }
+    }
+}
+
+###########################################################################
+#
+# Checks the status of all the pantasks servers 
+#
+###########################################################################
+function createServersTable($pass, $proj, $db, $servers) {
 
     // set up table columns
@@ -87,167 +348,24 @@
     echo "<table class=$class>\n";
     echo "<tr><td></td>\n";
-    write_header_cell($class, "state");
-    foreach ($stages as &$stage) {write_header_cell($class, $stage);}
+    write_header_cell($class, "Server");
+    write_header_cell($class, "Alive?");
+    write_header_cell($class, "Scheduler running?");
     echo "</tr>\n";
 
-    // write rows
-    foreach ($states as &$state) {
-
-        $link = "czartool_labels.php?pass=" . $pass . "&proj=" . $proj . "&selection=" . $state;
-        $defaultlink = "czartool_labels.php?pass=" . $pass . "&proj=" . $proj;
+    foreach ($servers as &$server) {
+
+        //$link = "czartool_servers.php?pass=" . $pass . "&proj=" . $proj . "&server=" . $server;
+        $link = "";
+
+        getServerStatus($db, $server, $alive, $running);
 
         echo "<tr><td></td>\n";
-        write_table_cell($class, '%s', $link, $state);
-
-        $str = "";
-        $anyFaults = false; 
-        $link = "chipProcessedImfile_failure.php?pass=" . $pass . "&proj=" . $proj . "&chipRun.label=" . $label . "&chipRun.state=new";
-        getStateAndFaults($db, $label,"chipRun", $state, "chip", $str, $anyFaults);
-        write_table_cell($class, '%s', $anyFaults ? $link : "", $str);
-
-        $link = "camProcessedExp_failure.php?pass=" . $pass . "&proj=" . $proj . "&camRun.label=" . $label . "&camRun.state=new";
-        getStateAndFaults($db, $label,"camRun", $state, "cam", $str, $anyFaults);
-        write_table_cell($class, '%s',  $anyFaults ? $link : "", $str);
-
-        $link = $defaultlink;
-        getStateAndFaults($db, $label,"fakeRun", $state, "fake", $str, $anyFaults);
-        write_table_cell($class, '%s',  $anyFaults ? $link : "", $str);
-
-        $link = "warpFailedSkyfiles.php?pass=" . $pass . "&proj=" . $proj . "&warpRun.label=" . $label . "&warpRun.state=new";
-        getStateAndFaults($db, $label,"warpRun", $state, "warp", $str, $anyFaults);
-        write_table_cell($class, '%s',  $anyFaults ? $link : "",  $str);
-
-        $link = "stackFailedSkyfile.php?pass=" . $pass . "&proj=" . $proj . "&stackRun.label=" . $label . "&stackRun.state=new";
-        getStateAndFaults($db, $label,"stackRun", $state, "stack", $str, $anyFaults);
-        write_table_cell($class, '%s',  $anyFaults ? $link : "", $str);
-
-        $link = "diffFailedSkyfile.php?pass=" . $pass . "&proj=" . $proj . "&diffRun.label=" . $label . "&diffRun.state=new";
-        getStateAndFaults($db, $label,"diffRun", $state, "diff", $str, $anyFaults);
-        write_table_cell($class, '%s',  $anyFaults ? $link : "",  $str);
-
-        $link = $defaultlink;
-        getStateAndFaults($db, $label,"magicRun", $state, "magic", $str, $anyFaults);
-        write_table_cell($class, '%s',  $anyFaults ? $link : "", $str);
-
-        $link = $defaultlink;
-        getStateAndFaults($db, $label,"magicDSRun", $state, "magicDS", $str, $anyFaults);
-        write_table_cell($class, '%s',  $anyFaults ? $link : "", $str);
-
-        $link = $defaultlink;
-        getStateAndFaults($db, $label,"distRun", $state, "dist", $str, $anyFaults);
-        write_table_cell($class, '%s',  $anyFaults ? $link : "", $str);
-
+        write_table_cell($class, '%s', $link, $server);
+        write_table_cell($class, '%s', "", $alive ? "yes" : "NO");
+        write_table_cell($class, '%s', "", $running ? "yes" : "NO");
         echo "</tr>\n";
     }
 
     echo "</table>\n";
-
-    echo "<p> - Click on a state to see all labels for that state <br>";
-    echo "- Click on a fault to find logfile </p>";
-}
-
-###########################################################################
-#
-# Creates table for all labels showing all stages for given 'state'
-#
-###########################################################################
-function showAllLabels($pass, $proj, $db, $stdsLabels, $distLabels, $stages, $states, $selectedState) {
-
-    echo "<p> Current stdscience labels for '$selectedState' (any faults are shown in parentheses)</p>";
-
-    // set up table columns
-    $class = "list";
-    echo "<table class=$class >\n";
-    echo "<tr><td></td>\n";
-
-    write_header_cell($class, "");
-    write_header_cell($class, "");
-    foreach ($stages as &$stage) {
-
-        $revertOnOff=array();
-        if ($stage == "destreak" or $stage == "dist") $server = "distribution";
-        else $server = "stdscience";
-        exec("czartool_revert.pl -s $server -t $stage", $revertOnOff, $status);
-        $link = "czartool_labels.php?pass=" . $pass . "&proj=" . $proj . "&server=" . $server . "&stage=" . $stage . "&revert=";
-        if($revertOnOff[0] == "off") {$label =  "Start reverts";$link = $link . "on";}
-        if($revertOnOff[0] == "on") {$label = "Stop reverts";$link = $link . "off";}
-        unset($revertOnOff);
-        write_table_cell($class, '%s', $link, $label);
-    }
-
-    echo "</tr>\n";
-    echo "<tr><td></td>\n";
-    write_header_cell($class, "label");
-    write_header_cell($class, "distributing?");
-    foreach ($stages as &$stage) write_header_cell($class, $stage);
-
-    echo "</tr>\n";
-    echo "<tr><td></td>\n";
-
-    // write rows
-    foreach ($stdsLabels as &$stdsLabel) {
-
-        $distributing = false;
-        foreach ($distLabels as &$distLabel) {
-
-            if ($stdsLabel == $distLabel) { $distributing = true; break;}
-        }
-
-        // create link to label summary page for each label
-        $link = "czartool_labels.php?pass=" . $pass . "&proj=" . $proj . "&selection=" . $stdsLabel;
-        $defaultlink = "czartool_labels.php?pass=" . $pass . "&proj=" . $proj;
-
-        echo "<tr><td></td>\n";
-        write_table_cell($class, '%s', $link, $stdsLabel);
-        write_table_cell($class, '%s', "", $distributing ? "yes" : "NO");
-
-        $str = "";
-        $anyFaults = false; 
-
-        $link = "chipProcessedImfile_failure.php?pass=" . $pass . "&proj=" . $proj . "&chipRun.label=" . $stdsLabel . "&chipRun.state=new";
-        getStateAndFaults($db, $stdsLabel,"chipRun", $selectedState, "chip", $str, $anyFaults);
-        write_table_cell($class, '%s', $anyFaults ? $link : "", $str);
-
-        $link = "camProcessedExp_failure.php?pass=" . $pass . "&proj=" . $proj . "&camRun.label=" . $stdsLabel . "&camRun.state=new";
-        getStateAndFaults($db, $stdsLabel,"camRun", $selectedState, "cam", $str, $anyFaults);
-        write_table_cell($class, '%s',  $anyFaults ? $link : "", $str);
-
-        $link = $defaultlink;
-        getStateAndFaults($db, $stdsLabel,"fakeRun", $selectedState, "fake", $str, $anyFaults);
-        write_table_cell($class, '%s',  $anyFaults ? $link : "", $str);
-
-        $link = "warpFailedSkyfiles.php?pass=" . $pass . "&proj=" . $proj . "&warpRun.label=" . $stdsLabel . "&warpRun.state=new";
-        getStateAndFaults($db, $stdsLabel,"warpRun", $selectedState, "warp", $str, $anyFaults);
-        write_table_cell($class, '%s',  $anyFaults ? $link : "",  $str);
-
-        $link = "stackFailedSkyfile.php?pass=" . $pass . "&proj=" . $proj . "&stackRun.label=" . $stdsLabel . "&stackRun.state=new";
-        getStateAndFaults($db, $stdsLabel,"stackRun", $selectedState, "stack", $str, $anyFaults);
-        write_table_cell($class, '%s',  $anyFaults ? $link : "", $str);
-
-        $link = "diffFailedSkyfile.php?pass=" . $pass . "&proj=" . $proj . "&diffRun.label=" . $stdsLabel . "&diffRun.state=new";
-        getStateAndFaults($db, $stdsLabel,"diffRun", $selectedState, "diff", $str, $anyFaults);
-        write_table_cell($class, '%s',  $anyFaults ? $link : "",  $str);
-
-        $link = $defaultlink;
-        getStateAndFaults($db, $stdsLabel,"magicRun", $selectedState, "magic", $str, $anyFaults);
-        write_table_cell($class, '%s',  $anyFaults ? $link : "", $str);
-
-        $link = $defaultlink;
-        getStateAndFaults($db, $stdsLabel,"magicDSRun", $selectedState, "magicDS", $str, $anyFaults);
-        write_table_cell($class, '%s',  $anyFaults ? $link : "", $str);
-
-        $link = $defaultlink;
-        getStateAndFaults($db, $stdsLabel,"distRun", $selectedState, "dist", $str, $anyFaults);
-        write_table_cell($class, '%s',  $anyFaults ? $link : "", $str);
-
-        echo "</tr>\n";
-    }
-
-    echo "</tr>\n";
-    echo "</table>\n";
-
-    echo "<p> - Click on a label to see all states for that label (full, new, drop etc)<br>";
-    echo "- Click on a fault to find logfile<br>";
-    echo "- Click on column header to turn reverts on or off </p>";
 }
 
@@ -257,69 +375,37 @@
 #
 ###########################################################################
-function getStateAndFaults($db, $label, $table, $state, $stage, &$str, &$anyFaults) {
-
-    $anyFaults = false;
-
-    $str = checkLabel($db, $label, $table, $state, $stage);
-
-    if ($state == "new") {
-
-        $faults = countFaults($db, $label,$table,$stage);
-
-        if ($faults > 0) {
-
-            $str = $str."(".$faults.")";
-            $anyFaults = true;
-        }
-    }
-}
-
-###########################################################################
-#
-# Returns count of exposures with this state for this label
-#
-###########################################################################
-function checkLabel($db, $label, $table, $state, $stage) {
-
-    $sql = "SELECT COUNT(state) FROM $table WHERE label LIKE '$label' AND state = '$state'";
-    if ($debug) {echo "$sql<br>";}
+function getServerStatus($db, $server, &$alive, &$running) {
+
+    $sql = "SELECT alive, running FROM servers WHERE server LIKE '$server' ORDER BY timestamp DESC LIMIT 1";
+    if($debug){echo "$sql<br>";}
 
     $qry = $db->query($sql);
     if (dberror($qry)) {echo "<b>error with $sql </b><br>\n";}
-    if (!$qry->fetchInto($row)) {echo "<b>error with $sql </b><br>\n";}
-    return $row[0];
-}
-
-###########################################################################
-#
-# Returns count of faults for this stage and label
-#
-###########################################################################
-function countFaults($db, $label, $table, $stage) {
-
-    $joinTable = 0;
-    $id = $stage."_id";
-
-    if ($stage == "chip") {$joinTable="chipProcessedImfile";}
-    elseif ($stage == "cam") {$joinTable="camProcessedExp";}
-    elseif ($stage == "fake") {$joinTable="fakeProcessedImfile";}
-    elseif ($stage == "warp") {$joinTable="warpSkyfile";}
-    elseif ($stage == "stack") {$joinTable="stackSumSkyfile";}
-    elseif ($stage == "diff") {$joinTable="diffSkyfile";}
-    elseif ($stage == "magic") {$joinTable="magicNodeResult";}
-    elseif ($stage == "magicDS") {$id = "magic_ds_id"; $joinTable="magicDSFile";}
-    elseif ($stage == "dist") {$joinTable="distComponent";}
-    else {return -1;}
-
-    $faultCol =  $joinTable.".fault";
-
-    $sql = "SELECT COUNT(DISTINCT $id) FROM $table JOIN $joinTable USING ($id) WHERE label LIKE '$label' AND $faultCol != 0 AND $table.state = 'new'";
+    $qry->fetchInto($row);
+
+    $alive = $row[0];
+    $running = $row[1];
+}
+
+###########################################################################
+#
+# Returns time of last czarDb update 
+#
+###########################################################################
+function getLastUpdateTime($db) {
+
+    $anyFaults = false;
+    $sql = "SELECT timestamp FROM chip ORDER BY timestamp DESC LIMIT 1";
     if ($debug) {echo "$sql<br>";}
 
     $qry = $db->query($sql);
     if (dberror($qry)) {echo "<b>error with $sql </b><br>\n";}
-    if (!$qry->fetchInto($row)) {echo "<b>error with $sql </b><br>\n";}
+    $qry->fetchInto($row);
+
     return $row[0];
 }
+
+
+
 ?>
 
