Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 7872)
+++ trunk/MagicSoft/Mars/Changelog	(revision 7873)
@@ -22,4 +22,54 @@
    * datacenter/macros/filldotrun.C:
      - implemented new arehucas version
+
+   * datacenter/db/culminating.php, datacenter/db/datacheck.php, 
+     datacenter/db/datasetinfo.php, datacenter/db/dbstatus.php, 
+     datacenter/db/index.php, datacenter/db/printtable.php, 
+     datacenter/db/querycal.php, datacenter/db/queryrbk.php, 
+     datacenter/db/queryseq.php, datacenter/db/querystar.php, 
+     datacenter/db/runinfo.php, datacenter/db/sequence.php, 
+     datacenter/db/sequinfo.php, datacenter/db/statusrps.php, 
+     datacenter/db/statussbs.php, datacenter/db/statussps.php: 
+     - moved some code to functions (mainly menu)
+
+   * datacenter/db/findoffdata.php:
+     - moved some code to functions (mainly menu)
+     - implemented zd-range fields
+     - improved limits functionality
+     - added some limit fields
+     - added new field for limits
+
+   * datacenter/db/include.php:
+     - implemented function to print or not print submitted query 
+       (PrintSubmittedQuery(..))
+     - removed not needed argument of function RemoveSortBy()
+     - implemented new algorithms for enhanced colour coding for limits 
+       in PrintMagicTable()
+
+   * datacenter/db/index-header.html:
+     - shortened menu (removed old websites)
+
+   * datacenter/db/index.html:
+     - added new websites
+     - added link to error coding
+
+   * datacenter/db/magicdefs.php:
+     - changed limits arrays for enhanced algorithms 
+     - added variables for starguider, new limit fields, zd range
+
+   * datacenter/db/sources.php:
+     - fixed bug (display of test sources)
+     - moved some code to functions (mainly menu)
+
+   * datacenter/db/sequinfo-aio.php, datacenter/db/runinfo-aio.php, 
+     datacenter/db/datasetinfo-aio.php:
+     - added (website unifying other websites, so that only one website
+       for runs, one for sequences and one for datasets is needed)
+
+   * datacenter/db/menu.php:
+     - added (containing functions for parts of the menu) 
+
+   * datacenter/db/menu.js: 
+     - added (script for diplaying/hiding parts of the menu)
 
 
Index: trunk/MagicSoft/Mars/datacenter/db/culminating.php
===================================================================
--- trunk/MagicSoft/Mars/datacenter/db/culminating.php	(revision 7872)
+++ trunk/MagicSoft/Mars/datacenter/db/culminating.php	(revision 7873)
@@ -235,6 +235,5 @@
         mysql_close($db_id);
 
-        if ($html=="1")
-            printf("<U><B>submitted query:</B></U><BR>%s<BR>", htmlspecialchars($query0));
+        PrintSubmittedQuery($query0, $html, $db "old");
     }
 
Index: trunk/MagicSoft/Mars/datacenter/db/datacheck.php
===================================================================
--- trunk/MagicSoft/Mars/datacenter/db/datacheck.php	(revision 7872)
+++ trunk/MagicSoft/Mars/datacenter/db/datacheck.php	(revision 7873)
@@ -432,6 +432,5 @@
         mysql_close($db_id);
 
-        if ($html=="1")
-            printf("<U><B>submitted query:</B></U><BR>%s<BR>", htmlspecialchars($query0));
+        PrintSubmittedQuery($query0, $html, $db, "old");
     }
 
Index: trunk/MagicSoft/Mars/datacenter/db/datasetinfo-aio.php
===================================================================
--- trunk/MagicSoft/Mars/datacenter/db/datasetinfo-aio.php	(revision 7873)
+++ trunk/MagicSoft/Mars/datacenter/db/datasetinfo-aio.php	(revision 7873)
@@ -0,0 +1,312 @@
+<?php
+{
+    function CreateQuery($_GET, $alias, $checkwhere, $checkgroup, $checkstatusgroup, $needs)
+    {
+        $fromtable="DataSets";
+
+        $groups = 0;
+        foreach ($checkgroup as $element)
+            if ($element==-1)
+                $groups++;
+
+        $statusgroups = 0;
+        foreach ($checkstatusgroup as $element)
+            if ($element==-1)
+                $statusgroups++;
+
+        $query0 = "SELECT ";
+
+        if ($groups>0)
+        {
+            foreach ($checkgroup as $key => $element)
+                if ($element==-1)
+                    $query0 .=  $key . " as '" . $alias[$key] . "' " . ", ";
+            $query0 .= " COUNT(*) as 'Dataset#' ";
+        }
+        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 . "), 'not done' ,if(" . $key . "='1970-01-01 00:00:00','dont do','done'))) as '" . $alias[$key] . "', ";
+
+                $query0 .= " count(*) as 'DataSet#'";
+
+            }
+            else
+            {
+                $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 .= " 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 .= " FROM " . $fromtable;
+
+        $query0 .= " LEFT JOIN DataSetProcessStatus ON " . $fromtable . ".fDataSetNumber=DataSetProcessStatus.fDataSetNumber ";
+        $query0 .= " LEFT JOIN Ganymed ON " . $fromtable . ".fDataSetNumber=Ganymed.fDataSetNumber ";
+
+        foreach ($_GET as $key => $element)
+            if (($_GET[$key]=="On" || $groups>0))// && !empty($joins[$key]))
+                $query0 .= GetJoin($fromtable,$key);
+
+        foreach ($checkwhere as $key => $element)
+        {
+            if (empty($element) || $element<=0)
+                continue;
+
+            if (strpos($query0, " WHERE ")==FALSE)
+                $query0 .= " WHERE ";
+            else
+                if ($element!=-1)
+                    if (strrpos($query0, " AND ")!=strlen($query0)-5)
+                        $query0 .= " AND ";
+
+            if ($element!=-1)
+                $query0 .= GetCheck($fromtable, $key) . "=" . $element;
+        }
+
+        if (strpos($query0, " WHERE ")==FALSE)
+            $query0 .= " WHERE ";
+        else
+            $query0 .= " AND ";
+
+        $query0 .= StatusQuery("fDataSetInserted", $needs);
+        $query0 .= StatusQuery("fStarFilesAvail", $needs);
+        $query0 .= StatusQuery("fGanymed", $needs);
+        $query0 .= StatusQuery("fFillGanymed", $needs);
+
+        if (!empty($_GET["fRunMin"]) && !empty($_GET["fRunMax"]))
+            $query0 .= "DataSets.fDataSetNumber BETWEEN " . $_GET["fRunMin"] . " AND " . $_GET["fRunMax"] . " ";
+
+/*
+        if (!empty($_GET["fDate"]))
+            $query0 .= " AND fRunStart REGEXP \"^" . $_GET["fDate"] . "\" ";
+*/
+
+        if (!empty($_GET["fSourceN"]))
+            $query0 .= " AND fSourceName REGEXP \"^" . $_GET["fSourceN"] . "\" ";
+
+        if ($groups>0)
+        {
+            $query0 .= " GROUP BY ";
+            $num = $groups;
+            foreach ($checkgroup as $key => $element)
+                if ($element==-1)
+                {
+                    $query0 .= GetCheck($fromtable,$key);
+                    if ($num-->1)
+                        $query0 .= ", ";
+                }
+        }
+
+        if ($statusgroups>0)
+        {
+            $query0 .= " GROUP BY ";
+            $num = $statusgroups;
+            foreach ($checkstatusgroup as $key => $element)
+                if ($element==-1)
+                {
+                    $query0 .= $alias[$key];
+                    if ($num-->1)
+                        $query0 .= ", ";
+                }
+        }
+
+        if (!empty($_GET["fSortBy"]))
+        {
+            $val=substr($_GET["fSortBy"], 0, -1);
+            $query0 .= " ORDER BY " . GetTable($fromtable, $val) . " ";
+            if (substr($_GET["fSortBy"], -1)=="-")
+                $query0 .= "DESC";
+        }
+
+        if (empty($_GET["fSortBy"]) && $groups==0 && $statusgroups==0)
+            $query0 .= "ORDER BY DataSets.fDataSetNumber ASC ";
+
+        if (empty($_GET["fNumStart"]))
+            $_GET["fNumStart"]=0;
+
+        if (empty($_GET["fSendTxt"]))
+            $query0 .= " LIMIT " . $_GET["fNumStart"] . ", " . $_GET["fNumResults"];
+
+        return $query0;
+    }
+
+    function InitGet($_GET)
+    {
+        // Find out whether it is the first call to the php script
+        $first = empty($_GET["fRunMin"]) && empty($_GET["fRunMax"]);
+
+        if (empty($_GET["fNumResults"]))
+            $_GET["fNumResults"]="50";
+
+        if (empty($_GET["fLinks"]))
+            $_GET["fLinks"]=$first?"On":"";
+
+        if (empty($_GET["fWobble"]))
+            $_GET["fWobble"]=$first?"On":"";
+
+        if (empty($_GET["fExcessEvents"]))
+            $_GET["fExcessEvents"]=$first?"On":"";
+
+        if (empty($_GET["fBackgroundEvents*60/fEffOnTime"]))
+            $_GET["fBackgroundEvents*60/fEffOnTime"]=$first?"On":"";
+
+        if (empty($_GET["fBackgroundEvents"]))
+            $_GET["fBackgroundEvents"]=$first?"On":"";
+
+        if (empty($_GET["fSignalEvents"]))
+            $_GET["fSignalEvents"]=$first?"On":"";
+
+        if (empty($_GET["fSignificance"]))
+            $_GET["fSignificance"]=$first?"On":"";
+
+        if (empty($_GET["fScaleFactor"]))
+            $_GET["fScaleFactor"]=$first?"On":"";
+
+        if (empty($_GET["fEffOnTime/3600"]))
+            $_GET["fEffOnTime/3600"]=$first?"On":"";
+        if (empty($_GET["fGanymed"]))
+            $_GET["fGanymed"]=$first?"On":"";
+
+        if (empty($_GET["fSourceName"]))
+            $_GET["fSourceName"]=$first?"On":"";
+
+        InitDataSetInfo($_GET);
+    }
+
+    function PrintForm($_GET, $host, $user, $pw, $db)
+    {
+        printf("<center>\n");
+        printf("<form action=\"datasetinfo-aio.php\" METHOD=\"GET\">\n");
+
+        printf("<input id='sh' type='hidden' name='fShowHide' value='");
+        if (!empty($_GET["fShowHide"]))
+            printf("%s", $_GET["fShowHide"]);
+        else
+            printf("100000000");
+        printf("'>\n");
+        printf("<img id='allbutton'    src='../minus.png' onclick=showhide('all')>                   Menu       \n");
+        printf("<img id='infobutton'   src='../plus.png'  onClick=showhide('info');showhide('info2')>DataSetInfo\n");
+        printf("<img id='statbutton'   src='../plus.png'  onClick=showhide('stat');showhide('fail')> StatusInfo \n");
+        printf("<img id='rangesbutton' src='../plus.png'  onClick=showhide('ranges')>                Ranges     \n");
+
+        printf(" <div id='all' style='display:block'>");
+        PrintDataSetInfoMenu($host, $user, $pw, $db);
+        printf(" <div id='info2' style='display:none'>");
+        printf("  <table><tr><td>\n");
+        PrintPullDown($host, $user, $pw, $db, "Source", "fSourceName", "fSourceKEY", "Source Name");
+        printf("  </td></tr>\n");
+        printf(" </table>\n");
+        printf("</div>");
+        printf(" <p>\n");
+        PrintFailMenu($host, $user, $pw, $db);
+        PrintDataSetStatMenu($host, $user, $pw, $db);
+
+        printf(" <p>\n");
+        printf(" <div id='ranges' style='display:none'>");
+        PrintSourceMenu($host,$user,$pw,$db);
+        PrintDataSetRangeMenu($host,$user,$pw,$db);
+        printf("</div>");
+        printf("</div>");
+        printf(" <P>\n");
+
+        PrintNumResPullDown();
+
+        ini_set("mysql.trace_mode", "Off");
+        ini_set("display_errors", "Off");
+
+        PrintButtons("datasetinfo-aio.php");
+
+        printf("</form>\n");
+        printf("</center>\n");
+        printf("</td>\n");
+        printf("</tr>\n");
+        printf("<tr class='Block'>\n");
+        printf("<td>\n");
+    }
+
+    function PrintPage($html, $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $needs)
+    {
+        $db_id = mysql_connect($host, $user, $pw);
+        if ($db_id==FALSE)
+        {
+            printf("mysql_connect returned the following error: %s\n", mysql_error());
+            die("");
+        }
+        mysql_select_db($db);
+
+        $query0 = CreateQuery($_GET, $alias, $checkwhere, $checkgroup, $checkstatusgroup, $needs);
+
+        $result0 = mysql_query($query0, $db_id);
+
+        if ($result0)
+        {
+            if ($html=="1" || $html=="2")
+                PrintMagicTable($result0, $alias, $rightalign, "", "", $_GET);
+            else
+                PrintText($result0);
+
+            mysql_free_result($result0);
+        }
+        mysql_close($db_id);
+
+        PrintSubmittedQuery($query0, $html, $db, "");
+    }
+
+    include ("include.php");
+    include ("db.php");
+    include ("menu.php");
+    include ("magicdefs.php");
+
+    ini_set("display_errors", "On");
+    ini_set("mysql.trace_mode", "On");
+
+    if (!empty($_GET["fSendTxt"]))
+    {
+        header("Content-type: application/octet");
+        header("Content-Disposition: attachment; filename=query-result.txt");
+
+        PrintPage("0", $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup);
+    }
+    else
+    {
+        echo (file_get_contents("index-header.html"));
+
+        $environment = sizeof($_GET);
+
+        InitGet($_GET);
+        if (empty($_GET["fPrintTable"]))
+            PrintForm($_GET, $host, $user, $pw, $db);
+
+        if ($environment==0)
+            printf("No query submitted yet.<BR>");
+        else
+        {
+            if (empty($_GET["fPrintTable"]))
+                PrintPage("1", $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $needs);
+            else
+                PrintPage("2", $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $needs);
+        }
+
+        echo (file_get_contents("index-footer.html"));
+    }
+
+    ini_set("display_errors", "Off");
+    ini_set("mysql.trace_mode", "Off");
+}
+?>
Index: trunk/MagicSoft/Mars/datacenter/db/datasetinfo.php
===================================================================
--- trunk/MagicSoft/Mars/datacenter/db/datasetinfo.php	(revision 7872)
+++ trunk/MagicSoft/Mars/datacenter/db/datasetinfo.php	(revision 7873)
@@ -388,6 +388,5 @@
         mysql_close($db_id);
 
-        if ($html=="1")
-            printf("<U><B>submitted query:</B></U><BR>%s<BR>", htmlspecialchars($query0));
+        PrintSubmittedQuery($query0, $html, $db, "old");
     }
 
Index: trunk/MagicSoft/Mars/datacenter/db/dbstatus.php
===================================================================
--- trunk/MagicSoft/Mars/datacenter/db/dbstatus.php	(revision 7872)
+++ trunk/MagicSoft/Mars/datacenter/db/dbstatus.php	(revision 7873)
@@ -369,6 +369,5 @@
         mysql_close($db_id);
 
-        if ($html=="1")
-            printf("<U><B>submitted query:</B></U><BR>%s<BR>", htmlspecialchars($query0));
+        PrintSubmittedQuery($query0, $html, $db, "old");
     }
 
Index: trunk/MagicSoft/Mars/datacenter/db/findoffdata.php
===================================================================
--- trunk/MagicSoft/Mars/datacenter/db/findoffdata.php	(revision 7872)
+++ trunk/MagicSoft/Mars/datacenter/db/findoffdata.php	(revision 7873)
@@ -127,8 +127,6 @@
             $query0 = substr($query0, 0, -4);
 
-/*
-        if (!empty($_GET["fDate"]))
-            $query0 .= " AND fRunStart REGEXP \"^" . $_GET["fDate"] . "\" ";
-*/
+        if (!empty($_GET["fZDMin"]) && !empty($_GET["fZDMax"]))
+            $query0 .= "AND (fZenithDistanceMin > " . $_GET["fZDMin"] . " AND fZenithDistanceMax < " . $_GET["fZDMax"] . ") ";
 
         if (!empty($_GET["fSourceN"]))
@@ -228,10 +226,4 @@
             $_GET["fNumResults"]="50";
 
-        if (empty($_GET["fLastUpdate"]))
-            $_GET["fLastUpdate"]="Off";
-
-        if (empty($_GET["fNumEvents"]))
-            $_GET["fNumEvents"]="Off";
-
         if (empty($_GET["fRunStart"]))
             $_GET["fRunStart"]=$first?"On":"";
@@ -240,61 +232,13 @@
             $_GET["fRunTime/60"]=$first?"On":"";
 
