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

Last change on this file since 7527 was 7527, checked in by Daniela Dorner, 19 years ago
*** empty log message ***
  • Property svn:executable set to *
File size: 14.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 }
229
230 function PrintForm($_GET, $db)
231 {
232 printf("<center>\n");
233 printf("<form action=\"datasetinfo.php\" METHOD=\"GET\">\n");
234 printf(" <table>\n");
235 printf(" <tr>\n");
236
237 CheckBox("fWobble", "Wobble");
238 CheckBox("fExcessEvents", "ExcEvts");
239 CheckBox("fBackgroundEvents", "BgEvts");
240 CheckBox("fSignalEvents", "SignEvts");
241
242 printf(" </tr><tr>\n");
243
244 CheckBox("fSignificance", "Sign");
245 CheckBox("fScaleFactor", "Scale");
246 CheckBox("fEffOnTime/3600", "EffOnTime");
247 CheckBox("fComment", "Comment");
248
249 printf(" </tr><tr>\n");
250
251 CheckBox("fExcessEvents*60/fEffOnTime", "ExcRate");
252 CheckBox("fBackgroundEvents*60/fEffOnTime", "BgRate");
253 CheckBox("fSignalEvents*60/fEffOnTime", "SignRate");
254 CheckBox("Round(fSignificance/Sqrt(fEffOnTime/3600),2)", "SignfRate");
255
256 printf(" </tr><tr>\n");
257
258 CheckBox("fLinks", "Links");
259
260 printf(" </tr><tr><td>\n");
261 PrintStatusMenu("fDataSetInserted", "DataSet Inserted");
262 printf(" </td><td>\n");
263 PrintStatusMenu("fStarFilesAvail", "FilesAvail");
264 printf(" </td><td>\n");
265 PrintStatusMenu("fGanymed", "Ganymed");
266 printf(" </td><td>\n");
267 PrintStatusMenu("fFillGanymed", "FillGanymed");
268
269 printf(" </td></tr><tr><td>\n");
270
271 PrintPullDown($db, "Source", "fSourceName", "fSourceKEY", "Source Name");
272
273 printf(" </td></tr>\n");
274 printf(" </table>\n");
275 printf(" <p>\n");
276
277 if (empty($_GET["fRunMin"]))
278 $min = GetMin("fDataSetNumber", "DataSets", $db);
279 else
280 $min = $_GET["fRunMin"];
281
282 if (empty($_GET["fRunMax"]))
283 $max = GetMax("fDataSetNumber", "DataSets", $db);
284 else
285 $max = $_GET["fRunMax"];
286
287/*
288 printf("Date&nbsp;(yyyy-mm-dd)&nbsp;<input name=\"fDate\" type=\"text\" size=\"10\" maxlength=\"10\" value=\"");
289 if (!empty($_GET["fDate"]))
290 printf("%s", $_GET["fDate"]);
291 printf("\">&nbsp;&nbsp;&nbsp;\n");
292*/
293
294 printf("Source&nbsp;(<A HREF=\"regexp.html\">regexp</A>)&nbsp;<input name=\"fSourceN\" type=\"text\" size=\"15\" maxlength=\"15\" value=\"");
295 if (!empty($_GET["fSourceN"]))
296 printf("%s", $_GET["fSourceN"]);
297 printf("\">&nbsp;&nbsp;&nbsp;\n");
298
299 printf("DataSets&nbsp;from&nbsp;<input name=\"fRunMin\" type=\"text\" size=\"6\" maxlength=\"6\" value=\"%s\">\n", $min);
300 printf("to&nbsp;<input name=\"fRunMax\" type=\"text\" size=\"6\" maxlength=\"6\" value=\"%s\">&nbsp;&nbsp;&nbsp;\n", $max);
301
302 printf(" <P>\n");
303
304 printf(" Results:\n");
305 printf(" <select name=\"fNumResults\">\n");
306
307 $numres = array("10", "20", "50", "100", "200", "500");
308 foreach ($numres as $element)
309 {
310 if ($element==$_GET["fNumResults"])
311 printf("<option value=\"%s\" selected>%3s</option>\n", $element, $element);
312 else
313 printf("<option value=\"%s\">%3s</option>\n", $element, $element);
314 }
315 printf(" </select>\n");
316 printf(" &nbsp;&nbsp;&nbsp;\n");
317
318 ini_set("mysql.trace_mode", "Off");
319 ini_set("display_errors", "Off");
320
321 printf("<input class='Width' type='submit' value='Query Table'>&nbsp;&nbsp;&nbsp;\n");
322 printf("<input class='Width' type='button' value='Reset' onClick='self.location.href=\"datasetinfo.php\"'>&nbsp;&nbsp;&nbsp;\n");
323 if (strchr($_SERVER["REQUEST_URI"], '?')!=FALSE)
324 printf("<input class='Width' type='button' value='Get .txt' onClick='self.location.href=\"%s&fSendTxt=1\"'>&nbsp;&nbsp;&nbsp;\n", $_SERVER["REQUEST_URI"]);
325 if (strchr($_SERVER["REQUEST_URI"], '?')!=FALSE)
326 printf("<input class='Width' type='button' value='Print' onClick='self.location.href=\"%s&fPrintTable=1\"'>&nbsp;&nbsp;&nbsp;\n", $_SERVER["REQUEST_URI"]);
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, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $needs)
336 {
337 $db_id = mysql_connect("hercules.astro.uni-wuerzburg.de", "MAGIC", "d99swMT!");
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, "", "", $_GET);
353 else
354 PrintText($result0);
355
356 mysql_free_result($result0);
357 }
358 mysql_close($db_id);
359
360 if ($html=="1")
361 printf("<U><B>submitted query:</B></U><BR>%s<BR>", htmlspecialchars($query0));
362 }
363
364 include ("include.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", $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup);
377 }
378 else
379 {
380 echo (file_get_contents("index-header.html"));
381
382 $environment = sizeof($_GET);
383
384 InitGet($_GET);
385 if (empty($_GET["fPrintTable"]))
386 PrintForm($_GET, $db);
387
388 if ($environment==0)
389 printf("No query submitted yet.<BR>");
390 else
391 {
392 if (empty($_GET["fPrintTable"]))
393 PrintPage("1", $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $needs);
394 else
395 PrintPage("2", $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $needs);
396 }
397
398 echo (file_get_contents("index-footer.html"));
399 }
400
401 ini_set("display_errors", "Off");
402 ini_set("mysql.trace_mode", "Off");
403}
404?>
Note: See TracBrowser for help on using the repository browser.