| 1 | <?php | 
|---|
| 2 | { | 
|---|
| 3 | function CreateQuery($_GET, $alias, $checkwhere) | 
|---|
| 4 | { | 
|---|
| 5 | $query0 = "SELECT fSequenceFirst as 'Sequence#' "; | 
|---|
| 6 |  | 
|---|
| 7 | foreach ($_GET as $key => $element) | 
|---|
| 8 | if ($_GET[$key]=="On") | 
|---|
| 9 | if (empty($checkwhere[$key]) || $checkwhere[$key]==0) | 
|---|
| 10 | $query0 .= ", " . $key . " as '" . $alias[$key] . "' "; | 
|---|
| 11 |  | 
|---|
| 12 | $query0 .= " FROM Star "; | 
|---|
| 13 |  | 
|---|
| 14 | if (strpos($query0, " WHERE ")==FALSE) | 
|---|
| 15 | $query0 .= " WHERE "; | 
|---|
| 16 | else | 
|---|
| 17 | $query0 .= " AND "; | 
|---|
| 18 |  | 
|---|
| 19 | $query0 .= "fSequenceFirst BETWEEN " . $_GET["fRunMin"] . " AND " . $_GET["fRunMax"] . " "; | 
|---|
| 20 |  | 
|---|
| 21 | if (!empty($_GET["fSortBy"])) | 
|---|
| 22 | { | 
|---|
| 23 | $query0 .= " ORDER BY " . substr($_GET["fSortBy"], 0, -1) . " "; | 
|---|
| 24 | if (substr($_GET["fSortBy"], -1)=="-") | 
|---|
| 25 | $query0 .= "DESC"; | 
|---|
| 26 | } | 
|---|
| 27 |  | 
|---|
| 28 | if (empty($_GET["fNumStart"])) | 
|---|
| 29 | $_GET["fNumStart"]=0; | 
|---|
| 30 |  | 
|---|
| 31 | if (empty($_GET["fSendTxt"])) | 
|---|
| 32 | $query0 .= " LIMIT " . $_GET["fNumStart"] . ", " . $_GET["fNumResults"]; | 
|---|
| 33 |  | 
|---|
| 34 | return $query0; | 
|---|
| 35 | } | 
|---|
| 36 |  | 
|---|
| 37 | function InitGet($_GET) | 
|---|
| 38 | { | 
|---|
| 39 | // Find out whether it is the first call to the php script | 
|---|
| 40 | $first = empty($_GET["fRunMin"]) && empty($_GET["fRunMax"]); | 
|---|
| 41 |  | 
|---|
| 42 | if (empty($_GET["fNumResults"])) | 
|---|
| 43 | $_GET["fNumResults"]="20"; | 
|---|
| 44 |  | 
|---|
| 45 | if (empty($_GET["fLastUpdate"])) | 
|---|
| 46 | $_GET["fLastUpdate"]="Off"; | 
|---|
| 47 |  | 
|---|
| 48 | if (empty($_GET["fMeanNumberIslands"])) | 
|---|
| 49 | $_GET["fMeanNumberIslands"]=$first?"On":""; | 
|---|
| 50 |  | 
|---|
| 51 | if (empty($_GET["fPSF"])) | 
|---|
| 52 | $_GET["fPSF"]=$first?"On":""; | 
|---|
| 53 |  | 
|---|
| 54 | if (empty($_GET["fRatio"])) | 
|---|
| 55 | $_GET["fRatio"]=$first?"On":""; | 
|---|
| 56 |  | 
|---|
| 57 | if (empty($_GET["fMuonNumber"])) | 
|---|
| 58 | $_GET["fMuonNumber"]=$first?"On":""; | 
|---|
| 59 |  | 
|---|
| 60 | if (empty($_GET["fEffOnTime"])) | 
|---|
| 61 | $_GET["fEffOnTime"]=$first?"On":""; | 
|---|
| 62 |  | 
|---|
| 63 | if (empty($_GET["fMuonRate"])) | 
|---|
| 64 | $_GET["fMuonRate"]=$first?"On":""; | 
|---|
| 65 |  | 
|---|
| 66 | if (empty($_GET["fInhomogeneity"])) | 
|---|
| 67 | $_GET["fInhomogeneity"]=$first?"On":""; | 
|---|
| 68 |  | 
|---|
| 69 | if (empty($_GET["fDataRate"])) | 
|---|
| 70 | $_GET["fDataRate"]=$first?"On":""; | 
|---|
| 71 |  | 
|---|
| 72 | if (empty($_GET["fMaxHumidity"])) | 
|---|
| 73 | $_GET["fMaxHumidity"]=$first?"On":""; | 
|---|
| 74 |  | 
|---|
| 75 | } | 
|---|
| 76 |  | 
|---|
| 77 | function PrintForm($_GET, $host, $user, $pw, $db) | 
|---|
| 78 | { | 
|---|
| 79 | printf("<center>\n"); | 
|---|
| 80 | printf("<form action=\"querystar.php\" METHOD=\"GET\">\n"); | 
|---|
| 81 | printf(" <table>\n"); | 
|---|
| 82 | printf("  <tr>\n"); | 
|---|
| 83 |  | 
|---|
| 84 | CheckBox("fMeanNumberIslands",  "MeanNumIslands"); | 
|---|
| 85 | CheckBox("fPSF",                "PSF"); | 
|---|
| 86 | CheckBox("fRatio",              "Ratio"); | 
|---|
| 87 |  | 
|---|
| 88 | printf("  </tr><tr>\n"); | 
|---|
| 89 |  | 
|---|
| 90 | CheckBox("fMuonRate",           "MuonRate"); | 
|---|
| 91 | CheckBox("fMuonNumber",         "MuonNumber"); | 
|---|
| 92 | CheckBox("fEffOnTime",          "EffOnTime"); | 
|---|
| 93 |  | 
|---|
| 94 | printf("  </tr><tr>\n"); | 
|---|
| 95 |  | 
|---|
| 96 | CheckBox("fMaxHumidity",        "MaxHumidity"); | 
|---|
| 97 | CheckBox("fDataRate",           "CleanedEvtRate"); | 
|---|
| 98 | CheckBox("fInhomogeneity",      "Inhomogeneity"); | 
|---|
| 99 |  | 
|---|
| 100 | printf("  </tr>\n"); | 
|---|
| 101 | printf(" </table>\n"); | 
|---|
| 102 | printf(" <p>\n"); | 
|---|
| 103 |  | 
|---|
| 104 | if (empty($_GET["fRunMin"])) | 
|---|
| 105 | $min = GetMin("fSequenceFirst", "Sequences", $host, $user, $pw, $db); | 
|---|
| 106 | else | 
|---|
| 107 | $min = $_GET["fRunMin"]; | 
|---|
| 108 |  | 
|---|
| 109 | if (empty($_GET["fRunMax"])) | 
|---|
| 110 | $max = GetMax("fSequenceFirst", "Sequences", $host, $user, $pw, $db); | 
|---|
| 111 | else | 
|---|
| 112 | $max = $_GET["fRunMax"]; | 
|---|
| 113 |  | 
|---|
| 114 |  | 
|---|
| 115 | printf("Sequences from <input name=\"fRunMin\" type=\"text\" size=\"6\" maxlength=\"6\" value=\"%s\">\n", $min); | 
|---|
| 116 | printf("to <input name=\"fRunMax\" type=\"text\" size=\"6\" maxlength=\"6\" value=\"%s\">   \n", $max); | 
|---|
| 117 |  | 
|---|
| 118 | printf(" <P>\n"); | 
|---|
| 119 |  | 
|---|
| 120 | printf(" Results:\n"); | 
|---|
| 121 | printf(" <select name=\"fNumResults\">\n"); | 
|---|
| 122 |  | 
|---|
| 123 | $numres = array("10", "20", "50", "100", "200", "500"); | 
|---|
| 124 | foreach ($numres as $element) | 
|---|
| 125 | { | 
|---|
| 126 | if ($element==$_GET["fNumResults"]) | 
|---|
| 127 | printf("<option value=\"%s\" selected>%3s</option>\n", $element, $element); | 
|---|
| 128 | else | 
|---|
| 129 | printf("<option value=\"%s\">%3s</option>\n", $element, $element); | 
|---|
| 130 | } | 
|---|
| 131 | printf(" </select>\n"); | 
|---|
| 132 | printf("    \n"); | 
|---|
| 133 |  | 
|---|
| 134 | ini_set("mysql.trace_mode", "Off"); | 
|---|
| 135 | ini_set("display_errors", "Off"); | 
|---|
| 136 |  | 
|---|
| 137 | printf("<input class='Width' type='submit' value='Query Table'>   \n"); | 
|---|
| 138 | printf("<input class='Width' type='button' value='Reset' onClick='self.location.href=\"querystar.php\"'>   \n"); | 
|---|
| 139 | if (strchr($_SERVER["REQUEST_URI"], '?')!=FALSE) | 
|---|
| 140 | printf("<input class='Width' type='button' value='Get .txt' onClick='self.location.href=\"%s&fSendTxt=1\"'>   \n", $_SERVER["REQUEST_URI"]); | 
|---|
| 141 | printf("</form>\n"); | 
|---|
| 142 | printf("</center>\n"); | 
|---|
| 143 | printf("</td>\n"); | 
|---|
| 144 | printf("</tr>\n"); | 
|---|
| 145 | printf("<tr class='Block'>\n"); | 
|---|
| 146 | printf("<td>\n"); | 
|---|
| 147 | } | 
|---|
| 148 |  | 
|---|
| 149 | function PrintPage($html, $host, $user, $pw, $db, $alias, $rightalign, $checkwhere) | 
|---|
| 150 | { | 
|---|
| 151 | $db_id = mysql_connect($host, $user, $pw); | 
|---|
| 152 | if ($db_id==FALSE) | 
|---|
| 153 | { | 
|---|
| 154 | printf("mysql_connect returned the following error: %s\n", mysql_error()); | 
|---|
| 155 | die(""); | 
|---|
| 156 | } | 
|---|
| 157 | mysql_select_db($db); | 
|---|
| 158 |  | 
|---|
| 159 | $query0 = CreateQuery($_GET, $alias, $checkwhere); | 
|---|
| 160 |  | 
|---|
| 161 | $result0 = mysql_query($query0, $db_id); | 
|---|
| 162 |  | 
|---|
| 163 | if ($result0) | 
|---|
| 164 | { | 
|---|
| 165 | if ($html=="1") | 
|---|
| 166 | PrintMagicTable($result0, $alias, $rightalign, "", "", "", $_GET); | 
|---|
| 167 | else | 
|---|
| 168 | PrintText($result0); | 
|---|
| 169 |  | 
|---|
| 170 | mysql_free_result($result0); | 
|---|
| 171 | } | 
|---|
| 172 | mysql_close($db_id); | 
|---|
| 173 |  | 
|---|
| 174 | PrintSubmittedQuery($query0, $html, $db, "old"); | 
|---|
| 175 | } | 
|---|
| 176 |  | 
|---|
| 177 | include ("include.php"); | 
|---|
| 178 | include ("db.php"); | 
|---|
| 179 | include ("magicdefs.php"); | 
|---|
| 180 |  | 
|---|
| 181 | ini_set("display_errors", "On"); | 
|---|
| 182 | ini_set("mysql.trace_mode", "On"); | 
|---|
| 183 |  | 
|---|
| 184 | if (!empty($_GET["fSendTxt"])) | 
|---|
| 185 | { | 
|---|
| 186 | header("Content-type: application/octet"); | 
|---|
| 187 | header("Content-Disposition: attachment; filename=query-result.txt"); | 
|---|
| 188 |  | 
|---|
| 189 | PrintPage("0", $host, $user, $pw, $db, $alias, $rightalign, $checkwhere); | 
|---|
| 190 | } | 
|---|
| 191 | else | 
|---|
| 192 | { | 
|---|
| 193 | echo (file_get_contents("index-header.html")); | 
|---|
| 194 |  | 
|---|
| 195 | $environment = sizeof($_GET); | 
|---|
| 196 |  | 
|---|
| 197 | InitGet($_GET); | 
|---|
| 198 | PrintForm($_GET, $host, $user, $pw, $db); | 
|---|
| 199 |  | 
|---|
| 200 | if ($environment==0) | 
|---|
| 201 | printf("No query submitted yet.<BR>"); | 
|---|
| 202 | else | 
|---|
| 203 | PrintPage("1", $host, $user, $pw, $db, $alias, $rightalign, $checkwhere); | 
|---|
| 204 |  | 
|---|
| 205 | echo (file_get_contents("index-footer.html")); | 
|---|
| 206 | } | 
|---|
| 207 |  | 
|---|
| 208 | ini_set("display_errors", "Off"); | 
|---|
| 209 | ini_set("mysql.trace_mode", "Off"); | 
|---|
| 210 | } | 
|---|
| 211 | ?> | 
|---|