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

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