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.
This commit is contained in:
stevenA 2022-01-19 12:07:41 +01:00
parent e08ad858f5
commit 381fe184bd
3 changed files with 23 additions and 54 deletions

View file

@ -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';

View file

@ -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);

View file

@ -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'];