source: tags/Mars-V0.10.1/datacenter/db/sequinfo-aio.php

Last change on this file was 7962, checked in by Daniela Dorner, 18 years ago
*** empty log message ***
  • Property svn:executable set to *
File size: 15.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 'Sequence' ";
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 'Sequence'";
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["fOff"]))
260 $_GET["fOff"]=$first?"On":"";
261
262 if (empty($_GET["fOnlyOff"]))
263 $_GET["fOnlyOff"]=$first?"Off":"";
264
265 InitSequInfo($_GET);
266 }
267
268 function PrintForm($_GET, $host, $user, $pw, $db, $limitsmean, $limitsmin, $limitsmax, $alias)
269 {
270 printf("<center>\n");
271 printf("<form action=\"sequinfo-aio.php\" METHOD=\"GET\">\n");
272 printf("<input id='sh' type='hidden' name='fShowHide' value='");
273 if (!empty($_GET["fShowHide"]))
274 printf("%s", $_GET["fShowHide"]);
275 else
276 printf("1000000000");
277 printf("'>\n");
278 printf("<img id='allbutton' src='../minus.png' alt='-' onclick='showhide(\"all\")'> Menu \n");
279 printf("<img id='infobutton' src='../plus.png' alt='+' onClick='showhide(\"info\");showhide(\"info2\")'>SequInfo \n");
280 printf("<img id='statbutton' src='../plus.png' alt='+' onClick='showhide(\"stat\");showhide(\"fail\")'> StatusInfo \n");
281 printf("<img id='calbutton' src='../plus.png' alt='+' onClick='showhide(\"cal\")'> CalInfo \n");
282 printf("<img id='starbutton' src='../plus.png' alt='+' onClick='showhide(\"star\")'> StarInfo \n");
283 printf("<img id='rangesbutton' src='../plus.png' alt='+' onClick='showhide(\"ranges\")'> Ranges \n");
284 printf("<img id='limitsbutton' src='../plus.png' alt='+' onClick='showhide(\"limits\")'> Limits \n");
285
286 printf(" <div id='all' style='display:block'>");
287
288 PrintSequInfoMenu();
289 PrintSequInfo2Menu($host,$user,$pw,$db);
290 PrintSequStatMenu();
291 PrintFailMenu();
292 PrintCalMenu();
293 PrintStarMenu();
294 PrintLimitsMenu($limitsmean, $limitsmin, $limitsmax, $alias, "");
295
296 printf(" <div id='ranges' style='display:none'>");
297 PrintZdRangeMenu($host,$user,$pw,$db);
298 PrintSequRangeMenu($host,$user,$pw,$db);
299 printf("<p>");
300 PrintSourceMenu($host,$user,$pw,$db);
301 PrintNightRangeMenu($host,$user,$pw,$db);
302 printf("<p>");
303 printf("</div>");
304
305 printf("</div>");
306 printf(" <P>\n");
307
308 PrintNumResPullDown();
309
310 ini_set("mysql.trace_mode", "Off");
311 ini_set("display_errors", "Off");
312
313 PrintButtons("sequinfo-aio.php");
314
315 printf("</form>\n");
316 printf("</center>\n");
317 printf("</td>\n");
318 printf("</tr>\n");
319 printf("<tr class='Block'>\n");
320 printf("<td>\n");
321 }
322
323 function PrintPage($html, $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $limitsmean, $limitsmin, $limitsmax, $needs)
324 {
325 $db_id = mysql_pconnect($host, $user, $pw);
326 if ($db_id==FALSE)
327 {
328 printf("mysql_connect returned the following error: %s\n", mysql_error());
329 die("");
330 }
331 mysql_select_db($db);
332
333 $query0 = CreateQuery($_GET, $alias, $checkwhere, $checkgroup, $checkstatusgroup, $needs);
334
335 $result0 = mysql_query($query0, $db_id);
336
337 if ($result0)
338 {
339 if ($html=="1" || $html=="2")
340 PrintMagicTable($result0, $alias, $rightalign, $limitsmean, $limitsmin, $limitsmax, $_GET);
341 else
342 PrintText($result0);
343
344 mysql_free_result($result0);
345 }
346 mysql_close($db_id);
347
348 PrintSubmittedQuery($query0, $html, $db, "");
349 }
350
351 include ("include.php");
352 include ("menu.php");
353 include ("db.php");
354 include ("magicdefs.php");
355
356 ini_set("display_errors", "On");
357 ini_set("mysql.trace_mode", "On");
358
359 if (!empty($_GET["fSendTxt"]))
360 {
361 header("Content-type: application/octet");
362 header("Content-Disposition: attachment; filename=query-result.txt");
363
364 PrintPage("0", $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $limitsmean, $limitsmin, $limitsmax, $needs);
365 }
366 else
367 {
368 echo (file_get_contents("index-header.html"));
369
370 $environment = sizeof($_GET);
371
372 InitGet($_GET);
373 if (empty($_GET["fPrintTable"]))
374 PrintForm($_GET, $host, $user, $pw, $db, $limitsmean, $limitsmin, $limitsmax, $alias);
375
376 if ($environment==0)
377 printf("No query submitted yet.<BR>");
378 else
379 {
380 if (empty($_GET["fPrintTable"]))
381 PrintPage("1", $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $limitsmean, $limitsmin, $limitsmax, $needs);
382 else
383 PrintPage("2", $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $limitsmean, $limitsmin, $limitsmax, $needs);
384 }
385
386 echo (file_get_contents("index-footer.html"));
387 }
388
389 ini_set("display_errors", "Off");
390 ini_set("mysql.trace_mode", "Off");
391}
392?>
Note: See TracBrowser for help on using the repository browser.