From 124f7052ebeedbfc1e749312a14f71227b02fcef Mon Sep 17 00:00:00 2001 From: steve-lad <72376554+steve-lad@users.noreply.github.com> Date: Mon, 8 Feb 2021 15:27:35 +0100 Subject: [PATCH] Further clean ups and annotations Document changes --- Sccp_manager.class.php | 18 ++---- Sccp_manager.inc/dbinterface.class.php | 76 ++++++++++---------------- assets/js/sccp_manager.js | 11 ++-- views/advserver.model.php | 33 +++++------ 4 files changed, 56 insertions(+), 82 deletions(-) diff --git a/Sccp_manager.class.php b/Sccp_manager.class.php index c4be0a1..12254fb 100644 --- a/Sccp_manager.class.php +++ b/Sccp_manager.class.php @@ -869,6 +869,7 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO { } break; case 'getDeviceModel': +dbug('getting Device model'); switch ($request['type']) { case 'all': case 'extension': @@ -929,6 +930,7 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO { return $result; break; case 'getExtensionGrid': +dbug('getting Extension Grid'); $result = $this->dbinterface->HWextension_db_SccpTableData('SccpExtension'); if (empty($result)) { return array(); @@ -952,6 +954,7 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO { return $result; break; case 'getPhoneGrid': +dbug('getting Phone Grid'); $cmd_type = !empty($request['type']) ? $request['type'] : ''; $result = $this->dbinterface->HWextension_db_SccpTableData('SccpDevice', array('type' => $cmd_type)); @@ -1865,22 +1868,10 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO { // $save_settings = array(); if (empty($save_value)) { $this->dbinterface->write('sccpsettings', $this->sccpvalues, 'clear'); - -/* foreach ($this->sccpvalues as $key => $val) { - if ((trim($val['data']) !== '') or ($val['data'] == '0')) { - $save_settings[] = array($key, $val['data'], $val['seq'], $val['type']); - } else { - $unsaved_settings[] = array($key, $val['data'], $val['seq'], $val['type']); - } - } - $this->dbinterface->write('sccpsettings', $save_settings, 'clear'); -*/ } else { $this->dbinterface->write('sccpsettings', $save_value, 'update'); } return true; -// } -// return true; } /* @@ -2140,9 +2131,8 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO { } else { $dir_list = $this->findAllFiles($dir, $file_ext, 'fileonly'); } - $raw_settings = $this->dbinterface->getDb_model_info($get, $format_list, $filter); - +dbug('reloading table'); if ($validate) { for ($i = 0; $i < count($raw_settings); $i++) { $raw_settings[$i]['validate'] = '-;-'; diff --git a/Sccp_manager.inc/dbinterface.class.php b/Sccp_manager.inc/dbinterface.class.php index 674f69e..a4bd67e 100644 --- a/Sccp_manager.inc/dbinterface.class.php +++ b/Sccp_manager.inc/dbinterface.class.php @@ -121,7 +121,7 @@ class dbinterface $sql = "DESCRIBE sccpuser"; $stmts = $db->prepare($sql); break; - case "get_sccpdevice_byid": + case 'get_sccpdevice_byid': $sql = 'SELECT t1.*, types.dns, types.buttons, types.loadimage, types.nametemplate as nametemplate, ' . 'addon.buttons as addon_buttons FROM sccpdevice AS t1 ' . 'LEFT JOIN sccpdevmodel as types ON t1.type=types.model ' @@ -185,21 +185,15 @@ class dbinterface * Get Sccp Device Model information */ - function getDb_model_info($get = "all", $format_list = "all", $filter = array()) + function getDb_model_info($get = 'all', $format_list = 'all', $filter = array()) { global $db; - switch ($format_list) { - case "model": - $sel_inf = "model, vendor, dns, buttons"; - break; - case "all": - default: - $sel_inf = "*"; - break; + $sel_inf = '*, 0 as validate'; + if ($format_list === 'model') { + $sel_inf = 'model, vendor, dns, buttons, 0 as validate'; } - $sel_inf .= ", '0' as 'validate'"; switch ($get) { - case "byciscoid": + case 'byciscoid': if (!empty($filter)) { if (!empty($filter['model'])) { if (strpos($filter['model'], 'loadInformation')) { @@ -214,7 +208,7 @@ class dbinterface break; } break; - case "byid": + case 'byid': if (!empty($filter)) { if (!empty($filter['model'])) { $sql = 'SELECT ' . $sel_inf . ' FROM sccpdevmodel WHERE (model =' . $filter['model'] . ') ORDER BY model'; @@ -225,31 +219,29 @@ class dbinterface break; } break; - case "extension": + case 'extension': $sql = 'SELECT ' . $sel_inf . ' FROM sccpdevmodel WHERE (dns = 0) and (enabled > 0) ORDER BY model'; //check table break; - case "enabled": - $sql = 'SELECT ' . $sel_inf . ' FROM sccpdevmodel WHERE enabled > 0 ORDER BY model '; + case 'enabled': + $sql = 'SELECT ' . $sel_inf . ' FROM sccpdevmodel WHERE enabled > 0 ORDER BY model '; //previously this fell through to phones. break; - case "phones": + case 'phones': $sql = 'SELECT ' . $sel_inf . ' FROM sccpdevmodel WHERE (dns > 0) and (enabled > 0) ORDER BY model '; //check table break; - case "ciscophones": + case 'ciscophones': $sql = 'SELECT ' . $sel_inf . ' FROM sccpdevmodel WHERE (dns > 0) and (enabled > 0) AND vendor NOT LIKE \'%-sip\' ORDER BY model'; break; - case "sipphones": + case 'sipphones': $sql = 'SELECT ' . $sel_inf . ' FROM sccpdevmodel WHERE (dns > 0) and (enabled > 0) AND `vendor` LIKE \'%-sip\' ORDER BY model'; break; - case "all": - $sql = 'SELECT ' . $sel_inf . ' FROM sccpdevmodel ORDER BY model'; - break; + case 'all': // Fall through to default default: $sql = 'SELECT ' . $sel_inf . ' FROM sccpdevmodel ORDER BY model'; break; } $stmt = $db->prepare($sql); $stmt->execute(); - return $stmt->fetchAll(); + return $stmt->fetchAll(\PDO::FETCH_ASSOC); } function write($table_name = "", $save_value = array(), $mode = 'update', $key_fld = "", $hwid = "") @@ -318,7 +310,7 @@ class dbinterface $req = 'DELETE FROM sccpuser WHERE ' . $sql_key . ''; } else { if ($mode == 'update') { - $req = 'UPDATE sccpuser SET ' . $sql_var . WHERE . $sql_key . ''; + $req = 'UPDATE sccpuser SET ' . $sql_var . 'WHERE ' . $sql_key . ''; } else { $req = 'REPLACE INTO sccpuser SET ' . $sql_var . ''; } @@ -368,37 +360,29 @@ class dbinterface public function validate() { global $db; - $result = false; - $check_fields = array('430' => array('_hwlang' => "varchar(12)"), '431' => array('private'=> "enum('on','off')"), '433' => array('directed_pickup'=>'') ); + $result = 0; + $check_fields = [ + '430' => ['_hwlang' => "varchar(12)"], + '431' => ['private'=> "enum('on','off')"], + '433' => ['directed_pickup'=>''] + ]; $stmt = $db->prepare('DESCRIBE sccpdevice'); $stmt->execute(); - foreach ($stmt->fetchAll() as $value) { + foreach ($stmt->fetchAll(\PDO::FETCH_ASSOC) as $value) { $id_result[$value['Field']] = $value['Type']; } foreach ($check_fields as $key => $value) { - $sub_result = true; - foreach ($value as $skey => $svalue) { - if (!empty($svalue)) { - if (empty($id_result[$skey])) { - $sub_result = false; - } else { - if (strtolower($id_result[$skey]) != strtolower($svalue)) { - $sub_result = false; - } - } - } else { - if (!empty($id_result[$skey])) { - $sub_result = false; + if (!empty(array_intersect_assoc($value, $id_result))) { + $result = $key; + } else { + // no match but maybe checking against an empty string so just need to check key does not exist + foreach ($value as $skey => $svalue) { + if (empty($svalue) && (!isset($id_result[$skey]))) { + $result = $key; } } } - if ($sub_result) { - $result = $key; - } else { - break; - } } - return $result; } } diff --git a/assets/js/sccp_manager.js b/assets/js/sccp_manager.js index b8502ff..d163635 100644 --- a/assets/js/sccp_manager.js +++ b/assets/js/sccp_manager.js @@ -241,7 +241,7 @@ $(document).ready(function () { } e.preventDefault(); }); - + // Form.buttons - Form.adddevice $('.futuretype').change(function (e) { var kid = $(this).data('id'); @@ -256,7 +256,7 @@ $(document).ready(function () { } } }); - + }); $('.buttontype').change(function (e) { @@ -627,7 +627,7 @@ $(document).ready(function () { i++; }); } - + if (datas === '') { if (confirm(conf_msg)) { datas = 'name[0]=all'; @@ -692,7 +692,7 @@ $(document).ready(function () { //}); -// Bootstrap table Enabled / Disabled buttons ( class="btn-tab-select") +// Bootstrap table Enable / Disable buttons ( class="btn-tab-select") $("table").on('check-all.bs.table', function (rows) { var id_fld = $(this).data('id'); $(".btn-tab-select").each(function () { @@ -1011,7 +1011,7 @@ function bs_page_reload() } function bs_alert(data, status, reload) { - + if (document.getElementById('hwalert') === null) { if (Array.isArray(data)) { data.forEach(function (entry) { @@ -1075,4 +1075,3 @@ function sleep(milliseconds) } } } - diff --git a/views/advserver.model.php b/views/advserver.model.php index d19ea78..0a999b4 100644 --- a/views/advserver.model.php +++ b/views/advserver.model.php @@ -13,12 +13,13 @@
- +
@@ -108,8 +109,8 @@
Help.
- - + +
@@ -129,7 +130,7 @@
Help.
- +
@@ -143,7 +144,7 @@ +
@@ -169,7 +170,7 @@ Help.
- +
@@ -190,12 +191,12 @@ Help.
- +
+ @@ -214,7 +215,7 @@ // function DispayInputFormatter(value, row, index) { // return (value == null) ? '' : ''; // } - + function DispayActionsModelFormatter(value, row, index) { var exp_model = ''; // exp_model += ''; @@ -236,12 +237,12 @@ return value; } - + function SetRowColor(row, index) { var tclass = "active"; if (row['enabled'] === 1) { tclass = (index % 2 === 0) ? "info" : "info"; - } + } if ((row['validate'] === 'yes;yes') || (row['validate'] === 'yes;-')) { // tclass = (row['enabled'] === '1') ? "danger" : "warning"; } else { @@ -249,7 +250,7 @@ } return {classes: tclass}; } - + function load_model(elmnt,clr) { // $("#edit_devmodel").text(clr); var drow = $("#table-models").bootstrapTable('getRowByUniqueId',clr);