source: trunk/MagicSoft/Mars/datacenter/db/include.php@ 9131

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