source: trunk/MagicSoft/Mars/datacenter/db/querycal.php@ 7507

Last change on this file since 7507 was 7507, checked in by hoehne, 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, $checkwhere)
4 {
5 $query0 = "SELECT fSequenceFirst as 'Sequence#' ";
6
7 foreach ($_GET as $key => $element)
8 if ($_GET[$key]=="On")
9 if (empty($checkwhere[$key]) || $checkwhere[$key]==0)
10 $query0 .= ", " . $key . " as '" . $alias[$key] . "' ";
11
12 $query0 .= " FROM Calibration ";
13
14 if (strpos($query0, " WHERE ")==FALSE)
15 $query0 .= " WHERE ";
16 else
17 $query0 .= " AND ";
18
19 $query0 .= "fSequenceFirst BETWEEN " . $_GET["fRunMin"] . " AND " . $_GET["fRunMax"] . " ";
20
21 if (!empty($_GET["fSortBy"]))
22 {
23 $query0 .= " ORDER BY " . substr($_GET["fSortBy"], 0, -1) . " ";
24 if (substr($_GET["fSortBy"], -1)=="-")
25 $query0 .= "DESC";
26 }
27
28 if (empty($_GET["fNumStart"]))
29 $_GET["fNumStart"]=0;
30
31 if (empty($_GET["fSendTxt"]))
32 $query0 .= " LIMIT " . $_GET["fNumStart"] . ", " . $_GET["fNumResults"];
33
34 return $query0;
35 }
36
37 function InitGet($_GET)
38 {
39 // Find out whether it is the first call to the php script
40 $first = empty($_GET["fRunMin"]) && empty($_GET["fRunMax"]);
41
42 if (empty($_GET["fNumResults"]))
43 $_GET["fNumResults"]="20";
44
45 if (empty($_GET["fLastUpdate"]))
46 $_GET["fLastUpdate"]="Off";
47
48 if (empty($_GET["fUnreliableInner"]))
49 $_GET["fUnreliableInner"]=$first?"On":"";
50
51 if (empty($_GET["fUnsuitableOuter"]))
52 $_GET["fUnsuitableOuter"]=$first?"On":"";
53
54 if (empty($_GET["fUnreliableOuter"]))
55 $_GET["fUnreliableOuter"]=$first?"On":"";
56
57 if (empty($_GET["fUnsuitableInner"]))
58 $_GET["fUnsuitableInner"]=$first?"On":"";
59
60 if (empty($_GET["fIsolatedInner"]))
61 $_GET["fIsolatedInner"]=$first?"On":"";
62
63 if (empty($_GET["fIsolatedOuter"]))
64 $_GET["fIsolatedOuter"]=$first?"On":"";
65
66 if (empty($_GET["fMeanPedRmsInner"]))
67 $_GET["fMeanPedRmsInner"]=$first?"On":"";
68
69 if (empty($_GET["fMeanPedRmsOuter"]))
70 $_GET["fMeanPedRmsOuter"]=$first?"On":"";
71
72 if (empty($_GET["fIsolatedMaxCluster"]))
73 $_GET["fIsolatedMaxCluster"]=$first?"On":"";
74
75 if (empty($_GET["fArrTimeMeanInner"]))
76 $_GET["fArrTimeMeanInner"]=$first?"On":"";
77
78 if (empty($_GET["fArrTimeMeanOuter"]))
79 $_GET["fArrTimeMeanOuter"]=$first?"On":"";
80
81 if (empty($_GET["fArrTimeRmsInner"]))
82 $_GET["fArrTimeRmsInner"]=$first?"On":"";
83
84 if (empty($_GET["fArrTimeRmsOuter"]))
85 $_GET["fArrTimeRmsOuter"]=$first?"On":"";
86
87 if (empty($_GET["fMeanSignalInner"]))
88 $_GET["fMeanSignalInner"]=$first?"Off":"";
89
90 if (empty($_GET["fMeanSignalOuter"]))
91 $_GET["fMeanSignalOuter"]=$first?"Off":"";
92
93 if (empty($_GET["fPulsePosMean"]))
94 $_GET["fPulsePosMean"]=$first?"Off":"";
95
96 if (empty($_GET["fConvFactorInner"]))
97 $_GET["fConvFactorInner"]=$first?"On":"";
98
99 if (empty($_GET["fConvFactorOuter"]))
100 $_GET["fConvFactorOuter"]=$first?"On":"";
101
102 }
103
104 function PrintForm($_GET, $db)
105 {
106 printf("<center>\n");
107 printf("<form action=\"querycal.php\" METHOD=\"GET\">\n");
108 printf(" <table>\n");
109 printf(" <tr>\n");
110
111 CheckBox("fUnsuitableInner", "Unsuitable inner");
112 CheckBox("fUnsuitableOuter", "Unsuitable outer");
113 CheckBox("fUnreliableInner", "Unreliable inner");
114 CheckBox("fUnreliableOuter", "Unreliable outer");
115 CheckBox("fIsolatedInner", "Isolated inner");
116 CheckBox("fIsolatedOuter", "Isolated outer");
117
118 printf(" </tr><tr>\n");
119
120 CheckBox("fIsolatedMaxCluster", "IsolatedMaxCluster");
121 CheckBox("fArrTimeMeanInner", "ArrTimeMean inner ");
122 CheckBox("fArrTimeMeanOuter", "ArrTimeMean outer ");
123 CheckBox("fArrTimeRmsInner", "ArrTimeRms inner ");
124 CheckBox("fArrTimeRmsOuter", "ArrTimeRms outer ");
125 CheckBox("fPulsePosMean", "Mean PulsePos");
126
127 printf(" </tr><tr>\n");
128
129 CheckBox("fConvFactorInner", "Conv inner ");
130 CheckBox("fConvFactorOuter", "Conv outer ");
131 CheckBox("fMeanPedRmsInner", "MeanPedRms inner");
132 CheckBox("fMeanPedRmsOuter", "MeanPedRms outer");
133 CheckBox("fMeanSignalInner", "MeanSignal inner");
134 CheckBox("fMeanSignalOuter", "MeanSignal outer");
135
136 printf(" </table>\n");
137 printf(" <p>\n");
138
139 if (empty($_GET["fRunMin"]))
140 $min = GetMin("fSequenceFirst", "Sequences", $db);
141 else
142 $min = $_GET["fRunMin"];
143
144 if (empty($_GET["fRunMax"]))
145 $max = GetMax("fSequenceFirst", "Sequences", $db);
146 else
147 $max = $_GET["fRunMax"];
148
149
150 printf("Sequences&nbsp;from&nbsp;<input name=\"fRunMin\" type=\"text\" size=\"6\" maxlength=\"6\" value=\"%s\">\n", $min);
151 printf("to&nbsp;<input name=\"fRunMax\" type=\"text\" size=\"6\" maxlength=\"6\" value=\"%s\">&nbsp;&nbsp;&nbsp;\n", $max);
152
153 printf(" <P>\n");
154
155 printf(" Results:\n");
156 printf(" <select name=\"fNumResults\">\n");
157
158 $numres = array("10", "20", "50", "100", "200", "500");
159 foreach ($numres as $element)
160 {
161 if ($element==$_GET["fNumResults"])
162 printf("<option value=\"%s\" selected>%3s</option>\n", $element, $element);
163 else
164 printf("<option value=\"%s\">%3s</option>\n", $element, $element);
165 }
166 printf(" </select>\n");
167 printf(" &nbsp;&nbsp;&nbsp;\n");
168
169 ini_set("mysql.trace_mode", "Off");
170 ini_set("display_errors", "Off");
171
172 printf("<input class='Width' type='submit' value='Query Table'>&nbsp;&nbsp;&nbsp;\n");
173 printf("<input class='Width' type='button' value='Reset' onClick='self.location.href=\"querycal.php\"'>&nbsp;&nbsp;&nbsp;\n");
174 if (strchr($_SERVER["REQUEST_URI"], '?')!=FALSE)
175 printf("<input class='Width' type='button' value='Get .txt' onClick='self.location.href=\"%s&fSendTxt=1\"'>&nbsp;&nbsp;&nbsp;\n", $_SERVER["REQUEST_URI"]);
176 printf("</form>\n");
177 printf("</center>\n");
178 printf("</td>\n");
179 printf("</tr>\n");
180 printf("<tr class='Block'>\n");
181 printf("<td>\n");
182 }
183
184 function PrintPage($html, $db, $alias, $rightalign, $checkwhere)
185 {
186 $db_id = mysql_connect("hercules.astro.uni-wuerzburg.de", "MAGIC", "d99swMT!");
187 if ($db_id==FALSE)
188 {
189 printf("mysql_connect returned the following error: %s\n", mysql_error());
190 die("");
191 }
192 mysql_select_db($db);
193
194 $query0 = CreateQuery($_GET, $alias, $checkwhere);
195
196 $result0 = mysql_query($query0, $db_id);
197
198 if ($result0)
199 {
200 if ($html=="1")
201 PrintMagicTable($result0, $alias, $rightalign, "", "", $_GET);
202 else
203 PrintText($result0);
204
205 mysql_free_result($result0);
206 }
207 mysql_close($db_id);
208
209 if ($html=="1")
210 printf("<U><B>submitted query:</B></U><BR>%s<BR>", htmlspecialchars($query0));
211 }
212
213 include ("include.php");
214 include ("db.php");
215 include ("magicdefs.php");
216
217 ini_set("display_errors", "On");
218 ini_set("mysql.trace_mode", "On");
219
220 if (!empty($_GET["fSendTxt"]))
221 {
222 header("Content-type: application/octet");
223 header("Content-Disposition: attachment; filename=query-result.txt");
224
225 PrintPage("0", $db, $alias, $rightalign, $checkwhere);
226 }
227 else
228 {
229 echo (file_get_contents("index-header.html"));
230
231 $environment = sizeof($_GET);
232
233 InitGet($_GET);
234 PrintForm($_GET, $db);
235
236 if ($environment==0)
237 printf("No query submitted yet.<BR>");
238 else
239 PrintPage("1", $db, $alias, $rightalign, $checkwhere);
240
241 echo (file_get_contents("index-footer.html"));
242 }
243
244 ini_set("display_errors", "Off");
245 ini_set("mysql.trace_mode", "Off");
246}
247?>
Note: See TracBrowser for help on using the repository browser.