1 | <?php
|
---|
2 | {
|
---|
3 | function CreateQuery($_GET, $alias, $checkwhere, $checkgroup, $checkstatusgroup)
|
---|
4 | {
|
---|
5 | $fromtable="Sequences";
|
---|
6 |
|
---|
7 | $groups = 0;
|
---|
8 | foreach ($checkgroup as $element)
|
---|
9 | if ($element==-1)
|
---|
10 | $groups++;
|
---|
11 |
|
---|
12 | $query0 = "SELECT ";
|
---|
13 |
|
---|
14 | if ($groups>0)
|
---|
15 | {
|
---|
16 | foreach ($checkgroup as $key => $element)
|
---|
17 | if ($element==-1)
|
---|
18 | $query0 .= $key . " as '" . $alias[$key] . "' " . ", ";
|
---|
19 | //--------------------------------------------------
|
---|
20 | $query0 .= "SUM(fRunTime)/3600 as '" . $alias["SUM(fRunTime)/3600"] . "', ";
|
---|
21 | //--------------------------------------------------
|
---|
22 | $query0 .= " SUM(fNumEvents) as '" . $alias["SUM(fNumEvents)"] . "', ";
|
---|
23 | $query0 .= " COUNT(*) as 'Sequ#' ";
|
---|
24 | }
|
---|
25 | else
|
---|
26 | {
|
---|
27 | if (!empty($_GET["fSendTxt"]))
|
---|
28 | $query0 .= " SELECT fSequenceFirst ";
|
---|
29 | else
|
---|
30 | $query0 .= " CONCAT('<A&ws;HREF=\"index.php?', 'fRunStart=On', '&fZenithDistance=On', '&fRunMin=', fSequenceFirst, '&fMeanTriggerRate=On', '&fRunTypeName=On', '&fRunMax=', fSequenceLast, '&fNumEvents=On', '&fSourceName=On&', 'fExcludedFDAKEY=1', '&fSequenceFirst=On', '&fNumResults=500\">', fSequenceFirst, '</A>') ";
|
---|
31 | $query0 .= " as 'Sequence#' ";
|
---|
32 |
|
---|
33 | foreach ($_GET as $key => $element)
|
---|
34 | if ($_GET[$key]=="On")
|
---|
35 | if (empty($checkwhere[$key]) || $checkwhere[$key]==0)
|
---|
36 | $query0 .= ", " . $key . " as '" . $alias[$key] . "' ";
|
---|
37 | }
|
---|
38 |
|
---|
39 | $query0 .= " FROM " . $fromtable;
|
---|
40 |
|
---|
41 | foreach ($_GET as $key => $element)
|
---|
42 | if (($_GET[$key]=="On" || $groups>0))// && !empty($joins[$key]))
|
---|
43 | $query0 .= GetJoin($fromtable, $key);
|
---|
44 |
|
---|
45 | foreach ($checkwhere as $key => $element)
|
---|
46 | {
|
---|
47 | if (empty($element) || $element<=0)
|
---|
48 | continue;
|
---|
49 |
|
---|
50 | if (strpos($query0, " WHERE ")==FALSE)
|
---|
51 | $query0 .= " WHERE ";
|
---|
52 | else
|
---|
53 | if ($element!=-1)
|
---|
54 | if (strrpos($query0, " AND ")!=strlen($query0)-5)
|
---|
55 | $query0 .= " AND ";
|
---|
56 |
|
---|
57 | if ($element!=-1)
|
---|
58 | $query0 .= GetCheck($fromtable, $key) . "=" . $element;
|
---|
59 | }
|
---|
60 |
|
---|
61 | if (strpos($query0, " WHERE ")==FALSE)
|
---|
62 | $query0 .= " WHERE ";
|
---|
63 | else
|
---|
64 | $query0 .= " AND ";
|
---|
65 |
|
---|
66 | $query0 .= "fSequenceFirst BETWEEN " . $_GET["fRunMin"] . " AND " . $_GET["fRunMax"] . " ";
|
---|
67 |
|
---|
68 | if (!empty($_GET["fSourceN"]))
|
---|
69 | $query0 .= " AND fSourceName REGEXP \"^" . $_GET["fSourceN"] . "\" ";
|
---|
70 |
|
---|
71 | $query0 .= " AND ((fAzimuthMin<0 and fAzimuthMax>0) OR (fAzimuthMin<180 and fAzimuthMax>180)) ";
|
---|
72 |
|
---|
73 | if ($groups>0)
|
---|
74 | {
|
---|
75 | $query0 .= " GROUP BY ";
|
---|
76 | $num = $groups;
|
---|
77 | foreach ($checkgroup as $key => $element)
|
---|
78 | if ($element==-1)
|
---|
79 | {
|
---|
80 | $query0 .= GetCheck($fromtable, $key);
|
---|
81 | if ($num-->1)
|
---|
82 | $query0 .= ", ";
|
---|
83 | }
|
---|
84 | }
|
---|
85 |
|
---|
86 | if (!empty($_GET["fSortBy"]))
|
---|
87 | {
|
---|
88 | $query0 .= " ORDER BY " . substr($_GET["fSortBy"], 0, -1) . " ";
|
---|
89 | if (substr($_GET["fSortBy"], -1)=="-")
|
---|
90 | $query0 .= "DESC";
|
---|
91 | }
|
---|
92 |
|
---|
93 | if (empty($_GET["fNumStart"]))
|
---|
94 | $_GET["fNumStart"]=0;
|
---|
95 |
|
---|
96 | if (empty($_GET["fSendTxt"]))
|
---|
97 | $query0 .= " LIMIT " . $_GET["fNumStart"] . ", " . $_GET["fNumResults"];
|
---|
98 |
|
---|
99 | return $query0;
|
---|
100 | }
|
---|
101 |
|
---|
102 | function InitGet($_GET)
|
---|
103 | {
|
---|
104 | // Find out whether it is the first call to the php script
|
---|
105 | $first = empty($_GET["fRunMin"]) && empty($_GET["fRunMax"]);
|
---|
106 |
|
---|
107 | if (empty($_GET["fNumResults"]))
|
---|
108 | $_GET["fNumResults"]="20";
|
---|
109 |
|
---|
110 | if (empty($_GET["fLastUpdate"]))
|
---|
111 | $_GET["fLastUpdate"]="Off";
|
---|
112 |
|
---|
113 | if (empty($_GET["fSourceName"]))
|
---|
114 | $_GET["fSourceName"]=$first?"On":"";
|
---|
115 |
|
---|
116 | if (empty($_GET["fRunStart"]))
|
---|
117 | $_GET["fRunStart"]=$first?"On":"";
|
---|
118 |
|
---|
119 | if (empty($_GET["fAzimuthMin"]))
|
---|
120 | $_GET["fAzimuthMin"]="Off";
|
---|
121 |
|
---|
122 | if (empty($_GET["fAzimuthMax"]))
|
---|
123 | $_GET["fAzimuthMax"]="Off";
|
---|
124 |
|
---|
125 | if (empty($_GET["fZenithDistanceMin"]))
|
---|
126 | $_GET["fZenithDistanceMin"]=$first?"On":"";
|
---|
127 |
|
---|
128 | if (empty($_GET["fZenithDistanceMax"]))
|
---|
129 | $_GET["fZenithDistanceMax"]="Off";
|
---|
130 |
|
---|
131 | if (empty($_GET["fRunTime/60"]))
|
---|
132 | $_GET["fRunTime/60"]="Off";
|
---|
133 |
|
---|
134 | }
|
---|
135 |
|
---|
136 | function PrintForm($_GET, $host, $user, $pw, $db)
|
---|
137 | {
|
---|
138 | printf("<center>\n");
|
---|
139 | printf("<form action=\"culminating.php\" METHOD=\"GET\">\n");
|
---|
140 | printf(" <table>\n");
|
---|
141 | printf(" <tr>\n");
|
---|
142 |
|
---|
143 | CheckBox("fAzimuthMin", "Azimuth min");
|
---|
144 | CheckBox("fAzimuthMax", "Azimuth max");
|
---|
145 | CheckBox("fZenithDistanceMin", "Zenith distance min");
|
---|
146 | CheckBox("fZenithDistanceMax", "Zenith distance max");
|
---|
147 |
|
---|
148 | printf(" </tr><tr>\n");
|
---|
149 |
|
---|
150 | CheckBox("fRunTime/60", "Duration");
|
---|
151 |
|
---|
152 | printf(" </table>\n");
|
---|
153 | printf(" <p>\n");
|
---|
154 |
|
---|
155 | printf(" <table>\n");
|
---|
156 | printf(" <tr><td>\n");
|
---|
157 | PrintPullDown($host, $user, $pw, $db, "Source", "fSourceName", "fSourceKEY", "Source Name");
|
---|
158 | printf(" </td></tr>\n");
|
---|
159 | printf(" </table>\n");
|
---|
160 | printf(" <p>\n");
|
---|
161 |
|
---|
162 | if (empty($_GET["fRunMin"]))
|
---|
163 | $min = GetMin("fSequenceFirst", "Sequences", $host, $user, $pw, $db);
|
---|
164 | else
|
---|
165 | $min = $_GET["fRunMin"];
|
---|
166 |
|
---|
167 | if (empty($_GET["fRunMax"]))
|
---|
168 | $max = GetMax("fSequenceFirst", "Sequences", $host, $user, $pw, $db);
|
---|
169 | else
|
---|
170 | $max = $_GET["fRunMax"];
|
---|
171 |
|
---|
172 |
|
---|
173 | printf("Source (<A HREF=\"regexp.html\">regexp</A>) <input name=\"fSourceN\" type=\"text\" size=\"15\" maxlength=\"15\" value=\"");
|
---|
174 | if (!empty($_GET["fSourceN"]))
|
---|
175 | printf("%s", $_GET["fSourceN"]);
|
---|
176 | printf("\"> \n");
|
---|
177 |
|
---|
178 | printf("Sequences from <input name=\"fRunMin\" type=\"text\" size=\"6\" maxlength=\"6\" value=\"%s\">\n", $min);
|
---|
179 | printf("to <input name=\"fRunMax\" type=\"text\" size=\"6\" maxlength=\"6\" value=\"%s\"> \n", $max);
|
---|
180 |
|
---|
181 | printf(" <P>\n");
|
---|
182 |
|
---|
183 | printf(" Results:\n");
|
---|
184 | printf(" <select name=\"fNumResults\">\n");
|
---|
185 |
|
---|
186 | $numres = array("10", "20", "50", "100", "200", "500");
|
---|
187 | foreach ($numres as $element)
|
---|
188 | {
|
---|
189 | if ($element==$_GET["fNumResults"])
|
---|
190 | printf("<option value=\"%s\" selected>%3s</option>\n", $element, $element);
|
---|
191 | else
|
---|
192 | printf("<option value=\"%s\">%3s</option>\n", $element, $element);
|
---|
193 | }
|
---|
194 | printf(" </select>\n");
|
---|
195 | printf(" \n");
|
---|
196 |
|
---|
197 | ini_set("mysql.trace_mode", "Off");
|
---|
198 | ini_set("display_errors", "Off");
|
---|
199 |
|
---|
200 | printf("<input class='Width' type='submit' value='Query Table'> \n");
|
---|
201 | printf("<input class='Width' type='button' value='Reset' onClick='self.location.href=\"culminating.php\"'> \n");
|
---|
202 | if (strchr($_SERVER["REQUEST_URI"], '?')!=FALSE)
|
---|
203 | printf("<input class='Width' type='button' value='Get .txt' onClick='self.location.href=\"%s&fSendTxt=1\"'> \n", $_SERVER["REQUEST_URI"]);
|
---|
204 | printf("</form>\n");
|
---|
205 | printf("</center>\n");
|
---|
206 | printf("</td>\n");
|
---|
207 | printf("</tr>\n");
|
---|
208 | printf("<tr class='Block'>\n");
|
---|
209 | printf("<td>\n");
|
---|
210 | }
|
---|
211 |
|
---|
212 | function PrintPage($html, $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup)
|
---|
213 | {
|
---|
214 | $db_id = mysql_connect($host, $user, $pw);
|
---|
215 | if ($db_id==FALSE)
|
---|
216 | {
|
---|
217 | printf("mysql_connect returned the following error: %s\n", mysql_error());
|
---|
218 | die("");
|
---|
219 | }
|
---|
220 | mysql_select_db($db);
|
---|
221 |
|
---|
222 | $query0 = CreateQuery($_GET, $alias, $checkwhere, $checkgroup, $checkstatusgroup);
|
---|
223 |
|
---|
224 | $result0 = mysql_query($query0, $db_id);
|
---|
225 |
|
---|
226 | if ($result0)
|
---|
227 | {
|
---|
228 | if ($html=="1")
|
---|
229 | PrintMagicTable($result0, $alias, $rightalign, "", "", $_GET);
|
---|
230 | else
|
---|
231 | PrintText($result0);
|
---|
232 |
|
---|
233 | mysql_free_result($result0);
|
---|
234 | }
|
---|
235 | mysql_close($db_id);
|
---|
236 |
|
---|
237 | if ($html=="1")
|
---|
238 | printf("<U><B>submitted query:</B></U><BR>%s<BR>", htmlspecialchars($query0));
|
---|
239 | }
|
---|
240 |
|
---|
241 | include ("include.php");
|
---|
242 | include ("db.php");
|
---|
243 | include ("magicdefs.php");
|
---|
244 |
|
---|
245 | ini_set("display_errors", "On");
|
---|
246 | ini_set("mysql.trace_mode", "On");
|
---|
247 |
|
---|
248 | if (!empty($_GET["fSendTxt"]))
|
---|
249 | {
|
---|
250 | header("Content-type: application/octet");
|
---|
251 | header("Content-Disposition: attachment; filename=query-result.txt");
|
---|
252 |
|
---|
253 | PrintPage("0", $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup);
|
---|
254 | }
|
---|
255 | else
|
---|
256 | {
|
---|
257 | echo (file_get_contents("index-header.html"));
|
---|
258 |
|
---|
259 | $environment = sizeof($_GET);
|
---|
260 |
|
---|
261 | InitGet($_GET);
|
---|
262 | PrintForm($_GET, $host, $user, $pw, $db);
|
---|
263 |
|
---|
264 | if ($environment==0)
|
---|
265 | printf("No query submitted yet.<BR>");
|
---|
266 | else
|
---|
267 | PrintPage("1", $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup);
|
---|
268 |
|
---|
269 | echo (file_get_contents("index-footer.html"));
|
---|
270 | }
|
---|
271 |
|
---|
272 | ini_set("display_errors", "Off");
|
---|
273 | ini_set("mysql.trace_mode", "Off");
|
---|
274 | }
|
---|
275 | ?>
|
---|