Skip to content

Commit

Permalink
Update destinations.php
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
markjcrane committed Apr 29, 2024
1 parent 6f6d84e commit 6176ea2
Showing 1 changed file with 57 additions and 25 deletions.
82 changes: 57 additions & 25 deletions app/destinations/destinations.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,27 @@ function action_name($destination_array, $destination_actions) {
$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 {
Expand All @@ -200,17 +219,17 @@ function action_name($destination_array, $destination_actions) {
}
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.'%';
}
Expand All @@ -220,6 +239,30 @@ function action_name($destination_array, $destination_actions) {
$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']);
Expand Down Expand Up @@ -320,16 +363,6 @@ function action_name($destination_array, $destination_actions) {
$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']);
Expand All @@ -344,8 +377,8 @@ function action_name($destination_array, $destination_actions) {
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'];
Expand All @@ -372,8 +405,7 @@ function action_name($destination_array, $destination_actions) {
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";
Expand Down Expand Up @@ -411,4 +443,4 @@ function action_name($destination_array, $destination_actions) {
//include the footer
require_once "resources/footer.php";

?>
?>

0 comments on commit 6176ea2

Please sign in to comment.