Portions created by the Initial Developer are Copyright (C) 2008-2019 the Initial Developer. All Rights Reserved. Contributor(s): Mark J Crane */ //includes include "root.php"; require_once "resources/require.php"; require_once "resources/check_auth.php"; require_once "resources/paging.php"; //check permissions if (permission_exists('dialplan_view')) { //access granted } else { echo "access denied"; exit; } //add multi-lingual support $language = new text; $text = $language->get(); //get posted data if (is_array($_POST['dialplans'])) { $action = $_POST['action']; $dialplans = $_POST['dialplans']; $search = $_POST['search']; $order_by = $_POST['order_by']; $order = $_POST['order']; } //get the app uuid if (is_uuid($_REQUEST["app_uuid"])) { $app_uuid = $_REQUEST["app_uuid"]; } //process the http post data by action if ($action != '' && is_array($dialplans) && @sizeof($dialplans) != 0) { //define redirect parameters and url if (is_uuid($app_uuid)) { $params[] = "app_uuid=".urlencode($app_uuid); } if ($search) { $params[] = "search=".urlencode($search); } if ($order_by) { $params[] = "order_by=".urlencode($order_by); } if ($order) { $params[] = "order=".urlencode($order); } $list_page = 'dialplans.php'.($params ? '?'.implode('&', $params) : null); unset($params); //process action switch ($action) { case 'copy': if (permission_exists('dialplan_add')) { $obj = new dialplan; $obj->app_uuid = $app_uuid; $obj->list_page = $list_page; $obj->copy($dialplans); } break; case 'toggle': if (permission_exists('dialplan_edit')) { $obj = new dialplan; $obj->app_uuid = $app_uuid; $obj->list_page = $list_page; $obj->toggle($dialplans); } break; case 'delete': if (permission_exists('dialplan_delete')) { $obj = new dialplan; $obj->app_uuid = $app_uuid; $obj->list_page = $list_page; $obj->delete($dialplans); } break; } //redirect header('Location: '.$list_page); exit; } //get order and order by and sanatize the values $order_by = $_GET["order_by"]; $order = $_GET["order"]; //make sure all dialplans with context of public have the inbound route app_uuid if ($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' "; $sql .= "and app_uuid is null; "; $database = new database; $database->execute($sql); unset($sql); } //add the search term $search = strtolower($_GET["search"]); if (strlen($search) > 0) { $sql_search = "and ("; $sql_search .= " lower(dialplan_context) like :search "; $sql_search .= " or lower(dialplan_name) like :search "; $sql_search .= " or lower(dialplan_number) like :search "; $sql_search .= " or lower(dialplan_continue) like :search "; $sql_search .= " or lower(dialplan_enabled) like :search "; $sql_search .= " or lower(dialplan_description) like :search "; if (is_numeric($search)) { $sql_search .= " or dialplan_order = :search_numeric "; $parameters['search_numeric'] = $search; } $sql_search .= ") "; $parameters['search'] = '%'.$search.'%'; } //get the number of rows in the dialplan $sql = "select count(*) 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' "; //hide outbound routes //$sql .= "and app_uuid <> '8c914ec3-9fc0-8ab5-4cda-6c9288bdc9a3' "; } else { if ($app_uuid == 'c03b422e-13a8-bd1b-e42b-b6b9b4d27ce4') { $sql .= "and (app_uuid = :app_uuid or dialplan_context = 'public') "; } else { $sql .= "and app_uuid = :app_uuid "; } $parameters['app_uuid'] = $app_uuid; } $sql .= $sql_search; $database = new database; $num_rows = $database->select($sql, $parameters, 'column'); //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; } if ($_GET['show'] == "all" && permission_exists('dialplan_all')) { $params[] .= "show=all"; } $param = $params ? implode('&', $params) : null; unset($params); $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 of dialplans $sql = str_replace('count(*)', '*', $sql); if ($order_by != '') { if ($order_by == 'dialplan_name' || $order_by == 'dialplan_description') { $sql .= 'order by lower('.$order_by.') '.$order.' '; } else { $sql .= order_by($order_by, $order); } } else { $sql .= "order by dialplan_order asc, lower(dialplan_name) asc "; } $sql .= limit_offset($rows_per_page, $offset); $database = new database; $dialplans = $database->select($sql, $parameters, 'all'); unset($sql, $parameters); //create token $object = new token; $token = $object->create($_SERVER['PHP_SELF']); //include the header switch ($app_uuid) { case "c03b422e-13a8-bd1b-e42b-b6b9b4d27ce4": $document['title'] = $text['title-inbound_routes']; break; case "8c914ec3-9fc0-8ab5-4cda-6c9288bdc9a3": $document['title'] = $text['title-outbound_routes']; break; case "16589224-c876-aeb3-f59f-523a1c0801f7": $document['title'] = $text['title-queues']; break; case "4b821450-926b-175a-af93-a03c441818b1": $document['title'] = $text['title-time_conditions']; break; default: $document['title'] = $text['title-dialplan_manager']; } require_once "resources/header.php"; //show the content echo "
\n"; echo "
"; switch ($app_uuid) { case "c03b422e-13a8-bd1b-e42b-b6b9b4d27ce4": echo $text['header-inbound_routes']; break; case "8c914ec3-9fc0-8ab5-4cda-6c9288bdc9a3": echo $text['header-outbound_routes']; break; case "16589224-c876-aeb3-f59f-523a1c0801f7": echo $text['header-queues']; break; case "4b821450-926b-175a-af93-a03c441818b1": echo $text['header-time_conditions']; break; default: echo $text['header-dialplan_manager']; } echo " (".$num_rows.")"; echo "
\n"; echo "
\n"; if ($app_uuid == "c03b422e-13a8-bd1b-e42b-b6b9b4d27ce4" && permission_exists('inbound_route_add')) { $button_add_url = PROJECT_PATH."/app/dialplan_inbound/dialplan_inbound_add.php"; } else if ($app_uuid == "8c914ec3-9fc0-8ab5-4cda-6c9288bdc9a3" && permission_exists('outbound_route_add')) { $button_add_url = PROJECT_PATH."/app/dialplan_outbound/dialplan_outbound_add.php"; } else if ($app_uuid == "16589224-c876-aeb3-f59f-523a1c0801f7" && permission_exists('fifo_add')) { $button_add_url = PROJECT_PATH."/app/fifo/fifo_add.php"; } 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]); } if ($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')) || ($app_uuid == "16589224-c876-aeb3-f59f-523a1c0801f7" && permission_exists('fifo_add')) || ($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'],'name'=>'btn_copy','onclick'=>"modal_open('modal-copy','btn_copy');"]); } if ( ($app_uuid == "c03b422e-13a8-bd1b-e42b-b6b9b4d27ce4" && permission_exists('inbound_route_edit')) || ($app_uuid == "8c914ec3-9fc0-8ab5-4cda-6c9288bdc9a3" && permission_exists('outbound_route_edit')) || ($app_uuid == "16589224-c876-aeb3-f59f-523a1c0801f7" && permission_exists('fifo_edit')) || ($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'],'name'=>'btn_toggle','onclick'=>"modal_open('modal-toggle','btn_toggle');"]); } if ( ($app_uuid == "c03b422e-13a8-bd1b-e42b-b6b9b4d27ce4" && permission_exists('inbound_route_delete')) || ($app_uuid == "8c914ec3-9fc0-8ab5-4cda-6c9288bdc9a3" && permission_exists('outbound_route_delete')) || ($app_uuid == "16589224-c876-aeb3-f59f-523a1c0801f7" && permission_exists('fifo_delete')) || ($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'],'name'=>'btn_delete','onclick'=>"modal_open('modal-delete','btn_delete');"]); } } echo "\n"; echo "
\n"; echo "
\n"; echo "
\n"; if ($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')) || ($app_uuid == "16589224-c876-aeb3-f59f-523a1c0801f7" && permission_exists('fifo_add')) || ($app_uuid == "4b821450-926b-175a-af93-a03c441818b1" && permission_exists('time_condition_add')) || permission_exists('dialplan_add') ) { echo modal::create(['id'=>'modal-copy','type'=>'copy','actions'=>button::create(['type'=>'button','label'=>$text['button-continue'],'icon'=>'check','id'=>'btn_copy','style'=>'float: right; margin-left: 15px;','collapse'=>'never','onclick'=>"modal_close(); list_action_set('copy'); list_form_submit('form_list');"])]); } if ( ($app_uuid == "c03b422e-13a8-bd1b-e42b-b6b9b4d27ce4" && permission_exists('inbound_route_edit')) || ($app_uuid == "8c914ec3-9fc0-8ab5-4cda-6c9288bdc9a3" && permission_exists('outbound_route_edit')) || ($app_uuid == "16589224-c876-aeb3-f59f-523a1c0801f7" && permission_exists('fifo_edit')) || ($app_uuid == "4b821450-926b-175a-af93-a03c441818b1" && permission_exists('time_condition_edit')) || permission_exists('dialplan_edit') ) { echo modal::create(['id'=>'modal-toggle','type'=>'toggle','actions'=>button::create(['type'=>'button','label'=>$text['button-continue'],'icon'=>'check','id'=>'btn_toggle','style'=>'float: right; margin-left: 15px;','collapse'=>'never','onclick'=>"modal_close(); list_action_set('toggle'); list_form_submit('form_list');"])]); } if ( ($app_uuid == "c03b422e-13a8-bd1b-e42b-b6b9b4d27ce4" && permission_exists('inbound_route_delete')) || ($app_uuid == "8c914ec3-9fc0-8ab5-4cda-6c9288bdc9a3" && permission_exists('outbound_route_delete')) || ($app_uuid == "16589224-c876-aeb3-f59f-523a1c0801f7" && permission_exists('fifo_delete')) || ($app_uuid == "4b821450-926b-175a-af93-a03c441818b1" && permission_exists('time_condition_delete')) || permission_exists('dialplan_delete') ) { echo modal::create(['id'=>'modal-delete','type'=>'delete','actions'=>button::create(['type'=>'button','label'=>$text['button-continue'],'icon'=>'check','id'=>'btn_delete','style'=>'float: right; margin-left: 15px;','collapse'=>'never','onclick'=>"modal_close(); list_action_set('delete'); list_form_submit('form_list');"])]); } } switch ($app_uuid) { case "c03b422e-13a8-bd1b-e42b-b6b9b4d27ce4": echo $text['description-inbound_routes']; break; case "8c914ec3-9fc0-8ab5-4cda-6c9288bdc9a3": echo $text['description-outbound_routes']; break; case "16589224-c876-aeb3-f59f-523a1c0801f7": echo $text['description-queues']; break; case "4b821450-926b-175a-af93-a03c441818b1": echo $text['description-time_conditions']; break; default: echo $text['description-dialplan_manager'.(if_group("superadmin") ? '-superadmin' : null)]; } echo "\n

