source: tags/Mars-V0.9.4.3/datacenter/db/statusrps.php

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