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 '# 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 from <input name=\"fRunMin\" type=\"text\" size=\"10\" maxlength=\"10\" value=\"%s\">\n", $min);
|
---|
135 | printf("to <input name=\"fRunMax\" type=\"text\" size=\"10\" maxlength=\"10\" value=\"%s\"> \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(" \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'> \n");
|
---|
157 | printf("<input class='Width' type='button' value='Reset' onClick='self.location.href=\"statussbs.php\"'> \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\"'> \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 |
|
---|
182 | if ($result0)
|
---|
183 | {
|
---|
184 | if ($html=="1")
|
---|
185 | PrintMagicTable($result0, $alias, $rightalign, "", "", "", "", $_GET);
|
---|
186 | else
|
---|
187 | PrintText($result0);
|
---|
188 |
|
---|
189 | mysql_free_result($result0);
|
---|
190 | }
|
---|
191 | mysql_close($db_id);
|
---|
192 |
|
---|
193 | PrintSubmittedQuery($query0, $html, $db, "old");
|
---|
194 | }
|
---|
195 |
|
---|
196 | include ("include.php");
|
---|
197 | include ("db.php");
|
---|
198 | include ("magicdefs.php");
|
---|
199 |
|
---|
200 | ini_set("display_errors", "On");
|
---|
201 | ini_set("mysql.trace_mode", "On");
|
---|
202 |
|
---|
203 | if (!empty($_GET["fSendTxt"]))
|
---|
204 | {
|
---|
205 | header("Content-type: application/octet");
|
---|
206 | header("Content-Disposition: attachment; filename=query-result.txt");
|
---|
207 |
|
---|
208 | PrintPage("0", $host, $user, $pw, $db, $alias, $rightalign, $checkstatusgroup, $checkwhere, $needs);
|
---|
209 | }
|
---|
210 | else
|
---|
211 | {
|
---|
212 | echo (file_get_contents("index-header.html"));
|
---|
213 |
|
---|
214 | $environment = sizeof($_GET);
|
---|
215 |
|
---|
216 | InitGet($_GET);
|
---|
217 | PrintForm($_GET, $host, $user, $pw, $db);
|
---|
218 |
|
---|
219 | if ($environment==0)
|
---|
220 | printf("No query submitted yet.<BR>");
|
---|
221 | else
|
---|
222 | PrintPage("1", $host, $user, $pw, $db, $alias, $rightalign, $checkstatusgroup, $checkwhere, $needs);
|
---|
223 |
|
---|
224 | echo (file_get_contents("index-footer.html"));
|
---|
225 | }
|
---|
226 |
|
---|
227 | ini_set("display_errors", "Off");
|
---|
228 | ini_set("mysql.trace_mode", "Off");
|
---|
229 | }
|
---|
230 | ?>
|
---|