source: tags/Mars-V0.10.3/datacenter/db/ganymed.php

Last change on this file was 7873, checked in by Daniela Dorner, 18 years ago
*** empty log message ***
  • Property svn:executable set to *
File size: 13.1 KB
Line 
1<?php
2{
3 function CreateQuery($_GET)
4 {
5 $query0 = "SELECT ";
6 //datasets (0-3)
7 $query0 .= " DataSets.fDataSetNumber, fWobble, 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 $wobble=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\"> Wobble: %s", $wobble);
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 if ($wobble=='Y')
252 $tabs=$ganymedtabsw;
253 else
254 $tabs=$ganymedtabs;
255 foreach($tabs as $key => $element)
256 if (!$key==0)
257 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);
258
259 printf("</td></tr>");
260
261 if ($_GET["fAll"]=="On" && !is_null($ganymed))
262 {
263 printf("<tr><td colspan=\"6\" align='center'>\n");
264 printf(" <img src=\"http://www.astro.uni-wuerzburg.de/datacenter/ganymed/%s/%s/ganymed%s-tab11.png\">",
265 $num2, $num, $num);
266 printf(" <img src=\"http://www.astro.uni-wuerzburg.de/datacenter/ganymed/%s/%s/ganymed%s-tab10.png\">",
267 $num2, $num, $num);
268 printf(" </td></tr>");
269 }
270
271 printf(" </table>");
272 printf("</td></tr><tr><td><br></td></tr>");
273 }
274 printf("</table>\n");
275
276 printf("</center>\n");
277 printf("</tr><tr class='Block'><td>\n");
278 }
279
280 function PrintPage($html, $host, $user, $pw, $db, $ganymedtabsw, $ganymedtabs)
281 {
282 $db_id = mysql_connect($host, $user, $pw);
283 if ($db_id==FALSE)
284 {
285 printf("mysql_connect returned the following error: %s\n", mysql_error());
286 die("");
287 }
288 mysql_select_db($db);
289
290 $query0 = CreateQuery($_GET);
291
292 $result0 = mysql_query($query0, $db_id);
293
294 if ($result0)
295 {
296 if ($html=="1" || $html=="2")
297 PrintDataSetInfo($db_id, $result0, $ganymedtabsw, $ganymedtabs);
298 else
299 PrintText($result0);
300
301 mysql_free_result($result0);
302 }
303 mysql_close($db_id);
304
305 PrintSubmittedQuery($query0, $html, $db, "old");
306 }
307
308 include ("include.php");
309 include ("db.php");
310 include ("tabs.php");
311
312 ini_set("display_errors", "On");
313 ini_set("mysql.trace_mode", "On");
314
315 if (!empty($_GET["fSendTxt"]))
316 {
317 header("Content-type: application/octet");
318 header("Content-Disposition: attachment; filename=query-result.txt");
319
320 PrintPage("0", $host, $user, $pw, $db, $ganymedtabsw, $ganymedtabs);
321 }
322 else
323 {
324 echo (file_get_contents("index-header.html"));
325
326 $environment = sizeof($_GET);
327
328 InitGet($_GET);
329 if (empty($_GET["fPrintTable"]))
330 PrintForm($_GET, $host, $user, $pw, $db);
331
332 if ($environment==0)
333 printf("No query submitted yet.<BR>");
334 else
335 {
336 if (empty($_GET["fPrintTable"]))
337 PrintPage("1", $host, $user, $pw, $db, $ganymedtabsw, $ganymedtabs);
338 else
339 PrintPage("2", $host, $user, $pw, $db, $ganymedtabsw, $ganymedtabs);
340 }
341
342 echo (file_get_contents("index-footer.html"));
343 }
344
345 ini_set("display_errors", "Off");
346 ini_set("mysql.trace_mode", "Off");
347}
348?>
Note: See TracBrowser for help on using the repository browser.