1 | <?php
|
---|
2 | {
|
---|
3 | function CreateQuery($_GET, $alias, $checkwhere, $checkgroup, $checkstatusgroup)
|
---|
4 | {
|
---|
5 | $fromtable="RunInfo";
|
---|
6 |
|
---|
7 | $groups = 0;
|
---|
8 | foreach ($checkgroup as $element)
|
---|
9 | if ($element==-1)
|
---|
10 | $groups++;
|
---|
11 |
|
---|
12 | $query0 = "SELECT SQL_CALC_FOUND_ROWS ";
|
---|
13 |
|
---|
14 | if ($groups>0)
|
---|
15 | {
|
---|
16 | foreach ($checkgroup as $key => $element)
|
---|
17 | if ($element==-1)
|
---|
18 | $query0 .= $key . " as '" . $alias[$key] . "' " . ", ";
|
---|
19 | //don't put a '#' at the beginning of the alias, else SortBy won't work anymore
|
---|
20 | $query0 .= " COUNT(*) as 'NumRuns', ";
|
---|
21 | //$query0 .= " Round(Sum(TimeDiff(fRunStop,fRunStart))/60./60.,2) as 'Time [h]' ";
|
---|
22 | $query0 .= " Sec_to_time(Sum(Time_to_sec(TimeDiff(fRunStop,fRunStart)))) as 'Time<br>[hh:mm:ss]' ";
|
---|
23 | }
|
---|
24 | else
|
---|
25 | {
|
---|
26 | $query0 .= " Concat(fNight,'_', LPAD(fRunID, 3, 0)) as 'Run' ";
|
---|
27 |
|
---|
28 | foreach ($_GET as $key => $element)
|
---|
29 | if ($_GET[$key]=="On")
|
---|
30 | if ($key!="fComments")
|
---|
31 | if (empty($checkwhere[$key]) || $checkwhere[$key]==0)
|
---|
32 | $query0 .= ", " . $key . " as '" . $alias[$key] . "' ";
|
---|
33 |
|
---|
34 | if (!empty($_GET["fComments"]))
|
---|
35 | {
|
---|
36 | //$query0 .= ", if (Count(fComment)>0, Concat('<a&ws;id=\'commentcell', fNight, fRunID, '\'&ws;href=\'run_comment.php?fNight=',fNight,'&fRunID=', fRunID, '\'&ws;onmouseover=\'get_comments(', fNight, ',', fRunID, ')\'>', Count(fComment), '</a>'), ' ') ";
|
---|
37 | $query0 .= ", CONCAT(if (Count(fComment)>0, Concat('<a&ws;id=\'commentcell', fNight, fRunID, '\'&ws;href=\'run_comment.php?fNight=',fNight,'&fRunID=', fRunID, '\'&ws;onmouseover=\'get_comments(', fNight, ',', fRunID, ')\'>', Count(fComment), '</a>')";
|
---|
38 | $query0 .= ", ' '), ' ', ";
|
---|
39 | $query0 .= "CONCAT('<a&ws;id=\'commentcell', fNight, fRunID, '\'&ws;href=\'../../logbook/calendar.php?calendar=1&year=', left(fNight,4), '&month=', left(right(fNight,4),2), '&day=', right(fNight,2), '&action=dayview\'>lbk</a>', '')) ";
|
---|
40 | //$query0 .= ", if (Count(fComment)>0, Concat('<a&ws;href=\'run_comment.php?fNight=',fNight,'&fRunID=', fRunID, '\'&ws;onmouseover=\'bla\'>', Count(fComment), '</a>'), ' ') ";
|
---|
41 | $query0 .= " as 'Comments'";
|
---|
42 | }
|
---|
43 |
|
---|
44 | }
|
---|
45 |
|
---|
46 | $query0 .= " FROM " . $fromtable;
|
---|
47 |
|
---|
48 | foreach ($_GET as $key => $element)
|
---|
49 | if (($_GET[$key]=="On" || $groups>0))// && !empty($joins[$key]))
|
---|
50 | $query0 .= GetJoin($fromtable, $key);
|
---|
51 | $query0 .= " LEFT JOIN RunComments USING (fNight, fRunID) ";
|
---|
52 |
|
---|
53 | foreach ($checkwhere as $key => $element)
|
---|
54 | {
|
---|
55 | if (empty($element) || $element<=0)
|
---|
56 | continue;
|
---|
57 |
|
---|
58 | if (strpos($query0, " WHERE ")==FALSE)
|
---|
59 | $query0 .= " WHERE ";
|
---|
60 | else
|
---|
61 | if ($element!=-1)
|
---|
62 | if (strrpos($query0, " AND ")!=strlen($query0)-5)// this if clause doesn't work
|
---|
63 | $query0 .= " AND ";
|
---|
64 |
|
---|
65 | if ($element!=-1)
|
---|
66 | $query0 .= GetCheck($fromtable, $key) . "=" . $element;
|
---|
67 | }
|
---|
68 |
|
---|
69 | if (strpos($query0, " WHERE ")==FALSE)
|
---|
70 | $query0 .= " WHERE ";
|
---|
71 | else
|
---|
72 | $query0 .= " AND ";
|
---|
73 |
|
---|
74 | if (!empty($_GET["fStartDate"]))
|
---|
75 | {
|
---|
76 | $startdate=substr($_GET["fStartDate"], 0, 10);
|
---|
77 | // if ($startdate=="0000-00-00")
|
---|
78 | $query0 .=" fNight >= " . $startdate . " ";
|
---|
79 | // else
|
---|
80 | // $query0 .= " fNight >= " . $startdate . " - 1 ";
|
---|
81 | }
|
---|
82 |
|
---|
83 | if (!empty($_GET["fStopDate"]))
|
---|
84 | {
|
---|
85 | // if (strpos(strrev($query0), " DNA ")!=0)
|
---|
86 | // $query0 .= " AND ";
|
---|
87 |
|
---|
88 | $stopdate=substr($_GET["fStopDate"], 0, 10);
|
---|
89 | $query0 .= " AND fNight <= " . $stopdate . " ";
|
---|
90 | }
|
---|
91 |
|
---|
92 | if ($groups>0)
|
---|
93 | {
|
---|
94 | $query0 .= " GROUP BY ";
|
---|
95 | $num = $groups;
|
---|
96 | foreach ($checkgroup as $key => $element)
|
---|
97 | if ($element==-1)
|
---|
98 | {
|
---|
99 | $query0 .= GetCheck($fromtable, $key);
|
---|
100 | if ($num-->1)
|
---|
101 | $query0 .= ", ";
|
---|
102 | }
|
---|
103 | }
|
---|
104 | else
|
---|
105 | $query0 .= " GROUP BY fNight, fRunID ";
|
---|
106 |
|
---|
107 |
|
---|
108 |
|
---|
109 | if (!empty($_GET["fSortBy"]))
|
---|
110 | {
|
---|
111 | $query0 .= " ORDER BY " . substr($_GET["fSortBy"], 0, -1) . " ";
|
---|
112 | if (substr($_GET["fSortBy"], -1)=="-")
|
---|
113 | $query0 .= "DESC";
|
---|
114 | }
|
---|
115 | else
|
---|
116 | if ($groups==0)
|
---|
117 | $query0 .= " ORDER BY Run DESC";
|
---|
118 |
|
---|
119 | if (empty($_GET["fNumStart"]))
|
---|
120 | $_GET["fNumStart"]=0;
|
---|
121 |
|
---|
122 | if (empty($_GET["fSendTxt"]))
|
---|
123 | $query0 .= " LIMIT " . $_GET["fNumStart"] . ", " . $_GET["fNumResults"];
|
---|
124 |
|
---|
125 | return $query0;
|
---|
126 | }
|
---|
127 |
|
---|
128 | function InitGet($_GET)
|
---|
129 | {
|
---|
130 | // Find out whether it is the first call to the php script
|
---|
131 | $first = empty($_GET["fStartDate"]) && empty($_GET["fStopDate"]);
|
---|
132 |
|
---|
133 | if (empty($_GET["fNumResults"]))
|
---|
134 | $_GET["fNumResults"]="200";
|
---|
135 |
|
---|
136 | if (empty($_GET["fNumEvents"]))
|
---|
137 | $_GET["fNumEvents"]=$first?"Off":"";
|
---|
138 |
|
---|
139 | if (empty($_GET["fComments"]))
|
---|
140 | $_GET["fComments"]=$first?"On":"";
|
---|
141 |
|
---|
142 | if (empty($_GET["fNumPhysicsTrigger"]))
|
---|
143 | $_GET["fNumPhysicsTrigger"]=$first?"On":"";
|
---|
144 |
|
---|
145 | if (empty($_GET["Round(fNumPhysicsTrigger/Time_to_sec(TimeDiff(fRunStop,fRunStart)),1)"]))
|
---|
146 | $_GET["Round(fNumPhysicsTrigger/Time_to_sec(TimeDiff(fRunStop,fRunStart)),1)"]=$first?"On":"";
|
---|
147 |
|
---|
148 | if (empty($_GET["fNumPedestalTrigger"]))
|
---|
149 | $_GET["fNumPedestalTrigger"]=$first?"On":"";
|
---|
150 |
|
---|
151 | if (empty($_GET["fNumELPTrigger"]))
|
---|
152 | $_GET["fNumELPTrigger"]=$first?"On":"";
|
---|
153 |
|
---|
154 | if (empty($_GET["fNumTimeTrigger"]))
|
---|
155 | $_GET["fNumTimeTrigger"]=$first?"Off":"";
|
---|
156 |
|
---|
157 | if (empty($_GET["fNumExt1Trigger"]))
|
---|
158 | $_GET["fNumExt1Trigger"]=$first?"Off":"";
|
---|
159 |
|
---|
160 | if (empty($_GET["fNumExt2Trigger"]))
|
---|
161 | $_GET["fNumExt2Trigger"]=$first?"Off":"";
|
---|
162 |
|
---|
163 | if (empty($_GET["fNumILPTrigger"]))
|
---|
164 | $_GET["fNumILPTrigger"]=$first?"Off":"";
|
---|
165 |
|
---|
166 | if (empty($_GET["fNumOtherTrigger"]))
|
---|
167 | $_GET["fNumOtherTrigger"]=$first?"Off":"";
|
---|
168 |
|
---|
169 | if (empty($_GET["TimeDiff(fRunStop,fRunStart)"]))
|
---|
170 | $_GET["TimeDiff(fRunStop,fRunStart)"]=$first?"On":"";
|
---|
171 |
|
---|
172 | if (empty($_GET["fRunStart"]))
|
---|
173 | $_GET["fRunStart"]=$first?"On":"";
|
---|
174 |
|
---|
175 | if (empty($_GET["fRunStop"]))
|
---|
176 | $_GET["fRunStop"]=$first?"Off":"";
|
---|
177 |
|
---|
178 | if (empty($_GET["fROI"]))
|
---|
179 | $_GET["fROI"]=$first?"On":"";
|
---|
180 |
|
---|
181 | if (empty($_GET["fROITimeMarker"]))
|
---|
182 | $_GET["fROITimeMarker"]=$first?"Off":"";
|
---|
183 |
|
---|
184 | if (empty($_GET["fFitsFileErrors"]))
|
---|
185 | $_GET["fFitsFileErrors"]=$first?"Off":"";
|
---|
186 |
|
---|
187 | if (empty($_GET["fCompileTime"]))
|
---|
188 | $_GET["fCompileTime"]=$first?"Off":"";
|
---|
189 |
|
---|
190 | if (empty($_GET["fRevisionNumber"]))
|
---|
191 | $_GET["fRevisionNumber"]=$first?"Off":"";
|
---|
192 |
|
---|
193 | if (empty($_GET["if(fHasDrsFile=0,\"N\",fDrsStep)"]))
|
---|
194 | $_GET["if(fHasDrsFile=0,\"N\",fDrsStep)"]=$first?"Off":"";
|
---|
195 |
|
---|
196 | if (empty($_GET["fMd5sumRaw"]))
|
---|
197 | $_GET["fMd5sumRaw"]=$first?"Off":"";
|
---|
198 |
|
---|
199 | if (empty($_GET["fMd5sumRawZip"]))
|
---|
200 | $_GET["fMd5sumRawZip"]=$first?"Off":"";
|
---|
201 |
|
---|
202 | if (empty($_GET["fRunTypeName"]))
|
---|
203 | $_GET["fRunTypeName"]=$first?"On":"";
|
---|
204 |
|
---|
205 | if (empty($_GET["fTriggerRateMedian"]))
|
---|
206 | $_GET["fTriggerRateMedian"]=$first?"Off":"";
|
---|
207 |
|
---|
208 | if (empty($_GET["fThresholdMedian"]))
|
---|
209 | $_GET["fThresholdMedian"]=$first?"On":"";
|
---|
210 |
|
---|
211 | if (empty($_GET["fBiasVoltageMedian"]))
|
---|
212 | $_GET["fBiasVoltageMedian"]=$first?"Off":"";
|
---|
213 |
|
---|
214 | if (empty($_GET["fRightAscension"]))
|
---|
215 | $_GET["fRightAscension"]=$first?"Off":"";
|
---|
216 |
|
---|
217 | if (empty($_GET["fDeclination"]))
|
---|
218 | $_GET["fDeclination"]=$first?"Off":"";
|
---|
219 |
|
---|
220 | if (empty($_GET["fZenithDistanceMean"]))
|
---|
221 | $_GET["fZenithDistanceMean"]=$first?"On":"";
|
---|
222 |
|
---|
223 | if (empty($_GET["fAzimuthMean"]))
|
---|
224 | $_GET["fAzimuthMean"]=$first?"On":"";
|
---|
225 |
|
---|
226 | }
|
---|
227 |
|
---|
228 | function PrintForm($_GET, $host, $user, $pw, $db)
|
---|
229 | {
|
---|
230 | printf("<center>\n");
|
---|
231 | printf("<form action=\"fact_runinfo.php\" METHOD=\"GET\">\n");
|
---|
232 |
|
---|
233 | // pull down boxes
|
---|
234 |
|
---|
235 | printf(" <table>\n");
|
---|
236 | printf(" <tr><td>\n");
|
---|
237 | PrintPullDown($host, $user, $pw, $db, "RunType", "fRunTypeName", "fRunTypeKEY", "RunType");
|
---|
238 | printf(" </td></tr></table>\n");
|
---|
239 | printf(" <p>\n");
|
---|
240 |
|
---|
241 | printf(" <table>\n");
|
---|
242 | printf(" <tr>\n");
|
---|
243 |
|
---|
244 | CheckBox("fComments", "comments");
|
---|
245 | CheckBox("fRunStart", "start time");
|
---|
246 | CheckBox("fRunStop", "stop time");
|
---|
247 | CheckBox("TimeDiff(fRunStop,fRunStart)", "duration");
|
---|
248 | CheckBox("fROI", "roi");
|
---|
249 | CheckBox("fNumEvents", "#Evts");
|
---|
250 |
|
---|
251 | printf(" </tr>\n");
|
---|
252 | printf(" <tr>\n");
|
---|
253 |
|
---|
254 | CheckBox("Round(fNumPhysicsTrigger/Time_to_sec(TimeDiff(fRunStop,fRunStart)),1)", "phys rate");
|
---|
255 | CheckBox("fNumPhysicsTrigger", "#Phys");
|
---|
256 | CheckBox("fNumPedestalTrigger", "#Ped");
|
---|
257 | CheckBox("fNumELPTrigger", "#ELP");
|
---|
258 | CheckBox("fNumTimeTrigger", "#Time");
|
---|
259 |
|
---|
260 | printf(" </tr>\n");
|
---|
261 | printf(" <tr>\n");
|
---|
262 |
|
---|
263 | CheckBox("fNumExt1Trigger", "#Ext1");
|
---|
264 | CheckBox("fNumExt2Trigger", "#Ext2");
|
---|
265 | CheckBox("fNumILPTrigger", "#ILP");
|
---|
266 | CheckBox("fNumOtherTrigger", "#Other");
|
---|
267 |
|
---|
268 | printf(" </tr>\n");
|
---|
269 | printf(" <tr>\n");
|
---|
270 |
|
---|
271 | CheckBox("fROITimeMarker", "roi-tm");
|
---|
272 | CheckBox("fFitsFileErrors", "file err");
|
---|
273 | CheckBox("fCompileTime", "compiled");
|
---|
274 | CheckBox("fRevisionNumber", "rev#");
|
---|
275 | //CheckBox("if(fHasDrsFile=0,\"N\",\"Y\")", "drs");
|
---|
276 | CheckBox("if(fHasDrsFile=0,\"N\",fDrsStep)", "drs");
|
---|
277 | CheckBox("fMd5sumRaw", "md5");
|
---|
278 | CheckBox("fMd5sumRawZip", "md5(gz)");
|
---|
279 |
|
---|
280 | printf(" </tr>\n");
|
---|
281 | printf(" <tr>\n");
|
---|
282 |
|
---|
283 | CheckBox("fTriggerRateMedian", "mean rate");
|
---|
284 | CheckBox("fThresholdMedian", "mean threshold");
|
---|
285 | CheckBox("fBiasVoltageMedian", "mean voltage");
|
---|
286 | CheckBox("fRightAscension", "RA");
|
---|
287 | CheckBox("fDeclination", "Dec");
|
---|
288 | CheckBox("fZenithDistanceMean", "ZdMean");
|
---|
289 | CheckBox("fAzimuthMean", "AzMean");
|
---|
290 |
|
---|
291 | printf(" </tr>\n");
|
---|
292 | printf(" </table>\n");
|
---|
293 | printf(" <p>\n");
|
---|
294 |
|
---|
295 | if (empty($_GET["fStartDate"]))
|
---|
296 | $timemin = GetMin("fNight", "RunInfo", $host, $user, $pw, $db);
|
---|
297 | else
|
---|
298 | $timemin = $_GET["fStartDate"];
|
---|
299 |
|
---|
300 | if (empty($_GET["fStopDate"]))
|
---|
301 | $timemax = GetMax("fNight", "RunInfo", $host, $user, $pw, $db);
|
---|
302 | else
|
---|
303 | $timemax = $_GET["fStopDate"];
|
---|
304 |
|
---|
305 | printf("Run (yyyymmdd) from <input name=\"fStartDate\" type=\"text\" size=\"10\" maxlength=\"10\" value=\"%s\">\n", $timemin);
|
---|
306 | printf("to <input name=\"fStopDate\" type=\"text\" size=\"10\" maxlength=\"10\" value=\"%s\"> \n", $timemax);
|
---|
307 |
|
---|
308 | printf(" Results:\n");
|
---|
309 | printf(" <select name=\"fNumResults\">\n");
|
---|
310 |
|
---|
311 | $numres = array("10", "20", "50", "100", "200", "500", "1000", "2000");
|
---|
312 | foreach ($numres as $element)
|
---|
313 | {
|
---|
314 | if ($element==$_GET["fNumResults"])
|
---|
315 | printf("<option value=\"%s\" selected>%3s</option>\n", $element, $element);
|
---|
316 | else
|
---|
317 | printf("<option value=\"%s\">%3s</option>\n", $element, $element);
|
---|
318 | }
|
---|
319 | printf(" </select>\n");
|
---|
320 | printf(" \n");
|
---|
321 |
|
---|
322 | ini_set("mysql.trace_mode", "Off");
|
---|
323 | ini_set("display_errors", "Off");
|
---|
324 |
|
---|
325 | printf("<input class='Width' type='submit' value='Query Table'> \n");
|
---|
326 | printf("<input class='Width' type='button' value='Reset' onClick='self.location.href=\"fact_runinfo.php\"'> \n");
|
---|
327 | if (strchr($_SERVER["REQUEST_URI"], '?')!=FALSE)
|
---|
328 | printf("<input class='Width' type='button' value='Get .txt' onClick='self.location.href=\"%s&fSendTxt=1\"'> \n", $_SERVER["REQUEST_URI"]);
|
---|
329 | printf("</form>\n");
|
---|
330 | printf("</center>\n");
|
---|
331 | printf("</td>\n");
|
---|
332 | printf("</tr>\n");
|
---|
333 | printf("<tr class='Block'>\n");
|
---|
334 | printf("<td>\n");
|
---|
335 | }
|
---|
336 |
|
---|
337 | function PrintPage($html, $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup)
|
---|
338 | {
|
---|
339 | $db_id = mysql_connect($host, $user, $pw);
|
---|
340 | if ($db_id==FALSE)
|
---|
341 | {
|
---|
342 | printf("mysql_connect returned the following error: %s\n", mysql_error());
|
---|
343 | die("");
|
---|
344 | }
|
---|
345 | mysql_select_db($db);
|
---|
346 | mysql_query("SET BIG_TABLES=1"); // necessary for mySQL <= 4
|
---|
347 |
|
---|
348 |
|
---|
349 | $query0 = CreateQuery($_GET, $alias, $checkwhere, $checkgroup, $checkstatusgroup);
|
---|
350 |
|
---|
351 | $result0 = mysql_query($query0, $db_id);
|
---|
352 | $result1 = mysql_query("SELECT FOUND_ROWS()", $db_id);
|
---|
353 |
|
---|
354 | if ($result0)
|
---|
355 | {
|
---|
356 | if ($html=="1")
|
---|
357 | PrintMagicTable($result0, $alias, $rightalign, "", "", "", $result1);
|
---|
358 | else
|
---|
359 | PrintText($result0);
|
---|
360 |
|
---|
361 | mysql_free_result($result0);
|
---|
362 | mysql_free_result($result1);
|
---|
363 | }
|
---|
364 | mysql_close($db_id);
|
---|
365 |
|
---|
366 | if ($html=="1")
|
---|
367 | PrintSubmittedQuery($query0, $db, "old");
|
---|
368 | }
|
---|
369 |
|
---|
370 | include ("include.php");
|
---|
371 | include ("db.php");
|
---|
372 | include ("factdefs.php");
|
---|
373 |
|
---|
374 | ini_set("display_errors", "On");
|
---|
375 | ini_set("mysql.trace_mode", "On");
|
---|
376 |
|
---|
377 | if (!empty($_GET["fSendTxt"]))
|
---|
378 | {
|
---|
379 | header("Content-type: application/octet");
|
---|
380 | header("Content-Disposition: attachment; filename=query-result.txt");
|
---|
381 |
|
---|
382 | PrintPage("0", $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup);
|
---|
383 | }
|
---|
384 | else
|
---|
385 | {
|
---|
386 | echo (file_get_contents("index-header.html"));
|
---|
387 |
|
---|
388 | $environment = sizeof($_GET);
|
---|
389 |
|
---|
390 | InitGet($_GET);
|
---|
391 | PrintForm($_GET, $host, $user, $pw, $db);
|
---|
392 |
|
---|
393 | if ($environment==0)
|
---|
394 | printf("No query submitted yet.<BR>");
|
---|
395 | else
|
---|
396 | PrintPage("1", $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup);
|
---|
397 |
|
---|
398 | echo (file_get_contents("index-footer.html"));
|
---|
399 | }
|
---|
400 |
|
---|
401 | ini_set("display_errors", "Off");
|
---|
402 | ini_set("mysql.trace_mode", "Off");
|
---|
403 | }
|
---|
404 | ?>
|
---|