Update destinations.php

- Update the array to add actions before display.
- Use column names in the SQL select
- Use a SQL Left Join to get the domain name
This commit is contained in:
FusionPBX
2024-04-29 12:46:32 -06:00
committed by GitHub
parent 6f6d84e1cc
commit 6176ea2376

View File

@@ -189,8 +189,27 @@
$offset = $rows_per_page * $page;
//get the list
$sql = "select * from v_destinations ";
$sql = "select ";
$sql .= " d.destination_uuid, ";
$sql .= " d.domain_uuid, ";
if ($show == "all" && permission_exists('destination_all')) {
$sql .= " domain_name, ";
}
$sql .= " d.destination_type, ";
$sql .= " d.destination_prefix, ";
$sql .= " d.destination_trunk_prefix, ";
$sql .= " d.destination_area_code, ";
$sql .= " d.destination_number, ";
$sql .= " d.destination_actions, ";
$sql .= " d.destination_context, ";
$sql .= " d.destination_caller_id_name, ";
$sql .= " d.destination_caller_id_number, ";
$sql .= " d.destination_enabled, ";
$sql .= " d.destination_description ";
$sql .= "from v_destinations as d ";
if ($show == "all" && permission_exists('destination_all')) {
$sql .= "LEFT JOIN v_domains as dom ";
$sql .= "ON d.domain_uuid = dom.domain_uuid ";
$sql .= "where destination_type = :destination_type ";
}
else {
@@ -200,17 +219,17 @@
}
if (!empty($search)) {
$sql .= "and (";
$sql .= "lower(destination_type) like :search ";
$sql .= "or lower(destination_number) like :search ";
$sql .= "or lower(destination_context) like :search ";
$sql .= "or lower(destination_accountcode) like :search ";
$sql .= " lower(destination_type) like :search ";
$sql .= " or lower(destination_number) like :search ";
$sql .= " or lower(destination_context) like :search ";
$sql .= " or lower(destination_accountcode) like :search ";
if (permission_exists('outbound_caller_id_select')) {
$sql .= "or lower(destination_caller_id_name) like :search ";
$sql .= "or destination_caller_id_number like :search ";
$sql .= " or lower(destination_caller_id_name) like :search ";
$sql .= " or destination_caller_id_number like :search ";
}
$sql .= "or lower(destination_enabled) like :search ";
$sql .= "or lower(destination_description) like :search ";
$sql .= "or lower(destination_data) like :search ";
$sql .= " or lower(destination_enabled) like :search ";
$sql .= " or lower(destination_description) like :search ";
$sql .= " or lower(destination_data) like :search ";
$sql .= ") ";
$parameters['search'] = '%'.$search.'%';
}
@@ -220,6 +239,30 @@
$destinations = $database->select($sql, $parameters, 'all');
unset($sql, $parameters);
//update the array to add the actions
if (!$show == "all") {
foreach ($destinations as &$row) {
if (!empty($row['destination_actions'])) {
//prepare the destination actions
if (!empty(json_decode($row['destination_actions'], true))) {
foreach (json_decode($row['destination_actions'], true) as $action) {
$destination_app_data[] = $action['destination_app'].':'.$action['destination_data'];
}
}
//add the actions to the array
$actions = action_name($destination_array, $destination_app_data);
$row['actions'] = (!empty($actions)) ? implode(', ', $actions) : '';
//empty the array before the next iteration
unset($destination_app_data);
}
else {
$row['actions'] = '';
}
}
}
//create token
$object = new token;
$token = $object->create($_SERVER['PHP_SELF']);
@@ -320,16 +363,6 @@
$x = 0;
foreach ($destinations as $row) {
//prepare the destination actions
if (!empty($row['destination_actions'])) {
$destination_actions = json_decode($row['destination_actions'], true);
if (!empty($destination_actions)) {
foreach ($destination_actions as $action) {
$destination_app_data[] = $action['destination_app'].':'.$action['destination_data'];
}
}
}
//create the row link
if (permission_exists('destination_edit')) {
$list_row_url = "destination_edit.php?id=".urlencode($row['destination_uuid']);
@@ -344,8 +377,8 @@
echo " </td>\n";
}
if ($show == "all" && permission_exists('destination_all')) {
if (!empty($_SESSION['domains'][$row['domain_uuid']]['domain_name'])) {
$domain = $_SESSION['domains'][$row['domain_uuid']]['domain_name'];
if (!empty($row['domain_name'])) {
$domain = $row['domain_name'];
}
else {
$domain = $text['label-global'];
@@ -372,8 +405,7 @@
echo " </td>\n";
if (!$show == "all") {
$actions = action_name($destination_array, $destination_app_data);
echo " <td class='overflow' style='min-width: 125px;'>".(!empty($actions) ? implode(', ', $actions) : null)."&nbsp;</td>\n";
echo " <td class='overflow' style='min-width: 125px;'>".$row['actions']."&nbsp;</td>\n";
}
if (permission_exists("destination_context")) {
echo " <td>".escape($row['destination_context'])."&nbsp;</td>\n";
@@ -411,4 +443,4 @@
//include the footer
require_once "resources/footer.php";
?>
?>