2019-04-09 15:53:22 +02:00
< ? php
2019-09-27 15:44:39 +02:00
/**
2021-05-27 14:55:01 +02:00
* Actual View script for Visual Consoles .
2019-09-27 15:44:39 +02:00
*
2021-05-27 14:55:01 +02:00
* @ category Operation
2019-09-27 15:44:39 +02:00
* @ package Pandora FMS
* @ subpackage Community
* @ version 1.0 . 0
* @ license See below
*
* ______ ___ _______ _______ ________
* | __ \ .-----.--.--.--| |.-----.----.-----. | ___ | | | __ |
* | __ /| _ | | _ || _ | _ | _ | | ___ | | __ |
* | ___ | | ___ . _ | __ | __ | _____ || _____ | __ | | ___ . _ | | ___ | | __ | _ | __ | _______ |
*
* ============================================================================
2020-11-27 13:52:35 +01:00
* Copyright ( c ) 2005 - 2021 Artica Soluciones Tecnologicas
2019-09-27 15:44:39 +02:00
* Please see http :// pandorafms . org for full contribution list
* This program is free software ; you can redistribute it and / or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation for version 2.
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
* ============================================================================
*/
2019-04-09 15:53:22 +02:00
2021-05-27 14:55:01 +02:00
// Begin.
2019-04-09 15:53:22 +02:00
global $config ;
// Login check.
check_login ();
require_once $config [ 'homedir' ] . '/vendor/autoload.php' ;
require_once $config [ 'homedir' ] . '/include/functions_visual_map.php' ;
2019-10-03 11:05:21 +02:00
2019-09-27 15:44:39 +02:00
/**
* Function for return button visual console edition .
*
* @ param string $idDiv Id button .
* @ param string $label Label and title button .
* @ param string $class Class button .
* @ param boolean $disabled Disabled button .
*
* @ return void Retun button .
*/
function visual_map_print_button_editor_refactor (
$idDiv ,
$label ,
$class = '' ,
$disabled = false
) {
2021-03-11 15:40:23 +01:00
global $config ;
2019-09-27 15:44:39 +02:00
html_print_button (
$label ,
$idDiv ,
$disabled ,
'' ,
2021-03-11 15:40:23 +01:00
'class=" sub visual_editor_button_toolbox ' . $idDiv . ' ' . $class . '"' ,
2019-09-27 15:44:39 +02:00
false ,
true
);
}
2019-06-24 17:57:45 +02:00
ui_require_css_file ( 'visual_maps' );
2020-01-23 17:52:59 +01:00
ui_require_css_file ( 'register' );
2019-06-24 17:57:45 +02:00
2019-04-09 16:36:31 +02:00
// Query parameters.
$visualConsoleId = ( int ) get_parameter ( ! is_metaconsole () ? 'id' : 'id_visualmap' );
2019-04-12 14:23:33 +02:00
// To hide the menus.
2019-04-09 16:36:31 +02:00
$pure = ( bool ) get_parameter ( 'pure' , $config [ 'pure' ]);
2019-04-12 14:23:33 +02:00
// Refresh interval in seconds.
$refr = ( int ) get_parameter ( 'refr' , $config [ 'vc_refr' ]);
2019-04-09 15:53:22 +02:00
2021-06-29 12:02:13 +02:00
$width = ( int ) get_parameter ( 'width' , 0 );
$height = ( int ) get_parameter ( 'height' , 0 );
2019-04-12 09:51:53 +02:00
// Load Visual Console.
use Models\VisualConsole\Container as VisualConsole ;
$visualConsole = null ;
try {
$visualConsole = VisualConsole :: fromDB ([ 'id' => $visualConsoleId ]);
} catch ( Throwable $e ) {
2019-04-09 15:53:22 +02:00
db_pandora_audit (
2022-01-20 10:55:23 +01:00
AUDIT_LOG_ACL_VIOLATION ,
2019-04-12 09:51:53 +02:00
'Trying to access visual console without Id'
2019-04-09 15:53:22 +02:00
);
include 'general/noaccess.php' ;
exit ;
}
2019-04-12 09:51:53 +02:00
$visualConsoleData = $visualConsole -> toArray ();
$groupId = $visualConsoleData [ 'groupId' ];
2021-05-27 14:55:01 +02:00
$visualConsoleName = io_safe_input ( strip_tags ( io_safe_output ( $visualConsoleData [ 'name' ])));
2019-04-09 15:53:22 +02:00
// ACL.
2021-05-27 14:55:01 +02:00
$aclRead = ( bool ) check_acl_restricted_all ( $config [ 'id_user' ], $groupId , 'VR' );
$aclWrite = ( bool ) check_acl_restricted_all ( $config [ 'id_user' ], $groupId , 'VW' );
$aclManage = ( bool ) check_acl_restricted_all ( $config [ 'id_user' ], $groupId , 'VM' );
2019-04-09 15:53:22 +02:00
2022-10-13 11:03:49 +02:00
// Maintenance Mode.
$maintenanceMode = $visualConsoleData [ 'maintenanceMode' ];
2021-05-27 14:55:01 +02:00
if ( $aclRead === false && $aclWrite === false && $aclManage === false ) {
2019-04-09 15:53:22 +02:00
db_pandora_audit (
2022-01-20 10:55:23 +01:00
AUDIT_LOG_ACL_VIOLATION ,
2019-04-09 15:53:22 +02:00
'Trying to access visual console without group access'
);
include 'general/noaccess.php' ;
exit ;
}
// Render map.
$options = [];
2019-04-09 16:36:31 +02:00
$options [ 'consoles_list' ][ 'text' ] = '<a href="index.php?sec=network&sec2=godmode/reporting/map_builder">' . html_print_image (
2019-04-09 15:53:22 +02:00
'images/visual_console.png' ,
true ,
2021-03-11 15:40:23 +01:00
[
'title' => __ ( 'Visual consoles list' ),
'class' => 'invert_filter' ,
]
2019-04-09 15:53:22 +02:00
) . '</a>' ;
2021-05-27 14:55:01 +02:00
if ( $aclWrite === true || $aclManage === true ) {
2019-04-12 13:22:13 +02:00
$action = get_parameterBetweenListValues (
2021-05-27 14:55:01 +02:00
( is_metaconsole () === true ) ? 'action2' : 'action' ,
2019-04-12 13:22:13 +02:00
[
'new' ,
'save' ,
'edit' ,
'update' ,
'delete' ,
],
'edit'
);
$baseUrl = 'index.php?sec=network&sec2=godmode/reporting/visual_console_builder&action=' . $action ;
2019-04-09 15:53:22 +02:00
2019-04-09 16:36:31 +02:00
$hash = md5 ( $config [ 'dbpass' ] . $visualConsoleId . $config [ 'id_user' ]);
2019-04-09 15:53:22 +02:00
$options [ 'public_link' ][ 'text' ] = '<a href="' . ui_get_full_url (
2019-07-08 17:51:01 +02:00
'operation/visual_console/public_console.php?hash=' . $hash . '&id_layout=' . $visualConsoleId . '&refr=' . $refr . '&id_user=' . $config [ 'id_user' ]
2019-04-09 15:53:22 +02:00
) . '" target="_blank">' . html_print_image (
'images/camera_mc.png' ,
true ,
2021-03-11 15:40:23 +01:00
[
'title' => __ ( 'Show link to public Visual Console' ),
'class' => 'invert_filter' ,
]
2019-04-09 15:53:22 +02:00
) . '</a>' ;
$options [ 'public_link' ][ 'active' ] = false ;
2019-04-12 13:22:13 +02:00
$options [ 'data' ][ 'text' ] = '<a href="' . $baseUrl . '&tab=data&id_visual_console=' . $visualConsoleId . '">' . html_print_image (
2019-04-09 15:53:22 +02:00
'images/op_reporting.png' ,
true ,
2021-03-11 15:40:23 +01:00
[
'title' => __ ( 'Main data' ),
'class' => 'invert_filter' ,
]
2019-04-09 15:53:22 +02:00
) . '</a>' ;
2019-04-12 13:22:13 +02:00
$options [ 'list_elements' ][ 'text' ] = '<a href="' . $baseUrl . '&tab=list_elements&id_visual_console=' . $visualConsoleId . '">' . html_print_image (
2019-04-09 15:53:22 +02:00
'images/list.png' ,
true ,
2021-03-11 15:40:23 +01:00
[
'title' => __ ( 'List elements' ),
'class' => 'invert_filter' ,
]
2019-04-09 15:53:22 +02:00
) . '</a>' ;
2021-05-27 14:55:01 +02:00
if ( enterprise_installed () === true ) {
2019-04-12 13:22:13 +02:00
$options [ 'wizard_services' ][ 'text' ] = '<a href="' . $baseUrl . '&tab=wizard_services&id_visual_console=' . $visualConsoleId . '">' . html_print_image (
2019-04-09 15:53:22 +02:00
'images/wand_services.png' ,
true ,
2021-03-11 15:40:23 +01:00
[
'title' => __ ( 'Services wizard' ),
'class' => 'invert_filter' ,
]
2019-04-09 15:53:22 +02:00
) . '</a>' ;
}
2019-04-12 13:22:13 +02:00
$options [ 'wizard' ][ 'text' ] = '<a href="' . $baseUrl . '&tab=wizard&id_visual_console=' . $visualConsoleId . '">' . html_print_image (
2019-04-09 15:53:22 +02:00
'images/wand.png' ,
true ,
2021-03-11 15:40:23 +01:00
[
'title' => __ ( 'Wizard' ),
'class' => 'invert_filter' ,
]
2019-04-09 15:53:22 +02:00
) . '</a>' ;
}
2019-05-20 15:15:54 +02:00
$options [ 'view' ][ 'text' ] = '<a href="index.php?sec=network&sec2=operation/visual_console/render_view&id=' . $visualConsoleId . '&refr=' . $refr . '">' . html_print_image (
2021-03-29 12:20:27 +02:00
'images/eye.png' ,
2019-04-12 14:23:33 +02:00
true ,
2021-03-11 15:40:23 +01:00
[
'title' => __ ( 'View' ),
'class' => 'invert_filter' ,
]
2019-04-12 14:23:33 +02:00
) . '</a>' ;
2019-04-09 15:53:22 +02:00
$options [ 'view' ][ 'active' ] = true ;
2019-04-09 16:36:31 +02:00
2021-04-30 13:24:55 +02:00
if ( is_metaconsole () === false ) {
2019-04-09 15:53:22 +02:00
if ( ! $config [ 'pure' ]) {
2021-06-29 12:02:13 +02:00
$options [ 'pure' ][ 'text' ] = '<a id ="full_screen" href="index.php?sec=network&sec2=operation/visual_console/render_view&id=' . $visualConsoleId . '&pure=1&refr=' . $refr . '">' . html_print_image (
2019-04-12 14:23:33 +02:00
'images/full_screen.png' ,
true ,
2021-03-11 15:40:23 +01:00
[
'title' => __ ( 'Full screen mode' ),
'class' => 'invert_filter' ,
]
2019-04-12 14:23:33 +02:00
) . '</a>' ;
2021-04-30 13:24:55 +02:00
// Header.
ui_print_standard_header (
2019-04-09 16:36:31 +02:00
$visualConsoleName ,
'images/visual_console.png' ,
false ,
2020-05-29 11:37:06 +02:00
'visual_console_view' ,
2019-04-09 16:36:31 +02:00
false ,
2021-04-30 13:24:55 +02:00
$options ,
[
[
'link' => '' ,
'label' => __ ( 'Topology maps' ),
],
[
'link' => '' ,
'label' => __ ( 'Visual console' ),
],
]
2019-04-09 16:36:31 +02:00
);
2019-04-09 15:53:22 +02:00
}
// Set the hidden value for the javascript.
html_print_input_hidden ( 'metaconsole' , 0 );
} else {
// Set the hidden value for the javascript.
html_print_input_hidden ( 'metaconsole' , 1 );
}
2020-02-03 17:08:37 +01:00
$edit_capable = ( bool ) (
check_acl ( $config [ 'id_user' ], 0 , 'VM' )
|| check_acl ( $config [ 'id_user' ], 0 , 'VW' )
);
2019-06-04 17:34:40 +02:00
if ( $pure === false ) {
2020-02-03 17:08:37 +01:00
if ( $edit_capable === true ) {
echo '<div id ="edit-vc">' ;
echo '<div id ="edit-controls" class="visual-console-edit-controls" style="visibility:hidden">' ;
echo '<div>' ;
2021-03-18 17:32:21 +01:00
$class_camera = 'camera_min link-create-item' ;
$class_percentile = 'percentile_item_min link-create-item' ;
$class_module_graph = 'graph_min link-create-item' ;
$class_donut = 'donut_graph_min link-create-item' ;
$class_bars = 'bars_graph_min link-create-item' ;
$class_value = 'binary_min link-create-item' ;
$class_sla = 'auto_sla_graph_min link-create-item' ;
$class_label = 'label_min link-create-item' ;
$class_icon = 'icon_min link-create-item' ;
$class_clock = 'clock_min link-create-item' ;
$class_group = 'group_item_min link-create-item' ;
$class_box = 'box_item link-create-item' ;
$class_line = 'line_item link-create-item' ;
$class_cloud = 'color_cloud_min link-create-item' ;
$class_nlink = 'network_link_min link-create-item' ;
2021-07-12 12:27:10 +02:00
$class_odometer = 'odometer_min link-create-item' ;
2021-07-16 14:16:45 +02:00
$class_basic_chart = 'basic_chart_min link-create-item' ;
2021-03-18 17:32:21 +01:00
$class_delete = 'delete_item delete_min' ;
$class_copy = 'copy_item' ;
2022-01-17 10:22:30 +01:00
if ( $config [ 'style' ] === 'pandora_black' && ! is_metaconsole ()) {
2021-03-18 17:32:21 +01:00
$class_camera = 'camera_min_white link-create-item' ;
$class_percentile = 'percentile_item_min_white link-create-item' ;
$class_module_graph = 'graph_min_white link-create-item' ;
$class_donut = 'donut_graph_min_white link-create-item' ;
$class_bars = 'bars_graph_min_white link-create-item' ;
$class_value = 'binary_min_white link-create-item' ;
$class_sla = 'auto_sla_graph_min_white link-create-item' ;
$class_label = 'label_min_white link-create-item' ;
$class_icon = 'icon_min_white link-create-item' ;
$class_clock = 'clock_min_white link-create-item' ;
$class_group = 'group_item_min_white link-create-item' ;
$class_box = 'box_item_white link-create-item' ;
$class_line = 'line_item_white link-create-item' ;
$class_cloud = 'color_cloud_min_white link-create-item' ;
$class_nlink = 'network_link_min_white link-create-item' ;
2021-07-12 12:27:10 +02:00
$class_odometer = 'odometer_min_white link-create-item' ;
2021-07-16 14:16:45 +02:00
$class_basic_chart = 'basic_chart_min_white link-create-item' ;
2021-03-18 17:32:21 +01:00
$class_delete = 'delete_item_white delete_min_white' ;
$class_copy = 'copy_item_white' ;
}
2019-09-27 15:44:39 +02:00
visual_map_print_button_editor_refactor (
2019-10-02 12:28:17 +02:00
'STATIC_GRAPH' ,
2019-09-27 15:44:39 +02:00
__ ( 'Static Image' ),
2021-03-18 17:32:21 +01:00
$class_camera
2019-09-27 15:44:39 +02:00
);
visual_map_print_button_editor_refactor (
2019-10-02 12:28:17 +02:00
'PERCENTILE_BAR' ,
2019-09-27 15:44:39 +02:00
__ ( 'Percentile Item' ),
2021-03-18 17:32:21 +01:00
$class_percentile
2019-09-27 15:44:39 +02:00
);
visual_map_print_button_editor_refactor (
2019-10-02 12:28:17 +02:00
'MODULE_GRAPH' ,
2019-09-27 15:44:39 +02:00
__ ( 'Module Graph' ),
2021-03-18 17:32:21 +01:00
$class_module_graph
2019-09-27 15:44:39 +02:00
);
2021-07-16 14:16:45 +02:00
visual_map_print_button_editor_refactor (
'BASIC_CHART' ,
__ ( 'Basic chart' ),
$class_basic_chart
);
2019-09-27 15:44:39 +02:00
visual_map_print_button_editor_refactor (
2019-10-02 12:28:17 +02:00
'DONUT_GRAPH' ,
2019-09-27 15:44:39 +02:00
__ ( 'Serialized pie graph' ),
2021-03-18 17:32:21 +01:00
$class_donut
2019-09-27 15:44:39 +02:00
);
visual_map_print_button_editor_refactor (
2019-10-02 12:28:17 +02:00
'BARS_GRAPH' ,
2019-09-27 15:44:39 +02:00
__ ( 'Bars Graph' ),
2021-03-18 17:32:21 +01:00
$class_bars
2019-09-27 15:44:39 +02:00
);
visual_map_print_button_editor_refactor (
2019-10-02 12:28:17 +02:00
'AUTO_SLA_GRAPH' ,
2020-01-23 19:54:47 +01:00
__ ( 'Event history graph' ),
2021-03-18 17:32:21 +01:00
$class_sla
2019-09-27 15:44:39 +02:00
);
visual_map_print_button_editor_refactor (
2019-10-02 12:28:17 +02:00
'SIMPLE_VALUE' ,
2019-09-27 15:44:39 +02:00
__ ( 'Simple Value' ),
2021-03-18 17:32:21 +01:00
$class_value
2019-09-27 15:44:39 +02:00
);
visual_map_print_button_editor_refactor (
2019-10-02 12:28:17 +02:00
'LABEL' ,
2019-09-27 15:44:39 +02:00
__ ( 'Label' ),
2021-03-18 17:32:21 +01:00
$class_label
2019-09-27 15:44:39 +02:00
);
visual_map_print_button_editor_refactor (
2019-10-02 12:28:17 +02:00
'ICON' ,
2019-09-27 15:44:39 +02:00
__ ( 'Icon' ),
2021-03-18 17:32:21 +01:00
$class_icon
2019-09-27 15:44:39 +02:00
);
visual_map_print_button_editor_refactor (
2019-10-02 12:28:17 +02:00
'CLOCK' ,
2019-09-27 15:44:39 +02:00
__ ( 'Clock' ),
2021-03-18 17:32:21 +01:00
$class_clock
2019-09-27 15:44:39 +02:00
);
visual_map_print_button_editor_refactor (
2019-10-02 12:28:17 +02:00
'GROUP_ITEM' ,
2019-09-27 15:44:39 +02:00
__ ( 'Group' ),
2021-03-18 17:32:21 +01:00
$class_group
2019-09-27 15:44:39 +02:00
);
visual_map_print_button_editor_refactor (
2019-10-02 12:28:17 +02:00
'BOX_ITEM' ,
2019-09-27 15:44:39 +02:00
__ ( 'Box' ),
2021-03-18 17:32:21 +01:00
$class_box
2019-09-27 15:44:39 +02:00
);
visual_map_print_button_editor_refactor (
2019-10-02 12:28:17 +02:00
'LINE_ITEM' ,
2019-09-27 15:44:39 +02:00
__ ( 'Line' ),
2021-03-18 17:32:21 +01:00
$class_line
2019-09-27 15:44:39 +02:00
);
visual_map_print_button_editor_refactor (
2019-10-02 12:28:17 +02:00
'COLOR_CLOUD' ,
2019-09-27 15:44:39 +02:00
__ ( 'Color cloud' ),
2021-03-18 17:32:21 +01:00
$class_cloud
2019-09-27 15:44:39 +02:00
);
2020-10-09 12:45:10 +02:00
visual_map_print_button_editor_refactor (
'NETWORK_LINK' ,
__ ( 'Network link' ),
2021-03-18 17:32:21 +01:00
$class_nlink
2020-10-09 12:45:10 +02:00
);
2021-07-12 12:27:10 +02:00
visual_map_print_button_editor_refactor (
'ODOMETER' ,
__ ( 'Odometer' ),
$class_odometer
);
2020-01-22 17:47:47 +01:00
enterprise_include_once ( 'include/functions_visual_map_editor.php' );
enterprise_hook (
'enterprise_visual_map_editor_print_toolbox_refactor'
);
2020-02-03 17:08:37 +01:00
echo '</div>' ;
echo '<div class="visual-console-copy-delete">' ;
visual_map_print_button_editor_refactor (
'button_delete' ,
__ ( 'Delete Item' ),
2021-03-18 17:32:21 +01:00
$class_delete ,
2020-02-03 17:08:37 +01:00
true
);
visual_map_print_button_editor_refactor (
'button_copy' ,
__ ( 'Copy Item' ),
2021-03-18 17:32:21 +01:00
$class_copy ,
2020-02-03 17:08:37 +01:00
true
);
echo '</div>' ;
echo '</div>' ;
2021-01-20 18:22:43 +01:00
2021-05-27 14:55:01 +02:00
if ( $aclWrite === true || $aclManage === true ) {
2022-10-13 11:03:49 +02:00
echo '<div class="flex-row" style="width:220px;">' ;
if ( is_metaconsole () === false ) {
echo '<div id="force_check_control" class="flex-column">' ;
echo html_print_label ( __ ( 'Force' ), 'force-mode' , true );
echo '<a id ="force_check" href="">' ;
echo html_print_image (
2021-12-21 09:33:55 +01:00
'images/target.png' ,
true ,
[
'title' => __ ( 'Force remote checks' ),
'class' => 'invert_filter' ,
]
2022-10-13 11:03:49 +02:00
);
echo '</a>' ;
echo '</div>' ;
2021-12-21 09:33:55 +01:00
}
2022-10-13 17:45:44 +02:00
$disabled_edit_mode = false ;
2022-10-13 11:03:49 +02:00
if ( $aclManage === true ) {
$value_maintenance_mode = true ;
if ( $maintenanceMode === null ) {
$value_maintenance_mode = false ;
} else {
if ( $maintenanceMode [ 'user' ] !== $config [ 'id_user' ]) {
2022-10-13 17:45:44 +02:00
$disabled_edit_mode = true ;
2022-10-13 11:03:49 +02:00
}
}
2022-10-13 17:45:44 +02:00
echo '<div id="maintenance-mode-control" class="flex-column">' ;
2022-10-13 11:03:49 +02:00
echo html_print_label (
2022-10-13 17:45:44 +02:00
__ ( 'Maintenance' ),
2022-10-13 11:03:49 +02:00
'maintenance-mode' ,
true
);
echo html_print_checkbox_switch (
'maintenance-mode' ,
1 ,
$value_maintenance_mode ,
true
);
echo '</div>' ;
}
2022-10-13 17:45:44 +02:00
echo '<div id="edit-mode-control" class="flex-column">' ;
echo html_print_label ( __ ( 'Edit' ), 'edit-mode' , true );
echo html_print_checkbox_switch ( 'edit-mode' , 1 , false , true , $disabled_edit_mode );
2022-10-13 11:03:49 +02:00
echo '</div>' ;
echo '</div>' ;
2021-01-20 18:22:43 +01:00
}
2020-02-03 17:08:37 +01:00
echo '</div>' ;
}
2019-06-04 17:34:40 +02:00
}
2019-06-04 17:21:54 +02:00
2021-03-18 10:35:19 +01:00
$bg_color = '' ;
2022-01-17 10:22:30 +01:00
if ( $config [ 'style' ] === 'pandora_black' && ! is_metaconsole ()) {
2021-03-18 10:35:19 +01:00
$bg_color = 'style="background-color: #222"' ;
}
2021-03-24 12:43:51 +01:00
echo '<div class="external-visual-console-container">' ;
2019-04-12 09:51:53 +02:00
echo '<div id="visual-console-container"></div>' ;
2021-03-24 12:43:51 +01:00
echo '</div>' ;
2019-04-09 15:53:22 +02:00
2019-04-09 16:36:31 +02:00
if ( $pure === true ) {
// Floating menu - Start.
2021-03-18 10:35:19 +01:00
echo '<div id="vc-controls" class="zindex999" ' . $bg_color . '>' ;
2019-04-09 15:53:22 +02:00
echo '<div id="menu_tab">' ;
2019-06-21 12:41:05 +02:00
echo '<ul class="mn white-box-content box-shadow flex-row">' ;
2019-04-09 15:53:22 +02:00
2019-04-09 16:36:31 +02:00
// Quit fullscreen.
2019-04-09 15:53:22 +02:00
echo '<li class="nomn">' ;
2021-05-27 14:55:01 +02:00
if ( is_metaconsole () === true ) {
2020-02-12 17:05:29 +01:00
$urlNoFull = 'index.php?sec=screen&sec2=screens/screens&action=visualmap&pure=0&id_visualmap=' . $visualConsoleId . '&refr=' . $refr ;
} else {
$urlNoFull = 'index.php?sec=network&sec2=operation/visual_console/render_view&id=' . $visualConsoleId . '&refr=' . $refr ;
}
2019-04-12 12:44:45 +02:00
echo '<a class="vc-btn-no-fullscreen" href="' . $urlNoFull . '">' ;
2021-03-11 15:40:23 +01:00
echo html_print_image ( 'images/normal_screen.png' , true , [ 'title' => __ ( 'Back to normal mode' ), 'class' => 'invert_filter' ]);
2019-04-09 15:53:22 +02:00
echo '</a>' ;
echo '</li>' ;
2019-04-29 12:09:40 +02:00
// Countdown.
echo '<li class="nomn">' ;
2021-05-27 14:55:01 +02:00
if ( is_metaconsole () === true ) {
2020-02-12 17:05:29 +01:00
echo '<div class="vc-refr-meta">' ;
} else {
echo '<div class="vc-refr">' ;
}
2019-04-29 12:09:40 +02:00
echo '<div id="vc-refr-form">' ;
echo __ ( 'Refresh' ) . ':' ;
2019-05-17 14:09:30 +02:00
echo html_print_select (
get_refresh_time_array (),
'vc-refr' ,
$refr ,
'' ,
'' ,
0 ,
true ,
false ,
false
);
2019-04-29 12:09:40 +02:00
echo '</div>' ;
echo '</div>' ;
echo '</li>' ;
2019-04-09 16:36:31 +02:00
// Console name.
2019-04-09 15:53:22 +02:00
echo '<li class="nomn">' ;
2021-05-27 14:55:01 +02:00
html_print_div (
[
'class' => ( is_metaconsole () === true ) ? 'vc-title-meta' : 'vc-title' ,
'content' => $visualConsoleName ,
]
);
2020-02-12 17:05:29 +01:00
2019-04-09 15:53:22 +02:00
echo '</li>' ;
echo '</ul>' ;
echo '</div>' ;
echo '</div>' ;
2019-04-09 16:36:31 +02:00
// Floating menu - End.
2019-04-09 15:53:22 +02:00
?>
2019-04-09 16:36:31 +02:00
< style type = " text/css " >
/* Avoid the main_pure container 1000px height */
body . pure {
min - height : 100 px ;
margin : 0 px ;
height : 100 % ;
2019-04-12 09:51:53 +02:00
background - color : < ? php echo $visualConsoleData [ 'backgroundColor' ]; ?> ;
2019-04-09 16:36:31 +02:00
}
div #main_pure {
height : 100 % ;
margin : 0 px ;
2019-04-12 09:51:53 +02:00
background - color : < ? php echo $visualConsoleData [ 'backgroundColor' ]; ?> ;
2019-04-09 16:36:31 +02:00
}
</ style >
2019-04-09 15:53:22 +02:00
< ? php
}
2019-04-11 10:05:28 +02:00
2019-04-12 13:59:19 +02:00
// Check groups can access user.
$aclUserGroups = [];
2021-04-30 13:24:55 +02:00
if ( users_can_manage_group_all ( 'AR' ) === false ) {
2019-04-12 13:59:19 +02:00
$aclUserGroups = array_keys ( users_get_groups ( false , 'AR' ));
}
2019-04-29 12:09:40 +02:00
$ignored_params [ 'refr' ] = '' ;
2019-09-23 19:16:36 +02:00
ui_require_javascript_file ( 'tiny_mce' , 'include/javascript/tiny_mce/' );
2019-04-17 12:32:08 +02:00
ui_require_javascript_file ( 'pandora_visual_console' );
include_javascript_d3 ();
visual_map_load_client_resources ();
2021-06-29 12:02:13 +02:00
$widthRatio = 0 ;
if ( $width > 0 && $pure == 1 ) {
$widthRatio = ( $width / $visualConsoleData [ 'width' ]);
if ( $visualConsoleData [ 'width' ] > $height ) {
?>
< style type = " text/css " >
div #main_pure {
width : 100 % ;
}
div #visual-console-container {
width : 100 % ! important ;
}
</ style >
< ? php
} else {
?>
< style type = " text/css " >
div #main_pure {
width : 100 % ;
display : flex ;
align - items : center ;
}
div #visual-console-container {
width : 100 % ! important ;
}
</ style >
< ? php
}
}
2019-04-12 09:51:53 +02:00
// Load Visual Console Items.
2019-04-12 13:59:19 +02:00
$visualConsoleItems = VisualConsole :: getItemsFromDB (
$visualConsoleId ,
2021-06-29 12:02:13 +02:00
$aclUserGroups ,
0 ,
$widthRatio
2019-04-12 13:59:19 +02:00
);
2021-06-29 12:02:13 +02:00
2019-10-02 18:37:50 +02:00
ui_require_css_file ( 'modal' );
ui_require_css_file ( 'form' );
2019-04-09 15:53:22 +02:00
?>
2019-10-02 18:37:50 +02:00
< div id = " modalVCItemForm " ></ div >
< div id = " modalVCItemFormMsg " ></ div >
2019-04-09 15:53:22 +02:00
< script type = " text/javascript " >
var container = document . getElementById ( " visual-console-container " );
var props = < ? php echo ( string ) $visualConsole ; ?> ;
2021-05-27 14:55:01 +02:00
var items = < ? php echo '[' . implode ( ',' , $visualConsoleItems ) . ']' ; ?> ;
2019-04-22 09:40:08 +02:00
var baseUrl = " <?php echo ui_get_full_url('/', false, false, false); ?> " ;
2021-03-05 14:11:08 +01:00
var controls = document . getElementById ( 'vc-controls' );
2021-06-29 12:02:13 +02:00
2021-03-05 14:11:08 +01:00
autoHideElement ( controls , 1000 );
2019-04-11 10:05:28 +02:00
var handleUpdate = function ( prevProps , newProps ) {
2019-04-12 12:44:45 +02:00
if ( ! newProps ) return ;
2020-01-28 16:42:51 +01:00
//Remove spinner change VC.
document
. getElementById ( " visual-console-container " )
. classList . remove ( " is-updating " );
var div = document
. getElementById ( " visual-console-container " )
. querySelector ( " .div-visual-console-spinner " );
if ( div !== null ) {
var parent = div . parentElement ;
if ( parent !== null ) {
2021-03-24 12:43:51 +01:00
parent . removeChild ( div );
2020-01-28 16:42:51 +01:00
}
}
2019-04-12 12:44:45 +02:00
// Change the background color when the fullscreen mode is enabled.
if ( prevProps
&& prevProps . backgroundColor != newProps . backgroundColor
&& < ? php echo json_encode ( $pure ); ?>
) {
var pureBody = document . querySelector ( " body.pure " );
var pureContainer = document . querySelector ( " div#main_pure " );
2019-09-23 19:16:36 +02:00
2019-04-12 12:44:45 +02:00
if ( pureBody !== null ) {
pureBody . style . backgroundColor = newProps . backgroundColor
}
if ( pureContainer !== null ) {
pureContainer . style . backgroundColor = newProps . backgroundColor
}
}
// Change the title.
if ( prevProps && prevProps . name != newProps . name ) {
// View title.
var title = document . querySelector (
2022-03-21 10:04:11 +01:00
" .breadcrumbs-title "
2019-04-12 12:44:45 +02:00
);
if ( title !== null ) {
title . textContent = newProps . name ;
}
// Fullscreen view title.
var fullscreenTitle = document . querySelector ( " div.vc-title " );
if ( fullscreenTitle !== null ) {
fullscreenTitle . textContent = newProps . name ;
}
2022-03-21 10:04:11 +01:00
// Fullscreen Meta view title.
var fullscreenTitleMeta = document . querySelector ( " div.vc-title-meta " );
if ( fullscreenTitleMeta !== null ) {
fullscreenTitleMeta . textContent = newProps . name ;
}
2019-04-12 12:44:45 +02:00
}
// Change the links.
if ( prevProps && prevProps . id !== newProps . id ) {
2019-04-29 11:03:56 +02:00
var regex = / ( id =| id_visual_console =| id_layout =| id_visualmap = ) \d + ( & ? ) / gi ;
2019-04-12 12:44:45 +02:00
var replacement = '$1' + newProps . id + '$2' ;
2020-11-23 16:38:06 +01:00
var regex_hash = / ( hash = )[ ^& ] + ( & ? ) / gi ;
var replacement_hash = '$1' + newProps . hash + '$2' ;
2019-04-12 12:44:45 +02:00
// Tab links.
var menuLinks = document . querySelectorAll ( " div#menu_tab a " );
if ( menuLinks !== null ) {
menuLinks . forEach ( function ( menuLink ) {
menuLink . href = menuLink . href . replace ( regex , replacement );
2020-11-23 16:38:06 +01:00
menuLink . href = menuLink . href . replace (
regex_hash ,
replacement_hash
);
2019-04-12 12:44:45 +02:00
});
}
// Go back from fullscreen button.
var btnNoFull = document . querySelector ( " a.vc-btn-no-fullscreen " );
if ( btnNoFull !== null ) {
btnNoFull . href = btnNoFull . href . replace ( regex , replacement );
}
// Change the URL (if the browser has support).
if ( " history " in window ) {
var href = window . location . href . replace ( regex , replacement );
2020-11-23 16:38:06 +01:00
href = href . replace ( regex_hash , replacement_hash );
2019-04-12 12:44:45 +02:00
window . history . replaceState ({}, document . title , href );
}
}
2022-10-13 13:44:39 +02:00
if ( newProps . maintenanceMode != null ) {
$ ( 'input[name=maintenance-mode]' ) . prop ( 'checked' , true );
if ( newProps . maintenanceMode . user !== '<?php echo $config[' id_user ']; ?>' ) {
2022-10-13 17:45:44 +02:00
$ ( 'input[name=edit-mode]' ) . prop ( 'disabled' , true );
2022-10-13 13:44:39 +02:00
} else {
2022-10-13 17:45:44 +02:00
$ ( 'input[name=edit-mode]' ) . prop ( 'disabled' , false );
2022-10-13 13:44:39 +02:00
}
} else {
$ ( 'input[name=maintenance-mode]' ) . prop ( 'checked' , false );
2022-10-13 17:45:44 +02:00
$ ( 'input[name=edit-mode]' ) . prop ( 'disabled' , false );
2022-10-13 13:44:39 +02:00
}
2019-04-09 15:53:22 +02:00
}
2019-06-04 17:21:54 +02:00
// Add the datetime when the item was received.
var receivedAt = new Date ();
items . map ( function ( item ) {
item [ " receivedAt " ] = receivedAt ;
return item ;
});
2019-05-17 14:09:30 +02:00
var visualConsoleManager = createVisualConsole (
2019-04-11 10:05:28 +02:00
container ,
props ,
items ,
baseUrl ,
2019-04-12 10:06:53 +02:00
< ? php echo ( $refr * 1000 ); ?> ,
2022-10-13 11:03:49 +02:00
handleUpdate ,
false ,
undefined ,
'<?php echo $config[' id_user ']; ?>' ,
2019-04-11 10:05:28 +02:00
);
2022-10-13 11:03:49 +02:00
if ( props . maintenanceMode != null ) {
if ( props . maintenanceMode . user !== '<?php echo $config[' id_user ']; ?>' ) {
visualConsoleManager . visualConsole . enableMaintenanceMode ();
}
}
2020-02-03 17:08:37 +01:00
< ? php
if ( $edit_capable === true ) {
?>
2019-06-04 17:21:54 +02:00
// Enable/disable the edition mode.
$ ( 'input[name=edit-mode]' ) . change ( function ( event ) {
2022-10-13 13:44:39 +02:00
var maintenanceMode = visualConsoleManager . visualConsole . props . maintenanceMode ;
2019-06-04 17:21:54 +02:00
if ( $ ( this ) . prop ( 'checked' )) {
visualConsoleManager . visualConsole . enableEditMode ();
2019-06-04 17:34:40 +02:00
visualConsoleManager . changeUpdateInterval ( 0 );
2019-07-26 14:17:14 +02:00
$ ( '#edit-controls' ) . css ( 'visibility' , '' );
2019-06-04 17:21:54 +02:00
} else {
visualConsoleManager . visualConsole . disableEditMode ();
2020-02-10 17:31:48 +01:00
visualConsoleManager . visualConsole . unSelectItems ();
2019-06-04 17:34:40 +02:00
visualConsoleManager . changeUpdateInterval ( < ? php echo ( $refr * 1000 ); ?> ); // To ms.
2019-07-26 14:17:14 +02:00
$ ( '#edit-controls' ) . css ( 'visibility' , 'hidden' );
2019-06-04 17:21:54 +02:00
}
2022-10-13 13:44:39 +02:00
resetInterval ();
2019-06-04 17:21:54 +02:00
});
2022-10-13 11:03:49 +02:00
// Enable/disable the maintenance mode.
$ ( 'input[name=maintenance-mode]' ) . click ( function ( event ) {
event . preventDefault ();
const idVisualConsole = '<?php echo $visualConsoleId; ?>' ;
const mode = ( $ ( this ) . prop ( 'checked' ) === true ) ? 1 : 0 ;
2022-10-13 13:44:39 +02:00
var maintenanceMode = visualConsoleManager . visualConsole . props . maintenanceMode ;
var msg = '' ;
if ( maintenanceMode == null ) {
msg = '<?php echo __(' Are you sure you wish to set the visual console in maintenance mode '); ?>' ;
msg += '?' ;
} else if ( maintenanceMode . user === '<?php echo $config[' id_user ']; ?>' ) {
msg += '<?php echo __(' Are you sure you wish to disable maintenance mode '); ?>' ;
msg += '?' ;
} else {
2022-10-13 17:45:44 +02:00
msg = '<?php echo __(' The visual console was set to maintenance mode '); ?>' ;
msg += ' ' + '<span title="' + maintenanceMode . date + '">' + maintenanceMode . timestamp + '</span>' ;
msg += ' ' + '<?php echo __(' ago by user '); ?>' ;
2022-10-13 13:44:39 +02:00
msg += ' ' + maintenanceMode . user ;
msg += '. ' + '<?php echo __(' Are you sure you wish to disable maintenance mode '); ?>' ;
msg += '?' ;
}
2022-10-13 11:03:49 +02:00
confirmDialog ({
title : '<?php echo __(' Maintenance mode '); ?>' ,
2022-10-13 13:44:39 +02:00
message : msg ,
2022-10-13 11:03:49 +02:00
onAccept : function () {
$ . ajax ({
type : " POST " ,
url : " ajax.php " ,
dataType : " json " ,
data : {
page : " include/ajax/visual_console.ajax " ,
update_maintanance_mode : true ,
idVisualConsole : idVisualConsole ,
mode : mode
},
success : function ( data ) {
if ( data . result ) {
$ ( 'input[name=maintenance-mode]' ) . prop ( 'checked' , mode );
$ ( 'input[name=maintenance-mode]' ) . trigger ( 'change' );
2022-10-13 13:44:39 +02:00
resetInterval ();
2022-10-13 11:03:49 +02:00
}
},
error : function ( err ) {
console . error ( err );
}
});
}
});
});
2020-02-03 17:08:37 +01:00
< ? php
}
?>
2019-06-04 17:21:54 +02:00
2019-05-17 14:09:30 +02:00
// Update the data fetch interval.
$ ( 'select#vc-refr' ) . change ( function ( event ) {
var refr = Number . parseInt ( event . target . value );
2019-04-29 12:09:40 +02:00
2019-05-17 14:09:30 +02:00
if ( ! Number . isNaN ( refr )) {
visualConsoleManager . changeUpdateInterval ( refr * 1000 ); // To ms.
// Change the URL (if the browser has support).
if ( " history " in window ) {
var regex = / ( refr = ) \d + ( & ? ) / gi ;
var replacement = '$1' + refr + '$2' ;
var href = window . location . href . replace ( regex , replacement );
window . history . replaceState ({}, document . title , href );
}
2019-04-29 12:09:40 +02:00
}
2019-04-11 10:05:28 +02:00
});
2019-07-25 17:58:37 +02:00
2019-07-30 11:20:03 +02:00
visualConsoleManager . visualConsole . onItemSelectionChanged ( function ( e ) {
if ( e . selected === true ) {
$ ( '#button-button_delete' ) . prop ( 'disabled' , false );
$ ( '#button-button_copy' ) . prop ( 'disabled' , false );
} else {
$ ( '#button-button_delete' ) . prop ( 'disabled' , true );
$ ( '#button-button_copy' ) . prop ( 'disabled' , true );
}
});
$ ( '#button-button_delete' ) . click ( function ( event ){
2020-01-23 09:20:40 +01:00
confirmDialog ({
title : " <?php echo __('Delete'); ?> " ,
message : " <?php echo __('Are you sure'); ?> " + " ? " ,
onAccept : function () {
visualConsoleManager . visualConsole . elements . forEach ( item => {
if ( item . meta . isSelected === true ) {
visualConsoleManager . deleteItem ( item );
}
});
2019-07-30 11:20:03 +02:00
}
});
2019-07-26 14:17:14 +02:00
});
2019-07-25 17:58:37 +02:00
2019-07-30 11:20:03 +02:00
$ ( '#button-button_copy' ) . click ( function ( event ){
2019-07-31 13:23:25 +02:00
visualConsoleManager . visualConsole . elements . forEach ( item => {
if ( item . meta . isSelected === true ) {
visualConsoleManager . copyItem ( item );
}
});
2019-07-25 17:58:37 +02:00
});
2019-09-27 15:44:39 +02:00
2019-10-02 12:28:17 +02:00
$ ( '.link-create-item' ) . click ( function ( event ){
var type = event . target . id . substr ( 7 );
visualConsoleManager . createItem ( type );
2019-09-27 15:44:39 +02:00
});
2019-10-02 18:37:50 +02:00
2021-06-29 12:02:13 +02:00
$ ( '#full_screen' ) . click ( function ( e ) {
e . preventDefault ();
if ( props . autoAdjust === true ) {
var hrefAux = $ ( '#full_screen' ) . attr ( 'href' );
hrefAux += '&width=' + document . body . offsetWidth + '&height=' + screen . height ;
$ ( '#full_screen' ) . attr ( 'href' , hrefAux );
}
window . location . href = $ ( '#full_screen' ) . attr ( 'href' );
});
2021-12-21 09:33:55 +01:00
$ ( '#force_check' ) . click ( function ( e ) {
e . preventDefault ();
visualConsoleManager . changeUpdateInterval ( 0 );
const id_layout = '<?php echo $visualConsoleId; ?>' ;
$ . ajax ({
type : " GET " ,
url : " ajax.php " ,
dataType : " json " ,
data : {
page : " include/ajax/visual_console.ajax " ,
force_remote_check : true ,
id_layout : id_layout
},
success : function ( data ) {
if ( data == 1 ) {
visualConsoleManager . changeUpdateInterval ( 5000 );
setTimeout ( resetInterval , 6000 );
} else {
resetInterval ();
}
},
error : function ( data ) {
resetInterval ();
}
});
});
function resetInterval () {
visualConsoleManager . changeUpdateInterval ( < ? php echo ( $refr * 1000 ); ?> );
2022-10-13 11:03:49 +02:00
visualConsoleManager . forceUpdateVisualConsole ();
2021-12-21 09:33:55 +01:00
}
2019-10-02 18:37:50 +02:00
/**
* Process ajax responses and shows a dialog with results .
*/
2019-10-03 11:04:13 +02:00
function handleFormResponse ( data ) {
2019-10-02 18:37:50 +02:00
var title = " <?php echo __('Success'); ?> " ;
var text = '' ;
var failed = 0 ;
try {
data = JSON . parse ( data );
text = data [ 'result' ];
} catch ( err ) {
title = " <?php echo __('Failed'); ?> " ;
text = err . message ;
failed = 1 ;
}
if ( ! failed && data [ 'error' ] != undefined ) {
title = " <?php echo __('Failed'); ?> " ;
text = data [ 'error' ];
failed = 1 ;
}
if ( data [ 'report' ] != undefined ) {
data [ 'report' ] . forEach ( function ( item ){
text += '<br>' + item ;
});
}
2019-10-03 11:04:13 +02:00
if ( failed == 1 ) {
$ ( '#modalVCItemFormMsg' ) . empty ();
$ ( '#modalVCItemFormMsg' ) . html ( text );
$ ( '#modalVCItemFormMsg' ) . dialog ({
width : 450 ,
position : {
my : 'center' ,
at : 'center' ,
of : window ,
collision : 'fit'
},
title : title ,
buttons : [
{
class : " ui-widget ui-state-default ui-corner-all ui-button-text-only sub ok submit-next " ,
text : 'OK' ,
click : function ( e ) {
2019-10-02 18:37:50 +02:00
$ ( this ) . dialog ( 'close' );
}
}
2019-10-03 11:04:13 +02:00
]
});
// Failed.
return false ;
}
// Success, return result.
return data [ 'result' ];
2019-10-02 18:37:50 +02:00
}
2019-04-09 15:53:22 +02:00
</ script >