From 381fe184bd1f37008f5d7687872012096303945d Mon Sep 17 00:00:00 2001 From: stevenA Date: Wed, 19 Jan 2022 12:07:41 +0100 Subject: [PATCH] Fix Issue #59 Correct error in update mode selection Save all buttons, rather than to last empty - buttons do not need to be allocated sequentially Remove on duplicate case - add should always be new as either device is new, or have deleted device data before. --- Sccp_manager.class.php | 49 +++++++++++----------------- sccpManClasses/dbinterface.class.php | 24 ++------------ sccpManTraits/ajaxHelper.php | 4 +-- 3 files changed, 23 insertions(+), 54 deletions(-) diff --git a/Sccp_manager.class.php b/Sccp_manager.class.php index a74a5d8..dcff7d8 100644 --- a/Sccp_manager.class.php +++ b/Sccp_manager.class.php @@ -390,21 +390,10 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO { // $lines_list = $this->dbinterface->getSccpDeviceTableData('SccpExtension'); $max_btn = (!empty($get_settings['buttonscount']) ? $get_settings['buttonscount'] : 60); - $last_btn = $max_btn; - for ($it = $max_btn; $it >= 0; $it--) { - if (!empty($get_settings['button' . $it . '_type'])) { - $last_btn = $it; - $btn_t = $get_settings['button' . $it . '_type']; - if ($btn_t != 'empty') { - break; - } - } - } - - for ($it = 0; $it <= $last_btn; $it++) { - if (!empty($get_settings['button' . $it . '_type'])) { - $btn_t = $get_settings['button' . $it . '_type']; + for ($it = 0; $it < $max_btn; $it++) { + if (!empty($get_settings["button${it}_type"])) { + $btn_t = $get_settings["button${it}_type"]; $btn_n = ''; $btn_opt = ''; if ($it == 0) { @@ -412,9 +401,9 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO { } switch ($btn_t) { case 'feature': - $btn_f = $get_settings['button' . $it . '_feature']; + $btn_f = $get_settings["button${it}_feature"]; // $btn_opt = (empty($get_settings['button' . $it . '_fvalue'])) ? '' : $get_settings['button' . $it . '_fvalue']; - $btn_n = (empty($get_settings['button' . $it . '_flabel'])) ? $def_feature[$btn_f]['name'] : $get_settings['button' . $it . '_flabel']; + $btn_n = (empty($get_settings["button${it}_flabel"])) ? $def_feature[$btn_f]['name'] : $get_settings["button${it}_flabel"]; $btn_opt = $btn_f; if (!empty($def_feature[$btn_f]['value'])) { if (empty($get_settings['button' . $it . '_fvalue'])) { @@ -432,46 +421,46 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO { break; case 'monitor': $btn_t = 'speeddial'; - $btn_opt = (string) $get_settings['button' . $it . '_line']; + $btn_opt = (string) $get_settings["button${it}_line"]; $db_res = $this->dbinterface->getSccpDeviceTableData('SccpExtension', array('name' => $btn_opt)); $btn_n = $db_res[0]['label']; $btn_opt .= ',' . $btn_opt . $this->hint_context['default']; break; case 'speeddial': - if (!empty($get_settings['button' . $it . '_input'])) { - $btn_n = $get_settings['button' . $it . '_input']; + if (!empty($get_settings["button${it}_input"])) { + $btn_n = $get_settings["button${it}_input"]; } - if (!empty($get_settings['button' . $it . '_phone'])) { - $btn_opt = $get_settings['button' . $it . '_phone']; + if (!empty($get_settings["button${it}_phone"])) { + $btn_opt = $get_settings["button${it}_phone"]; if (empty($btn_n)) { $btn_n = $btn_opt; } } - if (!empty($get_settings['button' . $it . '_hint'])) { - if ($get_settings['button' . $it . '_hint'] == "hint") { + if (!empty($get_settings["button${it}_hint"])) { + if ($get_settings["button${it}_hint"] == "hint") { if (empty($btn_n)) { $btn_t = 'line'; - $btn_n = $get_settings['button' . $it . '_hline'] . '!silent'; + $btn_n = $get_settings["button${it}_hline"] . '!silent'; $btn_opt = ''; } else { // $btn_opt .= ',' . $get_settings['button' . $it . '_hline'] . $this->hint_context['default']; - $btn_opt .= ',' . $get_settings['button' . $it . '_hline']; + $btn_opt .= ',' . $get_settings["button${it}_hline"]; } } } break; case 'adv.line': $btn_t = 'line'; - $btn_n = (string) $get_settings['button' . $it . '_line']; - $btn_n .= '@' . (string) $get_settings['button' . $it . '_advline']; - $btn_opt = (string) $get_settings['button' . $it . '_advopt']; + $btn_n = (string) $get_settings["button${it}_line"]; + $btn_n .= '@' . (string) $get_settings["button${it}_advline"]; + $btn_opt = (string) $get_settings["button${it}_advopt"]; break; case 'line': case 'silent': - if (isset($get_settings['button' . $it . '_line'])) { - $btn_n = (string) $get_settings['button' . $it . '_line']; + if (isset($get_settings["button${it}_line"])) { + $btn_n = (string) $get_settings["button${it}_line"]; if ($it > 0) { if ($btn_t == 'silent') { $btn_n .= '!silent'; diff --git a/sccpManClasses/dbinterface.class.php b/sccpManClasses/dbinterface.class.php index c0fa897..3dc9e7b 100644 --- a/sccpManClasses/dbinterface.class.php +++ b/sccpManClasses/dbinterface.class.php @@ -334,27 +334,7 @@ class dbinterface break; case 'add': foreach ($save_value as $button_array) { - $stmt = $this->db->prepare("INSERT INTO sccpbuttonconfig SET ref = :ref, reftype = :reftype, instance = :instance, buttontype = :buttontype, name = :name, options = :options - ON DUPLICATE KEY UPDATE ref = :refU, reftype = :reftypeU, instance = :instanceU, buttontype = :buttontypeU, name = :nameU, options = :optionsU"); - $stmt->bindParam(':ref', $button_array['ref'],\PDO::PARAM_STR); - $stmt->bindParam(':reftype', $button_array['reftype'],\PDO::PARAM_STR); - $stmt->bindParam(':instance', $button_array['instance'],\PDO::PARAM_INT); - $stmt->bindParam(':buttontype', $button_array['buttontype'],\PDO::PARAM_STR); - $stmt->bindParam(':name', $button_array['name'],\PDO::PARAM_STR); - $stmt->bindParam(':options', $button_array['options'],\PDO::PARAM_STR); - $stmt->bindParam(':refU', $button_array['ref'],\PDO::PARAM_STR); - $stmt->bindParam(':reftypeU', $button_array['reftype'],\PDO::PARAM_STR); - $stmt->bindParam(':instanceU', $button_array['instance'],\PDO::PARAM_INT); - $stmt->bindParam(':buttontypeU', $button_array['buttontype'],\PDO::PARAM_STR); - $stmt->bindParam(':nameU', $button_array['name'],\PDO::PARAM_STR); - $stmt->bindParam(':optionsU', $button_array['options'],\PDO::PARAM_STR); - $result = $stmt->execute(); - } - break; - /* - case 'add': - foreach ($save_value as $button_array) { - $stmt = $this->db->prepare('INSERT INTO sccpbuttonconfig (ref, reftype, instance, buttontype, name, options) VALUES (:ref, :reftype, :instance, :buttontype, :name, :options)'); + $stmt = $this->db->prepare("INSERT INTO sccpbuttonconfig SET ref = :ref, reftype = :reftype, instance = :instance, buttontype = :buttontype, name = :name, options = :options"); $stmt->bindParam(':ref', $button_array['ref'],\PDO::PARAM_STR); $stmt->bindParam(':reftype', $button_array['reftype'],\PDO::PARAM_STR); $stmt->bindParam(':instance', $button_array['instance'],\PDO::PARAM_INT); @@ -362,9 +342,9 @@ class dbinterface $stmt->bindParam(':name', $button_array['name'],\PDO::PARAM_STR); $stmt->bindParam(':options', $button_array['options'],\PDO::PARAM_STR); $result = $stmt->execute(); + } break; - */ case 'clear'; // Clear is equivalent of delete + insert. Mode is used in order to activate trigger. $this->write('sccpbuttons', '', $mode = 'delete','', $hwid); diff --git a/sccpManTraits/ajaxHelper.php b/sccpManTraits/ajaxHelper.php index 56fcf05..267b793 100644 --- a/sccpManTraits/ajaxHelper.php +++ b/sccpManTraits/ajaxHelper.php @@ -647,9 +647,9 @@ trait ajaxHelper { $save_codec = array(); $name_dev = ''; $db_field = array_keys($this->dbinterface->getSccpDeviceTableData("get_columns_sccpdevice")); - $hw_id = (empty($get_settings['sccp_deviceid'])) ? 'new' : $get_settings['sccp_deviceid']; + $hw_id = (empty($get_settings['sccp_device_id'])) ? 'new' : $get_settings['sccp_device_id']; $hw_type = (empty($get_settings['sccp_device_typeid'])) ? 'sccpdevice' : $get_settings['sccp_device_typeid']; - $update_hw = ($hw_id == 'new') ? 'add' : 'clear'; // Clear is delete + add + $update_hw = ($hw_id == 'new') ? 'add' : 'clear'; // Clear is delete + add. Only used for buttons $hw_prefix = 'SEP'; if (!empty($get_settings[$hdr_prefix . 'type'])) { $value = $get_settings[$hdr_prefix . 'type'];