diff -r 13555c27b592 -r 5b6d7b640e52 www-thermferm/global.php --- a/www-thermferm/global.php Thu Apr 25 14:26:47 2024 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,288 +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'); - - -if (isset($_POST['action'])) { - if ($_POST['action'] == "testdata") - testdata(); -} else { - edit_screen(""); -} - - -exit; - - -/***************************************************************************** - * - */ - - -function global_update() { - - if ($_POST['key'] == 'Save') { - $cmd = array("GLOBAL PUT"); - $cmd[] = "NAME,".$_POST['Name']; - $cmd[] = "PORT,".$_POST['Port']; - $cmd[] = "TEMP_UUID,".$_POST['TempAddress']; - $cmd[] = "HUM_UUID,".$_POST['HumAddress']; - $cmd[] = "TEMP_HUM_IDX,".$_POST['TempHumIdx']; - if (isset($_POST['LCDcols'])) - $cmd[] = "LCD_COLS,".$_POST['LCDcols']; - if (isset($_POST['LCDrows'])) - $cmd[] = "LCD_ROWS,".$_POST['LCDrows']; - $cmd[] = "MQTT_HOST,".$_POST['MQTThost']; - $cmd[] = "MQTT_POST,".$_POST['MQTTport']; - $cmd[] = "MQTT_USER,".$_POST['MQTTuser']; - $cmd[] = "MQTT_PASS,".$_POST['MQTTpass']; - $cmd[] = "."; - send_array($cmd); - } - - unset($_POST['Name']); - unset($_POST['Port']); - unset($_POST['TempAddress']); - unset($_POST['HumAddress']); - unset($_POST['TempHumIdx']); - unset($_POST['LCDcols']); - unset($_POST['LCDrows']); - unset($_POST['MQTThost']); - unset($_POST['MQTTport']); - unset($_POST['MQTTuser']); - unset($_POST['MQTTpass']); - unset($_POST['key']); - load('maintenance.php'); -} - - - -function test_thedata() { - - if (isset($_POST['Name']) && isset($_POST['Port']) && - isset($_POST['TempAddress']) && isset($_POST['HumAddress']) && - isset($_POST['TempHumIdx']) && isset($_POST['key']) && - isset($_POST['MQTThost']) && isset($_POST['MQTTport']) && - isset($_POST['MQTTuser']) && isset($_POST['MQTTpass'])) { - - if ($_POST['key'] == 'Cancel') - return 99; - - if (isset($_POST['LCDcols']) && (($_POST['LCDcols'] != 16) && ($_POST['LCDcols'] != 20))) - return 2; - - if (isset($_POST['LCDrows']) && (($_POST['LCDrows'] != 2) && ($_POST['LCDrows'] != 4))) - return 3; - - } else { - return 1; - } - - return 0; -} - - - -function testdata() -{ - $result = test_thedata(); - $error = ''; - - switch ($result) { - case 0: global_update(); - return; - break; - case 1: $error = 'Missing data'; - break; - case 2: $error = 'LCD columns must be 16 or 20'; - break; - case 3: $error = 'LCD rows must be 2 or 4'; - break; - case 99: - load('maintenance.php'); - break; - } - - edit_screen($error); -} - - - -function edit_screen($error_message) -{ - /* - * Get list of devices, we need it later - */ - $answer = send_cmd("DEVICE LIST"); - $devices = explode("\r\n", $answer); - - /* - * Get current global data - */ - $answer = send_cmd("GLOBAL GET"); - $reply = explode("\r\n", $answer); - - $outstr = build_header("ThermFerm - Global Setup"); - $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; - - if (startsWith($reply[0], "213")) { - $i = 1; - while (1) { - if (strcmp($reply[$i], ".") == 0) - break; - $f = explode(",", $reply[$i]); - - if ($f[0] == "NAME") { - $outstr .= ' '.PHP_EOL; - $outstr .= ' '.PHP_EOL; - $outstr .= ' '.PHP_EOL; - $outstr .= ' '.PHP_EOL; - } - if ($f[0] == "PORT") { - $outstr .= ' '.PHP_EOL; - $outstr .= ' '.PHP_EOL; - $outstr .= ' '.PHP_EOL; - $outstr .= ' '.PHP_EOL; - } - if ($f[0] == "TEMP_UUID") { - $outstr .= ' '.PHP_EOL; - $outstr .= ' '.PHP_EOL; - $outstr .= ' '.PHP_EOL; - $outstr .= ' '.PHP_EOL; - } - if ($f[0] == "HUM_UUID") { - $outstr .= ' '.PHP_EOL; - $outstr .= ' '.PHP_EOL; - $outstr .= ' '.PHP_EOL; - $outstr .= ' '.PHP_EOL; - } - if ($f[0] == "TEMP_HUM_IDX") { - $outstr .= ' '.PHP_EOL; - $outstr .= ' '.PHP_EOL; - $outstr .= ' '.PHP_EOL; - $outstr .= ' '.PHP_EOL; - } - if ($f[0] == "LCD_COLS") { - $outstr .= ' '.PHP_EOL; - $outstr .= ' '.PHP_EOL; - $outstr .= ' '.PHP_EOL; - $outstr .= ' '.PHP_EOL; - } - if ($f[0] == "LCD_ROWS") { - $outstr .= ' '.PHP_EOL; - $outstr .= ' '.PHP_EOL; - $outstr .= ' '.PHP_EOL; - $outstr .= ' '.PHP_EOL; - } - if ($f[0] == "MQTT_HOST") { - $outstr .= ' '.PHP_EOL; - $outstr .= ' '.PHP_EOL; - $outstr .= ' '.PHP_EOL; - $outstr .= ' '.PHP_EOL; - } - if ($f[0] == "MQTT_PORT") { - $outstr .= ' '.PHP_EOL; - $outstr .= ' '.PHP_EOL; - $outstr .= ' '.PHP_EOL; - $outstr .= ' '.PHP_EOL; - } - if ($f[0] == "MQTT_USER") { - $outstr .= ' '.PHP_EOL; - $outstr .= ' '.PHP_EOL; - if (strcmp($f[1], "(null)") == 0) { - $f[1] = ""; - } - $outstr .= ' '.PHP_EOL; - $outstr .= ' '.PHP_EOL; - } - if ($f[0] == "MQTT_PASS") { - $outstr .= ' '.PHP_EOL; - $outstr .= ' '.PHP_EOL; - if (strcmp($f[1], "(null)") == 0) { - $f[1] = ""; - } - $outstr .= ' '.PHP_EOL; - $outstr .= ' '.PHP_EOL; - } - $i++; - } - } - - $outstr .= ' '.PHP_EOL; - $outstr .= ' '.PHP_EOL; - $outstr .= ' '.PHP_EOL; - $outstr .= '
Global Setup
System Name
Telnet port
Room temperature sensor
Room humidity sensor
Domoticz TH index
LCD columns
LCD rows
MQTT host
MQTT port
MQTT username
MQTT password
'; - $outstr .= ''; - $outstr .= '
'.PHP_EOL; - $outstr .= '
'.PHP_EOL; - $outstr .= '
'.PHP_EOL; - $outstr .= ' '.PHP_EOL; - $outstr .= build_footer(); - - echo $outstr; -} - -