fusionpbx/core/domains/domains.php

311 lines
12 KiB
PHP
Raw Normal View History

<?php
/*
2019-12-16 17:59:50 +01:00
FusionPBX
Version: MPL 1.1
2019-12-16 17:59:50 +01:00
The contents of this file are subject to the Mozilla Public License Version
1.1 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/
2019-12-16 17:59:50 +01:00
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
for the specific language governing rights and limitations under the
License.
2019-12-16 17:59:50 +01:00
The Original Code is FusionPBX
2019-12-16 17:59:50 +01:00
The Initial Developer of the Original Code is
Mark J Crane <markjcrane@fusionpbx.com>
2022-02-23 21:56:00 +01:00
Portions created by the Initial Developer are Copyright (C) 2018 - 2022
2019-12-16 17:59:50 +01:00
the Initial Developer. All Rights Reserved.
2019-12-16 17:59:50 +01:00
Contributor(s):
Mark J Crane <markjcrane@fusionpbx.com>
*/
2019-12-16 17:59:50 +01:00
2022-10-11 00:35:14 +02:00
//includes files
Use magic constant dir (#6711) * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ to load only functions.php * replace spaces with tab character * update dirname command to use levels instead of nesting * use magic constant __DIR__ * update dirname command to use levels instead of nesting * Update access_control_edit.php * Update access_control_import.php * Update access_controls.php * Update dnd.php * Update access_controls_reload.php * Update call_center_agents.php * Update call_center_agents.php * Update fax_queue.php * Update login.php * Update pdo.php * Update pdo_vm.php * Update switch.php * Update index.php * Update css.php * Update v_mailto.php * Update fax_to_email.php --------- Co-authored-by: FusionPBX <markjcrane@gmail.com>
2023-06-15 19:28:23 +02:00
require_once dirname(__DIR__, 2) . "/resources/require.php";
2018-03-26 07:13:47 +02:00
require_once "resources/check_auth.php";
2019-12-16 17:59:50 +01:00
require_once "resources/paging.php";
2024-08-29 11:35:38 +02:00
//connect to the database
$database = new database;
//redirect admin to app instead
2019-08-22 19:03:23 +02:00
if (file_exists($_SERVER["PROJECT_ROOT"]."/app/domains/app_config.php") && !permission_exists('domain_all') && !is_cli()) {
header("Location: ".PROJECT_PATH."/app/domains/domains.php");
exit;
}
//change the domain
2023-05-13 07:42:41 +02:00
if (!empty($_GET["domain_uuid"]) && is_uuid($_GET["domain_uuid"]) && $_GET["domain_change"] == "true") {
if (permission_exists('domain_select')) {
//update the domain session variables
$domain_uuid = $_GET["domain_uuid"];
$_SESSION["previous_domain_uuid"] = $_SESSION['domain_uuid'];
$_SESSION['domain_uuid'] = $domain_uuid;
//get the domain details
$sql = "select * from v_domains ";
$sql .= "order by domain_name asc ";
$domains = $database->select($sql, null, 'all');
if (!empty($domains)) {
foreach($domains as $row) {
$_SESSION['domains'][$row['domain_uuid']] = $row;
}
}
2019-07-10 20:14:47 +02:00
unset($sql, $result);
//update the domain session variables
$_SESSION["domain_name"] = $_SESSION['domains'][$domain_uuid]['domain_name'];
2023-05-26 00:43:34 +02:00
$_SESSION['domain']['template']['name'] = $_SESSION['domains'][$domain_uuid]['template_name'] ?? null;
$_SESSION["context"] = $_SESSION["domain_name"];
//clear the extension array so that it is regenerated for the selected domain
unset($_SESSION['extension_array']);
//set the setting arrays
$domain = new domains();
$domain->set();
//redirect the user
2023-05-13 07:42:41 +02:00
if (!empty($_SESSION["login"]["destination"])) {
// to default, or domain specific, login destination
2023-07-11 23:28:01 +02:00
header("Location: ".PROJECT_PATH.$_SESSION["login"]["destination"]["text"]);
}
else {
2021-11-13 23:30:16 +01:00
header("Location: ".PROJECT_PATH."/core/dashboard/");
}
2019-07-10 20:14:47 +02:00
exit;
}
}
2019-12-16 17:59:50 +01:00
//check permission
if (permission_exists('domain_all') && permission_exists('domain_view')) {
//access granted
}
else {
echo "access denied";
exit;
2015-09-16 05:53:14 +02:00
}
2019-12-16 17:59:50 +01:00
//add multi-lingual support
$language = new text;
$text = $language->get();
//get the http post data
2023-05-13 07:42:41 +02:00
if (!empty($_POST['domains'])) {
$action = $_POST['action'] ?? '';
$search = $_POST['search'] ?? '';
$domains = $_POST['domains'] ?? '';
2019-12-16 17:59:50 +01:00
}
//process the http post data by action
2023-05-13 07:42:41 +02:00
if (!empty($action) && !empty($domains)) {
2019-12-16 17:59:50 +01:00
switch ($action) {
case 'copy':
if (permission_exists('domain_add')) {
$obj = new domains;
$obj->copy($domains);
}
break;
case 'toggle':
if (permission_exists('domain_edit')) {
$obj = new domains;
$obj->toggle($domains);
}
break;
case 'delete':
if (permission_exists('domain_delete')) {
$obj = new domains;
$obj->delete($domains);
}
break;
}
2023-05-13 07:42:41 +02:00
header('Location: domains.php'.(!empty($search) ? '?search='.urlencode($search) : null));
2019-12-16 17:59:50 +01:00
exit;
}
2023-05-13 07:42:41 +02:00
//get order and order by and sanitize the values
$order_by = $_GET["order_by"] ?? '';
$order = $_GET["order"] ?? '';
//set additional variables
$search = $_GET["search"] ?? '';
$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';
2019-07-10 20:14:47 +02:00
2019-12-16 17:59:50 +01:00
//add the search string
2023-05-13 07:42:41 +02:00
if (!empty($search)) {
2019-12-16 17:59:50 +01:00
$search = strtolower($_GET["search"]);
$sql_search = " (";
$sql_search .= " lower(domain_name) like :search ";
$sql_search .= " or lower(domain_description) like :search ";
$sql_search .= ") ";
$parameters['search'] = '%'.$search.'%';
2014-07-23 06:24:57 +02:00
}
2019-12-16 17:59:50 +01:00
//get the count
$sql = "select count(domain_uuid) from v_domains ";
2023-05-13 07:42:41 +02:00
if (!empty($sql_search)) {
2019-12-16 17:59:50 +01:00
$sql .= "where ".$sql_search;
}
2023-05-13 07:42:41 +02:00
$num_rows = $database->select($sql, $parameters ?? null, 'column');
2014-07-23 06:24:57 +02:00
//prepare to page the results
2023-05-13 07:42:41 +02:00
$rows_per_page = (!empty($_SESSION['domain']['paging']['numeric'])) ? $_SESSION['domain']['paging']['numeric'] : 50;
2019-12-16 17:59:50 +01:00
$param = $search ? "&search=".$search : null;
2023-05-13 07:42:41 +02:00
$page = !empty($_GET['page']) ? $_GET['page'] : 0;
2019-12-16 17:59:50 +01:00
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);
2014-07-23 06:24:57 +02:00
$offset = $rows_per_page * $page;
2019-12-16 17:59:50 +01:00
//get the list
2020-07-10 17:44:53 +02:00
$sql = "select domain_uuid, domain_name, cast(domain_enabled as text), domain_description ";
2020-07-10 17:41:43 +02:00
$sql .= "from v_domains ";
2023-05-13 07:42:41 +02:00
if (!empty($sql_search)) {
2020-07-10 17:41:43 +02:00
$sql .= "where ".$sql_search;
}
2019-12-16 17:59:50 +01:00
$sql .= order_by($order_by, $order, 'domain_name', 'asc');
2019-07-10 20:14:47 +02:00
$sql .= limit_offset($rows_per_page, $offset);
2023-05-13 07:42:41 +02:00
$domains = $database->select($sql, $parameters ?? null, 'all');
2019-12-16 17:59:50 +01:00
unset($sql, $parameters);
//create token
$object = new token;
$token = $object->create($_SERVER['PHP_SELF']);
2019-12-16 17:59:50 +01:00
//include the header
2020-01-06 20:17:16 +01:00
$document['title'] = $text['title-domains'];
2019-12-16 17:59:50 +01:00
require_once "resources/header.php";
//show the content
echo "<div class='action_bar' id='action_bar'>\n";
2024-09-07 00:43:42 +02:00
echo " <div class='heading'><b>".$text['title-domains']."</b><div class='count'>".number_format($num_rows)."</div></div>\n";
2019-12-16 17:59:50 +01:00
echo " <div class='actions'>\n";
if (permission_exists('domain_add')) {
echo button::create(['type'=>'button','label'=>$text['button-add'],'icon'=>$_SESSION['theme']['button_icon_add'],'id'=>'btn_add','link'=>'domain_edit.php']);
2019-12-16 17:59:50 +01:00
}
if (permission_exists('domain_edit') && $domains) {
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');"]);
2019-12-16 17:59:50 +01:00
}
2020-01-30 21:02:37 +01:00
if (permission_exists('domain_delete') && $domains) {
2022-02-23 21:56:00 +01:00
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_domain');"]);
2020-01-30 21:02:37 +01:00
}
2019-12-16 17:59:50 +01:00
echo "<form id='form_search' class='inline' method='get'>\n";
echo "<input type='text' class='txt list-search' name='search' id='search' value=\"".escape($search)."\" placeholder=\"".$text['label-search']."\" onkeydown=''>";
echo button::create(['label'=>$text['button-search'],'icon'=>$_SESSION['theme']['button_icon_search'],'type'=>'submit','id'=>'btn_search']);
//echo button::create(['label'=>$text['button-reset'],'icon'=>$_SESSION['theme']['button_icon_reset'],'type'=>'button','id'=>'btn_reset','link'=>'domains.php','style'=>($search == '' ? 'display: none;' : null)]);
2023-05-13 07:42:41 +02:00
if (!empty($paging_controls_mini)) {
2019-12-16 17:59:50 +01:00
echo "<span style='margin-left: 15px;'>".$paging_controls_mini."</span>\n";
}
echo " </form>\n";
echo " </div>\n";
echo " <div style='clear: both;'></div>\n";
echo "</div>\n";
2023-05-13 07:42:41 +02:00
if (permission_exists('domain_edit') && !empty($domains)) {
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');"])]);
}
2023-05-13 07:42:41 +02:00
if (permission_exists('domain_delete') && !empty($domains)) {
2022-02-23 21:56:00 +01:00
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');"])]);
}
2019-12-16 17:59:50 +01:00
echo $text['description-domains']."\n";
echo "<br /><br />\n";
echo "<form id='form_list' method='post'>\n";
echo "<input type='hidden' id='action' name='action' value=''>\n";
echo "<input type='hidden' name='search' value=\"".escape($search)."\">\n";
echo "<div class='card'>\n";
2019-12-16 17:59:50 +01:00
echo "<table class='list'>\n";
echo "<tr class='list-header'>\n";
2019-12-16 21:32:27 +01:00
if (permission_exists('domain_edit') || permission_exists('domain_delete')) {
2019-12-16 17:59:50 +01:00
echo " <th class='checkbox'>\n";
2023-05-13 07:42:41 +02:00
echo " <input type='checkbox' id='checkbox_all' name='checkbox_all' onclick='list_all_toggle(); checkbox_on_change(this);' ".(!empty($domains) ?: "style='visibility: hidden;'").">\n";
2019-12-16 17:59:50 +01:00
echo " </th>\n";
}
2023-05-13 07:42:41 +02:00
if ($show == 'all' && permission_exists('domain_all')) {
2019-12-16 17:59:50 +01:00
echo th_order_by('domain_name', $text['label-domain'], $order_by, $order);
}
echo th_order_by('domain_name', $text['label-domain_name'], $order_by, $order);
echo "<th class='center'>".$text['label-tools']."</th>";
2019-12-16 17:59:50 +01:00
echo th_order_by('domain_enabled', $text['label-domain_enabled'], $order_by, $order, null, "class='center'");
echo " <th class='hide-sm-dn'>".$text['label-domain_description']."</th>\n";
2023-05-13 07:42:41 +02:00
if (permission_exists('domain_edit') && $list_row_edit_button == 'true') {
2019-12-16 17:59:50 +01:00
echo " <td class='action-button'>&nbsp;</td>\n";
}
2014-06-22 03:16:49 +02:00
echo "</tr>\n";
2023-05-13 07:42:41 +02:00
if (!empty($domains)) {
2019-12-16 17:59:50 +01:00
$x = 0;
foreach ($domains as $row) {
2023-05-13 07:42:41 +02:00
$list_row_url = '';
2019-12-16 17:59:50 +01:00
if (permission_exists('domain_edit')) {
$list_row_url = "domain_edit.php?id=".urlencode($row['domain_uuid']);
}
2019-12-16 17:59:50 +01:00
echo "<tr class='list-row' href='".$list_row_url."'>\n";
2019-12-16 21:32:27 +01:00
if (permission_exists('domain_edit') || permission_exists('domain_delete')) {
2019-12-16 17:59:50 +01:00
echo " <td class='checkbox'>\n";
echo " <input type='checkbox' name='domains[$x][checked]' id='checkbox_".$x."' value='true' onclick=\"checkbox_on_change(this); if (!this.checked) { document.getElementById('checkbox_all').checked = false; }\">\n";
2019-12-16 17:59:50 +01:00
echo " <input type='hidden' name='domains[$x][uuid]' value='".escape($row['domain_uuid'])."' />\n";
echo " </td>\n";
}
2023-05-13 07:42:41 +02:00
if ($show == 'all' && permission_exists('domain_all')) {
2019-12-16 17:59:50 +01:00
echo " <td>".escape($_SESSION['domains'][$row['domain_uuid']]['domain_name'])."</td>\n";
}
echo " <td>\n";
if (permission_exists('domain_edit')) {
2019-12-16 17:59:50 +01:00
echo " <a href='".$list_row_url."' title=\"".$text['button-edit']."\">".escape($row['domain_name'])."</a>\n";
}
else {
echo " ".escape($row['domain_name']);
}
2019-12-16 17:59:50 +01:00
echo " </td>\n";
echo " <td class='no-link center'>\n";
echo " <a href='".PROJECT_PATH."/core/domains/domains.php?domain_uuid=".escape($row['domain_uuid'])."&domain_change=true'>".$text['label-manage']."</a>";
if (permission_exists('domain_setting_view')) {
$list_setting_url = PROJECT_PATH."/core/domain_settings/domain_settings.php?id=".urlencode($row['domain_uuid']);
echo "&nbsp;&nbsp; <a href='".$list_setting_url."'\">".$text['button-settings'];
}
echo " </td>\n";
if (permission_exists('domain_edit')) {
2019-12-16 17:59:50 +01:00
echo " <td class='no-link center'>\n";
echo button::create(['type'=>'submit','class'=>'link','label'=>$text['label-'.$row['domain_enabled']],'title'=>$text['button-toggle'],'onclick'=>"list_self_check('checkbox_".$x."'); list_action_set('toggle'); list_form_submit('form_list')"]);
echo " </td>\n";
}
2019-12-16 17:59:50 +01:00
else {
echo " <td class='center'>\n";
echo $text['label-'.$row['domain_enabled']];
echo " </td>\n";
}
2019-12-16 17:59:50 +01:00
echo " <td class='description overflow hide-sm-dn'>".escape($row['domain_description'])."</td>\n";
2023-05-13 07:42:41 +02:00
if (permission_exists('domain_edit') && $list_row_edit_button == 'true') {
2019-12-16 17:59:50 +01:00
echo " <td class='action-button'>\n";
echo button::create(['type'=>'button','title'=>$text['button-edit'],'icon'=>$_SESSION['theme']['button_icon_edit'],'link'=>$list_row_url]);
echo " </td>\n";
}
echo "</tr>\n";
2019-12-16 17:59:50 +01:00
$x++;
}
2019-12-16 17:59:50 +01:00
unset($domains);
}
2019-12-16 17:59:50 +01:00
echo "</table>\n";
echo "</div>\n";
2019-12-16 17:59:50 +01:00
echo "<br />\n";
echo "<div align='center'>".$paging_controls."</div>\n";
echo "<input type='hidden' name='".$token['name']."' value='".$token['hash']."'>\n";
echo "</form>\n";
//include the footer
require_once "resources/footer.php";
2020-01-30 21:02:37 +01:00
?>