source: trunk/MagicSoft/Mars/datacenter/db/sources.php@ 9501

Last change on this file since 9501 was 9498, checked in by Daniela Dorner, 15 years ago
*** empty log message ***
  • Property svn:executable set to *
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 PrintSubmittedQuery($query0, $html, $db, "old");
129 }
130
131 include ("include.php");
132 include ("menu.php");
133 include ("db.php");
134 include ("magicdefs.php");
135
136 ini_set("display_errors", "On");
137 ini_set("mysql.trace_mode", "On");
138
139 if (!empty($_GET["fSendTxt"]))
140 {
141 header("Content-type: application/octet");
142 header("Content-Disposition: attachment; filename=query-result.txt");
143
144 PrintPage("0", $host, $user, $pw, $db, $alias, $rightalign);
145 }
146 else
147 {
148 echo (file_get_contents("index-header.html"));
149
150 $environment = sizeof($_GET);
151
152 InitGet($_GET);
153 PrintForm($_GET,$host,$user,$pw,$db);
154
155 if ($environment==0)
156 printf("No query submitted yet.<BR>");
157 else
158 PrintPage("1", $host, $user, $pw, $db, $alias, $rightalign);
159
160 echo (file_get_contents("index-footer.html"));
161 }
162
163 ini_set("display_errors", "Off");
164 ini_set("mysql.trace_mode", "Off");
165}
166?>
Note: See TracBrowser for help on using the repository browser.