<?php
//ESP Temperature, humitidy and pressure logger based on BME280 sensor and ESP32. Pushes the data to a web database for display. 
//See full project at http://projects.xief.net
//
//Permission is hereby granted, free of charge, to any person obtaining a copy
//of this software and associated documentation files.
//
//The above copyright notice and this permission notice shall be included in all
//copies or substantial portions of the Software.
//
//Creates page that displays linegraph. 
?>


<!DOCTYPE html>
<html>
  <head>
    <script>
	function goBack() {
	  window.history.back()
	}
	</script>
    <title>Last 24hrs</title>
    <style>
      .chart-container {
        width: 1024px;
        height: auto;
      }
    a {
     text-decoration: none;
	 color:green;
    }
    </style>
  </head>
  <body>
    <div class="chart-container">
      <canvas id="mycanvas"></canvas>
    </div>
    
    <!-- javascript -->
    <script type="text/javascript" src="js/jquery.min.js"></script>
    <script type="text/javascript" src="js/Chart.bundle.js"></script>
	
	<?php
	
	
	$sensorName = str_replace(" ", "", $_GET["sensorName"]);
	$sensorName= substr($sensorName,0,20); //db only set up for max 20 length, truncating everything else
	$daysback = floatval(isset($_GET["daysback"]) ? $_GET["daysback"] : 1);  //by changing to float should be tamper proof
	
	print("<script id='linegraph' sensorName='" . $sensorName ."' daysback='" . strval($daysback) ."'  type='text/javascript' src='linegraph.js'></script>");
	
	
	?>
	
	
  
	<a href="logger-esp-data.php">Overview</a> -- 
	<? //buttons for other times
	$file='linegraph.php';
	$times = array(30, 7, 2, 1, 0.5, 2/24, 1/24);
	
	foreach ($times as $time) {
	print("  --  <a href='linegraph.php?sensorName=" . $sensorName . "&daysback=" . strval(round($time,2)) . "'>");
	print(strval(round($time,2)) . " days </a>");
	
	}
	
	
	?>

  </body>
</html>