From ea6b7b378330202f480b2c5da246fe1cd3c03a0a Mon Sep 17 00:00:00 2001 From: stevenA Date: Sun, 9 Jan 2022 12:58:18 +0100 Subject: [PATCH] Use doConfigPageInit BMO method Increase compliance with BMO. Decreases calls and improves responsiveness --- Sccp_manager.class.php | 8 ++ assets/js/sccp_manager.js | 2 +- page.sccp_phone.php | 1 + sccpManTraits/ajaxHelper.php | 112 +--------------------- sccpManTraits/bmoFunctions.php | 153 +++++++++++++++++++++++++----- sccpManTraits/helperFunctions.php | 1 + views/advserver.dialtemplate.php | 7 +- views/advserver.model.php | 44 ++++----- views/hardware.extension.php | 7 +- views/hardware.phone.php | 7 +- views/hardware.rnav.php | 7 +- views/hardware.sphone.php | 8 +- 12 files changed, 193 insertions(+), 164 deletions(-) diff --git a/Sccp_manager.class.php b/Sccp_manager.class.php index dcff7d8..3a70872 100644 --- a/Sccp_manager.class.php +++ b/Sccp_manager.class.php @@ -110,6 +110,7 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO { if ($freepbx == null) { throw new Exception("Not given a FreePBX Object"); } + dbug('__construct called', debug_backtrace(2)); $this->class_error = array(); $this->FreePBX = $freepbx; $this->db = $freepbx->Database; @@ -198,6 +199,11 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO { } } + public function showPage() { + dbug('showPage called', $_REQUEST); + return; + } + /* * Show form information - General */ @@ -296,6 +302,8 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO { } public function phoneShowPage() { + dbug($_REQUEST); + dbug(debug_backtrace(0)); $request = $_REQUEST; $action = !empty($request['action']) ? $request['action'] : ''; $inputform = !empty($request['tech_hardware']) ? $request['tech_hardware'] : ''; diff --git a/assets/js/sccp_manager.js b/assets/js/sccp_manager.js index b1b1d8f..7bb653d 100644 --- a/assets/js/sccp_manager.js +++ b/assets/js/sccp_manager.js @@ -187,7 +187,7 @@ $(document).ready(function () { $('.dropdown-menu a.dropitem').on("click", function (e) { $(this).parents('div.btn-group').find('.dropdown_capture').text($(this).text()); -// console.log($(this).data('id')); + //console.log($(this).data('id')); ref_url = "ajax.php?module=sccp_manager&command=getDeviceModel&type=" + $(this).data('id'); $('#table-models').bootstrapTable('refresh', {url: ref_url}); }); diff --git a/page.sccp_phone.php b/page.sccp_phone.php index 4d65ba7..111ee2c 100644 --- a/page.sccp_phone.php +++ b/page.sccp_phone.php @@ -14,6 +14,7 @@ if (!defined('FREEPBX_IS_AUTH')) { // function is called. This is where you do any changes. The page.foo.php // is only for DISPLAYING things. MVC is a cool idea, ya know? // +dbug(debug_backtrace()); $spage = FreePBX::create()->Sccp_manager; if (empty($spage->class_error)) { $display_page = $spage->phoneShowPage(); diff --git a/sccpManTraits/ajaxHelper.php b/sccpManTraits/ajaxHelper.php index 267b793..423812f 100644 --- a/sccpManTraits/ajaxHelper.php +++ b/sccpManTraits/ajaxHelper.php @@ -15,12 +15,8 @@ trait ajaxHelper { case 'save_ruser': case 'save_dialplan_template': case 'delete_hardware': - case 'getPhoneGrid': - case 'getExtensionGrid': case 'getDeviceModel': case 'getUserGrid': - case 'getSoftKey': - case 'getDialTemplate': case 'get_ext_files': case 'create_hw_tftp': case 'reset_dev': @@ -49,6 +45,7 @@ trait ajaxHelper { $request = $_REQUEST; $msg = array(); $cmd_id = $request['command']; + dbug('ajax', $cmd_id); switch ($cmd_id) { case 'savesettings': // Consolidate this into a separate method to improve legibility @@ -265,113 +262,6 @@ trait ajaxHelper { return array('status' => true, 'table_reload' => true); } break; - case '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; - break; - case 'getExtensionGrid': - $lineList = $this->dbinterface->getSccpDeviceTableData($request['type']); - if (empty($lineList)) { - return array(); - } - $activeDevices = $this->aminterface->sccp_get_active_device(); - $uniqueLineList = array(); - foreach ($lineList as $key => &$lineArr) { - if (array_key_exists($lineArr['mac'], $activeDevices)) { - $lineArr['line_status'] = "{$activeDevices[$lineArr['mac']]['status']} | {$activeDevices[$lineArr['mac']]['act']}"; - } - if (array_key_exists($lineArr['name'], $uniqueLineList)) { - $lineList[$uniqueLineList[$lineArr['name']]]['mac'] .= '
' . $lineArr['mac']; - $lineList[$uniqueLineList[$lineArr['name']]]['line_status'] .= '
' . $lineArr['line_status']; - unset($lineList[$key]); // Drop this array as no longer used - continue; - } - $uniqueLineList[$lineArr['name']] = $key; - } - unset($lineArr, $uniqueLineList); // unset reference and temp vars. - return array_values($lineList); // Reindex array and return - break; - case 'getPhoneGrid': - $dbDevices = array(); - // Find all devices defined in the database. - $dbDevices = $this->dbinterface->getSccpDeviceTableData('phoneGrid', array('type' => $request['type'])); - - // Return if only interested in SIP devices - if ($request['type'] == 'cisco-sip') { - return $dbDevices; //this may be empty - } - // Find all devices currently connected - $activeDevices = $this->aminterface->sccp_get_active_device(); - - foreach ($dbDevices as &$dev_id) { - if (!empty($activeDevices[$dev_id['name']])) { - // Device is in db and is connected - $dev_id['description'] = $activeDevices[$dev_id['name']]['descr']; - $dev_id['status'] = $activeDevices[$dev_id['name']]['status']; - $dev_id['address'] = $activeDevices[$dev_id['name']]['address']; - $dev_id['new_hw'] = 'N'; - // No further action required on this active device - unset($activeDevices[$dev_id['name']]); - } - } - unset($dev_id); // unset reference. - - if (!empty($activeDevices)) { - // Have a device that is connected but is not currently in the database - // This device must have connected via hotline or config in sccp.conf. - // Pass parameters to addDevice so that can be added to db. - foreach ($activeDevices as $dev_ids) { - $id_name = $dev_ids['name']; - $dev_data = $this->aminterface->sccp_getdevice_info($id_name); - if (!empty($dev_data['SCCP_Vendor']['model_id'])) { - $dev_addon = $dev_data['SCCP_Vendor']['model_addon']; - if (empty($dev_addon)) { - $dev_addon = null; - } - $dev_schema = $this->getSccpModelInformation('byciscoid', false, "all", array('model' => $dev_data['SCCP_Vendor']['model_id'])); - if (empty($dev_schema)) { - $dev_schema[0]['model'] = "ERROR in Model Schema"; - } - $dbDevices[] = array( - 'name' => $id_name, - 'mac' => $id_name, - 'button' => '---', - 'type' => $dev_schema[0]['model'], - 'new_hw' => 'Y', - 'description' => '*NEW* ' . $dev_ids['descr'], - 'status' => '*NEW* ' . $dev_ids['status'], - 'address' => $dev_ids['address'], - 'addon' => $dev_addon - ); - } - } - } - return $dbDevices; - break; - case 'getDialTemplate': - // ------------------------------- Old device support - In the development--- - $result = $this->getDialPlanList(); - if (empty($result)) { - $result = array(); - } - return $result; - break; case 'backupsettings': // ------------------------------- Old device support - In the development--- $filename = $this->createSccpBackup(); diff --git a/sccpManTraits/bmoFunctions.php b/sccpManTraits/bmoFunctions.php index 633ad4f..83c2a03 100644 --- a/sccpManTraits/bmoFunctions.php +++ b/sccpManTraits/bmoFunctions.php @@ -5,41 +5,148 @@ namespace FreePBX\modules\Sccp_manager\sccpManTraits; trait bmoFunctions { //Need to reload freePBX for modifications below to work -/* + //want to catch extensions public static function myConfigPageInits() { - return array("extensions"); + return array('sccpsettings', 'sccp_phone','sccp_adv'); } -*/ public function doConfigPageInit($page) { - if ($page == "extensions") { + switch ($page) { + case 'sccpsettings': + dbug('doConfigPageInit called for', $page); + break; + case 'sccp_phone': + dbug('doConfigPageInit called for', $page); + //dbug('doConfigPageInit called from', debug_backtrace()); + //"ajax.php?module=sccp_manager&command=getExtensionGrid&type=extGrid" + //header('Content-type: application/json'); + $this->extensionData = json_encode($this->getExtensionGrid('extGrid')); + //$this->extensionData = $this->getExtensionGrid('extGrid'); + //"ajax.php?module=sccp_manager&command=getPhoneGrid&type=sccp + $this->sccpPhoneData = json_encode($this->getPhoneGrid('sccp')); + $this->sipPhoneData = json_encode($this->getPhoneGrid('cisco-sip')); + break; + case 'sccp_adv': + dbug('doConfigPageInit called for', $page); + $this->dialTemplateData = json_encode($this->getDialTemplate()); + $this->softKeyData = json_encode($this->getSoftKey()); + $this->deviceModelData = json_encode($this->ajaxHandler($_REQUEST = array('command'=>'getDeviceModel', 'type'=>'enabled'))); + //dbug($this->deviceModelData); + break; + default: + break; } - $this->doGeneralPost(); } - // Try to change extensions which is part of core -/* - public static function myGuiHooks() { - return array('core'); - } -*/ -/* - public function doGuiHook(&$cc) { - if ($_REQUEST['display'] == "extensions" ) { - if ($_REQUEST['tech_hardware'] == 'sccp_custom') { + function getPhoneGrid(string $type){ + $dbDevices = array(); + // Find all devices defined in the database. + $dbDevices = $this->dbinterface->getSccpDeviceTableData('phoneGrid', array('type' => $type)); - this is the add extensions form - On submit returns to extensions page. Users prefer that it returns - To Sccp Phone. - Below adds redirect URL, but it is not followed - $cc->setRedirectURL("config.php?display=sccp_phone"); - so force redirect at end of addDevice in SccpClass + // Return if only interested in SIP devices + if ($type == 'cisco-sip') { + return $dbDevices; //this may be empty + } + // Find all devices currently connected + $activeDevices = $this->aminterface->sccp_get_active_device(); + foreach ($dbDevices as &$dev_id) { + if (!empty($activeDevices[$dev_id['name']])) { + // Device is in db and is connected + $dev_id['description'] = $activeDevices[$dev_id['name']]['descr']; + $dev_id['status'] = $activeDevices[$dev_id['name']]['status']; + $dev_id['address'] = $activeDevices[$dev_id['name']]['address']; + $dev_id['new_hw'] = 'N'; + // No further action required on this active device + unset($activeDevices[$dev_id['name']]); } } + unset($dev_id); // unset reference. + + if (!empty($activeDevices)) { + // Have a device that is connected but is not currently in the database + // This device must have connected via hotline or config in sccp.conf. + // Pass parameters to addDevice so that can be added to db. + foreach ($activeDevices as $dev_ids) { + $id_name = $dev_ids['name']; + $dev_data = $this->aminterface->sccp_getdevice_info($id_name); + if (!empty($dev_data['SCCP_Vendor']['model_id'])) { + $dev_addon = $dev_data['SCCP_Vendor']['model_addon']; + if (empty($dev_addon)) { + $dev_addon = null; + } + $dev_schema = $this->getSccpModelInformation('byciscoid', false, "all", array('model' => $dev_data['SCCP_Vendor']['model_id'])); + if (empty($dev_schema)) { + $dev_schema[0]['model'] = "ERROR in Model Schema"; + } + $dbDevices[] = array( + 'name' => $id_name, + 'mac' => $id_name, + 'button' => '---', + 'type' => $dev_schema[0]['model'], + 'new_hw' => 'Y', + 'description' => '*NEW* ' . $dev_ids['descr'], + 'status' => '*NEW* ' . $dev_ids['status'], + 'address' => $dev_ids['address'], + 'addon' => $dev_addon + ); + } + } + } + return $dbDevices; + } + + function getExtensionGrid(string $type) { + $lineList = $this->dbinterface->getSccpDeviceTableData($type); + if (empty($lineList)) { + return array(); + } + $activeDevices = $this->aminterface->sccp_get_active_device(); + $uniqueLineList = array(); + foreach ($lineList as $key => &$lineArr) { + if (array_key_exists($lineArr['mac'], $activeDevices)) { + $lineArr['line_status'] = "{$activeDevices[$lineArr['mac']]['status']} | {$activeDevices[$lineArr['mac']]['act']}"; + } + if (array_key_exists($lineArr['name'], $uniqueLineList)) { + $lineList[$uniqueLineList[$lineArr['name']]]['mac'] .= '
' . $lineArr['mac']; + $lineList[$uniqueLineList[$lineArr['name']]]['line_status'] .= '
' . $lineArr['line_status']; + unset($lineList[$key]); // Drop this array as no longer used + continue; + } + $uniqueLineList[$lineArr['name']] = $key; + } + unset($lineArr, $uniqueLineList); // unset reference and temp vars. + return array_values($lineList); // Reindex array and return + } + + function getDialTemplate() { + // ------------------------------- Old device support - In the development--- + $result = array(); + $result = $this->getDialPlanList(); + 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; } -*/ /* unused but FPBX API requires it */ public function install() { @@ -140,7 +247,7 @@ trait bmoFunctions { public function getRightNav($request) { global $amp_conf; if (isset($request['tech_hardware']) && ($request['tech_hardware'] == 'cisco')) { - return load_view($amp_conf['AMPWEBROOT'] .'/admin/modules/sccp_manager/views/hardware.rnav.php', array('request' => $request)); + return load_view($amp_conf['AMPWEBROOT'] .'/admin/modules/sccp_manager/views/hardware.rnav.php', array('data' => $this->sccpPhoneData)); } } diff --git a/sccpManTraits/helperFunctions.php b/sccpManTraits/helperFunctions.php index a6e4c3a..c101802 100644 --- a/sccpManTraits/helperFunctions.php +++ b/sccpManTraits/helperFunctions.php @@ -265,6 +265,7 @@ trait helperfunctions { return true; } + public function getChanSccpSettings() { // This is a utility function for debug only, and is not used by core code foreach (array('general','line', 'device') as $section) { diff --git a/views/advserver.dialtemplate.php b/views/advserver.dialtemplate.php index e7bd7bf..7e3f620 100644 --- a/views/advserver.dialtemplate.php +++ b/views/advserver.dialtemplate.php @@ -17,7 +17,7 @@ - +
@@ -31,6 +31,11 @@ diff --git a/views/hardware.extension.php b/views/hardware.extension.php index c261ccb..7a99bbc 100644 --- a/views/hardware.extension.php +++ b/views/hardware.extension.php @@ -20,7 +20,7 @@ if (!empty($this->sccpvalues['system_rouminguser'])) {
 
-
+
@@ -36,6 +36,11 @@ if (!empty($this->sccpvalues['system_rouminguser'])) {