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

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