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

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