source: trunk/MagicSoft/Mars/datacenter/db/statussps.php@ 9464

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