source: trunk/MagicSoft/Mars/datacenter/db/ganymed.php@ 8467

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