| 1 | <?php
|
|---|
| 2 |
|
|---|
| 3 | //arrays and functions for plot.php and plotdb.php
|
|---|
| 4 | include("include.php");
|
|---|
| 5 | include("magicdefs.php");
|
|---|
| 6 | include("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 |
|
|---|
| 21 | function 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 |
|
|---|
| 43 | function CheckQuery($query)
|
|---|
| 44 | {
|
|---|
| 45 | if (strpos($query, " WHERE ")==FALSE)
|
|---|
| 46 | return " WHERE ";
|
|---|
| 47 | else
|
|---|
| 48 | return " AND ";
|
|---|
| 49 | }
|
|---|
| 50 |
|
|---|
| 51 | function 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 | $query="SELECT " . $table . "." . $primary . ", ";
|
|---|
| 76 | if ($column==$primary)
|
|---|
| 77 | $query.=$table . "." . $column;
|
|---|
| 78 | else
|
|---|
| 79 | $query.=$column;
|
|---|
| 80 |
|
|---|
| 81 | if ($_GET["plot"]=="val")
|
|---|
| 82 | {
|
|---|
| 83 | if (empty($_GET[$primary."Col2"]))
|
|---|
| 84 | $_GET[$primary."Col2"]="";
|
|---|
| 85 | $column2=$_GET[$primary."Col2"];
|
|---|
| 86 | if (empty($_GET["Start2"]))
|
|---|
| 87 | $_GET["Start2"]="";
|
|---|
| 88 | $start2=$_GET["Start2"];
|
|---|
| 89 | if (empty($_GET["Stop2"]))
|
|---|
| 90 | $_GET["Stop2"]="";
|
|---|
| 91 | $stop2=$_GET["Stop2"];
|
|---|
| 92 |
|
|---|
| 93 | if ($column2==$primary)
|
|---|
| 94 | $query.=", " . $table . "." . $column2;
|
|---|
| 95 | else
|
|---|
| 96 | $query.=", " . $column2;
|
|---|
| 97 | }
|
|---|
| 98 | $query.=" FROM " . $table;
|
|---|
| 99 | $query.=$joins[$primary];
|
|---|
| 100 |
|
|---|
| 101 | if (!empty($primstart))
|
|---|
| 102 | $query.= " WHERE " . $table . "." . $primary . " > " . $primstart;
|
|---|
| 103 |
|
|---|
| 104 | if (!empty($primstop))
|
|---|
| 105 | $query.= CheckQuery($query) . $table . "." . $primary . " < " . $primstop;
|
|---|
| 106 |
|
|---|
| 107 | if (!empty($start1))
|
|---|
| 108 | $query.= CheckQuery($query) . GetTable($table, $column) . " > " . $start1;
|
|---|
| 109 |
|
|---|
| 110 | if (!empty($stop1))
|
|---|
| 111 | $query.= CheckQuery($query) . GetTable($table, $column) . " < " . $stop1;
|
|---|
| 112 |
|
|---|
| 113 | if ($_GET["plot"]=="val")
|
|---|
| 114 | {
|
|---|
| 115 | if (!empty($start2))
|
|---|
| 116 | $query.= CheckQuery($query) . GetTable($table, $column2) . " > " . $start2;
|
|---|
| 117 |
|
|---|
| 118 | if (!empty($stop2))
|
|---|
| 119 | $query.= CheckQuery($query) . GetTable($table, $column2) . " < " . $stop2;
|
|---|
| 120 | }
|
|---|
| 121 |
|
|---|
| 122 | if (!empty($set) && !empty($_GET[$set]))
|
|---|
| 123 | $query.= CheckQuery($query) . $table . "." . $primary . " IN (" . str_replace(" ", ",", $_GET[$set]) . ") ";
|
|---|
| 124 |
|
|---|
| 125 | if (empty($_GET[$primary."Col3"]))
|
|---|
| 126 | $_GET[$primary."Col3"]="";
|
|---|
| 127 | $column3=$_GET[$primary."Col3"];
|
|---|
| 128 | if (empty($_GET["Start3"]))
|
|---|
| 129 | $_GET["Start3"]="";
|
|---|
| 130 | $start3=$_GET["Start3"];
|
|---|
| 131 | if (empty($_GET["Stop3"]))
|
|---|
| 132 | $_GET["Stop3"]="";
|
|---|
| 133 | $stop3=$_GET["Stop3"];
|
|---|
| 134 |
|
|---|
| 135 | if (!empty($start3))
|
|---|
| 136 | $query.= CheckQuery($query) . GetTable($table, $column3) . " > " . $start3;
|
|---|
| 137 |
|
|---|
| 138 | if (!empty($stop3))
|
|---|
| 139 | $query.= CheckQuery($query) . GetTable($table, $column3) . " < " . $stop3;
|
|---|
| 140 |
|
|---|
| 141 | if (empty($_GET[$primary."Col4"]))
|
|---|
| 142 | $_GET[$primary."Col4"]="";
|
|---|
| 143 | $column4=$_GET[$primary."Col4"];
|
|---|
| 144 | if (empty($_GET["Start4"]))
|
|---|
| 145 | $_GET["Start4"]="";
|
|---|
| 146 | $start4=$_GET["Start4"];
|
|---|
| 147 | if (empty($_GET["Stop4"]))
|
|---|
| 148 | $_GET["Stop4"]="";
|
|---|
| 149 | $stop4=$_GET["Stop4"];
|
|---|
| 150 |
|
|---|
| 151 | if (!empty($start4))
|
|---|
| 152 | $query.= CheckQuery($query) . GetTable($table, $column4) . " > " . $start4;
|
|---|
| 153 |
|
|---|
| 154 | if (!empty($stop4))
|
|---|
| 155 | $query.= CheckQuery($query) . GetTable($table, $column4) . " < " . $stop4;
|
|---|
| 156 |
|
|---|
| 157 | return $query;
|
|---|
| 158 | }
|
|---|
| 159 |
|
|---|
| 160 | //functions for showplots*.php
|
|---|
| 161 | function gettypename($type2)
|
|---|
| 162 | {
|
|---|
| 163 | switch ($type2)
|
|---|
| 164 | {
|
|---|
| 165 | case "calib":
|
|---|
| 166 | $type="callisto";
|
|---|
| 167 | break;
|
|---|
| 168 | case "signal":
|
|---|
| 169 | $type="callisto";
|
|---|
| 170 | break;
|
|---|
| 171 | case "star":
|
|---|
| 172 | $type="star";
|
|---|
| 173 | break;
|
|---|
| 174 | }
|
|---|
| 175 | return $type;
|
|---|
| 176 | }
|
|---|
| 177 |
|
|---|
| 178 | function getplotname($seq, $tabnum, $type, $type2)
|
|---|
| 179 | {
|
|---|
| 180 | $seqlong=str_pad($seq, 8, "0", STR_PAD_LEFT);
|
|---|
| 181 | $seqshort=substr($seqlong, 0, 4);
|
|---|
| 182 | $plot = "http://datacenter.astro.uni-wuerzburg.de/";
|
|---|
| 183 | $plot .= $type . "/" . str_pad( $seqshort, 4, "0", STR_PAD_LEFT);
|
|---|
| 184 | // $plot .= "/" . $seqlong . "/" . $type2 . $seqlong . "-tab" . $tabnum . ".png";
|
|---|
| 185 | $plot .= "/" . $seqlong . "/" . $type2 . $tabnum . ".png";
|
|---|
| 186 | return $plot;
|
|---|
| 187 | }
|
|---|
| 188 |
|
|---|
| 189 | function PrintType2Pulldown($type2)
|
|---|
| 190 | {
|
|---|
| 191 | $types=array("calib", "signal", "star");
|
|---|
| 192 | printf("<select name='type2'>\n");
|
|---|
| 193 | foreach($types as $t => $typename)
|
|---|
| 194 | if ($type2==$typename)
|
|---|
| 195 | printf("<option value='%s' selected>%s </option>\n", $type2, $type2);
|
|---|
| 196 | else
|
|---|
| 197 | printf("<option value='%s'>%s </option>\n", $typename, $typename);
|
|---|
| 198 | print("</select>\n");
|
|---|
| 199 | }
|
|---|
| 200 |
|
|---|
| 201 | function PrintHomeHelp()
|
|---|
| 202 | {
|
|---|
| 203 | printf("<td valign='top'>\n");
|
|---|
| 204 | printf("<a href='http://www.astro.uni-wuerzburg.de/wiki/Database_Websites'>home</a>\n");
|
|---|
| 205 | printf("<a href='http://www.astro.uni-wuerzburg.de/wiki/Database_Tutorial#showplots:_calib.2C_signal.2C_star'>help</a>\n");
|
|---|
| 206 | printf("</td>\n");
|
|---|
| 207 | }
|
|---|
| 208 |
|
|---|
| 209 |
|
|---|
| 210 | ?>
|
|---|