Update SoftKey Set Management

Prior versions relied on preestablished default  softkeyset which was no longer correct, and data from sccp.conf.

Data returned from chan-sccp was mishandled, and only returned a keyset name.

Now process data from AMI and show actual data in use by chan-sccp
This commit is contained in:
stevenA 2022-01-21 16:12:01 +01:00
parent a58d397866
commit fb7a7da60a
6 changed files with 59 additions and 87 deletions

View file

@ -252,33 +252,47 @@ class SCCPGeneric_Response extends Response
protected function ConvertTableData( $_tablename, array $_fkey, array $_fields) protected function ConvertTableData( $_tablename, array $_fkey, array $_fields)
{ {
//dbug(debug_backtrace(2)); /* except for softkeysets, $_fkey is a single element array so the Returned
array is a normal array. For softkey sets, need to return an associative
array with a second level.
*/
$result = array(); $result = array();
$_rawtable = $this->Table2Array($_tablename); $_rawtable = $this->Table2Array($_tablename);
// Check that there is actually data to be converted // Check that there is actually data to be converted
if (empty($_rawtable)) { return $result;} if (empty($_rawtable)) {
foreach ($_rawtable as $_row) { return $result;
$all_key_ok = true; }
// No need to test if $_fkey is array as array required // Now check that fkey fields exist in the $_rawtable. If exists in
// the first element, Assume that it exists in all elements.
foreach ($_fkey as $_fid) { foreach ($_fkey as $_fid) {
if (empty($_row[$_fid])) { if (!isset($_rawtable[0][$_fid])) {
$all_key_ok = false; return $result;
} else {
$set_name[$_fid] = $_row[$_fid];
} }
} }
$Data = &$result; // could also use tablename here
$complexArray = true;
if ($all_key_ok) { if (count($_fkey) === 1) {
foreach ($set_name as $value_id) { $complexArray = false;
$Data = &$Data[$value_id];
} }
// Label converter in case labels and keys are different foreach ($_rawtable as $_rowArr) {
// $_row is a table element
$outputArr = array();
foreach ($_fields as $value_key => $value_id) { foreach ($_fields as $value_key => $value_id) {
$Data[$value_id] = $_row[$value_key]; $outputArr[$value_id] = $_rowArr[$value_key];
} }
if ($complexArray) {
// We are returning softkey sets. Only looking for formatted value
$result[$_rowArr[$_fkey[0]]]['softkeys'] = $_rowArr[$_fkey[0]];
if (isset($result[$_rowArr[$_fkey[0]]][$_rowArr[$_fkey[1]]])) {
$result[$_rowArr[$_fkey[0]]][$_rowArr[$_fkey[1]]] .= "{$outputArr['label']}<br>";
} else {
$result[$_rowArr[$_fkey[0]]][$_rowArr[$_fkey[1]]] = "{$outputArr['label']}<br>";
}
} else {
$result[$_rowArr[$_fkey[0]]] = $outputArr;
} }
} }
//dbug($result);
return $result; return $result;
} }

View file

@ -361,10 +361,7 @@ class aminterface
$result = array(); $result = array();
if ($this->_connect_state) { if ($this->_connect_state) {
$_action = new \FreePBX\modules\Sccp_manager\aminterface\SCCPShowSoftkeySetsAction(); $_action = new \FreePBX\modules\Sccp_manager\aminterface\SCCPShowSoftkeySetsAction();
$_res = $this->send($_action)->getResult(); $result = $this->send($_action)->getResult();
foreach ($_res as $key => $value) {
$result[$key] = $key;
}
} }
return $result; return $result;
} }

View file

