Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 9248)
+++ trunk/MagicSoft/Mars/Changelog	(revision 9249)
@@ -18,4 +18,30 @@
 
                                                  -*-*- END OF LINE -*-*-
+
+
+ 2009/01/23 Daniela Dorner
+
+   * datacenter/db/showplots-ds.php, datacenter/db/tabs.php, 
+     datacenter/db/plot.php:
+     - adapted path to new web file structure
+
+   * datacenter/db/sequinfo-aio.php, datacenter/db/runinfo-aio.php:
+     - added option to group by date (year, month, night): pulldown in
+       menu and adapted query
+
+   * datacenter/db/sequinfo-aio.php, datacenter/db/runinfo-aio.php
+     datacenter/db/datasetinfo-aio.php:
+     - enabled possibility to combine all group-bys 
+
+   * datacenter/db/datasetinfo-aio.php:
+     - enhances information printed in table in case of group-by
+
+   * datacenter/db/include.php:
+     - adapted pulldown of status-group-by
+
+   * datacenter/db/menu.php:
+     - added pulldown for sumtrigger-flag to sequinfo-menu
+     - added function to print pulldown for group-by date
+
 
 
Index: trunk/MagicSoft/Mars/NEWS
===================================================================
--- trunk/MagicSoft/Mars/NEWS	(revision 9248)
+++ trunk/MagicSoft/Mars/NEWS	(revision 9249)
@@ -48,4 +48,8 @@
    * Websites: added option to query only sequences containing sumtrigger 
      events
+
+   * Websites: added option to group by date (year, month, night) for runs
+     and sequences and enabled that combining of different group-bys, 
+     e.g. status, date and source is possible
 
  ;automatic analyis
Index: trunk/MagicSoft/Mars/datacenter/db/datasetinfo-aio.php
===================================================================
--- trunk/MagicSoft/Mars/datacenter/db/datasetinfo-aio.php	(revision 9248)
+++ trunk/MagicSoft/Mars/datacenter/db/datasetinfo-aio.php	(revision 9249)
@@ -17,44 +17,52 @@
         $query0 = "SELECT ";
 