\n"; echo "
\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; if ( ($app_uuid == "c03b422e-13a8-bd1b-e42b-b6b9b4d27ce4" && (permission_exists('inbound_route_copy') || permission_exists('inbound_route_edit') || permission_exists('inbound_route_delete'))) || ($app_uuid == "8c914ec3-9fc0-8ab5-4cda-6c9288bdc9a3" && (permission_exists('outbound_route_copy') || permission_exists('outbound_route_edit') || permission_exists('outbound_route_delete'))) || ($app_uuid == "16589224-c876-aeb3-f59f-523a1c0801f7" && (permission_exists('fifo_add') || permission_exists('fifo_edit') || permission_exists('fifo_delete'))) || ($app_uuid == "4b821450-926b-175a-af93-a03c441818b1" && (permission_exists('time_condition_add') || permission_exists('time_condition_edit') || permission_exists('time_condition_delete'))) || permission_exists('dialplan_add') || permission_exists('dialplan_edit') || permission_exists('dialplan_delete') ) { echo " \n"; } if ($_GET['show'] == "all" && permission_exists('dialplan_all')) { echo "\n"; } 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)); echo th_order_by('dialplan_number', $text['label-number'], $order_by, $order, $app_uuid, null, ($params ? implode('&', $params) : null)); if (permission_exists('dialplan_context')) { echo th_order_by('dialplan_context', $text['label-context'], $order_by, $order, $app_uuid, null, ($params ? implode('&', $params) : null)); } echo th_order_by('dialplan_order', $text['label-order'], $order_by, $order, $app_uuid, "class='center shrink'", ($params ? implode('&', $params) : null)); echo th_order_by('dialplan_enabled', $text['label-enabled'], $order_by, $order, $app_uuid, "class='center'", ($params ? implode('&', $params) : null)); echo th_order_by('dialplan_description', $text['label-description'], $order_by, $order, $app_uuid, "class='hide-sm-dn' style='min-width: 100px;'", ($params ? implode('&', $params) : null)); unset($params); if (( ($app_uuid == "c03b422e-13a8-bd1b-e42b-b6b9b4d27ce4" && permission_exists('inbound_route_edit')) || ($app_uuid == "8c914ec3-9fc0-8ab5-4cda-6c9288bdc9a3" && permission_exists('outbound_route_edit')) || ($app_uuid == "16589224-c876-aeb3-f59f-523a1c0801f7" && permission_exists('fifo_edit')) || ($app_uuid == "4b821450-926b-175a-af93-a03c441818b1" && permission_exists('time_condition_edit')) || permission_exists('dialplan_edit')) && $_SESSION['theme']['list_row_edit_button']['boolean'] == 'true' ) { echo " \n"; } echo "\n"; if (is_array($dialplans) && @sizeof($dialplans) != 0) { $x = 0; foreach ($dialplans as $row) { if ($row['app_uuid'] == "4b821450-926b-175a-af93-a03c441818b1") { if (permission_exists('time_condition_edit') || permission_exists('dialplan_edit')) { $list_row_url = PROJECT_PATH."/app/time_conditions/time_condition_edit.php?id=".urlencode($row['dialplan_uuid']).(is_uuid($app_uuid) ? "&app_uuid=".urlencode($app_uuid) : null); } } else if ( ($row['app_uuid'] == "c03b422e-13a8-bd1b-e42b-b6b9b4d27ce4" && permission_exists('inbound_route_edit')) || ($row['app_uuid'] == "8c914ec3-9fc0-8ab5-4cda-6c9288bdc9a3" && permission_exists('outbound_route_edit')) || ($row['app_uuid'] == "16589224-c876-aeb3-f59f-523a1c0801f7" && permission_exists('fifo_edit')) || permission_exists('dialplan_edit') ) { $list_row_url = "dialplan_edit.php?id=".urlencode($row['dialplan_uuid']).(is_uuid($app_uuid) ? "&app_uuid=".urlencode($app_uuid) : null); } else { unset($list_row_url); } echo "\n"; if ( (!is_uuid($app_uuid) && (permission_exists('dialplan_add') || permission_exists('dialplan_edit') || permission_exists('dialplan_delete'))) || ($app_uuid == "c03b422e-13a8-bd1b-e42b-b6b9b4d27ce4" && (permission_exists('inbound_route_copy') || permission_exists('inbound_route_edit') || permission_exists('inbound_route_delete'))) || ($app_uuid == "8c914ec3-9fc0-8ab5-4cda-6c9288bdc9a3" && (permission_exists('outbound_route_copy') || permission_exists('outbound_route_edit') || permission_exists('outbound_route_delete'))) || ($app_uuid == "16589224-c876-aeb3-f59f-523a1c0801f7" && (permission_exists('fifo_add') || permission_exists('fifo_edit') || permission_exists('fifo_delete'))) || ($app_uuid == "4b821450-926b-175a-af93-a03c441818b1" && (permission_exists('time_condition_add') || permission_exists('time_condition_edit') || permission_exists('time_condition_delete'))) ) { echo " \n"; } if ($_GET['show'] == "all" && permission_exists('dialplan_all')) { if (strlen($_SESSION['domains'][$row['domain_uuid']]['domain_name']) > 0) { $domain = $_SESSION['domains'][$row['domain_uuid']]['domain_name']; } else { $domain = $text['label-global']; } echo " \n"; } echo " \n"; echo " \n"; if (permission_exists('dialplan_context')) { echo " \n"; } echo " \n"; if ( (!is_uuid($app_uuid) && permission_exists('dialplan_edit')) || ($row['app_uuid'] == "c03b422e-13a8-bd1b-e42b-b6b9b4d27ce4" && permission_exists('inbound_route_edit')) || ($row['app_uuid'] == "8c914ec3-9fc0-8ab5-4cda-6c9288bdc9a3" && permission_exists('outbound_route_edit')) || ($row['app_uuid'] == "16589224-c876-aeb3-f59f-523a1c0801f7" && permission_exists('fifo_edit')) || ($row['app_uuid'] == "4b821450-926b-175a-af93-a03c441818b1" && permission_exists('time_condition_edit')) ) { echo " \n"; echo " \n"; if ($_SESSION['theme']['list_row_edit_button']['boolean'] == 'true' && ( (!is_uuid($app_uuid) && permission_exists('dialplan_edit')) || ($row['app_uuid'] == "c03b422e-13a8-bd1b-e42b-b6b9b4d27ce4" && permission_exists('inbound_route_edit')) || ($row['app_uuid'] == "8c914ec3-9fc0-8ab5-4cda-6c9288bdc9a3" && permission_exists('outbound_route_edit')) || ($row['app_uuid'] == "16589224-c876-aeb3-f59f-523a1c0801f7" && permission_exists('fifo_edit')) || ($row['app_uuid'] == "4b821450-926b-175a-af93-a03c441818b1" && permission_exists('time_condition_edit')) )) { echo " \n"; } echo "\n"; $x++; } unset($dialplans); } echo "
\n"; echo " \n"; echo " ".$text['label-domain']." 
\n"; echo " \n"; echo " \n"; echo " ".escape($domain).""; if ($list_row_url) { echo "".escape($row['dialplan_name']).""; } else { echo escape($row['dialplan_name']); } echo " ".((strlen($row['dialplan_number']) > 0) ? escape(format_phone($row['dialplan_number'])) : " ")."".escape($row['dialplan_context'])."".escape($row['dialplan_order']).""; echo $text['label-'.$row['dialplan_enabled']]; } echo " ".escape($row['dialplan_description'])." "; 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 "\n"; echo "
\n"; //include the footer require_once "resources/footer.php"; ?>