source: branches/removing_cpp11_features/datacenter/db/datasetinfo-aio.php@ 18656

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