-        if (empty($_GET["fSequenceLast"]))
-            $_GET["fSequenceLast"]="Off";
-
         if (empty($_GET["fLinks"]))
             $_GET["fLinks"]=$first?"On":"";
 
         if (empty($_GET["fOff"]))
-            $_GET["fOff"]=$first?"On":"Off";
+            $_GET["fOff"]=$first?"On":"";
 
         if (empty($_GET["fOnlyOff"]))
             $_GET["fOnlyOff"]=$first?"Off":"";
 
-        if (empty($_GET["fArrTimeLimitMean"]))
-            $_GET["fArrTimeLimitMean"]="";
-
-        if (empty($_GET["fArrTimeLimitRms"]))
-            $_GET["fArrTimeLimitRms"]="";
-
-        if (empty($_GET["fPedRmsInLimitMean"]))
-            $_GET["fPedRmsInLimitMean"]="";
-
-        if (empty($_GET["fPedRmsInLimitRms"]))
-            $_GET["fPedRmsInLimitRms"]="";
-
-        if (empty($_GET["fMuonRateLimitMean"]))
-            $_GET["fMuonRateLimitMean"]="";
-
-        if (empty($_GET["fMuonRateLimitRms"]))
-            $_GET["fMuonRateLimitRms"]="";
-
-        if (empty($_GET["fImgRateLimitMean"]))
-            $_GET["fImgRateLimitMean"]="";
-
-        if (empty($_GET["fImgRateLimitRms"]))
-            $_GET["fImgRateLimitRms"]="";
-
-        if (empty($_GET["fPSFLimitMean"]))
-            $_GET["fPSFLimitMean"]="";
-
-        if (empty($_GET["fPSFLimitRms"]))
-            $_GET["fPSFLimitRms"]="";
-
-        if (empty($_GET["fUnsInLimitMean"]))
-            $_GET["fUnsInLimitMean"]="";
-
-        if (empty($_GET["fZdMinLimitMean"]))
-            $_GET["fZdMinLimitMean"]="";
-
-        if (empty($_GET["fZdMaxLimitMean"]))
-            $_GET["fZdMaxLimitMean"]="";
-
-        if (empty($_GET["fAzimuthMin"]))
-            $_GET["fAzimuthMin"]="Off";
-
-        if (empty($_GET["fAzimuthMax"]))
-            $_GET["fAzimuthMax"]="Off";
-
         if (empty($_GET["fZenithDistanceMin"]))
             $_GET["fZenithDistanceMin"]=$first?"On":"";
@@ -306,76 +250,25 @@
             $_GET["fSourceName"]="On";
 
-        if (empty($_GET["fManuallyChangedName"]))
-            $_GET["fManuallyChangedName"]="Off";
-
         if (empty($_GET["fLightConditionsName"]))
             $_GET["fLightConditionsName"]=$first?"On":"";
 
-        if (empty($_GET["fDiscriminatorThresholdTableName"]))
-            $_GET["fDiscriminatorThresholdTableName"]="Off";
-
-        if (empty($_GET["fStar"]))
-            $_GET["fStar"]="Off";
-
         if (empty($_GET["fStarStatus"]))
             $_GET["fStarStatus"]=$first?"1":"";
 
-        if (empty($_GET["fUnreliableInner"]))
-            $_GET["fUnreliableInner"]="Off";
-
-        if (empty($_GET["fUnsuitableOuter"]))
-            $_GET["fUnsuitableOuter"]="Off";
-
-        if (empty($_GET["fUnreliableOuter"]))
-            $_GET["fUnreliableOuter"]="Off";
-
         if (empty($_GET["fUnsuitableInner"]))
             $_GET["fUnsuitableInner"]=$first?"On":"";
 
-        if (empty($_GET["fIsolatedInner"]))
-            $_GET["fIsolatedInner"]="Off";
-
-        if (empty($_GET["fIsolatedOuter"]))
-            $_GET["fIsolatedOuter"]="Off";
-
         if (empty($_GET["fMeanPedRmsInner"]))
             $_GET["fMeanPedRmsInner"]=$first?"On":"";
 
-        if (empty($_GET["fMeanPedRmsOuter"]))
-            $_GET["fMeanPedRmsOuter"]="Off";
-
-        if (empty($_GET["fIsolatedMaxCluster"]))
-            $_GET["fIsolatedMaxCluster"]="Off";
-
-        if (empty($_GET["fArrTimeMeanInner"]))
-            $_GET["fArrTimeMeanInner"]="Off";
-
-        if (empty($_GET["fArrTimeMeanOuter"]))
-            $_GET["fArrTimeMeanOuter"]="Off";
-
         if (empty($_GET["fArrTimeRmsInner"]))
             $_GET["fArrTimeRmsInner"]=$first?"On":"";
 
-        if (empty($_GET["fArrTimeRmsOuter"]))
-            $_GET["fArrTimeRmsOuter"]="Off";
-
         if (empty($_GET["fConvFactorInner"]))
             $_GET["fConvFactorInner"]=$first?"On":"";
 
-        if (empty($_GET["fConvFactorOuter"]))
-            $_GET["fConvFactorOuter"]="Off";
-
-        if (empty($_GET["fMeanNumberIslands"]))
-            $_GET["fMeanNumberIslands"]="Off";
-
         if (empty($_GET["fPSF"]))
             $_GET["fPSF"]=$first?"On":"";
 
-        if (empty($_GET["fRatio"]))
-            $_GET["fRatio"]="Off";
-
-        if (empty($_GET["fMuonNumber"]))
-            $_GET["fMuonNumber"]="Off";
-
         if (empty($_GET["fEffOnTime"]))
             $_GET["fEffOnTime"]=$first?"On":"";
@@ -388,15 +281,13 @@
 
         if (empty($_GET["fInhomogeneity"]))
-            $_GET["fInhomogeneity"]="Off";
+            $_GET["fInhomogeneity"]="On";
 
         if (empty($_GET["fDataRate"]))
             $_GET["fDataRate"]=$first?"On":"";
 
-        if (empty($_GET["fMaxHumidity"]))
-            $_GET["fMaxHumidity"]="Off";
-
-    }
-
-    function PrintForm($_GET, $host, $user, $pw, $db, $limits, $rms, $alias)
+        InitFindOffData($_GET);
+    }
+
+    function PrintForm($_GET, $host, $user, $pw, $db, $limitsmean, $limitsmin, $limitsmax, $alias)
     {
         printf("<center>\n");
@@ -404,89 +295,14 @@
 
         printf(" <table>\n");
-        printf("  <tr><td align='center'>\n");
-
-
-        printf(" <table>\n");
-        printf("  <tr>\n");
-
-        CheckBox("fRunStart",          "Start time");
-        CheckBox("fSequenceLast",      "Last run");
-        CheckBox("fZenithDistanceMin", "Zd min");
-        CheckBox("fZenithDistanceMax", "Zd max");
-
-        printf("  </tr><tr>\n");
-
-        CheckBox("fNumEvents",         "Num of events");
-        CheckBox("fRunTime/60",        "Duration");
-        CheckBox("fAzimuthMin",        "Azimuth min");
-        CheckBox("fAzimuthMax",        "Azimuth max");
-//        CheckBox("fLinks",             "Links");
-/*
-        printf("  </tr></table>\n");
+        printf("  <tr><td align='center' valign='top'>\n");
+
+        PrintSequInfoMenu();
         printf(" <p>\n");
-        printf(" <table>\n");
-        printf("  <tr>\n");
-*/
-
-        printf("  </tr><tr>\n");
-
-        CheckBox("fUnsuitableInner",     "Unsuitable inner");
-        CheckBox("fUnsuitableOuter",     "Unsuitable outer");
-        CheckBox("fUnreliableInner",     "Unreliable inner");
-        CheckBox("fUnreliableOuter",     "Unreliable outer");
-
-        printf("  </tr><tr>\n");
-
-        CheckBox("fIsolatedInner",       "Isolated inner");
-        CheckBox("fIsolatedOuter",       "Isolated outer");
-        CheckBox("fIsolatedMaxCluster",  "IsolatedMaxCl.");
-        CheckBox("fMaxHumidity",        "MaxHumidity");
-
-        printf("  </tr><tr>\n");
-
-        CheckBox("fArrTimeMeanInner",    "ArrTimeMean in");
-        CheckBox("fArrTimeMeanOuter",    "ArrTimeMean out");
-        CheckBox("fArrTimeRmsInner",     "ArrTimeRms in");
-        CheckBox("fArrTimeRmsOuter",     "ArrTimeRms out");
-
-        printf("  </tr><tr>\n");
-
-        CheckBox("fConvFactorInner",     "Conv inner ");
-        CheckBox("fConvFactorOuter",     "Conv outer ");
-        CheckBox("fMeanPedRmsInner",     "MeanPedRms in");
-        CheckBox("fMeanPedRmsOuter",     "MeanPedRms out");
-
-/*
-        printf(" </tr></table>\n");
+        PrintCalMenu();
         printf(" <p>\n");
-
-        printf(" <table>\n");
-        printf("  <tr>\n");
-*/
-
-        printf("  </tr><tr>\n");
-
-        CheckBox("fMeanNumberIslands",  "MeanNumIslands");
-        CheckBox("fPSF",                "PSF");
-        CheckBox("fRatio",              "Ratio");
-        CheckBox("fMuonRate",           "MuonRate");
-
-        printf("  </tr><tr>\n");
-
-        CheckBox("fMuonNumber",         "MuonNumber");
-        CheckBox("fEffOnTime",          "EffOnTime");
-        CheckBox("fEffOnTime/fRunTime", "RelOnTime");
-        CheckBox("fDataRate",           "CleanedEvtRate");
-
-        printf("  </tr><tr>\n");
-
-        CheckBox("fInhomogeneity",      "Inhomogeneity");
-
-        printf("  </tr>\n");
-        printf(" </table>\n");
+        PrintStarMenu();
         printf(" <p>\n");
 
         printf(" <table><tr><td>\n");
-
         PrintPullDown($host, $user, $pw, $db, "Source",                      "fSourceName",                      "fSourceKEY",                      "Source Name");
         printf("  </td><td>\n");
@@ -498,22 +314,9 @@
         printf("  </td><td>\n");
         PrintStatusMenu("fStar",                "Star");
-
         printf("</td></tr> </table>\n");
         printf(" <p>\n");
 
-        printf("  </td><td valign='top'>\n");
-
-        printf("  <table>\n");
-        printf("  <tr><th colspan='3'>Limits</th><tr>\n");
-        printf("  <tr><td>Name </td><td> Mean </td><td> Rms </td></tr>\n");
-        PrintLimitsMenu($limits, $rms, $alias);
-        printf("  </td></tr></table>\n");
-
-        printf("  </td></tr><tr><td colspan='2' align='center'>\n");
-
-        printf(" <p>\n");
-
         printf(" <table>\n");
-        printf("  <tr><td>\n");
+        printf("  <tr><td colspan='3'>\n");
 
         if (empty($_GET["fStarStart"]))
@@ -529,5 +332,6 @@
         printf("StarDone&nbsp;(yyyy-mm-dd)&nbsp;from&nbsp;<input name=\"fStarStart\" type=\"text\" size=\"10\" maxlength=\"10\" value=\"%s\">\n", $starmin);
         printf("to&nbsp;<input name=\"fStarStop\" type=\"text\" size=\"10\" maxlength=\"10\" value=\"%s\">&nbsp;&nbsp;&nbsp;&nbsp;\n", $starmax);
-        printf("  </td>\n");
+        printf("  </td></tr><tr><td><br></td></tr><tr>\n");
+
         CheckBox("fLinks",    "Links");
         CheckBox("fOff",      "incl. offsources");
@@ -536,45 +340,15 @@
         printf("  </tr>\n");
         printf(" </table>\n");
+
         printf(" <p>\n");
 
-        if (empty($_GET["fStartDate"]))
-            $timemin = GetMin("fRunStart", "Sequences", $host, $user, $pw, $db);
-        else
-            $timemin = $_GET["fStartDate"];
-
-        if (empty($_GET["fStopDate"]))
-            $timemax = GetMax("fRunStart", "Sequences", $host, $user, $pw, $db);
-        else
-            $timemax = $_GET["fStopDate"];
-
-        printf("Night&nbsp;(yyyy-mm-dd)&nbsp;from&nbsp;<input name=\"fStartDate\" type=\"text\" size=\"10\" maxlength=\"10\" value=\"%s\">\n", $timemin);
-        printf("to&nbsp;<input name=\"fStopDate\" type=\"text\" size=\"10\" maxlength=\"10\" value=\"%s\">&nbsp;&nbsp;&nbsp;&nbsp;\n", $timemax);
-
-        if (empty($_GET["fRunMin"]))
-            $min = GetMin("fSequenceFirst", "Sequences", $host, $user, $pw, $db);
-        else
-            $min = $_GET["fRunMin"];
-
-        if (empty($_GET["fRunMax"]))
-            $max = GetMax("fSequenceFirst", "Sequences", $host, $user, $pw, $db);
-        else
-            $max = $_GET["fRunMax"];
-
-/*
-        printf("Date&nbsp;(yyyy-mm-dd)&nbsp;<input name=\"fDate\" type=\"text\" size=\"10\" maxlength=\"10\" value=\"");
-        if (!empty($_GET["fDate"]))
-            printf("%s", $_GET["fDate"]);
-        printf("\">&nbsp;&nbsp;&nbsp;\n");
-*/
-
-        printf("Sequences&nbsp;from&nbsp;<input name=\"fRunMin\" type=\"text\" size=\"6\" maxlength=\"6\" value=\"%s\">\n", $min);
-        printf("to&nbsp;<input name=\"fRunMax\" type=\"text\" size=\"6\" maxlength=\"6\" value=\"%s\">&nbsp;&nbsp;&nbsp;\n", $max);
-
-        printf(" <P>\n");
-
-        printf("Source&nbsp;(<A HREF=\"regexp.html\">regexp</A>)&nbsp;<input name=\"fSourceN\" type=\"text\" size=\"15\" maxlength=\"15\" value=\"");
-        if (!empty($_GET["fSourceN"]))
-            printf("%s", $_GET["fSourceN"]);
-        printf("\">&nbsp;&nbsp;&nbsp;\n");
+        PrintZdRangeMenu($host,$user,$pw,$db);
+        printf("<p>\n");
+        PrintSequRangeMenu($host,$user,$pw,$db);
+        printf("<p>\n");
+        PrintSourceMenu($host,$user,$pw,$db);
+        printf("<p>\n");
+        PrintNightRangeMenu($host,$user,$pw,$db);
+        printf("<p>\n");
 
         printf(" Results:\n");
@@ -591,7 +365,4 @@
         printf(" </select>\n");
         printf(" &nbsp;&nbsp;&nbsp;\n");
-
-        ini_set("mysql.trace_mode", "Off");
-        ini_set("display_errors", "Off");
 
         printf("<input class='Width' type='submit' value='Query Table'>&nbsp;&nbsp;&nbsp;\n");
@@ -601,9 +372,19 @@
         if (strchr($_SERVER["REQUEST_URI"], '?')!=FALSE)
             printf("<input class='Width' type='button' value='Print' onClick='self.location.href=\"%s&fPrintTable=1\"'>&nbsp;&nbsp;&nbsp;\n", $_SERVER["REQUEST_URI"]);
+
+        printf("  </td><td valign='top'>\n");
+
+        PrintLimitsMenu($limitsmean, $limitsmin, $limitsmax, $alias, "yes");
+
+        printf("  </td></tr>\n");
+        printf(" </table>\n");
+
         printf("</form>\n");
         printf("</center>\n");
 
 
-        printf("  </td></tr> </table>\n");
+        ini_set("mysql.trace_mode", "Off");
+        ini_set("display_errors", "Off");
+
 
         printf("</td>\n");
@@ -615,5 +396,5 @@
     }
 
-    function PrintPage($html, $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $limits, $rms, $needs)
+    function PrintPage($html, $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $limitsmean, $limitsmin, $limitsmax, $needs)
     {
         $db_id = mysql_connect($host, $user, $pw);
@@ -632,5 +413,5 @@
         {
             if ($html=="1" || $html=="2")
-                PrintMagicTable($result0, $alias, $rightalign, $limits, $rms, $_GET);
+                PrintMagicTable($result0, $alias, $rightalign, $limitsmean, $limitsmin, $limitsmax, $_GET);
             else
                 PrintText($result0);
@@ -640,9 +421,9 @@
         mysql_close($db_id);
 
-        if ($html=="1")
-            printf("<U><B>submitted query:</B></U><BR>%s<BR>", htmlspecialchars($query0));
+        PrintSubmittedQuery($query0, $html, $db, "old");
     }
 
     include ("include.php");
+    include ("menu.php");
     include ("db.php");
     include ("magicdefs.php");
@@ -656,5 +437,5 @@
         header("Content-Disposition: attachment; filename=query-result.txt");
 
-        PrintPage("0", $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $limits, $rms, $needs);
+        PrintPage("0", $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $limitsmean, $limitsmin, $limitsmax, $needs);
     }
     else
