Move handleSubmit to AjaxHelper

This commit is contained in:
steve-lad 2021-06-17 15:54:04 +02:00
parent 5df918a04b
commit afe3382aed
3 changed files with 123 additions and 123 deletions

View file

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

View file

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

View file

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