source: tags/Mars-V0.9.6/datacenter/db/datacheck.php

Last change on this file was 7638, checked in by Daniela Dorner, 19 years ago
*** empty log message ***
  • Property svn:executable set to *
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 ";
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 ON RunData.fRunNumber=RunProcessStatus.fRunNumber ";
79 $query0 .= " LEFT JOIN DataCheck ON DataCheck.fRunNumber=RunData.fRunNumber ";
80 $query0 .= " LEFT JOIN RunType ON RunType.fRunTypeKEY=RunData.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);
104 $query0 .= StatusQuery("fDataCheckDone", $needs);
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["fFailedCode"]))
281 $_GET["fFailedCode"]="Off";
282
283 if (empty($_GET["fFailedCodeAdd"]))
284 $_GET["fFailedCodeAdd"]="Off";
285
286 }
287
288 function PrintForm($_GET, $host, $user, $pw, $db)
289 {
290 printf("<center>\n");
291 printf("<form action=\"datacheck.php\" METHOD=\"GET\">\n");
292 printf(" <table>\n");
293 printf(" <tr>\n");
294
295 CheckBox("fLinks", "Links");
296 CheckBox("fEvents", "DataEvents");
297 CheckBox("fEventsInterlaced", "CalEvents");
298 CheckBox("fSequenceFirst", "Sequence#");
299
300 printf(" </tr><tr>\n");
301
302 CheckBox("fPositionSignal", "ArrTime");
303 CheckBox("fPositionFWHM", "ArrTimeFWHM");
304 CheckBox("fPositionSignalInterlaced", "ArrTimeCal");
305 CheckBox("fPositionFWHMInterlaced", "ArrTimeFWHMCal");
306
307 printf(" </tr><tr>\n");
308
309 CheckBox("fHeightSignal", "Signal");
310 CheckBox("fPositionFWHM", "SignalFWHM");
311 CheckBox("fHeightSignalInterlaced", "SignalCal");
312 CheckBox("fPositionFWHMInterlaced", "SignalFWHMCal");
313
314 printf(" </tr><tr>\n");
315
316 CheckBox("fPositionAsym", "ArrTimeAsym");
317 CheckBox("fHeightAsym", "SignalAsym");
318 CheckBox("fPositionAsymInterlaced", "ArrTimeAsymCal");
319 CheckBox("fHeightAsymInterlaced", "SignalAsymCal");
320
321 printf(" </tr><tr><td>\n");
322
323 PrintEnumMenu("fHasSignal", "HasSignal");
324 printf(" </td><td>\n");
325 PrintEnumMenu("fHasPedestal", "HasPedestal");
326 printf(" </td><td>\n");
327 PrintEnumMenu("fHasSignalInterlaced", "HasSignalCal");
328 printf(" </td><td>\n");
329 PrintEnumMenu("fHasPedestalInterlaced", "HasPedestalCal");
330
331 printf(" </td></tr><tr><td>\n");
332
333 PrintStatusMenu("fDataCheckDone", "DataCheck");
334 printf(" </td><td>\n");
335 PrintStatusMenu("fRawFileAvail", "RawFile");
336 printf("</td><td>\n");
337
338 PrintPullDown($host, $user, $pw, $db, "RunType", "fRunTypeName", "fRunTypeKEY", "Run Type");
339
340 printf(" </td></tr>\n");
341 printf(" </table>\n");
342
343 printf(" <table>\n");
344 printf(" <tr>\n");
345
346 CheckBox("fStartTime", "StartTime");
347 CheckBox("fFailedTime", "FailedTime");
348 CheckBox("fReturnCode", "ErrCode");
349 CheckBox("fFailedCode", "RetCode");
350 CheckBox("fFailedCodeAdd", "CodeAdd");
351
352 printf(" </tr>\n");
353 printf(" </table>\n");
354 printf(" <p>\n");
355
356 if (empty($_GET["fRunMin"]))
357 $min = GetMin("fRunNumber", "RunData", $host, $user, $pw, $db);
358 else
359 $min = $_GET["fRunMin"];
360
361 if (empty($_GET["fRunMax"]))
362 $max = GetMax("fRunNumber", "RunData", $host, $user, $pw, $db);
363 else
364 $max = $_GET["fRunMax"];
365
366/*
367 printf("Date&nbsp;(yyyy-mm-dd)&nbsp;<input name=\"fDate\" type=\"text\" size=\"10\" maxlength=\"10\" value=\"");
368 if (!empty($_GET["fDate"]))
369 printf("%s", $_GET["fDate"]);
370 printf("\">&nbsp;&nbsp;&nbsp;\n");
371*/
372
373 printf("DataCheck&nbsp;from&nbsp;<input name=\"fRunMin\" type=\"text\" size=\"6\" maxlength=\"6\" value=\"%s\">\n", $min);
374 printf("to&nbsp;<input name=\"fRunMax\" type=\"text\" size=\"6\" maxlength=\"6\" value=\"%s\">&nbsp;&nbsp;&nbsp;\n", $max);
375
376 printf(" <P>\n");
377
378 printf(" Results:\n");
379 printf(" <select name=\"fNumResults\">\n");
380
381 $numres = array("10", "20", "50", "100", "200", "500");
382 foreach ($numres as $element)
383 {
384 if ($element==$_GET["fNumResults"])
385 printf("<option value=\"%s\" selected>%3s</option>\n", $element, $element);
386 else
387 printf("<option value=\"%s\">%3s</option>\n", $element, $element);
388 }
389 printf(" </select>\n");
390 printf(" &nbsp;&nbsp;&nbsp;\n");
391
392 ini_set("mysql.trace_mode", "Off");
393 ini_set("display_errors", "Off");
394
395 printf("<input class='Width' type='submit' value='Query Table'>&nbsp;&nbsp;&nbsp;\n");
396 printf("<input class='Width' type='button' value='Reset' onClick='self.location.href=\"datacheck.php\"'>&nbsp;&nbsp;&nbsp;\n");
397 if (strchr($_SERVER["REQUEST_URI"], '?')!=FALSE)
398 printf("<input class='Width' type='button' value='Get .txt' onClick='self.location.href=\"%s&fSendTxt=1\"'>&nbsp;&nbsp;&nbsp;\n", $_SERVER["REQUEST_URI"]);
399 if (strchr($_SERVER["REQUEST_URI"], '?')!=FALSE)
400 printf("<input class='Width' type='button' value='Print' onClick='self.location.href=\"%s&fPrintTable=1\"'>&nbsp;&nbsp;&nbsp;\n", $_SERVER["REQUEST_URI"]);
401 printf("</form>\n");
402 printf("</center>\n");
403 printf("</td>\n");
404 printf("</tr>\n");
405 printf("<tr class='Block'>\n");
406 printf("<td>\n");
407 }
408
409 function PrintPage($html, $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $checkenumgroup, $needs)
410 {
411 $db_id = mysql_connect($host, $user, $pw);
412 if ($db_id==FALSE)
413 {
414 printf("mysql_connect returned the following error: %s\n", mysql_error());
415 die("");
416 }
417 mysql_select_db($db);
418
419 $query0 = CreateQuery($_GET, $alias, $checkwhere, $checkgroup, $checkstatusgroup, $checkenumgroup, $needs);
420
421 $result0 = mysql_query($query0, $db_id);
422
423 if ($result0)
424 {
425 if ($html=="1" || $html=="2")
426 PrintMagicTable($result0, $alias, $rightalign, "", "", $_GET);
427 else
428 PrintText($result0);
429
430 mysql_free_result($result0);
431 }
432 mysql_close($db_id);
433
434 if ($html=="1")
435 printf("<U><B>submitted query:</B></U><BR>%s<BR>", htmlspecialchars($query0));
436 }
437
438 include ("include.php");
439 include ("db.php");
440 include ("magicdefs.php");
441
442 ini_set("display_errors", "On");
443 ini_set("mysql.trace_mode", "On");
444
445 if (!empty($_GET["fSendTxt"]))
446 {
447 header("Content-type: application/octet");
448 header("Content-Disposition: attachment; filename=query-result.txt");
449
450 PrintPage("0", $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $checkenumgroup, $needs);
451 }
452 else
453 {
454 echo (file_get_contents("index-header.html"));
455
456 $environment = sizeof($_GET);
457
458 InitGet($_GET);
459 if (empty($_GET["fPrintTable"]))
460 PrintForm($_GET, $host, $user, $pw, $db);
461
462 if ($environment==0)
463 printf("No query submitted yet.<BR>");
464 else
465 {
466 if (empty($_GET["fPrintTable"]))
467 PrintPage("1", $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $checkenumgroup, $needs);
468 else
469 PrintPage("2", $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $checkenumgroup, $needs);
470 }
471
472 echo (file_get_contents("index-footer.html"));
473 }
474
475 ini_set("display_errors", "Off");
476 ini_set("mysql.trace_mode", "Off");
477}
478?>
Note: See TracBrowser for help on using the repository browser.