diff -r 13555c27b592 -r 5b6d7b640e52 www-thermferm/simulator.php --- a/www-thermferm/simulator.php Thu Apr 25 14:26:47 2024 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,452 +0,0 @@ - - * - * This file is part of ThermFerm - * - * This is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation; either version 2, or (at your option) any - * later version. - * - * ThermFerm is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with ThermFerm; see the file COPYING. If not, write to the Free - * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. - *****************************************************************************/ - -require_once('utilities.php'); - -/* - * $arr contains the complete reply of the SIMULATOR LIST command - */ -$answer = send_cmd("SIMULATOR LIST"); -$arr = explode("\r\n", $answer); - - -if (isset($_GET['action'])) { - switch ($_GET['action']) { - case 'edit': simulator_edit(); - break; - default: break; - } -} elseif (isset($_POST['action'])) { - switch ($_POST['action']) { - case 'testdata': testdata(); - break; - default: break; - } -} else { - simulator_list(); -} - -exit; - -/**************************************************************************** - * - */ - - -/* - * Simulator add - * - * @param string $_POST['Name'] The simulator name - */ -function simulator_add() { - if ($_POST['key'] == 'Add') - send_cmd("SIMULATOR ADD ".$_POST['Name']); - unset($_POST['UUID']); - unset($_POST['Name']); - unset($_POST['key']); - unset($_POST['command']); - load('simulator.php'); -} - - - -/* - * Simulator update - * - * @param string $_POST['UUID'] The simulator UUID - * @param string $_POST['Name'] The simulator name - * @param string $_POST['VolumeAir'] The simulator Air volume - * @param string $_POST['VolumeBeer'] The simulator Beer volume - * @param string $_POST['RoomTemperature'] The simulator room temp - * @param string $_POST['RoomHumidity'] The simulator room humidity - * @param string $_POST['CoolerTemp'] The simulator cold temp - * @param string $_POST['CoolerTime'] The simulator time to reach this - * @param string $_POST['CoolerSize'] The simulator plate size - * @param string $_POST['HeaterTemp'] The simulator heater temp - * @param string $_POST['HeaterTime'] The simulator time to reach this - * @param string $_POST['HeaterSize'] The simulator plate size - * @param string $_POST['FrigoIsolation'] The simulator isolation - * @param string $_POST['key'] The button pressed. - */ -function simulator_update() { - /* - * Build the update command - */ - if ($_POST['key'] == 'Delete') { - send_cmd("SIMULATOR DEL ".$_POST['UUID']); - } - - if ($_POST['key'] == 'Save') { - $cmd = array("SIMULATOR PUT ".$_POST['UUID']); - $cmd[] = "NAME,".$_POST['Name']; - $cmd[] = "VOLUME_AIR,".$_POST['VolumeAir']; - $cmd[] = "VOLUME_BEER,".$_POST['VolumeBeer']; - $cmd[] = "ROOM_TEMPERATURE,".$_POST['RoomTemperature']; - $cmd[] = "ROOM_HUMIDITY,".$_POST['RoomHumidity']; - $cmd[] = "COOLER_TEMP,".$_POST['CoolerTemp']; - $cmd[] = "COOLER_TIME,".$_POST['CoolerTime']; - $cmd[] = "COOLER_SIZE,".$_POST['CoolerSize']; - $cmd[] = "HEATER_TEMP,".$_POST['HeaterTemp']; - $cmd[] = "HEATER_TIME,".$_POST['HeaterTime']; - $cmd[] = "HEATER_SIZE,".$_POST['HeaterSize']; - $cmd[] = "FRIGO_ISOLATION,".$_POST['FrigoIsolation']; - $cmd[] = "."; - send_array($cmd); - } - - unset($_POST['UUID']); - unset($_POST['Name']); - unset($_POST['VolumeAir']); - unset($_POST['VolumeBeer']); - unset($_POST['RoomTemperature']); - unset($_POST['RoomHumidity']); - unset($_POST['CoolerTemp']); - unset($_POST['CoolerTime']); - unset($_POST['CoolerSize']); - unset($_POST['HeaterTemp']); - unset($_POST['HeaterTime']); - unset($_POST['HeaterSize']); - unset($_POST['FrigoIsolation']); - unset($_POST['key']); - unset($_POST['command']); - load('simulator.php'); -} - - - -/* - * Test input of a modified or new simulator. - * - * @param string $_POST['UUID'] Unique record UUID - * @param string $_POST['Name'] The simulator name - * @param string $_POST['VolumeAir'] The simulator Air volume - * @param string $_POST['VolumeBeer'] The simulator Beer volume - * @param string $_POST['RoomTemperature'] The simulator room temp - * @param string $_POST['RoomHumidity'] The simulator room humidity - * @param string $_POST['CoolerTemp'] The simulator cold temp - * @param string $_POST['CoolerTime'] The simulator time to reach this - * @param string $_POST['CoolerSize'] The simulator plate size - * @param string $_POST['HeaterTemp'] The simulator heater temp - * @param string $_POST['HeaterTime'] The simulator time to reach this - * @param string $_POST['HeaterSize'] The simulator plate size - * @param string $_POST['FrigoIsolation'] The simulator isolation - * @param string $_POST['key'] Key choice, Save or Cancel - * @param string $_POST['command'] Command used, 'add' or 'update' - * - * Return: 0 = Ok - * 1 = Missing data - * 2 = Name too short - * 3 = Name already in use - * 99 = Cancel key - */ -function test_thedata() { - - global $arr; - - if (isset($_POST['UUID']) && isset($_POST['Name']) && isset($_POST['VolumeAir']) && isset($_POST['VolumeBeer']) && - isset($_POST['RoomTemperature']) && isset($_POST['RoomHumidity']) && isset($_POST['CoolerTemp']) && isset($_POST['CoolerTime']) && - isset($_POST['CoolerSize']) && isset($_POST['HeaterTemp']) && isset($_POST['HeaterTime']) && isset($_POST['HeaterSize']) && - isset($_POST['FrigoIsolation']) && isset($_POST['key']) && isset($_POST['command'])) { - - if ($_POST['key'] == 'Cancel') - return 99; - - if (strlen($_POST['Name']) < 2) - return 2; - - if (startsWith($arr[0], "212")) { - $j = 1; - while (1) { - if (strcmp($arr[$j], ".") == 0) - break; - $f = explode(",", $arr[$j]); - if (strcmp($f[0], $_POST['UUID']) && ($f[1] == $_POST['Name'])) { - return 3; - } - $j++; - } - } - - } else { - return 1; - } - - return 0; -} - - - -/* - * Test result from edit screen and do next action - */ -function testdata() { - - $result = test_thedata(); - $error = ''; - - switch ($result) { - case 0: if ($_POST['command'] == 'add') { - simulator_add(); - return; - } else if ($_POST['command'] == 'update') { - simulator_update(); - return; - } - break; - case 1: $error = 'Missing data'; - break; - case 2: $error = 'The Name is too short'; - break; - case 3: $error = 'The Name is already in use, choose another one'; - break; - case 99: - load('simulator.php'); - break; - } - - if ($_POST['command'] == 'add') { - $heading = 'ThermFerm - Add Simulator'; - } else { - $heading = 'ThermFerm - Edit Simulator'; - } - - edit_screen($_POST['UUID'], $_POST['command'], $heading, $error); -} - - - -/* - * Simulator edit screen. Used by simulator_edit(), simulator_add() and testdata() - * - * @param string $UUID The record UUID (fixed). - * @param string $command 'add' or 'update' - * @param string $heading Page heading title. - * @Param string $error_message Blank or previous error. - */ -function edit_screen($UUID, $command, $heading, $error_message) { - - $answer = send_cmd("SIMULATOR GET ".$UUID); - $reply = explode("\r\n", $answer); - - $outstr = build_header($heading); - $outstr .= '
'.PHP_EOL; - $outstr .= ' '.$error_message.PHP_EOL; - $outstr .= '
'.PHP_EOL; - $outstr .= '
'.PHP_EOL; - $outstr .= '
'.PHP_EOL; - $outstr .= ' '.PHP_EOL; - - if (startsWith($reply[0], "213")) { - $j = 1; - while (1) { - if (strcmp($reply[$j], ".") == 0) - break; - $f = explode(",", $reply[$j]); - if ($f[0] == "NAME") { - $outstr .= ' '.PHP_EOL; - $outstr .= ' '.PHP_EOL; - $outstr .= ' '.PHP_EOL; - $outstr .= ' '.PHP_EOL; - } - if ($f[0] == "VOLUME_AIR") { - $outstr .= ' '.PHP_EOL; - $outstr .= ' '.PHP_EOL; - $outstr .= ' '.PHP_EOL; - $outstr .= ' '.PHP_EOL; - } - if ($f[0] == "VOLUME_BEER") { - $outstr .= ' '.PHP_EOL; - $outstr .= ' '.PHP_EOL; - $outstr .= ' '.PHP_EOL; - $outstr .= ' '.PHP_EOL; - } - if ($f[0] == "ROOM_TEMPERATURE") { - $outstr .= ' '.PHP_EOL; - $outstr .= ' '.PHP_EOL; - $outstr .= ' '.PHP_EOL; - $outstr .= ' '.PHP_EOL; - } - if ($f[0] == "ROOM_HUMIDITY") { - $outstr .= ' '.PHP_EOL; - $outstr .= ' '.PHP_EOL; - $outstr .= ' '.PHP_EOL; - $outstr .= ' '.PHP_EOL; - } - if ($f[0] == "COOLER_TEMP") { - $outstr .= ' '.PHP_EOL; - $outstr .= ' '.PHP_EOL; - $outstr .= ' '.PHP_EOL; - $outstr .= ' '.PHP_EOL; - } - if ($f[0] == "COOLER_TIME") { - $outstr .= ' '.PHP_EOL; - $outstr .= ' '.PHP_EOL; - $outstr .= ' '.PHP_EOL; - $outstr .= ' '.PHP_EOL; - } - if ($f[0] == "COOLER_SIZE") { - $outstr .= ' '.PHP_EOL; - $outstr .= ' '.PHP_EOL; - $outstr .= ' '.PHP_EOL; - $outstr .= ' '.PHP_EOL; - } - if ($f[0] == "HEATER_TEMP") { - $outstr .= ' '.PHP_EOL; - $outstr .= ' '.PHP_EOL; - $outstr .= ' '.PHP_EOL; - $outstr .= ' '.PHP_EOL; - } - if ($f[0] == "HEATER_TIME") { - $outstr .= ' '.PHP_EOL; - $outstr .= ' '.PHP_EOL; - $outstr .= ' '.PHP_EOL; - $outstr .= ' '.PHP_EOL; - } - if ($f[0] == "HEATER_SIZE") { - $outstr .= ' '.PHP_EOL; - $outstr .= ' '.PHP_EOL; - $outstr .= ' '.PHP_EOL; - $outstr .= ' '.PHP_EOL; - } - if ($f[0] == "FRIGO_ISOLATION") { - $outstr .= ' '.PHP_EOL; - $outstr .= ' '.PHP_EOL; - $outstr .= ' '.PHP_EOL; - $outstr .= ' '.PHP_EOL; - } - $j++; - } - } - - $outstr .= ' '.PHP_EOL; - $outstr .= ' '.PHP_EOL; - $outstr .= ' '.PHP_EOL; - $outstr .= ' '.PHP_EOL; - $outstr .= '
Name
Volume Air
Volume Beer
Room Temperature
Room Humidity
Cooler Temperature
Cooler Time
Cooler Size
Heater Temperature
Heater Time
Heater Size
Frigo Isolation
'; - $outstr .= ''; - $outstr .= ''; - $outstr .= ''; - $outstr .= '
'.PHP_EOL; - $outstr .= '
'.PHP_EOL; - $outstr .= '
'.PHP_EOL; - $outstr .= ' '.PHP_EOL; - $outstr .= build_footer(); - echo $outstr; -} - - - -/* - * Edit a Simulator. Fetches the record data and shows the edit screen. - * - * @param string $_GET['action'] Must be 'edit'. - * @param string $_GET['UUID'] The UUID of the Unit. - */ -function simulator_edit() { - if ($_GET['action'] == 'edit') { - edit_screen($_GET['UUID'], 'update', 'ThermFerm - Edit Simulator', ''); - return; - } else { - load('simulator.php'); - } -} - - - -/* - * @link edit simulator - * @link add simulator - */ -function simulator_list() { - global $arr; - - $outstr = build_header("ThermFerm - Simulator Setup"); - $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")) { - $j = 1; - while (1) { - if (strcmp($arr[$j], ".") == 0) - break; - $f = explode(",", $arr[$j]); - $outstr .= ' '.PHP_EOL; - $outstr .= ' '.PHP_EOL; - $outstr .= ' '.PHP_EOL; - $outstr .= ' '.PHP_EOL; - $outstr .= ' '.PHP_EOL; - $j++; - } - } - - $outstr .= '
UUIDNameEdit
'.$f[0].''.$f[1].'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 .= ''; - $outstr .= ''; - $outstr .= ''; - $outstr .= ''; - $outstr .= ''; - $outstr .= ''; - $outstr .= ''; - $outstr .= ''; - $outstr .= ''; - $outstr .= ''; - $outstr .= ' '.PHP_EOL; - $outstr .= '
Add new Simulator
Simulator Name
'.PHP_EOL; - $outstr .= '
'.PHP_EOL; - $outstr .= '
'.PHP_EOL; - - $outstr .= ' '.PHP_EOL; - $outstr .= build_footer(); - - echo $outstr; -} -