source: tags/Mars-V0.9.4.3/datacenter/db/statussps.php

Last change on this file was 7484, checked in by Daniela Dorner, 19 years ago
*** empty log message ***
  • Property svn:executable set to *
File size: 8.0 KB
Line 
1<?php
2{
3 function CreateQuery($_GET, $alias, $checkstatusgroup, $checkwhere)
4 {
5 $statusgroups = 0;
6 foreach ($checkstatusgroup as $element)
7 if ($element==-1)
8 $statusgroups++;
9
10 $query0 = "SELECT ";
11
12 if ($statusgroups>0)
13 {
14 foreach ($checkstatusgroup as $key => $element)
15 if ($element==-1)
16 $query0 .= " (if(IsNull(" . $key . "), 'not done' ,if(" . $key . "='1970-01-01 00:00:00','dont do','done'))) as '" . $alias[$key] . "', ";
17
18 $query0 .= " count(*) as 'Sequence#'";
19
20 }
21 else
22 {
23 if (!empty($_GET["fSendTxt"]))
24 $query0 .= " fSequenceFirst ";
25 else
26 $query0 .= " CONCAT('<A&ws;HREF=\"index.php?', 'fRunStart=On', '&fZenithDistance=On', '&fMeanTriggerRate=On', '&fRunTypeName=On', '&fNumEvents=On', '&fSourceName=On&', 'fExcludedFDAKEY=1', '&fSequenceFirst=On', '&fSequenceNo=', fSequenceFirst, '&fNumResults=500\">', fSequenceFirst, '</A>') ";
27 $query0 .= " as 'Sequence#' ";
28
29 foreach ($_GET as $key => $element)
30 if ($_GET[$key]=="On")
31 if (empty($checkwhere[$key]) || $checkwhere[$key]==0)
32 $query0 .= ", " . $key . " as '" . $alias[$key] . "' ";
33 }
34
35 $query0 .= " FROM SequenceProcessStatus ";
36
37 if (strpos($query0, " WHERE ")==FALSE)
38 $query0 .= " WHERE ";
39 else
40 $query0 .= " AND ";
41
42 $query0 .= StatusQuery("fSequenceFileWritten");
43 $query0 .= StatusQuery("fAllFilesAvail");
44 $query0 .= StatusQuery("fCallisto");
45 $query0 .= StatusQuery("fFillCallisto");
46 $query0 .= StatusQuery("fStar");
47 $query0 .= StatusQuery("fFillStar");
48
49 $query0 .= "fSequenceFirst BETWEEN " . $_GET["fRunMin"] . " AND " . $_GET["fRunMax"] . " ";
50
51 if ($statusgroups>0)
52 {
53 $query0 .= " GROUP BY ";
54 $num = $statusgroups;
55 foreach ($checkstatusgroup as $key => $element)
56 if ($element==-1)
57 {
58 $query0 .= $alias[$key];
59 if ($num-->1)
60 $query0 .= ", ";
61 }
62 }
63
64 if (!empty($_GET["fSortBy"]))
65 {
66 $query0 .= " ORDER BY " . substr($_GET["fSortBy"], 0, -1) . " ";
67 if (substr($_GET["fSortBy"], -1)=="-")
68 $query0 .= "DESC";
69 }
70
71 if (empty($_GET["fSortBy"]) && $statusgroups==0)
72 $query0 .= "ORDER BY fSequenceFirst ASC ";
73
74 if (empty($_GET["fNumStart"]))
75 $_GET["fNumStart"]=0;
76
77 if (empty($_GET["fSendTxt"]))
78 $query0 .= " LIMIT " . $_GET["fNumStart"] . ", " . $_GET["fNumResults"];
79
80 return $query0;
81 }
82
83 function InitGet($_GET)
84 {
85 // Find out whether it is the first call to the php script
86 $first = empty($_GET["fRunMin"]) && empty($_GET["fRunMax"]);
87
88 if (empty($_GET["fNumResults"]))
89 $_GET["fNumResults"]="20";
90
91 if (empty($_GET["fSequenceFileWritten"]))
92 $_GET["fSequenceFileWritten"]=$first?"On":"";
93
94 if (empty($_GET["fAllFilesAvail"]))
95 $_GET["fAllFilesAvail"]=$first?"On":"";
96
97 if (empty($_GET["fCallisto"]))
98 $_GET["fCallisto"]=$first?"On":"";
99
100 if (empty($_GET["fStar"]))
101 $_GET["fStar"]=$first?"On":"";
102
103 if (empty($_GET["fFillCallisto"]))
104 $_GET["fFillCallisto"]="Off";
105
106 if (empty($_GET["fFillStar"]))
107 $_GET["fFillStar"]="Off";
108
109 }
110
111 function PrintForm($_GET, $db)
112 {
113 printf("<center>\n");
114 printf("<form action=\"statussps.php\" METHOD=\"GET\">\n");
115 printf(" <table>\n");
116 printf(" <tr><td>\n");
117
118 PrintStatusMenu("fSequenceFileWritten", "Sequencefile written");
119 printf(" </td><td>\n");
120 PrintStatusMenu("fCallisto", "Callisto");
121 printf(" </td><td>\n");
122 PrintStatusMenu("fStar", "Star");
123
124 printf(" </td></tr><tr><td>\n");
125
126 PrintStatusMenu("fAllFilesAvail", "All files available");
127 printf(" </td><td>\n");
128 PrintStatusMenu("fFillCallisto", "Fillcallisto");
129 printf(" </td><td>\n");
130 PrintStatusMenu("fFillStar", "Fillstar");
131
132 printf("</td></tr> </table>\n");
133 printf(" <p>\n");
134
135 if (empty($_GET["fRunMin"]))
136 $min = GetMin("fSequenceFirst", "SequenceProcessStatus", $db);
137 else
138 $min = $_GET["fRunMin"];
139
140 if (empty($_GET["fRunMax"]))
141 $max = GetMax("fSequenceFirst", "SequenceProcessStatus", $db);
142 else
143 $max = $_GET["fRunMax"];
144
145
146 printf("Sequences&nbsp;from&nbsp;<input name=\"fRunMin\" type=\"text\" size=\"6\" maxlength=\"6\" value=\"%s\">\n", $min);
147 printf("to&nbsp;<input name=\"fRunMax\" type=\"text\" size=\"6\" maxlength=\"6\" value=\"%s\">&nbsp;&nbsp;&nbsp;\n", $max);
148
149 printf(" <P>\n");
150
151 printf(" Results:\n");
152 printf(" <select name=\"fNumResults\">\n");
153
154 $numres = array("10", "20", "50", "100", "200", "500");
155 foreach ($numres as $element)
156 {
157 if ($element==$_GET["fNumResults"])
158 printf("<option value=\"%s\" selected>%3s</option>\n", $element, $element);
159 else
160 printf("<option value=\"%s\">%3s</option>\n", $element, $element);
161 }
162 printf(" </select>\n");
163 printf(" &nbsp;&nbsp;&nbsp;\n");
164
165 ini_set("mysql.trace_mode", "Off");
166 ini_set("display_errors", "Off");
167
168 printf("<input class='Width' type='submit' value='Query Table'>&nbsp;&nbsp;&nbsp;\n");
169 printf("<input class='Width' type='button' value='Reset' onClick='self.location.href=\"statussps.php\"'>&nbsp;&nbsp;&nbsp;\n");
170 if (strchr($_SERVER["REQUEST_URI"], '?')!=FALSE)
171 printf("<input class='Width' type='button' value='Get .txt' onClick='self.location.href=\"%s&fSendTxt=1\"'>&nbsp;&nbsp;&nbsp;\n", $_SERVER["REQUEST_URI"]);
172 printf("</form>\n");
173 printf("</center>\n");
174 printf("</td>\n");
175 printf("</tr>\n");
176 printf("<tr class='Block'>\n");
177 printf("<td>\n");
178 }
179
180 function PrintPage($html, $db, $alias, $rightalign, $checkstatusgroup, $checkwhere)
181 {
182 $db_id = mysql_connect("hercules.astro.uni-wuerzburg.de", "MAGIC", "d99swMT!");
183 if ($db_id==FALSE)
184 {
185 printf("mysql_connect returned the following error: %s\n", mysql_error());
186 die("");
187 }
188 mysql_select_db($db);
189
190 $query0 = CreateQuery($_GET, $alias, $checkstatusgroup, $checkwhere);
191
192 $result0 = mysql_query($query0, $db_id);
193
194 if ($result0)
195 {
196 if ($html=="1")
197 PrintMagicTable($result0, $alias, $rightalign, "", "", $_GET);
198 else
199 PrintText($result0);
200
201 mysql_free_result($result0);
202 }
203 mysql_close($db_id);
204
205 if ($html=="1")
206 printf("<U><B>submitted query:</B></U><BR>%s<BR>", htmlspecialchars($query0));
207 }
208
209 include ("include.php");
210 include ("db.php");
211 include ("magicdefs.php");
212
213 ini_set("display_errors", "On");
214 ini_set("mysql.trace_mode", "On");
215
216 if (!empty($_GET["fSendTxt"]))
217 {
218 header("Content-type: application/octet");
219 header("Content-Disposition: attachment; filename=query-result.txt");
220
221 PrintPage("0", $db, $alias, $rightalign, $checkstatusgroup, $checkwhere);
222 }
223 else
224 {
225 echo (file_get_contents("index-header.html"));
226
227 $environment = sizeof($_GET);
228
229 InitGet($_GET);
230 PrintForm($_GET, $db);
231
232 if ($environment==0)
233 printf("No query submitted yet.<BR>");
234 else
235 PrintPage("1", $db, $alias, $rightalign, $checkstatusgroup, $checkwhere);
236
237 echo (file_get_contents("index-footer.html"));
238 }
239
240 ini_set("display_errors", "Off");
241 ini_set("mysql.trace_mode", "Off");
242}
243?>
Note: See TracBrowser for help on using the repository browser.