Index: trunk/www/dch/obs_time.php
===================================================================
--- trunk/www/dch/obs_time.php	(revision 18885)
+++ trunk/www/dch/obs_time.php	(revision 18885)
@@ -0,0 +1,192 @@
+<?php
+
+    include("db.php");
+
+ //   ini_set("display_errors", "On");
+ //   ini_set("mysql.trace_mode", "On");
+
+
+$db_id = mysql_connect($host, $user, $pw);
+if ($db_id==FALSE)
+{
+    printf("mysql_connect returned the following error: %s\n", mysql_error());
+    die("");
+}
+mysql_select_db($db);
+
+date_default_timezone_set('UTC');
+
+$begin  = isset($_GET["b"]) ? "AND fRunStart>'".$_GET["b"]."'" : "";
+$end    = isset($_GET["e"]) ? "AND fRunStop<'".$_GET["e"]."'" : "";
+$limit  = isset($_GET["l"]) ? 0+$_GET["l"] : 10;
+$hidden = isset($_GET["print"]) ? "*{visibility:hidden;}.print{position:fixed;left:0;top:0;}.print *{visibility:visible;}" : "";
+
+// ====================================================================
+
+$query = <<<EOT
+
+ SELECT
+    fSourceName AS 'Source' ,
+    SUM(TIME_TO_SEC(TIMEDIFF(fRunStop,fRunStart)))/3600 AS 'Time'
+ FROM RunInfo
+ LEFT JOIN Source USING(fSourceKEY)
+ WHERE fRunTypeKEY=1 AND fSourceTypeKey=1 $begin $end
+ GROUP BY fSourceKEY
+ HAVING Time>=$limit
+ ORDER BY Time DESC
+
+EOT;
+
+$html = "";
+//$data  = "['Source','Observation Time [h]'],\n";
+$data  = "['Source','Observation Time [h]',{role:'annotation'}],\n";
+$var1 = "";
+$count = 0;
+$total = 0;
+
+$result = mysql_query($query, $db_id);
+if ($result)
+{
+    $html .= "<table>\n";
+
+    while ($row = mysql_fetch_assoc($result))
+    {
+	$html .= " <tr>";
+        $html .= "  <td>".$row["Source"]."</td>\n";
+        $html .= "  <td>|".$row["Time"]."</td>\n";
+        $html .= " </tr>\n";
+
+	$data .= "['".$row['Source']."',".$row['Time'].",'".number_format($row['Time'],0,'','')." h'],\n";
+	//$data .= "['".$row['Source']."',".$row['Time'].",'".$row['Source']."'],\n";
+        //$data .= "['',".$row['Time'].",'".$row['Source']."'],\n";
+
+	$total += $row['Time'];
+
+        $count++;
+    }
+    $html .= "</table>\n";
+
+    mysql_free_result($result);
+}
+else
+    $html = "[empty:".mysql_error()."]\n";
+
+// --------------------------------------------------------------------
+
+mysql_close($db_id);
+
+// --------------------------------------------------------------------
+
+if (isset($_GET['test']))
+{
+    print(json_encode($data/*, JSON_PRETTY_PRINT*/));
+    return;
+}
+
+// --------------------------------------------------------------------
+
+$querycol = $query;//colorize($query),
+
+// --------------------------------------------------------------------
+
+$height = $count*60;
+$width  = $height*18/9;
+
+$total = number_format($total, 0, '', '');
+
+echo <<<EOT
+
+<!DOCTYPE HTML>
+<html>
+<head>
+<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
+<!--<script type="text/javascript" src="//www.gstatic.com/charts/loader.js"></script>-->
+<script type="text/javascript" src="https://www.google.com/jsapi"></script>
+<script type="text/javascript">
+
+    google.load('visualization', 1, {packages: ['corechart', 'bar']});
+    google.setOnLoadCallback(drawAxisTickColors);
+
+    //google.charts.load('current', {packages: ['corechart', 'bar']});
+    //google.charts.setOnLoadCallback(drawAxisTickColors);
+
+    function drawAxisTickColors(data)
+    {
+      var data = google.visualization.arrayToDataTable(
+      [
+         $data
+      ]);
+
+      var options = {
+        width:  $width,
+        height: $height,
+        legend: { position: 'top', maxLines: 1 },
+        bar:    { groupWidth: '90%' },
+        dataOpacity: 0.9,
+        hAxis: {minValue: 0, gridlines: {count:-1}, minorGridlines: {count:1}},
+      };
+
+      var chart = new google.visualization.BarChart(document.getElementById('chart_div'));
+      chart.draw(data, options);
+      document.getElementById('print_chart').innerHTML = '<a href="' + chart.getImageURI() + '">Print</a>';
+
+      console.log("Google.chart.ready");
+    }
+
+</script>
+<style>
+dl {
+    //border: 3px double #ccc;
+    padding: 0.5em;
+  }
+  dt {
+    float: left;
+    clear: left;
+    width: 130px;
+    text-align: right;
+    font-weight: bold;
+    color: green;
+  }
+  dt:after {
+    content: ":";
+  }
+  dd {
+    margin: 0 0 0 140px;
+    padding: 0 0 1em 0;
+  }
+  $hidden
+</style>
+
+<body>
+
+Total observation time: $total h (excluding sources with less than $limit h)
+<hr>
+
+<div style='position:relative'>
+<div id='chart_div' class="print">Preparing char... please stand by.</div>
+<div id='print_chart' style='position:absolute;top:10px;right:40px;'></div>
+</div>
+
+<hr>
+
+<input type="button" onclick="$('#spoiler1').toggle(300);" value="Table"/>
+<div id="spoiler1" style="display:none">
+$html
+</div>
+
+<hr>
+
+<input type="button" onclick="$('#spoiler2').toggle(300);" value="SQL query"/>
+<div id="spoiler2" style="display:none">
+<pre>
+$querycol
+</pre>
+</div>
+
+<hr>
+
+</body>
+</html>
+EOT;
+
+?>
