Index: trunk/MagicSoft/Mars/datacenter/db/culminating.php
===================================================================
--- trunk/MagicSoft/Mars/datacenter/db/culminating.php	(revision 7484)
+++ trunk/MagicSoft/Mars/datacenter/db/culminating.php	(revision 7484)
@@ -0,0 +1,275 @@
+<?php
+{
+    function CreateQuery($_GET, $alias, $checkwhere, $checkgroup, $checkstatusgroup)
+    {
+        $fromtable="Sequences";
+
+        $groups = 0;
+        foreach ($checkgroup as $element)
+            if ($element==-1)
+                $groups++;
+
+        $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 .= " COUNT(*) as 'Sequ#' ";
+        }
+        else
+        {
+            if (!empty($_GET["fSendTxt"]))
+                $query0 .= " SELECT fSequenceFirst ";
+            else
+                $query0 .= " CONCAT('<A&ws;HREF=\"index.php?',  'fRunStart=On', '&fZenithDistance=On', '&fRunMin=', fSequenceFirst, '&fMeanTriggerRate=On', '&fRunTypeName=On', '&fRunMax=', fSequenceLast, '&fNumEvents=On', '&fSourceName=On&', 'fExcludedFDAKEY=1', '&fSequenceFirst=On', '&fNumResults=500\">', fSequenceFirst, '</A>') ";
+            $query0 .= " as 'Sequence#' ";
+
+            foreach ($_GET as $key => $element)
+                if ($_GET[$key]=="On")
+                    if (empty($checkwhere[$key]) || $checkwhere[$key]==0)
+                        $query0 .= ", " . $key . " as '" . $alias[$key] . "' ";
+        }
+
+        $query0 .= " FROM " . $fromtable;
+
+        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 .= "fSequenceFirst BETWEEN " . $_GET["fRunMin"] . " AND " . $_GET["fRunMax"] . " ";
+
+        if (!empty($_GET["fSourceN"]))
+            $query0 .= " AND fSourceName REGEXP \"^" . $_GET["fSourceN"] . "\" ";
+
+        $query0 .= " AND ((fAzimuthMin<0 and fAzimuthMax>0) OR (fAzimuthMin<180 and fAzimuthMax>180)) ";
+
+        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 (!empty($_GET["fSortBy"]))
+        {
+            $query0 .= " ORDER BY " . substr($_GET["fSortBy"], 0, -1) . " ";
+            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["fLastUpdate"]))
+            $_GET["fLastUpdate"]="Off";
+
+        if (empty($_GET["fSourceName"]))
+            $_GET["fSourceName"]=$first?"On":"";
+
+        if (empty($_GET["fRunStart"]))
+            $_GET["fRunStart"]=$first?"On":"";
+
+        if (empty($_GET["fAzimuthMin"]))
+            $_GET["fAzimuthMin"]="Off";
+
+        if (empty($_GET["fAzimuthMax"]))
+            $_GET["fAzimuthMax"]="Off";
+
+        if (empty($_GET["fZenithDistanceMin"]))
+            $_GET["fZenithDistanceMin"]=$first?"On":"";
+
+        if (empty($_GET["fZenithDistanceMax"]))
+            $_GET["fZenithDistanceMax"]="Off";
+
+        if (empty($_GET["fRunTime/60"]))
+            $_GET["fRunTime/60"]="Off";
+
+    }
+
+    function PrintForm($_GET, $db)
+    {
+        printf("<center>\n");
+        printf("<form action=\"culminating.php\" METHOD=\"GET\">\n");
+        printf(" <table>\n");
+        printf("  <tr>\n");
+
+        CheckBox("fAzimuthMin",        "Azimuth min");
+        CheckBox("fAzimuthMax",        "Azimuth max");
+        CheckBox("fZenithDistanceMin", "Zenith distance min");
+        CheckBox("fZenithDistanceMax", "Zenith distance max");
+
+        printf("  </tr><tr>\n");
+
+        CheckBox("fRunTime/60",        "Duration");
+
+        printf(" </table>\n");
+        printf(" <p>\n");
+
+        printf(" <table>\n");
+        printf("  <tr><td>\n");
+        PrintPullDown($db, "Source",      "fSourceName",      "fSourceKEY", "Source Name");
+        printf("  </td></tr>\n");
+        printf(" </table>\n");
+        printf(" <p>\n");
+
+        if (empty($_GET["fRunMin"]))
+            $min = GetMin("fSequenceFirst", "Sequences", $db);
+        else
+            $min = $_GET["fRunMin"];
+
+        if (empty($_GET["fRunMax"]))
+            $max = GetMax("fSequenceFirst", "Sequences", $db);
+        else
+            $max = $_GET["fRunMax"];
+
+
+        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");
+
+        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(" 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");
+
+        ini_set("mysql.trace_mode", "Off");
+        ini_set("display_errors", "Off");
+
+        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=\"culminating.php\"'>&nbsp;&nbsp;&nbsp;\n");
+        if (strchr($_SERVER["REQUEST_URI"], '?')!=FALSE)
+            printf("<input class='Width' type='button' value='Get .txt' onClick='self.location.href=\"%s&fSendTxt=1\"'>&nbsp;&nbsp;&nbsp;\n", $_SERVER["REQUEST_URI"]);
+        printf("</form>\n");
+        printf("</center>\n");
+        printf("</td>\n");
+        printf("</tr>\n");
+        printf("<tr class='Block'>\n");
+        printf("<td>\n");
+    }
+
+    function PrintPage($html, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup)
+    {
+        $db_id = mysql_connect("hercules.astro.uni-wuerzburg.de", "MAGIC", "d99swMT!");
+        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);
+
+        $result0 = mysql_query($query0, $db_id);
+
+        if ($result0)
+        {
+            if ($html=="1")
+                PrintMagicTable($result0, $alias, $rightalign, "", "", $_GET);
+            else
+                PrintText($result0);
+
+            mysql_free_result($result0);
+        }
+        mysql_close($db_id);
+
+        if ($html=="1")
+            printf("<U><B>submitted query:</B></U><BR>%s<BR>", htmlspecialchars($query0));
+    }
+
+    include ("include.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", $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup);
+    }
+    else
+    {
+        echo (file_get_contents("index-header.html"));
+
+        $environment = sizeof($_GET);
+
+        InitGet($_GET);
+        PrintForm($_GET, $db);
+
+        if ($environment==0)
+            printf("No query submitted yet.<BR>");
+        else
+            PrintPage("1", $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup);
+
+        echo (file_get_contents("index-footer.html"));
+    }
+
+    ini_set("display_errors", "Off");
+    ini_set("mysql.trace_mode", "Off");
+}
+?>
Index: trunk/MagicSoft/Mars/datacenter/db/datacheck.php
===================================================================
--- trunk/MagicSoft/Mars/datacenter/db/datacheck.php	(revision 7484)
+++ trunk/MagicSoft/Mars/datacenter/db/datacheck.php	(revision 7484)
@@ -0,0 +1,450 @@
+<?php
+{
+    function CreateQuery($_GET, $alias, $checkwhere, $checkgroup, $checkstatusgroup, $checkenumgroup)
+    {
+        $fromtable="RunData";
+
+        $groups = 0;
+        foreach ($checkgroup as $element)
+            if ($element==-1)
+                $groups++;
+
+        $statusgroups = 0;
+        foreach ($checkstatusgroup as $element)
+            if ($element==-1)
+                $statusgroups++;
+
+        $enumgroups = 0;
+        foreach ($checkenumgroup as $element)
+            if ($element==-1)
+                $enumgroups++;
+
+        $query0 = "SELECT ";
+
+        if ($groups>0)
+        {
+            foreach ($checkgroup as $key => $element)
+                if ($element==-1)
+                    $query0 .=  $key . " as '" . $alias[$key] . "' " . ", ";
+            $query0 .= " COUNT(*) as 'Runs' ";
+        }
+        else
+        {
+            if ($statusgroups>0)
+            {
+                foreach ($checkstatusgroup as $key => $element)
+                    if ($element==-1)
+                        $query0 .= " (if(IsNull(" . $key . "), 'not done' ,if(" . $key . "='1970-01-01 00:00:00','dont do','done'))) as '" . $alias[$key] . "', ";
+
+                $query0 .= " count(*) as 'Runs'";
+
+            }
+            else
+            {
+                if ($enumgroups>0)
+                {
+                    foreach ($checkenumgroup as $key => $element)
+                        if ($element==-1)
+                            $query0 .=  $key . " as '" . $alias[$key] . "' " . ", ";
+                    $query0 .= " COUNT(*) as 'Runs' ";
+                }
+                else
+                {
+                    $query0 .= " RunData.fRunNumber as 'RunNumber'";
+                    if (!empty($_GET["fLinks"]))
+                    {
+                        $query0 .= ", CONCAT('<A&ws;HREF=\"http://www.astro.uni-wuerzburg.de/datacenter/sinope/' , DATE_FORMAT(ADDDATE(RunData.fRunStart, INTERVAL 13 HOUR), '%Y') , '/', DATE_FORMAT(ADDDATE(RunData.fRunStart, INTERVAL 13 HOUR), '%m') , '/', DATE_FORMAT(ADDDATE(RunData.fRunStart, INTERVAL 13 HOUR), '%d') , '/sinope-dat' ,  LPAD(CONCAT(RunData.fRunNumber , '.html'), 13,'0') , '\">dl</A>' ";
+                        $query0 .= ", '&nbsp;<A&ws;HREF=\"http://www.astro.uni-wuerzburg.de/datacenter/sinope/' , DATE_FORMAT(ADDDATE(RunData.fRunStart, INTERVAL 13 HOUR), '%Y') , '/', DATE_FORMAT(ADDDATE(RunData.fRunStart, INTERVAL 13 HOUR), '%m') , '/', DATE_FORMAT(ADDDATE(RunData.fRunStart, INTERVAL 13 HOUR), '%d') , '/sinope-cal' ,  LPAD(CONCAT(RunData.fRunNumber , '.html'), 13,'0') , '\">cl</A>' ";
+                        $query0 .= ", '&nbsp;<A&ws;HREF=\"http://www.astro.uni-wuerzburg.de/datacenter/sinope/' , DATE_FORMAT(ADDDATE(RunData.fRunStart, INTERVAL 13 HOUR), '%Y') , '/', DATE_FORMAT(ADDDATE(RunData.fRunStart, INTERVAL 13 HOUR), '%m') , '/', DATE_FORMAT(ADDDATE(RunData.fRunStart, INTERVAL 13 HOUR), '%d') , '/sinope-dat' ,  LPAD(CONCAT(RunData.fRunNumber , '.txt'), 12,'0') , '\">dt</A>' ";
+                        $query0 .= ", '&nbsp;<A&ws;HREF=\"http://www.astro.uni-wuerzburg.de/datacenter/sinope/' , DATE_FORMAT(ADDDATE(RunData.fRunStart, INTERVAL 13 HOUR), '%Y') , '/', DATE_FORMAT(ADDDATE(RunData.fRunStart, INTERVAL 13 HOUR), '%m') , '/', DATE_FORMAT(ADDDATE(RunData.fRunStart, INTERVAL 13 HOUR), '%d') , '/sinope-cal' ,  LPAD(CONCAT(RunData.fRunNumber , '.txt'), 12,'0') , '\">ct</A>' ";
+                        $query0 .= ", '&nbsp;<A&ws;HREF=\"http://www.astro.uni-wuerzburg.de/datacenter/callisto/' , LEFT(LPAD(CONCAT(fSequenceFirst, '.'), 9,'0'),4), '/', LPAD(CONCAT(fSequenceFirst, '/'), 9,'0'), 'callisto', LPAD(CONCAT(fSequenceFirst , '.html'), 13,'0') , '\">c</A>'";
+                        $query0 .= ", '&nbsp;<A&ws;HREF=\"http://www.astro.uni-wuerzburg.de/datacenter/star/' , LEFT(LPAD(CONCAT(fSequenceFirst, '.'), 9,'0'),4), '/', LPAD(CONCAT(fSequenceFirst, '/'), 9,'0'), 'star', LPAD(CONCAT(fSequenceFirst , '.html'), 13,'0') , '\">s</A>'";
+                        $query0 .= ", '&nbsp;<A&ws;HREF=\"http://www.astro.uni-wuerzburg.de/datacenter/sequences/' , LEFT(LPAD(CONCAT(fSequenceFirst, '.'), 9,'0'),4), '/sequence', LPAD(CONCAT(fSequenceFirst , '.txt'), 12,'0') , '\">', 'f </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 RunData ";
+
+        $query0 .= " LEFT JOIN RunProcessStatus ON RunData.fRunNumber=RunProcessStatus.fRunNumber ";
+        $query0 .= " LEFT JOIN DataCheck ON DataCheck.fRunNumber=RunData.fRunNumber ";
+        $query0 .= " LEFT JOIN RunType ON RunType.fRunTypeKEY=RunData.fRunTypeKEY ";
+
+        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("fRawFileAvail");
+        $query0 .= StatusQuery("fDataCheckDone");
+
+        $query0 .= EnumQuery("fHasSignal");
+        $query0 .= EnumQuery("fHasPedestal");
+        $query0 .= EnumQuery("fHasSignalInterlaced");
+        $query0 .= EnumQuery("fHasPedestalInterlaced");
+
+        if (!empty($_GET["fRunMin"]) && !empty($_GET["fRunMax"]))
+            $query0 .= "RunData.fRunNumber BETWEEN " . $_GET["fRunMin"] . " AND " . $_GET["fRunMax"] . " ";
+
+        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 ($enumgroups>0)
+        {
+            $query0 .= " GROUP BY ";
+            $num = $enumgroups;
+            foreach ($checkenumgroup 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 RunData.fRunNumber 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"]="20";
+
+        if (empty($_GET["fLinks"]))
+            $_GET["fLinks"]=$first?"On":"";
+
+        if (empty($_GET["fSequenceFirst"]))
+            $_GET["fSequenceFirst"]=$first?"On":"";
+
+        if (empty($_GET["fEvents"]))
+            $_GET["fEvents"]=$first?"On":"";
+
+        if (empty($_GET["fPositionSignal"]))
+            $_GET["fPositionSignal"]="Off";
+
+        if (empty($_GET["fPositionFWHM"]))
+            $_GET["fPositionFWHM"]="Off";
+
+        if (empty($_GET["fHeightSignal"]))
+            $_GET["fHeightSignal"]="Off";
+
+        if (empty($_GET["fHeightFWHM"]))
+            $_GET["fHeightFWHM"]="Off";
+
+        if (empty($_GET["fHasSignal"]))
+            $_GET["fHasSignal"]=$first?"On":"";
+
+        if (empty($_GET["fHasSignalEnum"]))
+            $_GET["fHasSignalEnum"]="0";
+
+        if (empty($_GET["fHasPedestal"]))
+            $_GET["fHasPedestal"]=$first?"On":"";
+
+        if (empty($_GET["fHasPedestalEnum"]))
+            $_GET["fHasPedestalEnum"]="0";
+
+        if (empty($_GET["fPositionAsym"]))
+            $_GET["fPositionAsym"]="Off";
+
+        if (empty($_GET["fHeightAsym"]))
+            $_GET["fHeightAsym"]="Off";
+
+        if (empty($_GET["fEventsInterlaced"]))
+            $_GET["fEventsInterlaced"]=$first?"On":"";
+
+        if (empty($_GET["fPositionSignalInterlaced"]))
+            $_GET["fPositionSignalInterlaced"]="Off";
+
+        if (empty($_GET["fPositionFWHMInterlaced"]))
+            $_GET["fPositionFWHMInterlaced"]="OFf";
+
+        if (empty($_GET["fHeightSignalInterlaced"]))
+            $_GET["fHeightSignalInterlaced"]="Off";
+
+        if (empty($_GET["fHeightFWHMInterlaced"]))
+            $_GET["fHeightFWHMInterlaced"]="Off";
+
+        if (empty($_GET["fHasSignalInterlaced"]))
+            $_GET["fHasSignalInterlaced"]=$first?"On":"";
+
+        if (empty($_GET["fHasSignalInterlacedEnum"]))
+            $_GET["fHasSignalInterlacedEnum"]="0";
+
+        if (empty($_GET["fHasPedestalInterlaced"]))
+            $_GET["fHasPedestalInterlaced"]=$first?"On":"";
+
+        if (empty($_GET["fHasPedestalInterlacedEnum"]))
+            $_GET["fHasPedestalInterlacedEnum"]="0";
+
+        if (empty($_GET["fPositionAsymInterlaced"]))
+            $_GET["fPositionAsymInterlaced"]="Off";
+
+        if (empty($_GET["fHeightAsymInterlaced"]))
+            $_GET["fHeightAsymInterlaced"]="Off";
+
+        if (empty($_GET["fRunTypeName"]))
+            $_GET["fRunTypeName"]=$first?"On":"";
+
+        if (empty($_GET["fDataCheckDone"]))
+            $_GET["fDataCheckDone"]="Off";
+
+        if (empty($_GET["fDataCheckDoneStatus"]))
+            $_GET["fDataCheckDoneStatus"]="1";
+
+        if (empty($_GET["fRawFileAvail"]))
+            $_GET["fRawFileAvail"]="Off";
+
+        if (empty($_GET["fRawFileAvailStatus"]))
+            $_GET["fRawFileAvailStatus"]="1";
+
+    }
+
+    function PrintForm($_GET, $db)
+    {
+        printf("<center>\n");
+        printf("<form action=\"datacheck.php\" METHOD=\"GET\">\n");
+        printf(" <table>\n");
+        printf("  <tr>\n");
+
+        CheckBox("fLinks",             "Links");
+        CheckBox("fEvents",            "DataEvents");
+        CheckBox("fEventsInterlaced",  "CalEvents");
+        CheckBox("fSequenceFirst",     "Sequence#");
+
+        printf("  </tr><tr>\n");
+
+        CheckBox("fPositionSignal",            "ArrTime");
+        CheckBox("fPositionFWHM",              "ArrTimeFWHM");
+        CheckBox("fPositionSignalInterlaced",  "ArrTimeCal");
+        CheckBox("fPositionFWHMInterlaced",    "ArrTimeFWHMCal");
+
+        printf("  </tr><tr>\n");
+
+        CheckBox("fHeightSignal",            "Signal");
+        CheckBox("fPositionFWHM",            "SignalFWHM");
+        CheckBox("fHeightSignalInterlaced",  "SignalCal");
+        CheckBox("fPositionFWHMInterlaced",  "SignalFWHMCal");
+
+        printf("  </tr><tr>\n");
+
+        CheckBox("fPositionAsym",            "ArrTimeAsym");
+        CheckBox("fHeightAsym",              "SignalAsym");
+        CheckBox("fPositionAsymInterlaced",  "ArrTimeAsymCal");
+        CheckBox("fHeightAsymInterlaced",    "SignalAsymCal");
+
+        printf("  </tr><tr><td>\n");
+
+        PrintEnumMenu("fHasSignal",               "HasSignal");
+        printf("  </td><td>\n");
+        PrintEnumMenu("fHasPedestal",             "HasPedestal");
+        printf("  </td><td>\n");
+        PrintEnumMenu("fHasSignalInterlaced",     "HasSignalCal");
+        printf("  </td><td>\n");
+        PrintEnumMenu("fHasPedestalInterlaced",   "HasPedestalCal");
+
+        printf("  </td></tr><tr><td>\n");
+
+        PrintStatusMenu("fDataCheckDone", "DataCheck");
+        printf("  </td><td>\n");
+        PrintStatusMenu("fRawFileAvail", "RawFile");
+        printf("</td><td>\n");
+
+        PrintPullDown($db, "RunType",      "fRunTypeName",      "fRunTypeKEY", "Run Type");
+
+        printf("  </td></tr>\n");
+        printf(" </table>\n");
+        printf(" <p>\n");
+
+        if (empty($_GET["fRunMin"]))
+            $min = GetMin("fRunNumber", "RunData", $db);
+        else
+            $min = $_GET["fRunMin"];
+
+        if (empty($_GET["fRunMax"]))
+            $max = GetMax("fRunNumber", "RunData", $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("DataCheck&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(" 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");
+
+        ini_set("mysql.trace_mode", "Off");
+        ini_set("display_errors", "Off");
+
+        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=\"datacheck.php\"'>&nbsp;&nbsp;&nbsp;\n");
+        if (strchr($_SERVER["REQUEST_URI"], '?')!=FALSE)
+            printf("<input class='Width' type='button' value='Get .txt' onClick='self.location.href=\"%s&fSendTxt=1\"'>&nbsp;&nbsp;&nbsp;\n", $_SERVER["REQUEST_URI"]);
+        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("</form>\n");
+        printf("</center>\n");
+        printf("</td>\n");
+        printf("</tr>\n");
+        printf("<tr class='Block'>\n");
+        printf("<td>\n");
+    }
+
+    function PrintPage($html, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $checkenumgroup)
+    {
+        $db_id = mysql_connect("hercules.astro.uni-wuerzburg.de", "MAGIC", "d99swMT!");
+        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, $checkenumgroup);
+
+        $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);
+
+        if ($html=="1")
+            printf("<U><B>submitted query:</B></U><BR>%s<BR>", htmlspecialchars($query0));
+    }
+
+    include ("include.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", $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $checkenumgroup);
+    }
+    else
+    {
+        echo (file_get_contents("index-header.html"));
+
+        $environment = sizeof($_GET);
+
+        InitGet($_GET);
+        if (empty($_GET["fPrintTable"]))
+            PrintForm($_GET, $db);
+
+        if ($environment==0)
+            printf("No query submitted yet.<BR>");
+        else
+        {
+            if (empty($_GET["fPrintTable"]))
+                PrintPage("1", $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $checkenumgroup);
+            else
+                PrintPage("2", $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $checkenumgroup);
+        }
+
+        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 7484)
+++ trunk/MagicSoft/Mars/datacenter/db/datasetinfo.php	(revision 7484)
@@ -0,0 +1,403 @@
+<?php
+{
+    function CreateQuery($_GET, $alias, $checkwhere, $checkgroup, $checkstatusgroup)
+    {
+        $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 . "), '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 .= " 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");
+        $query0 .= StatusQuery("fStarFilesAvail");
+        $query0 .= StatusQuery("fGanymed");
+        $query0 .= StatusQuery("fFillGanymed");
+
+        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["fLastUpdate"]))
+            $_GET["fLastUpdate"]="Off";
+
+        if (empty($_GET["fLinks"]))
+            $_GET["fLinks"]=$first?"On":"";
+
+        if (empty($_GET["fComment"]))
+            $_GET["fComment"]="Off";
+
+        if (empty($_GET["fWobble"]))
+            $_GET["fWobble"]=$first?"On":"";
+
+        if (empty($_GET["fExcessEvents"]))
+            $_GET["fExcessEvents"]=$first?"On":"";
+
+        if (empty($_GET["fExcessEvents*60/fEffOnTime"]))
+            $_GET["fExcessEvents*60/fEffOnTime"]=$first?"Off":"";
+
+        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["fSignalEvents*60/fEffOnTime"]))
+            $_GET["fSignalEvents*60/fEffOnTime"]=$first?"Off":"";
+
+        if (empty($_GET["fSignificance"]))
+            $_GET["fSignificance"]=$first?"On":"";
+
+        if (empty($_GET["Round(fSignificance/Sqrt(fEffOnTime/3600),2)"]))
+            $_GET["Round(fSignificance/Sqrt(fEffOnTime/3600),2)"]=$first?"Off":"";
+
+        if (empty($_GET["fScaleFactor"]))
+            $_GET["fScaleFactor"]=$first?"On":"";
+
+        if (empty($_GET["fEffOnTime/3600"]))
+            $_GET["fEffOnTime/3600"]=$first?"On":"";
+
+        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";
+
+        if (empty($_GET["fSourceName"]))
+            $_GET["fSourceName"]=$first?"On":"";
+
+        if (empty($_GET["fLastUpdate"]))
+            $_GET["fLastUpdate"]="Off";
+
+    }
+
+    function PrintForm($_GET, $db)
+    {
+        printf("<center>\n");
+        printf("<form action=\"datasetinfo.php\" METHOD=\"GET\">\n");
+        printf(" <table>\n");
+        printf("  <tr>\n");
+
+        CheckBox("fWobble",           "Wobble");
+        CheckBox("fExcessEvents",     "ExcEvts");
+        CheckBox("fBackgroundEvents", "BgEvts");
+        CheckBox("fSignalEvents",     "SignEvts");
+
+        printf("  </tr><tr>\n");
+
+        CheckBox("fSignificance",     "Sign");
+        CheckBox("fScaleFactor",      "Scale");
+        CheckBox("fEffOnTime/3600",   "EffOnTime");
+        CheckBox("fComment",          "Comment");
+
+        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><tr>\n");       
+
+        CheckBox("fLinks",             "Links");
+
+        printf("  </tr><tr><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("  </td></tr><tr><td>\n");
+
+        PrintPullDown($db, "Source",      "fSourceName",      "fSourceKEY", "Source Name");
+
+        printf("  </td></tr>\n");
+        printf(" </table>\n");
+        printf(" <p>\n");
+
+        if (empty($_GET["fRunMin"]))
+            $min = GetMin("fDataSetNumber", "DataSets", $db);
+        else
+            $min = $_GET["fRunMin"];
+
+        if (empty($_GET["fRunMax"]))
+            $max = GetMax("fDataSetNumber", "DataSets", $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("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");
+
+        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);
+
+        printf(" <P>\n");
+
+        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");
+
+        ini_set("mysql.trace_mode", "Off");
+        ini_set("display_errors", "Off");
+
+        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=\"datasetinfo.php\"'>&nbsp;&nbsp;&nbsp;\n");
+        if (strchr($_SERVER["REQUEST_URI"], '?')!=FALSE)
+            printf("<input class='Width' type='button' value='Get .txt' onClick='self.location.href=\"%s&fSendTxt=1\"'>&nbsp;&nbsp;&nbsp;\n", $_SERVER["REQUEST_URI"]);
+        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("</form>\n");
+        printf("</center>\n");
+        printf("</td>\n");
+        printf("</tr>\n");
+        printf("<tr class='Block'>\n");
+        printf("<td>\n");
+    }
+
+    function PrintPage($html, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup)
+    {
+        $db_id = mysql_connect("hercules.astro.uni-wuerzburg.de", "MAGIC", "d99swMT!");
+        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);
+
+        $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);
+
+        if ($html=="1")
+            printf("<U><B>submitted query:</B></U><BR>%s<BR>", htmlspecialchars($query0));
+    }
+
+    include ("include.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", $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, $db);
+
+        if ($environment==0)
+            printf("No query submitted yet.<BR>");
+        else
+        {
+            if (empty($_GET["fPrintTable"]))
+                PrintPage("1", $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup);
+            else
+                PrintPage("2", $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup);
+        }
+
+        echo (file_get_contents("index-footer.html"));
+    }
+
+    ini_set("display_errors", "Off");
+    ini_set("mysql.trace_mode", "Off");
+}
+?>
Index: trunk/MagicSoft/Mars/datacenter/db/db.php
===================================================================
--- trunk/MagicSoft/Mars/datacenter/db/db.php	(revision 7484)
+++ trunk/MagicSoft/Mars/datacenter/db/db.php	(revision 7484)
@@ -0,0 +1,5 @@
+<?php
+
+$db="MyMagic";
+
+?>
Index: trunk/MagicSoft/Mars/datacenter/db/dbstatus.php
===================================================================
--- trunk/MagicSoft/Mars/datacenter/db/dbstatus.php	(revision 7484)
+++ trunk/MagicSoft/Mars/datacenter/db/dbstatus.php	(revision 7484)
@@ -0,0 +1,413 @@
+<?php
+{
+    function CreateQuery($_GET, $alias)
+    {
+        $joins = array
+            (
+             "fSourceName"                       => " LEFT JOIN Source                       ON Sequences.fSourceKEY=Source.fSourceKEY ",
+            );
+
+        $checkwhere = array
+            (
+             "fSourceName"                       => CheckWhere("fSourceKEY",                       $_GET),
+            );
+        $checkgroup = array
+            (
+             "fSourceName"                       => CheckGroup("fSourceKEY",                       $_GET),
+            );
+
+        $checkstatusgroup = array
+            (
+             "fAllFilesAvail"                    => CheckStatusGroup("fAllFilesAvailStatus",       $_GET),
+             "fCallisto"                         => CheckStatusGroup("fCallistoStatus",            $_GET),
+             "fFillCallisto"                     => CheckStatusGroup("fFillCallistoStatus",        $_GET),
+             "fStar"                             => CheckStatusGroup("fStarStatus",                $_GET),
+             "fFillStar"                         => CheckStatusGroup("fFillStarStatus",            $_GET),
+            );
+
+        $check = array
+            (
+             "fSourceName"                       => " Sequences.fSourceKEY",
+            );
+
+        $table = array
+            (
+             "fSourceName"                       => "Source.fSourceName",
+             "fAllFilesAvail"                    => "SequenceProcessStatus.fAllFilesAvail",
+             "fCallisto"                         => "SequenceProcessStatus.fCallisto",
+             "fFillCallisto"                     => "SequenceProcessStatus.fFillCallisto",
+             "fStar"                             => "SequenceProcessStatus.fStar",
+             "fFillStar"                         => "SequenceProcessStatus.fFillStar",
+             );
+
+        $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 . "), '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 .= " Sequences.fSequenceFirst ";
+                else
+                    $query0 .= " CONCAT('<A&ws;HREF=\"runinfo.php?',  'fRunStart=On', '&fZenithDistance=On', '&fRunMin=', Sequences.fSequenceFirst, '&fMeanTriggerRate=On', '&fRunTypeName=On', '&fRunMax=', fSequenceLast, '&fNumEvents=On', '&fSourceName=On&', 'fExcludedFDAKEY=1', '&fSequenceFirst=On', '&fRawFileAvail=On', '&fCCFileAvail=On', '&fCaCoFileAvail=On\">', Sequences.fSequenceFirst, '</A>') ";
+                $query0 .= " as 'Sequence#' ";
+
+                foreach ($_GET as $key => $element)
+                    if ($_GET[$key]=="On")
+                        if (empty($checkwhere[$key]) || $checkwhere[$key]==0)
+                            $query0 .= ", " . $key . " as '" . $alias[$key] . "' ";
+            }
+        }
+
+        $query0 .= " FROM Sequences ";
+
+        $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($joins[$key]))
+                $query0 .= $joins[$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 .= $check[$key] . "=" . $element;
+        }
+
+        if (strpos($query0, " WHERE ")==FALSE)
+            $query0 .= " WHERE ";
+        else
+            $query0 .= " AND ";
+
+        $query0 .= StatusQuery("fSequenceFileWritten");
+        $query0 .= StatusQuery("fAllFilesAvail");
+        $query0 .= StatusQuery("fCallisto");
+        $query0 .= StatusQuery("fFillCallisto");
+        $query0 .= StatusQuery("fStar");
+        $query0 .= StatusQuery("fFillStar");
+
+        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["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 || !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 ($groups>0)
+        {
+            $query0 .= " GROUP BY ";
+            $num = $groups;
+            foreach ($checkgroup as $key => $element)
+                if ($element==-1)
+                {
+                    $query0 .= $check[$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;
+
+        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["fSourceName"]))
+            $_GET["fSourceName"]=$first?"On":"";
+
+        if (empty($_GET["fAllFilesAvail"]))
+            $_GET["fAllFilesAvail"]="On";
+
+        if (empty($_GET["fAllFilesAvailStatus"]))
+            $_GET["fAllFilesAvailStatus"]="4";
+
+        if (empty($_GET["fCallisto"]))
+            $_GET["fCallisto"]="On";
+
+        if (empty($_GET["fCallistoStatus"]))
+            $_GET["fCallistoStatus"]="4";
+
+        if (empty($_GET["fFillCallisto"]))
+            $_GET["fFillCallisto"]="Off";
+
+        if (empty($_GET["fFillCallistoStatus"]))
+            $_GET["fFillCallistoStatus"]="0";
+
+        if (empty($_GET["fStar"]))
+            $_GET["fStar"]=$first?"On":"";
+
+        if (empty($_GET["fStarStatus"]))
+            $_GET["fStarStatus"]="4";
+
+        if (empty($_GET["fFillStar"]))
+            $_GET["fFillStar"]="Off";
+
+        if (empty($_GET["fFillStarStatus"]))
+            $_GET["fFillStarStatus"]="0";
+    }
+
+    function PrintForm($_GET, $db)
+    {
+        printf("<center>\n");
+        printf("<form action=\"dbstatus.php\" METHOD=\"GET\">\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><td>\n");
+        PrintStatusMenu("fFillCallisto",        "Fillcallisto");
+        printf("  </td><td>\n");
+        PrintStatusMenu("fFillStar",            "Fillstar");
+
+        printf("</td></tr> </table>\n");
+        printf(" <p>\n");
+
+        // pull down boxes
+
+        printf(" <table>\n");
+        printf("  <tr><td>\n");
+        PrintPullDown($db, "Source",      "fSourceName",      "fSourceKEY", "Source Name");
+        printf("  </td><td>\n");
+
+        printf("&nbsp;&nbsp;&nbsp;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");
+
+        printf("  </td></tr>\n");
+        printf(" </table>\n");
+        printf(" <p>\n");
+
+        if (empty($_GET["fStartDate"]))
+            $timemin = GetMin("fRunStart", "Sequences", $db);
+        else
+            $timemin = $_GET["fStartDate"];
+
+        if (empty($_GET["fStopDate"]))
+            $timemax = GetMax("fRunStart", "Sequences", $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", $db);
+        else
+            $min = $_GET["fRunMin"];
+
+        if (empty($_GET["fRunMax"]))
+            $max = GetMax("fSequenceFirst", "Sequences", $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);
+
+        printf(" <P>\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");
+        printf("<input class='Width' type='button' value='Reset' onClick='self.location.href=\"sequinfo.php\"'>&nbsp;&nbsp;&nbsp;\n");
+        if (strchr($_SERVER["REQUEST_URI"], '?')!=FALSE)
+            printf("<input class='Width' type='button' value='Get .txt' onClick='self.location.href=\"%s&fSendTxt=1\"'>&nbsp;&nbsp;&nbsp;\n", $_SERVER["REQUEST_URI"]);
+        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("</form>\n");
+        printf("</center>\n");
+        printf("</td>\n");
+        printf("</tr>\n");
+        printf("<tr class='Block'>\n");
+        printf("<td>\n");
+    }
+
+    function PrintPage($html, $db)
+    {
+        $db_id = mysql_connect("hercules.astro.uni-wuerzburg.de", "MAGIC", "d99swMT!");
+        if ($db_id==FALSE)
+        {
+            printf("mysql_connect returned the following error: %s\n", mysql_error());
+            die("");
+        }
+        mysql_select_db($db);
+
+        $alias = array
+            (
+             "fSourceName"                      => "Source",
+             "fAllFilesAvail"                   => "FilesAvail",
+             "fCallisto"                        => "Callisto",
+             "fStar"                            => "Star",
+             "fFillCallisto"                    => "FillCal",
+             "fFillStar"                        => "FillStar",
+            );
+        $rightalign = array
+            (
+            );
+
+        $query0 = CreateQuery($_GET, $alias);
+
+        $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);
+
+        if ($html=="1")
+            printf("<U><B>submitted query:</B></U><BR>%s<BR>", htmlspecialchars($query0));
+    }
+
+    include ("include.php");
+    include ("db.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", $db);
+    }
+    else
+    {
+        echo (file_get_contents("index-header.html"));
+
+        $environment = sizeof($_GET);
+
+        InitGet($_GET);
+        if (empty($_GET["fPrintTable"]))
+            PrintForm($_GET, $db);
+
+        if ($environment==0)
+            printf("No query submitted yet.<BR>");
+        else
+        {
+            if (empty($_GET["fPrintTable"]))
+                PrintPage("1", $db);
+            else
+                PrintPage("2", $db);
+        }
+
+        echo (file_get_contents("index-footer.html"));
+    }
+
+    ini_set("display_errors", "Off");
+    ini_set("mysql.trace_mode", "Off");
+}
+?>
Index: trunk/MagicSoft/Mars/datacenter/db/findoffdata.php
===================================================================
--- trunk/MagicSoft/Mars/datacenter/db/findoffdata.php	(revision 7484)
+++ trunk/MagicSoft/Mars/datacenter/db/findoffdata.php	(revision 7484)
@@ -0,0 +1,638 @@
+<?php
+{
+    function CreateQuery($_GET, $alias, $checkwhere, $checkgroup, $checkstatusgroup)
+    {
+        $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 . "), '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.php?',  'fRunStart=On', '&fZenithDistance=On', '&fRunMin=', Sequences.fSequenceFirst, '&fMeanTriggerRate=On', '&fRunTypeName=On', '&fRunMax=', fSequenceLast, '&fNumEvents=On', '&fSourceName=On&', 'fExcludedFDAKEY=1', '&fSequenceFirst=On', '&fRawFileAvail=On', '&fCCFileAvail=On', '&fCaCoFileAvail=On', '&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 .= " 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["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("fStar");
+
+        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["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 || !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 ($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["fLastUpdate"]))
+            $_GET["fLastUpdate"]="Off";
+
+        if (empty($_GET["fNumEvents"]))
+            $_GET["fNumEvents"]="Off";
+
+        if (empty($_GET["fRunStart"]))
+            $_GET["fRunStart"]=$first?"On":"";
+
+        if (empty($_GET["fRunTime/60"]))
+            $_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";
+
+        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":"";
+
+        if (empty($_GET["fZenithDistanceMax"]))
+            $_GET["fZenithDistanceMax"]=$first?"On":"";
+
+        if (empty($_GET["fSourceName"]))
+            $_GET["fSourceName"]="On";
+
+        if (empty($_GET["fManuallyChangedName"]))
+            $_GET["fManuallyChangedName"]="Off";
+
+        if (empty($_GET["fLightConditionsName"]))
+            $_GET["fLightConditionsName"]=$first?"On":"";
+
+        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"]="Off";
+
+        if (empty($_GET["fMuonRate"]))
+            $_GET["fMuonRate"]=$first?"On":"";
+
+        if (empty($_GET["fDataRate"]))
+            $_GET["fDataRate"]=$first?"On":"";
+
+        if (empty($_GET["fMaxHumidity"]))
+            $_GET["fMaxHumidity"]="Off";
+
+    }
+
+    function PrintForm($_GET, $db, $limits, $rms, $alias)
+    {
+        printf("<center>\n");
+        printf("<form action=\"findoffdata.php\" METHOD=\"GET\">\n");
+
+        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(" <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.");
+
+        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");
+        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("fMaxHumidity",        "MaxHumidity");
+        CheckBox("fDataRate",           "CleanedEvtRate");
+
+        printf("  </tr>\n");
+        printf(" </table>\n");
+        printf(" <p>\n");
+
+        printf(" <table><tr><td>\n");
+
+        PrintPullDown($db, "Source",                      "fSourceName",                      "fSourceKEY",                      "Source Name");
+        printf("  </td><td>\n");
+        PrintPullDown($db, "LightConditions",             "fLightConditionsName",             "fLightConditionsKEY",             "Light Conditions");
+        printf("  </td><td>\n");
+        PrintPullDown($db, "ManuallyChanged",             "fManuallyChangedName",             "fManuallyChangedKEY",             "Manually changed");
+        printf("  </td><td>\n");
+        PrintStatusMenu("fStar",                "Star");
+
+        printf("</td></tr> </table>\n");
+        printf(" <p>\n");
+
+        printf(" <table>\n");
+        printf("  <tr>\n");
+
+        CheckBox("fLinks",    "Links");
+        CheckBox("fOff",      "incl. offsources");
+        CheckBox("fOnlyOff",  "only offsources");
+
+        printf("  </tr>\n");
+        printf(" </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");
+
+
+        if (empty($_GET["fStartDate"]))
+            $timemin = GetMin("fRunStart", "Sequences", $db);
+        else
+            $timemin = $_GET["fStartDate"];
+
+        if (empty($_GET["fStopDate"]))
+            $timemax = GetMax("fRunStart", "Sequences", $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", $db);
+        else
+            $min = $_GET["fRunMin"];
+
+        if (empty($_GET["fRunMax"]))
+            $max = GetMax("fSequenceFirst", "Sequences", $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");
+
+        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");
+
+        ini_set("mysql.trace_mode", "Off");
+        ini_set("display_errors", "Off");
+
+        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=\"findoffdata.php\"'>&nbsp;&nbsp;&nbsp;\n");
+        if (strchr($_SERVER["REQUEST_URI"], '?')!=FALSE)
+            printf("<input class='Width' type='button' value='Get .txt' onClick='self.location.href=\"%s&fSendTxt=1\"'>&nbsp;&nbsp;&nbsp;\n", $_SERVER["REQUEST_URI"]);
+        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("</form>\n");
+        printf("</center>\n");
+
+
+        printf("  </td></tr> </table>\n");
+
+        printf("</td>\n");
+        printf("</tr>\n");
+
+
+        printf("<tr class='Block'>\n");
+        printf("<td>\n");
+    }
+
+    function PrintPage($html, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $limits, $rms)
+    {
+        $db_id = mysql_connect("hercules.astro.uni-wuerzburg.de", "MAGIC", "d99swMT!");
+        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);
+
+        $result0 = mysql_query($query0, $db_id);
+
+        if ($result0)
+        {
+            if ($html=="1" || $html=="2")
+                PrintMagicTable($result0, $alias, $rightalign, $limits, $rms, $_GET);
+            else
+                PrintText($result0);
+
+            mysql_free_result($result0);
+        }
+        mysql_close($db_id);
+
+        if ($html=="1")
+            printf("<U><B>submitted query:</B></U><BR>%s<BR>", htmlspecialchars($query0));
+    }
+
+    include ("include.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", $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $limits, $rms);
+    }
+    else
+    {
+        echo (file_get_contents("index-header.html"));
+
+        $environment = sizeof($_GET);
+
+        InitGet($_GET);
+        if (empty($_GET["fPrintTable"]))
+            PrintForm($_GET, $db, $limits, $rms, $alias);
+
+        if ($environment==0)
+            printf("No query submitted yet.<BR>");
+        else
+        {
+            if (empty($_GET["fPrintTable"]))
+                PrintPage("1", $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $limits, $rms);
+            else
+                PrintPage("2", $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $limits, $rms);
+        }
+
+        echo (file_get_contents("index-footer.html"));
+    }
+
+    ini_set("display_errors", "Off");
+    ini_set("mysql.trace_mode", "Off");
+}
+?>
Index: trunk/MagicSoft/Mars/datacenter/db/include.php
===================================================================
--- trunk/MagicSoft/Mars/datacenter/db/include.php	(revision 7484)
+++ trunk/MagicSoft/Mars/datacenter/db/include.php	(revision 7484)
@@ -0,0 +1,611 @@
+<?php
+/*
+function PrintTable($table)
+{
+    $db_id = mysql_connect("hercules.astro.uni-wuerzburg.de", "MAGIC", "d99swMT!");
+    if ($db_id==FALSE)
+    {
+            printf("mysql_connect returned the following error:<br>");
+            printf("%s<br>", mysql_error());
+            die("");
+    }
+    printf("%s<br>", $table);
+    printf("<table BORDER=\"1\">");
+
+    $query = "EXPLAIN ";
+    $query .= $table;
+    
+    $result = mysql_query($query);
+    $numrows = mysql_num_rows($result);
+    $numcols = mysql_num_fields($result);
+    printf("%d x %d<br>", $numrows, $numcols);
+
+    printf("<tr>");
+    for ($i=0; $i<$numrows; $i++)
+    {
+       $row = mysql_fetch_row($result);
+       printf("<th>%s</th> ", $row[0]);
+    }
+    printf("</tr>");
+    
+    $query = "SELECT * FROM ";
+    $query .= $table;
+    
+    $result = mysql_query($query);
+    
+    $numrows = mysql_num_rows($result);
+    $numcols = mysql_num_fields($result);
+    printf("%d x %d<br>", $numrows, $numcols);
+
+    while ($row = mysql_fetch_row($result))
+    {
+       printf("<tr>");
+       foreach ($row as $entry)
+       {
+     	   printf("<td>%s</td> ", $entry);
+       }
+       printf("</tr>");
+    }
+    printf("</table>");
+    
+    mysql_free_result($result);
+
+    mysql_close($db_id);
+}
+*/
+
+function EnumQuery($name)
+{
+    $var  = $name . "Enum";
+    $txt  = "";
+    switch ($_GET[$var])
+    {
+    case 0: $txt .= ""; break;
+    case 1: $txt .= $name . "='yes' AND "; break;
+    case 2: $txt .= $name . "='no' AND "; break;
+    case 3: $txt .= ""; break;
+    }
+    return $txt;
+}
+
+function PrintEnumMenu($name, $text)
+{
+    $var = $name . "Enum";
+
+    if ($_GET[$name]=="On")
+        $checked = "checked";
+    else
+        $checked = "";
+
+    printf("    <input type=\"checkbox\" name=\"%s\" value=\"On\" %s>%s\n", $name, $checked, $text);
+    printf("<BR>");
+
+    printf(" <select name=\"%s\">\n", $var);
+
+    $status = array
+        ( 0 => "all",
+          1 => "yes",
+          2 => "no",
+          3 => "group by"
+        );
+
+    $stat=$_GET[$var];
+    for ($i=0; $i<4; $i++)
+    {
+        if ($stat==$i)
+            printf("<option value=\"%d\" selected>%s</option>\n", $i, $status[$i]);
+        else
+            printf("<option value=\"%d\">%s</option>\n", $i, $status[$i]);
+    }
+
+    printf(" </select>\n");
+    printf(" &nbsp;&nbsp;&nbsp;\n");
+
+}
+
+function StatusQuery($name)
+{
+    $var  = $name . "Status";
+    $txt  = "";
+    switch ($_GET[$var])
+    {
+    case 0: $txt .= ""; break;
+    case 1: $txt .= "NOT (IsNull(" . $name . ") OR " . $name . "='1970-01-01 00:00:00') AND "; break;
+    case 2: $txt .= "IsNull(" . $name . ") AND "; break;
+    case 3: $txt .= $name ."='1970-01-01 00:00:00' AND "; break;
+    case 4: $txt .= ""; break;
+    }
+    return $txt;
+}
+
+function PrintStatusMenu($name, $text)
+{
+    $var = $name . "Status";
+
+    if ($_GET[$name]=="On")
+        $checked = "checked";
+    else
+        $checked = "";
+
+    printf("    <input type=\"checkbox\" name=\"%s\" value=\"On\" %s>%s\n", $name, $checked, $text);
+    printf("<BR>");
+
+    printf(" <select name=\"%s\">\n", $var);
+
+    $status = array
+        ( 0 => "all",
+          1 => "done",
+          2 => "not done",
+          3 => "not to be done",
+          4 => "group by"
+        );
+
+    $stat=$_GET[$var];
+    for ($i=0; $i<5; $i++)
+    {
+        if ($stat==$i)
+            printf("<option value=\"%d\" selected>%s</option>\n", $i, $status[$i]);
+        else
+            printf("<option value=\"%d\">%s</option>\n", $i, $status[$i]);
+    }
+
+    /*
+    $status = array("all", "done", "not done", "not to be done");
+    $counter = 0;
+    foreach ($status as $element)
+    {
+        if ($counter==$_GET[$var])
+            printf("<option value=\"%d\" selected>%3s</option>\n", $counter++, $element);
+        else
+            printf("<option value=\"%d\">%3s</option>\n", $counter++, $element);
+    }*/
+    printf(" </select>\n");
+    printf(" &nbsp;&nbsp;&nbsp;\n");
+
+}
+
+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($db, $table, $name, $index, $descr)
+{
+    $db_id = mysql_connect("hercules.astro.uni-wuerzburg.de", "MAGIC", "d99swMT!");
+    if ($db_id==FALSE)
+    {
+            printf("mysql_connect returned the following error:<br>");
+            printf("%s<br>", mysql_error());
+            die("");
+    }
+
+    $query   = "SELECT " . $index . ", " . $name . " FROM " . $db . "." . $table . " ORDER BY " . $name;
+    $result  = mysql_query($query);
+
+    if (!$result)
+    {
+        printf("-N/A-");
+        return;
+    }
+
+    $numrows = mysql_num_rows($result);
+
+    if ($_GET[$name]=="On")
+        $checked = "checked";
+    else
+        $checked = "";
+
+    printf("    <input type=\"checkbox\" name=\"%s\" value=\"On\" %s><A HREF=\"printtable.php?fTable=%s\">%s</A>\n", $name, $checked, $table, $descr);
+
+    printf("   <BR>\n");
+
+    printf("   <select name=\"%s\" size=\"1\" class=\"Width\">\n", $index);
+
+    if (empty($_GET[$index]) || $_GET[$index]==0)
+        printf("    <option value=\"0\" selected>--- ALL ---</option>\n");
+    else
+        printf("    <option value=\"0\">--- ALL ---</option>\n");
+
+    if (!empty($_GET[$index]) && $_GET[$index]==-1)
+        printf("    <option value=\"-1\" selected>--- GROUP BY ---</option>\n");
+    else
+        printf("    <option value=\"-1\">--- GROUP BY ---</option>\n");
+
+    while ($row = mysql_fetch_row($result))
+    {
+        if (!empty($_GET[$index]) && $_GET[$index]==$row[0])
+            printf("    <option value=\"%s\" selected>%s</option>\n", $row[0], $row[1]);
+        else
+            printf("    <option value=\"%s\">%s</option>\n", $row[0], $row[1]);
+    }
+    printf("   </select>\n");
+    printf("   &nbsp;\n", $index);
+    
+    mysql_free_result($result);
+
+    mysql_close($db_id);
+}
+
+function GetMin($field, $table, $db)
+{
+    $db_id = mysql_connect("hercules.astro.uni-wuerzburg.de", "MAGIC", "d99swMT!");
+    if ($db_id==FALSE)
+    {
+            printf("mysql_connect returned the following error:<br>");
+            printf("%s<br>", mysql_error());
+            die("");
+    }
+
+    $query  = "SELECT MIN(" . $field . ") FROM " . $db . "." . $table;
+    $result = mysql_query($query);
+    if (!$result)
+        return "0";
+
+    $row = mysql_fetch_row($result);
+
+    $min = $row[0];
+
+    mysql_free_result($result);
+    mysql_close($db_id);
+
+    return $min;
+}
+
+function GetMax($field, $table, $db)
+{
+    $db_id = mysql_connect("hercules.astro.uni-wuerzburg.de", "MAGIC", "d99swMT!");
+    if ($db_id==FALSE)
+    {
+            printf("mysql_connect returned the following error:<br>");
+            printf("%s<br>", mysql_error());
+            die("");
+    }
+
+    $query  = "SELECT MAX(" . $field . ") FROM " . $db . "." . $table;
+    $result = mysql_query($query);
+    if (!$result)
+        return "0";
+
+    $row = mysql_fetch_row($result);
+
+    $max = $row[0];
+
+    mysql_free_result($result);
+    mysql_close($db_id);
+
+    return $max;
+}
+/*
+function GetMin()
+{
+    $db_id = mysql_connect("hercules.astro.uni-wuerzburg.de", "MAGIC", "d99swMT!");
+    if ($db_id==FALSE)
+    {
+            printf("mysql_connect returned the following error:<br>");
+            printf("%s<br>", mysql_error());
+            die("");
+    }
+
+    $query  = "SELECT MIN(fRunNumber) FROM MyMagic.RunData";
+    $result = mysql_query($query);
+    if (!$result)
+        return "0";
+
+    $row = mysql_fetch_row($result);
+
+    $min = $row[0];
+
+    mysql_free_result($result);
+    mysql_close($db_id);
+
+    return $min;
+}
+
+function GetMax()
+{
+    $db_id = mysql_connect("hercules.astro.uni-wuerzburg.de", "MAGIC", "d99swMT!");
+    if ($db_id==FALSE)
+    {
+            printf("mysql_connect returned the following error:<br>");
+            printf("%s<br>", mysql_error());
+            die("");
+    }
+
+    $query  = "SELECT MAX(fRunNumber) FROM MyMagic.RunData";
+    $result = mysql_query($query);
+    if (!$result)
+        return "0";
+
+    $row = mysql_fetch_row($result);
+
+    $max = $row[0];
+
+    mysql_free_result($result);
+    mysql_close($db_id);
+
+    return $max;
+}
+*/
+
+function PrintText($result0)
+{
+    header("Content-type: application/octet");
+    header("Content-Disposition: attachment; filename=query-result.txt");
+
+    while ($row0 = mysql_fetch_assoc($result0))
+    {
+        foreach ($row0 as $key => $element)
+            printf("%s\t", $element);
+        printf("\n");
+    }
+}
+
+function Checkbox($value, $text)
+{
+    if ($_GET[$value]=="On")
+        $checked = "checked";
+    else
+        $checked = "";
+
+    printf("    <td><input type=\"checkbox\" name=\"%s\" value=\"On\" %s>%s</td>\n", $value, $checked, $text);
+}
+
+function CheckWhere($column, $_GET)
+{
+    foreach ($_GET as $key => $element)
+    {
+        if ($key==$column)
+        {
+            if ($element>0)
+                printf ("FIXED: %s<BR>", $column);
+            return $element;
+        }
+    }
+    return 0;
+}
+
+function CheckGroup($column, $_GET)
+{
+    foreach ($_GET as $key => $element)
+    {
+        if ($key==$column)
+        {
+            //if ($element==-1)
+            //    printf ("GROUP: %s<BR>", $column);
+            return $element;
+        }
+    }
+    return 0;
+}
+
+function CheckStatusGroup($column, $_GET)
+{
+    foreach ($_GET as $key => $element)
+        if ($key==$column)
+            if ($element==4)
+                return -1;
+    return 0;
+}
+
+function CheckEnumGroup($column, $_GET)
+{
+    foreach ($_GET as $key => $element)
+        if ($key==$column)
+            if ($element==3)
+                return -1;
+    return 0;
+}
+
+function CreateMenu($rows)
+{
+    $menu = "";
+
+    if (empty($_GET["fNumResults"]))
+        return;
+
+    if ($_GET["fNumStart"]!=0)
+    {
+        $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;
+        }
+        $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";
+    }
+    return $menu;
+}
+
+function RemoveSortBy($rows)
+{
+    $menu = "";
+
+    $uri = $_SERVER["REQUEST_URI"];
+    $pos = strpos($uri, "fSortBy");
+    $amp3=FALSE;
+    if ($pos!=FALSE)
+    {
+        $amp1 = substr($uri, 0, $pos-1);
+        $amp2 = substr($uri, $pos);
+        $amp3 = strchr($amp2, "&");
+
+        $uri = $amp1;
+    }
+
+    return $uri;
+}
+
+function FindAlias($alias, $search)
+{
+    foreach ($alias as $key => $element)
+        if ($element==$search)
+            return $key;
+
+    return "";
+}
+
+function PrintMagicTable($result0, $alias, $rightalign, $limits, $rms, $_GET)
+{
+    $col   = FALSE;
+    $first = TRUE;
+
+    $menu = CreateMenu(mysql_num_rows($result0));
+
+    printf("\n<center>\n<p>%s<P>\n", $menu);
+    printf("<table BORDER=\"0\">\n");
+    while ($row0 = mysql_fetch_assoc($result0))
+    {
+        if ($first)
+        {
+            printf(" <tr BGCOLOR='#C0C0C0'>\n");
+            $first = FALSE;
+            foreach ($row0 as $key => $element)
+            {
+                $col = FindAlias($alias, $key);
+
+                $ord="%2B";
+                $issort = "";
+                if (!empty($_GET["fSortBy"]) && substr($_GET["fSortBy"], 0, -1)==$col)
+                {
+                    if (substr($_GET["fSortBy"], -1)=="+")
+                    {
+                        $ord="-";
+                        $issort="&nbsp;<IMG SRC='down.gif'>";
+                    }
+                    else
+                        $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(" </tr>\n\n");
+        }
+
+        if (!$col)
+            printf(" <tr BGCOLOR='#E0E0E0'>\n");
+        else
+            printf(" <tr BGCOLOR='#D0D0D0'>\n");
+        $col = !$col;
+
+        foreach ($row0 as $key => $element)
+        {
+            if (empty($rightalign[$key]))
+                printf("  <td align=\"left\">");
+            else
+                printf("  <td align=\"right\">");
+
+            if (!(empty($limits) && empty($rms)))
+            {
+                foreach($limits as $key2 => $element2)
+                {
+                    $mean=$key2 . "Mean";
+                    $rms2=$key2 . "Rms";
+                    if ($key==$alias[$element2] && !empty($_GET[$mean]))
+                    {
+                        if ($rms[$key2]=="yes")
+                        {
+                            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'>");
+                            }
+                        }
+                        else
+                        {
+                            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'>");
+                            }
+                        }
+                    }
+
+                }
+            }
+
+            printf("&nbsp;%s&nbsp;</td>\n", str_replace("&ws;", " ", str_replace(" ", "&nbsp;", $element)));
+        }
+        printf(" </tr>\n");
+    }
+    printf("</table>\n");
+
+    /*
+     $info = mysql_info();
+     if (!empty($info))
+     printf("%s<BR>\n", $info);
+     */
+
+    printf("<P><B>Number of displayed results: %d</B><P><P>\n", mysql_num_rows($result0));
+    printf("%s\n", $menu);
+    printf("<P>\n");
+    printf("</center>\n");
+    printf("</tr><tr class='Block'><td>\n");
+}
+
+?>
Index: trunk/MagicSoft/Mars/datacenter/db/index-footer.html
===================================================================
--- trunk/MagicSoft/Mars/datacenter/db/index-footer.html	(revision 7484)
+++ trunk/MagicSoft/Mars/datacenter/db/index-footer.html	(revision 7484)
@@ -0,0 +1,23 @@
+</td>
+</tr>
+
+</table>
+
+<hr NOSHADE WIDTH="80%">
+<i><font color="#000099" size=-1>
+This Web Site is hosted by Apache for OS/2 and done by 
+<a href="mailto:tbretz@astro.uni-wuerzburg.de">Thomas&nbsp;Bretz</a>
+and
+<a href="mailto:dorner@astro.uni-wuerzburg.de">Daniela&nbsp;Dorner</a>.
+</font></i>
+<BR>&nbsp;<BR>
+<a href="http://validator.w3.org/check/referer">
+<img border="0"src="../../valid-html40.png" alt="Valid HTML 4.0!" height="20" width="66"></a>
+<BR>&nbsp;
+</center>
+</td>
+</tr>
+</table></center>
+
+</body>
+</html>
Index: trunk/MagicSoft/Mars/datacenter/db/index-header.html
===================================================================
--- trunk/MagicSoft/Mars/datacenter/db/index-header.html	(revision 7484)
+++ trunk/MagicSoft/Mars/datacenter/db/index-header.html	(revision 7484)
@@ -0,0 +1,61 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
+
+<html>
+<head>
+   <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+   <meta name="Author" content="Thomas Bretz">
+   <title>Magic Database</title>
+   <link rel="stylesheet" type="text/css" href="../mars.css">
+   <style type="text/css">
+    <!--
+       select.Width
+         { width: 150px; }
+       input.Width 
+         { width: 102px; }
+     -->
+   </style>
+</head>
+
+<body background="../background.gif" text="#000000" bgcolor="#000099" link="#1122FF" vlink="#8888FF" alink="#FF0000">
+&nbsp;
+
+<center><table class="Main" CELLPADDING="0">
+
+<tr>
+<td class="Edge"><img SRC="../ecke.gif" ALT=""></td>
+<td class="Header">
+<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;
+DB:&nbsp;
+<A HREF="index.php">Run</A>&nbsp;&nbsp;
+<A HREF="queryseq.php">Sequ</A>&nbsp;&nbsp;
+<A HREF="querycal.php">Cal</A>&nbsp;&nbsp;
+<A HREF="querystar.php">Star</A>&nbsp;&nbsp;
+<A HREF="queryrbk.php">Runbook</A>&nbsp;&nbsp;
+Info:&nbsp;
+<A HREF="runinfo.php">Run</A>&nbsp;&nbsp;
+<A HREF="sequinfo.php">Sequ</A>&nbsp;&nbsp;
+<A HREF="datasetinfo.php">DataSets</A>
+<BR>
+more:&nbsp;
+<A HREF="culminating.php">Culm</A>&nbsp;
+<A HREF="sequence.php">Sequ</A>&nbsp;
+<A HREF="sources.php">Sources</A>&nbsp;
+<A HREF="findoffdata.php">Off</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>
+<hr SIZE=1 NOSHADE WIDTH="80%">
+</td>
+</tr>
+
+<tr>
+<td COLSPAN="2" BGCOLOR="#FFFFFF">
+
+<center><table class="Inner" CELLPADDING=15>
+<tr  class="Block">
+<td>
Index: trunk/MagicSoft/Mars/datacenter/db/index.html
===================================================================
--- trunk/MagicSoft/Mars/datacenter/db/index.html	(revision 7484)
+++ trunk/MagicSoft/Mars/datacenter/db/index.html	(revision 7484)
@@ -0,0 +1,114 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
+
+<html>
+<head>
+   <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+   <meta name="Author" content="Thomas Bretz">
+   <title>Magic Database</title>
+   <link rel="stylesheet" type="text/css" href="../mars.css">
+</head>
+
+<body background="../background.gif" text="#000000" bgcolor="#000099" link="#1122FF" vlink="#8888FF" alink="#FF0000">
+&nbsp;
+
+<center>
+<table class="Main" CELLPADDING=0>
+
+<tr>
+<td class="Edge">
+<img SRC="../ecke.gif" ALT="">
+</td>
+<td class="Header">
+<font size=+1><B>Magic Database</B></font><BR>
+</td>
+</tr>
+
+<tr>
+<td COLSPAN=2 BGCOLOR="#FFFFFF">
+<hr SIZE=1 NOSHADE WIDTH="80%">
+<center>
+<table class="Inner" CELLPADDING=15>
+
+<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>
+Some useful queries:<p>
+<ul>
+<li><A HREF="runinfo.php">Run Information</A></li>
+<li><A HREF="sequinfo.php">Sequence Information</A></li>
+<li><A HREF="queryrbk.php">Runbook Database</A></li>
+<li><A HREF="datasetinfo.php">Dataset Information</A> 
+(<A HREF="http://www.astro.uni-wuerzburg.de/~dorner/analysis/datasets.html">comments</A>, 
+ <A HREF="http://www.astro.uni-wuerzburg.de/datacenter/datasets/">files</A>)</li>
+</ul>
+Other queries:<p>
+<ul>
+<li><A HREF="culminating.php">Sequences with Culmination</A> 
+(<A HREF="http://www.astro.uni-wuerzburg.de/results/culmination.html">information about 'culmination problem'</A>)</li>
+<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="datacheck.php">DataCheck</A>: datacheck values from sinope </li>
+<li><A HREF="findoffdata.php">Find Offdata</A>: find appropriate (off)data </li>
+</ul>
+Query Status:<p>
+<ul>
+<li><A HREF="statussbs.php">Sequence Build Status</A>: querying only the information from the table SequenceBuildStatus </li>
+<li><A HREF="statusrps.php">Run Process Status</A>: querying only the information from the table RunProcessStatus </li>
+<li><A HREF="statussps.php">Sequence Process Status</A>: querying only the information from the table SequenceProcessStatus </li>
+<li><A HREF="printtable.php?fTable=MarsVersion">Mars Versions in the DC</A>: querying all information from the table MarsVersions </li>
+<li><A HREF="dbstatus.php?fAllFilesAvailStatus=0&fCallisto=On&fCallistoStatus=4&fStar=On&fStarStatus=4&fFillCallistoStatus=0&fFillStarStatus=0&fSourceName=On&fSourceKEY=0&fSourceN=&fStartDate=0000-00-00&fStopDate=2010-10-04&fRunMin=3340&fRunMax=64713&fNumResults=20">Processing status</A> (a simplified version of sequinfo.php)</li>
+</ul>
+Some very simple queries:<p>
+<ul>
+<li><A HREF="index.php">Run Database</A>: querying only the information from the table RunData </li>
+<li><A HREF="queryseq.php">Sequence Database</A>: querying only the information from the table Sequences </li>
+<li><A HREF="querycal.php">Calibration Database</A>: querying only the information from the table Calibration </li>
+<li><A HREF="querystar.php">Star Database</A>: querying only the information from the table Star </li>
+</ul>
+<P>
+</td>
+</tr>
+
+</table>
+</center>
+
+<center>
+<hr NOSHADE WIDTH="80%"><i><font color="#000099"><font size=-1>This Web Site is 
+hosted by Apache for OS/2 and done by <a href="mailto:tbretz@astro.uni-wuerzburg.de">Thomas&nbsp;Bretz</a> and <a href="mailto:dorner@astro.uni-wuerzburg.de">Daniela&nbsp;Dorner</a> .</font></font></i><BR>
+&nbsp;<BR>
+<a href="http://validator.w3.org/check/referer"><img border="0"
+   src="../../valid-html40.png" alt="Valid HTML 4.0!" height="20" width="66"></a>
+</center>&nbsp;
+</tr>
+</table>
+
+<BR>
+
+<table class="Main">
+<tr>
+<!-- This is the old stylish counter....
+  <td ALIGN=RIGHT VALIGN=TOP>NedStat - website access statistics:&nbsp;<a href="http://de.nedstat.net/viewstat.asp?name=magicmars" onMouseover="status='Statistics on Web Access by NedStat.de';return true;" onMouseout="status='';return true;"><img SRC="http://de.nedstat.net/scripts/nedstat.dll?name=magicmars" ALT="STAT" BORDER=0 height=18 width=18 align=TEXTTOP></a></td>
+-->
+<td ALIGN=RIGHT VALIGN=MIDDLE><FONT COLOR="#FFFFFF">NedStat - website access statistics:&nbsp;</FONT>
+<!--<script language='JavaScript' src="http://m1.nedstatbasic.net/basic.js" type="text/javascript"></script>-->
+<script language="JavaScript" type="text/javascript">          
+<!--
+  nedstatbasic("AAGh1A6qQKZFLpl2rXaOC3LPo1OA", 0);
+// -->
+</script>
+<!--<noscript>-->
+<a target="_self" href="http://v1.nedstatbasic.net/stats?AAGh1A6qQKZFLpl2rXaOC3LPo1OA" onMouseover="status='Statistics on Web Access by NedStat.de';return true;" onMouseout="status='';return true;"></a>
+<!--</noscript>-->
+</td>
+
+</tr>
+</table>
+</center>
+
+</body>
+</html>
+
Index: trunk/MagicSoft/Mars/datacenter/db/index.php
===================================================================
--- trunk/MagicSoft/Mars/datacenter/db/index.php	(revision 7484)
+++ trunk/MagicSoft/Mars/datacenter/db/index.php	(revision 7484)
@@ -0,0 +1,424 @@
+<?php
+{
+    function CreateQuery($_GET, $alias, $checkwhere, $checkgroup, $checkstatusgroup)
+    {
+        $fromtable="RunData";
+
+        $groups = 0;
+        foreach ($checkgroup as $element)
+            if ($element==-1)
+                $groups++;
+
+        $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
+        {
+            $query0 .= " fRunNumber as 'Run#' ";
+
+            foreach ($_GET as $key => $element)
+                if ($_GET[$key]=="On")
+                    if (empty($checkwhere[$key]) || $checkwhere[$key]==0)
+                        $query0 .= ", " . $key . " as '" . $alias[$key] . "' ";
+        }
+
+        $query0 .= " FROM RunData ";
+
+        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)// 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 ";
+
+        if (!empty($_GET["fRunMin"]) && !empty($_GET["fRunMax"]))
+            $query0 .= "fRunNumber BETWEEN " . $_GET["fRunMin"] . " AND " . $_GET["fRunMax"] . " ";
+
+/*
+        if (!empty($_GET["fDate"]))
+            $query0 .= " AND fRunStart REGEXP \"^" . $_GET["fDate"] . "\" ";
+*/
+
+
+        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"]))
+        {
+            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 (!empty($_GET["fSortBy"]))
+        {
+            $query0 .= " ORDER BY " . substr($_GET["fSortBy"], 0, -1) . " ";
+            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)
+    {
+        /*
+         if (empty($_GET["fRawFileKEY"]))
+         $_GET["fRawFileKEY"]="Off";
+         */
+
+        // 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["fLastUpdate"]))
+            $_GET["fLastUpdate"]="Off";
+
+        if (empty($_GET["fFormatVersion"]))
+            $_GET["fFormatVersion"]="Off";
+
+        if (empty($_GET["fNumEvents"]))
+            $_GET["fNumEvents"]=$first?"On":"";
+
+        if (empty($_GET["fRunStart"]))
+            $_GET["fRunStart"]=$first?"On":"";
+
+        if (empty($_GET["fRunStop"]))
+            $_GET["fRunStop"]="Off";
+
+        if (empty($_GET["fAzimuth"]))
+            $_GET["fAzimuth"]="Off";
+
+        if (empty($_GET["fZenithDistance"]))
+            $_GET["fZenithDistance"]=$first?"On":"";
+
+        if (empty($_GET["fRunTypeName"]))
+            $_GET["fRunTypeName"]=$first?"On":"";
+
+        if (empty($_GET["fMagicNumberName"]))
+            $_GET["fMagicNumberName"]="Off";
+
+        if (empty($_GET["fSourceName"]))
+            $_GET["fSourceName"]=$first?"On":"";
+
+        if (empty($_GET["fProjectName"]))
+            $_GET["fProjectName"]="Off";
+
+        if (empty($_GET["fL1TriggerTableName"]))
+            $_GET["fL1TriggerTableName"]="Off";
+
+        if (empty($_GET["fL2TriggerTableName"]))
+            $_GET["fL2TriggerTableName"]="Off";
+
+        if (empty($_GET["fMeanTriggerRate"]))
+            $_GET["fMeanTriggerRate"]=$first?"On":"";
+
+        if (empty($_GET["fHvSettingsName"]))
+            $_GET["fHvSettingsName"]="Off";
+
+        if (empty($_GET["fCalibrationScriptName"]))
+            $_GET["fCalibrationScriptName"]="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";
+
+        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["fExcludedFDAName"]))
+            $_GET["fExcludedFDAName"]=$first?"On":"";
+
+        if (empty($_GET["fSequenceFirst"]))
+            $_GET["fSequenceFirst"]="Off";
+    }
+
+    function PrintForm($_GET, $db)
+    {
+        printf("<center>\n");
+        printf("<form action=\"index.php\" METHOD=\"GET\">\n");
+        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");
+
+        printf("  </tr>\n");
+        printf(" </table>\n");
+         printf(" <p>\n");
+
+        // pull down boxes
+
+        printf(" <table>\n");
+        printf("  <tr><td>\n");
+        PrintPullDown($db, "RunType",     "fRunTypeName",     "fRunTypeKEY", "Run type");
+        printf("  </td><td>\n");
+        PrintPullDown($db, "Source",      "fSourceName",      "fSourceKEY", "Source Name");
+        printf("  </td><td>\n");
+        PrintPullDown($db, "HvSettings",  "fHvSettingsName",  "fHvSettingsKEY", "HV Settings");
+        printf("  </td><td>\n");
+        PrintPullDown($db, "L1TriggerTable", "fL1TriggerTableName", "fL1TriggerTableKEY", "L1 Trigger Table");
+        printf("  </td></tr><tr><td>\n");
+        PrintPullDown($db, "TestFlag",  "fTestFlagName",  "fTestFlagKEY", "Test Flag");
+        printf("  </td><td>\n");
+        PrintPullDown($db, "Project",     "fProjectName",     "fProjectKEY", "Project Name");
+        printf("  </td><td>\n");
+        PrintPullDown($db, "DiscriminatorThresholdTable",  "fDiscriminatorThresholdTableName",  "fDiscriminatorThresholdTableKEY", "DT Table");
+        printf("  </td><td>\n");
+        PrintPullDown($db, "L2TriggerTable", "fL2TriggerTableName", "fL2TriggerTableKEY", "L2 Trigger Table");
+        printf("  </td></tr><tr><td>\n");
+        PrintPullDown($db, "ExcludedFDA", "fExcludedFDAName", "fExcludedFDAKEY", "Exclusions");
+        printf("  </td><td>\n");
+        PrintPullDown($db, "LightConditions",  "fLightConditionsName",  "fLightConditionsKEY", "Light Conditions");
+        printf("  </td><td>\n");
+        PrintPullDown($db, "CalibrationScript",  "fCalibrationScriptName",  "fCalibrationScriptKEY", "Cal Script");
+        printf("  </td><td>\n");
+        PrintPullDown($db, "TriggerDelayTable",  "fTriggerDelayTableName",  "fTriggerDelayTableKEY", "Trigger Delay Table");
+        printf("  </td></tr><tr><td>\n");
+        PrintPullDown($db, "MagicNumber", "fMagicNumberName", "fMagicNumberKEY", "Magic Number");
+        printf(" </td></tr></table>\n");
+        printf(" <p>\n");
+
+        if (empty($_GET["fStartDate"]))
+            $timemin = GetMin("fRunStart", "RunData", $db);
+        else
+            $timemin = $_GET["fStartDate"];
+
+        if (empty($_GET["fStopDate"]))
+            $timemax = GetMax("fRunStart", "RunData", $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);
+
+/*
+        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");
+*/
+
+        if (empty($_GET["fRunMin"]))
+            $min = GetMin("fRunNumber", "RunData", $db);
+        else
+            $min = $_GET["fRunMin"];
+
+        if (empty($_GET["fRunMax"]))
+            $max = GetMax("fRunNumber", "RunData", $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);
+
+        printf(" <P>\n");
+
+        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");
+
+        printf(" Results:\n");
+        printf(" <select name=\"fNumResults\">\n");
+
+        $numres = array("10", "20", "50", "100", "200", "500", "1000", "2000");
+        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");
+
+        ini_set("mysql.trace_mode", "Off");
+        ini_set("display_errors", "Off");
+
+        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=\"index.php\"'>&nbsp;&nbsp;&nbsp;\n");
+        if (strchr($_SERVER["REQUEST_URI"], '?')!=FALSE)
+            printf("<input class='Width' type='button' value='Get .txt' onClick='self.location.href=\"%s&fSendTxt=1\"'>&nbsp;&nbsp;&nbsp;\n", $_SERVER["REQUEST_URI"]);
+        printf("</form>\n");
+        printf("</center>\n");
+        printf("</td>\n");
+        printf("</tr>\n");
+        printf("<tr class='Block'>\n");
+        printf("<td>\n");
+    }
+
+    function PrintPage($html, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup)
+    {
+        $db_id = mysql_connect("hercules.astro.uni-wuerzburg.de", "MAGIC", "d99swMT!");
+        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);
+
+        $result0 = mysql_query($query0, $db_id);
+
+        if ($result0)
+        {
+            if ($html=="1")
+                PrintMagicTable($result0, $alias, $rightalign, "", "", $_GET);
+            else
+                PrintText($result0);
+
+            mysql_free_result($result0);
+        }
+        mysql_close($db_id);
+
+        if ($html=="1")
+            printf("<U><B>submitted query:</B></U><BR>%s<BR>", htmlspecialchars($query0));
+    }
+
+    include ("include.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", $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup);
+    }
+    else
+    {
+        echo (file_get_contents("index-header.html"));
+
+        $environment = sizeof($_GET);
+
+        InitGet($_GET);
+        PrintForm($_GET, $db);
+
+        if ($environment==0)
+            printf("No query submitted yet.<BR>");
+        else
+            PrintPage("1", $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup);
+
+        echo (file_get_contents("index-footer.html"));
+    }
+
+    ini_set("display_errors",   "Off");
+    ini_set("mysql.trace_mode", "Off");
+}
+?>
Index: trunk/MagicSoft/Mars/datacenter/db/magicdefs.php
===================================================================
--- trunk/MagicSoft/Mars/datacenter/db/magicdefs.php	(revision 7484)
+++ trunk/MagicSoft/Mars/datacenter/db/magicdefs.php	(revision 7484)
@@ -0,0 +1,493 @@
+<?php
+
+$limits = array
+    (
+     "fPedRmsInLimit"    => "fMeanPedRmsInner",
+     "fArrTimeLimit"     => "fArrTimeRmsInner",
+     "fMuonRateLimit"    => "fMuonRate",
+     "fPSFLimit"         => "fPSF",
+     "fImgRateLimit"     => "fDataRate",
+     "fUnsInLimit"       => "fUnsuitableInner",
+     "fZdMinLimit"       => "fZenithDistanceMin",
+     "fZdMaxLimit"       => "fZenithDistanceMax",
+    );
+
+$rms = array
+    (
+     "fPedRmsInLimit"    => "yes",
+     "fArrTimeLimit"     => "yes",
+     "fMuonRateLimit"    => "yes",
+     "fUnsInLimit"       => "max",
+     "fPSFLimit"         => "yes",
+     "fImgRateLimit"     => "yes",
+     "fZdMinLimit"       => "min",
+     "fZdMaxLimit"       => "max",
+    );
+
+$checkwhere = array
+    (
+     "fRunTypeName"                      => CheckWhere("fRunTypeKEY",                      $_GET),
+     "fProjectName"                      => CheckWhere("fProjectKEY",                      $_GET),
+     "fSourceName"                       => CheckWhere("fSourceKEY",                       $_GET),
+     "fMagicNumberName"                  => CheckWhere("fMagicNumberKEY",                  $_GET),
+     "fL1TriggerTableName"               => CheckWhere("fL1TriggerTableKEY",               $_GET),
+     "fL2TriggerTableName"               => CheckWhere("fL2TriggerTableKEY",               $_GET),
+     "fHvSettingsName"                   => CheckWhere("fHvSettingsKEY",                   $_GET),
+     "fCalibrationScriptName"            => CheckWhere("fCalibrationScriptKEY",            $_GET),
+     "fExcludedFDAName"                  => CheckWhere("fExcludedFDAKEY",                  $_GET),
+     "fManuallyChangedName"              => CheckWhere("fManuallyChangedKEY",              $_GET),
+     "fDiscriminatorThresholdTableName"  => CheckWhere("fDiscriminatorThresholdTableKEY",  $_GET),
+     "fTriggerDelayTableName"            => CheckWhere("fTriggerDelayTableKEY",            $_GET),
+     "fTestFlagName"                     => CheckWhere("fTestFlagKEY",                     $_GET),
+     "fLightConditionsName"              => CheckWhere("fLightConditionsKEY",              $_GET),
+    );
+
+$checkgroup = array
+    (
+     "fRunTypeName"                      => CheckGroup("fRunTypeKEY",                      $_GET),
+     "fProjectName"                      => CheckGroup("fProjectKEY",                      $_GET),
+     "fSourceName"                       => CheckGroup("fSourceKEY",                       $_GET),
+     "fMagicNumberName"                  => CheckGroup("fMagicNumberKEY",                  $_GET),
+     "fL1TriggerTableName"               => CheckGroup("fL1TriggerTableKEY",               $_GET),
+     "fL2TriggerTableName"               => CheckGroup("fL2TriggerTableKEY",               $_GET),
+     "fHvSettingsName"                   => CheckGroup("fHvSettingsKEY",                   $_GET),
+     "fCalibrationScriptName"            => CheckGroup("fCalibrationScriptKEY",            $_GET),
+     "fExcludedFDAName"                  => CheckGroup("fExcludedFDAKEY",                  $_GET),
+     "fManuallyChangedName"              => CheckGroup("fManuallyChangedKEY",              $_GET),
+     "fDiscriminatorThresholdTableName"  => CheckGroup("fDiscriminatorThresholdTableKEY",  $_GET),
+     "fTriggerDelayTableName"            => CheckGroup("fTriggerDelayTableKEY",            $_GET),
+     "fTestFlagName"                     => CheckGroup("fTestFlagKEY",                     $_GET),
+     "fLightConditionsName"              => CheckGroup("fLightConditionsKEY",              $_GET),
+    );
+
+
+$checkstatusgroup = array
+    (
+     "fCCFilled"                         => CheckStatusGroup("fCCFilledStatus",            $_GET),
+     "fExclusionsDone"                   => CheckStatusGroup("fExclusionsDoneStatus",      $_GET),
+     "fSequenceEntriesBuilt"             => CheckStatusGroup("fSequenceEntriesBuiltStatus",$_GET),
+     "fCCFileAvail"                      => CheckStatusGroup("fCCFileAvailStatus",         $_GET),
+     "fCaCoFileAvail"                    => CheckStatusGroup("fCaCoFileAvailStatus",       $_GET),
+     "fCaCoFileFound"                    => CheckStatusGroup("fCaCoFileFoundStatus",       $_GET),
+     "fRawFileAvail"                     => CheckStatusGroup("fRawFileAvailStatu",         $_GET),
+     "fTimingCorrection"                 => CheckStatusGroup("fTimingCorrectionStatus",    $_GET),
+     "fDataCheckDone"                    => CheckStatusGroup("fDataCheckDoneStatus",       $_GET),
+//     "fFillDotRaw"                       => CheckStatusGroup("fFillDotRawStatus",          $_GET),
+     "fSequenceFileWritten"              => CheckStatusGroup("fSequenceFileWrittenStatus", $_GET),
+     "fAllFilesAvail"                    => CheckStatusGroup("fAllFilesAvailStatus",       $_GET),
+     "fCallisto"                         => CheckStatusGroup("fCallistoStatus",            $_GET),
+     "fFillCallisto"                     => CheckStatusGroup("fFillCallistoStatus",        $_GET),
+     "fStar"                             => CheckStatusGroup("fStarStatus",                $_GET),
+     "fFillStar"                         => CheckStatusGroup("fFillStarStatus",            $_GET),
+     "fDataSetInserted"                  => CheckStatusGroup("fDataSetInsertedStatus",     $_GET),
+     "fStarFilesAvail"                   => CheckStatusGroup("fStarFilesAvailStatus",      $_GET),
+     "fGanymed"                          => CheckStatusGroup("fGanymedStatus",             $_GET),
+     "fFillGanymed"                      => CheckStatusGroup("fFillGanymedStatus",         $_GET),
+    );
+
+
+$checkenumgroup = array
+    (
+     "fHasSignal"              => CheckEnumGroup("fHasSignalEnum",             $_GET),
+     "fHasPedestal"            => CheckEnumGroup("fHasPedestalEnum",           $_GET),
+     "fHasSignalInterlaced"    => CheckEnumGroup("fHasSignalInterlacedEnum",   $_GET),
+     "fHasPedestalInterlaced"  => CheckEnumGroup("fHasPedestalInterlacedEnum", $_GET),
+    );
+
+
+
+$alias = array
+    (
+     "fRawFileKEY"                      => "Idx",
+     "fMagicNumberName"                 => "Magic#",
+     "fFormatVersion"                   => "F-Ver",
+     "fLastUpdate"                      => "LastUpd",
+     "fRunNumber"                       => "Run#",
+     "fRunTypeName"                     => "RunType",
+     "fMeanTriggerRate"                 => "Rate<br>[Hz]",
+     "fDaqTriggerRate"                  => "Daq<br>TRate<br>[Hz]",
+     "fDaqStoreRate"                    => "Daq<br>SRate<br>[Hz]",
+     "fL2RatePresc"                     => "L2<br>pRate<br>[Hz]",
+     "fL2RateUnpresc"                   => "L2<br>upRate<br>[Hz]",
+     "fManuallyChangedName"             => "Manually<br>Changed",
+     "fLastUpdate"                      => "LastUpd",
+     "fSequenceFirst"                   => "Sequ",
+     "fProjectName"                     => "Project",
+     "fSourceName"                      => "Source",
+     "fNumEvents"                       => "#Evts",
+     "fRunTime/60"                      => "Up<br>Time<br>[min]",
+     "fRunStart"                        => "Start",
+     "fRunStop"                         => "Stop",
+//     "fRunStart"                        => "StartTime",
+     "fSequenceLast"                    => "Last<br>Run",
+     "fL1TriggerTableName"              => "L1Trig<br>Table",
+     "fL2TriggerTableName"              => "L2Trig<br>Table",
+     "fHvSettingsName"                  => "HV Settings",
+     "fCalibrationScriptName"           => "Cal Script",
+     "fTestFlagName"                    => "Testflag",
+     "fLightConditionsName"             => "Lightcond",
+     "fTriggerDelayTableName"           => "TrigDelay",
+     "fDiscriminatorThresholdTableName" => "DT",
+     "fExcludedFDAName"                 => "Exclusion",
+     "fZenithDistance"                  => "Zd",
+     "fAzimuth"                         => "Az",
+     "fZenithDistanceMin"               => "Zd<br>Min",
+     "fZenithDistanceMax"               => "Zd<br>Max",
+     "fAzimuthMin"                      => "Az<br>Min",
+     "fAzimuthMax"                      => "Az<br>Max",
+     "fTest"                            => "Test",
+     "fSourceKEY"                       => "KEY",
+     "fDate"                            => "Date",
+     "fCCFilled"                        => "CCFilled",
+     "fExclusionsDone"                  => "Exclusions",
+     "fSequenceEntriesBuilt"            => "Sequences",
+     "fCCFileAvail"                     => "CCFile",
+     "fCaCoFileAvail"                   => "CaCoFile",
+     "fCaCoFileFound"                   => "CaCoRun",
+     "fRawFileAvail"                    => "Rawfile",
+     "fTimingCorrection"                => "TimingCorr",
+     "fDataCheckDone"                   => "Datacheck",
+//     "fFillDotRaw"                      => "Filldotraw",
+     "fSequenceFileWritten"             => "SequFile",
+     "fAllFilesAvail"                   => "FilesAvail",
+     "fCallisto"                        => "Callisto",
+     "fStar"                            => "Star",
+     "fFillCallisto"                    => "FillCal",
+     "fFillStar"                        => "FillStar",
+     "fDataSetInserted"                 => "DataSet",
+     "fStarFilesAvail"                  => "FilesAvail",
+     "fGanymed"                         => "Ganymed",
+     "fFillGanymed"                     => "FillGanymed",
+     "fUnsuitableOuter"                 => "Un<br>suit.<br>Out",
+     "fUnreliableOuter"                 => "Un<br>rel.<br>Out",
+     "fUnreliableInner"                 => "Un<br>rel.<br>In",
+     "fUnsuitableInner"                 => "Un<br>suit.<br>In",
+     "fIsolatedOuter"                   => "Isol.<br>Out",
+     "fIsolatedInner"                   => "Isol.<br>In",
+     "fMeanPedRmsOuter"                 => "Ped<br>Rms<br>Out",
+     "fMeanPedRmsInner"                 => "Ped<br>Rms<br>In",
+     "fArrTimeMeanInner"                => "Arr<br>Time<br>In",
+     "fArrTimeMeanOuter"                => "Arr<br>Time<br>Out",
+     "fArrTimeRmsInner"                 => "Rms<br>ArrT<br>In",
+     "fArrTimeRmsOuter"                 => "Rms<br>ArrT<br>Out",
+     "fConvFactorInner"                 => "Conv<br>In",
+     "fConvFactorOuter"                 => "Conv<br>Out",
+     //             "fConvFactorInner"                 => "Conv Inner<BR>[ph/FADC]",
+     //             "fConvFactorOuter"                 => "Conv Outer<BR>[ph/FADC]",
+     "fIsolatedMaxCluster"              => "Isol.<br>Max<br>Cl",
+     "fMeanNumberIslands"               => "Mean<br>Num<br>Isl",
+     "fPSF"                             => "PSF<br>[mm]",
+     "fRatio"                           => "Ratio<br>[%]",
+     "fMuonNumber"                      => "#<br>Muons",
+     "fEffOnTime"                       => "EffOn<br>Time<br>[s]",
+     "fEffOnTime/3600"                  => "EffOn<br>Time<br>[h]",
+     "fMuonRate"                        => "Muon<br>Rate<br>[Hz]",
+     "fDataRate"                        => "Img.<br>Rate<br>[Hz]",
+     "fMaxHumidity"                     => "Max<br>Hum<br>[%]",
+     "fEvents"                          => "DataEvents",
+     "fPositionSignal"                  => "ArrTime",
+     "fPositionFWHM"                    => "ArrTimeFWHM",
+     "fHeightSignal"                    => "Signal",
+     "fHeightFWHM"                      => "SignalFWHM",
+     "fHasSignal"                       => "HasSignal",
+     "fHasPedestal"                     => "HasPedestal",
+     "fPositionAsym"                    => "ArrTimeAsym",
+     "fHeightAsym"                      => "SignalAsym",
+     "fEventsInterlaced"                => "CalEvents",
+     "fPositionSignalInterlaced"        => "ArrTimeCal",
+     "fPositionFWHMInterlaced"          => "ArrTimeFWHMCal",
+     "fHeightSignalInterlaced"          => "SignalCal",
+     "fHeightFWHMInterlaced"            => "SignalFWHMCal",
+     "fHasSignalInterlaced"             => "HasSignalCal",
+     "fHasPedestalInterlaced"           => "HasPedestalCal",
+     "fPositionAsymInterlaced"          => "ArrTimeAsymCal",
+     "fHeightAsymInterlaced"            => "SignalAsymCal",
+     "fExcessEvents"                    => "Exc<br>Evts",
+     "fBackgroundEvents"                => "Bg<br>Evts",
+     "fSignalEvents"                    => "Sign<br>Evts",
+     "fSignificance"                    => "Sign",
+     "fScaleFactor"                     => "Scale",
+     "fDataSetNumber"                   => "Data<br>Set#",
+     "fWobble"                          => "Wobble",
+     "fComment"                         => "Comment",
+     "fExcessEvents*60/fEffOnTime"      => "Exc<br>Rate",
+     "fBackgroundEvents*60/fEffOnTime"  => "Bg<br>Rate",
+     "fSignalEvents*60/fEffOnTime"      => "Sign<br>Rate",
+     "Round(fSignificance/Sqrt(fEffOnTime/3600),2)" => "Signf<br>Rate",
+     "SUM(fRunTime)/3600"               => "Time [h]",
+     "SUM(fNumEvents)"                  => "Evts",
+     "Min(fZenithDistanceMin)"          => "ZDMin",
+     "Max(fZenithDistanceMax)"          => "ZDMax",
+     "Min(fZenithDistance)"             => "ZdMin",
+     "Max(fZenithDistance)"             => "ZdMax",
+     "COUNT(*)"                         => "Sequence",
+     "fArrTimeLimit"                    => "ArrTRms",
+     "fPedRmsInLimit"                   => "PedRms",
+     "fMuonRateLimit"                   => "MuonRate",
+     "fPSFLimit"                        => "PSF",
+     "fImgRateLimit"                    => "ImgRate",
+     "fUnsInLimit"                      => "Unsuit.In",
+     "fZdMinLimit"                      => "ZdMin",
+     "fZdMaxLimit"                      => "ZdMax",
+    );
+
+
+$rightalign = array
+    (
+     $alias["fRawFileKEY"]               => "1",
+     $alias["fFormatVersion"]            => "1",
+     $alias["fRunNumber"]                => "1",
+     $alias["fZenithDistance"]           => "1",
+     $alias["fAzimuth"]                  => "1",
+     $alias["fMeanTriggerRate"]          => "1",
+     $alias["fDaqTriggerRate"]           => "1",
+     $alias["fDaqStoreRate"]             => "1",
+     $alias["fL2RatePresc"]              => "1",
+     $alias["fL2RateUnpresc"]            => "1",
+     $alias["fSequenceFirst"]            => "1",
+     $alias["fNumEvents"]                => "1",
+     $alias["fRunTime/60"]               => "1",
+     $alias["fSequenceLast"]             => "1",
+     $alias["fZenithDistanceMin"]        => "1",
+     $alias["fZenithDistanceMax"]        => "1",
+     $alias["fAzimuthMin"]               => "1",
+     $alias["fAzimuthMax"]               => "1",
+     $alias["fUnsuitableOuter"]          => "1",
+     $alias["fUnreliableOuter"]          => "1",
+     $alias["fUnsuitableInner"]          => "1",
+     $alias["fUnreliableInner"]          => "1",
+     $alias["fIsolatedOuter"]            => "1",
+     $alias["fIsolatedInner"]            => "1",
+     $alias["fMeanPedRmsOuter"]          => "1",
+     $alias["fMeanPedRmsInner"]          => "1",
+     $alias["fArrTimeMeanInner"]         => "1",
+     $alias["fArrTimeMeanOuter"]         => "1",
+     $alias["fArrTimeRmsInner"]          => "1",
+     $alias["fArrTimeRmsOuter"]          => "1",
+     $alias["fConvFactorInner"]          => "1",
+     $alias["fConvFactorOuter"]          => "1",
+     $alias["fIsolatedMaxCluster"]       => "1",
+     $alias["fMeanNumberIslands"]        => "1",
+     $alias["fPSF"]                      => "1",
+     $alias["fRatio"]                    => "1",
+     $alias["fMuonNumber"]               => "1",
+     $alias["fEffOnTime"]                => "1",
+     $alias["fEffOnTime/3600"]           => "1",
+     $alias["fMuonRate"]                 => "1",
+     $alias["fDataRate"]                 => "1",
+     $alias["fMaxHumidity"]              => "1",
+     $alias["fDate"]                     => "1",
+     $alias["fCaCoFileFound"]            => "1",
+     $alias["fTest"]                     => "1",
+     $alias["fSourceKEY"]                => "1",
+     $alias["fEvents"]                   => "1",
+     $alias["fPositionSignal"]           => "1",
+     $alias["fPositionFWHM"]             => "1",
+     $alias["fHeightSignal"]             => "1",
+     $alias["fHeightFWHM"]               => "1",
+     $alias["fHasSignal"]                => "1",
+     $alias["fHasPedestal"]              => "1",
+     $alias["fPositionAsym"]             => "1",
+     $alias["fHeightAsym"]               => "1",
+     $alias["fEventsInterlaced"]         => "1",
+     $alias["fPositionSignalInterlaced"] => "1",
+     $alias["fPositionFWHMInterlaced"]   => "1",
+     $alias["fHeightSignalInterlaced"]   => "1",
+     $alias["fHeightFWHMInterlaced"]     => "1",
+     $alias["fHasSignalInterlaced"]      => "1",
+     $alias["fHasPedestalInterlaced"]    => "1",
+     $alias["fPositionAsymInterlaced"]   => "1",
+     $alias["fHeightAsymInterlaced"]     => "1",
+     "Time"                              => "1",
+//     "Time [h]"                 => "1",
+     "ZDMin"                             => "1",
+     "ZDMax"                             => "1",
+//     "Evts#"                    => "1",
+//     "Runs#"                    => "1"
+     "Runs"                              => "1",
+     "Evts"                              => "1",
+);
+
+function GetCheck($fromtable, $val)
+{
+    $checks = array
+        (
+         "fRunTypeName"                      => $fromtable . ".fRunTypeKEY",
+         "fProjectName"                      => $fromtable . ".fProjectKEY",
+         "fSourceName"                       => $fromtable . ".fSourceKEY",
+         "fMagicNumberName"                  => $fromtable . ".fMagicNumberKEY",
+         "fL1TriggerTableName"               => $fromtable . ".fL1TriggerTableKEY",
+         "fL2TriggerTableName"               => $fromtable . ".fL2TriggerTableKEY",
+         "fHvSettingsName"                   => $fromtable . ".fHvSettingsKEY",
+         "fCalibrationScriptName"            => $fromtable . ".fCalibrationScriptKEY",
+         "fExcludedFDAName"                  => $fromtable . ".fExcludedFDAKEY",
+         "fManuallyChangedName"              => $fromtable . ".fManuallyChangedKEY",
+         "fDiscriminatorThresholdTableName"  => $fromtable . ".fDiscriminatorThresholdTableKEY",
+         "fTriggerDelayTableName"            => $fromtable . ".fTriggerDelayTableKEY",
+         "fTestFlagName"                     => $fromtable . ".fTestFlagKEY",
+         "fLightConditionsName"              => $fromtable . ".fLightConditionsKEY",
+        );
+
+    $check="";
+    if (!empty($checks[$val]))
+        $check=$checks[$val];
+    return $check;
+}
+
+
+function GetTable($fromtable, $val)
+{
+    $tables = array
+        (
+         "fSequenceFirst"                    => $fromtable . ".fSequenceFirst",
+         "fSequenceLast"                     => $fromtable . ".fSequenceLast",
+         "fNumEvents"                        => $fromtable . ".fNumEvents",
+         "fRunStart"                         => $fromtable . ".fRunStart",
+         "fLastUpdate"                       => $fromtable . ".fLastUpdate",
+         "fRunTime"                          => $fromtable . ".fRunTime",
+         "fRunTime/60"                       => $fromtable . ".fRunTime/60",
+         "fAzimuthMin"                       => $fromtable . ".fAzimuthMin",
+         "fAzimuthMax"                       => $fromtable . ".fAzimuthMax",
+         "fZenithDistanceMin"                => $fromtable . ".fZenithDistanceMin",
+         "fZenithDistanceMax"                => $fromtable . ".fZenithDistanceMax",
+         "fRunNumber"                        => "RunData.fRunNumber",
+         "fRunStop"                          => "RunData.fRunStop",
+         "fAzimuth"                          => "RunData.fAzimuth",
+         "fZenithDistance"                   => "RunData.fZenithDistance",
+         "fFormatVersion"                    => "RunData.fFormatVersion",
+         "fRunTypeName"                      => "RunType.fRunTypeName",
+         "fDaqStoreRate"                     => "RunData.fDaqStoreRate",
+         "fDaqTriggerRate"                   => "RunData.fDaqTriggerRate",
+         "fMeanTriggerRate"                  => "RunData.fMeanTriggerRate",
+         "fL2RatePresc"                      => "RunData.fL2RatePresc",
+         "fL2RateUnpresc"                    => "RunData.fL2RateUnpresc",
+         "fMagicNumberName"                  => "MagicNumber.fMagicNumberName",
+         "fExcludedFDAName"                  => "ExcludedFDA.fExcludedFDAName",
+         "fProjectName"                      => "Project.fProjectName",
+         "fSourceName"                       => "Source.fSourceName",
+         "fL1TriggerTableName"               => "L1TriggerTable.fL1TriggerTableName",
+         "fL2TriggerTableName"               => "L2TriggerTable.fL2TriggerTableName",
+         "fHvSettingsName"                   => "HvSettings.fHvSettingsName",
+         "fManuallyChangedName"              => "ManuallyChanged.fManuallyChangedName",
+         "fTriggerDelayTableName"            => "TriggerDelayTable.fTriggerDelayTableName",
+         "fDiscriminatorThresholdTableName"  => "DiscriminatorThresholdTable.fDiscriminatorThesholdTableName",
+         "fCalibrationScriptName"            => "CalibrationScript.fCalibrationScriptName",
+         "fTestFlagName"                     => "TestFlag.fTestFlagName",
+         "fLightConditionsName"              => "LightConditions.fLightConditionsName",
+         "fRawFileAvail"                     => "RunProcessStatus.fRawFileAvail",
+         "fCCFileAvail"                      => "RunProcessStatus.fCCFileAvail",
+         "fCaCoFileAvail"                    => "RunProcessStatus.fCaCoFileAvail",
+         "fCaCoFileFound"                    => "RunProcessStatus.fCaCoFileFound",
+         "fTimingCorrection"                 => "RunProcessStatus.fTimingCorrection",
+//         "fFillDotRaw"                       => "RunProcessStatus.fFillDotRaw",
+         "fSequenceFileWritten"              => "SequenceProcessStatus.fSequenceFileWritten",
+         "fAllFilesAvail"                    => "SequenceProcessStatus.fAllFilesAvail",
+         "fCallisto"                         => "SequenceProcessStatus.fCallisto",
+         "fFillCallisto"                     => "SequenceProcessStatus.fFillCallisto",
+         "fStar"                             => "SequenceProcessStatus.fStar",
+         "fFillStar"                         => "SequenceProcessStatus.fFillStar",
+         "fUnsuitableInner"                  => "Calibration.fUnsuitableInner",
+         "fUnsuitableOuter"                  => "Calibration.fUnsuitableOuter",
+         "fUnreliableInner"                  => "Calibration.fUnreliableInner",
+         "fUnreliableOuter"                  => "Calibration.fUnreliableOuter",
+         "fIsolatedInner"                    => "Calibration.fIsolatedInner",
+         "fIsolatedOuter"                    => "Calibration.fIsolatedOuter",
+         "fIsolatedMaxCluster"               => "Calibration.fIsolatedMaxCluster",
+         "fLastUpdate"                       => "Calibration.fLastUpdate",
+         "fMeanPedRmsInner"                  => "Calibration.fMeanPedRmsInner",
+         "fMeanPedRmsOuter"                  => "Calibration.fMeanPedRmsOuter",
+         "fArrTimeMeanInner"                 => "Calibration.fArrTimeMeanInner",
+         "fArrTimeMeanOuter"                 => "Calibration.fArrTimeMeanOuter",
+         "fArrTimeRmsInner"                  => "Calibration.fArrTimeRmsInner",
+         "fArrTimeRmsOuter"                  => "Calibration.fArrTimeRmsOuter",
+         "fConvFactorInner"                  => "Calibration.fConvFactorInner",
+         "fConvFactorOuter"                  => "Calibration.fConvFactorOuter",
+         "fMeanNumberIslands"                => "Star.fMeanNumberIslands",
+         "fPSF"                              => "Star.fPSF",
+         "fRatio"                            => "Star.fRatio",
+         "fMuonNumber"                       => "Star.fMuonNumber",
+         "fEffOnTime"                        => "fEffOnTime",
+         "fEffOnTime/3600"                   => "fEffOnTime/3600",
+//         "fEffOnTime"                        => $fromtable . ".fEffOnTime",
+         "fMuonRate"                         => "Star.fMuonRate",
+         "fDataRate"                         => "Star.fDataRate",
+         "fMaxHumidity"                      => "Star.fMaxHumidity",
+         "fDataSetNumber"                    => $fromtable . ".fDataSetNumber",
+         "fDataSetInserted"                  => "DataSetProcessStatus.fDataSetInserted",
+         "fStarFilesAvail"                   => "DataSetProcessStatus.fStarFilesAvail",
+         "fGanymed"                          => "DataSetProcessStatus.fGanymed",
+         "fFillGanymed"                      => "DataSetProcessStatus.fFillGanymed",
+         "fWobble"                           => "DataSets.fWobble",
+         "fComment"                          => "DataSets.fComment",
+         "fEvents"                           => "DataCheck.fEvents",
+         "fPositionSignal"                   => "DataCheck.fPositionSignal",
+         "fPositionFWHM"                     => "DataCheck.fPositionFWHM",
+         "fHeightSignal"                     => "DataCheck.fHeightSignal",
+         "fHeightFWHM"                       => "DataCheck.fHeightFWHM",
+         "fHasSignal"                        => "DataCheck.fHasSignal",
+         "fHasPedestal"                      => "DataCheck.fHasPedestal",
+         "fPositionAsym"                     => "DataCheck.fPositionAsym",
+         "fHeightAsym"                       => "DataCheck.fHeightAsym",
+         "fEventsInterlaced"                 => "DataCheck.fEventsInterlaced",
+         "fPositionSignalInterlaced"         => "DataCheck.fPositionSignalInterlaced",
+         "fPositionFWHMInterlaced"           => "DataCheck.fPositionFWHMInterlaced",
+         "fHeightSignalInterlaced"           => "DataCheck.fHeightSignalInterlaced",
+         "fHeightFWHMInterlaced"             => "DataCheck.fHeightFWHMInterlaced",
+         "fHasSignalInterlaced"              => "DataCheck.fHasSignalInterlaced",
+         "fHasPedestalInterlaced"            => "DataCheck.fHasPedestalInterlaced",
+         "fPositionAsymInterlaced"           => "DataCheck.fPositionAsymInterlaced",
+         "fHeightAsymInterlaced"             => "DataCheck.fHeightAsymInterlaced",
+         "fExcessEvents"                     => "Ganymed.fExcessEvents",
+         "fBackgroundEvents"                 => "Ganymed.fBackgroundEvents",
+         "fSignalEvents"                     => "Ganymed.fSignalEvents",
+         "fSignificance"                     => "Ganymed.fSignificance",
+         "fScaleFactor"                      => "Ganymed.fScaleFactor",
+         "fExcessEvents*60/fEffOnTime"       => "fExcessEvents*60/fEffOnTime",
+         "fBackgroundEvents*60/fEffOnTime"   => "fBackgroundEvents*60/fEffOnTime",
+         "fSignalEvents*60/fEffOnTime"       => "fSignalEvents*60/fEffOnTime",
+         "Round(fSignificance/Sqrt(fEffOnTime/3600),2)" => "Round(fSignificance/Sqrt(fEffOnTime/3600),2)",
+         "SUM(fRunTime)/3600"                => "'Time [h]'",
+         "SUM(fNumEvents)"                   => "'Evts'",
+         "Min(fZenithDistanceMin)"           => "'ZDMin'",
+         "Max(fZenithDistanceMax)"           => "'ZDMax'",
+         "Min(fZenithDistance)"              => "'ZdMin'",
+         "Max(fZenithDistance)"              => "'ZdMax'",
+//         "COUNT(*)"                          => "'Sequ'",
+        );
+
+    $table="";
+    if (!empty($tables[$val]))
+        $table=$tables[$val];
+    return $table;
+}
+
+
+function GetJoin($fromtable, $val)
+{
+    $joins = array
+        (
+         "fRunTypeName"                      => " LEFT JOIN RunType                      ON " . $fromtable . ".fRunTypeKEY=RunType.fRunTypeKEY ",
+         "fProjectName"                      => " LEFT JOIN Project                      ON " . $fromtable . ".fProjectKEY=Project.fProjectKEY ",
+         "fSourceName"                       => " LEFT JOIN Source                       ON " . $fromtable . ".fSourceKEY=Source.fSourceKEY ",
+         "fMagicNumberName"                  => " LEFT JOIN MagicNumber                  ON " . $fromtable . ".fMagicNumberKEY=MagicNumber.fMagicNumberKEY ",
+         "fL1TriggerTableName"               => " LEFT JOIN L1TriggerTable               ON " . $fromtable . ".fL1TriggerTableKEY=L1TriggerTable.fL1TriggerTableKEY",
+         "fL2TriggerTableName"               => " LEFT JOIN L2TriggerTable               ON " . $fromtable . ".fL2TriggerTableKEY=L2TriggerTable.fL2TriggerTableKEY",
+         "fHvSettingsName"                   => " LEFT JOIN HvSettings                   ON " . $fromtable . ".fHvSettingsKEY=HvSettings.fHvSettingsKEY",
+         "fCalibrationScriptName"            => " LEFT JOIN CalibrationScript            ON " . $fromtable . ".fCalibrationScriptKEY=CalibrationScript.fCalibrationScriptKEY",
+         "fExcludedFDAName"                  => " LEFT JOIN ExcludedFDA                  ON " . $fromtable . ".fExcludedFDAKEY=ExcludedFDA.fExcludedFDAKEY",
+         "fManuallyChangedName"              => " LEFT JOIN ManuallyChanged              ON " . $fromtable . ".fManuallyChangedKEY=ManuallyChanged.fManuallyChangedKEY ",
+         "fDiscriminatorThresholdTableName"  => " LEFT JOIN DiscriminatorThresholdTable  ON " . $fromtable . ".fDiscriminatorThresholdTableKEY=DiscriminatorThresholdTable.fDiscriminatorThresholdTableKEY ",
+         "fTriggerDelayTableName"            => " LEFT JOIN TriggerDelayTable            ON " . $fromtable . ".fTriggerDelayTableKEY=TriggerDelayTable.fTriggerDelayTableKEY ",
+         "fTestFlagName"                     => " LEFT JOIN TestFlag                     ON " . $fromtable . ".fTestFlagKEY=TestFlag.fTestFlagKEY",
+         "fLightConditionsName"              => " LEFT JOIN LightConditions              ON " . $fromtable . ".fLightConditionsKEY=LightConditions.fLightConditionsKEY",
+        );
+
+
+    $join="";
+    if (!empty($joins[$val]))
+        $join=$joins[$val];
+    return $join;
+}
+
+
+?>
Index: trunk/MagicSoft/Mars/datacenter/db/printtable.php
===================================================================
--- trunk/MagicSoft/Mars/datacenter/db/printtable.php	(revision 7484)
+++ trunk/MagicSoft/Mars/datacenter/db/printtable.php	(revision 7484)
@@ -0,0 +1,90 @@
+<?php
+{
+    function PrintForm($_GET)
+    {
+        if (empty($_GET["fTable"]))
+        {
+            printf("ERROR - No table selected.\n");
+            return;
+        }
+    }
+
+    function PrintPage($html, $db, $limits, $rms)
+    {
+        if (empty($_GET["fTable"]))
+        {
+            printf("ERROR - No table selected.\n");
+            return;
+
+        }
+
+        $db_id = mysql_connect("hercules.astro.uni-wuerzburg.de", "MAGIC", "d99swMT!");
+        if ($db_id==FALSE)
+        {
+            printf("mysql_connect returned the following error: %s\n", mysql_error());
+            die("");
+        }
+        mysql_select_db($db);
+
+        $query0  = "SELECT * FROM ";
+        $query0 .= $_GET["fTable"];
+
+        $result0 = mysql_query($query0, $db_id);
+
+        if ($result0)
+        {
+            if ($html=="1")
+            {
+                $alias = array
+                (
+                );
+                $rightalign = array
+                (
+                );
+                PrintMagicTable($result0, $alias, $rightalign, "", "", $_GET);
+            }
+            else
+                PrintText($result0);
+
+            mysql_free_result($result0);
+        }
+        mysql_close($db_id);
+
+        if ($html=="1")
+            printf("<U><B>submitted query:</B></U><BR>%s<BR>", $query0);
+    }
+
+    include ("include.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", $db, $limits, $rms);
+    }
+    else
+    {
+        echo (file_get_contents("index-header.html"));
+
+        $environment = sizeof($_GET);
+
+        PrintForm($_GET);
+
+        if ($environment==0)
+            printf("No query submitted yet.<BR>");
+        else
+            PrintPage("1", $db, $limits, $rms);
+
+        echo (file_get_contents("index-footer.html"));
+    }
+
+    ini_set("display_errors", "Off");
+    ini_set("mysql.trace_mode", "Off");
+}
+?>
Index: trunk/MagicSoft/Mars/datacenter/db/querycal.php
===================================================================
--- trunk/MagicSoft/Mars/datacenter/db/querycal.php	(revision 7484)
+++ trunk/MagicSoft/Mars/datacenter/db/querycal.php	(revision 7484)
@@ -0,0 +1,238 @@
+<?php
+{
+    function CreateQuery($_GET, $alias, $checkwhere)
+    {
+        $query0 = "SELECT fSequenceFirst as 'Sequence#' ";
+
+        foreach ($_GET as $key => $element)
+            if ($_GET[$key]=="On")
+                if (empty($checkwhere[$key]) || $checkwhere[$key]==0)
+                    $query0 .= ", " . $key . " as '" . $alias[$key] . "' ";
+
+        $query0 .= " FROM Calibration ";
+
+        if (strpos($query0, " WHERE ")==FALSE)
+            $query0 .= " WHERE ";
+        else
+            $query0 .= " AND ";
+
+        $query0 .= "fSequenceFirst BETWEEN " . $_GET["fRunMin"] . " AND " . $_GET["fRunMax"] . " ";
+
+        if (!empty($_GET["fSortBy"]))
+        {
+            $query0 .= " ORDER BY " . substr($_GET["fSortBy"], 0, -1) . " ";
+            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["fLastUpdate"]))
+            $_GET["fLastUpdate"]="Off";
+
+        if (empty($_GET["fUnreliableInner"]))
+            $_GET["fUnreliableInner"]=$first?"On":"";
+
+        if (empty($_GET["fUnsuitableOuter"]))
+            $_GET["fUnsuitableOuter"]=$first?"On":"";
+
+        if (empty($_GET["fUnreliableOuter"]))
+            $_GET["fUnreliableOuter"]=$first?"On":"";
+
+        if (empty($_GET["fUnsuitableInner"]))
+            $_GET["fUnsuitableInner"]=$first?"On":"";
+
+        if (empty($_GET["fIsolatedInner"]))
+            $_GET["fIsolatedInner"]=$first?"On":"";
+
+        if (empty($_GET["fIsolatedOuter"]))
+            $_GET["fIsolatedOuter"]=$first?"On":"";
+
+        if (empty($_GET["fMeanPedRmsInner"]))
+            $_GET["fMeanPedRmsInner"]=$first?"On":"";
+
+        if (empty($_GET["fMeanPedRmsOuter"]))
+            $_GET["fMeanPedRmsOuter"]=$first?"On":"";
+
+        if (empty($_GET["fIsolatedMaxCluster"]))
+            $_GET["fIsolatedMaxCluster"]=$first?"On":"";
+
+        if (empty($_GET["fArrTimeMeanInner"]))
+            $_GET["fArrTimeMeanInner"]=$first?"On":"";
+
+        if (empty($_GET["fArrTimeMeanOuter"]))
+            $_GET["fArrTimeMeanOuter"]=$first?"On":"";
+
+        if (empty($_GET["fArrTimeRmsInner"]))
+            $_GET["fArrTimeRmsInner"]=$first?"On":"";
+
+        if (empty($_GET["fArrTimeRmsOuter"]))
+            $_GET["fArrTimeRmsOuter"]=$first?"On":"";
+
+        if (empty($_GET["fConvFactorInner"]))
+            $_GET["fConvFactorInner"]=$first?"On":"";
+
+        if (empty($_GET["fConvFactorOuter"]))
+            $_GET["fConvFactorOuter"]=$first?"On":"";
+
+    }
+
+    function PrintForm($_GET, $db)
+    {
+        printf("<center>\n");
+        printf("<form action=\"querycal.php\" METHOD=\"GET\">\n");
+        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("fConvFactorInner",     "Conv inner ");
+        CheckBox("fConvFactorOuter",     "Conv outer ");
+        CheckBox("fMeanPedRmsInner",     "MeanPedRms inner");
+        CheckBox("fMeanPedRmsOuter",     "MeanPedRms outer");
+
+        printf(" </table>\n");
+        printf(" <p>\n");
+
+        if (empty($_GET["fRunMin"]))
+            $min = GetMin("fSequenceFirst", "Sequences", $db);
+        else
+            $min = $_GET["fRunMin"];
+
+        if (empty($_GET["fRunMax"]))
+            $max = GetMax("fSequenceFirst", "Sequences", $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);
+
+        printf(" <P>\n");
+
+        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");
+
+        ini_set("mysql.trace_mode", "Off");
+        ini_set("display_errors", "Off");
+
+        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=\"querycal.php\"'>&nbsp;&nbsp;&nbsp;\n");
+        if (strchr($_SERVER["REQUEST_URI"], '?')!=FALSE)
+            printf("<input class='Width' type='button' value='Get .txt' onClick='self.location.href=\"%s&fSendTxt=1\"'>&nbsp;&nbsp;&nbsp;\n", $_SERVER["REQUEST_URI"]);
+        printf("</form>\n");
+        printf("</center>\n");
+        printf("</td>\n");
+        printf("</tr>\n");
+        printf("<tr class='Block'>\n");
+        printf("<td>\n");
+    }
+
+    function PrintPage($html, $db, $alias, $rightalign, $checkwhere)
+    {
+        $db_id = mysql_connect("hercules.astro.uni-wuerzburg.de", "MAGIC", "d99swMT!");
+        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);
+
+        $result0 = mysql_query($query0, $db_id);
+
+        if ($result0)
+        {
+            if ($html=="1")
+                PrintMagicTable($result0, $alias, $rightalign, "", "", $_GET);
+            else
+                PrintText($result0);
+
+            mysql_free_result($result0);
+        }
+        mysql_close($db_id);
+
+        if ($html=="1")
+            printf("<U><B>submitted query:</B></U><BR>%s<BR>", htmlspecialchars($query0));
+    }
+
+    include ("include.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", $db, $alias, $rightalign, $checkwhere);
+    }
+    else
+    {
+        echo (file_get_contents("index-header.html"));
+
+        $environment = sizeof($_GET);
+
+        InitGet($_GET);
+        PrintForm($_GET, $db);
+
+        if ($environment==0)
+            printf("No query submitted yet.<BR>");
+        else
+            PrintPage("1", $db, $alias, $rightalign, $checkwhere);
+
+        echo (file_get_contents("index-footer.html"));
+    }
+
+    ini_set("display_errors", "Off");
+    ini_set("mysql.trace_mode", "Off");
+}
+?>
Index: trunk/MagicSoft/Mars/datacenter/db/queryrbk.php
===================================================================
--- trunk/MagicSoft/Mars/datacenter/db/queryrbk.php	(revision 7484)
+++ trunk/MagicSoft/Mars/datacenter/db/queryrbk.php	(revision 7484)
@@ -0,0 +1,112 @@
+<?php
+{
+    function PrintForm($_GET)
+    {
+        if (empty($_GET["fDate"]))
+            $_GET["fDate"]=date("Y-m-d");
+
+        printf("<center>\n");
+        printf("<form action=\"queryrbk.php\" METHOD=\"GET\">\n");
+
+        printf("Date&nbsp;(yyyy-mm-dd)&nbsp;<input name=\"fDate\" type=\"text\" size=\"10\" maxlength=\"10\" value=\"");
+        printf("%s\">&nbsp;&nbsp;&nbsp;\n", $_GET["fDate"]);
+
+        printf("Search&nbsp;<A HREF=\"regexp.html\">regexp:</A>&nbsp;<input name=\"fRegexp\" type=\"text\" size=\"32\" maxlength=\"128\" value=\"");
+        if (!empty($_GET["fRegexp"]))
+            printf("%s", $_GET["fRegexp"]);
+        printf("\">&nbsp;&nbsp;&nbsp;\n<P>\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");
+        printf("<input class='Width' type='button' value='Reset' onClick='self.location.href=\"queryrbk.php\"'>&nbsp;&nbsp;&nbsp;\n");
+        if (strchr($_SERVER["REQUEST_URI"], '?')!=FALSE)
+            printf("<input class='Width' type='button' value='Get .txt' onClick='self.location.href=\"%s&fSendTxt=1\"'>&nbsp;&nbsp;&nbsp;\n", $_SERVER["REQUEST_URI"]);
+        printf("</form>\n");
+        printf("</center>\n");
+        printf("</td>\n");
+        printf("</tr>\n");
+        printf("<tr class='Block'>\n");
+        printf("<td>\n");
+    }
+
+    function PrintPage($html, $db)
+    {
+        $db_id = mysql_connect("hercules.astro.uni-wuerzburg.de", "MAGIC", "d99swMT!");
+        if ($db_id==FALSE)
+        {
+            printf("mysql_connect returned the following error: %s\n", mysql_error());
+            die("");
+        }
+        mysql_select_db($db);
+
+        $query0  = "SELECT fRunBookDate AS Date, fRunBookText AS Entry ";
+        $query0 .= "FROM " . $db . ".RunBook ";
+        $query0 .= "WHERE fRunBookDate REGEXP '^" . $_GET["fDate"] . "' ";
+
+        if (!empty($_GET["fRegexp"]))
+            $query0 .= "AND fRunBookText REGEXP '" . $_GET["fRegexp"] . "' ";
+
+        $query0 .= "ORDER BY fRunBookDate";
+
+        $result0 = mysql_query($query0, $db_id);
+
+        if ($result0)
+        {
+            if ($html=="1")
+            {
+                $alias = array
+                (
+                 "fRunBookDate"  => "Date",
+                 "fRunBookText"  => "Entry"
+                );
+                $rightalign = array
+                (
+                );
+                PrintMagicTable($result0, $alias, $rightalign, "", "", $_GET);
+            }
+            else
+                PrintText($result0);
+
+            mysql_free_result($result0);
+        }
+        mysql_close($db_id);
+
+        if ($html=="1")
+            printf("<U><B>submitted query:</B></U><BR>%s<BR>", $query0);
+    }
+
+    include ("include.php");
+    include ("db.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", $db);
+    }
+    else
+    {
+        echo (file_get_contents("index-header.html"));
+
+        $environment = sizeof($_GET);
+
+        PrintForm($_GET);
+
+        if ($environment==0)
+            printf("No query submitted yet.<BR>");
+        else
+            PrintPage("1", $db);
+
+        echo (file_get_contents("index-footer.html"));
+    }
+
+    ini_set("display_errors", "Off");
+    ini_set("mysql.trace_mode", "Off");
+}
+?>
Index: trunk/MagicSoft/Mars/datacenter/db/queryseq.php
===================================================================
--- trunk/MagicSoft/Mars/datacenter/db/queryseq.php	(revision 7484)
+++ trunk/MagicSoft/Mars/datacenter/db/queryseq.php	(revision 7484)
@@ -0,0 +1,366 @@
+<?php
+{
+    function CreateQuery($_GET, $alias, $checkwhere, $checkgroup, $checkstatusgroup)
+    {
+        $fromtable="Sequences";
+
+        $groups = 0;
+        foreach ($checkgroup as $element)
+            if ($element==-1)
+                $groups++;
+
+        $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 (!empty($_GET["fSendTxt"]))
+                $query0 .= " SELECT fSequenceFirst ";
+            else
+                $query0 .= " CONCAT('<A&ws;HREF=\"index.php?',  'fRunStart=On', '&fZenithDistance=On', '&fRunMin=', fSequenceFirst, '&fMeanTriggerRate=On', '&fRunTypeName=On', '&fRunMax=', fSequenceLast, '&fNumEvents=On', '&fSourceName=On&', 'fExcludedFDAKEY=1', '&fSequenceFirst=On', '&fNumResults=500\">', fSequenceFirst, '</A>') ";
+            $query0 .= " as 'Sequence#' ";
+
+            foreach ($_GET as $key => $element)
+                if ($_GET[$key]=="On")
+                    if (empty($checkwhere[$key]) || $checkwhere[$key]==0)
+                        $query0 .= ", " . $key . " as '" . $alias[$key] . "' ";
+        }
+
+        $query0 .= " FROM Sequences ";
+
+        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 ";
+
+        if (!empty($_GET["fRunMin"]) && !empty($_GET["fRunMax"]))
+            $query0 .= "fSequenceFirst BETWEEN " . $_GET["fRunMin"] . " AND " . $_GET["fRunMax"] . " ";
+
+/*
+        if (!empty($_GET["fDate"]))
+            $query0 .= " AND fRunStart REGEXP \"^" . $_GET["fDate"] . "\" ";
+*/
+
+        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 || !strpos(strrev($query0), " DNA "))
+                $query0 .= " AND ";
+
+            $stopdate=substr($_GET["fStopDate"], 0, 10);
+            $query0 .= " fRunStart < '" . $stopdate . " 13:00:00' ";
+        }
+
+        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 (!empty($_GET["fSortBy"]))
+        {
+            $query0 .= " ORDER BY " . substr($_GET["fSortBy"], 0, -1) . " ";
+            if (substr($_GET["fSortBy"], -1)=="-")
+                $query0 .= "DESC";
+        }
+
+        if (empty($_GET["fSortBy"]) && $groups==0)
+            $query0 .= "ORDER BY 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"]="20";
+
+        if (empty($_GET["fLastUpdate"]))
+            $_GET["fLastUpdate"]="Off";
+
+        if (empty($_GET["fNumEvents"]))
+            $_GET["fNumEvents"]=$first?"On":"";
+
+        if (empty($_GET["fRunStart"]))
+            $_GET["fRunStart"]=$first?"On":"";
+
+        if (empty($_GET["fRunTime/60"]))
+            $_GET["fRunTime/60"]=$first?"On":"";
+
+        if (empty($_GET["fSequenceLast"]))
+            $_GET["fSequenceLast"]=$first?"On":"";
+
+        if (empty($_GET["fAzimuthMin"]))
+            $_GET["fAzimuthMin"]="Off";
+
+        if (empty($_GET["fAzimuthMax"]))
+            $_GET["fAzimuthMax"]="Off";
+
+        if (empty($_GET["fZenithDistanceMin"]))
+            $_GET["fZenithDistanceMin"]=$first?"On":"";
+
+        if (empty($_GET["fZenithDistanceMax"]))
+            $_GET["fZenithDistanceMax"]="Off";
+
+        if (empty($_GET["fManuallyChangedName"]))
+            $_GET["fManuallyChangedName"]="Off";
+
+        if (empty($_GET["fSourceName"]))
+            $_GET["fSourceName"]=$first?"On":"";
+
+        if (empty($_GET["fProjectName"]))
+            $_GET["fProjectName"]="Off";
+
+        if (empty($_GET["fTriggerTableName"]))
+            $_GET["fTriggerTableName"]="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 PrintForm($_GET, $db)
+    {
+        printf("<center>\n");
+        printf("<form action=\"queryseq.php\" METHOD=\"GET\">\n");
+        printf(" <table>\n");
+        printf("  <tr>\n");
+
+        CheckBox("fSequenceLast",      "Last run");
+        CheckBox("fRunStart",          "Start time");
+        CheckBox("fAzimuthMin",        "Azimuth min");
+        CheckBox("fAzimuthMax",        "Azimuth max");
+
+        printf("  </tr><tr>\n");
+
+        CheckBox("fNumEvents",         "Num of events");
+        CheckBox("fRunTime/60",        "Duration");
+        CheckBox("fZenithDistanceMin", "Zenith distance min");
+        CheckBox("fZenithDistanceMax", "Zenith distance max");
+
+        printf(" </table>\n");
+         printf(" <p>\n");
+
+        // pull down boxes
+
+        printf(" <table>\n");
+        printf("  <tr><td>\n");
+        PrintPullDown($db, "Source",      "fSourceName",      "fSourceKEY", "Source Name");
+        printf("  </td><td>\n");
+        PrintPullDown($db, "TriggerTable", "fTriggerTableName", "fTriggerTableKEY", "Trigger Table");
+        printf("  </td><td>\n");
+        PrintPullDown($db, "TriggerDelayTable",  "fTriggerDelayTableName",  "fTriggerDelayTableKEY", "Trigger Delay Table");
+        printf("  </td></tr><tr><td>\n");
+        PrintPullDown($db, "Project",     "fProjectName",     "fProjectKEY", "Project Name");
+        printf("  </td><td>\n");
+        PrintPullDown($db, "HvSettings",  "fHvSettingsName",  "fHvSettingsKEY", "HV Settings");
+        printf("  </td><td>\n");
+        PrintPullDown($db, "DiscriminatorThresholdTable",  "fDiscriminatorThresholdTableName",  "fDiscriminatorThresholdTableKEY", "DT Table");
+        printf("  </td></tr><tr><td>\n");
+        PrintPullDown($db, "TestFlag",  "fTestFlagName",  "fTestFlagKEY", "Test Flag");
+        printf("  </td><td>\n");
+        PrintPullDown($db, "LightConditions",  "fLightConditionsName",  "fLightConditionsKEY", "Light Conditions");
+        printf("  </td><td>\n");
+        PrintPullDown($db, "ManuallyChanged", "fManuallyChangedName", "fManuallyChangedKEY", "Manually changed");
+        printf("  </td></tr>\n");
+        printf(" </table>\n");
+        printf(" <p>\n");
+
+        if (empty($_GET["fStartDate"]))
+            $timemin = GetMin("fRunStart", "RunData", $db);
+        else
+            $timemin = $_GET["fStartDate"];
+
+        if (empty($_GET["fStopDate"]))
+            $timemax = GetMax("fRunStart", "RunData", $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", $db);
+        else
+            $min = $_GET["fRunMin"];
+
+        if (empty($_GET["fRunMax"]))
+            $max = GetMax("fSequenceFirst", "Sequences", $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(" 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");
+
+        ini_set("mysql.trace_mode", "Off");
+        ini_set("display_errors", "Off");
+
+        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=\"queryseq.php\"'>&nbsp;&nbsp;&nbsp;\n");
+        if (strchr($_SERVER["REQUEST_URI"], '?')!=FALSE)
+            printf("<input class='Width' type='button' value='Get .txt' onClick='self.location.href=\"%s&fSendTxt=1\"'>&nbsp;&nbsp;&nbsp;\n", $_SERVER["REQUEST_URI"]);
+        printf("</form>\n");
+        printf("</center>\n");
+        printf("</td>\n");
+        printf("</tr>\n");
+        printf("<tr class='Block'>\n");
+        printf("<td>\n");
+    }
+
+    function PrintPage($html, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup)
+    {
+        $db_id = mysql_connect("hercules.astro.uni-wuerzburg.de", "MAGIC", "d99swMT!");
+        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);
+
+        $result0 = mysql_query($query0, $db_id);
+
+        if ($result0)
+        {
+            if ($html=="1")
+                PrintMagicTable($result0, $alias, $rightalign, "", "", $_GET);
+            else
+                PrintText($result0);
+
+            mysql_free_result($result0);
+        }
+        mysql_close($db_id);
+
+        if ($html=="1")
+            printf("<U><B>submitted query:</B></U><BR>%s<BR>", htmlspecialchars($query0));
+    }
+
+    include ("include.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", $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup);
+    }
+    else
+    {
+        echo (file_get_contents("index-header.html"));
+
+        $environment = sizeof($_GET);
+
+        InitGet($_GET);
+        PrintForm($_GET, $db);
+
+        if ($environment==0)
+            printf("No query submitted yet.<BR>");
+        else
+            PrintPage("1", $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup);
+
+        echo (file_get_contents("index-footer.html"));
+    }
+
+    ini_set("display_errors", "Off");
+    ini_set("mysql.trace_mode", "Off");
+}
+?>
Index: trunk/MagicSoft/Mars/datacenter/db/querystar.php
===================================================================
--- trunk/MagicSoft/Mars/datacenter/db/querystar.php	(revision 7484)
+++ trunk/MagicSoft/Mars/datacenter/db/querystar.php	(revision 7484)
@@ -0,0 +1,205 @@
+<?php
+{
+    function CreateQuery($_GET, $alias, $checkwhere)
+    {
+        $query0 = "SELECT fSequenceFirst as 'Sequence#' ";
+
+        foreach ($_GET as $key => $element)
+            if ($_GET[$key]=="On")
+                if (empty($checkwhere[$key]) || $checkwhere[$key]==0)
+                    $query0 .= ", " . $key . " as '" . $alias[$key] . "' ";
+
+        $query0 .= " FROM Star ";
+
+        if (strpos($query0, " WHERE ")==FALSE)
+            $query0 .= " WHERE ";
+        else
+            $query0 .= " AND ";
+
+        $query0 .= "fSequenceFirst BETWEEN " . $_GET["fRunMin"] . " AND " . $_GET["fRunMax"] . " ";
+
+        if (!empty($_GET["fSortBy"]))
+        {
+            $query0 .= " ORDER BY " . substr($_GET["fSortBy"], 0, -1) . " ";
+            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["fLastUpdate"]))
+            $_GET["fLastUpdate"]="Off";
+
+        if (empty($_GET["fMeanNumberIslands"]))
+            $_GET["fMeanNumberIslands"]=$first?"On":"";
+
+        if (empty($_GET["fPSF"]))
+            $_GET["fPSF"]=$first?"On":"";
+
+        if (empty($_GET["fRatio"]))
+            $_GET["fRatio"]=$first?"On":"";
+
+        if (empty($_GET["fMuonNumber"]))
+            $_GET["fMuonNumber"]=$first?"On":"";
+
+        if (empty($_GET["fEffOnTime"]))
+            $_GET["fEffOnTime"]=$first?"On":"";
+
+        if (empty($_GET["fMuonRate"]))
+            $_GET["fMuonRate"]=$first?"On":"";
+
+        if (empty($_GET["fDataRate"]))
+            $_GET["fDataRate"]=$first?"On":"";
+
+        if (empty($_GET["fMaxHumidity"]))
+            $_GET["fMaxHumidity"]=$first?"On":"";
+
+    }
+
+    function PrintForm($_GET, $db)
+    {
+        printf("<center>\n");
+        printf("<form action=\"querystar.php\" METHOD=\"GET\">\n");
+        printf(" <table>\n");
+        printf("  <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("fMaxHumidity",        "MaxHumidity");
+        CheckBox("fDataRate",           "CleanedEvtRate");
+
+        printf("  </tr>\n");
+        printf(" </table>\n");
+        printf(" <p>\n");
+
+        if (empty($_GET["fRunMin"]))
+            $min = GetMin("fSequenceFirst", "Sequences", $db);
+        else
+            $min = $_GET["fRunMin"];
+
+        if (empty($_GET["fRunMax"]))
+            $max = GetMax("fSequenceFirst", "Sequences", $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);
+
+        printf(" <P>\n");
+
+        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");
+
+        ini_set("mysql.trace_mode", "Off");
+        ini_set("display_errors", "Off");
+
+        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=\"querystar.php\"'>&nbsp;&nbsp;&nbsp;\n");
+        if (strchr($_SERVER["REQUEST_URI"], '?')!=FALSE)
+            printf("<input class='Width' type='button' value='Get .txt' onClick='self.location.href=\"%s&fSendTxt=1\"'>&nbsp;&nbsp;&nbsp;\n", $_SERVER["REQUEST_URI"]);
+        printf("</form>\n");
+        printf("</center>\n");
+        printf("</td>\n");
+        printf("</tr>\n");
+        printf("<tr class='Block'>\n");
+        printf("<td>\n");
+    }
+
+    function PrintPage($html, $db, $alias, $rightalign, $checkwhere)
+    {
+        $db_id = mysql_connect("hercules.astro.uni-wuerzburg.de", "MAGIC", "d99swMT!");
+        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);
+
+        $result0 = mysql_query($query0, $db_id);
+
+        if ($result0)
+        {
+            if ($html=="1")
+                PrintMagicTable($result0, $alias, $rightalign, "", "", $_GET);
+            else
+                PrintText($result0);
+
+            mysql_free_result($result0);
+        }
+        mysql_close($db_id);
+
+        if ($html=="1")
+            printf("<U><B>submitted query:</B></U><BR>%s<BR>", htmlspecialchars($query0));
+    }
+
+    include ("include.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", $db, $alias, $rightalign, $checkwhere);
+    }
+    else
+    {
+        echo (file_get_contents("index-header.html"));
+
+        $environment = sizeof($_GET);
+
+        InitGet($_GET);
+        PrintForm($_GET, $db);
+
+        if ($environment==0)
+            printf("No query submitted yet.<BR>");
+        else
+            PrintPage("1", $db, $alias, $rightalign, $checkwhere);
+
+        echo (file_get_contents("index-footer.html"));
+    }
+
+    ini_set("display_errors", "Off");
+    ini_set("mysql.trace_mode", "Off");
+}
+?>
Index: trunk/MagicSoft/Mars/datacenter/db/reference.html
===================================================================
--- trunk/MagicSoft/Mars/datacenter/db/reference.html	(revision 7484)
+++ trunk/MagicSoft/Mars/datacenter/db/reference.html	(revision 7484)
@@ -0,0 +1,115 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
+
+<html>
+<head>
+   
+<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+   
+<meta name="Author" content="Thomas Bretz">
+   
+<title>Magic Database</title>
+   
+<link rel="stylesheet" type="text/css" href="../mars.css">
+</head>
+
+<body background="../background.gif" text="#000000" bgcolor="#000099" link="#1122FF" vlink="#8888FF" alink="#FF0000">
+&nbsp;
+
+<center>
+<table class="Main" CELLPADDING=0>
+
+<tr>
+<td class="Edge">
+<img SRC="../ecke.gif" ALT="">
+</td>
+<td class="Header">
+<font size=+1><B>Magic Database</B></font><BR>
+</td>
+</tr>
+
+<tr>
+<td COLSPAN=2 BGCOLOR="#FFFFFF">
+<hr SIZE=1 NOSHADE WIDTH="80%">
+<center>
+<table class="Inner" CELLPADDING=15>
+
+<tr class="Block">
+<td>
+<table BORDER=\"1\">
+<tr BGCOLOR='#D0D0D0'>
+<th BGCOLOR='#C0C0C0'>calibration</th>
+<td>inner</td>
+<td>outer</td>
+</tr><tr BGCOLOR='#E0E0E0'>
+<td>unsuitable pixel</td>
+<td> </td>
+<td> </td>
+</tr><tr BGCOLOR='#D0D0D0'>
+<td>unreliable pixel</td>
+<td> 198 </td>
+<td> 90 </td>
+</tr><tr BGCOLOR='#E0E0E0'>
+<td>isolated pixel</td>
+<td>  </td>
+<td>  </td>
+</tr><tr BGCOLOR='#D0D0D0'>
+<td>arrival time</td>
+<td> 1.5 &lt; time &lt; 8.5 &plusmn; 3.5 </td>
+<td> 1.5 &lt; time &lt; 8.5 &plusmn; 3.5 </td>
+</tr><tr BGCOLOR='#E0E0E0'>
+<td>conversion factor (df)</td>
+<td> 0.8 &plusmn; 0.1 </td>
+<td> 3.8 &plusmn; 0.5 </td>
+</tr><tr BGCOLOR='#E0E0E0'>
+<td>conversion factor (spline)</td>
+<td> 1.7 &plusmn; 0.2 </td>
+<td> 6.5 &plusmn; 0.8 </td>
+</tr><tr BGCOLOR='#D0D0D0'>
+<td>mean ped rms</td>
+<td>  </td>
+<td>  </td>
+</tr>
+</table>
+
+</td>
+</tr>
+
+</table>
+</center>
+
+<center>
+<hr NOSHADE WIDTH="80%"><i><font color="#000099"><font size=-1>This Web Site is 
+hosted by Apache for OS/2 and done by <a href="mailto:tbretz@astro.uni-wuerzburg.de">Thomas&nbsp;Bretz</a> and <a href="mailto:dorner@astro.uni-wuerzburg.de">Daniela&nbsp;Dorner</a> .</font></font></i><BR>
+&nbsp;<BR>
+<a href="http://validator.w3.org/check/referer"><img border="0"
+   src="../../valid-html40.png" alt="Valid HTML 4.0!" height="20" width="66"></a>
+</center>&nbsp;
+</tr>
+</table>
+
+<BR>
+
+<table class="Main">
+<tr>
+<!-- This is the old stylish counter....
+  <td ALIGN=RIGHT VALIGN=TOP>NedStat - website access statistics:&nbsp;<a href="http://de.nedstat.net/viewstat.asp?name=magicmars" onMouseover="status='Statistics on Web Access by NedStat.de';return true;" onMouseout="status='';return true;"><img SRC="http://de.nedstat.net/scripts/nedstat.dll?name=magicmars" ALT="STAT" BORDER=0 height=18 width=18 align=TEXTTOP></a></td>
+-->
+<td ALIGN=RIGHT VALIGN=MIDDLE><FONT COLOR="#FFFFFF">NedStat - website access statistics:&nbsp;</FONT>
+<script language='JavaScript' src="http://m1.nedstatbasic.net/basic.js" type="text/javascript"></script>
+<script language="JavaScript" type="text/javascript">          
+<!--
+  nedstatbasic("AAGh1A6qQKZFLpl2rXaOC3LPo1OA", 0);
+// -->
+</script>
+<!--<noscript>-->
+<a target="_self" href="http://v1.nedstatbasic.net/stats?AAGh1A6qQKZFLpl2rXaOC3LPo1OA" onMouseover="status='Statistics on Web Access by NedStat.de';return true;" onMouseout="status='';return true;"></a>
+<!--</noscript>-->
+</td>
+
+</tr>
+</table>
+</center>
+
+</body>
+</html>
+
Index: trunk/MagicSoft/Mars/datacenter/db/regexp.html
===================================================================
--- trunk/MagicSoft/Mars/datacenter/db/regexp.html	(revision 7484)
+++ trunk/MagicSoft/Mars/datacenter/db/regexp.html	(revision 7484)
@@ -0,0 +1,389 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
+
+<html>
+<head>
+   <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+   <meta name="Author" content="Thomas Bretz">
+   <title>MARS: Magic Analysis and Reconstruction Software</title>
+   <link rel="stylesheet" type="text/css" href="../mars.css">
+</head>
+
+<body background="background.gif" text="#000000" bgcolor="#000099" link="#1122FF" vlink="#8888FF" alink="#FF0000">
+&nbsp;
+
+<center>
+<table class="Main" CELLPADDING=0>
+
+<tr>
+<td class="Edge"><img SRC="../ecke.gif" ALT=""></td>
+<td class="Header">
+<B>M A R S</B><BR><B>M</B>agic <B>A</B>nalysis and <B>R</B>econstruction <B>S</B>oftware
+</td>
+</tr>
+
+<tr>
+<td COLSPAN=2 BGCOLOR="#FFFFFF">
+<hr SIZE=1 NOSHADE WIDTH="80%">
+<center><table class="Inner" CELLPADDING=15>
+
+<tr class="Block">
+<td><b><u><A NAME="OVERVIEW">MySQL Regular Expressions</A>:</u></b>
+<P>
+A <B>regular expression (regex)</B> is a powerful way of specifying a complex search. <P>
+
+  MySQL uses Henry Spencer's implementation of regular expressions, which is aimed at conformance with POSIX 
+  1003.2. MySQL uses the extended version. <P>
+
+  This is a simplistic reference that skips the details. To get more exact information, see 
+  Henry Spencer's <A HREF="#REGEX">regex(7)</A><P>
+
+  A regular expression describes a set of strings. The simplest regexp is one that has no special characters in it. For 
+  example, the regexp <b>hello</B> matches <B>hello</B> and nothing else. <P>
+
+  Non-trivial regular expressions use certain special constructs so that they can match more than one string. For 
+  example, the regexp hello|word matches either the string hello or the string word. <P>
+
+  As a more complex example, the regexp B[an]*s matches any of the strings Bananas, Baaaaas, Bs, and any 
+  other string starting with a B, ending with an s, and containing any number of a or n characters in between. <P>
+
+  A regular expression may use any of the following special characters/constructs:   <P>
+<pre>
+  ^         Match the beginning of a string. 
+            mysql> SELECT "fo\nfo" REGEXP "^fo$";           -> 0 
+            mysql> SELECT "fofo"   REGEXP "^fo";            -> 1 
+
+  $         Match the end of a string. 
+            mysql> SELECT "fo\no" REGEXP "^fo\no$";         -> 1 
+            mysql> SELECT "fo\no" REGEXP "^fo$";            -> 0 
+
+  .         Match any character (including newline). 
+            mysql> SELECT "fofo"  REGEXP "^f.*";            -> 1 
+            mysql> SELECT "fo\nfo" REGEXP "^f.*";           -> 1 
+
+  a*        Match any sequence of zero or more a characters. 
+            mysql> SELECT "Ban"   REGEXP "^Ba*n";           -> 1 
+            mysql> SELECT "Baaan" REGEXP "^Ba*n";           -> 1 
+            mysql> SELECT "Bn"    REGEXP "^Ba*n";           -> 1 
+
+  a+        Match any sequence of one or more a characters. 
+            mysql> SELECT "Ban" REGEXP "^Ba+n";             -> 1 
+            mysql> SELECT "Bn"  REGEXP "^Ba+n";             -> 0 
+
+  a?        Match either zero or one a character. 
+            mysql> SELECT "Bn"   REGEXP "^Ba?n";            -> 1 
+            mysql> SELECT "Ban"  REGEXP "^Ba?n";            -> 1 
+            mysql> SELECT "Baan" REGEXP "^Ba?n";            -> 0 
+
+  de|abc    Match either of the sequences de or abc. 
+            mysql> SELECT "pi"  REGEXP "pi|apa";            -> 1 
+            mysql> SELECT "axe" REGEXP "pi|apa";            -> 0 
+            mysql> SELECT "apa" REGEXP "pi|apa";            -> 1 
+            mysql> SELECT "apa" REGEXP "^(pi|apa)$";        -> 1 
+            mysql> SELECT "pi"  REGEXP "^(pi|apa)$";        -> 1 
+            mysql> SELECT "pix" REGEXP "^(pi|apa)$";        -> 0 
+
+  (abc)*    Match zero or more instances of the sequence abc. 
+            mysql> SELECT "pi"   REGEXP "^(pi)*$";          -> 1 
+            mysql> SELECT "pip"  REGEXP "^(pi)*$";          -> 0 
+            mysql> SELECT "pipi" REGEXP "^(pi)*$";          -> 1 
+
+  {1}       The is a more general way of writing regexps that match many
+  {2,3}     occurrences of the previous atom.   
+              a*          Can be written as a{0,}. 
+              a+          Can be written as a{1,}. 
+              a?          Can be written as a{0,1}.   
+
+              To be more precise, an atom followed by a bound containing one 
+              integer i and no comma matches a sequence of exactly i matches 
+              of the atom. An atom followed by a bound containing one integer i 
+              and a comma matches a sequence of i or more matches of the atom. 
+              An atom followed by a bound containing two integers i and j matches 
+              a sequence of i through j (inclusive) matches of the atom. 
+
+              Both arguments must be in the range from 0 to RE_DUP_MAX (default 255), 
+              inclusive.  If there are two arguments, the second must be greater
+              than or equal to the first. 
+
+  [a-dX]    Matches any character which is (or is not, if ^ is used) either a, b, c, 
+  [^a-dX]   d or X. To include a literal ] character, it must immediately follow 
+            the opening bracket [.  To include a literal - character, it must be 
+            written first or last. So [0-9] matches any decimal digit. Any character 
+            that does not have a defined meaning inside a [] pair has no special 
+            meaning and matches only itself. 
+               mysql> SELECT "aXbc"   REGEXP "[a-dXYZ]";               -> 1 
+               mysql> SELECT "aXbc"   REGEXP "^[a-dXYZ]$";             -> 0 
+               mysql> SELECT "aXbc"   REGEXP "^[a-dXYZ]+$";            -> 1 
+               mysql> SELECT "aXbc"   REGEXP "^[^a-dXYZ]+$";           -> 0 
+               mysql> SELECT "gheis"  REGEXP "^[^a-dXYZ]+$";           -> 1 
+               mysql> SELECT "gheisa" REGEXP "^[^a-dXYZ]+$";           -> 0 
+
+  [[.characters.]] 
+            The sequence of characters of that collating element. characters is 
+            either a single character or a character name like newline. You can 
+            find the full list of character names in 'regexp/cname.h'. 
+
+  [ =character_class=] 
+            An equivalence class, standing for the sequences of characters of all 
+            collating elements equivalent to that one, including itself. 
+
+            For example, if o and (+) are the members of an equivalence class, 
+            then [[=o=]], [[=(+)=]], and [o(+)] are all synonymous. An equivalence 
+            class may not be an endpoint of a range. 
+
+  [:character_class:] 
+            Within a bracket expression, the name of a character class enclosed 
+            in [: and :] stands for the list of all characters belonging to that 
+            class. Standard character class names are: 
+
+            These stand for the character classes defined in the ctype(3) manual 
+            page. A locale may provide others. A character class may not be used 
+            as an endpoint of a range. 
+               mysql> SELECT "justalnums" REGEXP "[[:alnum:]]+";       -> 1 
+               mysql> SELECT "!!" REGEXP "[[:alnum:]]+";               -> 0 
+                        
+  [[:<:]]   These match the null string at the beginning and end of a word 
+  [[:>:]]   respectively.  A word is defined as a sequence of word characters 
+            which is neither preceded nor followed by word characters. A word 
+            character is an alnum character (as defined by ctype(3)) or an 
+            underscore (_). 
+               mysql> SELECT "a word a" REGEXP "[[:<:]]word[[:>:]]";   -> 1 
+               mysql> SELECT "a xword a" REGEXP "[[:<:]]word[[:>:]]";  -> 0 
+                          
+            mysql> SELECT "weeknights" REGEXP "^(wee|week)(knights|nights)$"; -> 1 
+</pre>
+</td></tr>
+<tr class="Block">
+<td>
+<center><h3>--- <A NAME="REGEX"><U>REGEX</U></A>(7) ---</h3></center>
+<B>NAME</B><BR>
+       regex - POSIX 1003.2 regular expressions<P>
+
+<B>DESCRIPTION</B><BR>
+       Regular expressions (``RE''s), as defined in POSIX 1003.2,
+       come in two forms: modern REs  (roughly  those  of  egrep;
+       1003.2  calls  these  ``extended''  REs)  and obsolete REs
+       (roughly those of ed; 1003.2 ``basic'' REs).  Obsolete REs
+       mostly  exist  for backward compatibility in some old pro-
+       grams; they will be discussed at the end.   1003.2  leaves
+       some  aspects  of  RE  syntax and semantics open; `' marks
+       decisions on these aspects that may not be fully  portable
+       to other 1003.2 implementations.<P>
+
+       A (modern) RE is one or more non-empty branches, separated
+       by `|'.  It matches  anything  that  matches  one  of  the
+       branches.<P>
+
+       A  branch is one or more pieces, concatenated.  It matches
+       a match for the first, followed by a match for the second,
+       etc.<P>
+
+       A piece is an atom possibly followed by a single `*', `+',
+       `?', or bound.  An atom followed by `*' matches a sequence
+       of 0 or more matches of the atom.  An atom followed by `+'
+       matches a sequence of 1 or more matches of the  atom.   An
+       atom  followed by `?' matches a sequence of 0 or 1 matches
+       of the atom.<P>
+
+       A bound is `{' followed by an  unsigned  decimal  integer,
+       possibly  followed  by  `,'  possibly  followed by another
+       unsigned decimal integer, always  followed  by  `}'.   The
+       integers  must  lie  between 0 and RE_DUP_MAX (255) inclu-
+       sive, and if there are two of  them,  the  first  may  not
+       exceed the second.  An atom followed by a bound containing
+       one integer i and no comma matches a sequence of exactly i
+       matches of the atom.  An atom followed by a bound contain-
+       ing one integer i and a comma matches a sequence of  i  or
+       more  matches  of  the  atom.  An atom followed by a bound
+       containing two integers i and j matches a  sequence  of  i
+       through j (inclusive) matches of the atom.<P>
+
+       An atom is a regular expression enclosed in `()' (matching
+       a match for the regular expression), an empty set of  `()'
+       (matching  the  null  string),  a  bracket expression (see
+       below), `.'  (matching any single character), `^'  (match-
+       ing  the  null  string  at  the  beginning of a line), `$'
+       (matching the null string at the end of  a  line),  a  `\'
+       followed by one of the characters `^.[$()|*+?{\' (matching
+       that character taken as an ordinary character), a `\' fol-
+       lowed  by  any  other  character  (matching that character
+       taken as an ordinary character, as if the `\' had not been
+       present), or a single character with no other significance
+       (matching that character).  A `{' followed by a  character
+       other  than  a  digit  is  an  ordinary character, not the
+       beginning of a bound.  It is illegal to  end  an  RE  with
+       `\'.<P>
+
+       A  bracket  expression is a list of characters enclosed in
+       `[]'.  It normally matches any single character  from  the
+       list  (but  see  below).   If the list begins with `^', it
+       matches any single character (but see below) not from  the
+       rest of the list.  If two characters in the list are sepa-
+       rated by `-', this is shorthand  for  the  full  range  of
+       characters  between those two (inclusive) in the collating
+       sequence, e.g. `[0-9]' in ASCII matches any decimal digit.
+       It  is  illegal  for two ranges to share an endpoint, e.g.
+       `a-c-e'.  Ranges  are  very  collating-sequence-dependent,
+       and portable programs should avoid relying on them.<P>
+
+       To  include  a  literal `]' in the list, make it the first
+       character (following a possible `^').  To include  a  lit-
+       eral `-', make it the first or last character, or the sec-
+       ond endpoint of a range.  To use  a  literal  `-'  as  the
+       first  endpoint of a range, enclose it in `[.' and `.]' to
+       make it a collating element (see below).  With the  excep-
+       tion  of  these  and some combinations using `[' (see next
+       paragraphs), all other special characters, including  `\',
+       lose  their  special significance within a bracket expres-
+       sion.<P>
+
+       Within a bracket expression, a collating element (a  char-
+       acter,  a  multi-character sequence that collates as if it
+       were a single character, or a collating-sequence name  for
+       either)  enclosed in `[.' and `.]' stands for the sequence
+       of characters of that collating element.  The sequence  is
+       a  single  element  of  the  bracket expression's list.  A
+       bracket expression containing a multi-character  collating
+       element  can  thus  match more than one character, e.g. if
+       the collating sequence includes a `ch' collating  element,
+       then the RE `[[.ch.]]*c' matches the first five characters
+       of `chchcc'.<P>
+
+       Within a bracket expression, a collating element  enclosed
+       in `[=' and `=]' is an equivalence class, standing for the
+       sequences of characters of all collating elements  equiva-
+       lent  to  that  one,  including  itself.  (If there are no
+       other equivalent collating elements, the treatment  is  as
+       if  the  enclosing  delimiters  were  `[.' and `.]'.)  For
+       example, if o and ^ are  the  members  of  an  equivalence
+       class,  then `[[=o=]]', `[[=^=]]', and `[o^]' are all syn-
+       onymous.  An equivalence class may not be an endpoint of a
+       range.<P>
+
+       Within a bracket expression, the name of a character class
+       enclosed in `[:' and `:]' stands for the list of all char-
+       acters  belonging to that class.  Standard character class
+       names are:<P>
+<table>
+<tr><td>alnum</TD><td>digit</td><td>punct</td></tr>
+<tr><td>alpha</TD><td>graph</TD><td>space</td></tr>
+<tr><td>blank</TD><td>lower</TD><td>upper</td></tr>
+<tr><td>cntrl</TD><td>print</TD><td>xdigit</td></tr>
+</table>
+<P>
+       These stand for the character classes defined in ctype(3).
+       A locale may provide others.  A character class may not be
+       used as an endpoint of a range.<P>
+
+       There are two special cases of  bracket  expressions:  the
+       bracket expressions `[[:&lt;:]]' and `[[:&gt;:]]' match the null
+       string at the beginning and end of a word respectively.  A
+       word  is defined as a sequence of word characters which is
+       neither preceded nor followed by word characters.  A  word
+       character  is  an alnum character (as defined by ctype(3))
+       or an underscore.  This is an extension,  compatible  with
+       but not specified by POSIX 1003.2, and should be used with
+       caution in software intended to be portable to other  sys-
+       tems.<P>
+
+       In  the  event  that  an RE could match more than one sub-
+       string of a given string, the RE matches the one  starting
+       earliest  in  the string.  If the RE could match more than
+       one substring starting  at  that  point,  it  matches  the
+       longest.   Subexpressions  also match the longest possible
+       substrings, subject to the constraint that the whole match
+       be  as long as possible, with subexpressions starting ear-
+       lier in the RE taking priority over ones  starting  later.
+       Note  that  higher-level subexpressions thus take priority
+       over their lower-level component subexpressions.<P>
+
+       Match lengths are measured in  characters,  not  collating
+       elements.   A  null  string  is  considered longer than no
+       match at all.  For example, `bb*' matches the three middle
+       characters    of   `abbbc',   `(wee|week)(knights|nights)'
+       matches all ten characters of `weeknights', when  `(.*).*'
+       is  matched  against `abc' the parenthesized subexpression
+       matches all three characters, and when `(a*)*' is  matched
+       against  `bc'  both  the  whole  RE  and the parenthesized
+       subexpression match the null string.<P>
+
+       If case-independent matching is specified, the  effect  is
+       much  as  if  all  case distinctions had vanished from the
+       alphabet.  When an  alphabetic  that  exists  in  multiple
+       cases  appears  as an ordinary character outside a bracket
+       expression, it is effectively transformed into  a  bracket
+       expression containing both cases, e.g. `x' becomes `[xX]'.
+       When it appears inside  a  bracket  expression,  all  case
+       counterparts of it are added to the bracket expression, so
+       that  (e.g.)  `[x]'  becomes  `[xX]'  and  `[^x]'  becomes
+       `[^xX]'.<P>
+
+       No particular limit is imposed on the length of REs.  Pro-
+       grams intended to be portable should not employ REs longer
+       than  256 bytes, as an implementation can refuse to accept
+       such REs and remain POSIX-compliant.<P>
+
+       Obsolete (``basic'') regular expressions differ in several
+       respects.   `|',  `+', and `?' are ordinary characters and
+       there is  no  equivalent  for  their  functionality.   The
+       delimiters  for bounds are `\{' and `\}', with `{' and `}'
+       by themselves ordinary characters.   The  parentheses  for
+       nested  subexpressions are `\(' and `\)', with `(' and `)'
+       by themselves ordinary characters.   `^'  is  an  ordinary
+       character  except at the beginning of the RE or the begin-
+       ning of a parenthesized subexpression, `$' is an  ordinary
+       character  except  at  the  end  of the RE or the end of a
+       parenthesized subexpression, and `*' is an ordinary  char-
+       acter  if  it  appears  at  the beginning of the RE or the
+       beginning of a parenthesized subexpression (after a possi-
+       ble leading `^').  Finally, there is one new type of atom,
+       a back reference: `\' followed by a non-zero decimal digit
+       d  matches  the same sequence of characters matched by the
+       dth parenthesized subexpression (numbering  subexpressions
+       by  the  positions  of  their opening parentheses, left to
+       right), so that (e.g.) `\([bc]\)\1' matches `bb'  or  `cc'
+       but not `bc'.<P>
+
+<B>SEE ALSO</B><BR>
+       POSIX 1003.2, section 2.8 (Regular Expression Notation).<P>
+
+<B>BUGS</B><BR>
+       Having two kinds of REs is a botch.<P>
+
+       The current 1003.2 spec says that `)' is an ordinary char-
+       acter in the absence of an  unmatched  `(';  this  was  an
+       unintentional  result  of  a  wording error, and change is
+       likely.  Avoid relying on it.<P>
+
+       Back references are a dreadful botch, posing  major  prob-
+       lems  for  efficient implementations.  They are also some-
+       what  vaguely  defined   (does   `a\(\(b\)*\2\)*d'   match
+       `abbbd'?).  Avoid using them.<P>
+
+       1003.2's  specification  of  case-independent  matching is
+       vague.  The ``one  case  implies  all  cases''  definition
+       given  above is current consensus among implementors as to
+       the right interpretation.<P>
+
+       The syntax for word boundaries is incredibly ugly.<P>
+
+<B>AUTHOR</B><BR>
+       This page was taken from Henry Spencer's regex package.
+</td>
+</tr>
+
+</table></center>
+
+<center>
+<hr NOSHADE WIDTH="80%"><i><font color="#000099"><font size=-1>This Web Site is 
+hosted by Apache for OS/2 and done by <a href="mailto:tbretz@astro.uni-wuerzburg.de">Thomas&nbsp;Bretz</a>.</font></font></i><BR>
+&nbsp;<BR>
+<a href="http://validator.w3.org/check/referer"><img border="0"
+   src="../../valid-html40.png" alt="Valid HTML 4.0!" height="20" width="66"></a>
+</center>&nbsp;
+</tr>
+</table>
+
+</center>
+
+</body>
+</html>
Index: trunk/MagicSoft/Mars/datacenter/db/runinfo.php
===================================================================
--- trunk/MagicSoft/Mars/datacenter/db/runinfo.php	(revision 7484)
+++ trunk/MagicSoft/Mars/datacenter/db/runinfo.php	(revision 7484)
@@ -0,0 +1,548 @@
+<?php
+{
+    function CreateQuery($_GET, $alias, $checkwhere, $checkgroup, $checkstatusgroup)
+    {
+        $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 . "), '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["fSource"]!="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");
+        $query0 .= StatusQuery("fCaCoFileAvail");
+        $query0 .= StatusQuery("fCaCoFileFound");
+        $query0 .= StatusQuery("fRawFileAvail");
+        $query0 .= StatusQuery("fDataCheckDone");
+        $query0 .= StatusQuery("fTimingCorrection");
+
+        if (!empty($_GET["fRunMin"]) && !empty($_GET["fRunMax"]))
+            $query0 .= "RunData.fRunNumber 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 (!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)
+    {
+        /*
+         if (empty($_GET["fRawFileKEY"]))
+         $_GET["fRawFileKEY"]="Off";
+         */
+
+        // 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["fLastUpdate"]))
+            $_GET["fLastUpdate"]="Off";
+
+        if (empty($_GET["fTest"]))
+            $_GET["fTest"]=$first?"On":"";
+
+        if (empty($_GET["fFormatVersion"]))
+            $_GET["fFormatVersion"]="Off";
+
+        if (empty($_GET["fNumEvents"]))
+            $_GET["fNumEvents"]=$first?"On":"";
+
+        if (empty($_GET["fRunStart"]))
+            $_GET["fRunStart"]=$first?"On":"";
+
+        if (empty($_GET["fRunStop"]))
+            $_GET["fRunStop"]="Off";
+
+        if (empty($_GET["fAzimuth"]))
+            $_GET["fAzimuth"]="Off";
+
+        if (empty($_GET["fZenithDistance"]))
+            $_GET["fZenithDistance"]=$first?"On":"";
+
+        if (empty($_GET["fRunTypeName"]))
+            $_GET["fRunTypeName"]=$first?"On":"";
+
+        if (empty($_GET["fMagicNumberName"]))
+            $_GET["fMagicNumberName"]="Off";
+
+        if (empty($_GET["fSourceName"]))
+            $_GET["fSourceName"]=$first?"On":"";
+
+        if (empty($_GET["fProjectName"]))
+            $_GET["fProjectName"]="Off";
+
+        if (empty($_GET["fL1TriggerTableName"]))
+            $_GET["fL1TriggerTableName"]="Off";
+
+        if (empty($_GET["fL2TriggerTableName"]))
+            $_GET["fL2TriggerTableName"]="Off";
+
+        if (empty($_GET["fMeanTriggerRate"]))
+            $_GET["fMeanTriggerRate"]=$first?"On":"";
+
+        if (empty($_GET["fHvSettingsName"]))
+            $_GET["fHvSettingsName"]="Off";
+
+        if (empty($_GET["fCalibrationScriptName"]))
+            $_GET["fCalibrationScriptName"]="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";
+
+        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["fExcludedFDAName"]))
+            $_GET["fExcludedFDAName"]=$first?"On":"";
+
+        if (empty($_GET["fSequenceFirst"]))
+            $_GET["fSequenceFirst"]="Off";
+
+        if (empty($_GET["fSequenceNo"]))
+            $_GET["fSequenceNo"]="";
+
+        if (empty($_GET["fDataCheckDone"]))
+            $_GET["fDataCheckDone"]="Off";
+
+        if (empty($_GET["fDataCheckDoneStatus"]))
+            $_GET["fDataCheckDoneStatus"]="0";
+
+        if (empty($_GET["fCCFileAvail"]))
+            $_GET["fCCFileAvail"]=$first?"On":"";
+
+        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"]=$first?"On":"";
+
+        if (empty($_GET["fRawFileAvailStatus"]))
+            $_GET["fRawFileAvailStatus"]="0";
+
+        if (empty($_GET["fTimingCorrection"]))
+            $_GET["fTimingCorrection"]=$first?"On":"";
+
+        if (empty($_GET["fTimingCorrectionStatus"]))
+            $_GET["fTimingCorrectionStatus"]="0";
+
+    }
+
+    function PrintForm($_GET, $db)
+    {
+        printf("<center>\n");
+        printf("<form action=\"runinfo.php\" METHOD=\"GET\">\n");
+        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(" <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");
+
+        // pull down boxes
+
+        printf(" <table>\n");
+        printf("  <tr><td>\n");
+        PrintPullDown($db, "RunType",     "fRunTypeName",     "fRunTypeKEY", "Run type");
+        printf("  </td><td>\n");
+        PrintPullDown($db, "Source",      "fSourceName",      "fSourceKEY", "Source Name");
+        printf("  </td><td>\n");
+        PrintPullDown($db, "HvSettings",  "fHvSettingsName",  "fHvSettingsKEY", "HV Settings");
+        printf("  </td><td>\n");
+        PrintPullDown($db, "L1TriggerTable", "fL1TriggerTableName", "fL1TriggerTableKEY", "L1 Trigger Table");
+        printf("  </td></tr><tr><td>\n");
+        PrintPullDown($db, "TestFlag",  "fTestFlagName",  "fTestFlagKEY", "Test Flag");
+        printf("  </td><td>\n");
+        PrintPullDown($db, "Project",     "fProjectName",     "fProjectKEY", "Project Name");
+        printf("  </td><td>\n");
+        PrintPullDown($db, "DiscriminatorThresholdTable",  "fDiscriminatorThresholdTableName",  "fDiscriminatorThresholdTableKEY", "DT Table");
+        printf("  </td><td>\n");
+        PrintPullDown($db, "L2TriggerTable", "fL2TriggerTableName", "fL2TriggerTableKEY", "L2 Trigger Table");
+        printf("  </td></tr><tr><td>\n");
+        PrintPullDown($db, "ExcludedFDA", "fExcludedFDAName", "fExcludedFDAKEY", "Exclusions");
+        printf("  </td><td>\n");
+        PrintPullDown($db, "LightConditions",  "fLightConditionsName",  "fLightConditionsKEY", "Light Conditions");
+        printf("  </td><td>\n");
+        PrintPullDown($db, "CalibrationScript",  "fCalibrationScriptName",  "fCalibrationScriptKEY", "Cal Script");
+        printf("  </td><td>\n");
+        PrintPullDown($db, "TriggerDelayTable",  "fTriggerDelayTableName",  "fTriggerDelayTableKEY", "Trigger Delay Table");
+        printf("  </td></tr><tr><td>\n");
+        PrintPullDown($db, "MagicNumber", "fMagicNumberName", "fMagicNumberKEY", "Magic Number");
+        printf(" </td></tr></table>\n");
+
+        printf(" <p>\n");
+
+        if (empty($_GET["fStartDate"]))
+            $timemin = GetMin("fRunStart", "RunData", $db);
+        else
+            $timemin = $_GET["fStartDate"];
+
+        if (empty($_GET["fStopDate"]))
+            $timemax = GetMax("fRunStart", "RunData", $db);
+        else
+            $timemax = $_GET["fStopDate"];
+
+        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");
+
+        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);
+
+/*
+        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");
+*/
+
+        if (empty($_GET["fRunMin"]))
+            $min = GetMin("fRunNumber", "RunData", $db);
+        else
+            $min = $_GET["fRunMin"];
+
+        if (empty($_GET["fRunMax"]))
+            $max = GetMax("fRunNumber", "RunData", $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);
+
+        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");
+
+        printf(" Results:\n");
+        printf(" <select name=\"fNumResults\">\n");
+
+        $numres = array("10", "20", "50", "100", "200", "500", "1000", "2000");
+        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");
+
+        ini_set("mysql.trace_mode", "Off");
+        ini_set("display_errors", "Off");
+
+        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=\"runinfo.php\"'>&nbsp;&nbsp;&nbsp;\n");
+        if (strchr($_SERVER["REQUEST_URI"], '?')!=FALSE)
+            printf("<input class='Width' type='button' value='Get .txt' onClick='self.location.href=\"%s&fSendTxt=1\"'>&nbsp;&nbsp;&nbsp;\n", $_SERVER["REQUEST_URI"]);
+        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("</form>\n");
+        printf("</center>\n");
+        printf("</td>\n");
+        printf("</tr>\n");
+        printf("<tr class='Block'>\n");
+        printf("<td>\n");
+    }
+
+    function PrintPage($html, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup)
+    {
+        $db_id = mysql_connect("hercules.astro.uni-wuerzburg.de", "MAGIC", "d99swMT!");
+        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);
+
+        $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);
+
+        if ($html=="1")
+            printf("<U><B>submitted query:</B></U><BR>%s<BR>", htmlspecialchars($query0));
+    }
+
+    include ("include.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", $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, $db);
+
+        if ($environment==0)
+            printf("No query submitted yet.<BR>");
+        else
+        {
+            if (empty($_GET["fPrintTable"]))
+                PrintPage("1", $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup);
+            else
+                PrintPage("2", $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup);
+        }
+
+        echo (file_get_contents("index-footer.html"));
+    }
+
+    ini_set("display_errors",   "Off");
+    ini_set("mysql.trace_mode", "Off");
+}
+?>
Index: trunk/MagicSoft/Mars/datacenter/db/sequence.php
===================================================================
--- trunk/MagicSoft/Mars/datacenter/db/sequence.php	(revision 7484)
+++ trunk/MagicSoft/Mars/datacenter/db/sequence.php	(revision 7484)
@@ -0,0 +1,565 @@
+<?php
+{
+    function CreateQuery($_GET)
+    {
+        $query0  = "SELECT ";
+        //main (0-18)
+        $query0 .= " Sequences.fSequenceFirst, fSequenceLast, ";//0,1
+        $query0 .= " fSourceName, fProjectName, ";//2,3
+        $query0 .= " fRunStart, fRunTime, fNumEvents, ";//4,5,6
+        $query0 .= " fZenithDistanceMin, fZenithDistanceMax, ";//7,8
+        $query0 .= " fAzimuthMin, fAzimuthMax, ";//9,10
+        $query0 .= " fHvSettingsName, fDiscriminatorThresholdTableName, ";//11,12
+        $query0 .= " fL1TriggerTableName, fL2TriggerTableName, ";//13,14
+        $query0 .= " fTriggerDelayTableName, fTestFlagName, ";//15,16
+        $query0 .= " fLightConditionsName, fManuallyChangedName, ";//17,18
+        //steps (19-24)
+        $query0 .= " fSequenceFileWritten, fAllFilesAvail, ";//19,20
+        $query0 .= " fCallisto, fFillCallisto, ";//21,22
+        $query0 .= " fStar, fFillStar, ";//23,24
+        //calibration (25-39)
+        $query0 .= " fUnsuitableInner, fUnsuitableOuter, ";//25,26
+        $query0 .= " fUnreliableInner, fUnreliableOuter, ";//27,28
+        $query0 .= " fIsolatedInner, fIsolatedOuter, fIsolatedMaxCluster, ";//29,30,31
+        $query0 .= " fArrTimeMeanInner, fArrTimeMeanOuter, ";//32,33
+        $query0 .= " fArrTimeRmsInner, fArrTimeRmsOuter, ";//34,35
+        $query0 .= " fConvFactorInner, fConvFactorOuter, ";//36,37
+        $query0 .= " fMeanPedRmsInner, fMeanPedRmsOuter, ";//38,39
+        //myon,star (40-47)
+        $query0 .= " fPSF, fRatio, fMuonRate, ";//40,41,42
+        $query0 .= " fMuonNumber, fEffOnTime, fDataRate, ";//43,44,45
+        $query0 .= " fMaxHumidity, fMeanNumberIslands, ";//46,47
+        $query0 .= " CONCAT('<a 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') , '\">cal-log</A>') as 'CalLink', ";//48
+        $query0 .= " CONCAT('<a 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') , '\">star-log</A>') as 'StarLink', ";//49
+        $query0 .= " CONCAT('<a 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') , '\">', 'sequ-file</a>') as 'SequLink' ";//50
+
+        $query0 .= " FROM Sequences ";
+
+        $query0 .= " LEFT JOIN Source ON Sequences.fSourceKEY=Source.fSourceKEY ";
+        $query0 .= " LEFT JOIN Project ON Sequences.fProjectKEY=Project.fProjectKEY ";
+        $query0 .= " LEFT JOIN HvSettings ON Sequences.fHvSettingsKEY=HvSettings.fHvSettingsKEY ";
+        $query0 .= " LEFT JOIN DiscriminatorThresholdTable ON Sequences.fDiscriminatorThresholdTableKEY=DiscriminatorThresholdTable.fDiscriminatorThresholdTableKEY ";
+        $query0 .= " LEFT JOIN L1TriggerTable ON Sequences.fL1TriggerTableKEY=L1TriggerTable.fL1TriggerTableKEY ";
+        $query0 .= " LEFT JOIN L2TriggerTable ON Sequences.fL2TriggerTableKEY=L2TriggerTable.fL2TriggerTableKEY ";
+        $query0 .= " LEFT JOIN TriggerDelayTable ON Sequences.fTriggerDelayTableKEY=TriggerDelayTable.fTriggerDelayTableKEY ";
+        $query0 .= " LEFT JOIN TestFlag ON Sequences.fTestFlagKEY=TestFlag.fTestFlagKEY ";
+        $query0 .= " LEFT JOIN LightConditions ON Sequences.fLightConditionsKEY=LightConditions.fLightConditionsKEY ";
+        $query0 .= " LEFT JOIN ManuallyChanged ON Sequences.fManuallyChangedKEY=ManuallyChanged.fManuallyChangedKEY ";
+        $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 ";
+
+        $query0 .= " WHERE Sequences.fSequenceFirst between " . $_GET["fRunMin"] . " and " . $_GET["fRunMax"] ;
+        if (!empty($_GET["fSequenceNo"]))
+            $query0 .= " AND Sequences.fSequenceFirst='" . $_GET["fSequenceNo"] . "'";
+        $query0 .= " AND fSourceName REGEXP \"^" . $_GET["fSourceN"] . "\" ";
+        $query0 .= " ORDER BY Sequences.fSequenceFirst ";
+
+        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["fAll"]))
+            $_GET["fAll"]=$first?"On":"";
+
+    }
+
+    function PrintForm($_GET, $db)
+    {
+        printf("<center>\n");
+        printf("<form action=\"sequence.php\" METHOD=\"GET\">\n");
+
+        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");
+//        printf("Sequence&nbsp;&nbsp;<input name=\"fSequence\" type=\"text\" size=\"10\" maxlength=\"10\" value=\"\">&nbsp;&nbsp;\n");
+
+        if (empty($_GET["fRunMin"]))
+            $min = GetMin("fSequenceFirst", "Sequences", $db);
+        else
+            $min = $_GET["fRunMin"];
+
+        if (empty($_GET["fRunMax"]))
+            $max = GetMax("fSequenceFirst", "Sequences", $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);
+
+        if ($_GET["fAll"]=="On")
+            $checked = "checked";
+        else
+            $checked = "";
+        printf("<input type=\"checkbox\" name=\"fAll\" value=\"On\" %s>all information\n", $checked);
+
+        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");
+
+
+        ini_set("mysql.trace_mode", "Off");
+        ini_set("display_errors", "Off");
+
+        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=\"sequence.php\"'>&nbsp;&nbsp;&nbsp;\n");
+//        if (strchr($_SERVER["REQUEST_URI"], '?')!=FALSE)
+//            printf("<input class='Width' type='button' value='Get .txt' onClick='self.location.href=\"%s&fSendTxt=1\"'>&nbsp;&nbsp;&nbsp;\n", $_SERVER["REQUEST_URI"]);
+        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("</form>\n");
+        printf("</center>\n");
+        printf("</td>\n");
+        printf("</tr>\n");
+        printf("<tr class='Block'>\n");
+        printf("<td>\n");
+    }
+
+    function GetStatus($step)
+    {
+        if (is_null($step))
+            return "<font color='#FF0000'>not done</font>";
+        else
+        {
+            if (strpos($step, "1970-01-01 00:00:00")==FALSE)
+                return "done";
+            else
+                return "not to be done";
+        }
+        return "there is an error -> tell Dani";
+    }
+
+    function GetCulm($azmin, $azmax)
+    {
+        $cul1=0;
+        $cul2=180;
+        if (($azmin < $cul1 && $azmax > $cul1) || ($azmin < $cul2 && $azmax > $cul2))
+            return "<font color='#FF0000'>yes</font>";
+        else
+            return "no";
+    }
+
+    function QueryRuns($type, $sequ, $db_id, $db)
+    {
+        $query1  = "SELECT fRunNumber, fCalibrationScriptName FROM RunData ";
+        $query1 .= " LEFT JOIN RunType ON RunData.fRunTypeKEY=RunType.fRunTypeKEY ";
+        $query1 .= " LEFT JOIN CalibrationScript ON RunData.fCalibrationScriptKEY=CalibrationScript.fCalibrationScriptKEY ";
+        $query1 .= " WHERE fSequenceFirst=" . $sequ . " AND fRunTypeName='" . $type . "'";
+
+        mysql_select_db($db);
+        $runs = mysql_query($query1, $db_id);
+        $numruns = mysql_num_rows($runs);
+        $calscript=mysql_result($runs, 0, 1);
+        printf(" <td align='left'>");
+        for ($i=0 ; $i<$numruns ; $i++)
+        {
+            $run=mysql_result($runs, $i, 0);
+            if ($i!=0)
+                printf(", ");
+            printf(" %s ", $run);
+        }
+        printf(" </td>\n");
+        printf(" <td> %s ", $calscript);
+        printf(" </td>\n");
+     }
+
+    function QueryMissingFiles($column, $sequ, $db_id, $db)
+    {
+        $query2  = "SELECT RunData.fRunNumber FROM RunData ";
+        $query2 .= " LEFT JOIN RunProcessStatus ON RunData.fRunNumber=RunProcessStatus.fRunNumber ";
+        $query2 .= " WHERE fSequenceFirst=" . $sequ . " AND IsNull(" . $column . ")";
+
+        mysql_select_db($db);
+        $files = mysql_query($query2, $db_id);
+        $numfiles = mysql_num_rows($files);
+        printf(" <td align='left'>");
+        for ($i=0 ; $i<$numfiles ; $i++)
+        {
+            $file=mysql_result($files, $i, 0);
+            if ($i!=0)
+                printf(", ");
+            printf(" %s ", $file);
+        }
+        printf(" </td>\n");
+     }
+
+
+    function PrintSequenceInfo($result0, $db_id, $db)
+    {
+        $numres = mysql_num_rows($result0);
+
+        printf("<center>");
+        printf("<table BORDER=\"0\">\n");
+        printf("<tr><td>");
+        printf("# of Sequences: %d ", $numres);
+        printf("</td></tr>");
+
+        for ($i=0 ; $i<$numres ; $i++)
+        {
+            $firstrun=mysql_result($result0, $i, 0);
+            $lastrun=mysql_result($result0, $i, 1);
+            $source=mysql_result($result0, $i, 2);
+            $project=mysql_result($result0, $i, 3);
+            $starttime=mysql_result($result0, $i, 4);
+            $duration=mysql_result($result0, $i, 5);
+            $numevents=mysql_result($result0, $i, 6);
+            $zdmin=mysql_result($result0, $i, 7);
+            $zdmax=mysql_result($result0, $i, 8);
+            $azmin=mysql_result($result0, $i, 9);
+            $azmax=mysql_result($result0, $i, 10);
+            $hv=mysql_result($result0, $i, 11);
+            $dt=mysql_result($result0, $i, 12);
+            $l1tt=mysql_result($result0, $i, 13);
+            $l2tt=mysql_result($result0, $i, 14);
+            $td=mysql_result($result0, $i, 15);
+            $testflag=mysql_result($result0, $i, 16);
+            $lightcond=mysql_result($result0, $i, 17);
+            $manuallychanged=mysql_result($result0, $i, 18);
+            $sequfile=mysql_result($result0, $i, 19);
+            $filesavail=mysql_result($result0, $i, 20);
+            $callisto=mysql_result($result0, $i, 21);
+            $star=mysql_result($result0, $i, 22);
+            $fillcallisto=mysql_result($result0, $i, 23);
+            $fillstar=mysql_result($result0, $i, 24);
+            $unsi=mysql_result($result0, $i, 25);
+            $unso=mysql_result($result0, $i, 26);
+            $unri=mysql_result($result0, $i, 27);
+            $unro=mysql_result($result0, $i, 28);
+            $isoi=mysql_result($result0, $i, 29);
+            $isoo=mysql_result($result0, $i, 30);
+            $imc=mysql_result($result0, $i, 31);
+            $arrtimei=mysql_result($result0, $i, 32);
+            $arrtimeo=mysql_result($result0, $i, 33);
+            $arrtimermsi=mysql_result($result0, $i, 34);
+            $arrtimermso=mysql_result($result0, $i, 35);
+            $convi=mysql_result($result0, $i, 36);
+            $convo=mysql_result($result0, $i, 37);
+            $meanpedrmsi=mysql_result($result0, $i, 38);
+            $meanpedrmso=mysql_result($result0, $i, 39);
+            $psf=mysql_result($result0, $i, 40);
+            $ratio=mysql_result($result0, $i, 41);
+            $muonrate=mysql_result($result0, $i, 42);
+            $muonnum=mysql_result($result0, $i, 43);
+            $effontime=mysql_result($result0, $i, 44);
+            $datarate=mysql_result($result0, $i, 45);
+            $maxhum=mysql_result($result0, $i, 46);
+            $meannumislands=mysql_result($result0, $i, 47);
+            $callink=mysql_result($result0, $i, 48);
+            $starlink=mysql_result($result0, $i, 49);
+            $sequlink=mysql_result($result0, $i, 50);
+
+            printf("<tr><td>");
+
+            printf(" <table BORDER=\"1\">");
+            printf(" <tr BGCOLOR='#C0C0C0'>\n");
+            printf(" <th><u>Sequence#:</u> %s </th>", $firstrun);
+            printf(" </tr><tr BGCOLOR='#D0D0D0' ALIGN='left'>\n");
+            printf(" <th> %s, %s, zd: %s&deg;-%s&deg;, %.2fmin ",
+                   $source, $starttime, $zdmin, $zdmax, $duration/60);
+            if (!is_null($star))
+                printf(", <font color='green'>image files available</font> ");
+            printf(" </td>\n");
+            printf(" </tr><tr>\n");
+            printf(" <td>\n");
+
+            printf("</td></tr><tr><td>\n");
+
+            printf(" <table BORDER=\"1\">");
+            printf(" <tr BGCOLOR='#C0C0C0'>\n");
+            printf(" <th colspan=\"4\">conditions</th>");
+            printf(" <th colspan=\"3\">muon parameter</th>\n");
+            printf(" </tr><tr BGCOLOR='#E0E0E0'>\n");
+            printf(" <td>light</td>\n");
+            printf(" <td>max hum</td>\n");
+            printf(" <td>zd</td>\n");
+            printf(" <td>culmination</td>");
+            if (!is_null($fillstar))
+            {
+                printf(" <td>muon rate</td>\n");
+                printf(" <td>ratio</td>\n");
+                printf(" <td>psf</td>\n");
+            }
+            printf(" </tr><tr BGCOLOR='#E0E0E0' align='right'>");
+            printf(" <td>%s</td>\n", $lightcond);
+            printf(" <td>%s %%</td>\n", $maxhum);
+            printf(" <td>%s&deg;-%s&deg;</td>\n", $zdmin, $zdmax);
+            printf(" <td>%s</td>\n", GetCulm($azmin, $azmax));
+            if (!is_null($fillstar))
+            {
+                printf(" <td> %sHz </td>\n", $muonrate);
+                printf(" <td> %s </td>\n", $ratio);
+                printf(" <td> %smm </td>\n", $psf);
+            }
+            printf(" </tr></table>");
+
+
+            if ($_GET["fAll"]=="On")
+            {
+                printf("</td></tr><tr><td>\n");
+                printf("</td></tr><tr><td>\n");
+
+                printf(" <table BORDER=\"1\">");
+                printf(" <tr BGCOLOR='#C0C0C0'>\n");
+                printf(" <th colspan=\"6\">general information</th>");
+                printf(" </tr>\n");
+                printf(" <tr BGCOLOR='#E0E0E0'>\n");
+                printf(" <td>source name</td>\n");
+                printf(" <td># events</td>\n");
+                printf(" <td>project name</td>\n");
+                printf(" <td>light conditions</td>\n");
+                printf(" <td>manually changed</td>\n");
+                printf(" <td>test flag</td>");
+                printf(" </tr><tr BGCOLOR='#E0E0E0'>");
+                printf(" <td> %s </td>\n", $source);
+                printf(" <td> %s </td>\n", $numevents);
+                printf(" <td> %s </td>\n", $project);
+                printf(" <td> %s </td>\n", $lightcond);
+                printf(" <td> %s </td>\n", $manuallychanged);
+                printf(" <td> %s </td>\n", $testflag);
+                printf(" </tr></table>");
+
+                printf("</td></tr><tr><td>\n");
+
+                printf(" <table BORDER=\"1\">");
+                printf(" <tr BGCOLOR='#C0C0C0'>\n");
+                printf(" <th colspan=\"5\">trigger & camera</th>");
+                printf(" </tr>\n");
+                printf(" <tr BGCOLOR='#E0E0E0'>\n");
+                printf(" <td>l1 trigger</td>\n");
+                printf(" <td>l2 trigger</td>\n");
+                printf(" <td>trigger delay</td>\n");
+                printf(" <td>HvSettings</td>\n");
+                printf(" <td>DT</td>");
+                printf(" </tr><tr BGCOLOR='#E0E0E0'>");
+                printf(" <td> %s </td>\n", $l1tt);
+                printf(" <td> %s </td>\n", $l2tt);
+                printf(" <td> %s </td>\n", $td);
+                printf(" <td> %s </td>\n", $hv);
+                printf(" <td> %s </td>\n", $dt);
+                printf(" </tr></table>");
+
+                printf("</td></tr><tr><td>\n");
+
+                printf(" <table BORDER=\"1\">");
+                printf(" <tr BGCOLOR='#C0C0C0'>\n");
+                printf(" <th colspan=\"6\">steps</th>");
+                printf(" </tr>\n");
+                printf(" <tr BGCOLOR='#E0E0E0' align='center'>\n");
+                printf(" <td>sequencefile</td>\n");
+                printf(" <td>files avail</td>\n");
+                printf(" <td>callisto</td>\n");
+                printf(" <td>fillcal</td>\n");
+                printf(" <td>star</td>");
+                printf(" <td>fillstar</td>");
+                printf(" </tr><tr BGCOLOR='#E0E0E0' align='right'>");
+                printf(" <td> %s </td>\n", GetStatus($sequfile));
+                printf(" <td> %s </td>\n", GetStatus($filesavail));
+                printf(" <td> %s </td>\n", GetStatus($callisto));
+                printf(" <td> %s </td>\n", GetStatus($fillcallisto));
+                printf(" <td> %s </td>\n", GetStatus($star));
+                printf(" <td> %s </td>\n", GetStatus($fillstar));
+                printf(" </tr>\n");
+                printf(" <tr BGCOLOR='#E0E0E0' align='center'>\n");
+                printf(" <td>%s</td>\n", $sequlink);
+                printf(" <td><br></td>\n");
+                printf(" <td>%s</td>\n", $callink);
+                printf(" <td><br></td>\n");
+                printf(" <td>%s</td>", $starlink);
+                printf(" <td><br></td>");
+                printf(" </tr></table>");
+
+                printf("</td></tr><tr><td>\n");
+
+                if (!is_null($fillcallisto))
+                {
+                    printf(" <table BORDER=\"1\">");
+                    printf(" <tr BGCOLOR='#D0D0D0'>");
+                    printf(" <th BGCOLOR='#C0C0C0'>calibration (<a href=\"reference.html\">ref</a>)</th>\n");
+                    printf(" <td>inner</td>\n");
+                    printf(" <td>outer</td>");
+                    printf(" </tr><tr BGCOLOR='#E0E0E0'>");
+                    printf(" <td>unsuitable pixel</td>\n");
+                    printf(" <td align='right'> %s </td>\n", $unsi);
+                    printf(" <td align='right'> %s </td>\n", $unso);
+                    printf(" </tr><tr BGCOLOR='#D0D0D0'>");
+                    printf(" <td>unreliable pixel</td>\n");
+                    printf(" <td align='right'> %s </td>\n", $unri);
+                    printf(" <td align='right'> %s </td>\n", $unro);
+                    printf(" </tr><tr BGCOLOR='#E0E0E0'>");
+                    printf(" <td>isolated pixel</td>\n");
+                    printf(" <td align='right'> %s </td>\n", $isoi);
+                    printf(" <td align='right'> %s </td>\n", $isoo);
+                    printf(" </tr><tr BGCOLOR='#D0D0D0'>");
+                    printf(" <td>isolated max cluster</td>\n");
+                    printf(" <td colspan=\"2\" align='right'> %s </td>\n", $imc);
+                    printf(" </tr><tr BGCOLOR='#E0E0E0'>");
+                    printf(" <td>arrival time</td>\n");
+                    printf(" <td align='right'> %s &plusmn; %s </td>\n", $arrtimei, $arrtimermsi);
+                    printf(" <td align='right'> %s &plusmn; %s </td>\n", $arrtimeo, $arrtimermso);
+                    printf(" </tr><tr BGCOLOR='#D0D0D0'>");
+                    printf(" <td>conversion factor</td>\n");
+                    printf(" <td align='right'> %s </td>\n", $convi);
+                    printf(" <td align='right'> %s </td>\n", $convo);
+                    printf(" </tr><tr BGCOLOR='#E0E0E0'>");
+                    printf(" <td>mean ped rms</td>\n");
+                    printf(" <td align='right'> %s </td>\n", $meanpedrmsi);
+                    printf(" <td align='right'> %s </td>\n", $meanpedrmso);
+                    printf(" </tr>");
+                    printf(" </table>");
+
+                    printf("</td></tr><tr><td>\n");
+                }
+
+                if (!is_null($fillstar))
+                {
+                    printf(" <table BORDER=\"1\">");
+                    printf(" <tr BGCOLOR='#C0C0C0'>");
+                    printf(" <th colspan=\"7\">star</th>\n");
+                    printf(" </tr><tr BGCOLOR='#D0D0D0' ALIGN='center'>");
+                    printf(" <td># islands</td>\n");
+                    printf(" <td># muons</td>\n");
+                    printf(" <td>effontime</td>\n");
+                    printf(" <td>datarate</td>\n");
+                    printf(" <td>muon rate</td>\n");
+                    printf(" <td>ratio</td>\n");
+                    printf(" <td>psf</td>\n");
+                    printf(" <tr BGCOLOR='#E0E0E0' ALIGN='right'>");
+                    printf(" <td> %s </td>\n", $meannumislands);
+                    printf(" <td> %s </td>\n", $muonnum);
+                    printf(" <td> %ss </td>\n", $effontime);
+                    printf(" <td> %sHz </td>\n", $datarate);
+                    printf(" <td> %sHz </td>\n", $muonrate);
+                    printf(" <td> %s </td>\n", $ratio);
+                    printf(" <td> %smm </td>\n", $psf);
+                    printf(" </tr>");
+                    printf(" </table>");
+                }
+
+                printf(" <table BORDER=\"1\">");
+                printf(" <tr BGCOLOR='#C0C0C0'>");
+                printf(" <th><A HREF=\"runinfo.php?fRunStart=On&fZenithDistance=On&fRunMin=%s&fMeanTriggerRate=On&fRunTypeName=On&fRunMax=%s&fNumEvents=On&fSourceName=On&fExcludedFDAKEY=1&fSequenceFirst=On&fRawFileAvail=On&fCCFileAvail=On&fCaCoFileAvail=On&fNumResults=500\">runs</A></th>", $firstrun, $lastrun);
+                printf(" <td>runs</td>\n");
+                printf(" <td>calscript</td>\n");
+                printf(" </tr><tr BGCOLOR='#D0D0D0' ALIGN='center'>");
+                printf(" <td>dataruns</td>\n");
+                QueryRuns("Data", $firstrun, $db_id, $db);
+                printf(" </tr><tr BGCOLOR='#E0E0E0' ALIGN='center'>");
+                printf(" <td>pedruns</td>\n");
+                QueryRuns("Pedestal", $firstrun, $db_id, $db);
+                printf(" </tr><tr BGCOLOR='#D0D0D0' ALIGN='center'>");
+                printf(" <td>calruns</td>\n");
+                QueryRuns("Calibration", $firstrun, $db_id, $db);
+                printf(" </tr>");
+                printf(" </table>");
+
+                if (is_null($filesavail))
+                {
+                    printf(" <table BORDER=\"1\">");
+                    printf(" <tr BGCOLOR='#C0C0C0'>");
+                    printf(" <th>missing files</th>");
+                    printf(" <td>run# of missing files</td>\n");
+                    printf(" </tr><tr BGCOLOR='#D0D0D0' ALIGN='center'>");
+                    printf(" <td>rawfiles</td>\n");
+                    QueryMissingFiles("fRawFileAvail", $firstrun, $db_id, $db);
+                    printf(" </tr><tr BGCOLOR='#E0E0E0' ALIGN='center'>");
+                    printf(" <td>ccfiles</td>\n");
+                    QueryMissingFiles("fCCFileAvail", $firstrun, $db_id, $db);
+                    printf(" </tr><tr BGCOLOR='#D0D0D0' ALIGN='center'>");
+                    printf(" <td>cacofiles</td>\n");
+                    QueryMissingFiles("fCaCoFileAvail", $firstrun, $db_id, $db);
+                    printf(" </tr>");
+                    printf(" </table>");
+                }
+
+
+            }
+            printf(" </table>");
+            printf("</td></tr><tr><td><br></td></tr>");
+
+        }
+        printf("</table>\n");
+
+        printf("</center>\n");
+        printf("</tr><tr class='Block'><td>\n");
+    }
+
+    function PrintPage($html, $db)
+    {
+        $db_id = mysql_connect("hercules.astro.uni-wuerzburg.de", "MAGIC", "d99swMT!");
+        if ($db_id==FALSE)
+        {
+            printf("mysql_connect returned the following error: %s\n", mysql_error());
+            die("");
+        }
+        mysql_select_db($db);
+
+        $query0 = CreateQuery($_GET);
+
+        $result0 = mysql_query($query0, $db_id);
+
+        if ($result0)
+        {
+            if ($html=="1" || $html=="2")
+                PrintSequenceInfo($result0, $db_id, $db);
+            else
+                PrintText($result0);
+
+            mysql_free_result($result0);
+        }
+        mysql_close($db_id);
+
+        if ($html=="1")
+            printf("<U><B>submitted query:</B></U><BR>%s<BR>", htmlspecialchars($query0));
+    }
+
+    include ("include.php");
+    include ("db.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", $db);
+    }
+    else
+    {
+        echo (file_get_contents("index-header.html"));
+
+        $environment = sizeof($_GET);
+
+        InitGet($_GET);
+        if (empty($_GET["fPrintTable"]))
+            PrintForm($_GET, $db);
+
+        if ($environment==0)
+            printf("No query submitted yet.<BR>");
+        else
+        {
+            if (empty($_GET["fPrintTable"]))
+                PrintPage("1", $db);
+            else
+                PrintPage("2", $db);
+        }
+
+        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 7484)
+++ trunk/MagicSoft/Mars/datacenter/db/sequinfo.php	(revision 7484)
@@ -0,0 +1,633 @@
+<?php
+{
+    function CreateQuery($_GET, $alias, $checkwhere, $checkgroup, $checkstatusgroup)
+    {
+        $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 . "), '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.php?',  'fRunStart=On', '&fZenithDistance=On', '&fRunMin=', Sequences.fSequenceFirst, '&fMeanTriggerRate=On', '&fTest=On', '&fRunTypeName=On', '&fRunMax=', fSequenceLast, '&fNumEvents=On', '&fSourceName=On&', 'fExcludedFDAKEY=1', '&fSequenceFirst=On', '&fRawFileAvail=On', '&fCCFileAvail=On', '&fCaCoFileAvail=On', '&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 .= " as 'Links'";
+                    }
+                }
+
+                foreach ($_GET as $key => $element)
+                    if ($_GET[$key]=="On")
+                        if ($key!="fLinks" && $key!="fTest")
+                            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($joins[$key]))
+//                $query0 .= $joins[$key];
+
+        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["fSource"]!="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)
+                        $query0 .= " AND ";
+
+            if ($element!=-1)
+                $query0 .= GetCheck($fromtable, $key) . "=" . $element;
+        }
+
+        if (strpos($query0, " WHERE ")==FALSE)
+            $query0 .= " WHERE ";
+        else
+            $query0 .= " AND ";
+
+        $query0 .= StatusQuery("fSequenceFileWritten");
+        $query0 .= StatusQuery("fAllFilesAvail");
+        $query0 .= StatusQuery("fCallisto");
+        $query0 .= StatusQuery("fFillCallisto");
+        $query0 .= StatusQuery("fStar");
+        $query0 .= StatusQuery("fFillStar");
+
+        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["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 || !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 ($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"]="20";
+
+        if (empty($_GET["fLastUpdate"]))
+            $_GET["fLastUpdate"]="Off";
+
+        if (empty($_GET["fNumEvents"]))
+            $_GET["fNumEvents"]=$first?"On":"";
+
+        if (empty($_GET["fRunStart"]))
+            $_GET["fRunStart"]=$first?"On":"";
+
+        if (empty($_GET["fRunTime/60"]))
+            $_GET["fRunTime/60"]=$first?"On":"";
+
+        if (empty($_GET["fSequenceLast"]))
+            $_GET["fSequenceLast"]=$first?"On":"";
+
+        if (empty($_GET["fLinks"]))
+            $_GET["fLinks"]=$first?"On":"";
+
+        if (empty($_GET["fTest"]))
+            $_GET["fTest"]=$first?"On":"";
+
+        if (empty($_GET["fAzimuthMin"]))
+            $_GET["fAzimuthMin"]="Off";
+
+        if (empty($_GET["fAzimuthMax"]))
+            $_GET["fAzimuthMax"]="Off";
+
+        if (empty($_GET["fZenithDistanceMin"]))
+            $_GET["fZenithDistanceMin"]=$first?"On":"";
+
+        if (empty($_GET["fZenithDistanceMax"]))
+            $_GET["fZenithDistanceMax"]="Off";
+
+        if (empty($_GET["fManuallyChangedName"]))
+            $_GET["fManuallyChangedName"]="Off";
+
+        if (empty($_GET["fSourceName"]))
+            $_GET["fSourceName"]=$first?"On":"";
+
+        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";
+
+        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"]=$first?"On":"";
+
+        if (empty($_GET["fStarStatus"]))
+            $_GET["fStarStatus"]="0";
+
+        if (empty($_GET["fFillStar"]))
+            $_GET["fFillStar"]="Off";
+
+        if (empty($_GET["fFillStarStatus"]))
+            $_GET["fFillStarStatus"]="0";
+
+        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["fConvFactorInner"]))
+            $_GET["fConvFactorInner"]=$first?"On":"";
+
+        if (empty($_GET["fConvFactorOuter"]))
+            $_GET["fConvFactorOuter"]=$first?"On":"";
+
+        if (empty($_GET["fMeanNumberIslands"]))
+            $_GET["fMeanNumberIslands"]="Off";
+
+        if (empty($_GET["fPSF"]))
+            $_GET["fPSF"]=$first?"On":"";
+
+        if (empty($_GET["fRatio"]))
+            $_GET["fRatio"]=$first?"On":"";
+
+        if (empty($_GET["fMuonNumber"]))
+            $_GET["fMuonNumber"]=$first?"On":"";
+
+        if (empty($_GET["fEffOnTime"]))
+            $_GET["fEffOnTime"]="Off";
+
+        if (empty($_GET["fMuonRate"]))
+            $_GET["fMuonRate"]="Off";
+
+        if (empty($_GET["fDataRate"]))
+            $_GET["fDataRate"]="Off";
+
+        if (empty($_GET["fMaxHumidity"]))
+            $_GET["fMaxHumidity"]="Off";
+
+    }
+
+    function PrintForm($_GET, $db)
+    {
+        printf("<center>\n");
+        printf("<form action=\"sequinfo.php\" METHOD=\"GET\">\n");
+        printf(" <table>\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");
+        printf(" <p>\n");
+        printf(" <table><tr><td>\n");
+
+        PrintStatusMenu("fSequenceFileWritten", "Sequfile");
+        printf("  </td><td>\n");
+        PrintStatusMenu("fAllFilesAvail",       "Files avail");
+        printf("  </td><td>\n");
+        PrintStatusMenu("fCallisto",            "Callisto");
+        printf("  </td><td>\n");
+        PrintStatusMenu("fStar",                "Star");
+        printf("  </td><td>\n");
+        PrintStatusMenu("fFillCallisto",        "Fillcallisto");
+        printf("  </td><td>\n");
+        PrintStatusMenu("fFillStar",            "Fillstar");
+
+        printf("</td></tr> </table>\n");
+        printf(" <p>\n");
+        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("fConvFactorInner",     "Conv inner ");
+        CheckBox("fConvFactorOuter",     "Conv outer ");
+        CheckBox("fMeanPedRmsInner",     "MeanPedRms inner");
+        CheckBox("fMeanPedRmsOuter",     "MeanPedRms outer");
+
+        printf(" </tr></table>\n");
+        printf(" <p>\n");
+
+        printf(" <table>\n");
+        printf("  <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("fMaxHumidity",        "MaxHumidity");
+        CheckBox("fDataRate",           "CleanedEvtRate");
+
+        printf("  </tr>\n");
+        printf(" </table>\n");
+        printf(" <p>\n");
+
+        // pull down boxes
+
+        printf(" <table>\n");
+        printf("  <tr><td>\n");
+        PrintPullDown($db, "Source",                      "fSourceName",                      "fSourceKEY",                      "Source Name");
+        printf("  </td><td>\n");
+        PrintPullDown($db, "L1TriggerTable",              "fL1TriggerTableName",              "fL1TriggerTableKEY",              "L1Trigger Table");
+        printf("  </td><td>\n");
+        PrintPullDown($db, "L2TriggerTable",              "fL2TriggerTableName",              "fL2TriggerTableKEY",              "L2Trigger Table");
+        printf("  </td><td>\n");
+        PrintPullDown($db, "TriggerDelayTable",           "fTriggerDelayTableName",           "fTriggerDelayTableKEY",           "Trigger Delay Table");
+        printf("  </td></tr><tr><td>\n");
+        PrintPullDown($db, "LightConditions",             "fLightConditionsName",             "fLightConditionsKEY",             "Light Conditions");
+        printf("  </td><td>\n");
+        PrintPullDown($db, "Project",                     "fProjectName",                     "fProjectKEY",                     "Project Name");
+        printf("  </td><td>\n");
+        PrintPullDown($db, "HvSettings",                  "fHvSettingsName",                  "fHvSettingsKEY",                  "HV Settings");
+        printf("  </td><td>\n");
+        PrintPullDown($db, "DiscriminatorThresholdTable", "fDiscriminatorThresholdTableName", "fDiscriminatorThresholdTableKEY", "DT Table");
+        printf("  </td></tr><tr><td>\n");
+        PrintPullDown($db, "ManuallyChanged",             "fManuallyChangedName",             "fManuallyChangedKEY",             "Manually changed");
+        printf("  </td><td>\n");
+        PrintPullDown($db, "TestFlag",                    "fTestFlagName",                    "fTestFlagKEY",                    "Test Flag");
+        printf("  </td></tr>\n");
+        printf(" </table>\n");
+        printf(" <p>\n");
+
+        if (empty($_GET["fStartDate"]))
+            $timemin = GetMin("fRunStart", "Sequences", $db);
+        else
+            $timemin = $_GET["fStartDate"];
+
+        if (empty($_GET["fStopDate"]))
+            $timemax = GetMax("fRunStart", "Sequences", $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", $db);
+        else
+            $min = $_GET["fRunMin"];
+
+        if (empty($_GET["fRunMax"]))
+            $max = GetMax("fSequenceFirst", "Sequences", $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");
+
+        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");
+
+        ini_set("mysql.trace_mode", "Off");
+        ini_set("display_errors", "Off");
+
+        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=\"sequinfo.php\"'>&nbsp;&nbsp;&nbsp;\n");
+        if (strchr($_SERVER["REQUEST_URI"], '?')!=FALSE)
+            printf("<input class='Width' type='button' value='Get .txt' onClick='self.location.href=\"%s&fSendTxt=1\"'>&nbsp;&nbsp;&nbsp;\n", $_SERVER["REQUEST_URI"]);
+        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("</form>\n");
+        printf("</center>\n");
+        printf("</td>\n");
+        printf("</tr>\n");
+        printf("<tr class='Block'>\n");
+        printf("<td>\n");
+    }
+
+    function PrintPage($html, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup)
+    {
+        $db_id = mysql_connect("hercules.astro.uni-wuerzburg.de", "MAGIC", "d99swMT!");
+        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);
+
+        $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);
+
+        if ($html=="1")
+            printf("<U><B>submitted query:</B></U><BR>%s<BR>", htmlspecialchars($query0));
+    }
+
+    include ("include.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", $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, $db);
+
+        if ($environment==0)
+            printf("No query submitted yet.<BR>");
+        else
+        {
+            if (empty($_GET["fPrintTable"]))
+                PrintPage("1", $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup);
+            else
+                PrintPage("2", $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup);
+        }
+
+        echo (file_get_contents("index-footer.html"));
+    }
+
+    ini_set("display_errors", "Off");
+    ini_set("mysql.trace_mode", "Off");
+}
+?>
Index: trunk/MagicSoft/Mars/datacenter/db/sources.php
===================================================================
--- trunk/MagicSoft/Mars/datacenter/db/sources.php	(revision 7484)
+++ trunk/MagicSoft/Mars/datacenter/db/sources.php	(revision 7484)
@@ -0,0 +1,152 @@
+<?php
+{
+    function CreateQuery($_GET, $alias)
+    {
+
+        $query0 = "SELECT ";
+        if ($_GET["fLinks"]=="Off" || !empty($_GET["fSendTxt"]))
+            $query0 .= " fSourceName as 'Source' ";
+        else
+        {
+            $query0 .= " CONCAT('<A&ws;HREF=\"sequinfo.php?', ";
+            $query0 .= " 'fRunStart=On', '&fZenithDistanceMin=On', '&fNumEvents=On', '&fRunTime%2F60=On', '&fSequenceLast=On', ";
+            $query0 .= " '&fSequenceFileWrittenStatus=0', '&fAllFilesAvail=On', '&fAllFilesAvailStatus=0', '&fCallisto=On', '&fCallistoStatus=0', '&fStar=On', '&fStarStatus=0', '&fFillCallistoStatus=0', '&fFillStarStatus=0', ";
+            $query0 .= " '&fSourceName=On', '&fSourceKEY=', fSourceKEY, "; //'&fRunMin=0', '&fRunMax=1000000', ";
+            $query0 .= " '&fNumResults=500\">', fSourcename, '</A>') ";
+            $query0 .= " as 'Source' ";
+        }
+        $query0 .= " , fSourceKEY as 'KEY', fTest as 'Test' ";
+        $query0 .= " FROM Source ";
+
+        if ($_GET["fTest"]=="Off")
+            $query0 .= " WHERE fTest='no'";
+
+        if ($_GET["fOff"]=="Off")
+        {
+            if (strpos($query0, " WHERE ")==FALSE)
+                $query0 .= " WHERE ";
+            else
+                $query0 .= " AND ";
+
+            $query0 .= " NOT (fSourceName like '%Off%')";
+        }
+
+        if (!empty($_GET["fSortBy"]))
+        {
+            $query0 .= " ORDER BY " . substr($_GET["fSortBy"], 0, -1) . " ";
+            if (substr($_GET["fSortBy"], -1)=="-")
+                $query0 .= "DESC";
+        }
+        else
+            $query0 .= " ORDER BY fSourceKEY ";
+
+        return $query0;
+    }
+
+    function InitGet($_GET)
+    {
+
+        if (empty($_GET["fTest"]))
+            $_GET["fTest"]="Off";
+
+        if (empty($_GET["fOff"]))
+            $_GET["fOff"]="Off";
+
+        if (empty($_GET["fLinks"]))
+            $_GET["fLinks"]="On";
+
+    }
+
+    function PrintForm($_GET)
+    {
+        printf("<center>\n");
+        printf("<form action=\"sources.php\" METHOD=\"GET\">\n");
+        printf(" <p><table>\n");
+        printf("  <tr>\n");
+
+        CheckBox("fOff",   "incl. offsources");
+        CheckBox("fTest",  "incl. test-sources");
+        CheckBox("fLinks", "links");
+
+        printf(" </table></p>\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");
+        printf("<input class='Width' type='button' value='Reset' onClick='self.location.href=\"sources.php\"'>&nbsp;&nbsp;&nbsp;\n");
+        if (strchr($_SERVER["REQUEST_URI"], '?')!=FALSE)
+            printf("<input class='Width' type='button' value='Get .txt' onClick='self.location.href=\"%s&fSendTxt=1\"'>&nbsp;&nbsp;&nbsp;\n", $_SERVER["REQUEST_URI"]);
+        printf("</form>\n");
+        printf("</center>\n");
+        printf("</td>\n");
+        printf("</tr>\n");
+        printf("<tr class='Block'>\n");
+        printf("<td>\n");
+    }
+
+    function PrintPage($html, $db, $alias, $rightalign)
+    {
+        $db_id = mysql_connect("hercules.astro.uni-wuerzburg.de", "MAGIC", "d99swMT!");
+        if ($db_id==FALSE)
+        {
+            printf("mysql_connect returned the following error: %s\n", mysql_error());
+            die("");
+        }
+        mysql_select_db($db);
+
+        $query0 = CreateQuery($_GET, $alias);
+
+        $result0 = mysql_query($query0, $db_id);
+
+        if ($result0)
+        {
+            if ($html=="1")
+                PrintMagicTable($result0, $alias, $rightalign, "", "", $_GET);
+            else
+                PrintText($result0);
+
+            mysql_free_result($result0);
+        }
+        mysql_close($db_id);
+
+        if ($html=="1")
+            printf("<U><B>submitted query:</B></U><BR>%s<BR>", htmlspecialchars($query0));
+    }
+
+    include ("include.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", $db, $alias, $rightalign);
+    }
+    else
+    {
+        echo (file_get_contents("index-header.html"));
+
+        $environment = sizeof($_GET);
+
+        InitGet($_GET);
+        PrintForm($_GET);
+
+        if ($environment==0)
+            printf("No query submitted yet.<BR>");
+        else
+            PrintPage("1", $db, $alias, $rightalign);
+
+        echo (file_get_contents("index-footer.html"));
+    }
+
+    ini_set("display_errors", "Off");
+    ini_set("mysql.trace_mode", "Off");
+}
+?>
Index: trunk/MagicSoft/Mars/datacenter/db/statusrps.php
===================================================================
--- trunk/MagicSoft/Mars/datacenter/db/statusrps.php	(revision 7484)
+++ trunk/MagicSoft/Mars/datacenter/db/statusrps.php	(revision 7484)
@@ -0,0 +1,254 @@
+<?php
+{
+    function CreateQuery($_GET, $alias, $checkstatusgroup, $checkwhere)
+    {
+        $query0 = "SELECT ";
+
+        $statusgroups = 0;
+        foreach ($checkstatusgroup as $element)
+            if ($element==-1)
+                $statusgroups++;
+
+        if ($statusgroups>0)
+        {
+            foreach ($checkstatusgroup as $key => $element)
+                if ($element==-1)
+                    $query0 .= " (if(IsNull(" . $key . "), 'not done' ,if(" . $key . "='1970-01-01 00:00:00','dont do','done'))) as '" . $key . "', ";
+
+            $query0 .= " count(*) as 'Run#'";
+
+        }
+        else
+        {
+            $query0 .= "fRunNumber as 'Run#' ";
+
+            foreach ($_GET as $key => $element)
+                if ($_GET[$key]=="On")
+                    if (empty($checkwhere[$key]) || $checkwhere[$key]==0)
+                        $query0 .= ", " . $key . " as '" . $alias[$key] . "' ";
+        }
+
+        $query0 .= " FROM RunProcessStatus ";
+
+        if (strpos($query0, " WHERE ")==FALSE)
+            $query0 .= " WHERE ";
+        else
+            $query0 .= " AND ";
+
+        $query0 .= StatusQuery("fCCFileAvail");
+        $query0 .= StatusQuery("fCaCoFileAvail");
+        $query0 .= StatusQuery("fCaCoFileFound");
+        $query0 .= StatusQuery("fRawFileAvail");
+        $query0 .= StatusQuery("fDataCheckDone");
+        $query0 .= StatusQuery("fTimingCorrection");
+
+        $query0 .= "fRunNumber BETWEEN " . $_GET["fRunMin"] . " AND " . $_GET["fRunMax"] . " ";
+
+        if ($statusgroups>0)
+        {
+            $query0 .= " GROUP BY ";
+            $num = $statusgroups;
+            foreach ($checkstatusgroup as $key => $element)
+                if ($element==-1)
+                {
+                    $query0 .= $key;
+                    if ($num-->1)
+                        $query0 .= ", ";
+                }
+        }
+
+        if (!empty($_GET["fSortBy"]))
+        {
+            $query0 .= " ORDER BY " . substr($_GET["fSortBy"], 0, -1) . " ";
+            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["fDataCheckDone"]))
+            $_GET["fDataCheckDone"]="Off";
+
+        if (empty($_GET["fDataCheckDoneStatus"]))
+            $_GET["fDataCheckDoneStatus"]="0";
+
+        if (empty($_GET["fCCFileAvail"]))
+            $_GET["fCCFileAvail"]=$first?"On":"";
+
+        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"]=$first?"On":"";
+
+        if (empty($_GET["fRawFileAvailStatus"]))
+            $_GET["fRawFileAvailStatus"]="0";
+
+        if (empty($_GET["fTimingCorrection"]))
+            $_GET["fTimingCorrection"]=$first?"On":"";
+
+        if (empty($_GET["fTimingCorrectionStatus"]))
+            $_GET["fTimingCorrectionStatus"]="0";
+
+    }
+
+    function PrintForm($_GET, $db)
+    {
+        printf("<center>\n");
+        printf("<form action=\"statusrps.php\" METHOD=\"GET\">\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");
+
+        if (empty($_GET["fRunMin"]))
+            $min = GetMin("fRunNumber", "RunProcessStatus", $db);
+        else
+            $min = $_GET["fRunMin"];
+
+        if (empty($_GET["fRunMax"]))
+            $max = GetMax("fRunNumber", "RunProcessStatus", $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);
+
+        printf(" <P>\n");
+
+        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");
+
+        ini_set("mysql.trace_mode", "Off");
+        ini_set("display_errors", "Off");
+
+        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=\"statusrps.php\"'>&nbsp;&nbsp;&nbsp;\n");
+        if (strchr($_SERVER["REQUEST_URI"], '?')!=FALSE)
+            printf("<input class='Width' type='button' value='Get .txt' onClick='self.location.href=\"%s&fSendTxt=1\"'>&nbsp;&nbsp;&nbsp;\n", $_SERVER["REQUEST_URI"]);
+        printf("</form>\n");
+        printf("</center>\n");
+        printf("</td>\n");
+        printf("</tr>\n");
+        printf("<tr class='Block'>\n");
+        printf("<td>\n");
+    }
+
+    function PrintPage($html, $db, $alias, $rightalign, $checkstatusgroup, $checkwhere)
+    {
+        $db_id = mysql_connect("hercules.astro.uni-wuerzburg.de", "MAGIC", "d99swMT!");
+        if ($db_id==FALSE)
+        {
+            printf("mysql_connect returned the following error: %s\n", mysql_error());
+            die("");
+        }
+        mysql_select_db($db);
+
+        $query0 = CreateQuery($_GET, $alias, $checkstatusgroup, $checkwhere);
+
+        $result0 = mysql_query($query0, $db_id);
+
+        if ($result0)
+        {
+            if ($html=="1")
+                PrintMagicTable($result0, $alias, $rightalign, "", "", $_GET);
+            else
+                PrintText($result0);
+
+            mysql_free_result($result0);
+        }
+        mysql_close($db_id);
+
+        if ($html=="1")
+            printf("<U><B>submitted query:</B></U><BR>%s<BR>", htmlspecialchars($query0));
+    }
+
+    include ("include.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", $db, $alias, $rightalign, $checkstatusgroup, $checkwhere);
+    }
+    else
+    {
+        echo (file_get_contents("index-header.html"));
+
+        $environment = sizeof($_GET);
+
+        InitGet($_GET);
+        PrintForm($_GET, $db);
+
+        if ($environment==0)
+            printf("No query submitted yet.<BR>");
+        else
+            PrintPage("1", $db, $alias, $rightalign, $checkstatusgroup, $checkwhere);
+
+        echo (file_get_contents("index-footer.html"));
+    }
+
+    ini_set("display_errors", "Off");
+    ini_set("mysql.trace_mode", "Off");
+}
+?>
Index: trunk/MagicSoft/Mars/datacenter/db/statussbs.php
===================================================================
--- trunk/MagicSoft/Mars/datacenter/db/statussbs.php	(revision 7484)
+++ trunk/MagicSoft/Mars/datacenter/db/statussbs.php	(revision 7484)
@@ -0,0 +1,230 @@
+<?php
+{
+    function CreateQuery($_GET, $alias, $checkstatusgroup, $checkwhere)
+    {
+        $statusgroups = 0;
+        foreach ($checkstatusgroup as $element)
+            if ($element==-1)
+                $statusgroups++;
+
+        $query0 = "SELECT ";
+
+        if ($statusgroups>0)
+        {
+            foreach ($checkstatusgroup as $key => $element)
+                if ($element==-1)
+                    $query0 .= " (if(IsNull(" . $key . "), 'not done' ,if(" . $key . "='1970-01-01 00:00:00','dont do','done'))) as '" . $alias[$key] . "', ";
+
+            $query0 .= " count(*) as '#days'";
+
+        }
+        else
+        {
+            if (!empty($_GET["fSendTxt"]))
+                $query0 .= " fDate ";
+            else
+            {
+                $query0 .= " CONCAT( fDate , ':  <A&ws;HREF=\"index.php?', 'fRunStart=On', '&fZenithDistance=On', '&fMeanTriggerRate=On', '&fRunTypeName=On', '&fNumEvents=On', '&fSourceName=On&', 'fExcludedFDAKEY=1', '&fSequenceFirst=On', '&fStartDate=', fDate, '&fStopDate=', fDate, '&fNumResults=500\">Runs</A> ' , ";
+                $query0 .= " ' <A&ws;HREF=\"queryseq.php?', 'fRunStart=On', '&fZenithDistanceMin=On', '&fNumEvents=On', '&fSourceName=On&', 'fExcludedFDAKEY=1', '&fStartDate=', fDate, '&fStopDate=', fDate, '&fNumResults=500\">Sequ</A> ') ";
+            }
+            $query0 .= " as 'Date' ";
+
+            foreach ($_GET as $key => $element)
+                if ($_GET[$key]=="On")
+                    if (empty($checkwhere[$key]) || $checkwhere[$key]==0)
+                        $query0 .= ", " . $key . " as '" . $alias[$key] . "' ";
+        }
+
+        $query0 .= " FROM SequenceBuildStatus ";
+
+        if (strpos($query0, " WHERE ")==FALSE)
+            $query0 .= " WHERE ";
+        else
+            $query0 .= " AND ";
+
+        $query0 .= StatusQuery("fCCFilled");
+        $query0 .= StatusQuery("fExclusionsDone");
+        $query0 .= StatusQuery("fSequenceEntriesBuilt");
+
+        $query0 .= "fDate BETWEEN '" . $_GET["fRunMin"] . "' AND '" . $_GET["fRunMax"] . "' ";
+
+        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"]))
+        {
+            $query0 .= " ORDER BY " . substr($_GET["fSortBy"], 0, -1) . " ";
+            if (substr($_GET["fSortBy"], -1)=="-")
+                $query0 .= "DESC";
+        }
+
+        if (empty($_GET["fSortBy"]) && $statusgroups==0)
+            $query0 .= "ORDER BY SequenceBuildStatus.fDate 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"]="20";
+
+        if (empty($_GET["fCCFilled"]))
+            $_GET["fCCFilled"]=$first?"On":"";
+
+        if (empty($_GET["fExclusionsDone"]))
+            $_GET["fExclusionsDone"]=$first?"On":"";
+
+        if (empty($_GET["fSequenceEntriesBuilt"]))
+            $_GET["fSequenceEntriesBuilt"]=$first?"On":"";
+    }
+
+    function PrintForm($_GET, $db)
+    {
+        printf("<center>\n");
+        printf("<form action=\"statussbs.php\" METHOD=\"GET\">\n");
+        printf(" <table>\n");
+        printf("  <tr><td>\n");
+
+        PrintStatusMenu("fCCFilled", "CC Filled");
+
+        printf("  </td><td>\n");
+
+        PrintStatusMenu("fExclusionsDone", "Exclusions");
+
+        printf("  </td><td>\n");
+
+        PrintStatusMenu("fSequenceEntriesBuilt", "Sequences");
+
+        printf(" </td></tr></table>\n");
+        printf(" <p>\n");
+
+
+        if (empty($_GET["fRunMin"]))
+            $min = GetMin("fDate", "SequenceBuildStatus", $db);
+        else
+            $min = $_GET["fRunMin"];
+
+        if (empty($_GET["fRunMax"]))
+            $max = GetMax("fDate", "SequenceBuildStatus", $db);
+        else
+            $max = $_GET["fRunMax"];
+
+
+        printf("Date&nbsp;from&nbsp;<input name=\"fRunMin\" type=\"text\" size=\"10\" maxlength=\"10\" value=\"%s\">\n", $min);
+        printf("to&nbsp;<input name=\"fRunMax\" type=\"text\" size=\"10\" maxlength=\"10\" value=\"%s\">&nbsp;&nbsp;&nbsp;\n", $max);
+
+        printf(" <P>\n");
+
+        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");
+
+        ini_set("mysql.trace_mode", "Off");
+        ini_set("display_errors", "Off");
+
+        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=\"statussbs.php\"'>&nbsp;&nbsp;&nbsp;\n");
+        if (strchr($_SERVER["REQUEST_URI"], '?')!=FALSE)
+            printf("<input class='Width' type='button' value='Get .txt' onClick='self.location.href=\"%s&fSendTxt=1\"'>&nbsp;&nbsp;&nbsp;\n", $_SERVER["REQUEST_URI"]);
+        printf("</form>\n");
+        printf("</center>\n");
+        printf("</td>\n");
+        printf("</tr>\n");
+        printf("<tr class='Block'>\n");
+        printf("<td>\n");
+    }
+
+    function PrintPage($html, $db, $alias, $rightalign, $checkstatusgroup, $checkwhere)
+    {
+        $db_id = mysql_connect("hercules.astro.uni-wuerzburg.de", "MAGIC", "d99swMT!");
+        if ($db_id==FALSE)
+        {
+            printf("mysql_connect returned the following error: %s\n", mysql_error());
+            die("");
+        }
+        mysql_select_db($db);
+
+        $query0 = CreateQuery($_GET, $alias, $checkstatusgroup, $checkwhere);
+
+        $result0 = mysql_query($query0, $db_id);
+
+        if ($result0)
+        {
+            if ($html=="1")
+                PrintMagicTable($result0, $alias, $rightalign, "", "", $_GET);
+            else
+                PrintText($result0);
+
+            mysql_free_result($result0);
+        }
+        mysql_close($db_id);
+
+        if ($html=="1")
+            printf("<U><B>submitted query:</B></U><BR>%s<BR>", htmlspecialchars($query0));
+    }
+
+    include ("include.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", $db, $alias, $rightalign, $checkstatusgroup, $checkwhere);
+    }
+    else
+    {
+        echo (file_get_contents("index-header.html"));
+
+        $environment = sizeof($_GET);
+
+        InitGet($_GET);
+        PrintForm($_GET, $db);
+
+        if ($environment==0)
+            printf("No query submitted yet.<BR>");
+        else
+            PrintPage("1", $db, $alias, $rightalign, $checkstatusgroup, $checkwhere);
+
+        echo (file_get_contents("index-footer.html"));
+    }
+
+    ini_set("display_errors", "Off");
+    ini_set("mysql.trace_mode", "Off");
+}
+?>
Index: trunk/MagicSoft/Mars/datacenter/db/statussps.php
===================================================================
--- trunk/MagicSoft/Mars/datacenter/db/statussps.php	(revision 7484)
+++ trunk/MagicSoft/Mars/datacenter/db/statussps.php	(revision 7484)
@@ -0,0 +1,243 @@
+<?php
+{
+    function CreateQuery($_GET, $alias, $checkstatusgroup, $checkwhere)
+    {
+        $statusgroups = 0;
+        foreach ($checkstatusgroup as $element)
+            if ($element==-1)
+                $statusgroups++;
+
+        $query0 = "SELECT ";
+
+        if ($statusgroups>0)
+        {
+            foreach ($checkstatusgroup as $key => $element)
+                if ($element==-1)
+                    $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 .= " fSequenceFirst ";
+            else
+                $query0 .= " CONCAT('<A&ws;HREF=\"index.php?', 'fRunStart=On', '&fZenithDistance=On', '&fMeanTriggerRate=On', '&fRunTypeName=On', '&fNumEvents=On', '&fSourceName=On&', 'fExcludedFDAKEY=1', '&fSequenceFirst=On', '&fSequenceNo=', fSequenceFirst, '&fNumResults=500\">', fSequenceFirst, '</A>') ";
+            $query0 .= " as 'Sequence#' ";
+
+            foreach ($_GET as $key => $element)
+                if ($_GET[$key]=="On")
+                if (empty($checkwhere[$key]) || $checkwhere[$key]==0)
+                    $query0 .= ", " . $key . " as '" . $alias[$key] . "' ";
+        }
+
+        $query0 .= " FROM SequenceProcessStatus ";
+
+        if (strpos($query0, " WHERE ")==FALSE)
+            $query0 .= " WHERE ";
+        else
+            $query0 .= " AND ";
+
+        $query0 .= StatusQuery("fSequenceFileWritten");
+        $query0 .= StatusQuery("fAllFilesAvail");
+        $query0 .= StatusQuery("fCallisto");
+        $query0 .= StatusQuery("fFillCallisto");
+        $query0 .= StatusQuery("fStar");
+        $query0 .= StatusQuery("fFillStar");
+
+        $query0 .= "fSequenceFirst BETWEEN " . $_GET["fRunMin"] . " AND " . $_GET["fRunMax"] . " ";
+
+        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"]))
+        {
+            $query0 .= " ORDER BY " . substr($_GET["fSortBy"], 0, -1) . " ";
+            if (substr($_GET["fSortBy"], -1)=="-")
+                $query0 .= "DESC";
+        }
+
+        if (empty($_GET["fSortBy"]) && $statusgroups==0)
+            $query0 .= "ORDER BY 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"]="20";
+
+        if (empty($_GET["fSequenceFileWritten"]))
+            $_GET["fSequenceFileWritten"]=$first?"On":"";
+
+        if (empty($_GET["fAllFilesAvail"]))
+            $_GET["fAllFilesAvail"]=$first?"On":"";
+
+        if (empty($_GET["fCallisto"]))
+            $_GET["fCallisto"]=$first?"On":"";
+
+        if (empty($_GET["fStar"]))
+            $_GET["fStar"]=$first?"On":"";
+
+        if (empty($_GET["fFillCallisto"]))
+            $_GET["fFillCallisto"]="Off";
+
+        if (empty($_GET["fFillStar"]))
+            $_GET["fFillStar"]="Off";
+
+    }
+
+    function PrintForm($_GET, $db)
+    {
+        printf("<center>\n");
+        printf("<form action=\"statussps.php\" METHOD=\"GET\">\n");
+        printf(" <table>\n");
+        printf("  <tr><td>\n");
+
+        PrintStatusMenu("fSequenceFileWritten", "Sequencefile written");
+        printf("  </td><td>\n");
+        PrintStatusMenu("fCallisto",            "Callisto");
+        printf("  </td><td>\n");
+        PrintStatusMenu("fStar",                "Star");
+
+        printf("  </td></tr><tr><td>\n");
+
+        PrintStatusMenu("fAllFilesAvail",       "All files available");
+        printf("  </td><td>\n");
+        PrintStatusMenu("fFillCallisto",        "Fillcallisto");
+        printf("  </td><td>\n");
+        PrintStatusMenu("fFillStar",            "Fillstar");
+
+        printf("</td></tr> </table>\n");
+        printf(" <p>\n");
+
+        if (empty($_GET["fRunMin"]))
+            $min = GetMin("fSequenceFirst", "SequenceProcessStatus", $db);
+        else
+            $min = $_GET["fRunMin"];
+
+        if (empty($_GET["fRunMax"]))
+            $max = GetMax("fSequenceFirst", "SequenceProcessStatus", $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);
+
+        printf(" <P>\n");
+
+        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");
+
+        ini_set("mysql.trace_mode", "Off");
+        ini_set("display_errors", "Off");
+
+        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=\"statussps.php\"'>&nbsp;&nbsp;&nbsp;\n");
+        if (strchr($_SERVER["REQUEST_URI"], '?')!=FALSE)
+            printf("<input class='Width' type='button' value='Get .txt' onClick='self.location.href=\"%s&fSendTxt=1\"'>&nbsp;&nbsp;&nbsp;\n", $_SERVER["REQUEST_URI"]);
+        printf("</form>\n");
+        printf("</center>\n");
+        printf("</td>\n");
+        printf("</tr>\n");
+        printf("<tr class='Block'>\n");
+        printf("<td>\n");
+    }
+
+    function PrintPage($html, $db, $alias, $rightalign, $checkstatusgroup, $checkwhere)
+    {
+        $db_id = mysql_connect("hercules.astro.uni-wuerzburg.de", "MAGIC", "d99swMT!");
+        if ($db_id==FALSE)
+        {
+            printf("mysql_connect returned the following error: %s\n", mysql_error());
+            die("");
+        }
+        mysql_select_db($db);
+
+        $query0 = CreateQuery($_GET, $alias, $checkstatusgroup, $checkwhere);
+
+        $result0 = mysql_query($query0, $db_id);
+
+        if ($result0)
+        {
+            if ($html=="1")
+                PrintMagicTable($result0, $alias, $rightalign, "", "", $_GET);
+            else
+                PrintText($result0);
+
+            mysql_free_result($result0);
+        }
+        mysql_close($db_id);
+
+        if ($html=="1")
+            printf("<U><B>submitted query:</B></U><BR>%s<BR>", htmlspecialchars($query0));
+    }
+
+    include ("include.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", $db, $alias, $rightalign, $checkstatusgroup, $checkwhere);
+    }
+    else
+    {
+        echo (file_get_contents("index-header.html"));
+
+        $environment = sizeof($_GET);
+
+        InitGet($_GET);
+        PrintForm($_GET, $db);
+
+        if ($environment==0)
+            printf("No query submitted yet.<BR>");
+        else
+            PrintPage("1", $db, $alias, $rightalign, $checkstatusgroup, $checkwhere);
+
+        echo (file_get_contents("index-footer.html"));
+    }
+
+    ini_set("display_errors", "Off");
+    ini_set("mysql.trace_mode", "Off");
+}
+?>
