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