Clean up and correct missing save settings

Remove unnecessary method from formcreate
Correct indentation in formcreate
Remove debug code in Sccp.class
correct logic for updating TFTP mode
This commit is contained in:
steve-lad 2021-07-10 17:51:55 +02:00
parent 30cbe1ba95
commit 248abe6cb7
5 changed files with 87 additions and 154 deletions

View file

@ -216,7 +216,6 @@ class Sccp extends \FreePBX\modules\Core\Driver {
}
public function getDeviceDisplay($display, $deviceInfo, $currentComponent, $primarySection) {
dbug('',$primarySection);
$activeCodecs = array();
// load xml data to get help from same source as rest of module
$xml_vars = $_SERVER['DOCUMENT_ROOT'] . '/admin/modules/sccp_manager/conf/sccpgeneral.xml.v433';
@ -321,7 +320,6 @@ class Sccp extends \FreePBX\modules\Core\Driver {
);
break;
case 'IS':
dbug('', $child);
$select = array();
foreach ($child->xpath('button') as $value) {
$select[] = array('value' => strtolower((string)$value[@value]), 'text' => (string)$value);

View file

@ -249,27 +249,27 @@ class extconfigs
'languages' => 'languages',
'templates' => 'templates',
'dialplan' => 'dialplan',
'softkey' => 'softkey'
'softkey' => 'softkey',
'ringtones' => 'ringtones',
'wallpapers' => 'wallpapers'
);
$adv_tree['pro'] = array('templates' => 'tftproot',
'settings' => 'tftproot',
'locales' => 'tftproot',
'firmware' => 'tftproot',
'languages' => 'locales',
'dialplan' => 'tftproot',
'softkey' => 'tftproot'
);
$adv_tree['def'] = array('templates' => 'tftproot',
'settings' => '',
'locales' => '',
'firmware' => '',
'languages' => 'tftproot',
'dialplan' => '',
'softkey' => ''
);
$adv_tree = array('pro' => array('templates' => 'tftproot',
'settings' => 'tftproot',
'locales' => 'tftproot',
'firmware' => 'tftproot',
'languages' => 'locales',
'dialplan' => 'tftproot',
'softkey' => 'tftproot'
),
'def' => array('templates' => 'tftproot',
'settings' => '',
'locales' => '',
'firmware' => '',
'languages' => 'tftproot',
'dialplan' => '',
'softkey' => ''
)
);
$base_tree = array('tftp_templates_path' => 'templates',
'tftp_store_path' => 'settings',
'tftp_lang_path' => 'languages',
@ -277,18 +277,17 @@ class extconfigs
'tftp_dialplan_path' => 'dialplan',
'tftp_softkey_path' => 'softkey'
);
$base_config = array();
if (!empty($settingsFromDb['tftp_rewrite_path']['data'])) {
// Have a setting in sccpsettings. It should start with $tftpRootPath
// If not we will replace it with $tftpRootPath. Avoids issues with legacy values
if (!strpos($settingsFromDb['tftp_rewrite_path']["data"],$settingsFromDb['tftp_path']['data'])) {
// Have a setting in sccpsettings. It should start with $tftp_path
// If not we will replace it with $tftp_path. Avoids issues with legacy values
if (!strpos($settingsFromDb['tftp_rewrite_path']["data"],$settingsFromDb['tftp_path']['data'])) {
$adv_ini = "{$tftpRootPath}/index.cnf";
$settingsToDb['tftp_rewrite_path'] = $settingsFromDb['tftp_rewrite_path'];
$settingsToDb['tftp_rewrite_path']['data'] = $tftpRootPath;
}
$adv_ini = "{$settingsFromDb['tftp_path']['data']}/index.cnf";
$settingsToDb['tftp_rewrite_path'] = $settingsFromDb['tftp_rewrite_path'];
$settingsToDb['tftp_rewrite_path']['data'] = $settingsFromDb['tftp_path']['data'];
}
$adv_ini = "{$settingsFromDb['tftp_rewrite_path']["data"]}/index.cnf";
}
@ -301,14 +300,14 @@ class extconfigs
$adv_ini_array = parse_ini_file($adv_ini);
$adv_config = array_merge($adv_config, $adv_ini_array);
}
$settingsToDb['tftp_rewrite'] =array( 'keyword' => 'tftp_rewrite', 'seq' => 20, 'type' => 2, 'data' => 'pro', 'systemdefault' => '');
break;
case 'on':
case 'internal':
case 'off':
break;
default:
// not defined so set here
$settingsToDb["tftp_rewrite"] =array( 'keyword' => 'tftp_rewrite', 'seq' => 20, 'type' => 2, 'data' => 'off');
// not defined so set here to off
$settingsToDb['tftp_rewrite'] =array( 'keyword' => 'tftp_rewrite', 'seq' => 20, 'type' => 2, 'data' => 'off', 'systemdefault' => '');
}
foreach ($adv_tree[$adv_tree_mode] as $key => $value) {
@ -322,10 +321,11 @@ class extconfigs
}
}
}
foreach ($base_tree as $key => $value) {
$base_config[$key] = $adv_config[$value];
// Save to sccpsettings
$settingsToDb[$key] =array( 'keyword' => $key, 'seq' => 20, 'type' => 0, 'data' => $adv_config[$value]);
$settingsToDb[$key] =array( 'keyword' => $key, 'seq' => 20, 'type' => 0, 'data' => $adv_config[$value], 'systemdefault' => '');
if (!is_dir($base_config[$key])) {
if (!mkdir($base_config[$key], 0755, true)) {
die_freepbx(_('Error creating dir : ' . $base_config[$key]));
@ -342,7 +342,18 @@ class extconfigs
}
// Remove keys that are not required before returning $base_config.
unset($base_config['asterisk'], $base_config['sccp_conf'], $base_config['tftp_path']);
return $base_config;
return $settingsToDb;
}
private function initializeTFtpLanguagePath() {
$dir = $this->sccppath["tftp_lang_path"];
foreach ($this->extconfigs->getExtConfig('sccp_lang') as $lang_key => $lang_value) {
$filename = $dir . DIRECTORY_SEPARATOR . $lang_value['locale'];
if (!file_exists($filename)) {
if (!mkdir($filename, 0777, true)) {
die('Error creating tftp language directory');
}
}
}
}
public function validate_RealTime( $connector )

View file

@ -476,93 +476,7 @@ class formcreate
<?php
}
function addElementSL($child, $fvalues, $sccp_defaults, $npref) {
// TODO: Unused function. Integrated into SL2. To be removed after full testing.
/*
* Input element Select SLD - Date format
* SLM - Music on hold
* SLK - System KeySet
* SLP - Dial Paterns
*/
$res_n = (string)$child ->name;
$res_id = $npref.$res_n;
// $select_opt is a simple array for these types.
$select_opt = array();
if (!empty($metainfo[$res_n])) {
if ($child->meta_help == '1' || $child->help == 'Help!') {
$child->help = $metaInfo[$res_n];
}
}
if (empty($child->class)) {
$child->class = 'form-control';
}
switch ($child['type']) {
case 'SLD':
$day_format = array("D.M.Y", "D.M.YA", "Y.M.D", "YA.M.D", "M-D-Y", "M-D-YA", "D-M-Y", "D-M-YA", "Y-M-D", "YA-M-D", "M/D/Y", "M/D/YA",
"D/M/Y", "D/M/YA", "Y/M/D", "YA/M/D", "M/D/Y", "M/D/YA");
$select_opt= $day_format;
break;
case 'SLM':
if (function_exists('music_list')) {
$moh_list = music_list();
}
if (!is_array($moh_list)) {
$moh_list = array('default');
}
$select_opt= $moh_list;
break;
case 'SLK':
$softKeyList = \FreePBX::Sccp_manager()->aminterface->sccp_list_keysets();
$select_opt= $softKeyList;
break;
case 'SLP':
$dialplan_list = array();
foreach (\FreePBX::Sccp_manager()->getDialPlanList() as $tmpkey) {
$tmp_id = $tmpkey['id'];
$dialplan_list[$tmp_id] = $tmp_id;
}
$select_opt= $dialplan_list;
break;
}
if (!empty($fvalues[$res_n])) {
if (!empty($fvalues[$res_n]['data'])) {
$child->value = $fvalues[$res_n]['data'];
}
}
?>
<div class="element-container">
<div class="row"> <div class="form-group">
<div class="col-md-3">
<label class="control-label" for="<?php echo $res_id; ?>"><?php echo _($child->label);?></label>
<i class="fa fa-question-circle fpbx-help-icon" data-for="<?php echo $res_id; ?>"></i>
</div>
<div class="col-md-9"><div class = "lnet form-group form-inline" data-nextid=1>
<?php
echo '<select name="'.$res_id.'" class="'. $child->class . '" id="' . $res_id . '">';
foreach ($select_opt as $key) {
echo '<option value="' . $key . '"';
if ($key == $child->value) {
echo ' selected="selected"';
}
echo '>' . $key . '</option>';
}
?>
</select>
</div>
</div>
</div>
</div>
<div class="row"><div class="col-md-12">
<span id="<?php echo $res_id;?>-help" class="help-block fpbx-help-block"><?php echo _($child->help);?></span>
</div>
</div>
</div>
<?php
}
function addElementSL2($child, $fvalues, $sccp_defaults,$npref, $tftpLang) {
function addElementSL($child, $fvalues, $sccp_defaults,$npref, $tftpLang) {
// Input element Select SLS - System Language
$res_n = (string)$child ->name;
$res_id = $npref.$res_n;
@ -652,42 +566,46 @@ class formcreate
}
?>
<div class="element-container">
<div class="row"> <div class="form-group">
<div class="col-md-3">
<div class="row">
<div class="form-group">
<div class="col-md-3">
<label class="control-label" for="<?php echo $res_id; ?>"><?php echo _($child->label);?></label>
<i class="fa fa-question-circle fpbx-help-icon" data-for="<?php echo $res_id; ?>"></i>
</div>
<div class="col-md-9"><div class = "lnet form-group form-inline" data-nextid=1>
<?php
<div class="col-md-9">
<div class = "lnet form-group form-inline" data-nextid=1>
<?php
echo '<select name="'.$res_id.'" class="'. $child->class . '" id="' . $res_id . '">';
dbug('', $res_id);
foreach ($select_opt as $key => $val) {
if (is_array($val)) {
$opt_key = (isset($val['id'])) ? $val['id'] : $key;
$opt_val = (isset($val['val'])) ? $val['val'] : $val;
} else if (\FreePBX::Sccp_manager()->is_assoc($select_opt)){
// have associative array
$opt_key = $key;
$opt_val = $val;
} else {
// Have simple array
$opt_key = $val;
$opt_val = $val;
}
echo '<option value="' . $opt_key . '"';
if ($opt_key == $child->value) {
echo ' selected="selected"';
}
echo '>' . $opt_val. '</option>';
}
?> </select>
foreach ($select_opt as $key => $val) {
if (is_array($val)) {
$opt_key = (isset($val['id'])) ? $val['id'] : $key;
$opt_val = (isset($val['val'])) ? $val['val'] : $val;
} else if (\FreePBX::Sccp_manager()->is_assoc($select_opt)){
// have associative array
$opt_key = $key;
$opt_val = $val;
} else {
// Have simple array
$opt_key = $val;
$opt_val = $val;
}
echo '<option value="' . $opt_key . '"';
if ($opt_key == $child->value) {
echo ' selected="selected"';
}
echo "> {$opt_val} </option>";
}
?>
</select>
</div>
</div>
</div>
</div>
</div>
<div class="row"><div class="col-md-12">
</div>
<div class="row">
<div class="col-md-12">
<span id="<?php echo $res_id;?>-help" class="help-block fpbx-help-block"><?php echo _($child->help);?></span>
</div></div>
</div>
</div>
</div>
<?php
}

