diff --git a/app/destinations/destinations.php b/app/destinations/destinations.php index 104a9606c2..90d4ac9545 100644 --- a/app/destinations/destinations.php +++ b/app/destinations/destinations.php @@ -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 "\n"; - //show the content - echo "
| ".$text['title-destinations']." (".$num_rows.") | \n"; - echo " \n"; - echo "|
| \n";
- echo " ".$text['description-destinations']." \n"; - echo " | \n";
- echo " |
| \n"; - echo " \n"; - echo " | \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 "|||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| \n"; + echo " \n"; + echo " | \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 "". $text['label-detail_action']." | "; } @@ -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 ""; - if (permission_exists('destination_add')) { - echo " $v_link_label_add"; + 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 " | \n"; } - else { - echo " \n"; - } - echo " \n"; - echo " | |||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| \n"; + echo " \n"; + echo " \n"; + echo " | \n"; } - echo "||||||||||||||||||||||||||||
| ".$row['destination_uuid']." | \n"; - //echo "".$row['dialplan_uuid']." | \n"; - echo "\n"; - echo " \n"; - echo " \n"; - echo " | \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 "".escape($domain)." | \n"; + echo "".escape($domain)." | \n"; } - echo "".escape($row['destination_type'])." | \n"; - echo "".escape(format_phone($row['destination_number']))." | \n"; - if (!$_GET['show'] == "all") { - echo "".$action_name." | \n"; - } - //echo "".$row['destination_number_regex']." | \n"; - if (permission_exists("destination_context")) { - echo "".escape($row['destination_context'])." | \n"; - } - //echo "".escape($row['fax_uuid'])." | \n"; - if (permission_exists('outbound_caller_id_select')) { - echo "".escape($row['destination_caller_id_name'])." | \n"; - echo "".escape($row['destination_caller_id_number'])." | \n"; - } - //echo "".escape($row['destination_cid_name_prefix'])." | \n"; - //echo "".escape($row['destination_app'])." | \n"; - //echo "".escape($row['destination_data'])." | \n"; - //echo "".escape($row['destination_record'])." | \n"; - //echo "".escape($row['destination_accountcode'])." | \n"; - echo "".escape($row['destination_enabled'])." | \n"; - echo "".escape($row['destination_description'])." | \n"; - echo ""; + echo " | ".escape($row['destination_type'])." | \n"; + echo ""; if (permission_exists('destination_edit')) { - echo "$v_link_label_edit"; + echo "".escape(format_phone($row['destination_number'])).""; } - if (permission_exists('destination_delete')) { - echo ""; + else { + echo escape(format_phone($row['destination_number'])); } echo " | \n"; + if (!$_GET['show'] == "all") { + echo "".action_name($destination_array, $row['destination_app'].':'.$row['destination_data'])." | \n"; + } + if (permission_exists("destination_context")) { + echo "".escape($row['destination_context'])." | \n"; + } + if (permission_exists('outbound_caller_id_select')) { + echo "".escape($row['destination_caller_id_name'])." | \n"; + echo "".escape($row['destination_caller_id_number'])." | \n"; + } + echo "".escape($text['label-'.$row['destination_enabled']])." | \n"; + echo " \n"; + if (permission_exists('destination_edit') && $_SESSION['theme']['list_row_edit_button']['boolean'] == 'true') { + echo ""; + echo button::create(['type'=>'button','title'=>$text['button-edit'],'icon'=>$_SESSION['theme']['button_icon_edit'],'link'=>$list_row_url]); + echo " | \n"; + } echo "
| \n"; - echo " | $paging_controls | \n"; - echo ""; - if (permission_exists('destination_add')) { - echo "$v_link_label_add"; - } - else { - echo " "; - } - echo " | \n"; - echo "