Destinations: List view updates.

This commit is contained in:
Nate 2019-11-06 11:29:11 -07:00
parent 6b47b8297b
commit d92b491600
2 changed files with 716 additions and 709 deletions

View File

@ -28,6 +28,7 @@
require_once "root.php";
require_once "resources/require.php";
require_once "resources/check_auth.php";
require_once "resources/paging.php";
//check permissions
if (permission_exists('destination_view')) {
@ -42,100 +43,37 @@
$language = new text;
$text = $language->get();
//get the action
if (is_array($_POST["destinations"])) {
$destinations = $_POST["destinations"];
foreach($destinations as $row) {
if ($row['action'] == 'delete') {
$action = 'delete';
break;
}
//get posted data
if (is_array($_POST['destinations'])) {
$action = $_POST['action'];
$search = $_POST['search'];
$destinations = $_POST['destinations'];
}
//toggle the destinations
if (permission_exists('destination_edit')) {
if ($action == 'toggle' && is_array($destinations) && @sizeof($destinations) != 0) {
//toggle
$obj = new destinations;
$obj->toggle($destinations);
//redirect
header('Location: destinations.php'.($search != '' ? '?search='.urlencode($search) : null));
exit;
}
}
//delete the destinations
if (permission_exists('destination_delete')) {
if ($action == "delete") {
//download
if ($action == 'delete' && is_array($destinations) && @sizeof($destinations) != 0) {
//delete
$obj = new destinations;
$obj->delete($destinations);
//delete message
message::add($text['message-delete']);
//redirect
header('Location: destinations.php'.($search != '' ? '?search='.urlencode($search) : null));
exit;
}
}
//get variables used to control the order
$order_by = $_GET["order_by"];
$order = $_GET["order"];
//set the type
switch ($_GET['type']) {
case 'inbound': $destination_type = 'inbound'; break;
case 'outbound': $destination_type = 'outbound'; break;
case 'local': $destination_type = 'local'; break;
default: $destination_type = 'inbound';
}
//add the search term
$search = strtolower($_GET["search"]);
if (strlen($search) > 0) {
$sql_search = " (";
$sql_search .= "lower(destination_type) like :search ";
$sql_search .= "or lower(destination_number) like :search ";
$sql_search .= "or lower(destination_context) like :search ";
$sql_search .= "or lower(destination_accountcode) like :search ";
if (permission_exists('outbound_caller_id_select')) {
$sql_search .= "or lower(destination_caller_id_name) like :search ";
$sql_search .= "or destination_caller_id_number like :search ";
}
$sql_search .= "or lower(destination_enabled) like :search ";
$sql_search .= "or lower(destination_description) like :search ";
$sql_search .= "or lower(destination_data) like :search ";
$sql_search .= ") ";
}
//common sql where
$sql_where = "where destination_type = :destination_type ";
if ($_GET['show'] == "all" && permission_exists('destination_all')) {
//show all
}
else {
$sql_where .= "and (domain_uuid = :domain_uuid or domain_uuid is null) ";
$parameters['domain_uuid'] = $domain_uuid;
}
if (isset($sql_search)) {
$sql_where .= "and ".$sql_search;
$parameters['search'] = '%'.$search.'%';
}
$parameters['destination_type'] = $destination_type;
//prepare to page the results
$sql = "select count(destination_uuid) from v_destinations ";
$sql .= $sql_where;
$database = new database;
$num_rows = $database->select($sql, $parameters, 'column');
//prepare to page the results
require_once "resources/paging.php";
$rows_per_page = ($_SESSION['domain']['paging']['numeric'] != '') ? $_SESSION['domain']['paging']['numeric'] : 50;
$param = "&search=".escape($search);
if ($_GET['show'] == "all" && permission_exists('destination_all')) {
$param .= "&show=all";
}
$page = $_GET['page'];
if (strlen($page) == 0) { $page = 0; $_GET['page'] = 0; }
list($paging_controls_mini, $rows_per_page, $var_3) = paging($num_rows, $param, $rows_per_page, true);
list($paging_controls, $rows_per_page, $var3) = paging($num_rows, $param, $rows_per_page);
$offset = $rows_per_page * $page;
//get the list
$sql = str_replace('count(destination_uuid)', '*', $sql);
$sql .= order_by($order_by, $order);
$sql .= limit_offset($rows_per_page, $offset);
$database = new database;
$destinations = $database->select($sql, $parameters, 'all');
unset($parameters);
//get the destination select list
$destination = new destinations;
$destination_array = $destination->all('dialplan');
@ -161,81 +99,131 @@
}
}
//alternate the row style
$c = 0;
$row_style["0"] = "row_style0";
$row_style["1"] = "row_style1";
//set the type
switch ($_GET['type']) {
case 'inbound': $destination_type = 'inbound'; break;
case 'outbound': $destination_type = 'outbound'; break;
case 'local': $destination_type = 'local'; break;
default: $destination_type = 'inbound';
}
//get variables used to control the order
$order_by = $_GET["order_by"];
$order = $_GET["order"];
//add the search term
$search = strtolower($_GET["search"]);
if (strlen($search) > 0) {
$sql_search = "and (";
$sql_search .= "lower(destination_type) like :search ";
$sql_search .= "or lower(destination_number) like :search ";
$sql_search .= "or lower(destination_context) like :search ";
$sql_search .= "or lower(destination_accountcode) like :search ";
if (permission_exists('outbound_caller_id_select')) {
$sql_search .= "or lower(destination_caller_id_name) like :search ";
$sql_search .= "or destination_caller_id_number like :search ";
}
$sql_search .= "or lower(destination_enabled) like :search ";
$sql_search .= "or lower(destination_description) like :search ";
$sql_search .= "or lower(destination_data) like :search ";
$sql_search .= ") ";
$parameters['search'] = '%'.$search.'%';
}
//prepare to page the results
$sql = "select count(*) from v_destinations ";
$sql .= "where destination_type = :destination_type ";
if ($_GET['show'] != "all" || !permission_exists('destination_all')) {
$sql .= "and (domain_uuid = :domain_uuid or domain_uuid is null) ";
$parameters['domain_uuid'] = $domain_uuid;
}
$sql .= $sql_search;
$parameters['destination_type'] = $destination_type;
$database = new database;
$num_rows = $database->select($sql, $parameters, 'column');
//prepare to page the results
$rows_per_page = ($_SESSION['domain']['paging']['numeric'] != '') ? $_SESSION['domain']['paging']['numeric'] : 50;
$param = "&search=".$search;
if ($_GET['show'] == "all" && permission_exists('destination_all')) {
$param .= "&show=all";
}
$page = $_GET['page'];
if (strlen($page) == 0) { $page = 0; $_GET['page'] = 0; }
list($paging_controls, $rows_per_page) = paging($num_rows, $param, $rows_per_page);
list($paging_controls_mini, $rows_per_page) = paging($num_rows, $param, $rows_per_page, true);
$offset = $rows_per_page * $page;
//get the list
$sql = str_replace('count(*)', '*', $sql);
$sql .= order_by($order_by, $order, 'destination_number', 'asc');
$sql .= limit_offset($rows_per_page, $offset);
$database = new database;
$destinations = $database->select($sql, $parameters, 'all');
unset($sql, $parameters);
//create token
$object = new token;
$token = $object->create($_SERVER['PHP_SELF']);
//include the header
require_once "resources/header.php";
//define the checkbox_toggle function
echo "<script type=\"text/javascript\">\n";
echo " function checkbox_toggle(item) {\n";
echo " var inputs = document.getElementsByTagName(\"input\");\n";
echo " for (var i = 0, max = inputs.length; i < max; i++) {\n";
echo " if (inputs[i].type === 'checkbox') {\n";
echo " if (document.getElementById('checkbox_all').checked == true) {\n";
echo " inputs[i].checked = true;\n";
echo " }\n";
echo " else {\n";
echo " inputs[i].checked = false;\n";
echo " }\n";
echo " }\n";
echo " }\n";
echo " }\n";
echo "</script>\n";
//show the content
echo "<table width='100%' border='0'>\n";
echo " <tr>\n";
echo " <td width='50%' align='left' nowrap='nowrap'><b>".$text['title-destinations']." (".$num_rows.")</b></td>\n";
echo " <form method='get' action=''>\n";
echo " <td width='50%' style='vertical-align: top; text-align: right; white-space: nowrap;'>\n";
echo " <input type='button' class='btn' value='".$text['button-inbound']."' onclick=\"window.location='destinations.php?type=inbound".($_GET['show'] == 'all' ? '&show=all' : null).($search != '' ? "&search=".urlencode($search) : null)."';\">\n";
echo " <input type='button' class='btn' value='".$text['button-outbound']."' onclick=\"window.location='destinations.php?type=outbound".($_GET['show'] == 'all' ? '&show=all' : null).($search != '' ? "&search=".urlencode($search) : null)."';\">\n";
echo " <input type='button' class='btn' value='".$text['button-local']."' onclick=\"window.location='destinations.php?type=local".($_GET['show'] == 'all' ? '&show=all' : null).($search != '' ? "&search=".urlencode($search) : null)."';\">\n";
echo " &nbsp;\n";
if (permission_exists('destination_import')) {
echo " <input type='button' class='btn' alt='".$text['button-import']."' onclick=\"window.location='destination_imports.php'\" value='".$text['button-import']."'>\n";
echo "<div class='action_bar' id='action_bar'>\n";
echo " <div class='heading'><b>".$text['title-destinations']." (".$num_rows.")</b></div>\n";
echo " <div class='actions'>\n";
if (permission_exists('destination_add')) {
echo button::create(['type'=>'button','label'=>$text['button-add'],'icon'=>$_SESSION['theme']['button_icon_add'],'link'=>'destination_edit.php']);
}
if (permission_exists('destination_delete') && $destinations) {
echo button::create(['type'=>'button','label'=>$text['button-delete'],'icon'=>$_SESSION['theme']['button_icon_delete'],'onclick'=>"if (confirm('".$text['confirm-delete']."')) { list_action_set('delete'); list_form_submit('form_list'); } else { this.blur(); return false; }"]);
}
echo "<form id='form_search' class='inline' method='get'>\n";
if (permission_exists('destination_all')) {
if ($_GET['show'] == 'all') {
echo " <input type='hidden' name='show' value='all'>";
}
else {
echo " <input type='button' class='btn' value='".$text['button-show_all']."' onclick=\"window.location='destinations.php?type=".urlencode($destination_type)."&show=all".($search != '' ? "&search=".urlencode($search) : null)."';\">\n";
echo button::create(['type'=>'button','label'=>$text['button-show_all'],'icon'=>$_SESSION['theme']['button_icon_all'],'link'=>'?type='.urlencode($destination_type).'&show=all'.($search != '' ? "&search=".urlencode($search) : null)]);
}
}
echo " <input type='text' class='txt' style='width: 150px; margin-left: 15px;' name='search' id='search' value='".escape($search)."'>\n";
echo " <input type='submit' class='btn' value='".$text['button-search']."'>\n";
echo "<input type='text' class='txt list-search' name='search' id='search' value=\"".escape($search)."\" placeholder=\"".$text['label-search']."\" onkeydown='list_search_reset();'>";
echo button::create(['label'=>$text['button-search'],'icon'=>$_SESSION['theme']['button_icon_search'],'type'=>'submit','id'=>'btn_search','style'=>($search != '' ? 'display: none;' : null)]);
echo button::create(['label'=>$text['button-reset'],'icon'=>$_SESSION['theme']['button_icon_reset'],'type'=>'button','id'=>'btn_reset','link'=>'destinations.php','style'=>($search == '' ? 'display: none;' : null)]);
if ($paging_controls_mini != '') {
echo " <span style='margin-left: 15px;'>".$paging_controls_mini."</span>\n";
echo "<span style='margin-left: 15px;'>".$paging_controls_mini."</span>";
}
echo button::create(['type'=>'button','label'=>$text['button-inbound'],'icon'=>'location-arrow fa-rotate-90', 'style'=>'margin-left: 15px;','link'=>'?type=inbound'.($_GET['show'] == 'all' ? '&show=all' : null).($search != '' ? "&search=".urlencode($search) : null)]);
echo button::create(['type'=>'button','label'=>$text['button-outbound'],'icon'=>'location-arrow','link'=>'?type=outbound'.($_GET['show'] == 'all' ? '&show=all' : null).($search != '' ? "&search=".urlencode($search) : null)]);
echo button::create(['type'=>'button','label'=>$text['button-local'],'icon'=>'vector-square','link'=>'?type=local'.($_GET['show'] == 'all' ? '&show=all' : null).($search != '' ? "&search=".urlencode($search) : null)]);
if (permission_exists('destination_import')) {
echo button::create(['type'=>'button','label'=>$text['button-import'],'icon'=>'file-import','link'=>'destination_imports.php']);
}
echo " </td>\n";
echo " </form>\n";
echo " </tr>\n";
echo " <tr>\n";
echo " <td align='left' colspan='2' valign='top'>\n";
echo " ".$text['description-destinations']."<br /><br />\n";
echo " </td>\n";
echo " </tr>\n";
echo "</table>\n";
echo " </div>\n";
echo " <div style='clear: both;'></div>\n";
echo "</div>\n";
echo "<form method='post' action=''>\n";
echo "<table class='tr_hover' width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
echo "<tr>\n";
echo " <th style='width:30px;'>\n";
echo " <input type='checkbox' name='checkbox_all' id='checkbox_all' value='' onclick=\"checkbox_toggle();\">\n";
echo " </th>\n";
if ($_GET['show'] == "all" && permission_exists('destination_all')) {
echo th_order_by('domain_name', $text['label-domain'], $order_by, $order, $param);
echo $text['description-destinations']."\n";
echo "<br /><br />\n";
echo "<form id='form_list' method='post'>\n";
echo "<input type='hidden' id='action' name='action' value=''>\n";
echo "<input type='hidden' name='search' value=\"".escape($search)."\">\n";
echo "<table class='list'>\n";
echo "<tr class='list-header'>\n";
if (permission_exists('destination_delete')) {
echo " <th class='checkbox'>\n";
echo " <input type='checkbox' id='checkbox_all' name='checkbox_all' onclick='list_all_toggle();' ".($destinations ?: "style='visibility: hidden;'").">\n";
echo " </th>\n";
}
echo th_order_by('destination_type', $text['label-destination_type'], $order_by, $order, $param);
echo th_order_by('destination_number', $text['label-destination_number'], $order_by, $order, $param);
if ($_GET['show'] == "all" && permission_exists('destination_all')) {
echo th_order_by('domain_name', $text['label-domain'], $order_by, $order, $param, "class='shrink'");
}
echo th_order_by('destination_type', $text['label-destination_type'], $order_by, $order, $param, "class='shrink'");
echo th_order_by('destination_number', $text['label-destination_number'], $order_by, $order, $param, "class='shrink'");
if (!$_GET['show'] == "all") {
echo "<th>". $text['label-detail_action']."</th>";
}
@ -247,30 +235,25 @@
echo th_order_by('destination_caller_id_number', $text['label-destination_caller_id_number'], $order_by, $order, $param);
}
echo th_order_by('destination_enabled', $text['label-destination_enabled'], $order_by, $order, $param);
echo th_order_by('destination_description', $text['label-destination_description'], $order_by, $order, $param);
echo " <td class='list_control_icons'>";
if (permission_exists('destination_add')) {
echo " <a href='destination_edit.php?type=$destination_type' alt='".$text['button-add']."'>$v_link_label_add</a>";
echo th_order_by('destination_description', $text['label-destination_description'], $order_by, $order, $param, "class='hide-sm-dn'");
if (permission_exists('destination_edit') && $_SESSION['theme']['list_row_edit_button']['boolean'] == 'true') {
echo " <td class='action-button'>&nbsp;</td>\n";
}
else {
echo "&nbsp;\n";
}
echo " </td>\n";
echo "<tr>\n";
echo "</tr>\n";
if (is_array($destinations) && @sizeof($destinations) != 0) {
$x = 0;
foreach($destinations as $row) {
$action_name = action_name($destination_array, $row['destination_app'].':'.$row['destination_data']);
if (permission_exists('destination_edit')) {
$tr_link = "href='destination_edit.php?id=".$row['destination_uuid']."'";
$list_row_url = "destination_edit.php?id=".urlencode($row['destination_uuid']);
}
echo "<tr class='list-row' href='".$list_row_url."'>\n";
if (permission_exists('destination_delete')) {
echo " <td class='checkbox'>\n";
echo " <input type='checkbox' name='destinations[$x][checked]' id='checkbox_".$x."' value='true' onclick=\"if (!this.checked) { document.getElementById('checkbox_all').checked = false; }\">\n";
echo " <input type='hidden' name='destinations[$x][uuid]' value='".escape($row['destination_uuid'])."' />\n";
echo " </td>\n";
}
echo "<tr ".$tr_link.">\n";
//echo " <td valign='top' class=''>".$row['destination_uuid']."&nbsp;</td>\n";
//echo " <td valign='top' class=''>".$row['dialplan_uuid']."&nbsp;</td>\n";
echo " <td valign='top' class='".$row_style[$c]." tr_link_void' style='align: center; padding: 3px 3px 0px 8px;'>\n";
echo " <input type='checkbox' name=\"destinations[$x][checked]\" id='checkbox_".$x."' value='true' onclick=\"if (!this.checked) { document.getElementById('chk_all_".$x."').checked = false; }\">\n";
echo " <input type='hidden' name=\"destinations[$x][destination_uuid]\" value='".escape($row['destination_uuid'])."' />\n";
echo " </td>\n";
if ($_GET['show'] == "all" && permission_exists('destination_all')) {
if (strlen($_SESSION['domains'][$row['domain_uuid']]['domain_name']) > 0) {
$domain = $_SESSION['domains'][$row['domain_uuid']]['domain_name'];
@ -278,67 +261,49 @@
else {
$domain = $text['label-global'];
}
echo " <td valign='top' class='".$row_style[$c]."'>".escape($domain)."</td>\n";
echo " <td>".escape($domain)."</td>\n";
}
echo " <td valign='top' class='".$row_style[$c]."'>".escape($row['destination_type'])."&nbsp;</td>\n";
echo " <td valign='top' class='".$row_style[$c]."'>".escape(format_phone($row['destination_number']))."&nbsp;</td>\n";
if (!$_GET['show'] == "all") {
echo " <td valign='top' class='".$row_style[$c]."'>".$action_name."&nbsp;</td>\n";
}
//echo " <td valign='top' class='".$row_style[$c]."'>".$row['destination_number_regex']."&nbsp;</td>\n";
if (permission_exists("destination_context")) {
echo " <td valign='top' class='".$row_style[$c]."'>".escape($row['destination_context'])."&nbsp;</td>\n";
}
//echo " <td valign='top' class='".$row_style[$c]."'>".escape($row['fax_uuid'])."&nbsp;</td>\n";
if (permission_exists('outbound_caller_id_select')) {
echo " <td valign='top' class='".$row_style[$c]."'>".escape($row['destination_caller_id_name'])."&nbsp;</td>\n";
echo " <td valign='top' class='".$row_style[$c]."'>".escape($row['destination_caller_id_number'])."&nbsp;</td>\n";
}
//echo " <td valign='top' class='".$row_style[$c]."'>".escape($row['destination_cid_name_prefix'])."&nbsp;</td>\n";
//echo " <td valign='top' class='".$row_style[$c]."'>".escape($row['destination_app'])."&nbsp;</td>\n";
//echo " <td valign='top' class='".$row_style[$c]."'>".escape($row['destination_data'])."&nbsp;</td>\n";
//echo " <td valign='top' class='".$row_style[$c]."'>".escape($row['destination_record'])."&nbsp;</td>\n";
//echo " <td valign='top' class='".$row_style[$c]."'>".escape($row['destination_accountcode'])."&nbsp;</td>\n";
echo " <td valign='top' class='".$row_style[$c]."'>".escape($row['destination_enabled'])."&nbsp;</td>\n";
echo " <td valign='top' class='row_stylebg'>".escape($row['destination_description'])."&nbsp;</td>\n";
echo " <td class='list_control_icons'>";
echo " <td>".escape($row['destination_type'])."&nbsp;</td>\n";
echo " <td>";
if (permission_exists('destination_edit')) {
echo "<a href='destination_edit.php?id=".escape($row['destination_uuid'])."' alt='".$text['button-edit']."'>$v_link_label_edit</a>";
echo "<a href='".$list_row_url."'>".escape(format_phone($row['destination_number']))."</a>";
}
if (permission_exists('destination_delete')) {
echo "<button type='submit' class='btn btn-default list_control_icon' name=\"destinations[$x][action]\" alt='".$text['button-delete']."' value='delete'><span class='fas fa-minus'></span></button>";
else {
echo escape(format_phone($row['destination_number']));
}
echo " </td>\n";
if (!$_GET['show'] == "all") {
echo " <td class='overflow' style='min-width: 125px;'>".action_name($destination_array, $row['destination_app'].':'.$row['destination_data'])."&nbsp;</td>\n";
}
if (permission_exists("destination_context")) {
echo " <td>".escape($row['destination_context'])."&nbsp;</td>\n";
}
if (permission_exists('outbound_caller_id_select')) {
echo " <td>".escape($row['destination_caller_id_name'])."&nbsp;</td>\n";
echo " <td>".escape($row['destination_caller_id_number'])."&nbsp;</td>\n";
}
echo " <td>".escape($text['label-'.$row['destination_enabled']])."&nbsp;</td>\n";
echo " <td class='description overflow hide-sm-dn'>".escape($row['destination_description'])."&nbsp;</td>\n";
if (permission_exists('destination_edit') && $_SESSION['theme']['list_row_edit_button']['boolean'] == 'true') {
echo " <td class='action-button'>";
echo button::create(['type'=>'button','title'=>$text['button-edit'],'icon'=>$_SESSION['theme']['button_icon_edit'],'link'=>$list_row_url]);
echo " </td>\n";
}
echo "</tr>\n";
$x++;
if ($c==0) { $c=1; } else { $c=0; }
} //end foreach
unset($sql, $destinations, $row_count);
} //end if results
}
unset($destinations);
}
echo "</table>\n";
echo "<br />\n";
echo "<div align='center'>".$paging_controls."</div>\n";
echo "<input type='hidden' name='".$token['name']."' value='".$token['hash']."'>\n";
echo "<tr>\n";
echo "<td colspan='10' align='left'>\n";
echo " <table width='100%' cellpadding='0' cellspacing='0'>\n";
echo " <tr>\n";
echo " <td width='33.3%' nowrap='nowrap'>&nbsp;</td>\n";
echo " <td width='33.3%' align='center' nowrap='nowrap'>$paging_controls</td>\n";
echo " <td class='list_control_icons'>";
if (permission_exists('destination_add')) {
echo "<a href='destination_edit.php?type=".escape($destination_type)."' alt='".$text['button-add']."'>$v_link_label_add</a>";
}
else {
echo "&nbsp;";
}
echo " </td>\n";
echo " </tr>\n";
echo " </table>\n";
echo "</td>\n";
echo "</tr>\n";
echo "</table>";
echo "</form>\n";
echo "<br /><br />";
//include the footer
require_once "resources/footer.php";
?>
?>

File diff suppressed because it is too large Load Diff