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

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