source: trunk/MagicSoft/Mars/datacenter/db/plotinclude.php@ 9463

Last change on this file since 9463 was 9458, checked in by aparavac, 15 years ago
*** empty log message ***
  • Property svn:executable set to *
File size: 6.3 KB
Line 
1<?php
2
3//arrays and functions for plot.php and plotdb.php
4include("include.php");
5include("magicdefs.php");
6include("db.php");
7
8$tables=array("fSequenceFirst" => "Sequences",
9 "fRunNumber" => "RunData",
10 "fDataSetNumber" => "DataSets");
11
12$prims=array("SequenceNumber" => "fSequenceFirst",
13 "RunNumber" => "fRunNumber",
14 "DataSetNumber" => "fDataSetNumber");
15
16$joins=array("fSequenceFirst" => " LEFT JOIN Star USING(fSequenceFirst,fTelescopeNumber) "
17 ."LEFT JOIN Calibration USING(fSequenceFirst,fTelescopeNumber) ",
18 "fRunNumber" => " LEFT JOIN DataCheck USING(fRunNumber) ",
19 "fDataSetNumber" =>" LEFT JOIN Ganymed USING(fDataSetNumber) ");
20
21function GetList($host, $user, $pw, $db, $column, $tables)
22{
23 $tab_fSequenceFirst=array("Sequences", "Calibration", "Star");
24 $tab_fRunNumber=array("RunData");
25 $tab_fDataSetNumber=array("DataSets", "Ganymed");
26
27 $table=$tables[$column];
28 foreach(${"tab_".$column} as $tab)
29 {
30 $query="EXPLAIN " . $tab;
31
32 mysql_connect($host, $user, $pw);
33 mysql_select_db($db);
34
35 $result=mysql_query($query);
36
37 while ($row = mysql_fetch_row($result))
38 $list[] = $row[0];
39 }
40 return $list;
41}
42
43function CheckQuery($query)
44{
45 if (strpos($query, " WHERE ")==FALSE)
46 return " WHERE ";
47 else
48 return " AND ";
49}
50
51function GetQuery($tables, $joins, $set)
52{
53 if (empty($_GET["prim"]))
54 $_GET["prim"]="";
55 $primary=$_GET["prim"];
56 if (empty($primary))
57 return "";
58 if (empty($_GET[$primary."Col"]))
59 $_GET[$primary."Col"]="";
60 $column=$_GET[$primary."Col"];
61 $table=$tables[$primary];
62 if (empty($_GET["primstart"]))
63 $_GET["primstart"]="";
64 $primstart=$_GET["primstart"];
65 if (empty($_GET["primstop"]))
66 $_GET["primstop"]="";
67 $primstop=$_GET["primstop"];
68 if (empty($_GET["Start"]))
69 $_GET["Start"]="";
70 $start1=$_GET["Start"];
71 if (empty($_GET["Stop"]))
72 $_GET["Stop"]="";
73 $stop1=$_GET["Stop"];
74
75 if (empty($_GET["fSourceN"]))
76 $_GET["fSourceN"]="";
77 $source=$_GET["fSourceN"];
78
79 $query="SELECT " . $table . "." . $primary . ", ";
80 if ($column==$primary)
81 $query.=$table . "." . $column;
82 else
83 $query.=$column;
84
85 if ($_GET["plot"]=="val")
86 {
87 if (empty($_GET[$primary."Col2"]))
88 $_GET[$primary."Col2"]="";
89 $column2=$_GET[$primary."Col2"];
90 if (empty($_GET["Start2"]))
91 $_GET["Start2"]="";
92 $start2=$_GET["Start2"];
93 if (empty($_GET["Stop2"]))
94 $_GET["Stop2"]="";
95 $stop2=$_GET["Stop2"];
96
97 if ($column2==$primary)
98 $query.=", " . $table . "." . $column2;
99 else
100 $query.=", " . $column2;
101 }
102 $query.=" FROM " . $table;
103 $query.=$joins[$primary];
104
105 if (!empty($source))
106 $query.= " LEFT JOIN Source USING(fSourceKEY) ";
107
108 if (!empty($primstart))
109 $query.= " WHERE " . $table . "." . $primary . " > " . $primstart;
110
111 if (!empty($primstop))
112 $query.= CheckQuery($query) . $table . "." . $primary . " < " . $primstop;
113
114 if (!empty($start1))
115 $query.= CheckQuery($query) . GetTable($table, $column) . " > " . $start1;
116
117 if (!empty($stop1))
118 $query.= CheckQuery($query) . GetTable($table, $column) . " < " . $stop1;
119
120 if ($_GET["plot"]=="val")
121 {
122 if (!empty($start2))
123 $query.= CheckQuery($query) . GetTable($table, $column2) . " > " . $start2;
124
125 if (!empty($stop2))
126 $query.= CheckQuery($query) . GetTable($table, $column2) . " < " . $stop2;
127 }
128
129 if (!empty($set) && !empty($_GET[$set]))
130 $query.= CheckQuery($query) . $table . "." . $primary . " IN (" . str_replace(" ", ",", $_GET[$set]) . ") ";
131
132 if (empty($_GET[$primary."Col3"]))
133 $_GET[$primary."Col3"]="";
134 $column3=$_GET[$primary."Col3"];
135 if (empty($_GET["Start3"]))
136 $_GET["Start3"]="";
137 $start3=$_GET["Start3"];
138 if (empty($_GET["Stop3"]))
139 $_GET["Stop3"]="";
140 $stop3=$_GET["Stop3"];
141
142 if (!empty($start3))
143 $query.= CheckQuery($query) . GetTable($table, $column3) . " > " . $start3;
144
145 if (!empty($stop3))
146 $query.= CheckQuery($query) . GetTable($table, $column3) . " < " . $stop3;
147
148 if (empty($_GET[$primary."Col4"]))
149 $_GET[$primary."Col4"]="";
150 $column4=$_GET[$primary."Col4"];
151 if (empty($_GET["Start4"]))
152 $_GET["Start4"]="";
153 $start4=$_GET["Start4"];
154 if (empty($_GET["Stop4"]))
155 $_GET["Stop4"]="";
156 $stop4=$_GET["Stop4"];
157
158 if (!empty($start4))
159 $query.= CheckQuery($query) . GetTable($table, $column4) . " > " . $start4;
160
161 if (!empty($stop4))
162 $query.= CheckQuery($query) . GetTable($table, $column4) . " < " . $stop4;
163
164 if (!empty($source))
165 $query.= CheckQuery($query) . " fSourceName REGEXP \"^" . $_GET["fSourceN"] . "\" ";
166
167 return $query;
168}
169
170//functions for showplots*.php
171function gettypename($type2)
172{
173 switch ($type2)
174 {
175 case "calib":
176 $type="callisto";
177 break;
178 case "signal":
179 $type="callisto";
180 break;
181 case "star":
182 $type="star";
183 break;
184 }
185 return $type;
186}
187
188function getplotname($seq, $tabnum, $type, $type2)
189{
190 $seqlong=str_pad($seq, 8, "0", STR_PAD_LEFT);
191 $seqshort=substr($seqlong, 0, 4);
192 $plot = "http://datacenter.astro.uni-wuerzburg.de/";
193 $plot .= $type . "/" . str_pad( $seqshort, 4, "0", STR_PAD_LEFT);
194// $plot .= "/" . $seqlong . "/" . $type2 . $seqlong . "-tab" . $tabnum . ".png";
195 $plot .= "/" . $seqlong . "/" . $type2 . $tabnum . ".png";
196 return $plot;
197}
198
199function PrintType2Pulldown($type2)
200{
201 $types=array("calib", "signal", "star");
202 printf("<select name='type2'>\n");
203 foreach($types as $t => $typename)
204 if ($type2==$typename)
205 printf("<option value='%s' selected>%s </option>\n", $type2, $type2);
206 else
207 printf("<option value='%s'>%s </option>\n", $typename, $typename);
208 print("</select>\n");
209}
210
211function PrintHomeHelp()
212{
213 printf("<td valign='top'>\n");
214 printf("<a href='http://www.astro.uni-wuerzburg.de/wiki/Database_Websites'>home</a>\n");
215 printf("<a href='http://www.astro.uni-wuerzburg.de/wiki/Database_Tutorial#showplots:_calib.2C_signal.2C_star'>help</a>\n");
216 printf("</td>\n");
217}
218
219
220?>
Note: See TracBrowser for help on using the repository browser.