

<?php
session_start ();
?>

<?php
//$datpick=$_POST['datum'];



$datum =  date('Y-m-d');
//echo $datum;
$ndatum = new DateTime ($datum);
$ndatum->modify('+2 day');

//echo $ndatum->format('Y-m-d');

$user="user";  
$host="127.0.0.1";  
$password="password";  
$database = "SensiHome";
$cxn = mysqli_connect($host,$user,$password,$database)         
	or die("geen verbinding mogelijk"); 
	
/*
$sth = "SELECT AVG(WindFC), HOUR(WindDateTime) FROM Wind WHERE DATE_SUB(WindDateTime, INTERVAL 0.25 HOUR) AND DATE(WindDateTime) > '$datum' GROUP BY HOUR(WindDateTime)"; 
	$result = mysqli_query($cxn,$sth)	
	or die ("Couldn’t execute query."); 
*/

$sth = "SELECT WindFC, WindDateTime, WindRunAv FROM Wind WHERE  DATE(WindDateTime) >= '$datum' "; 
	$result = mysqli_query($cxn,$sth)	
	or die ("Couldn’t execute query."); 



//echo $sth;
$a=0;


$table = "[[{'label' : 'UUR', 'type' : 'datetime'},{'label':'Actual', 'type':'number'},{'label':'Forcast', 'type':'number'}],";
$nrows = mysqli_num_rows($result);
$rows = array();
	while($row = mysqli_fetch_assoc($result)) {
		
		$toeren  =$row["WindFC"];
		$toeren = round($toeren, 2);
		$t= $row["WindRunAv"];
		//echo $toeren . "<br>";
			if ($t==null){
				$t="0";
			}
		//echo $t;
		//$t = 200;
		$a= $a+1;
		$table .=  "[new Date(";
		
		$WDT= $row["WindDateTime"];
		$WDT=strtotime($WDT);
		//$WDT= date('Y, m , d, H, i, s', $WDT);
		$Ys= date('Y', $WDT);
		$ms= date('m', $WDT);
		$ds= date('d', $WDT);
		$Hs= date('H', $WDT);
		$is= date('i', $WDT);
		$ss= date('s', $WDT);
//echo $ms;

		$ms= $ms-1;
		//$WDT = "(";
		$WDT = $Ys ;
		$WDT .=",";
		$WDT .=$ms;
		$WDT .=",";
		$WDT .=$ds;
		$WDT .=",";
		$WDT .=$Hs;
		$WDT .=",";
		$WDT .=$is;
		$WDT .=",";
		$WDT .=$ss;
		//$WDT .=")";


		

//echo $WDT;
//$WDT = 1;


		//$WDT = idate ('d', $WDT);
		//echo $WDT;
		

		$table .= $WDT;
		$table .=  "), ";
		$table .=  $t;
		$table .= ", ";
		$table .=  $toeren;
		$table .=   "]";
			if ($a<$nrows){
				$table .= ",";
			}
			else {
				$table .= "]";
			}
	
	}	
	
//echo $table;
?>

<! DOCTYPE html>
  <head>
<style type="text/css">

#pos1 {
position : absolute;
margin-left : 50px;
margin-top : -100px;
width : 50%;
}

#pos2 {
position : absolute;
margin-left : 350px;
margin-top : -100px;
width : 50%;
}

#testbutton {
  font-family: arial;
  color: #ffffff !important;
  font-size: 2em;
  text-shadow: 1px 1px 0px #7CACDE;
  box-shadow: 1px 1px 1px #BEE2F9;
  padding: 10px 25px;
  -moz-border-radius: 10px;
  -webkit-border-radius: 10px;
  border-radius: 10px;
  border: 3px solid #3866A3;
  background: #63B8EE;
	widht : 12em; height : 2em;


}
#testbutton:hover {
  color: #ffffff !important;
  background: #468CCF;
}
</style>
    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript">
      google.load("visualization", "1", {packages:["corechart"]});
      google.setOnLoadCallback(drawChart);
      function drawChart() {
        
	var data = google.visualization.arrayToDataTable(<?php echo $table; ?>);
	
      	
      

        var options = {
          title: 'Windforcast <?php echo $datum  ?>',
        titlePosition : 'out',  
	vAxis: {title: 'Forcast'},
	hAxis: {
            format: 'H',
            gridlines: {count: 24}
          },

          isStacked: false,
		colors:['#468CCF','#63B8EE'],
	chartArea:{left : 50, top : 100},
		  animation:{
        duration: 1000,
		  easing: 'out',
		  startup: true},
		  axisTitlesPosition : 'in',
		  fontName : 'Calibri',
		
		  titlePosition : 'out',
		vAxis: { ticks: [500 ,1000,1500, 1800] }, 
		seriesType: "area",
    		//series: {1: {type: "line"}}
        };



        var chart = new google.visualization.ComboChart(document.getElementById('chart_div'));

        chart.draw(data, options);
      }
    </script>
  </head>
  <body>
<div id="chart_div" style="left : 20px; top : 1px; width: 95%; height: 95%;"></div>

<div id="pos2" >
<form action = 'datepicker.php'  >   
<input type='submit' name='datepick' value='Dagverbruik' id='testbutton' >
</form>
</div>

<div id="pos1" >
<form action = 'Meter.php'  >   
<input type='submit' name='MR' value='Huidig verbruik' id='testbutton'>
</form>
</div>




  </body>
</html>
