diff -r ffcabb9166bf -r 1b001de37945 www-thermferm/profiles.php --- a/www-thermferm/profiles.php Sat Jul 26 22:26:30 2014 +0200 +++ b/www-thermferm/profiles.php Sun Jul 27 17:06:08 2014 +0200 @@ -46,16 +46,21 @@ $arr = explode("\r\n", $answer); + if (isset($_GET['action'])) { switch ($_GET['action']) { case 'edit': profile_edit(); - break; + break; + case 'esteps': profile_steps(); + break; default: break; } } elseif (isset($_POST['action'])) { switch ($_POST['action']) { case 'testdata': testdata(); - break; + break; + case 'teststeps': teststeps(); + break; default: break; } } else { @@ -66,6 +71,111 @@ +/* + * Profile steps + */ +function profile_steps() +{ + global $arr; + $UUID = $_GET['UUID']; + + /* + * $steps contains all steps of a profile + */ + $steps = array ( + 1 => array("steptime" => 0, "resttime" => 1, "target" => 20.0 ), + 2 => array("steptime" => 0, "resttime" => 1, "target" => 20.0 ), + 3 => array("steptime" => 0, "resttime" => 1, "target" => 20.0 ), + 4 => array("steptime" => 0, "resttime" => 1, "target" => 20.0 ), + 5 => array("steptime" => 0, "resttime" => 1, "target" => 20.0 ), + 6 => array("steptime" => 0, "resttime" => 1, "target" => 20.0 ), + 7 => array("steptime" => 0, "resttime" => 1, "target" => 20.0 ), + 8 => array("steptime" => 0, "resttime" => 1, "target" => 20.0 ), + ); + + $sock = open_socket(); + if ($sock == false) { + load('profiles.php'); + } + + socket_write($sock, "PROFILES GETS ".$UUID, 4096); + $answer = ""; + while (1) { + $line = socket_read($sock, 4096); + if ($line === '') + break; + $answer .= $line; + } + socket_close($sock); + $psteps = explode("\r\n", $answer); + + if (startsWith($arr[0], "212")) { + $j = 1; + while (1) { + if (strcmp($psteps[$j], ".") == 0) + break; + $f = explode(",", $psteps[$j]); + $steps[$j]["steptime"] = $f[0]; + $steps[$j]["resttime"] = $f[1]; + $steps[$j]["target"] = $f[2]; + $j++; + } + } + + edit_steps($UUID, $steps, "", "ThermFerm - Edit Profile Steps"); +} + + +function edit_steps($UUID, $steps, $error_message, $heading) +{ + $outstr = build_header($heading); + $outstr .= '
'.PHP_EOL; + $outstr .= ' '.$error_message.PHP_EOL; + $outstr .= '
'.PHP_EOL; + $outstr .= '
'.PHP_EOL; + $outstr .= '
'.PHP_EOL; + $outstr .= ' '.PHP_EOL; + $outstr .= ' '.PHP_EOL; + $outstr .= ' '.PHP_EOL; + $outstr .= ' '.PHP_EOL; + $outstr .= ' '.PHP_EOL; + $outstr .= ' '.PHP_EOL; + $outstr .= ' '.PHP_EOL; + + for ($i = 1; $i <= 8; $i++) { + $outstr .= ' '.PHP_EOL; + $outstr .= ' '.PHP_EOL; + $outstr .= ' '.PHP_EOL; + $outstr .= ' '.PHP_EOL; + $outstr .= ' '.PHP_EOL; + $outstr .= ' '.PHP_EOL; + } + + $outstr .= ' '.PHP_EOL; + $outstr .= ' '.PHP_EOL; + $outstr .= ' '.PHP_EOL; + $outstr .= ' '.PHP_EOL; + $outstr .= ' '.PHP_EOL; + $outstr .= ' '.PHP_EOL; + $outstr .= '
StepSteptimeResttimeTemperature
Step '.$i.'
 '; + $outstr .= ''; + $outstr .= ' 
'.PHP_EOL; + $outstr .= '
'.PHP_EOL; + $outstr .= '
'.PHP_EOL; + $outstr .= '
'.PHP_EOL; + $outstr .= ' The steptime is the time to go from the previous to the target temperature.'.PHP_EOL; + $outstr .= ' The resttime is the total time in this step including the steptime.'.PHP_EOL; + $outstr .= ' Steps are valid if the steptime is greater then zero.'.PHP_EOL; + $outstr .= ' Order is important.'.PHP_EOL; + $outstr .= ' Lines with a steptime of zero are ignored.'.PHP_EOL; + $outstr .= ' The step- and resttimes are in hours.'.PHP_EOL; + $outstr .= '
'.PHP_EOL; + $outstr .= build_footer(); + echo $outstr; +} + + + /* * Profile add @@ -74,24 +184,27 @@ */ function profile_add() { - $cmd = "ADD PROFILE ".$_POST['Name']; + if ($_POST['key'] == 'Add') { + + $cmd = "ADD PROFILE ".$_POST['Name']; - $sock = open_socket(); - if ($sock != false) { - /* - * Send command and absorb the result. - */ - socket_write($sock, $cmd, 4096); - 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, $cmd, 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['key']); unset($_POST['command']); load('profiles.php'); @@ -131,6 +244,7 @@ unset($_POST['UUID']); unset($_POST['Name']); + unset($_POST['Steps']); unset($_POST['key']); unset($_POST['command']); load('profiles.php'); @@ -142,7 +256,117 @@ * Test input of a modified or new profile. * * @param string $_POST['UUID'] Unique record UUID + * @param int $_POST['steptime'n] Profile steptime + * @param int $_POST['resttime'n] Profile resttime + * @param float $_POST['target'n] Profile target temperature + * @param string $_POST['key'] Key choice, Save or Cancel + * + * Return: 0 = Ok + * 1 = Missing data + * 2 = A resttime < steptime + * 3 = A target temperature out of range + * 99 = Cancel key + */ +function test_thesteps() { + + global $arr; + + print_r($_POST); + + for ($i = 1; $i <= 8; $i++) { + if ((! isset($_POST['steptime'.$i])) || (! isset($_POST['resttime'.$i])) || (! isset($_POST['target'.$i]))) + return 1; + if ((strlen($_POST['steptime'.$i]) == 0) || (strlen($_POST['resttime'.$i]) == 0) || (strlen($_POST['target'.$i]) == 0)) + return 1; + } + + if (isset($_POST['UUID']) && isset($_POST['key'])) { + + if ($_POST['key'] == 'Cancel') + return 99; + + for ($i = 1; $i <= 8; $i++) { + if ($_POST['resttime'.$i] < $_POST['steptime'.$i]) + return 2; + + if (($_POST['target'.$i] < -5) || ($_POST['target'.$i] > 30)) + return 3; + } + } else { + return 1; + } + + return 0; +} + + + +/* + * Test result from edit_steps screen and do next action + */ +function teststeps() { + + $result = test_thesteps(); + $error = ''; + + switch ($result) { + case 0: $sock = open_socket(); + if ($sock != false) { + socket_write($sock, 'PROFILE PUTS '.$_POST['UUID'], 4096); + for ($i = 1; $i <= 8; $i++) { + if ($_POST['steptime'.$i] > 0) + socket_write($sock, $_POST['steptime'.$i].','.$_POST['resttime'.$i].','.$_POST['target'.$i], 4096); + unset($_POST['steptime'.$i]); + unset($_POST['resttime'.$i]); + unset($_POST['target'.$i]); + } + socket_write($sock, '.', 4096); + /* Absorb response */ + while (1) { + $line = socket_read($sock, 4096); + if ($line === '') + break; + } + socket_close($sock); + unset($_POST['UUID']); + unset($_POST['key']); + load('profiles.php'); + return; + } + break; + case 1: $error = 'Missing data'; + break; + case 2: $error = 'A resttime is shorter then the steptime'; + break; + case 3: $error = 'A target temperature is out of range'; + break; + case 99: + load('profiles.php'); + break; + } + + $steps = array ( + 1 => array("steptime" => $_POST['steptime1'], "resttime" => $_POST['resttime1'], "target" => $_POST['target1'] ), + 2 => array("steptime" => $_POST['steptime2'], "resttime" => $_POST['resttime2'], "target" => $_POST['target2'] ), + 3 => array("steptime" => $_POST['steptime3'], "resttime" => $_POST['resttime3'], "target" => $_POST['target3'] ), + 4 => array("steptime" => $_POST['steptime4'], "resttime" => $_POST['resttime4'], "target" => $_POST['target4'] ), + 5 => array("steptime" => $_POST['steptime5'], "resttime" => $_POST['resttime5'], "target" => $_POST['target5'] ), + 6 => array("steptime" => $_POST['steptime6'], "resttime" => $_POST['resttime6'], "target" => $_POST['target6'] ), + 7 => array("steptime" => $_POST['steptime7'], "resttime" => $_POST['resttime7'], "target" => $_POST['target7'] ), + 8 => array("steptime" => $_POST['steptime8'], "resttime" => $_POST['resttime8'], "target" => $_POST['target8'] ), + ); + + edit_steps($_POST['UUID'], $steps, $error, "ThermFerm - Edit Profile Steps"); +} + + + +/* + * Test input of a modified or new profile. + * + * @param string $_POST['UUID'] Unique record UUID * @param string $_POST['Name'] Profile name + * @param int $_POST['Steps'] Profile steps * @param string $_POST['key'] Key choice, Save or Cancel * @param string $_POST['command'] Command used, 'add' or 'update' * @@ -252,6 +476,10 @@ $outstr .= ' '.PHP_EOL; $outstr .= ' '.PHP_EOL; $outstr .= ' '.PHP_EOL; + $outstr .= ' Profile Steps'.PHP_EOL; + $outstr .= ' '.$Steps.''.PHP_EOL; + $outstr .= ' '.PHP_EOL; + $outstr .= ' '.PHP_EOL; $outstr .= ' '.PHP_EOL; $outstr .= ' '; $outstr .= ''; @@ -317,11 +545,11 @@ $outstr .= ' '.PHP_EOL; $outstr .= '
'.PHP_EOL; $outstr .= ' '.PHP_EOL; - $outstr .= ' '.PHP_EOL; - $outstr .= ' '.PHP_EOL; - $outstr .= ' '.PHP_EOL; - $outstr .= ' '.PHP_EOL; - $outstr .= ' '.PHP_EOL; + $outstr .= ' '.PHP_EOL; + $outstr .= ' '.PHP_EOL; + $outstr .= ' '.PHP_EOL; + $outstr .= ' '.PHP_EOL; + $outstr .= ' '.PHP_EOL; $outstr .= ' '.PHP_EOL; if (startsWith($arr[0], "212")) { @@ -333,11 +561,13 @@ $outstr .= ' '.PHP_EOL; $outstr .= ' '.PHP_EOL; $outstr .= ' '.PHP_EOL; - $outstr .= ' '.PHP_EOL; - if ($f[3] == 1) + if ($f[3] == 1) { + $outstr .= ' '.PHP_EOL; $outstr .= ' '.PHP_EOL; - else - $outstr .= ' '.PHP_EOL; + } else { + $outstr .= ' '.PHP_EOL; + $outstr .= ' '.PHP_EOL; + } $outstr .= ' '.PHP_EOL; $j++; } @@ -349,14 +579,14 @@ $outstr .= ' '.PHP_EOL; $outstr .= '
UUIDNameStepsEdit
UUIDNameStepsEdit
'.$f[0].''.$f[1].''.$f[2].''.$f[2].'BusyEdit'.$f[2].'Edit
'.PHP_EOL; + $outstr .= ' '.PHP_EOL; $outstr .= ' '.PHP_EOL; $outstr .= ' '.PHP_EOL; - $outstr .= ' '.PHP_EOL; - $outstr .= ' '.PHP_EOL; - $outstr .= ' '.PHP_EOL; - $outstr .= ' '.PHP_EOL; + $outstr .= ' '.PHP_EOL; + $outstr .= ' '.PHP_EOL; $outstr .= ''; $outstr .= ''; + $outstr .= ''; $outstr .= ''; $outstr .= ' '.PHP_EOL; $outstr .= '
Add new profile
Profile Name
'.PHP_EOL;