diff --git a/app/dialplans/dialplans.php b/app/dialplans/dialplans.php index a0ad3b147e..53183a66d1 100644 --- a/app/dialplans/dialplans.php +++ b/app/dialplans/dialplans.php @@ -34,13 +34,13 @@ require_once "resources/paging.php"; //check permissions - if (permission_exists('dialplan_view') || permission_exists('inbound_route_view') || permission_exists('outbound_route_view')) { - //access granted - } - else { - echo "access denied"; - exit; - } + if (permission_exists('dialplan_view') || permission_exists('inbound_route_view') || permission_exists('outbound_route_view')) { + //access granted + } + else { + echo "access denied"; + exit; + } //add multi-lingual support $language = new text; @@ -57,15 +57,13 @@ } //get the app uuid - if (isset($_REQUEST["app_uuid"]) && is_uuid($_REQUEST["app_uuid"])) { - $app_uuid = $_REQUEST["app_uuid"]; - } + $app_uuid = (!empty($_REQUEST["app_uuid"]) && is_uuid($_REQUEST["app_uuid"])) ? $_REQUEST["app_uuid"] : ''; //process the http post data by action if (!empty($action) && is_array($dialplans) && @sizeof($dialplans) != 0) { //define redirect parameters and url - if (isset($app_uuid) && is_uuid($app_uuid)) { $params[] = "app_uuid=".urlencode($app_uuid); } + if (!empty($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); } @@ -107,15 +105,11 @@ } //get order and order by and sanatize the values - if (!empty($_GET["order_by"])) { - $order_by = $_GET["order_by"]; - } - if (!empty($_GET["order"])) { - $order = $_GET["order"]; - } + $order_by = (!empty($_GET["order_by"])) ? $_GET["order_by"] : ''; + $order = (!empty($_GET["order"])) ? $_GET["order"] : ''; //make sure all dialplans with context of public have the inbound route app_uuid - if (isset($app_uuid) && $app_uuid == 'c03b422e-13a8-bd1b-e42b-b6b9b4d27ce4') { + if (!empty($app_uuid) && $app_uuid == 'c03b422e-13a8-bd1b-e42b-b6b9b4d27ce4') { $sql = "update v_dialplans set "; $sql .= "app_uuid = 'c03b422e-13a8-bd1b-e42b-b6b9b4d27ce4' "; $sql .= "where dialplan_context = 'public' "; @@ -125,24 +119,32 @@ unset($sql); } -//add the search form elements - if (isset($_GET["context"])) { - $context = strtolower($_GET["context"]); - } - if (isset($_GET["search"])) { - $search = strtolower($_GET["search"]); - } +//set additional variables + $context = !empty($_GET["context"]) ? $_GET["context"] : ''; + $search = !empty($_GET["search"]) ? $_GET["search"] : ''; + $show = !empty($_GET["show"]) ? $_GET["show"] : ''; + +//set from session variables + $list_row_edit_button = !empty($_SESSION['theme']['list_row_edit_button']['boolean']) ? $_SESSION['theme']['list_row_edit_button']['boolean'] : 'false'; + $button_icon_add = !empty($_SESSION['theme']['button_icon_add']) ? $_SESSION['theme']['button_icon_add'] : ''; + $button_icon_copy = !empty($_SESSION['theme']['button_icon_copy']) ? $_SESSION['theme']['button_icon_copy'] : ''; + $button_icon_toggle = !empty($_SESSION['theme']['button_icon_toggle']) ? $_SESSION['theme']['button_icon_toggle'] : ''; + $button_icon_all = !empty($_SESSION['theme']['button_icon_all']) ? $_SESSION['theme']['button_icon_all'] : ''; + $button_icon_delete = !empty($_SESSION['theme']['button_icon_delete']) ? $_SESSION['theme']['button_icon_delete'] : ''; + $button_icon_search = !empty($_SESSION['theme']['button_icon_search']) ? $_SESSION['theme']['button_icon_search'] : ''; + $button_icon_edit = !empty($_SESSION['theme']['button_icon_edit']) ? $_SESSION['theme']['button_icon_edit'] : ''; + $button_icon_reset = !empty($_SESSION['theme']['button_icon_reset']) ? $_SESSION['theme']['button_icon_reset'] : ''; //get the number of rows in the dialplan $sql = "select count(*) from v_dialplans "; - if (!empty($_GET['show']) && $_GET['show'] == "all" && permission_exists('dialplan_all')) { + if ($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 (!isset($app_uuid)) { + if (empty($app_uuid)) { //hide inbound routes $sql .= "and app_uuid <> 'c03b422e-13a8-bd1b-e42b-b6b9b4d27ce4' "; $sql .= "and dialplan_context <> 'public' "; @@ -150,7 +152,7 @@ //$sql .= "and app_uuid <> '8c914ec3-9fc0-8ab5-4cda-6c9288bdc9a3' "; } else { - if (isset($app_uuid) && $app_uuid == 'c03b422e-13a8-bd1b-e42b-b6b9b4d27ce4') { + if (!empty($app_uuid) && $app_uuid == 'c03b422e-13a8-bd1b-e42b-b6b9b4d27ce4') { $sql .= "and (app_uuid = :app_uuid or dialplan_context = 'public') "; } else { @@ -158,11 +160,11 @@ } $parameters['app_uuid'] = $app_uuid; } - if (isset($context)) { + if (!empty($context)) { $sql .= "and dialplan_context = :dialplan_context "; $parameters['dialplan_context'] = $context; } - if (isset($search)) { + if (!empty($search)) { $sql .= "and ("; $sql .= " lower(dialplan_context) like :search "; $sql .= " or lower(dialplan_name) like :search "; @@ -178,16 +180,16 @@ $parameters['search'] = '%'.$search.'%'; } $database = new database; - $num_rows = $database->select($sql, $parameters, 'column'); + $num_rows = $database->select($sql, $parameters ?? null, 'column'); //prepare the paging $rows_per_page = ($_SESSION['domain']['paging']['numeric'] != '') ? $_SESSION['domain']['paging']['numeric'] : 50; - if (isset($app_uuid)) { $params[] = "app_uuid=".urlencode($app_uuid); } - if (isset($context)) { $params[] = "context=".urlencode($context); } - if (isset($search)) { $params[] = "search=".urlencode($search); } - if (isset($order_by)) { $params[] = "order_by=".urlencode($order_by); } - if (isset($order)) { $params[] = "order=".urlencode($order); } - if (!empty($_GET['show']) && $_GET['show'] == "all" && permission_exists('dialplan_all')) { + if (!empty($app_uuid)) { $params[] = "app_uuid=".urlencode($app_uuid); } + if (!empty($context)) { $params[] = "context=".urlencode($context); } + if (!empty($search)) { $params[] = "search=".urlencode($search); } + if (!empty($order_by)) { $params[] = "order_by=".urlencode($order_by); } + if (!empty($order)) { $params[] = "order=".urlencode($order); } + if ($show == "all" && permission_exists('dialplan_all')) { $params[] = "show=all"; } if (!empty($params)) { @@ -204,7 +206,7 @@ //get the list of dialplans $sql = "select * from v_dialplans "; - if ($_GET['show'] == "all" && permission_exists('dialplan_all')) { + if ($show == "all" && permission_exists('dialplan_all')) { $sql .= "where true "; } else { @@ -227,11 +229,11 @@ } $parameters['app_uuid'] = $app_uuid; } - if ($context) { + if (!empty($context)) { $sql .= "and dialplan_context = :dialplan_context "; $parameters['dialplan_context'] = $context; } - if ($search) { + if (!empty($search)) { $sql .= "and ("; $sql .= " lower(dialplan_context) like :search "; $sql .= " or lower(dialplan_name) like :search "; @@ -246,7 +248,7 @@ $sql .= ") "; $parameters['search'] = '%'.$search.'%'; } - if ($order_by != '') { + if (!empty($order_by)) { if ($order_by == 'dialplan_name' || $order_by == 'dialplan_description') { $sql .= 'order by lower('.$order_by.') '.$order.' '; } @@ -259,13 +261,13 @@ } $sql .= limit_offset($rows_per_page, $offset); $database = new database; - $dialplans = $database->select($sql, $parameters, 'all'); + $dialplans = $database->select($sql, $parameters ?? null, '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')) { + if ($show == "all" && permission_exists('dialplan_all')) { $sql .= "where true "; } else { @@ -283,7 +285,7 @@ } $sql .= ") as dc "; $database = new database; - $rows = $database->select($sql, $parameters, 'all'); + $rows = $database->select($sql, $parameters ?? null, 'all'); if (is_array($rows) && @sizeof($rows) != 0) { foreach ($rows as $row) { //reverse the array's (string) values in preparation to sort @@ -352,9 +354,9 @@ else if ($app_uuid == "4b821450-926b-175a-af93-a03c441818b1" && permission_exists('time_condition_add')) { $button_add_url = PROJECT_PATH."/app/time_conditions/time_condition_edit.php"; } else if (permission_exists('dialplan_add')) { $button_add_url = PROJECT_PATH."/app/dialplans/dialplan_add.php"; } if ($button_add_url) { - echo button::create(['type'=>'button','label'=>$text['button-add'],'icon'=>$_SESSION['theme']['button_icon_add'],'id'=>'btn_add','link'=>$button_add_url]); + echo button::create(['type'=>'button','label'=>$text['button-add'],'icon'=>$button_icon_add,'id'=>'btn_add','link'=>$button_add_url]); } - if ($dialplans) { + if (!empty($dialplans)) { if ( ($app_uuid == "c03b422e-13a8-bd1b-e42b-b6b9b4d27ce4" && permission_exists('inbound_route_copy')) || ($app_uuid == "8c914ec3-9fc0-8ab5-4cda-6c9288bdc9a3" && permission_exists('outbound_route_copy')) || @@ -362,7 +364,7 @@ ($app_uuid == "4b821450-926b-175a-af93-a03c441818b1" && permission_exists('time_condition_add')) || permission_exists('dialplan_add') ) { - echo button::create(['type'=>'button','label'=>$text['button-copy'],'icon'=>$_SESSION['theme']['button_icon_copy'],'id'=>'btn_copy','name'=>'btn_copy','style'=>'display: none;','onclick'=>"modal_open('modal-copy','btn_copy');"]); + echo button::create(['type'=>'button','label'=>$text['button-copy'],'icon'=>$button_icon_copy,'id'=>'btn_copy','name'=>'btn_copy','style'=>'display: none;','onclick'=>"modal_open('modal-copy','btn_copy');"]); } if ( ($app_uuid == "c03b422e-13a8-bd1b-e42b-b6b9b4d27ce4" && permission_exists('inbound_route_edit')) || @@ -371,7 +373,7 @@ ($app_uuid == "4b821450-926b-175a-af93-a03c441818b1" && permission_exists('time_condition_edit')) || permission_exists('dialplan_edit') ) { - echo button::create(['type'=>'button','label'=>$text['button-toggle'],'icon'=>$_SESSION['theme']['button_icon_toggle'],'id'=>'btn_toggle','name'=>'btn_toggle','style'=>'display: none;','onclick'=>"modal_open('modal-toggle','btn_toggle');"]); + echo button::create(['type'=>'button','label'=>$text['button-toggle'],'icon'=>$button_icon_toggle,'id'=>'btn_toggle','name'=>'btn_toggle','style'=>'display: none;','onclick'=>"modal_open('modal-toggle','btn_toggle');"]); } if ( ($app_uuid == "c03b422e-13a8-bd1b-e42b-b6b9b4d27ce4" && permission_exists('inbound_route_delete')) || @@ -380,35 +382,35 @@ ($app_uuid == "4b821450-926b-175a-af93-a03c441818b1" && permission_exists('time_condition_delete')) || permission_exists('dialplan_delete') ) { - echo button::create(['type'=>'button','label'=>$text['button-delete'],'icon'=>$_SESSION['theme']['button_icon_delete'],'id'=>'btn_delete','name'=>'btn_delete','style'=>'display: none;','onclick'=>"modal_open('modal-delete','btn_delete');"]); + echo button::create(['type'=>'button','label'=>$text['button-delete'],'icon'=>$button_icon_delete,'id'=>'btn_delete','name'=>'btn_delete','style'=>'display: none;','onclick'=>"modal_open('modal-delete','btn_delete');"]); } } echo "
\n"; @@ -443,7 +445,7 @@ echo " \n"; echo "\n"; - if ($dialplans) { + if (!empty($dialplans)) { if ( ($app_uuid == "c03b422e-13a8-bd1b-e42b-b6b9b4d27ce4" && permission_exists('inbound_route_copy')) || ($app_uuid == "8c914ec3-9fc0-8ab5-4cda-6c9288bdc9a3" && permission_exists('outbound_route_copy')) || @@ -500,36 +502,36 @@ permission_exists('dialplan_add') || permission_exists('dialplan_edit') || permission_exists('dialplan_delete') ) { echo "