Index: trunk/MagicSoft/Mars/datacenter/db/findoffdata.php
===================================================================
--- trunk/MagicSoft/Mars/datacenter/db/findoffdata.php	(revision 7637)
+++ trunk/MagicSoft/Mars/datacenter/db/findoffdata.php	(revision 7873)
@@ -127,8 +127,6 @@
             $query0 = substr($query0, 0, -4);
 
-/*
-        if (!empty($_GET["fDate"]))
-            $query0 .= " AND fRunStart REGEXP \"^" . $_GET["fDate"] . "\" ";
-*/
+        if (!empty($_GET["fZDMin"]) && !empty($_GET["fZDMax"]))
+            $query0 .= "AND (fZenithDistanceMin > " . $_GET["fZDMin"] . " AND fZenithDistanceMax < " . $_GET["fZDMax"] . ") ";
 
         if (!empty($_GET["fSourceN"]))
@@ -228,10 +226,4 @@
             $_GET["fNumResults"]="50";
 
-        if (empty($_GET["fLastUpdate"]))
-            $_GET["fLastUpdate"]="Off";
-
-        if (empty($_GET["fNumEvents"]))
-            $_GET["fNumEvents"]="Off";
-
         if (empty($_GET["fRunStart"]))
             $_GET["fRunStart"]=$first?"On":"";
@@ -240,61 +232,13 @@
             $_GET["fRunTime/60"]=$first?"On":"";
 
-        if (empty($_GET["fSequenceLast"]))
-            $_GET["fSequenceLast"]="Off";
-
         if (empty($_GET["fLinks"]))
             $_GET["fLinks"]=$first?"On":"";
 
         if (empty($_GET["fOff"]))
-            $_GET["fOff"]=$first?"On":"Off";
+            $_GET["fOff"]=$first?"On":"";
 
         if (empty($_GET["fOnlyOff"]))
             $_GET["fOnlyOff"]=$first?"Off":"";
 
-        if (empty($_GET["fArrTimeLimitMean"]))
-            $_GET["fArrTimeLimitMean"]="";
-
-        if (empty($_GET["fArrTimeLimitRms"]))
-            $_GET["fArrTimeLimitRms"]="";
-
-        if (empty($_GET["fPedRmsInLimitMean"]))
-            $_GET["fPedRmsInLimitMean"]="";
-
-        if (empty($_GET["fPedRmsInLimitRms"]))
-            $_GET["fPedRmsInLimitRms"]="";
-
-        if (empty($_GET["fMuonRateLimitMean"]))
-            $_GET["fMuonRateLimitMean"]="";
-
-        if (empty($_GET["fMuonRateLimitRms"]))
-            $_GET["fMuonRateLimitRms"]="";
-
-        if (empty($_GET["fImgRateLimitMean"]))
-            $_GET["fImgRateLimitMean"]="";
-
-        if (empty($_GET["fImgRateLimitRms"]))
-            $_GET["fImgRateLimitRms"]="";
-
-        if (empty($_GET["fPSFLimitMean"]))
-            $_GET["fPSFLimitMean"]="";
-
-        if (empty($_GET["fPSFLimitRms"]))
-            $_GET["fPSFLimitRms"]="";
-
-        if (empty($_GET["fUnsInLimitMean"]))
-            $_GET["fUnsInLimitMean"]="";
-
-        if (empty($_GET["fZdMinLimitMean"]))
-            $_GET["fZdMinLimitMean"]="";
-
-        if (empty($_GET["fZdMaxLimitMean"]))
-            $_GET["fZdMaxLimitMean"]="";
-
-        if (empty($_GET["fAzimuthMin"]))
-            $_GET["fAzimuthMin"]="Off";
-
-        if (empty($_GET["fAzimuthMax"]))
-            $_GET["fAzimuthMax"]="Off";
-
         if (empty($_GET["fZenithDistanceMin"]))
             $_GET["fZenithDistanceMin"]=$first?"On":"";
