Files
fusionpbx/core/dashboard/dashboard_edit.php
Alex e8681737dc Add ability to create multiple dashboards (#7483)
* Add ability to create multiple dashboards

* Create dashboard_widget_list.php

* Create dashboard_widget_edit.php

* Update dashboard_edit.php

* Update dashboard_config_json.php

* Update dashboard.php

* Update app_languages.php

* Update app_defaults.php

* Update app_config.php

* Update dashboard.php

* Create config.php

* Update content.php

* Update icon.php

* Update parent.php

* Update template.php

* Update config.php

* Update config.php

* Update domains.php

* Update config.php

* Update active_calls.php

* Update config.php

* Update config.php

* Update config.php

* Update config.php

* Update call_forward.php

* Update config.php

* Update config.php

* Update config.php

* Update config.php

* Update config.php

* Update domain_limits.php

* Update caller_id.php

* Update config.php

* Update config.php

* Update config.php

* Update config.php

* Update config.php

* Update registrations.php

* Update ring_group_forward.php

* Update config.php

* Update config.php

* Update switch_status.php

* Update config.php

* Update system_counts.php

* Update system_cpu_status.php

* Update system_disk_usage.php

* Update system_services.php

* Update system_status.php

* Update config.php

* Update config.php

* Update voicemails.php

* Update config.php

* Update missed_calls.php

* Update recent_calls.php

* Update dashboard_widget_edit.php

* Update app_languages.php

* Update dashboard_widget_edit.php

* Update index.php

* Update parent.php
2025-09-08 17:33:29 -06:00

267 lines
9.2 KiB
PHP

<?php
/*
FusionPBX
Version: MPL 1.1
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/
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.
The Original Code is FusionPBX
The Initial Developer of the Original Code is
Mark J Crane <markjcrane@fusionpbx.com>
Portions created by the Initial Developer are Copyright (C) 2021-2025
the Initial Developer. All Rights Reserved.
*/
//includes files
require_once dirname(__DIR__, 2) . "/resources/require.php";
require_once "resources/check_auth.php";
//check permissions
if (permission_exists('dashboard_add') || permission_exists('dashboard_edit')) {
//access granted
}
else {
echo "access denied";
exit;
}
//initialize the database
$database = new database;
//add multi-lingual support
$language = new text;
$text = $language->get();
//set the defaults
$domain_uuid = '';
$dashboard_uuid = '';
$dashboard_name = '';
$dashboard_enabled = 'true';
$dashboard_description = '';
//action add or update
if (!empty($_REQUEST["id"]) && is_uuid($_REQUEST["id"])) {
$action = "update";
$dashboard_uuid = $_REQUEST["id"];
$id = $_REQUEST["id"];
}
else {
$action = "add";
$domain_uuid = $_SESSION['domain_uuid'];
}
//get http post variables and set them to php variables
if (!empty($_POST)) {
$domain_uuid = permission_exists('dashboard_domain') ? $_POST["domain_uuid"] : $_SESSION['domain_uuid'];
$dashboard_name = $_POST["dashboard_name"] ?? '';
$dashboard_enabled = $_POST["dashboard_enabled"] ?? 'false';
$dashboard_description = $_POST["dashboard_description"] ?? '';
//define the regex patterns
$uuid_pattern = '/[^-A-Fa-f0-9]/';
$number_pattern = '/[^-A-Za-z0-9()*#]/';
$text_pattern = '/[^a-zA-Z0-9 _\-\/.\?:\=#\n]/';
//sanitize the data
$domain_uuid = preg_replace($uuid_pattern, '', $domain_uuid);
$dashboard_name = trim($dashboard_name);
$dashboard_enabled = preg_replace($text_pattern, '', $dashboard_enabled);
$dashboard_description = preg_replace($text_pattern, '', $dashboard_description);
}
//process the user data and save it to the database
if (count($_POST) > 0 && empty($_POST["persistformvar"])) {
//validate the token
$token = new token;
if (!$token->validate($_SERVER['PHP_SELF'])) {
message::add($text['message-invalid_token'],'negative');
header('Location: dashboard.php');
exit;
}
//check for all required data
$msg = '';
//if (empty($dashboard_name)) { $msg .= $text['message-required']." ".$text['label-dashboard_name']."<br>\n"; }
//if (empty($dashboard_enabled)) { $msg .= $text['message-required']." ".$text['label-dashboard_enabled']."<br>\n"; }
//if (empty($dashboard_description)) { $msg .= $text['message-required']." ".$text['label-dashboard_description']."<br>\n"; }
if (!empty($msg) && empty($_POST["persistformvar"])) {
require_once "resources/header.php";
require_once "resources/persist_form_var.php";
echo "<div align='center'>\n";
echo "<table><tr><td>\n";
echo $msg."<br />\n";
echo "</td></tr></table>\n";
persistformvar($_POST);
echo "</div>\n";
require_once "resources/footer.php";
return;
}
//add the dashboard_uuid
if (!is_uuid($_POST["dashboard_uuid"])) {
$dashboard_uuid = uuid();
}
//prepare the array
$array['dashboards'][0]['domain_uuid'] = $domain_uuid;
$array['dashboards'][0]['dashboard_uuid'] = $dashboard_uuid;
$array['dashboards'][0]['dashboard_name'] = $dashboard_name;
$array['dashboards'][0]['dashboard_enabled'] = $dashboard_enabled;
$array['dashboards'][0]['dashboard_description'] = $dashboard_description;
//save the data
$database->app_name = 'dashboard';
$database->app_uuid = '55533bef-4f04-434a-92af-999c1e9927f7';
$result = $database->save($array);
//redirect the user
if (isset($action)) {
if ($action == "add") {
$_SESSION["message"] = $text['message-add'];
}
if ($action == "update") {
$_SESSION["message"] = $text['message-update'];
}
//header('Location: dashboard.php');
header('Location: dashboard_edit.php?id='.urlencode($dashboard_uuid));
return;
}
}
//pre-populate the form
if (empty($_POST["persistformvar"])) {
$sql = "select ";
$sql .= " domain_uuid, ";
$sql .= " dashboard_uuid, ";
$sql .= " dashboard_name, ";
$sql .= " dashboard_enabled, ";
$sql .= " dashboard_description ";
$sql .= "from v_dashboards ";
$sql .= "where dashboard_uuid = :dashboard_uuid ";
$parameters['dashboard_uuid'] = $dashboard_uuid;
$row = $database->select($sql, $parameters ?? null, 'row');
if (is_array($row) && @sizeof($row) != 0) {
$domain_uuid = $row["domain_uuid"];
$dashboard_name = $row["dashboard_name"];
$dashboard_enabled = $row["dashboard_enabled"] ?? 'false';
$dashboard_description = $row["dashboard_description"];
}
unset($sql, $parameters, $row);
}
//create token
$object = new token;
$token = $object->create($_SERVER['PHP_SELF']);
//show the header
$document['title'] = $text['title-dashboard'];
require_once "resources/header.php";
//show the content
echo "<form method='post' name='frm' id='frm'>\n";
echo "<input class='formfld' type='hidden' name='dashboard_uuid' value='".escape($dashboard_uuid)."'>\n";
echo "<div class='action_bar' id='action_bar'>\n";
echo " <div class='heading'><b>".$text['title-dashboard']."</b></div>\n";
echo " <div class='actions'>\n";
echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$settings->get('theme', 'button_icon_back'),'id'=>'btn_back','collapse'=>'hide-xs','style'=>'margin-right: 15px;','link'=>'dashboard.php']);
echo button::create(['type'=>'submit','label'=>$text['button-save'],'icon'=>$settings->get('theme', 'button_icon_save'),'id'=>'btn_save','collapse'=>'hide-xs']);
echo " </div>\n";
echo " <div style='clear: both;'></div>\n";
echo "</div>\n";
//echo $text['title_description-dashboard']."\n";
//echo "<br /><br />\n";
echo "<div class='card'>\n";
echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
echo "<tr>\n";
echo "<td width='30%' class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
echo $text['label-dashboard_name'] ?? '';
echo "\n";
echo "</td>\n";
echo "<td width='70%' class='vtable' style='position: relative;' align='left'>\n";
echo " <input class='formfld' type='text' name='dashboard_name' maxlength='255' value='".escape($dashboard_name)."'>\n";
echo "<br />\n";
echo $text['description-dashboard_name']."\n";
echo "</td>\n";
echo "</tr>\n";
if (permission_exists('dashboard_domain')) {
echo "<tr>\n";
echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
echo " ".$text['label-domain']."\n";
echo "</td>\n";
echo "<td class='vtable' align='left'>\n";
echo " <select class='formfld' name='domain_uuid'>\n";
echo " <option value=''>".$text['label-global']."</option>\n";
foreach ($_SESSION['domains'] as $row) {
echo " <option value='".escape($row['domain_uuid'])."' ".($row['domain_uuid'] == $domain_uuid ? "selected='selected'" : null).">".escape($row['domain_name'])."</option>\n";
}
echo " </select>\n";
echo "<br />\n";
echo $text['description-domain_name']."\n";
echo "</td>\n";
echo "</tr>\n";
}
echo "<tr>\n";
echo "<td class='vncellreq' valign='top' align='left' nowrap='nowrap'>\n";
echo " ".$text['label-dashboard_enabled']."\n";
echo "</td>\n";
echo "<td class='vtable' style='position: relative;' align='left'>\n";
if (substr($_SESSION['theme']['input_toggle_style']['text'], 0, 6) == 'switch') {
echo " <label class='switch'>\n";
echo " <input type='checkbox' id='dashboard_enabled' name='dashboard_enabled' value='true' ".($dashboard_enabled == 'true' ? "checked='checked'" : null).">\n";
echo " <span class='slider'></span>\n";
echo " </label>\n";
}
else {
echo " <select class='formfld' id='dashboard_enabled' name='dashboard_enabled'>\n";
echo " <option value='false'>".$text['option-false']."</option>\n";
echo " <option value='true' ".($dashboard_enabled == 'true' ? "selected='selected'" : null).">".$text['option-true']."</option>\n";
echo " </select>\n";
}
echo "<br />\n";
echo $text['description-dashboard_enabled']."\n";
echo "</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
echo " ".$text['label-dashboard_description']."\n";
echo "</td>\n";
echo "<td class='vtable' style='position: relative;' align='left'>\n";
echo " <input class='formfld' type='text' name='dashboard_description' maxlength='255' value='".escape($dashboard_description)."'>\n";
echo "<br />\n";
echo $text['description-dashboard_description']."\n";
echo "</td>\n";
echo "</tr>\n";
echo "</table>\n";
echo "</div>\n";
echo "<br /><br />\n";
echo "<input type='hidden' name='".$token['name']."' value='".$token['hash']."'>\n";
echo "</form>\n";
if ($action == "update") {
require_once "core/dashboard/dashboard_widget_list.php";
}
//include the footer
require_once "resources/footer.php";
?>