Index: trunk/MagicSoft/Mars/datacenter/db/mcinfo.php
===================================================================
--- trunk/MagicSoft/Mars/datacenter/db/mcinfo.php	(revision 9548)
+++ trunk/MagicSoft/Mars/datacenter/db/mcinfo.php	(revision 9599)
@@ -1,7 +1,7 @@
 <?php
 {
-    function CreateQuery($_GET, $alias, $checkwhere, $checkgroup, $checkstatusgroup, $needs, $timelimits)
-    {
-        $fromtable="MCCorsikaRunData";
+    function CreateQuery($_GET, $alias, $checkwhere, $checkgroup, $checkstatusgroup, $timelimits)
+    {
+        $fromtable="CeresInfo";
 
         $groups = 0;
@@ -42,19 +42,27 @@
                 foreach ($checkstatusgroup as $key => $element)
                     if ($element==-1)
-                        $query0 .= " (if(IsNull(" . $key . "), if(isnull(fStartTime), 'not done', if(isnull(fFailedTime),if(isnull(" . $needs[$key] . "),'not done',if(date_sub(Now(),interval " . $timelimits[$key] . " hour) < fStartTime,'running','crashed')),if(isnull(" . $needs[$key] . "),'not done','failed'))) ,if(" . $key . "='1970-01-01 00:00:00','dont do','done'))) as '" . $alias[$key] . "', ";
-                //                        $query0 .= " (if(IsNull(" . $key . "), 'not done' ,if(" . $key . "='1970-01-01 00:00:00','dont do','done'))) as '" . $alias[$key] . "', ";
-
-//                $query0 .= " count(*) as '# Runs'";
-//                $query0 .= ", SUM(fNumEvents) as '" . $alias["SUM(fNumEvents)"] . "' ";
-
+                        $query0 .= " IF( ISNULL(" . $key . "Status.fStartTime) "
+                            ." AND ISNULL(" . $key . "Status.fStopTime) "
+                            ." AND ISNULL(" . $key . "Status.fReturnCode), 'not done', "
+                            ." IF (NOT ISNULL(" . $key . "Status.fStartTime) "
+                            ." AND DATE_SUB(Now(),INTERVAL " . $timelimits[$key] . " HOUR) > " . $key . "Status.fStartTime "
+                            ." AND ISNULL(" . $key . "Status.fStopTime) "
+                            ." AND ISNULL(" . $key . "Status.fReturnCode), 'crashed', "
+                            ." IF (NOT ISNULL(" . $key . "Status.fStartTime) "
+                            ." AND DATE_SUB(Now(),INTERVAL " . $timelimits[$key] . " HOUR) < " . $key . "Status.fStartTime "
+                            ." AND ISNULL(" . $key . "Status.fStopTime) "
+                            ." AND ISNULL(" . $key . "Status.fReturnCode), 'running', "
+                            ." IF (NOT ISNULL(" . $key . "Status.fStartTime) "
+                            ." AND NOT ISNULL(" . $key . "Status.fStopTime) "
+                            ." AND ISNULL(" . $key . "Status.fReturnCode), 'done', 'bla' "
+                            ." )))) AS '". $key . "', ";
             }
-            $query0 .= " COUNT(*) as '# Runs' ";
+            $query0 .= " COUNT(*) as '# Files' ";
             $query0 .= ", SUM(fNumEvents) as '" . $alias["SUM(fNumEvents)"] . "' ";
         }
         else
         {
-            $query0 .= " MCCorsikaRunData.fCorsikaRunNumber as 'Run' ";
-//                $query0 .= " Concat(RunData.fTelescopeNumber,':', RunData.fRunNumber,':', RunData.fFileNumber) as 'Run' ";
-//                $query0 .= " Concat('M', RunData.fTelescopeNumber,':', LPAD(RunData.fRunNumber,8, ' '),'/', LPAD(RunData.fFileNumber, 3, ' ')) as 'Tel:Run/File' ";
+            $query0 .= " CONCAT(LPAD(" . $fromtable . ".fRunNumber,8, ' '),'.', ";
+            $query0 .= " RIGHT(LPAD(" . $fromtable . ".fFileNumber, 6, 0), 3)) as 'Run.File' ";
 
             if (empty($_GET["fSendTxt"]) && !empty($_GET["fLinks"]))
@@ -65,25 +73,31 @@
 
             foreach ($_GET as $key => $element)
-                if ($key!="fLinks" && $_GET[$key]=="On" && $key!="fTest")
-                    if (empty($checkwhere[$key]) || $checkwhere[$key]==0)
-                        $query0 .= ", " . $key . " as '" . $alias[$key] . "' ";
-        }
-
-        $query0 .= " FROM MCCorsikaRunData ";
-
-        $query0 .= " LEFT JOIN MCRunProcessStatus ON MCCorsikaRunData.fCorsikaRunNumber=MCRunProcessStatus.fMCRunNumber ";
+                if ($_GET[$key]=="On" && $key!="fTest" && $key!="fLinks")
+                    if (!ereg("^f", $key))
+                    {
+
+                        $query0 .= ", IF (ISNULL(" . $key . "Status.fStartTime) AND ";
+                        $query0 .= " ISNULL(" . $key . "Status.fStopTime) AND ";
+                        $query0 .= " ISNULL(" . $key . "Status.fReturnCode), 'not done', ";
+                        $query0 .= " IF (NOT ISNULL(" . $key . "Status.fReturnCode), ";
+                        $query0 .= " CONCAT('failed (', " . $key . "Status.fReturnCode, ')'), ";
+                        $query0 .= " CONCAT('done (', " . $key . "Status.fStopTime, ')'))) ";
+
+                        //$query0 .= ", CONCAT( 'halo', " . $key . "Status.fStartTime)";
+                        $query0 .= " AS '" . $alias[$key] . "' ";
+                        //echo "ereg: " . $key . "<br>";
+                    }
+                    else
+                        if (empty($checkwhere[$key]) || $checkwhere[$key]==0)
+                            $query0 .= ", " . $key . " as '" . $alias[$key] . "' ";
+        }
+
+        $query0 .= " FROM " . $fromtable;
+
+        $query0 .= " LEFT JOIN CorsikaInfo USING(fRunNumber,fFileNumber) ";
 
         foreach ($_GET as $key => $element)
             if (($_GET[$key]=="On" || $groups>0))// && !empty($joins[$key]))
                 $query0 .= GetJoin($fromtable,$key);