@@ -666,5 +447,5 @@
         InitGet($_GET);
         if (empty($_GET["fPrintTable"]))
-            PrintForm($_GET, $host, $user, $pw, $db, $limits, $rms, $alias);
+            PrintForm($_GET, $host, $user, $pw, $db, $limitsmean, $limitsmin, $limitsmax, $alias);
 
         if ($environment==0)
@@ -673,7 +454,7 @@
         {
             if (empty($_GET["fPrintTable"]))
-                PrintPage("1", $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $limits, $rms, $needs);
-            else
-                PrintPage("2", $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $limits, $rms, $needs);
+                PrintPage("1", $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $limitsmean, $limitsmin, $limitsmax, $needs);
+            else
+                PrintPage("2", $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $limitsmean, $limitsmin, $limitsmax, $needs);
         }
 
Index: trunk/MagicSoft/Mars/datacenter/db/ganymed.php
===================================================================
--- trunk/MagicSoft/Mars/datacenter/db/ganymed.php	(revision 7872)
+++ trunk/MagicSoft/Mars/datacenter/db/ganymed.php	(revision 7873)
@@ -303,6 +303,5 @@
         mysql_close($db_id);
 
-        if ($html=="1")
-            printf("<U><B>submitted query:</B></U><BR>%s<BR>", htmlspecialchars($query0));
+        PrintSubmittedQuery($query0, $html, $db, "old");
     }
 
Index: trunk/MagicSoft/Mars/datacenter/db/include.php
===================================================================
--- trunk/MagicSoft/Mars/datacenter/db/include.php	(revision 7872)
+++ trunk/MagicSoft/Mars/datacenter/db/include.php	(revision 7873)
@@ -118,25 +118,4 @@
 }
 
-function PrintLimitsMenu($limits, $rms, $alias)
-{
-    foreach($limits as $key => $element)
-    {
-        printf("<tr><td>%s</td>\n", $alias[$key]);
-        $mean=$key . "Mean";
-        $limitmean=$_GET[$mean];
-        printf("<td><input name=\"%sMean\" type=\"text\" size=\"6\" maxlength=\"6\" value=\"%s\"></td>\n", $key, $limitmean);
-        if ($rms[$key]=="yes")
-        {
-            $rms2=$key . "Rms";
-            $limitrms=$_GET[$rms2];
-            printf("<td><input name=\"%sRms\" type=\"text\" size=\"6\" maxlength=\"6\" value=\"%s\"></td>\n", $key, $limitrms);
-        }
-        else
-            printf("<td><br></td>\n");
-        printf("</tr>\n");
-    }
-
-}
-
 function PrintPullDown($host, $user, $pw, $db, $table, $name, $index, $descr)
 {
@@ -257,4 +236,17 @@
         printf("\n");
     }
+}
+
+function PrintSubmittedQuery($query0, $html, $db, $old)
+{
+    //diplay query on old websites
+    if (empty($old))
+        printf("<tr class='Block' id='showquery' style='display:none'><td>");
+    else
+        printf("<tr class='Block' id='showquery' style='display:block'><td>");
+    printf("<b>DB:</b> %s <br>", $db);
+    if ($html=="1")
+        printf("<U><B>submitted query:</B></U><BR>%s<BR>", htmlspecialchars($query0));
+    printf("</td></tr>");
 }
 
@@ -323,4 +315,31 @@
 
     if ($_GET["fNumStart"]!=0)
+    {
+        $uri = htmlspecialchars($_SERVER["REQUEST_URI"]);
+        $pos = strpos($uri, "fNumStart");
+        $amp3=FALSE;
+        if ($pos!=FALSE)
+        {
+            $amp1 = substr($uri, 0, $pos-1);
+            $amp2 = substr($uri, $pos);
+            $amp3 = strchr($amp2, "&");
+
+            $uri = $amp1;
+        }
+        $pos = $_GET["fNumStart"]-$rows;
+        if ($pos<0)
+            $pos=0;
+        $uri .= "&fNumStart=" . $pos;
+        if ($amp3!=FALSE)
+            $uri .= $amp3;
+
+        $menu .= "<A HREF='" . $uri . "'><<< Prev</A>\n";
+    }
+
+    $menu .= "&nbsp;&nbsp;&nbsp;---&nbsp;<B>";
+    $menu .= $_GET["fNumStart"];
+    $menu .= "</B>&nbsp;---&nbsp;&nbsp;&nbsp;\n";
+
+    if ($rows==$_GET["fNumResults"])
     {
         $uri = $_SERVER["REQUEST_URI"];
@@ -335,41 +354,14 @@
             $uri = $amp1;
         }
-        $pos = $_GET["fNumStart"]-$rows;
-        if ($pos<0)
-            $pos=0;
-        $uri .= "&fNumStart=" . $pos;
-        if ($amp3!=FALSE)
-            $uri .= $amp3;
-
-        $menu .= "<A HREF='" . $uri . "'><<< Prev</A>\n";
-    }
-
-    $menu .= "&nbsp;&nbsp;&nbsp;---&nbsp;<B>";
-    $menu .= $_GET["fNumStart"];
-    $menu .= "</B>&nbsp;---&nbsp;&nbsp;&nbsp;\n";
-
-    if ($rows==$_GET["fNumResults"])
-    {
-        $uri = $_SERVER["REQUEST_URI"];
-        $pos = strpos($uri, "fNumStart");
-        $amp3=FALSE;
-        if ($pos!=FALSE)
-        {
-            $amp1 = substr($uri, 0, $pos-1);
-            $amp2 = substr($uri, $pos);
-            $amp3 = strchr($amp2, "&");
-
-            $uri = $amp1;
-        }
         $uri .= "&fNumStart=" . ($_GET["fNumStart"]+$rows);
         if ($amp3!=FALSE)
             $uri .= $amp3;
 
-        $menu .= "<A HREF='" . $uri . "'>Next >>></A>\n";
+        $menu .= "<A HREF='" . htmlspecialchars($uri) . "'>Next >>></A>\n";
     }
     return $menu;
 }
 
-function RemoveSortBy($rows)
+function RemoveSortBy()
 {
     $menu = "";
@@ -399,12 +391,25 @@
 }
 
-function PrintMagicTable($result0, $alias, $rightalign, $limits, $rms, $_GET)
+function PrintMagicTable($result0, $alias, $rightalign, $limitsmean, $limitsmin, $limitsmax, $_GET)
 {
     $col   = FALSE;
     $first = TRUE;
 
+    $sigma = array
+        (
+         5    => "#FF9900",
+         3    => "#FFFF66",
+         2    => "#33CC00",
+         1    => "#006600",
+        );
+    $offlimitcolour="#FF0000";
+
+
+
     $menu = CreateMenu(mysql_num_rows($result0));
 
-    printf("\n<center>\n<p>%s<P>\n", $menu);
+    printf("\n<center>\n");
+    if (empty($_GET["fPrintTable"]))
+        printf("<p>%s<P>\n", $menu);
     printf("<table BORDER=\"0\">\n");
     while ($row0 = mysql_fetch_assoc($result0))
@@ -430,6 +435,6 @@
                         $issort="&nbsp;<IMG SRC='up.gif'>";
                 }
-                printf("  <th>&nbsp;<A HREF='%s&fSortBy=%s%s'>%s</A>%s&nbsp;</th>\n",
-                       RemoveSortBy($_SERVER["REQUEST_URI"]), $col, $ord, $key, $issort);
+                printf("  <th>&nbsp;<A HREF='%s&amp;fSortBy=%s%s'>%s</A>%s&nbsp;</th>\n",
+                       htmlspecialchars(RemoveSortBy()), $col, $ord, $key, $issort);
             }
             printf(" </tr>\n\n");
@@ -449,47 +454,70 @@
                 printf("  <td align=\"right\">");
 
-            if (!(empty($limits) && empty($rms)))
+            //determine color of text in cell
+            foreach($limitsmean as $key2 => $element2)
             {
-                foreach($limits as $key2 => $element2)
+                $mean=$key2 . "Mean";
+                $rms2=$key2 . "Rms";
+                if ($key==$alias[$element2] && !empty($_GET[$mean]))
                 {
-                    $mean=$key2 . "Mean";
-                    $rms2=$key2 . "Rms";
-                    if ($key==$alias[$element2] && !empty($_GET[$mean]))
+                    if (!empty($_GET[$rms2]))
                     {
-                        if ($rms[$key2]=="yes")
+                        $colour=$offlimitcolour;
+                        foreach ($sigma as $margin => $newcolour)
                         {
-                            if (!empty($_GET[$rms2]))
-                            {
-                                $min=$_GET[$mean] - $_GET[$rms2];
-                                $max=$_GET[$mean] + $_GET[$rms2];
-                                if ($min < $element && $element < $max)
-                                    printf("<font color='green'>");
-                                else
-                                    printf("<font color='red'>");
-                            }
+                            $min=$_GET[$mean] - ($margin * $_GET[$rms2]);
+                            $max=$_GET[$mean] + ($margin * $_GET[$rms2]);
+                            if ($min < $element && $element < $max)
+                                $colour=$newcolour;
                         }
-                        else
+                        printf("<font color='%s' style='font-weight:bold'>", $colour);
+                    }
+                }
+            }
+
+            foreach($limitsmin as $key2 => $element2)
+            {
+                $limit1=$key2 . "1";
+                $limit2=$key2 . "2";
+                if ($key==$alias[$element2] && !empty($_GET[$limit1]))
+                {
+                    $colour=$offlimitcolour;
+                    if ($_GET[$limit1] <= $element)
+                        $colour=$sigma[1];
+                    else
+                    {
+                        if (!empty($_GET[$limit2]))
                         {
-                            if ($rms[$key2]=="min")
-                            {
-                                if ($_GET[$mean] <= $element)
-                                    printf("<font color='green'>");
-                                else
-                                    printf("<font color='red'>");
-                            }
-
-                            if ($rms[$key2]=="max")
-                            {
-                                if ($_GET[$mean] >= $element)
-                                    printf("<font color='green'>");
-                                else
-                                    printf("<font color='red'>");
-                            }
+                            if ($_GET[$limit2] <= $element)
+                                $colour=$sigma[5];
                         }
                     }
-
+                    printf("<font color='%s' style='font-weight:bold'>", $colour);
+                }
+
+            }
+
+            foreach($limitsmax as $key2 => $element2)
+            {
+                $limit1=$key2 . "1";
+                $limit2=$key2 . "2";
+                if ($key==$alias[$element2] && !empty($_GET[$limit1]))
+                {
+                    $colour=$offlimitcolour;
+                    if ($_GET[$limit1] >= $element)
+                        $colour=$sigma[1];
+                    else
+                    {
+                        if (!empty($_GET[$limit2]))
+                        {
+                            if ($_GET[$limit2] >= $element)
+                                $colour=$sigma[5];
+                        }
+                    }
+                    printf("<font color='%s' style='font-weight:bold'>", $colour);
                 }
             }
 
+            //fill text in cell
             printf("&nbsp;%s&nbsp;</td>\n", str_replace("&ws;", " ", str_replace(" ", "&nbsp;", $element)));
         }
@@ -505,8 +533,10 @@
 
     printf("<P><B>Number of displayed results: %d</B><P><P>\n", mysql_num_rows($result0));
-    printf("%s\n", $menu);
+    if (empty($_GET["fPrintTable"]))
+        printf("%s\n", $menu);
     printf("<P>\n");
     printf("</center>\n");
-    printf("</tr><tr class='Block'><td>\n");
+    printf("</td>\n");
+    printf("</tr>\n");
 }
 
Index: trunk/MagicSoft/Mars/datacenter/db/index-footer.html
===================================================================
--- trunk/MagicSoft/Mars/datacenter/db/index-footer.html	(revision 7872)
+++ trunk/MagicSoft/Mars/datacenter/db/index-footer.html	(revision 7873)
@@ -1,4 +1,2 @@
-</td>
-</tr>
 
 </table>
Index: trunk/MagicSoft/Mars/datacenter/db/index-header.html
===================================================================
--- trunk/MagicSoft/Mars/datacenter/db/index-header.html	(revision 7872)
+++ trunk/MagicSoft/Mars/datacenter/db/index-header.html	(revision 7873)
@@ -15,7 +15,9 @@
      -->
    </style>
+<script type="text/javascript" src="dhtml.js"></script>
+<script type="text/javascript" src="menu.js"></script>
 </head>
 
-<body background="../background.gif" text="#000000" bgcolor="#000099" link="#1122FF" vlink="#8888FF" alink="#FF0000">
+<body onload="getdisplay();" background="../background.gif" text="#000000" bgcolor="#000099" link="#1122FF" vlink="#8888FF" alink="#FF0000">
 &nbsp;
 
@@ -25,31 +27,20 @@
 <td class="Edge"><img SRC="../ecke.gif" ALT=""></td>
 <td class="Header">
-<font size=+1><B>Magic Database</B></font><BR>
+<font size='+1'><B>Magic Database</B></font><BR>
 <hr SIZE=1 NOSHADE WIDTH="80%">
 <A HREF="index.html">H</A>&nbsp;
 <A HREF="http://www.astro.uni-wuerzburg.de/~dorner/datacenter/index.html#db">Docu</A>&nbsp;
 Info:&nbsp;
-<A HREF="runinfo.php">Run</A>&nbsp;
-<A HREF="sequinfo.php">Sequ</A>&nbsp;
-<A HREF="datasetinfo.php">DataSets</A>&nbsp;
-Status:&nbsp;
-<A HREF="statussbs.php">SequBuild</A>&nbsp;
-<A HREF="statusrps.php">RunProc</A>&nbsp;
-<A HREF="statussps.php">SequProc</A>&nbsp;
-<A HREF="printtable.php?fTable=MarsVersion">Mars</A>
+<A HREF="runinfo-aio.php">Run</A>&nbsp;
+<A HREF="sequinfo-aio.php">Sequ</A>&nbsp;
+<A HREF="datasetinfo-aio.php">DataSets</A>&nbsp;
+<A HREF="queryrbk.php">Runbook</A>&nbsp;
 <BR>
 more:&nbsp;
-<A HREF="culminating.php">Culm</A>&nbsp;
-<A HREF="datacheck.php">DataCh</A>&nbsp;
 <A HREF="ganymed.php">Results</A>&nbsp;
 <A HREF="sequence.php">Sequ</A>&nbsp;
 <A HREF="sources.php">Sources</A>&nbsp;
-<A HREF="findoffdata.php">Off</A>&nbsp;
-DB:&nbsp;
-<A HREF="queryrbk.php">Runbook</A>&nbsp;
-<A HREF="index.php">Run</A>&nbsp;
-<A HREF="queryseq.php">Sequ</A>&nbsp;
-<A HREF="querycal.php">Cal</A>&nbsp;
-<A HREF="querystar.php">Star</A>
+<A HREF="statussbs.php">SequBuildStatus</A>&nbsp;
+<A HREF="printtable.php?fTable=MarsVersion">Mars</A>
 <hr SIZE=1 NOSHADE WIDTH="80%">
 </td>
@@ -59,4 +50,5 @@
 <td COLSPAN="2" BGCOLOR="#FFFFFF">
 
+
 <center><table class="Inner" CELLPADDING=15>
 <tr  class="Block">
Index: trunk/MagicSoft/Mars/datacenter/db/index.html
===================================================================
--- trunk/MagicSoft/Mars/datacenter/db/index.html	(revision 7872)
+++ trunk/MagicSoft/Mars/datacenter/db/index.html	(revision 7873)
@@ -32,9 +32,25 @@
 <tr class="Block">
 <td>
-<!--
-<b>Database Access:</b><p>
--->
-<p><A HREF="http://www.astro.uni-wuerzburg.de/~dorner/datacenter/index.html#db">
-Documentation</A></b><p>
+<p>
+Some useful queries:<p>
+<ul>
+<li><A HREF="runinfo-aio.php">Run Information</A></li>
+<li><A HREF="sequinfo-aio.php">Sequence Information</A> (including find-off-data functionalities)</li>
+<li><A HREF="queryrbk.php">Runbook Database</A></li>
+<li><A HREF="datasetinfo-aio.php">Dataset Information</A> 
+(<A HREF="http://www.astro.uni-wuerzburg.de/datacenter/datasets/">dataset files</A>)</li>
+<li><A HREF="ganymed.php">Results of the Automatic Analysis</A> 
+<li><A HREF="sequence.php">Sequence(s)</A>: all information of one sequence in one table </li>
+<li><A HREF="sources.php">Sources - list of sources</A> (possibility to ex/include test- and off-sources)</li>
+<li><A HREF="statussbs.php">Sequence Build Status</A>: querying only the information from the table SequenceBuildStatus </li>
+</ul>
+<p>
+Documentation: <br>
+<a href="http://vela.astro.uni-wuerzburg.de/datacenter/instructions/intern/errorcoding.txt">error coding</a><br>
+<A HREF="http://www.astro.uni-wuerzburg.de/~dorner/datacenter/index.html#db">old documentation</A>
+<p>
+<br>
+<p>
+<u>Old websites:</u> <p>
 Some useful queries:<p>
 <ul>
