1 | <?php
|
---|
2 | {
|
---|
3 | function CreateQuery($_GET, $alias, $checkwhere, $checkgroup, $checkstatusgroup, $needs)
|
---|
4 | {
|
---|
5 | $fromtable="DataSets";
|
---|
6 |
|
---|
7 | $groups = 0;
|
---|
8 | foreach ($checkgroup as $element)
|
---|
9 | if ($element==-1)
|
---|
10 | $groups++;
|
---|
11 |
|
---|
12 | $statusgroups = 0;
|
---|
13 | foreach ($checkstatusgroup as $element)
|
---|
14 | if ($element==-1)
|
---|
15 | $statusgroups++;
|
---|
16 |
|
---|
17 | $query0 = "SELECT ";
|
---|
18 |
|
---|
19 | if ($groups>0)
|
---|
20 | {
|
---|
21 | foreach ($checkgroup as $key => $element)
|
---|
22 | if ($element==-1)
|
---|
23 | $query0 .= $key . " as '" . $alias[$key] . "' " . ", ";
|
---|
24 | $query0 .= " COUNT(*) as '# Datasets' ";
|
---|
25 | }
|
---|
26 | else
|
---|
27 | {
|
---|
28 | if ($statusgroups>0)
|
---|
29 | {
|
---|
30 | foreach ($checkstatusgroup as $key => $element)
|
---|
31 | if ($element==-1)
|
---|
32 | $query0 .= " (if(IsNull(" . $key . "), if(isnull(fStartTime), 'not done', if(isnull(fFailedTime),if(isnull(" . $needs[$key] . "),'not done',if(date_sub(Now(),interval 12 hour) < fStartTime,'running','crashed')),if(isnull(" . $needs[$key] . "),'not done','failed'))) ,if(" . $key . "='1970-01-01 00:00:00','dont do','done'))) as '" . $alias[$key] . "', ";
|
---|
33 | // $query0 .= " (if(IsNull(" . $key . "), 'not done' ,if(" . $key . "='1970-01-01 00:00:00','dont do','done'))) as '" . $alias[$key] . "', ";
|
---|
34 |
|
---|
35 | $query0 .= " COUNT(*) as '# Datasets'";
|
---|
36 |
|
---|
37 | }
|
---|
38 | else
|
---|
39 | {
|
---|
40 | $query0 .= " " . $fromtable . ".fDataSetNumber as '" . $alias["fDataSetNumber"] . "' ";
|
---|
41 | if (!empty($_GET["fLinks"]))
|
---|
42 | {
|
---|
43 | $query0 .= ", CONCAT('<A&ws;HREF=\"http://www.astro.uni-wuerzburg.de/datacenter/datasets/' , LEFT(LPAD(CONCAT(DataSets.fDataSetNumber, '.'), 9,'0'),5), '/dataset', LPAD(CONCAT(DataSets.fDataSetNumber , '.txt'), 12,'0') , '\">f</A>' ";
|
---|
44 | $query0 .= ", ' <A&ws;HREF=\"http://www.astro.uni-wuerzburg.de/datacenter/ganymed/' , LEFT(LPAD(CONCAT(DataSets.fDataSetNumber, '.'), 9,'0'),5), '/', LEFT(LPAD(CONCAT(DataSets.fDataSetNumber, '.'), 9,'0'), 8), '\">g</A>'";
|
---|
45 | $query0 .= ", ' <A&ws;HREF=\"ganymed.php?fDataSetNo=', DataSets.fDataSetNumber, '\">i</A>') ";
|
---|
46 | $query0 .= " as 'Links'";
|
---|
47 | }
|
---|
48 |
|
---|
49 | foreach ($_GET as $key => $element)
|
---|
50 | if ($_GET[$key]=="On")
|
---|
51 | if ($key!="fLinks")
|
---|
52 | if (empty($checkwhere[$key]) || $checkwhere[$key]==0)
|
---|
53 | $query0 .= ", " . $key . " as '" . $alias[$key] . "' ";
|
---|
54 | }
|
---|
55 | }
|
---|
56 |
|
---|
57 | $query0 .= " FROM " . $fromtable;
|
---|
58 |
|
---|
59 | $query0 .= " LEFT JOIN DataSetProcessStatus ON " . $fromtable . ".fDataSetNumber=DataSetProcessStatus.fDataSetNumber ";
|
---|
60 | $query0 .= " LEFT JOIN Ganymed ON " . $fromtable . ".fDataSetNumber=Ganymed.fDataSetNumber ";
|
---|
61 |
|
---|
62 | foreach ($_GET as $key => $element)
|
---|
63 | if (($_GET[$key]=="On" || $groups>0))// && !empty($joins[$key]))
|
---|
64 | $query0 .= GetJoin($fromtable,$key);
|
---|
65 |
|
---|
66 | foreach ($checkwhere as $key => $element)
|
---|
67 | {
|
---|
68 | if (empty($element) || $element<=0)
|
---|
69 | continue;
|
---|
70 |
|
---|
71 | if (strpos($query0, " WHERE ")==FALSE)
|
---|
72 | $query0 .= " WHERE ";
|
---|
73 | else
|
---|
74 | if ($element!=-1)
|
---|
75 | if (strrpos($query0, " AND ")!=strlen($query0)-5)
|
---|
76 | $query0 .= " AND ";
|
---|
77 |
|
---|
78 | if ($element!=-1)
|
---|
79 | $query0 .= GetCheck($fromtable, $key) . "=" . $element;
|
---|
80 | }
|
---|
81 |
|
---|
82 | if (strpos($query0, " WHERE ")==FALSE)
|
---|
83 | $query0 .= " WHERE ";
|
---|
84 | else
|
---|
85 | $query0 .= " AND ";
|
---|
86 |
|
---|
87 | $query0 .= StatusQuery("fDataSetInserted", $needs);
|
---|
88 | $query0 .= StatusQuery("fStarFilesAvail", $needs);
|
---|
89 | $query0 .= StatusQuery("fGanymed", $needs);
|
---|
90 | $query0 .= StatusQuery("fFillGanymed", $needs);
|
---|
91 |
|
---|
92 | if (!empty($_GET["fRunMin"]) && !empty($_GET["fRunMax"]))
|
---|
93 | $query0 .= "DataSets.fDataSetNumber BETWEEN " . $_GET["fRunMin"] . " AND " . $_GET["fRunMax"] . " ";
|
---|
94 |
|
---|
95 | /*
|
---|
96 | if (!empty($_GET["fDate"]))
|
---|
97 | $query0 .= " AND fRunStart REGEXP \"^" . $_GET["fDate"] . "\" ";
|
---|
98 | */
|
---|
99 |
|
---|
100 | if (!empty($_GET["fSourceN"]))
|
---|
101 | $query0 .= " AND fSourceName REGEXP \"^" . $_GET["fSourceN"] . "\" ";
|
---|
102 |
|
---|
103 | if ($groups>0)
|
---|
104 | {
|
---|
105 | $query0 .= " GROUP BY ";
|
---|
106 | $num = $groups;
|
---|
107 | foreach ($checkgroup as $key => $element)
|
---|
108 | if ($element==-1)
|
---|
109 | {
|
---|
110 | $query0 .= GetCheck($fromtable,$key);
|
---|
111 | if ($num-->1)
|
---|
112 | $query0 .= ", ";
|
---|
113 | }
|
---|
114 | }
|
---|
115 |
|
---|
116 | if ($statusgroups>0)
|
---|
117 | {
|
---|
118 | $query0 .= " GROUP BY ";
|
---|
119 | $num = $statusgroups;
|
---|
120 | foreach ($checkstatusgroup as $key => $element)
|
---|
121 | if ($element==-1)
|
---|
122 | {
|
---|
123 | $query0 .= $alias[$key];
|
---|
124 | if ($num-->1)
|
---|
125 | $query0 .= ", ";
|
---|
126 | }
|
---|
127 | }
|
---|
128 |
|
---|
129 | if (!empty($_GET["fSortBy"]))
|
---|
130 | {
|
---|
131 | $val=substr($_GET["fSortBy"], 0, -1);
|
---|
132 | $query0 .= " ORDER BY " . GetTable($fromtable, $val) . " ";
|
---|
133 | if (substr($_GET["fSortBy"], -1)=="-")
|
---|
134 | $query0 .= "DESC";
|
---|
135 | }
|
---|
136 |
|
---|
137 | if (empty($_GET["fSortBy"]) && $groups==0 && $statusgroups==0)
|
---|
138 | $query0 .= "ORDER BY DataSets.fDataSetNumber ASC ";
|
---|
139 |
|
---|
140 | if (empty($_GET["fNumStart"]))
|
---|
141 | $_GET["fNumStart"]=0;
|
---|
142 |
|
---|
143 | if (empty($_GET["fSendTxt"]))
|
---|
144 | $query0 .= " LIMIT " . $_GET["fNumStart"] . ", " . $_GET["fNumResults"];
|
---|
145 |
|
---|
146 | return $query0;
|
---|
147 | }
|
---|
148 |
|
---|
149 | function InitGet($_GET)
|
---|
150 | {
|
---|
151 | // Find out whether it is the first call to the php script
|
---|
152 | $first = empty($_GET["fRunMin"]) && empty($_GET["fRunMax"]);
|
---|
153 |
|
---|
154 | if (empty($_GET["fNumResults"]))
|
---|
155 | $_GET["fNumResults"]="50";
|
---|
156 |
|
---|
157 | if (empty($_GET["fLinks"]))
|
---|
158 | $_GET["fLinks"]=$first?"On":"";
|
---|
159 |
|
---|
160 | if (empty($_GET["fWobble"]))
|
---|
161 | $_GET["fWobble"]=$first?"On":"";
|
---|
162 |
|
---|
163 | if (empty($_GET["fExcessEvents"]))
|
---|
164 | $_GET["fExcessEvents"]=$first?"On":"";
|
---|
165 |
|
---|
166 | if (empty($_GET["fBackgroundEvents*60/fEffOnTime"]))
|
---|
167 | $_GET["fBackgroundEvents*60/fEffOnTime"]=$first?"On":"";
|
---|
168 |
|
---|
169 | if (empty($_GET["fBackgroundEvents"]))
|
---|
170 | $_GET["fBackgroundEvents"]=$first?"On":"";
|
---|
171 |
|
---|
172 | if (empty($_GET["fSignalEvents"]))
|
---|
173 | $_GET["fSignalEvents"]=$first?"On":"";
|
---|
174 |
|
---|
175 | if (empty($_GET["fSignificance"]))
|
---|
176 | $_GET["fSignificance"]=$first?"On":"";
|
---|
177 |
|
---|
178 | if (empty($_GET["fScaleFactor"]))
|
---|
179 | $_GET["fScaleFactor"]=$first?"On":"";
|
---|
180 |
|
---|
181 | if (empty($_GET["fEffOnTime/3600"]))
|
---|
182 | $_GET["fEffOnTime/3600"]=$first?"On":"";
|
---|
183 | if (empty($_GET["fGanymed"]))
|
---|
184 | $_GET["fGanymed"]=$first?"On":"";
|
---|
185 |
|
---|
186 | if (empty($_GET["fSourceName"]))
|
---|
187 | $_GET["fSourceName"]=$first?"On":"";
|
---|
188 |
|
---|
189 | InitDataSetInfo($_GET);
|
---|
190 | }
|
---|
191 |
|
---|
192 | function PrintForm($_GET, $host, $user, $pw, $db)
|
---|
193 | {
|
---|
194 | printf("<center>\n");
|
---|
195 | printf("<form action=\"datasetinfo-aio.php\" METHOD=\"GET\">\n");
|
---|
196 |
|
---|
197 | printf("<input id='sh' type='hidden' name='fShowHide' value='");
|
---|
198 | if (!empty($_GET["fShowHide"]))
|
---|
199 | printf("%s", $_GET["fShowHide"]);
|
---|
200 | else
|
---|
201 | printf("1000000000");
|
---|
202 | printf("'>\n");
|
---|
203 | printf("<img id='allbutton' src='../minus.png' onclick=showhide('all')> Menu \n");
|
---|
204 | printf(" <img id='infobutton' src='../plus.png' onClick=showhide('info');showhide('info2')>DataSetInfo\n");
|
---|
205 | printf(" <img id='statbutton' src='../plus.png' onClick=showhide('stat');showhide('fail')> StatusInfo \n");
|
---|
206 | printf(" <img id='rangesbutton' src='../plus.png' onClick=showhide('ranges')> Ranges \n");
|
---|
207 |
|
---|
208 | printf(" <div id='all' style='display:block'>");
|
---|
209 | PrintDataSetInfoMenu($host, $user, $pw, $db);
|
---|
210 | printf(" <div id='info2' style='display:none'>");
|
---|
211 | printf(" <table><tr><td>\n");
|
---|
212 | PrintPullDown($host, $user, $pw, $db, "Source", "fSourceName", "fSourceKEY", "Source Name");
|
---|
213 | printf(" </td></tr>\n");
|
---|
214 | printf(" </table>\n");
|
---|
215 | printf("</div>");
|
---|
216 | printf(" <p>\n");
|
---|
217 | PrintFailMenu($host, $user, $pw, $db);
|
---|
218 | PrintDataSetStatMenu($host, $user, $pw, $db);
|
---|
219 |
|
---|
220 | printf(" <p>\n");
|
---|
221 | printf(" <div id='ranges' style='display:none'>");
|
---|
222 | PrintSourceMenu($host,$user,$pw,$db);
|
---|
223 | PrintDataSetRangeMenu($host,$user,$pw,$db);
|
---|
224 | printf("</div>");
|
---|
225 | printf("</div>");
|
---|
226 | printf(" <P>\n");
|
---|
227 |
|
---|
228 | PrintNumResPullDown();
|
---|
229 |
|
---|
230 | ini_set("mysql.trace_mode", "Off");
|
---|
231 | ini_set("display_errors", "Off");
|
---|
232 |
|
---|
233 | PrintButtons("datasetinfo-aio.php");
|
---|
234 |
|
---|
235 | printf("</form>\n");
|
---|
236 | printf("</center>\n");
|
---|
237 | printf("</td>\n");
|
---|
238 | printf("</tr>\n");
|
---|
239 | printf("<tr class='Block'>\n");
|
---|
240 | printf("<td>\n");
|
---|
241 | }
|
---|
242 |
|
---|
243 | function PrintPage($html, $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $needs)
|
---|
244 | {
|
---|
245 | $db_id = mysql_connect($host, $user, $pw);
|
---|
246 | if ($db_id==FALSE)
|
---|
247 | {
|
---|
248 | printf("mysql_connect returned the following error: %s\n", mysql_error());
|
---|
249 | die("");
|
---|
250 | }
|
---|
251 | mysql_select_db($db);
|
---|
252 |
|
---|
253 | $query0 = CreateQuery($_GET, $alias, $checkwhere, $checkgroup, $checkstatusgroup, $needs);
|
---|
254 |
|
---|
255 | $result0 = mysql_query($query0, $db_id);
|
---|
256 |
|
---|
257 | if ($result0)
|
---|
258 | {
|
---|
259 | if ($html=="1" || $html=="2")
|
---|
260 | PrintMagicTable($result0, $alias, $rightalign, "", "", "", "", $_GET);
|
---|
261 | else
|
---|
262 | PrintText($result0);
|
---|
263 |
|
---|
264 | mysql_free_result($result0);
|
---|
265 | }
|
---|
266 | mysql_close($db_id);
|
---|
267 |
|
---|
268 | PrintSubmittedQuery($query0, $html, $db, "");
|
---|
269 | }
|
---|
270 |
|
---|
271 | include ("include.php");
|
---|
272 | include ("db.php");
|
---|
273 | include ("menu.php");
|
---|
274 | include ("magicdefs.php");
|
---|
275 |
|
---|
276 | ini_set("display_errors", "On");
|
---|
277 | ini_set("mysql.trace_mode", "On");
|
---|
278 |
|
---|
279 | if (!empty($_GET["fSendTxt"]))
|
---|
280 | {
|
---|
281 | header("Content-type: application/octet");
|
---|
282 | header("Content-Disposition: attachment; filename=query-result.txt");
|
---|
283 |
|
---|
284 | PrintPage("0", $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup);
|
---|
285 | }
|
---|
286 | else
|
---|
287 | {
|
---|
288 | echo (file_get_contents("index-header.html"));
|
---|
289 |
|
---|
290 | $environment = sizeof($_GET);
|
---|
291 |
|
---|
292 | InitGet($_GET);
|
---|
293 | if (empty($_GET["fPrintTable"]))
|
---|
294 | PrintForm($_GET, $host, $user, $pw, $db);
|
---|
295 |
|
---|
296 | if ($environment==0)
|
---|
297 | printf("No query submitted yet.<BR>");
|
---|
298 | else
|
---|
299 | {
|
---|
300 | if (empty($_GET["fPrintTable"]))
|
---|
301 | PrintPage("1", $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $needs);
|
---|
302 | else
|
---|
303 | PrintPage("2", $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $needs);
|
---|
304 | }
|
---|
305 |
|
---|
306 | echo (file_get_contents("index-footer.html"));
|
---|
307 | }
|
---|
308 |
|
---|
309 | ini_set("display_errors", "Off");
|
---|
310 | ini_set("mysql.trace_mode", "Off");
|
---|
311 | }
|
---|
312 | ?>
|
---|