source: branches/Mars_McMismatchStudy/datacenter/db/sources.php@ 20029

Last change on this file since 20029 was 17386, checked in by tbretz, 11 years ago
Removed svn:executable property, these are no executables.
File size: 5.0 KB
Line 
1<?php
2{
3 function CreateQuery($_GET, $alias)
4 {
5
6 $query0 = "SELECT SQL_CALC_FOUND_ROWS ";
7 if ($_GET["fLinks"]=="Off" || !empty($_GET["fSendTxt"]))
8 $query0 .= " fSourceName as 'Source' ";
9 else
10 {
11 $query0 .= " CONCAT('<A&ws;HREF=\"sequinfo-aio.php?', ";
12 $query0 .= " 'fRunStart=On', '&fZenithDistanceMin=On', '&fNumEvents=On', '&fRunTime%2F60=On', '&fSequenceLast=On', ";
13 $query0 .= " '&fSequenceFileWrittenStatus=0', '&fAllFilesAvailStatus=0', '&fCallistoStatus=0', '&fStar=On', '&fStarStatus=0', '&fFillCallistoStatus=0', '&fFillStarStatus=0', ";
14 $query0 .= " '&fSourceName=On', '&fSourceKEY=', fSourceKEY, "; //'&fRunMin=0', '&fRunMax=1000000', ";
15 $query0 .= " '&fNumResults=500\">', fSourcename, '</A>') ";
16 $query0 .= " as 'Source' ";
17 }
18 $query0 .= " , fSourceKEY as 'KEY', fTest as 'Test' ";
19 $query0 .= " FROM Source ";
20
21 if ($_GET["fTest"]=="Off")
22 $query0 .= " WHERE fTest='no'";
23
24 if ($_GET["fOff"]=="Off")
25 {
26 if (strpos($query0, " WHERE ")==FALSE)
27 $query0 .= " WHERE ";
28 else
29 $query0 .= " AND ";
30
31 $query0 .= " NOT (fSourceName like '%Off%')";
32 }
33
34 if (!empty($_GET["fSourceN"]))
35 {
36 if (strpos($query0, " WHERE ")==FALSE)
37 $query0 .= " WHERE ";
38 else
39 $query0 .= " AND ";
40
41 $query0 .= " fSourceName REGEXP \"^" . $_GET["fSourceN"] . "\" ";
42 }
43
44
45 if (!empty($_GET["fSortBy"]))
46 {
47 $query0 .= " ORDER BY " . substr($_GET["fSortBy"], 0, -1) . " ";
48 if (substr($_GET["fSortBy"], -1)=="-")
49 $query0 .= "DESC";
50 }
51 else
52 $query0 .= " ORDER BY fSourceKEY ";
53
54 return $query0;
55 }
56
57 function InitGet($_GET)
58 {
59
60 if (empty($_GET["fOff"]))
61 $_GET["fOff"]="Off";
62
63 if (empty($_GET["fTest"]))
64 $_GET["fTest"]="Off";
65
66 if (empty($_GET["fLinks"]))
67 $_GET["fLinks"]="On";
68
69 }
70
71 function PrintForm($_GET,$host,$user,$pw,$db)
72 {
73 printf("<center>\n");
74 printf("<form action=\"sources.php\" METHOD=\"GET\">\n");
75 printf(" <p><table>\n");
76 printf(" <tr>\n");
77
78 CheckBox("fOff", "incl. offsources");
79 CheckBox("fTest", "incl. test-sources");
80 CheckBox("fLinks", "links");
81
82 printf(" </table></p>\n");
83 printf("<p>");
84 PrintSourceMenu($host,$user,$pw,$db);
85
86 ini_set("mysql.trace_mode", "Off");
87 ini_set("display_errors", "Off");
88
89 printf("<input class='Width' type='submit' value='Query Table'>&nbsp;&nbsp;&nbsp;\n");
90 printf("<input class='Width' type='button' value='Reset' onClick='self.location.href=\"sources.php\"'>&nbsp;&nbsp;&nbsp;\n");
91 if (strchr($_SERVER["REQUEST_URI"], '?')!=FALSE)
92 printf("<input class='Width' type='button' value='Get .txt' onClick='self.location.href=\"%s&fSendTxt=1\"'>&nbsp;&nbsp;&nbsp;\n", $_SERVER["REQUEST_URI"]);
93 printf("</form>\n");
94 printf("</center>\n");
95 printf("</td>\n");
96 printf("</tr>\n");
97 printf("<tr class='Block'>\n");
98 printf("<td>\n");
99 }
100
101 function PrintPage($html, $host, $user, $pw, $db, $alias, $rightalign)
102 {
103 $db_id = mysql_connect($host, $user, $pw);
104 if ($db_id==FALSE)
105 {
106 printf("mysql_connect returned the following error: %s\n", mysql_error());
107 die("");
108 }
109 mysql_select_db($db);
110
111 $query0 = CreateQuery($_GET, $alias);
112
113 $result0 = mysql_query($query0, $db_id);
114 $result1 = mysql_query("SELECT FOUND_ROWS()", $db_id);
115
116 if ($result0)
117 {
118 if ($html=="1")
119 PrintMagicTable($result0, $alias, $rightalign, "", "", "", $result1);
120 else
121 PrintText($result0);
122
123 mysql_free_result($result0);
124 mysql_free_result($result1);
125 }
126 mysql_close($db_id);
127
128 if ($html=="1")
129 PrintSubmittedQuery($query0, $db, "old");
130 }
131
132 include ("include.php");
133 include ("menu.php");
134 include ("db.php");
135 include ("magicdefs.php");
136
137 ini_set("display_errors", "On");
138 ini_set("mysql.trace_mode", "On");
139
140 if (!empty($_GET["fSendTxt"]))
141 {
142 header("Content-type: application/octet");
143 header("Content-Disposition: attachment; filename=query-result.txt");
144
145 PrintPage("0", $host, $user, $pw, $db, $alias, $rightalign);
146 }
147 else
148 {
149 echo (file_get_contents("index-header.html"));
150
151 $environment = sizeof($_GET);
152
153 InitGet($_GET);
154 PrintForm($_GET,$host,$user,$pw,$db);
155
156 if ($environment==0)
157 printf("No query submitted yet.<BR>");
158 else
159 PrintPage("1", $host, $user, $pw, $db, $alias, $rightalign);
160
161 echo (file_get_contents("index-footer.html"));
162 }
163
164 ini_set("display_errors", "Off");
165 ini_set("mysql.trace_mode", "Off");
166}
167?>
Note: See TracBrowser for help on using the repository browser.