source: trunk/MagicSoft/Mars/datacenter/db/statusrps.php@ 9384

Last change on this file since 9384 was 8180, checked in by Daniela Dorner, 18 years ago
*** empty log message ***
  • Property svn:executable set to *
File size: 8.5 KB
Line 
1<?php
2{
3 function CreateQuery($_GET, $alias, $checkstatusgroup, $checkwhere, $needs)
4 {
5 $query0 = "SELECT ";
6
7 $statusgroups = 0;
8 foreach ($checkstatusgroup as $element)
9 if ($element==-1)
10 $statusgroups++;
11
12 if ($statusgroups>0)
13 {
14 foreach ($checkstatusgroup as $key => $element)
15 if ($element==-1)
16 $query0 .= " (if(IsNull(" . $key . "), if(isnull(fStartTime), 'not done', if(isnull(fFailedTime),if(isnull(" . $needs[$key] . "),'not done',if(date_sub(Now(),interval 12 hour) < fStartTime,'running','crashed')),if(isnull(" . $needs[$key] . "),'not done','failed'))) ,if(" . $key . "='1970-01-01 00:00:00','dont do','done'))) as '" . $alias[$key] . "', ";
17// $query0 .= " (if(IsNull(" . $key . "), 'not done' ,if(" . $key . "='1970-01-01 00:00:00','dont do','done'))) as '" . $key . "', ";
18
19 $query0 .= " count(*) as '# Runs'";
20
21 }
22 else
23 {
24 $query0 .= "fRunNumber as '# Runs' ";
25
26 foreach ($_GET as $key => $element)
27 if ($_GET[$key]=="On")
28 if (empty($checkwhere[$key]) || $checkwhere[$key]==0)
29 $query0 .= ", " . $key . " as '" . $alias[$key] . "' ";
30 }
31
32 $query0 .= " FROM RunProcessStatus ";
33
34 if (strpos($query0, " WHERE ")==FALSE)
35 $query0 .= " WHERE ";
36 else
37 $query0 .= " AND ";
38
39 $query0 .= StatusQuery("fCCFileAvail", $needs);
40 $query0 .= StatusQuery("fCaCoFileAvail", $needs);
41 $query0 .= StatusQuery("fCaCoFileFound", $needs);
42 $query0 .= StatusQuery("fRawFileAvail", $needs);
43 $query0 .= StatusQuery("fDataCheckDone", $needs);
44 $query0 .= StatusQuery("fTimingCorrection", $needs);
45
46 $query0 .= "fRunNumber BETWEEN " . $_GET["fRunMin"] . " AND " . $_GET["fRunMax"] . " ";
47
48 if ($statusgroups>0)
49 {
50 $query0 .= " GROUP BY ";
51 $num = $statusgroups;
52 foreach ($checkstatusgroup as $key => $element)
53 if ($element==-1)
54 {
55 $query0 .= $alias[$key];
56 if ($num-->1)
57 $query0 .= ", ";
58 }
59 }
60
61 if (!empty($_GET["fSortBy"]))
62 {
63 $query0 .= " ORDER BY " . substr($_GET["fSortBy"], 0, -1) . " ";
64 if (substr($_GET["fSortBy"], -1)=="-")
65 $query0 .= "DESC";
66 }
67
68 if (empty($_GET["fNumStart"]))
69 $_GET["fNumStart"]=0;
70
71 if (empty($_GET["fSendTxt"]))
72 $query0 .= " LIMIT " . $_GET["fNumStart"] . ", " . $_GET["fNumResults"];
73
74 return $query0;
75 }
76
77 function InitGet($_GET)
78 {
79 // Find out whether it is the first call to the php script
80 $first = empty($_GET["fRunMin"]) && empty($_GET["fRunMax"]);
81
82 if (empty($_GET["fNumResults"]))
83 $_GET["fNumResults"]="20";
84
85 if (empty($_GET["fDataCheckDone"]))
86 $_GET["fDataCheckDone"]="Off";
87
88 if (empty($_GET["fDataCheckDoneStatus"]))
89 $_GET["fDataCheckDoneStatus"]="0";
90
91 if (empty($_GET["fCCFileAvail"]))
92 $_GET["fCCFileAvail"]=$first?"On":"";
93
94 if (empty($_GET["fCCFileAvailStatus"]))
95 $_GET["fCCFileAvailStatus"]="0";
96
97 if (empty($_GET["fCaCoFileAvail"]))
98 $_GET["fCaCoFileAvail"]=$first?"On":"";
99
100 if (empty($_GET["fCaCoFileAvailStatus"]))
101 $_GET["fCaCoFileAvailStatus"]="0";
102
103 if (empty($_GET["fCaCoFileFound"]))
104 $_GET["fCaCoFileFound"]="Off";
105
106 if (empty($_GET["fCaCoFileFoundStatus"]))
107 $_GET["fCaCoFileFoundStatus"]="0";
108
109 if (empty($_GET["fRawFileAvail"]))
110 $_GET["fRawFileAvail"]=$first?"On":"";
111
112 if (empty($_GET["fRawFileAvailStatus"]))
113 $_GET["fRawFileAvailStatus"]="0";
114
115 if (empty($_GET["fTimingCorrection"]))
116 $_GET["fTimingCorrection"]=$first?"On":"";
117
118 if (empty($_GET["fTimingCorrectionStatus"]))
119 $_GET["fTimingCorrectionStatus"]="0";
120
121 }
122
123 function PrintForm($_GET, $host, $user, $pw, $db)
124 {
125 printf("<center>\n");
126 printf("<form action=\"statusrps.php\" METHOD=\"GET\">\n");
127 printf(" <table>\n");
128 printf(" <tr><td>\n");
129
130 PrintStatusMenu("fCCFileAvail", "CC File available");
131 printf(" </td><td>\n");
132 PrintStatusMenu("fCaCoFileAvail", "Caco File available");
133 printf(" </td><td>\n");
134 PrintStatusMenu("fRawFileAvail", "Rawfile available");
135
136 printf(" </td></tr><tr><td>\n");
137
138 PrintStatusMenu("fTimingCorrection", "Timing Correction");
139 printf(" </td><td>\n");
140 PrintStatusMenu("fCaCoFileFound", "Caco File");
141 printf(" </td><td>\n");
142 PrintStatusMenu("fDataCheckDone", "Datacheck");
143
144 printf(" </td></tr></table>\n");
145 printf(" <p>\n");
146
147 if (empty($_GET["fRunMin"]))
148 $min = GetMin("fRunNumber", "RunProcessStatus", $host, $user, $pw, $db);
149 else
150 $min = $_GET["fRunMin"];
151
152 if (empty($_GET["fRunMax"]))
153 $max = GetMax("fRunNumber", "RunProcessStatus", $host, $user, $pw, $db);
154 else
155 $max = $_GET["fRunMax"];
156
157
158 printf("Runs&nbsp;from&nbsp;<input name=\"fRunMin\" type=\"text\" size=\"6\" maxlength=\"6\" value=\"%s\">\n", $min);
159 printf("to&nbsp;<input name=\"fRunMax\" type=\"text\" size=\"6\" maxlength=\"6\" value=\"%s\">&nbsp;&nbsp;&nbsp;\n", $max);
160
161 printf(" <P>\n");
162
163 printf(" Results:\n");
164 printf(" <select name=\"fNumResults\">\n");
165
166 $numres = array("10", "20", "50", "100", "200", "500");
167 foreach ($numres as $element)
168 {
169 if ($element==$_GET["fNumResults"])
170 printf("<option value=\"%s\" selected>%3s</option>\n", $element, $element);
171 else
172 printf("<option value=\"%s\">%3s</option>\n", $element, $element);
173 }
174 printf(" </select>\n");
175 printf(" &nbsp;&nbsp;&nbsp;\n");
176
177 ini_set("mysql.trace_mode", "Off");
178 ini_set("display_errors", "Off");
179
180 printf("<input class='Width' type='submit' value='Query Table'>&nbsp;&nbsp;&nbsp;\n");
181 printf("<input class='Width' type='button' value='Reset' onClick='self.location.href=\"statusrps.php\"'>&nbsp;&nbsp;&nbsp;\n");
182 if (strchr($_SERVER["REQUEST_URI"], '?')!=FALSE)
183 printf("<input class='Width' type='button' value='Get .txt' onClick='self.location.href=\"%s&fSendTxt=1\"'>&nbsp;&nbsp;&nbsp;\n", $_SERVER["REQUEST_URI"]);
184 printf("</form>\n");
185 printf("</center>\n");
186 printf("</td>\n");
187 printf("</tr>\n");
188 printf("<tr class='Block'>\n");
189 printf("<td>\n");
190 }
191
192 function PrintPage($html, $host, $user, $pw, $db, $alias, $rightalign, $checkstatusgroup, $checkwhere, $needs)
193 {
194 $db_id = mysql_connect($host, $user, $pw);
195 if ($db_id==FALSE)
196 {
197 printf("mysql_connect returned the following error: %s\n", mysql_error());
198 die("");
199 }
200 mysql_select_db($db);
201
202 $query0 = CreateQuery($_GET, $alias, $checkstatusgroup, $checkwhere, $needs);
203
204 $result0 = mysql_query($query0, $db_id);
205
206 if ($result0)
207 {
208 if ($html=="1")
209 PrintMagicTable($result0, $alias, $rightalign, "", "", "", "", $_GET);
210 else
211 PrintText($result0);
212
213 mysql_free_result($result0);
214 }
215 mysql_close($db_id);
216
217 PrintSubmittedQuery($query0, $html, $db, "old");
218 }
219
220 include ("include.php");
221 include ("db.php");
222 include ("magicdefs.php");
223
224 ini_set("display_errors", "On");
225 ini_set("mysql.trace_mode", "On");
226
227 if (!empty($_GET["fSendTxt"]))
228 {
229 header("Content-type: application/octet");
230 header("Content-Disposition: attachment; filename=query-result.txt");
231
232 PrintPage("0", $host, $user, $pw, $db, $alias, $rightalign, $checkstatusgroup, $checkwhere, $needs);
233 }
234 else
235 {
236 echo (file_get_contents("index-header.html"));
237
238 $environment = sizeof($_GET);
239
240 InitGet($_GET);
241 PrintForm($_GET, $host, $user, $pw, $db);
242
243 if ($environment==0)
244 printf("No query submitted yet.<BR>");
245 else
246 PrintPage("1", $host, $user, $pw, $db, $alias, $rightalign, $checkstatusgroup, $checkwhere, $needs);
247
248 echo (file_get_contents("index-footer.html"));
249 }
250
251 ini_set("display_errors", "Off");
252 ini_set("mysql.trace_mode", "Off");
253}
254?>
Note: See TracBrowser for help on using the repository browser.