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 .= ", 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>' ";
|
---|
47 | $query0 .= ", ' <A&ws;HREF=\"tabs.php?t=ganymed&n=' , fDataSetNumber, '\">g</A>'";
|
---|
48 | $query0 .= ", ' <A&ws;HREF=\"tabs.php?t=gplotdb&n=' , fDataSetNumber, '\">pdb</A>'";
|
---|
49 | // $query0 .= ", ' <A&ws;HREF=\"ganymed.php?fDataSetNo=', DataSets.fDataSetNumber, '\">i</A>' ";
|
---|
50 | $query0 .= ") as 'Links'";
|
---|
51 | }
|
---|
52 |
|
---|
53 | foreach ($_GET as $key => $element)
|
---|
54 | if ($_GET[$key]=="On")
|
---|
55 | if ($key!="fLinks")
|
---|
56 | if (empty($checkwhere[$key]) || $checkwhere[$key]==0)
|
---|
57 | $query0 .= ", " . $key . " as '" . $alias[$key] . "' ";
|
---|
58 | }
|
---|
59 | }
|
---|
60 |
|
---|
61 | $query0 .= " FROM " . $fromtable;
|
---|
62 |
|
---|
63 | $query0 .= " LEFT JOIN DataSetProcessStatus USING(fDataSetNumber) ";
|
---|
64 | $query0 .= " LEFT JOIN Ganymed USING(fDataSetNumber) ";
|
---|
65 |
|
---|
66 | foreach ($_GET as $key => $element)
|
---|
67 | if (($_GET[$key]=="On" || $groups>0))// && !empty($joins[$key]))
|
---|
68 | $query0 .= GetJoin($fromtable,$key);
|
---|
69 |
|
---|
70 | foreach ($checkwhere as $key => $element)
|
---|
71 | {
|
---|
72 | if (empty($element) || $element<=0)
|
---|
73 | continue;
|
---|
74 |
|
---|
75 | if (strpos($query0, " WHERE ")==FALSE)
|
---|
76 | $query0 .= " WHERE ";
|
---|
77 | else
|
---|
78 | if ($element!=-1)
|
---|
79 | if (strrpos($query0, " AND ")!=strlen($query0)-5)
|
---|
80 | $query0 .= " AND ";
|
---|
81 |
|
---|
82 | if ($element!=-1)
|
---|
83 | $query0 .= GetCheck($fromtable, $key) . "=" . $element;
|
---|
84 | }
|
---|
85 |
|
---|
86 | if (strpos($query0, " WHERE ")==FALSE)
|
---|
87 | $query0 .= " WHERE ";
|
---|
88 | else
|
---|
89 | $query0 .= " AND ";
|
---|
90 |
|
---|
91 | $query0 .= StatusQuery("fDataSetInserted", $needs);
|
---|
92 | $query0 .= StatusQuery("fStarFilesAvail", $needs);
|
---|
93 | $query0 .= StatusQuery("fGanymed", $needs);
|
---|
94 | $query0 .= StatusQuery("fFillGanymed", $needs);
|
---|
95 |
|
---|
96 | if (!empty($_GET["fRunMin"]) && !empty($_GET["fRunMax"]))
|
---|
97 | $query0 .= "DataSets.fDataSetNumber BETWEEN " . $_GET["fRunMin"] . " AND " . $_GET["fRunMax"] . " ";
|
---|
98 |
|
---|
99 | /*
|
---|
100 | if (!empty($_GET["fDate"]))
|
---|
101 | $query0 .= " AND fRunStart REGEXP \"^" . $_GET["fDate"] . "\" ";
|
---|
102 | */
|
---|
103 |
|
---|
104 | if (!empty($_GET["fSourceN"]))
|
---|
105 | $query0 .= " AND fSourceName REGEXP \"^" . $_GET["fSourceN"] . "\" ";
|
---|
106 |
|
---|
107 | if ($groups>0)
|
---|
108 | {
|
---|
109 | $query0 .= " GROUP BY ";
|
---|
110 | $num = $groups;
|
---|
111 | foreach ($checkgroup as $key => $element)
|
---|
112 | if ($element==-1)
|
---|
113 | {
|
---|
114 | $query0 .= GetCheck($fromtable,$key);
|
---|
115 | if ($num-->1)
|
---|
116 | $query0 .= ", ";
|
---|
117 | }
|
---|
118 | }
|
---|
119 |
|
---|
120 | if ($statusgroups>0)
|
---|
121 | {
|
---|
122 | $query0 .= " GROUP BY ";
|
---|
123 | $num = $statusgroups;
|
---|
124 | foreach ($checkstatusgroup as $key => $element)
|
---|
125 | if ($element==-1)
|
---|
126 | {
|
---|
127 | $query0 .= $alias[$key];
|
---|
128 | if ($num-->1)
|
---|
129 | $query0 .= ", ";
|
---|
130 | }
|
---|
131 | }
|
---|
132 |
|
---|
133 | if (!empty($_GET["fSortBy"]))
|
---|
134 | {
|
---|
135 | $val=substr($_GET["fSortBy"], 0, -1);
|
---|
136 | $query0 .= " ORDER BY " . GetTable($fromtable, $val) . " ";
|
---|
137 | if (substr($_GET["fSortBy"], -1)=="-")
|
---|
138 | $query0 .= "DESC";
|
---|
139 | }
|
---|
140 |
|
---|
141 | if (empty($_GET["fSortBy"]) && $groups==0 && $statusgroups==0)
|
---|
142 | $query0 .= "ORDER BY DataSets.fDataSetNumber ASC ";
|
---|
143 |
|
---|
144 | if (empty($_GET["fNumStart"]))
|
---|
145 | $_GET["fNumStart"]=0;
|
---|
146 |
|
---|
147 | if (empty($_GET["fSendTxt"]))
|
---|
148 | $query0 .= " LIMIT " . $_GET["fNumStart"] . ", " . $_GET["fNumResults"];
|
---|
149 |
|
---|
150 | return $query0;
|
---|
151 | }
|
---|
152 |
|
---|
153 | function InitGet($_GET)
|
---|
154 | {
|
---|
155 | // Find out whether it is the first call to the php script
|
---|
156 | $first = empty($_GET["fRunMin"]) && empty($_GET["fRunMax"]);
|
---|
157 |
|
---|
158 | if (empty($_GET["fNumResults"]))
|
---|
159 | $_GET["fNumResults"]="50";
|
---|
160 |
|
---|
161 | InitDataSetInfo($_GET, $first);
|
---|
162 | }
|
---|
163 |
|
---|
164 | function PrintForm($_GET, $host, $user, $pw, $db)
|
---|
165 | {
|
---|
166 | printf("<center>\n");
|
---|
167 | printf("<form action=\"datasetinfo-aio.php\" METHOD=\"GET\">\n");
|
---|
168 |
|
---|
169 | printf("<input id='sh' type='hidden' name='fShowHide' value='");
|
---|
170 | if (!empty($_GET["fShowHide"]))
|
---|
171 | printf("%s", $_GET["fShowHide"]);
|
---|
172 | else
|
---|
173 | printf("1000000000");
|
---|
174 | printf("'>\n");
|
---|
175 | printf("<img id='allbutton' src='minus.png' alt='-' onclick=showhide('all')> <b>Menu</b> \n");
|
---|
176 | printf(" <img id='infobutton' src='plus.png' alt='+' onClick=showhide('info');showhide('info2')> DataSetInfo\n");
|
---|
177 | printf(" <img id='statbutton' src='plus.png' alt='+' onClick=showhide('stat');showhide('fail')> StatusInfo \n");
|
---|
178 | printf(" <img id='rangesbutton' src='plus.png' alt='+' onClick=showhide('ranges')> Ranges \n");
|
---|
179 |
|
---|
180 | printf(" <div id='all' style='display:block'>");
|
---|
181 | PrintDataSetInfoMenu($host, $user, $pw, $db);
|
---|
182 | PrintDataSetInfoMenu2($host, $user, $pw, $db);
|
---|
183 | printf(" <p>\n");
|
---|
184 | PrintFailMenu($host, $user, $pw, $db);
|
---|
185 | PrintDataSetStatMenu($host, $user, $pw, $db);
|
---|
186 |
|
---|
187 | printf(" <p>\n");
|
---|
188 | printf(" <div id='ranges' style='display:none'>");
|
---|
189 | PrintSourceMenu($host,$user,$pw,$db);
|
---|
190 | PrintDataSetRangeMenu($host,$user,$pw,$db);
|
---|
191 | printf("</div>");
|
---|
192 | printf("</div>");
|
---|
193 | printf(" <P>\n");
|
---|
194 |
|
---|
195 | PrintNumResPullDown();
|
---|
196 |
|
---|
197 | ini_set("mysql.trace_mode", "Off");
|
---|
198 | ini_set("display_errors", "Off");
|
---|
199 |
|
---|
200 | PrintButtons("datasetinfo-aio.php");
|
---|
201 |
|
---|
202 | printf("</form>\n");
|
---|
203 | printf("</center>\n");
|
---|
204 | printf("</td>\n");
|
---|
205 | printf("</tr>\n");
|
---|
206 | printf("<tr class='Block'>\n");
|
---|
207 | printf("<td>\n");
|
---|
208 | }
|
---|
209 |
|
---|
210 | function PrintPage($html, $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $needs)
|
---|
211 | {
|
---|
212 | $db_id = mysql_connect($host, $user, $pw);
|
---|
213 | if ($db_id==FALSE)
|
---|
214 | {
|
---|
215 | printf("mysql_connect returned the following error: %s\n", mysql_error());
|
---|
216 | die("");
|
---|
217 | }
|
---|
218 | mysql_select_db($db);
|
---|
219 |
|
---|
220 | $query0 = CreateQuery($_GET, $alias, $checkwhere, $checkgroup, $checkstatusgroup, $needs);
|
---|
221 |
|
---|
222 | $result0 = mysql_query($query0, $db_id);
|
---|
223 |
|
---|
224 | if ($result0)
|
---|
225 | {
|
---|
226 | if ($html=="1" || $html=="2")
|
---|
227 | PrintMagicTable($result0, $alias, $rightalign, "", "", "", "", $_GET);
|
---|
228 | else
|
---|
229 | PrintText($result0);
|
---|
230 |
|
---|
231 | mysql_free_result($result0);
|
---|
232 | }
|
---|
233 | mysql_close($db_id);
|
---|
234 |
|
---|
235 | PrintSubmittedQuery($query0, $html, $db, "");
|
---|
236 | }
|
---|
237 |
|
---|
238 | include ("include.php");
|
---|
239 | include ("db.php");
|
---|
240 | include ("menu.php");
|
---|
241 | include ("magicdefs.php");
|
---|
242 |
|
---|
243 | ini_set("display_errors", "On");
|
---|
244 | ini_set("mysql.trace_mode", "On");
|
---|
245 |
|
---|
246 | if (!empty($_GET["fSendTxt"]))
|
---|
247 | {
|
---|
248 | header("Content-type: application/octet");
|
---|
249 | header("Content-Disposition: attachment; filename=query-result.txt");
|
---|
250 |
|
---|
251 | PrintPage("0", $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup);
|
---|
252 | }
|
---|
253 | else
|
---|
254 | {
|
---|
255 | if (empty($_GET["fPrintTable"]))
|
---|
256 | echo (file_get_contents("index-header.html"));
|
---|
257 |
|
---|
258 | $environment = sizeof($_GET);
|
---|
259 |
|
---|
260 | InitGet($_GET);
|
---|
261 | if (empty($_GET["fPrintTable"]))
|
---|
262 | PrintForm($_GET, $host, $user, $pw, $db);
|
---|
263 |
|
---|
264 | if ($environment==0)
|
---|
265 | printf("No query submitted yet.<BR>");
|
---|
266 | else
|
---|
267 | {
|
---|
268 | if (empty($_GET["fPrintTable"]))
|
---|
269 | PrintPage("1", $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $needs);
|
---|
270 | else
|
---|
271 | PrintPage("2", $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $needs);
|
---|
272 | }
|
---|
273 |
|
---|
274 | if (empty($_GET["fPrintTable"]))
|
---|
275 | echo (file_get_contents("index-footer.html"));
|
---|
276 | }
|
---|
277 |
|
---|
278 | ini_set("display_errors", "Off");
|
---|
279 | ini_set("mysql.trace_mode", "Off");
|
---|
280 | }
|
---|
281 | ?>
|
---|