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

Last change on this file since 8333 was 8161, checked in by Daniela Dorner, 18 years ago
*** empty log message ***
  • Property svn:executable set to *
File size: 3.1 KB
Line 
1<?php
2
3include("include.php");
4include("magicdefs.php");
5include("db.php");
6
7$tables=array("fSequenceFirst" => "Sequences",
8 "fRunNumber" => "RunData",
9 "fDataSetNumber" => "DataSets");
10
11$prims=array("SequenceNumber" => "fSequenceFirst",
12 "RunNumber" => "fRunNumber",
13 "DataSetNumber" => "fDataSetNumber");
14
15$joins=array("fSequenceFirst" => " LEFT JOIN Star ON Star.fSequenceFirst=Sequences.fSequenceFirst "
16 ."LEFT JOIN Calibration ON Calibration.fSequenceFirst=Sequences.fSequenceFirst",
17 "fRunNumber" => " LEFT JOIN DataCheck ON DataCheck.fRunNumber=RunData.fRunNumber ",
18 "fDataSetNumber" =>" LEFT JOIN Ganymed ON Ganymed.fDataSetNumber=DataSets.fDataSetNumber");
19
20function GetList($host, $user, $pw, $db, $column, $tables)
21{
22 $tab_fSequenceFirst=array("Sequences", "Calibration", "Star");
23 $tab_fRunNumber=array("RunData");
24 $tab_fDataSetNumber=array("DataSets", "Ganymed");
25
26 $table=$tables[$column];
27 foreach(${"tab_".$column} as $tab)
28 {
29 $query="EXPLAIN " . $tab;
30
31 mysql_connect($host, $user, $pw);
32 mysql_select_db($db);
33
34 $result=mysql_query($query);
35
36 while ($row = mysql_fetch_row($result))
37 $list[] = $row[0];
38 }
39 return $list;
40}
41
42
43function GetQuery($tables, $joins, $set)
44{
45 $primary=$_GET["prim"];
46 $column=$_GET[$primary."Col"];
47 $table=$tables[$primary];
48 $primstart=$_GET["primstart"];
49 $primstop=$_GET["primstop"];
50 $start1=$_GET[$column."Start"];
51 $stop1=$_GET[$column."Stop"];
52
53 $query="SELECT " . $table . "." . $primary . ", ";
54 if ($column==$primary)
55 $query.=$table . "." . $column;
56 else
57 $query.=$column;
58
59 if ($_GET["plot"]=="val")
60 {
61 $column2=$_GET[$primary."Col2"];
62 $start2=$_GET[$column2."Start2"];
63 $stop2=$_GET[$column2."Stop2"];
64
65 if ($column2==$primary)
66 $query.=", " . $table . "." . $column2;
67 else
68 $query.=", " . $column2;
69 }
70 $query.=" FROM " . $table;
71 $query.=$joins[$primary];
72 if (!empty($primstart) && !empty($primstop))
73 $query.=" WHERE " . $table . "." . $primary . " BETWEEN " . $primstart . " AND " . $primstop;
74
75 if (!empty($start1) && !empty($stop1))
76 {
77 if (strpos($query, " WHERE ")==FALSE)
78 $query.=" WHERE " . $column . " BETWEEN " . $start1 . " AND " . $stop1;
79 else
80 $query.=" AND " . $column . " BETWEEN " . $start1 . " AND " . $stop1;
81 }
82
83 if ($_GET["plot"]=="val" && !empty($start2) && !empty($stop2))
84 {
85 if (strpos($query, " WHERE ")==FALSE)
86 $query.=" WHERE " . $column2 . " BETWEEN " . $start2 . " AND " . $stop2;
87 else
88 $query.=" AND " . $column2 . " BETWEEN " . $start2 . " AND " . $stop2;
89 }
90
91 if (!empty($set) && !empty($_GET[$set]))
92 {
93 if (strpos($query, " WHERE ")==FALSE)
94 $query .= " WHERE ";
95 else
96 $query.=" AND ";
97 $query.= $table . "." . $primary . " IN (" . str_replace(" ", ",", $_GET[$set]) . ") ";
98 }
99
100 return $query;
101}
102
103
104?>
Note: See TracBrowser for help on using the repository browser.