This repository has been archived by the owner on Jul 12, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
selectdevice.php
113 lines (83 loc) · 2.88 KB
/
selectdevice.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
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
<?php
//foreach ($_POST as $key => $value) echo "Field ".htmlspecialchars($key)." is ".htmlspecialchars($value)."<br>";
header('Content-Type: text/html; charset=ISO-8859-1');
$servername = "localhost";
$username = "fagprojekt";
$password = "gf3qAdOPH1l9YtSp";
$dbname = "fagprojekt";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($_POST["selectgroup"]) {
$groupID = $_POST["selectgroup"];
$sql = "SELECT ID, name, type FROM `devices` WHERE `groupID` LIKE '".$groupID."'";
$result = $conn->query($sql);
$options;
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$options[$row["ID"]]["type"] = $row["type"];
$options[$row["ID"]]["name"] = $row["name"];
}
} else {
// echo "0 results";
}
//var_dump($options);
foreach ($options as $key => $value) {
if ($value["type"] == "relay") {
echo "<option value=".$key."current>current ".$value["name"]."</option>";
}
}
foreach ($options as $key => $value) {
if ($value["type"] == "relay") {
echo "<option value=".$key."voltage>voltage ".$value["name"]."</option>";
}
}
foreach ($options as $key => $value) {
if ($value["type"] == "relay") {
echo "<option value=".$key."power>power ".$value["name"]."</option>";
}
}
foreach ($options as $key => $value) {
if ($value["type"] == "sensor") {
echo "<option value=".$key."temp>temp ".$value["name"]."</option>";
}
}
foreach ($options as $key => $value) {
if ($value["type"] == "sensor") {
echo "<option value=".$key."light>light ".$value["name"]."</option>";
}
}
foreach ($options as $key => $value) {
if ($value["type"] == "sensor") {
echo "<option value=".$key."motion>motion ".$value["name"]."</option>";
}
}
}
elseif ($_POST["selecttype"]) {
$type = "";
if ($_POST["selecttype"] == "voltage" || $_POST["selecttype"] == "current" || $_POST["selecttype"] == "power") $type = "relay";
elseif ($_POST["selecttype"] == "motion" || $_POST["selecttype"] == "light" || $_POST["selecttype"] == "temp") $type = "sensor";
$sql = "SELECT ID, name, groupID FROM `devices` WHERE `type` LIKE '".$type."'";
$result = $conn->query($sql);
$options;
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$options[$row["ID"]]["groupID"] = $row["groupID"];
$options[$row["ID"]]["name"] = $row["name"];
}
} else {
// echo "0 results";
}
$group2name;
$sql = "SELECT ID, name FROM `groups`";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$group2name[$row['ID']] = $row['name'];
}
}
echo "<option value=0".$_POST["selecttype"].">Sum af gns for hvert minut</option>";
foreach ($options as $key => $value) {
echo "<option value=".$key.$_POST["selecttype"].">".$group2name[$value["groupID"]]." ".$value["name"]."</option>";
}
}
$conn->close();
?>