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

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