Index: trunk/MagicSoft/Mars/datacenter/db/index.php
===================================================================
--- trunk/MagicSoft/Mars/datacenter/db/index.php	(revision 7872)
+++ trunk/MagicSoft/Mars/datacenter/db/index.php	(revision 7873)
@@ -384,6 +384,5 @@
         mysql_close($db_id);
 
-        if ($html=="1")
-            printf("<U><B>submitted query:</B></U><BR>%s<BR>", htmlspecialchars($query0));
+        PrintSubmittedQuery($query0, $html, $db, "old");
     }
 
Index: trunk/MagicSoft/Mars/datacenter/db/magicdefs.php
===================================================================
--- trunk/MagicSoft/Mars/datacenter/db/magicdefs.php	(revision 7872)
+++ trunk/MagicSoft/Mars/datacenter/db/magicdefs.php	(revision 7873)
@@ -25,26 +25,35 @@
 
 
-$limits = array
+$limitsmean = array
     (
      "fPedRmsInLimit"    => "fMeanPedRmsInner",
-     "fArrTimeLimit"     => "fArrTimeRmsInner",
+//     "fArrTRmsLimit"     => "fArrTimeRmsInner",
      "fMuonRateLimit"    => "fMuonRate",
+     "fMuonCalLimit"     => "fRatio",
      "fPSFLimit"         => "fPSF",
+     "fInhomLimit"       => "fInhomogeneity",
+     "fNumIslLimit"      => "fMeanNumberIslands",
      "fImgRateLimit"     => "fDataRate",
+     "fSkyBrightLimit"   => "fBrightnessMed",
+    );
+
+$limitsmin = array
+    (
+     "fZdMinLimit"       => "fZenithDistanceMin",
+     "fNumStarsLimit"    => "fNumStarsMed",
+     "fNumStarsCorLimit" => "fNumStarsCorMed",
+     "fMuonNumLimit"     => "fMuonNumber",
+     "fArrTimeLimit"     => "fArrTimeInner",
+     "fPulsePosLimit"    => "fMeanPulsePosInner",
+    );
+
+$limitsmax = array
+    (
+     "fZdMaxLimit"       => "fZenithDistanceMax",
      "fUnsInLimit"       => "fUnsuitableInner",
-     "fZdMinLimit"       => "fZenithDistanceMin",
-     "fZdMaxLimit"       => "fZenithDistanceMax",
-    );
-
-$rms = array
-    (
-     "fPedRmsInLimit"    => "yes",
-     "fArrTimeLimit"     => "yes",
-     "fMuonRateLimit"    => "yes",
-     "fUnsInLimit"       => "max",
-     "fPSFLimit"         => "yes",
-     "fImgRateLimit"     => "yes",
-     "fZdMinLimit"       => "min",
-     "fZdMaxLimit"       => "max",
+     "fIsoInLimit"       => "fIsolatedInner",
+     "fIMCLimit"         => "fIsolatedMaxCluster",
+     "fMaxHumLimit"      => "fMaxHumidity",
+     "fRelTimeLimit"     => "fEffOnTime/fRunTime",
     );
 
@@ -216,4 +225,10 @@
      "fDataRate"                        => "Img.<br>Rate<br>[Hz]",
      "fMaxHumidity"                     => "Max<br>Hum<br>[%]",
+     "fBrightnessMed"                   => "Sky<br>Brightness<br>Med",
+     "fBrightnessRMS"                   => "Sky<br>Brightness<br>RMS",
+     "fNumStarsMed"                     => "#<br>id.<br>stars",
+     "fNumStarsRMS"                     => "RMS<br>id.<br>stars",
+     "fNumStarsCorMed"                  => "#<br>cor.<br>stars",
+     "fNumStarsCorRMS"                  => "RMS<br>cor.<br>stars",
      "fEvents"                          => "DataEvents",
      "fPositionSignal"                  => "ArrTime",
@@ -253,12 +268,25 @@
      "Max(fZenithDistance)"             => "ZdMax",
      "COUNT(*)"                         => "Sequence",
-     "fArrTimeLimit"                    => "ArrTRms",
+//     "fArrTimeLimit"                    => "ArrTRms",
+     "fArrTimeLimit"                    => "ArrTime",
+     "fPulsePosLimit"                   => "PulsePos",
      "fPedRmsInLimit"                   => "PedRms",
      "fMuonRateLimit"                   => "MuonRate",
+     "fMuonNumLimit"                    => "# Muons",
+     "fMuonCalLimit"                    => "MuonCal",
      "fPSFLimit"                        => "PSF",
+     "fInhomLimit"                      => "Inhom.",
+     "fNumIslLimit"                     => "# Islands",
      "fImgRateLimit"                    => "ImgRate",
+     "fSkyBrightLimit"                  => "SkyBrightness",
+     "fNumStarsLimit"                   => "# id. Stars",
+     "fNumStarsCorLimit"                => "# cor. Stars",
      "fUnsInLimit"                      => "Unsuit.In",
+     "fIsoInLimit"                      => "Isol.In",
+     "fIMCLimit"                        => "IMC",
+     "fMaxHumLimit"                     => "Humidity",
      "fZdMinLimit"                      => "ZdMin",
      "fZdMaxLimit"                      => "ZdMax",
+     "fRelTimeLimit"                    => "Rel.Ontime",
      "fEMin"                            => "Emin",
      "fEMax"                            => "Emax",
@@ -321,4 +349,10 @@
      $alias["fDataRate"]                 => "1",
      $alias["fMaxHumidity"]              => "1",
+     $alias["fBrightnessMed"]            => "1",
+     $alias["fBrightnessRMS"]            => "1",
+     $alias["fNumStarsMed"]              => "1",
+     $alias["fNumStarsRMS"]              => "1",
+     $alias["fNumStarsCorMed"]           => "1",
+     $alias["fNumStarsCorRMS"]           => "1",
      $alias["fDate"]                     => "1",
      $alias["fCaCoFileFound"]            => "1",
@@ -466,4 +500,10 @@
          "fDataRate"                         => "Star.fDataRate",
          "fMaxHumidity"                      => "Star.fMaxHumidity",
+         "fBrightnessMed"                    => "Star.fBrightnessMed",
+         "fBrightnessRMS"                    => "Star.fBrightnessRMS",
+         "fNumStarsMed"                      => "Star.fNumStarsMed",
+         "fNumStarsRMS"                      => "Star.fNumStarsRMS",
+         "fNumStarsCorMed"                   => "Star.fNumStarsCorMed",
+         "fNumStarsCorRMS"                   => "Star.fNumStarsCorRMS",
          "fDataSetNumber"                    => $fromtable . ".fDataSetNumber",
          "fDataSetInserted"                  => "DataSetProcessStatus.fDataSetInserted",
@@ -506,5 +546,5 @@
          "Min(fZenithDistance)"              => "'ZdMin'",
          "Max(fZenithDistance)"              => "'ZdMax'",
-//         "COUNT(*)"                          => "'Sequ'",
+         "COUNT(*)"                          => "'Sequence'",
          "fStartTime"                        => "fStartTime",
          "fFailedTime"                       => "fFailedTime",