@@ -306,76 +250,25 @@
             $_GET["fSourceName"]="On";
 
-        if (empty($_GET["fManuallyChangedName"]))
-            $_GET["fManuallyChangedName"]="Off";
-
         if (empty($_GET["fLightConditionsName"]))
             $_GET["fLightConditionsName"]=$first?"On":"";
 
-        if (empty($_GET["fDiscriminatorThresholdTableName"]))
-            $_GET["fDiscriminatorThresholdTableName"]="Off";
-
-        if (empty($_GET["fStar"]))
-            $_GET["fStar"]="Off";
-
         if (empty($_GET["fStarStatus"]))
             $_GET["fStarStatus"]=$first?"1":"";
 
-        if (empty($_GET["fUnreliableInner"]))
-            $_GET["fUnreliableInner"]="Off";
-
-        if (empty($_GET["fUnsuitableOuter"]))
-            $_GET["fUnsuitableOuter"]="Off";
-
-        if (empty($_GET["fUnreliableOuter"]))
-            $_GET["fUnreliableOuter"]="Off";
-
         if (empty($_GET["fUnsuitableInner"]))
             $_GET["fUnsuitableInner"]=$first?"On":"";
 
-        if (empty($_GET["fIsolatedInner"]))
-            $_GET["fIsolatedInner"]="Off";
-
-        if (empty($_GET["fIsolatedOuter"]))
-            $_GET["fIsolatedOuter"]="Off";
-
         if (empty($_GET["fMeanPedRmsInner"]))
             $_GET["fMeanPedRmsInner"]=$first?"On":"";
 
-        if (empty($_GET["fMeanPedRmsOuter"]))
-            $_GET["fMeanPedRmsOuter"]="Off";
-
-        if (empty($_GET["fIsolatedMaxCluster"]))
-            $_GET["fIsolatedMaxCluster"]="Off";
-
-        if (empty($_GET["fArrTimeMeanInner"]))
-            $_GET["fArrTimeMeanInner"]="Off";
-
-        if (empty($_GET["fArrTimeMeanOuter"]))
-            $_GET["fArrTimeMeanOuter"]="Off";
-
         if (empty($_GET["fArrTimeRmsInner"]))
             $_GET["fArrTimeRmsInner"]=$first?"On":"";
 
-        if (empty($_GET["fArrTimeRmsOuter"]))
-            $_GET["fArrTimeRmsOuter"]="Off";
-
         if (empty($_GET["fConvFactorInner"]))
             $_GET["fConvFactorInner"]=$first?"On":"";
 
-        if (empty($_GET["fConvFactorOuter"]))
-            $_GET["fConvFactorOuter"]="Off";
-
-        if (empty($_GET["fMeanNumberIslands"]))
-            $_GET["fMeanNumberIslands"]="Off";
-
         if (empty($_GET["fPSF"]))
             $_GET["fPSF"]=$first?"On":"";
 
-        if (empty($_GET["fRatio"]))
-            $_GET["fRatio"]="Off";
-
-        if (empty($_GET["fMuonNumber"]))
-            $_GET["fMuonNumber"]="Off";
-
         if (empty($_GET["fEffOnTime"]))
             $_GET["fEffOnTime"]=$first?"On":"";
@@ -388,15 +281,13 @@
 
         if (empty($_GET["fInhomogeneity"]))
-            $_GET["fInhomogeneity"]="Off";
+            $_GET["fInhomogeneity"]="On";
 
         if (empty($_GET["fDataRate"]))
             $_GET["fDataRate"]=$first?"On":"";
 
