Simplify chan-sccp help usage

Convert array to string when loaded, and rename arrays that hold the data for clarity
This commit is contained in:
steve-lad 2021-06-30 08:14:15 +02:00
parent 3ec730b71b
commit 64624fa597
4 changed files with 45 additions and 36 deletions

View file

@ -101,7 +101,7 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
public $xml_data;
public $class_error; //error construct
public $info_warning;
public $sccp_metainfo = array();
public $sccpHelpInfo = array();
// Move all non sccp_manager specific functions to traits
use \FreePBX\modules\Sccp_Manager\sccpManTraits\helperFunctions;
@ -155,11 +155,13 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
$xml_vars = __DIR__ . '/conf/sccpgeneral.xml.v433';
$this->xml_data = simplexml_load_file($xml_vars);
// load metainfo from chan-sccp - help information if not in xml. Only load first time as static data.
if (empty($this->sccp_metainfo)) {
if (empty($this->sccpHelpInfo)) {
$sysConfiguration = $this->aminterface->getSCCPConfigMetaData('general');
foreach ($sysConfiguration['Options'] as $key => $valueArray) {
$this->sccp_metainfo[$valueArray['Name']] = $valueArray['Description'];
foreach ($valueArray['Description'] as $descKey => $descValue) {
$this->sccpHelpInfo[$valueArray['Name']] .= $descValue . '<br>';
}
}
unset($sysConfiguration);
}
@ -174,7 +176,7 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
'form_prefix' => $form_prefix,
'fvalues' => $form_values,
'tftp_lang' => $this->tftpLang,
'metainfo' => $this->sccp_metainfo,
'chanSccpHelp' => $this->sccpHelpInfo,
'sccp_defaults' => $this->sccpvalues
));
} else {
@ -184,7 +186,7 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
'form_prefix' => $form_prefix,
'fvalues' => $form_values,
'tftp_lang' => $this->tftpLang,
'metainfo' => $this->sccp_metainfo,
'chanSccpHelp' => $this->sccpHelpInfo,
'sccp_defaults' => $this->sccpvalues
)
);

View file

@ -107,7 +107,6 @@ and open the template in the editor. Base Version before all crash :-)
<class>sccp-custom</class>
<options placeholder="Host Name"></options>
</input>
<help>External IP Address of the firewall, required in case the PBX is running on a separate host behind it. IP Address that we're going to notify in RTP media stream as the pbx source address. Resolve Hostname (if dynamic) that we're going to resolve when setting up the RTP media stream (only active if externip=0.0.0.0 and host is natted.)</help>
<meta_help>1</meta_help>
<nameseparator> / </nameseparator>

View file

