Portions created by the Initial Developer are Copyright (C) 2008-2024 the Initial Developer. All Rights Reserved. Contributor(s): Mark J Crane */ //includes files require_once dirname(__DIR__, 2) . "/resources/require.php"; require_once "resources/check_auth.php"; require_once "resources/paging.php"; //check permissions if (permission_exists('fax_extension_view')) { //access granted } else { echo "access denied"; exit; } //add multi-lingual support $language = new text; $text = $language->get(); //get posted data if (!empty($_POST['fax_servers']) && is_array($_POST['fax_servers'])) { $action = $_POST['action']; $search = $_POST['search']; $fax_servers = $_POST['fax_servers']; } //process the http post data by action if (!empty($action) && !empty($fax_servers) && is_array($fax_servers) && @sizeof($fax_servers) != 0) { switch ($action) { case 'copy': if (permission_exists('fax_extension_copy')) { $obj = new fax; $obj->copy($fax_servers); } break; case 'delete': if (permission_exists('fax_extension_delete')) { $obj = new fax; $obj->delete($fax_servers); } break; } header('Location: fax.php'.($search != '' ? '?search='.urlencode($search) : null)); exit; } //get order and order by $order_by = $_GET["order_by"] ?? 'fax_name'; $order = $_GET["order"] ?? 'asc'; $sort = $order_by == 'fax_extension' ? 'natural' : null; //add the search and show variables $search = $_GET["search"] ?? ''; $show = $_GET["show"] ?? ''; //get record counts if ($show == "all" && permission_exists('fax_extension_view_all')) { //show all fax extensions $sql = "select count(f.fax_uuid) "; $sql .= "from v_fax as f "; $sql .= "where true "; } elseif (permission_exists('fax_extension_view_domain') || permission_exists('fax_extension_view_all')) { //show all fax extensions for this domain $sql = "select count(f.fax_uuid) "; $sql .= "from v_fax as f "; $sql .= "where (f.domain_uuid = :domain_uuid or f.domain_uuid is null) "; $parameters['domain_uuid'] = $_SESSION['domain_uuid']; } else { //show only assigned fax extensions $sql = "select count(f.fax_uuid) "; $sql .= "from v_fax as f, v_fax_users as u "; $sql .= "where f.fax_uuid = u.fax_uuid "; $sql .= "and f.domain_uuid = :domain_uuid "; $sql .= "and u.user_uuid = :user_uuid "; $parameters['domain_uuid'] = $_SESSION['domain_uuid']; $parameters['user_uuid'] = $_SESSION['user_uuid']; } if (!empty($search)) { $sql .= "and lower(fax_name) like :search "; $sql .= "or lower(fax_email) like :search "; $sql .= "or lower(fax_extension) like :search "; $sql .= "or lower(fax_destination_number) like :search "; $sql .= "or lower(fax_caller_id_name) like :search "; $sql .= "or lower(fax_caller_id_number) like :search "; $sql .= "or lower(fax_forward_number) like :search "; $sql .= "or lower(fax_description) like :search "; $parameters['search'] = '%'.strtolower($search).'%'; } $database = new database; $num_rows = $database->select($sql, $parameters ?? null, 'column'); //prepare paging $rows_per_page = (!empty($_SESSION['domain']['paging']['numeric'])) ? $_SESSION['domain']['paging']['numeric'] : 50; $param = "&search=".urlencode($search); if ($show == "all" && permission_exists('fax_extension_view_all')) { $param .= "&show=all"; } $page = !empty($_GET['page']) ? $_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 fax extensions if ($show == "all" && permission_exists('fax_extension_view_all')) { //show all fax extensions $sql = "select * from v_fax as f "; $sql .= "where true "; } elseif (permission_exists('fax_extension_view_domain') || permission_exists('fax_extension_view_all')) { //show all fax extensions for this domain $sql = "select fax_uuid, domain_uuid, fax_extension, fax_prefix, fax_name, fax_email, fax_description "; $sql .= "from v_fax as f "; $sql .= "where (f.domain_uuid = :domain_uuid or f.domain_uuid is null) "; $parameters['domain_uuid'] = $_SESSION['domain_uuid']; } else { //show only assigned fax extensions $sql = "select f.fax_uuid, fax_extension, fax_prefix, fax_name, fax_email, fax_description "; $sql .= "from v_fax as f, v_fax_users as u "; $sql .= "where f.fax_uuid = u.fax_uuid "; $sql .= "and f.domain_uuid = :domain_uuid "; $sql .= "and u.user_uuid = :user_uuid "; $parameters['domain_uuid'] = $_SESSION['domain_uuid']; $parameters['user_uuid'] = $_SESSION['user_uuid']; } if (!empty($search)) { $sql .= "and lower(fax_name) like :search "; $sql .= "or lower(fax_email) like :search "; $sql .= "or lower(fax_extension) like :search "; $sql .= "or lower(fax_destination_number) like :search "; $sql .= "or lower(fax_caller_id_name) like :search "; $sql .= "or lower(fax_caller_id_number) like :search "; $sql .= "or lower(fax_forward_number) like :search "; $sql .= "or lower(fax_description) like :search "; $parameters['search'] = '%'.strtolower($search).'%'; } $sql .= order_by($order_by, $order, 'fax_name', 'asc', $sort); $sql .= limit_offset($rows_per_page, $offset); $database = new database; $result = $database->select($sql, $parameters ?? null, 'all'); unset($sql, $parameters); //create token $object = new token; $token = $object->create($_SERVER['PHP_SELF']); //additional includes $document['title'] = $text['title-fax']; require_once "resources/header.php"; //show the content echo "
\n"; echo "
".$text['title-fax']."
".number_format($num_rows)."
\n"; echo "
\n"; if (permission_exists('fax_extension_add')) { echo button::create(['type'=>'button','label'=>$text['button-add'],'icon'=>$_SESSION['theme']['button_icon_add'],'id'=>'btn_add','link'=>'fax_edit.php']); } if (permission_exists('fax_extension_copy') && $result) { 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');"]); } if (permission_exists('fax_extension_delete') && $result) { 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');"]); } if (permission_exists('fax_extension_view_all')) { if ($show == 'all') { echo " "; } else { echo button::create(['type'=>'button','label'=>$text['button-show_all'],'icon'=>$_SESSION['theme']['button_icon_all'],'link'=>'?type=&show=all'.(!empty($search) ? "&search=".urlencode($search) : null)]); } } echo "\n"; echo "
\n"; echo "
\n"; echo "
\n"; if (permission_exists('fax_extension_copy') && $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('fax_extension_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']."\n"; echo "

\n"; echo "
\n"; echo "\n"; echo "\n"; echo "
\n"; echo "\n"; echo "\n"; if (permission_exists('fax_extension_add') || permission_exists('fax_extension_delete')) { echo " \n"; } if (permission_exists('fax_extension_view_all') && !empty($_GET['show']) && $_GET['show'] == 'all') { echo th_order_by('domain_name', $text['label-domain'], $order_by, $order); } echo th_order_by('fax_name', $text['label-name'], $order_by, $order); echo th_order_by('fax_extension', $text['label-extension'], $order_by, $order); echo th_order_by('fax_email', $text['label-email'], $order_by, $order); echo " "; echo th_order_by('fax_description', $text['label-description'], $order_by, $order, null, "class='hide-sm-dn'"); if (permission_exists('fax_extension_edit') && !empty($_SESSION['theme']['list_row_edit_button']['boolean']) && $_SESSION['theme']['list_row_edit_button']['boolean'] == 'true') { echo " \n"; } echo "\n"; if (is_array($result) && @sizeof($result) != 0) { $x = 0; foreach ($result as $row) { if (permission_exists('fax_extension_edit')) { $list_row_url = "fax_edit.php?id=".urlencode($row['fax_uuid']); } echo "\n"; if (permission_exists('fax_extension_add') || permission_exists('fax_extension_delete')) { echo " \n"; } if (permission_exists('fax_extension_view_all') && !empty($_GET['show']) && $_GET['show'] == 'all') { echo " \n"; } echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; if (permission_exists('fax_extension_edit') && !empty($_SESSION['theme']['list_row_edit_button']['boolean']) && $_SESSION['theme']['list_row_edit_button']['boolean'] == 'true') { echo " \n"; } echo "\n"; $x++; } unset($result); } echo "
\n"; echo " \n"; echo " ".$text['label-tools']." 
\n"; echo " \n"; echo " \n"; echo " ".escape($_SESSION['domains'][$row['domain_uuid']]['domain_name']).""; if (permission_exists('fax_extension_edit')) { echo "".escape($row['fax_name']).""; } else { echo escape($row['fax_name']); } echo " ".escape($row['fax_extension'])."".escape(str_replace("\\",'', $row['fax_email'] ?? ''))." ".escape($row['fax_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 "
\n"; echo "
".$paging_controls."
\n"; echo "\n"; echo "
\n"; //include the footer require_once "resources/footer.php"; ?>