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