1 | <?php
|
---|
2 | {
|
---|
3 | function CreateQuery($_GET, $alias, $checkwhere, $checkgroup, $checkstatusgroup, $needs)
|
---|
4 | {
|
---|
5 | $fromtable="DataSets";
|
---|
6 |
|
---|
7 | $groups = 0;
|
---|
8 | foreach ($checkgroup as $element)
|
---|
9 | if ($element==-1)
|
---|
10 | $groups++;
|
---|
11 |
|
---|
12 | $statusgroups = 0;
|
---|
13 | foreach ($checkstatusgroup as $element)
|
---|
14 | if ($element==-1)
|
---|
15 | $statusgroups++;
|
---|
16 |
|
---|
17 | $query0 = "SELECT ";
|
---|
18 |
|
---|
19 | if ($groups>0)
|
---|
20 | {
|
---|
21 | foreach ($checkgroup as $key => $element)
|
---|
22 | if ($element==-1)
|
---|
23 | $query0 .= $key . " as '" . $alias[$key] . "' " . ", ";
|
---|
24 | $query0 .= " COUNT(*) as '# Datasets' ";
|
---|
25 | }
|
---|
26 | else
|
---|
27 | {
|
---|
28 | if ($statusgroups>0)
|
---|
29 | {
|
---|
30 | foreach ($checkstatusgroup as $key => $element)
|
---|
31 | if ($element==-1)
|
---|
32 | $query0 .= " (if(IsNull(" . $key . "), if(isnull(fStartTime), 'not done', if(isnull(fFailedTime),if(isnull(" . $needs[$key] . "),'not done',if(date_sub(Now(),interval 12 hour) < fStartTime,'running','crashed')),if(isnull(" . $needs[$key] . "),'not done','failed'))) ,if(" . $key . "='1970-01-01 00:00:00','dont do','done'))) as '" . $alias[$key] . "', ";
|
---|
33 | // $query0 .= " (if(IsNull(" . $key . "), 'not done' ,if(" . $key . "='1970-01-01 00:00:00','dont do','done'))) as '" . $alias[$key] . "', ";
|
---|
34 |
|
---|
35 | $query0 .= " COUNT(*) as '# Datasets'";
|
---|
36 |
|
---|
37 | }
|
---|
38 | else
|
---|
39 | {
|
---|
40 | $query0 .= " " . $fromtable . ".fDataSetNumber as '" . $alias["fDataSetNumber"] . "' ";
|
---|
41 | if (!empty($_GET["fLinks"]))
|
---|
42 | {
|
---|
43 | $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>' ";
|
---|
44 | $query0 .= ", ' <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>'";
|
---|
45 | $query0 .= ", ' <A&ws;HREF=\"ganymed.php?fDataSetNo=', DataSets.fDataSetNumber, '\">i</A>') ";
|
---|
46 | $query0 .= " as 'Links'";
|
---|
47 | }
|
---|
48 |
|
---|
49 | foreach ($_GET as $key => $element)
|
---|
50 | if ($_GET[$key]=="On")
|
---|
51 | if ($key!="fLinks")
|
---|
52 | if (empty($checkwhere[$key]) || $checkwhere[$key]==0)
|
---|
53 | $query0 .= ", " . $key . " as '" . $alias[$key] . "' ";
|
---|
54 | }
|
---|
55 | }
|
---|
56 |
|
---|
57 | $query0 .= " FROM " . $fromtable;
|
---|
58 |
|
---|
59 | $query0 .= " LEFT JOIN DataSetProcessStatus ON " . $fromtable . ".fDataSetNumber=DataSetProcessStatus.fDataSetNumber ";
|
---|
60 | $query0 .= " LEFT JOIN Ganymed ON " . $fromtable . ".fDataSetNumber=Ganymed.fDataSetNumber ";
|
---|
61 |
|
---|
62 | foreach ($_GET as $key => $element)
|
---|
63 | if (($_GET[$key]=="On" || $groups>0))// && !empty($joins[$key]))
|
---|
64 | $query0 .= GetJoin($fromtable,$key);
|
---|
65 |
|
---|
66 | foreach ($checkwhere as $key => $element)
|
---|
67 | {
|
---|
68 | if (empty($element) || $element<=0)
|
---|
69 | continue;
|
---|
70 |
|
---|
71 | if (strpos($query0, " WHERE ")==FALSE)
|
---|
72 | $query0 .= " WHERE ";
|
---|
73 | else
|
---|
74 | if ($element!=-1)
|
---|
75 | if (strrpos($query0, " AND ")!=strlen($query0)-5)
|
---|
76 | $query0 .= " AND ";
|
---|
77 |
|
---|
78 | if ($element!=-1)
|
---|
79 | $query0 .= GetCheck($fromtable, $key) . "=" . $element;
|
---|
80 | }
|
---|
81 |
|
---|
82 | if (strpos($query0, " WHERE ")==FALSE)
|
---|
83 | $query0 .= " WHERE ";
|
---|
84 | else
|
---|
85 | $query0 .= " AND ";
|
---|
86 |
|
---|
87 | $query0 .= StatusQuery("fDataSetInserted", $needs);
|
---|
88 | $query0 .= StatusQuery("fStarFilesAvail", $needs);
|
---|
89 | $query0 .= StatusQuery("fGanymed", $needs);
|
---|
90 | $query0 .= StatusQuery("fFillGanymed", $needs);
|
---|
91 |
|
---|
92 | if (!empty($_GET["fRunMin"]) && !empty($_GET["fRunMax"]))
|
---|
93 | $query0 .= "DataSets.fDataSetNumber BETWEEN " . $_GET["fRunMin"] . " AND " . $_GET["fRunMax"] . " ";
|
---|
94 |
|
---|
95 | /*
|
---|
96 | if (!empty($_GET["fDate"]))
|
---|
97 | $query0 .= " AND fRunStart REGEXP \"^" . $_GET["fDate"] . "\" ";
|
---|
98 | */
|
---|
99 |
|
---|
100 | if (!empty($_GET["fSourceN"]))
|
---|
101 | $query0 .= " AND fSourceName REGEXP \"^" . $_GET["fSourceN"] . "\" ";
|
---|
102 |
|
---|
103 | if ($groups>0)
|
---|
104 | {
|
---|
105 | $query0 .= " GROUP BY ";
|
---|
106 | $num = $groups;
|
---|
107 | foreach ($checkgroup as $key => $element)
|
---|
108 | if ($element==-1)
|
---|
109 | {
|
---|
110 | $query0 .= GetCheck($fromtable,$key);
|
---|
111 | if ($num-->1)
|
---|
112 | $query0 .= ", ";
|
---|
113 | }
|
---|
114 | }
|
---|
115 |
|
---|
116 | if ($statusgroups>0)
|
---|
117 | {
|
---|
118 | $query0 .= " GROUP BY ";
|
---|
119 | $num = $statusgroups;
|
---|
120 | foreach ($checkstatusgroup as $key => $element)
|
---|
121 | if ($element==-1)
|
---|
122 | {
|
---|
123 | $query0 .= $alias[$key];
|
---|
124 | if ($num-->1)
|
---|
125 | $query0 .= ", ";
|
---|
126 | }
|
---|
127 | }
|
---|
128 |
|
---|
129 | if (!empty($_GET["fSortBy"]))
|
---|
130 | {
|
---|
131 | $val=substr($_GET["fSortBy"], 0, -1);
|
---|
132 | $query0 .= " ORDER BY " . GetTable($fromtable, $val) . " ";
|
---|
133 | if (substr($_GET["fSortBy"], -1)=="-")
|
---|
134 | $query0 .= "DESC";
|
---|
135 | }
|
---|
136 |
|
---|
137 | if (empty($_GET["fSortBy"]) && $groups==0 && $statusgroups==0)
|
---|
138 | $query0 .= "ORDER BY DataSets.fDataSetNumber ASC ";
|
---|
139 |
|
---|
140 | if (empty($_GET["fNumStart"]))
|
---|
141 | $_GET["fNumStart"]=0;
|
---|
142 |
|
---|
143 | if (empty($_GET["fSendTxt"]))
|
---|
144 | $query0 .= " LIMIT " . $_GET["fNumStart"] . ", " . $_GET["fNumResults"];
|
---|
145 |
|
---|
146 | return $query0;
|
---|
147 | }
|
---|
148 |
|
---|
149 | function InitGet($_GET)
|
---|
150 | {
|
---|
151 | // Find out whether it is the first call to the php script
|
---|
152 | $first = empty($_GET["fRunMin"]) && empty($_GET["fRunMax"]);
|
---|
153 |
|
---|
154 | if (empty($_GET["fNumResults"]))
|
---|
155 | $_GET["fNumResults"]="50";
|
---|
156 |
|
---|
157 | if (empty($_GET["fLastUpdate"]))
|
---|
158 | $_GET["fLastUpdate"]="Off";
|
---|
159 |
|
---|
160 | if (empty($_GET["fLinks"]))
|
---|
161 | $_GET["fLinks"]=$first?"On":"";
|
---|
162 |
|
---|
163 | if (empty($_GET["fComment"]))
|
---|
164 | $_GET["fComment"]="Off";
|
---|
165 |
|
---|
166 | if (empty($_GET["fWobble"]))
|
---|
167 | $_GET["fWobble"]=$first?"On":"";
|
---|
168 |
|
---|
169 | if (empty($_GET["fExcessEvents"]))
|
---|
170 | $_GET["fExcessEvents"]=$first?"On":"";
|
---|
171 |
|
---|
172 | if (empty($_GET["fExcessEvents*60/fEffOnTime"]))
|
---|
173 | $_GET["fExcessEvents*60/fEffOnTime"]=$first?"Off":"";
|
---|
174 |
|
---|
175 | if (empty($_GET["fBackgroundEvents*60/fEffOnTime"]))
|
---|
176 | $_GET["fBackgroundEvents*60/fEffOnTime"]=$first?"On":"";
|
---|
177 |
|
---|
178 | if (empty($_GET["fBackgroundEvents"]))
|
---|
179 | $_GET["fBackgroundEvents"]=$first?"On":"";
|
---|
180 |
|
---|
181 | if (empty($_GET["fSignalEvents"]))
|
---|
182 | $_GET["fSignalEvents"]=$first?"On":"";
|
---|
183 |
|
---|
184 | if (empty($_GET["fSignalEvents*60/fEffOnTime"]))
|
---|
185 | $_GET["fSignalEvents*60/fEffOnTime"]=$first?"Off":"";
|
---|
186 |
|
---|
187 | if (empty($_GET["fSignificance"]))
|
---|
188 | $_GET["fSignificance"]=$first?"On":"";
|
---|
189 |
|
---|
190 | if (empty($_GET["Round(fSignificance/Sqrt(fEffOnTime/3600),2)"]))
|
---|
191 | $_GET["Round(fSignificance/Sqrt(fEffOnTime/3600),2)"]=$first?"Off":"";
|
---|
192 |
|
---|
193 | if (empty($_GET["fScaleFactor"]))
|
---|
194 | $_GET["fScaleFactor"]=$first?"On":"";
|
---|
195 |
|
---|
196 | if (empty($_GET["fEffOnTime/3600"]))
|
---|
197 | $_GET["fEffOnTime/3600"]=$first?"On":"";
|
---|
198 |
|
---|
199 | if (empty($_GET["fDataSetInserted"]))
|
---|
200 | $_GET["fDataSetInserted"]="Off";
|
---|
201 |
|
---|
202 | if (empty($_GET["fDataSetInsertedStatus"]))
|
---|
203 | $_GET["fDataSetInsertedStatus"]="0";
|
---|
204 |
|
---|
205 | if (empty($_GET["fStarFilesAvail"]))
|
---|
206 | $_GET["fStarFilesAvail"]="Off";
|
---|
207 |
|
---|
208 | if (empty($_GET["fStarFilesAvailStatus"]))
|
---|
209 | $_GET["fStarFilesAvailStatus"]="0";
|
---|
210 |
|
---|
211 | if (empty($_GET["fGanymed"]))
|
---|
212 | $_GET["fGanymed"]=$first?"On":"";
|
---|
213 |
|
---|
214 | if (empty($_GET["fGanymedStatus"]))
|
---|
215 | $_GET["fGanymedStatus"]="0";
|
---|
216 |
|
---|
217 | if (empty($_GET["fFillGanymed"]))
|
---|
218 | $_GET["fFillGanymed"]="Off";
|
---|
219 |
|
---|
220 | if (empty($_GET["fFillGanymedStatus"]))
|
---|
221 | $_GET["fFillGanymedStatus"]="0";
|
---|
222 |
|
---|
223 | if (empty($_GET["fSourceName"]))
|
---|
224 | $_GET["fSourceName"]=$first?"On":"";
|
---|
225 |
|
---|
226 | if (empty($_GET["fLastUpdate"]))
|
---|
227 | $_GET["fLastUpdate"]="Off";
|
---|
228 |
|
---|
229 | if (empty($_GET["fStartTime"]))
|
---|
230 | $_GET["fStartTime"]="Off";
|
---|
231 |
|
---|
232 | if (empty($_GET["fFailedTime"]))
|
---|
233 | $_GET["fFailedTime"]="Off";
|
---|
234 |
|
---|
235 | if (empty($_GET["fReturnCode"]))
|
---|
236 | $_GET["fReturnCode"]="Off";
|
---|
237 |
|
---|
238 | if (empty($_GET["fFailedCode"]))
|
---|
239 | $_GET["fFailedCode"]="Off";
|
---|
240 |
|
---|
241 | if (empty($_GET["fFailedCodeAdd"]))
|
---|
242 | $_GET["fFailedCodeAdd"]="Off";
|
---|
243 |
|
---|
244 | }
|
---|
245 |
|
---|
246 | function PrintForm($_GET, $host, $user, $pw, $db)
|
---|
247 | {
|
---|
248 | printf("<center>\n");
|
---|
249 | printf("<form action=\"datasetinfo.php\" METHOD=\"GET\">\n");
|
---|
250 | printf(" <table>\n");
|
---|
251 | printf(" <tr>\n");
|
---|
252 |
|
---|
253 | CheckBox("fWobble", "Wobble");
|
---|
254 | CheckBox("fComment", "Comment");
|
---|
255 | CheckBox("fScaleFactor", "Scale");
|
---|
256 | CheckBox("fEffOnTime/3600", "EffOnTime");
|
---|
257 | CheckBox("fLinks", "Links");
|
---|
258 |
|
---|
259 | printf(" </tr><tr>\n");
|
---|
260 |
|
---|
261 | CheckBox("fExcessEvents", "ExcEvts");
|
---|
262 | CheckBox("fBackgroundEvents", "BgEvts");
|
---|
263 | CheckBox("fSignalEvents", "SignEvts");
|
---|
264 | CheckBox("fSignificance", "Sign");
|
---|
265 |
|
---|
266 | printf(" </tr><tr>\n");
|
---|
267 |
|
---|
268 | CheckBox("fExcessEvents*60/fEffOnTime", "ExcRate");
|
---|
269 | CheckBox("fBackgroundEvents*60/fEffOnTime", "BgRate");
|
---|
270 | CheckBox("fSignalEvents*60/fEffOnTime", "SignRate");
|
---|
271 | CheckBox("Round(fSignificance/Sqrt(fEffOnTime/3600),2)", "SignfRate");
|
---|
272 |
|
---|
273 | printf(" </tr>\n");
|
---|
274 | printf(" </table>\n");
|
---|
275 | printf(" <p>\n");
|
---|
276 | printf(" <table>\n");
|
---|
277 | printf(" <tr>\n");
|
---|
278 |
|
---|
279 | CheckBox("fStartTime", "StartTime");
|
---|
280 | CheckBox("fFailedTime", "FailedTime");
|
---|
281 | CheckBox("fReturnCode", "ErrCode");
|
---|
282 | CheckBox("fFailedCode", "RetCode");
|
---|
283 | CheckBox("fFailedCodeAdd", "CodeAdd");
|
---|
284 |
|
---|
285 | printf(" </tr>\n");
|
---|
286 | printf(" </table>\n");
|
---|
287 | printf(" <table>\n");
|
---|
288 | printf(" <tr>\n");
|
---|
289 |
|
---|
290 | printf(" <td>\n");
|
---|
291 | PrintStatusMenu("fDataSetInserted", "DataSet Inserted");
|
---|
292 | printf(" </td><td>\n");
|
---|
293 | PrintStatusMenu("fStarFilesAvail", "FilesAvail");
|
---|
294 | printf(" </td><td>\n");
|
---|
295 | PrintStatusMenu("fGanymed", "Ganymed");
|
---|
296 | printf(" </td><td>\n");
|
---|
297 | PrintStatusMenu("fFillGanymed", "FillGanymed");
|
---|
298 |
|
---|
299 | printf(" </td></tr><tr><td>\n");
|
---|
300 |
|
---|
301 | PrintPullDown($host, $user, $pw, $db, "Source", "fSourceName", "fSourceKEY", "Source Name");
|
---|
302 |
|
---|
303 | printf(" </td></tr>\n");
|
---|
304 | printf(" </table>\n");
|
---|
305 | printf(" <p>\n");
|
---|
306 |
|
---|
307 | if (empty($_GET["fRunMin"]))
|
---|
308 | $min = GetMin("fDataSetNumber", "DataSets", $host, $user, $pw, $db);
|
---|
309 | else
|
---|
310 | $min = $_GET["fRunMin"];
|
---|
311 |
|
---|
312 | if (empty($_GET["fRunMax"]))
|
---|
313 | $max = GetMax("fDataSetNumber", "DataSets", $host, $user, $pw, $db);
|
---|
314 | else
|
---|
315 | $max = $_GET["fRunMax"];
|
---|
316 |
|
---|
317 | /*
|
---|
318 | printf("Date (yyyy-mm-dd) <input name=\"fDate\" type=\"text\" size=\"10\" maxlength=\"10\" value=\"");
|
---|
319 | if (!empty($_GET["fDate"]))
|
---|
320 | printf("%s", $_GET["fDate"]);
|
---|
321 | printf("\"> \n");
|
---|
322 | */
|
---|
323 |
|
---|
324 | printf("Source (<A HREF=\"regexp.html\">regexp</A>) <input name=\"fSourceN\" type=\"text\" size=\"15\" maxlength=\"15\" value=\"");
|
---|
325 | if (!empty($_GET["fSourceN"]))
|
---|
326 | printf("%s", $_GET["fSourceN"]);
|
---|
327 | printf("\"> \n");
|
---|
328 |
|
---|
329 | printf("DataSets from <input name=\"fRunMin\" type=\"text\" size=\"6\" maxlength=\"6\" value=\"%s\">\n", $min);
|
---|
330 | printf("to <input name=\"fRunMax\" type=\"text\" size=\"6\" maxlength=\"6\" value=\"%s\"> \n", $max);
|
---|
331 |
|
---|
332 | printf(" <P>\n");
|
---|
333 |
|
---|
334 | printf(" Results:\n");
|
---|
335 | printf(" <select name=\"fNumResults\">\n");
|
---|
336 |
|
---|
337 | $numres = array("10", "20", "50", "100", "200", "500");
|
---|
338 | foreach ($numres as $element)
|
---|
339 | {
|
---|
340 | if ($element==$_GET["fNumResults"])
|
---|
341 | printf("<option value=\"%s\" selected>%3s</option>\n", $element, $element);
|
---|
342 | else
|
---|
343 | printf("<option value=\"%s\">%3s</option>\n", $element, $element);
|
---|
344 | }
|
---|
345 | printf(" </select>\n");
|
---|
346 | printf(" \n");
|
---|
347 |
|
---|
348 | ini_set("mysql.trace_mode", "Off");
|
---|
349 | ini_set("display_errors", "Off");
|
---|
350 |
|
---|
351 | printf("<input class='Width' type='submit' value='Query Table'> \n");
|
---|
352 | printf("<input class='Width' type='button' value='Reset' onClick='self.location.href=\"datasetinfo.php\"'> \n");
|
---|
353 | if (strchr($_SERVER["REQUEST_URI"], '?')!=FALSE)
|
---|
354 | printf("<input class='Width' type='button' value='Get .txt' onClick='self.location.href=\"%s&fSendTxt=1\"'> \n", $_SERVER["REQUEST_URI"]);
|
---|
355 | if (strchr($_SERVER["REQUEST_URI"], '?')!=FALSE)
|
---|
356 | printf("<input class='Width' type='button' value='Print' onClick='self.location.href=\"%s&fPrintTable=1\"'> \n", $_SERVER["REQUEST_URI"]);
|
---|
357 | printf("</form>\n");
|
---|
358 | printf("</center>\n");
|
---|
359 | printf("</td>\n");
|
---|
360 | printf("</tr>\n");
|
---|
361 | printf("<tr class='Block'>\n");
|
---|
362 | printf("<td>\n");
|
---|
363 | }
|
---|
364 |
|
---|
365 | function PrintPage($html, $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $needs)
|
---|
366 | {
|
---|
367 | $db_id = mysql_connect($host, $user, $pw);
|
---|
368 | if ($db_id==FALSE)
|
---|
369 | {
|
---|
370 | printf("mysql_connect returned the following error: %s\n", mysql_error());
|
---|
371 | die("");
|
---|
372 | }
|
---|
373 | mysql_select_db($db);
|
---|
374 |
|
---|
375 | $query0 = CreateQuery($_GET, $alias, $checkwhere, $checkgroup, $checkstatusgroup, $needs);
|
---|
376 |
|
---|
377 | $result0 = mysql_query($query0, $db_id);
|
---|
378 |
|
---|
379 | if ($result0)
|
---|
380 | {
|
---|
381 | if ($html=="1" || $html=="2")
|
---|
382 | PrintMagicTable($result0, $alias, $rightalign, "", "", "", "", $_GET);
|
---|
383 | else
|
---|
384 | PrintText($result0);
|
---|
385 |
|
---|
386 | mysql_free_result($result0);
|
---|
387 | }
|
---|
388 | mysql_close($db_id);
|
---|
389 |
|
---|
390 | PrintSubmittedQuery($query0, $html, $db, "old");
|
---|
391 | }
|
---|
392 |
|
---|
393 | include ("include.php");
|
---|
394 | include ("db.php");
|
---|
395 | include ("magicdefs.php");
|
---|
396 |
|
---|
397 | ini_set("display_errors", "On");
|
---|
398 | ini_set("mysql.trace_mode", "On");
|
---|
399 |
|
---|
400 | if (!empty($_GET["fSendTxt"]))
|
---|
401 | {
|
---|
402 | header("Content-type: application/octet");
|
---|
403 | header("Content-Disposition: attachment; filename=query-result.txt");
|
---|
404 |
|
---|
405 | PrintPage("0", $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup);
|
---|
406 | }
|
---|
407 | else
|
---|
408 | {
|
---|
409 | echo (file_get_contents("index-header.html"));
|
---|
410 |
|
---|
411 | $environment = sizeof($_GET);
|
---|
412 |
|
---|
413 | InitGet($_GET);
|
---|
414 | if (empty($_GET["fPrintTable"]))
|
---|
415 | PrintForm($_GET, $host, $user, $pw, $db);
|
---|
416 |
|
---|
417 | if ($environment==0)
|
---|
418 | printf("No query submitted yet.<BR>");
|
---|
419 | else
|
---|
420 | {
|
---|
421 | if (empty($_GET["fPrintTable"]))
|
---|
422 | PrintPage("1", $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $needs);
|
---|
423 | else
|
---|
424 | PrintPage("2", $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $needs);
|
---|
425 | }
|
---|
426 |
|
---|
427 | echo (file_get_contents("index-footer.html"));
|
---|
428 | }
|
---|
429 |
|
---|
430 | ini_set("display_errors", "Off");
|
---|
431 | ini_set("mysql.trace_mode", "Off");
|
---|
432 | }
|
---|
433 | ?>
|
---|