@ -92,7 +92,7 @@ foreach ($items as $child) {
$res_id = $npref.$res_oid;
if (!empty($metainfo[$res_oid])) {
if ($child->meta_help == '1' || $child->help == 'Help!') {
$child->help = $metainfo[$res_oid]['Description'];
$child->help = $metainfo[$res_oid];
}
}
@ -179,7 +179,7 @@ foreach ($items as $child) {
if (!empty($metainfo[$res_n])) {
if ($child->meta_help == '1' || $child->help == 'Help!') {
$child->help = $metainfo[$res_n]['Description'];
$child->help = $metaInfo[$res_n];
}
}
// $res_value
@ -323,7 +323,7 @@ foreach ($items as $child) {
$res_ext = str_replace($npref,'',$res_n);
if (!empty($metainfo[$res_n])) {
if ($child->meta_help == '1' || $child->help == 'Help!') {
$child->help = $metainfo[$res_n]['Description'];
$child->help = $metaInfo[$res_n];
}
}
@ -410,7 +410,7 @@ foreach ($items as $child) {
$res_id = $npref.$res_n;
if (!empty($metainfo[$res_n])) {
if ($child->meta_help == '1' || $child->help == 'Help!') {
$child->help = $metainfo[$res_n]['Description'];
$child->help = $metaInfo[$res_n];
}
}
@ -490,7 +490,7 @@ foreach ($items as $child) {
if (!empty($metainfo[$res_n])) {
if ($child->meta_help == '1' || $child->help == 'Help!') {
$child->help = $metainfo[$res_n]['Description'];
$child->help = $metaInfo[$res_n];
}
}
@ -582,7 +582,7 @@ foreach ($items as $child) {
if (!empty($metainfo[$res_n])) {
if ($child->meta_help == '1' || $child->help == 'Help!') {
$child->help = $metainfo[$res_n]['Description'];
$child->help = $metaInfo[$res_n];
}
}
@ -643,7 +643,7 @@ foreach ($items as $child) {
if (!empty($metainfo[$res_n])) {
if ($child->meta_help == '1' || $child->help == 'Help!') {
$child->help = $metainfo[$res_n]['Description'];
$child->help = $metaInfo[$res_n];
}
}
@ -935,7 +935,7 @@ foreach ($items as $child) {
if (!empty($metainfo[$res_n])) {
if ($child->meta_help == '1' || $child->help == 'Help!') {
$child->help = $metainfo[$res_n]['Description'];
$child->help = $metaInfo[$res_n];
}
}

View file

@ -89,11 +89,11 @@ foreach ($items as $child) {
$res_input = '';
$res_name = '';
$usingSysDefaults = true;
$res_oid = (string)$child->input[0]->name;
$res_id = $npref.$res_oid;
if (!empty($metainfo[$res_oid])) {
$shortId = (string)$child->input[0]->name;
$res_id = $npref.$shortId;
if (!empty($metainfo[$shortId])) {
if ($child->meta_help == '1' || $child->help == 'Help!') {
$child->help = $metainfo[$res_oid]['Description'];
$child->help = $metainfo[$shortId];
}
}
@ -109,7 +109,17 @@ foreach ($items as $child) {
$i = 0;
echo '<!-- Begin '.$child->label.' -->';
?>
<div class="element-container">
<div class="row">
<div class="form-group <?php echo $res_sec_class; ?>">
<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-3">
<?php
// Can have multiple inputs for a field displayed with a separator
foreach ($child->xpath('input') as $value) {
$res_n = (string)$value->name;
$res_name = $npref . $res_n;
@ -133,19 +143,16 @@ foreach ($items as $child) {
if (empty($value->class)) {
$value->class = 'form-control';
}
// TODO: This is a temporary workaround and should be fixed
$item = array('id' => $res_id, 'setting' => $child->label, 'feature' => $res_id, 'iscustom' => 'checked');
if ($i > 0) {
echo $child->nameseparator;
}
echo $value->value;
$i ++;
}
?>
<div class="element-container">
<div class="row">
<div class="form-group <?php echo $res_sec_class; ?>">
<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-3">
<?php echo $value->value; ?>
</div>
<div class="col-md-4">
<span class="radioset">
@ -158,11 +165,12 @@ foreach ($items as $child) {
<div class="row" id="edit_<?php echo $res_id; ?>" style="display: none;">
<div class="form-group <?php echo $res_sec_class; ?>">
<div class="col-md-3">
<i><?php echo "Enter new site value for {$res_oid}"; ?></i>
<i><?php echo "Enter new site value for {$shortId}"; ?></i>
</div>
<div class="col-md-9">
<?php
$i=0;
// Can have multiple inputs for a field displayed with a separator
foreach ($child->xpath('input') as $value) {
$res_n = (string)$value->name;
$res_name = $npref . $res_n;
@ -225,7 +233,7 @@ foreach ($items as $child) {
if (!empty($metainfo[$res_n])) {
if ($child->meta_help == '1' || $child->help == 'Help!') {
$child->help = $metainfo[$res_n]['Description'];
$child->help = $metaInfo[$res_n];
}
}
// $res_value
@ -369,7 +377,7 @@ foreach ($items as $child) {
$res_ext = str_replace($npref,'',$res_n);
if (!empty($metainfo[$res_n])) {
if ($child->meta_help == '1' || $child->help == 'Help!') {
$child->help = $metainfo[$res_n]['Description'];
$child->help = $metaInfo[$res_n];
}
}
@ -456,7 +464,7 @@ foreach ($items as $child) {
$res_id = $npref.$res_n;
if (!empty($metainfo[$res_n])) {
if ($child->meta_help == '1' || $child->help == 'Help!') {
$child->help = $metainfo[$res_n]['Description'];
$child->help = $metaInfo[$res_n];
}
}
@ -536,7 +544,7 @@ foreach ($items as $child) {
if (!empty($metainfo[$res_n])) {
if ($child->meta_help == '1' || $child->help == 'Help!') {
$child->help = $metainfo[$res_n]['Description'];
$child->help = $metaInfo[$res_n];
}
}
@ -628,7 +636,7 @@ foreach ($items as $child) {
if (!empty($metainfo[$res_n])) {
if ($child->meta_help == '1' || $child->help == 'Help!') {
$child->help = $metainfo[$res_n]['Description'];
$child->help = $metaInfo[$res_n];
}
}
@ -689,7 +697,7 @@ foreach ($items as $child) {
if (!empty($metainfo[$res_n])) {
if ($child->meta_help == '1' || $child->help == 'Help!') {
$child->help = $metainfo[$res_n]['Description'];
$child->help = $metaInfo[$res_n];
}
}
@ -981,7 +989,7 @@ foreach ($items as $child) {
if (!empty($metainfo[$res_n])) {
if ($child->meta_help == '1' || $child->help == 'Help!') {
$child->help = $metainfo[$res_n]['Description'];
$child->help = $metaInfo[$res_n];
}
}