www-thermferm/units.php

changeset 709
5b6d7b640e52
parent 708
13555c27b592
child 710
abe60578d695
equal deleted inserted replaced
708:13555c27b592 709:5b6d7b640e52
1 <?php
2 /*****************************************************************************
3 * Copyright (C) 2014-2019
4 *
5 * Michiel Broek <mbroek at mbse dot eu>
6 *
7 * This file is part of ThermFerm
8 *
9 * This is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation; either version 2, or (at your option) any
12 * later version.
13 *
14 * ThermFerm is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with ThermFerm; see the file COPYING. If not, write to the Free
21 * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
22 *****************************************************************************/
23
24 require_once('utilities.php');
25
26
27 /*
28 * $arr contains the complete reply of the LIST command.
29 */
30 $answer = send_cmd("UNIT LIST");
31 $arr = explode("\r\n", $answer);
32
33
34 if (isset($_GET['action'])) {
35 switch ($_GET['action']) {
36 case 'edit': unit_edit();
37 break;
38 default: break;
39 }
40 } elseif (isset($_POST['action'])) {
41 switch ($_POST['action']) {
42 case 'testdata': testdata();
43 break;
44 default: break;
45 }
46 } else {
47 unit_list();
48 }
49
50 exit;
51
52 /****************************************************************************
53 *
54 */
55
56 /*
57 * Unit add
58 *
59 * @param string $_POST['Name'] The product name
60 */
61 function unit_add() {
62
63 if ($_POST['key'] == 'Add') {
64 send_cmd("UNIT ADD ".$_POST['ProductName']);
65 }
66
67 unset($_POST['UUID']);
68 unset($_POST['ProductName']);
69 unset($_POST['key']);
70 unset($_POST['command']);
71 load('units.php');
72 }
73
74
75
76 /*
77 * Unit update
78 *
79 * @param string $_POST['UUID'] The unit UUID
80 * @param string $_POST['key'] The button pressed.
81 */
82 function unit_update() {
83 /*
84 * Build the update command
85 */
86 if ($_POST['key'] == 'Delete') {
87 send_cmd("UNIT DEL ".$_POST['UUID']);
88 }
89
90 if ($_POST['key'] == 'Save') {
91 $cmd = array("UNIT PUT ".$_POST['UUID']);
92 $cmd[] = "PRODUCT_CODE,".$_POST['ProductCode'];
93 $cmd[] = "PRODUCT_NAME,".$_POST['ProductName'];
94 $cmd[] = "VOLUME,".$_POST['Volume'];
95 $cmd[] = "STAGE,".$_POST['Stage'];
96 $cmd[] = "AIR_ADDRESS,".$_POST['AirAddress'];
97 $cmd[] = "AIR_IDX,".$_POST['AirIdx'];
98 $cmd[] = "BEER_ADDRESS,".$_POST['BeerAddress'];
99 $cmd[] = "BEER_IDX,".$_POST['BeerIdx'];
100 $cmd[] = "BEER_ADDRESS2,".$_POST['BeerAddress2'];
101 $cmd[] = "CHILLER_ADDRESS,".$_POST['ChillerAddress'];
102 $cmd[] = "CHILLER_IDX,".$_POST['ChillerIdx'];
103 $cmd[] = "HEATER_ADDRESS,".$_POST['HeaterAddress'];
104 $cmd[] = "HEATER_DELAY,".$_POST['HeaterDelay'];
105 $cmd[] = "HEATER_IDX,".$_POST['HeaterIdx'];
106 $cmd[] = "COOLER_ADDRESS,".$_POST['CoolerAddress'];
107 $cmd[] = "COOLER_DELAY,".$_POST['CoolerDelay'];
108 $cmd[] = "COOLER_IDX,".$_POST['CoolerIdx'];
109 $cmd[] = "FAN_ADDRESS,".$_POST['FanAddress'];
110 $cmd[] = "FAN_DELAY,".$_POST['FanDelay'];
111 $cmd[] = "FAN_IDX,".$_POST['FanIdx'];
112 $cmd[] = "LIGHT_ADDRESS,".$_POST['LightAddress'];
113 $cmd[] = "LIGHT_DELAY,".$_POST['LightDelay'];
114 $cmd[] = "LIGHT_IDX,".$_POST['LightIdx'];
115 $cmd[] = "DOOR_ADDRESS,".$_POST['DoorAddress'];
116 $cmd[] = "DOOR_IDX,".$_POST['DoorIdx'];
117 $cmd[] = "PSU_ADDRESS,".$_POST['PSUAddress'];
118 $cmd[] = "PSU_IDX,".$_POST['PSUIdx'];
119 $cmd[] = "TEMP_SET_MIN,".$_POST['TempSetMin'];
120 $cmd[] = "TEMP_SET_MAX,".$_POST['TempSetMax'];
121 $cmd[] = "PIDC_IMAX,".$_POST['PIDC_iMax'];
122 $cmd[] = "PIDC_PGAIN,".$_POST['PIDC_pGain'];
123 $cmd[] = "PIDC_DGAIN,".$_POST['PIDC_dGain'];
124 $cmd[] = "PIDC_IGAIN,".$_POST['PIDC_iGain'];
125 $cmd[] = "PIDC_IDLERANGE,".$_POST['PIDC_idleRange'];
126 $cmd[] = "PIDH_IMAX,".$_POST['PIDC_iMax'];
127 $cmd[] = "PIDH_PGAIN,".$_POST['PIDH_pGain'];
128 $cmd[] = "PIDH_DGAIN,".$_POST['PIDH_dGain'];
129 $cmd[] = "PIDH_IGAIN,".$_POST['PIDH_iGain'];
130 $cmd[] = "PIDH_IDLERANGE,".$_POST['PIDH_idleRange'];
131 $cmd[] = ".";
132 send_array($cmd);
133 }
134
135 unset($_POST['UUID']);
136 unset($_POST['ProductName']);
137 unset($_POST['ProductCode']);
138 unset($_POST['Volume']);
139 Unset($_POST['Stage']);
140 unset($_POST['key']);
141 unset($_POST['command']);
142 unset($_POST['AirAddress']);
143 unset($_POST['AirIdx']);
144 unset($_POST['BeerAddress']);
145 unset($_POST['BeerIdx']);
146 unset($_POST['ChillerAddress']);
147 unset($_POST['ChillerIdx']);
148 unset($_POST['HeaterAddress']);
149 unset($_POST['HeaterDelay']);
150 unset($_POST['HeaterIdx']);
151 unset($_POST['CoolerAddress']);
152 unset($_POST['CoolerDelay']);
153 unset($_POST['CoolerIdx']);
154 unset($_POST['LightAddress']);
155 unset($_POST['LightDelay']);
156 unset($_POST['LightIdx']);
157 unset($_POST['FanAddress']);
158 unset($_POST['FanDelay']);
159 unset($_POST['FanIdx']);
160 unset($_POST['DoorAddress']);
161 unset($_POST['DoorIdx']);
162 unset($_POST['PSUAddress']);
163 unset($_POST['PSUIdx']);
164 unset($_POST['TempSetMin']);
165 unset($_POST['TempSetMax']);
166 unset($_POST['PIDC_iMax']);
167 unset($_POST['PIDC_pGain']);
168 unset($_POST['PIDC_dGain']);
169 unset($_POST['PIDC_iGain']);
170 unset($_POST['PIDC_idleRange']);
171 unset($_POST['PIDH_iMax']);
172 unset($_POST['PIDH_pGain']);
173 unset($_POST['PIDH_dGain']);
174 unset($_POST['PIDH_iGain']);
175 unset($_POST['PIDH_idleRange']);
176 load('units.php');
177 }
178
179
180
181 /*
182 * Test input of a modified or new fermentation unit.
183 *
184 * @param string $_POST['UUID'] Unique record UUID
185 * @param string $_POST['key'] Key choice, Save or Cancel
186 * @param string $_POST['command'] Command used, 'add' or 'update'
187 *
188 * Return: 0 = Ok
189 * 1 = Missing data
190 * // 2 = Name field too short
191 * // 3 = Name already in use
192 * 4 = TempSetMax <= TempSetMin
193 * 5 = TempSetMax < 25 or > 35
194 * 6 = TempSetMin < -5 or > 15
195 * 7 = HeaterDelay out of range
196 * 8 = CoolerDelay out of range
197 * 9 = PIDC idleRange out of range
198 * 10 = PIDH idleRange out of range
199 * 11 = LightDelay out of range
200 * 12 = FanDelay out of range
201 * 99 = Cancel key
202 */
203 function test_thedata() {
204
205 global $arr;
206
207 if (isset($_POST['UUID']) && isset($_POST['ProductCode']) && isset($_POST['ProductName']) && isset($_POST['Volume']) &&
208 isset($_POST['AirAddress']) && isset($_POST['ChillerAddress']) &&
209 isset($_POST['BeerAddress']) && isset($_POST['HeaterAddress']) &&
210 isset($_POST['CoolerAddress']) && isset($_POST['LightAddress']) &&
211 isset($_POST['HeaterDelay']) && isset($_POST['CoolerDelay']) && isset($_POST['LightDelay']) && isset($_POST['PSUAddress']) &&
212 isset($_POST['FanAddress']) && isset($_POST['DoorAddress']) && isset($_POST['TempSetMin']) && isset($_POST['TempSetMax']) &&
213 isset($_POST['PIDC_pGain']) && isset($_POST['PIDC_iGain']) && isset($_POST['PIDC_dGain']) && isset($_POST['PIDC_idleRange']) &&
214 isset($_POST['PIDH_pGain']) && isset($_POST['PIDH_iGain']) && isset($_POST['PIDH_dGain']) && isset($_POST['PIDH_idleRange']) &&
215 isset($_POST['PIDC_iMax']) && isset($_POST['PIDH_iMax']) && isset($_POST['AirIdx']) && isset($_POST['BeerIdx']) &&
216 isset($_POST['HeaterIdx']) && isset($_POST['CoolerIdx']) && isset($_POST['LightIdx']) && isset($_POST['DoorIdx']) &&
217 isset($_POST['PSUIdx']) && isset($_POST['FanIdx']) && isset($_POST['ChillerIdx']) && isset($_POST['Stage']) &&
218 isset($_POST['FanDelay']) && isset($_POST['key']) && isset($_POST['command'])) {
219
220 if ($_POST['key'] == 'Cancel')
221 return 99;
222
223 // if (strlen($_POST['Name']) < 2)
224 // return 2;
225
226 /* if (startsWith($arr[0], "212")) {
227 $j = 1;
228 while (1) {
229 if (strcmp($arr[$j], ".") == 0)
230 break;
231 $f = explode(",", $arr[$j]);
232 if (strcmp($f[0], $_POST['UUID']) && (strcmp($f[1], $_POST['Name']) == 0)) {
233 return 3;
234 }
235 $j++;
236 }
237 } */
238
239 if ($_POST['TempSetMax'] <= $_POST['TempSetMin'])
240 return 4;
241
242 if (($_POST['TempSetMax'] < 25) || ($_POST['TempSetMax'] > 45))
243 return 5;
244
245 if (($_POST['TempSetMin'] < -5) || ($_POST['TempSetMin'] > 15))
246 return 6;
247
248 if (($_POST['HeaterDelay'] < 0) || ($_POST['HeaterDelay'] > 720))
249 return 7;
250
251 if (($_POST['CoolerDelay'] < 0) || ($_POST['CoolerDelay'] > 720))
252 return 8;
253
254 if (($_POST['PIDC_idleRange'] < 0) || ($_POST['PIDC_idleRange'] > 5))
255 return 9;
256
257 if (($_POST['PIDH_idleRange'] < 0) || ($_POST['PIDH_idleRange'] > 5))
258 return 10;
259
260 if (($_POST['LightDelay'] < 0) || ($_POST['LightDelay'] > 720))
261 return 11;
262
263 if (($_POST['FanDelay'] < 0) || ($_POST['FanDelay'] > 720))
264 return 12;
265
266 } else {
267 return 1;
268 }
269
270 return 0;
271 }
272
273
274
275 /*
276 * Test result from edit screen and do next action
277 */
278 function testdata() {
279
280 $result = test_thedata();
281 $error = '';
282
283 switch ($result) {
284 case 0: if ($_POST['command'] == 'add') {
285 unit_add();
286 return;
287 } else if ($_POST['command'] == 'update') {
288 unit_update();
289 return;
290 }
291 break;
292 case 1: $error = 'Missing data';
293 break;
294 case 2: $error = 'The name is too short';
295 break;
296 case 3: $error = 'The name is already in use, choose another one';
297 break;
298 case 4: $error = 'Temperature Maximum cannot be smaller then Temperature Minimum';
299 break;
300 case 5: $error = 'Temperature Maximum must be between 25 and 45 &deg;C';
301 break;
302 case 6: $error = 'Temperature Minimum must be between -5 and 15 &deg;C';
303 break;
304 case 7: $error = 'Heater Delay must be bewteen 0 and 720 seconds';
305 break;
306 case 8: $error = 'Cooler Delay must be bewteen 0 and 720 seconds';
307 break;
308 case 9: $error = 'PID cool Idle Range must be between 0 en 5';
309 break;
310 case 10: $error = 'PID heat Idle Range must be between 0 and 5';
311 break;
312 case 11: $error = 'Light Delay must be bewteen 0 and 720 seconds';
313 break;
314 case 12: $error = 'Fan Delay must be bewteen 0 and 720 seconds';
315 break;
316 case 99:
317 load('units.php');
318 break;
319 }
320
321 if ($_POST['command'] == 'add') {
322 $heading = 'ThermFerm - Add Unit';
323 } else {
324 $heading = 'ThermFerm - Edit Unit';
325 }
326
327 edit_screen($_POST['UUID'], $_POST['command'], $heading, $error);
328 }
329
330
331
332 /*
333 * Unit edit screen. Used by unit_edit(), unit_add() and testdata()
334 *
335 * @param string $UUID The record UUID (fixed).
336 * @param string $command 'add' or 'update'
337 * @param string $heading Page heading title.
338 * @Param string $error_message Blank or previous error.
339 */
340 function edit_screen($UUID, $command, $heading, $error_message) {
341
342 /*
343 * Get list of devices, we need it later
344 */
345 $answer = send_cmd("DEVICE LIST");
346 $devices = explode("\r\n", $answer);
347
348 /*
349 * Get current unit data
350 */
351 $answer = send_cmd("UNIT GET ".$UUID);
352 $reply = explode("\r\n", $answer);
353
354 $outstr = build_header($heading);
355 $outstr .= ' <div id="errors">'.PHP_EOL;
356 $outstr .= ' '.$error_message.PHP_EOL;
357 $outstr .= ' </div> <!-- errors -->'.PHP_EOL;
358 $outstr .= ' <div id="etable">'.PHP_EOL;
359 $outstr .= ' <form method="POST" action="units.php">'.PHP_EOL;
360 $outstr .= ' <table class="editor">'.PHP_EOL;
361
362 if (startsWith($reply[0], "213")) {
363 $i = 1;
364 while (1) {
365 if (strcmp($reply[$i], ".") == 0)
366 break;
367 $f = explode(",", $reply[$i]);
368
369 if ($f[0] == "PRODUCT_CODE") {
370 $outstr .= ' <tr class="editor">'.PHP_EOL;
371 $outstr .= ' <td class="editname">Product Code</td>'.PHP_EOL;
372 $outstr .= ' <td colspan="3" class="editfield"><input type="text" name="ProductCode" size="32" value="'.$f[1].'"></td>'.PHP_EOL;
373 $outstr .= ' </tr>'.PHP_EOL;
374 }
375
376 if ($f[0] == "PRODUCT_NAME") {
377 $outstr .= ' <tr class="editor">'.PHP_EOL;
378 $outstr .= ' <td class="editname">Product Name</td>'.PHP_EOL;
379 $outstr .= ' <td colspan="3" class="editfield"><input type="text" name="ProductName" size="50" value="'.$f[1].'"></td>'.PHP_EOL;
380 $outstr .= ' </tr>'.PHP_EOL;
381 }
382
383 if ($f[0] == "STAGE") {
384 $outstr .= ' <tr class="editor">'.PHP_EOL;
385 $outstr .= ' <td class="editname">Fermentation</td>'.PHP_EOL;
386 $outstr .= ' <td class="editfield"><select name="Stage">'.PHP_EOL;
387 ($f[1] == "PRIMARY") ? $se = " selected" : $se = "";
388 $outstr .= ' <option value="PRIMARY"'.$se.'>Primary</option>'.PHP_EOL;
389 ($f[1] == "SECONDARY") ? $se = " selected" : $se = "";
390 $outstr .= ' <option value="SECONDARY"'.$se.'>Secondary</option>'.PHP_EOL;
391 ($f[1] == "TERTIARY") ? $se = " selected" : $se = "";
392 $outstr .= ' <option value="TERTIARY"'.$se.'>Tertiary</option>'.PHP_EOL;
393 ($f[1] == "CARBONATION") ? $se = " selected" : $se = "";
394 $outstr .= ' <option value="CARBONATION"'.$se.'>Carbonation</option>'.PHP_EOL;
395 $outstr .= ' </select></td>'.PHP_EOL;
396 }
397
398 if ($f[0] == "VOLUME") {
399 $outstr .= ' <td class="editname">Unit Volume</td>'.PHP_EOL;
400 $outstr .= ' <td class="editfield"><input type="text" name="Volume" size="5" value="'.$f[1].'"></td>'.PHP_EOL;
401 $outstr .= ' </tr>'.PHP_EOL;
402 }
403
404 if ($f[0] == "AIR_ADDRESS") {
405 $outstr .= ' <tr class="editor">'.PHP_EOL;
406 $outstr .= ' <td class="editname">Air Sensor Address</td>'.PHP_EOL;
407 $outstr .= ' <td class="editfield"><select name="AirAddress">'.PHP_EOL;
408 $outstr .= ' <option value="">Not Assigned</option>'.PHP_EOL;
409 if (startsWith($devices[0], "212")) {
410 $j = 1;
411 while (1) {
412 if (strcmp($devices[$j], ".") == 0)
413 break;
414 $g = explode(",", $devices[$j]);
415 if ($g[5] == "IN_ANALOG") {
416 ($f[1] == $g[0]) ? $se = " selected" : $se = "";
417 $outstr .= ' <option value="'.$g[0].'"'.$se.'>'.$g[1].' '.$g[4].'</option>'.PHP_EOL;
418 }
419 $j++;
420 }
421 }
422 $outstr .= ' </select></td>'.PHP_EOL;
423 }
424 if ($f[0] == "AIR_IDX") {
425 $outstr .= ' <td class="editname">Air domoticz idx</td>'.PHP_EOL;
426 $outstr .= ' <td class="editfield"><input type="text" name="AirIdx" size="5" value="'.$f[1].'"></td>'.PHP_EOL;
427 $outstr .= ' </tr>'.PHP_EOL;
428 }
429
430 if ($f[0] == "BEER_ADDRESS") {
431 $outstr .= ' <tr class="editor">'.PHP_EOL;
432 $outstr .= ' <td class="editname">Beer Sensor Address</td>'.PHP_EOL;
433 $outstr .= ' <td class="editfield"><select name="BeerAddress">'.PHP_EOL;
434 $outstr .= ' <option value="">Not Assigned</option>'.PHP_EOL;
435 if (startsWith($devices[0], "212")) {
436 $j = 1;
437 while (1) {
438 if (strcmp($devices[$j], ".") == 0)
439 break;
440 $g = explode(",", $devices[$j]);
441 if ($g[5] == "IN_ANALOG") {
442 ($f[1] == $g[0]) ? $se = " selected" : $se = "";
443 $outstr .= ' <option value="'.$g[0].'"'.$se.'>'.$g[1].' '.$g[4].'</option>'.PHP_EOL;
444 }
445 $j++;
446 }
447 }
448 $outstr .= ' </select></td>'.PHP_EOL;
449 }
450 if ($f[0] == "BEER_IDX") {
451 $outstr .= ' <td class="editname">Beer domoticz idx</td>'.PHP_EOL;
452 $outstr .= ' <td class="editfield"><input type="text" name="BeerIdx" size="5" value="'.$f[1].'"></td>'.PHP_EOL;
453 $outstr .= ' </tr>'.PHP_EOL;
454 }
455 if ($f[0] == "BEER_ADDRESS2") {
456 $outstr .= ' <tr class="editor">'.PHP_EOL;
457 $outstr .= ' <td class="editname">Beer Sensor Address (alt)</td>'.PHP_EOL;
458 $outstr .= ' <td colspan="3" class="editfield"><select name="BeerAddress2">'.PHP_EOL;
459 $outstr .= ' <option value="">Not Assigned</option>'.PHP_EOL;
460 if (startsWith($devices[0], "212")) {
461 $j = 1;
462 while (1) {
463 if (strcmp($devices[$j], ".") == 0)
464 break;
465 $g = explode(",", $devices[$j]);
466 if ($g[5] == "IN_ANALOG") {
467 ($f[1] == $g[0]) ? $se = " selected" : $se = "";
468 $outstr .= ' <option value="'.$g[0].'"'.$se.'>'.$g[1].' '.$g[4].'</option>'.PHP_EOL;
469 }
470 $j++;
471 }
472 }
473 $outstr .= ' </select></td></tr>'.PHP_EOL;
474 }
475
476 if ($f[0] == "CHILLER_ADDRESS") {
477 $outstr .= ' <tr class="editor">'.PHP_EOL;
478 $outstr .= ' <td class="editname">Chiller Sensor Address</td>'.PHP_EOL;
479 $outstr .= ' <td class="editfield"><select name="ChillerAddress">'.PHP_EOL;
480 $outstr .= ' <option value="">Not Assigned</option>'.PHP_EOL;
481 if (startsWith($devices[0], "212")) {
482 $j = 1;
483 while (1) {
484 if (strcmp($devices[$j], ".") == 0)
485 break;
486 $g = explode(",", $devices[$j]);
487 if ($g[5] == "IN_ANALOG") {
488 ($f[1] == $g[0]) ? $se = " selected" : $se = "";
489 $outstr .= ' <option value="'.$g[0].'"'.$se.'>'.$g[1].' '.$g[4].'</option>'.PHP_EOL;
490 }
491 $j++;
492 }
493 }
494 $outstr .= ' </select></td>'.PHP_EOL;
495 }
496 if ($f[0] == "CHILLER_IDX") {
497 $outstr .= ' <td class="editname">Chiller domoticz idx</td>'.PHP_EOL;
498 $outstr .= ' <td class="editfield"><input type="text" name="ChillerIdx" size="5" value="'.$f[1].'"></td>'.PHP_EOL;
499 $outstr .= ' </tr>'.PHP_EOL;
500 }
501
502 if ($f[0] == "HEATER_ADDRESS") {
503 $outstr .= ' <tr class="editor">'.PHP_EOL;
504 $outstr .= ' <td class="editname">Heater Switch Address</td>'.PHP_EOL;
505 $outstr .= ' <td class="editfield"><select name="HeaterAddress">'.PHP_EOL;
506 $outstr .= ' <option value="">Not Assigned</option>'.PHP_EOL;
507 if (startsWith($devices[0], "212")) {
508 $j = 1;
509 while (1) {
510 if (strcmp($devices[$j], ".") == 0)
511 break;
512 $g = explode(",", $devices[$j]);
513 if (($g[5] == "OUT_ANALOG") || ($g[5] == "OUT_BIN")) {
514 ($f[1] == $g[0]) ? $se = " selected" : $se = "";
515 $outstr .= ' <option value="'.$g[0].'"'.$se.'>'.$g[1].' '.$g[4].'</option>'.PHP_EOL;
516 }
517 $j++;
518 }
519 }
520 $outstr .= ' </select></td>'.PHP_EOL;
521 }
522 if ($f[0] == "HEATER_DELAY") {
523 $outstr .= ' <td class="editname">Heater Switch Delay</td>'.PHP_EOL;
524 $outstr .= ' <td class="editfield"><input type="text" name="HeaterDelay" size="5" value="'.$f[1].'"> seconds (0..720)</td>'.PHP_EOL;
525 $outstr .= ' </tr>'.PHP_EOL;
526 }
527
528 if ($f[0] == "HEATER_IDX") {
529 $outstr .= ' <tr class="editor">'.PHP_EOL;
530 $outstr .= ' <td class="editname">Heater domoticz idx</td>'.PHP_EOL;
531 $outstr .= ' <td class="editfield"><input type="text" name="HeaterIdx" size="5" value="'.$f[1].'"></td>'.PHP_EOL;
532 }
533 if ($f[0] == "PIDH_IMAX") {
534 $outstr .= ' <td class="editname">PID Heat Maximum</td>'.PHP_EOL;
535 $outstr .= ' <td class="editfield"><input type="text" name="PIDH_iMax" size="6" value="'.$f[1].'"> % (1..100)</td>'.PHP_EOL;
536 $outstr .= ' </tr>'.PHP_EOL;
537 }
538
539 if ($f[0] == "PIDH_IDLERANGE") {
540 $outstr .= ' <tr class="editor">'.PHP_EOL;
541 $outstr .= ' <td class="editname">Heater Idle Range</td>'.PHP_EOL;
542 $outstr .= ' <td class="editfield"><input type="text" name="PIDH_idleRange" size="6" value="'.$f[1].'"> &deg;C (Heater margin)</td>'.PHP_EOL;
543 }
544 if ($f[0] == "PIDH_PGAIN") {
545 $outstr .= ' <td class="editname">PID Heat pGain</td>'.PHP_EOL;
546 $outstr .= ' <td class="editfield"><input type="text" name="PIDH_pGain" size="6" value="'.$f[1].'"> Proportional</td>'.PHP_EOL;
547 $outstr .= ' </tr>'.PHP_EOL;
548 }
549
550 if ($f[0] == "PIDH_IGAIN") {
551 $outstr .= ' <tr class="editor">'.PHP_EOL;
552 $outstr .= ' <td class="editname">PID Heat iGain</td>'.PHP_EOL;
553 $outstr .= ' <td class="editfield"><input type="text" name="PIDH_iGain" size="6" value="'.$f[1].'"> Intergral</td>'.PHP_EOL;
554 }
555 if ($f[0] == "PIDH_DGAIN") {
556 $outstr .= ' <td class="editname">PID Heat dGain</td>'.PHP_EOL;
557 $outstr .= ' <td class="editfield"><input type="text" name="PIDH_dGain" size="6" value="'.$f[1].'"> Derivative</td>'.PHP_EOL;
558 $outstr .= ' </tr>'.PHP_EOL;
559 }
560
561 if ($f[0] == "COOLER_ADDRESS") {
562 $outstr .= ' <tr class="editor">'.PHP_EOL;
563 $outstr .= ' <td class="editname">Cooler Switch Address</td>'.PHP_EOL;
564 $outstr .= ' <td class="editfield"><select name="CoolerAddress">'.PHP_EOL;
565 $outstr .= ' <option value="">Not Assigned</option>'.PHP_EOL;
566 if (startsWith($devices[0], "212")) {
567 $j = 1;
568 while (1) {
569 if (strcmp($devices[$j], ".") == 0)
570 break;
571 $g = explode(",", $devices[$j]);
572 if (($g[5] == "OUT_ANALOG") || ($g[5] == "OUT_BIN")) {
573 ($f[1] == $g[0]) ? $se = " selected" : $se = "";
574 $outstr .= ' <option value="'.$g[0].'"'.$se.'>'.$g[1].' '.$g[4].'</option>'.PHP_EOL;
575 }
576 $j++;
577 }
578 }
579 $outstr .= ' </select></td>'.PHP_EOL;
580 }
581 if ($f[0] == "COOLER_DELAY") {
582 $outstr .= ' <td class="editname">Cooler Switch Delay</td>'.PHP_EOL;
583 $outstr .= ' <td class="editfield"><input type="text" name="CoolerDelay" size="5" value="'.$f[1].'"> seconds (0..720)</td>'.PHP_EOL;
584 $outstr .= ' </tr>'.PHP_EOL;
585 }
586
587 if ($f[0] == "COOLER_IDX") {
588 $outstr .= ' <tr class="editor">'.PHP_EOL;
589 $outstr .= ' <td class="editname">Cooler domoticz idx</td>'.PHP_EOL;
590 $outstr .= ' <td class="editfield"><input type="text" name="CoolerIdx" size="5" value="'.$f[1].'"></td>'.PHP_EOL;
591 }
592 if ($f[0] == "PIDC_IMAX") {
593 $outstr .= ' <td class="editname">PID Cool Maximum</td>'.PHP_EOL;
594 $outstr .= ' <td class="editfield"><input type="text" name="PIDC_iMax" size="6" value="'.$f[1].'"> % (1..100)</td>'.PHP_EOL;
595 $outstr .= ' </tr>'.PHP_EOL;
596 }
597
598 if ($f[0] == "PIDC_IDLERANGE") {
599 $outstr .= ' <tr class="editor">'.PHP_EOL;
600 $outstr .= ' <td class="editname">Cooler Idle Range</td>'.PHP_EOL;
601 $outstr .= ' <td class="editfield"><input type="text" name="PIDC_idleRange" size="6" value="'.$f[1].'"> &deg;C (Cooler margin)</td>'.PHP_EOL;
602 }
603 if ($f[0] == "PIDC_PGAIN") {
604 $outstr .= ' <td class="editname">PID Cool pGain</td>'.PHP_EOL;
605 $outstr .= ' <td class="editfield"><input type="text" name="PIDC_pGain" size="6" value="'.$f[1].'"> Proportional</td>'.PHP_EOL;
606 $outstr .= ' </tr>'.PHP_EOL;
607 }
608
609 if ($f[0] == "PIDC_IGAIN") {
610 $outstr .= ' <tr class="editor">'.PHP_EOL;
611 $outstr .= ' <td class="editname">PID Cool iGain</td>'.PHP_EOL;
612 $outstr .= ' <td class="editfield"><input type="text" name="PIDC_iGain" size="6" value="'.$f[1].'"> Intergral</td>'.PHP_EOL;
613 }
614 if ($f[0] == "PIDC_DGAIN") {
615 $outstr .= ' <td class="editname">PID Cool dGain</td>'.PHP_EOL;
616 $outstr .= ' <td class="editfield"><input type="text" name="PIDC_dGain" size="6" value="'.$f[1].'"> Derivative</td>'.PHP_EOL;
617 $outstr .= ' </tr>'.PHP_EOL;
618 }
619
620 if ($f[0] == "FAN_ADDRESS") {
621 $outstr .= ' <tr class="editor">'.PHP_EOL;
622 $outstr .= ' <td class="editname">Fan Switch Address</td>'.PHP_EOL;
623 $outstr .= ' <td class="editfield"><select name="FanAddress">'.PHP_EOL;
624 $outstr .= ' <option value="">Not Assigned</option>'.PHP_EOL;
625 if (startsWith($devices[0], "212")) {
626 $j = 1;
627 while (1) {
628 if (strcmp($devices[$j], ".") == 0)
629 break;
630 $g = explode(",", $devices[$j]);
631 if (($g[5] == "OUT_ANALOG") || ($g[5] == "OUT_BIN")) {
632 ($f[1] == $g[0]) ? $se = " selected" : $se = "";
633 $outstr .= ' <option value="'.$g[0].'"'.$se.'>'.$g[1].' '.$g[4].'</option>'.PHP_EOL;
634 }
635 $j++;
636 }
637 }
638 $outstr .= ' </select></td>'.PHP_EOL;
639 }
640 if ($f[0] == "FAN_DELAY") {
641 $outstr .= ' <td class="editname">Fan Switch Delay</td>'.PHP_EOL;
642 $outstr .= ' <td class="editfield"><input type="text" name="FanDelay" size="5" value="'.$f[1].'"> seconds (0..720)</td>'.PHP_EOL;
643 $outstr .= ' </tr>'.PHP_EOL;
644 }
645
646 if ($f[0] == "FAN_IDX") {
647 $outstr .= ' <tr class="editor">'.PHP_EOL;
648 $outstr .= ' <td class="editname">Fan domoticz idx</td>'.PHP_EOL;
649 $outstr .= ' <td colspan="3" class="editfield"><input type="text" name="FanIdx" size="5" value="'.$f[1].'"></td>'.PHP_EOL;
650 $outstr .= ' </tr>'.PHP_EOL;
651 }
652 if ($f[0] == "LIGHT_ADDRESS") {
653 $outstr .= ' <tr class="editor">'.PHP_EOL;
654 $outstr .= ' <td class="editname">Lights Address</td>'.PHP_EOL;
655 $outstr .= ' <td class="editfield"><select name="LightAddress">'.PHP_EOL;
656 $outstr .= ' <option value="">Not Assigned</option>'.PHP_EOL;
657 if (startsWith($devices[0], "212")) {
658 $j = 1;
659 while (1) {
660 if (strcmp($devices[$j], ".") == 0)
661 break;
662 $g = explode(",", $devices[$j]);
663 if (($g[5] == "OUT_ANALOG") || ($g[5] == "OUT_BIN")) {
664 ($f[1] == $g[0]) ? $se = " selected" : $se = "";
665 $outstr .= ' <option value="'.$g[0].'"'.$se.'>'.$g[1].' '.$g[4].'</option>'.PHP_EOL;
666 }
667 $j++;
668 }
669 }
670 $outstr .= ' </select></td>'.PHP_EOL;
671 }
672
673 if ($f[0] == "LIGHT_DELAY") {
674 $outstr .= ' <td class="editname">Lights Delay</td>'.PHP_EOL;
675 $outstr .= ' <td class="editfield"><input type="text" name="LightDelay" size="5" value="'.$f[1].'"> seconds (0..720)</td>'.PHP_EOL;
676 $outstr .= ' </tr>'.PHP_EOL;
677 }
678
679 if ($f[0] == "LIGHT_IDX") {
680 $outstr .= ' <tr class="editor">'.PHP_EOL;
681 $outstr .= ' <td class="editname">Light domoticz idx</td>'.PHP_EOL;
682 $outstr .= ' <td colspan="3" class="editfield"><input type="text" name="LightIdx" size="5" value="'.$f[1].'"></td>'.PHP_EOL;
683 $outstr .= ' </tr>'.PHP_EOL;
684 }
685
686 if ($f[0] == "DOOR_ADDRESS") {
687 $outstr .= ' <tr class="editor">'.PHP_EOL;
688 $outstr .= ' <td class="editname">Door Sensor Address</td>'.PHP_EOL;
689 $outstr .= ' <td class="editfield"><select name="DoorAddress">'.PHP_EOL;
690 $outstr .= ' <option value="">Not Assigned</option>'.PHP_EOL;
691 if (startsWith($devices[0], "212")) {
692 $j = 1;
693 while (1) {
694 if (strcmp($devices[$j], ".") == 0)
695 break;
696 $g = explode(",", $devices[$j]);
697 if ($g[5] == "IN_BIN") {
698 ($f[1] == $g[0]) ? $se = " selected" : $se = "";
699 $outstr .= ' <option value="'.$g[0].'"'.$se.'>'.$g[1].' '.$g[4].'</option>'.PHP_EOL;
700 }
701 $j++;
702 }
703 }
704 $outstr .= ' </select></td>'.PHP_EOL;
705 }
706 if ($f[0] == "DOOR_IDX") {
707 $outstr .= ' <td class="editname">Door domoticz idx</td>'.PHP_EOL;
708 $outstr .= ' <td class="editfield"><input type="text" name="DoorIdx" size="5" value="'.$f[1].'"></td>'.PHP_EOL;
709 $outstr .= ' </tr>'.PHP_EOL;
710 }
711
712 if ($f[0] == "PSU_ADDRESS") {
713 $outstr .= ' <tr class="editor">'.PHP_EOL;
714 $outstr .= ' <td class="editname">PSU Sensor Address</td>'.PHP_EOL;
715 $outstr .= ' <td class="editfield"><select name="PSUAddress">'.PHP_EOL;
716 $outstr .= ' <option value="">Not Assigned</option>'.PHP_EOL;
717 if (startsWith($devices[0], "212")) {
718 $j = 1;
719 while (1) {
720 if (strcmp($devices[$j], ".") == 0)
721 break;
722 $g = explode(",", $devices[$j]);
723 if ($g[5] == "IN_BIN") {
724 ($f[1] == $g[0]) ? $se = " selected" : $se = "";
725 $outstr .= ' <option value="'.$g[0].'"'.$se.'>'.$g[1].' '.$g[4].'</option>'.PHP_EOL;
726 }
727 $j++;
728 }
729 }
730 $outstr .= ' </select></td>'.PHP_EOL;
731 }
732 if ($f[0] == "PSU_IDX") {
733 $outstr .= ' <td class="editname">PSU domoticz idx</td>'.PHP_EOL;
734 $outstr .= ' <td class="editfield"><input type="text" name="PSUIdx" size="5" value="'.$f[1].'"></td>'.PHP_EOL;
735 $outstr .= ' </tr>'.PHP_EOL;
736 }
737
738 if ($f[0] == "TEMP_SET_MIN") {
739 $outstr .= ' <tr class="editor">'.PHP_EOL;
740 $outstr .= ' <td class="editname">Min. temp setting</td>'.PHP_EOL;
741 $outstr .= ' <td class="editfield"><input type="text" name="TempSetMin" size="5" value="'.$f[1].'"> &deg;C</td>'.PHP_EOL;
742 }
743 if ($f[0] == "TEMP_SET_MAX") {
744 $outstr .= ' <td class="editname">Max. temp setting</td>'.PHP_EOL;
745 $outstr .= ' <td class="editfield"><input type="text" name="TempSetMax" size="5" value="'.$f[1].'"> &deg;C</td>'.PHP_EOL;
746 $outstr .= ' </tr>'.PHP_EOL;
747 }
748
749 $i++;
750 }
751 }
752 $outstr .= ' <tr class="editor">'.PHP_EOL;
753 $outstr .= ' <td class="editname"><input type="submit" value="Save" name="key"></td>'.PHP_EOL;
754 $outstr .= ' <td colspan="3" class="editfield"><input type="submit" value="Cancel" name="key">';
755 $outstr .= '<input type="submit" value="Delete" name="key" style="margin-left: 100px;">';
756 $outstr .= '<input type="hidden" value="testdata" name="action">';
757 $outstr .= '<input type="hidden" value="'.$command.'" name="command">';
758 $outstr .= '<input type="hidden" value="'.$UUID.'" name="UUID"></td>'.PHP_EOL;
759 $outstr .= ' </tr>'.PHP_EOL;
760 $outstr .= ' </table>'.PHP_EOL;
761 $outstr .= ' </form>'.PHP_EOL;
762 $outstr .= ' </div> <!-- etable -->'.PHP_EOL;
763 $outstr .= ' <script type="text/javascript">'.PHP_EOL;
764 $outstr .= ' $(document).ready(function () {'.PHP_EOL;
765 $outstr .= ' $("#maintenance").jqxButton({ width: 150, height: 25, theme: \'ui-redmond\' });'.PHP_EOL;
766 $outstr .= ' });'.PHP_EOL;
767 $outstr .= ' </script>'.PHP_EOL;
768 $outstr .= build_footer();
769 echo $outstr;
770 }
771
772
773
774 /*
775 * Edit a Unit. Fetches the record data and shows the edit screen.
776 *
777 * @param string $_GET['action'] Must be 'edit'.
778 * @param string $_GET['UUID'] The UUID of the Unit.
779 */
780 function unit_edit() {
781 if ($_GET['action'] == 'edit') {
782 edit_screen($_GET['UUID'], 'update', 'ThermFerm - Edit Unit', '');
783 return;
784 } else {
785 load('units.php');
786 }
787 }
788
789
790
791 /*
792 * @link edit unit
793 * @link add unit
794 */
795 function unit_list() {
796
797 global $arr;
798
799 $outstr = build_header('ThermFerm - Units Maintenance');
800 $outstr .= ' <div id="errors">'.PHP_EOL;
801 $outstr .= ' </div> <!-- errors -->'.PHP_EOL;
802 $outstr .= ' <div id="etable">'.PHP_EOL;
803 $outstr .= ' <table class="setup">'.PHP_EOL;
804 $outstr .= ' <tr class="trhead">'.PHP_EOL;
805 $outstr .= ' <td class="setup" style="width: 300px;">UUID</td>'.PHP_EOL;
806 $outstr .= ' <td class="setup" style="width: 300px;">Alias</td>'.PHP_EOL;
807 $outstr .= ' <td class="setup" style="width: 60px;">Mode</td>'.PHP_EOL;
808 $outstr .= ' <td class="setup" style="width: 40px;">Edit</td>'.PHP_EOL;
809 $outstr .= ' </tr>'.PHP_EOL;
810
811 if (startsWith($arr[0], "212")) {
812 $j = 1;
813 while (1) {
814 if (strcmp($arr[$j], ".") == 0)
815 break;
816 $f = explode(",", $arr[$j]);
817 $outstr .= ' <tr class="setup">'.PHP_EOL;
818 $outstr .= ' <td class="setup">'.$f[0].'</td>'.PHP_EOL;
819 $outstr .= ' <td class="setup">'.$f[1].'</td>'.PHP_EOL;
820 $outstr .= ' <td class="setup">'.$f[2].'</td>'.PHP_EOL;
821 if (strcmp($f[2], "OFF")) {
822 $outstr .= ' <td class="setup">Busy</td>'.PHP_EOL;
823 } else {
824 $outstr .= ' <td class="setup"><a href="units.php?action=edit&amp;UUID='.$f[0].'">Edit</a></td>'.PHP_EOL;
825 }
826 $outstr .= ' </tr>'.PHP_EOL;
827 $j++;
828 }
829 }
830
831 $outstr .= ' </table>'.PHP_EOL;
832 $outstr .= ' </div> <!-- etable -->'.PHP_EOL;
833
834 $outstr .= ' <div id="atable">'.PHP_EOL;
835 $outstr .= ' <form method="POST" action="units.php">'.PHP_EOL;
836 $outstr .= ' <table class="editor">'.PHP_EOL;
837 $outstr .= ' <tr class="trhead"><td colspan="3">Add new unit</td></tr>'.PHP_EOL;
838 $outstr .= ' <tr class="editor">'.PHP_EOL;
839 $outstr .= ' <td class="editname">Product Name</td>'.PHP_EOL;
840 $outstr .= ' <td class="editfield"><input type="text" name="ProductName" size="50" value=""></td>'.PHP_EOL;
841 $outstr .= ' <td class="editsub"><input type="submit" value="Add" name="key"></td>'.PHP_EOL;
842 $outstr .= '<input type="hidden" value="FAKE000" name="ProductCode">';
843 $outstr .= '<input type="hidden" value="0.0" name="Volume">';
844 $outstr .= '<input type="hidden" value="PRIMARY" name="Stage">';
845 $outstr .= '<input type="hidden" value="" name="AirAddress">';
846 $outstr .= '<input type="hidden" value="0" name="AirIdx">';
847 $outstr .= '<input type="hidden" value="" name="BeerAddress">';
848 $outstr .= '<input type="hidden" value="0" name="BeerIdx">';
849 $outstr .= '<input type="hidden" value="" name="ChillerAddress">';
850 $outstr .= '<input type="hidden" value="0" name="ChillerIdx">';
851 $outstr .= '<input type="hidden" value="" name="HeaterAddress">';
852 $outstr .= '<input type="hidden" value="20" name="HeaterDelay">';
853 $outstr .= '<input type="hidden" value="0" name="HeaterIdx">';
854 $outstr .= '<input type="hidden" value="" name="CoolerAddress">';
855 $outstr .= '<input type="hidden" value="20" name="CoolerDelay">';
856 $outstr .= '<input type="hidden" value="0" name="CoolerIdx">';
857 $outstr .= '<input type="hidden" value="" name="FanAddress">';
858 $outstr .= '<input type="hidden" value="20" name="FanDelay">';
859 $outstr .= '<input type="hidden" value="0" name="FanIdx">';
860 $outstr .= '<input type="hidden" value="" name="LightAddress">';
861 $outstr .= '<input type="hidden" value="1" name="LightDelay">';
862 $outstr .= '<input type="hidden" value="0" name="LightIdx">';
863 $outstr .= '<input type="hidden" value="" name="DoorAddress">';
864 $outstr .= '<input type="hidden" value="0" name="DoorIdx">';
865 $outstr .= '<input type="hidden" value="" name="PSUAddress">';
866 $outstr .= '<input type="hidden" value="0" name="PSUIdx">';
867 $outstr .= '<input type="hidden" value="1.0" name="TempSetMin">';
868 $outstr .= '<input type="hidden" value="30.0" name="TempSetMax">';
869 $outstr .= '<input type="hidden" value="100" name="PIDC_iMax">';
870 $outstr .= '<input type="hidden" value="4.0" name="PIDC_pGain">';
871 $outstr .= '<input type="hidden" value="0.2" name="PIDC_dGain">';
872 $outstr .= '<input type="hidden" value="1.0" name="PIDC_iGain">';
873 $outstr .= '<input type="hidden" value="1.0" name="PIDC_idleRange">';
874 $outstr .= '<input type="hidden" value="100" name="PIDH_iMax">';
875 $outstr .= '<input type="hidden" value="4.0" name="PIDH_pGain">';
876 $outstr .= '<input type="hidden" value="0.2" name="PIDH_dGain">';
877 $outstr .= '<input type="hidden" value="1.0" name="PIDH_iGain">';
878 $outstr .= '<input type="hidden" value="1.0" name="PIDH_idleRange">';
879 $outstr .= '<input type="hidden" value="testdata" name="action">';
880 $outstr .= '<input type="hidden" value="add" name="command">';
881 $outstr .= '<input type="hidden" value="00000000-0000-0000-0000-000000000000" name="UUID">';
882 $outstr .= ' </tr>'.PHP_EOL;
883 $outstr .= ' </table>'.PHP_EOL;
884 $outstr .= ' </form>'.PHP_EOL;
885 $outstr .= ' </div> <!-- atable -->'.PHP_EOL;
886 $outstr .= ' <script type="text/javascript">'.PHP_EOL;
887 $outstr .= ' $(document).ready(function () {'.PHP_EOL;
888 $outstr .= ' $("#maintenance").jqxButton({ width: 150, height: 25, theme: \'ui-redmond\' });'.PHP_EOL;
889 $outstr .= ' });'.PHP_EOL;
890 $outstr .= ' </script>'.PHP_EOL;
891 $outstr .= build_footer();
892 echo $outstr;
893 }
894

mercurial