| 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["fDataRate"]))
|
|---|
| 67 | $_GET["fDataRate"]=$first?"On":"";
|
|---|
| 68 |
|
|---|
| 69 | if (empty($_GET["fMaxHumidity"]))
|
|---|
| 70 | $_GET["fMaxHumidity"]=$first?"On":"";
|
|---|
| 71 |
|
|---|
| 72 | }
|
|---|
| 73 |
|
|---|
| 74 | function PrintForm($_GET, $db)
|
|---|
| 75 | {
|
|---|
| 76 | printf("<center>\n");
|
|---|
| 77 | printf("<form action=\"querystar.php\" METHOD=\"GET\">\n");
|
|---|
| 78 | printf(" <table>\n");
|
|---|
| 79 | printf(" <tr>\n");
|
|---|
| 80 |
|
|---|
| 81 | CheckBox("fMeanNumberIslands", "MeanNumIslands");
|
|---|
| 82 | CheckBox("fPSF", "PSF");
|
|---|
| 83 | CheckBox("fRatio", "Ratio");
|
|---|
| 84 | CheckBox("fMuonRate", "MuonRate");
|
|---|
| 85 |
|
|---|
| 86 | printf(" </tr><tr>\n");
|
|---|
| 87 |
|
|---|
| 88 | CheckBox("fMuonNumber", "MuonNumber");
|
|---|
| 89 | CheckBox("fEffOnTime", "EffOnTime");
|
|---|
| 90 | CheckBox("fMaxHumidity", "MaxHumidity");
|
|---|
| 91 | CheckBox("fDataRate", "CleanedEvtRate");
|
|---|
| 92 |
|
|---|
| 93 | printf(" </tr>\n");
|
|---|
| 94 | printf(" </table>\n");
|
|---|
| 95 | printf(" <p>\n");
|
|---|
| 96 |
|
|---|
| 97 | if (empty($_GET["fRunMin"]))
|
|---|
| 98 | $min = GetMin("fSequenceFirst", "Sequences", $db);
|
|---|
| 99 | else
|
|---|
| 100 | $min = $_GET["fRunMin"];
|
|---|
| 101 |
|
|---|
| 102 | if (empty($_GET["fRunMax"]))
|
|---|
| 103 | $max = GetMax("fSequenceFirst", "Sequences", $db);
|
|---|
| 104 | else
|
|---|
| 105 | $max = $_GET["fRunMax"];
|
|---|
| 106 |
|
|---|
| 107 |
|
|---|
| 108 | printf("Sequences from <input name=\"fRunMin\" type=\"text\" size=\"6\" maxlength=\"6\" value=\"%s\">\n", $min);
|
|---|
| 109 | printf("to <input name=\"fRunMax\" type=\"text\" size=\"6\" maxlength=\"6\" value=\"%s\"> \n", $max);
|
|---|
| 110 |
|
|---|
| 111 | printf(" <P>\n");
|
|---|
| 112 |
|
|---|
| 113 | printf(" Results:\n");
|
|---|
| 114 | printf(" <select name=\"fNumResults\">\n");
|
|---|
| 115 |
|
|---|
| 116 | $numres = array("10", "20", "50", "100", "200", "500");
|
|---|
| 117 | foreach ($numres as $element)
|
|---|
| 118 | {
|
|---|
| 119 | if ($element==$_GET["fNumResults"])
|
|---|
| 120 | printf("<option value=\"%s\" selected>%3s</option>\n", $element, $element);
|
|---|
| 121 | else
|
|---|
| 122 | printf("<option value=\"%s\">%3s</option>\n", $element, $element);
|
|---|
| 123 | }
|
|---|
| 124 | printf(" </select>\n");
|
|---|
| 125 | printf(" \n");
|
|---|
| 126 |
|
|---|
| 127 | ini_set("mysql.trace_mode", "Off");
|
|---|
| 128 | ini_set("display_errors", "Off");
|
|---|
| 129 |
|
|---|
| 130 | printf("<input class='Width' type='submit' value='Query Table'> \n");
|
|---|
| 131 | printf("<input class='Width' type='button' value='Reset' onClick='self.location.href=\"querystar.php\"'> \n");
|
|---|
| 132 | if (strchr($_SERVER["REQUEST_URI"], '?')!=FALSE)
|
|---|
| 133 | printf("<input class='Width' type='button' value='Get .txt' onClick='self.location.href=\"%s&fSendTxt=1\"'> \n", $_SERVER["REQUEST_URI"]);
|
|---|
| 134 | printf("</form>\n");
|
|---|
| 135 | printf("</center>\n");
|
|---|
| 136 | printf("</td>\n");
|
|---|
| 137 | printf("</tr>\n");
|
|---|
| 138 | printf("<tr class='Block'>\n");
|
|---|
| 139 | printf("<td>\n");
|
|---|
| 140 | }
|
|---|
| 141 |
|
|---|
| 142 | function PrintPage($html, $db, $alias, $rightalign, $checkwhere)
|
|---|
| 143 | {
|
|---|
| 144 | $db_id = mysql_connect("hercules.astro.uni-wuerzburg.de", "MAGIC", "d99swMT!");
|
|---|
| 145 | if ($db_id==FALSE)
|
|---|
| 146 | {
|
|---|
| 147 | printf("mysql_connect returned the following error: %s\n", mysql_error());
|
|---|
| 148 | die("");
|
|---|
| 149 | }
|
|---|
| 150 | mysql_select_db($db);
|
|---|
| 151 |
|
|---|
| 152 | $query0 = CreateQuery($_GET, $alias, $checkwhere);
|
|---|
| 153 |
|
|---|
| 154 | $result0 = mysql_query($query0, $db_id);
|
|---|
| 155 |
|
|---|
| 156 | if ($result0)
|
|---|
| 157 | {
|
|---|
| 158 | if ($html=="1")
|
|---|
| 159 | PrintMagicTable($result0, $alias, $rightalign, "", "", $_GET);
|
|---|
| 160 | else
|
|---|
| 161 | PrintText($result0);
|
|---|
| 162 |
|
|---|
| 163 | mysql_free_result($result0);
|
|---|
| 164 | }
|
|---|
| 165 | mysql_close($db_id);
|
|---|
| 166 |
|
|---|
| 167 | if ($html=="1")
|
|---|
| 168 | printf("<U><B>submitted query:</B></U><BR>%s<BR>", htmlspecialchars($query0));
|
|---|
| 169 | }
|
|---|
| 170 |
|
|---|
| 171 | include ("include.php");
|
|---|
| 172 | include ("db.php");
|
|---|
| 173 | include ("magicdefs.php");
|
|---|
| 174 |
|
|---|
| 175 | ini_set("display_errors", "On");
|
|---|
| 176 | ini_set("mysql.trace_mode", "On");
|
|---|
| 177 |
|
|---|
| 178 | if (!empty($_GET["fSendTxt"]))
|
|---|
| 179 | {
|
|---|
| 180 | header("Content-type: application/octet");
|
|---|
| 181 | header("Content-Disposition: attachment; filename=query-result.txt");
|
|---|
| 182 |
|
|---|
| 183 | PrintPage("0", $db, $alias, $rightalign, $checkwhere);
|
|---|
| 184 | }
|
|---|
| 185 | else
|
|---|
| 186 | {
|
|---|
| 187 | echo (file_get_contents("index-header.html"));
|
|---|
| 188 |
|
|---|
| 189 | $environment = sizeof($_GET);
|
|---|
| 190 |
|
|---|
| 191 | InitGet($_GET);
|
|---|
| 192 | PrintForm($_GET, $db);
|
|---|
| 193 |
|
|---|
| 194 | if ($environment==0)
|
|---|
| 195 | printf("No query submitted yet.<BR>");
|
|---|
| 196 | else
|
|---|
| 197 | PrintPage("1", $db, $alias, $rightalign, $checkwhere);
|
|---|
| 198 |
|
|---|
| 199 | echo (file_get_contents("index-footer.html"));
|
|---|
| 200 | }
|
|---|
| 201 |
|
|---|
| 202 | ini_set("display_errors", "Off");
|
|---|
| 203 | ini_set("mysql.trace_mode", "Off");
|
|---|
| 204 | }
|
|---|
| 205 | ?>
|
|---|