Index: /trunk/ippMonitor/raw/czartool_labels.php
===================================================================
--- /trunk/ippMonitor/raw/czartool_labels.php	(revision 41177)
+++ /trunk/ippMonitor/raw/czartool_labels.php	(revision 41178)
@@ -626,4 +626,220 @@
         echo "</tr>";
     }
+
+
+    #-----------------------------------------
+    #list bad quality cam exposures
+    if ($badcamflag != 0) {
+
+        // set up another table
+        global $table;
+        echo $table;
+        echo "<tr>";
+        createTableTitle("Bad quality camRun exposures", 6);
+        echo "<tr>";
+        createTableColumnHeader("exp_name");
+        createTableColumnHeader("cam_id");
+        createTableColumnHeader("quality");
+        createTableColumnHeader("sigma_ra");
+        createTableColumnHeader("sigma_dec");
+        createTableColumnHeader("comment");
+
+         #query the bad cam exposures
+        $query = "SELECT exp_name,cam_id, camProcessedExp.quality, camProcessedExp.sigma_ra, camProcessedExp.sigma_dec, comment";
+        $query .= " FROM rawExp";
+        $query .= " JOIN chipRun USING (exp_id)";
+        $query .= " JOIN camRun USING (chip_id)";
+        $query .= " JOIN camProcessedExp USING (cam_id)";
+        $query .= " WHERE dateobs LIKE '$date%'";
+        $query .= " AND exp_id > $refExpID[0]"; 
+        $query .= " AND exp_type = 'OBJECT'";
+        $query .= " AND (obs_mode LIKE '%SS%' OR obs_mode LIKE '%BRIGHT%') AND obs_mode NOT LIKE 'ENGINEERING' AND obs_mode NOT LIKE 'MANUAL'";
+        $query .= " AND (camProcessedExp.quality > 0 OR camProcessedExp.sigma_ra > 5 OR camProcessedExp.sigma_dec > 5)";
+        $query .= " ORDER BY comment";
+
+        $qry1 = $projectdb->query($query);
+        while ($qry1->fetchInto($row)) {
+
+            echo "<tr>";
+
+            echo "<td>$row[0]</td>";
+            echo "<td>$row[1]</td>";
+            echo "<td>$row[2]</td>";
+            echo "<td>$row[3]</td>";
+            echo "<td>$row[4]</td>";
+            echo "<td>$row[5]</td>";
+
+            echo "</tr>";
+        }
+    }
+
+    #-----------------------------------------
+    #list bad quality warp exposures
+    if ($badwarpflag != 0) {
+
+        // set up another table
+        global $table;
+        echo $table;
+        echo "<tr>";
+        createTableTitle("Bad quality warpRun exposures", 3);
+        echo "<tr>";
+        createTableColumnHeader("exp_name");
+        createTableColumnHeader("warp_id");
+        createTableColumnHeader("comment");
+
+        #query the bad warps
+        $query = "SELECT exp_name,warp_id,count(warpSkyfile.quality) AS Nwarpskycell,count(if(warpSkyfile.quality > 0,1,NULL)) AS Nwarpskycellbad, comment";
+        $query .= "      FROM rawExp LEFT JOIN chipRun USING (exp_id) LEFT JOIN camRun USING (chip_id) LEFT JOIN fakeRun USING (cam_id) LEFT JOIN warpRun USING (fake_id) JOIN warpSkyfile USING (warp_id)";
+        $query .= "      WHERE dateobs like '$date%' AND exp_id > $refExpID[0]";
+        $query .= "      AND (obs_mode LIKE '%SS%' OR obs_mode LIKE '%BRIGHT%') AND obs_mode NOT LIKE 'ENGINEERING' AND obs_mode NOT LIKE 'MANUAL'";
+        $query .= "      GROUP BY exp_name ORDER BY comment";
+
+        $qry1 = $projectdb->query($query);
+        while ($qry1->fetchInto($row)) {
+
+            echo "<tr>";
+
+            echo "<td>$row[0]</td>";
+            echo "<td>$row[1]</td>";
+            echo "<td>$row[2]</td>";
+
+            echo "</tr>";
+        }
+    }
+
+    #-----------------------------------------
+    #list bad quality diff exposures
+    if ($baddiffflag != 0) {
+        // set up another table
+        global $table;
+        echo $table;
+        echo "<tr>";
+        createTableTitle("Bad diffRun exposures", 7);
+        echo "<tr>";
+        createTableColumnHeader("exp_name");
+        createTableColumnHeader("diff_id");
+        createTableColumnHeader("warp1");
+        createTableColumnHeader("stack1");
+        createTableColumnHeader("warp2");
+        createTableColumnHeader("stack2");
+        createTableColumnHeader("comment");
+
+        #query the bad diffs
+        $query = "     SELECT diff_id,warp1,stack1,warp2,stack2,exp_name,comment FROM ";
+        $query .= "           diffInputSkyfile JOIN warpRun ON (warp1=warp_id OR warp2=warp_id) JOIN fakeRun USING (fake_id) JOIN camRun USING (cam_id) JOIN camProcessedExp USING (cam_id) JOIN chipRun USING (chip_id) JOIN rawExp USING (exp_id)";
+        $query .= "           WHERE rawExp.dateobs LIKE '$date%' AND exp_id > $refExpID[0] AND (obs_mode LIKE '%SS%' OR obs_mode LIKE '%BRIGHT%') AND obs_mode NOT LIKE 'ENGINEERING' AND obs_mode NOT LIKE 'MANUAL'";
+        $query .= "           GROUP By diff_id";
+        $qry1 = $projectdb->query($query);
+
+        while ($qry1->fetchInto($row)) {
+            #distinguish between WW and WS diffs based on stack2
+            if ($row[4] == 0) {
+                  #find the total number of skycell and the number of skycell with a bad quality flag as well as the full publish state 
+                  $query3 = "     SELECT count(diffSkyfile.quality) AS Ndiff,count(if(diffSkyfile.quality > 0,1,NULL)) AS Ndiffbad,count(if(publishRun.state LIKE 'full',1,NULL)) AS Npub FROM ";
+                  $query3 .= "           diffRun JOIN diffSkyfile USING (diff_id) LEFT JOIN publishRun ON (diffRun.diff_id = stage_id)";
+                  $query3 .= "           WHERE diff_id='$row[0]' GROUP BY diffRun.diff_id";
+                  $qry3 = $projectdb->query($query3);
+
+                  while ($qry3->fetchInto($row3)) {
+                      #if all skycells have bad quality, this is a bad diff. If all the skycells are in a full state in publishRun, it is fully published 
+                      if ($row3[1]==$row3[0]) {
+                          echo "<tr>";
+
+                          echo "<td>$row[5]</td>";
+                          echo "<td>$row[0]</td>";
+                          echo "<td>$row[1]</td>";
+                          echo "<td>$row[2]</td>";
+                          echo "<td>$row[3]</td>";
+                          echo "<td>$row[4]</td>";
+                          echo "<td>$row[6]</td>";
+
+                          echo "</tr>";
+                      } 
+                  }
+            }
+
+            if ($row[4] > 0) {
+                  #find the total number of skycell and the number of skycell with a bad quality flag as well as the full publish state 
+                  $query3 = "     SELECT count(diffSkyfile.quality) AS Ndiff,count(if(diffSkyfile.quality > 0,1,NULL)) AS Ndiffbad,count(if(publishRun.state LIKE 'full',1,NULL)) AS Npub FROM ";
+                  $query3 .= "           diffRun JOIN diffSkyfile USING (diff_id) LEFT JOIN publishRun ON (diffRun.diff_id = stage_id)";
+                  $query3 .= "           WHERE diff_id='$row[0]' GROUP BY diffRun.diff_id";
+                  $qry3 = $projectdb->query($query3);
+
+                  while ($qry3->fetchInto($row3)) {
+                      #if all skycells have bad quality, this is a bad diff. If all the skycells are in a full state in publishRun, it is fully published 
+                      if ($row3[1]==$row3[0]) {
+                          echo "<tr>";
+
+                          echo "<td>$row[5]</td>";
+                          echo "<td>$row[0]</td>";
+                          echo "<td>$row[1]</td>";
+                          echo "<td>$row[2]</td>";
+                          echo "<td>$row[3]</td>";
+                          echo "<td>$row[4]</td>";
+                          echo "<td>$row[6]</td>";
+
+                          echo "</tr>";
+                       }
+                  }
+            }
+        }
+    }
+
+    #-----------------------------------------
+    #check for overridden exposures
+    $query = "SELECT COUNT(comment), comment";
+    $query .= " FROM rawExp";
+    $query .= " JOIN chipRun USING (exp_id)";
+    $query .= " JOIN camRun USING (chip_id)";
+    $query .= " WHERE dateobs LIKE '$date%'";
+    $query .= " AND exp_id > $refExpID[0]"; 
+    $query .= " AND exp_type = 'OBJECT'";
+    $query .= " AND (obs_mode LIKE '%SS%' OR obs_mode LIKE '%BRIGHT%') AND obs_mode NOT LIKE 'ENGINEERING' AND obs_mode NOT LIKE 'MANUAL'";
+    $query .= " GROUP BY comment";
+
+    $qry1 = $projectdb->query($query);
+    $doHeader = 1; 
+
+    while ($qry1->fetchInto($row)) {
+        if ($row[0] > 1) {
+            $query = "SELECT exp_name,dateobs, comment";
+            $query .= " FROM rawExp";
+            $query .= " JOIN chipRun USING (exp_id)";
+            $query .= " JOIN camRun USING (chip_id)";
+            $query .= " WHERE dateobs LIKE '$date%' AND comment LIKE '$row[1]'";
+            $query .= " AND exp_id > $refExpID[0]"; 
+            $query .= " AND exp_type = 'OBJECT'";
+            $query .= " AND (obs_mode LIKE '%SS%' OR obs_mode LIKE '%BRIGHT%') AND obs_mode NOT LIKE 'ENGINEERING' AND obs_mode NOT LIKE 'MANUAL'";
+            $query .= " ORDER BY dateobs DESC";
+            $qry2 = $projectdb->query($query);
+
+            $doskip = 0;
+            while ($qry2->fetchInto($row2)) {
+               if ($doskip) {
+                    if ($doHeader) {
+                       // set up another table
+                       global $table;
+                       echo $table;
+                       echo "<tr>";
+                       createTableTitle("Overridden exposures", 3);
+                       echo "<tr>";
+                       createTableColumnHeader("exp_name");
+                       createTableColumnHeader("dateobs");
+                       createTableColumnHeader("comment");
+                       $doHeader = 0;
+                    }
+                    echo "<tr>";
+
+                    echo "<td>$row2[0]</td>";
+                    echo "<td>$row2[1]</td>";
+                    echo "<td>$row2[2]</td>";
+
+                    echo "</tr>";
+                }
+                $doskip = 1;
+            }
+        }
+    }
+    if (!$doHeader) { print "\n"; }
 
 
