1 <?php |
|
2 /***************************************************************************** |
|
3 * Copyright (C) 2014-2018 |
|
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 if (isset($_POST['action'])) { |
|
28 if ($_POST['action'] == "testdata") |
|
29 testdata(); |
|
30 } else { |
|
31 edit_screen(""); |
|
32 } |
|
33 |
|
34 |
|
35 exit; |
|
36 |
|
37 |
|
38 /***************************************************************************** |
|
39 * |
|
40 */ |
|
41 |
|
42 |
|
43 function global_update() { |
|
44 |
|
45 if ($_POST['key'] == 'Save') { |
|
46 $cmd = array("GLOBAL PUT"); |
|
47 $cmd[] = "NAME,".$_POST['Name']; |
|
48 $cmd[] = "PORT,".$_POST['Port']; |
|
49 $cmd[] = "TEMP_UUID,".$_POST['TempAddress']; |
|
50 $cmd[] = "HUM_UUID,".$_POST['HumAddress']; |
|
51 $cmd[] = "TEMP_HUM_IDX,".$_POST['TempHumIdx']; |
|
52 if (isset($_POST['LCDcols'])) |
|
53 $cmd[] = "LCD_COLS,".$_POST['LCDcols']; |
|
54 if (isset($_POST['LCDrows'])) |
|
55 $cmd[] = "LCD_ROWS,".$_POST['LCDrows']; |
|
56 $cmd[] = "MQTT_HOST,".$_POST['MQTThost']; |
|
57 $cmd[] = "MQTT_POST,".$_POST['MQTTport']; |
|
58 $cmd[] = "MQTT_USER,".$_POST['MQTTuser']; |
|
59 $cmd[] = "MQTT_PASS,".$_POST['MQTTpass']; |
|
60 $cmd[] = "."; |
|
61 send_array($cmd); |
|
62 } |
|
63 |
|
64 unset($_POST['Name']); |
|
65 unset($_POST['Port']); |
|
66 unset($_POST['TempAddress']); |
|
67 unset($_POST['HumAddress']); |
|
68 unset($_POST['TempHumIdx']); |
|
69 unset($_POST['LCDcols']); |
|
70 unset($_POST['LCDrows']); |
|
71 unset($_POST['MQTThost']); |
|
72 unset($_POST['MQTTport']); |
|
73 unset($_POST['MQTTuser']); |
|
74 unset($_POST['MQTTpass']); |
|
75 unset($_POST['key']); |
|
76 load('maintenance.php'); |
|
77 } |
|
78 |
|
79 |
|
80 |
|
81 function test_thedata() { |
|
82 |
|
83 if (isset($_POST['Name']) && isset($_POST['Port']) && |
|
84 isset($_POST['TempAddress']) && isset($_POST['HumAddress']) && |
|
85 isset($_POST['TempHumIdx']) && isset($_POST['key']) && |
|
86 isset($_POST['MQTThost']) && isset($_POST['MQTTport']) && |
|
87 isset($_POST['MQTTuser']) && isset($_POST['MQTTpass'])) { |
|
88 |
|
89 if ($_POST['key'] == 'Cancel') |
|
90 return 99; |
|
91 |
|
92 if (isset($_POST['LCDcols']) && (($_POST['LCDcols'] != 16) && ($_POST['LCDcols'] != 20))) |
|
93 return 2; |
|
94 |
|
95 if (isset($_POST['LCDrows']) && (($_POST['LCDrows'] != 2) && ($_POST['LCDrows'] != 4))) |
|
96 return 3; |
|
97 |
|
98 } else { |
|
99 return 1; |
|
100 } |
|
101 |
|
102 return 0; |
|
103 } |
|
104 |
|
105 |
|
106 |
|
107 function testdata() |
|
108 { |
|
109 $result = test_thedata(); |
|
110 $error = ''; |
|
111 |
|
112 switch ($result) { |
|
113 case 0: global_update(); |
|
114 return; |
|
115 break; |
|
116 case 1: $error = 'Missing data'; |
|
117 break; |
|
118 case 2: $error = 'LCD columns must be 16 or 20'; |
|
119 break; |
|
120 case 3: $error = 'LCD rows must be 2 or 4'; |
|
121 break; |
|
122 case 99: |
|
123 load('maintenance.php'); |
|
124 break; |
|
125 } |
|
126 |
|
127 edit_screen($error); |
|
128 } |
|
129 |
|
130 |
|
131 |
|
132 function edit_screen($error_message) |
|
133 { |
|
134 /* |
|
135 * Get list of devices, we need it later |
|
136 */ |
|
137 $answer = send_cmd("DEVICE LIST"); |
|
138 $devices = explode("\r\n", $answer); |
|
139 |
|
140 /* |
|
141 * Get current global data |
|
142 */ |
|
143 $answer = send_cmd("GLOBAL GET"); |
|
144 $reply = explode("\r\n", $answer); |
|
145 |
|
146 $outstr = build_header("ThermFerm - Global Setup"); |
|
147 $outstr .= ' <div id="errors">'.PHP_EOL; |
|
148 $outstr .= ' '.$error_message.PHP_EOL; |
|
149 $outstr .= ' </div> <!-- errors -->'.PHP_EOL; |
|
150 $outstr .= ' <div id="etable">'.PHP_EOL; |
|
151 $outstr .= ' <form method="POST" action="global.php">'.PHP_EOL; |
|
152 $outstr .= ' <table class="editor">'.PHP_EOL; |
|
153 $outstr .= ' <tr class="trhead">'.PHP_EOL; |
|
154 $outstr .= ' <td class="setup" colspan="2" style="text-align: center; height: 20px; padding-top: 5px;">Global Setup</td>'.PHP_EOL; |
|
155 $outstr .= ' </tr>'.PHP_EOL; |
|
156 |
|
157 if (startsWith($reply[0], "213")) { |
|
158 $i = 1; |
|
159 while (1) { |
|
160 if (strcmp($reply[$i], ".") == 0) |
|
161 break; |
|
162 $f = explode(",", $reply[$i]); |
|
163 |
|
164 if ($f[0] == "NAME") { |
|
165 $outstr .= ' <tr class="editor">'.PHP_EOL; |
|
166 $outstr .= ' <td class="editname">System Name</td>'.PHP_EOL; |
|
167 $outstr .= ' <td class="editfield"><input type="text" name="Name" size="50" value="'.$f[1].'"></td>'.PHP_EOL; |
|
168 $outstr .= ' </tr>'.PHP_EOL; |
|
169 } |
|
170 if ($f[0] == "PORT") { |
|
171 $outstr .= ' <tr class="editor">'.PHP_EOL; |
|
172 $outstr .= ' <td class="editname">Telnet port</td>'.PHP_EOL; |
|
173 $outstr .= ' <td class="editfield"><input type="text" name="Port" size="5" value="'.$f[1].'"></td>'.PHP_EOL; |
|
174 $outstr .= ' </tr>'.PHP_EOL; |
|
175 } |
|
176 if ($f[0] == "TEMP_UUID") { |
|
177 $outstr .= ' <tr class="editor">'.PHP_EOL; |
|
178 $outstr .= ' <td class="editname">Room temperature sensor</td>'.PHP_EOL; |
|
179 $outstr .= ' <td class="editfield"><select name="TempAddress">'.PHP_EOL; |
|
180 $outstr .= ' <option value="">Not Assigned</option>'.PHP_EOL; |
|
181 if (startsWith($devices[0], "212")) { |
|
182 $j = 1; |
|
183 while (1) { |
|
184 if (strcmp($devices[$j], ".") == 0) |
|
185 break; |
|
186 $g = explode(",", $devices[$j]); |
|
187 if ($g[5] == "IN_ANALOG") { |
|
188 ($f[1] == $g[0]) ? $se = " selected" : $se = ""; |
|
189 $outstr .= ' <option value="'.$g[0].'"'.$se.'>'.$g[1].' '.$g[4].'</option>'.PHP_EOL; |
|
190 } |
|
191 $j++; |
|
192 } |
|
193 } |
|
194 $outstr .= ' </select></td>'.PHP_EOL; |
|
195 $outstr .= ' </tr>'.PHP_EOL; |
|
196 } |
|
197 if ($f[0] == "HUM_UUID") { |
|
198 $outstr .= ' <tr class="editor">'.PHP_EOL; |
|
199 $outstr .= ' <td class="editname">Room humidity sensor</td>'.PHP_EOL; |
|
200 $outstr .= ' <td class="editfield"><select name="HumAddress">'.PHP_EOL; |
|
201 $outstr .= ' <option value="">Not Assigned</option>'.PHP_EOL; |
|
202 if (startsWith($devices[0], "212")) { |
|
203 $j = 1; |
|
204 while (1) { |
|
205 if (strcmp($devices[$j], ".") == 0) |
|
206 break; |
|
207 $g = explode(",", $devices[$j]); |
|
208 if ($g[5] == "IN_ANALOG") { |
|
209 ($f[1] == $g[0]) ? $se = " selected" : $se = ""; |
|
210 $outstr .= ' <option value="'.$g[0].'"'.$se.'>'.$g[1].' '.$g[4].'</option>'.PHP_EOL; |
|
211 } |
|
212 $j++; |
|
213 } |
|
214 } |
|
215 $outstr .= ' </select></td>'.PHP_EOL; |
|
216 $outstr .= ' </tr>'.PHP_EOL; |
|
217 } |
|
218 if ($f[0] == "TEMP_HUM_IDX") { |
|
219 $outstr .= ' <tr class="editor">'.PHP_EOL; |
|
220 $outstr .= ' <td class="editname">Domoticz TH index</td>'.PHP_EOL; |
|
221 $outstr .= ' <td class="editfield"><input type="text" name="TempHumIdx" size="5" value="'.$f[1].'"></td>'.PHP_EOL; |
|
222 $outstr .= ' </tr>'.PHP_EOL; |
|
223 } |
|
224 if ($f[0] == "LCD_COLS") { |
|
225 $outstr .= ' <tr class="editor">'.PHP_EOL; |
|
226 $outstr .= ' <td class="editname">LCD columns</td>'.PHP_EOL; |
|
227 $outstr .= ' <td class="editfield"><input type="text" name="LCDcols" size="5" value="'.$f[1].'"></td>'.PHP_EOL; |
|
228 $outstr .= ' </tr>'.PHP_EOL; |
|
229 } |
|
230 if ($f[0] == "LCD_ROWS") { |
|
231 $outstr .= ' <tr class="editor">'.PHP_EOL; |
|
232 $outstr .= ' <td class="editname">LCD rows</td>'.PHP_EOL; |
|
233 $outstr .= ' <td class="editfield"><input type="text" name="LCDrows" size="5" value="'.$f[1].'"></td>'.PHP_EOL; |
|
234 $outstr .= ' </tr>'.PHP_EOL; |
|
235 } |
|
236 if ($f[0] == "MQTT_HOST") { |
|
237 $outstr .= ' <tr class="editor">'.PHP_EOL; |
|
238 $outstr .= ' <td class="editname">MQTT host</td>'.PHP_EOL; |
|
239 $outstr .= ' <td class="editfield"><input type="text" name="MQTThost" size="50" value="'.$f[1].'"></td>'.PHP_EOL; |
|
240 $outstr .= ' </tr>'.PHP_EOL; |
|
241 } |
|
242 if ($f[0] == "MQTT_PORT") { |
|
243 $outstr .= ' <tr class="editor">'.PHP_EOL; |
|
244 $outstr .= ' <td class="editname">MQTT port</td>'.PHP_EOL; |
|
245 $outstr .= ' <td class="editfield"><input type="text" name="MQTTport" size="5" value="'.$f[1].'"></td>'.PHP_EOL; |
|
246 $outstr .= ' </tr>'.PHP_EOL; |
|
247 } |
|
248 if ($f[0] == "MQTT_USER") { |
|
249 $outstr .= ' <tr class="editor">'.PHP_EOL; |
|
250 $outstr .= ' <td class="editname">MQTT username</td>'.PHP_EOL; |
|
251 if (strcmp($f[1], "(null)") == 0) { |
|
252 $f[1] = ""; |
|
253 } |
|
254 $outstr .= ' <td class="editfield"><input type="text" name="MQTTuser" size="50" value="'.$f[1].'"></td>'.PHP_EOL; |
|
255 $outstr .= ' </tr>'.PHP_EOL; |
|
256 } |
|
257 if ($f[0] == "MQTT_PASS") { |
|
258 $outstr .= ' <tr class="editor">'.PHP_EOL; |
|
259 $outstr .= ' <td class="editname">MQTT password</td>'.PHP_EOL; |
|
260 if (strcmp($f[1], "(null)") == 0) { |
|
261 $f[1] = ""; |
|
262 } |
|
263 $outstr .= ' <td class="editfield"><input type="text" name="MQTTpass" size="50" value="'.$f[1].'"></td>'.PHP_EOL; |
|
264 $outstr .= ' </tr>'.PHP_EOL; |
|
265 } |
|
266 $i++; |
|
267 } |
|
268 } |
|
269 |
|
270 $outstr .= ' <tr class="editor">'.PHP_EOL; |
|
271 $outstr .= ' <td class="editname"><input type="submit" value="Save" name="key"></td>'.PHP_EOL; |
|
272 $outstr .= ' <td class="editfield"><input type="submit" value="Cancel" name="key">'; |
|
273 $outstr .= '<input type="hidden" value="testdata" name="action">'; |
|
274 $outstr .= ' </tr>'.PHP_EOL; |
|
275 $outstr .= ' </table>'.PHP_EOL; |
|
276 $outstr .= ' </form>'.PHP_EOL; |
|
277 $outstr .= ' </div> <!-- etable -->'.PHP_EOL; |
|
278 $outstr .= ' <script type="text/javascript">'.PHP_EOL; |
|
279 $outstr .= ' $(document).ready(function () {'.PHP_EOL; |
|
280 $outstr .= ' $("#maintenance").jqxButton({ width: 150, height: 25, theme: \'ui-redmond\' });'.PHP_EOL; |
|
281 $outstr .= ' });'.PHP_EOL; |
|
282 $outstr .= ' </script>'.PHP_EOL; |
|
283 $outstr .= build_footer(); |
|
284 |
|
285 echo $outstr; |
|
286 } |
|
287 |
|
288 |
|