-        if (empty($_GET["fMaxHumidity"]))
-            $_GET["fMaxHumidity"]="Off";
-
-    }
-
-    function PrintForm($_GET, $host, $user, $pw, $db, $limits, $rms, $alias)
+        InitFindOffData($_GET);
+    }
+
+    function PrintForm($_GET, $host, $user, $pw, $db, $limitsmean, $limitsmin, $limitsmax, $alias)
     {
         printf("<center>\n");
@@ -404,89 +295,14 @@
 
         printf(" <table>\n");
-        printf("  <tr><td align='center'>\n");
-
-
-        printf(" <table>\n");
-        printf("  <tr>\n");
-
-        CheckBox("fRunStart",          "Start time");
-        CheckBox("fSequenceLast",      "Last run");
-        CheckBox("fZenithDistanceMin", "Zd min");
-        CheckBox("fZenithDistanceMax", "Zd max");
-
-        printf("  </tr><tr>\n");
-
-        CheckBox("fNumEvents",         "Num of events");
-        CheckBox("fRunTime/60",        "Duration");
-        CheckBox("fAzimuthMin",        "Azimuth min");
-        CheckBox("fAzimuthMax",        "Azimuth max");
-//        CheckBox("fLinks",             "Links");
-/*
-        printf("  </tr></table>\n");
+        printf("  <tr><td align='center' valign='top'>\n");
+
+        PrintSequInfoMenu();
         printf(" <p>\n");
-        printf(" <table>\n");
-        printf("  <tr>\n");
-*/
-
-        printf("  </tr><tr>\n");
-
-        CheckBox("fUnsuitableInner",     "Unsuitable inner");
-        CheckBox("fUnsuitableOuter",     "Unsuitable outer");
-        CheckBox("fUnreliableInner",     "Unreliable inner");
-        CheckBox("fUnreliableOuter",     "Unreliable outer");
-
-        printf("  </tr><tr>\n");
-
-        CheckBox("fIsolatedInner",       "Isolated inner");
-        CheckBox("fIsolatedOuter",       "Isolated outer");
-        CheckBox("fIsolatedMaxCluster",  "IsolatedMaxCl.");
-        CheckBox("fMaxHumidity",        "MaxHumidity");
-
-        printf("  </tr><tr>\n");
-
-        CheckBox("fArrTimeMeanInner",    "ArrTimeMean in");
-        CheckBox("fArrTimeMeanOuter",    "ArrTimeMean out");
-        CheckBox("fArrTimeRmsInner",     "ArrTimeRms in");
-        CheckBox("fArrTimeRmsOuter",     "ArrTimeRms out");
-
-        printf("  </tr><tr>\n");
-
-        CheckBox("fConvFactorInner",     "Conv inner ");
-        CheckBox("fConvFactorOuter",     "Conv outer ");
-        CheckBox("fMeanPedRmsInner",     "MeanPedRms in");
-        CheckBox("fMeanPedRmsOuter",     "MeanPedRms out");
-
-/*
-        printf(" </tr></table>\n");
+        PrintCalMenu();
         printf(" <p>\n");
-
-        printf(" <table>\n");
-        printf("  <tr>\n");
-*/
-
-        printf("  </tr><tr>\n");
-
-        CheckBox("fMeanNumberIslands",  "MeanNumIslands");
-        CheckBox("fPSF",                "PSF");
-        CheckBox("fRatio",              "Ratio");
-        CheckBox("fMuonRate",           "MuonRate");
-
-        printf("  </tr><tr>\n");
-
-        CheckBox("fMuonNumber",         "MuonNumber");
-        CheckBox("fEffOnTime",          "EffOnTime");
-        CheckBox("fEffOnTime/fRunTime", "RelOnTime");
-        CheckBox("fDataRate",           "CleanedEvtRate");
-
-        printf("  </tr><tr>\n");
-
-        CheckBox("fInhomogeneity",      "Inhomogeneity");
-
-        printf("  </tr>\n");
-        printf(" </table>\n");
+        PrintStarMenu();
         printf(" <p>\n");
 
         printf(" <table><tr><td>\n");
-
         PrintPullDown($host, $user, $pw, $db, "Source",                      "fSourceName",                      "fSourceKEY",                      "Source Name");
         printf("  </td><td>\n");
@@ -498,22 +314,9 @@
         printf("  </td><td>\n");
         PrintStatusMenu("fStar",                "Star");
-
         printf("</td></tr> </table>\n");
         printf(" <p>\n");
 
-        printf("  </td><td valign='top'>\n");
-
-        printf("  <table>\n");
-        printf("  <tr><th colspan='3'>Limits</th><tr>\n");
-        printf("  <tr><td>Name </td><td> Mean </td><td> Rms </td></tr>\n");
-        PrintLimitsMenu($limits, $rms, $alias);
-        printf("  </td></tr></table>\n");
-
-        printf("  </td></tr><tr><td colspan='2' align='center'>\n");
-
-        printf(" <p>\n");
-
         printf(" <table>\n");
-        printf("  <tr><td>\n");
+        printf("  <tr><td colspan='3'>\n");
 
         if (empty($_GET["fStarStart"]))
@@ -529,5 +332,6 @@
         printf("StarDone&nbsp;(yyyy-mm-dd)&nbsp;from&nbsp;<input name=\"fStarStart\" type=\"text\" size=\"10\" maxlength=\"10\" value=\"%s\">\n", $starmin);
         printf("to&nbsp;<input name=\"fStarStop\" type=\"text\" size=\"10\" maxlength=\"10\" value=\"%s\">&nbsp;&nbsp;&nbsp;&nbsp;\n", $starmax);
-        printf("  </td>\n");
+        printf("  </td></tr><tr><td><br></td></tr><tr>\n");
+
         CheckBox("fLinks",    "Links");
         CheckBox("fOff",      "incl. offsources");
@@ -536,45 +340,15 @@
         printf("  </tr>\n");
         printf(" </table>\n");
+
         printf(" <p>\n");
 
-        if (empty($_GET["fStartDate"]))
-            $timemin = GetMin("fRunStart", "Sequences", $host, $user, $pw, $db);
-        else
-            $timemin = $_GET["fStartDate"];
-
-        if (empty($_GET["fStopDate"]))
-            $timemax = GetMax("fRunStart", "Sequences", $host, $user, $pw, $db);
-        else
-            $timemax = $_GET["fStopDate"];
-
-        printf("Night&nbsp;(yyyy-mm-dd)&nbsp;from&nbsp;<input name=\"fStartDate\" type=\"text\" size=\"10\" maxlength=\"10\" value=\"%s\">\n", $timemin);
-        printf("to&nbsp;<input name=\"fStopDate\" type=\"text\" size=\"10\" maxlength=\"10\" value=\"%s\">&nbsp;&nbsp;&nbsp;&nbsp;\n", $timemax);
-
-        if (empty($_GET["fRunMin"]))
-            $min = GetMin("fSequenceFirst", "Sequences", $host, $user, $pw, $db);
-        else
-            $min = $_GET["fRunMin"];
-
-        if (empty($_GET["fRunMax"]))
-            $max = GetMax("fSequenceFirst", "Sequences", $host, $user, $pw, $db);
-        else
-            $max = $_GET["fRunMax"];
-
-/*
-        printf("Date&nbsp;(yyyy-mm-dd)&nbsp;<input name=\"fDate\" type=\"text\" size=\"10\" maxlength=\"10\" value=\"");
-        if (!empty($_GET["fDate"]))
-            printf("%s", $_GET["fDate"]);
-        printf("\">&nbsp;&nbsp;&nbsp;\n");
-*/
-
-        printf("Sequences&nbsp;from&nbsp;<input name=\"fRunMin\" type=\"text\" size=\"6\" maxlength=\"6\" value=\"%s\">\n", $min);
-        printf("to&nbsp;<input name=\"fRunMax\" type=\"text\" size=\"6\" maxlength=\"6\" value=\"%s\">&nbsp;&nbsp;&nbsp;\n", $max);
-
-        printf(" <P>\n");
-
-        printf("Source&nbsp;(<A HREF=\"regexp.html\">regexp</A>)&nbsp;<input name=\"fSourceN\" type=\"text\" size=\"15\" maxlength=\"15\" value=\"");
-        if (!empty($_GET["fSourceN"]))
-            printf("%s", $_GET["fSourceN"]);
-        printf("\">&nbsp;&nbsp;&nbsp;\n");
+        PrintZdRangeMenu($host,$user,$pw,$db);
+        printf("<p>\n");
+        PrintSequRangeMenu($host,$user,$pw,$db);
+        printf("<p>\n");
+        PrintSourceMenu($host,$user,$pw,$db);
+        printf("<p>\n");
+        PrintNightRangeMenu($host,$user,$pw,$db);
+        printf("<p>\n");
 
         printf(" Results:\n");
@@ -591,7 +365,4 @@
         printf(" </select>\n");
         printf(" &nbsp;&nbsp;&nbsp;\n");
-
-        ini_set("mysql.trace_mode", "Off");
-        ini_set("display_errors", "Off");
 
         printf("<input class='Width' type='submit' value='Query Table'>&nbsp;&nbsp;&nbsp;\n");
@@ -601,9 +372,19 @@
         if (strchr($_SERVER["REQUEST_URI"], '?')!=FALSE)
             printf("<input class='Width' type='button' value='Print' onClick='self.location.href=\"%s&fPrintTable=1\"'>&nbsp;&nbsp;&nbsp;\n", $_SERVER["REQUEST_URI"]);
+
+        printf("  </td><td valign='top'>\n");
+
+        PrintLimitsMenu($limitsmean, $limitsmin, $limitsmax, $alias, "yes");
+
+        printf("  </td></tr>\n");
+        printf(" </table>\n");
+
         printf("</form>\n");
         printf("</center>\n");
 
 
-        printf("  </td></tr> </table>\n");
+        ini_set("mysql.trace_mode", "Off");
+        ini_set("display_errors", "Off");
+
 
         printf("</td>\n");
@@ -615,5 +396,5 @@
     }
 
