-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathindex.php
More file actions
155 lines (135 loc) · 5.5 KB
/
index.php
File metadata and controls
155 lines (135 loc) · 5.5 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<?php
include("other_page_login.php");
if($user){
$devices = getDevices($user["tenant_id"], false);
$weatherColumns = getGraphColumns($user["tenant_id"]);
//var_dump($devices);
if(array_key_exists( "device_id", $_REQUEST)) {
$deviceId = $_REQUEST["device_id"];
} else {
if($devices && $devices[0]){
$deviceId = $devices[0]["device_id"]; //picking the first device now, but this could be in the tenant config
}
}
}
function multiDevicePicker($tenantId, $devices) {
$out = "";
foreach($devices as $device){
if($device["location_name"]){
$out .= "<div><input onchange='getWeatherData()' name='specificDevice' type='checkbox' value='" . $device["device_id"] . "'/> ";
$out .= $device["location_name"];
$out .= "</div>";
}
}
return $out;
}
function plotTypePicker($type, $handler){
$checked = "";
if(gvfw("plot_type") == $type || gvfw("plot_type")=="" && $type == "single"){
$checked = "checked";
}
$out = "<div class='listtitle' style='opacity:1'><input type='radio' id='plottype' " . $checked . " name='plottype' onchange='" . $handler . "' value='" . $type . "'>" . ucfirst($type) . "-location Plot</div>";
return $out;
}
?>
<html>
<head>
<title>Weather Information</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/3.7.0/chart.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chartjs-adapter-date-fns@2.0.0/dist/chartjs-adapter-date-fns.bundle.min.js"></script>
<script src = "tinycolor.js"></script>
<script>
let scaleConfig = JSON.parse('<?php echo json_encode(timeScales()); ?>');
let devices = [];//JSON.parse('<?php echo json_encode($devices); ?>');
window.timezone ='<?php echo $timezone ?>';
</script>
<script src='tool.js'></script>
<link rel='stylesheet' href='tool.css?version=1711570359'>
<link rel="icon" type="image/x-icon" href="./favicon.ico" />
</head>
<body>
<?php
$out .= topmostNav();
$out .= "<div class='logo'>Weather Data</div>";
if($user) {
$out .= "<div class='outercontent'>";
if($poser) {
$poserString = " posing as <span class='poserindication'>" . userDisplayText($poser) . "</span> (<a href='?action=disimpersonate'>unpose</a>)";
}
$out .= "<div class='loggedin'>You are logged in as <b>" . userDisplayText($user) . "</b>" . $poserString . " on " . $user["name"] . " <div class='basicbutton'><a href=\"?action=logout\">logout</a></div></div>\n";
}
else
{
//$out .= "<div class='loggedin'>You are logged out. </div>\n";
}
$out .= "<div>\n";
$out .= "<div class='documentdescription'>";
$out .= "</div>";
//$out .= "<div class='innercontent'>";
echo $out;
?>
<div style="text-align:center;"><b><span id='greatestTime'></span></b></div>
<div class="chart-container" style="width: 100%; height: 70vh;">
<canvas id="Chart"></canvas>
</div>
<div>
<div style='display:inline-block;vertical-align:top'>
<?php
$selectId = "locationDropdown";
$handler = "getWeatherData()";
echo "\n<table>\n";
echo "<tr><td>Time Scale:</td><td>";
echo genericSelect("scaleDropdown", "scale", defaultFailDown(gvfw("scale"), "day"), $scaleConfig, "onchange", $handler);
echo "</td></tr>";
echo "<tr><td>Date/Time Begin:</td><td id='placeforscaledropdown'></td></tr>";
//absolute_timespan_cusps
echo "<tr><td>Use Absolute Timespan Cusps</td><td><input type='checkbox' value='absolute_timespan_cusps' id='atc_id' onchange='" . $handler . "'/></td></tr>";
echo "\n</table>\n";
echo "<br/><button onclick='getWeatherData(1);return false'>show data from a year before</button>";
echo "<br/><button onclick='editColumns();return false'>edit weather columns</button>";
?>
</div>
<div style='display:inline-block;vertical-align:top' >
<?php echo plotTypePicker("single", $handler); ?>
<div id='singleplotdiv'>
<table id="dataTable">
<?php
//lol, it's easier to specify an object in json and decode it than it is just specify it in PHP
$thisDataSql = "SELECT location_name as text, device_id as value FROM device WHERE location_name <> '' AND location_name IS NOT NULL AND tenant_id=" . intval($user["tenant_id"]) . " ORDER BY location_name ASC;";
$result = mysqli_query($conn, $thisDataSql);
if($result) {
$selectData = mysqli_fetch_all($result, MYSQLI_ASSOC);
}
//$selectData = json_decode('[{"text":"Outside Cabin","value":1},{"text":"Cabin Downstairs","value":2},{"text":"Cabin Watchdog","value":3}]');
//var_dump($selectData);
//echo json_last_error_msg();
echo "<tr><td>Location:</td><td>" . genericSelect($selectId, "deviceId", defaultFailDown(gvfw("device_id"), $deviceId), $selectData, "onchange", $handler) . "</td></tr>";
?>
</table>
</div>
</div>
<div style='display:inline-block;vertical-align:top'>
<?php
echo plotTypePicker("multi", $handler);
echo "<div id='multiplotdiv'>";
echo "<div>Weather Column: ";
//$weatherColumns = ["temperature", "pressure", "humidity"]; //now derived programmatically
echo "</div>";
echo genericSelect("specific_column", "specific_column", defaultFailDown(gvfw("specific_column"), "temperature"), $weatherColumns, "onchange", $handler);
echo multiDevicePicker($user["tenant_id"], $devices);
echo "</div>";
?>
</div>
<div style='display:inline-block;vertical-align:top' id='officialweather'>
</div>
</div>
<!--</div>-->
</div>
</div>
<script>
let defaultdeviceId = <?php echo $deviceId?>;
let columnsWeCareAbout = <?php echo json_encode($weatherColumns)?>;
</script>
<script src='weather.js'></script>
</body>
</html>