From a146cd235437893f9106766ffe8f758aed2feb46 Mon Sep 17 00:00:00 2001
From: steve-lad <72376554+steve-lad@users.noreply.github.com>
Date: Thu, 17 Jun 2021 09:40:24 +0200
Subject: [PATCH] Set defaults for Add Device
Get default values from db for add new device
Tidy up AjaxHelper get phone grid removing unnecessary tests and using clearer variable names
Correct typos in sccpgeneral
---
conf/sccpgeneral.xml.v433 | 6 +--
sccpManTraits/ajaxHelper.php | 94 +++++++++++++++++++-----------------
views/form.adddevice.php | 30 +++++++++---
3 files changed, 76 insertions(+), 54 deletions(-)
diff --git a/conf/sccpgeneral.xml.v433 b/conf/sccpgeneral.xml.v433
index 4bfe55b..261de0c 100644
--- a/conf/sccpgeneral.xml.v433
+++ b/conf/sccpgeneral.xml.v433
@@ -1119,7 +1119,7 @@ and open the template in the editor. Base Version before all crash :-)
off
- Enable/Disable conferencing via meetme (on/off), make sure you have one of the meetme apps mentioned below activated in module.conf
+ Enable/Disable conferencing via meetme (on/off), make sure you have one of the meetme apps mentioned below is activated in module.conf
-
@@ -1534,7 +1534,7 @@ and open the template in the editor. Base Version before all crash :-)
-
conf_play_general_announce
-
+
on
@@ -1542,7 +1542,7 @@ and open the template in the editor. Base Version before all crash :-)
-
conf_play_part_announce
-
+
on
diff --git a/sccpManTraits/ajaxHelper.php b/sccpManTraits/ajaxHelper.php
index 33e2620..2e2fdc3 100644
--- a/sccpManTraits/ajaxHelper.php
+++ b/sccpManTraits/ajaxHelper.php
@@ -299,61 +299,67 @@ trait ajaxHelper {
return $result;
break;
case 'getPhoneGrid':
+ $dbDevices = array();
$cmd_type = !empty($request['type']) ? $request['type'] : '';
- $result = $this->dbinterface->HWextension_db_SccpTableData('SccpDevice', array('type' => $cmd_type));
+ // Find all devices defined in the database
+ $dbDevices = $this->dbinterface->HWextension_db_SccpTableData('SccpDevice', array('type' => $cmd_type));
+ // Return if only interested in SIP devices
if ($cmd_type == 'cisco-sip') {
- return $result;
+ return $dbDevices; //this may be empty
}
- $staus = $this->aminterface->sccp_get_active_device();
- if (empty($result)) {
- $result = array();
- } else {
- foreach ($result as &$dev_id) {
- $id_name = $dev_id['name'];
- if (!empty($staus[$id_name])) {
- $dev_id['description'] = $staus[$id_name]['descr'];
- $dev_id['status'] = $staus[$id_name]['status'];
- $dev_id['address'] = $staus[$id_name]['address'];
- $dev_id['new_hw'] = 'N';
- $staus[$id_name]['news'] = 'N';
- } else {
- $dev_id['description'] = '- -';
- $dev_id['status'] = 'not connected';
- $dev_id['address'] = '- -';
- }
+ // Find all devices currently connected
+ $activeDevices = $this->aminterface->sccp_get_active_device();
+
+ foreach ($dbDevices as &$dev_id) {
+ $id_name = $dev_id['name'];
+ if (!empty($activeDevices[$id_name])) {
+ // Device is in db and is connected
+ $dev_id['description'] = $activeDevices[$id_name]['descr'];
+ $dev_id['status'] = $activeDevices[$id_name]['status'];
+ $dev_id['address'] = $activeDevices[$id_name]['address'];
+ $dev_id['new_hw'] = 'N';
+ // No further action required on this active device
+ unset($activeDevices[$id_name]);
+ } else {
+ // Device is in db but not connected
+ $dev_id['description'] = '- -';
+ $dev_id['status'] = 'not connected';
+ $dev_id['address'] = '- -';
}
}
- if (!empty($staus)) {
- foreach ($staus as $dev_ids) {
+
+ if (!empty($activeDevices)) {
+ // Have a device that is connected but is not currently in the database
+ // This device must have been configured by sccp.conf
+ // Pass parameters to addDevice so that can be added to db.
+ foreach ($activeDevices as $dev_ids) {
$id_name = $dev_ids['name'];
- if (empty($dev_ids['news'])) {
- $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";
- }
- $result[] = 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
- );
+ $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 $result;
+ return $dbDevices;
break;
case 'getDialTemplate':
// ------------------------------- Old device support - In the development---
diff --git a/views/form.adddevice.php b/views/form.adddevice.php
index 47f046d..f220a6e 100644
--- a/views/form.adddevice.php
+++ b/views/form.adddevice.php
@@ -4,7 +4,7 @@
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
-$def_val = null;
+$def_val = array();
$dev_id = null;
$dev_new = null;
$device_warning= null;
@@ -15,7 +15,18 @@ $def_val['devlang'] = array("keyword" => 'devlang', "data" => $this->sccpvalues
$def_val['directed_pickup_context'] = array("keyword" => 'directed_pickup_context', "data" => $this->sccpvalues['directed_pickup_context']['data'], "seq" => "99");
if (!empty($_REQUEST['new_id'])) {
+ // Adding device that is connected but not in database
$dev_id = $_REQUEST['new_id'];
+
+ // Get device defaults from db
+ $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");
+ }
+
+ // Overwrite some specific defaults based on $_REQUEST
$val = str_replace(array('SEP','ATA','VG'), '', $dev_id);
$val = implode('.', sscanf($val, '%4s%4s%4s')); // Convert to Cisco display Format
$def_val['mac'] = array("keyword" => 'mac', "data" => $val, "seq" => "99");
@@ -24,13 +35,17 @@ if (!empty($_REQUEST['new_id'])) {
if (!empty($_REQUEST['addon'])) {
$def_val['addon'] = array("keyword" => 'type', "data" => $_REQUEST['addon'], "seq" => "99");
}
- // TODO Default values should be used to populate this device
- // Currently these are read from sccpgeneral.xml
- // Need to get these from the db as defaults may have changed.
}
+if (empty($_REQUEST['id'])) {
+ // Adding new device to database
+ $sccpDeviceDesc = $this->dbinterface->HWextension_db_SccpTableData('get_columns_sccpdevice');
-// Editing an existing Device
-if (!empty($_REQUEST['id'])) {
+ foreach ($sccpDeviceDesc as $data) {
+ $key = (string) $data['Field'];
+ $def_val[$key] = array("keyword" => $key, "data" => $data['Default'], "seq" => "99");
+ }
+} else {
+ // Editing an existing Device
$dev_id = $_REQUEST['id'];
$dev_new = $dev_id;
$db_res = $this->dbinterface->HWextension_db_SccpTableData('get_sccpdevice_byid', array("id" => $dev_id));
@@ -68,8 +83,9 @@ if (!empty($_REQUEST['id'])) {
// $key = $key . '_mask';
// $val = after('/', $val);
// break;
+ default:
+ $def_val[$key] = array("keyword" => $key, "data" => $val, "seq" => "99");
}
- $def_val[$key] = array("keyword" => $key, "data" => $val, "seq" => "99");
}
}