1 | <?php
|
---|
2 | {
|
---|
3 | function CreateQuery($_GET, $alias, $checkwhere, $checkgroup, $checkstatusgroup, $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 | $query0 = "SELECT ";
|
---|
18 |
|
---|
19 | if ($groups>0)
|
---|
20 | {
|
---|
21 | foreach ($checkgroup as $key => $element)
|
---|
22 | if ($element==-1)
|
---|
23 | $query0 .= $key . " as '" . $alias[$key] . "' " . ", ";
|
---|
24 | //--------------------------------------------------
|
---|
25 | //$query0 .= " TIMEDIFF(fRunStop, fRunStart), ";
|
---|
26 | // Only available in MySQL>4.1.1
|
---|
27 | $query0 .= "SUM(if(TIME_TO_SEC(fRunStop)-TIME_TO_SEC(fRunStart)<0, " .
|
---|
28 | "TIME_TO_SEC(fRunStop)-TIME_TO_SEC(fRunStart)+24*60*60, " .
|
---|
29 | "TIME_TO_SEC(fRunStop)-TIME_TO_SEC(fRunStart)))/3600 as '" . $alias["SUM(fRunTime)/3600"] . "', ";
|
---|
30 | //--------------------------------------------------
|
---|
31 | $query0 .= " SUM(fNumEvents) as '" . $alias["SUM(fNumEvents)"] . "', ";
|
---|
32 | $query0 .= " Min(fZenithDistance) as '" . $alias["Min(fZenithDistance)"] . "', ";
|
---|
33 | $query0 .= " Max(fZenithDistance) as '" . $alias["Max(fZenithDistance)"] . "', ";
|
---|
34 | $query0 .= " COUNT(*) as '# Runs' ";
|
---|
35 | }
|
---|
36 | else
|
---|
37 | {
|
---|
38 | if ($statusgroups>0)
|
---|
39 | {
|
---|
40 | foreach ($checkstatusgroup as $key => $element)
|
---|
41 | if ($element==-1)
|
---|
42 | $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] . "', ";
|
---|
43 | // $query0 .= " (if(IsNull(" . $key . "), 'not done' ,if(" . $key . "='1970-01-01 00:00:00','dont do','done'))) as '" . $alias[$key] . "', ";
|
---|
44 |
|
---|
45 | $query0 .= " count(*) as '# Runs'";
|
---|
46 |
|
---|
47 | }
|
---|
48 | else
|
---|
49 | {
|
---|
50 | $query0 .= " RunData.fRunNumber as 'Run#' ";
|
---|
51 |
|
---|
52 | foreach ($_GET as $key => $element)
|
---|
53 | if ($_GET[$key]=="On" && $key!="fTest")
|
---|
54 | if (empty($checkwhere[$key]) || $checkwhere[$key]==0)
|
---|
55 | $query0 .= ", " . $key . " as '" . $alias[$key] . "' ";
|
---|
56 | }
|
---|
57 | }
|
---|
58 |
|
---|
59 | $query0 .= " FROM RunData ";
|
---|
60 |
|
---|
61 | $query0 .= " LEFT JOIN RunProcessStatus ON RunData.fRunNumber=RunProcessStatus.fRunNumber ";
|
---|
62 |
|
---|
63 | foreach ($_GET as $key => $element)
|
---|
64 | if (($_GET[$key]=="On" || $groups>0))// && !empty($joins[$key]))
|
---|
65 | $query0 .= GetJoin($fromtable,$key);
|
---|
66 |
|
---|
67 | if ($_GET["fTest"]!="On")
|
---|
68 | {
|
---|
69 | if ($_GET["fSourceName"]!="On")
|
---|
70 | $query0 .= " LEFT JOIN Source ON Sequences.fSourceKEY=Source.fSourceKEY ";
|
---|
71 | $query0 .= " WHERE fTest='no'";
|
---|
72 | }
|
---|
73 |
|
---|
74 | foreach ($checkwhere as $key => $element)
|
---|
75 | {
|
---|
76 | if (empty($element) || $element<=0)
|
---|
77 | continue;
|
---|
78 |
|
---|
79 | if (strpos($query0, " WHERE ")==FALSE)
|
---|
80 | $query0 .= " WHERE ";
|
---|
81 | else
|
---|
82 | if ($element!=-1)
|
---|
83 | if (strrpos($query0, " AND ")!=strlen($query0)-5)// this if clause doesn't work
|
---|
84 | $query0 .= " AND ";
|
---|
85 |
|
---|
86 | if ($element!=-1)
|
---|
87 | $query0 .= GetCheck($fromtable, $key) . "=" . $element;
|
---|
88 | }
|
---|
89 |
|
---|
90 | if (strpos($query0, " WHERE ")==FALSE)
|
---|
91 | $query0 .= " WHERE ";
|
---|
92 | else
|
---|
93 | $query0 .= " AND ";
|
---|
94 |
|
---|
95 | $query0 .= StatusQuery("fCCFileAvail", $needs);
|
---|
96 | $query0 .= StatusQuery("fCaCoFileAvail", $needs);
|
---|
97 | $query0 .= StatusQuery("fCaCoFileFound", $needs);
|
---|
98 | $query0 .= StatusQuery("fRawFileAvail", $needs);
|
---|
99 | $query0 .= StatusQuery("fDataCheckDone", $needs);
|
---|
100 | $query0 .= StatusQuery("fTimingCorrection", $needs);
|
---|
101 |
|
---|
102 | if (!empty($_GET["fRunMin"]) && !empty($_GET["fRunMax"]))
|
---|
103 | $query0 .= "RunData.fRunNumber BETWEEN " . $_GET["fRunMin"] . " AND " . $_GET["fRunMax"] . " ";
|
---|
104 |
|
---|
105 | if (!empty($_GET["fZDMin"]) && !empty($_GET["fZDMax"]))
|
---|
106 | $query0 .= "AND fZenithDistance BETWEEN " . $_GET["fZDMin"] . " AND " . $_GET["fZDMax"] . " ";
|
---|
107 |
|
---|
108 | /*
|
---|
109 | if (!empty($_GET["fDate"]))
|
---|
110 | $query0 .= " AND fRunStart REGEXP \"^" . $_GET["fDate"] . "\" ";
|
---|
111 | */
|
---|
112 |
|
---|
113 | if (!empty($_GET["fSourceN"]))
|
---|
114 | $query0 .= " AND fSourceName REGEXP \"^" . $_GET["fSourceN"] . "\" ";
|
---|
115 |
|
---|
116 | if (!empty($_GET["fStartDate"]))
|
---|
117 | {
|
---|
118 | if (strpos(strrev($query0), " DNA ")!=0)
|
---|
119 | $query0 .= " AND ";
|
---|
120 |
|
---|
121 | $startdate=substr($_GET["fStartDate"], 0, 10);
|
---|
122 | if ($startdate=="0000-00-00")
|
---|
123 | $query0 .=" fRunStart >= '" . $startdate . " 00:00:00' ";
|
---|
124 | else
|
---|
125 | $query0 .= " fRunStart >= ADDDATE('" . $startdate . " 13:00:00', INTERVAL -1 DAY) ";
|
---|
126 | }
|
---|
127 |
|
---|
128 | if (!empty($_GET["fStopDate"]))
|
---|
129 | {
|
---|
130 | if (strpos(strrev($query0), " DNA ")!=0)
|
---|
131 | $query0 .= " AND ";
|
---|
132 |
|
---|
133 | $stopdate=substr($_GET["fStopDate"], 0, 10);
|
---|
134 | $query0 .= " fRunStart < '" . $stopdate . " 13:00:00' ";
|
---|
135 | }
|
---|
136 |
|
---|
137 | if (!empty($_GET["fSequenceNo"]) || $_GET["fSequenceNo"]=="0")
|
---|
138 | {
|
---|
139 | if (strpos(strrev($query0), " DNA ")!=0)
|
---|
140 | $query0 .= " AND ";
|
---|
141 |
|
---|
142 | $query0 .= " fSequenceFirst = '" . $_GET["fSequenceNo"] . "' ";
|
---|
143 | }
|
---|
144 |
|
---|
145 |
|
---|
146 | if ($groups>0)
|
---|
147 | {
|
---|
148 | $query0 .= " GROUP BY ";
|
---|
149 | $num = $groups;
|
---|
150 | foreach ($checkgroup as $key => $element)
|
---|
151 | if ($element==-1)
|
---|
152 | {
|
---|
153 | $query0 .= GetCheck($fromtable,$key);
|
---|
154 | if ($num-->1)
|
---|
155 | $query0 .= ", ";
|
---|
156 | }
|
---|
157 | }
|
---|
158 |
|
---|
159 | if ($statusgroups>0)
|
---|
160 | {
|
---|
161 | $query0 .= " GROUP BY ";
|
---|
162 | $num = $statusgroups;
|
---|
163 | foreach ($checkstatusgroup as $key => $element)
|
---|
164 | if ($element==-1)
|
---|
165 | {
|
---|
166 | $query0 .= $alias[$key];
|
---|
167 | if ($num-->1)
|
---|
168 | $query0 .= ", ";
|
---|
169 | }
|
---|
170 | }
|
---|
171 |
|
---|
172 | if (!empty($_GET["fSortBy"]))
|
---|
173 | {
|
---|
174 | $val=substr($_GET["fSortBy"], 0, -1);
|
---|
175 | // $query0 .= "---" . $val . "---";
|
---|
176 | $query0 .= " ORDER BY " . GetTable($fromtable, $val) . " ";
|
---|
177 | if (substr($_GET["fSortBy"], -1)=="-")
|
---|
178 | $query0 .= "DESC";
|
---|
179 | }
|
---|
180 |
|
---|
181 | if (empty($_GET["fNumStart"]))
|
---|
182 | $_GET["fNumStart"]=0;
|
---|
183 |
|
---|
184 | if (empty($_GET["fSendTxt"]))
|
---|
185 | $query0 .= " LIMIT " . $_GET["fNumStart"] . ", " . $_GET["fNumResults"];
|
---|
186 |
|
---|
187 | return $query0;
|
---|
188 | }
|
---|
189 |
|
---|
190 | function InitGet($_GET)
|
---|
191 | {
|
---|
192 | // Find out whether it is the first call to the php script
|
---|
193 | $first = empty($_GET["fRunMin"]) && empty($_GET["fRunMax"]);
|
---|
194 |
|
---|
195 | if (empty($_GET["fNumResults"]))
|
---|
196 | $_GET["fNumResults"]="20";
|
---|
197 |
|
---|
198 | if (empty($_GET["fTest"]))
|
---|
199 | $_GET["fTest"]=$first?"On":"";
|
---|
200 |
|
---|
201 | if (empty($_GET["fNumEvents"]))
|
---|
202 | $_GET["fNumEvents"]=$first?"On":"";
|
---|
203 |
|
---|
204 | if (empty($_GET["fRunStart"]))
|
---|
205 | $_GET["fRunStart"]=$first?"On":"";
|
---|
206 |
|
---|
207 | if (empty($_GET["fZenithDistance"]))
|
---|
208 | $_GET["fZenithDistance"]=$first?"On":"";
|
---|
209 |
|
---|
210 | if (empty($_GET["fRunTypeName"]))
|
---|
211 | $_GET["fRunTypeName"]=$first?"On":"";
|
---|
212 |
|
---|
213 | if (empty($_GET["fSourceName"]))
|
---|
214 | $_GET["fSourceName"]=$first?"On":"";
|
---|
215 |
|
---|
216 | if (empty($_GET["fMeanTriggerRate"]))
|
---|
217 | $_GET["fMeanTriggerRate"]=$first?"On":"";
|
---|
218 |
|
---|
219 | if (empty($_GET["fExcludedFDAName"]))
|
---|
220 | $_GET["fExcludedFDAName"]=$first?"On":"";
|
---|
221 |
|
---|
222 | if (empty($_GET["fSequenceNo"]))
|
---|
223 | $_GET["fSequenceNo"]="";
|
---|
224 |
|
---|
225 | InitRunInfo($_GET);
|
---|
226 | }
|
---|
227 |
|
---|
228 | function PrintForm($_GET, $host, $user, $pw, $db)
|
---|
229 | {
|
---|
230 | printf("<center>\n");
|
---|
231 | printf("<form action=\"runinfo-aio.php\" METHOD=\"GET\">\n");
|
---|
232 |
|
---|
233 | printf("<input id='sh' type='hidden' name='fShowHide' value='");
|
---|
234 | if (!empty($_GET["fShowHide"]))
|
---|
235 | printf("%s", $_GET["fShowHide"]);
|
---|
236 | else
|
---|
237 | printf("1000000000");
|
---|
238 | printf("'>\n");
|
---|
239 | printf("<img id='allbutton' src='../minus.png' onclick=showhide('all')> Menu \n");
|
---|
240 | printf("<img id='infobutton' src='../plus.png' onClick=showhide('info');showhide('info2')>RunInfo \n");
|
---|
241 | printf("<img id='statbutton' src='../plus.png' onClick=showhide('stat');showhide('fail')> StatusInfo \n");
|
---|
242 | printf("<img id='rangesbutton' src='../plus.png' onClick=showhide('ranges')> Ranges \n");
|
---|
243 |
|
---|
244 | printf(" <div id='all' style='display:block'>");
|
---|
245 | PrintRunInfoMenu();
|
---|
246 | PrintRunInfo2Menu($host,$user,$pw,$db);
|
---|
247 | PrintRunStatMenu();
|
---|
248 | PrintFailMenu();
|
---|
249 | printf(" <div id='ranges' style='display:none'>");
|
---|
250 | PrintSequMenu($host,$user,$pw,$db);
|
---|
251 | PrintNightRangeMenu($host,$user,$pw,$db);
|
---|
252 | printf("<p>");
|
---|
253 | PrintZdRangeMenu($host,$user,$pw,$db);
|
---|
254 | PrintRunRangeMenu($host,$user,$pw,$db);
|
---|
255 | printf(" <P>\n");
|
---|
256 | PrintSourceMenu($host,$user,$pw,$db);
|
---|
257 | PrintNumResPullDown();
|
---|
258 | printf("<p>");
|
---|
259 | printf("</div>");
|
---|
260 | printf("</div>");
|
---|
261 | printf(" <P>\n");
|
---|
262 |
|
---|
263 | ini_set("mysql.trace_mode", "Off");
|
---|
264 | ini_set("display_errors", "Off");
|
---|
265 |
|
---|
266 | PrintButtons("runinfo-aio.php");
|
---|
267 |
|
---|
268 | printf("</form>\n");
|
---|
269 | printf("</center>\n");
|
---|
270 | printf("</td>\n");
|
---|
271 | printf("</tr>\n");
|
---|
272 | printf("<tr class='Block'>\n");
|
---|
273 | printf("<td>\n");
|
---|
274 | }
|
---|
275 |
|
---|
276 | function PrintPage($html, $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $needs)
|
---|
277 | {
|
---|
278 | $db_id = mysql_connect($host, $user, $pw);
|
---|
279 | if ($db_id==FALSE)
|
---|
280 | {
|
---|
281 | printf("mysql_connect returned the following error: %s\n", mysql_error());
|
---|
282 | die("");
|
---|
283 | }
|
---|
284 | mysql_select_db($db);
|
---|
285 | mysql_query("SET BIG_TABLES=1"); // necessary for mySQL <= 4
|
---|
286 |
|
---|
287 | $query0 = CreateQuery($_GET, $alias, $checkwhere, $checkgroup, $checkstatusgroup, $needs);
|
---|
288 |
|
---|
289 | $result0 = mysql_query($query0, $db_id);
|
---|
290 |
|
---|
291 | if ($result0)
|
---|
292 | {
|
---|
293 | if ($html=="1" || $html=="2")
|
---|
294 | PrintMagicTable($result0, $alias, $rightalign, "", "", "", $_GET);
|
---|
295 | else
|
---|
296 | PrintText($result0);
|
---|
297 |
|
---|
298 | mysql_free_result($result0);
|
---|
299 | }
|
---|
300 | mysql_close($db_id);
|
---|
301 |
|
---|
302 | PrintSubmittedQuery($query0, $html, $db);
|
---|
303 | }
|
---|
304 |
|
---|
305 | include ("include.php");
|
---|
306 | include ("db.php");
|
---|
307 | include ("menu.php");
|
---|
308 | include ("magicdefs.php");
|
---|
309 |
|
---|
310 | ini_set("display_errors", "On");
|
---|
311 | ini_set("mysql.trace_mode", "On");
|
---|
312 |
|
---|
313 | if (!empty($_GET["fSendTxt"]))
|
---|
314 | {
|
---|
315 | header("Content-type: application/octet");
|
---|
316 | header("Content-Disposition: attachment; filename=query-result.txt");
|
---|
317 |
|
---|
318 | PrintPage("0", $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $needs);
|
---|
319 | }
|
---|
320 | else
|
---|
321 | {
|
---|
322 | echo (file_get_contents("index-header.html"));
|
---|
323 |
|
---|
324 | $environment = sizeof($_GET);
|
---|
325 |
|
---|
326 | InitGet($_GET);
|
---|
327 | if (empty($_GET["fPrintTable"]))
|
---|
328 | PrintForm($_GET, $host, $user, $pw, $db);
|
---|
329 |
|
---|
330 | if ($environment==0)
|
---|
331 | printf("No query submitted yet.<BR>");
|
---|
332 | else
|
---|
333 | {
|
---|
334 | if (empty($_GET["fPrintTable"]))
|
---|
335 | PrintPage("1", $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $needs);
|
---|
336 | else
|
---|
337 | PrintPage("2", $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $needs);
|
---|
338 | }
|
---|
339 |
|
---|
340 | echo (file_get_contents("index-footer.html"));
|
---|
341 | }
|
---|
342 |
|
---|
343 | ini_set("display_errors", "Off");
|
---|
344 | ini_set("mysql.trace_mode", "Off");
|
---|
345 | }
|
---|
346 | ?>
|
---|