source: trunk/Mars/datacenter/db/culminating.php@ 18066

Last change on this file since 18066 was 17386, checked in by tbretz, 11 years ago
Removed svn:executable property, these are no executables.
File size: 9.4 KB
Line 
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 SQL_CALC_FOUND_ROWS ";
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&nbsp;(<A HREF=\"regexp.html\">regexp</A>)&nbsp;<input name=\"fSourceN\" type=\"text\" size=\"15\" maxlength=\"15\" value=\"");
174 if (!empty($_GET["fSourceN"]))
175 printf("%s", $_GET["fSourceN"]);
176 printf("\">&nbsp;&nbsp;&nbsp;\n");
177
178 printf("Sequences&nbsp;from&nbsp;<input name=\"fRunMin\" type=\"text\" size=\"6\" maxlength=\"6\" value=\"%s\">\n", $min);
179 printf("to&nbsp;<input name=\"fRunMax\" type=\"text\" size=\"6\" maxlength=\"6\" value=\"%s\">&nbsp;&nbsp;&nbsp;\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(" &nbsp;&nbsp;&nbsp;\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'>&nbsp;&nbsp;&nbsp;\n");
201 printf("<input class='Width' type='button' value='Reset' onClick='self.location.href=\"culminating.php\"'>&nbsp;&nbsp;&nbsp;\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\"'>&nbsp;&nbsp;&nbsp;\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 $result1 = mysql_query("SELECT FOUND_ROWS()", $db_id);
226
227 if ($result0)
228 {
229 if ($html=="1")
230 PrintMagicTable($result0, $alias, $rightalign, "", "", "", $result1);
231 else
232 PrintText($result0);
233
234 mysql_free_result($result0);
235 mysql_free_result($result1);
236 }
237 mysql_close($db_id);
238
239 if ($html=="1")
240 PrintSubmittedQuery($query0, $db, "old");
241 }
242 include ("include.php");
243 include ("db.php");
244 include ("magicdefs.php");
245
246 ini_set("display_errors", "On");
247 ini_set("mysql.trace_mode", "On");
248
249 if (!empty($_GET["fSendTxt"]))
250 {
251 header("Content-type: application/octet");
252 header("Content-Disposition: attachment; filename=query-result.txt");
253
254 PrintPage("0", $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup);
255 }
256 else
257 {
258 echo (file_get_contents("index-header.html"));
259
260 $environment = sizeof($_GET);
261
262 InitGet($_GET);
263 PrintForm($_GET, $host, $user, $pw, $db);
264
265 if ($environment==0)
266 printf("No query submitted yet.<BR>");
267 else
268 PrintPage("1", $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup);
269
270 echo (file_get_contents("index-footer.html"));
271 }
272
273 ini_set("display_errors", "Off");
274 ini_set("mysql.trace_mode", "Off");
275}
276?>
Note: See TracBrowser for help on using the repository browser.