Cleaning up

Simplify structure and fix errors
This commit is contained in:
steve-lad 2021-02-07 16:09:35 +01:00 committed by Diederik de Groot
parent 95405190cc
commit bda7518932
No known key found for this signature in database
GPG key ID: AFA728250A1BECD6

View file

@ -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')) {
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();
}
if ($mode == 'delete') {
break;
}
if (empty($save_value)) {
break;
}
if ($mode == 'replace') {
case 'replace':
if (!empty($save_value)) {
$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 {
}
break;
default:
if (!empty($save_value)) {
$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)