| 1 | <?php
|
|---|
| 2 | {
|
|---|
| 3 | function CreateQuery($_GET, $alias, $checkwhere, $checkgroup, $checkstatusgroup)
|
|---|
| 4 | {
|
|---|
| 5 | $fromtable="OpticalData";
|
|---|
| 6 |
|
|---|
| 7 | $groups = 0;
|
|---|
| 8 | foreach ($checkgroup as $element)
|
|---|
| 9 | if ($element==-1)
|
|---|
| 10 | $groups++;
|
|---|
| 11 |
|
|---|
| 12 | $query0 = "SELECT ";
|
|---|
| 13 |
|
|---|
| 14 | if ($groups>0)
|
|---|
| 15 | {
|
|---|
| 16 | foreach ($checkgroup as $key => $element)
|
|---|
| 17 | if ($element==-1)
|
|---|
| 18 | $query0 .= $key . " as '" . $alias[$key] . "' " . ", ";
|
|---|
| 19 | $query0 .= " COUNT(*) as '# Runs' ";
|
|---|
| 20 | }
|
|---|
| 21 | else
|
|---|
| 22 | {
|
|---|
| 23 | $query0 .= " fTimeStamp as 'Time' ";
|
|---|
| 24 |
|
|---|
| 25 | foreach ($_GET as $key => $element)
|
|---|
| 26 | if ($_GET[$key]=="On")
|
|---|
| 27 | if (empty($checkwhere[$key]) || $checkwhere[$key]==0)
|
|---|
| 28 | $query0 .= ", " . $key . " as '" . $alias[$key] . "' ";
|
|---|
| 29 | }
|
|---|
| 30 |
|
|---|
| 31 | $query0 .= " FROM " . $fromtable;
|
|---|
| 32 |
|
|---|
| 33 | foreach ($_GET as $key => $element)
|
|---|
| 34 | if (($_GET[$key]=="On" || $groups>0))// && !empty($joins[$key]))
|
|---|
| 35 | $query0 .= GetJoin($fromtable, $key);
|
|---|
| 36 |
|
|---|
| 37 | foreach ($checkwhere as $key => $element)
|
|---|
| 38 | {
|
|---|
| 39 | if (empty($element) || $element<=0)
|
|---|
| 40 | continue;
|
|---|
| 41 |
|
|---|
| 42 | if (strpos($query0, " WHERE ")==FALSE)
|
|---|
| 43 | $query0 .= " WHERE ";
|
|---|
| 44 | else
|
|---|
| 45 | if ($element!=-1)
|
|---|
| 46 | if (strrpos($query0, " AND ")!=strlen($query0)-5)// this if clause doesn't work
|
|---|
| 47 | $query0 .= " AND ";
|
|---|
| 48 |
|
|---|
| 49 | if ($element!=-1)
|
|---|
| 50 | $query0 .= GetCheck($fromtable, $key) . "=" . $element;
|
|---|
| 51 | }
|
|---|
| 52 |
|
|---|
| 53 | if (strpos($query0, " WHERE ")==FALSE)
|
|---|
| 54 | $query0 .= " WHERE ";
|
|---|
| 55 | else
|
|---|
| 56 | $query0 .= " AND ";
|
|---|
| 57 |
|
|---|
| 58 | if (!empty($_GET["fStartDate"]))
|
|---|
| 59 | {
|
|---|
| 60 | $startdate=substr($_GET["fStartDate"], 0, 10);
|
|---|
| 61 | if ($startdate=="0000-00-00")
|
|---|
| 62 | $query0 .=" fTimestamp >= '" . $startdate . " 00:00:00' ";
|
|---|
| 63 | else
|
|---|
| 64 | $query0 .= " fTimestamp >= ADDDATE('" . $startdate . " 13:00:00', INTERVAL -1 DAY) ";
|
|---|
| 65 | }
|
|---|
| 66 |
|
|---|
| 67 | if (!empty($_GET["fStopDate"]))
|
|---|
| 68 | {
|
|---|
| 69 | // if (strpos(strrev($query0), " DNA ")!=0)
|
|---|
| 70 | // $query0 .= " AND ";
|
|---|
| 71 |
|
|---|
| 72 | $stopdate=substr($_GET["fStopDate"], 0, 10);
|
|---|
| 73 | $query0 .= " AND fTimestamp < '" . $stopdate . " 13:00:00' ";
|
|---|
| 74 | }
|
|---|
| 75 |
|
|---|
| 76 | if ($groups>0)
|
|---|
| 77 | {
|
|---|
| 78 | $query0 .= " GROUP BY ";
|
|---|
| 79 | $num = $groups;
|
|---|
| 80 | foreach ($checkgroup as $key => $element)
|
|---|
| 81 | if ($element==-1)
|
|---|
| 82 | {
|
|---|
| 83 | $query0 .= GetCheck($fromtable, $key);
|
|---|
| 84 | if ($num-->1)
|
|---|
| 85 | $query0 .= ", ";
|
|---|
| 86 | }
|
|---|
| 87 | }
|
|---|
| 88 |
|
|---|
| 89 | if (!empty($_GET["fSortBy"]))
|
|---|
| 90 | {
|
|---|
| 91 | $query0 .= " ORDER BY " . substr($_GET["fSortBy"], 0, -1) . " ";
|
|---|
| 92 | if (substr($_GET["fSortBy"], -1)=="-")
|
|---|
| 93 | $query0 .= "DESC";
|
|---|
| 94 | }
|
|---|
| 95 |
|
|---|
| 96 | if (empty($_GET["fNumStart"]))
|
|---|
| 97 | $_GET["fNumStart"]=0;
|
|---|
| 98 |
|
|---|
| 99 | if (empty($_GET["fSendTxt"]))
|
|---|
| 100 | $query0 .= " LIMIT " . $_GET["fNumStart"] . ", " . $_GET["fNumResults"];
|
|---|
| 101 |
|
|---|
| 102 | return $query0;
|
|---|
| 103 | }
|
|---|
| 104 |
|
|---|
| 105 | function InitGet($_GET)
|
|---|
| 106 | {
|
|---|
| 107 | // Find out whether it is the first call to the php script
|
|---|
| 108 | $first = empty($_GET["fRunMin"]) && empty($_GET["fRunMax"]);
|
|---|
| 109 |
|
|---|
| 110 | if (empty($_GET["fNumResults"]))
|
|---|
| 111 | $_GET["fNumResults"]="20";
|
|---|
| 112 |
|
|---|
| 113 | if (empty($_GET["fTimestamp"]))
|
|---|
| 114 | $_GET["fTimestamp"]=$first?"On":"";
|
|---|
| 115 |
|
|---|
| 116 | if (empty($_GET["fExposure"]))
|
|---|
| 117 | $_GET["fExposure"]=$first?"On":"";
|
|---|
| 118 |
|
|---|
| 119 | if (empty($_GET["fSkyLevel"]))
|
|---|
| 120 | $_GET["fSkyLevel"]=$first?"On":"";
|
|---|
| 121 |
|
|---|
| 122 | if (empty($_GET["fFWHM"]))
|
|---|
| 123 | $_GET["fFWHM"]=$first?"On":"";
|
|---|
| 124 |
|
|---|
| 125 | if (empty($_GET["fApertureRadius"]))
|
|---|
| 126 | $_GET["fApertureRadius"]=$first?"On":"";
|
|---|
| 127 |
|
|---|
| 128 | if (empty($_GET["fInstrumentalMag"]))
|
|---|
| 129 | $_GET["fInstrumentalMag"]=$first?"On":"";
|
|---|
| 130 |
|
|---|
| 131 | if (empty($_GET["fInstrumentalMagErr"]))
|
|---|
| 132 | $_GET["fInstrumentalMagErr"]=$first?"On":"";
|
|---|
| 133 |
|
|---|
| 134 | if (empty($_GET["fFitsFileName"]))
|
|---|
| 135 | $_GET["fFitsFileName"]=$first?"On":"";
|
|---|
| 136 |
|
|---|
| 137 | if (empty($_GET["fObjectName"]))
|
|---|
| 138 | $_GET["fObjectName"]=$first?"On":"";
|
|---|
| 139 |
|
|---|
| 140 | if (empty($_GET["fStatusName"]))
|
|---|
| 141 | $_GET["fStatusName"]=$first?"On":"";
|
|---|
| 142 |
|
|---|
| 143 | // if (empty($_GET["fRunStop"]))
|
|---|
| 144 | // $_GET["fRunStop"]="Off";
|
|---|
| 145 |
|
|---|
| 146 | }
|
|---|
| 147 |
|
|---|
| 148 | function PrintForm($_GET, $host, $user, $pw, $db)
|
|---|
| 149 | {
|
|---|
| 150 | printf("<center>\n");
|
|---|
| 151 | printf("<form action=\"opticaldata.php\" METHOD=\"GET\">\n");
|
|---|
| 152 | printf(" <table>\n");
|
|---|
| 153 | printf(" <tr>\n");
|
|---|
| 154 |
|
|---|
| 155 | CheckBox("fTimestamp", "Time");
|
|---|
| 156 | CheckBox("fExposure", "Exposure");
|
|---|
| 157 | CheckBox("fSkyLevel", "Skylevel");
|
|---|
| 158 | CheckBox("fFWHM", "FWHM");
|
|---|
| 159 |
|
|---|
| 160 | printf(" </tr><tr>\n");
|
|---|
| 161 |
|
|---|
| 162 | CheckBox("fApertureRadius", "Aperture radius");
|
|---|
| 163 | CheckBox("fInstrumentalMag", "instrumental magnitude");
|
|---|
| 164 | CheckBox("fInstrumentalMagErr", "instrum. mag. error");
|
|---|
| 165 |
|
|---|
| 166 | printf(" </tr>\n");
|
|---|
| 167 | printf(" </table>\n");
|
|---|
| 168 | printf(" <p>\n");
|
|---|
| 169 |
|
|---|
| 170 | // pull down boxes
|
|---|
| 171 |
|
|---|
| 172 | printf(" <table>\n");
|
|---|
| 173 | printf(" <tr><td>\n");
|
|---|
| 174 | PrintPullDown($host, $user, $pw, $db, "FitsFile", "fFitsFileName", "fFitsFileKEY", "Fits File");
|
|---|
| 175 | printf(" </td><td>\n");
|
|---|
| 176 | PrintPullDown($host, $user, $pw, $db, "Object", "fObjectName", "fObjectKEY", "Object Name");
|
|---|
| 177 | printf(" </td><td>\n");
|
|---|
| 178 | PrintPullDown($host, $user, $pw, $db, "Status", "fStatusName", "fStatusKEY", "Status Code");
|
|---|
| 179 | printf(" </td></tr></table>\n");
|
|---|
| 180 | printf(" <p>\n");
|
|---|
| 181 |
|
|---|
| 182 | if (empty($_GET["fStartDate"]))
|
|---|
| 183 | $timemin = GetMin("fTimestamp", "OpticalData", $host, $user, $pw, $db);
|
|---|
| 184 | else
|
|---|
| 185 | $timemin = $_GET["fStartDate"];
|
|---|
| 186 |
|
|---|
| 187 | if (empty($_GET["fStopDate"]))
|
|---|
| 188 | $timemax = GetMax("fTimestamp", "OpticalData", $host, $user, $pw, $db);
|
|---|
| 189 | else
|
|---|
| 190 | $timemax = $_GET["fStopDate"];
|
|---|
| 191 |
|
|---|
| 192 | printf("Night (yyyy-mm-dd) from <input name=\"fStartDate\" type=\"text\" size=\"10\" maxlength=\"10\" value=\"%s\">\n", $timemin);
|
|---|
| 193 | printf("to <input name=\"fStopDate\" type=\"text\" size=\"10\" maxlength=\"10\" value=\"%s\"> \n", $timemax);
|
|---|
| 194 |
|
|---|
| 195 | printf(" Results:\n");
|
|---|
| 196 | printf(" <select name=\"fNumResults\">\n");
|
|---|
| 197 |
|
|---|
| 198 | $numres = array("10", "20", "50", "100", "200", "500", "1000", "2000");
|
|---|
| 199 | foreach ($numres as $element)
|
|---|
| 200 | {
|
|---|
| 201 | if ($element==$_GET["fNumResults"])
|
|---|
| 202 | printf("<option value=\"%s\" selected>%3s</option>\n", $element, $element);
|
|---|
| 203 | else
|
|---|
| 204 | printf("<option value=\"%s\">%3s</option>\n", $element, $element);
|
|---|
| 205 | }
|
|---|
| 206 | printf(" </select>\n");
|
|---|
| 207 | printf(" \n");
|
|---|
| 208 |
|
|---|
| 209 | ini_set("mysql.trace_mode", "Off");
|
|---|
| 210 | ini_set("display_errors", "Off");
|
|---|
| 211 |
|
|---|
| 212 | printf("<input class='Width' type='submit' value='Query Table'> \n");
|
|---|
| 213 | printf("<input class='Width' type='button' value='Reset' onClick='self.location.href=\"opticaldata.php\"'> \n");
|
|---|
| 214 | if (strchr($_SERVER["REQUEST_URI"], '?')!=FALSE)
|
|---|
| 215 | printf("<input class='Width' type='button' value='Get .txt' onClick='self.location.href=\"%s&fSendTxt=1\"'> \n", $_SERVER["REQUEST_URI"]);
|
|---|
| 216 | printf("</form>\n");
|
|---|
| 217 | printf("</center>\n");
|
|---|
| 218 | printf("</td>\n");
|
|---|
| 219 | printf("</tr>\n");
|
|---|
| 220 | printf("<tr class='Block'>\n");
|
|---|
| 221 | printf("<td>\n");
|
|---|
| 222 | }
|
|---|
| 223 |
|
|---|
| 224 | function PrintPage($html, $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup)
|
|---|
| 225 | {
|
|---|
| 226 | $db_id = mysql_connect($host, $user, $pw);
|
|---|
| 227 | if ($db_id==FALSE)
|
|---|
| 228 | {
|
|---|
| 229 | printf("mysql_connect returned the following error: %s\n", mysql_error());
|
|---|
| 230 | die("");
|
|---|
| 231 | }
|
|---|
| 232 | mysql_select_db($db);
|
|---|
| 233 | mysql_query("SET BIG_TABLES=1"); // necessary for mySQL <= 4
|
|---|
| 234 |
|
|---|
| 235 |
|
|---|
| 236 | $query0 = CreateQuery($_GET, $alias, $checkwhere, $checkgroup, $checkstatusgroup);
|
|---|
| 237 |
|
|---|
| 238 | $result0 = mysql_query($query0, $db_id);
|
|---|
| 239 |
|
|---|
| 240 | if ($result0)
|
|---|
| 241 | {
|
|---|
| 242 | if ($html=="1")
|
|---|
| 243 | PrintMagicTable($result0, $alias, $rightalign, "", "", "", $_GET);
|
|---|
| 244 | else
|
|---|
| 245 | PrintText($result0);
|
|---|
| 246 |
|
|---|
| 247 | mysql_free_result($result0);
|
|---|
| 248 | }
|
|---|
| 249 | mysql_close($db_id);
|
|---|
| 250 |
|
|---|
| 251 | PrintSubmittedQuery($query0, $html, $db, "old");
|
|---|
| 252 | }
|
|---|
| 253 |
|
|---|
| 254 | include ("include.php");
|
|---|
| 255 | include ("db.php");
|
|---|
| 256 | include ("magicdefs.php");
|
|---|
| 257 |
|
|---|
| 258 | ini_set("display_errors", "On");
|
|---|
| 259 | ini_set("mysql.trace_mode", "On");
|
|---|
| 260 |
|
|---|
| 261 | if (!empty($_GET["fSendTxt"]))
|
|---|
| 262 | {
|
|---|
| 263 | header("Content-type: application/octet");
|
|---|
| 264 | header("Content-Disposition: attachment; filename=query-result.txt");
|
|---|
| 265 |
|
|---|
| 266 | PrintPage("0", $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup);
|
|---|
| 267 | }
|
|---|
| 268 | else
|
|---|
| 269 | {
|
|---|
| 270 | echo (file_get_contents("index-header.html"));
|
|---|
| 271 |
|
|---|
| 272 | $environment = sizeof($_GET);
|
|---|
| 273 |
|
|---|
| 274 | InitGet($_GET);
|
|---|
| 275 | PrintForm($_GET, $host, $user, $pw, $db);
|
|---|
| 276 |
|
|---|
| 277 | if ($environment==0)
|
|---|
| 278 | printf("No query submitted yet.<BR>");
|
|---|
| 279 | else
|
|---|
| 280 | PrintPage("1", $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup);
|
|---|
| 281 |
|
|---|
| 282 | echo (file_get_contents("index-footer.html"));
|
|---|
| 283 | }
|
|---|
| 284 |
|
|---|
| 285 | ini_set("display_errors", "Off");
|
|---|
| 286 | ini_set("mysql.trace_mode", "Off");
|
|---|
| 287 | }
|
|---|
| 288 | ?>
|
|---|