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

Last change on this file since 8015 was 7974, checked in by Daniela Dorner, 18 years ago
*** empty log message ***
  • Property svn:executable set to *
File size: 15.0 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 PrintText($result0)
228{
229 header("Content-type: application/octet");
230 header("Content-Disposition: attachment; filename=query-result.txt");
231
232 while ($row0 = mysql_fetch_assoc($result0))
233 {
234 foreach ($row0 as $key => $element)
235 printf("%s\t", $element);
236 printf("\n");
237 }
238}
239
240function PrintSubmittedQuery($query0, $html, $db, $old)
241{
242 //diplay query on old websites
243 if (empty($old))
244 printf("<tr class='Block' id='showquery' style='display:none'><td>");
245 else
246 printf("<tr class='Block' id='showquery' style='display:block'><td>");
247 printf("<b>DB:</b> %s <br>", $db);
248 if ($html=="1")
249 printf("<U><B>submitted query:</B></U><BR>%s<BR>", htmlspecialchars($query0));
250 printf("</td></tr>");
251}
252
253function Checkbox($value, $text)
254{
255 if ($_GET[$value]=="On")
256 $checked = "checked";
257 else
258 $checked = "";
259
260 printf(" <td><input type=\"checkbox\" name=\"%s\" value=\"On\" %s>%s</td>\n", $value, $checked, $text);
261}
262
263function CheckWhere($column, $_GET)
264{
265 foreach ($_GET as $key => $element)
266 {
267 if ($key==$column)
268 {
269 if ($element>0)
270 printf ("FIXED: %s<BR>", $column);
271 return $element;
272 }
273 }
274 return 0;
275}
276
277function CheckGroup($column, $_GET)
278{
279 foreach ($_GET as $key => $element)
280 {
281 if ($key==$column)
282 {
283 //if ($element==-1)
284 // printf ("GROUP: %s<BR>", $column);
285 return $element;
286 }
287 }
288 return 0;
289}
290
291function CheckStatusGroup($column, $_GET)
292{
293 foreach ($_GET as $key => $element)
294 if ($key==$column)
295 if ($element==7)
296 return -1;
297 return 0;
298}
299
300function CheckEnumGroup($column, $_GET)
301{
302 foreach ($_GET as $key => $element)
303 if ($key==$column)
304 if ($element==3)
305 return -1;
306 return 0;
307}
308
309function CreateMenu($rows)
310{
311 $menu = "";
312
313 if (empty($_GET["fNumResults"]))
314 return;
315
316 if ($_GET["fNumStart"]!=0)
317 {
318 $uri = htmlspecialchars($_SERVER["REQUEST_URI"]);
319 $pos = strpos($uri, "fNumStart");
320 $amp3=FALSE;
321 if ($pos!=FALSE)
322 {
323 $amp1 = substr($uri, 0, $pos-1);
324 $amp2 = substr($uri, $pos);
325 $amp3 = strchr($amp2, "&");
326
327 $uri = $amp1;
328 }
329 $pos = $_GET["fNumStart"]-$rows;
330 if ($pos<0)
331 $pos=0;
332 $uri .= "&fNumStart=" . $pos;
333 if ($amp3!=FALSE)
334 $uri .= $amp3;
335
336 $menu .= "<A HREF='" . $uri . "'><<< Prev</A>\n";
337 }
338
339 $menu .= "&nbsp;&nbsp;&nbsp;---&nbsp;<B>";
340 $menu .= $_GET["fNumStart"];
341 $menu .= "</B>&nbsp;---&nbsp;&nbsp;&nbsp;\n";
342
343 if ($rows==$_GET["fNumResults"])
344 {
345 $uri = $_SERVER["REQUEST_URI"];
346 $pos = strpos($uri, "fNumStart");
347 $amp3=FALSE;
348 if ($pos!=FALSE)
349 {
350 $amp1 = substr($uri, 0, $pos-1);
351 $amp2 = substr($uri, $pos);
352 $amp3 = strchr($amp2, "&");
353
354 $uri = $amp1;
355 }
356 $uri .= "&fNumStart=" . ($_GET["fNumStart"]+$rows);
357 if ($amp3!=FALSE)
358 $uri .= $amp3;
359
360 $menu .= "<A HREF='" . htmlspecialchars($uri) . "'>Next >>></A>\n";
361 }
362 return $menu;
363}
364
365function RemoveSortBy()
366{
367 $menu = "";
368
369 $uri = $_SERVER["REQUEST_URI"];
370 $pos = strpos($uri, "fSortBy");
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
381 return $uri;
382}
383
384function FindAlias($alias, $search)
385{
386 foreach ($alias as $key => $element)
387 if ($element==$search)
388 return $key;
389
390 return "";
391}
392
393function PrintMagicTable($result0, $alias, $rightalign, $limitsmean, $limitsmin, $limitsmax, $_GET)
394{
395 $col = FALSE;
396 $first = TRUE;
397
398 $sigma = array
399 (
400 5 => "#FF9900",
401 3 => "#FFFF66",
402 2 => "#33CC00",
403 1 => "#006600",
404 );
405 $offlimitcolour="#FF0000";
406
407
408 $menu = CreateMenu(mysql_num_rows($result0));
409
410 printf("\n<center>\n");
411 if (empty($_GET["fPrintTable"]))
412 printf("<p>%s<P>\n", $menu);
413 printf("<table BORDER=\"0\">\n");
414 while ($row0 = mysql_fetch_assoc($result0))
415 {
416 if ($first)
417 {
418 printf(" <tr BGCOLOR='#C0C0C0'>\n");
419 $first = FALSE;
420 foreach ($row0 as $key => $element)
421 {
422 $col = FindAlias($alias, $key);
423
424 $ord="-";
425 $issort = "";
426 if (!empty($_GET["fSortBy"]) && substr($_GET["fSortBy"], 0, -1)==$col)
427 {
428 if (substr($_GET["fSortBy"], -1)=="-")
429 {
430 $ord="+";
431 $issort="&nbsp;<IMG SRC='down.gif'>";
432 }
433 else
434 $issort="&nbsp;<IMG SRC='up.gif'>";
435 }
436 printf(" <th>&nbsp;<A HREF='%s&amp;fSortBy=%s%s'>%s</A>%s&nbsp;</th>\n",
437 htmlspecialchars(RemoveSortBy()), $col, $ord, $key, $issort);
438 }
439 printf(" </tr>\n\n");
440 }
441
442 if (!$col)
443 printf(" <tr BGCOLOR='#E0E0E0'>\n");
444 else
445 printf(" <tr BGCOLOR='#D0D0D0'>\n");
446 $col = !$col;
447
448 foreach ($row0 as $key => $element)
449 {
450 if (empty($rightalign[$key]))
451 printf(" <td align=\"left\">");
452 else
453 printf(" <td align=\"right\">");
454
455 //determine color of text in cell
456 if (!empty($limitsmean))
457 {
458 foreach($limitsmean as $key2 => $element2)
459 {
460 $mean=$key2 . "Mean";
461 $rms2=$key2 . "Rms";
462 if ($key==$alias[$element2] && !empty($_GET[$mean]))
463 {
464 if (!empty($_GET[$rms2]))
465 {
466 $colour=$offlimitcolour;
467 foreach ($sigma as $margin => $newcolour)
468 {
469 $min=$_GET[$mean] - ($margin * $_GET[$rms2]);
470 $max=$_GET[$mean] + ($margin * $_GET[$rms2]);
471 if ($min < $element && $element < $max)
472 $colour=$newcolour;
473 }
474 printf("<font color='%s' style='font-weight:bold'>", $colour);
475 }
476 }
477 }
478 }
479 if (!empty($limitsmin))
480 {
481 foreach($limitsmin as $key2 => $element2)
482 {
483 $limit1=$key2 . "1";
484 $limit2=$key2 . "2";
485 if ($key==$alias[$element2] && !empty($_GET[$limit1]))
486 {
487 $colour=$offlimitcolour;
488 if ($_GET[$limit1] <= $element)
489 $colour=$sigma[1];
490 else
491 {
492 if (!empty($_GET[$limit2]))
493 {
494 if ($_GET[$limit2] <= $element)
495 $colour=$sigma[5];
496 }
497 }
498 printf("<font color='%s' style='font-weight:bold'>", $colour);
499 }
500 }
501 }
502
503 if (!empty($limitsmax))
504 {
505 foreach($limitsmax as $key2 => $element2)
506 {
507 $limit1=$key2 . "1";
508 $limit2=$key2 . "2";
509 if ($key==$alias[$element2] && !empty($_GET[$limit1]))
510 {
511 $colour=$offlimitcolour;
512 if ($_GET[$limit1] >= $element)
513 $colour=$sigma[1];
514 else
515 {
516 if (!empty($_GET[$limit2]))
517 {
518 if ($_GET[$limit2] >= $element)
519 $colour=$sigma[5];
520 }
521 }
522 printf("<font color='%s' style='font-weight:bold'>", $colour);
523 }
524 }
525 }
526
527 //fill text in cell
528 printf("&nbsp;%s&nbsp;</td>\n", str_replace("&ws;", " ", str_replace(" ", "&nbsp;", $element)));
529 }
530 printf(" </tr>\n");
531 }
532 printf("</table>\n");
533
534 /*
535 $info = mysql_info();
536 if (!empty($info))
537 printf("%s<BR>\n", $info);
538 */
539
540 printf("<P><B>Number of displayed results: %d</B><P><P>\n", mysql_num_rows($result0));
541 if (empty($_GET["fPrintTable"]))
542 printf("%s\n", $menu);
543 printf("<P>\n");
544 printf("</center>\n");
545 printf("</td>\n");
546 printf("</tr>\n");
547}
548
549?>
Note: See TracBrowser for help on using the repository browser.