From fb7a7da60a455d03af2c05354f00f8a72fa241ba Mon Sep 17 00:00:00 2001 From: stevenA Date: Fri, 21 Jan 2022 16:12:01 +0100 Subject: [PATCH] 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 --- .../amInterfaceClasses/Response.class.php | 58 ++++++++++++------- sccpManClasses/aminterface.class.php | 5 +- sccpManClasses/formcreate.class.php | 3 + sccpManTraits/ajaxHelper.php | 8 +-- sccpManTraits/bmoFunctions.php | 43 +------------- views/advserver.keyset.php | 29 +++++----- 6 files changed, 59 insertions(+), 87 deletions(-) diff --git a/sccpManClasses/amInterfaceClasses/Response.class.php b/sccpManClasses/amInterfaceClasses/Response.class.php index 9805e61..7445ef3 100644 --- a/sccpManClasses/amInterfaceClasses/Response.class.php +++ b/sccpManClasses/amInterfaceClasses/Response.class.php @@ -252,33 +252,47 @@ class SCCPGeneric_Response extends Response 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(); $_rawtable = $this->Table2Array($_tablename); // Check that there is actually data to be converted - if (empty($_rawtable)) { return $result;} - foreach ($_rawtable as $_row) { - $all_key_ok = true; - // No need to test if $_fkey is array as array required - foreach ($_fkey as $_fid) { - if (empty($_row[$_fid])) { - $all_key_ok = false; - } else { - $set_name[$_fid] = $_row[$_fid]; - } - } - $Data = &$result; - - if ($all_key_ok) { - foreach ($set_name as $value_id) { - $Data = &$Data[$value_id]; - } - // Label converter in case labels and keys are different - foreach ($_fields as $value_key => $value_id) { - $Data[$value_id] = $_row[$value_key]; - } + if (empty($_rawtable)) { + return $result; + } + // 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) { + if (!isset($_rawtable[0][$_fid])) { + return $result; } } + // could also use tablename here + $complexArray = true; + if (count($_fkey) === 1) { + $complexArray = false; + } + foreach ($_rawtable as $_rowArr) { + // $_row is a table element + $outputArr = array(); + foreach ($_fields as $value_key => $value_id) { + $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']}
"; + } else { + $result[$_rowArr[$_fkey[0]]][$_rowArr[$_fkey[1]]] = "{$outputArr['label']}
"; + } + } else { + $result[$_rowArr[$_fkey[0]]] = $outputArr; + } + } + //dbug($result); return $result; } diff --git a/sccpManClasses/aminterface.class.php b/sccpManClasses/aminterface.class.php index e20a636..94de2af 100644 --- a/sccpManClasses/aminterface.class.php +++ b/sccpManClasses/aminterface.class.php @@ -361,10 +361,7 @@ class aminterface $result = array(); if ($this->_connect_state) { $_action = new \FreePBX\modules\Sccp_manager\aminterface\SCCPShowSoftkeySetsAction(); - $_res = $this->send($_action)->getResult(); - foreach ($_res as $key => $value) { - $result[$key] = $key; - } + $result = $this->send($_action)->getResult(); } return $result; } diff --git a/sccpManClasses/formcreate.class.php b/sccpManClasses/formcreate.class.php index 6aeb546..65c2419 100644 --- a/sccpManClasses/formcreate.class.php +++ b/sccpManClasses/formcreate.class.php @@ -571,9 +571,12 @@ class formcreate class . '" id="' . $res_id . '">'; foreach ($select_opt as $key => $val) { + // TODO: Clean this up - its a bunch of fixes if (is_array($val)) { $opt_key = (isset($val['id'])) ? $val['id'] : $key; $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)){ // have associative array $opt_key = $key; diff --git a/sccpManTraits/ajaxHelper.php b/sccpManTraits/ajaxHelper.php index e7a7f7f..2a9601c 100644 --- a/sccpManTraits/ajaxHelper.php +++ b/sccpManTraits/ajaxHelper.php @@ -234,8 +234,8 @@ trait ajaxHelper { //$id_name = $request['softkey']; unset($this->sccp_conf_init[$request['softkey']]); $this->createDefaultSccpConfig($this->sccpvalues, $this->sccppath["asterisk"]); - $msg = print_r($this->aminterface->core_sccp_reload(), 1); - return array('status' => true, 'table_reload' => true); + $msg = $this->aminterface->core_sccp_reload(); + return array('status' => true, 'reload' => true, 'message' => $msg['Response'] .' - Softkey set deleted'); } break; case 'updateSoftKey': @@ -251,8 +251,8 @@ trait ajaxHelper { // !TODO!: -TODO-: Check SIP Support Enabled $this->createSccpXmlSoftkey(); - $msg = print_r($this->aminterface->core_sccp_reload(), 1); - return array('status' => true, 'table_reload' => true, 'msg' => $msg); + $msg = $this->aminterface->core_sccp_reload(); + return array('status' => true, 'reload' => true, 'message' => $msg['Response'] .' - Softkey sets updated'); } break; case 'backupsettings': diff --git a/sccpManTraits/bmoFunctions.php b/sccpManTraits/bmoFunctions.php index c9a6486..70c8d62 100644 --- a/sccpManTraits/bmoFunctions.php +++ b/sccpManTraits/bmoFunctions.php @@ -23,7 +23,7 @@ trait bmoFunctions { break; case 'sccp_adv': $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'))); break; default: @@ -125,47 +125,6 @@ trait bmoFunctions { 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(',', '
', $value); - } - } else { - foreach ($this->getMyConfig('softkeyset', $keyl) as $key => $value) { - $result[$i][$key] = str_replace(',', '
', $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 */ public function install() { diff --git a/views/advserver.keyset.php b/views/advserver.keyset.php index 3b2d8a0..6164616 100644 --- a/views/advserver.keyset.php +++ b/views/advserver.keyset.php @@ -26,20 +26,19 @@ $keysetarray = $this->extconfigs->getExtConfig('keyset'); 'uriaction' => array('default')); */ // ------------------------------------- Key Set Display information --------------------------------------------------------- -$keynamearray = array('onhook' => array('sname' => 'ONHOOK', 'name' =>'Display Onhook', 'help' =>'help.'), - 'connected' => array('sname' => 'CONNECTED', 'name' =>'Display Connected', 'help' =>'help.'), - 'onhold' => array('sname' => 'ONHOLD', 'name' =>'Display onhold', 'help' =>'help.'), - 'ringin' => array('sname' => 'RINGIN', 'name' =>'Display ringin', 'help' =>'help.'), - 'offhook' => array('sname' => 'OFFHOOK', 'name' =>'Display offhook', 'help' =>'help.'), - 'conntrans' => array('sname' => 'CONNTRANS', 'name' =>'Display conntrans', 'help' =>'help.'), - 'digitsfoll' => array('sname' => 'DIGITSFOLL', 'name' =>'Display digitsfoll', 'help' =>'help.'), - 'connconf' => array('sname' => 'CONNCONF', 'name' =>'Display connconf', 'help' =>'help.'), - 'ringout' => array('sname' => 'RINGOUT', 'name' =>'Display ringout', 'help' =>'help.'), - 'offhookfeat'=> array('sname' => 'OFFHOOKFEAT', 'name' =>'Display offhookfeat', 'help' =>'help.'), - 'onhint' => array('sname' => 'ONHINT', 'name' =>'Display onhint', 'help' =>'help.'), - 'onstealable'=> array('sname' => 'onstealable', 'name' =>'Display onstealable', 'help' =>'help.'), - 'holdconf' => array('sname' => 'HOLDCONF', 'name' =>'Display holdconf', 'help' =>'help.'), - 'uriaction' => array('sname' => '', 'name' =>'Display uriaction', 'help' =>'help.') +$keynamearray = array('ONHOOK' => array('sname' => 'ONHOOK', 'name' =>'Display Onhook', 'help' =>'help.'), + 'CONNECTED' => array('sname' => 'CONNECTED', 'name' =>'Display Connected', 'help' =>'help.'), + 'ONHOLD' => array('sname' => 'ONHOLD', 'name' =>'Display onhold', 'help' =>'help.'), + 'RINGIN' => array('sname' => 'RINGIN', 'name' =>'Display ringin', 'help' =>'help.'), + 'OFFHOOK' => array('sname' => 'OFFHOOK', 'name' =>'Display offhook', 'help' =>'help.'), + 'CONNTRANS' => array('sname' => 'CONNTRANS', 'name' =>'Display conntrans', 'help' =>'help.'), + 'DIGITSFOLL' => array('sname' => 'DIGITSFOLL', 'name' =>'Display digitsfoll', 'help' =>'help.'), + 'CONNCONF' => array('sname' => 'CONNCONF', 'name' =>'Display connconf', 'help' =>'help.'), + 'RINGOUT' => array('sname' => 'RINGOUT', 'name' =>'Display ringout', 'help' =>'help.'), + 'OFFHOOKFEAT'=> array('sname' => 'OFFHOOKFEAT', 'name' =>'Display offhookfeat', 'help' =>'help.'), + 'INUSEHINT' => array('sname' => 'INUSEHINT', 'name' =>'Display inusehint', 'help' =>'help.'), + 'ONHOOKSTEALABLE'=> array('sname' => 'ONHOOKSTEALABLE', 'name' =>'Display onhookstealable', 'help' =>'help.'), + 'HOLDCONF' => array('sname' => 'HOLDCONF', 'name' =>'Display holdconf', 'help' =>'help.') ); ?> @@ -60,7 +59,7 @@ $keynamearray = array('onhook' => array('sname' => 'ONHOOK', 'name' =>'Displa $value) { - if ($i < 12) { + if ($i < 13) { echo ''._($value['sname']).''; } $i ++;