-        if ($groups>0)
-        {
-            foreach ($checkgroup as $key => $element)
-                if ($element==-1)
-                    $query0 .=  $key . " as '" . $alias[$key] . "' " . ", ";
-            $query0 .= " COUNT(*) as '# Datasets' ";
-        }
-        else
-        {
+        if ($groups>0 || $statusgroups>0)
+        {
+            if ($groups>0)
+            {
+                foreach ($checkgroup as $key => $element)
+                    if ($element==-1)
+                        $query0 .=  $key . " as '" . $alias[$key] . "' " . ", ";
+                $query0 .= " COUNT(*) as '# Datasets', ";
+            }
+
+            //--------------------------------------------------
+            $query0 .= "SUM(fRunTime)/3600 as '" . $alias["SUM(fRunTime)/3600"] . "', ";
+            //--------------------------------------------------
+            $query0 .= " Min(fZenithDistanceMin) as '" . $alias["Min(fZenithDistanceMin)"] . "', ";
+            $query0 .= " Max(fZenithDistanceMax) as '" . $alias["Max(fZenithDistanceMax)"] . "', ";
+            $query0 .= " COUNT(*) as '# Sequ' ";
+
             if ($statusgroups>0)
             {
                 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 12 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 . "), if(isnull(fStartTime), 'not done', if(isnull(fFailedTime),if(isnull(" . $needs[$key] . "),'not done',if(date_sub(Now(),interval 12 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 '# Datasets'";
+                $query0 .= ", COUNT(*) as '# Datasets'";
 
             }
-            else
+        }
+        else
+        {
+            $query0 .= " " . $fromtable . ".fDataSetNumber as '" . $alias["fDataSetNumber"] . "' ";
+            if (!empty($_GET["fLinks"]))
             {
-                $query0 .= " " . $fromtable . ".fDataSetNumber as '" . $alias["fDataSetNumber"] . "' ";
-                if (!empty($_GET["fLinks"]))
-                {
-//                    $query0 .= ", CONCAT('<A&ws;HREF=\"http://www.astro.uni-wuerzburg.de/datacenter/datasets/' , LEFT(LPAD(CONCAT(DataSets.fDataSetNumber, '.'), 9,'0'),5), '/dataset', LPAD(CONCAT(DataSets.fDataSetNumber , '.txt'), 12,'0') , '\">f</A>' ";
-//                    $query0 .= ", '&nbsp;<A&ws;HREF=\"http://www.astro.uni-wuerzburg.de/datacenter/ganymed/' , LEFT(LPAD(CONCAT(DataSets.fDataSetNumber, '.'), 9,'0'),5), '/', LEFT(LPAD(CONCAT(DataSets.fDataSetNumber, '.'), 9,'0'), 8), '\">g</A>'";
-//                    $query0 .= ", '&nbsp;<A&ws;HREF=\"ganymed.php?fDataSetNo=', DataSets.fDataSetNumber, '\">i</A>') ";
-                    $query0 .= ", CONCAT('<A&ws;HREF=\"http://www.astro.uni-wuerzburg.de/datacenter/datasets/' , LEFT(LPAD(CONCAT(DataSets.fDataSetNumber, '.'), 9,'0'),5), '/dataset', LPAD(CONCAT(DataSets.fDataSetNumber , '.txt'), 12,'0') , '\">f</A>' ";
-                    $query0 .= ", '&nbsp;<A&ws;HREF=\"tabs.php?t=ganymed&n=' , fDataSetNumber, '\">g</A>'";
-                    $query0 .= ", '&nbsp;<A&ws;HREF=\"tabs.php?t=gplotdb&n=' , fDataSetNumber, '\">pdb</A>'";
-//                    $query0 .= ", '&nbsp;<A&ws;HREF=\"ganymed.php?fDataSetNo=', DataSets.fDataSetNumber, '\">i</A>' ";
-                    $query0 .= ") as 'Links'";
-                }
-
-                foreach ($_GET as $key => $element)
-                    if ($_GET[$key]=="On")
-                        if ($key!="fLinks")
-                            if (empty($checkwhere[$key]) || $checkwhere[$key]==0)
-                                $query0 .= ", " . $key . " as '" . $alias[$key] . "' ";
+                //$query0 .= ", CONCAT('<A&ws;HREF=\"http://www.astro.uni-wuerzburg.de/datacenter/datasets/' , LEFT(LPAD(CONCAT(DataSets.fDataSetNumber, '.'), 9,'0'),5), '/dataset', LPAD(CONCAT(DataSets.fDataSetNumber , '.txt'), 12,'0') , '\">f</A>' ";
+                //$query0 .= ", '&nbsp;<A&ws;HREF=\"http://www.astro.uni-wuerzburg.de/datacenter/ganymed/' , LEFT(LPAD(CONCAT(DataSets.fDataSetNumber, '.'), 9,'0'),5), '/', LEFT(LPAD(CONCAT(DataSets.fDataSetNumber, '.'), 9,'0'), 8), '\">g</A>'";
+                //$query0 .= ", '&nbsp;<A&ws;HREF=\"ganymed.php?fDataSetNo=', DataSets.fDataSetNumber, '\">i</A>') ";
+                $query0 .= ", CONCAT('<A&ws;HREF=\"http://www.astro.uni-wuerzburg.de/datacenter/datasets/' , LEFT(LPAD(CONCAT(DataSets.fDataSetNumber, '.'), 9,'0'),5), '/dataset', LPAD(CONCAT(DataSets.fDataSetNumber , '.txt'), 12,'0') , '\">f</A>' ";
+                $query0 .= ", '&nbsp;<A&ws;HREF=\"tabs.php?t=ganymed&n=' , fDataSetNumber, '\">g</A>'";
+                $query0 .= ", '&nbsp;<A&ws;HREF=\"tabs.php?t=gplotdb&n=' , fDataSetNumber, '\">pdb</A>'";
+                //$query0 .= ", '&nbsp;<A&ws;HREF=\"ganymed.php?fDataSetNo=', DataSets.fDataSetNumber, '\">i</A>' ";
+                $query0 .= ") as 'Links'";
             }
+
+            foreach ($_GET as $key => $element)
+                if ($_GET[$key]=="On")
+                    if ($key!="fLinks")
+                        if (empty($checkwhere[$key]) || $checkwhere[$key]==0)
+                            $query0 .= ", " . $key . " as '" . $alias[$key] . "' ";
         }
 
@@ -120,5 +128,8 @@
         if ($statusgroups>0)
         {
-            $query0 .= " GROUP BY ";
+            if (strpos($query0, " GROUP BY ")==FALSE)
+                $query0 .= " GROUP BY  ";
+            else
+                $query0 .= ",  ";
             $num = $statusgroups;
             foreach ($checkstatusgroup as $key => $element)
Index: trunk/MagicSoft/Mars/datacenter/db/include.php
===================================================================
--- trunk/MagicSoft/Mars/datacenter/db/include.php	(revision 9248)
+++ trunk/MagicSoft/Mars/datacenter/db/include.php	(revision 9249)
@@ -84,5 +84,5 @@
 
     $status = array
-        ( 0 => "all",
+        ( 0 => "ALL",
           1 => "done",
           2 => "not done",
@@ -91,5 +91,5 @@
           5 => "failed",
           6 => "crashed",
-          7 => "group by",
+          7 => "GROUP BY",
         );
 
Index: trunk/MagicSoft/Mars/datacenter/db/menu.php
===================================================================
--- trunk/MagicSoft/Mars/datacenter/db/menu.php	(revision 9248)
+++ trunk/MagicSoft/Mars/datacenter/db/menu.php	(revision 9249)
@@ -161,5 +161,5 @@
     printf("  </td><td>\n");
     printf("  </td><td>\n");
-    PrintPullDown($host, $user, $pw, $db, "SumTriggerFlag",              "fSumTriggerFlagName",                  "fSumTriggerFlagKEY",              "SumTrigger Flag");
+    PrintPullDown($host, $user, $pw, $db, "SumTriggerFlag",              "fSumTriggerFlagName",              "fSumTriggerFlagKEY",              "SumTrigger Flag");
 //    printf("  </td><td>\n");
 //    PrintPullDown($host, $user, $pw, $db, "ManuallyChanged",             "fManuallyChangedName",             "fManuallyChangedKEY",             "Manually changed");
@@ -564,4 +564,23 @@
 }
 
+function PrintGroupByDateMenu()
+{
+    printf("Group by Date ");
+    printf("<select name='fGroupByDate' size='1' class='Width'>\n");
+    if (empty($_GET["fGroupByDate"]) || $_GET["fGroupByDate"]==0)
+        printf("    <option value='0' selected>--- NO GROUP BY ---</option>\n");
+    else
+        printf("    <option value='0'>--- NO GROUP BY ---</option>\n");
+    $dates=array("Year", "Month","Night");
+    foreach ($dates as $date)
+    {
+        if ($_GET["fGroupByDate"]==$date)
+            printf("    <option value='%s' selected> %s </option>\n", $date, $date);
+        else
+            printf("    <option value='%s'> %s </option>\n", $date, $date);
+    }
+    printf("   </select>\n");
+}
+
 function PrintSourceMenu($host,$user,$pw,$db)
 {
Index: trunk/MagicSoft/Mars/datacenter/db/plot.php
===================================================================
--- trunk/MagicSoft/Mars/datacenter/db/plot.php	(revision 9248)
+++ trunk/MagicSoft/Mars/datacenter/db/plot.php	(revision 9249)
@@ -1,4 +1,4 @@
 <?php
-    require_once("../phpchartdir.php");
+    require_once("./phpchartdir.php");
 
 include("plotinclude.php");
Index: trunk/MagicSoft/Mars/datacenter/db/runinfo-aio.php
===================================================================
--- trunk/MagicSoft/Mars/datacenter/db/runinfo-aio.php	(revision 9248)
+++ trunk/MagicSoft/Mars/datacenter/db/runinfo-aio.php	(revision 9249)
@@ -17,9 +17,28 @@
         $query0 = "SELECT ";
 
-        if ($groups>0)
+        if ($groups>0 || ((!empty($_GET["fGroupByDate"])) && !$_GET["fGroupByDate"]==0) || $statusgroups>0)
         {
             foreach ($checkgroup as $key => $element)
                 if ($element==-1)
                     $query0 .=  $key . " as '" . $alias[$key] . "' " . ", ";
+
+            if ((!empty($_GET["fGroupByDate"])) && !$_GET["fGroupByDate"]==0)
+            {
+                $query0 .= " DATE_FORMAT(ADDDATE(fRunStart,Interval 12 hour), '";
+                switch($_GET["fGroupByDate"])
+                {
+                case "Year":
+                    $query0 .= "%Y ";
+                    break;
+                case "Month":
+                    $query0 .= "%Y-%m ";
+                    break;
+                case "Night":
+                    $query0 .= "%Y-%m-%d ";
+                    break;
+                }
+                $query0 .= "')  AS GroupByDate, ";
+            }
+
             //--------------------------------------------------
             //$query0 .= " TIMEDIFF(fRunStop, fRunStart), ";
@@ -33,34 +52,32 @@
             $query0 .= " Max(fZenithDistance) as '" . $alias["Max(fZenithDistance)"] . "', ";
             $query0 .= " COUNT(*) as '# Runs' ";
-        }
-        else
-        {
+
             if ($statusgroups>0)
             {
                 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 12 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 . "), if(isnull(fStartTime), 'not done', if(isnull(fFailedTime),if(isnull(" . $needs[$key] . "),'not done',if(date_sub(Now(),interval 12 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 .= ", COUNT(*) AS '# Runs'";
 
             }
-            else
+        }
+        else
+        {
+            //$query0 .= " RunData.fRunNumber 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 .= " RunData.fRunNumber 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] . "' ";
+                $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] . "' ";
         }
 
@@ -165,7 +182,16 @@
         }
 
+        if ((!empty($_GET["fGroupByDate"])) && !$_GET["fGroupByDate"]==0)
+            if (strpos($query0, " GROUP BY ")==FALSE)
+                $query0 .= " GROUP BY GroupByDate ";
+            else
+                $query0 .= ", GroupByDate ";
+
         if ($statusgroups>0)
         {
-            $query0 .= " GROUP BY ";
+            if (strpos($query0, " GROUP BY ")==FALSE)
+                $query0 .= " GROUP BY  ";
+            else
+                $query0 .= ",  ";
             $num = $statusgroups;
             foreach ($checkstatusgroup as $key => $element)
@@ -264,4 +290,5 @@
         printf(" <P>\n");
         PrintSourceMenu($host,$user,$pw,$db);
+        PrintGroupByDateMenu();
         printf("<p>");
         printf("</div>");
Index: trunk/MagicSoft/Mars/datacenter/db/sequinfo-aio.php
===================================================================
--- trunk/MagicSoft/Mars/datacenter/db/sequinfo-aio.php	(revision 9248)
+++ trunk/MagicSoft/Mars/datacenter/db/sequinfo-aio.php	(revision 9249)
@@ -17,9 +17,29 @@
         $query0 = "SELECT ";
 
-        if ($groups>0)
-        {
-            foreach ($checkgroup as $key => $element)
-                if ($element==-1)
-                    $query0 .=  $key . " as '" . $alias[$key] . "' " . ", ";
+        if ($groups>0 || ((!empty($_GET["fGroupByDate"])) && !$_GET["fGroupByDate"]==0) || $statusgroups>0)
+        {
+            if ($groups>0)
+                foreach ($checkgroup as $key => $element)
+                    if ($element==-1)
+                        $query0 .=  $key . " as '" . $alias[$key] . "' " . ", ";
+
+            if ((!empty($_GET["fGroupByDate"])) && !$_GET["fGroupByDate"]==0)
+            {
+                $query0 .= " DATE_FORMAT(ADDDATE(fRunStart,Interval 12 hour), '";
+                switch($_GET["fGroupByDate"])
+                {
+                case "Year":
+                    $query0 .= "%Y ";
+                    break;
+                case "Month":
+                    $query0 .= "%Y-%m ";
+                    break;
+                case "Night":
+                    $query0 .= "%Y-%m-%d ";
+                    break;
+                }
+                $query0 .= "')  AS GroupByDate, ";
+            }
+
             //--------------------------------------------------
             $query0 .= "SUM(fRunTime)/3600 as '" . $alias["SUM(fRunTime)/3600"] . "', ";
@@ -29,54 +49,52 @@
             $query0 .= " Max(fZenithDistanceMax) as '" . $alias["Max(fZenithDistanceMax)"] . "', ";
             $query0 .= " COUNT(*) as '# Sequ' ";
-        }
-        else
-        {
+
             if ($statusgroups>0)
             {
                 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 12 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 . "), if(isnull(fStartTime), 'not done', if(isnull(fFailedTime),if(isnull(" . $needs[$key] . "),'not done',if(date_sub(Now(),interval 12 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 '# Sequ'";
+                $query0 .= ", COUNT(*) as '# Sequ'";
 
             }
+        }
+        else
+        {
+            if (!empty($_GET["fSendTxt"]))
+                $query0 .= " " . $fromtable . ".fSequenceFirst as '" . $alias["fSequenceFirst"] . "' ";
             else
             {
-                if (!empty($_GET["fSendTxt"]))
-                    $query0 .= " " . $fromtable . ".fSequenceFirst as '" . $alias["fSequenceFirst"] . "' ";
-                else
+                //old version using fRunMin, fRunMax
+                //$query0 .= " CONCAT('<A&ws;HREF=\"runinfo-aio.php?',  'fRunStart=On', '&amp;fZenithDistance=On', '&amp;fRunMin=', Sequences.fSequenceFirst, '&amp;fMeanTriggerRate=On', '&amp;fTest=On', '&amp;fRunTypeName=On', '&amp;fRunMax=', fSequenceLast, '&amp;fNumEvents=On', '&amp;fSourceName=On&amp;', 'fExcludedFDAKEY=1', '&amp;fSequenceFirst=On', '&amp;fRawFileAvail=On', '&amp;fCCFileAvail=On', '&amp;fCaCoFileAvail=On', '&amp;fNumResults=500\">', Sequences.fSequenceFirst, '</A>') ";
+                //new version using fSequenceNo
+                $query0 .= " CONCAT('<A&ws;HREF=\"runinfo-aio.php?',  'fRunStart=On', '&amp;fZenithDistance=On', '&amp;fSequenceNo=', Sequences.fSequenceFirst, '&amp;fMeanTriggerRate=On', '&amp;fTest=On', '&amp;fRunTypeName=On', '&amp;fNumEvents=On', '&amp;fSourceName=On&amp;', 'fExcludedFDAKEY=1', '&amp;fSequenceFirst=On', '&amp;fRawFileAvail=On', '&amp;fCCFileAvail=On', '&amp;fCaCoFileAvail=On', '&amp;fNumResults=500\">', 'M', Sequences.fTelescopeNumber, ':', LPAD(Sequences.fSequenceFirst, 8, ' '), '</A>') ";
+                //$query0 .= " as " . $alias["fSequenceFirst"];
+                $query0 .= " as 'Tel:Sequ'";
+                if (!empty($_GET["fLinks"]))
                 {
-                    //old version using fRunMin, fRunMax
-                    //$query0 .= " CONCAT('<A&ws;HREF=\"runinfo-aio.php?',  'fRunStart=On', '&amp;fZenithDistance=On', '&amp;fRunMin=', Sequences.fSequenceFirst, '&amp;fMeanTriggerRate=On', '&amp;fTest=On', '&amp;fRunTypeName=On', '&amp;fRunMax=', fSequenceLast, '&amp;fNumEvents=On', '&amp;fSourceName=On&amp;', 'fExcludedFDAKEY=1', '&amp;fSequenceFirst=On', '&amp;fRawFileAvail=On', '&amp;fCCFileAvail=On', '&amp;fCaCoFileAvail=On', '&amp;fNumResults=500\">', Sequences.fSequenceFirst, '</A>') ";
-                    //new version using fSequenceNo
-                    $query0 .= " CONCAT('<A&ws;HREF=\"runinfo-aio.php?',  'fRunStart=On', '&amp;fZenithDistance=On', '&amp;fSequenceNo=', Sequences.fSequenceFirst, '&amp;fMeanTriggerRate=On', '&amp;fTest=On', '&amp;fRunTypeName=On', '&amp;fNumEvents=On', '&amp;fSourceName=On&amp;', 'fExcludedFDAKEY=1', '&amp;fSequenceFirst=On', '&amp;fRawFileAvail=On', '&amp;fCCFileAvail=On', '&amp;fCaCoFileAvail=On', '&amp;fNumResults=500\">', 'M', Sequences.fTelescopeNumber, ':', LPAD(Sequences.fSequenceFirst, 8, ' '), '</A>') ";
-//                    $query0 .= " as " . $alias["fSequenceFirst"];
-                    $query0 .= " as 'Tel:Sequ'";
-                    if (!empty($_GET["fLinks"]))
-                    {
-                        $query0 .= ", CONCAT('<A&ws;HREF=\"tabs.php?t=calib&n=', fSequenceFirst, '\">cal</A>'";
-                        $query0 .= ", '&nbsp;<A&ws;HREF=\"tabs.php?t=signal&n=', fSequenceFirst, '\">sig</A>'";
-                        $query0 .= ", '&nbsp;<A&ws;HREF=\"tabs.php?t=star&n=', fSequenceFirst, '\">star</A>'";
-                        $query0 .= ", '&nbsp;<A&ws;HREF=\"http://www.astro.uni-wuerzburg.de/datacenter/sequences/' , LEFT(LPAD(CONCAT(Sequences.fSequenceFirst, '.'), 9,'0'),4), '/sequence', LPAD(CONCAT(Sequences.fSequenceFirst , '.txt'), 12,'0') , '\">', 'f </A>' ";
-//                        $query0 .= ", '&nbsp;<A&ws;HREF=\"sequence.php?fSequenceNo=', Sequences.fSequenceFirst , '&amp;fAll=On\">i</A>'";
-                        $query0 .= ", '&nbsp;<A&ws;HREF=\"queryrbk.php?fNight=', date_format(adddate(fRunStart, interval +13 HOUR), '%Y-%m-%d') , '&amp;fDate=2\">rbk</A>') ";
-//                        $query0 .= ", CONCAT('<A&ws;HREF=\"http://www.astro.uni-wuerzburg.de/datacenter/callisto/' , LEFT(LPAD(CONCAT(Sequences.fSequenceFirst, '.'), 9,'0'),4), '/', LPAD(CONCAT(Sequences.fSequenceFirst, '/'), 9,'0'), 'callisto', LPAD(CONCAT(Sequences.fSequenceFirst , '.html'), 13,'0') , '\">cl</A>'";
-//                        $query0 .= ", '&nbsp;<A&ws;HREF=\"http://www.astro.uni-wuerzburg.de/datacenter/callisto/' , LEFT(LPAD(CONCAT(Sequences.fSequenceFirst, '.'), 9,'0'),4), '/', LPAD(CONCAT(Sequences.fSequenceFirst, '/'), 9,'0'), '\">c</A>'";
-//                        $query0 .= ", '&nbsp;<A&ws;HREF=\"http://www.astro.uni-wuerzburg.de/datacenter/star/' , LEFT(LPAD(CONCAT(Sequences.fSequenceFirst, '.'), 9,'0'),4), '/', LPAD(CONCAT(Sequences.fSequenceFirst, '/'), 9,'0'), 'star', LPAD(CONCAT(Sequences.fSequenceFirst , '.html'), 13,'0') , '\">sl</A>'";
-//                        $query0 .= ", '&nbsp;<A&ws;HREF=\"http://www.astro.uni-wuerzburg.de/datacenter/star/' , LEFT(LPAD(CONCAT(Sequences.fSequenceFirst, '.'), 9,'0'),4), '/', LPAD(CONCAT(Sequences.fSequenceFirst, '/'), 9,'0'), '\">s</A>'";
-//                        $query0 .= ", '&nbsp;<A&ws;HREF=\"http://www.astro.uni-wuerzburg.de/datacenter/sequences/' , LEFT(LPAD(CONCAT(Sequences.fSequenceFirst, '.'), 9,'0'),4), '/sequence', LPAD(CONCAT(Sequences.fSequenceFirst , '.txt'), 12,'0') , '\">', 'f </A>' ";
-//                        $query0 .= ", '&nbsp;<A&ws;HREF=\"sequence.php?fSequenceNo=', Sequences.fSequenceFirst , '&amp;fAll=On\">i</A>'";
-//                        $query0 .= ", '&nbsp;<A&ws;HREF=\"queryrbk.php?fNight=', date_format(adddate(fRunStart, interval +13 HOUR), '%Y-%m-%d') , '&amp;fDate=2\">rbk</A>') ";
-                        $query0 .= " as 'Links'";
-                    }
+                    $query0 .= ", CONCAT('<A&ws;HREF=\"tabs.php?t=calib&n=', fSequenceFirst, '\">cal</A>'";
+                    $query0 .= ", '&nbsp;<A&ws;HREF=\"tabs.php?t=signal&n=', fSequenceFirst, '\">sig</A>'";
+                    $query0 .= ", '&nbsp;<A&ws;HREF=\"tabs.php?t=star&n=', fSequenceFirst, '\">star</A>'";
+                    $query0 .= ", '&nbsp;<A&ws;HREF=\"http://www.astro.uni-wuerzburg.de/datacenter/sequences/' , LEFT(LPAD(CONCAT(Sequences.fSequenceFirst, '.'), 9,'0'),4), '/sequence', LPAD(CONCAT(Sequences.fSequenceFirst , '.txt'), 12,'0') , '\">', 'f </A>' ";
+                    //$query0 .= ", '&nbsp;<A&ws;HREF=\"sequence.php?fSequenceNo=', Sequences.fSequenceFirst , '&amp;fAll=On\">i</A>'";
+                    $query0 .= ", '&nbsp;<A&ws;HREF=\"queryrbk.php?fNight=', date_format(adddate(fRunStart, interval +13 HOUR), '%Y-%m-%d') , '&amp;fDate=2\">rbk</A>') ";
+                    //$query0 .= ", CONCAT('<A&ws;HREF=\"http://www.astro.uni-wuerzburg.de/datacenter/callisto/' , LEFT(LPAD(CONCAT(Sequences.fSequenceFirst, '.'), 9,'0'),4), '/', LPAD(CONCAT(Sequences.fSequenceFirst, '/'), 9,'0'), 'callisto', LPAD(CONCAT(Sequences.fSequenceFirst , '.html'), 13,'0') , '\">cl</A>'";
+                    //$query0 .= ", '&nbsp;<A&ws;HREF=\"http://www.astro.uni-wuerzburg.de/datacenter/callisto/' , LEFT(LPAD(CONCAT(Sequences.fSequenceFirst, '.'), 9,'0'),4), '/', LPAD(CONCAT(Sequences.fSequenceFirst, '/'), 9,'0'), '\">c</A>'";
+                    //$query0 .= ", '&nbsp;<A&ws;HREF=\"http://www.astro.uni-wuerzburg.de/datacenter/star/' , LEFT(LPAD(CONCAT(Sequences.fSequenceFirst, '.'), 9,'0'),4), '/', LPAD(CONCAT(Sequences.fSequenceFirst, '/'), 9,'0'), 'star', LPAD(CONCAT(Sequences.fSequenceFirst , '.html'), 13,'0') , '\">sl</A>'";
+                    //$query0 .= ", '&nbsp;<A&ws;HREF=\"http://www.astro.uni-wuerzburg.de/datacenter/star/' , LEFT(LPAD(CONCAT(Sequences.fSequenceFirst, '.'), 9,'0'),4), '/', LPAD(CONCAT(Sequences.fSequenceFirst, '/'), 9,'0'), '\">s</A>'";
+                    //$query0 .= ", '&nbsp;<A&ws;HREF=\"http://www.astro.uni-wuerzburg.de/datacenter/sequences/' , LEFT(LPAD(CONCAT(Sequences.fSequenceFirst, '.'), 9,'0'),4), '/sequence', LPAD(CONCAT(Sequences.fSequenceFirst , '.txt'), 12,'0') , '\">', 'f </A>' ";
+                    //$query0 .= ", '&nbsp;<A&ws;HREF=\"sequence.php?fSequenceNo=', Sequences.fSequenceFirst , '&amp;fAll=On\">i</A>'";
+                    //$query0 .= ", '&nbsp;<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 ($_GET[$key]=="On")
-                        if ($key!="fLinks" && $key!="fOff" && $key!="fOnlyOff" && $key!="fOnlySum")
-                            if (empty($checkwhere[$key]) || $checkwhere[$key]==0)
-                                $query0 .= ", " . $key . " as '" . $alias[$key] . "' ";
             }
+
+            foreach ($_GET as $key => $element)
+                if ($_GET[$key]=="On")
+                    if ($key!="fLinks" && $key!="fOff" && $key!="fOnlyOff" && $key!="fOnlySum")
+                        if (empty($checkwhere[$key]) || $checkwhere[$key]==0)
+                            $query0 .= ", " . $key . " as '" . $alias[$key] . "' ";
         }
 
@@ -219,7 +237,17 @@
         }
 
+        if ((!empty($_GET["fGroupByDate"])) && !$_GET["fGroupByDate"]==0)
+            if (strpos($query0, " GROUP BY ")==FALSE)
+                $query0 .= " GROUP BY GroupByDate ";
+            else
+                $query0 .= ", GroupByDate ";
+
         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)
@@ -332,4 +360,6 @@
         printf("<p>");
         PrintSourceMenu($host,$user,$pw,$db);
+        PrintGroupByDateMenu();
+        printf("<p>");
         PrintNightRangeMenu($host,$user,$pw,$db, "Sequences");
         printf("<p>");
