source: trunk/MagicSoft/Mars/datacenter/db/sequinfo-aio.php@ 9105

Last change on this file since 9105 was 9105, checked in by Daniela Dorner, 17 years ago
*** empty log message ***
  • Property svn:executable set to *
File size: 17.0 KB
Line 
1<?php
2{
3 function CreateQuery($_GET, $alias, $checkwhere, $checkgroup, $checkstatusgroup, $needs)
4 {
5 $fromtable="Sequences";
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 $query0 .= "SUM(fRunTime)/3600 as '" . $alias["SUM(fRunTime)/3600"] . "', ";
26 //--------------------------------------------------
27 $query0 .= " SUM(fNumEvents) as '" . $alias["SUM(fNumEvents)"] . "', ";
28 $query0 .= " Min(fZenithDistanceMin) as '" . $alias["Min(fZenithDistanceMin)"] . "', ";
29 $query0 .= " Max(fZenithDistanceMax) as '" . $alias["Max(fZenithDistanceMax)"] . "', ";
30 $query0 .= " COUNT(*) as '# Sequ' ";
31 }
32 else
33 {
34 if ($statusgroups>0)
35 {
36 foreach ($checkstatusgroup as $key => $element)
37 if ($element==-1)
38 $query0 .= " (if(IsNull(" . $key . "), if(isnull(fStartTime), 'not done', if(isnull(fFailedTime),if(isnull(" . $needs[$key] . "),'not done',if(date_sub(Now(),interval 12 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] . "', ";
39// $query0 .= " (if(IsNull(" . $key . "), 'not done' ,if(" . $key . "='1970-01-01 00:00:00','dont do','done'))) as '" . $alias[$key] . "', ";
40
41 $query0 .= " COUNT(*) as '# Sequ'";
42
43 }
44 else
45 {
46 if (!empty($_GET["fSendTxt"]))
47 $query0 .= " " . $fromtable . ".fSequenceFirst as '" . $alias["fSequenceFirst"] . "' ";
48 else
49 {
50 //old version using fRunMin, fRunMax
51 //$query0 .= " CONCAT('<A&ws;HREF=\"runinfo-aio.php?', 'fRunStart=On', '&amp;fZenithDistance=On', '&amp;fRunMin=', Sequences.fSequenceFirst, '&amp;fMeanTriggerRate=On', '&amp;fTest=On', '&amp;fRunTypeName=On', '&amp;fRunMax=', fSequenceLast, '&amp;fNumEvents=On', '&amp;fSourceName=On&amp;', 'fExcludedFDAKEY=1', '&amp;fSequenceFirst=On', '&amp;fRawFileAvail=On', '&amp;fCCFileAvail=On', '&amp;fCaCoFileAvail=On', '&amp;fNumResults=500\">', Sequences.fSequenceFirst, '</A>') ";
52 //new version using fSequenceNo
53 $query0 .= " CONCAT('<A&ws;HREF=\"runinfo-aio.php?', 'fRunStart=On', '&amp;fZenithDistance=On', '&amp;fSequenceNo=', Sequences.fSequenceFirst, '&amp;fMeanTriggerRate=On', '&amp;fTest=On', '&amp;fRunTypeName=On', '&amp;fNumEvents=On', '&amp;fSourceName=On&amp;', 'fExcludedFDAKEY=1', '&amp;fSequenceFirst=On', '&amp;fRawFileAvail=On', '&amp;fCCFileAvail=On', '&amp;fCaCoFileAvail=On', '&amp;fNumResults=500\">', Sequences.fTelescopeNumber, ':', Sequences.fSequenceFirst, '</A>') ";
54// $query0 .= " as " . $alias["fSequenceFirst"];
55 $query0 .= " as 'Tel:Sequ'";
56 if (!empty($_GET["fLinks"]))
57 {
58 $query0 .= ", CONCAT('<A&ws;HREF=\"http://www.astro.uni-wuerzburg.de/datacenter/callisto/' , LEFT(LPAD(CONCAT(Sequences.fSequenceFirst, '.'), 9,'0'),4), '/', LPAD(CONCAT(Sequences.fSequenceFirst, '/'), 9,'0'), 'callisto', LPAD(CONCAT(Sequences.fSequenceFirst , '.html'), 13,'0') , '\">cl</A>'";
59 $query0 .= ", '&nbsp;<A&ws;HREF=\"http://www.astro.uni-wuerzburg.de/datacenter/callisto/' , LEFT(LPAD(CONCAT(Sequences.fSequenceFirst, '.'), 9,'0'),4), '/', LPAD(CONCAT(Sequences.fSequenceFirst, '/'), 9,'0'), '\">c</A>'";
60 $query0 .= ", '&nbsp;<A&ws;HREF=\"http://www.astro.uni-wuerzburg.de/datacenter/star/' , LEFT(LPAD(CONCAT(Sequences.fSequenceFirst, '.'), 9,'0'),4), '/', LPAD(CONCAT(Sequences.fSequenceFirst, '/'), 9,'0'), 'star', LPAD(CONCAT(Sequences.fSequenceFirst , '.html'), 13,'0') , '\">sl</A>'";
61 $query0 .= ", '&nbsp;<A&ws;HREF=\"http://www.astro.uni-wuerzburg.de/datacenter/star/' , LEFT(LPAD(CONCAT(Sequences.fSequenceFirst, '.'), 9,'0'),4), '/', LPAD(CONCAT(Sequences.fSequenceFirst, '/'), 9,'0'), '\">s</A>'";
62 $query0 .= ", '&nbsp;<A&ws;HREF=\"http://www.astro.uni-wuerzburg.de/datacenter/sequences/' , LEFT(LPAD(CONCAT(Sequences.fSequenceFirst, '.'), 9,'0'),4), '/sequence', LPAD(CONCAT(Sequences.fSequenceFirst , '.txt'), 12,'0') , '\">', 'f </A>' ";
63 $query0 .= ", '&nbsp;<A&ws;HREF=\"sequence.php?fSequenceNo=', Sequences.fSequenceFirst , '&amp;fAll=On\">i</A>'";
64 $query0 .= ", '&nbsp;<A&ws;HREF=\"queryrbk.php?fNight=', date_format(adddate(fRunStart, interval +13 HOUR), '%Y-%m-%d') , '&amp;fDate=2\">rbk</A>') ";
65 $query0 .= " as 'Links'";
66 }
67 }
68
69 foreach ($_GET as $key => $element)
70 if ($_GET[$key]=="On")
71 if ($key!="fLinks" && $key!="fOff" && $key!="fOnlyOff")
72 if (empty($checkwhere[$key]) || $checkwhere[$key]==0)
73 $query0 .= ", " . $key . " as '" . $alias[$key] . "' ";
74 }
75 }
76
77 $query0 .= " FROM " . $fromtable;
78
79 $query0 .= " LEFT JOIN SequenceProcessStatus USING(fSequenceFirst,fTelescopeNumber) ";
80 $query0 .= " LEFT JOIN Calibration USING(fSequenceFirst,fTelescopeNumber) ";
81 $query0 .= " LEFT JOIN Star USING(fSequenceFirst,fTelescopeNumber) ";
82
83 foreach ($_GET as $key => $element)
84 if (($_GET[$key]=="On" || $groups>0))// && !empty(GetJoin($fromtable,$key)))
85 $query0 .= GetJoin($fromtable,$key);
86
87 if ($_GET["fTest"]!="On")
88 {
89 if ($_GET["fSourceName"]!="On")
90 $query0 .= " LEFT JOIN Source ON USING(fSourceKEY) ";
91 $query0 .= " WHERE fTest='no'";
92 }
93
94 if ($_GET["fOff"]=="Off")
95 {
96 if (strpos($query0, " WHERE ")==FALSE)
97 $query0 .= " WHERE ";
98 else
99 $query0 .= " AND ";
100
101 $query0 .= " NOT (fSourceName like '%Off%')";
102 }
103
104 if ($_GET["fOnlyOff"]=="On")
105 {
106 if (strpos($query0, " WHERE ")==FALSE)
107 $query0 .= " WHERE ";
108 else
109 $query0 .= " AND ";
110
111 $query0 .= " fSourceName like '%Off%'";
112 }
113
114 foreach ($checkwhere as $key => $element)
115 {
116 if (empty($element) || $element<=0)
117 continue;
118
119 if (strpos($query0, " WHERE ")==FALSE)
120 $query0 .= " WHERE ";
121 else
122 if ($element!=-1)
123 if (strrpos($query0, " AND ")!=strlen($query0)-5)
124 $query0 .= " AND ";
125
126 if ($element!=-1)
127 $query0 .= GetCheck($fromtable, $key) . "=" . $element;
128 }
129
130 if (strpos($query0, " WHERE ")==FALSE)
131 $query0 .= " WHERE ";
132 else
133 $query0 .= " AND ";
134
135 $query0 .= StatusQuery("fSequenceFileWritten", $needs);
136 $query0 .= StatusQuery("fAllFilesAvail", $needs);
137 $query0 .= StatusQuery("fCallisto", $needs);
138 $query0 .= StatusQuery("fFillCallisto", $needs);
139 $query0 .= StatusQuery("fStar", $needs);
140 $query0 .= StatusQuery("fFillStar", $needs);
141
142 if (!empty($_GET["fRunMin"]) && !empty($_GET["fRunMax"]))
143 $query0 .= "Sequences.fSequenceFirst BETWEEN " . $_GET["fRunMin"] . " AND " . $_GET["fRunMax"] . " ";
144 else
145 $query0 = substr($query0, 0, -4);
146
147 if ((!empty($_GET["fZDMin"]) || $_GET["fZDMin"]==0) && !empty($_GET["fZDMax"]))
148 $query0 .= "AND (fZenithDistanceMin >= " . $_GET["fZDMin"] . " AND fZenithDistanceMax <= " . $_GET["fZDMax"] . ") ";
149
150 if (!empty($_GET["fSourceN"]))
151 $query0 .= " AND fSourceName REGEXP \"^" . $_GET["fSourceN"] . "\" ";
152
153 if (!empty($_GET["fStartDate"]))
154 {
155 if (strpos(strrev($query0), " DNA ")!=0 || !strpos(strrev($query0), " DNA "))
156 $query0 .= " AND ";
157
158 $startdate=substr($_GET["fStartDate"], 0, 10);
159 if ($startdate=="0000-00-00")
160 $query0 .=" fRunStart >= '" . $startdate . " 00:00:00' ";
161 else
162 $query0 .= " fRunStart >= ADDDATE('" . $startdate . " 13:00:00', INTERVAL -1 DAY) ";
163 }
164
165 if (!empty($_GET["fStopDate"]))
166 {
167 if (strpos(strrev($query0), " DNA ")!=0 || !strpos(strrev($query0), " DNA "))
168 $query0 .= " AND ";
169
170 $stopdate=substr($_GET["fStopDate"], 0, 10);
171 $query0 .= " fRunStart < '" . $stopdate . " 13:00:00' ";
172 }
173
174 if (!empty($_GET["fStarStart"]))
175 {
176 if (strpos(strrev($query0), " DNA ")!=0 || !strpos(strrev($query0), " DNA "))
177 $query0 .= " AND ";
178
179 $starstart=substr($_GET["fStarStart"], 0, 10);
180 $query0 .=" fStar >= '" . $starstart . " 00:00:00' ";
181 }
182
183 if (!empty($_GET["fStarStop"]))
184 {
185 if (strpos(strrev($query0), " DNA ")!=0 || !strpos(strrev($query0), " DNA "))
186 $query0 .= " AND ";
187
188 $starstop=substr($_GET["fStarStop"], 0, 10);
189 $query0 .= " fStar < '" . $starstop . " 23:59:59' ";
190 }
191
192 if ($groups>0)
193 {
194 $query0 .= " GROUP BY ";
195 $num = $groups;
196 foreach ($checkgroup as $key => $element)
197 if ($element==-1)
198 {
199 $query0 .= GetCheck($fromtable,$key);
200 if ($num-->1)
201 $query0 .= ", ";
202 }
203 }
204
205 if ($statusgroups>0)
206 {
207 $query0 .= " GROUP BY ";
208 $num = $statusgroups;
209 foreach ($checkstatusgroup as $key => $element)
210 if ($element==-1)
211 {
212 $query0 .= $alias[$key];
213 if ($num-->1)
214 $query0 .= ", ";
215 }
216 }
217
218 if (!empty($_GET["fSortBy"]))
219 {
220 $val=substr($_GET["fSortBy"], 0, -1);
221 $query0 .= " ORDER BY " . GetTable($fromtable,$val) . " ";
222 if (substr($_GET["fSortBy"], -1)=="-")
223 $query0 .= "DESC";
224 }
225
226 if (empty($_GET["fSortBy"]) && $groups==0 && $statusgroups==0)
227 $query0 .= "ORDER BY Sequences.fSequenceFirst ASC ";
228
229 if (empty($_GET["fNumStart"]))
230 $_GET["fNumStart"]=0;
231
232 if (empty($_GET["fSendTxt"]))
233 $query0 .= " LIMIT " . $_GET["fNumStart"] . ", " . $_GET["fNumResults"];
234
235 return $query0;
236 }
237
238 function InitGet($_GET)
239 {
240 // Find out whether it is the first call to the php script
241 $first = empty($_GET["fRunMin"]) && empty($_GET["fRunMax"]);
242
243 if (empty($_GET["fNumResults"]))
244 $_GET["fNumResults"]="50";
245
246 if (empty($_GET["fRunStart"]))
247 $_GET["fRunStart"]=$first?"On":"";
248
249 if (empty($_GET["fRunTime/60"]))
250 $_GET["fRunTime/60"]=$first?"On":"";
251
252 if (empty($_GET["fZenithDistanceMin"]))
253 $_GET["fZenithDistanceMin"]=$first?"On":"";
254
255 if (empty($_GET["fSourceName"]))
256 $_GET["fSourceName"]=$first?"On":"";
257
258 if (empty($_GET["fStar"]))
259 $_GET["fStar"]=$first?"On":"";
260
261 if (empty($_GET["fInhomogeneity"]))
262 $_GET["fInhomogeneity"]=$first?"On":"";
263
264 if (empty($_GET["fPSF"]))
265 $_GET["fPSF"]=$first?"On":"";
266
267 if (empty($_GET["fMeanPedRmsInner"]))
268 $_GET["fMeanPedRmsInner"]=$first?"On":"";
269
270 if (empty($_GET["fOff"]))
271 $_GET["fOff"]=$first?"On":"";
272
273 if (empty($_GET["fLinks"]))
274 $_GET["fLinks"]=$first?"On":"";
275
276 if (empty($_GET["fOnlyOff"]))
277 $_GET["fOnlyOff"]=$first?"Off":"";
278
279 InitFindOffData($_GET, $first);
280 }
281
282 function PrintForm($_GET, $host, $user, $pw, $db, $limitsmean, $limitsmin, $limitsmax, $alias)
283 {
284 printf("<center>\n");
285 printf("<form action='sequinfo-aio.php' METHOD='GET'>\n");
286 printf("<input id='sh' type='hidden' name='fShowHide' value='");
287 if (!empty($_GET["fShowHide"]))
288 printf("%s", $_GET["fShowHide"]);
289 else
290 printf("1000000010");
291 printf("'>\n");
292 printf("<img id='allbutton' src='minus.png' alt='-' onclick='showhide(\"all\")'> <b>Menu</b>&nbsp;&nbsp;&nbsp;&nbsp; \n");
293 printf("&nbsp;&nbsp;<img id='infobutton' src='plus.png' alt='+' onClick='showhide(\"info\");showhide(\"info2\")'> SequInfo \n");
294 printf("&nbsp;&nbsp;<img id='statbutton' src='plus.png' alt='+' onClick='showhide(\"stat\");showhide(\"fail\")'> StatusInfo \n");
295 printf("&nbsp;&nbsp;<img id='calbutton' src='plus.png' alt='+' onClick='showhide(\"cal\")'> CalInfo \n");
296 printf("&nbsp;&nbsp;<img id='starbutton' src='plus.png' alt='+' onClick='showhide(\"star\")'> StarInfo \n");
297 printf("&nbsp;&nbsp;<img id='limitsbutton' src='plus.png' alt='+' onClick='showhide(\"limits\")'> Limits \n");
298 printf("&nbsp;&nbsp;<img id='rangesbutton' src='minus.png' alt='-' onClick='showhide(\"ranges\")'> Ranges \n");
299
300 printf(" <div id='all' style='display:block'>");
301
302 PrintSequInfoMenu();
303 PrintSequInfo2Menu($host,$user,$pw,$db);
304 PrintSequStatMenu();
305 PrintFailMenu();
306 PrintCalMenu();
307 PrintStarMenu();
308 PrintLimitsMenu($limitsmean, $limitsmin, $limitsmax, $alias, "");
309
310 printf(" <div id='ranges' style='display:block'>");
311 PrintZdRangeMenu($host,$user,$pw,$db);
312 PrintSequRangeMenu($host,$user,$pw,$db);
313 printf("<p>");
314 PrintSourceMenu($host,$user,$pw,$db);
315 PrintNightRangeMenu($host,$user,$pw,$db, "Sequences");
316 printf("<p>");
317 printf("</div>");
318
319 printf("</div>");
320 printf(" <P>\n");
321
322
323 ini_set("mysql.trace_mode", "Off");
324 ini_set("display_errors", "Off");
325
326 PrintNumResPullDown();
327 PrintButtons("sequinfo-aio.php");
328
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, $limitsmean, $limitsmin, $limitsmax, $needs)
338 {
339 $db_id = mysql_pconnect($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
347 $query0 = CreateQuery($_GET, $alias, $checkwhere, $checkgroup, $checkstatusgroup, $needs);
348
349 $result0 = mysql_query($query0, $db_id);
350
351 if ($result0)
352 {
353 if ($html=="1" || $html=="2")
354 PrintMagicTable($result0, $alias, $rightalign, $limitsmean, $limitsmin, $limitsmax, "", $_GET);
355 else
356 PrintText($result0);
357
358 mysql_free_result($result0);
359 }
360 mysql_close($db_id);
361
362 PrintSubmittedQuery($query0, $html, $db, "");
363 }
364
365 include ("include.php");
366 include ("menu.php");
367 include ("db.php");
368 include ("magicdefs.php");
369
370 ini_set("display_errors", "On");
371 ini_set("mysql.trace_mode", "On");
372
373 if (!empty($_GET["fSendTxt"]))
374 {
375 header("Content-type: application/octet");
376 header("Content-Disposition: attachment; filename=query-result.txt");
377
378 PrintPage("0", $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $limitsmean, $limitsmin, $limitsmax, $needs);
379 }
380 else
381 {
382 if (empty($_GET["fPrintTable"]))
383 echo (file_get_contents("index-header.html"));
384
385 $environment = sizeof($_GET);
386
387 InitGet($_GET);
388 if (empty($_GET["fPrintTable"]))
389 PrintForm($_GET, $host, $user, $pw, $db, $limitsmean, $limitsmin, $limitsmax, $alias);
390
391 if ($environment==0)
392 printf("No query submitted yet.<BR>");
393 else
394 {
395 if (empty($_GET["fPrintTable"]))
396 PrintPage("1", $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $limitsmean, $limitsmin, $limitsmax, $needs);
397 else
398 PrintPage("2", $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $limitsmean, $limitsmin, $limitsmax, $needs);
399 }
400
401 if (empty($_GET["fPrintTable"]))
402 echo (file_get_contents("index-footer.html"));
403 }
404
405 ini_set("display_errors", "Off");
406 ini_set("mysql.trace_mode", "Off");
407}
408?>
Note: See TracBrowser for help on using the repository browser.