-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsensor_funct.php
180 lines (169 loc) · 5.81 KB
/
sensor_funct.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
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
<?php
include('config.php');
function lastreading()
{
global $link;
$query = "SELECT symbol, name, id FROM `sensorsg` WHERE active=1 ORDER BY symbol ASC";
if ($result = mysqli_query($link, $query)) {
echo '<table class="table table-striped"><th>Czujnik</th><th>Nazwa</th><th>Odczyt</th><th></th>';
while ($row = mysqli_fetch_array($result)) {
$id = $row['id'];
echo '<tr>';
echo '<td>' . $row['symbol'] . '</td>';
echo '<td>' . $row['name'] . '</td>';
echo '<td>';
$subquery = "SELECT value FROM readg WHERE sensorid = " . $id . " ORDER BY date DESC LIMIT 1";
if ($subresult = mysqli_query($link, $subquery)) {
while ($subrow = mysqli_fetch_array($subresult)) {
echo liczba($subrow['value']);
}
}
?>
</td>
<td>
<form action="/details.php" method="get">
<input type="hidden" name="s" value="<? echo $id; ?>">
<button type="submit" class="btn btn-primary btn-xs btn-info">
Szczegóły
</button>
</form>
<?
echo "</td></tr>\n";
}
/* free result set */
mysqli_free_result($result);
echo '</table>';
} else {
echo "0";
}
}
function detailedreadings($s)
{
global $link;
$lp = 1;
$query = "SELECT value, date FROM readg WHERE sensorid = " . $s . " ORDER BY date DESC LIMIT 150";
if ($result = mysqli_query($link, $query)) {
echo '<table class="table table-condensed table-hover"><th>Lp.</th><th>Godzina</th><th>Odczyt</th>';
while ($row = mysqli_fetch_array($result)) {
echo '<tr>';
echo '<td>' . $lp++ . '</td>';
echo '<td>' . $row['date'] . '</td>';
echo '<td>' . liczba($row['value']) . '</td>';
echo "</tr>\n";
}
/* free result set */
mysqli_free_result($result);
echo '</table>';
} else {
echo "0";
}
}
function sensordata($s)
{
global $link;
$query = "SELECT symbol, name, address, pinid, active, minimum, maximum FROM `sensorsg` WHERE id = " . $s . "";
if ($result = mysqli_query($link, $query)) {
echo '<table class="table table-striped"><th>Ustawienie</th><th>Wartość</th></tr>';
while ($row = mysqli_fetch_array($result)) {
echo '<tr><td>Symbol<td>' . $row['symbol'] . '</td></tr>';
echo '<tr><td>Nazwa<td>' . $row['name'] . '</td></tr>';
echo '<tr><td>Złącze<td>' . $row['pinid'] . '</td></tr>';
echo '<tr><td>Adres<td>' . $row['address'] . '</td></tr>';
echo '<tr><td>Minimum<td>' . $row['minimum'] . '</td></tr>';
echo '<tr><td>Maksimum<td>' . $row['maximum'] . '</td></tr>';
echo '<tr><td>Aktywny<td><input type="checkbox" disabled name="active" value="active"';
if ($row['active'] == 1)
echo ' checked ';
echo '></td></tr>';
}
/* free result set */
mysqli_free_result($result);
echo '</table>';
?>
<form action="/sensoredit.php" method="get">
<input type="hidden" name="s" value="<? echo $s; ?>">
<input type="hidden" name="type" value="edit">
<button type="submit" class="btn btn-primary btn-info">
Edytuj
</button>
</form>
<?
} else {
echo "0";
}
}
function sensoredit($s, $type)
{
global $link;
$query = "SELECT symbol, name, address, pinid, active, minimum, maximum FROM `sensorsg` WHERE id = " . $s . "";
if ($result = mysqli_query($link, $query)) {
echo '<form action="/settingssave.php" method="post">';
echo '<table class="table table-striped"><th>Ustawienie</th><th>Wartość</th></tr>';
// while ($row = mysqli_fetch_array($result)) {
$row = mysqli_fetch_array($result);
echo '<tr><td>Symbol</td><td><input type="text" required maxlength="5" name="symbol" value="' . $row['symbol'] . '"></td></tr>';
echo '<tr><td>Nazwa</td><td><input type="text" required size="30" maxlength="30" name="name" value="' . $row['name'] . '"></td></tr>';
echo '<tr><td>Złącze (od 1 do 5)</td><td><input type="number" required size="5" name="pinid" min="1" max="5" value="' . $row['pinid'] . '"></td></tr>';
echo '<tr><td>Adres<br>(8 znaków hex)</td><td><input type="text" required size="35" name="address" value="' . $row['address'] . '"></td></tr>';
echo '<tr><td>Minimum</td><td><input type="number" size="5" name="minimum" min="0" max="100" value="' . $row['minimum'] . '"></td></tr>';
echo '<tr><td>Maksimum</td><td><input type="number" size="5" name="maximum" min="0" max="100" value="' . $row['maximum'] . '"></td></tr>';
echo '<tr><td>Aktywny</td><td><input type="checkbox" name="active" value="active"';
if ($row['active'] == 1)
echo ' checked ';
if ($type == 'new')
echo ' checked ';
echo '></td></tr>';
// }
/* free result set */
mysqli_free_result($result);
echo '</table>';
?>
<input type="hidden" name="s" value="<? echo $s; ?>">
<input type="hidden" name="type" value="<? echo $type; ?>">
<button type="submit" class="btn btn-primary btn-info">
Zapisz
</button>
</form>
<?
} else {
echo "0";
}
}
function sensorlist($active)
{
global $link;
$query = "SELECT symbol, name, id FROM `sensorsg` WHERE active='$active' ORDER BY symbol ASC";
if ($result = mysqli_query($link, $query)) {
echo '<table class="table table-striped"><th>Czujnik</th><th>Nazwa</th><th>Odczyt</th><th></th>';
while ($row = mysqli_fetch_array($result)) {
$id = $row['id'];
echo '<tr>';
echo '<td>' . $row['symbol'] . '</td>';
echo '<td>' . $row['name'] . '</td>';
echo '<td>';
$subquery = "SELECT value FROM readg WHERE sensorid = " . $id . " ORDER BY date DESC LIMIT 1";
if ($subresult = mysqli_query($link, $subquery)) {
while ($subrow = mysqli_fetch_array($subresult)) {
echo liczba($subrow['value']);
}
}
?>
</td>
<td>
<form action="/details.php" method="get">
<input type="hidden" name="s" value="<? echo $id; ?>">
<button type="submit" class="btn btn-primary btn-xs btn-info">
Szczegóły
</button>
</form>
<?php
echo '</td></tr>';
}
/* free result set */
mysqli_free_result($result);
echo '</table>';
} else {
echo "0";
}
}
?>