@ -571,9 +571,12 @@ class formcreate
<?php <?php
echo '<select name="'.$res_id.'" class="'. $child->class . '" id="' . $res_id . '">'; echo '<select name="'.$res_id.'" class="'. $child->class . '" id="' . $res_id . '">';
foreach ($select_opt as $key => $val) { foreach ($select_opt as $key => $val) {
// TODO: Clean this up - its a bunch of fixes
if (is_array($val)) { if (is_array($val)) {
$opt_key = (isset($val['id'])) ? $val['id'] : $key; $opt_key = (isset($val['id'])) ? $val['id'] : $key;
$opt_val = (isset($val['val'])) ? $val['val'] : $val; $opt_val = (isset($val['val'])) ? $val['val'] : $val;
$opt_key = (isset($val['softkeys'])) ? $val['softkeys'] : $key;
$opt_val = (isset($val['softkeys'])) ? $val['softkeys'] : $val;
} else if (\FreePBX::Sccp_manager()->is_assoc($select_opt)){ } else if (\FreePBX::Sccp_manager()->is_assoc($select_opt)){
// have associative array // have associative array
$opt_key = $key; $opt_key = $key;

View file

@ -234,8 +234,8 @@ trait ajaxHelper {
//$id_name = $request['softkey']; //$id_name = $request['softkey'];
unset($this->sccp_conf_init[$request['softkey']]); unset($this->sccp_conf_init[$request['softkey']]);
$this->createDefaultSccpConfig($this->sccpvalues, $this->sccppath["asterisk"]); $this->createDefaultSccpConfig($this->sccpvalues, $this->sccppath["asterisk"]);
$msg = print_r($this->aminterface->core_sccp_reload(), 1); $msg = $this->aminterface->core_sccp_reload();
return array('status' => true, 'table_reload' => true); return array('status' => true, 'reload' => true, 'message' => $msg['Response'] .' - Softkey set deleted');
} }
break; break;
case 'updateSoftKey': case 'updateSoftKey':
@ -251,8 +251,8 @@ trait ajaxHelper {
// !TODO!: -TODO-: Check SIP Support Enabled // !TODO!: -TODO-: Check SIP Support Enabled
$this->createSccpXmlSoftkey(); $this->createSccpXmlSoftkey();
$msg = print_r($this->aminterface->core_sccp_reload(), 1); $msg = $this->aminterface->core_sccp_reload();
return array('status' => true, 'table_reload' => true, 'msg' => $msg); return array('status' => true, 'reload' => true, 'message' => $msg['Response'] .' - Softkey sets updated');
} }
break; break;
case 'backupsettings': case 'backupsettings':

View file

@ -23,7 +23,7 @@ trait bmoFunctions {
break; break;
case 'sccp_adv': case 'sccp_adv':
$this->dialTemplateData = json_encode($this->getDialTemplate()); $this->dialTemplateData = json_encode($this->getDialTemplate());
$this->softKeyData = json_encode($this->getSoftKey()); $this->softKeyData = json_encode(array_values($this->aminterface->sccp_list_keysets()));
$this->deviceModelData = json_encode($this->ajaxHandler($_REQUEST = array('command'=>'getDeviceModel', 'type'=>'enabled'))); $this->deviceModelData = json_encode($this->ajaxHandler($_REQUEST = array('command'=>'getDeviceModel', 'type'=>'enabled')));
break; break;
default: default:
@ -125,47 +125,6 @@ trait bmoFunctions {
return $result; return $result;
} }
function getSoftKey() {
$result = array();
$i = 0;
$keyl = 'default';
foreach ($this->aminterface->sccp_list_keysets() as $keyl => $vall) {
$result[$i]['softkeys'] = $keyl;
if ($keyl == 'default') {
foreach ($this->extconfigs->getExtConfig('keyset') as $key => $value) {
$result[$i][$key] = str_replace(',', '<br>', $value);
}
} else {
foreach ($this->getMyConfig('softkeyset', $keyl) as $key => $value) {
$result[$i][$key] = str_replace(',', '<br>', $value);
}
}
$i++;
}
return $result;
}
public function getMyConfig(string $var, $id = "noid") {
$final = array();
$i = 0;
if ($id == "noid") {
foreach ($this->sccp_conf_init as $key => $value) {
if ($this->sccp_conf_init[$key]['type'] == 'softkeyset') {
$final[$i] = $value;
$i++;
}
}
} else {
if (!empty($this->sccp_conf_init[$id])) {
if ($this->sccp_conf_init[$id]['type'] == 'softkeyset') {
$final = $this->sccp_conf_init[$id];
}
}
$i++;
}
return $final;
}
/* unused but FPBX API requires it */ /* unused but FPBX API requires it */
public function install() { public function install() {

View file

@ -26,20 +26,19 @@ $keysetarray = $this->extconfigs->getExtConfig('keyset');
'uriaction' => array('default')); 'uriaction' => array('default'));
*/ */
// ------------------------------------- Key Set Display information --------------------------------------------------------- // ------------------------------------- Key Set Display information ---------------------------------------------------------
$keynamearray = array('onhook' => array('sname' => 'ONHOOK', 'name' =>'Display Onhook', 'help' =>'help.'), $keynamearray = array('ONHOOK' => array('sname' => 'ONHOOK', 'name' =>'Display Onhook', 'help' =>'help.'),
'connected' => array('sname' => 'CONNECTED', 'name' =>'Display Connected', 'help' =>'help.'), 'CONNECTED' => array('sname' => 'CONNECTED', 'name' =>'Display Connected', 'help' =>'help.'),
'onhold' => array('sname' => 'ONHOLD', 'name' =>'Display onhold', 'help' =>'help.'), 'ONHOLD' => array('sname' => 'ONHOLD', 'name' =>'Display onhold', 'help' =>'help.'),
'ringin' => array('sname' => 'RINGIN', 'name' =>'Display ringin', 'help' =>'help.'), 'RINGIN' => array('sname' => 'RINGIN', 'name' =>'Display ringin', 'help' =>'help.'),
'offhook' => array('sname' => 'OFFHOOK', 'name' =>'Display offhook', 'help' =>'help.'), 'OFFHOOK' => array('sname' => 'OFFHOOK', 'name' =>'Display offhook', 'help' =>'help.'),
'conntrans' => array('sname' => 'CONNTRANS', 'name' =>'Display conntrans', 'help' =>'help.'), 'CONNTRANS' => array('sname' => 'CONNTRANS', 'name' =>'Display conntrans', 'help' =>'help.'),
'digitsfoll' => array('sname' => 'DIGITSFOLL', 'name' =>'Display digitsfoll', 'help' =>'help.'), 'DIGITSFOLL' => array('sname' => 'DIGITSFOLL', 'name' =>'Display digitsfoll', 'help' =>'help.'),
'connconf' => array('sname' => 'CONNCONF', 'name' =>'Display connconf', 'help' =>'help.'), 'CONNCONF' => array('sname' => 'CONNCONF', 'name' =>'Display connconf', 'help' =>'help.'),
'ringout' => array('sname' => 'RINGOUT', 'name' =>'Display ringout', 'help' =>'help.'), 'RINGOUT' => array('sname' => 'RINGOUT', 'name' =>'Display ringout', 'help' =>'help.'),
'offhookfeat'=> array('sname' => 'OFFHOOKFEAT', 'name' =>'Display offhookfeat', 'help' =>'help.'), 'OFFHOOKFEAT'=> array('sname' => 'OFFHOOKFEAT', 'name' =>'Display offhookfeat', 'help' =>'help.'),
'onhint' => array('sname' => 'ONHINT', 'name' =>'Display onhint', 'help' =>'help.'), 'INUSEHINT' => array('sname' => 'INUSEHINT', 'name' =>'Display inusehint', 'help' =>'help.'),
'onstealable'=> array('sname' => 'onstealable', 'name' =>'Display onstealable', 'help' =>'help.'), 'ONHOOKSTEALABLE'=> array('sname' => 'ONHOOKSTEALABLE', 'name' =>'Display onhookstealable', 'help' =>'help.'),
'holdconf' => array('sname' => 'HOLDCONF', 'name' =>'Display holdconf', 'help' =>'help.'), 'HOLDCONF' => array('sname' => 'HOLDCONF', 'name' =>'Display holdconf', 'help' =>'help.')
'uriaction' => array('sname' => '', 'name' =>'Display uriaction', 'help' =>'help.')
); );
?> ?>
@ -60,7 +59,7 @@ $keynamearray = array('onhook' => array('sname' => 'ONHOOK', 'name' =>'Displa
<?php <?php
$i = 0; $i = 0;
foreach ($keynamearray as $key => $value) { foreach ($keynamearray as $key => $value) {
if ($i < 12) { if ($i < 13) {
echo '<th data-sortable="false" data-field="'.$key.'">'._($value['sname']).'</th>'; echo '<th data-sortable="false" data-field="'.$key.'">'._($value['sname']).'</th>';
} }
$i ++; $i ++;