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