source: tags/Mars-V0.9.4.3/datacenter/db/dbstatus.php

Last change on this file was 7484, checked in by Daniela Dorner, 19 years ago
*** empty log message ***
  • Property svn:executable set to *
File size: 14.7 KB
Line 
1<?php
2{
3 function CreateQuery($_GET, $alias)
4 {
5 $joins = array
6 (
7 "fSourceName" => " LEFT JOIN Source ON Sequences.fSourceKEY=Source.fSourceKEY ",
8 );
9
10 $checkwhere = array
11 (
12 "fSourceName" => CheckWhere("fSourceKEY", $_GET),
13 );
14 $checkgroup = array
15 (
16 "fSourceName" => CheckGroup("fSourceKEY", $_GET),
17 );
18
19 $checkstatusgroup = array
20 (
21 "fAllFilesAvail" => CheckStatusGroup("fAllFilesAvailStatus", $_GET),
22 "fCallisto" => CheckStatusGroup("fCallistoStatus", $_GET),
23 "fFillCallisto" => CheckStatusGroup("fFillCallistoStatus", $_GET),
24 "fStar" => CheckStatusGroup("fStarStatus", $_GET),
25 "fFillStar" => CheckStatusGroup("fFillStarStatus", $_GET),
26 );
27
28 $check = array
29 (
30 "fSourceName" => " Sequences.fSourceKEY",
31 );
32
33 $table = array
34 (
35 "fSourceName" => "Source.fSourceName",
36 "fAllFilesAvail" => "SequenceProcessStatus.fAllFilesAvail",
37 "fCallisto" => "SequenceProcessStatus.fCallisto",
38 "fFillCallisto" => "SequenceProcessStatus.fFillCallisto",
39 "fStar" => "SequenceProcessStatus.fStar",
40 "fFillStar" => "SequenceProcessStatus.fFillStar",
41 );
42
43 $groups = 0;
44 foreach ($checkgroup as $element)
45 if ($element==-1)
46 $groups++;
47
48 $statusgroups = 0;
49 foreach ($checkstatusgroup as $element)
50 if ($element==-1)
51 $statusgroups++;
52
53 $query0 = "SELECT ";
54
55 if ($groups>0)
56 {
57 foreach ($checkgroup as $key => $element)
58 if ($element==-1)
59 $query0 .= $key . " as '" . $alias[$key] . "' " . ", ";
60 //--------------------------------------------------
61 $query0 .= "SUM(fRunTime)/3600 as '" . $alias["SUM(fRunTime)/3600"] . "', ";
62 //--------------------------------------------------
63 $query0 .= " SUM(fNumEvents) as '" . $alias["SUM(fNumEvents)"] . "', ";
64 $query0 .= " Min(fZenithDistanceMin) as '" . $alias["Min(fZenithDistanceMin)"] . "', ";
65 $query0 .= " Max(fZenithDistanceMax) as '" . $alias["Max(fZenithDistanceMax)"] . "', ";
66 $query0 .= " COUNT(*) as 'Sequence#' ";
67 }
68 else
69 {
70 if ($statusgroups>0)
71 {
72 foreach ($checkstatusgroup as $key => $element)
73 if ($element==-1)
74 $query0 .= " (if(IsNull(" . $key . "), 'not done' ,if(" . $key . "='1970-01-01 00:00:00','dont do','done'))) as '" . $alias[$key] . "', ";
75
76 $query0 .= " count(*) as 'Sequence#'";
77
78 }
79 else
80 {
81 if (!empty($_GET["fSendTxt"]))
82 $query0 .= " Sequences.fSequenceFirst ";
83 else
84 $query0 .= " CONCAT('<A&ws;HREF=\"runinfo.php?', 'fRunStart=On', '&fZenithDistance=On', '&fRunMin=', Sequences.fSequenceFirst, '&fMeanTriggerRate=On', '&fRunTypeName=On', '&fRunMax=', fSequenceLast, '&fNumEvents=On', '&fSourceName=On&', 'fExcludedFDAKEY=1', '&fSequenceFirst=On', '&fRawFileAvail=On', '&fCCFileAvail=On', '&fCaCoFileAvail=On\">', Sequences.fSequenceFirst, '</A>') ";
85 $query0 .= " as 'Sequence#' ";
86
87 foreach ($_GET as $key => $element)
88 if ($_GET[$key]=="On")
89 if (empty($checkwhere[$key]) || $checkwhere[$key]==0)
90 $query0 .= ", " . $key . " as '" . $alias[$key] . "' ";
91 }
92 }
93
94 $query0 .= " FROM Sequences ";
95
96 $query0 .= " LEFT JOIN SequenceProcessStatus ON Sequences.fSequenceFirst=SequenceProcessStatus.fSequenceFirst ";
97
98 $query0 .= " LEFT JOIN Calibration ON Sequences.fSequenceFirst=Calibration.fSequenceFirst ";
99
100 $query0 .= " LEFT JOIN Star ON Sequences.fSequenceFirst=Star.fSequenceFirst ";
101
102 foreach ($_GET as $key => $element)
103 if (($_GET[$key]=="On" || $groups>0) && !empty($joins[$key]))
104 $query0 .= $joins[$key];
105
106 foreach ($checkwhere as $key => $element)
107 {
108 if (empty($element) || $element<=0)
109 continue;
110
111 if (strpos($query0, " WHERE ")==FALSE)
112 $query0 .= " WHERE ";
113 else
114 if ($element!=-1)
115 if (strrpos($query0, " AND ")!=strlen($query0)-5)
116 $query0 .= " AND ";
117
118 if ($element!=-1)
119 $query0 .= $check[$key] . "=" . $element;
120 }
121
122 if (strpos($query0, " WHERE ")==FALSE)
123 $query0 .= " WHERE ";
124 else
125 $query0 .= " AND ";
126
127 $query0 .= StatusQuery("fSequenceFileWritten");
128 $query0 .= StatusQuery("fAllFilesAvail");
129 $query0 .= StatusQuery("fCallisto");
130 $query0 .= StatusQuery("fFillCallisto");
131 $query0 .= StatusQuery("fStar");
132 $query0 .= StatusQuery("fFillStar");
133
134 if (!empty($_GET["fRunMin"]) && !empty($_GET["fRunMax"]))
135 $query0 .= "Sequences.fSequenceFirst BETWEEN " . $_GET["fRunMin"] . " AND " . $_GET["fRunMax"] . " ";
136 else
137 $query0 = substr($query0, 0, -4);
138
139/*
140 if (!empty($_GET["fDate"]))
141 $query0 .= " AND fRunStart REGEXP \"^" . $_GET["fDate"] . "\" ";
142*/
143
144 if (!empty($_GET["fSourceN"]))
145 $query0 .= " AND fSourceName REGEXP \"^" . $_GET["fSourceN"] . "\" ";
146
147 if (!empty($_GET["fStartDate"]))
148 {
149 if (strpos(strrev($query0), " DNA ")!=0 || !strpos(strrev($query0), " DNA "))
150 $query0 .= " AND ";
151
152 $startdate=substr($_GET["fStartDate"], 0, 10);
153 if ($startdate=="0000-00-00")
154 $query0 .=" fRunStart >= '" . $startdate . " 00:00:00' ";
155 else
156 $query0 .= " fRunStart >= ADDDATE('" . $startdate . " 13:00:00', INTERVAL -1 DAY) ";
157 }
158
159 if (!empty($_GET["fStopDate"]))
160 {
161 if (strpos(strrev($query0), " DNA ")!=0 || !strpos(strrev($query0), " DNA "))
162 $query0 .= " AND ";
163
164 $stopdate=substr($_GET["fStopDate"], 0, 10);
165 $query0 .= " fRunStart < '" . $stopdate . " 13:00:00' ";
166 }
167
168 if ($groups>0)
169 {
170 $query0 .= " GROUP BY ";
171 $num = $groups;
172 foreach ($checkgroup as $key => $element)
173 if ($element==-1)
174 {
175 $query0 .= $check[$key];
176 if ($num-->1)
177 $query0 .= ", ";
178 }
179 }
180
181 if ($statusgroups>0)
182 {
183 $query0 .= " GROUP BY ";
184 $num = $statusgroups;
185 foreach ($checkstatusgroup as $key => $element)
186 if ($element==-1)
187 {
188 $query0 .= $alias[$key];
189 if ($num-->1)
190 $query0 .= ", ";
191 }
192 }
193
194 if (!empty($_GET["fSortBy"]))
195 {
196 $val=substr($_GET["fSortBy"], 0, -1);
197 $query0 .= " ORDER BY " . GetTable($fromtable, $val) . " ";
198 if (substr($_GET["fSortBy"], -1)=="-")
199 $query0 .= "DESC";
200 }
201
202 if (empty($_GET["fSortBy"]) && $groups==0 && $statusgroups==0)
203 $query0 .= "ORDER BY Sequences.fSequenceFirst ASC ";
204
205 if (empty($_GET["fNumStart"]))
206 $_GET["fNumStart"]=0;
207
208 return $query0;
209 }
210
211 function InitGet($_GET)
212 {
213 // Find out whether it is the first call to the php script
214 $first = empty($_GET["fRunMin"]) && empty($_GET["fRunMax"]);
215
216 if (empty($_GET["fSourceName"]))
217 $_GET["fSourceName"]=$first?"On":"";
218
219 if (empty($_GET["fAllFilesAvail"]))
220 $_GET["fAllFilesAvail"]="On";
221
222 if (empty($_GET["fAllFilesAvailStatus"]))
223 $_GET["fAllFilesAvailStatus"]="4";
224
225 if (empty($_GET["fCallisto"]))
226 $_GET["fCallisto"]="On";
227
228 if (empty($_GET["fCallistoStatus"]))
229 $_GET["fCallistoStatus"]="4";
230
231 if (empty($_GET["fFillCallisto"]))
232 $_GET["fFillCallisto"]="Off";
233
234 if (empty($_GET["fFillCallistoStatus"]))
235 $_GET["fFillCallistoStatus"]="0";
236
237 if (empty($_GET["fStar"]))
238 $_GET["fStar"]=$first?"On":"";
239
240 if (empty($_GET["fStarStatus"]))
241 $_GET["fStarStatus"]="4";
242
243 if (empty($_GET["fFillStar"]))
244 $_GET["fFillStar"]="Off";
245
246 if (empty($_GET["fFillStarStatus"]))
247 $_GET["fFillStarStatus"]="0";
248 }
249
250 function PrintForm($_GET, $db)
251 {
252 printf("<center>\n");
253 printf("<form action=\"dbstatus.php\" METHOD=\"GET\">\n");
254 printf(" <table><tr><td>\n");
255
256 PrintStatusMenu("fAllFilesAvail", "Files avail");
257 printf(" </td><td>\n");
258 PrintStatusMenu("fCallisto", "Callisto");
259 printf(" </td><td>\n");
260 PrintStatusMenu("fStar", "Star");
261 printf(" </td><td>\n");
262 PrintStatusMenu("fFillCallisto", "Fillcallisto");
263 printf(" </td><td>\n");
264 PrintStatusMenu("fFillStar", "Fillstar");
265
266 printf("</td></tr> </table>\n");
267 printf(" <p>\n");
268
269 // pull down boxes
270
271 printf(" <table>\n");
272 printf(" <tr><td>\n");
273 PrintPullDown($db, "Source", "fSourceName", "fSourceKEY", "Source Name");
274 printf(" </td><td>\n");
275
276 printf("&nbsp;&nbsp;&nbsp;Source&nbsp;(<A HREF=\"regexp.html\">regexp</A>)&nbsp;<input name=\"fSourceN\" type=\"text\" size=\"15\" maxlength=\"15\" value=\"");
277 if (!empty($_GET["fSourceN"]))
278 printf("%s", $_GET["fSourceN"]);
279 printf("\">&nbsp;&nbsp;&nbsp;\n");
280
281 printf(" </td></tr>\n");
282 printf(" </table>\n");
283 printf(" <p>\n");
284
285 if (empty($_GET["fStartDate"]))
286 $timemin = GetMin("fRunStart", "Sequences", $db);
287 else
288 $timemin = $_GET["fStartDate"];
289
290 if (empty($_GET["fStopDate"]))
291 $timemax = GetMax("fRunStart", "Sequences", $db);
292 else
293 $timemax = $_GET["fStopDate"];
294
295 printf("Night&nbsp;(yyyy-mm-dd)&nbsp;from&nbsp;<input name=\"fStartDate\" type=\"text\" size=\"10\" maxlength=\"10\" value=\"%s\">\n", $timemin);
296 printf("to&nbsp;<input name=\"fStopDate\" type=\"text\" size=\"10\" maxlength=\"10\" value=\"%s\">&nbsp;&nbsp;&nbsp;&nbsp;\n", $timemax);
297
298 if (empty($_GET["fRunMin"]))
299 $min = GetMin("fSequenceFirst", "Sequences", $db);
300 else
301 $min = $_GET["fRunMin"];
302
303 if (empty($_GET["fRunMax"]))
304 $max = GetMax("fSequenceFirst", "Sequences", $db);
305 else
306 $max = $_GET["fRunMax"];
307
308 printf("Sequences&nbsp;from&nbsp;<input name=\"fRunMin\" type=\"text\" size=\"6\" maxlength=\"6\" value=\"%s\">\n", $min);
309 printf("to&nbsp;<input name=\"fRunMax\" type=\"text\" size=\"6\" maxlength=\"6\" value=\"%s\">&nbsp;&nbsp;&nbsp;\n", $max);
310
311 printf(" <P>\n");
312
313 printf(" &nbsp;&nbsp;&nbsp;\n");
314
315 ini_set("mysql.trace_mode", "Off");
316 ini_set("display_errors", "Off");
317
318 printf("<input class='Width' type='submit' value='Query Table'>&nbsp;&nbsp;&nbsp;\n");
319 printf("<input class='Width' type='button' value='Reset' onClick='self.location.href=\"sequinfo.php\"'>&nbsp;&nbsp;&nbsp;\n");
320 if (strchr($_SERVER["REQUEST_URI"], '?')!=FALSE)
321 printf("<input class='Width' type='button' value='Get .txt' onClick='self.location.href=\"%s&fSendTxt=1\"'>&nbsp;&nbsp;&nbsp;\n", $_SERVER["REQUEST_URI"]);
322 if (strchr($_SERVER["REQUEST_URI"], '?')!=FALSE)
323 printf("<input class='Width' type='button' value='Print' onClick='self.location.href=\"%s&fPrintTable=1\"'>&nbsp;&nbsp;&nbsp;\n", $_SERVER["REQUEST_URI"]);
324 printf("</form>\n");
325 printf("</center>\n");
326 printf("</td>\n");
327 printf("</tr>\n");
328 printf("<tr class='Block'>\n");
329 printf("<td>\n");
330 }
331
332 function PrintPage($html, $db)
333 {
334 $db_id = mysql_connect("hercules.astro.uni-wuerzburg.de", "MAGIC", "d99swMT!");
335 if ($db_id==FALSE)
336 {
337 printf("mysql_connect returned the following error: %s\n", mysql_error());
338 die("");
339 }
340 mysql_select_db($db);
341
342 $alias = array
343 (
344 "fSourceName" => "Source",
345 "fAllFilesAvail" => "FilesAvail",
346 "fCallisto" => "Callisto",
347 "fStar" => "Star",
348 "fFillCallisto" => "FillCal",
349 "fFillStar" => "FillStar",
350 );
351 $rightalign = array
352 (
353 );
354
355 $query0 = CreateQuery($_GET, $alias);
356
357 $result0 = mysql_query($query0, $db_id);
358
359 if ($result0)
360 {
361 if ($html=="1" || $html=="2")
362 PrintMagicTable($result0, $alias, $rightalign, "", "", $_GET);
363 else
364 PrintText($result0);
365
366 mysql_free_result($result0);
367 }
368 mysql_close($db_id);
369
370 if ($html=="1")
371 printf("<U><B>submitted query:</B></U><BR>%s<BR>", htmlspecialchars($query0));
372 }
373
374 include ("include.php");
375 include ("db.php");
376
377 ini_set("display_errors", "On");
378 ini_set("mysql.trace_mode", "On");
379
380 if (!empty($_GET["fSendTxt"]))
381 {
382 header("Content-type: application/octet");
383 header("Content-Disposition: attachment; filename=query-result.txt");
384
385 PrintPage("0", $db);
386 }
387 else
388 {
389 echo (file_get_contents("index-header.html"));
390
391 $environment = sizeof($_GET);
392
393 InitGet($_GET);
394 if (empty($_GET["fPrintTable"]))
395 PrintForm($_GET, $db);
396
397 if ($environment==0)
398 printf("No query submitted yet.<BR>");
399 else
400 {
401 if (empty($_GET["fPrintTable"]))
402 PrintPage("1", $db);
403 else
404 PrintPage("2", $db);
405 }
406
407 echo (file_get_contents("index-footer.html"));
408 }
409
410 ini_set("display_errors", "Off");
411 ini_set("mysql.trace_mode", "Off");
412}
413?>
Note: See TracBrowser for help on using the repository browser.