source: branches/Mars_use_drstimefiles/datacenter/db/datacheck.php@ 18066

Last change on this file since 18066 was 17386, checked in by tbretz, 11 years ago
Removed svn:executable property, these are no executables.
File size: 18.4 KB
Line 
1<?php
2{
3 function CreateQuery($_GET, $alias, $checkwhere, $checkgroup, $checkstatusgroup, $checkenumgroup, $needs)
4 {
5 $fromtable="RunData";
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 $enumgroups = 0;
18 foreach ($checkenumgroup as $element)
19 if ($element==-1)
20 $enumgroups++;
21
22 $query0 = "SELECT SQL_CALC_FOUND_ROWS ";
23
24 if ($groups>0)
25 {
26 foreach ($checkgroup as $key => $element)
27 if ($element==-1)
28 $query0 .= $key . " as '" . $alias[$key] . "' " . ", ";
29 $query0 .= " COUNT(*) as 'Runs' ";
30 }
31 else
32 {
33 if ($statusgroups>0)
34 {
35 foreach ($checkstatusgroup as $key => $element)
36 if ($element==-1)
37 $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] . "', ";
38// $query0 .= " (if(IsNull(" . $key . "), 'not done' ,if(" . $key . "='1970-01-01 00:00:00','dont do','done'))) as '" . $alias[$key] . "', ";
39
40 $query0 .= " count(*) as 'Runs'";
41
42 }
43 else
44 {
45 if ($enumgroups>0)
46 {
47 foreach ($checkenumgroup as $key => $element)
48 if ($element==-1)
49 $query0 .= $key . " as '" . $alias[$key] . "' " . ", ";
50 $query0 .= " COUNT(*) as 'Runs' ";
51 }
52 else
53 {
54 $query0 .= " RunData.fRunNumber as 'RunNumber'";
55 if (!empty($_GET["fLinks"]))
56 {
57 $query0 .= ", CONCAT('<A&ws;HREF=\"http://www.astro.uni-wuerzburg.de/datacenter/sinope/' , DATE_FORMAT(ADDDATE(RunData.fRunStart, INTERVAL 13 HOUR), '%Y') , '/', DATE_FORMAT(ADDDATE(RunData.fRunStart, INTERVAL 13 HOUR), '%m') , '/', DATE_FORMAT(ADDDATE(RunData.fRunStart, INTERVAL 13 HOUR), '%d') , '/sinope-dat' , LPAD(CONCAT(RunData.fRunNumber , '.html'), 13,'0') , '\">dl</A>' ";
58 $query0 .= ", '&nbsp;<A&ws;HREF=\"http://www.astro.uni-wuerzburg.de/datacenter/sinope/' , DATE_FORMAT(ADDDATE(RunData.fRunStart, INTERVAL 13 HOUR), '%Y') , '/', DATE_FORMAT(ADDDATE(RunData.fRunStart, INTERVAL 13 HOUR), '%m') , '/', DATE_FORMAT(ADDDATE(RunData.fRunStart, INTERVAL 13 HOUR), '%d') , '/sinope-cal' , LPAD(CONCAT(RunData.fRunNumber , '.html'), 13,'0') , '\">cl</A>' ";
59 $query0 .= ", '&nbsp;<A&ws;HREF=\"http://www.astro.uni-wuerzburg.de/datacenter/sinope/' , DATE_FORMAT(ADDDATE(RunData.fRunStart, INTERVAL 13 HOUR), '%Y') , '/', DATE_FORMAT(ADDDATE(RunData.fRunStart, INTERVAL 13 HOUR), '%m') , '/', DATE_FORMAT(ADDDATE(RunData.fRunStart, INTERVAL 13 HOUR), '%d') , '/sinope-dat' , LPAD(CONCAT(RunData.fRunNumber , '.txt'), 12,'0') , '\">dt</A>' ";
60 $query0 .= ", '&nbsp;<A&ws;HREF=\"http://www.astro.uni-wuerzburg.de/datacenter/sinope/' , DATE_FORMAT(ADDDATE(RunData.fRunStart, INTERVAL 13 HOUR), '%Y') , '/', DATE_FORMAT(ADDDATE(RunData.fRunStart, INTERVAL 13 HOUR), '%m') , '/', DATE_FORMAT(ADDDATE(RunData.fRunStart, INTERVAL 13 HOUR), '%d') , '/sinope-cal' , LPAD(CONCAT(RunData.fRunNumber , '.txt'), 12,'0') , '\">ct</A>' ";
61 $query0 .= ", '&nbsp;<A&ws;HREF=\"http://www.astro.uni-wuerzburg.de/datacenter/callisto/' , LEFT(LPAD(CONCAT(fSequenceFirst, '.'), 9,'0'),4), '/', LPAD(CONCAT(fSequenceFirst, '/'), 9,'0'), 'callisto', LPAD(CONCAT(fSequenceFirst , '.html'), 13,'0') , '\">c</A>'";
62 $query0 .= ", '&nbsp;<A&ws;HREF=\"http://www.astro.uni-wuerzburg.de/datacenter/star/' , LEFT(LPAD(CONCAT(fSequenceFirst, '.'), 9,'0'),4), '/', LPAD(CONCAT(fSequenceFirst, '/'), 9,'0'), 'star', LPAD(CONCAT(fSequenceFirst , '.html'), 13,'0') , '\">s</A>'";
63 $query0 .= ", '&nbsp;<A&ws;HREF=\"http://www.astro.uni-wuerzburg.de/datacenter/sequences/' , LEFT(LPAD(CONCAT(fSequenceFirst, '.'), 9,'0'),4), '/sequence', LPAD(CONCAT(fSequenceFirst , '.txt'), 12,'0') , '\">', 'f </A>') ";
64 $query0 .= " as 'Links'";
65 }
66
67 foreach ($_GET as $key => $element)
68 if ($_GET[$key]=="On")
69 if ($key!="fLinks")
70 if (empty($checkwhere[$key]) || $checkwhere[$key]==0)
71 $query0 .= ", " . $key . " as '" . $alias[$key] . "' ";
72 }
73 }
74 }
75
76 $query0 .= " FROM RunData ";
77
78 $query0 .= " LEFT JOIN RunProcessStatus USING(fRunNumber,fTelescopeNumber,fFileNumber) ";
79 $query0 .= " LEFT JOIN DataCheck USING(fRunNumber) ";
80 $query0 .= " LEFT JOIN RunType USING(fRunTypeKEY) ";
81
82 foreach ($checkwhere as $key => $element)
83 {
84 if (empty($element) || $element<=0)
85 continue;
86
87 if (strpos($query0, " WHERE ")==FALSE)
88 $query0 .= " WHERE ";
89 else
90 if ($element!=-1)
91 if (strrpos($query0, " AND ")!=strlen($query0)-5)
92 $query0 .= " AND ";
93
94 if ($element!=-1)
95 $query0 .= GetCheck($fromtable, $key) . "=" . $element;
96 }
97
98 if (strpos($query0, " WHERE ")==FALSE)
99 $query0 .= " WHERE ";
100 else
101 $query0 .= " AND ";
102
103 $query0 .= StatusQuery("fRawFileAvail", $needs, $timelimits);
104 $query0 .= StatusQuery("fDataCheckDone", $needs, $timelimits);
105
106 $query0 .= EnumQuery("fHasSignal");
107 $query0 .= EnumQuery("fHasPedestal");
108 $query0 .= EnumQuery("fHasSignalInterlaced");
109 $query0 .= EnumQuery("fHasPedestalInterlaced");
110
111 if (!empty($_GET["fRunMin"]) && !empty($_GET["fRunMax"]))
112 $query0 .= "RunData.fRunNumber BETWEEN " . $_GET["fRunMin"] . " AND " . $_GET["fRunMax"] . " ";
113
114 if (!empty($_GET["fSourceN"]))
115 $query0 .= " AND fSourceName REGEXP \"^" . $_GET["fSourceN"] . "\" ";
116
117 if ($groups>0)
118 {
119 $query0 .= " GROUP BY ";
120 $num = $groups;
121 foreach ($checkgroup as $key => $element)
122 if ($element==-1)
123 {
124 $query0 .= GetCheck($fromtable,$key);
125 if ($num-->1)
126 $query0 .= ", ";
127 }
128 }
129
130 if ($statusgroups>0)
131 {
132 $query0 .= " GROUP BY ";
133 $num = $statusgroups;
134 foreach ($checkstatusgroup as $key => $element)
135 if ($element==-1)
136 {
137 $query0 .= $alias[$key];
138 if ($num-->1)
139 $query0 .= ", ";
140 }
141 }
142
143 if ($enumgroups>0)
144 {
145 $query0 .= " GROUP BY ";
146 $num = $enumgroups;
147 foreach ($checkenumgroup as $key => $element)
148 if ($element==-1)
149 {
150 $query0 .= $alias[$key];
151 if ($num-->1)
152 $query0 .= ", ";
153 }
154 }
155
156 if (!empty($_GET["fSortBy"]))
157 {
158 $val=substr($_GET["fSortBy"], 0, -1);
159 $query0 .= " ORDER BY " . GetTable($fromtable, $val) . " ";
160 if (substr($_GET["fSortBy"], -1)=="-")
161 $query0 .= "DESC";
162 }
163
164 if (empty($_GET["fSortBy"]) && $groups==0 && $statusgroups==0)
165 $query0 .= " ORDER BY RunData.fRunNumber ASC ";
166
167 if (empty($_GET["fNumStart"]))
168 $_GET["fNumStart"]=0;
169
170 if (empty($_GET["fSendTxt"]))
171 $query0 .= " LIMIT " . $_GET["fNumStart"] . ", " . $_GET["fNumResults"];
172
173 return $query0;
174 }
175
176 function InitGet($_GET)
177 {
178 // Find out whether it is the first call to the php script
179 $first = empty($_GET["fRunMin"]) && empty($_GET["fRunMax"]);
180
181 if (empty($_GET["fNumResults"]))
182 $_GET["fNumResults"]="20";
183
184 if (empty($_GET["fLinks"]))
185 $_GET["fLinks"]=$first?"On":"";
186
187 if (empty($_GET["fSequenceFirst"]))
188 $_GET["fSequenceFirst"]=$first?"On":"";
189
190 if (empty($_GET["fEvents"]))
191 $_GET["fEvents"]=$first?"On":"";
192
193 if (empty($_GET["fPositionSignal"]))
194 $_GET["fPositionSignal"]="Off";
195
196 if (empty($_GET["fPositionFWHM"]))
197 $_GET["fPositionFWHM"]="Off";
198
199 if (empty($_GET["fHeightSignal"]))
200 $_GET["fHeightSignal"]="Off";
201
202 if (empty($_GET["fHeightFWHM"]))
203 $_GET["fHeightFWHM"]="Off";
204
205 if (empty($_GET["fHasSignal"]))
206 $_GET["fHasSignal"]=$first?"On":"";
207
208 if (empty($_GET["fHasSignalEnum"]))
209 $_GET["fHasSignalEnum"]="0";
210
211 if (empty($_GET["fHasPedestal"]))
212 $_GET["fHasPedestal"]=$first?"On":"";
213
214 if (empty($_GET["fHasPedestalEnum"]))
215 $_GET["fHasPedestalEnum"]="0";
216
217 if (empty($_GET["fPositionAsym"]))
218 $_GET["fPositionAsym"]="Off";
219
220 if (empty($_GET["fHeightAsym"]))
221 $_GET["fHeightAsym"]="Off";
222
223 if (empty($_GET["fEventsInterlaced"]))
224 $_GET["fEventsInterlaced"]=$first?"On":"";
225
226 if (empty($_GET["fPositionSignalInterlaced"]))
227 $_GET["fPositionSignalInterlaced"]="Off";
228
229 if (empty($_GET["fPositionFWHMInterlaced"]))
230 $_GET["fPositionFWHMInterlaced"]="OFf";
231
232 if (empty($_GET["fHeightSignalInterlaced"]))
233 $_GET["fHeightSignalInterlaced"]="Off";
234
235 if (empty($_GET["fHeightFWHMInterlaced"]))
236 $_GET["fHeightFWHMInterlaced"]="Off";
237
238 if (empty($_GET["fHasSignalInterlaced"]))
239 $_GET["fHasSignalInterlaced"]=$first?"On":"";
240
241 if (empty($_GET["fHasSignalInterlacedEnum"]))
242 $_GET["fHasSignalInterlacedEnum"]="0";
243
244 if (empty($_GET["fHasPedestalInterlaced"]))
245 $_GET["fHasPedestalInterlaced"]=$first?"On":"";
246
247 if (empty($_GET["fHasPedestalInterlacedEnum"]))
248 $_GET["fHasPedestalInterlacedEnum"]="0";
249
250 if (empty($_GET["fPositionAsymInterlaced"]))
251 $_GET["fPositionAsymInterlaced"]="Off";
252
253 if (empty($_GET["fHeightAsymInterlaced"]))
254 $_GET["fHeightAsymInterlaced"]="Off";
255
256 if (empty($_GET["fRunTypeName"]))
257 $_GET["fRunTypeName"]=$first?"On":"";
258
259 if (empty($_GET["fDataCheckDone"]))
260 $_GET["fDataCheckDone"]="Off";
261
262 if (empty($_GET["fDataCheckDoneStatus"]))
263 $_GET["fDataCheckDoneStatus"]=$first?"1":"";
264
265 if (empty($_GET["fRawFileAvail"]))
266 $_GET["fRawFileAvail"]="Off";
267
268 if (empty($_GET["fRawFileAvailStatus"]))
269 $_GET["fRawFileAvailStatus"]=$first?"1":"";
270
271 if (empty($_GET["fStartTime"]))
272 $_GET["fStartTime"]="Off";
273
274 if (empty($_GET["fFailedTime"]))
275 $_GET["fFailedTime"]="Off";
276
277 if (empty($_GET["fReturnCode"]))
278 $_GET["fReturnCode"]="Off";
279
280 if (empty($_GET["fProgramId"]))
281 $_GET["fProgramId"]="Off";
282
283 }
284
285 function PrintForm($_GET, $host, $user, $pw, $db)
286 {
287 printf("<center>\n");
288 printf("<form action=\"datacheck.php\" METHOD=\"GET\">\n");
289 printf(" <table>\n");
290 printf(" <tr>\n");
291
292 CheckBox("fLinks", "Links");
293 CheckBox("fEvents", "DataEvents");
294 CheckBox("fEventsInterlaced", "CalEvents");
295 CheckBox("fSequenceFirst", "Sequence#");
296
297 printf(" </tr><tr>\n");
298
299 CheckBox("fPositionSignal", "ArrTime");
300 CheckBox("fPositionFWHM", "ArrTimeFWHM");
301 CheckBox("fPositionSignalInterlaced", "ArrTimeCal");
302 CheckBox("fPositionFWHMInterlaced", "ArrTimeFWHMCal");
303
304 printf(" </tr><tr>\n");
305
306 CheckBox("fHeightSignal", "Signal");
307 CheckBox("fPositionFWHM", "SignalFWHM");
308 CheckBox("fHeightSignalInterlaced", "SignalCal");
309 CheckBox("fPositionFWHMInterlaced", "SignalFWHMCal");
310
311 printf(" </tr><tr>\n");
312
313 CheckBox("fPositionAsym", "ArrTimeAsym");
314 CheckBox("fHeightAsym", "SignalAsym");
315 CheckBox("fPositionAsymInterlaced", "ArrTimeAsymCal");
316 CheckBox("fHeightAsymInterlaced", "SignalAsymCal");
317
318 printf(" </tr><tr><td>\n");
319
320 PrintEnumMenu("fHasSignal", "HasSignal");
321 printf(" </td><td>\n");
322 PrintEnumMenu("fHasPedestal", "HasPedestal");
323 printf(" </td><td>\n");
324 PrintEnumMenu("fHasSignalInterlaced", "HasSignalCal");
325 printf(" </td><td>\n");
326 PrintEnumMenu("fHasPedestalInterlaced", "HasPedestalCal");
327
328 printf(" </td></tr><tr><td>\n");
329
330 PrintStatusMenu("fDataCheckDone", "DataCheck");
331 printf(" </td><td>\n");
332 PrintStatusMenu("fRawFileAvail", "RawFile");
333 printf("</td><td>\n");
334
335 PrintPullDown($host, $user, $pw, $db, "RunType", "fRunTypeName", "fRunTypeKEY", "Run Type");
336
337 printf(" </td></tr>\n");
338 printf(" </table>\n");
339
340 printf(" <table>\n");
341 printf(" <tr>\n");
342
343 CheckBox("fStartTime", "StartTime");
344 CheckBox("fFailedTime", "FailedTime");
345 CheckBox("fReturnCode", "RetCode");
346 CheckBox("fProgramId", "ProgramId");
347
348 printf(" </tr>\n");
349 printf(" </table>\n");
350 printf(" <p>\n");
351
352 if (empty($_GET["fRunMin"]))
353 $min = GetMin("fRunNumber", "RunData", $host, $user, $pw, $db);
354 else
355 $min = $_GET["fRunMin"];
356
357 if (empty($_GET["fRunMax"]))
358 $max = GetMax("fRunNumber", "RunData", $host, $user, $pw, $db);
359 else
360 $max = $_GET["fRunMax"];
361
362/*
363 printf("Date&nbsp;(yyyy-mm-dd)&nbsp;<input name=\"fDate\" type=\"text\" size=\"10\" maxlength=\"10\" value=\"");
364 if (!empty($_GET["fDate"]))
365 printf("%s", $_GET["fDate"]);
366 printf("\">&nbsp;&nbsp;&nbsp;\n");
367*/
368
369 printf("DataCheck&nbsp;from&nbsp;<input name=\"fRunMin\" type=\"text\" size=\"6\" maxlength=\"6\" value=\"%s\">\n", $min);
370 printf("to&nbsp;<input name=\"fRunMax\" type=\"text\" size=\"6\" maxlength=\"6\" value=\"%s\">&nbsp;&nbsp;&nbsp;\n", $max);
371
372 printf(" <P>\n");
373
374 printf(" Results:\n");
375 printf(" <select name=\"fNumResults\">\n");
376
377 $numres = array("10", "20", "50", "100", "200", "500");
378 foreach ($numres as $element)
379 {
380 if ($element==$_GET["fNumResults"])
381 printf("<option value=\"%s\" selected>%3s</option>\n", $element, $element);
382 else
383 printf("<option value=\"%s\">%3s</option>\n", $element, $element);
384 }
385 printf(" </select>\n");
386 printf(" &nbsp;&nbsp;&nbsp;\n");
387
388 ini_set("mysql.trace_mode", "Off");
389 ini_set("display_errors", "Off");
390
391 printf("<input class='Width' type='submit' value='Query Table'>&nbsp;&nbsp;&nbsp;\n");
392 printf("<input class='Width' type='button' value='Reset' onClick='self.location.href=\"datacheck.php\"'>&nbsp;&nbsp;&nbsp;\n");
393 if (strchr($_SERVER["REQUEST_URI"], '?')!=FALSE)
394 printf("<input class='Width' type='button' value='Get .txt' onClick='self.location.href=\"%s&fSendTxt=1\"'>&nbsp;&nbsp;&nbsp;\n", $_SERVER["REQUEST_URI"]);
395 if (strchr($_SERVER["REQUEST_URI"], '?')!=FALSE)
396 printf("<input class='Width' type='button' value='Print' onClick='self.location.href=\"%s&fPrintTable=1\"'>&nbsp;&nbsp;&nbsp;\n", $_SERVER["REQUEST_URI"]);
397 printf("</form>\n");
398 printf("</center>\n");
399 printf("</td>\n");
400 printf("</tr>\n");
401 printf("<tr class='Block'>\n");
402 printf("<td>\n");
403 }
404
405 function PrintPage($html, $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $checkenumgroup, $needs)
406 {
407 $db_id = mysql_connect($host, $user, $pw);
408 if ($db_id==FALSE)
409 {
410 printf("mysql_connect returned the following error: %s\n", mysql_error());
411 die("");
412 }
413 mysql_select_db($db);
414
415 $query0 = CreateQuery($_GET, $alias, $checkwhere, $checkgroup, $checkstatusgroup, $checkenumgroup, $needs);
416
417 $result0 = mysql_query($query0, $db_id);
418 $result1 = mysql_query("SELECT FOUND_ROWS()", $db_id);
419
420 if ($result0)
421 {
422 if ($html=="1" || $html=="2")
423 PrintMagicTable($result0, $alias, $rightalign, "", "", "", $result1);
424 else
425 PrintText($result0);
426
427 mysql_free_result($result0);
428 mysql_free_result($result1);
429 }
430 mysql_close($db_id);
431
432 if ($html=="1")
433 PrintSubmittedQuery($query0, $db, "old");
434 }
435
436 include ("include.php");
437 include ("db.php");
438 include ("magicdefs.php");
439
440 ini_set("display_errors", "On");
441 ini_set("mysql.trace_mode", "On");
442
443 if (!empty($_GET["fSendTxt"]))
444 {
445 header("Content-type: application/octet");
446 header("Content-Disposition: attachment; filename=query-result.txt");
447
448 PrintPage("0", $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $checkenumgroup, $needs);
449 }
450 else
451 {
452 echo (file_get_contents("index-header.html"));
453
454 $environment = sizeof($_GET);
455
456 InitGet($_GET);
457 if (empty($_GET["fPrintTable"]))
458 PrintForm($_GET, $host, $user, $pw, $db);
459
460 if ($environment==0)
461 printf("No query submitted yet.<BR>");
462 else
463 {
464 if (empty($_GET["fPrintTable"]))
465 PrintPage("1", $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $checkenumgroup, $needs);
466 else
467 PrintPage("2", $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $checkenumgroup, $needs);
468 }
469
470 echo (file_get_contents("index-footer.html"));
471 }
472
473 ini_set("display_errors", "Off");
474 ini_set("mysql.trace_mode", "Off");
475}
476?>
Note: See TracBrowser for help on using the repository browser.