Index: trunk/MagicSoft/Mars/datacenter/db/menu.js
===================================================================
--- trunk/MagicSoft/Mars/datacenter/db/menu.js	(revision 7873)
+++ trunk/MagicSoft/Mars/datacenter/db/menu.js	(revision 7873)
@@ -0,0 +1,56 @@
+
+ids = new Array( "all", "info", "info2", "stat", "cal", "star", "ranges", "limits", "showquery");
+statarr = new Array( 1, 0, 0, 0, 0, 0, 0, 0, 0);
+
+function setdisplays ()
+{
+    var blub="";
+    for (var i = 0 ; i < ids.length ; i++)
+    {
+        var d = document.getElementById(ids[i]);
+        if (d)
+            d.style.display == 'none' ? statarr[i]=0 : statarr[i]=1;
+        if (i==0)
+            statarr[i]=0;
+        blub=blub+statarr[i];
+    }
+    return blub;
+}
+
+function show(el,img)
+{
+    el.style.display="none";
+    if (img)
+        img.src='../plus.png';
+}
+
+function hide(el,img)
+{
+    el.style.display="block";
+    if (img)
+        img.src='../minus.png';
+}
+
+function showhide (id)
+{
+    var el = document.getElementById(id);
+    var img = document.getElementById(id+"button");
+    el.style.display == 'block' ? show(el,img) : hide(el,img);
+    var soso = document.getElementById("sh");
+    soso.value = setdisplays();
+}
+
+function getdisplay()
+{
+    var stat = document.getElementById("sh");
+    statvalue=stat.value;
+    for (var i = 0 ; i < ids.length ; i++)
+    {
+        var status = statvalue.slice(i,i+1);
+        var el = document.getElementById(ids[i]);
+        var img = document.getElementById(ids[i]+"button");
+        if (!el)
+            continue;
+        status==0 ? show(el,img) : hide(el,img);
+    }
+}
Index: trunk/MagicSoft/Mars/datacenter/db/menu.php
===================================================================
--- trunk/MagicSoft/Mars/datacenter/db/menu.php	(revision 7873)
+++ trunk/MagicSoft/Mars/datacenter/db/menu.php	(revision 7873)
@@ -0,0 +1,942 @@
+<?php
+
+function PrintRunInfoMenu()
+{
+    printf(" <div id=\"info\" style='display:none'>");
+    printf(" <table>\n");
+    printf("  <tr>\n");
+
+    CheckBox("fRunStart",         "Run start time");
+    CheckBox("fL2RatePresc",      "L2 presc Rate");
+    CheckBox("fDaqStoreRate",     "DAQ Storage Rate");
+    CheckBox("fAzimuth",          "Azimuth");
+
+    printf("  </tr><tr>\n");
+
+    CheckBox("fRunStop",          "Run stop time");
+    CheckBox("fL2RateUnpresc",    "L2 unpresc Rate");
+    CheckBox("fDaqTriggerRate",   "DAQ Trigger Rate");
+    CheckBox("fZenithDistance",   "Zenith distance");
+
+    printf("  </tr><tr>\n");
+
+    //        CheckBox("fFormatVersion",    "File format");
+    CheckBox("fNumEvents",        "Num of events");
+    CheckBox("fMeanTriggerRate",  "Mean Trigger rate");
+    CheckBox("fSequenceFirst",    "Sequence Number");
+    CheckBox("fTest",             "incl. TestSources");
+
+    printf("  </tr>\n");
+    printf(" </table>\n");
+    printf(" </div><p>\n");
+}
+
+function PrintRunStatMenu()
+{
+    printf(" <div id=\"stat\" style='display:none'>\n");
+    printf(" <table>\n");
+    printf("  <tr><td>\n");
+
+    PrintStatusMenu("fCCFileAvail",    "CC File available");
+    printf("  </td><td>\n");
+    PrintStatusMenu("fCaCoFileAvail",  "Caco File available");
+    printf("  </td><td>\n");
+    PrintStatusMenu("fRawFileAvail",   "Rawfile available");
+
+    printf("  </td></tr><tr><td>\n");
+
+    PrintStatusMenu("fTimingCorrection",  "Timing Correction");
+    printf("  </td><td>\n");
+    PrintStatusMenu("fCaCoFileFound",     "Caco File");
+    printf("  </td><td>\n");
+    PrintStatusMenu("fDataCheckDone",        "DataCheck");
+
+    printf(" </td></tr></table>\n");
+    printf(" <p>\n");
+    printf(" </div><p>\n");
+}
+
+function PrintRunInfo2Menu($host,$user,$pw,$db)
+{
+    printf(" <div id=\"info2\" style='display:none'>");
+    printf(" <table>\n");
+    printf("  <tr><td>\n");
+    PrintPullDown($host, $user, $pw, $db, "RunType",     "fRunTypeName",     "fRunTypeKEY", "Run type");
+    printf("  </td><td>\n");
+    PrintPullDown($host, $user, $pw, $db, "Source",      "fSourceName",      "fSourceKEY", "Source Name");
+    printf("  </td><td>\n");
+    PrintPullDown($host, $user, $pw, $db, "HvSettings",  "fHvSettingsName",  "fHvSettingsKEY", "HV Settings");
+    printf("  </td><td>\n");
+    PrintPullDown($host, $user, $pw, $db, "L1TriggerTable", "fL1TriggerTableName", "fL1TriggerTableKEY", "L1 Trigger Table");
+    printf("  </td></tr><tr><td>\n");
+    PrintPullDown($host, $user, $pw, $db, "TestFlag",  "fTestFlagName",  "fTestFlagKEY", "Test Flag");
+    printf("  </td><td>\n");
+    PrintPullDown($host, $user, $pw, $db, "Project",     "fProjectName",     "fProjectKEY", "Project Name");
+    printf("  </td><td>\n");
+    PrintPullDown($host, $user, $pw, $db, "DiscriminatorThresholdTable",  "fDiscriminatorThresholdTableName",  "fDiscriminatorThresholdTableKEY", "DT Table");
+    printf("  </td><td>\n");
+    PrintPullDown($host, $user, $pw, $db, "L2TriggerTable", "fL2TriggerTableName", "fL2TriggerTableKEY", "L2 Trigger Table");
+    printf("  </td></tr><tr><td>\n");
+    PrintPullDown($host, $user, $pw, $db, "ExcludedFDA", "fExcludedFDAName", "fExcludedFDAKEY", "Exclusions");
+    printf("  </td><td>\n");
+    PrintPullDown($host, $user, $pw, $db, "LightConditions",  "fLightConditionsName",  "fLightConditionsKEY", "Light Conditions");
+    printf("  </td><td>\n");
+    PrintPullDown($host, $user, $pw, $db, "CalibrationScript",  "fCalibrationScriptName",  "fCalibrationScriptKEY", "Cal Script");
+    printf("  </td><td>\n");
+    PrintPullDown($host, $user, $pw, $db, "TriggerDelayTable",  "fTriggerDelayTableName",  "fTriggerDelayTableKEY", "Trigger Delay Table");
+    printf("  </td></tr><tr><td>\n");
+    PrintPullDown($host, $user, $pw, $db, "MagicNumber", "fMagicNumberName", "fMagicNumberKEY", "Magic Number");
+    printf(" </td></tr></table>\n");
+    printf(" </div><p>\n");
+}
+
+function PrintSequInfoMenu()
+{
+    printf(" <table>\n");
+
+    printf("<tr><td align='center'>\n");
+    printf("  <tr>\n");
+
+    CheckBox("fRunStart",          "Start time");
+    CheckBox("fAzimuthMin",        "Azimuth min");
+    CheckBox("fAzimuthMax",        "Azimuth max");
+    CheckBox("fZenithDistanceMin", "Zenith distance min");
+    CheckBox("fZenithDistanceMax", "Zenith distance max");
+
+    printf("  </tr><tr>\n");
+
+    CheckBox("fNumEvents",         "Num of events");
+    CheckBox("fRunTime/60",        "Duration");
+    CheckBox("fSequenceLast",      "Last run");
+    CheckBox("fLinks",             "Links");
+    CheckBox("fTest",              "incl. TestSources");
+
+    printf("  </tr></table>\n");
+}
+
+function PrintSequInfo2Menu($host,$user,$pw,$db)
+{
+    printf(" <div id='info2' style='display:none'>\n");
+    printf(" <table>\n");
+    printf("  <tr><td>\n");
+    PrintPullDown($host, $user, $pw, $db, "Source",                      "fSourceName",                      "fSourceKEY",                      "Source Name");
+    printf("  </td><td>\n");
+    PrintPullDown($host, $user, $pw, $db, "L1TriggerTable",              "fL1TriggerTableName",              "fL1TriggerTableKEY",              "L1Trigger Table");
+    printf("  </td><td>\n");
+    PrintPullDown($host, $user, $pw, $db, "L2TriggerTable",              "fL2TriggerTableName",              "fL2TriggerTableKEY",              "L2Trigger Table");
+    printf("  </td><td>\n");
+    PrintPullDown($host, $user, $pw, $db, "TriggerDelayTable",           "fTriggerDelayTableName",           "fTriggerDelayTableKEY",           "Trigger Delay Table");
+    printf("  </td></tr><tr><td>\n");
+    PrintPullDown($host, $user, $pw, $db, "LightConditions",             "fLightConditionsName",             "fLightConditionsKEY",             "Light Conditions");
+    printf("  </td><td>\n");
+    PrintPullDown($host, $user, $pw, $db, "Project",                     "fProjectName",                     "fProjectKEY",                     "Project Name");
+    printf("  </td><td>\n");
+    PrintPullDown($host, $user, $pw, $db, "HvSettings",                  "fHvSettingsName",                  "fHvSettingsKEY",                  "HV Settings");
+    printf("  </td><td>\n");
+    PrintPullDown($host, $user, $pw, $db, "DiscriminatorThresholdTable", "fDiscriminatorThresholdTableName", "fDiscriminatorThresholdTableKEY", "DT Table");
+    printf("  </td></tr><tr><td>\n");
+    PrintPullDown($host, $user, $pw, $db, "ManuallyChanged",             "fManuallyChangedName",             "fManuallyChangedKEY",             "Manually changed");
+    printf("  </td><td>\n");
+    PrintPullDown($host, $user, $pw, $db, "TestFlag",                    "fTestFlagName",                    "fTestFlagKEY",                    "Test Flag");
+    printf("  </td></tr>\n");
+    printf(" </table>\n");
+    printf(" </div><p>\n");
+}
+
+function PrintLimitsMenu($limitsmean, $limitsmin, $limitsmax, $alias, $old)
+{
+    printf("  <table>\n");
+    printf("  <tr><th colspan='3'>Limits</th></tr>\n");
+    printf("  <tr><td valign='top'>\n");
+
+    printf("   <table>\n");
+    printf("  <tr><th>Name </th><th> Mean </th><th> Rms </th></tr>\n");
+
+    foreach($limitsmean as $key => $element)
+    {
+        printf("<tr><td>%s</td>\n", $alias[$key]);
+        $mean=$key . "Mean";
+        $limitmean=$_GET[$mean];
+        printf("<td><input name=\"%sMean\" type=\"text\" size=\"6\" maxlength=\"6\" value=\"%s\"></td>\n", $key, $limitmean);
+        $rms2=$key . "Rms";
+        $limitrms=$_GET[$rms2];
+        printf("<td><input name=\"%sRms\" type=\"text\" size=\"6\" maxlength=\"6\" value=\"%s\"></td>\n", $key, $limitrms);
+        printf("</tr>\n");
+    }
+
+    if (empty($old))
+    {
+        printf("  </table>\n");
+        printf("  </td>\n");
+        printf("  <td valign='top'>\n");
+        printf("   <table>\n");
+    }
+
+    printf("  <tr><th>Name </th><th> Min </th><th> Min2 </th></tr>\n");
+    foreach($limitsmin as $key => $element)
+    {
+        printf("<tr><td>%s</td>\n", $alias[$key]);
+        $level1=$key . "1";
+        $limit1=$_GET[$level1];
+        printf("<td><input name=\"%s1\" type=\"text\" size=\"6\" maxlength=\"6\" value=\"%s\"></td>\n", $key, $limit1);
+        $level2=$key . "2";
+        $limit2=$_GET[$level2];
+        printf("<td><input name=\"%s2\" type=\"text\" size=\"6\" maxlength=\"6\" value=\"%s\"></td>\n", $key, $limit2);
+        printf("</tr>\n");
+    }
+
+    if (empty($old))
+    {
+        printf("  </table>\n");
+        printf("  </td>\n");
+        printf("  <td valign='top'>\n");
+        printf("   <table>\n");
+    }
+
+    printf("  <tr><th>Name </th><th> Max </th><th> Max2 </th></tr>\n");
+    foreach($limitsmax as $key => $element)
+    {
+        printf("<tr><td>%s</td>\n", $alias[$key]);
+        $level1=$key . "1";
+        $limit1=$_GET[$level1];
+        printf("<td><input name=\"%s1\" type=\"text\" size=\"6\" maxlength=\"6\" value=\"%s\"></td>\n", $key, $limit1);
+        $level2=$key . "2";
+        $limit2=$_GET[$level2];
+        printf("<td><input name=\"%s2\" type=\"text\" size=\"6\" maxlength=\"6\" value=\"%s\"></td>\n", $key, $limit2);
+        printf("</tr>\n");
+    }
+    printf("  </table>\n");
+
+    printf("  </td></tr></table>\n");
+    printf("<p>\n");
+
+}
+
+function PrintSequStatMenu()
+{
+    printf(" <div id=\"stat\" style='display:none'>\n");
+    printf(" <table><tr><td>\n");
+
+    PrintStatusMenu("fAllFilesAvail",       "Files avail");
+    printf("  </td><td>\n");
+    PrintStatusMenu("fCallisto",            "Callisto");
+    printf("  </td><td>\n");
+    PrintStatusMenu("fStar",                "Star");
+    printf("  </td></tr><tr><td>\n");
+    PrintStatusMenu("fSequenceFileWritten", "Sequfile");
+    printf("  </td><td>\n");
+    PrintStatusMenu("fFillCallisto",        "Fillcallisto");
+    printf("  </td><td>\n");
+    PrintStatusMenu("fFillStar",            "Fillstar");
+
+    printf("</td></tr> </table>\n");
+    printf(" </div><p>\n");
+}
+
+function PrintFailMenu()
+{
+    printf(" <div id=\"fail\" style='display:none'>\n");
+    printf(" <table>\n");
+    printf("  <tr>\n");
+
+    CheckBox("fStartTime",     "StartTime");
+    CheckBox("fFailedTime",    "FailedTime");
+    CheckBox("fReturnCode",    "ErrCode");
+    CheckBox("fFailedCode",    "RetCode");
+    CheckBox("fFailedCodeAdd", "CodeAdd");
+
+    printf("  </tr>\n");
+    printf(" </table>\n");
+    printf(" </div><p>\n");
+}
+
+function PrintCalMenu()
+{
+    printf(" <table>\n");
+    printf("  <tr>\n");
+
+    CheckBox("fUnsuitableInner",     "Unsuitable inner");
+    CheckBox("fUnsuitableOuter",     "Unsuitable outer");
+    CheckBox("fUnreliableInner",     "Unreliable inner");
+    CheckBox("fUnreliableOuter",     "Unreliable outer");
+
+    printf("  </tr><tr>\n");
+
+    CheckBox("fIsolatedInner",       "Isolated inner");
+    CheckBox("fIsolatedOuter",       "Isolated outer");
+    CheckBox("fIsolatedMaxCluster",  "IsolatedMaxCluster");
+
+    printf("  </tr><tr>\n");
+
+    CheckBox("fArrTimeMeanInner",    "ArrTimeMean inner ");
+    CheckBox("fArrTimeMeanOuter",    "ArrTimeMean outer ");
+    CheckBox("fArrTimeRmsInner",     "ArrTimeRms inner ");
+    CheckBox("fArrTimeRmsOuter",     "ArrTimeRms outer ");
+
+    printf("  </tr><tr>\n");
+
+    CheckBox("fMeanPedRmsInner",     "MeanPedRms inner");
+    CheckBox("fMeanPedRmsOuter",     "MeanPedRms outer");
+    CheckBox("fMeanSignalInner",     "MeanSignal inner");
+    CheckBox("fMeanSignalOuter",     "MeanSignal outer");
+
+    printf("  </tr><tr>\n");
+
+    CheckBox("fConvFactorInner",     "Conv inner ");
+    CheckBox("fConvFactorOuter",     "Conv outer ");
+    CheckBox("fPulsePosMean",        "Mean PulsePos");
+
+    printf(" </tr></table>\n");
+}
+
+function PrintStarMenu()
+{
+    printf(" <table>\n");
+    printf("  <tr>\n");
+
+    CheckBox("fDataRate",           "CleanedEvtRate");
+    CheckBox("fMeanNumberIslands",  "MeanNumIslands");
+    CheckBox("fMaxHumidity",        "MaxHumidity");
+    CheckBox("fInhomogeneity",      "Inhomogeneity");
+
+    printf("  </tr><tr>\n");
+
+    CheckBox("fMuonRate",           "MuonRate");
+    CheckBox("fMuonNumber",         "MuonNumber");
+    CheckBox("fRatio",              "Ratio");
+    CheckBox("fPSF",                "PSF");
+
+    printf("  </tr><tr>\n");
+
+    CheckBox("fEffOnTime",          "EffOnTime");
+    CheckBox("fEffOnTime/fRunTime", "RelOnTime");
+    CheckBox("fBrightnessMed",      "SkyBrightnessMed");
+    CheckBox("fBrightnessRMS",      "SkyBrightnessRMS");
+
+    printf("  </tr><tr>\n");
+
+    CheckBox("fNumStarsMed",        "# id. Stars");
+    CheckBox("fNumStarsRMS",        "RMS id. Stars");
+    CheckBox("fNumStarsCorMed",     "# cor. Stars");
+    CheckBox("fNumStarsCorRMS",     "RMS cor. Stars");
+
+    printf("  </tr>\n");
+    printf(" </table>\n");
+}
+
+function PrintDataSetInfoMenu($host,$user,$pw,$db)
+{
+    printf(" <div id=\"info\" style='display:none'>");
+    printf(" <table>\n");
+    printf("  <tr>\n");
+
+    CheckBox("fWobble",           "Wobble");
+    CheckBox("fComment",          "Comment");
+    CheckBox("fScaleFactor",      "Scale");
+    CheckBox("fEffOnTime/3600",   "EffOnTime");
+    CheckBox("fLinks",             "Links");
+
+    printf("  </tr><tr>\n");
+
+    CheckBox("fExcessEvents",     "ExcEvts");
+    CheckBox("fBackgroundEvents", "BgEvts");
+    CheckBox("fSignalEvents",     "SignEvts");
+    CheckBox("fSignificance",     "Sign");
+
+    printf("  </tr><tr>\n");
+
+    CheckBox("fExcessEvents*60/fEffOnTime",                   "ExcRate");
+    CheckBox("fBackgroundEvents*60/fEffOnTime",               "BgRate");
+    CheckBox("fSignalEvents*60/fEffOnTime",                   "SignRate");
+    CheckBox("Round(fSignificance/Sqrt(fEffOnTime/3600),2)",  "SignfRate");
+
+    printf("  </tr>\n");
+    printf(" </table>\n");
+    printf(" </div><p>\n");
+}
+
+function PrintDataSetStatMenu($host,$user,$pw,$db)
+{
+    printf(" <div id=\"stat\" style='display:none'>\n");
+    printf(" <table>\n");
+    printf("  <tr>\n");
+
+    printf("  <td>\n");
+    PrintStatusMenu("fDataSetInserted", "DataSet Inserted");
+    printf("  </td><td>\n");
+    PrintStatusMenu("fStarFilesAvail",  "FilesAvail");
+    printf("  </td><td>\n");
+    PrintStatusMenu("fGanymed",         "Ganymed");
+    printf("  </td><td>\n");
+    PrintStatusMenu("fFillGanymed",     "FillGanymed");
+    printf("  </tr>\n");
+    printf(" </table>\n");
+    printf(" </div><p>\n");
+}
+
+function PrintRunRangeMenu($host,$user,$pw,$db)
+{
+    if (empty($_GET["fRunMin"]))
+        $min = GetMin("fRunNumber", "RunData", $host, $user, $pw, $db);
+    else
+        $min = $_GET["fRunMin"];
+
+    if (empty($_GET["fRunMax"]))
+        $max = GetMax("fRunNumber", "RunData", $host, $user, $pw, $db);
+    else
+        $max = $_GET["fRunMax"];
+
+    printf("Runs&nbsp;from&nbsp;<input name=\"fRunMin\" type=\"text\" size=\"6\" maxlength=\"6\" value=\"%s\">\n", $min);
+    printf("to&nbsp;<input name=\"fRunMax\" type=\"text\" size=\"6\" maxlength=\"6\" value=\"%s\">&nbsp;&nbsp;&nbsp;\n", $max);
+}
+
+function PrintSequRangeMenu($host,$user,$pw,$db)
+{
+    if (empty($_GET["fRunMin"]))
+        $min = GetMin("fSequenceFirst", "Sequences", $host, $user, $pw, $db);
+    else
+            $min = $_GET["fRunMin"];
+
+    if (empty($_GET["fRunMax"]))
+        $max = GetMax("fSequenceFirst", "Sequences", $host, $user, $pw, $db);
+    else
+        $max = $_GET["fRunMax"];
+
+    printf("Sequences&nbsp;from&nbsp;<input name=\"fRunMin\" type=\"text\" size=\"6\" maxlength=\"6\" value=\"%s\">\n", $min);
+    printf("to&nbsp;<input name=\"fRunMax\" type=\"text\" size=\"6\" maxlength=\"6\" value=\"%s\">&nbsp;&nbsp;&nbsp;\n", $max);
+}
+
+function PrintDataSetRangeMenu($host,$user,$pw,$db)
+{
+    if (empty($_GET["fRunMin"]))
+        $min = GetMin("fDataSetNumber", "DataSets", $host, $user, $pw, $db);
+    else
+        $min = $_GET["fRunMin"];
+
+    if (empty($_GET["fRunMax"]))
+        $max = GetMax("fDataSetNumber", "DataSets", $host, $user, $pw, $db);
+    else
+        $max = $_GET["fRunMax"];
+
+    printf("DataSets&nbsp;from&nbsp;<input name=\"fRunMin\" type=\"text\" size=\"6\" maxlength=\"6\" value=\"%s\">\n", $min);
+    printf("to&nbsp;<input name=\"fRunMax\" type=\"text\" size=\"6\" maxlength=\"6\" value=\"%s\">&nbsp;&nbsp;&nbsp;\n", $max);
+}
+
+function PrintZdRangeMenu($host,$user,$pw,$db)
+{
+    if (empty($_GET["fZDMin"]))
+        $zdmin = GetMin("fZenithDistanceMin", "Sequences", $host, $user, $pw, $db);
+    else
+        $zdmin = $_GET["fZDMin"];
+
+    if (empty($_GET["fZDMax"]))
+        $zdmax = GetMax("fZenithDistanceMax", "Sequences", $host, $user, $pw, $db);
+    else
+        $zdmax = $_GET["fZDMax"];
+
+    printf("ZenithDistance&nbsp;from&nbsp;<input name=\"fZDMin\" type=\"text\" size=\"2\" maxlength=\"2\" value=\"%s\">\n", $zdmin);
+    printf("to&nbsp;<input name=\"fZDMax\" type=\"text\" size=\"2\" maxlength=\"2\" value=\"%s\">&nbsp;&nbsp;&nbsp;\n", $zdmax);
+}
+
+function PrintNightRangeMenu($host,$user,$pw,$db)
+{
+    if (empty($_GET["fStartDate"]))
+        $timemin = GetMin("fRunStart", "Sequences", $host, $user, $pw, $db);
+    else
+        $timemin = $_GET["fStartDate"];
+
+    if (empty($_GET["fStopDate"]))
+        $timemax = GetMax("fRunStart", "Sequences", $host, $user, $pw, $db);
+    else
+            $timemax = $_GET["fStopDate"];
+
+    printf("Night&nbsp;(yyyy-mm-dd)&nbsp;from&nbsp;<input name=\"fStartDate\" type=\"text\" size=\"10\" maxlength=\"10\" value=\"%s\">\n", $timemin);
+    printf("to&nbsp;<input name=\"fStopDate\" type=\"text\" size=\"10\" maxlength=\"10\" value=\"%s\">&nbsp;&nbsp;&nbsp;&nbsp;\n", $timemax);
+}
+
+function PrintSourceMenu($host,$user,$pw,$db)
+{
+    printf("Source&nbsp;(<A HREF=\"regexp.html\">regexp</A>)&nbsp;<input name=\"fSourceN\" type=\"text\" size=\"15\" maxlength=\"15\" value=\"");
+    if (!empty($_GET["fSourceN"]))
+        printf("%s", $_GET["fSourceN"]);
+    printf("\">&nbsp;&nbsp;&nbsp;\n");
+}
+function PrintSequMenu($host,$user,$pw,$db)
+{
+    printf("Sequ#&nbsp;<input name=\"fSequenceNo\" type=\"text\" size=\"6\" maxlength=\"6\" value=\"");
+    if (!empty($_GET["fSequenceNo"]))
+        printf("%s", $_GET["fSequenceNo"]);
+    printf("\">&nbsp;&nbsp;&nbsp;\n");
+}
+
+function PrintNumResPullDown()
+{
+    printf(" Results:\n");
+    printf(" <select name=\"fNumResults\">\n");
+
+    $numres = array("10", "20", "50", "100", "200", "500");
+    foreach ($numres as $element)
+    {
+        if ($element==$_GET["fNumResults"])
+            printf("<option value=\"%s\" selected>%3s</option>\n", $element, $element);
+        else
+            printf("<option value=\"%s\">%3s</option>\n", $element, $element);
+    }
+    printf(" </select>\n");
+    printf(" &nbsp;&nbsp;&nbsp;\n");
+}
+
+function PrintButtons($page)
+{
+    printf("<input class='Width' type='submit' value='Query Table'>&nbsp;&nbsp;&nbsp;\n");
+    printf("<input class='Width' type='button' value='Reset' onClick='self.location.href=\"%s\"'>&nbsp;&nbsp;&nbsp;\n", $page);
+//    printf("<p>");
+    if (strchr($_SERVER["REQUEST_URI"], '?')!=FALSE)
+        printf("<input class='Width' type='button' value='Get .txt' onClick='self.location.href=\"%s&amp;fSendTxt=1\"'>&nbsp;&nbsp;&nbsp;\n", htmlspecialchars($_SERVER["REQUEST_URI"]));
+    if (strchr($_SERVER["REQUEST_URI"], '?')!=FALSE)
+    {
+        printf("<input class='Width' type='button' value='Print' onClick='self.location.href=\"%s&amp;fPrintTable=1\"'>&nbsp;&nbsp;&nbsp;\n", htmlspecialchars($_SERVER["REQUEST_URI"]));
+        printf("MySqlQuery: <img id='showquerybutton' src='../plus.png' alt='+' onClick='showhide(\"showquery\")'>\n");
+    }
+}
+
+function InitFailInfo($_GET)
+{
+    if (empty($_GET["fStartTime"]))
+        $_GET["fStartTime"]="Off";
+
+    if (empty($_GET["fFailedTime"]))
+        $_GET["fFailedTime"]="Off";
+
+    if (empty($_GET["fReturnCode"]))
+        $_GET["fReturnCode"]="Off";
+
+    if (empty($_GET["fFailedCode"]))
+        $_GET["fFailedCode"]="Off";
+
+    if (empty($_GET["fFailedCodeAdd"]))
+        $_GET["fFailedCodeAdd"]="Off";
+}
+
+function InitInfo($_GET)
+{
+    if (empty($_GET["fNumResults"]))
+        $_GET["fNumResults"]="20";
+
+    if (empty($_GET["fNumEvents"]))
+        $_GET["fNumEvents"]="Off";
+
+    if (empty($_GET["fRunStart"]))
+        $_GET["fRunStart"]="Off";
+
+    if (empty($_GET["fTest"]))
+        $_GET["fTest"]="Off";
+
+    if (empty($_GET["fSourceName"]))
+        $_GET["fSourceName"]="Off";
+
+    if (empty($_GET["fProjectName"]))
+        $_GET["fProjectName"]="Off";
+
+    if (empty($_GET["fL1TriggerTableName"]))
+        $_GET["fL1TriggerTableName"]="Off";
+
+    if (empty($_GET["fL2TriggerTableName"]))
+        $_GET["fL2TriggerTableName"]="Off";
+
+    if (empty($_GET["fHvSettingsName"]))
+        $_GET["fHvSettingsName"]="Off";
+
+    if (empty($_GET["fDiscriminatorThresholdTableName"]))
+        $_GET["fDiscriminatorThresholdTableName"]="Off";
+
+    if (empty($_GET["fTriggerDelayTableName"]))
+        $_GET["fTriggerDelayTableName"]="Off";
+
+    if (empty($_GET["fLightConditionsName"]))
+        $_GET["fLightConditionsName"]="Off";
+
+    if (empty($_GET["fTestFlagName"]))
+        $_GET["fTestFlagName"]="Off";
+}
+
+function InitRunStatus($_GET)
+{
+   if (empty($_GET["fDataCheckDone"]))
+        $_GET["fDataCheckDone"]="Off";
+
+    if (empty($_GET["fDataCheckDoneStatus"]))
+        $_GET["fDataCheckDoneStatus"]="0";
+
+    if (empty($_GET["fCCFileAvail"]))
+        $_GET["fCCFileAvail"]="Off";
+
+    if (empty($_GET["fCCFileAvailStatus"]))
+        $_GET["fCCFileAvailStatus"]="0";
+
+    if (empty($_GET["fCaCoFileAvail"]))
+        $_GET["fCaCoFileAvail"]=$first?"On":"";
+
+    if (empty($_GET["fCaCoFileAvailStatus"]))
+        $_GET["fCaCoFileAvailStatus"]="0";
+
+    if (empty($_GET["fCaCoFileFound"]))
+        $_GET["fCaCoFileFound"]="Off";
+
+    if (empty($_GET["fCaCoFileFoundStatus"]))
+        $_GET["fCaCoFileFoundStatus"]="0";
+
+    if (empty($_GET["fRawFileAvail"]))
+        $_GET["fRawFileAvail"]="Off";
+
+    if (empty($_GET["fRawFileAvailStatus"]))
+        $_GET["fRawFileAvailStatus"]="0";
+
+    if (empty($_GET["fTimingCorrection"]))
+        $_GET["fTimingCorrection"]="Off";
+
+    if (empty($_GET["fTimingCorrectionStatus"]))
+        $_GET["fTimingCorrectionStatus"]="0";
+}
+
+function InitRunInfo($_GET)
+{
+    InitRunStatus($_GET);
+    InitInfo($_GET);
+    InitFailInfo($_GET);
+
+    if (empty($_GET["fFormatVersion"]))
+        $_GET["fFormatVersion"]="Off";
+
+    if (empty($_GET["fRunStop"]))
+        $_GET["fRunStop"]="Off";
+
+    if (empty($_GET["fAzimuth"]))
+        $_GET["fAzimuth"]="Off";
+
+    if (empty($_GET["fZenithDistance"]))
+        $_GET["fZenithDistance"]="Off";
+
+    if (empty($_GET["fRunTypeName"]))
+        $_GET["fRunTypeName"]="Off";
+
+    if (empty($_GET["fExcludedFDAName"]))
+        $_GET["fExcludedFDAName"]="Off";
+
+    if (empty($_GET["fMagicNumberName"]))
+        $_GET["fMagicNumberName"]="Off";
+
+    if (empty($_GET["fMeanTriggerRate"]))
+        $_GET["fMeanTriggerRate"]="Off";
+
+    if (empty($_GET["fCalibrationScriptName"]))
+        $_GET["fCalibrationScriptName"]="Off";
+
+    if (empty($_GET["fTestFlagName"]))
+        $_GET["fTestFlagName"]="Off";
+
+    if (empty($_GET["fDaqStoreRate"]))
+        $_GET["fDaqStoreRate"]="Off";
+
+    if (empty($_GET["fDaqTriggerRate"]))
+        $_GET["fDaqTriggerRate"]="Off";
+
+    if (empty($_GET["fL2RatePresc"]))
+        $_GET["fL2RatePresc"]="Off";
+
+    if (empty($_GET["fL2RateUnpresc"]))
+        $_GET["fL2RateUnpresc"]="Off";
+
+    if (empty($_GET["fSequenceFirst"]))
+        $_GET["fSequenceFirst"]="Off";
+
+    if (empty($_GET["fSequenceNo"]))
+        $_GET["fSequenceNo"]="";
+}
+
+function InitSequStatus($_GET)
+{
+    if (empty($_GET["fSequenceFileWritten"]))
+        $_GET["fSequenceFileWritten"]="Off";
+
+    if (empty($_GET["fSequenceFileWrittenStatus"]))
+        $_GET["fSequenceFileWrittenStatus"]="0";
+
+    if (empty($_GET["fAllFilesAvail"]))
+        $_GET["fAllFilesAvail"]="Off";
+
+    if (empty($_GET["fAllFilesAvailStatus"]))
+        $_GET["fAllFilesAvailStatus"]="0";
+
+    if (empty($_GET["fCallisto"]))
+        $_GET["fCallisto"]="Off";
+
+    if (empty($_GET["fCallistoStatus"]))
+        $_GET["fCallistoStatus"]="0";
+
+    if (empty($_GET["fFillCallisto"]))
+        $_GET["fFillCallisto"]="Off";
+
+    if (empty($_GET["fFillCallistoStatus"]))
+        $_GET["fFillCallistoStatus"]="0";
+
+    if (empty($_GET["fStar"]))
+        $_GET["fStar"]="Off";
+
+    if (empty($_GET["fStarStatus"]))
+        $_GET["fStarStatus"]="0";
+
+    if (empty($_GET["fFillStar"]))
+        $_GET["fFillStar"]="Off";
+
+    if (empty($_GET["fFillStarStatus"]))
+        $_GET["fFillStarStatus"]="0";
+}
+
+function InitStarInfo($_GET)
+{
+    if (empty($_GET["fMeanNumberIslands"]))
+        $_GET["fMeanNumberIslands"]="Off";
+
+    if (empty($_GET["fPSF"]))
+        $_GET["fPSF"]="Off";
+
+    if (empty($_GET["fRatio"]))
+        $_GET["fRatio"]="Off";
+
+    if (empty($_GET["fMuonNumber"]))
+        $_GET["fMuonNumber"]="Off";
+
+    if (empty($_GET["fEffOnTime"]))
+        $_GET["fEffOnTime"]="Off";
+
+    if (empty($_GET["fEffOnTime/fRunTime"]))
+        $_GET["fEffOnTime/fRunTime"]="Off";
+
+    if (empty($_GET["fMuonRate"]))
+        $_GET["fMuonRate"]="Off";
+
+    if (empty($_GET["fInhomogeneity"]))
+        $_GET["fInhomogeneity"]="Off";
+
+    if (empty($_GET["fDataRate"]))
+        $_GET["fDataRate"]="Off";
+
+    if (empty($_GET["fMaxHumidity"]))
+        $_GET["fMaxHumidity"]="Off";
+}
+
+function InitCalInfo($_GET)
+{
+    if (empty($_GET["fUnreliableInner"]))
+        $_GET["fUnreliableInner"]="Off";
+
+    if (empty($_GET["fUnsuitableOuter"]))
+        $_GET["fUnsuitableOuter"]="Off";
+
+    if (empty($_GET["fUnreliableOuter"]))
+        $_GET["fUnreliableOuter"]="Off";
+
+    if (empty($_GET["fUnsuitableInner"]))
+        $_GET["fUnsuitableInner"]="Off";
+
+    if (empty($_GET["fIsolatedInner"]))
+        $_GET["fIsolatedInner"]="Off";
+
+    if (empty($_GET["fIsolatedOuter"]))
+        $_GET["fIsolatedOuter"]="Off";
+
+    if (empty($_GET["fMeanPedRmsInner"]))
+        $_GET["fMeanPedRmsInner"]="Off";
+
+    if (empty($_GET["fMeanPedRmsOuter"]))
+        $_GET["fMeanPedRmsOuter"]="Off";
+
+    if (empty($_GET["fIsolatedMaxCluster"]))
+        $_GET["fIsolatedMaxCluster"]="Off";
+
+    if (empty($_GET["fArrTimeMeanInner"]))
+        $_GET["fArrTimeMeanInner"]="Off";
+
+    if (empty($_GET["fArrTimeMeanOuter"]))
+        $_GET["fArrTimeMeanOuter"]="Off";
+
+    if (empty($_GET["fArrTimeRmsInner"]))
+        $_GET["fArrTimeRmsInner"]="Off";
+
+    if (empty($_GET["fArrTimeRmsOuter"]))
+        $_GET["fArrTimeRmsOuter"]="Off";
+
+    if (empty($_GET["fMeanSignalInner"]))
+        $_GET["fMeanSignalInner"]=$first?"Off":"";
+
+    if (empty($_GET["fMeanSignalOuter"]))
+        $_GET["fMeanSignalOuter"]=$first?"Off":"";
+
+    if (empty($_GET["fPulsePosMean"]))
+        $_GET["fPulsePosMean"]=$first?"Off":"";
+
+    if (empty($_GET["fConvFactorInner"]))
+        $_GET["fConvFactorInner"]="Off";
+
+    if (empty($_GET["fConvFactorOuter"]))
+        $_GET["fConvFactorOuter"]="Off";
+}
+
+function InitSequInfo($_GET)
+{
+    InitInfo($_GET);
+    InitSequStatus($_GET);
+    InitFailInfo($_GET);
+    InitCalInfo($_GET);
+    InitStarInfo($_GET);
+
+    if (empty($_GET["fRunTime/60"]))
+        $_GET["fRunTime/60"]="Off";
+
+    if (empty($_GET["fSequenceLast"]))
+        $_GET["fSequenceLast"]="Off";
+
+    if (empty($_GET["fLinks"]))
+        $_GET["fLinks"]="Off";
+
+    if (empty($_GET["fAzimuthMin"]))
+        $_GET["fAzimuthMin"]="Off";
+
+    if (empty($_GET["fAzimuthMax"]))
+        $_GET["fAzimuthMax"]="Off";
+
+    if (empty($_GET["fZenithDistanceMin"]))
+        $_GET["fZenithDistanceMin"]="Off";
+
+    if (empty($_GET["fZenithDistanceMax"]))
+        $_GET["fZenithDistanceMax"]="Off";
+
+    if (empty($_GET["fManuallyChangedName"]))
+        $_GET["fManuallyChangedName"]="Off";
+}
+
+function InitDataSetStatus($_GET)
+{
+    if (empty($_GET["fDataSetInserted"]))
+        $_GET["fDataSetInserted"]="Off";
+
+    if (empty($_GET["fDataSetInsertedStatus"]))
+        $_GET["fDataSetInsertedStatus"]="0";
+
+    if (empty($_GET["fStarFilesAvail"]))
+        $_GET["fStarFilesAvail"]="Off";
+
+    if (empty($_GET["fStarFilesAvailStatus"]))
+        $_GET["fStarFilesAvailStatus"]="0";
+
+    if (empty($_GET["fGanymed"]))
+        $_GET["fGanymed"]=$first?"On":"";
+
+    if (empty($_GET["fGanymedStatus"]))
+        $_GET["fGanymedStatus"]="0";
+
+    if (empty($_GET["fFillGanymed"]))
+        $_GET["fFillGanymed"]="Off";
+
+    if (empty($_GET["fFillGanymedStatus"]))
+        $_GET["fFillGanymedStatus"]="0";
+}
+
+function InitDataSetInfo($_GET)
+{
+    InitDataSetStatus($_GET);
+    InitFailInfo($_GET);
+
+    if (empty($_GET["fNumResults"]))
+        $_GET["fNumResults"]="50";
+
+    if (empty($_GET["fSourceName"]))
+        $_GET["fSourceName"]="Off";
+
+    if (empty($_GET["fLinks"]))
+        $_GET["fLinks"]="Off";
+
+    if (empty($_GET["fComment"]))
+        $_GET["fComment"]="Off";
+
+    if (empty($_GET["fWobble"]))
+        $_GET["fWobble"]="Off";
+
+    if (empty($_GET["fExcessEvents"]))
+        $_GET["fExcessEvents"]="Off";
+
+    if (empty($_GET["fExcessEvents*60/fEffOnTime"]))
+        $_GET["fExcessEvents*60/fEffOnTime"]="Off";
+
+    if (empty($_GET["fBackgroundEvents*60/fEffOnTime"]))
+        $_GET["fBackgroundEvents*60/fEffOnTime"]="Off";
+
+    if (empty($_GET["fBackgroundEvents"]))
+        $_GET["fBackgroundEvents"]="Off";
+
+    if (empty($_GET["fSignalEvents"]))
+        $_GET["fSignalEvents"]="Off";
+
+    if (empty($_GET["fSignalEvents*60/fEffOnTime"]))
+        $_GET["fSignalEvents*60/fEffOnTime"]="Off";
+
+    if (empty($_GET["fSignificance"]))
+        $_GET["fSignificance"]="Off";
+
+    if (empty($_GET["Round(fSignificance/Sqrt(fEffOnTime/3600),2)"]))
+        $_GET["Round(fSignificance/Sqrt(fEffOnTime/3600),2)"]="Off";
+
+    if (empty($_GET["fScaleFactor"]))
+        $_GET["fScaleFactor"]="Off";
+
+    if (empty($_GET["fEffOnTime/3600"]))
+        $_GET["fEffOnTime/3600"]="Off";
+}
+
+function InitFindOffData($_GET)
+{
+    InitSequInfo($_GET);
+
+    if (empty($_GET["fArrTimeLimitMean"]))
+        $_GET["fArrTimeLimitMean"]="";
+
+    if (empty($_GET["fArrTimeLimitRms"]))
+        $_GET["fArrTimeLimitRms"]="";
+
+    if (empty($_GET["fPedRmsInLimitMean"]))
+        $_GET["fPedRmsInLimitMean"]="";
+
+    if (empty($_GET["fPedRmsInLimitRms"]))
+        $_GET["fPedRmsInLimitRms"]="";
+
+    if (empty($_GET["fMuonRateLimitMean"]))
+        $_GET["fMuonRateLimitMean"]="";
+
+    if (empty($_GET["fMuonRateLimitRms"]))
+        $_GET["fMuonRateLimitRms"]="";
+
+    if (empty($_GET["fImgRateLimitMean"]))
+        $_GET["fImgRateLimitMean"]="";
+
+    if (empty($_GET["fImgRateLimitRms"]))
+        $_GET["fImgRateLimitRms"]="";
+
+    if (empty($_GET["fPSFLimitMean"]))
+        $_GET["fPSFLimitMean"]="";
+
+    if (empty($_GET["fPSFLimitRms"]))
+        $_GET["fPSFLimitRms"]="";
+
+    if (empty($_GET["fUnsInLimitMean"]))
+        $_GET["fUnsInLimitMean"]="";
+
+    if (empty($_GET["fZdMinLimitMean"]))
+        $_GET["fZdMinLimitMean"]="";
+
+    if (empty($_GET["fZdMaxLimitMean"]))
+        $_GET["fZdMaxLimitMean"]="";
+}
+
+
+?>
Index: trunk/MagicSoft/Mars/datacenter/db/printtable.php
===================================================================
--- trunk/MagicSoft/Mars/datacenter/db/printtable.php	(revision 7872)
+++ trunk/MagicSoft/Mars/datacenter/db/printtable.php	(revision 7873)
@@ -51,6 +51,5 @@
         mysql_close($db_id);
 