-
-        /*
-        if ($_GET["fTest"]!="On")
-        {
-            if ($_GET["fSourceName"]!="On")
-                $query0 .= " LEFT JOIN Source USING(fSourceKEY) ";
-            $query0 .= " WHERE fTest='no'";
-        }
-        */
 
         foreach ($checkwhere as $key => $element)
@@ -108,51 +122,13 @@
             $query0 .= " AND ";
 
-        $query0 .= StatusQuery("fCorsikaInputCreated", $needs, $timelimits);
-        $query0 .= StatusQuery("fCorsikaFileAvail", $needs, $timelimits);
+        $query0 .= StatusQuery("Corsika",      $timelimits);
+        $query0 .= StatusQuery("Ceres",        $timelimits);
+        $query0 .= StatusQuery("SequenceFile", $timelimits);
+        $query0 .= StatusQuery("Callisto",     $timelimits);
+        $query0 .= StatusQuery("Star",         $timelimits);
 
         if ((!empty($_GET["fRunMin"]) || $_GET["fRunMin"]=="0") && !empty($_GET["fRunMax"]))
-            $query0 .= "MCCorsikaRunData.fCorsikaRunNumber BETWEEN " . $_GET["fRunMin"] . " AND " . $_GET["fRunMax"] . " ";
-
-//        if ((!empty($_GET["fZDMin"]) || $_GET["fZDMin"]==0) && !empty($_GET["fZDMax"]))
-//            $query0 .= "AND fZenithDistance BETWEEN " . $_GET["fZDMin"] . " AND  " . $_GET["fZDMax"] . " ";
-
-/*
-        if (!empty($_GET["fDate"]))
-            $query0 .= " AND fRunStart REGEXP \"^" . $_GET["fDate"] . "\" ";
-*/
-
-        /*
-        if (!empty($_GET["fSourceN"]))
-            $query0 .= " AND fSourceName REGEXP \"^" . $_GET["fSourceN"] . "\" ";
-
-        if (!empty($_GET["fStartDate"]))
-        {
-            if (strpos(strrev($query0), " DNA ")!=0)
-                $query0 .= " AND ";
-
-            $startdate=substr($_GET["fStartDate"], 0, 10);
-            if ($startdate=="0000-00-00")
-                $query0 .=" fRunStart >= '" . $startdate . " 00:00:00' ";
-            else
-                $query0 .= " fRunStart >= ADDDATE('" . $startdate . " 13:00:00', INTERVAL -1 DAY) ";
-        }
-
-        if (!empty($_GET["fStopDate"]))
-        {
-            if (strpos(strrev($query0), " DNA ")!=0)
-                $query0 .= " AND ";
-
-            $stopdate=substr($_GET["fStopDate"], 0, 10);
-            $query0 .= " fRunStart < '" . $stopdate . " 13:00:00' ";
-        }
-
-        if (!empty($_GET["fSequenceNo"]) || $_GET["fSequenceNo"]=="0")
-        {
-            if (strpos(strrev($query0), " DNA ")!=0)
-                $query0 .= " AND ";
-
-            $query0 .= " fSequenceFirst = '" . $_GET["fSequenceNo"] . "' ";
-        }
-        */
+            $query0 .= " " . $fromtable . ".fRunNumber BETWEEN " . $_GET["fRunMin"] . " AND " . $_GET["fRunMax"] . " ";
+
 
         //remove WHERE or AND in the end of the query
