From 22a4eb6e9e65b2ed5c3684744f91c469b3ebe374 Mon Sep 17 00:00:00 2001 From: steve-lad <72376554+steve-lad@users.noreply.github.com> Date: Sun, 7 Feb 2021 16:09:35 +0100 Subject: [PATCH] Cleaning up Simplify structure and fix errors --- Sccp_manager.inc/dbinterface.class.php | 71 ++++++++++++-------------- 1 file changed, 34 insertions(+), 37 deletions(-) diff --git a/Sccp_manager.inc/dbinterface.class.php b/Sccp_manager.inc/dbinterface.class.php index b4ee6ee..674f69e 100644 --- a/Sccp_manager.inc/dbinterface.class.php +++ b/Sccp_manager.inc/dbinterface.class.php @@ -31,20 +31,21 @@ class dbinterface */ public function get_db_SccpTableByID($dataid, $data = array(), $indexField = '') { - $resut = array(); + $result = array(); $raw = $this->HWextension_db_SccpTableData($dataid, $data); if (empty($raw) || empty($indexField)) { return $raw; } foreach ($raw as $value) { $id = $value[$indexField]; - $resut[$id] = $value; + $result[$id] = $value; } return $resut; } public function HWextension_db_SccpTableData($dataid, $data = array()) { + // $stmt is a single row fetch, $stmts is a fetchAll. global $db; $stmt = ''; $stmts = ''; @@ -52,14 +53,14 @@ class dbinterface return false; } switch ($dataid) { - case "SccpExtension": + case 'SccpExtension': if (empty($data['name'])) { $stmts = $db->prepare('SELECT * FROM sccpline ORDER BY name'); } else { $stmts = $db->prepare('SELECT * FROM sccpline WHERE name = $data[name]'); } break; - case "SccpDevice": + case 'SccpDevice': $filtered =''; $singlerow = false; if (empty($data['fields'])) { @@ -103,20 +104,20 @@ class dbinterface $stmts = $db->prepare($sql); } break; - case "HWSipDevice": + case 'HWSipDevice': $raw_settings = $this->getDb_model_info($get = "sipphones", $format_list = "model"); break; - case "HWDevice": + case 'HWDevice': $raw_settings = $this->getDb_model_info($get = "ciscophones", $format_list = "model"); break; - case "HWextension": + case 'HWextension': $raw_settings = $this->getDb_model_info($get = "extension", $format_list = "model"); break; - case "get_colums_sccpdevice": + case 'get_colums_sccpdevice': $sql = "DESCRIBE sccpdevice"; $stmt = $db->prepare($sql); break; - case "get_colums_sccpuser": + case 'get_colums_sccpuser': $sql = "DESCRIBE sccpuser"; $stmts = $db->prepare($sql); break; @@ -127,7 +128,7 @@ class dbinterface . 'LEFT JOIN sccpdevmodel as addon ON t1.addon=addon.model WHERE name="' . $data['id'] . ''; $stmt = $db->prepare($sql); break; - case "get_sccpuser": + case 'get_sccpuser': $sql = 'SELECT * FROM sccpuser '; if (!empty($data['id'])) { $sql .= 'WHERE name= ' . $data['id'] . ''; @@ -135,13 +136,13 @@ class dbinterface $sql .= ' ORDER BY name'; $stmt = $db->prepare($sql); break; - case "get_sccpdevice_buttons": + case 'get_sccpdevice_buttons': $sql = ''; if (!empty($data['buttontype'])) { $sql .= 'buttontype="' . $data['buttontype'] . '" '; } if (!empty($data['id'])) { - $sql .= (empty($sql)) ? 'ref="' . $data['id'] . '" ' : 'and ref="' . $data['id'] . '" '; + $sql .= (empty($sql)) ? 'ref="' . $data['id'] . '" ' : 'and ref="' . $data['id'] . ''; } if (!empty($sql)) { $sql = 'SELECT * FROM sccpbuttonconfig WHERE ' .$sql. ' ORDER BY `instance`;'; @@ -204,7 +205,7 @@ class dbinterface if (strpos($filter['model'], 'loadInformation')) { $sql = 'SELECT ' . $sel_inf . ' FROM sccpdevmodel WHERE (loadinformationid =' . $filter['model'] . ') ORDER BY model'; } else { - $sql = 'SELECT ' . $sel_inf . ' FROM sccpdevmodel WHERE (loadinformationid =loadInformation' . $filter['model'] . ') ORDER BY model'; + $sql = 'SELECT ' . $sel_inf . ' FROM sccpdevmodel WHERE (loadinformationid = loadInformation' . $filter['model'] . ') ORDER BY model'; } } else { // $sql = "SELECT ".$filter['model']; @@ -326,36 +327,32 @@ class dbinterface $result = $db->prepare($req)->execute(); break; case 'sccpbuttons': - if (($mode == 'clear') || ($mode == 'delete')) { - $sql = 'DELETE FROM sccpbuttonconfig WHERE ref=' . $hwid . ''; - $result = $db->prepare($sql)->execute(); + switch ($mode) { + case 'clear': // no break here as clear is same as delete + case 'delete': + $sql = 'DELETE FROM sccpbuttonconfig WHERE ref=' . $hwid . ''; + $result = $db->prepare($sql)->execute(); + break; + case 'replace': + if (!empty($save_value)) { + $sql = 'UPDATE sccpbuttonconfig SET `name`=? WHERE `ref`= ? AND `reftype`=? AND `instance`=? AND `buttontype`=?'; + $stmt = $db->prepare($sql); + $result= $db->executeMultiple($stmt, $save_value); + } + break; + default: + if (!empty($save_value)) { + $sql = 'INSERT INTO sccpbuttonconfig (`ref`, `reftype`,`instance`, `buttontype`, `name`, `options`) VALUES (?,?,?,?,?,?)'; + $stmt = $db->prepare($sql); + $result = $db->executeMultiple($stmt, $save_value); + } } - if ($mode == 'delete') { - break; - } - if (empty($save_value)) { - break; - } - if ($mode == 'replace') { - $sql = 'UPDATE sccpbuttonconfig SET `name`=? WHERE `ref`= ? AND `reftype`=? AND `instance`=? AND `buttontype`=?'; -// $sql = 'INSERT INTO `sccpbuttonconfig` (`ref`, `reftype`,`instance`, `buttontype`, `name`, `options`) VALUES (?,?,?,?,?,?);'; -// die(print_r($save_value,1)); - $stmt = $db->prepare($sql); - $result= $db->executeMultiple($stmt, $save_value); - } else { - $sql = 'INSERT INTO sccpbuttonconfig (`ref`, `reftype`,`instance`, `buttontype`, `name`, `options`) VALUES (?,?,?,?,?,?)'; -// die(print_r($save_value,1)); - $stmt = $db->prepare($sql); - $result = $db->executeMultiple($stmt, $save_value); - } - - break; } return $result; } /* - * My be Replace by SccpTables ??! + * Maybe Replace by SccpTables ??! * */ public function dump_sccp_tables($data_path, $database, $user, $pass)