source: trunk/Mars/datacenter/db/statussbs.php@ 12778

Last change on this file since 12778 was 9548, checked in by Daniela Dorner, 15 years ago
*** empty log message ***
  • Property svn:executable set to *
File size: 8.2 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 SQL_CALC_FOUND_ROWS ";
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 '# days'";
20
21 }
22 else
23 {
24 if (!empty($_GET["fSendTxt"]))
25 $query0 .= " fDate ";
26 else
27 {
28 $query0 .= " CONCAT( fDate , ': <A&ws;HREF=\"index.php?', 'fRunStart=On', '&fZenithDistance=On', '&fMeanTriggerRate=On', '&fRunTypeName=On', '&fNumEvents=On', '&fSourceName=On&', 'fExcludedFDAKEY=1', '&fSequenceFirst=On', '&fStartDate=', fDate, '&fStopDate=', fDate, '&fNumResults=500\">Runs</A> ' , ";
29 $query0 .= " ' <A&ws;HREF=\"queryseq.php?', 'fRunStart=On', '&fZenithDistanceMin=On', '&fNumEvents=On', '&fSourceName=On&', '&fStartDate=', fDate, '&fStopDate=', fDate, '&fNumResults=500\">Sequ</A> ') ";
30 }
31 $query0 .= " as 'Date' ";
32
33 foreach ($_GET as $key => $element)
34 if ($_GET[$key]=="On")
35 if (empty($checkwhere[$key]) || $checkwhere[$key]==0)
36 $query0 .= ", " . $key . " as '" . $alias[$key] . "' ";
37 }
38
39 $query0 .= " FROM SequenceBuildStatus ";
40
41 if (strpos($query0, " WHERE ")==FALSE)
42 $query0 .= " WHERE ";
43 else
44 $query0 .= " AND ";
45
46 $query0 .= StatusQuery("fCCFilled", $needs, $timelimits);
47 $query0 .= StatusQuery("fExclusionsDone", $needs, $timelimits);
48 $query0 .= StatusQuery("fSequenceEntriesBuilt", $needs, $timelimits);
49
50 $query0 .= "fDate 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 SequenceBuildStatus.fDate 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["fCCFilled"]))
93 $_GET["fCCFilled"]=$first?"On":"";
94
95 if (empty($_GET["fExclusionsDone"]))
96 $_GET["fExclusionsDone"]=$first?"On":"";
97
98 if (empty($_GET["fSequenceEntriesBuilt"]))
99 $_GET["fSequenceEntriesBuilt"]=$first?"On":"";
100 }
101
102 function PrintForm($_GET, $host, $user, $pw, $db)
103 {
104 printf("<center>\n");
105 printf("<form action=\"statussbs.php\" METHOD=\"GET\">\n");
106 printf(" <table>\n");
107 printf(" <tr><td>\n");
108
109 PrintStatusMenu("fCCFilled", "CC Filled");
110
111 printf(" </td><td>\n");
112
113 PrintStatusMenu("fExclusionsDone", "Exclusions");
114
115 printf(" </td><td>\n");
116
117 PrintStatusMenu("fSequenceEntriesBuilt", "Sequences");
118
119 printf(" </td></tr></table>\n");
120 printf(" <p>\n");
121
122
123 if (empty($_GET["fRunMin"]))
124 $min = GetMin("fDate", "SequenceBuildStatus", $host, $user, $pw, $db);
125 else
126 $min = $_GET["fRunMin"];
127
128 if (empty($_GET["fRunMax"]))
129 $max = GetMax("fDate", "SequenceBuildStatus", $host, $user, $pw, $db);
130 else
131 $max = $_GET["fRunMax"];
132
133
134 printf("Date&nbsp;from&nbsp;<input name=\"fRunMin\" type=\"text\" size=\"10\" maxlength=\"10\" value=\"%s\">\n", $min);
135 printf("to&nbsp;<input name=\"fRunMax\" type=\"text\" size=\"10\" maxlength=\"10\" value=\"%s\">&nbsp;&nbsp;&nbsp;\n", $max);
136
137 printf(" <P>\n");
138
139 printf(" Results:\n");
140 printf(" <select name=\"fNumResults\">\n");
141
142 $numres = array("10", "20", "50", "100", "200", "500");
143 foreach ($numres as $element)
144 {
145 if ($element==$_GET["fNumResults"])
146 printf("<option value=\"%s\" selected>%3s</option>\n", $element, $element);
147 else
148 printf("<option value=\"%s\">%3s</option>\n", $element, $element);
149 }
150 printf(" </select>\n");
151 printf(" &nbsp;&nbsp;&nbsp;\n");
152
153 ini_set("mysql.trace_mode", "Off");
154 ini_set("display_errors", "Off");
155
156 printf("<input class='Width' type='submit' value='Query Table'>&nbsp;&nbsp;&nbsp;\n");
157 printf("<input class='Width' type='button' value='Reset' onClick='self.location.href=\"statussbs.php\"'>&nbsp;&nbsp;&nbsp;\n");
158 if (strchr($_SERVER["REQUEST_URI"], '?')!=FALSE)
159 printf("<input class='Width' type='button' value='Get .txt' onClick='self.location.href=\"%s&fSendTxt=1\"'>&nbsp;&nbsp;&nbsp;\n", $_SERVER["REQUEST_URI"]);
160 printf("</form>\n");
161 printf("</center>\n");
162 printf("</td>\n");
163 printf("</tr>\n");
164 printf("<tr class='Block'>\n");
165 printf("<td>\n");
166 }
167
168 function PrintPage($html, $host, $user, $pw, $db, $alias, $rightalign, $checkstatusgroup, $checkwhere, $needs)
169 {
170 $db_id = mysql_connect($host, $user, $pw);
171 if ($db_id==FALSE)
172 {
173 printf("mysql_connect returned the following error: %s\n", mysql_error());
174 die("");
175 }
176 mysql_select_db($db);
177
178 $query0 = CreateQuery($_GET, $alias, $checkstatusgroup, $checkwhere, $needs);
179
180 $result0 = mysql_query($query0, $db_id);
181 $result1 = mysql_query("SELECT FOUND_ROWS()", $db_id);
182
183 if ($result0)
184 {
185 if ($html=="1")
186 PrintMagicTable($result0, $alias, $rightalign, "", "", "", $result1);
187 else
188 PrintText($result0);
189
190 mysql_free_result($result0);
191 mysql_free_result($result1);
192 }
193 mysql_close($db_id);
194
195 if ($html=="1")
196 PrintSubmittedQuery($query0, $db, "old");
197 }
198
199 include ("include.php");
200 include ("db.php");
201 include ("magicdefs.php");
202
203 ini_set("display_errors", "On");
204 ini_set("mysql.trace_mode", "On");
205
206 if (!empty($_GET["fSendTxt"]))
207 {
208 header("Content-type: application/octet");
209 header("Content-Disposition: attachment; filename=query-result.txt");
210
211 PrintPage("0", $host, $user, $pw, $db, $alias, $rightalign, $checkstatusgroup, $checkwhere, $needs);
212 }
213 else
214 {
215 echo (file_get_contents("index-header.html"));
216
217 $environment = sizeof($_GET);
218
219 InitGet($_GET);
220 PrintForm($_GET, $host, $user, $pw, $db);
221
222 if ($environment==0)
223 printf("No query submitted yet.<BR>");
224 else
225 PrintPage("1", $host, $user, $pw, $db, $alias, $rightalign, $checkstatusgroup, $checkwhere, $needs);
226
227 echo (file_get_contents("index-footer.html"));
228 }
229
230 ini_set("display_errors", "Off");
231 ini_set("mysql.trace_mode", "Off");
232}
233?>
Note: See TracBrowser for help on using the repository browser.