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

Last change on this file since 9106 was 9106, checked in by Daniela Dorner, 16 years ago
*** empty log message ***
  • Property svn:executable set to *
File size: 9.9 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 .= " 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 USING(fDataSetNumber) ";
60 $query0 .= " LEFT JOIN Ganymed USING(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 InitDataSetInfo($_GET, $first);
158 }
159
160 function PrintForm($_GET, $host, $user, $pw, $db)
161 {
162 printf("<center>\n");
163 printf("<form action=\"datasetinfo-aio.php\" METHOD=\"GET\">\n");
164
165 printf("<input id='sh' type='hidden' name='fShowHide' value='");
166 if (!empty($_GET["fShowHide"]))
167 printf("%s", $_GET["fShowHide"]);
168 else
169 printf("1000000000");
170 printf("'>\n");
171 printf("<img id='allbutton' src='minus.png' alt='-' onclick=showhide('all')> <b>Menu</b>&nbsp;&nbsp;&nbsp;&nbsp;\n");
172 printf("&nbsp;&nbsp;<img id='infobutton' src='plus.png' alt='+' onClick=showhide('info');showhide('info2')> DataSetInfo\n");
173 printf("&nbsp;&nbsp;<img id='statbutton' src='plus.png' alt='+' onClick=showhide('stat');showhide('fail')> StatusInfo \n");
174 printf("&nbsp;&nbsp;<img id='rangesbutton' src='plus.png' alt='+' onClick=showhide('ranges')> Ranges \n");
175
176 printf(" <div id='all' style='display:block'>");
177 PrintDataSetInfoMenu($host, $user, $pw, $db);
178 PrintDataSetInfoMenu2($host, $user, $pw, $db);
179 printf(" <p>\n");
180 PrintFailMenu($host, $user, $pw, $db);
181 PrintDataSetStatMenu($host, $user, $pw, $db);
182
183 printf(" <p>\n");
184 printf(" <div id='ranges' style='display:none'>");
185 PrintSourceMenu($host,$user,$pw,$db);
186 PrintDataSetRangeMenu($host,$user,$pw,$db);
187 printf("</div>");
188 printf("</div>");
189 printf(" <P>\n");
190
191 PrintNumResPullDown();
192
193 ini_set("mysql.trace_mode", "Off");
194 ini_set("display_errors", "Off");
195
196 PrintButtons("datasetinfo-aio.php");
197
198 printf("</form>\n");
199 printf("</center>\n");
200 printf("</td>\n");
201 printf("</tr>\n");
202 printf("<tr class='Block'>\n");
203 printf("<td>\n");
204 }
205
206 function PrintPage($html, $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $needs)
207 {
208 $db_id = mysql_connect($host, $user, $pw);
209 if ($db_id==FALSE)
210 {
211 printf("mysql_connect returned the following error: %s\n", mysql_error());
212 die("");
213 }
214 mysql_select_db($db);
215
216 $query0 = CreateQuery($_GET, $alias, $checkwhere, $checkgroup, $checkstatusgroup, $needs);
217
218 $result0 = mysql_query($query0, $db_id);
219
220 if ($result0)
221 {
222 if ($html=="1" || $html=="2")
223 PrintMagicTable($result0, $alias, $rightalign, "", "", "", "", $_GET);
224 else
225 PrintText($result0);
226
227 mysql_free_result($result0);
228 }
229 mysql_close($db_id);
230
231 PrintSubmittedQuery($query0, $html, $db, "");
232 }
233
234 include ("include.php");
235 include ("db.php");
236 include ("menu.php");
237 include ("magicdefs.php");
238
239 ini_set("display_errors", "On");
240 ini_set("mysql.trace_mode", "On");
241
242 if (!empty($_GET["fSendTxt"]))
243 {
244 header("Content-type: application/octet");
245 header("Content-Disposition: attachment; filename=query-result.txt");
246
247 PrintPage("0", $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup);
248 }
249 else
250 {
251 if (empty($_GET["fPrintTable"]))
252 echo (file_get_contents("index-header.html"));
253
254 $environment = sizeof($_GET);
255
256 InitGet($_GET);
257 if (empty($_GET["fPrintTable"]))
258 PrintForm($_GET, $host, $user, $pw, $db);
259
260 if ($environment==0)
261 printf("No query submitted yet.<BR>");
262 else
263 {
264 if (empty($_GET["fPrintTable"]))
265 PrintPage("1", $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $needs);
266 else
267 PrintPage("2", $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $needs);
268 }
269
270 if (empty($_GET["fPrintTable"]))
271 echo (file_get_contents("index-footer.html"));
272 }
273
274 ini_set("display_errors", "Off");
275 ini_set("mysql.trace_mode", "Off");
276}
277?>
Note: See TracBrowser for help on using the repository browser.