source: trunk/MagicSoft/Mars/datacenter/db/mcinfo.php@ 9599

Last change on this file since 9599 was 9599, checked in by Daniela Dorner, 16 years ago
*** empty log message ***
  • Property svn:executable set to *
File size: 12.3 KB
Line 
1<?php
2{
3 function CreateQuery($_GET, $alias, $checkwhere, $checkgroup, $checkstatusgroup, $timelimits)
4 {
5 $fromtable="CeresInfo";
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 SQL_CALC_FOUND_ROWS ";
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
40 if ($statusgroups>0)
41 {
42 foreach ($checkstatusgroup as $key => $element)
43 if ($element==-1)
44 $query0 .= " IF( ISNULL(" . $key . "Status.fStartTime) "
45 ." AND ISNULL(" . $key . "Status.fStopTime) "
46 ." AND ISNULL(" . $key . "Status.fReturnCode), 'not done', "
47 ." IF (NOT ISNULL(" . $key . "Status.fStartTime) "
48 ." AND DATE_SUB(Now(),INTERVAL " . $timelimits[$key] . " HOUR) > " . $key . "Status.fStartTime "
49 ." AND ISNULL(" . $key . "Status.fStopTime) "
50 ." AND ISNULL(" . $key . "Status.fReturnCode), 'crashed', "
51 ." IF (NOT ISNULL(" . $key . "Status.fStartTime) "
52 ." AND DATE_SUB(Now(),INTERVAL " . $timelimits[$key] . " HOUR) < " . $key . "Status.fStartTime "
53 ." AND ISNULL(" . $key . "Status.fStopTime) "
54 ." AND ISNULL(" . $key . "Status.fReturnCode), 'running', "
55 ." IF (NOT ISNULL(" . $key . "Status.fStartTime) "
56 ." AND NOT ISNULL(" . $key . "Status.fStopTime) "
57 ." AND ISNULL(" . $key . "Status.fReturnCode), 'done', 'bla' "
58 ." )))) AS '". $key . "', ";
59 }
60 $query0 .= " COUNT(*) as '# Files' ";
61 $query0 .= ", SUM(fNumEvents) as '" . $alias["SUM(fNumEvents)"] . "' ";
62 }
63 else
64 {
65 $query0 .= " CONCAT(LPAD(" . $fromtable . ".fRunNumber,8, ' '),'.', ";
66 $query0 .= " RIGHT(LPAD(" . $fromtable . ".fFileNumber, 6, 0), 3)) as 'Run.File' ";
67
68 if (empty($_GET["fSendTxt"]) && !empty($_GET["fLinks"]))
69 {
70 $query0 .= ", CONCAT('<A&ws;HREF=\"queryrbk.php?fNight=', date_format(adddate(fRunStart, interval +13 HOUR), '%Y-%m-%d') , '&amp;fDate=2\">rbk</A>') ";
71 $query0 .= " as 'Links'";
72 }
73
74 foreach ($_GET as $key => $element)
75 if ($_GET[$key]=="On" && $key!="fTest" && $key!="fLinks")
76 if (!ereg("^f", $key))
77 {
78
79 $query0 .= ", IF (ISNULL(" . $key . "Status.fStartTime) AND ";
80 $query0 .= " ISNULL(" . $key . "Status.fStopTime) AND ";
81 $query0 .= " ISNULL(" . $key . "Status.fReturnCode), 'not done', ";
82 $query0 .= " IF (NOT ISNULL(" . $key . "Status.fReturnCode), ";
83 $query0 .= " CONCAT('failed (', " . $key . "Status.fReturnCode, ')'), ";
84 $query0 .= " CONCAT('done (', " . $key . "Status.fStopTime, ')'))) ";
85
86 //$query0 .= ", CONCAT( 'halo', " . $key . "Status.fStartTime)";
87 $query0 .= " AS '" . $alias[$key] . "' ";
88 //echo "ereg: " . $key . "<br>";
89 }
90 else
91 if (empty($checkwhere[$key]) || $checkwhere[$key]==0)
92 $query0 .= ", " . $key . " as '" . $alias[$key] . "' ";
93 }
94
95 $query0 .= " FROM " . $fromtable;
96
97 $query0 .= " LEFT JOIN CorsikaInfo USING(fRunNumber,fFileNumber) ";
98
99 foreach ($_GET as $key => $element)
100 if (($_GET[$key]=="On" || $groups>0))// && !empty($joins[$key]))
101 $query0 .= GetJoin($fromtable,$key);
102
103 foreach ($checkwhere as $key => $element)
104 {
105 if (empty($element) || $element<=0)
106 continue;
107
108 if (strpos($query0, " WHERE ")==FALSE)
109 $query0 .= " WHERE ";
110 else
111 if ($element!=-1)
112 if (strrpos($query0, " AND ")!=strlen($query0)-5)// this if clause doesn't work
113 $query0 .= " AND ";
114
115 if ($element!=-1)
116 $query0 .= GetCheck($fromtable, $key) . "=" . $element;
117 }
118
119 if (strpos($query0, " WHERE ")==FALSE)
120 $query0 .= " WHERE ";
121 else
122 $query0 .= " AND ";
123
124 $query0 .= StatusQuery("Corsika", $timelimits);
125 $query0 .= StatusQuery("Ceres", $timelimits);
126 $query0 .= StatusQuery("SequenceFile", $timelimits);
127 $query0 .= StatusQuery("Callisto", $timelimits);
128 $query0 .= StatusQuery("Star", $timelimits);
129
130 if ((!empty($_GET["fRunMin"]) || $_GET["fRunMin"]=="0") && !empty($_GET["fRunMax"]))
131 $query0 .= " " . $fromtable . ".fRunNumber BETWEEN " . $_GET["fRunMin"] . " AND " . $_GET["fRunMax"] . " ";
132
133
134 //remove WHERE or AND in the end of the query
135 $query0=ereg_replace(" WHERE \$", " ", $query0);
136 $query0=ereg_replace(" AND \$", " ", $query0);
137
138 if ($groups>0)
139 {
140 $query0 .= " GROUP BY ";
141 $num = $groups;
142 foreach ($checkgroup as $key => $element)
143 if ($element==-1)
144 {
145 $query0 .= GetCheck($fromtable,$key);
146 if ($num-->1)
147 $query0 .= ", ";
148 }
149 }
150
151 if ($statusgroups>0)
152 {
153 if (strpos($query0, " GROUP BY ")==FALSE)
154 $query0 .= " GROUP BY ";
155 else
156 $query0 .= ", ";
157 $num = $statusgroups;
158 foreach ($checkstatusgroup as $key => $element)
159 if ($element==-1)
160 {
161 $query0 .= $alias[$key];
162 if ($num-->1)
163 $query0 .= ", ";
164 }
165 }
166
167 if (!empty($_GET["fSortBy"]))
168 {
169 $val=substr($_GET["fSortBy"], 0, -1);
170 $query0 .= " ORDER BY " . GetTable($fromtable, $val) . " ";
171 if (substr($_GET["fSortBy"], -1)=="-")
172 $query0 .= "DESC";
173 }
174 else
175 $query0 .=" ORDER BY " . $fromtable . ".fRunNumber ASC";
176
177 if (empty($_GET["fNumStart"]))
178 $_GET["fNumStart"]=0;
179
180 if (empty($_GET["fSendTxt"]))
181 $query0 .= " LIMIT " . $_GET["fNumStart"] . ", " . $_GET["fNumResults"];
182
183 return $query0;
184 }
185
186 function InitGet($_GET)
187 {
188 // Find out whether it is the first call to the php script
189 $first = empty($_GET["fRunMin"]) && empty($_GET["fRunMax"]);
190
191 InitMCRunInfo($_GET, $first);
192 }
193
194 function PrintForm($_GET, $host, $user, $pw, $db)
195 {
196 printf("<center>\n");
197 printf("<form action=\"mcinfo.php\" METHOD=\"GET\">\n");
198
199 printf("<input id='sh' type='hidden' name='fShowHide' value='");
200 if (!empty($_GET["fShowHide"]))
201 printf("%s", $_GET["fShowHide"]);
202 else
203 printf("1000000010");
204 printf("'>\n");
205 printf("<img id='allbutton' src='minus.png' alt='-' onclick=\"showhide('all')\"> <b>Menu</b>&nbsp;&nbsp;&nbsp;&nbsp;\n");
206 printf("&nbsp;&nbsp;<img id='infobutton' src='plus.png' alt='+' onClick=\"showhide('info');showhide('info2')\"> MCRunInfo \n");
207 printf("&nbsp;&nbsp;<img id='statbutton' src='plus.png' alt='+' onClick=\"showhide('stat');showhide('fail')\"> StatusInfo \n");
208 printf("&nbsp;&nbsp;<img id='rangesbutton' src='plus.png' alt='+' onClick=\"showhide('ranges')\"> Ranges \n");
209
210 printf(" <div id='all' style='display:block'>");
211 PrintMCRunInfoMenu($host,$user,$pw,$db);
212// PrintRunInfo2Menu($host,$user,$pw,$db);
213 PrintMCRunStatMenu();
214 PrintFailMenu();
215 printf(" <div id='ranges' style='display:none'>");
216// PrintSequMenu($host,$user,$pw,$db);
217// PrintNightRangeMenu($host,$user,$pw,$db, "RunData");
218 printf("<p>");
219// PrintZdRangeMenu($host,$user,$pw,$db);
220 PrintMCRunRangeMenu($host,$user,$pw,$db);
221// printf(" <P>\n");
222// PrintSourceMenu($host,$user,$pw,$db);
223 printf("<p>");
224 printf("</div>");
225 printf("</div>");
226 printf(" <P>\n");
227
228 ini_set("mysql.trace_mode", "Off");
229 ini_set("display_errors", "Off");
230
231 PrintNumResPullDown();
232 PrintButtons("mcinfo.php");
233
234 printf("</form>\n");
235 printf("</center>\n");
236 printf("</td>\n");
237 printf("</tr>\n");
238 printf("<tr class='Block'>\n");
239 printf("<td>\n");
240 }
241
242 function PrintPage($html, $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $timelimits)
243 {
244 $db_id = mysql_connect($host, $user, $pw);
245 if ($db_id==FALSE)
246 {
247 printf("mysql_connect returned the following error: %s\n", mysql_error());
248 die("");
249 }
250 mysql_select_db($db);
251 mysql_query("SET BIG_TABLES=1"); // necessary for mySQL <= 4
252
253 $query0 = CreateQuery($_GET, $alias, $checkwhere, $checkgroup, $checkstatusgroup, $timelimits);
254
255 $result0 = mysql_query($query0, $db_id);
256 $result1 = mysql_query("SELECT FOUND_ROWS()", $db_id);
257
258 if ($result0)
259 {
260 if ($html=="1" || $html=="2")
261 PrintMagicTable($result0, $alias, $rightalign, "", "", "", $result1);
262 else
263 PrintText($result0);
264
265 mysql_free_result($result0);
266 mysql_free_result($result1);
267 }
268 mysql_close($db_id);
269
270 if ($html=="1")
271 PrintSubmittedQuery($query0, $db, "");
272 }
273
274 include ("include.php");
275 include ("db2.php");
276 include ("menu.php");
277 include ("mcdefs.php");
278
279 ini_set("display_errors", "On");
280 ini_set("mysql.trace_mode", "On");
281
282 if (!empty($_GET["fSendTxt"]))
283 {
284 header("Content-type: application/octet");
285 header("Content-Disposition: attachment; filename=query-result.txt");
286
287 PrintPage("0", $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $timelimits);
288 }
289 else
290 {
291 if (empty($_GET["fPrintTable"]))
292 echo (file_get_contents("index-header-fact.html"));
293
294 $environment = sizeof($_GET);
295
296 InitGet($_GET);
297 if (empty($_GET["fPrintTable"]))
298 PrintForm($_GET, $host, $user, $pw, $db);
299
300 if ($environment==0)
301 printf("No query submitted yet.<BR>");
302 else
303 {
304 if (empty($_GET["fPrintTable"]))
305 PrintPage("1", $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $timelimits);
306 else
307 PrintPage("2", $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $timelimits);
308 }
309
310 if (empty($_GET["fPrintTable"]))
311 echo (file_get_contents("index-footer.html"));
312 }
313
314 ini_set("display_errors", "Off");
315 ini_set("mysql.trace_mode", "Off");
316}
317?>
Note: See TracBrowser for help on using the repository browser.