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

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