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

Last change on this file since 7484 was 7484, checked in by Daniela Dorner, 19 years ago
*** empty log message ***
  • Property svn:executable set to *
File size: 7.6 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["fConvFactorInner"]))
88 $_GET["fConvFactorInner"]=$first?"On":"";
89
90 if (empty($_GET["fConvFactorOuter"]))
91 $_GET["fConvFactorOuter"]=$first?"On":"";
92
93 }
94
95 function PrintForm($_GET, $db)
96 {
97 printf("<center>\n");
98 printf("<form action=\"querycal.php\" METHOD=\"GET\">\n");
99 printf(" <table>\n");
100 printf(" <tr>\n");
101
102 CheckBox("fUnsuitableInner", "Unsuitable inner");
103 CheckBox("fUnsuitableOuter", "Unsuitable outer");
104 CheckBox("fUnreliableInner", "Unreliable inner");
105 CheckBox("fUnreliableOuter", "Unreliable outer");
106
107 printf(" </tr><tr>\n");
108
109 CheckBox("fIsolatedInner", "Isolated inner");
110 CheckBox("fIsolatedOuter", "Isolated outer");
111 CheckBox("fIsolatedMaxCluster", "IsolatedMaxCluster");
112
113 printf(" </tr><tr>\n");
114
115 CheckBox("fArrTimeMeanInner", "ArrTimeMean inner ");
116 CheckBox("fArrTimeMeanOuter", "ArrTimeMean outer ");
117 CheckBox("fArrTimeRmsInner", "ArrTimeRms inner ");
118 CheckBox("fArrTimeRmsOuter", "ArrTimeRms outer ");
119
120 printf(" </tr><tr>\n");
121
122 CheckBox("fConvFactorInner", "Conv inner ");
123 CheckBox("fConvFactorOuter", "Conv outer ");
124 CheckBox("fMeanPedRmsInner", "MeanPedRms inner");
125 CheckBox("fMeanPedRmsOuter", "MeanPedRms outer");
126
127 printf(" </table>\n");
128 printf(" <p>\n");
129
130 if (empty($_GET["fRunMin"]))
131 $min = GetMin("fSequenceFirst", "Sequences", $db);
132 else
133 $min = $_GET["fRunMin"];
134
135 if (empty($_GET["fRunMax"]))
136 $max = GetMax("fSequenceFirst", "Sequences", $db);
137 else
138 $max = $_GET["fRunMax"];
139
140
141 printf("Sequences&nbsp;from&nbsp;<input name=\"fRunMin\" type=\"text\" size=\"6\" maxlength=\"6\" value=\"%s\">\n", $min);
142 printf("to&nbsp;<input name=\"fRunMax\" type=\"text\" size=\"6\" maxlength=\"6\" value=\"%s\">&nbsp;&nbsp;&nbsp;\n", $max);
143
144 printf(" <P>\n");
145
146 printf(" Results:\n");
147 printf(" <select name=\"fNumResults\">\n");
148
149 $numres = array("10", "20", "50", "100", "200", "500");
150 foreach ($numres as $element)
151 {
152 if ($element==$_GET["fNumResults"])
153 printf("<option value=\"%s\" selected>%3s</option>\n", $element, $element);
154 else
155 printf("<option value=\"%s\">%3s</option>\n", $element, $element);
156 }
157 printf(" </select>\n");
158 printf(" &nbsp;&nbsp;&nbsp;\n");
159
160 ini_set("mysql.trace_mode", "Off");
161 ini_set("display_errors", "Off");
162
163 printf("<input class='Width' type='submit' value='Query Table'>&nbsp;&nbsp;&nbsp;\n");
164 printf("<input class='Width' type='button' value='Reset' onClick='self.location.href=\"querycal.php\"'>&nbsp;&nbsp;&nbsp;\n");
165 if (strchr($_SERVER["REQUEST_URI"], '?')!=FALSE)
166 printf("<input class='Width' type='button' value='Get .txt' onClick='self.location.href=\"%s&fSendTxt=1\"'>&nbsp;&nbsp;&nbsp;\n", $_SERVER["REQUEST_URI"]);
167 printf("</form>\n");
168 printf("</center>\n");
169 printf("</td>\n");
170 printf("</tr>\n");
171 printf("<tr class='Block'>\n");
172 printf("<td>\n");
173 }
174
175 function PrintPage($html, $db, $alias, $rightalign, $checkwhere)
176 {
177 $db_id = mysql_connect("hercules.astro.uni-wuerzburg.de", "MAGIC", "d99swMT!");
178 if ($db_id==FALSE)
179 {
180 printf("mysql_connect returned the following error: %s\n", mysql_error());
181 die("");
182 }
183 mysql_select_db($db);
184
185 $query0 = CreateQuery($_GET, $alias, $checkwhere);
186
187 $result0 = mysql_query($query0, $db_id);
188
189 if ($result0)
190 {
191 if ($html=="1")
192 PrintMagicTable($result0, $alias, $rightalign, "", "", $_GET);
193 else
194 PrintText($result0);
195
196 mysql_free_result($result0);
197 }
198 mysql_close($db_id);
199
200 if ($html=="1")
201 printf("<U><B>submitted query:</B></U><BR>%s<BR>", htmlspecialchars($query0));
202 }
203
204 include ("include.php");
205 include ("db.php");
206 include ("magicdefs.php");
207
208 ini_set("display_errors", "On");
209 ini_set("mysql.trace_mode", "On");
210
211 if (!empty($_GET["fSendTxt"]))
212 {
213 header("Content-type: application/octet");
214 header("Content-Disposition: attachment; filename=query-result.txt");
215
216 PrintPage("0", $db, $alias, $rightalign, $checkwhere);
217 }
218 else
219 {
220 echo (file_get_contents("index-header.html"));
221
222 $environment = sizeof($_GET);
223
224 InitGet($_GET);
225 PrintForm($_GET, $db);
226
227 if ($environment==0)
228 printf("No query submitted yet.<BR>");
229 else
230 PrintPage("1", $db, $alias, $rightalign, $checkwhere);
231
232 echo (file_get_contents("index-footer.html"));
233 }
234
235 ini_set("display_errors", "Off");
236 ini_set("mysql.trace_mode", "Off");
237}
238?>
Note: See TracBrowser for help on using the repository browser.