source: tags/Mars-V0.9.5.1/datacenter/db/include.php

Last change on this file was 7546, checked in by Daniela Dorner, 19 years ago
*** empty log message ***
  • Property svn:executable set to *
File size: 13.7 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 PrintLimitsMenu($limits, $rms, $alias)
121{
122 foreach($limits as $key => $element)
123 {
124 printf("<tr><td>%s</td>\n", $alias[$key]);
125 $mean=$key . "Mean";
126 $limitmean=$_GET[$mean];
127 printf("<td><input name=\"%sMean\" type=\"text\" size=\"6\" maxlength=\"6\" value=\"%s\"></td>\n", $key, $limitmean);
128 if ($rms[$key]=="yes")
129 {
130 $rms2=$key . "Rms";
131 $limitrms=$_GET[$rms2];
132 printf("<td><input name=\"%sRms\" type=\"text\" size=\"6\" maxlength=\"6\" value=\"%s\"></td>\n", $key, $limitrms);
133 }
134 else
135 printf("<td><br></td>\n");
136 printf("</tr>\n");
137 }
138
139}
140
141function PrintPullDown($host, $user, $pw, $db, $table, $name, $index, $descr)
142{
143 $db_id = mysql_connect($host, $user, $pw);
144 if ($db_id==FALSE)
145 {
146 printf("mysql_connect returned the following error:<br>");
147 printf("%s<br>", mysql_error());
148 die("");
149 }
150
151 $query = "SELECT " . $index . ", " . $name . " FROM " . $db . "." . $table . " ORDER BY " . $name;
152 $result = mysql_query($query);
153
154 if (!$result)
155 {
156 printf("-N/A-");
157 return;
158 }
159
160 $numrows = mysql_num_rows($result);
161
162 if ($_GET[$name]=="On")
163 $checked = "checked";
164 else
165 $checked = "";
166
167 printf(" <input type=\"checkbox\" name=\"%s\" value=\"On\" %s><A HREF=\"printtable.php?fTable=%s\">%s</A>\n", $name, $checked, $table, $descr);
168
169 printf(" <BR>\n");
170
171 printf(" <select name=\"%s\" size=\"1\" class=\"Width\">\n", $index);
172
173 if (empty($_GET[$index]) || $_GET[$index]==0)
174 printf(" <option value=\"0\" selected>--- ALL ---</option>\n");
175 else
176 printf(" <option value=\"0\">--- ALL ---</option>\n");
177
178 if (!empty($_GET[$index]) && $_GET[$index]==-1)
179 printf(" <option value=\"-1\" selected>--- GROUP BY ---</option>\n");
180 else
181 printf(" <option value=\"-1\">--- GROUP BY ---</option>\n");
182
183 while ($row = mysql_fetch_row($result))
184 {
185 if (!empty($_GET[$index]) && $_GET[$index]==$row[0])
186 printf(" <option value=\"%s\" selected>%s</option>\n", $row[0], $row[1]);
187 else
188 printf(" <option value=\"%s\">%s</option>\n", $row[0], $row[1]);
189 }
190 printf(" </select>\n");
191 printf(" &nbsp;\n", $index);
192
193 mysql_free_result($result);
194
195 mysql_close($db_id);
196}
197
198function GetMin($field, $table, $host, $user, $pw, $db)
199{
200 $db_id = mysql_connect($host, $user, $pw);
201 if ($db_id==FALSE)
202 {
203 printf("mysql_connect returned the following error:<br>");
204 printf("%s<br>", mysql_error());
205 die("");
206 }
207
208 $query = "SELECT MIN(" . $field . ") FROM " . $db . "." . $table;
209 $result = mysql_query($query);
210 if (!$result)
211 return "0";
212
213 $row = mysql_fetch_row($result);
214
215 $min = $row[0];
216
217 mysql_free_result($result);
218 mysql_close($db_id);
219
220 return $min;
221}
222
223function GetMax($field, $table, $host, $user, $pw, $db)
224{
225 $db_id = mysql_connect($host, $user, $pw);
226 if ($db_id==FALSE)
227 {
228 printf("mysql_connect returned the following error:<br>");
229 printf("%s<br>", mysql_error());
230 die("");
231 }
232
233 $query = "SELECT MAX(" . $field . ") FROM " . $db . "." . $table;
234 $result = mysql_query($query);
235 if (!$result)
236 return "0";
237
238 $row = mysql_fetch_row($result);
239
240 $max = $row[0];
241
242 mysql_free_result($result);
243 mysql_close($db_id);
244
245 return $max;
246}
247
248function PrintText($result0)
249{
250 header("Content-type: application/octet");
251 header("Content-Disposition: attachment; filename=query-result.txt");
252
253 while ($row0 = mysql_fetch_assoc($result0))
254 {
255 foreach ($row0 as $key => $element)
256 printf("%s\t", $element);
257 printf("\n");
258 }
259}
260
261function Checkbox($value, $text)
262{
263 if ($_GET[$value]=="On")
264 $checked = "checked";
265 else
266 $checked = "";
267
268 printf(" <td><input type=\"checkbox\" name=\"%s\" value=\"On\" %s>%s</td>\n", $value, $checked, $text);
269}
270
271function CheckWhere($column, $_GET)
272{
273 foreach ($_GET as $key => $element)
274 {
275 if ($key==$column)
276 {
277 if ($element>0)
278 printf ("FIXED: %s<BR>", $column);
279 return $element;
280 }
281 }
282 return 0;
283}
284
285function CheckGroup($column, $_GET)
286{
287 foreach ($_GET as $key => $element)
288 {
289 if ($key==$column)
290 {
291 //if ($element==-1)
292 // printf ("GROUP: %s<BR>", $column);
293 return $element;
294 }
295 }
296 return 0;
297}
298
299function CheckStatusGroup($column, $_GET)
300{
301 foreach ($_GET as $key => $element)
302 if ($key==$column)
303 if ($element==7)
304 return -1;
305 return 0;
306}
307
308function CheckEnumGroup($column, $_GET)
309{
310 foreach ($_GET as $key => $element)
311 if ($key==$column)
312 if ($element==3)
313 return -1;
314 return 0;
315}
316
317function CreateMenu($rows)
318{
319 $menu = "";
320
321 if (empty($_GET["fNumResults"]))
322 return;
323
324 if ($_GET["fNumStart"]!=0)
325 {
326 $uri = $_SERVER["REQUEST_URI"];
327 $pos = strpos($uri, "fNumStart");
328 $amp3=FALSE;
329 if ($pos!=FALSE)
330 {
331 $amp1 = substr($uri, 0, $pos-1);
332 $amp2 = substr($uri, $pos);
333 $amp3 = strchr($amp2, "&");
334
335 $uri = $amp1;
336 }
337 $pos = $_GET["fNumStart"]-$rows;
338 if ($pos<0)
339 $pos=0;
340 $uri .= "&fNumStart=" . $pos;
341 if ($amp3!=FALSE)
342 $uri .= $amp3;
343
344 $menu .= "<A HREF='" . $uri . "'><<< Prev</A>\n";
345 }
346
347 $menu .= "&nbsp;&nbsp;&nbsp;---&nbsp;<B>";
348 $menu .= $_GET["fNumStart"];
349 $menu .= "</B>&nbsp;---&nbsp;&nbsp;&nbsp;\n";
350
351 if ($rows==$_GET["fNumResults"])
352 {
353 $uri = $_SERVER["REQUEST_URI"];
354 $pos = strpos($uri, "fNumStart");
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 $uri .= "&fNumStart=" . ($_GET["fNumStart"]+$rows);
365 if ($amp3!=FALSE)
366 $uri .= $amp3;
367
368 $menu .= "<A HREF='" . $uri . "'>Next >>></A>\n";
369 }
370 return $menu;
371}
372
373function RemoveSortBy($rows)
374{
375 $menu = "";
376
377 $uri = $_SERVER["REQUEST_URI"];
378 $pos = strpos($uri, "fSortBy");
379 $amp3=FALSE;
380 if ($pos!=FALSE)
381 {
382 $amp1 = substr($uri, 0, $pos-1);
383 $amp2 = substr($uri, $pos);
384 $amp3 = strchr($amp2, "&");
385
386 $uri = $amp1;
387 }
388
389 return $uri;
390}
391
392function FindAlias($alias, $search)
393{
394 foreach ($alias as $key => $element)
395 if ($element==$search)
396 return $key;
397
398 return "";
399}
400
401function PrintMagicTable($result0, $alias, $rightalign, $limits, $rms, $_GET)
402{
403 $col = FALSE;
404 $first = TRUE;
405
406 $menu = CreateMenu(mysql_num_rows($result0));
407
408 printf("\n<center>\n<p>%s<P>\n", $menu);
409 printf("<table BORDER=\"0\">\n");
410 while ($row0 = mysql_fetch_assoc($result0))
411 {
412 if ($first)
413 {
414 printf(" <tr BGCOLOR='#C0C0C0'>\n");
415 $first = FALSE;
416 foreach ($row0 as $key => $element)
417 {
418 $col = FindAlias($alias, $key);
419
420 $ord="%2B";
421 $issort = "";
422 if (!empty($_GET["fSortBy"]) && substr($_GET["fSortBy"], 0, -1)==$col)
423 {
424 if (substr($_GET["fSortBy"], -1)=="+")
425 {
426 $ord="-";
427 $issort="&nbsp;<IMG SRC='down.gif'>";
428 }
429 else
430 $issort="&nbsp;<IMG SRC='up.gif'>";
431 }
432 printf(" <th>&nbsp;<A HREF='%s&fSortBy=%s%s'>%s</A>%s&nbsp;</th>\n",
433 RemoveSortBy($_SERVER["REQUEST_URI"]), $col, $ord, $key, $issort);
434 }
435 printf(" </tr>\n\n");
436 }
437
438 if (!$col)
439 printf(" <tr BGCOLOR='#E0E0E0'>\n");
440 else
441 printf(" <tr BGCOLOR='#D0D0D0'>\n");
442 $col = !$col;
443
444 foreach ($row0 as $key => $element)
445 {
446 if (empty($rightalign[$key]))
447 printf(" <td align=\"left\">");
448 else
449 printf(" <td align=\"right\">");
450
451 if (!(empty($limits) && empty($rms)))
452 {
453 foreach($limits as $key2 => $element2)
454 {
455 $mean=$key2 . "Mean";
456 $rms2=$key2 . "Rms";
457 if ($key==$alias[$element2] && !empty($_GET[$mean]))
458 {
459 if ($rms[$key2]=="yes")
460 {
461 if (!empty($_GET[$rms2]))
462 {
463 $min=$_GET[$mean] - $_GET[$rms2];
464 $max=$_GET[$mean] + $_GET[$rms2];
465 if ($min < $element && $element < $max)
466 printf("<font color='green'>");
467 else
468 printf("<font color='red'>");
469 }
470 }
471 else
472 {
473 if ($rms[$key2]=="min")
474 {
475 if ($_GET[$mean] <= $element)
476 printf("<font color='green'>");
477 else
478 printf("<font color='red'>");
479 }
480
481 if ($rms[$key2]=="max")
482 {
483 if ($_GET[$mean] >= $element)
484 printf("<font color='green'>");
485 else
486 printf("<font color='red'>");
487 }
488 }
489 }
490
491 }
492 }
493
494 printf("&nbsp;%s&nbsp;</td>\n", str_replace("&ws;", " ", str_replace(" ", "&nbsp;", $element)));
495 }
496 printf(" </tr>\n");
497 }
498 printf("</table>\n");
499
500 /*
501 $info = mysql_info();
502 if (!empty($info))
503 printf("%s<BR>\n", $info);
504 */
505
506 printf("<P><B>Number of displayed results: %d</B><P><P>\n", mysql_num_rows($result0));
507 printf("%s\n", $menu);
508 printf("<P>\n");
509 printf("</center>\n");
510 printf("</tr><tr class='Block'><td>\n");
511}
512
513?>
Note: See TracBrowser for help on using the repository browser.