Optimise handlerSubmit and activate TZ

Simplify process
Reenable TZ offset test on save
This commit is contained in:
steve-lad 2021-06-18 13:13:38 +02:00
parent de3c58178b
commit 510b4259ac
2 changed files with 33 additions and 27 deletions

View file

@ -520,13 +520,13 @@ and open the template in the editor. Base Version before all crash :-)
</select> </select>
<help>Date Format: The date format for the on-screen display. Can be one of the following: (D-M-YA, M.D.Y, Y/M/D) where 'D' is Day, 'M' is Month, 'Y' is Year, 'A' is 24-hour, 'a' is 12-hour, and the separators can be '.','-','/'</help> <help>Date Format: The date format for the on-screen display. Can be one of the following: (D-M-YA, M.D.Y, Y/M/D) where 'D' is Day, 'M' is Month, 'Y' is Year, 'A' is 24-hour, 'a' is 12-hour, and the separators can be '.','-','/'</help>
</item> </item>
<item type="SLTZN" id="2" seq="95"> <item type="IE" id="4" seq="10">
<label>Time Zone</label> <label>Time Zone</label>
<name>ntp_timezone</name> <input>
<class>sccp-custom</class> <name>ntp_timezone</name>
<select> <default></default>
<default>UTC</default> <options readonly="readonly"></options>
</select> </input>
<help>System Time zone - this is set by FreePBX and can be changed in Settings : Advanced Settings</help> <help>System Time zone - this is set by FreePBX and can be changed in Settings : Advanced Settings</help>
</item> </item>
</page_group> </page_group>

View file

@ -381,7 +381,6 @@ trait ajaxHelper {
} }
function handleSubmit($request, $validateonly = false) { function handleSubmit($request, $validateonly = false) {
dbug('Request', $request);
$hdr_prefix = 'sccp_'; $hdr_prefix = 'sccp_';
$hdr_arprefix = 'sccp-ar_'; $hdr_arprefix = 'sccp-ar_';
$save_settings = array(); $save_settings = array();
@ -434,22 +433,23 @@ trait ajaxHelper {
unset($request[$key]); unset($request[$key]);
continue; continue;
} }
dbug('still in loop with key', $key);
$pos = strpos($key, $hdr_prefix); $key = (str_replace($hdr_prefix, '', $key, $count_mods));
if ($pos !== false) { if ($count_mods) {
$key1 = substr_replace($key, '', 0, strlen($hdr_prefix)); if (!empty($this->sccpvalues[$key]) && (!($this->sccpvalues[$key]['data'] == $value))) {
if (!empty($this->sccpvalues[$key1])) { $save_settings[] = array(
if (!($this->sccpvalues[$key1]['data'] == $value)) { 'keyword' => $this->sccpvalues[$key]['keyword'],
$save_settings[] = array('keyword' => $this->sccpvalues[$key1]['keyword'], 'data' => $value, 'data' => $value,
'seq' => $this->sccpvalues[$key1]['seq'], 'type' => $this->sccpvalues[$key1]['type']); 'seq' => $this->sccpvalues[$key]['seq'],
} 'type' => $this->sccpvalues[$key1]['type']
);
} }
} }
$pos = strpos($key, $hdr_arprefix);
if ($pos !== false) { $key = (str_replace($hdr_arprefix, '', $key, $count_mods));
$key1 = substr_replace($key, '', 0, strlen($hdr_arprefix)); if ($count_mods) {
$arr_data = ''; $arr_data = '';
if (!empty($this->sccpvalues[$key1])) { if (!empty($this->sccpvalues[$key])) {
foreach ($value as $vkey => $vval) { foreach ($value as $vkey => $vval) {
$tmp_data = ''; $tmp_data = '';
foreach ($vval as $vkey => $vval) { foreach ($vval as $vkey => $vval) {
@ -475,9 +475,13 @@ trait ajaxHelper {
while (substr($arr_data, -1) == ';') { while (substr($arr_data, -1) == ';') {
$arr_data = substr($arr_data, 0, -1); $arr_data = substr($arr_data, 0, -1);
} }
if (!($this->sccpvalues[$key1]['data'] == $arr_data)) { if (!($this->sccpvalues[$key]['data'] == $arr_data)) {
$save_settings[] = array('keyword' => $this->sccpvalues[$key1]['keyword'], 'data' => $arr_data, $save_settings[] = array(
'seq' => $this->sccpvalues[$key1]['seq'], 'type' => $this->sccpvalues[$key1]['type']); 'keyword' => $this->sccpvalues[$key]['keyword'],
'data' => $arr_data,
'seq' => $this->sccpvalues[$key]['seq'],
'type' => $this->sccpvalues[$key]['type']
);
} }
} }
} }
@ -496,15 +500,18 @@ trait ajaxHelper {
} }
break; break;
case 'sccp_ntp_timezone': case 'ntp_timezone':
$tz_id = $value; $tz_id = $value;
$TZdata = $this->extconfigs->getextConfig('sccp_timezone', $tz_id); $TZdata = $this->extconfigs->getextConfig('sccp_timezone', $tz_id);
if (!empty($TZdata)) { if (!empty($TZdata)) {
$value = $TZdata['offset']/60; $value = $TZdata['offset']/60;
if (!($this->sccpvalues['tzoffset']['data'] == $value)) { if (!($this->sccpvalues['tzoffset']['data'] == $value)) {
$save_settings[] = array('keyword' => 'tzoffset', 'data' => $value, $save_settings[] = array(
'keyword' => 'tzoffset',
'data' => $value,
'seq' => '98', 'seq' => '98',
'type' => '2'); 'type' => '2'
);
} }
} }
break; break;
@ -512,7 +519,6 @@ trait ajaxHelper {
} }
if (!empty($save_settings)) { if (!empty($save_settings)) {
dbug('save settings', $save_settings);
$this->saveSccpSettings($save_settings); $this->saveSccpSettings($save_settings);
$this->sccpvalues = $this->dbinterface->get_db_SccpSetting(); $this->sccpvalues = $this->dbinterface->get_db_SccpSetting();
} }