source: trunk/MagicSoft/Mars/datacenter/db/datacheck.php@ 7546

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