-        if ($html=="1")
-            printf("<U><B>submitted query:</B></U><BR>%s<BR>", $query0);
+        PrintSubmittedQuery($query0, $html, $db, "old");
     }
 
Index: trunk/MagicSoft/Mars/datacenter/db/querycal.php
===================================================================
--- trunk/MagicSoft/Mars/datacenter/db/querycal.php	(revision 7872)
+++ trunk/MagicSoft/Mars/datacenter/db/querycal.php	(revision 7873)
@@ -207,6 +207,5 @@
         mysql_close($db_id);
 
-        if ($html=="1")
-            printf("<U><B>submitted query:</B></U><BR>%s<BR>", htmlspecialchars($query0));
+        PrintSubmittedQuery($query0, $html, $db, "old");
     }
 
Index: trunk/MagicSoft/Mars/datacenter/db/queryrbk.php
===================================================================
--- trunk/MagicSoft/Mars/datacenter/db/queryrbk.php	(revision 7872)
+++ trunk/MagicSoft/Mars/datacenter/db/queryrbk.php	(revision 7873)
@@ -80,6 +80,5 @@
         mysql_close($db_id);
 
-        if ($html=="1")
-            printf("<U><B>submitted query:</B></U><BR>%s<BR>", $query0);
+        PrintSubmittedQuery($query0, $html, $db, "old");
     }
 
