Skip to content

Commit

Permalink
FREEI-3010 Added hidding of trunks on core destinations when routedis…
Browse files Browse the repository at this point in the history
…play is off
  • Loading branch information
aahmoud authored and kguptasangoma committed Mar 15, 2021
1 parent 8e303f9 commit 1609b4a
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 13 deletions.
14 changes: 10 additions & 4 deletions Core.class.php
Expand Up @@ -700,7 +700,8 @@ public function ajaxHandler() {
return array_values($dids);
break;
case 'allTrunks':
return array_values($this->listTrunks());
$displayOnly = (isset($request['jdisplay']) && $request['jdisplay']=='onlyVisible') ? true : false;
return array_values($this->listTrunks($displayOnly));
break;
case 'routingrnav':
return array_values($this->getAllRoutes());
Expand Down Expand Up @@ -1897,9 +1898,10 @@ public function deleteTrunk($trunknum, $tech = null, $edit = false){

/**
* List All Trunks
* if$displayOnly is true, will get only the trunks with routedisplay field set to on
* @return array Array of Trunks
*/
public function listTrunks() {
public function listTrunks($displayOnly = false) {
$sql = 'SELECT * from `trunks` ORDER BY `trunkid`';
$stmt = $this->database->prepare($sql);
$ret = $stmt->execute();
Expand All @@ -1917,8 +1919,12 @@ public function listTrunks() {
break;
}
}
$trunk['dialopts'] = $this->freepbx->astman->database_get("TRUNK",$trunk['trunkid'] . "/dialopts");
$trunk_list[$trunk['trunkid']] = $trunk;
if (!$displayOnly || ($displayOnly && (!isset($trunk['routedisplay']) || $trunk['routedisplay'] == 'on'))) {
// if displayOnly is set let's return only the trunks with routedisplay set to 'off'
$trunk['dialopts'] = $this->freepbx->astman->database_get("TRUNK",$trunk['trunkid'] . "/dialopts");
$trunk_list[$trunk['trunkid']] = $trunk;
}

}
return $trunk_list;
}
Expand Down
12 changes: 7 additions & 5 deletions functions.inc.php
Expand Up @@ -893,7 +893,7 @@ function core_destinations() {
}
}

$trunklist = core_trunks_listbyid();
$trunklist = core_trunks_listbyid(true);
if (is_array($trunklist)) foreach ($trunklist as $trunk) {
switch($trunk['tech']) {
case 'enum':
Expand Down Expand Up @@ -4947,15 +4947,17 @@ function core_trunks_addSipOrIax($config,$table,$channelid,$trunknum,$disable_fl
}

//get unique trunks
function core_trunks_getDetails($trunkid='') {
function core_trunks_getDetails($trunkid='', $displayOnly = false) {
if ($trunkid != '') {
return \FreePBX::Core()->getTrunkByID($trunkid);
}
return \FreePBX::Core()->listTrunks();
return \FreePBX::Core()->listTrunks($displayOnly);
}

function core_trunks_listbyid() {
return \FreePBX::Core()->listTrunks();
// get list of trunks, if $displayOnly is true, will get only the trunks
// with routedisplay field set to on
function core_trunks_listbyid($displayOnly = false) {
return \FreePBX::Core()->listTrunks($displayOnly);
}

function core_trunks_list($assoc = false) {
Expand Down
2 changes: 1 addition & 1 deletion page.trunks.php
Expand Up @@ -340,7 +340,7 @@
}

//get existing trunk info
$tresults = core_trunks_getDetails();
$tresults = core_trunks_getDetails('', true);

$trunks = array();
foreach ($tresults as $tresult) {
Expand Down
2 changes: 1 addition & 1 deletion views/routing/form.php
Expand Up @@ -200,7 +200,7 @@
}
//trunk html
$trunks = array();
foreach (core_trunks_listbyid() as $temp) {
foreach (core_trunks_listbyid(true) as $temp) {
$trunks[$temp['trunkid']] = $temp['name'];
$trunkstate[$temp['trunkid']] = $temp['disabled'];
$trunkdisplay[$temp['trunkid']] = isset($temp['routedisplay']) ? $temp['routedisplay'] : 'on';
Expand Down
2 changes: 1 addition & 1 deletion views/trunks/bootnav.php
Expand Up @@ -14,7 +14,7 @@
<a href="?display=trunks" class="btn btn-default"><i class="fa fa-list"></i>&nbsp;<?php echo _("List Trunks")?></a>

</div>
<table data-url="ajax.php?module=core&amp;command=getJSON&amp;jdata=allTrunks" data-cache="false" data-toggle="table" data-search="true" data-toolbar="#bnavtrunk" class="table" id="table-all-side">
<table data-url="ajax.php?module=core&amp;command=getJSON&amp;jdata=allTrunks&amp;jdisplay=onlyVisible" data-cache="false" data-toggle="table" data-search="true" data-toolbar="#bnavtrunk" class="table" id="table-all-side">
<thead>
<tr>
<th data-formatter="rtrunk" data-sortable="true" data-field="name"><?php echo _('Trunks')?></th>
Expand Down
2 changes: 1 addition & 1 deletion views/trunks/sip.php
@@ -1,5 +1,5 @@
<?php
$trunk_list = \FreePBX::Core()->listTrunks();
$trunk_list = \FreePBX::Core()->listTrunks(true);
if($trunk_list){
$trunk_names = array();
$trunk_channelids = array();
Expand Down

0 comments on commit 1609b4a

Please sign in to comment.