Index: trunk/MagicSoft/Mars/datacenter/db/ctamcinfo.php
===================================================================
--- trunk/MagicSoft/Mars/datacenter/db/ctamcinfo.php	(revision 9474)
+++ trunk/MagicSoft/Mars/datacenter/db/ctamcinfo.php	(revision 9486)
@@ -17,25 +17,24 @@
         $query0 = "SELECT ";
 
-        if ($groups>0)
-        {
-            foreach ($checkgroup as $key => $element)
-                if ($element==-1)
-                    $query0 .=  $key . " as '" . $alias[$key] . "' " . ", ";
-            /*
-            //--------------------------------------------------
-            //$query0 .= " TIMEDIFF(fRunStop, fRunStart), ";
-            // Only available in MySQL>4.1.1
-            $query0 .= "SUM(if(TIME_TO_SEC(fRunStop)-TIME_TO_SEC(fRunStart)<0, " .
-                "TIME_TO_SEC(fRunStop)-TIME_TO_SEC(fRunStart)+24*60*60, " .
-                "TIME_TO_SEC(fRunStop)-TIME_TO_SEC(fRunStart)))/3600 as '" . $alias["SUM(fRunTime)/3600"] . "', ";
-            //--------------------------------------------------
-            $query0 .= " SUM(fNumEvents) as '" . $alias["SUM(fNumEvents)"] . "', ";
-            $query0 .= " Min(fZenithDistance) as '" . $alias["Min(fZenithDistance)"] . "', ";
-            $query0 .= " Max(fZenithDistance) as '" . $alias["Max(fZenithDistance)"] . "', ";
-            */
-            $query0 .= " COUNT(*) as '# Runs' ";
-        }
-        else
-        {
+        if ($groups>0 || $statusgroups>0)
+        {
+            if ($groups>0)
+            {
+                foreach ($checkgroup as $key => $element)
+                    if ($element==-1)
+                        $query0 .=  $key . " as '" . $alias[$key] . "' " . ", ";
+                /*
+                 //--------------------------------------------------
+                 //$query0 .= " TIMEDIFF(fRunStop, fRunStart), ";
+                 // Only available in MySQL>4.1.1
+                 $query0 .= "SUM(if(TIME_TO_SEC(fRunStop)-TIME_TO_SEC(fRunStart)<0, " .
+                 "TIME_TO_SEC(fRunStop)-TIME_TO_SEC(fRunStart)+24*60*60, " .
+                 "TIME_TO_SEC(fRunStop)-TIME_TO_SEC(fRunStart)))/3600 as '" . $alias["SUM(fRunTime)/3600"] . "', ";
+                 //--------------------------------------------------
+                 $query0 .= " SUM(fNumEvents) as '" . $alias["SUM(fNumEvents)"] . "', ";
+                 $query0 .= " Min(fZenithDistance) as '" . $alias["Min(fZenithDistance)"] . "', ";
+                 $query0 .= " Max(fZenithDistance) as '" . $alias["Max(fZenithDistance)"] . "', ";
+                 */
+            }
             if ($statusgroups>0)
             {
@@ -43,26 +42,29 @@
                     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 .= " (if(IsNull(" . $key . "), 'not done' ,if(" . $key . "='1970-01-01 00:00:00','dont do','done'))) as '" . $alias[$key] . "', ";
+
+//                $query0 .= " count(*) as '# Runs'";
 
             }
-            else
-            {
-                $query0 .= " MCRunData.fMCRunNumber as 'Run#' ";
+            $query0 .= " COUNT(*) as '# Runs' ";
+            $query0 .= ", SUM(fNumEvents) as '" . $alias["SUM(fNumEvents)"] . "' ";
+            $query0 .= ", SUM(fNumEvents) DIV 1000 as '" . $alias["SUM(fNumEvents) DIV 1000"] . "' ";
+        }
+        else
+        {
+            $query0 .= " MCRunData.fMCRunNumber 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' ";
 
-                if (empty($_GET["fSendTxt"]) && !empty($_GET["fLinks"]))
-                {
-                    $query0 .= ", CONCAT('<A&ws;HREF=\"queryrbk.php?fNight=', date_format(adddate(fRunStart, interval +13 HOUR), '%Y-%m-%d') , '&amp;fDate=2\">rbk</A>') ";
-                    $query0 .= " as 'Links'";
-                }
-
-                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] . "' ";
+            if (empty($_GET["fSendTxt"]) && !empty($_GET["fLinks"]))
+            {
+                $query0 .= ", CONCAT('<A&ws;HREF=\"queryrbk.php?fNight=', date_format(adddate(fRunStart, interval +13 HOUR), '%Y-%m-%d') , '&amp;fDate=2\">rbk</A>') ";
+                $query0 .= " as 'Links'";
             }
+
+            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] . "' ";
         }
 
@@ -105,10 +107,10 @@
             $query0 .= " AND ";
 
-        $query0 .= StatusQuery("fCorsikaSimTelarray", $needs);
-        $query0 .= StatusQuery("fChimp", $needs);
-        $query0 .= StatusQuery("fCTAStar", $needs);
-        $query0 .= StatusQuery("fStereoB", $needs);
-        $query0 .= StatusQuery("fStereoC", $needs);
-        $query0 .= StatusQuery("fStereoG", $needs);
+        $query0 .= StatusQuery("fCorsikaSimTelarray", $needs, $timelimits);
+        $query0 .= StatusQuery("fChimp", $needs, $timelimits);
+        $query0 .= StatusQuery("fCTAStar", $needs, $timelimits);
+        $query0 .= StatusQuery("fStereoB", $needs, $timelimits);
+        $query0 .= StatusQuery("fStereoC", $needs, $timelimits);
+        $query0 .= StatusQuery("fStereoG", $needs, $timelimits);
 
         if ((!empty($_GET["fRunMin"]) || $_GET["fRunMin"]=="0") && !empty($_GET["fRunMax"]))
@@ -176,5 +178,9 @@
         if ($statusgroups>0)
         {
-            $query0 .= " GROUP BY ";
+//            $query0 .= " GROUP BY ";
+            if (strpos($query0, " GROUP BY ")==FALSE)
+                $query0 .= " GROUP BY ";
+            else
+                $query0 .= ", ";
             $num = $statusgroups;
             foreach ($checkstatusgroup as $key => $element)
