source: trunk/Mars/datacenter/db/opticaldata.php@ 12582

Last change on this file since 12582 was 9548, checked in by Daniela Dorner, 15 years ago
*** empty log message ***
  • Property svn:executable set to *
File size: 10.7 KB
Line 
1<?php
2{
3 function CreateQuery($_GET, $alias, $checkwhere, $checkgroup, $checkstatusgroup)
4 {
5 $fromtable="OpticalData";
6
7 $groups = 0;
8 foreach ($checkgroup as $element)
9 if ($element==-1)
10 $groups++;
11
12 $query0 = "SELECT SQL_CALC_FOUND_ROWS ";
13
14 if ($groups>0)
15 {
16 foreach ($checkgroup as $key => $element)
17 if ($element==-1)
18 $query0 .= $key . " as '" . $alias[$key] . "' " . ", ";
19 $query0 .= " COUNT(*) as '# Runs' ";
20 }
21 else
22 {
23 $query0 .= " fTimeStamp as 'Time' ";
24
25 foreach ($_GET as $key => $element)
26 if ($_GET[$key]=="On")
27 if (empty($checkwhere[$key]) || $checkwhere[$key]==0)
28 $query0 .= ", " . $key . " as '" . $alias[$key] . "' ";
29 }
30
31 $query0 .= " FROM " . $fromtable;
32
33 foreach ($_GET as $key => $element)
34 if (($_GET[$key]=="On" || $groups>0))// && !empty($joins[$key]))
35 $query0 .= GetJoin($fromtable, $key);
36
37 foreach ($checkwhere as $key => $element)
38 {
39 if (empty($element) || $element<=0)
40 continue;
41
42 if (strpos($query0, " WHERE ")==FALSE)
43 $query0 .= " WHERE ";
44 else
45 if ($element!=-1)
46 if (strrpos($query0, " AND ")!=strlen($query0)-5)// this if clause doesn't work
47 $query0 .= " AND ";
48
49 if ($element!=-1)
50 $query0 .= GetCheck($fromtable, $key) . "=" . $element;
51 }
52
53 if (strpos($query0, " WHERE ")==FALSE)
54 $query0 .= " WHERE ";
55 else
56 $query0 .= " AND ";
57
58 if (!empty($_GET["fStartDate"]))
59 {
60 $startdate=substr($_GET["fStartDate"], 0, 10);
61 if ($startdate=="0000-00-00")
62 $query0 .=" fTimestamp >= '" . $startdate . " 00:00:00' ";
63 else
64 $query0 .= " fTimestamp >= ADDDATE('" . $startdate . " 13:00:00', INTERVAL -1 DAY) ";
65 }
66
67 if (!empty($_GET["fStopDate"]))
68 {
69// if (strpos(strrev($query0), " DNA ")!=0)
70// $query0 .= " AND ";
71
72 $stopdate=substr($_GET["fStopDate"], 0, 10);
73 $query0 .= " AND fTimestamp < '" . $stopdate . " 13:00:00' ";
74 }
75
76 if ($groups>0)
77 {
78 $query0 .= " GROUP BY ";
79 $num = $groups;
80 foreach ($checkgroup as $key => $element)
81 if ($element==-1)
82 {
83 $query0 .= GetCheck($fromtable, $key);
84 if ($num-->1)
85 $query0 .= ", ";
86 }
87 }
88
89 if (!empty($_GET["fSortBy"]))
90 {
91 $query0 .= " ORDER BY " . substr($_GET["fSortBy"], 0, -1) . " ";
92 if (substr($_GET["fSortBy"], -1)=="-")
93 $query0 .= "DESC";
94 }
95
96 if (empty($_GET["fNumStart"]))
97 $_GET["fNumStart"]=0;
98
99 if (empty($_GET["fSendTxt"]))
100 $query0 .= " LIMIT " . $_GET["fNumStart"] . ", " . $_GET["fNumResults"];
101
102 return $query0;
103 }
104
105 function InitGet($_GET)
106 {
107 // Find out whether it is the first call to the php script
108 $first = empty($_GET["fRunMin"]) && empty($_GET["fRunMax"]);
109
110 if (empty($_GET["fNumResults"]))
111 $_GET["fNumResults"]="20";
112
113 if (empty($_GET["fTimestamp"]))
114 $_GET["fTimestamp"]=$first?"On":"";
115
116 if (empty($_GET["fExposure"]))
117 $_GET["fExposure"]=$first?"On":"";
118
119 if (empty($_GET["fSkyLevel"]))
120 $_GET["fSkyLevel"]=$first?"On":"";
121
122 if (empty($_GET["fFWHM"]))
123 $_GET["fFWHM"]=$first?"On":"";
124
125 if (empty($_GET["fApertureRadius"]))
126 $_GET["fApertureRadius"]=$first?"On":"";
127
128 if (empty($_GET["fInstrumentalMag"]))
129 $_GET["fInstrumentalMag"]=$first?"On":"";
130
131 if (empty($_GET["fInstrumentalMagErr"]))
132 $_GET["fInstrumentalMagErr"]=$first?"On":"";
133
134 if (empty($_GET["fFitsFileName"]))
135 $_GET["fFitsFileName"]="Off";
136
137 if (empty($_GET["fObjectName"]))
138 $_GET["fObjectName"]=$first?"On":"";
139
140 if (empty($_GET["fStatusName"]))
141 $_GET["fStatusName"]="Off";
142
143 if (empty($_GET["fBandName"]))
144 $_GET["fBandName"]=$first?"On":"";
145
146 if (empty($_GET["fTelescopeName"]))
147 $_GET["fTelescopeName"]=$first?"On":"";
148
149// if (empty($_GET["fRunStop"]))
150// $_GET["fRunStop"]="Off";
151
152 }
153
154 function PrintForm($_GET, $host, $user, $pw, $db)
155 {
156 printf("<center>\n");
157 printf("<form action=\"opticaldata.php\" METHOD=\"GET\">\n");
158 printf(" <table>\n");
159 printf(" <tr>\n");
160
161 CheckBox("fTimestamp", "Time");
162 CheckBox("fExposure", "Exposure");
163 CheckBox("fSkyLevel", "Skylevel");
164 CheckBox("fFWHM", "FWHM");
165
166 printf(" </tr><tr>\n");
167
168 CheckBox("fApertureRadius", "Aperture radius");
169 CheckBox("fInstrumentalMag", "instrumental magnitude");
170 CheckBox("fInstrumentalMagErr", "instrum. mag. error");
171
172 printf(" </tr>\n");
173 printf(" </table>\n");
174 printf(" <p>\n");
175
176 // pull down boxes
177
178 printf(" <table>\n");
179 printf(" <tr><td>\n");
180 PrintPullDown($host, $user, $pw, $db, "Telescope", "fTelescopeName", "fTelescopeKEY", "Telescope");
181 printf(" </td><td>\n");
182 PrintPullDown($host, $user, $pw, $db, "Object", "fObjectName", "fObjectKEY", "Object Name");
183 printf(" </td><td>\n");
184 PrintPullDown($host, $user, $pw, $db, "Band", "fBandName", "fBandKEY", "Band");
185 printf(" </td></tr><tr><td>\n");
186 PrintPullDown($host, $user, $pw, $db, "FitsFile", "fFitsFileName", "fFitsFileKEY", "Fits File");
187 printf(" </td><td>\n");
188 PrintPullDown($host, $user, $pw, $db, "Status", "fStatusName", "fStatusKEY", "Status Code");
189 printf(" </td></tr></table>\n");
190 printf(" <p>\n");
191
192 if (empty($_GET["fStartDate"]))
193 $timemin = GetMin("fTimestamp", "OpticalData", $host, $user, $pw, $db);
194 else
195 $timemin = $_GET["fStartDate"];
196
197 if (empty($_GET["fStopDate"]))
198 $timemax = GetMax("fTimestamp", "OpticalData", $host, $user, $pw, $db);
199 else
200 $timemax = $_GET["fStopDate"];
201
202 printf("Night&nbsp;(yyyy-mm-dd)&nbsp;from&nbsp;<input name=\"fStartDate\" type=\"text\" size=\"10\" maxlength=\"10\" value=\"%s\">\n", $timemin);
203 printf("to&nbsp;<input name=\"fStopDate\" type=\"text\" size=\"10\" maxlength=\"10\" value=\"%s\">&nbsp;&nbsp;&nbsp;&nbsp;\n", $timemax);
204
205 printf(" Results:\n");
206 printf(" <select name=\"fNumResults\">\n");
207
208 $numres = array("10", "20", "50", "100", "200", "500", "1000", "2000");
209 foreach ($numres as $element)
210 {
211 if ($element==$_GET["fNumResults"])
212 printf("<option value=\"%s\" selected>%3s</option>\n", $element, $element);
213 else
214 printf("<option value=\"%s\">%3s</option>\n", $element, $element);
215 }
216 printf(" </select>\n");
217 printf(" &nbsp;&nbsp;&nbsp;\n");
218
219 ini_set("mysql.trace_mode", "Off");
220 ini_set("display_errors", "Off");
221
222 printf("<input class='Width' type='submit' value='Query Table'>&nbsp;&nbsp;&nbsp;\n");
223 printf("<input class='Width' type='button' value='Reset' onClick='self.location.href=\"opticaldata.php\"'>&nbsp;&nbsp;&nbsp;\n");
224 if (strchr($_SERVER["REQUEST_URI"], '?')!=FALSE)
225 printf("<input class='Width' type='button' value='Get .txt' onClick='self.location.href=\"%s&fSendTxt=1\"'>&nbsp;&nbsp;&nbsp;\n", $_SERVER["REQUEST_URI"]);
226 printf("</form>\n");
227 printf("</center>\n");
228 printf("</td>\n");
229 printf("</tr>\n");
230 printf("<tr class='Block'>\n");
231 printf("<td>\n");
232 }
233
234 function PrintPage($html, $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup)
235 {
236 $db_id = mysql_connect($host, $user, $pw);
237 if ($db_id==FALSE)
238 {
239 printf("mysql_connect returned the following error: %s\n", mysql_error());
240 die("");
241 }
242 mysql_select_db($db);
243 mysql_query("SET BIG_TABLES=1"); // necessary for mySQL <= 4
244
245
246 $query0 = CreateQuery($_GET, $alias, $checkwhere, $checkgroup, $checkstatusgroup);
247
248 $result0 = mysql_query($query0, $db_id);
249 $result1 = mysql_query("SELECT FOUND_ROWS()", $db_id);
250
251 if ($result0)
252 {
253 if ($html=="1")
254 PrintMagicTable($result0, $alias, $rightalign, "", "", "", $result1);
255 else
256 PrintText($result0);
257
258 mysql_free_result($result0);
259 mysql_free_result($result1);
260 }
261 mysql_close($db_id);
262
263 if ($html=="1")
264 PrintSubmittedQuery($query0, $db, "old");
265 }
266
267 include ("include.php");
268 include ("db.php");
269 include ("magicdefs.php");
270
271 ini_set("display_errors", "On");
272 ini_set("mysql.trace_mode", "On");
273
274 $sitepw="\$1\$jfBkkHx1\$WmxNVaOWPCBC8asfKDfBZ/";
275 $siteuser="optical";
276
277 if (!isset($_SERVER['PHP_AUTH_USER']) || $_SERVER['PHP_AUTH_USER']!=$siteuser)
278 {
279 header('WWW-Authenticate: Basic realm="Optical Data - Tuorla Observatory"');
280 header('HTTP/1.0 401 Unauthorized');
281 echo 'Action cancelled.';
282 return;
283 }
284 else
285 {
286// echo "<p>Hello {$_SERVER['PHP_AUTH_USER']}.</p>";
287// echo "<p>You entered {$_SERVER['PHP_AUTH_PW']} as your password.</p>";
288// printf("pw: %s", crypt($_SERVER['PHP_AUTH_PW']));
289 if (crypt($_SERVER['PHP_AUTH_PW'], $sitepw)!=$sitepw || $_SERVER['PHP_AUTH_USER']!=$siteuser)
290 {
291 printf("<br>pw or user incorrect<br>");
292 return;
293 }
294 }
295
296 if (!empty($_GET["fSendTxt"]))
297 {
298 header("Content-type: application/octet");
299 header("Content-Disposition: attachment; filename=query-result.txt");
300
301 PrintPage("0", $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup);
302 }
303 else
304 {
305 echo (file_get_contents("index-header.html"));
306
307 $environment = sizeof($_GET);
308
309 InitGet($_GET);
310 PrintForm($_GET, $host, $user, $pw, $db);
311
312 if ($environment==0)
313 printf("No query submitted yet.<BR>");
314 else
315 PrintPage("1", $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup);
316
317 echo (file_get_contents("index-footer.html"));
318 }
319
320 ini_set("display_errors", "Off");
321 ini_set("mysql.trace_mode", "Off");
322}
323?>
Note: See TracBrowser for help on using the repository browser.