From 416cedc42558472c53a6a150adb705eed14f49f3 Mon Sep 17 00:00:00 2001 From: steve-lad <72376554+steve-lad@users.noreply.github.com> Date: Thu, 17 Jun 2021 10:18:07 +0200 Subject: [PATCH] Create new function to get device defaults Add new function in helperFunctions and use --- sccpManTraits/helperFunctions.php | 10 ++++++++++ views/form.adddevice.php | 9 ++------- views/server.advanced.php | 9 ++------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/sccpManTraits/helperFunctions.php b/sccpManTraits/helperFunctions.php index 4441e46..3e135d0 100644 --- a/sccpManTraits/helperFunctions.php +++ b/sccpManTraits/helperFunctions.php @@ -69,6 +69,16 @@ trait helperfunctions { } return FALSE; } + private function getDeviceDefaults() { + $def_val = array(); + $sccpDeviceDesc = $this->dbinterface->HWextension_db_SccpTableData('get_columns_sccpdevice'); + + foreach ($sccpDeviceDesc as $data) { + $key = (string) $data['Field']; + $def_val[$key] = array("keyword" => $key, "data" => $data['Default'], "seq" => "99"); + } + return $def_val; + } private function findAllFiles($dir, $file_mask = null, $mode = 'full') { $result = null; diff --git a/views/form.adddevice.php b/views/form.adddevice.php index f220a6e..e0cae98 100644 --- a/views/form.adddevice.php +++ b/views/form.adddevice.php @@ -37,13 +37,8 @@ if (!empty($_REQUEST['new_id'])) { } } if (empty($_REQUEST['id'])) { - // Adding new device to database - $sccpDeviceDesc = $this->dbinterface->HWextension_db_SccpTableData('get_columns_sccpdevice'); - - foreach ($sccpDeviceDesc as $data) { - $key = (string) $data['Field']; - $def_val[$key] = array("keyword" => $key, "data" => $data['Default'], "seq" => "99"); - } + // Adding new device to database. Get default values + $def_val = $this->getDeviceDefaults(); } else { // Editing an existing Device $dev_id = $_REQUEST['id']; diff --git a/views/server.advanced.php b/views/server.advanced.php index f592dff..d712320 100644 --- a/views/server.advanced.php +++ b/views/server.advanced.php @@ -14,15 +14,10 @@ // originally, this was populated by sccpgeneral.xml but that should be static // now will populate from the db defaults. - $defaultVal = array(); - $sccpDeviceDesc = $this->dbinterface->HWextension_db_SccpTableData('get_columns_sccpdevice'); + $defaultVals = $this->getDeviceDefaults(); - foreach ($sccpDeviceDesc as $data) { - $key = (string) $data['Field']; - $defaultVal[$key] = array("keyword" => $key, "data" => $data['Default'], "seq" => "99"); - } echo $this->showGroup('sccp_srst', 1); - echo $this->showGroup('sccp_dev_vendor_conf', 1,'vendorconfig',$defaultVal,false); + echo $this->showGroup('sccp_dev_vendor_conf', 1,'vendorconfig',$defaultVals,false); ?>