Index: trunk/MagicSoft/Mars/datacenter/db/queryseq.php
===================================================================
--- trunk/MagicSoft/Mars/datacenter/db/queryseq.php	(revision 7872)
+++ trunk/MagicSoft/Mars/datacenter/db/queryseq.php	(revision 7873)
@@ -326,6 +326,5 @@
         mysql_close($db_id);
 
-        if ($html=="1")
-            printf("<U><B>submitted query:</B></U><BR>%s<BR>", htmlspecialchars($query0));
+        PrintSubmittedQuery($query0, $html, $db, "old");
     }
 
Index: trunk/MagicSoft/Mars/datacenter/db/querystar.php
===================================================================
--- trunk/MagicSoft/Mars/datacenter/db/querystar.php	(revision 7872)
+++ trunk/MagicSoft/Mars/datacenter/db/querystar.php	(revision 7873)
@@ -172,6 +172,5 @@
         mysql_close($db_id);
 
-        if ($html=="1")
-            printf("<U><B>submitted query:</B></U><BR>%s<BR>", htmlspecialchars($query0));
+        PrintSubmittedQuery($query0, $html, $db, "old");
     }
 
Index: trunk/MagicSoft/Mars/datacenter/db/runinfo-aio.php
===================================================================
--- trunk/MagicSoft/Mars/datacenter/db/runinfo-aio.php	(revision 7873)
+++ trunk/MagicSoft/Mars/datacenter/db/runinfo-aio.php	(revision 7873)
@@ -0,0 +1,345 @@
+<?php
+{
+    function CreateQuery($_GET, $alias, $checkwhere, $checkgroup, $checkstatusgroup, $needs)
+    {
+        $fromtable="RunData";
+
+        $groups = 0;
+        foreach ($checkgroup as $element)
+            if ($element==-1)
+                $groups++;
+
+        $statusgroups = 0;
+        foreach ($checkstatusgroup as $element)
+            if ($element==-1)
+                $statusgroups++;
+
+        $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 ($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 . "), 'not done' ,if(" . $key . "='1970-01-01 00:00:00','dont do','done'))) as '" . $alias[$key] . "', ";
+
+                $query0 .= " count(*) as 'Run#'";
+
+            }
+            else
+            {
+                $query0 .= " RunData.fRunNumber as 'Run#' ";
+
+                foreach ($_GET as $key => $element)
+                    if ($_GET[$key]=="On" && $key!="fTest")
+                        if (empty($checkwhere[$key]) || $checkwhere[$key]==0)
+                            $query0 .= ", " . $key . " as '" . $alias[$key] . "' ";
+            }
+        }
+
+        $query0 .= " FROM RunData ";
+
+        $query0 .= " LEFT JOIN RunProcessStatus ON RunData.fRunNumber=RunProcessStatus.fRunNumber ";
+
+        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 ON Sequences.fSourceKEY=Source.fSourceKEY ";
+            $query0 .= " WHERE fTest='no'";
+        }
+
+        foreach ($checkwhere as $key => $element)
+        {
+            if (empty($element) || $element<=0)
+                continue;
+
+            if (strpos($query0, " WHERE ")==FALSE)
+                $query0 .= " WHERE ";
+            else
+                if ($element!=-1)
+                    if (strrpos($query0, " AND ")!=strlen($query0)-5)// this if clause doesn't work
+                        $query0 .= " AND ";
+
+            if ($element!=-1)
+                $query0 .= GetCheck($fromtable, $key) . "=" . $element;
+        }
+
+        if (strpos($query0, " WHERE ")==FALSE)
+            $query0 .= " WHERE ";
+        else
+            $query0 .= " AND ";
+
+        $query0 .= StatusQuery("fCCFileAvail", $needs);
+        $query0 .= StatusQuery("fCaCoFileAvail", $needs);
+        $query0 .= StatusQuery("fCaCoFileFound", $needs);
+        $query0 .= StatusQuery("fRawFileAvail", $needs);
+        $query0 .= StatusQuery("fDataCheckDone", $needs);
+        $query0 .= StatusQuery("fTimingCorrection", $needs);
+
+        if (!empty($_GET["fRunMin"]) && !empty($_GET["fRunMax"]))
+            $query0 .= "RunData.fRunNumber BETWEEN " . $_GET["fRunMin"] . " AND " . $_GET["fRunMax"] . " ";
+
+        if (!empty($_GET["fZDMin"]) && !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"] . "' ";
+        }
+
+
+        if ($groups>0)
+        {
+            $query0 .= " GROUP BY ";
+            $num = $groups;
+            foreach ($checkgroup as $key => $element)
+                if ($element==-1)
+                {
+                    $query0 .= GetCheck($fromtable,$key);
+                    if ($num-->1)
+                        $query0 .= ", ";
+                }
+        }
+
+        if ($statusgroups>0)
+        {
+            $query0 .= " GROUP BY ";
+            $num = $statusgroups;
+            foreach ($checkstatusgroup as $key => $element)
+                if ($element==-1)
+                {
+                    $query0 .= $alias[$key];
+                    if ($num-->1)
+                        $query0 .= ", ";
+                }
+        }
+
+        if (!empty($_GET["fSortBy"]))
+        {
+            $val=substr($_GET["fSortBy"], 0, -1);
+            $query0 .= " ORDER BY " . GetTable($fromtable, $val) . " ";
+            if (substr($_GET["fSortBy"], -1)=="-")
+                $query0 .= "DESC";
+        }
+
+        if (empty($_GET["fNumStart"]))
+            $_GET["fNumStart"]=0;
+
+        if (empty($_GET["fSendTxt"]))
+            $query0 .= " LIMIT " . $_GET["fNumStart"] . ", " . $_GET["fNumResults"];
+
+        return $query0;
+    }
+
+    function InitGet($_GET)
+    {
+        // Find out whether it is the first call to the php script
+        $first = empty($_GET["fRunMin"]) && empty($_GET["fRunMax"]);
+
+        if (empty($_GET["fNumResults"]))
+            $_GET["fNumResults"]="20";
+
+        if (empty($_GET["fTest"]))
+            $_GET["fTest"]=$first?"On":"";
+
+        if (empty($_GET["fNumEvents"]))
+            $_GET["fNumEvents"]=$first?"On":"";
+
+        if (empty($_GET["fRunStart"]))
+            $_GET["fRunStart"]=$first?"On":"";
+
+        if (empty($_GET["fZenithDistance"]))
+            $_GET["fZenithDistance"]=$first?"On":"";
+
+        if (empty($_GET["fRunTypeName"]))
+            $_GET["fRunTypeName"]=$first?"On":"";
+
+        if (empty($_GET["fSourceName"]))
+            $_GET["fSourceName"]=$first?"On":"";
+
+        if (empty($_GET["fMeanTriggerRate"]))
+            $_GET["fMeanTriggerRate"]=$first?"On":"";
+
+        if (empty($_GET["fExcludedFDAName"]))
+            $_GET["fExcludedFDAName"]=$first?"On":"";
+
+        if (empty($_GET["fSequenceNo"]))
+            $_GET["fSequenceNo"]="";
+
+        InitRunInfo($_GET);
+    }
+
+    function PrintForm($_GET, $host, $user, $pw, $db)
+    {
+        printf("<center>\n");
+        printf("<form action=\"runinfo-aio.php\" METHOD=\"GET\">\n");
+
+        printf("<input id='sh' type='hidden' name='fShowHide' value='");
+        if (!empty($_GET["fShowHide"]))
+            printf("%s", $_GET["fShowHide"]);
+        else
+            printf("100000000");
+        printf("'>\n");
+        printf("<img id='allbutton'    src='../minus.png' onclick=showhide('all')>                   Menu       \n");
+        printf("<img id='infobutton'   src='../plus.png'  onClick=showhide('info');showhide('info2')>RunInfo    \n");
+        printf("<img id='statbutton'   src='../plus.png'  onClick=showhide('stat');showhide('fail')> StatusInfo \n");
+        printf("<img id='rangesbutton' src='../plus.png'  onClick=showhide('ranges')>                Ranges     \n");
+
+        printf(" <div id='all' style='display:block'>");
+        PrintRunInfoMenu();
+        PrintRunInfo2Menu($host,$user,$pw,$db);
+        PrintRunStatMenu();
+        PrintFailMenu();
+        printf(" <div id='ranges' style='display:none'>");
+        PrintSequMenu($host,$user,$pw,$db);
+        PrintNightRangeMenu($host,$user,$pw,$db);
+        printf("<p>");
+        PrintZdRangeMenu($host,$user,$pw,$db);
+        PrintRunRangeMenu($host,$user,$pw,$db);
+        printf(" <P>\n");
+        PrintSourceMenu($host,$user,$pw,$db);
+        PrintNumResPullDown();
+        printf("<p>");
+        printf("</div>");
+        printf("</div>");
+        printf(" <P>\n");
+
+        ini_set("mysql.trace_mode", "Off");
+        ini_set("display_errors", "Off");
+
+        PrintButtons("runinfo-aio.php");
+
+        printf("</form>\n");
+        printf("</center>\n");
+        printf("</td>\n");
+        printf("</tr>\n");
+        printf("<tr class='Block'>\n");
+        printf("<td>\n");
+    }
+
+    function PrintPage($html, $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $needs)
+    {
+        $db_id = mysql_connect($host, $user, $pw);
+        if ($db_id==FALSE)
+        {
+            printf("mysql_connect returned the following error: %s\n", mysql_error());
+            die("");
+        }
+        mysql_select_db($db);
+        mysql_query("SET BIG_TABLES=1"); // necessary for mySQL <= 4
+
+        $query0 = CreateQuery($_GET, $alias, $checkwhere, $checkgroup, $checkstatusgroup, $needs);
+
+        $result0 = mysql_query($query0, $db_id);
+
+        if ($result0)
+        {
+            if ($html=="1" || $html=="2")
+                PrintMagicTable($result0, $alias, $rightalign, "", "", $_GET);
+            else
+                PrintText($result0);
+
+            mysql_free_result($result0);
+        }
+        mysql_close($db_id);
+
+        PrintSubmittedQuery($query0, $html, $db);
+    }
+
+    include ("include.php");
+    include ("db.php");
+    include ("menu.php");
+    include ("magicdefs.php");
+
+    ini_set("display_errors",   "On");
+    ini_set("mysql.trace_mode", "On");
+
+    if (!empty($_GET["fSendTxt"]))
+    {
+        header("Content-type: application/octet");
+        header("Content-Disposition: attachment; filename=query-result.txt");
+
+        PrintPage("0", $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $needs);
+    }
+    else
+    {
+        echo (file_get_contents("index-header.html"));
+
+        $environment = sizeof($_GET);
+
+        InitGet($_GET);
+        if (empty($_GET["fPrintTable"]))
+            PrintForm($_GET, $host, $user, $pw, $db);
+
+        if ($environment==0)
+            printf("No query submitted yet.<BR>");
+        else
+        {
+            if (empty($_GET["fPrintTable"]))
+                PrintPage("1", $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $needs);
+            else
+                PrintPage("2", $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $needs);
+        }
+
+        echo (file_get_contents("index-footer.html"));
+    }
+
+    ini_set("display_errors",   "Off");
+    ini_set("mysql.trace_mode", "Off");
+}
+?>
Index: trunk/MagicSoft/Mars/datacenter/db/runinfo.php
===================================================================
--- trunk/MagicSoft/Mars/datacenter/db/runinfo.php	(revision 7872)
+++ trunk/MagicSoft/Mars/datacenter/db/runinfo.php	(revision 7873)
@@ -530,6 +530,5 @@
         mysql_close($db_id);
 
-        if ($html=="1")
-            printf("<U><B>submitted query:</B></U><BR>%s<BR>", htmlspecialchars($query0));
+        PrintSubmittedQuery($query0, $html, $db, "old");
     }
 
Index: trunk/MagicSoft/Mars/datacenter/db/sequence.php
===================================================================
--- trunk/MagicSoft/Mars/datacenter/db/sequence.php	(revision 7872)
+++ trunk/MagicSoft/Mars/datacenter/db/sequence.php	(revision 7873)
@@ -580,6 +580,5 @@
         mysql_close($db_id);
 
-        if ($html=="1")
-            printf("<U><B>submitted query:</B></U><BR>%s<BR>", htmlspecialchars($query0));
+        PrintSubmittedQuery($query0, $html, $db, "old");
     }
 
