source: tags/Mars-V0.9.4.3/datacenter/db/statussbs.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: 7.5 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 '#days'";
19
20 }
21 else
22 {
23 if (!empty($_GET["fSendTxt"]))
24 $query0 .= " fDate ";
25 else
26 {
27 $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> ' , ";
28 $query0 .= " ' <A&ws;HREF=\"queryseq.php?', 'fRunStart=On', '&fZenithDistanceMin=On', '&fNumEvents=On', '&fSourceName=On&', 'fExcludedFDAKEY=1', '&fStartDate=', fDate, '&fStopDate=', fDate, '&fNumResults=500\">Sequ</A> ') ";
29 }
30 $query0 .= " as 'Date' ";
31
32 foreach ($_GET as $key => $element)
33 if ($_GET[$key]=="On")
34 if (empty($checkwhere[$key]) || $checkwhere[$key]==0)
35 $query0 .= ", " . $key . " as '" . $alias[$key] . "' ";
36 }
37
38 $query0 .= " FROM SequenceBuildStatus ";
39
40 if (strpos($query0, " WHERE ")==FALSE)
41 $query0 .= " WHERE ";
42 else
43 $query0 .= " AND ";
44
45 $query0 .= StatusQuery("fCCFilled");
46 $query0 .= StatusQuery("fExclusionsDone");
47 $query0 .= StatusQuery("fSequenceEntriesBuilt");
48
49 $query0 .= "fDate 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 SequenceBuildStatus.fDate 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["fCCFilled"]))
92 $_GET["fCCFilled"]=$first?"On":"";
93
94 if (empty($_GET["fExclusionsDone"]))
95 $_GET["fExclusionsDone"]=$first?"On":"";
96
97 if (empty($_GET["fSequenceEntriesBuilt"]))
98 $_GET["fSequenceEntriesBuilt"]=$first?"On":"";
99 }
100
101 function PrintForm($_GET, $db)
102 {
103 printf("<center>\n");
104 printf("<form action=\"statussbs.php\" METHOD=\"GET\">\n");
105 printf(" <table>\n");
106 printf(" <tr><td>\n");
107
108 PrintStatusMenu("fCCFilled", "CC Filled");
109
110 printf(" </td><td>\n");
111
112 PrintStatusMenu("fExclusionsDone", "Exclusions");
113
114 printf(" </td><td>\n");
115
116 PrintStatusMenu("fSequenceEntriesBuilt", "Sequences");
117
118 printf(" </td></tr></table>\n");
119 printf(" <p>\n");
120
121
122 if (empty($_GET["fRunMin"]))
123 $min = GetMin("fDate", "SequenceBuildStatus", $db);
124 else
125 $min = $_GET["fRunMin"];
126
127 if (empty($_GET["fRunMax"]))
128 $max = GetMax("fDate", "SequenceBuildStatus", $db);
129 else
130 $max = $_GET["fRunMax"];
131
132
133 printf("Date&nbsp;from&nbsp;<input name=\"fRunMin\" type=\"text\" size=\"10\" maxlength=\"10\" value=\"%s\">\n", $min);
134 printf("to&nbsp;<input name=\"fRunMax\" type=\"text\" size=\"10\" maxlength=\"10\" value=\"%s\">&nbsp;&nbsp;&nbsp;\n", $max);
135
136 printf(" <P>\n");
137
138 printf(" Results:\n");
139 printf(" <select name=\"fNumResults\">\n");
140
141 $numres = array("10", "20", "50", "100", "200", "500");
142 foreach ($numres as $element)
143 {
144 if ($element==$_GET["fNumResults"])
145 printf("<option value=\"%s\" selected>%3s</option>\n", $element, $element);
146 else
147 printf("<option value=\"%s\">%3s</option>\n", $element, $element);
148 }
149 printf(" </select>\n");
150 printf(" &nbsp;&nbsp;&nbsp;\n");
151
152 ini_set("mysql.trace_mode", "Off");
153 ini_set("display_errors", "Off");
154
155 printf("<input class='Width' type='submit' value='Query Table'>&nbsp;&nbsp;&nbsp;\n");
156 printf("<input class='Width' type='button' value='Reset' onClick='self.location.href=\"statussbs.php\"'>&nbsp;&nbsp;&nbsp;\n");
157 if (strchr($_SERVER["REQUEST_URI"], '?')!=FALSE)
158 printf("<input class='Width' type='button' value='Get .txt' onClick='self.location.href=\"%s&fSendTxt=1\"'>&nbsp;&nbsp;&nbsp;\n", $_SERVER["REQUEST_URI"]);
159 printf("</form>\n");
160 printf("</center>\n");
161 printf("</td>\n");
162 printf("</tr>\n");
163 printf("<tr class='Block'>\n");
164 printf("<td>\n");
165 }
166
167 function PrintPage($html, $db, $alias, $rightalign, $checkstatusgroup, $checkwhere)
168 {
169 $db_id = mysql_connect("hercules.astro.uni-wuerzburg.de", "MAGIC", "d99swMT!");
170 if ($db_id==FALSE)
171 {
172 printf("mysql_connect returned the following error: %s\n", mysql_error());
173 die("");
174 }
175 mysql_select_db($db);
176
177 $query0 = CreateQuery($_GET, $alias, $checkstatusgroup, $checkwhere);
178
179 $result0 = mysql_query($query0, $db_id);
180
181 if ($result0)
182 {
183 if ($html=="1")
184 PrintMagicTable($result0, $alias, $rightalign, "", "", $_GET);
185 else
186 PrintText($result0);
187
188 mysql_free_result($result0);
189 }
190 mysql_close($db_id);
191
192 if ($html=="1")
193 printf("<U><B>submitted query:</B></U><BR>%s<BR>", htmlspecialchars($query0));
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", $db, $alias, $rightalign, $checkstatusgroup, $checkwhere);
209 }
210 else
211 {
212 echo (file_get_contents("index-header.html"));
213
214 $environment = sizeof($_GET);
215
216 InitGet($_GET);
217 PrintForm($_GET, $db);
218
219 if ($environment==0)
220 printf("No query submitted yet.<BR>");
221 else
222 PrintPage("1", $db, $alias, $rightalign, $checkstatusgroup, $checkwhere);
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?>
Note: See TracBrowser for help on using the repository browser.