source: trunk/MagicSoft/Mars/datacenter/db/datasetinfo.php@ 9190

Last change on this file since 9190 was 9106, checked in by Daniela Dorner, 16 years ago
*** empty log message ***
  • Property svn:executable set to *
File size: 15.2 KB
Line 
1<?php
2{
3 function CreateQuery($_GET, $alias, $checkwhere, $checkgroup, $checkstatusgroup, $needs)
4 {
5 $fromtable="DataSets";
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 $query0 .= " COUNT(*) as '# Datasets' ";
25 }
26 else
27 {
28 if ($statusgroups>0)
29 {
30 foreach ($checkstatusgroup as $key => $element)
31 if ($element==-1)
32 $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] . "', ";
33// $query0 .= " (if(IsNull(" . $key . "), 'not done' ,if(" . $key . "='1970-01-01 00:00:00','dont do','done'))) as '" . $alias[$key] . "', ";
34
35 $query0 .= " COUNT(*) as '# Datasets'";
36
37 }
38 else
39 {
40 $query0 .= " " . $fromtable . ".fDataSetNumber as '" . $alias["fDataSetNumber"] . "' ";
41 if (!empty($_GET["fLinks"]))
42 {
43 $query0 .= ", CONCAT('<A&ws;HREF=\"http://www.astro.uni-wuerzburg.de/datacenter/datasets/' , LEFT(LPAD(CONCAT(DataSets.fDataSetNumber, '.'), 9,'0'),5), '/dataset', LPAD(CONCAT(DataSets.fDataSetNumber , '.txt'), 12,'0') , '\">f</A>' ";
44 $query0 .= ", '&nbsp;<A&ws;HREF=\"http://www.astro.uni-wuerzburg.de/datacenter/ganymed/' , LEFT(LPAD(CONCAT(DataSets.fDataSetNumber, '.'), 9,'0'),5), '/', LEFT(LPAD(CONCAT(DataSets.fDataSetNumber, '.'), 9,'0'), 8), '\">g</A>'";
45 $query0 .= ", '&nbsp;<A&ws;HREF=\"ganymed.php?fDataSetNo=', DataSets.fDataSetNumber, '\">i</A>') ";
46 $query0 .= " as 'Links'";
47 }
48
49 foreach ($_GET as $key => $element)
50 if ($_GET[$key]=="On")
51 if ($key!="fLinks")
52 if (empty($checkwhere[$key]) || $checkwhere[$key]==0)
53 $query0 .= ", " . $key . " as '" . $alias[$key] . "' ";
54 }
55 }
56
57 $query0 .= " FROM " . $fromtable;
58
59 $query0 .= " LEFT JOIN DataSetProcessStatus USING(fDataSetNumber) ";
60 $query0 .= " LEFT JOIN Ganymed USING(fDataSetNumber) ";
61
62 foreach ($_GET as $key => $element)
63 if (($_GET[$key]=="On" || $groups>0))// && !empty($joins[$key]))
64 $query0 .= GetJoin($fromtable,$key);
65
66 foreach ($checkwhere as $key => $element)
67 {
68 if (empty($element) || $element<=0)
69 continue;
70
71 if (strpos($query0, " WHERE ")==FALSE)
72 $query0 .= " WHERE ";
73 else
74 if ($element!=-1)
75 if (strrpos($query0, " AND ")!=strlen($query0)-5)
76 $query0 .= " AND ";
77
78 if ($element!=-1)
79 $query0 .= GetCheck($fromtable, $key) . "=" . $element;
80 }
81
82 if (strpos($query0, " WHERE ")==FALSE)
83 $query0 .= " WHERE ";
84 else
85 $query0 .= " AND ";
86
87 $query0 .= StatusQuery("fDataSetInserted", $needs);
88 $query0 .= StatusQuery("fStarFilesAvail", $needs);
89 $query0 .= StatusQuery("fGanymed", $needs);
90 $query0 .= StatusQuery("fFillGanymed", $needs);
91
92 if (!empty($_GET["fRunMin"]) && !empty($_GET["fRunMax"]))
93 $query0 .= "DataSets.fDataSetNumber BETWEEN " . $_GET["fRunMin"] . " AND " . $_GET["fRunMax"] . " ";
94
95/*
96 if (!empty($_GET["fDate"]))
97 $query0 .= " AND fRunStart REGEXP \"^" . $_GET["fDate"] . "\" ";
98*/
99
100 if (!empty($_GET["fSourceN"]))
101 $query0 .= " AND fSourceName REGEXP \"^" . $_GET["fSourceN"] . "\" ";
102
103 if ($groups>0)
104 {
105 $query0 .= " GROUP BY ";
106 $num = $groups;
107 foreach ($checkgroup as $key => $element)
108 if ($element==-1)
109 {
110 $query0 .= GetCheck($fromtable,$key);
111 if ($num-->1)
112 $query0 .= ", ";
113 }
114 }
115
116 if ($statusgroups>0)
117 {
118 $query0 .= " GROUP BY ";
119 $num = $statusgroups;
120 foreach ($checkstatusgroup as $key => $element)
121 if ($element==-1)
122 {
123 $query0 .= $alias[$key];
124 if ($num-->1)
125 $query0 .= ", ";
126 }
127 }
128
129 if (!empty($_GET["fSortBy"]))
130 {
131 $val=substr($_GET["fSortBy"], 0, -1);
132 $query0 .= " ORDER BY " . GetTable($fromtable, $val) . " ";
133 if (substr($_GET["fSortBy"], -1)=="-")
134 $query0 .= "DESC";
135 }
136
137 if (empty($_GET["fSortBy"]) && $groups==0 && $statusgroups==0)
138 $query0 .= "ORDER BY DataSets.fDataSetNumber ASC ";
139
140 if (empty($_GET["fNumStart"]))
141 $_GET["fNumStart"]=0;
142
143 if (empty($_GET["fSendTxt"]))
144 $query0 .= " LIMIT " . $_GET["fNumStart"] . ", " . $_GET["fNumResults"];
145
146 return $query0;
147 }
148
149 function InitGet($_GET)
150 {
151 // Find out whether it is the first call to the php script
152 $first = empty($_GET["fRunMin"]) && empty($_GET["fRunMax"]);
153
154 if (empty($_GET["fNumResults"]))
155 $_GET["fNumResults"]="50";
156
157 if (empty($_GET["fLastUpdate"]))
158 $_GET["fLastUpdate"]="Off";
159
160 if (empty($_GET["fLinks"]))
161 $_GET["fLinks"]=$first?"On":"";
162
163 if (empty($_GET["fComment"]))
164 $_GET["fComment"]="Off";
165
166 if (empty($_GET["fWobble"]))
167 $_GET["fWobble"]=$first?"On":"";
168
169 if (empty($_GET["fExcessEvents"]))
170 $_GET["fExcessEvents"]=$first?"On":"";
171
172 if (empty($_GET["fExcessEvents*60/fEffOnTime"]))
173 $_GET["fExcessEvents*60/fEffOnTime"]=$first?"Off":"";
174
175 if (empty($_GET["fBackgroundEvents*60/fEffOnTime"]))
176 $_GET["fBackgroundEvents*60/fEffOnTime"]=$first?"On":"";
177
178 if (empty($_GET["fBackgroundEvents"]))
179 $_GET["fBackgroundEvents"]=$first?"On":"";
180
181 if (empty($_GET["fSignalEvents"]))
182 $_GET["fSignalEvents"]=$first?"On":"";
183
184 if (empty($_GET["fSignalEvents*60/fEffOnTime"]))
185 $_GET["fSignalEvents*60/fEffOnTime"]=$first?"Off":"";
186
187 if (empty($_GET["fSignificance"]))
188 $_GET["fSignificance"]=$first?"On":"";
189
190 if (empty($_GET["Round(fSignificance/Sqrt(fEffOnTime/3600),2)"]))
191 $_GET["Round(fSignificance/Sqrt(fEffOnTime/3600),2)"]=$first?"Off":"";
192
193 if (empty($_GET["fScaleFactor"]))
194 $_GET["fScaleFactor"]=$first?"On":"";
195
196 if (empty($_GET["fEffOnTime/3600"]))
197 $_GET["fEffOnTime/3600"]=$first?"On":"";
198
199 if (empty($_GET["fDataSetInserted"]))
200 $_GET["fDataSetInserted"]="Off";
201
202 if (empty($_GET["fDataSetInsertedStatus"]))
203 $_GET["fDataSetInsertedStatus"]="0";
204
205 if (empty($_GET["fStarFilesAvail"]))
206 $_GET["fStarFilesAvail"]="Off";
207
208 if (empty($_GET["fStarFilesAvailStatus"]))
209 $_GET["fStarFilesAvailStatus"]="0";
210
211 if (empty($_GET["fGanymed"]))
212 $_GET["fGanymed"]=$first?"On":"";
213
214 if (empty($_GET["fGanymedStatus"]))
215 $_GET["fGanymedStatus"]="0";
216
217 if (empty($_GET["fFillGanymed"]))
218 $_GET["fFillGanymed"]="Off";
219
220 if (empty($_GET["fFillGanymedStatus"]))
221 $_GET["fFillGanymedStatus"]="0";
222
223 if (empty($_GET["fSourceName"]))
224 $_GET["fSourceName"]=$first?"On":"";
225
226 if (empty($_GET["fLastUpdate"]))
227 $_GET["fLastUpdate"]="Off";
228
229 if (empty($_GET["fStartTime"]))
230 $_GET["fStartTime"]="Off";
231
232 if (empty($_GET["fFailedTime"]))
233 $_GET["fFailedTime"]="Off";
234
235 if (empty($_GET["fReturnCode"]))
236 $_GET["fReturnCode"]="Off";
237
238 if (empty($_GET["fProgramId"]))
239 $_GET["fProgramId"]="Off";
240
241 }
242
243 function PrintForm($_GET, $host, $user, $pw, $db)
244 {
245 printf("<center>\n");
246 printf("<form action=\"datasetinfo.php\" METHOD=\"GET\">\n");
247 printf(" <table>\n");
248 printf(" <tr>\n");
249
250 CheckBox("fWobble", "Wobble");
251 CheckBox("fComment", "Comment");
252 CheckBox("fScaleFactor", "Scale");
253 CheckBox("fEffOnTime/3600", "EffOnTime");
254 CheckBox("fLinks", "Links");
255
256 printf(" </tr><tr>\n");
257
258 CheckBox("fExcessEvents", "ExcEvts");
259 CheckBox("fBackgroundEvents", "BgEvts");
260 CheckBox("fSignalEvents", "SignEvts");
261 CheckBox("fSignificance", "Sign");
262
263 printf(" </tr><tr>\n");
264
265 CheckBox("fExcessEvents*60/fEffOnTime", "ExcRate");
266 CheckBox("fBackgroundEvents*60/fEffOnTime", "BgRate");
267 CheckBox("fSignalEvents*60/fEffOnTime", "SignRate");
268 CheckBox("Round(fSignificance/Sqrt(fEffOnTime/3600),2)", "SignfRate");
269
270 printf(" </tr>\n");
271 printf(" </table>\n");
272 printf(" <p>\n");
273 printf(" <table>\n");
274 printf(" <tr>\n");
275
276 CheckBox("fStartTime", "StartTime");
277 CheckBox("fFailedTime", "FailedTime");
278 CheckBox("fReturnCode", "RetCode");
279 CheckBox("fProgramId", "ProgramId");
280
281 printf(" </tr>\n");
282 printf(" </table>\n");
283 printf(" <table>\n");
284 printf(" <tr>\n");
285
286 printf(" <td>\n");
287 PrintStatusMenu("fDataSetInserted", "DataSet Inserted");
288 printf(" </td><td>\n");
289 PrintStatusMenu("fStarFilesAvail", "FilesAvail");
290 printf(" </td><td>\n");
291 PrintStatusMenu("fGanymed", "Ganymed");
292 printf(" </td><td>\n");
293 PrintStatusMenu("fFillGanymed", "FillGanymed");
294
295 printf(" </td></tr><tr><td>\n");
296
297 PrintPullDown($host, $user, $pw, $db, "Source", "fSourceName", "fSourceKEY", "Source Name");
298
299 printf(" </td></tr>\n");
300 printf(" </table>\n");
301 printf(" <p>\n");
302
303 if (empty($_GET["fRunMin"]))
304 $min = GetMin("fDataSetNumber", "DataSets", $host, $user, $pw, $db);
305 else
306 $min = $_GET["fRunMin"];
307
308 if (empty($_GET["fRunMax"]))
309 $max = GetMax("fDataSetNumber", "DataSets", $host, $user, $pw, $db);
310 else
311 $max = $_GET["fRunMax"];
312
313/*
314 printf("Date&nbsp;(yyyy-mm-dd)&nbsp;<input name=\"fDate\" type=\"text\" size=\"10\" maxlength=\"10\" value=\"");
315 if (!empty($_GET["fDate"]))
316 printf("%s", $_GET["fDate"]);
317 printf("\">&nbsp;&nbsp;&nbsp;\n");
318*/
319
320 printf("Source&nbsp;(<A HREF=\"regexp.html\">regexp</A>)&nbsp;<input name=\"fSourceN\" type=\"text\" size=\"15\" maxlength=\"15\" value=\"");
321 if (!empty($_GET["fSourceN"]))
322 printf("%s", $_GET["fSourceN"]);
323 printf("\">&nbsp;&nbsp;&nbsp;\n");
324
325 printf("DataSets&nbsp;from&nbsp;<input name=\"fRunMin\" type=\"text\" size=\"6\" maxlength=\"6\" value=\"%s\">\n", $min);
326 printf("to&nbsp;<input name=\"fRunMax\" type=\"text\" size=\"6\" maxlength=\"6\" value=\"%s\">&nbsp;&nbsp;&nbsp;\n", $max);
327
328 printf(" <P>\n");
329
330 printf(" Results:\n");
331 printf(" <select name=\"fNumResults\">\n");
332
333 $numres = array("10", "20", "50", "100", "200", "500");
334 foreach ($numres as $element)
335 {
336 if ($element==$_GET["fNumResults"])
337 printf("<option value=\"%s\" selected>%3s</option>\n", $element, $element);
338 else
339 printf("<option value=\"%s\">%3s</option>\n", $element, $element);
340 }
341 printf(" </select>\n");
342 printf(" &nbsp;&nbsp;&nbsp;\n");
343
344 ini_set("mysql.trace_mode", "Off");
345 ini_set("display_errors", "Off");
346
347 printf("<input class='Width' type='submit' value='Query Table'>&nbsp;&nbsp;&nbsp;\n");
348 printf("<input class='Width' type='button' value='Reset' onClick='self.location.href=\"datasetinfo.php\"'>&nbsp;&nbsp;&nbsp;\n");
349 if (strchr($_SERVER["REQUEST_URI"], '?')!=FALSE)
350 printf("<input class='Width' type='button' value='Get .txt' onClick='self.location.href=\"%s&fSendTxt=1\"'>&nbsp;&nbsp;&nbsp;\n", $_SERVER["REQUEST_URI"]);
351 if (strchr($_SERVER["REQUEST_URI"], '?')!=FALSE)
352 printf("<input class='Width' type='button' value='Print' onClick='self.location.href=\"%s&fPrintTable=1\"'>&nbsp;&nbsp;&nbsp;\n", $_SERVER["REQUEST_URI"]);
353 printf("</form>\n");
354 printf("</center>\n");
355 printf("</td>\n");
356 printf("</tr>\n");
357 printf("<tr class='Block'>\n");
358 printf("<td>\n");
359 }
360
361 function PrintPage($html, $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $needs)
362 {
363 $db_id = mysql_connect($host, $user, $pw);
364 if ($db_id==FALSE)
365 {
366 printf("mysql_connect returned the following error: %s\n", mysql_error());
367 die("");
368 }
369 mysql_select_db($db);
370
371 $query0 = CreateQuery($_GET, $alias, $checkwhere, $checkgroup, $checkstatusgroup, $needs);
372
373 $result0 = mysql_query($query0, $db_id);
374
375 if ($result0)
376 {
377 if ($html=="1" || $html=="2")
378 PrintMagicTable($result0, $alias, $rightalign, "", "", "", "", $_GET);
379 else
380 PrintText($result0);
381
382 mysql_free_result($result0);
383 }
384 mysql_close($db_id);
385
386 PrintSubmittedQuery($query0, $html, $db, "old");
387 }
388
389 include ("include.php");
390 include ("db.php");
391 include ("magicdefs.php");
392
393 ini_set("display_errors", "On");
394 ini_set("mysql.trace_mode", "On");
395
396 if (!empty($_GET["fSendTxt"]))
397 {
398 header("Content-type: application/octet");
399 header("Content-Disposition: attachment; filename=query-result.txt");
400
401 PrintPage("0", $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup);
402 }
403 else
404 {
405 echo (file_get_contents("index-header.html"));
406
407 $environment = sizeof($_GET);
408
409 InitGet($_GET);
410 if (empty($_GET["fPrintTable"]))
411 PrintForm($_GET, $host, $user, $pw, $db);
412
413 if ($environment==0)
414 printf("No query submitted yet.<BR>");
415 else
416 {
417 if (empty($_GET["fPrintTable"]))
418 PrintPage("1", $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $needs);
419 else
420 PrintPage("2", $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $needs);
421 }
422
423 echo (file_get_contents("index-footer.html"));
424 }
425
426 ini_set("display_errors", "Off");
427 ini_set("mysql.trace_mode", "Off");
428}
429?>
Note: See TracBrowser for help on using the repository browser.