Index: /trunk/MagicSoft/Mars/Changelog
===================================================================
--- /trunk/MagicSoft/Mars/Changelog	(revision 8160)
+++ /trunk/MagicSoft/Mars/Changelog	(revision 8161)
@@ -22,4 +22,8 @@
    * datacenter/scripts/jobmanager, datacenter/scripts/setup:
      - added longer sleeping, when there is nothing to do for any script
+
+   * datacenter/db/plot.php, datacenter/db/plotdb.php, 
+     datacenter/db/plotinclude.php:
+     - added (websites to plot values from the db)
 
 
Index: /trunk/MagicSoft/Mars/NEWS
===================================================================
--- /trunk/MagicSoft/Mars/NEWS	(revision 8160)
+++ /trunk/MagicSoft/Mars/NEWS	(revision 8161)
@@ -5,4 +5,6 @@
    - general: The changes to the interpretation of phrases lead to
      a problem with the access of MHMatrix objects (eg. "M[0]")... fixed.
+
+   - database: Website to plot values from the database has been added. 
 
 
Index: /trunk/MagicSoft/Mars/datacenter/db/plot.php
===================================================================
--- /trunk/MagicSoft/Mars/datacenter/db/plot.php	(revision 8161)
+++ /trunk/MagicSoft/Mars/datacenter/db/plot.php	(revision 8161)
@@ -0,0 +1,97 @@
+<?php
+    require_once("../phpchartdir.php");
+
+include("plotinclude.php");
+
+function GetData($db_id, $tables, $joins, $set, &$prim, &$val1, &$val2)
+{
+    $query=GetQuery($tables, $joins, $set);
+//    printf("query:%s<br>", $query);
+    $result=mysql_query($query, $db_id);
+
+    while ($row = mysql_fetch_row($result))
+    {
+        $prim[] = $row[0];
+        $val1[] = $row[1];
+        if ($_GET["plot"]=="val")
+            $val2[] = $row[2];
+    }
+    mysql_free_result($result);
+}
+
+$primary=$_GET["prim"];
+$column=$_GET[$primary."Col"];
+
+//get data from db
+$db_id = mysql_pconnect($host, $user, $pw);
+if ($db_id==FALSE)
+{
+    printf("mysql_connect returned the following error: %s\n", mysql_error());
+    die("");
+}
+mysql_select_db($db);
+
+GetData($db_id, $tables, $joins, "", $prim, $val1, $val2);
+if (!empty($_GET["Set"]))
+    GetData($db_id, $tables, $joins, "Set", $Setprim, $Setval1, $Setval2);
+if (!empty($_GET["Set2"]))
+    GetData($db_id, $tables, $joins, "Set2", $Set2prim, $Set2val1, $Set2val2);
+
+mysql_close($db_id);
+
+//set up plot
+$c= new XYChart(640,400);//, 0xeeeeee, 0x000000, 1);
+//$c->setRoundedFrame();
+$c->setPlotArea(70, 45, 540, 300, 0xffffff, -1, 0xcccccc, 0xccccccc);
+
+//size of the symbols
+$small=2;//normal data
+$large=8;//set1, set2
+//fonts
+$titlesize=13;
+$font="arialbd.ttf";
+$axisfont="";
+$axissize=10;
+$labelfont="arialdb.ttf";
+$labelsize=10;
+if ($_GET["plot"]=="val")
+{
+    $column2=$_GET[$primary."Col2"];
+    $c->addScatterLayer($val2, $val1, $column, CircleSymbol, $small, 0x000000, 0x000000);
+    if (!empty($_GET["Set"]))
+        $c->addScatterLayer($Setval2, $Setval1, $column, CircleSymbol, $large, 0x0080ff, 0x0080ff);
+    if (!empty($_GET["Set2"]))
+        $c->addScatterLayer($Set2val2, $Set2val1, $column, CircleSymbol, $large, 0xff0000, 0xff0000);
+    $c->yAxis->setTitle($column, $axisfont, $axissize);
+    $c->xAxis->setTitle($column2, $axisfont, $axissize);
+    $textBoxObj = $c->addTitle(ltrim($column, "f")."  vs  ".ltrim($column2, "f"), $font, $titlesize);
+}
+else
+{
+    $c->addScatterLayer($prim, $val1, $column, CircleSymbol, $small, 0x000000, 0x000000);
+    if (!empty($_GET["Set"]))
+        $c->addScatterLayer($Setprim, $Setval1, $column, CircleSymbol, $large, 0x0080ff, 0x0080ff);
+    if (!empty($_GET["Set2"]))
+        $c->addScatterLayer($Set2prim, $Set2val1, $column, CircleSymbol, $large, 0xff0000, 0xff0000);
+    $c->yAxis->setTitle($column, $axisfont, $axissize);
+    $c->xAxis->setTitle($primary, $axisfont, $axissize);
+    $textBoxObj = $c->addTitle(ltrim($column,"f")."  vs  ".ltrim($primary,"f"), $font, $titlesize);
+}
+//get scaling of the yAxis
+if (!empty($_GET[$column."Start"]) && !empty($_GET[$column."Stop"]))
+{
+    $start=$_GET[$column."Start"];
+    $stop=$_GET[$column."Stop"];
+    $numticks=($stop-$start)/4;
+    $numticks2=($stop-$start)/8;
+    $c->yAxis->setLinearScale($start, $stop, $numticks, $numticks2);
+}
+//background of title
+$textBoxObj->setBackground(0xccccff,-1, softLighting());
+$c->xAxis->setLabelStyle($labelfont, $labelsize);
+$c->yAxis->setLabelStyle($labelfont, $labelsize);
+
+header("Content-type: image/png");
+print($c->makeChart2(PNG));
+
+?>
Index: /trunk/MagicSoft/Mars/datacenter/db/plotdb.php
===================================================================
--- /trunk/MagicSoft/Mars/datacenter/db/plotdb.php	(revision 8161)
+++ /trunk/MagicSoft/Mars/datacenter/db/plotdb.php	(revision 8161)
@@ -0,0 +1,105 @@
+<?php
+{
+    function PrintDiv($column, $list, $num)
+    {
+        if (($_GET["prim"]==$column && empty($num)) || ($_GET["prim"]==$column && $_GET["plot"]=="val" && $num==2))
+            printf("<div id='%s%s' style='display:inline'>\n", $column, $num);
+        else
+            printf("<div id='%s%s' style='display:none'>\n", $column, $num);
+
+        if (!empty($num))
+            $vs="vs";
+
+        printf("<select name='%sCol%s' size='1' class='Width'>\n", $column, $num);
+        foreach($list as $column2)
+            if ($_GET[$column."Col".$num]==$column2)
+                printf("<option value='%s' selected>%s %s</option>\n", $column2, $vs, $column2);
+            else
+                printf("<option value='%s'>%s %s</option>\n", $column2, $vs, $column2);
+
+        printf("</select>\n");
+        printf(" from&nbsp;<input name='%sStart%s' type='text' size='6' maxlength='6' value='%s'>", $_GET[$column."Col".$num], $num, $_GET[$_GET[$column."Col".$num]."Start".$num]);
+        printf(" to&nbsp;<input name='%sStop%s' type='text' size='6' maxlength='6' value='%s'><br>\n", $_GET[$column."Col".$num], $num, $_GET[$_GET[$column."Col".$num]."Stop".$num]);
+        printf("</div>\n");
+    }
+
+    ini_set("display_errors", "On");
+    ini_set("mysql.trace_mode", "On");
+
+    echo (file_get_contents("index-header.html"));
+
+    include("plotinclude.php");
+
+    printf("<center>\n<table cellpadding='0'>\n");
+    printf("<tr><td align='left'>\n");
+    printf("<form style='margin-bottom:0;' action='plotdb.php' METHOD='GET'>\n");
+
+    printf("<select name='plot' size='1' class='Width'>\n");
+    if ($_GET["plot"]=="prim")
+        printf("<option value='prim' onclick='hidepulldown2()' selected>vs primary</option>\n");
+    else
+        printf("<option value='prim' onclick='hidepulldown2()'>vs primary</option>\n");
+    if ($_GET["plot"]=="val")
+        printf("<option value='val' onclick='showpulldown2()' selected>vs value</option>\n");
+    else
+        printf("<option value='val' onclick='showpulldown2()'>vs value</option>\n");
+    printf("</select><br>\n");
+
+    printf("<select name='prim' size='1' class='Width'>\n");
+    foreach($prims as $primary => $column)
+        if ($_GET["prim"]==$column)
+            printf("<option onclick=\"showpulldown('%s')\" value='%s' selected>%s</option>\n", $column, $column, $primary);
+        else
+            printf("<option onclick=\"showpulldown('%s')\" value='%s'>%s</option>\n", $column, $column, $primary);
+    printf("</select>\n");
+    printf(" from&nbsp;<input name='primstart' type='text' size='6' maxlength='6' value='%s'>", $_GET["primstart"]);
+    printf(" to&nbsp;<input name='primstop' type='text' size='6' maxlength='6' value='%s'><br>\n", $_GET["primstop"]);
+
+    foreach($prims as $primary => $column)
+    {
+        $list=GetList($host, $user, $pw, $db, $column, $tables);
+        PrintDiv($column, $list, "");
+        PrintDiv($column, $list, "2");
+    }
+
+    printf("<br>Set1: <input name='Set' type='text' size='20' maxlength='100' value='%s'>\n", $_GET["Set"]);
+    printf("<br>Set2: <input name='Set2' type='text' size='20' maxlength='100' value='%s'>\n", $_GET["Set2"]);
+    printf("<br><br><input class='Width' type='submit' value='Query Plot'><br>\n");
+    printf("<input class='Width' type='button' value='Reset' onClick='self.location.href=\"plotdb.php\"'><br>\n");
+
+    printf("</form>");
+    printf("</td>\n");
+
+    printf("<td align='right' width='640px'>\n");
+    if (!empty($_GET))
+    {
+        $img="plot.php?par=hallo";
+        foreach($_GET as $var => $val)
+            $img.="&amp;".$var ."=".$val;
+//        printf("link: %s<br>", $img);
+        printf("<img src='%s' alt='plot'>", $img);
+    }
+    printf("</td></tr>\n");
+    printf("<tr><td colspan='2'>\n");
+    printf("some remarks:\n<ul>");
+    printf("<li>For Runs plotting the whole range (i.e. without giving a range or when giving a too large range) ");
+    printf("doesn't work with ChartDirector.</li>\n");
+    printf("<li>In Set1 and Set2 Sets can be given (e.g. on sequences in Set1 and off sequences in Set2) - they ");
+    printf("are displayed in colour (Set:blue, Set2: red). Please give the numbers with space as separator (e.g. 40004 40022).</<li>\n");
+    printf("<li>0 is not accepted in the ranges fields, please write .0 or 00</li>");
+    printf("<li>Be aware, that plotting timestamps, e.g. fRunStart, doesn't work. </li>");
+    printf("</ul></td></tr>\n");
+    /*
+    printf("<tr><td>\n");
+    $query=GetQuery($tables, $joins);
+    printf("Q: %s</td></tr>", $query);
+    */
+    printf("</table>\n");
+    printf("</center>\n");
+
+    echo (file_get_contents("index-footer.html"));
+
+    ini_set("display_errors", "Off");
+    ini_set("mysql.trace_mode", "Off");
+}
+?>
Index: /trunk/MagicSoft/Mars/datacenter/db/plotinclude.php
===================================================================
--- /trunk/MagicSoft/Mars/datacenter/db/plotinclude.php	(revision 8161)
+++ /trunk/MagicSoft/Mars/datacenter/db/plotinclude.php	(revision 8161)
@@ -0,0 +1,104 @@
+<?php
+
+include("include.php");
+include("magicdefs.php");
+include("db.php");
+
+$tables=array("fSequenceFirst" => "Sequences",
+              "fRunNumber"     => "RunData",
+              "fDataSetNumber" => "DataSets");
+
+$prims=array("SequenceNumber" => "fSequenceFirst",
+             "RunNumber"      => "fRunNumber",
+             "DataSetNumber"  => "fDataSetNumber");
+
+$joins=array("fSequenceFirst" => " LEFT JOIN Star ON Star.fSequenceFirst=Sequences.fSequenceFirst "
+             ."LEFT JOIN Calibration ON Calibration.fSequenceFirst=Sequences.fSequenceFirst",
+             "fRunNumber" => " LEFT JOIN DataCheck ON DataCheck.fRunNumber=RunData.fRunNumber ",
+             "fDataSetNumber" =>" LEFT JOIN Ganymed ON Ganymed.fDataSetNumber=DataSets.fDataSetNumber");
+
+function GetList($host, $user, $pw, $db, $column, $tables)
+{
+    $tab_fSequenceFirst=array("Sequences", "Calibration", "Star");
+    $tab_fRunNumber=array("RunData");
+    $tab_fDataSetNumber=array("DataSets", "Ganymed");
+
+    $table=$tables[$column];
+    foreach(${"tab_".$column} as $tab)
+    {
+        $query="EXPLAIN " . $tab;
+
+        mysql_connect($host, $user, $pw);
+        mysql_select_db($db);
+
+        $result=mysql_query($query);
+
+        while ($row = mysql_fetch_row($result))
+            $list[] = $row[0];
+    }
+    return $list;
+}
+
+
+function GetQuery($tables, $joins, $set)
+{
+    $primary=$_GET["prim"];
+    $column=$_GET[$primary."Col"];
+    $table=$tables[$primary];
+    $primstart=$_GET["primstart"];
+    $primstop=$_GET["primstop"];
+    $start1=$_GET[$column."Start"];
+    $stop1=$_GET[$column."Stop"];
+
+    $query="SELECT " . $table . "." . $primary . ", ";
+    if ($column==$primary)
+        $query.=$table . "." . $column;
+    else
+        $query.=$column;
+
+    if ($_GET["plot"]=="val")
+    {
+        $column2=$_GET[$primary."Col2"];
+        $start2=$_GET[$column2."Start2"];
+        $stop2=$_GET[$column2."Stop2"];
+
+        if ($column2==$primary)
+            $query.=", " . $table . "." . $column2;
+        else
+            $query.=", " . $column2;
+    }
+    $query.=" FROM " . $table;
+    $query.=$joins[$primary];
+    if (!empty($primstart) && !empty($primstop))
+        $query.=" WHERE " . $table . "." . $primary . " BETWEEN " . $primstart . " AND " . $primstop;
+
+    if (!empty($start1) && !empty($stop1))
+    {
+        if (strpos($query, " WHERE ")==FALSE)
+            $query.=" WHERE " . $column . " BETWEEN " . $start1 . " AND " . $stop1;
+        else
+            $query.=" AND " . $column . " BETWEEN " . $start1 . " AND " . $stop1;
+    }
+
+    if ($_GET["plot"]=="val" && !empty($start2) && !empty($stop2))
+    {
+        if (strpos($query, " WHERE ")==FALSE)
+            $query.=" WHERE " . $column2 . " BETWEEN " . $start2 . " AND " . $stop2;
+        else
+            $query.=" AND " . $column2 . " BETWEEN " . $start2 . " AND " . $stop2;
+    }
+
+    if (!empty($set) && !empty($_GET[$set]))
+    {
+        if (strpos($query, " WHERE ")==FALSE)
+            $query .= " WHERE ";
+        else
+            $query.=" AND ";
+        $query.= $table . "." . $primary . " IN (" . str_replace(" ", ",", $_GET[$set]) . ") ";
+    }
+
+    return $query;
+}
+
+
+?>
