source: trunk/MagicSoft/Mars/datacenter/db/dbstatus.php@ 8420

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