source: trunk/MagicSoft/Mars/datacenter/db/datasetinfo-aio.php@ 9151

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