--- a/www-thermferm/profiles.php Thu Aug 07 19:38:30 2014 +0200 +++ b/www-thermferm/profiles.php Thu Aug 07 20:34:07 2014 +0200 @@ -186,7 +186,7 @@ if ($_POST['key'] == 'Add') { - $cmd = "ADD PROFILE ".$_POST['Name']; + $cmd = "PROFILE ADD ".$_POST['Name']; $sock = open_socket(); if ($sock != false) { @@ -213,38 +213,57 @@ /* - * Profile update + * Profile update or delete * * @param string $_POST['UUID'] The profile UUID * @param string $_POST['Name'] The profile name + * @param string $_POST['Inittemp'] The profile initial temperature * @param string $_POST['key'] The button pressed. */ function profile_update() { /* * Build the update command */ - if ($_POST['key'] == 'Delete') - $update_cmd = "DEL PROFILE ".$_POST['UUID']; - else - $update_cmd = "PROFILE ".$_POST['UUID'].",".$_POST['Name']; + if ($_POST['key'] == 'Delete') { + $sock = open_socket(); + if ($sock != false) { + socket_write($sock, "PROFILE DEL ".$_POST['UUID'], 4096); + /* Absorb response */ + while (1) { + $line = socket_read($sock, 4096); + if ($line === '') + break; + } + socket_close($sock); + } + } + - $sock = open_socket(); - if ($sock != false) { - /* - * Send command and absorb the result. - */ - socket_write($sock, $update_cmd, 4096); - while (1) { - $line = socket_read($sock, 4096); - if ($line === '') - break; - } - socket_close($sock); + if ($_POST['key'] == 'Save') { + $sock = open_socket(); + if ($sock != false) { + /* + * Send command and absorb the result. + */ + socket_write($sock, "PROFILE PUT ".$_POST['UUID'], 4096); + usleep(20000); + socket_write($sock, "NAME,".$_POST['Name'], 4096); + usleep(20000); + socket_write($sock, "INITTEMP,".$_POST['Inittemp'], 4096); + usleep(20000); + socket_write($sock, ".", 4096); + while (1) { + $line = socket_read($sock, 4096); + if ($line === '') + break; + } + socket_close($sock); + } } unset($_POST['UUID']); unset($_POST['Name']); - unset($_POST['Steps']); + unset($_POST['Inittemp']); unset($_POST['key']); unset($_POST['command']); load('profiles.php'); @@ -375,7 +394,7 @@ * * @param string $_POST['UUID'] Unique record UUID * @param string $_POST['Name'] Profile name - * @param int $_POST['Steps'] Profile steps + * @param float $_POST['Inittemp'] Profile initial temperature * @param string $_POST['key'] Key choice, Save or Cancel * @param string $_POST['command'] Command used, 'add' or 'update' * @@ -389,7 +408,7 @@ global $arr; - if (isset($_POST['UUID']) && isset($_POST['Name']) && isset($_POST['key']) && isset($_POST['command'])) { + if (isset($_POST['UUID']) && isset($_POST['Name']) && isset($_POST['Inittemp']) && isset($_POST['key']) && isset($_POST['command'])) { if ($_POST['key'] == 'Cancel') return 99; @@ -453,7 +472,7 @@ $heading = 'ThermFerm - Edit Profile'; } - edit_screen($_POST['UUID'], $_POST['Name'], $_POST['command'], $heading, $error); + edit_screen($_POST['UUID'], $_POST['command'], $heading, $error); } @@ -467,7 +486,27 @@ * @param string $heading Pagina heading title. * @Param string $error_message Blank or previous error. */ -function edit_screen($UUID, $Name, $command, $heading, $error_message) { +function edit_screen($UUID, $command, $heading, $error_message) { + + /* + * Get current profile data + */ + $sock = open_socket(); + if ($sock == false) { + load("profiles.php"); + return; + } + + socket_write($sock, "PROFILE GET ".$UUID, 4096); + $answer = ""; + while (1) { + $line = socket_read($sock, 4096); + if ($line === '') + break; + $answer .= $line; + } + socket_close($sock); + $reply = explode("\r\n", $answer); $outstr = build_header($heading); $outstr .= ' <div id="errors">'.PHP_EOL; @@ -476,18 +515,29 @@ $outstr .= ' <div id="etable">'.PHP_EOL; $outstr .= ' <form method="POST" action="profiles.php">'.PHP_EOL; $outstr .= ' <table class="editor">'.PHP_EOL; - $outstr .= ' <tr class="editor">'.PHP_EOL; - $outstr .= ' <td class="editname">UUID</td>'.PHP_EOL; - $outstr .= ' <td class="editfield">'.$UUID.'</td>'.PHP_EOL; - $outstr .= ' </tr>'.PHP_EOL; - $outstr .= ' <tr class="editor">'.PHP_EOL; - $outstr .= ' <td class="editname">Profile Name</td>'.PHP_EOL; - $outstr .= ' <td class="editfield"><input type="text" name="Name" size="50" value="'.$Name.'"></td>'.PHP_EOL; - $outstr .= ' </tr>'.PHP_EOL; - $outstr .= ' <tr class="editor">'.PHP_EOL; - $outstr .= ' <td class="editname">Profile Steps</td>'.PHP_EOL; - $outstr .= ' <td class="editfield">'.$Steps.'</td>'.PHP_EOL; - $outstr .= ' </tr>'.PHP_EOL; + + if (startsWith($reply[0], "213")) { + $i = 1; + while (1) { + if (strcmp($reply[$i], ".") == 0) + break; + $f = explode(",", $reply[$i]); + + if ($f[0] == "NAME") { + $outstr .= ' <tr class="editor">'.PHP_EOL; + $outstr .= ' <td class="editname">Profile Name</td>'.PHP_EOL; + $outstr .= ' <td class="editfield"><input type="text" name="Name" size="50" value="'.$f[1].'"></td>'.PHP_EOL; + $outstr .= ' </tr>'.PHP_EOL; + } + if ($f[0] == "INITTEMP") { + $outstr .= ' <tr class="editor">'.PHP_EOL; + $outstr .= ' <td class="editname">Initial temperature</td>'.PHP_EOL; + $outstr .= ' <td class="editfield"><input type="text" name="Inittemp" size="5" value="'.$f[1].'"></td>'.PHP_EOL; + $outstr .= ' </tr>'.PHP_EOL; + } + $i++; + } + } $outstr .= ' <tr class="editor">'.PHP_EOL; $outstr .= ' <td class="editname"><input type="submit" value="Save" name="key"></td>'.PHP_EOL; $outstr .= ' <td class="editfield"><input type="submit" value="Cancel" name="key">'; @@ -512,27 +562,9 @@ * @param string $_GET['UUID'] The UUID of the Profile. */ function profile_edit() { - - global $arr; - if ($_GET['action'] == 'edit') { - - if (startsWith($arr[0], "212")) { - $j = 1; - while (1) { - if (strcmp($arr[$j], ".") == 0) - break; - $f = explode(",", $arr[$j]); - if (strcmp($f[0], $_GET['UUID']) == 0) { - edit_screen($f[0], $f[1], 'update', 'ThermFerm - Edit Profile', ''); - return; - } - $j++; - } - } else { - load('profiles.php'); - } - + edit_screen($_GET['UUID'], 'update', 'ThermFerm - Edit Profile', ''); + return; } else { load('profiles.php'); } @@ -595,8 +627,8 @@ $outstr .= ' <td class="editsub"><input type="submit" value="Add" name="key"></td>'.PHP_EOL; $outstr .= '<input type="hidden" value="testdata" name="action">'; $outstr .= '<input type="hidden" value="add" name="command">'; - $outstr .= '<input type="hidden" value="0" name="Steps"></td>'; $outstr .= '<input type="hidden" value="00000000-0000-0000-0000-000000000000" name="UUID">'; + $outstr .= '<input type="hidden" value="20.0" name="Inittemp"></td>'; $outstr .= ' </tr>'.PHP_EOL; $outstr .= ' </table>'.PHP_EOL; $outstr .= ' </form>'.PHP_EOL;