Portions created by the Initial Developer are Copyright (C) 2022-2025 the Initial Developer. All Rights Reserved. Contributor(s): Mark J Crane */ //includes files require_once dirname(__DIR__, 2) . "/resources/require.php"; //if config.conf file does not exist then redirect to the install page if (file_exists("/usr/local/etc/fusionpbx/config.conf")){ //BSD } elseif (file_exists("/etc/fusionpbx/config.conf")){ //Linux } elseif (file_exists(getenv('SystemDrive') . DIRECTORY_SEPARATOR . 'ProgramData' . DIRECTORY_SEPARATOR . 'fusionpbx' . DIRECTORY_SEPARATOR . 'config.conf')) { // Windows } else { header("Location: /core/install/install.php"); exit; } //additional includes require_once "resources/check_auth.php"; //disable login message if (isset($_GET['msg']) && $_GET['msg'] == 'dismiss') { unset($_SESSION['login']['message']); $sql = "update v_default_settings "; $sql .= "set default_setting_enabled = false "; $sql .= "where "; $sql .= "default_setting_category = 'login' "; $sql .= "and default_setting_subcategory = 'message' "; $sql .= "and default_setting_name = 'text' "; $database->execute($sql); unset($sql); } //build a list of groups the user is a member of to be used in a SQL in if (is_array($_SESSION['user']['groups'])) { foreach ($_SESSION['user']['groups'] as $group) { $group_uuids[] = $group['group_uuid']; } } if (is_array($group_uuids)) { $group_uuids_in = "'".implode("','", $group_uuids)."'"; } //get the dashboard uuid $sql = "select dashboard_uuid "; $sql .= "from v_dashboards "; $sql .= "where dashboard_enabled = true "; $sql .= "and ("; $sql .= " domain_uuid = :domain_uuid "; $sql .= " or domain_uuid is null "; $sql .= ") "; if (!empty($_GET['name'])) { $sql .= "and dashboard_name = :dashboard_name "; $parameters['dashboard_name'] = $_GET['name']; } $sql .= "order by case when domain_uuid = :domain_uuid then 0 else 1 end "; $parameters['domain_uuid'] = $_SESSION['domain_uuid']; $result = $database->select($sql, $parameters ?? null, 'all'); $dashboard_uuid = $result[0]['dashboard_uuid'] ?? null; unset($sql, $parameters); //get the list $sql = "select "; $sql .= "dashboard_uuid, "; $sql .= "dashboard_widget_uuid, "; $sql .= "widget_name, "; $sql .= "widget_path, "; $sql .= "widget_icon, "; $sql .= "widget_icon_color, "; $sql .= "widget_url, "; $sql .= "widget_target, "; $sql .= "widget_width, "; $sql .= "widget_height, "; $sql .= "widget_content, "; $sql .= "widget_content_text_align, "; $sql .= "widget_content_details, "; $sql .= "widget_chart_type, "; $sql .= "widget_label_enabled, "; $sql .= "widget_label_text_color, "; $sql .= "widget_label_text_color_hover, "; $sql .= "widget_label_background_color, "; $sql .= "widget_label_background_color_hover, "; $sql .= "widget_number_text_color, "; $sql .= "widget_number_text_color_hover, "; $sql .= "widget_number_background_color, "; $sql .= "widget_background_color, "; $sql .= "widget_background_color_hover, "; $sql .= "widget_detail_background_color, "; $sql .= "widget_background_gradient_style, "; $sql .= "widget_background_gradient_angle, "; $sql .= "widget_column_span, "; $sql .= "widget_row_span, "; $sql .= "widget_details_state, "; $sql .= "dashboard_widget_parent_uuid, "; $sql .= "widget_order, "; $sql .= "cast(widget_enabled as text), "; $sql .= "widget_description "; $sql .= "from v_dashboard_widgets as d "; $sql .= "where widget_enabled = true "; $sql .= "and dashboard_widget_uuid in ( "; $sql .= " select dashboard_widget_uuid from v_dashboard_widget_groups where group_uuid in ( "; $sql .= " ".$group_uuids_in." "; $sql .= " ) "; $sql .= ") "; $sql .= "and dashboard_uuid = :dashboard_uuid "; $sql .= "order by widget_order, widget_name asc "; $parameters['dashboard_uuid'] = $dashboard_uuid; $widgets = $database->select($sql, $parameters ?? null, 'all'); unset($sql, $parameters); //get the list of widget uuids $widget_uuid_list = []; foreach ($widgets as $row) { $widget_uuid_list[] = $row['dashboard_widget_uuid']; } //get http post variables and set them to php variables if (count($_POST) > 0 && permission_exists('dashboard_edit')) { //set the variables from the http values if (isset($_POST["widget_order"])) { $widget_order = explode(",", $_POST["widget_order"]); $x = 0; foreach ($widget_order as $widget) { list($widget_id, $parent_id, $order) = explode("|", $widget); $parent_uuid = null; foreach ($widgets as $row) { $dashboard_widget_id = 'id_'.md5(preg_replace('/[^-A-Fa-f0-9]/', '', $row['dashboard_widget_uuid'])); if ($widget_id == $dashboard_widget_id) { if (!empty($parent_id)) { //find parent uuid foreach ($widgets as $parent_row) { $parent_widget_id = 'id_'.md5(preg_replace('/[^-A-Fa-f0-9]/', '', $parent_row['dashboard_widget_uuid'])); if ($parent_widget_id === $parent_id) { $parent_uuid = $parent_row['dashboard_widget_uuid']; break; } } } $array['dashboard_widgets'][$x]['dashboard_widget_uuid'] = $row['dashboard_widget_uuid']; $array['dashboard_widgets'][$x]['widget_name'] = $row['widget_name']; $array['dashboard_widgets'][$x]['widget_icon'] = $row['widget_icon']; $array['dashboard_widgets'][$x]['widget_url'] = $row['widget_url']; $array['dashboard_widgets'][$x]['widget_content'] = $row['widget_content']; $array['dashboard_widgets'][$x]['widget_content_text_align'] = $row['widget_content_text_align']; $array['dashboard_widgets'][$x]['widget_content_details'] = $row['widget_content_details']; $array['dashboard_widgets'][$x]['widget_target'] = $row['widget_target']; $array['dashboard_widgets'][$x]['widget_width'] = $row['widget_width']; $array['dashboard_widgets'][$x]['widget_height'] = $row['widget_height']; $array['dashboard_widgets'][$x]['widget_order'] = $order; $array['dashboard_widgets'][$x]['dashboard_widget_parent_uuid'] = $parent_uuid; $x++; break; } } } //save the data if (is_array($array)) { $database->save($array); } //redirect the browser message::add($text['message-update']); header("Location: /core/dashboard/".(!empty($_GET['name']) ? "?name=".urlencode($_GET['name']) : null)); return; } } //add multi-lingual support $language = new text; $text = $language->get(); //add the settings object $settings = new settings(["domain_uuid" => $_SESSION['domain_uuid'], "user_uuid" => $_SESSION['user_uuid']]); //load the header $document['title'] = $text['title-dashboard']; require_once "resources/header.php"; //include websockets $version = md5(file_get_contents(__DIR__ . '/resources/javascript/ws_client.js')); echo "\n"; //include sortablejs echo ""; //include chart.js echo ""; echo ""; echo ""; //chart variables echo "\n"; //determine initial state all button to display $expanded_all = true; if (!empty($widgets)) { foreach ($widgets as $row) { if ($row['widget_details_state'] == 'contracted' || $row['widget_details_state'] == 'hidden' || $row['widget_details_state'] == 'disabled') { $expanded_all = false; } } } //show the content echo "
\n"; echo "
".$text['title-dashboard']."
\n"; echo "
\n"; echo "
\n"; if ($settings->get('theme', 'menu_style', '') != 'side') { echo " ".$text['label-welcome']." ".$_SESSION["username"]."   "; } if (permission_exists('dashboard_edit')) { echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$settings->get('theme', 'button_icon_back'),'id'=>'btn_back','name'=>'btn_back','style'=>'display: none;','onclick'=>"edit_mode('off');"]); echo button::create(['type'=>'submit','label'=>$text['button-save'],'icon'=>$settings->get('theme', 'button_icon_save'),'id'=>'btn_save','name'=>'btn_save','style'=>'display: none; margin-left: 15px;']); } echo "\n"; echo button::create(['type'=>'button','label'=>$text['button-expand_all'],'icon'=>$settings->get('theme', 'button_icon_expand'),'id'=>'btn_expand','name'=>'btn_expand','style'=>($expanded_all ? 'display: none;' : null),'onclick'=>"$('.hud_details').slideDown('fast'); $(this).hide(); $('#btn_contract').show(); toggle_grid_row_span_all();"]); echo button::create(['type'=>'button','label'=>$text['button-collapse_all'],'icon'=>$settings->get('theme', 'button_icon_contract'),'id'=>'btn_contract','name'=>'btn_contract','style'=>(!$expanded_all ? 'display: none;' : null),'onclick'=>"$('.hud_details').slideUp('fast'); $(this).hide(); $('#btn_expand').show(); toggle_grid_row_span_all();"]); echo "\n"; if (permission_exists('dashboard_edit')) { echo button::create(['type'=>'button','label'=>$text['button-edit'],'icon'=>$settings->get('theme', 'button_icon_edit'),'id'=>'btn_edit','name'=>'btn_edit','style'=>'margin-left: 15px;','onclick'=>"edit_mode('on');"]); echo button::create(['type'=>'button','label'=>$text['button-settings'],'icon'=>$settings->get('theme', 'button_icon_add'),'id'=>'btn_add','name'=>'btn_add','link'=>'dashboard.php']); } echo " \n"; echo "
\n"; echo "
\n"; echo "
\n"; echo "
\n"; //display login message //if (if_group("superadmin") && !empty($settings->get('login', 'message')) && $settings->get('login', 'message') != '') { // echo "
".$text['login-message_attention']."  ".$settings->get('login', 'message')."  (".$text['login-message_dismiss'].")
\n"; //} ?> \n"; $x = 0; foreach ($widgets as $row) { //skip child widgets unless the parent doesn't exist if (!empty($row['dashboard_widget_parent_uuid']) && in_array($row['dashboard_widget_parent_uuid'], $widget_uuid_list)) { continue; } //set the variables $widget_uuid = $row['dashboard_widget_uuid'] ?? ''; $widget_name = $row['widget_name'] ?? ''; $widget_icon = $row['widget_icon'] ?? ''; $widget_url = $row['widget_url'] ?? ''; $widget_target = $row['widget_target'] ?? ''; $widget_width = $row['widget_width'] ?? ''; $widget_height = $row['widget_height'] ?? ''; $widget_content = $row['widget_content'] ?? ''; $widget_content_text_align = $row['widget_content_text_align'] ?? ''; $widget_content_details = $row['widget_content_details'] ?? ''; $widget_chart_type = $row['widget_chart_type'] ?? ''; $widget_label_text_color = $row['widget_label_text_color'] ?? $settings->get('theme', 'dashboard_label_text_color', ''); $widget_number_text_color = $row['widget_number_text_color'] ?? $settings->get('theme', 'dashboard_number_text_color', ''); $widget_number_background_color = $row['widget_number_background_color'] ?? $settings->get('theme', 'dashboard_number_background_color', ''); $widget_details_state = $row['widget_details_state'] ?? 'disabled'; $widget_row_span = $row['widget_row_span'] ?? ''; //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 $widget_uuid = preg_replace($uuid_pattern, '', $widget_uuid); $widget_id = 'id_'.md5($widget_uuid); $widget_name = trim(preg_replace($text_pattern, '', $widget_name)); $widget_icon = preg_replace($text_pattern, '', $widget_icon); $widget_url = trim(preg_replace($text_pattern, '', $widget_url)); $widget_target = trim(preg_replace($text_pattern, '', $widget_target)); $widget_width = trim(preg_replace($text_pattern, '', $widget_width)); $widget_height = trim(preg_replace($text_pattern, '', $widget_height)); $widget_content = preg_replace($text_pattern, '', $widget_content); $widget_content = str_replace("\n", '
', $widget_content); $widget_content_text_align = trim(preg_replace($text_pattern, '', $widget_content_text_align)); $widget_content_details = preg_replace($text_pattern, '', $widget_content_details); $widget_content_details = str_replace("\n", '
', $widget_content_details); $widget_chart_type = preg_replace($text_pattern, '', $widget_chart_type); $widget_label_text_color = preg_replace($text_pattern, '', $widget_label_text_color); $widget_number_text_color = preg_replace($text_pattern, '', $widget_number_text_color); $widget_number_background_color = preg_replace($text_pattern, '', $widget_number_background_color); $widget_details_state = preg_replace($text_pattern, '', $widget_details_state); $widget_row_span = preg_replace($number_pattern, '', $widget_row_span); $widget_path = preg_replace($text_pattern, '', strtolower($row['widget_path'])); //find the application and widget $widget_path_array = explode('/', $widget_path); $application_name = $widget_path_array[0]; $widget_path_name = $widget_path_array[1]; $path_array = glob(dirname(__DIR__, 2).'/*/'.$application_name.'/resources/dashboard/'.$widget_path_name.'.php'); echo "
\n"; if (file_exists($path_array[0])) { include $path_array[0]; } echo "
\n"; $x++; } echo "\n"; //begin edit if (permission_exists('dashboard_edit')) { ?>