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

Last change on this file since 9498 was 9498, checked in by Daniela Dorner, 16 years ago
*** empty log message ***
  • Property svn:executable set to *
File size: 19.2 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
257//for download of output
258function PrintText($result0)
259{
260 while ($row0 = mysql_fetch_assoc($result0))
261 {
262 foreach ($row0 as $key => $element)
263 printf("%s\t", $element);
264 printf("\n");
265 }
266}
267
268function PrintSubmittedQuery($query0, $html, $db, $old)
269{
270 //diplay query on old websites
271 if (empty($old))
272 printf("<tr class='Block' id='showquery' style='display:none'><td>");
273 else
274 printf("<tr class='Block' id='showquery' style='display:block'><td>");
275 if ($html=="1")
276 {
277 printf("<b>DB:</b> %s <br>", $db);
278 printf("<U><B>submitted query:</B></U><BR>%s<BR>", htmlspecialchars($query0));
279 }
280 printf("</td></tr>");
281}
282
283function Checkbox($value, $text)
284{
285 if ($_GET[$value]=="On")
286 $checked = "checked";
287 else
288 $checked = "";
289
290 printf(" <td><input type='checkbox' name='%s' value='On' %s>%s</td>\n", $value, $checked, $text);
291}
292
293function Checkbox2($value, $text)
294{
295 if ($_SESSION[$value]=="On")
296 $checked = "checked";
297 else
298 $checked = "";
299
300 printf(" <td><input type='checkbox' name='%s' value='On' %s>%s</td>\n", $value, $checked, $text);
301}
302
303function CheckWhere($column)
304{
305 foreach ($_GET as $key => $element)
306 {
307 if ($key==$column)
308 {
309// if ($element>0)
310// printf ("FIXED: %s<BR>", $column);
311 return $element;
312 }
313 }
314 return 0;
315}
316
317function CheckGroup($column)
318{
319 foreach ($_GET as $key => $element)
320 {
321 if ($key==$column)
322 {
323 //if ($element==-1)
324 // printf ("GROUP: %s<BR>", $column);
325 return $element;
326 }
327 }
328 return 0;
329}
330
331function CheckStatusGroup($column)
332{
333 foreach ($_GET as $key => $element)
334 if ($key==$column)
335 if ($element==7)
336 return -1;
337 return 0;
338}
339
340function CheckEnumGroup($column)
341{
342 foreach ($_GET as $key => $element)
343 if ($key==$column)
344 if ($element==3)
345 return -1;
346 return 0;
347}
348
349function RemoveSortBy()
350{
351 $menu = "";
352
353 $uri = $_SERVER["REQUEST_URI"];
354 $pos = strpos($uri, "fSortBy");
355 $amp3=FALSE;
356 if ($pos!=FALSE)
357 {
358 $amp1 = substr($uri, 0, $pos-1);
359 $amp2 = substr($uri, $pos);
360 $amp3 = strchr($amp2, "&");
361
362 $uri = $amp1;
363 }
364
365 return $uri;
366}
367
368function FindAlias($alias, $search)
369{
370 foreach ($alias as $key => $element)
371 if ($element==$search)
372 return $key;
373
374 if ($search=="# Runs")
375 return "NumRuns";
376 if ($search=="# Sequ")
377 return "NumSequ";
378 if ($search=="# Datasets")
379 return "NumDS";
380 if ($search=="# days")
381 return "NumDays";
382 return $search;
383 return "";
384}
385
386//function for button in builddatasets.php
387function GetClearedURL($all)
388{
389// $url=htmlspecialchars($_SERVER["REQUEST_URI"]);
390 $url=$_SERVER["REQUEST_URI"];
391// echo "before:".$url."<br>";
392 if ($all=="yes")
393 {
394// echo "replace <br>";
395// $url=str_replace("&DisplaySelected", "halo", $url);
396 $url=str_replace("&DisplaySelected=yes", "", $url);
397 $url=str_replace("&DisplaySelected=no", "", $url);
398 }
399 $url=str_replace("&insert=yes", "", $url);
400 $url=str_replace("&fSendTxt=2", "", $url);
401 $url=str_replace("&fSendTxt=1", "", $url);
402// echo "after:".$url."<br>";
403 $url=htmlspecialchars($url);
404 return $url;
405}
406
407function PrintUpdateDataSetButton()
408{
409 if (empty($_SESSION["insert"]))
410 printf("<input type='submit' value='Update Data Set'>&nbsp;&nbsp;&nbsp;\n");
411 else
412 printf("<input type='button' value='Continue' onClick='self.location.href=\"%s\"'>&nbsp;&nbsp;&nbsp;\n", GetClearedURL());
413
414}
415
416//function for button in builddatasets.php
417function PrintDisplaySequencesButtons()
418{
419 if ($_SESSION["DisplaySelected"]!="yes" && ($_SESSION["sequon"]!=" " || $_SESSION["sequoff"]!=" "))
420 {
421 PrintUpdateDataSetButton();
422 printf("<input type='button' value='Display Selected Sequences' onClick='self.location.href=\"%s&DisplaySelected=yes\"'><br><br>\n", GetClearedURL("yes"));
423 }
424
425 if ($_SESSION["DisplaySelected"]=="yes")
426 {
427 PrintUpdateDataSetButton();
428 printf("<input type='button' value='Display All Sequences' onClick='self.location.href=\"%s&DisplaySelected=no\"'>\n", GetClearedURL("yes"));
429 printf("&nbsp;&nbsp;&nbsp;<i>Currently only selected sequences are displayed.</i><br><br>\n");
430 }
431}
432
433
434function ReplaceInUri($name, $rows, $direction, $result1=0)
435{
436 $uri = htmlspecialchars($_SERVER["REQUEST_URI"]);
437 $pos = strpos($uri, "fNumStart");
438 $amp3=FALSE;
439 if ($pos!=FALSE)
440 {
441 $amp1 = substr($uri, 0, $pos-1);
442 $amp2 = substr($uri, $pos);
443 $amp3 = strchr($amp2, "&");
444
445 $uri = $amp1;
446 }
447
448 switch($direction)
449 {
450 case 0:
451 $pos = $_GET["fNumStart"]-$rows;
452 if ($pos<0)
453 $pos=0;
454 break;
455 case 1:
456 $pos = $_GET["fNumStart"]+$rows;
457 break;
458 case 2:
459 $pos = 0;
460 break;
461 case 3:
462 $row1 = mysql_fetch_assoc($result1);
463 $pos = $row1["FOUND_ROWS()"]-$rows+1;
464 break;
465 }
466
467 $uri .= "&fNumStart=" . $pos;
468 if ($amp3!=FALSE)
469 $uri .= $amp3;
470
471 switch($direction)
472 {
473 case 0:
474 $link .= " <A HREF='" . $uri . "'>< Prev</A> \n";
475 break;
476 case 1:
477 $link .= " <A HREF='" . $uri . "'>Next ></A> \n";
478 break;
479 case 2:
480 $link .= " <A HREF='" . $uri . "'><< First</A> \n";
481 break;
482 case 3:
483 $link .= " <A HREF='" . $uri . "'>Last >></A> \n";
484 break;
485 }
486 return $link;
487}
488
489function CreateMenu($rows, $result1)
490{
491 $menu = "";
492
493 if (empty($_GET["fNumResults"]))
494 return;
495
496 if ($_GET["fNumStart"]!=0)
497 {
498 $menu .= ReplaceInUri("fNumStart", $rows, 2);
499 $menu .= ReplaceInUri("fNumStart", $rows, 0);
500 }
501
502 $menu .= "&nbsp;&nbsp;&nbsp;---&nbsp;<B>";
503 if (empty($_GET["fNumStart"]))
504 $menu .= "0";
505 else
506 $menu .= $_GET["fNumStart"];
507 $menu .= "</B>&nbsp;---&nbsp;&nbsp;&nbsp;\n";
508
509 if ($rows==$_GET["fNumResults"])
510 {
511 $menu .= ReplaceInUri("fNumStart", $rows, 1);
512 $menu .= ReplaceInUri("fNumStart", $rows, 3, $result1);
513 }
514 return $menu;
515}
516
517function PrintMagicTable($result0, $alias, $rightalign, $limitsmean, $limitsmin, $limitsmax, $result1, $form="")
518{
519 $col = FALSE;
520 $first = TRUE;
521
522 $sigma = array
523 (
524 1 => "#33CC00",
525 2 => "#FFFF66",
526 3 => "#FF9900",
527 5 => "#FF0000",
528 );
529 $okcolour="#006600";
530
531
532 $menu = CreateMenu(mysql_num_rows($result0), $result1);
533
534 if ($form)
535 {
536 printf("<form method='POST'>");
537 PrintDisplaySequencesButtons();
538 }
539 printf("\n<center>\n");
540 if (empty($_GET["fPrintTable"]))
541 printf("%s\n", $menu);
542
543 printf("<table BORDER='0' style='margin-top:1ex'>\n");
544 $counter=0;
545 while ($row0 = mysql_fetch_assoc($result0))
546 {
547 if ($first)
548 {
549 printf(" <tr BGCOLOR='#C0C0C0'>\n<td BGCOLOR='#F0F0F0'><img src='plus.png' alt='+' onClick='showalllines(%d)'></td>\n", mysql_num_rows($result0));
550 $first = FALSE;
551 if ($form)
552 printf("<td>ON</td><td>Off</td>");
553 foreach ($row0 as $key => $element)
554 {
555 $col = FindAlias($alias, $key);
556
557 $ord="-";
558 $issort = "";
559 if (!empty($_GET["fSortBy"]) && substr($_GET["fSortBy"], 0, -1)==$col)
560 {
561 if (substr($_GET["fSortBy"], -1)=="-")
562 {
563 $ord="+";
564 $issort="&nbsp;<IMG SRC='down.gif'>";
565 }
566 else
567 $issort="&nbsp;<IMG SRC='up.gif'>";
568 }
569 printf(" <th>&nbsp;<A HREF='%s&amp;fSortBy=%s%s'>%s</A>%s&nbsp;</th>\n",
570 htmlspecialchars(RemoveSortBy()), $col, $ord, $key, $issort);
571 }
572 printf(" </tr>\n\n");
573 }
574
575 $counter++;
576 if (!$col)
577 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);
578 else
579 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);
580 $col = !$col;
581
582 if ($form)
583 {
584 CheckBox2($row0["Sequ"]."ON","");
585 CheckBox2($row0["Sequ"]."Off","");
586 }
587 foreach ($row0 as $key => $element)
588 {
589 if (empty($rightalign[$key]))
590 printf(" <td align='left' valign='top'>");
591 else
592 printf(" <td align='right' valign='top'>");
593
594 $colour='#000000';
595 //determine color of text in cell
596 if (!empty($limitsmean))
597 {
598 foreach($limitsmean as $key2 => $element2)
599 {
600 $mean=$key2 . "Mean";
601 $rms2=$key2 . "Rms";
602 if ($key==$alias[$element2] && !empty($_GET[$mean]) && !empty($_GET[$rms2]))
603 {
604 $colour=$okcolour;
605 foreach ($sigma as $margin => $newcolour)
606 {
607 $min=$_GET[$mean] - ($margin * $_GET[$rms2]);
608 $max=$_GET[$mean] + ($margin * $_GET[$rms2]);
609 if (!($min < $element && $element < $max))
610 $colour=$newcolour;
611 }
612 }
613 }
614 }
615 if (!empty($limitsmin))
616 {
617 foreach($limitsmin as $key2 => $element2)
618 {
619 $limit1=$key2 . "1";
620 $limit2=$key2 . "2";
621 if ($key==$alias[$element2] && !empty($_GET[$limit1]))
622 {
623 if ($colour=='#000000')
624 $colour=$okcolour;
625
626 if (!empty($_GET[$limit2]) && $_GET[$limit2] > $element)
627 $colour=$sigma[5];
628
629 if ($_GET[$limit1] > $element && $_GET[$limit2] <= $element)
630 $colour=$sigma[3];
631 }
632 }
633 }
634
635 if (!empty($limitsmax))
636 {
637 foreach($limitsmax as $key2 => $element2)
638 {
639 $limit1=$key2 . "1";
640 $limit2=$key2 . "2";
641 if ($key==$alias[$element2] && !empty($_GET[$limit1]))
642 {
643 if ($colour=='#000000')
644 $colour=$okcolour;
645
646 if (!empty($_GET[$limit2]) && $_GET[$limit2] < $element)
647 $colour=$sigma[5];
648
649 if ($_GET[$limit1] < $element && $_GET[$limit2] >= $element)
650 $colour=$sigma[3];
651 }
652 }
653 }
654 if ($colour!='#000000' && (!empty($limitsmean) || !empty($limitsmin) || !empty($limitsmax)))
655 printf("<font color='%s' style='font-weight:bold'>", $colour);
656
657 //fill text in cell
658 printf("&nbsp;%s&nbsp;</td>\n", str_replace("&ws;", " ", str_replace(" ", "&nbsp;", $element)));
659
660 if ($colour!='#000000' && (!empty($limitsmean) || !empty($limitsmin) || !empty($limitsmax)))
661 printf("</font>");
662 }
663 printf(" </tr>\n");
664 }
665 printf("</table>\n");
666
667 /*
668 $info = mysql_info();
669 if (!empty($info))
670 printf("%s<BR>\n", $info);
671 */
672
673 $row1 = mysql_fetch_assoc($result1);
674 printf("<P><B>Number of displayed results: %d of %s in total</B><P><P>\n", mysql_num_rows($result0), $row1["FOUND_ROWS()"]);
675 if (empty($_GET["fPrintTable"]))
676 printf("%s\n", $menu);
677 printf("<P>\n");
678 printf("</center>\n");
679
680 if (!$form)
681 {
682 printf("</td>\n");
683 printf("</tr>\n");
684 }
685 else
686 PrintDisplaySequencesButtons();
687}
688
689?>
Note: See TracBrowser for help on using the repository browser.