-    function PrintPage($html, $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $limits, $rms, $needs)
+    function PrintPage($html, $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $limitsmean, $limitsmin, $limitsmax, $needs)
     {
         $db_id = mysql_connect($host, $user, $pw);
@@ -632,5 +413,5 @@
         {
             if ($html=="1" || $html=="2")
-                PrintMagicTable($result0, $alias, $rightalign, $limits, $rms, $_GET);
+                PrintMagicTable($result0, $alias, $rightalign, $limitsmean, $limitsmin, $limitsmax, $_GET);
             else
                 PrintText($result0);
@@ -640,9 +421,9 @@
         mysql_close($db_id);
 
-        if ($html=="1")
-            printf("<U><B>submitted query:</B></U><BR>%s<BR>", htmlspecialchars($query0));
+        PrintSubmittedQuery($query0, $html, $db, "old");
     }
 
     include ("include.php");
+    include ("menu.php");
     include ("db.php");
     include ("magicdefs.php");
@@ -656,5 +437,5 @@
         header("Content-Disposition: attachment; filename=query-result.txt");
 
-        PrintPage("0", $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $limits, $rms, $needs);
+        PrintPage("0", $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $limitsmean, $limitsmin, $limitsmax, $needs);
     }
     else
@@ -666,5 +447,5 @@
         InitGet($_GET);
         if (empty($_GET["fPrintTable"]))
-            PrintForm($_GET, $host, $user, $pw, $db, $limits, $rms, $alias);
+            PrintForm($_GET, $host, $user, $pw, $db, $limitsmean, $limitsmin, $limitsmax, $alias);
 
         if ($environment==0)
@@ -673,7 +454,7 @@
         {
             if (empty($_GET["fPrintTable"]))
-                PrintPage("1", $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $limits, $rms, $needs);
-            else
-                PrintPage("2", $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $limits, $rms, $needs);
+                PrintPage("1", $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $limitsmean, $limitsmin, $limitsmax, $needs);
+            else
+                PrintPage("2", $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $limitsmean, $limitsmin, $limitsmax, $needs);
         }
 
