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

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