diff --git a/app/dialplans/dialplans.php b/app/dialplans/dialplans.php index f519a6b51b..c998f6b2e6 100644 --- a/app/dialplans/dialplans.php +++ b/app/dialplans/dialplans.php @@ -17,7 +17,7 @@ The Initial Developer of the Original Code is Mark J Crane - Portions created by the Initial Developer are Copyright (C) 2008-2019 + Portions created by the Initial Developer are Copyright (C) 2008-2023 the Initial Developer. All Rights Reserved. Contributor(s): @@ -50,6 +50,7 @@ if (is_array($_POST['dialplans'])) { $action = $_POST['action']; $dialplans = $_POST['dialplans']; + $context = $_POST['context']; $search = $_POST['search']; $order_by = $_POST['order_by']; $order = $_POST['order']; @@ -65,6 +66,7 @@ //define redirect parameters and url if (is_uuid($app_uuid)) { $params[] = "app_uuid=".urlencode($app_uuid); } + if ($context) { $params[] = "context=".urlencode($context); } if ($search) { $params[] = "search=".urlencode($search); } if ($order_by) { $params[] = "order_by=".urlencode($order_by); } if ($order) { $params[] = "order=".urlencode($order); } @@ -119,7 +121,10 @@ unset($sql); } -//add the search term +//add the search form elements + if (isset($_GET["context"])) { + $context = strtolower($_GET["context"]); + } if (isset($_GET["search"])) { $search = strtolower($_GET["search"]); } @@ -149,7 +154,11 @@ } $parameters['app_uuid'] = $app_uuid; } - if (isset($search)) { + if ($context) { + $sql .= "and dialplan_context = :dialplan_context "; + $parameters['dialplan_context'] = $context; + } + if ($search) { $sql .= "and ("; $sql .= " lower(dialplan_context) like :search "; $sql .= " or lower(dialplan_name) like :search "; @@ -169,12 +178,13 @@ //prepare the paging $rows_per_page = ($_SESSION['domain']['paging']['numeric'] != '') ? $_SESSION['domain']['paging']['numeric'] : 50; - $params[] = "app_uuid=".$app_uuid; - if ($search) { $params[] = "search=".$search; } - if ($order_by) { $params[] = "order_by=".$order_by; } - if ($order) { $params[] = "order=".$order; } + $params[] = "app_uuid=".urlencode($app_uuid); + if ($context) { $params[] = "context=".urlencode($context); } + if ($search) { $params[] = "search=".urlencode($search); } + if ($order_by) { $params[] = "order_by=".urlencode($order_by); } + if ($order) { $params[] = "order=".urlencode($order); } if ($_GET['show'] == "all" && permission_exists('dialplan_all')) { - $params[] .= "show=all"; + $params[] = "show=all"; } $param = $params ? implode('&', $params) : null; unset($params); @@ -209,7 +219,11 @@ } $parameters['app_uuid'] = $app_uuid; } - if (isset($search)) { + if ($context) { + $sql .= "and dialplan_context = :dialplan_context "; + $parameters['dialplan_context'] = $context; + } + if ($search) { $sql .= "and ("; $sql .= " lower(dialplan_context) like :search "; $sql .= " or lower(dialplan_name) like :search "; @@ -240,6 +254,63 @@ $dialplans = $database->select($sql, $parameters, 'all'); unset($sql, $parameters); +//get the list of all dialplan contexts + $sql = "select dc.* from ( "; + $sql .= "select distinct dialplan_context from v_dialplans "; + if ($_GET['show'] == "all" && permission_exists('dialplan_all')) { + $sql .= "where true "; + } + else { + $sql .= "where (domain_uuid = :domain_uuid or domain_uuid is null) "; + $parameters['domain_uuid'] = $domain_uuid; + } + if (!is_uuid($app_uuid)) { + //hide inbound routes + $sql .= "and app_uuid <> 'c03b422e-13a8-bd1b-e42b-b6b9b4d27ce4' "; + $sql .= "and dialplan_context <> 'public' "; + } + else { + $sql .= "and (app_uuid = :app_uuid ".($app_uuid == 'c03b422e-13a8-bd1b-e42b-b6b9b4d27ce4' ? "or dialplan_context = 'public'" : null).") "; + $parameters['app_uuid'] = $app_uuid; + } + $sql .= ") as dc "; + $database = new database; + $rows = $database->select($sql, $parameters, 'all'); + if (is_array($rows) && @sizeof($rows) != 0) { + foreach ($rows as $row) { + //reverse the array's (string) values in preparation to sort + $dialplan_contexts[] = strrev($row['dialplan_context']); + } + //sort the reversed context values, now grouping them by the domain + sort($dialplan_contexts, SORT_NATURAL); + //create new array + foreach ($dialplan_contexts as $dialplan_context) { + //if no subcontext (doesn't contain '@'), create new key in array with a null value + if (!substr_count($dialplan_context, '@') || strrev($dialplan_context) == 'global' || strrev($dialplan_context) == 'public') { + $array[strrev($dialplan_context)] = null; + } + //subcontext (contains '@'), create new key in array, and place subcontext in subarray + else { + $dialplan_context_parts = explode('@', $dialplan_context); + $array[strrev($dialplan_context_parts[0])][] = strrev($dialplan_context_parts[1]); + } + } + // sort array by key (domain) + ksort($array, SORT_NATURAL); + // move global and public to beginning of array + if (array_key_exists('global', $array)) { + unset($array['global']); + $array = array_merge(['global'=>null], $array); + } + if (array_key_exists('public', $array)) { + unset($array['public']); + $array = array_merge(['public'=>null], $array); + } + $dialplan_contexts = $array; + unset($dialplan_context, $array, $dialplan_context_parts); + } + unset($sql, $parameters, $rows, $row); + //create token $object = new token; $token = $object->create($_SERVER['PHP_SELF']); @@ -311,6 +382,7 @@ } else { if (is_uuid($app_uuid)) { $params[] = "app_uuid=".urlencode($app_uuid); } + if ($context) { $params[] = "context=".urlencode($context); } if ($search) { $params[] = "search=".urlencode($search); } if ($order_by) { $params[] = "order_by=".urlencode($order_by); } if ($order) { $params[] = "order=".urlencode($order); } @@ -327,6 +399,26 @@ if ($order) { echo ""; } + if (permission_exists('dialplan_context')) { + echo "\n"; + } echo ""; echo button::create(['label'=>$text['button-search'],'icon'=>$_SESSION['theme']['button_icon_search'],'type'=>'submit','id'=>'btn_search']); $params[] = "app_uuid=".urlencode($app_uuid); @@ -385,6 +477,7 @@ echo "
\n"; echo "\n"; echo "\n"; + echo "\n"; echo "\n"; echo "\n"; echo "\n"; @@ -405,6 +498,7 @@ if ($_GET['show'] == "all" && permission_exists('dialplan_all')) { echo "".$text['label-domain']."\n"; } + if ($context) { $params[] = "context=".urlencode($context); } if ($search) { $params[] = "search=".urlencode($search); } if ($_GET['show'] == 'all' && permission_exists('dialplan_all')) { $params[] = "show=all"; } echo th_order_by('dialplan_name', $text['label-name'], $order_by, $order, $app_uuid, null, ($params ? implode('&', $params) : null)); @@ -526,4 +620,4 @@ //include the footer require_once "resources/footer.php"; -?> +?> \ No newline at end of file