source: tags/Mars-V1.1/datacenter/db/ganymed.php

Last change on this file was 8273, checked in by Daniela Dorner, 18 years ago
*** empty log message ***
  • Property svn:executable set to *
File size: 13.2 KB
Line 
1<?php
2{
3 function CreateQuery($_GET)
4 {
5 $query0 = "SELECT ";
6 //datasets (0-3)
7 $query0 .= " DataSets.fDataSetNumber, fDataSetName, fComment, ";//0,1,2
8 $query0 .= " fSourceName, ";//3
9 //steps (4-7)
10 $query0 .= " fDataSetInserted, fStarFilesAvail, ";//4,5
11 $query0 .= " fGanymed, fFillGanymed, ";//6,7
12 //ganymed (8-13)
13 $query0 .= " fExcessEvents, fBackgroundEvents, fSignalEvents, ";//8,9,10
14 $query0 .= " fSignificance, fScaleFactor, fEffOnTime/3600 ";//11,12,13
15
16 $query0 .= " FROM DataSets ";
17
18 $query0 .= " LEFT JOIN Source ON DataSets.fSourceKEY=Source.fSourceKEY ";
19 $query0 .= " LEFT JOIN DataSetProcessStatus ON DataSets.fDataSetNumber=DataSetProcessStatus.fDataSetNumber ";
20 $query0 .= " LEFT JOIN Ganymed ON DataSets.fDataSetNumber=Ganymed.fDataSetNumber ";
21
22 if (!empty($_GET["fRunMin"]) && !empty($_GET["fRunMax"]))
23 $query0 .= " WHERE DataSets.fDataSetNumber between " . $_GET["fRunMin"] . " and " . $_GET["fRunMax"] ;
24 if (!empty($_GET["fDataSetNo"]))
25 {
26 if (strpos($query0, " WHERE ")==FALSE)
27 $query0 .= " WHERE ";
28 else
29 $query0 .= " AND ";
30 $query0 .= " DataSets.fDataSetNumber='" . $_GET["fDataSetNo"] . "'";
31 }
32 if (!empty($_GET["fSourceN"]))
33 {
34 if (strpos($query0, " WHERE ")==FALSE)
35 $query0 .= " WHERE ";
36 else
37 $query0 .= " AND ";
38 $query0 .= " fSourceName REGEXP \"^" . $_GET["fSourceN"] . "\" ";
39 }
40 $query0 .= " ORDER BY DataSets.fDataSetNumber ";
41
42 return $query0;
43 }
44
45 function InitGet($_GET)
46 {
47 // Find out whether it is the first call to the php script
48 $first = empty($_GET["fRunMin"]) && empty($_GET["fRunMax"]);
49
50 if (empty($_GET["fNumResults"]))
51 $_GET["fNumResults"]="20";
52
53 if (empty($_GET["fAll"]))
54 $_GET["fAll"]="Off";
55
56 if (empty($_GET["fSequ"]))
57 $_GET["fSequ"]="Off";
58
59 }
60
61 function PrintForm($_GET, $host, $user, $pw, $db)
62 {
63 printf("<center>\n");
64 printf("<form action=\"ganymed.php\" METHOD=\"GET\">\n");
65
66 printf("DataSet#&nbsp;<input name=\"fDataSetNo\" type=\"text\" size=\"6\" maxlength=\"6\" value=\"");
67 if (!empty($_GET["fDataSetNo"]))
68 printf("%s", $_GET["fDataSetNo"]);
69 printf("\">&nbsp;&nbsp;&nbsp;\n");
70
71 if (empty($_GET["fRunMin"]))
72// $min = "100";
73 $min = GetMin("fDataSetNumber", "DataSets", $host, $user, $pw, $db);
74 else
75 $min = $_GET["fRunMin"];
76
77 if (empty($_GET["fRunMax"]))
78 $max = GetMax("fDataSetNumber", "DataSets", $host, $user, $pw, $db);
79 else
80 $max = $_GET["fRunMax"];
81
82 printf("DataSets&nbsp;from&nbsp;<input name=\"fRunMin\" type=\"text\" size=\"6\" maxlength=\"6\" value=\"%s\">\n", $min);
83 printf("to&nbsp;<input name=\"fRunMax\" type=\"text\" size=\"6\" maxlength=\"6\" value=\"%s\">&nbsp;&nbsp;&nbsp;\n", $max);
84
85 if ($_GET["fAll"]=="On")
86 $checked = "checked";
87 else
88 $checked = "";
89 printf("<input type=\"checkbox\" name=\"fAll\" value=\"On\" %s>plots\n", $checked);
90
91 if ($_GET["fSequ"]=="On")
92 $checked = "checked";
93 else
94 $checked = "";
95 printf("<input type=\"checkbox\" name=\"fSequ\" value=\"On\" %s>sequences\n", $checked);
96
97 printf(" <P>\n");
98
99 printf("Source&nbsp;(<A HREF=\"regexp.html\">regexp</A>)&nbsp;<input name=\"fSourceN\" type=\"text\" size=\"15\" maxlength=\"15\" value=\"");
100 if (!empty($_GET["fSourceN"]))
101 printf("%s", $_GET["fSourceN"]);
102 printf("\">&nbsp;&nbsp;&nbsp;\n");
103
104
105 ini_set("mysql.trace_mode", "Off");
106 ini_set("display_errors", "Off");
107
108 printf("<input class='Width' type='submit' value='Query Table'>&nbsp;&nbsp;&nbsp;\n");
109 printf("<input class='Width' type='button' value='Reset' onClick='self.location.href=\"ganymed.php\"'>&nbsp;&nbsp;&nbsp;\n");
110 if (strchr($_SERVER["REQUEST_URI"], '?')!=FALSE)
111 printf("<input class='Width' type='button' value='Print' onClick='self.location.href=\"%s&fPrintTable=1\"'>&nbsp;&nbsp;&nbsp;\n", $_SERVER["REQUEST_URI"]);
112 printf("</form>\n");
113 printf("</center>\n");
114 printf("</td>\n");
115 printf("</tr>\n");
116 printf("<tr class='Block'>\n");
117 printf("<td>\n");
118 }
119
120 function GetStatus($step)
121 {
122 if (is_null($step))
123 return "<font color='#FF0000'>not done</font>";
124 else
125 {
126 if (strpos($step, "1970-01-01 00:00:00")==FALSE)
127 return "done";
128 else
129 return "not to be done";
130 }
131 return "there is an error -> tell Dani";
132 }
133
134 function GetRanges($db_id, $sequences)
135 {
136 $query="SELECT Min(fZenithDistanceMin), Max(fZenithDistanceMax), Min(fRunStart), Max(fRunStart) FROM Sequences WHERE fSequenceFirst IN (";
137 $sequlist=str_replace(" ", ",", trim($sequences));
138// printf("sequ-after: %s", $sequlist);
139 $query .= $sequlist . ")";
140 $result = mysql_query($query, $db_id);
141// printf("query: %s", $query);
142 $zdmin=mysql_result($result, $i, 0);
143 $zdmax=mysql_result($result, $i, 1);
144 $starttime=str_replace("-", "/",substr(mysql_result($result, $i, 2),0,10));
145 $stoptime=str_replace("-", "/",substr(mysql_result($result, $i, 3),0,10));
146 printf("<br> Zd: %s - %s degree <br> Observationperiod: %s - %s ", $zdmin, $zdmax, $starttime, $stoptime);
147 }
148
149 function PrintDataSetInfo($db_id, $result0, $ganymedtabsw, $ganymedtabs)
150 {
151 $numres = mysql_num_rows($result0);
152
153 printf("<center>");
154 printf("<table BORDER=\"0\">\n");
155 printf("<tr><td>");
156 printf("# of DataSets: %d ", $numres);
157 printf("</td></tr>");
158
159 for ($i=0 ; $i<$numres ; $i++)
160 {
161 $datasetno=mysql_result($result0, $i, 0);
162 $datasetname=mysql_result($result0, $i, 1);
163 $comment=mysql_result($result0, $i, 2);
164 $source=mysql_result($result0, $i, 3);
165 $inserted=mysql_result($result0, $i, 4);
166 $filesavail=mysql_result($result0, $i, 5);
167 $ganymed=mysql_result($result0, $i, 6);
168 $fillganymed=mysql_result($result0, $i, 7);
169 $excess=mysql_result($result0, $i, 8);
170 $bg=mysql_result($result0, $i, 9);
171 $signal=mysql_result($result0, $i, 10);
172 $signif=mysql_result($result0, $i, 11);
173 $scale=mysql_result($result0, $i, 12);
174 $effontime=mysql_result($result0, $i, 13);
175 $num=sprintf("%08d",$datasetno);
176 $num2=substr($num,0,5);
177 $datasetfile="http://www.astro.uni-wuerzburg.de/datacenter/datasets/" . $num2 . "/dataset" . $num . ".txt";
178
179 printf("<tr><td>");
180
181 printf(" <table BORDER=\"1\">");
182 printf(" <tr BGCOLOR='#C0C0C0'>\n");
183 printf(" <th colspan=\"6\"><big>Source: <big>%s </big></big>(DataSet#:", $source, $datasetno);
184 printf(" <a href=\"%s\">%s</a>) </th>", $datasetfile, $datasetno);
185 printf(" </tr><tr BGCOLOR='#E0E0E0' ALIGN='left'>\n");
186 printf(" <th colspan=\"6\"> %s ", $comment);
187 printf(" </th></tr><tr>\n");
188
189 printf(" <td colspan=\"6\"> DatasetName: %s", $datasetname);
190 if (!is_null($ganymed))
191 printf(", <font color='green'> ganymed done</font> ");
192
193 printf(" <tr>");
194
195 if (!is_null($fillganymed))
196 {
197 printf("<td colspan=\"6\"></td></tr>\n");
198 printf(" <tr BGCOLOR='#C0C0C0'><th colspan=\"6\">results ");
199 printf(" (<a href=\"http://www.astro.uni-wuerzburg.de/datacenter/ganymed/%s/%s/\">plots</a>)",
200 $num2, $num);
201 printf(" </th></tr><tr BGCOLOR='#E0E0E0'>\n");
202 printf(" <td>excess events</td>\n");
203 printf(" <td>background events</td>\n");
204 printf(" <td>signal events</td>\n");
205 printf(" <td>significance</td>\n");
206 printf(" <td>scale factor</td>\n");
207 printf(" <td>effective ontime</td>\n");
208 printf(" </tr><tr BGCOLOR='#D0D0D0' align='right'>");
209 printf(" <td>%s</td>\n", $excess);
210 printf(" <td>%s</td>\n", $bg);
211 printf(" <td>%s</td>\n", $signal);
212 printf(" <td>%s</td>\n", $signif);
213 printf(" <td>%s</td>\n", $scale);
214 printf(" <td>%s h</td>\n", $effontime);
215 }
216
217 if ($_GET["fSequ"]=="On")
218 {
219 $dataset=file_get_contents($datasetfile);
220 $onpos=strpos($dataset, "SequencesOn:");
221 $offpos=strpos($dataset, "SequencesOff:");
222 $possource=strpos($dataset, "SourceName:");
223 $sequoff="";
224 if (!empty($offpos))
225 $sequoff=substr($dataset, $offpos+13, $possource-($offpos+13));
226 if (empty($offpos))
227 $offpos=$possource;
228 $sequon=substr($dataset, $onpos+12, $offpos-($onpos+12));
229
230 if (!empty($sequon))
231 {
232 printf("<tr><td colspan=\"6\">\n SequencesOn: ");
233 $sequences=split(" ", trim($sequon));
234 foreach($sequences as $key => $sequ)
235 printf("<a href=\"sequence.php?fSequenceNo=%s&fAll=On\">%s</a> ", $sequ, $sequ);
236 GetRanges($db_id, $sequon);
237 printf("</td></tr>");
238
239 if (!empty($sequoff))
240 {
241 printf("<tr><td colspan=\"6\">\n SequencesOff: ");
242 $sequences=split(" ", trim($sequoff));
243 foreach($sequences as $key => $sequ)
244 printf("<a href=\"sequence.php?fSequenceNo=%s&fAll=On\">%s</a> ", $sequ, $sequ);
245 GetRanges($db_id, $sequoff);
246 printf("</td></tr>");
247 }
248 }
249 }
250 printf("<tr><td colspan=\"6\">\n Plots: ");
251
252 if ($wobble=='Y')
253 $tabs=$ganymedtabsw;
254 else
255 $tabs=$ganymedtabs;
256 foreach($tabs as $key => $element)
257 if (!$key==0)
258 printf("<a href=\"http://www.astro.uni-wuerzburg.de/datacenter/ganymed/%s/%s/ganymed%s-tab%s.png\">%s</a> ", $num2, $num, $num, $key, $element);
259
260 printf("</td></tr>");
261
262 if ($_GET["fAll"]=="On" && !is_null($ganymed))
263 {
264 printf("<tr><td colspan=\"6\" align='center'>\n");
265 printf(" <img src=\"http://www.astro.uni-wuerzburg.de/datacenter/ganymed/%s/%s/ganymed%s-tab11.png\">",
266 $num2, $num, $num);
267 printf(" <img src=\"http://www.astro.uni-wuerzburg.de/datacenter/ganymed/%s/%s/ganymed%s-tab10.png\">",
268 $num2, $num, $num);
269 printf(" </td></tr>");
270 }
271
272 printf(" </table>");
273 printf("</td></tr><tr><td><br></td></tr>");
274 }
275 printf("</table>\n");
276
277 printf("</center>\n");
278 printf("</tr><tr class='Block'><td>\n");
279 }
280
281 function PrintPage($html, $host, $user, $pw, $db, $ganymedtabsw, $ganymedtabs)
282 {
283 $db_id = mysql_connect($host, $user, $pw);
284 if ($db_id==FALSE)
285 {
286 printf("mysql_connect returned the following error: %s\n", mysql_error());
287 die("");
288 }
289 mysql_select_db($db);
290
291 $query0 = CreateQuery($_GET);
292
293 $result0 = mysql_query($query0, $db_id);
294
295 if ($result0)
296 {
297 if ($html=="1" || $html=="2")
298 PrintDataSetInfo($db_id, $result0, $ganymedtabsw, $ganymedtabs);
299 else
300 PrintText($result0);
301
302 mysql_free_result($result0);
303 }
304 mysql_close($db_id);
305
306 PrintSubmittedQuery($query0, $html, $db, "old");
307 }
308
309 include ("include.php");
310 include ("db.php");
311 include ("tabs.php");
312
313 ini_set("display_errors", "On");
314 ini_set("mysql.trace_mode", "On");
315
316 if (!empty($_GET["fSendTxt"]))
317 {
318 header("Content-type: application/octet");
319 header("Content-Disposition: attachment; filename=query-result.txt");
320
321 PrintPage("0", $host, $user, $pw, $db, $ganymedtabsw, $ganymedtabs);
322 }
323 else
324 {
325 echo (file_get_contents("index-header.html"));
326
327 $environment = sizeof($_GET);
328
329 InitGet($_GET);
330 if (empty($_GET["fPrintTable"]))
331 PrintForm($_GET, $host, $user, $pw, $db);
332
333 if ($environment==0)
334 printf("No query submitted yet.<BR>");
335 else
336 {
337 if (empty($_GET["fPrintTable"]))
338 PrintPage("1", $host, $user, $pw, $db, $ganymedtabsw, $ganymedtabs);
339 else
340 PrintPage("2", $host, $user, $pw, $db, $ganymedtabsw, $ganymedtabs);
341 }
342
343 echo (file_get_contents("index-footer.html"));
344 }
345
346 ini_set("display_errors", "Off");
347 ini_set("mysql.trace_mode", "Off");
348}
349?>
Note: See TracBrowser for help on using the repository browser.