From afe3382aed548da1fb19bdf3137ade9a99c822a6 Mon Sep 17 00:00:00 2001 From: steve-lad <72376554+steve-lad@users.noreply.github.com> Date: Thu, 17 Jun 2021 15:54:04 +0200 Subject: [PATCH] Move handleSubmit to AjaxHelper --- Sccp_manager.class.php | 122 --------------------------- sccpManClasses/dbinterface.class.php | 2 +- sccpManTraits/ajaxHelper.php | 122 +++++++++++++++++++++++++++ 3 files changed, 123 insertions(+), 123 deletions(-) diff --git a/Sccp_manager.class.php b/Sccp_manager.class.php index 0df07df..67967b6 100644 --- a/Sccp_manager.class.php +++ b/Sccp_manager.class.php @@ -692,128 +692,6 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO { return $save_settings; } - function handleSubmit($get_settings, $validateonly = false) { - $hdr_prefix = 'sccp_'; - $hdr_arprefix = 'sccp-ar_'; - $save_settings = array(); - $save_codec = array(); - $count_mods = 0; - $dbSaveArray = array(); - $integer_msg = _("%s must be a non-negative integer"); - $errors = array(); - $i = 0; - foreach ($get_settings as $key => $value) { - // Initallly saved all to sccpvalues. Now will save to db defaults if appropriate - // TODO: Need to verify the tables defined in showGroup - some options maybe - // device options, but if set by freePbx extensions, be in sccpline. - $key = (str_replace('sccpdevice_', '', $key, $count_mods)); - if (($count_mods) && (!empty($value))) { - // There will be some exceptions to be handled where there should be no underscore - // Handle at db write - // Have default to be saved to db sccpdevice - $dev_def = $this->getDeviceDefaults(); - if (!array_key_exists($key, $dev_def)) { - // This key needs to be prefixed with underscore - $key = '_'.$key; - } - if ((array_key_exists($key, $dev_def)) && ($dev_def[$key]['data'] == $value)) { - // Value unchanged so ignore and get next key. - continue; - } - $dbSaveArray[] = array('table' => 'sccpdevice', 'field' => $key, 'Default' => $value); - unset($get_settings[$key]); - continue; - } - - $pos = strpos($key, $hdr_prefix); - if ($pos !== false) { - $key1 = substr_replace($key, '', 0, strlen($hdr_prefix)); - if (!empty($this->sccpvalues[$key1])) { - if (!($this->sccpvalues[$key1]['data'] == $value)) { - $save_settings[] = array('keyword' => $this->sccpvalues[$key1]['keyword'], 'data' => $value, - 'seq' => $this->sccpvalues[$key1]['seq'], 'type' => $this->sccpvalues[$key1]['type']); - } - } - } - $pos = strpos($key, $hdr_arprefix); - if ($pos !== false) { - $key1 = substr_replace($key, '', 0, strlen($hdr_arprefix)); - $arr_data = ''; - if (!empty($this->sccpvalues[$key1])) { - foreach ($value as $vkey => $vval) { - $tmp_data = ''; - foreach ($vval as $vkey => $vval) { - switch ($vkey) { - case 'inherit': - case 'internal': - if ($vval == 'on') { - $tmp_data .= 'internal;'; - } - break; - default: - $tmp_data .= $vval . '/'; - break; - } - } - if (strlen($tmp_data) > 2) { - while (substr($tmp_data, -1) == '/') { - $tmp_data = substr($tmp_data, 0, -1); - } - $arr_data .= $tmp_data . ';'; - } - } - while (substr($arr_data, -1) == ';') { - $arr_data = substr($arr_data, 0, -1); - } - if (!($this->sccpvalues[$key1]['data'] == $arr_data)) { - $save_settings[] = array('keyword' => $this->sccpvalues[$key1]['keyword'], 'data' => $arr_data, - 'seq' => $this->sccpvalues[$key1]['seq'], 'type' => $this->sccpvalues[$key1]['type']); - } - } - } - switch ($key) { - case 'voicecodecs': - case 'vcodec': - foreach ($value as $keycodeс => $valcodeс) { - $save_codec[$i] = $keycodeс; - $i++; - }; - $tmpv = implode(";", $save_codec); - if ($tmpv !== $this->sccpvalues['allow']['data']) { - $save_settings[] = array('keyword' => 'allow', 'data' => $tmpv, - 'seq' => $this->sccpvalues['allow']['seq'], - 'type' => $this->sccpvalues['allow']['type']); - } - break; - - case 'sccp_ntp_timezone': - $tz_id = $value; - $TZdata = $this->extconfigs->getextConfig('sccp_timezone', $tz_id); - if (!empty($TZdata)) { - $value = $TZdata['offset']/60; - if (!($this->sccpvalues['tzoffset']['data'] == $value)) { - $save_settings[] = array('keyword' => 'tzoffset', 'data' => $value, - 'seq' => '98', - 'type' => '2'); - } - } - break; - } - } - if (!empty($save_settings)) { - $this->saveSccpSettings($save_settings); - $this->sccpvalues = $this->dbinterface->get_db_SccpSetting(); - } - - foreach ($dbSaveArray as $rowToSave) { - $this->dbinterface->updateTableDefaults($rowToSave['table'], $rowToSave['field'], $rowToSave['Default']); - } - - $this->createDefaultSccpConfig(); // Rewrite Config. - $save_settings[] = array('status' => true); - return $save_settings; - } - function handleRoamingUsers($get_settings, $validateonly = false) { $hdr_prefix = 'sccp_ru_'; $hdr_arprefix = 'sccp_ru-ar_'; diff --git a/sccpManClasses/dbinterface.class.php b/sccpManClasses/dbinterface.class.php index 909d3b4..a9aa47d 100644 --- a/sccpManClasses/dbinterface.class.php +++ b/sccpManClasses/dbinterface.class.php @@ -21,7 +21,7 @@ class dbinterface public function info() { - $Ver = '13.0.2'; // This should be updated + $Ver = '13.0.10'; // This should be updated return array('Version' => $Ver, 'about' => 'Data access interface ver: ' . $Ver); } diff --git a/sccpManTraits/ajaxHelper.php b/sccpManTraits/ajaxHelper.php index 2162826..c54df57 100644 --- a/sccpManTraits/ajaxHelper.php +++ b/sccpManTraits/ajaxHelper.php @@ -386,6 +386,128 @@ trait ajaxHelper { return $result; break; } + + } + function handleSubmit($get_settings, $validateonly = false) { + $hdr_prefix = 'sccp_'; + $hdr_arprefix = 'sccp-ar_'; + $save_settings = array(); + $save_codec = array(); + $count_mods = 0; + $dbSaveArray = array(); + $integer_msg = _("%s must be a non-negative integer"); + $errors = array(); + $i = 0; + foreach ($get_settings as $key => $value) { + // Initallly saved all to sccpvalues. Now will save to db defaults if appropriate + // TODO: Need to verify the tables defined in showGroup - some options maybe + // device options, but if set by freePbx extensions, be in sccpline. + $key = (str_replace('sccpdevice_', '', $key, $count_mods)); + if (($count_mods) && (!empty($value))) { + // There will be some exceptions to be handled where there should be no underscore + // Handle at db write + // Have default to be saved to db sccpdevice + $dev_def = $this->getDeviceDefaults(); + if (!array_key_exists($key, $dev_def)) { + // This key needs to be prefixed with underscore + $key = '_'.$key; + } + if ((array_key_exists($key, $dev_def)) && ($dev_def[$key]['data'] == $value)) { + // Value unchanged so ignore and get next key. + continue; + } + $dbSaveArray[] = array('table' => 'sccpdevice', 'field' => $key, 'Default' => $value); + unset($get_settings[$key]); + continue; + } + + $pos = strpos($key, $hdr_prefix); + if ($pos !== false) { + $key1 = substr_replace($key, '', 0, strlen($hdr_prefix)); + if (!empty($this->sccpvalues[$key1])) { + if (!($this->sccpvalues[$key1]['data'] == $value)) { + $save_settings[] = array('keyword' => $this->sccpvalues[$key1]['keyword'], 'data' => $value, + 'seq' => $this->sccpvalues[$key1]['seq'], 'type' => $this->sccpvalues[$key1]['type']); + } + } + } + $pos = strpos($key, $hdr_arprefix); + if ($pos !== false) { + $key1 = substr_replace($key, '', 0, strlen($hdr_arprefix)); + $arr_data = ''; + if (!empty($this->sccpvalues[$key1])) { + foreach ($value as $vkey => $vval) { + $tmp_data = ''; + foreach ($vval as $vkey => $vval) { + switch ($vkey) { + case 'inherit': + case 'internal': + if ($vval == 'on') { + $tmp_data .= 'internal;'; + } + break; + default: + $tmp_data .= $vval . '/'; + break; + } + } + if (strlen($tmp_data) > 2) { + while (substr($tmp_data, -1) == '/') { + $tmp_data = substr($tmp_data, 0, -1); + } + $arr_data .= $tmp_data . ';'; + } + } + while (substr($arr_data, -1) == ';') { + $arr_data = substr($arr_data, 0, -1); + } + if (!($this->sccpvalues[$key1]['data'] == $arr_data)) { + $save_settings[] = array('keyword' => $this->sccpvalues[$key1]['keyword'], 'data' => $arr_data, + 'seq' => $this->sccpvalues[$key1]['seq'], 'type' => $this->sccpvalues[$key1]['type']); + } + } + } + switch ($key) { + case 'voicecodecs': + case 'vcodec': + foreach ($value as $keycodeс => $valcodeс) { + $save_codec[$i] = $keycodeс; + $i++; + }; + $tmpv = implode(";", $save_codec); + if ($tmpv !== $this->sccpvalues['allow']['data']) { + $save_settings[] = array('keyword' => 'allow', 'data' => $tmpv, + 'seq' => $this->sccpvalues['allow']['seq'], + 'type' => $this->sccpvalues['allow']['type']); + } + break; + + case 'sccp_ntp_timezone': + $tz_id = $value; + $TZdata = $this->extconfigs->getextConfig('sccp_timezone', $tz_id); + if (!empty($TZdata)) { + $value = $TZdata['offset']/60; + if (!($this->sccpvalues['tzoffset']['data'] == $value)) { + $save_settings[] = array('keyword' => 'tzoffset', 'data' => $value, + 'seq' => '98', + 'type' => '2'); + } + } + break; + } + } + if (!empty($save_settings)) { + $this->saveSccpSettings($save_settings); + $this->sccpvalues = $this->dbinterface->get_db_SccpSetting(); + } + + foreach ($dbSaveArray as $rowToSave) { + $this->dbinterface->updateTableDefaults($rowToSave['table'], $rowToSave['field'], $rowToSave['Default']); + } + + $this->createDefaultSccpConfig(); // Rewrite Config. + $save_settings[] = array('status' => true); + return $save_settings; } }