-
Notifications
You must be signed in to change notification settings - Fork 1
/
Particles.php
67 lines (63 loc) · 2.07 KB
/
Particles.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
require_once("common.php");
if (!isset($loginSession))
doUnauthenticatedRedirect();
//$sensor = $db->readSensors();
$device = $loginSession->authenticatedUser->deviceId;
$today = date('m/d/Y');
if(isset($_POST['calDate'])){
$date = date('m/d/Y',strtotime($_POST['calDate'])); //Use posted date
}else{
$date = date('m/d/Y'); //Default to today
}
$js_array = $db->readParticles($date,$device);
$readingCount = count($js_array);
?>
<script type="text/javascript">
window.onresize = resize;
function resize()
{
window.location.reload();
}
</script>
<script type="text/javascript">
// Init date picker and display UI
$('#datepicker').datepicker();
</script>
<body>
<form method="post">
<input name='calDate' value="<?php echo $date; ?>" type="text" class="form-control" id="datepicker" style="display: block; text-align:center; width: 20%; margin-left: auto; margin-right: auto; border: 2px black solid;" data-provide="datepicker" placeholder="Click to choose a date..." />
<script type="text/javascript">
// Init date picker and display UI
$('#datepicker').datepicker({
format: "mm/dd/yyyy",
clearBtn: true,
todayBtn: "linked",
autoclose: true,
endDate: "<?php echo $today;?>",
todayHighlight: true
}).on('changeDate', function(){
$(this).parent('form').submit();
});
</script>
</form>
<br />
<?php if($readingCount > 1) : ?>
<script type="text/javascript">
google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable(<?= json_encode($js_array); ?>);
var options = {
title: 'Particle Readings'
};
var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
</script>
<div id="chart_div" style="width: 90%; height: 500px; margin: auto; border: 2px black solid;"></div>
<?php else : ?>
<div class="alert alert-danger" role="alert" style="width: 50%; margin: auto;">There is no data for this day :(</div>
<?php endif; ?>
</body>
</html>