2017-05-23 17:13:47 +02:00
< ? php
// Pandora FMS - http://pandorafms.com
// ==================================================
// Copyright (c) 2005-2010 Artica Soluciones Tecnologicas
// 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.
// Load global variables
global $config ;
// Check user credentials
2019-01-30 16:18:44 +01:00
check_login ();
if ( ! check_acl ( $config [ 'id_user' ], 0 , 'RW' )) {
db_pandora_audit (
'ACL Violation' ,
'Trying to access Inventory Module Management'
);
include 'general/noaccess.php' ;
return ;
2017-05-23 17:13:47 +02:00
}
2019-01-30 16:18:44 +01:00
require_once 'include/functions_container.php' ;
require_once $config [ 'homedir' ] . '/include/functions_custom_graphs.php' ;
$id_container = get_parameter ( 'id' , 0 );
$offset = ( int ) get_parameter ( 'offset' , 0 );
if ( is_ajax ()) {
$add_single = ( bool ) get_parameter ( 'add_single' , 0 );
$add_custom = ( bool ) get_parameter ( 'add_custom' , 0 );
$add_dynamic = ( bool ) get_parameter ( 'add_dynamic' , 0 );
$id_container2 = get_parameter ( 'id_container' , 0 );
if ( $add_single ) {
$id_agent = get_parameter ( 'id_agent' );
$id_agent_module = get_parameter ( 'id_agent_module' );
$time_lapse = get_parameter ( 'time_lapse' );
$simple_type_graph = get_parameter ( 'simple_type_graph' );
$fullscale = get_parameter ( 'fullscale' );
if ( $fullscale != 'false' ) {
$fullscale = 1 ;
} else {
$fullscale = 0 ;
}
$values = [
'id_container' => $id_container2 ,
'type' => 'simple_graph' ,
'id_agent' => $id_agent ,
'id_agent_module' => $id_agent_module ,
'time_lapse' => $time_lapse ,
'type_graph' => $simple_type_graph ,
'fullscale' => $fullscale ,
];
$id_item = db_process_sql_insert ( 'tcontainer_item' , $values );
return ;
}
2018-06-13 11:02:58 +02:00
2019-01-30 16:18:44 +01:00
if ( $add_custom ) {
$time_lapse = get_parameter ( 'time_lapse' );
$id_custom = get_parameter ( 'id_custom' );
$fullscale = get_parameter ( 'fullscale' );
if ( $fullscale != 'false' ) {
$fullscale = 1 ;
} else {
$fullscale = 0 ;
}
$values = [
2018-06-13 11:02:58 +02:00
'id_container' => $id_container2 ,
2019-01-30 16:18:44 +01:00
'type' => 'custom_graph' ,
'time_lapse' => $time_lapse ,
'id_graph' => $id_custom ,
'fullscale' => $fullscale ,
];
$id_item = db_process_sql_insert ( 'tcontainer_item' , $values );
return ;
}
if ( $add_dynamic ) {
$time_lapse = get_parameter ( 'time_lapse' );
$group = get_parameter ( 'group' , 0 );
$module_group = get_parameter ( 'module_group' , 0 );
$agent_alias = get_parameter ( 'agent_alias' , '' );
$module_name = get_parameter ( 'module_name' , '' );
$tag = get_parameter ( 'tag' , 0 );
$simple_type_graph2 = get_parameter ( 'simple_type_graph2' );
$fullscale = get_parameter ( 'fullscale' );
if ( $fullscale != 'false' ) {
$fullscale = 1 ;
} else {
$fullscale = 0 ;
}
$values = [
'id_container' => $id_container2 ,
'type' => 'dynamic_graph' ,
'time_lapse' => $time_lapse ,
'id_group' => $group ,
2018-06-13 11:02:58 +02:00
'id_module_group' => $module_group ,
2019-01-30 16:18:44 +01:00
'agent' => $agent_alias ,
'module' => $module_name ,
'id_tag' => $tag ,
'type_graph' => $simple_type_graph2 ,
'fullscale' => $fullscale ,
];
$id_item = db_process_sql_insert ( 'tcontainer_item' , $values );
return ;
}
2017-05-23 17:13:47 +02:00
}
2019-01-30 16:18:44 +01:00
$add_container = ( bool ) get_parameter ( 'add_container' , 0 );
$edit_container = ( bool ) get_parameter ( 'edit_container' , 0 );
$update_container = ( bool ) get_parameter ( 'update_container' , 0 );
$delete_item = ( bool ) get_parameter ( 'delete_item' , 0 );
2017-05-23 17:13:47 +02:00
if ( $edit_container ) {
2019-01-30 16:18:44 +01:00
$name = io_safe_input ( get_parameter ( 'name' , '' ));
if ( ! empty ( $name )) {
$id_parent = get_parameter ( 'id_parent' , 0 );
$description = io_safe_input ( get_parameter ( 'description' , '' ));
$id_group = get_parameter ( 'container_id_group' , 0 );
} else {
$tcontainer = db_get_row_sql ( 'SELECT * FROM tcontainer WHERE id_container = ' . $id_container );
2017-05-23 17:13:47 +02:00
$name = $tcontainer [ 'name' ];
$id_parent = $tcontainer [ 'parent' ];
$description = $tcontainer [ 'description' ];
$id_group = $tcontainer [ 'id_group' ];
}
}
2019-01-30 16:18:44 +01:00
if ( $add_container ) {
$values = [
'name' => $name ,
2017-05-23 17:13:47 +02:00
'description' => $description ,
2019-01-30 16:18:44 +01:00
'parent' => $id_parent ,
'id_group' => $id_group ,
];
2017-05-23 17:13:47 +02:00
$id_container = db_process_sql_insert ( 'tcontainer' , $values );
}
2019-01-30 16:18:44 +01:00
if ( $update_container ) {
if ( $id_container === $id_parent ) {
2017-05-23 17:13:47 +02:00
$success = false ;
} else {
2019-01-30 16:18:44 +01:00
$values = [
'name' => $name ,
2017-05-23 17:13:47 +02:00
'description' => $description ,
2019-01-30 16:18:44 +01:00
'parent' => $id_parent ,
'id_group' => $id_group ,
];
$success = db_process_sql_update ( 'tcontainer' , $values , [ 'id_container' => $id_container ]);
2017-05-23 17:13:47 +02:00
}
}
2019-01-30 16:18:44 +01:00
if ( $delete_item ) {
$id_item = get_parameter ( 'id_item' , 0 );
$success = db_process_sql_delete ( 'tcontainer_item' , [ 'id_ci' => $id_item ]);
2017-05-23 17:13:47 +02:00
}
2019-01-30 16:18:44 +01:00
$buttons [ 'graph_container' ] = [
'active' => false ,
'text' => '<a href="index.php?sec=reporting&sec2=godmode/reporting/graph_container">' . html_print_image ( 'images/graph-container.png' , true , [ 'title' => __ ( 'Graph container' )]) . '</a>' ,
];
2017-05-23 17:13:47 +02:00
// Header
2019-01-30 16:18:44 +01:00
ui_print_page_header ( __ ( 'Create container' ), '' , false , '' , false , $buttons );
2017-05-23 17:13:47 +02:00
2019-01-30 16:18:44 +01:00
if ( $add_container ) {
2017-05-23 17:13:47 +02:00
ui_print_result_message ( $id_container , __ ( 'Container stored successfully' ), __ ( 'There was a problem storing container' ));
}
2019-01-30 16:18:44 +01:00
if ( $update_container ) {
ui_print_result_message ( $success , __ ( 'Update the container' ), __ ( 'Bad update the container' ));
2017-05-23 17:13:47 +02:00
}
echo " <table width='100%' cellpadding=4 cellspacing=4 class='databox filters'> " ;
2019-01-30 16:18:44 +01:00
if ( $edit_container ) {
echo " <form method='post' action='index.php?sec=reporting&sec2=godmode/reporting/create_container&edit_container=1&update_container=1&id= " . $id_container . " '> " ;
2017-05-23 17:13:47 +02:00
} else {
echo " <form method='post' action='index.php?sec=reporting&sec2=godmode/reporting/create_container&edit_container=1&add_container=1'> " ;
}
2019-01-30 16:18:44 +01:00
echo '<tr>' ;
echo " <td class='datos' style='width: 12%;'><b> " . __ ( 'Name' ) . '</b></td>' ;
if ( $id_container === '1' ) {
2017-05-23 17:13:47 +02:00
echo " <td class='datos' style='width: 27%;'><input type='text' name='name' size='30' disabled='1' " ;
} else {
echo " <td class='datos' style='width: 27%;'><input type='text' name='name' size='30' " ;
}
if ( $edit_container ) {
2019-01-30 16:18:44 +01:00
echo " value=' " . io_safe_output ( $name ) . " ' " ;
2017-05-23 17:13:47 +02:00
}
2019-01-30 16:18:44 +01:00
echo '></td>' ;
$own_info = get_user_info ( $config [ 'id_user' ]);
if ( $own_info [ 'is_admin' ] || check_acl ( $config [ 'id_user' ], 0 , 'PM' )) {
$return_all_groups = true ;
} else {
$return_all_groups = false ;
}
echo " <td style='width: 12%;'><b> " . __ ( 'Group' ) . '</b></td><td>' ;
if ( $id_container === '1' ) {
echo html_print_select_groups ( $config [ 'id_user' ], '' , $return_all_groups , 'container_id_group' , $id_group , '' , '' , '' , true , false , true , '' , true );
2017-05-23 17:13:47 +02:00
} else {
2019-01-30 16:18:44 +01:00
echo html_print_select_groups ( $config [ 'id_user' ], '' , $return_all_groups , 'container_id_group' , $id_group , '' , '' , '' , true , false , true , '' , false );
2017-05-23 17:13:47 +02:00
}
2019-01-30 16:18:44 +01:00
echo '</td></tr>' ;
echo '<tr>' ;
echo " <td class='datos2'><b> " . __ ( 'Description' ) . '</b></td>' ;
if ( $id_container === '1' ) {
2017-05-23 17:13:47 +02:00
echo " <td class='datos2' colspan=3><textarea name='description' style='height:45px;' cols=95 rows=2 disabled> " ;
} else {
echo " <td class='datos2' colspan=3><textarea name='description' style='height:45px;' cols=95 rows=2> " ;
}
if ( $edit_container ) {
2019-01-30 16:18:44 +01:00
echo io_safe_output ( $description );
2017-05-23 17:13:47 +02:00
}
2019-01-30 16:18:44 +01:00
echo '</textarea>' ;
echo '</td></tr>' ;
2017-05-23 17:13:47 +02:00
$container = folder_get_folders ();
$tree = folder_get_folders_tree_recursive ( $container );
2019-01-30 16:18:44 +01:00
$containers_tree = folder_flatten_tree_folders ( $tree , 0 );
2017-05-23 17:13:47 +02:00
$containers_tree = folder_get_select ( $containers_tree );
unset ( $containers_tree [ $id_container ]);
2019-01-30 16:18:44 +01:00
echo '<tr>' ;
echo " <td class='datos2'><b> " . __ ( 'Parent container' ) . '</b></td>' ;
if ( $id_container === '1' ) {
echo " <td class='datos2'> " . html_print_select (
$containers_tree ,
'id_parent' ,
$id_parent ,
'' ,
__ ( 'none' ),
0 ,
true ,
'' ,
false ,
'w130' ,
true ,
'width: 195px' ,
''
);
2017-05-23 17:13:47 +02:00
} else {
2019-01-30 16:18:44 +01:00
echo " <td class='datos2'> " . html_print_select (
$containers_tree ,
'id_parent' ,
$id_parent ,
'' ,
__ ( 'none' ),
0 ,
true ,
'' ,
false ,
'w130' ,
'' ,
'width: 195px' ,
''
);
2017-05-23 17:13:47 +02:00
}
2019-01-30 16:18:44 +01:00
echo '</td></tr>' ;
2017-05-23 17:13:47 +02:00
2019-01-30 16:18:44 +01:00
echo '</table>' ;
2017-05-23 17:13:47 +02:00
if ( $edit_container ) {
2019-01-30 16:18:44 +01:00
if ( $id_container !== '1' ) {
2017-05-23 17:13:47 +02:00
echo " <div style='width:100%'><input style='float:right;' type=submit name='store' disbaled class='sub upd' value=' " . __ ( 'Update' ) . " '></div> " ;
}
2019-01-30 16:18:44 +01:00
} else {
echo " <div style='width:100%'><input style='float:right;' type=submit name='store' class='sub next' value=' " . __ ( 'Create' ) . " '></div> " ;
2017-05-23 17:13:47 +02:00
}
2019-01-30 16:18:44 +01:00
echo '</form>' ;
echo '</br>' ;
echo '</br>' ;
echo '</br>' ;
if ( $edit_container ) {
$period = SECONDS_15DAYS ;
$periods = [];
$periods [ - 1 ] = __ ( 'custom' );
$periods [ SECONDS_1HOUR ] = __ ( '1 hour' );
$periods [ SECONDS_2HOUR ] = sprintf ( __ ( '%s hours' ), '2 ' );
$periods [ SECONDS_6HOURS ] = sprintf ( __ ( '%s hours' ), '6 ' );
$periods [ SECONDS_12HOURS ] = sprintf ( __ ( '%s hours' ), '12 ' );
$periods [ SECONDS_1DAY ] = __ ( '1 day' );
$periods [ SECONDS_2DAY ] = sprintf ( __ ( '%s days' ), '2 ' );
$periods [ SECONDS_5DAY ] = sprintf ( __ ( '%s days' ), '5 ' );
$periods [ SECONDS_1WEEK ] = __ ( '1 week' );
$periods [ SECONDS_15DAYS ] = __ ( '15 days' );
$periods [ SECONDS_1MONTH ] = __ ( '1 month' );
$type_graphs = [];
$type_graphs [ 0 ] = __ ( 'Area' );
$type_graphs [ 1 ] = __ ( 'Line' );
2017-05-23 17:13:47 +02:00
$single_table = " <table width='100%' cellpadding=4 cellspacing=4> " ;
$single_table .= " <tr id='row_time_lapse' style='' class='datos'> " ;
2018-01-03 15:53:49 +01:00
$single_table .= " <td style='font-weight:bold;width: 13%;'> " ;
2017-05-23 17:13:47 +02:00
$single_table .= __ ( 'Time lapse' );
2019-01-30 16:18:44 +01:00
$single_table .= ui_print_help_tip ( __ ( 'This is the interval or period of time with which the graph data will be obtained. For example, a week means data from a week ago from now. ' ), true );
$single_table .= '</td>' ;
$single_table .= '<td>' ;
$single_table .= html_print_extended_select_for_time (
'period_single' ,
$period ,
'' ,
'' ,
'0' ,
10 ,
true ,
false ,
true ,
'' ,
false ,
$periods
);
$single_table .= '</td>' ;
$single_table .= '</tr>' ;
2017-05-23 17:13:47 +02:00
$single_table .= " <tr id='row_agent' style='' class='datos'> " ;
$single_table .= " <td style='font-weight:bold;width: 12%;'> " ;
$single_table .= __ ( 'Agent' );
2019-01-30 16:18:44 +01:00
$single_table .= '</td>' ;
$single_table .= '<td>' ;
$params = [];
2017-05-23 17:13:47 +02:00
$params [ 'show_helptip' ] = false ;
$params [ 'input_name' ] = 'agent' ;
$params [ 'value' ] = '' ;
$params [ 'return' ] = true ;
2019-01-30 16:18:44 +01:00
2017-05-23 17:13:47 +02:00
$params [ 'javascript_is_function_select' ] = true ;
$params [ 'selectbox_id' ] = 'id_agent_module' ;
$params [ 'add_none_module' ] = true ;
$params [ 'use_hidden_input_idagent' ] = true ;
$params [ 'hidden_input_idagent_id' ] = 'hidden-id_agent' ;
2019-01-30 16:18:44 +01:00
2017-05-23 17:13:47 +02:00
$single_table .= ui_print_agent_autocomplete_input ( $params );
2019-01-30 16:18:44 +01:00
$single_table .= '</td>' ;
$single_table .= '</tr>' ;
2017-05-23 17:13:47 +02:00
$single_table .= " <tr id='row_module' style='' class='datos'> " ;
$single_table .= " <td style='font-weight:bold;width: 12%;'> " ;
$single_table .= __ ( 'Module' );
2019-01-30 16:18:44 +01:00
$single_table .= '</td>' ;
$single_table .= '<td>' ;
if ( $idAgent ) {
$single_table .= html_print_select_from_sql ( $sql_modules , 'id_agent_module' , $idAgentModule , '' , '' , '0' , true );
} else {
$single_table .= " <select style='max-width: 180px' id='id_agent_module' name='id_agent_module' disabled='disabled'> " ;
$single_table .= " <option value='0'> " ;
$single_table .= __ ( 'Select an Agent first' );
$single_table .= '</option>' ;
$single_table .= '</select>' ;
}
$single_table .= '</td>' ;
$single_table .= '</tr>' ;
2018-06-13 11:02:58 +02:00
$single_table .= " <tr id='row_type_graphs' style='' class='datos'> " ;
$single_table .= " <td style='font-weight:bold;'> " ;
$single_table .= __ ( 'Type of graph' );
2019-01-30 16:18:44 +01:00
$single_table .= '</td>' ;
$single_table .= '<td>' ;
$single_table .= html_print_select ( $type_graphs , 'simple_type_graph' , '' , '' , '' , 0 , true );
$single_table .= '</td>' ;
$single_table .= '</tr>' ;
2018-06-13 11:02:58 +02:00
2018-01-03 15:53:49 +01:00
$single_table .= " <tr id='row_fullscale' style='' class='datos'> " ;
$single_table .= " <td style='font-weight:bold;'> " ;
2019-01-30 16:18:44 +01:00
$single_table .= __ ( 'Show full scale graph (TIP)' ) . ui_print_help_tip ( 'This option may cause performance issues' , true );
$single_table .= '</td>' ;
$single_table .= '<td>' ;
$single_table .= html_print_checkbox ( 'fullscale' , 1 , false , true );
$single_table .= '</td>' ;
$single_table .= '</tr>' ;
$single_table .= '<tr>' ;
$single_table .= '<td >' ;
$single_table .= '</td>' ;
2017-05-23 17:13:47 +02:00
$single_table .= " <td style='float:right;'> " ;
$single_table .= " <input style='float:right;' type=submit name='add_single' class='sub add' value=' " . __ ( 'Add item' ) . " '> " ;
2019-01-30 16:18:44 +01:00
$single_table .= '</td>' ;
$single_table .= '</tr>' ;
$single_table .= '</table>' ;
2017-05-23 17:13:47 +02:00
echo " <table width='100%' cellpadding=4 cellspacing=4 class='databox filters'> " ;
2019-01-30 16:18:44 +01:00
echo '<tr>' ;
echo '<td>' ;
2019-06-04 13:57:55 +02:00
echo ui_toggle ( $single_table , 'Simple module graph' , '' , '' , true );
2019-01-30 16:18:44 +01:00
echo '</td>' ;
echo '</tr>' ;
echo '</table>' ;
2017-05-23 17:13:47 +02:00
$table = new stdClass ();
$table -> id = 'custom_graph_table' ;
$table -> width = '100%' ;
$table -> cellspacing = 4 ;
$table -> cellpadding = 4 ;
$table -> class = 'dat' ;
$table -> styleTable = 'font-weight: bold;' ;
2018-01-03 15:53:49 +01:00
$table -> style [ 0 ] = 'width: 13%' ;
2019-01-30 16:18:44 +01:00
$table -> data = [];
2017-05-23 17:13:47 +02:00
2019-01-30 16:18:44 +01:00
$data = [];
2017-05-23 17:13:47 +02:00
$data [ 0 ] = __ ( 'Time lapse' );
2019-01-30 16:18:44 +01:00
$data [ 0 ] .= ui_print_help_tip ( __ ( 'This is the interval or period of time with which the graph data will be obtained. For example, a week means data from a week ago from now. ' ), true );
$data [ 1 ] = html_print_extended_select_for_time ( 'period_custom' , $period , '' , '' , '0' , 10 , true , false , true , '' , false , $periods );
2017-05-23 17:13:47 +02:00
$table -> data [] = $data ;
$table -> rowclass [] = '' ;
2019-01-30 16:18:44 +01:00
$data = [];
2017-05-23 17:13:47 +02:00
$data [ 0 ] = __ ( 'Custom graph' );
2019-01-30 16:18:44 +01:00
$list_custom_graphs = custom_graphs_get_user ( $config [ 'id_user' ], false , true , 'RR' );
2017-05-23 17:13:47 +02:00
2019-01-30 16:18:44 +01:00
$graphs = [];
2017-05-23 17:13:47 +02:00
foreach ( $list_custom_graphs as $custom_graph ) {
$graphs [ $custom_graph [ 'id_graph' ]] = $custom_graph [ 'name' ];
}
2019-01-30 16:18:44 +01:00
$data [ 1 ] = html_print_select ( $graphs , 'id_custom_graph' , $idCustomGraph , '' , __ ( 'None' ), 0 , true );
2017-05-23 17:13:47 +02:00
$table -> data [] = $data ;
$table -> rowclass [] = '' ;
2019-01-30 16:18:44 +01:00
$data = [];
$data [ 0 ] = __ ( 'Show full scale graph (TIP)' ) . ui_print_help_tip ( 'This option may cause performance issues' , true );
$data [ 1 ] = html_print_checkbox ( 'fullscale_2' , 1 , false , true );
2018-01-03 15:53:49 +01:00
$table -> data [] = $data ;
$table -> rowclass [] = '' ;
2019-01-30 16:18:44 +01:00
$data = [];
$data [ 0 ] = '' ;
2017-05-23 17:13:47 +02:00
$data [ 1 ] = " <input style='float:right;' type=submit name='add_custom' class='sub add' value=' " . __ ( 'Add item' ) . " '> " ;
$table -> data [] = $data ;
$table -> rowclass [] = '' ;
echo " <table width='100%' cellpadding=4 cellspacing=4 class='databox filters'> " ;
2019-01-30 16:18:44 +01:00
echo '<tr>' ;
echo '<td>' ;
2019-06-04 13:57:55 +02:00
echo ui_toggle ( html_print_table ( $table , true ), 'Custom graph' , '' , '' , true );
2019-01-30 16:18:44 +01:00
echo '</td>' ;
echo '</tr>' ;
echo '</table>' ;
2017-05-23 17:13:47 +02:00
unset ( $table );
$table = new stdClass ();
$table -> id = 'dynamic_rules_table' ;
$table -> width = '100%' ;
$table -> cellspacing = 4 ;
$table -> cellpadding = 4 ;
$table -> class = 'dat' ;
$table -> styleTable = 'font-weight: bold;' ;
2018-01-03 15:53:49 +01:00
$table -> style [ 0 ] = 'width: 13%' ;
2019-01-30 16:18:44 +01:00
$table -> data = [];
2017-05-23 17:13:47 +02:00
2019-01-30 16:18:44 +01:00
$data = [];
2017-05-23 17:13:47 +02:00
$data [ 0 ] = __ ( 'Time lapse' );
2019-01-30 16:18:44 +01:00
$data [ 0 ] .= ui_print_help_tip ( __ ( 'This is the interval or period of time with which the graph data will be obtained. For example, a week means data from a week ago from now. ' ), true );
$data [ 1 ] = html_print_extended_select_for_time ( 'period_dynamic' , $period , '' , '' , '0' , 10 , true , false , true , '' , false , $periods );
2017-05-23 17:13:47 +02:00
$table -> data [] = $data ;
$table -> rowclass [] = '' ;
2019-01-30 16:18:44 +01:00
$data = [];
2017-05-23 17:13:47 +02:00
$data [ 0 ] = __ ( 'Group' );
$data [ 1 ] = html_print_select_groups ( $config [ 'id_user' ], 'RW' , $return_all_groups , 'container_id_group' , $id_group , '' , '' , '' , true );
$table -> data [] = $data ;
$table -> rowclass [] = '' ;
2019-01-30 16:18:44 +01:00
$data = [];
2017-05-23 17:13:47 +02:00
$data [ 0 ] = __ ( 'Module group' );
$data [ 1 ] = html_print_select_from_sql (
2019-01-30 16:18:44 +01:00
'SELECT * FROM tmodule_group ORDER BY name' ,
'combo_modulegroup' ,
$modulegroup ,
'' ,
__ ( 'All' ),
false ,
true
);
2017-05-23 17:13:47 +02:00
$table -> data [] = $data ;
$table -> rowclass [] = '' ;
2019-01-30 16:18:44 +01:00
$data = [];
$data [ 0 ] = __ ( 'Agent' );
$data [ 1 ] = html_print_input_text ( 'text_agent' , $textAgent , '' , 30 , 100 , true );
2017-05-23 17:13:47 +02:00
$table -> data [] = $data ;
$table -> rowclass [] = '' ;
2019-01-30 16:18:44 +01:00
$data = [];
$data [ 0 ] = __ ( 'Module' );
$data [ 1 ] = html_print_input_text ( 'text_agent_module' , $textModule , '' , 30 , 100 , true );
2017-05-23 17:13:47 +02:00
$table -> data [] = $data ;
$table -> rowclass [] = '' ;
2019-01-30 16:18:44 +01:00
$data = [];
$data [ 0 ] = __ ( 'Tag' );
$select_tags = tags_search_tag ( false , false , true );
$data [ 1 ] = html_print_select (
$select_tags ,
'tag' ,
$tag ,
'' ,
__ ( 'Any' ),
0 ,
true ,
false ,
false
);
2017-05-23 17:13:47 +02:00
$table -> data [] = $data ;
$table -> rowclass [] = '' ;
2019-01-30 16:18:44 +01:00
$data = [];
$data [ 0 ] = __ ( 'Type of graph' );
$data [ 1 ] = html_print_select ( $type_graphs , 'simple_type_graph2' , '' , '' , '' , 0 , true );
$table -> data [] = $data ;
2017-11-23 18:01:32 +01:00
$table -> rowclass [] = '' ;
2018-01-03 15:53:49 +01:00
2019-01-30 16:18:44 +01:00
$data = [];
$data [ 0 ] = __ ( 'Show full scale graph (TIP)' ) . ui_print_help_tip ( 'This option may cause performance issues' , true );
$data [ 1 ] = html_print_checkbox ( 'fullscale_3' , 1 , false , true );
2018-01-03 15:53:49 +01:00
$table -> data [] = $data ;
$table -> rowclass [] = '' ;
2019-01-30 16:18:44 +01:00
$data = [];
$data [ 0 ] = '' ;
2017-05-23 17:13:47 +02:00
$data [ 1 ] = " <input style='float:right;' type=submit name='add_dynamic' class='sub add' value=' " . __ ( 'Add item' ) . " '> " ;
$table -> data [] = $data ;
$table -> rowclass [] = '' ;
echo " <table width='100%' cellpadding=4 cellspacing=4 class='databox filters'> " ;
2019-01-30 16:18:44 +01:00
echo '<tr>' ;
echo '<td>' ;
2019-06-04 13:57:55 +02:00
echo ui_toggle ( html_print_table ( $table , true ), 'Dynamic rules for simple module graph' , '' , '' , true );
2019-01-30 16:18:44 +01:00
echo '</td>' ;
echo '</tr>' ;
echo '</table>' ;
$total_item = db_get_all_rows_sql ( 'SELECT count(*) FROM tcontainer_item WHERE id_container = ' . $id_container );
$result_item = db_get_all_rows_sql ( 'SELECT * FROM tcontainer_item WHERE id_container = ' . $id_container . ' LIMIT 10 OFFSET ' . $offset );
if ( ! $result_item ) {
echo " <div class='nf'> " . __ ( 'There are no defined item container' ) . '</div>' ;
2017-05-23 17:13:47 +02:00
} else {
2019-01-30 16:18:44 +01:00
ui_pagination ( $total_item [ 0 ][ 'count(*)' ], false , $offset , 10 );
2017-05-23 17:13:47 +02:00
$table = new stdClass ();
2019-01-30 16:18:44 +01:00
$table -> width = '100%' ;
$table -> class = 'databox data' ;
2017-05-23 17:13:47 +02:00
$table -> id = 'item_table' ;
2019-01-30 16:18:44 +01:00
$table -> align = [];
$table -> head = [];
$table -> head [ 0 ] = __ ( 'Agent/Module' );
$table -> head [ 1 ] = __ ( 'Custom graph' );
$table -> head [ 2 ] = __ ( 'Group' );
$table -> head [ 3 ] = __ ( 'M.Group' );
2017-05-23 17:13:47 +02:00
$table -> head [ 4 ] = __ ( 'Agent' );
$table -> head [ 5 ] = __ ( 'Module' );
$table -> head [ 6 ] = __ ( 'Tag' );
2019-01-30 16:18:44 +01:00
$table -> head [ 7 ] = __ ( 'Delete' );
$table -> data = [];
foreach ( $result_item as $item ) {
$data = [];
switch ( $item [ 'type' ]) {
case 'simple_graph' :
$agent_alias = ui_print_truncate_text ( agents_get_alias ( $item [ 'id_agent' ], 20 , false ));
$module_name = ui_print_truncate_text ( modules_get_agentmodule_name ( $item [ 'id_agent_module' ]), 20 , false );
$module_name = $data [ 0 ] = $agent_alias . ' / ' . $module_name ;
$data [ 1 ] = '' ;
$data [ 2 ] = '' ;
$data [ 3 ] = '' ;
$data [ 4 ] = '' ;
$data [ 5 ] = '' ;
$data [ 6 ] = '' ;
break ;
case 'custom_graph' :
$data [ 0 ] = '' ;
$name = db_get_value_filter ( 'name' , 'tgraph' , [ 'id_graph' => $item [ 'id_graph' ]]);
$data [ 1 ] = ui_print_truncate_text ( io_safe_output ( $name ), 35 , false );
$data [ 2 ] = '' ;
$data [ 3 ] = '' ;
$data [ 4 ] = '' ;
$data [ 5 ] = '' ;
$data [ 6 ] = '' ;
break ;
case 'dynamic_graph' :
$data [ 0 ] = '' ;
$data [ 1 ] = '' ;
$data [ 2 ] = ui_print_group_icon ( $item [ 'id_group' ], true );
if ( $item [ 'id_module_group' ] === '0' ) {
$data [ 3 ] = 'All' ;
} else {
$data [ 3 ] = io_safe_output ( db_get_value_filter ( 'name' , 'tmodule_group' , [ 'id_mg' => $item [ 'id_module_group' ]]));
}
$data [ 4 ] = io_safe_output ( $item [ 'agent' ]);
$data [ 5 ] = io_safe_output ( $item [ 'module' ]);
if ( $item [ 'id_tag' ] === '0' ) {
$data [ 6 ] = 'Any' ;
} else {
$data [ 6 ] = io_safe_output ( db_get_value_filter ( 'name' , 'ttag' , [ 'id_tag' => $item [ 'id_tag' ]]));
}
break ;
}
$data [ 7 ] = '<a href="index.php?sec=reporting&sec2=godmode/reporting/create_container&edit_container=1&delete_item=1&id_item=' . $item [ 'id_ci' ] . '&id=' . $id_container . '" onClick="if (!confirm(\'' . __ ( 'Are you sure?' ) . ' \ ' ))
return false ; " >'.html_print_image('images/cross.png', true, ['alt' => __('Delete'), 'title' => __('Delete')]).'</a>';
array_push ( $table -> data , $data );
2017-05-23 17:13:47 +02:00
}
2019-01-30 16:18:44 +01:00
html_print_table ( $table );
}
2017-05-23 17:13:47 +02:00
}
echo html_print_input_hidden ( 'id_agent' , 0 );
?>
< script type = " text/javascript " >
$ ( document ) . ready ( function () {
$ ( " input[name=add_single] " ) . click ( function () {
var id_agent_module = $ ( " #id_agent_module " ) . val ();
2018-06-13 11:02:58 +02:00
if ( id_agent_module !== '0' ){
var id_agent = $ ( " #hidden-id_agent " ) . attr ( 'value' );
var time_lapse = $ ( " #hidden-period_single " ) . attr ( 'value' );
var simple_type_graph = $ ( " #simple_type_graph option:selected " ) . attr ( 'value' );
var fullscale = $ ( " #checkbox-fullscale " ) . prop ( " checked " );
var id_container = < ? php echo $id_container ; ?> ;
jQuery . post (
" ajax.php " ,
{ " page " : " godmode/reporting/create_container " ,
" add_single " : 1 ,
" id_agent " : id_agent ,
" id_agent_module " : id_agent_module ,
" time_lapse " : time_lapse ,
" simple_type_graph " : simple_type_graph ,
" fullscale " : fullscale ,
" id_container " : id_container },
function ( data , status ) {
var url = location . href . replace ( '&update_container=1' , " " );
url = url . replace ( '&delete_item=1' , " " );
location . href = url . replace ( '&add_container=1' , " &id= " + id_container );
}
);
}
2017-05-23 17:13:47 +02:00
});
2018-06-13 11:02:58 +02:00
2017-05-23 17:13:47 +02:00
$ ( " input[name=add_custom] " ) . click ( function () {
var id_custom = $ ( " #id_custom_graph " ) . val ();
2018-01-03 15:53:49 +01:00
var fullscale = $ ( " #checkbox-fullscale_2 " ) . prop ( " checked " );
2019-01-30 16:18:44 +01:00
if ( id_custom !== '0' ){
var time_lapse = $ ( " #hidden-period_custom " ) . attr ( 'value' );
var id_container = < ? php echo $id_container ; ?> ;
jQuery . post ( " ajax.php " ,
{ " page " : " godmode/reporting/create_container " ,
" add_custom " : 1 ,
" time_lapse " : time_lapse ,
" id_custom " : id_custom ,
" id_container " : id_container ,
2018-02-06 09:21:07 +01:00
" fullscale " : fullscale ,
2019-01-30 16:18:44 +01:00
},
function ( data , status ) {
var url = location . href . replace ( '&update_container=1' , " " );
url = url . replace ( '&delete_item=1' , " " );
location . href = url . replace ( '&add_container=1' , " &id= " + id_container );
}
);
}
2017-05-23 17:13:47 +02:00
});
2019-01-30 16:18:44 +01:00
$ ( " input[name=add_dynamic] " ) . click ( function () {
var agent_alias = $ ( " #text-text_agent " ) . val ();
var module_name = $ ( " #text-text_agent_module " ) . val ();
var time_lapse = $ ( " #hidden-period_dynamic " ) . attr ( 'value' );
var group = $ ( " #container_id_group1 " ) . val ();
var module_group = $ ( " #combo_modulegroup " ) . val ();
var simple_type_graph2 = $ ( " #simple_type_graph2 option:selected " ) . attr ( 'value' );
var tag = $ ( " #tag " ) . val ();
var id_container = < ? php echo $id_container ; ?> ;
var fullscale = $ ( " #checkbox-fullscale_3 " ) . prop ( " checked " );
2017-05-23 17:13:47 +02:00
jQuery . post ( " ajax.php " ,
2019-01-30 16:18:44 +01:00
{ " page " : " godmode/reporting/create_container " ,
" add_dynamic " : 1 ,
" time_lapse " : time_lapse ,
" group " : group ,
" module_group " : module_group ,
" agent_alias " : agent_alias ,
" module_name " : module_name ,
" simple_type_graph2 " : simple_type_graph2 ,
" tag " : tag ,
" id_container " : id_container ,
2018-06-13 11:02:58 +02:00
" fullscale " : fullscale
2019-01-30 16:18:44 +01:00
},
function ( data , status ) {
var url = location . href . replace ( '&update_container=1' , " " );
url = url . replace ( '&delete_item=1' , " " );
location . href = url . replace ( '&add_container=1' , " &id= " + id_container );
}
2017-05-23 17:13:47 +02:00
);
});
});
</ script >