Portions created by the Initial Developer are Copyright (C) 2008-2019 the Initial Developer. All Rights Reserved. Contributor(s): Mark J Crane The original Call Block was written by Gerrit Visser All of it has been rewritten over years. */ //includes 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('call_block_view')) { echo "access denied"; exit; } //add multi-lingual support $language = new text; $text = $language->get(); //get posted data if (is_array($_POST['call_blocks'])) { $action = $_POST['action']; $search = $_POST['search']; $call_blocks = $_POST['call_blocks']; } //process the http post data by action if ($action != '' && is_array($call_blocks) && @sizeof($call_blocks) != 0) { switch ($action) { case 'copy': if (permission_exists('call_block_add')) { $obj = new call_block; $obj->copy($call_blocks); } break; case 'toggle': if (permission_exists('call_block_edit')) { $obj = new call_block; $obj->toggle($call_blocks); } break; case 'delete': if (permission_exists('call_block_delete')) { $obj = new call_block; $obj->delete($call_blocks); } break; } header('Location: call_block.php'.($search != '' ? '?search='.urlencode($search) : null)); exit; } //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 = " ("; $sql_search .= "lower(call_block_name) like :search "; $sql_search .= "or call_block_country_code like :search "; $sql_search .= "or lower(call_block_number) like :search "; $sql_search .= "or lower(call_block_description) like :search "; $sql_search .= ") "; $parameters['search'] = '%'.$search.'%'; } //prepare to page the results $sql = "select count(*) from view_call_block "; $sql .= "where true "; if ($_GET['show'] == "all" && permission_exists('call_forward_all')) { $sql .= "and (domain_uuid = :domain_uuid or domain_uuid is null) "; $parameters['domain_uuid'] = $_SESSION['domain_uuid']; } else { $sql .= "and (domain_uuid = :domain_uuid) "; $parameters['domain_uuid'] = $_SESSION['domain_uuid']; } if (!permission_exists('call_block_all') && is_array($_SESSION['user']['extension']) && count($_SESSION['user']['extension']) > 0) { $sql .= "and extension_uuid in ("; $x = 0; foreach ($_SESSION['user']['extension'] as $field) { if (is_uuid($field['extension_uuid'])) { $sql .= ($x == 0) ? "'".$field['extension_uuid']."'" : ",'".$field['extension_uuid']."'"; } $x++; } $sql .= ") "; } if (isset($sql_search)) { $sql .= "and ".$sql_search; } $database = new database; $num_rows = $database->select($sql, $parameters, 'column'); unset($parameters); //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('call_forward_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 = "select * from view_call_block "; $sql .= "where true "; if ($_GET['show'] == "all" && permission_exists('call_forward_all')) { $sql .= "and (domain_uuid = :domain_uuid or domain_uuid is null) "; $parameters['domain_uuid'] = $_SESSION['domain_uuid']; } else { $sql .= "and (domain_uuid = :domain_uuid) "; $parameters['domain_uuid'] = $_SESSION['domain_uuid']; } if (!permission_exists('call_block_all') && is_array($_SESSION['user']['extension']) && count($_SESSION['user']['extension']) > 0) { $sql .= "and extension_uuid in ("; $x = 0; foreach ($_SESSION['user']['extension'] as $field) { if (is_uuid($field['extension_uuid'])) { $sql .= ($x == 0) ? "'".$field['extension_uuid']."'" : ",'".$field['extension_uuid']."'"; } $x++; } $sql .= ") "; } if (isset($sql_search)) { $sql .= "and ".$sql_search; } $sql .= order_by($order_by, $order, ['call_block_country_code','call_block_number']); $sql .= limit_offset($rows_per_page, $offset); $database = new database; $result = $database->select($sql, $parameters, 'all'); unset($sql, $parameters); //create token $object = new token; $token = $object->create($_SERVER['PHP_SELF']); //include the header $document['title'] = $text['title-call-block']; require_once "resources/header.php"; //show the content echo "
\n"; echo "
".$text['title-call-block']." (".$num_rows.")
\n"; echo "
\n"; if (permission_exists('call_block_add')) { echo button::create(['type'=>'button','label'=>$text['button-add'],'icon'=>$_SESSION['theme']['button_icon_add'],'id'=>'btn_add','link'=>'call_block_edit.php']); } if (permission_exists('call_block_add') && $result) { 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 (permission_exists('call_block_edit') && $result) { 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 (permission_exists('call_block_delete') && $result) { 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 (permission_exists('call_block_add') && $result) { 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 (permission_exists('call_block_edit') && $result) { 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 (permission_exists('call_block_delete') && $result) { 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');"])]); } echo $text['description-call-block']."\n"; echo "

