44 * $arr contains the complete reply of he LIST PROFILES command. |
44 * $arr contains the complete reply of he LIST PROFILES command. |
45 */ |
45 */ |
46 $arr = explode("\r\n", $answer); |
46 $arr = explode("\r\n", $answer); |
47 |
47 |
48 |
48 |
|
49 |
49 if (isset($_GET['action'])) { |
50 if (isset($_GET['action'])) { |
50 switch ($_GET['action']) { |
51 switch ($_GET['action']) { |
51 case 'edit': profile_edit(); |
52 case 'edit': profile_edit(); |
52 break; |
53 break; |
|
54 case 'esteps': profile_steps(); |
|
55 break; |
53 default: break; |
56 default: break; |
54 } |
57 } |
55 } elseif (isset($_POST['action'])) { |
58 } elseif (isset($_POST['action'])) { |
56 switch ($_POST['action']) { |
59 switch ($_POST['action']) { |
57 case 'testdata': testdata(); |
60 case 'testdata': testdata(); |
58 break; |
61 break; |
|
62 case 'teststeps': teststeps(); |
|
63 break; |
59 default: break; |
64 default: break; |
60 } |
65 } |
61 } else { |
66 } else { |
62 profile_list(); |
67 profile_list(); |
63 } |
68 } |
64 |
69 |
65 exit; |
70 exit; |
66 |
71 |
67 |
72 |
68 |
73 |
|
74 /* |
|
75 * Profile steps |
|
76 */ |
|
77 function profile_steps() |
|
78 { |
|
79 global $arr; |
|
80 $UUID = $_GET['UUID']; |
|
81 |
|
82 /* |
|
83 * $steps contains all steps of a profile |
|
84 */ |
|
85 $steps = array ( |
|
86 1 => array("steptime" => 0, "resttime" => 1, "target" => 20.0 ), |
|
87 2 => array("steptime" => 0, "resttime" => 1, "target" => 20.0 ), |
|
88 3 => array("steptime" => 0, "resttime" => 1, "target" => 20.0 ), |
|
89 4 => array("steptime" => 0, "resttime" => 1, "target" => 20.0 ), |
|
90 5 => array("steptime" => 0, "resttime" => 1, "target" => 20.0 ), |
|
91 6 => array("steptime" => 0, "resttime" => 1, "target" => 20.0 ), |
|
92 7 => array("steptime" => 0, "resttime" => 1, "target" => 20.0 ), |
|
93 8 => array("steptime" => 0, "resttime" => 1, "target" => 20.0 ), |
|
94 ); |
|
95 |
|
96 $sock = open_socket(); |
|
97 if ($sock == false) { |
|
98 load('profiles.php'); |
|
99 } |
|
100 |
|
101 socket_write($sock, "PROFILES GETS ".$UUID, 4096); |
|
102 $answer = ""; |
|
103 while (1) { |
|
104 $line = socket_read($sock, 4096); |
|
105 if ($line === '') |
|
106 break; |
|
107 $answer .= $line; |
|
108 } |
|
109 socket_close($sock); |
|
110 $psteps = explode("\r\n", $answer); |
|
111 |
|
112 if (startsWith($arr[0], "212")) { |
|
113 $j = 1; |
|
114 while (1) { |
|
115 if (strcmp($psteps[$j], ".") == 0) |
|
116 break; |
|
117 $f = explode(",", $psteps[$j]); |
|
118 $steps[$j]["steptime"] = $f[0]; |
|
119 $steps[$j]["resttime"] = $f[1]; |
|
120 $steps[$j]["target"] = $f[2]; |
|
121 $j++; |
|
122 } |
|
123 } |
|
124 |
|
125 edit_steps($UUID, $steps, "", "ThermFerm - Edit Profile Steps"); |
|
126 } |
|
127 |
|
128 |
|
129 function edit_steps($UUID, $steps, $error_message, $heading) |
|
130 { |
|
131 $outstr = build_header($heading); |
|
132 $outstr .= ' <div id="errors">'.PHP_EOL; |
|
133 $outstr .= ' '.$error_message.PHP_EOL; |
|
134 $outstr .= ' </div> <!-- errors -->'.PHP_EOL; |
|
135 $outstr .= ' <div id="etable">'.PHP_EOL; |
|
136 $outstr .= ' <form method="POST" action="profiles.php">'.PHP_EOL; |
|
137 $outstr .= ' <table class="editor">'.PHP_EOL; |
|
138 $outstr .= ' <tr class="trhead">'.PHP_EOL; |
|
139 $outstr .= ' <td>Step</td>'.PHP_EOL; |
|
140 $outstr .= ' <td>Steptime</td>'.PHP_EOL; |
|
141 $outstr .= ' <td>Resttime</td>'.PHP_EOL; |
|
142 $outstr .= ' <td>Temperature</td>'.PHP_EOL; |
|
143 $outstr .= ' </tr>'.PHP_EOL; |
|
144 |
|
145 for ($i = 1; $i <= 8; $i++) { |
|
146 $outstr .= ' <tr class="editor">'.PHP_EOL; |
|
147 $outstr .= ' <td>Step '.$i.'</td>'.PHP_EOL; |
|
148 $outstr .= ' <td><input type="text" name="steptime'.$i.'" size="4" value="'.$steps[$i]["steptime"].'"></td>'.PHP_EOL; |
|
149 $outstr .= ' <td><input type="text" name="resttime'.$i.'" size="4" value="'.$steps[$i]["resttime"].'"></td>'.PHP_EOL; |
|
150 $outstr .= ' <td><input type="text" name="target'.$i.'" size="4" value="'.$steps[$i]["target"].'"></td>'.PHP_EOL; |
|
151 $outstr .= ' </tr>'.PHP_EOL; |
|
152 } |
|
153 |
|
154 $outstr .= ' <tr class="editor">'.PHP_EOL; |
|
155 $outstr .= ' <td class="editname"> </td>'.PHP_EOL; |
|
156 $outstr .= ' <td class="editname"><input type="submit" value="Save" name="key"></td>'.PHP_EOL; |
|
157 $outstr .= ' <td class="editname"><input type="submit" value="Cancel" name="key">'; |
|
158 $outstr .= '<input type="hidden" value="teststeps" name="action">'; |
|
159 $outstr .= '<input type="hidden" value="'.$UUID.'" name="UUID"></td>'.PHP_EOL; |
|
160 $outstr .= ' <td class="editname"> </td>'.PHP_EOL; |
|
161 $outstr .= ' </tr>'.PHP_EOL; |
|
162 $outstr .= ' </table>'.PHP_EOL; |
|
163 $outstr .= ' </form>'.PHP_EOL; |
|
164 $outstr .= ' </div> <!-- etable -->'.PHP_EOL; |
|
165 $outstr .= ' <div id="atable" style="margin-left: 100px; width:780px;">'.PHP_EOL; |
|
166 $outstr .= ' The steptime is the time to go from the previous to the target temperature.'.PHP_EOL; |
|
167 $outstr .= ' The resttime is the total time in this step including the steptime.'.PHP_EOL; |
|
168 $outstr .= ' Steps are valid if the steptime is greater then zero.'.PHP_EOL; |
|
169 $outstr .= ' Order is important.'.PHP_EOL; |
|
170 $outstr .= ' Lines with a steptime of zero are ignored.'.PHP_EOL; |
|
171 $outstr .= ' The step- and resttimes are in hours.'.PHP_EOL; |
|
172 $outstr .= ' </div> <!-- atable -->'.PHP_EOL; |
|
173 $outstr .= build_footer(); |
|
174 echo $outstr; |
|
175 } |
|
176 |
|
177 |
|
178 |
69 |
179 |
70 /* |
180 /* |
71 * Profile add |
181 * Profile add |
72 * |
182 * |
73 * @param string $_POST['Name'] The rpofile name |
183 * @param string $_POST['Name'] The rpofile name |
74 */ |
184 */ |
75 function profile_add() { |
185 function profile_add() { |
76 |
186 |
77 $cmd = "ADD PROFILE ".$_POST['Name']; |
187 if ($_POST['key'] == 'Add') { |
78 |
188 |
79 $sock = open_socket(); |
189 $cmd = "ADD PROFILE ".$_POST['Name']; |
80 if ($sock != false) { |
190 |
81 /* |
191 $sock = open_socket(); |
82 * Send command and absorb the result. |
192 if ($sock != false) { |
83 */ |
193 /* |
84 socket_write($sock, $cmd, 4096); |
194 * Send command and absorb the result. |
85 while (1) { |
195 */ |
86 $line = socket_read($sock, 4096); |
196 socket_write($sock, $cmd, 4096); |
87 if ($line === '') |
197 while (1) { |
88 break; |
198 $line = socket_read($sock, 4096); |
89 } |
199 if ($line === '') |
90 socket_close($sock); |
200 break; |
91 } |
201 } |
92 |
202 socket_close($sock); |
|
203 } |
|
204 } |
93 unset($_POST['UUID']); |
205 unset($_POST['UUID']); |
94 unset($_POST['Name']); |
206 unset($_POST['Name']); |
|
207 unset($_POST['Steps']); |
95 unset($_POST['key']); |
208 unset($_POST['key']); |
96 unset($_POST['command']); |
209 unset($_POST['command']); |
97 load('profiles.php'); |
210 load('profiles.php'); |
98 } |
211 } |
99 |
212 |
140 |
254 |
141 /* |
255 /* |
142 * Test input of a modified or new profile. |
256 * Test input of a modified or new profile. |
143 * |
257 * |
144 * @param string $_POST['UUID'] Unique record UUID |
258 * @param string $_POST['UUID'] Unique record UUID |
|
259 * @param int $_POST['steptime'n] Profile steptime |
|
260 * @param int $_POST['resttime'n] Profile resttime |
|
261 * @param float $_POST['target'n] Profile target temperature |
|
262 * @param string $_POST['key'] Key choice, Save or Cancel |
|
263 * |
|
264 * Return: 0 = Ok |
|
265 * 1 = Missing data |
|
266 * 2 = A resttime < steptime |
|
267 * 3 = A target temperature out of range |
|
268 * 99 = Cancel key |
|
269 */ |
|
270 function test_thesteps() { |
|
271 |
|
272 global $arr; |
|
273 |
|
274 print_r($_POST); |
|
275 |
|
276 for ($i = 1; $i <= 8; $i++) { |
|
277 if ((! isset($_POST['steptime'.$i])) || (! isset($_POST['resttime'.$i])) || (! isset($_POST['target'.$i]))) |
|
278 return 1; |
|
279 if ((strlen($_POST['steptime'.$i]) == 0) || (strlen($_POST['resttime'.$i]) == 0) || (strlen($_POST['target'.$i]) == 0)) |
|
280 return 1; |
|
281 } |
|
282 |
|
283 if (isset($_POST['UUID']) && isset($_POST['key'])) { |
|
284 |
|
285 if ($_POST['key'] == 'Cancel') |
|
286 return 99; |
|
287 |
|
288 for ($i = 1; $i <= 8; $i++) { |
|
289 if ($_POST['resttime'.$i] < $_POST['steptime'.$i]) |
|
290 return 2; |
|
291 |
|
292 if (($_POST['target'.$i] < -5) || ($_POST['target'.$i] > 30)) |
|
293 return 3; |
|
294 } |
|
295 } else { |
|
296 return 1; |
|
297 } |
|
298 |
|
299 return 0; |
|
300 } |
|
301 |
|
302 |
|
303 |
|
304 /* |
|
305 * Test result from edit_steps screen and do next action |
|
306 */ |
|
307 function teststeps() { |
|
308 |
|
309 $result = test_thesteps(); |
|
310 $error = ''; |
|
311 |
|
312 switch ($result) { |
|
313 case 0: $sock = open_socket(); |
|
314 if ($sock != false) { |
|
315 socket_write($sock, 'PROFILE PUTS '.$_POST['UUID'], 4096); |
|
316 for ($i = 1; $i <= 8; $i++) { |
|
317 if ($_POST['steptime'.$i] > 0) |
|
318 socket_write($sock, $_POST['steptime'.$i].','.$_POST['resttime'.$i].','.$_POST['target'.$i], 4096); |
|
319 unset($_POST['steptime'.$i]); |
|
320 unset($_POST['resttime'.$i]); |
|
321 unset($_POST['target'.$i]); |
|
322 } |
|
323 socket_write($sock, '.', 4096); |
|
324 /* Absorb response */ |
|
325 while (1) { |
|
326 $line = socket_read($sock, 4096); |
|
327 if ($line === '') |
|
328 break; |
|
329 } |
|
330 socket_close($sock); |
|
331 unset($_POST['UUID']); |
|
332 unset($_POST['key']); |
|
333 load('profiles.php'); |
|
334 return; |
|
335 } |
|
336 break; |
|
337 case 1: $error = 'Missing data'; |
|
338 break; |
|
339 case 2: $error = 'A resttime is shorter then the steptime'; |
|
340 break; |
|
341 case 3: $error = 'A target temperature is out of range'; |
|
342 break; |
|
343 case 99: |
|
344 load('profiles.php'); |
|
345 break; |
|
346 } |
|
347 |
|
348 $steps = array ( |
|
349 1 => array("steptime" => $_POST['steptime1'], "resttime" => $_POST['resttime1'], "target" => $_POST['target1'] ), |
|
350 2 => array("steptime" => $_POST['steptime2'], "resttime" => $_POST['resttime2'], "target" => $_POST['target2'] ), |
|
351 3 => array("steptime" => $_POST['steptime3'], "resttime" => $_POST['resttime3'], "target" => $_POST['target3'] ), |
|
352 4 => array("steptime" => $_POST['steptime4'], "resttime" => $_POST['resttime4'], "target" => $_POST['target4'] ), |
|
353 5 => array("steptime" => $_POST['steptime5'], "resttime" => $_POST['resttime5'], "target" => $_POST['target5'] ), |
|
354 6 => array("steptime" => $_POST['steptime6'], "resttime" => $_POST['resttime6'], "target" => $_POST['target6'] ), |
|
355 7 => array("steptime" => $_POST['steptime7'], "resttime" => $_POST['resttime7'], "target" => $_POST['target7'] ), |
|
356 8 => array("steptime" => $_POST['steptime8'], "resttime" => $_POST['resttime8'], "target" => $_POST['target8'] ), |
|
357 ); |
|
358 |
|
359 edit_steps($_POST['UUID'], $steps, $error, "ThermFerm - Edit Profile Steps"); |
|
360 } |
|
361 |
|
362 |
|
363 |
|
364 /* |
|
365 * Test input of a modified or new profile. |
|
366 * |
|
367 * @param string $_POST['UUID'] Unique record UUID |
145 * @param string $_POST['Name'] Profile name |
368 * @param string $_POST['Name'] Profile name |
|
369 * @param int $_POST['Steps'] Profile steps |
146 * @param string $_POST['key'] Key choice, Save or Cancel |
370 * @param string $_POST['key'] Key choice, Save or Cancel |
147 * @param string $_POST['command'] Command used, 'add' or 'update' |
371 * @param string $_POST['command'] Command used, 'add' or 'update' |
148 * |
372 * |
149 * Return: 0 = Ok |
373 * Return: 0 = Ok |
150 * 1 = Missing data |
374 * 1 = Missing data |
248 $outstr .= ' <td class="editfield">'.$UUID.'</td>'.PHP_EOL; |
472 $outstr .= ' <td class="editfield">'.$UUID.'</td>'.PHP_EOL; |
249 $outstr .= ' </tr>'.PHP_EOL; |
473 $outstr .= ' </tr>'.PHP_EOL; |
250 $outstr .= ' <tr class="editor">'.PHP_EOL; |
474 $outstr .= ' <tr class="editor">'.PHP_EOL; |
251 $outstr .= ' <td class="editname">Profile Name</td>'.PHP_EOL; |
475 $outstr .= ' <td class="editname">Profile Name</td>'.PHP_EOL; |
252 $outstr .= ' <td class="editfield"><input type="text" name="Name" size="50" value="'.$Name.'"></td>'.PHP_EOL; |
476 $outstr .= ' <td class="editfield"><input type="text" name="Name" size="50" value="'.$Name.'"></td>'.PHP_EOL; |
|
477 $outstr .= ' </tr>'.PHP_EOL; |
|
478 $outstr .= ' <tr class="editor">'.PHP_EOL; |
|
479 $outstr .= ' <td class="editname">Profile Steps</td>'.PHP_EOL; |
|
480 $outstr .= ' <td class="editfield">'.$Steps.'</td>'.PHP_EOL; |
253 $outstr .= ' </tr>'.PHP_EOL; |
481 $outstr .= ' </tr>'.PHP_EOL; |
254 $outstr .= ' <tr class="editor">'.PHP_EOL; |
482 $outstr .= ' <tr class="editor">'.PHP_EOL; |
255 $outstr .= ' <td class="editname"><input type="submit" value="Save" name="key"></td>'.PHP_EOL; |
483 $outstr .= ' <td class="editname"><input type="submit" value="Save" name="key"></td>'.PHP_EOL; |
256 $outstr .= ' <td class="editfield"><input type="submit" value="Cancel" name="key">'; |
484 $outstr .= ' <td class="editfield"><input type="submit" value="Cancel" name="key">'; |
257 $outstr .= '<input type="submit" value="Delete" name="key" style="margin-left: 100px;">'; |
485 $outstr .= '<input type="submit" value="Delete" name="key" style="margin-left: 100px;">'; |
347 $outstr .= ' </div> <!-- etable -->'.PHP_EOL; |
577 $outstr .= ' </div> <!-- etable -->'.PHP_EOL; |
348 $outstr .= ' <div id="atable">'.PHP_EOL; |
578 $outstr .= ' <div id="atable">'.PHP_EOL; |
349 |
579 |
350 $outstr .= ' <form method="POST" action="profiles.php">'.PHP_EOL; |
580 $outstr .= ' <form method="POST" action="profiles.php">'.PHP_EOL; |
351 $outstr .= ' <table class="editor">'.PHP_EOL; |
581 $outstr .= ' <table class="editor">'.PHP_EOL; |
|
582 $outstr .= ' <tr class="trhead"><td colspan="3">Add new profile</td></tr>'.PHP_EOL; |
352 $outstr .= ' <tr class="editor">'.PHP_EOL; |
583 $outstr .= ' <tr class="editor">'.PHP_EOL; |
353 $outstr .= ' <td class="editname">Profile Name</td>'.PHP_EOL; |
584 $outstr .= ' <td class="editname">Profile Name</td>'.PHP_EOL; |
354 $outstr .= ' <td class="editfield"><input type="text" name="Name" size="50" value="'.$Name.'"></td>'.PHP_EOL; |
585 $outstr .= ' <td class="editfield"><input type="text" name="Name" size="50" value=""></td>'.PHP_EOL; |
355 $outstr .= ' </tr>'.PHP_EOL; |
586 $outstr .= ' <td class="editsub"><input type="submit" value="Add" name="key"></td>'.PHP_EOL; |
356 $outstr .= ' <tr class="editor">'.PHP_EOL; |
|
357 $outstr .= ' <td class="editname"><input type="submit" value="Add" name="key"></td>'.PHP_EOL; |
|
358 $outstr .= '<input type="hidden" value="testdata" name="action">'; |
587 $outstr .= '<input type="hidden" value="testdata" name="action">'; |
359 $outstr .= '<input type="hidden" value="add" name="command">'; |
588 $outstr .= '<input type="hidden" value="add" name="command">'; |
|
589 $outstr .= '<input type="hidden" value="0" name="Steps"></td>'; |
360 $outstr .= '<input type="hidden" value="00000000-0000-0000-0000-000000000000" name="UUID">'; |
590 $outstr .= '<input type="hidden" value="00000000-0000-0000-0000-000000000000" name="UUID">'; |
361 $outstr .= ' </tr>'.PHP_EOL; |
591 $outstr .= ' </tr>'.PHP_EOL; |
362 $outstr .= ' </table>'.PHP_EOL; |
592 $outstr .= ' </table>'.PHP_EOL; |
363 $outstr .= ' </form>'.PHP_EOL; |
593 $outstr .= ' </form>'.PHP_EOL; |
364 |
594 |