@@ -175,5 +151,4 @@
         if ($statusgroups>0)
         {
-//            $query0 .= " GROUP BY ";
             if (strpos($query0, " GROUP BY ")==FALSE)
                 $query0 .= " GROUP BY ";
@@ -198,5 +173,5 @@
         }
         else
-            $query0 .=" ORDER BY MCCorsikaRunData.fCorsikaRunNumber ASC";
+            $query0 .=" ORDER BY " . $fromtable . ".fRunNumber ASC";
 
         if (empty($_GET["fNumStart"]))
@@ -265,5 +240,5 @@
     }
 
-    function PrintPage($html, $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $needs, $timelimits)
+    function PrintPage($html, $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $timelimits)
     {
         $db_id = mysql_connect($host, $user, $pw);
@@ -276,5 +251,5 @@
         mysql_query("SET BIG_TABLES=1"); // necessary for mySQL <= 4
 
-        $query0 = CreateQuery($_GET, $alias, $checkwhere, $checkgroup, $checkstatusgroup, $needs, $timelimits);
+        $query0 = CreateQuery($_GET, $alias, $checkwhere, $checkgroup, $checkstatusgroup, $timelimits);
 
         $result0 = mysql_query($query0, $db_id);
@@ -310,10 +285,10 @@
         header("Content-Disposition: attachment; filename=query-result.txt");
 
-        PrintPage("0", $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $needs, $timelimits);
+        PrintPage("0", $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $timelimits);
     }
     else
     {
         if (empty($_GET["fPrintTable"]))
-            echo (file_get_contents("index-header.html"));
+            echo (file_get_contents("index-header-fact.html"));
 
         $environment = sizeof($_GET);
@@ -328,7 +303,7 @@
         {
             if (empty($_GET["fPrintTable"]))
-                PrintPage("1", $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $needs, $timelimits);
+                PrintPage("1", $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $timelimits);
             else
-                PrintPage("2", $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $needs, $timelimits);
+                PrintPage("2", $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $timelimits);
         }
 
