Simplify db queries and change alignment

This commit is contained in:
steve-lad 2021-07-21 08:57:43 +02:00
parent 97c1395eb1
commit a4aa4eb03b
3 changed files with 19 additions and 8 deletions

View file

@ -55,7 +55,7 @@ class dbinterface
return false; return false;
} }
switch ($dataid) { switch ($dataid) {
case 'sccp': case 'extGrid':
// only called by getExtensionGrid from hardware.extension.php view // only called by getExtensionGrid from hardware.extension.php view
$stmts = $this->db->prepare('SELECT sccpline.name, sccpline.label, sccpbuttonconfig.ref as mac $stmts = $this->db->prepare('SELECT sccpline.name, sccpline.label, sccpbuttonconfig.ref as mac
FROM sccpline INNER JOIN sccpbuttonconfig ON sccpline.name=sccpbuttonconfig.name'); FROM sccpline INNER JOIN sccpbuttonconfig ON sccpline.name=sccpbuttonconfig.name');
@ -68,6 +68,18 @@ class dbinterface
$stmts->bindParam(':name', $data['name'],\PDO::PARAM_STR); $stmts->bindParam(':name', $data['name'],\PDO::PARAM_STR);
} }
break; break;
case 'phoneGrid':
$fld = 'name, name as mac, type, button, addon, _description as description';
switch ($data['type']) {
case "cisco-sip":
$stmts = $this->db->prepare("SELECT {$fld} FROM sccpdeviceconfig WHERE type LIKE '%-sip' ORDER BY name");
break;
case "sccp": // Fall through to default intentionally
default:
$stmts = $this->db->prepare("SELECT {$fld} FROM sccpdeviceconfig WHERE type not LIKE '%-sip' ORDER BY name");
break;
}
break;
case 'SccpDevice': case 'SccpDevice':
if (empty($data['fields'])) { if (empty($data['fields'])) {
$fld = 'name, name as mac, type, button, addon, _description as description'; $fld = 'name, name as mac, type, button, addon, _description as description';

View file

@ -315,19 +315,18 @@ trait ajaxHelper {
break; break;
case 'getPhoneGrid': case 'getPhoneGrid':
$dbDevices = array(); $dbDevices = array();
$cmd_type = !empty($request['type']) ? $request['type'] : '';
// Find all devices defined in the database // Find all devices defined in the database.
$dbDevices = $this->dbinterface->getSccpDeviceTableData('SccpDevice', array('type' => $cmd_type)); $dbDevices = $this->dbinterface->getSccpDeviceTableData('phoneGrid', array('type' => $request['type']));
// Return if only interested in SIP devices // Return if only interested in SIP devices
if ($cmd_type == 'cisco-sip') { if ($request['type'] == 'cisco-sip') {
return $dbDevices; //this may be empty return $dbDevices; //this may be empty
} }
// Find all devices currently connected // Find all devices currently connected
$activeDevices = $this->aminterface->sccp_get_active_device(); $activeDevices = $this->aminterface->sccp_get_active_device();
foreach ($dbDevices as &$dev_id) { foreach ($dbDevices as &$dev_id) {
$id_name = $dev_id['name']; $id_name = $dev_id['mac'];
if (!empty($activeDevices[$id_name])) { if (!empty($activeDevices[$id_name])) {
// Device is in db and is connected // Device is in db and is connected
$dev_id['description'] = $activeDevices[$id_name]['descr']; $dev_id['description'] = $activeDevices[$id_name]['descr'];

View file

@ -20,13 +20,13 @@ if (!empty($this->sccpvalues['system_rouminguser'])) {
<div id="toolbar-sccp-extension"> <div id="toolbar-sccp-extension">
<a class="btn btn-default" href="config.php?display=extensions&tech_hardware=sccp_custom"><i class="fa fa-plus">&nbsp;</i><?php echo _("Add Extension") ?></a> <a class="btn btn-default" href="config.php?display=extensions&tech_hardware=sccp_custom"><i class="fa fa-plus">&nbsp;</i><?php echo _("Add Extension") ?></a>
</div> </div>
<table data-cookie="true" data-cookie-id-table="sccp-extension-table" data-url="ajax.php?module=sccp_manager&command=getExtensionGrid&type=sccp" data-cache="false" data-show-refresh="true" data-toolbar="#toolbar-sip" data-maintain-selected="true" data-show-columns="true" data-show-toggle="true" data-toggle="table" data-pagination="true" data-search="true" class="table table-striped ext-list-sccp" id="table-sccp-extension" data-id="name"> <table data-cookie="true" data-cookie-id-table="sccp-extension-table" data-url="ajax.php?module=sccp_manager&command=getExtensionGrid&type=extGrid" data-cache="false" data-show-refresh="true" data-toolbar="#toolbar-sip" data-maintain-selected="true" data-show-columns="true" data-show-toggle="true" data-toggle="table" data-pagination="true" data-search="true" class="table table-striped ext-list-sccp" id="table-sccp-extension" data-id="name">
<thead> <thead>
<tr> <tr>
<!-- <th data-checkbox="true"></th> --> <!-- <th data-checkbox="true"></th> -->
<th data-sortable="true" data-field="name"><?php echo _('Extension') ?></th> <th data-sortable="true" data-field="name"><?php echo _('Extension') ?></th>
<th data-sortable="true" data-field="label"><?php echo _('Display Name') ?></th> <th data-sortable="true" data-field="label"><?php echo _('Display Name') ?></th>
<th data-sortable="true" data-field="line_status"><?php echo _('Status | Active') ?></th> <th data-sortable="true" data-field="line_status" class="text-center"><?php echo _('Status | Active') ?></th>
<th data-field="actions" data-formatter="DispayPhoneActionsKeyFormatter"><?php echo _('Actions') ?></th> <th data-field="actions" data-formatter="DispayPhoneActionsKeyFormatter"><?php echo _('Actions') ?></th>
</tr> </tr>
</thead> </thead>