source: tags/Mars-V0.9.4.3/datacenter/db/include.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: 15.4 KB
Line 
1<?php
2/*
3function PrintTable($table)
4{
5 $db_id = mysql_connect("hercules.astro.uni-wuerzburg.de", "MAGIC", "d99swMT!");
6 if ($db_id==FALSE)
7 {
8 printf("mysql_connect returned the following error:<br>");
9 printf("%s<br>", mysql_error());
10 die("");
11 }
12 printf("%s<br>", $table);
13 printf("<table BORDER=\"1\">");
14
15 $query = "EXPLAIN ";
16 $query .= $table;
17
18 $result = mysql_query($query);
19 $numrows = mysql_num_rows($result);
20 $numcols = mysql_num_fields($result);
21 printf("%d x %d<br>", $numrows, $numcols);
22
23 printf("<tr>");
24 for ($i=0; $i<$numrows; $i++)
25 {
26 $row = mysql_fetch_row($result);
27 printf("<th>%s</th> ", $row[0]);
28 }
29 printf("</tr>");
30
31 $query = "SELECT * FROM ";
32 $query .= $table;
33
34 $result = mysql_query($query);
35
36 $numrows = mysql_num_rows($result);
37 $numcols = mysql_num_fields($result);
38 printf("%d x %d<br>", $numrows, $numcols);
39
40 while ($row = mysql_fetch_row($result))
41 {
42 printf("<tr>");
43 foreach ($row as $entry)
44 {
45 printf("<td>%s</td> ", $entry);
46 }
47 printf("</tr>");
48 }
49 printf("</table>");
50
51 mysql_free_result($result);
52
53 mysql_close($db_id);
54}
55*/
56
57function EnumQuery($name)
58{
59 $var = $name . "Enum";
60 $txt = "";
61 switch ($_GET[$var])
62 {
63 case 0: $txt .= ""; break;
64 case 1: $txt .= $name . "='yes' AND "; break;
65 case 2: $txt .= $name . "='no' AND "; break;
66 case 3: $txt .= ""; break;
67 }
68 return $txt;
69}
70
71function PrintEnumMenu($name, $text)
72{
73 $var = $name . "Enum";
74
75 if ($_GET[$name]=="On")
76 $checked = "checked";
77 else
78 $checked = "";
79
80 printf(" <input type=\"checkbox\" name=\"%s\" value=\"On\" %s>%s\n", $name, $checked, $text);
81 printf("<BR>");
82
83 printf(" <select name=\"%s\">\n", $var);
84
85 $status = array
86 ( 0 => "all",
87 1 => "yes",
88 2 => "no",
89 3 => "group by"
90 );
91
92 $stat=$_GET[$var];
93 for ($i=0; $i<4; $i++)
94 {
95 if ($stat==$i)
96 printf("<option value=\"%d\" selected>%s</option>\n", $i, $status[$i]);
97 else
98 printf("<option value=\"%d\">%s</option>\n", $i, $status[$i]);
99 }
100
101 printf(" </select>\n");
102 printf(" &nbsp;&nbsp;&nbsp;\n");
103
104}
105
106function StatusQuery($name)
107{
108 $var = $name . "Status";
109 $txt = "";
110 switch ($_GET[$var])
111 {
112 case 0: $txt .= ""; break;
113 case 1: $txt .= "NOT (IsNull(" . $name . ") OR " . $name . "='1970-01-01 00:00:00') AND "; break;
114 case 2: $txt .= "IsNull(" . $name . ") AND "; break;
115 case 3: $txt .= $name ."='1970-01-01 00:00:00' AND "; break;
116 case 4: $txt .= ""; break;
117 }
118 return $txt;
119}
120
121function PrintStatusMenu($name, $text)
122{
123 $var = $name . "Status";
124
125 if ($_GET[$name]=="On")
126 $checked = "checked";
127 else
128 $checked = "";
129
130 printf(" <input type=\"checkbox\" name=\"%s\" value=\"On\" %s>%s\n", $name, $checked, $text);
131 printf("<BR>");
132
133 printf(" <select name=\"%s\">\n", $var);
134
135 $status = array
136 ( 0 => "all",
137 1 => "done",
138 2 => "not done",
139 3 => "not to be done",
140 4 => "group by"
141 );
142
143 $stat=$_GET[$var];
144 for ($i=0; $i<5; $i++)
145 {
146 if ($stat==$i)
147 printf("<option value=\"%d\" selected>%s</option>\n", $i, $status[$i]);
148 else
149 printf("<option value=\"%d\">%s</option>\n", $i, $status[$i]);
150 }
151
152 /*
153 $status = array("all", "done", "not done", "not to be done");
154 $counter = 0;
155 foreach ($status as $element)
156 {
157 if ($counter==$_GET[$var])
158 printf("<option value=\"%d\" selected>%3s</option>\n", $counter++, $element);
159 else
160 printf("<option value=\"%d\">%3s</option>\n", $counter++, $element);
161 }*/
162 printf(" </select>\n");
163 printf(" &nbsp;&nbsp;&nbsp;\n");
164
165}
166
167function PrintLimitsMenu($limits, $rms, $alias)
168{
169 foreach($limits as $key => $element)
170 {
171 printf("<tr><td>%s</td>\n", $alias[$key]);
172 $mean=$key . "Mean";
173 $limitmean=$_GET[$mean];
174 printf("<td><input name=\"%sMean\" type=\"text\" size=\"6\" maxlength=\"6\" value=\"%s\"></td>\n", $key, $limitmean);
175 if ($rms[$key]=="yes")
176 {
177 $rms2=$key . "Rms";
178 $limitrms=$_GET[$rms2];
179 printf("<td><input name=\"%sRms\" type=\"text\" size=\"6\" maxlength=\"6\" value=\"%s\"></td>\n", $key, $limitrms);
180 }
181 else
182 printf("<td><br></td>\n");
183 printf("</tr>\n");
184 }
185
186}
187
188function PrintPullDown($db, $table, $name, $index, $descr)
189{
190 $db_id = mysql_connect("hercules.astro.uni-wuerzburg.de", "MAGIC", "d99swMT!");
191 if ($db_id==FALSE)
192 {
193 printf("mysql_connect returned the following error:<br>");
194 printf("%s<br>", mysql_error());
195 die("");
196 }
197
198 $query = "SELECT " . $index . ", " . $name . " FROM " . $db . "." . $table . " ORDER BY " . $name;
199 $result = mysql_query($query);
200
201 if (!$result)
202 {
203 printf("-N/A-");
204 return;
205 }
206
207 $numrows = mysql_num_rows($result);
208
209 if ($_GET[$name]=="On")
210 $checked = "checked";
211 else
212 $checked = "";
213
214 printf(" <input type=\"checkbox\" name=\"%s\" value=\"On\" %s><A HREF=\"printtable.php?fTable=%s\">%s</A>\n", $name, $checked, $table, $descr);
215
216 printf(" <BR>\n");
217
218 printf(" <select name=\"%s\" size=\"1\" class=\"Width\">\n", $index);
219
220 if (empty($_GET[$index]) || $_GET[$index]==0)
221 printf(" <option value=\"0\" selected>--- ALL ---</option>\n");
222 else
223 printf(" <option value=\"0\">--- ALL ---</option>\n");
224
225 if (!empty($_GET[$index]) && $_GET[$index]==-1)
226 printf(" <option value=\"-1\" selected>--- GROUP BY ---</option>\n");
227 else
228 printf(" <option value=\"-1\">--- GROUP BY ---</option>\n");
229
230 while ($row = mysql_fetch_row($result))
231 {
232 if (!empty($_GET[$index]) && $_GET[$index]==$row[0])
233 printf(" <option value=\"%s\" selected>%s</option>\n", $row[0], $row[1]);
234 else
235 printf(" <option value=\"%s\">%s</option>\n", $row[0], $row[1]);
236 }
237 printf(" </select>\n");
238 printf(" &nbsp;\n", $index);
239
240 mysql_free_result($result);
241
242 mysql_close($db_id);
243}
244
245function GetMin($field, $table, $db)
246{
247 $db_id = mysql_connect("hercules.astro.uni-wuerzburg.de", "MAGIC", "d99swMT!");
248 if ($db_id==FALSE)
249 {
250 printf("mysql_connect returned the following error:<br>");
251 printf("%s<br>", mysql_error());
252 die("");
253 }
254
255 $query = "SELECT MIN(" . $field . ") FROM " . $db . "." . $table;
256 $result = mysql_query($query);
257 if (!$result)
258 return "0";
259
260 $row = mysql_fetch_row($result);
261
262 $min = $row[0];
263
264 mysql_free_result($result);
265 mysql_close($db_id);
266
267 return $min;
268}
269
270function GetMax($field, $table, $db)
271{
272 $db_id = mysql_connect("hercules.astro.uni-wuerzburg.de", "MAGIC", "d99swMT!");
273 if ($db_id==FALSE)
274 {
275 printf("mysql_connect returned the following error:<br>");
276 printf("%s<br>", mysql_error());
277 die("");
278 }
279
280 $query = "SELECT MAX(" . $field . ") FROM " . $db . "." . $table;
281 $result = mysql_query($query);
282 if (!$result)
283 return "0";
284
285 $row = mysql_fetch_row($result);
286
287 $max = $row[0];
288
289 mysql_free_result($result);
290 mysql_close($db_id);
291
292 return $max;
293}
294/*
295function GetMin()
296{
297 $db_id = mysql_connect("hercules.astro.uni-wuerzburg.de", "MAGIC", "d99swMT!");
298 if ($db_id==FALSE)
299 {
300 printf("mysql_connect returned the following error:<br>");
301 printf("%s<br>", mysql_error());
302 die("");
303 }
304
305 $query = "SELECT MIN(fRunNumber) FROM MyMagic.RunData";
306 $result = mysql_query($query);
307 if (!$result)
308 return "0";
309
310 $row = mysql_fetch_row($result);
311
312 $min = $row[0];
313
314 mysql_free_result($result);
315 mysql_close($db_id);
316
317 return $min;
318}
319
320function GetMax()
321{
322 $db_id = mysql_connect("hercules.astro.uni-wuerzburg.de", "MAGIC", "d99swMT!");
323 if ($db_id==FALSE)
324 {
325 printf("mysql_connect returned the following error:<br>");
326 printf("%s<br>", mysql_error());
327 die("");
328 }
329
330 $query = "SELECT MAX(fRunNumber) FROM MyMagic.RunData";
331 $result = mysql_query($query);
332 if (!$result)
333 return "0";
334
335 $row = mysql_fetch_row($result);
336
337 $max = $row[0];
338
339 mysql_free_result($result);
340 mysql_close($db_id);
341
342 return $max;
343}
344*/
345
346function PrintText($result0)
347{
348 header("Content-type: application/octet");
349 header("Content-Disposition: attachment; filename=query-result.txt");
350
351 while ($row0 = mysql_fetch_assoc($result0))
352 {
353 foreach ($row0 as $key => $element)
354 printf("%s\t", $element);
355 printf("\n");
356 }
357}
358
359function Checkbox($value, $text)
360{
361 if ($_GET[$value]=="On")
362 $checked = "checked";
363 else
364 $checked = "";
365
366 printf(" <td><input type=\"checkbox\" name=\"%s\" value=\"On\" %s>%s</td>\n", $value, $checked, $text);
367}
368
369function CheckWhere($column, $_GET)
370{
371 foreach ($_GET as $key => $element)
372 {
373 if ($key==$column)
374 {
375 if ($element>0)
376 printf ("FIXED: %s<BR>", $column);
377 return $element;
378 }
379 }
380 return 0;
381}
382
383function CheckGroup($column, $_GET)
384{
385 foreach ($_GET as $key => $element)
386 {
387 if ($key==$column)
388 {
389 //if ($element==-1)
390 // printf ("GROUP: %s<BR>", $column);
391 return $element;
392 }
393 }
394 return 0;
395}
396
397function CheckStatusGroup($column, $_GET)
398{
399 foreach ($_GET as $key => $element)
400 if ($key==$column)
401 if ($element==4)
402 return -1;
403 return 0;
404}
405
406function CheckEnumGroup($column, $_GET)
407{
408 foreach ($_GET as $key => $element)
409 if ($key==$column)
410 if ($element==3)
411 return -1;
412 return 0;
413}
414
415function CreateMenu($rows)
416{
417 $menu = "";
418
419 if (empty($_GET["fNumResults"]))
420 return;
421
422 if ($_GET["fNumStart"]!=0)
423 {
424 $uri = $_SERVER["REQUEST_URI"];
425 $pos = strpos($uri, "fNumStart");
426 $amp3=FALSE;
427 if ($pos!=FALSE)
428 {
429 $amp1 = substr($uri, 0, $pos-1);
430 $amp2 = substr($uri, $pos);
431 $amp3 = strchr($amp2, "&");
432
433 $uri = $amp1;
434 }
435 $pos = $_GET["fNumStart"]-$rows;
436 if ($pos<0)
437 $pos=0;
438 $uri .= "&fNumStart=" . $pos;
439 if ($amp3!=FALSE)
440 $uri .= $amp3;
441
442 $menu .= "<A HREF='" . $uri . "'><<< Prev</A>\n";
443 }
444
445 $menu .= "&nbsp;&nbsp;&nbsp;---&nbsp;<B>";
446 $menu .= $_GET["fNumStart"];
447 $menu .= "</B>&nbsp;---&nbsp;&nbsp;&nbsp;\n";
448
449 if ($rows==$_GET["fNumResults"])
450 {
451 $uri = $_SERVER["REQUEST_URI"];
452 $pos = strpos($uri, "fNumStart");
453 $amp3=FALSE;
454 if ($pos!=FALSE)
455 {
456 $amp1 = substr($uri, 0, $pos-1);
457 $amp2 = substr($uri, $pos);
458 $amp3 = strchr($amp2, "&");
459
460 $uri = $amp1;
461 }
462 $uri .= "&fNumStart=" . ($_GET["fNumStart"]+$rows);
463 if ($amp3!=FALSE)
464 $uri .= $amp3;
465
466 $menu .= "<A HREF='" . $uri . "'>Next >>></A>\n";
467 }
468 return $menu;
469}
470
471function RemoveSortBy($rows)
472{
473 $menu = "";
474
475 $uri = $_SERVER["REQUEST_URI"];
476 $pos = strpos($uri, "fSortBy");
477 $amp3=FALSE;
478 if ($pos!=FALSE)
479 {
480 $amp1 = substr($uri, 0, $pos-1);
481 $amp2 = substr($uri, $pos);
482 $amp3 = strchr($amp2, "&");
483
484 $uri = $amp1;
485 }
486
487 return $uri;
488}
489
490function FindAlias($alias, $search)
491{
492 foreach ($alias as $key => $element)
493 if ($element==$search)
494 return $key;
495
496 return "";
497}
498
499function PrintMagicTable($result0, $alias, $rightalign, $limits, $rms, $_GET)
500{
501 $col = FALSE;
502 $first = TRUE;
503
504 $menu = CreateMenu(mysql_num_rows($result0));
505
506 printf("\n<center>\n<p>%s<P>\n", $menu);
507 printf("<table BORDER=\"0\">\n");
508 while ($row0 = mysql_fetch_assoc($result0))
509 {
510 if ($first)
511 {
512 printf(" <tr BGCOLOR='#C0C0C0'>\n");
513 $first = FALSE;
514 foreach ($row0 as $key => $element)
515 {
516 $col = FindAlias($alias, $key);
517
518 $ord="%2B";
519 $issort = "";
520 if (!empty($_GET["fSortBy"]) && substr($_GET["fSortBy"], 0, -1)==$col)
521 {
522 if (substr($_GET["fSortBy"], -1)=="+")
523 {
524 $ord="-";
525 $issort="&nbsp;<IMG SRC='down.gif'>";
526 }
527 else
528 $issort="&nbsp;<IMG SRC='up.gif'>";
529 }
530 printf(" <th>&nbsp;<A HREF='%s&fSortBy=%s%s'>%s</A>%s&nbsp;</th>\n",
531 RemoveSortBy($_SERVER["REQUEST_URI"]), $col, $ord, $key, $issort);
532 }
533 printf(" </tr>\n\n");
534 }
535
536 if (!$col)
537 printf(" <tr BGCOLOR='#E0E0E0'>\n");
538 else
539 printf(" <tr BGCOLOR='#D0D0D0'>\n");
540 $col = !$col;
541
542 foreach ($row0 as $key => $element)
543 {
544 if (empty($rightalign[$key]))
545 printf(" <td align=\"left\">");
546 else
547 printf(" <td align=\"right\">");
548
549 if (!(empty($limits) && empty($rms)))
550 {
551 foreach($limits as $key2 => $element2)
552 {
553 $mean=$key2 . "Mean";
554 $rms2=$key2 . "Rms";
555 if ($key==$alias[$element2] && !empty($_GET[$mean]))
556 {
557 if ($rms[$key2]=="yes")
558 {
559 if (!empty($_GET[$rms2]))
560 {
561 $min=$_GET[$mean] - $_GET[$rms2];
562 $max=$_GET[$mean] + $_GET[$rms2];
563 if ($min < $element && $element < $max)
564 printf("<font color='green'>");
565 else
566 printf("<font color='red'>");
567 }
568 }
569 else
570 {
571 if ($rms[$key2]=="min")
572 {
573 if ($_GET[$mean] <= $element)
574 printf("<font color='green'>");
575 else
576 printf("<font color='red'>");
577 }
578
579 if ($rms[$key2]=="max")
580 {
581 if ($_GET[$mean] >= $element)
582 printf("<font color='green'>");
583 else
584 printf("<font color='red'>");
585 }
586 }
587 }
588
589 }
590 }
591
592 printf("&nbsp;%s&nbsp;</td>\n", str_replace("&ws;", " ", str_replace(" ", "&nbsp;", $element)));
593 }
594 printf(" </tr>\n");
595 }
596 printf("</table>\n");
597
598 /*
599 $info = mysql_info();
600 if (!empty($info))
601 printf("%s<BR>\n", $info);
602 */
603
604 printf("<P><B>Number of displayed results: %d</B><P><P>\n", mysql_num_rows($result0));
605 printf("%s\n", $menu);
606 printf("<P>\n");
607 printf("</center>\n");
608 printf("</tr><tr class='Block'><td>\n");
609}
610
611?>
Note: See TracBrowser for help on using the repository browser.