211 } |
211 } |
212 |
212 |
213 |
213 |
214 |
214 |
215 /* |
215 /* |
216 * Profile update |
216 * Profile update or delete |
217 * |
217 * |
218 * @param string $_POST['UUID'] The profile UUID |
218 * @param string $_POST['UUID'] The profile UUID |
219 * @param string $_POST['Name'] The profile name |
219 * @param string $_POST['Name'] The profile name |
|
220 * @param string $_POST['Inittemp'] The profile initial temperature |
220 * @param string $_POST['key'] The button pressed. |
221 * @param string $_POST['key'] The button pressed. |
221 */ |
222 */ |
222 function profile_update() { |
223 function profile_update() { |
223 /* |
224 /* |
224 * Build the update command |
225 * Build the update command |
225 */ |
226 */ |
226 if ($_POST['key'] == 'Delete') |
227 if ($_POST['key'] == 'Delete') { |
227 $update_cmd = "DEL PROFILE ".$_POST['UUID']; |
228 $sock = open_socket(); |
228 else |
229 if ($sock != false) { |
229 $update_cmd = "PROFILE ".$_POST['UUID'].",".$_POST['Name']; |
230 socket_write($sock, "PROFILE DEL ".$_POST['UUID'], 4096); |
230 |
231 /* Absorb response */ |
231 $sock = open_socket(); |
232 while (1) { |
232 if ($sock != false) { |
233 $line = socket_read($sock, 4096); |
233 /* |
234 if ($line === '') |
234 * Send command and absorb the result. |
235 break; |
235 */ |
236 } |
236 socket_write($sock, $update_cmd, 4096); |
237 socket_close($sock); |
237 while (1) { |
238 } |
238 $line = socket_read($sock, 4096); |
239 } |
239 if ($line === '') |
240 |
240 break; |
241 |
241 } |
242 if ($_POST['key'] == 'Save') { |
242 socket_close($sock); |
243 $sock = open_socket(); |
|
244 if ($sock != false) { |
|
245 /* |
|
246 * Send command and absorb the result. |
|
247 */ |
|
248 socket_write($sock, "PROFILE PUT ".$_POST['UUID'], 4096); |
|
249 usleep(20000); |
|
250 socket_write($sock, "NAME,".$_POST['Name'], 4096); |
|
251 usleep(20000); |
|
252 socket_write($sock, "INITTEMP,".$_POST['Inittemp'], 4096); |
|
253 usleep(20000); |
|
254 socket_write($sock, ".", 4096); |
|
255 while (1) { |
|
256 $line = socket_read($sock, 4096); |
|
257 if ($line === '') |
|
258 break; |
|
259 } |
|
260 socket_close($sock); |
|
261 } |
243 } |
262 } |
244 |
263 |
245 unset($_POST['UUID']); |
264 unset($_POST['UUID']); |
246 unset($_POST['Name']); |
265 unset($_POST['Name']); |
247 unset($_POST['Steps']); |
266 unset($_POST['Inittemp']); |
248 unset($_POST['key']); |
267 unset($_POST['key']); |
249 unset($_POST['command']); |
268 unset($_POST['command']); |
250 load('profiles.php'); |
269 load('profiles.php'); |
251 } |
270 } |
252 |
271 |
465 * @param string $Name The Profile Name. |
484 * @param string $Name The Profile Name. |
466 * @param string $command 'add' or 'update' |
485 * @param string $command 'add' or 'update' |
467 * @param string $heading Pagina heading title. |
486 * @param string $heading Pagina heading title. |
468 * @Param string $error_message Blank or previous error. |
487 * @Param string $error_message Blank or previous error. |
469 */ |
488 */ |
470 function edit_screen($UUID, $Name, $command, $heading, $error_message) { |
489 function edit_screen($UUID, $command, $heading, $error_message) { |
|
490 |
|
491 /* |
|
492 * Get current profile data |
|
493 */ |
|
494 $sock = open_socket(); |
|
495 if ($sock == false) { |
|
496 load("profiles.php"); |
|
497 return; |
|
498 } |
|
499 |
|
500 socket_write($sock, "PROFILE GET ".$UUID, 4096); |
|
501 $answer = ""; |
|
502 while (1) { |
|
503 $line = socket_read($sock, 4096); |
|
504 if ($line === '') |
|
505 break; |
|
506 $answer .= $line; |
|
507 } |
|
508 socket_close($sock); |
|
509 $reply = explode("\r\n", $answer); |
471 |
510 |
472 $outstr = build_header($heading); |
511 $outstr = build_header($heading); |
473 $outstr .= ' <div id="errors">'.PHP_EOL; |
512 $outstr .= ' <div id="errors">'.PHP_EOL; |
474 $outstr .= ' '.$error_message.PHP_EOL; |
513 $outstr .= ' '.$error_message.PHP_EOL; |
475 $outstr .= ' </div> <!-- errors -->'.PHP_EOL; |
514 $outstr .= ' </div> <!-- errors -->'.PHP_EOL; |
476 $outstr .= ' <div id="etable">'.PHP_EOL; |
515 $outstr .= ' <div id="etable">'.PHP_EOL; |
477 $outstr .= ' <form method="POST" action="profiles.php">'.PHP_EOL; |
516 $outstr .= ' <form method="POST" action="profiles.php">'.PHP_EOL; |
478 $outstr .= ' <table class="editor">'.PHP_EOL; |
517 $outstr .= ' <table class="editor">'.PHP_EOL; |
479 $outstr .= ' <tr class="editor">'.PHP_EOL; |
518 |
480 $outstr .= ' <td class="editname">UUID</td>'.PHP_EOL; |
519 if (startsWith($reply[0], "213")) { |
481 $outstr .= ' <td class="editfield">'.$UUID.'</td>'.PHP_EOL; |
520 $i = 1; |
482 $outstr .= ' </tr>'.PHP_EOL; |
521 while (1) { |
483 $outstr .= ' <tr class="editor">'.PHP_EOL; |
522 if (strcmp($reply[$i], ".") == 0) |
484 $outstr .= ' <td class="editname">Profile Name</td>'.PHP_EOL; |
523 break; |
485 $outstr .= ' <td class="editfield"><input type="text" name="Name" size="50" value="'.$Name.'"></td>'.PHP_EOL; |
524 $f = explode(",", $reply[$i]); |
486 $outstr .= ' </tr>'.PHP_EOL; |
525 |
487 $outstr .= ' <tr class="editor">'.PHP_EOL; |
526 if ($f[0] == "NAME") { |
488 $outstr .= ' <td class="editname">Profile Steps</td>'.PHP_EOL; |
527 $outstr .= ' <tr class="editor">'.PHP_EOL; |
489 $outstr .= ' <td class="editfield">'.$Steps.'</td>'.PHP_EOL; |
528 $outstr .= ' <td class="editname">Profile Name</td>'.PHP_EOL; |
490 $outstr .= ' </tr>'.PHP_EOL; |
529 $outstr .= ' <td class="editfield"><input type="text" name="Name" size="50" value="'.$f[1].'"></td>'.PHP_EOL; |
|
530 $outstr .= ' </tr>'.PHP_EOL; |
|
531 } |
|
532 if ($f[0] == "INITTEMP") { |
|
533 $outstr .= ' <tr class="editor">'.PHP_EOL; |
|
534 $outstr .= ' <td class="editname">Initial temperature</td>'.PHP_EOL; |
|
535 $outstr .= ' <td class="editfield"><input type="text" name="Inittemp" size="5" value="'.$f[1].'"></td>'.PHP_EOL; |
|
536 $outstr .= ' </tr>'.PHP_EOL; |
|
537 } |
|
538 $i++; |
|
539 } |
|
540 } |
491 $outstr .= ' <tr class="editor">'.PHP_EOL; |
541 $outstr .= ' <tr class="editor">'.PHP_EOL; |
492 $outstr .= ' <td class="editname"><input type="submit" value="Save" name="key"></td>'.PHP_EOL; |
542 $outstr .= ' <td class="editname"><input type="submit" value="Save" name="key"></td>'.PHP_EOL; |
493 $outstr .= ' <td class="editfield"><input type="submit" value="Cancel" name="key">'; |
543 $outstr .= ' <td class="editfield"><input type="submit" value="Cancel" name="key">'; |
494 $outstr .= '<input type="submit" value="Delete" name="key" style="margin-left: 100px;">'; |
544 $outstr .= '<input type="submit" value="Delete" name="key" style="margin-left: 100px;">'; |
495 $outstr .= '<input type="hidden" value="testdata" name="action">'; |
545 $outstr .= '<input type="hidden" value="testdata" name="action">'; |
510 * |
560 * |
511 * @param string $_GET['action'] Must be 'edit'. |
561 * @param string $_GET['action'] Must be 'edit'. |
512 * @param string $_GET['UUID'] The UUID of the Profile. |
562 * @param string $_GET['UUID'] The UUID of the Profile. |
513 */ |
563 */ |
514 function profile_edit() { |
564 function profile_edit() { |
515 |
|
516 global $arr; |
|
517 |
|
518 if ($_GET['action'] == 'edit') { |
565 if ($_GET['action'] == 'edit') { |
519 |
566 edit_screen($_GET['UUID'], 'update', 'ThermFerm - Edit Profile', ''); |
520 if (startsWith($arr[0], "212")) { |
567 return; |
521 $j = 1; |
|
522 while (1) { |
|
523 if (strcmp($arr[$j], ".") == 0) |
|
524 break; |
|
525 $f = explode(",", $arr[$j]); |
|
526 if (strcmp($f[0], $_GET['UUID']) == 0) { |
|
527 edit_screen($f[0], $f[1], 'update', 'ThermFerm - Edit Profile', ''); |
|
528 return; |
|
529 } |
|
530 $j++; |
|
531 } |
|
532 } else { |
|
533 load('profiles.php'); |
|
534 } |
|
535 |
|
536 } else { |
568 } else { |
537 load('profiles.php'); |
569 load('profiles.php'); |
538 } |
570 } |
539 } |
571 } |
540 |
572 |
593 $outstr .= ' <td class="editname">Profile Name</td>'.PHP_EOL; |
625 $outstr .= ' <td class="editname">Profile Name</td>'.PHP_EOL; |
594 $outstr .= ' <td class="editfield"><input type="text" name="Name" size="50" value=""></td>'.PHP_EOL; |
626 $outstr .= ' <td class="editfield"><input type="text" name="Name" size="50" value=""></td>'.PHP_EOL; |
595 $outstr .= ' <td class="editsub"><input type="submit" value="Add" name="key"></td>'.PHP_EOL; |
627 $outstr .= ' <td class="editsub"><input type="submit" value="Add" name="key"></td>'.PHP_EOL; |
596 $outstr .= '<input type="hidden" value="testdata" name="action">'; |
628 $outstr .= '<input type="hidden" value="testdata" name="action">'; |
597 $outstr .= '<input type="hidden" value="add" name="command">'; |
629 $outstr .= '<input type="hidden" value="add" name="command">'; |
598 $outstr .= '<input type="hidden" value="0" name="Steps"></td>'; |
|
599 $outstr .= '<input type="hidden" value="00000000-0000-0000-0000-000000000000" name="UUID">'; |
630 $outstr .= '<input type="hidden" value="00000000-0000-0000-0000-000000000000" name="UUID">'; |
|
631 $outstr .= '<input type="hidden" value="20.0" name="Inittemp"></td>'; |
600 $outstr .= ' </tr>'.PHP_EOL; |
632 $outstr .= ' </tr>'.PHP_EOL; |
601 $outstr .= ' </table>'.PHP_EOL; |
633 $outstr .= ' </table>'.PHP_EOL; |
602 $outstr .= ' </form>'.PHP_EOL; |
634 $outstr .= ' </form>'.PHP_EOL; |
603 |
635 |
604 $outstr .= ' </div> <!-- atable -->'.PHP_EOL; |
636 $outstr .= ' </div> <!-- atable -->'.PHP_EOL; |