source: tags/Mars-V0.9.4.3/datacenter/db/datasetinfo.php

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