Index: trunk/MagicSoft/Mars/datacenter/db/sequinfo-aio.php
===================================================================
--- trunk/MagicSoft/Mars/datacenter/db/sequinfo-aio.php	(revision 7873)
+++ trunk/MagicSoft/Mars/datacenter/db/sequinfo-aio.php	(revision 7873)
@@ -0,0 +1,404 @@
+<?php
+{
+    function CreateQuery($_GET, $alias, $checkwhere, $checkgroup, $checkstatusgroup, $needs)
+    {
+        $fromtable="Sequences";
+
+        $groups = 0;
+        foreach ($checkgroup as $element)
+            if ($element==-1)
+                $groups++;
+
+        $statusgroups = 0;
+        foreach ($checkstatusgroup as $element)
+            if ($element==-1)
+                $statusgroups++;
+
+        $query0 = "SELECT ";
+
+        if ($groups>0)
+        {
+            foreach ($checkgroup as $key => $element)
+                if ($element==-1)
+                    $query0 .=  $key . " as '" . $alias[$key] . "' " . ", ";
+            //--------------------------------------------------
+            $query0 .= "SUM(fRunTime)/3600 as '" . $alias["SUM(fRunTime)/3600"] . "', ";
+            //--------------------------------------------------
+            $query0 .= " SUM(fNumEvents) as '" . $alias["SUM(fNumEvents)"] . "', ";
+            $query0 .= " Min(fZenithDistanceMin) as '" . $alias["Min(fZenithDistanceMin)"] . "', ";
+            $query0 .= " Max(fZenithDistanceMax) as '" . $alias["Max(fZenithDistanceMax)"] . "', ";
+            $query0 .= " COUNT(*) as 'Sequence' ";
+        }
+        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 . "), 'not done' ,if(" . $key . "='1970-01-01 00:00:00','dont do','done'))) as '" . $alias[$key] . "', ";
+
+                $query0 .= " count(*) as 'Sequence'";
+
+            }
+            else
+            {
+                if (!empty($_GET["fSendTxt"]))
+                    $query0 .= " " . $fromtable . ".fSequenceFirst as '" . $alias["fSequenceFirst"] . "' ";
+                else
+                {
+                    $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>') ";
+                    $query0 .= " as " . $alias["fSequenceFirst"];
+                    if (!empty($_GET["fLinks"]))
+                    {
+                        $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 .= " as 'Links'";
+                    }
+                }
+
+                foreach ($_GET as $key => $element)
+                    if ($_GET[$key]=="On")
+                        if ($key!="fLinks" && $key!="fOff" && $key!="fOnlyOff")
+                            if (empty($checkwhere[$key]) || $checkwhere[$key]==0)
+                                $query0 .= ", " . $key . " as '" . $alias[$key] . "' ";
+            }
+        }
+
+        $query0 .= " FROM " . $fromtable;
+
+        $query0 .= " LEFT JOIN SequenceProcessStatus ON Sequences.fSequenceFirst=SequenceProcessStatus.fSequenceFirst ";
+        $query0 .= " LEFT JOIN Calibration ON Sequences.fSequenceFirst=Calibration.fSequenceFirst ";
+        $query0 .= " LEFT JOIN Star ON Sequences.fSequenceFirst=Star.fSequenceFirst ";
+
+        foreach ($_GET as $key => $element)
+            if (($_GET[$key]=="On" || $groups>0))// && !empty(GetJoin($fromtable,$key)))
+                $query0 .= GetJoin($fromtable,$key);
+
+        if ($_GET["fTest"]!="On")
+        {
+            if ($_GET["fSourceName"]!="On")
+                $query0 .= " LEFT JOIN Source ON Sequences.fSourceKEY=Source.fSourceKEY ";
+            $query0 .= " WHERE fTest='no'";
+        }
+
+        if ($_GET["fOff"]=="Off")
+        {
+            if (strpos($query0, " WHERE ")==FALSE)
+                $query0 .= " WHERE ";
+            else
+                $query0 .= " AND ";
+
+            $query0 .= " NOT (fSourceName like '%Off%')";
+        }
+
+        if ($_GET["fOnlyOff"]=="On")
+        {
+            if (strpos($query0, " WHERE ")==FALSE)
+                $query0 .= " WHERE ";
+            else
+                $query0 .= " AND ";
+
+            $query0 .= " fSourceName like '%Off%'";
+        }
+
+        foreach ($checkwhere as $key => $element)
+        {
+            if (empty($element) || $element<=0)
+                continue;
+
+            if (strpos($query0, " WHERE ")==FALSE)
+                $query0 .= " WHERE ";
+            else
+                if ($element!=-1)
+                    if (strrpos($query0, " AND ")!=strlen($query0)-5)
+                        $query0 .= " AND ";
+
+            if ($element!=-1)
+                $query0 .= GetCheck($fromtable, $key) . "=" . $element;
+        }
+
+        if (strpos($query0, " WHERE ")==FALSE)
+            $query0 .= " WHERE ";
+        else
+            $query0 .= " AND ";
+
+        $query0 .= StatusQuery("fSequenceFileWritten", $needs);
+        $query0 .= StatusQuery("fAllFilesAvail", $needs);
+        $query0 .= StatusQuery("fCallisto", $needs);
+        $query0 .= StatusQuery("fFillCallisto", $needs);
+        $query0 .= StatusQuery("fStar", $needs);
+        $query0 .= StatusQuery("fFillStar", $needs);
+
+        if (!empty($_GET["fRunMin"]) && !empty($_GET["fRunMax"]))
+            $query0 .= "Sequences.fSequenceFirst BETWEEN " . $_GET["fRunMin"] . " AND " . $_GET["fRunMax"] . " ";
+        else
+            $query0 = substr($query0, 0, -4);
+
+        if (!empty($_GET["fZDMin"]) && !empty($_GET["fZDMax"]))
+            $query0 .= "AND (fZenithDistanceMin > " . $_GET["fZDMin"] . " AND fZenithDistanceMax < " . $_GET["fZDMax"] . ") ";
+
+        if (!empty($_GET["fSourceN"]))
+            $query0 .= " AND fSourceName REGEXP \"^" . $_GET["fSourceN"] . "\" ";
+
+        if (!empty($_GET["fStartDate"]))
+        {
+            if (strpos(strrev($query0), " DNA ")!=0 || !strpos(strrev($query0), " DNA "))
+                $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 || !strpos(strrev($query0), " DNA "))
+                $query0 .= " AND ";
+
+            $stopdate=substr($_GET["fStopDate"], 0, 10);
+            $query0 .= " fRunStart < '" . $stopdate . " 13:00:00' ";
+        }
+
+        if (!empty($_GET["fStarStart"]))
+        {
+            if (strpos(strrev($query0), " DNA ")!=0 || !strpos(strrev($query0), " DNA "))
+                $query0 .= " AND ";
+
+            $starstart=substr($_GET["fStarStart"], 0, 10);
+            $query0 .=" fStar >= '" . $starstart . " 00:00:00' ";
+        }
+
+        if (!empty($_GET["fStarStop"]))
+        {
+            if (strpos(strrev($query0), " DNA ")!=0 || !strpos(strrev($query0), " DNA "))
+                $query0 .= " AND ";
+
+            $starstop=substr($_GET["fStarStop"], 0, 10);
+            $query0 .= " fStar < '" . $starstop . " 23:59:59' ";
+        }
+
+        if ($groups>0)
+        {
+            $query0 .= " GROUP BY ";
+            $num = $groups;
+            foreach ($checkgroup as $key => $element)
+                if ($element==-1)
+                {
+                    $query0 .= GetCheck($fromtable,$key);
+                    if ($num-->1)
+                        $query0 .= ", ";
+                }
+        }
+
+        if ($statusgroups>0)
+        {
+            $query0 .= " GROUP BY ";
+            $num = $statusgroups;
+            foreach ($checkstatusgroup as $key => $element)
+                if ($element==-1)
+                {
+                    $query0 .= $alias[$key];
+                    if ($num-->1)
+                        $query0 .= ", ";
+                }
+        }
+
+        if (!empty($_GET["fSortBy"]))
+        {
+            $val=substr($_GET["fSortBy"], 0, -1);
+            $query0 .= " ORDER BY " . GetTable($fromtable,$val) . " ";
+            if (substr($_GET["fSortBy"], -1)=="-")
+                $query0 .= "DESC";
+        }
+
+        if (empty($_GET["fSortBy"]) && $groups==0 && $statusgroups==0)
+            $query0 .= "ORDER BY Sequences.fSequenceFirst ASC ";
+
+        if (empty($_GET["fNumStart"]))
+            $_GET["fNumStart"]=0;
+
+        if (empty($_GET["fSendTxt"]))
+            $query0 .= " LIMIT " . $_GET["fNumStart"] . ", " . $_GET["fNumResults"];
+
+        return $query0;
+    }
+
+    function InitGet($_GET)
+    {
+        // Find out whether it is the first call to the php script
+        $first = empty($_GET["fRunMin"]) && empty($_GET["fRunMax"]);
+
+        if (empty($_GET["fNumResults"]))
+            $_GET["fNumResults"]="50";
+
+        if (empty($_GET["fRunStart"]))
+            $_GET["fRunStart"]=$first?"On":"";
+
+        if (empty($_GET["fRunTime/60"]))
+            $_GET["fRunTime/60"]=$first?"On":"";
+
+        if (empty($_GET["fZenithDistanceMin"]))
+            $_GET["fZenithDistanceMin"]=$first?"On":"";
+
+        if (empty($_GET["fSourceName"]))
+            $_GET["fSourceName"]=$first?"On":"";
+
+        if (empty($_GET["fStar"]))
+            $_GET["fStar"]=$first?"On":"";
+
+        if (empty($_GET["fInhomogeneity"]))
+            $_GET["fInhomogeneity"]=$first?"On":"";
+
+        if (empty($_GET["fOff"]))
+            $_GET["fOff"]=$first?"On":"";
+
+        if (empty($_GET["fOnlyOff"]))
+            $_GET["fOnlyOff"]=$first?"Off":"";
+
+        InitSequInfo($_GET);
+    }
+
+    function PrintForm($_GET, $host, $user, $pw, $db, $limitsmean, $limitsmin, $limitsmax, $alias)
+    {
+        printf("<center>\n");
+        printf("<form action=\"sequinfo-aio.php\" METHOD=\"GET\">\n");
+        printf("<input id='sh' type='hidden' name='fShowHide' value='");
+        if (!empty($_GET["fShowHide"]))
+            printf("%s", $_GET["fShowHide"]);
+        else
+            printf("100000000");
+        printf("'>\n");
+        printf("<img id='allbutton'    src='../minus.png' alt='-' onclick='showhide(\"all\")'>                     Menu       \n");
+        printf("<img id='infobutton'   src='../plus.png'  alt='+' onClick='showhide(\"info\");showhide(\"info2\")'>SequInfo   \n");
+        printf("<img id='statbutton'   src='../plus.png'  alt='+' onClick='showhide(\"stat\");showhide(\"fail\")'> StatusInfo \n");
+        printf("<img id='calbutton'    src='../plus.png'  alt='+' onClick='showhide(\"cal\")'>                     CalInfo    \n");
+        printf("<img id='starbutton'   src='../plus.png'  alt='+' onClick='showhide(\"star\")'>                    StarInfo   \n");
+        printf("<img id='rangesbutton' src='../plus.png'  alt='+' onClick='showhide(\"ranges\")'>                  Ranges     \n");
+        printf("<img id='limitsbutton' src='../plus.png'  alt='+' onClick='showhide(\"limits\")'>                  Limits     \n");
+
+        printf(" <div id='all' style='display:block'>");
+
+        printf(" <div id=\"info\" style='display:none'>");
+        PrintSequInfoMenu();
+        printf(" </div><p>\n");
+
+        PrintSequInfo2Menu($host,$user,$pw,$db);
+        PrintSequStatMenu();
+        PrintFailMenu();
+
+        printf(" <div id=\"cal\" style='display:none'>\n");
+        PrintCalMenu();
+        printf(" </div><p>\n");
+
+        printf(" <div id=\"star\" style='display:none'>\n");
+        PrintStarMenu();
+        printf(" </div><p>\n");
+
+        printf("<div id='limits' style='display:none'>\n");
+        PrintLimitsMenu($limitsmean, $limitsmin, $limitsmax, $alias, "");
+        printf("</div>\n");
+
+        printf(" <div id='ranges' style='display:none'>");
+        PrintZdRangeMenu($host,$user,$pw,$db);
+        PrintSequRangeMenu($host,$user,$pw,$db);
+        printf("<p>");
+        PrintSourceMenu($host,$user,$pw,$db);
+        PrintNightRangeMenu($host,$user,$pw,$db);
+        printf("<p>");
+        printf("</div>");
+
+        printf("</div>");
+        printf(" <P>\n");
+
+        PrintNumResPullDown();
+
+        ini_set("mysql.trace_mode", "Off");
+        ini_set("display_errors", "Off");
+
+        PrintButtons("sequinfo-aio.php");
+
+        printf("</form>\n");
+        printf("</center>\n");
+        printf("</td>\n");
+        printf("</tr>\n");
+        printf("<tr class='Block'>\n");
+        printf("<td>\n");
+    }
+
+    function PrintPage($html, $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $limitsmean, $limitsmin, $limitsmax, $needs)
+    {
+        $db_id = mysql_pconnect($host, $user, $pw);
+        if ($db_id==FALSE)
+        {
+            printf("mysql_connect returned the following error: %s\n", mysql_error());
+            die("");
+        }
+        mysql_select_db($db);
+
+        $query0 = CreateQuery($_GET, $alias, $checkwhere, $checkgroup, $checkstatusgroup, $needs);
+
+        $result0 = mysql_query($query0, $db_id);
+
+        if ($result0)
+        {
+            if ($html=="1" || $html=="2")
+                PrintMagicTable($result0, $alias, $rightalign, $limitsmean, $limitsmin, $limitsmax, $_GET);
+            else
+                PrintText($result0);
+
+            mysql_free_result($result0);
+        }
+        mysql_close($db_id);
+
+        PrintSubmittedQuery($query0, $html, $db, "");
+    }
+
+    include ("include.php");
+    include ("menu.php");
+    include ("db.php");
+    include ("magicdefs.php");
+
+    ini_set("display_errors", "On");
+    ini_set("mysql.trace_mode", "On");
+
+    if (!empty($_GET["fSendTxt"]))
+    {
+        header("Content-type: application/octet");
+        header("Content-Disposition: attachment; filename=query-result.txt");
+
+        PrintPage("0", $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $limitsmean, $limitsmin, $limitsmax, $needs);
+    }
+    else
+    {
+        echo (file_get_contents("index-header.html"));
+
+        $environment = sizeof($_GET);
+
+        InitGet($_GET);
+        if (empty($_GET["fPrintTable"]))
+            PrintForm($_GET, $host, $user, $pw, $db, $limitsmean, $limitsmin, $limitsmax, $alias);
+
+        if ($environment==0)
+            printf("No query submitted yet.<BR>");
+        else
+        {
+            if (empty($_GET["fPrintTable"]))
+                PrintPage("1", $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $limitsmean, $limitsmin, $limitsmax, $needs);
+            else
+                PrintPage("2", $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $limitsmean, $limitsmin, $limitsmax, $needs);
+        }
+
+        echo (file_get_contents("index-footer.html"));
+    }
+
+    ini_set("display_errors", "Off");
+    ini_set("mysql.trace_mode", "Off");
+}
+?>
Index: trunk/MagicSoft/Mars/datacenter/db/sequinfo.php
===================================================================
--- trunk/MagicSoft/Mars/datacenter/db/sequinfo.php	(revision 7872)
+++ trunk/MagicSoft/Mars/datacenter/db/sequinfo.php	(revision 7873)
@@ -644,6 +644,5 @@
         mysql_close($db_id);
 
-        if ($html=="1")
-            printf("<U><B>submitted query:</B></U><BR>%s<BR>", htmlspecialchars($query0));
+        PrintSubmittedQuery($query0, $html, $db, "old");
     }
 
Index: trunk/MagicSoft/Mars/datacenter/db/sources.php
===================================================================
--- trunk/MagicSoft/Mars/datacenter/db/sources.php	(revision 7872)
+++ trunk/MagicSoft/Mars/datacenter/db/sources.php	(revision 7873)
@@ -19,5 +19,5 @@
         $query0 .= " FROM Source ";
 
-        if ($_GET["fTest"]=="Off")
+        if (!$_GET["fTest"]=="On")
             $query0 .= " WHERE fTest='no'";
 
@@ -112,6 +112,5 @@
         mysql_close($db_id);
 
-        if ($html=="1")
-            printf("<U><B>submitted query:</B></U><BR>%s<BR>", htmlspecialchars($query0));
+        PrintSubmittedQuery($query0, $html, $db, "old");
     }
 
Index: trunk/MagicSoft/Mars/datacenter/db/statusrps.php
===================================================================
--- trunk/MagicSoft/Mars/datacenter/db/statusrps.php	(revision 7872)
+++ trunk/MagicSoft/Mars/datacenter/db/statusrps.php	(revision 7873)
@@ -215,6 +215,5 @@
         mysql_close($db_id);
 
-        if ($html=="1")
-            printf("<U><B>submitted query:</B></U><BR>%s<BR>", htmlspecialchars($query0));
+        PrintSubmittedQuery($query0, $html, $db, "old");
     }
 
Index: trunk/MagicSoft/Mars/datacenter/db/statussbs.php
===================================================================
--- trunk/MagicSoft/Mars/datacenter/db/statussbs.php	(revision 7872)
+++ trunk/MagicSoft/Mars/datacenter/db/statussbs.php	(revision 7873)
@@ -191,6 +191,5 @@
         mysql_close($db_id);
 
-        if ($html=="1")
-            printf("<U><B>submitted query:</B></U><BR>%s<BR>", htmlspecialchars($query0));
+        PrintSubmittedQuery($query0, $html, $db, "old");
     }
 
Index: trunk/MagicSoft/Mars/datacenter/db/statussps.php
===================================================================
--- trunk/MagicSoft/Mars/datacenter/db/statussps.php	(revision 7872)
+++ trunk/MagicSoft/Mars/datacenter/db/statussps.php	(revision 7873)
@@ -204,6 +204,5 @@
         mysql_close($db_id);
 
-        if ($html=="1")
-            printf("<U><B>submitted query:</B></U><BR>%s<BR>", htmlspecialchars($query0));
+        PrintSubmittedQuery($query0, $html, $db, "old");
     }
 