View file

@ -405,6 +405,7 @@ trait ajaxHelper {
if ($action == 'yes') {
$this->initializeTFtpLanguagePath();
}
foreach ($request as $key => $value) {
// Originally saved all to sccpvalues. Now will save to db defaults if appropriate
// TODO: Need to verify the tables defined in showGroup - some options maybe
@ -448,7 +449,7 @@ trait ajaxHelper {
$key = (str_replace($hdr_prefix, '', $key, $count_mods));
if ($count_mods) {
if (!empty($this->sccpvalues[$key]) && (!($this->sccpvalues[$key]['data'] == $value))) {
$save_settings[] = array(
$save_settings[$this->sccpvalues[$key]['keyword']] = array(
'keyword' => $this->sccpvalues[$key]['keyword'],
'data' => $value,
'seq' => $this->sccpvalues[$key]['seq'],
@ -457,7 +458,6 @@ trait ajaxHelper {
);
}
}
$key = (str_replace($hdr_arprefix, '', $key, $count_mods));
if ($count_mods) {
$arr_data = '';
@ -537,11 +537,14 @@ trait ajaxHelper {
}
}
$extSettings = $this->extconfigs->updateTftpStructure(array_merge($this->sccpvalues, $save_settings));
$save_settings = array_merge($save_settings, $extSettings);
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']);
}
@ -549,6 +552,9 @@ trait ajaxHelper {
$this->createDefaultSccpConfig(); // Rewrite Config.
$save_settings[] = array('status' => true);
$this->createDefaultSccpXml();
return $save_settings;
}

View file

@ -74,7 +74,7 @@ foreach ($items as $child) {
case 'SLA':
case 'SLZ':
case 'SL':
\FreePbx::sccp_manager()->formcreate->addElementSL2($child, $fvalues, $sccp_defaults,$npref, $tftpLang);
\FreePbx::sccp_manager()->formcreate->addElementSL($child, $fvalues, $sccp_defaults,$npref, $tftpLang);
break;
case 'SDM':
case 'SDMS':