\n"; echo "
\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; if (permission_exists('call_block_add') || permission_exists('call_block_edit') || permission_exists('call_block_delete')) { echo " \n"; } if ($_GET['show'] == 'all' && permission_exists('domain_all')) { echo th_order_by('domain_name', $text['label-domain'], $order_by, $order); } echo th_order_by('call_block_direction', $text['label-direction'], $order_by, $order, null, "style='width: 1%;' class='center'"); echo th_order_by('extension', $text['label-extension'], $order_by, $order, null, "class='center'"); echo th_order_by('call_block_name', $text['label-name'], $order_by, $order); echo th_order_by('call_block_country_code', $text['label-country_code'], $order_by, $order); echo th_order_by('call_block_number', $text['label-number'], $order_by, $order); echo th_order_by('call_block_count', $text['label-count'], $order_by, $order, '', "class='center hide-sm-dn'"); echo th_order_by('call_block_action', $text['label-action'], $order_by, $order); echo th_order_by('call_block_enabled', $text['label-enabled'], $order_by, $order, null, "class='center'"); echo th_order_by('date_added', $text['label-date-added'], $order_by, $order, null, "class='shrink no-wrap'"); echo "\n"; if (permission_exists('call_block_edit') && $_SESSION['theme']['list_row_edit_button']['boolean'] == 'true') { echo " \n"; } echo "\n"; if (is_array($result)) { $x = 0; foreach($result as $row) { if (permission_exists('call_block_edit')) { $list_row_url = "call_block_edit.php?id=".urlencode($row['call_block_uuid']); } echo "\n"; if (permission_exists('call_block_add') || permission_exists('call_block_edit') || permission_exists('call_block_delete')) { echo " \n"; } if ($_GET['show'] == 'all' && permission_exists('domain_all')) { echo " \n"; } echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; if (permission_exists('call_block_edit')) { echo " \n"; echo " \n"; echo " \n"; if (permission_exists('call_block_edit') && $_SESSION['theme']['list_row_edit_button']['boolean'] == 'true') { echo " \n"; } echo "\n"; $x++; } unset($result); } echo "
\n"; echo " \n"; echo " ".$text['label-description']." 
\n"; echo " \n"; echo " \n"; echo " ".escape($_SESSION['domains'][$row['domain_uuid']]['domain_name']).""; switch ($row['call_block_direction']) { case "inbound": echo "\n"; break; case "outbound": echo "\n"; break; } echo " "; if (strlen($row['extension']) == 0) { echo $text['label-all']; } else { echo escape($row['extension']); } echo " ".escape($row['call_block_name']).""; if (permission_exists('call_block_edit')) { echo "".escape($row['call_block_country_code']).""; } else { echo escape($row['call_block_country_code']); } echo " "; if (permission_exists('call_block_edit')) { echo "".escape(format_phone($row['call_block_number'])).""; } else { echo escape(format_phone($row['call_block_number'])); } echo " ".escape($row['call_block_count'])."".$text['label-'.$row['call_block_app']]." ".escape($row['call_block_data']).""; echo $text['label-'.$row['call_block_enabled']]; } echo " ".date('j M Y', $row['date_added'])." ".date(($_SESSION['domain']['time_format']['text'] == '12h' ? 'h:i:s a' : 'H:i:s'), $row['date_added'])."".escape($row['call_block_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"; ?>