Sat, 09 Aug 2014 11:29:02 +0200
Code cleanup
134
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
1 | <?php |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
2 | /***************************************************************************** |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
3 | * Copyright (C) 2014 |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
4 | * |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
5 | * Michiel Broek <mbroek at mbse dot eu> |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
6 | * |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
7 | * This file is part of ThermFerm |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
8 | * |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
9 | * This is free software; you can redistribute it and/or modify it |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
10 | * under the terms of the GNU General Public License as published by the |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
11 | * Free Software Foundation; either version 2, or (at your option) any |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
12 | * later version. |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
13 | * |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
14 | * ThermFerm is distributed in the hope that it will be useful, but |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
15 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
17 | * General Public License for more details. |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
18 | * |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
19 | * You should have received a copy of the GNU General Public License |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
20 | * along with ThermFerm; see the file COPYING. If not, write to the Free |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
21 | * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
22 | *****************************************************************************/ |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
23 | |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
24 | require_once('utilities.php'); |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
25 | |
174 | 26 | /* |
27 | * $arr contains the complete reply of the LIST BUS command | |
28 | */ | |
196 | 29 | $answer = send_cmd("DEVICE LIST"); |
134
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
30 | $arr = explode("\r\n", $answer); |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
31 | |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
32 | |
174 | 33 | if (isset($_GET['action'])) { |
34 | switch ($_GET['action']) { | |
35 | case 'edit': device_edit(); | |
36 | break; | |
37 | default: break; | |
38 | } | |
39 | } elseif (isset($_POST['action'])) { | |
40 | switch ($_POST['action']) { | |
41 | case 'testdata': testdata(); | |
42 | break; | |
43 | default: break; | |
44 | } | |
45 | } else { | |
46 | device_list(); | |
47 | } | |
48 | ||
49 | exit; | |
50 | ||
51 | /**************************************************************************** | |
52 | * | |
53 | */ | |
54 | ||
55 | ||
56 | /* | |
57 | * Device add | |
58 | * | |
59 | * @param string $_POST['Name'] The rpofile name | |
60 | */ | |
61 | function device_add() { | |
62 | ||
63 | if ($_POST['key'] == 'Add') { | |
64 | ||
65 | $cmd = "DEVICE ADD ".$_POST['Type']; | |
134
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
66 | |
174 | 67 | $sock = open_socket(); |
68 | if ($sock != false) { | |
69 | /* | |
70 | * Send command and absorb the result. | |
71 | */ | |
72 | socket_write($sock, $cmd, 4096); | |
73 | while (1) { | |
74 | $line = socket_read($sock, 4096); | |
75 | if ($line === '') | |
76 | break; | |
77 | } | |
78 | socket_close($sock); | |
79 | } | |
80 | } | |
81 | ||
82 | unset($_POST['UUID']); | |
83 | unset($_POST['Name']); | |
84 | unset($_POST['key']); | |
85 | unset($_POST['command']); | |
86 | load('devices.php'); | |
87 | } | |
88 | ||
89 | ||
90 | ||
91 | /* | |
92 | * Device update | |
93 | * | |
94 | * @param string $_POST['UUID'] The device UUID | |
95 | * @param string $_POST['Type'] The device Type | |
96 | * @param string $_POST['Direction'] The device IO Direction | |
97 | * @param string $_POST['Value'] The device value | |
98 | * @param string $_POST['Present'] The device Present state | |
99 | * @param string $_POST['Address'] The device Address | |
100 | * @param string $_POST['Subdevice'] The device Subaddress | |
101 | * @param string $_POST['Gpiopin'] The device GPIO pin | |
102 | * @param string $_POST['Description'] The device Description | |
103 | * @param string $_POST['Comment'] The device Comment | |
104 | * @param string $_POST['key'] The button pressed. | |
105 | */ | |
106 | function device_update() { | |
107 | /* | |
108 | * Build the update command | |
109 | */ | |
110 | if ($_POST['key'] == 'Delete') { | |
196 | 111 | send_cmd("DEVICE DEL ".$_POST['UUID']); |
174 | 112 | } |
134
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
113 | |
174 | 114 | if ($_POST['key'] == 'Save') { |
115 | $sock = open_socket(); | |
116 | if ($sock != false) { | |
117 | /* | |
118 | * Send command and absorb the result. | |
119 | */ | |
120 | socket_write($sock, "DEVICE PUT ".$_POST['UUID'], 4096); | |
121 | usleep(20000); | |
122 | socket_write($sock, "TYPE,".$_POST['Type'], 4096); | |
123 | usleep(20000); | |
124 | socket_write($sock, "DIRECTION,".$_POST['Direction'], 4096); | |
125 | usleep(20000); | |
126 | socket_write($sock, "VALUE,".$_POST['Value'], 4096); | |
127 | usleep(20000); | |
128 | socket_write($sock, "PRESENT,".$_POST['Present'], 4096); | |
129 | usleep(20000); | |
130 | socket_write($sock, "ADDRESS,".$_POST['Address'], 4096); | |
131 | usleep(20000); | |
132 | socket_write($sock, "SUBDEVICE,".$_POST['Subdevice'], 4096); | |
133 | usleep(20000); | |
134 | socket_write($sock, "GPIOPIN,".$_POST['Gpiopin'], 4096); | |
135 | usleep(20000); | |
136 | socket_write($sock, "DESCRIPTION,".$_POST['Description'], 4096); | |
137 | usleep(20000); | |
138 | socket_write($sock, "COMMENT,".$_POST['Comment'], 4096); | |
139 | usleep(20000); | |
140 | socket_write($sock, '.', 4096); | |
141 | /* Absorb response */ | |
142 | while (1) { | |
143 | $line = socket_read($sock, 4096); | |
144 | if ($line === '') | |
145 | break; | |
146 | } | |
147 | socket_close($sock); | |
148 | } | |
149 | } | |
150 | ||
151 | unset($_POST['UUID']); | |
152 | unset($_POST['Type']); | |
153 | unset($_POST['Direction']); | |
154 | unset($_POST['Value']); | |
155 | unset($_POST['Present']); | |
156 | unset($_POST['Address']); | |
157 | unset($_POST['Subdevice']); | |
158 | unset($_POST['Gpiopin']); | |
159 | unset($_POST['Description']); | |
160 | unset($_POST['Comment']); | |
161 | unset($_POST['key']); | |
162 | unset($_POST['command']); | |
163 | load('devices.php'); | |
164 | } | |
165 | ||
166 | ||
167 | ||
168 | /* | |
169 | * Test input of a modified or new device. | |
170 | * | |
171 | * @param string $_POST['UUID'] Unique record UUID | |
172 | * @param string $_POST['Type'] Device Type | |
173 | * @param string $_POST['Direction'] | |
174 | * @param string $_POST['Value'] | |
175 | * @param string $_POST['Present'] | |
176 | * @param string $_POST['Address'] | |
177 | * @param string $_POST['Subdevice'] | |
178 | * @param string $_POST['Gpiopin'] | |
179 | * @param string $_POST['Description'] | |
180 | * @param string $_POST['Comment'] | |
181 | * @param string $_POST['key'] Key choice, Save or Cancel | |
182 | * @param string $_POST['command'] Command used, 'add' or 'update' | |
183 | * | |
184 | * Return: 0 = Ok | |
185 | * 1 = Missing data | |
186 | * 2 = Address field too short | |
187 | * 3 = Address/Subdevice already in use | |
188 | * 4 = Description field too short | |
189 | * 5 = Comment field too short | |
190 | * 99 = Cancel key | |
191 | */ | |
192 | function test_thedata() { | |
193 | ||
194 | global $arr; | |
195 | ||
196 | if (isset($_POST['UUID']) && isset($_POST['Type']) && isset($_POST['Direction']) && isset($_POST['Value']) && | |
197 | isset($_POST['Present']) && isset($_POST['Address']) && isset($_POST['Subdevice']) && isset($_POST['Gpiopin']) && | |
198 | isset($_POST['Description']) && isset($_POST['Comment']) && isset($_POST['key']) && isset($_POST['command'])) { | |
199 | ||
200 | if ($_POST['key'] == 'Cancel') | |
201 | return 99; | |
202 | ||
203 | if (strlen($_POST['Address']) < 2) | |
204 | return 2; | |
205 | ||
206 | if (startsWith($arr[0], "212")) { | |
207 | $j = 1; | |
208 | while (1) { | |
209 | if (strcmp($arr[$j], ".") == 0) | |
210 | break; | |
211 | $f = explode(",", $arr[$j]); | |
212 | if (strcmp($f[0], $_POST['UUID']) && ($f[1] == $_POST['Address']) && ($f[2] == $_POST['Subdevice'])) { | |
213 | return 3; | |
214 | } | |
215 | $j++; | |
216 | } | |
217 | } | |
218 | ||
219 | if (strlen($_POST['Description']) < 2) | |
220 | return 4; | |
221 | ||
222 | if (strlen($_POST['Comment']) < 2) | |
223 | return 5; | |
224 | ||
225 | } else { | |
226 | return 1; | |
227 | } | |
228 | ||
229 | return 0; | |
230 | } | |
231 | ||
232 | ||
233 | ||
234 | /* | |
235 | * Test result from edit screen and do next action | |
236 | */ | |
237 | function testdata() { | |
238 | ||
239 | $result = test_thedata(); | |
240 | $error = ''; | |
134
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
241 | |
174 | 242 | switch ($result) { |
243 | case 0: if ($_POST['command'] == 'add') { | |
244 | device_add(); | |
245 | return; | |
246 | } else if ($_POST['command'] == 'update') { | |
247 | device_update(); | |
248 | return; | |
249 | } | |
250 | break; | |
251 | case 1: $error = 'Missing data'; | |
252 | break; | |
253 | case 2: $error = 'The Address is too short'; | |
254 | break; | |
255 | case 3: $error = 'The Address + Subdevice is already in use, choose another one'; | |
256 | break; | |
257 | case 4: $error = 'The Description is too short'; | |
258 | break; | |
259 | case 5: $error = 'The Comment is too short'; | |
260 | break; | |
261 | case 99: | |
262 | load('devices.php'); | |
263 | break; | |
264 | } | |
265 | ||
266 | if ($_POST['command'] == 'add') { | |
267 | $heading = 'ThermFerm - Add Device'; | |
268 | } else { | |
269 | $heading = 'ThermFerm - Edit Device'; | |
270 | } | |
271 | ||
272 | edit_screen($_POST['UUID'], $_POST['command'], $heading, $error); | |
273 | } | |
274 | ||
275 | ||
276 | ||
277 | /* | |
278 | * Unit edit screen. Used by unit_edit(), unit_add() and testdata() | |
279 | * | |
280 | * @param string $UUID The record UUID (fixed). | |
281 | * @param string $command 'add' or 'update' | |
282 | * @param string $heading Page heading title. | |
283 | * @Param string $error_message Blank or previous error. | |
284 | */ | |
285 | function edit_screen($UUID, $command, $heading, $error_message) { | |
286 | ||
196 | 287 | $answer = send_cmd("DEVICE GET ".$UUID); |
174 | 288 | $reply = explode("\r\n", $answer); |
289 | ||
290 | $outstr = build_header($heading); | |
291 | $outstr .= ' <div id="errors">'.PHP_EOL; | |
292 | $outstr .= ' '.$error_message.PHP_EOL; | |
293 | $outstr .= ' </div> <!-- errors -->'.PHP_EOL; | |
294 | $outstr .= ' <div id="etable">'.PHP_EOL; | |
295 | $outstr .= ' <form method="POST" action="devices.php">'.PHP_EOL; | |
296 | $outstr .= ' <table class="editor">'.PHP_EOL; | |
297 | ||
298 | if (startsWith($reply[0], "213")) { | |
299 | $j = 1; | |
300 | while (1) { | |
301 | if (strcmp($reply[$j], ".") == 0) | |
302 | break; | |
303 | $f = explode(",", $reply[$j]); | |
304 | if ($f[0] == "TYPE") { | |
305 | $type = $f[1]; | |
306 | /* | |
307 | * Only allow certain types to edit. Auto detected hardware cannot be changed. | |
308 | */ | |
309 | $outstr .= ' <tr class="editor">'.PHP_EOL; | |
310 | $outstr .= ' <td class="editname">Device Type</td>'.PHP_EOL; | |
311 | if (($type == "W1") || ($type == "GPIO")) | |
312 | $outstr .= ' <td class="editfield"><input type="hidden" name="Type" value="'.$f[1].'">'.$f[1].'</td>'.PHP_EOL; | |
313 | else | |
314 | $outstr .= ' <td class="editfield"><input type="text" name="Type" size="50" value="'.$f[1].'"></td>'.PHP_EOL; | |
315 | $outstr .= ' </tr>'.PHP_EOL; | |
316 | } | |
317 | if ($f[0] == "DIRECTION") { | |
318 | $direction = $f[1]; | |
319 | /* | |
320 | * Only devices that cannot auto detect can be changed. | |
321 | */ | |
322 | $outstr .= ' <tr class="editor">'.PHP_EOL; | |
323 | $outstr .= ' <td class="editname">IO Direction and mode</td>'.PHP_EOL; | |
324 | if ($type == "W1") | |
325 | $outstr .= ' <td class="editfield"><input type="hidden" name="Direction" value="'.$f[1].'">'.$f[1].'</td>'.PHP_EOL; | |
326 | else { | |
327 | $outstr .= ' <td class="editfield"><select name="Direction">'.PHP_EOL; | |
328 | if ($type == "GPIO") { | |
329 | $se = ($f[1] == "UNDEF")?" selected":""; | |
330 | $outstr .= ' <option value="UNDEF"'.$se.'>Undefined</option>'.PHP_EOL; | |
331 | $se = ($f[1] == "IN_BIN")?" selected":""; | |
332 | $outstr .= ' <option value="IN_BIN"'.$se.'>Binary input</option>'.PHP_EOL; | |
333 | $se = ($f[1] == "OUT_BIN")?" selected":""; | |
334 | $outstr .= ' <option value="OUT_BIN"'.$se.'>Binary output</option>'.PHP_EOL; | |
335 | $se = ($f[1] == "OUT_PWM")?" selected":""; | |
336 | $outstr .= ' <option value="OUT_PWM"'.$se.'>PWM output</option>'.PHP_EOL; | |
337 | } | |
338 | if ($type == "RC433") { | |
339 | $se = ($f[1] == "UNDEF")?" selected":""; | |
340 | $outstr .= ' <option value="UNDEF"'.$se.'>Undefined</option>'.PHP_EOL; | |
341 | $se = ($f[1] == "OUT_BIN")?" selected":""; | |
342 | $outstr .= ' <option value="OUT_BIN"'.$se.'>Binary output</option>'.PHP_EOL; | |
343 | } | |
344 | if ($type == "DHT") { | |
345 | $se = ($f[1] == "UNDEF")?" selected":""; | |
346 | $outstr .= ' <option value="UNDEF"'.$se.'>Undefined</option>'.PHP_EOL; | |
347 | $se = ($f[1] == "IN_ANALOG")?" selected":""; | |
348 | $outstr .= ' <option value="IN_ANALOG"'.$se.'>Analog input</option>'.PHP_EOL; | |
349 | } | |
350 | $outstr .= ' </select></td>'.PHP_EOL; | |
351 | } | |
352 | $outstr .= ' </tr>'.PHP_EOL; | |
353 | } | |
354 | if ($f[0] == "VALUE") { | |
355 | /* | |
356 | * Only output can be changed | |
357 | */ | |
358 | $outstr .= ' <tr class="editor">'.PHP_EOL; | |
359 | $outstr .= ' <td class="editname">Value</td>'.PHP_EOL; | |
360 | if (($direction == "OUT_BIN") || ($direction == "OUT_ANALOG") || ($direction == "OUT_PWM")) | |
361 | $outstr .= ' <td class="editfield"><input type="text" name="Value" size="50" value="'.$f[1].'"></td>'.PHP_EOL; | |
362 | else | |
363 | $outstr .= ' <td class="editfield"><input type="hidden" name="Value" value="'.$f[1].'">'.$f[1].'</td>'.PHP_EOL; | |
364 | $outstr .= ' </tr>'.PHP_EOL; | |
365 | } | |
366 | if ($f[0] == "PRESENT") { | |
367 | /* | |
368 | * Only devices that cannot auto detect can be changed. | |
369 | */ | |
370 | $outstr .= ' <tr class="editor">'.PHP_EOL; | |
371 | $outstr .= ' <td class="editname">Device Present</td>'.PHP_EOL; | |
372 | if (($type == "W1") || ($type == "GPIO")) | |
373 | $outstr .= ' <td class="editfield"><input type="hidden" name="Present" value="'.$f[1].'">'.$f[1].'</td>'.PHP_EOL; | |
374 | else { | |
375 | $outstr .= ' <td class="editfield"><select name="Present">'.PHP_EOL; | |
376 | $se = ($f[1] == "UNDEF")?" selected":""; | |
377 | $outstr .= ' <option value="UNDEF"'.$se.'>Undefined</option>'.PHP_EOL; | |
378 | $se = ($f[1] == "NO")?" selected":""; | |
379 | $outstr .= ' <option value="NO"'.$se.'>Not present</option>'.PHP_EOL; | |
380 | $se = ($f[1] == "YES")?" selected":""; | |
381 | $outstr .= ' <option value="YES"'.$se.'>Present and Ok</option>'.PHP_EOL; | |
382 | $se = ($f[1] == "ERROR")?" selected":""; | |
383 | $outstr .= ' <option value="ERROR"'.$se.'>Present and Error</option>'.PHP_EOL; | |
384 | $outstr .= ' </select></td>'.PHP_EOL; | |
385 | } | |
386 | $outstr .= ' </tr>'.PHP_EOL; | |
387 | } | |
388 | if ($f[0] == "ADDRESS") { | |
389 | $outstr .= ' <tr class="editor">'.PHP_EOL; | |
390 | $outstr .= ' <td class="editname">Address</td>'.PHP_EOL; | |
391 | if (($type == "W1") || ($type == "GPIO")) | |
392 | $outstr .= ' <td class="editfield"><input type="hidden" name="Address" value="'.$f[1].'">'.$f[1].'</td>'.PHP_EOL; | |
393 | else | |
394 | $outstr .= ' <td class="editfield"><input type="text" name="Address" size="50" value="'.$f[1].'"></td>'.PHP_EOL; | |
395 | $outstr .= ' </tr>'.PHP_EOL; | |
396 | } | |
397 | if ($f[0] == "SUBDEVICE") { | |
398 | $outstr .= ' <tr class="editor">'.PHP_EOL; | |
399 | $outstr .= ' <td class="editname">Subdevice</td>'.PHP_EOL; | |
400 | if (($type == "W1") || ($type == "GPIO")) | |
401 | $outstr .= ' <td class="editfield"><input type="hidden" name="Subdevice" value="'.$f[1].'">'.$f[1].'</td>'.PHP_EOL; | |
402 | else | |
403 | $outstr .= ' <td class="editfield"><input type="text" name="Subdevice" size="5" value="'.$f[1].'"></td>'.PHP_EOL; | |
404 | $outstr .= ' </tr>'.PHP_EOL; | |
405 | } | |
406 | if ($f[0] == "GPIOPIN") { | |
407 | $outstr .= ' <tr class="editor">'.PHP_EOL; | |
408 | $outstr .= ' <td class="editname">GPIO pin</td>'.PHP_EOL; | |
409 | $outstr .= ' <td class="editfield"><input type="text" name="Gpiopin" size="5" value="'.$f[1].'"></td>'.PHP_EOL; | |
410 | $outstr .= ' </tr>'.PHP_EOL; | |
411 | } | |
412 | if ($f[0] == "DESCRIPTION") { | |
413 | $outstr .= ' <tr class="editor">'.PHP_EOL; | |
414 | $outstr .= ' <td class="editname">Description</td>'.PHP_EOL; | |
415 | $outstr .= ' <td class="editfield"><input type="text" name="Description" size="50" value="'.$f[1].'"></td>'.PHP_EOL; | |
416 | $outstr .= ' </tr>'.PHP_EOL; | |
417 | } | |
418 | if ($f[0] == "COMMENT") { | |
419 | $outstr .= ' <tr class="editor">'.PHP_EOL; | |
420 | $outstr .= ' <td class="editname">Comment</td>'.PHP_EOL; | |
421 | $outstr .= ' <td class="editfield"><input type="text" name="Comment" size="50" value="'.$f[1].'"></td>'.PHP_EOL; | |
422 | $outstr .= ' </tr>'.PHP_EOL; | |
423 | } | |
424 | $j++; | |
425 | } | |
426 | } | |
427 | ||
428 | $outstr .= ' <tr class="editor">'.PHP_EOL; | |
429 | $outstr .= ' <td class="editname"><input type="submit" value="Save" name="key"></td>'.PHP_EOL; | |
430 | $outstr .= ' <td class="editfield"><input type="submit" value="Cancel" name="key">'; | |
431 | $outstr .= '<input type="submit" value="Delete" name="key" style="margin-left: 100px;">'; | |
432 | $outstr .= '<input type="hidden" value="testdata" name="action">'; | |
433 | $outstr .= '<input type="hidden" value="'.$command.'" name="command">'; | |
434 | $outstr .= '<input type="hidden" value="'.$UUID.'" name="UUID"></td>'.PHP_EOL; | |
435 | $outstr .= ' </tr>'.PHP_EOL; | |
436 | $outstr .= ' </table>'.PHP_EOL; | |
437 | $outstr .= ' </form>'.PHP_EOL; | |
438 | $outstr .= ' </div> <!-- etable -->'.PHP_EOL; | |
439 | $outstr .= build_footer(); | |
440 | echo $outstr; | |
441 | } | |
442 | ||
443 | ||
444 | ||
445 | /* | |
446 | * Edit a Device. Fetches the record data and shows the edit screen. | |
447 | * | |
448 | * @param string $_GET['action'] Must be 'edit'. | |
449 | * @param string $_GET['UUID'] The UUID of the Unit. | |
450 | */ | |
451 | function device_edit() { | |
452 | if ($_GET['action'] == 'edit') { | |
453 | edit_screen($_GET['UUID'], 'update', 'ThermFerm - Edit Device', ''); | |
454 | return; | |
455 | } else { | |
456 | load('devices.php'); | |
134
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
457 | } |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
458 | } |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
459 | |
174 | 460 | |
461 | ||
462 | /* | |
463 | * @link edit device | |
464 | * @link add device | |
465 | */ | |
466 | function device_list() { | |
467 | global $arr; | |
468 | ||
469 | $outstr = build_header("ThermFerm - Devices Setup"); | |
470 | $outstr .= ' <div id="errors">'.PHP_EOL; | |
471 | $outstr .= ' </div> <!-- errors -->'.PHP_EOL; | |
472 | $outstr .= ' <div id="etable">'.PHP_EOL; | |
473 | $outstr .= ' <table class="setup">'.PHP_EOL; | |
474 | $outstr .= ' <tr class="trhead">'.PHP_EOL; | |
475 | $outstr .= ' <td class="setup" style="width: 300px;">UUID</td>'.PHP_EOL; | |
476 | $outstr .= ' <td class="setup" style="width: 120px;">Address</td>'.PHP_EOL; | |
477 | $outstr .= ' <td class="setup" style="width: 30px;">Sub</td>'.PHP_EOL; | |
478 | $outstr .= ' <td class="setup" style="width: 30px;">Ref</td>'.PHP_EOL; | |
479 | $outstr .= ' <td class="setup" style="width: 300px;">Cmt</td>'.PHP_EOL; | |
480 | $outstr .= ' <td class="setup" style="width: 35px;">Edit</td>'.PHP_EOL; | |
481 | $outstr .= ' </tr>'.PHP_EOL; | |
134
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
482 | |
174 | 483 | if (startsWith($arr[0], "212")) { |
484 | $j = 1; | |
485 | while (1) { | |
486 | if (strcmp($arr[$j], ".") == 0) | |
487 | break; | |
488 | $f = explode(",", $arr[$j]); | |
489 | $outstr .= ' <tr class="setup">'.PHP_EOL; | |
490 | $outstr .= ' <td class="setup">'.$f[0].'</td>'.PHP_EOL; | |
491 | $outstr .= ' <td class="setup">'.$f[1].'</td>'.PHP_EOL; | |
492 | $outstr .= ' <td class="setup">'.$f[2].'</td>'.PHP_EOL; | |
493 | $outstr .= ' <td class="setup">'.$f[3].'</td>'.PHP_EOL; | |
494 | $outstr .= ' <td class="setup">'.$f[4].'</td>'.PHP_EOL; | |
495 | if ($f[3] == 0) | |
496 | $outstr .= ' <td class="setup"><a href="devices.php?action=edit&UUID='.$f[0].'">Edit</a></td>'.PHP_EOL; | |
497 | else | |
498 | $outstr .= ' <td class="setup">Busy</td>'.PHP_EOL; | |
499 | $outstr .= ' </tr>'.PHP_EOL; | |
500 | $j++; | |
501 | } | |
502 | } | |
503 | ||
504 | $outstr .= ' </table>'.PHP_EOL; | |
505 | $outstr .= ' </div> <!-- etable -->'.PHP_EOL; | |
134
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
506 | |
174 | 507 | $outstr .= ' <div id="atable">'.PHP_EOL; |
508 | $outstr .= ' <form method="POST" action="devices.php">'.PHP_EOL; | |
509 | $outstr .= ' <table class="editor">'.PHP_EOL; | |
510 | $outstr .= ' <tr class="trhead"><td colspan="3">Add new Device</td></tr>'.PHP_EOL; | |
511 | $outstr .= ' <tr class="editor">'.PHP_EOL; | |
512 | $outstr .= ' <td class="editname">Select Device type</td>'.PHP_EOL; | |
513 | $outstr .= ' <td class="editfield">'.PHP_EOL; | |
514 | $outstr .= ' <select name="Type">'.PHP_EOL; | |
515 | $outstr .= ' <option value="NA">Not Available</option>'.PHP_EOL; | |
516 | $outstr .= ' <option value="RC433">433 Mhz Radio Controller</option>'.PHP_EOL; | |
517 | $outstr .= ' <option value="DHT">DHTnn type sensor</option>'.PHP_EOL; | |
518 | $outstr .= ' <option value="I2C">I2C bus device</option>'.PHP_EOL; | |
519 | $outstr .= ' <option value="SPI">SPI bus device</option>'.PHP_EOL; | |
520 | $outstr .= ' </select>'.PHP_EOL; | |
521 | $outstr .= ' </td>'.PHP_EOL; | |
522 | $outstr .= ' <td class="editsub"><input type="submit" value="Add" name="key"></td>'.PHP_EOL; | |
523 | $outstr .= '<input type="hidden" value="testdata" name="action">'; | |
524 | $outstr .= '<input type="hidden" value="add" name="command">'; | |
525 | $outstr .= '<input type="hidden" value="00000000-0000-0000-0000-000000000000" name="UUID">'; | |
526 | $outstr .= '<input type="hidden" value="UNDEF" name="Direction">'; | |
527 | $outstr .= '<input type="hidden" value="0" name="Value">'; | |
528 | $outstr .= '<input type="hidden" value="UNDEF" name="Present">'; | |
529 | $outstr .= '<input type="hidden" value="address unknown" name="Address">'; | |
530 | $outstr .= '<input type="hidden" value="0" name="Subdevice">'; | |
531 | $outstr .= '<input type="hidden" value="-1" name="Gpiopin">'; | |
532 | $outstr .= '<input type="hidden" value="Describe me" name="Description">'; | |
533 | $outstr .= '<input type="hidden" value="Comment me" name="Comment">'; | |
534 | $outstr .= ' </tr>'.PHP_EOL; | |
535 | $outstr .= ' </table>'.PHP_EOL; | |
536 | $outstr .= ' </form>'.PHP_EOL; | |
537 | $outstr .= ' </div> <!-- atable -->'.PHP_EOL; | |
538 | ||
539 | $outstr .= build_footer(); | |
540 | ||
541 | echo $outstr; | |
542 | } | |
543 |