2010-06-21 17:59:37 +02:00
< ? php
// Pandora FMS - http://pandorafms.com
// ==================================================
2010-06-22 18:16:28 +02:00
// Copyright (c) 2005-2010 Artica Soluciones Tecnologicas
2010-06-21 17:59:37 +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.
global $config ;
2019-01-30 16:18:44 +01:00
require_once 'include/functions_custom_graphs.php' ;
2012-03-13 18:07:05 +01:00
2019-01-30 16:18:44 +01:00
if ( is_ajax ()) {
$search_agents = ( bool ) get_parameter ( 'search_agents' );
if ( $search_agents ) {
include_once 'include/functions_agents.php' ;
$id_agent = ( int ) get_parameter ( 'id_agent' );
$string = ( string ) get_parameter ( 'q' );
// q is what autocomplete plugin gives
$id_group = ( int ) get_parameter ( 'id_group' );
$filter = [];
$filter [] = '(nombre COLLATE utf8_general_ci LIKE "%' . $string . '%" OR direccion LIKE "%' . $string . '%" OR comentarios LIKE "%' . $string . '%")' ;
$filter [ 'id_grupo' ] = $id_group ;
$agents = agents_get_agents ( $filter , [ 'nombre' , 'direccion' ]);
if ( $agents === false ) {
return ;
}
foreach ( $agents as $agent ) {
echo $agent [ 'nombre' ] . '|' . $agent [ 'direccion' ] . " \n " ;
}
return ;
}
return ;
2010-06-21 17:59:37 +02:00
}
2019-01-30 16:18:44 +01:00
check_login ();
2010-06-21 17:59:37 +02:00
2019-01-30 16:18:44 +01:00
if ( ! check_acl ( $config [ 'id_user' ], 0 , 'RW' ) && ! check_acl ( $config [ 'id_user' ], 0 , 'RM' )) {
db_pandora_audit (
'ACL Violation' ,
'Trying to access graph builder'
);
include 'general/noaccess.php' ;
exit ;
2010-06-21 17:59:37 +02:00
}
if ( $edit_graph ) {
2019-01-30 16:18:44 +01:00
$graphInTgraph = db_get_row_sql ( 'SELECT * FROM tgraph WHERE id_graph = ' . $id_graph );
$stacked = $graphInTgraph [ 'stacked' ];
$period = $graphInTgraph [ 'period' ];
$id_group = $graphInTgraph [ 'id_group' ];
$check = false ;
$percentil = $graphInTgraph [ 'percentil' ];
$summatory_series = $graphInTgraph [ 'summatory_series' ];
$average_series = $graphInTgraph [ 'average_series' ];
$modules_series = $graphInTgraph [ 'modules_series' ];
$fullscale = $graphInTgraph [ 'fullscale' ];
if ( $stacked == CUSTOM_GRAPH_BULLET_CHART_THRESHOLD ) {
$stacked = CUSTOM_GRAPH_BULLET_CHART ;
$check = true ;
}
} else {
$id_agent = 0 ;
$id_module = 0 ;
$id_group = 0 ;
$period = SECONDS_1DAY ;
$factor = 1 ;
$stacked = 4 ;
$check = false ;
$percentil = 0 ;
$summatory_series = 0 ;
$average_series = 0 ;
$modules_series = 0 ;
if ( $config [ 'full_scale_option' ] == 1 ) {
$fullscale = 1 ;
} else {
$fullscale = 0 ;
}
2010-06-21 17:59:37 +02:00
}
// -----------------------
// CREATE/EDIT GRAPH FORM
// -----------------------
2015-06-12 15:50:46 +02:00
echo " <table width='100%' cellpadding=4 cellspacing=4 class='databox filters'> " ;
2010-06-21 17:59:37 +02:00
2019-01-30 16:18:44 +01:00
if ( $edit_graph ) {
echo " <form method='post' action='index.php?sec=reporting&sec2=godmode/reporting/graph_builder&edit_graph=1&update_graph=1&id= " . $id_graph . " '> " ;
} else {
echo " <form method='post' action='index.php?sec=reporting&sec2=godmode/reporting/graph_builder&edit_graph=1&add_graph=1'> " ;
}
2010-06-21 17:59:37 +02:00
2019-01-30 16:18:44 +01:00
echo '<tr>' ;
echo " <td class='datos'><b> " . __ ( 'Name' ) . '</b></td>' ;
2010-06-21 17:59:37 +02:00
echo " <td class='datos'><input type='text' name='name' size='25' " ;
if ( $edit_graph ) {
2019-01-30 16:18:44 +01:00
echo " value=' " . $graphInTgraph [ 'name' ] . " ' " ;
2010-06-21 17:59:37 +02:00
}
2019-01-30 16:18:44 +01:00
echo '>' ;
$own_info = get_user_info ( $config [ 'id_user' ]);
echo '<td><b>' . __ ( 'Group' ) . '</b></td><td>' ;
if ( check_acl ( $config [ 'id_user' ], 0 , 'RW' )) {
echo html_print_select_groups ( $config [ 'id_user' ], 'RW' , true , 'graph_id_group' , $id_group , '' , '' , '' , true );
} else if ( check_acl ( $config [ 'id_user' ], 0 , 'RM' )) {
echo html_print_select_groups ( $config [ 'id_user' ], 'RM' , true , 'graph_id_group' , $id_group , '' , '' , '' , true );
}
echo '</td></tr>' ;
echo '<tr>' ;
echo " <td class='datos2'><b> " . __ ( 'Description' ) . '</b></td>' ;
2010-06-21 17:59:37 +02:00
echo " <td class='datos2' colspan=3><textarea name='description' style='height:45px;' cols=55 rows=2> " ;
if ( $edit_graph ) {
2019-01-30 16:18:44 +01:00
echo $graphInTgraph [ 'description' ];
2010-06-21 17:59:37 +02:00
}
2015-11-04 17:42:45 +01:00
2019-01-30 16:18:44 +01:00
echo '</textarea>' ;
echo '</td></tr>' ;
if ( $stacked == CUSTOM_GRAPH_GAUGE ) {
$hidden = ' style="display:none;" ' ;
} else {
$hidden = '' ;
}
2010-06-21 17:59:37 +02:00
2019-01-30 16:18:44 +01:00
echo '<tr>' ;
2010-06-21 17:59:37 +02:00
echo " <td class='datos'> " ;
2019-01-30 16:18:44 +01:00
echo '<b>' . __ ( 'Period' ) . '</b></td>' ;
2010-06-21 17:59:37 +02:00
echo " <td class='datos'> " ;
2019-01-30 16:18:44 +01:00
html_print_extended_select_for_time ( 'period' , $period , '' , '' , '0' , 10 );
2010-06-21 17:59:37 +02:00
echo " </td><td class='datos2'> " ;
2019-01-30 16:18:44 +01:00
echo '<b>' . __ ( 'Type of graph' ) . '</b></td>' ;
2016-08-23 08:50:23 +02:00
echo " <td class='datos2'> <div style='float:left;display:inline-block'> " ;
2011-04-11 18:45:03 +02:00
2019-01-30 16:18:44 +01:00
require_once $config [ 'homedir' ] . '/include/functions_graph.php' ;
$stackeds = [
CUSTOM_GRAPH_AREA => __ ( 'Area' ),
CUSTOM_GRAPH_STACKED_AREA => __ ( 'Stacked area' ),
CUSTOM_GRAPH_LINE => __ ( 'Line' ),
CUSTOM_GRAPH_STACKED_LINE => __ ( 'Stacked line' ),
CUSTOM_GRAPH_BULLET_CHART => __ ( 'Bullet chart' ),
CUSTOM_GRAPH_GAUGE => __ ( 'Gauge' ),
CUSTOM_GRAPH_HBARS => __ ( 'Horizontal bars' ),
CUSTOM_GRAPH_VBARS => __ ( 'Vertical bars' ),
CUSTOM_GRAPH_PIE => __ ( 'Pie' ),
];
html_print_select ( $stackeds , 'stacked' , $stacked );
echo '</div></td></tr>' ;
echo " <tr><td class='datos2'><b> " . __ ( 'Percentil' ) . '</b></td>' ;
echo " <td class='datos2'> " . html_print_checkbox ( 'percentil' , 1 , $percentil , true ) . '</td>' ;
echo " <td class='datos2'><div id='thresholdDiv' name='thresholdDiv'><b> " . __ ( 'Equalize maximum thresholds' ) . '</b>' . ui_print_help_tip ( __ ( 'If an option is selected, all graphs will have the highest value from all modules included in the graph as a maximum threshold' ), true );
html_print_checkbox ( 'threshold' , CUSTOM_GRAPH_BULLET_CHART_THRESHOLD , $check , false , false , '' , false );
echo '</div></td></tr>' ;
echo " <tr><td class='datos2'><b> " . __ ( 'Add summatory series' ) . ui_print_help_tip (
__ (
' Adds synthetic series to the graph , using all module
2017-12-13 11:50:15 +01:00
values to calculate the summation and / or average in each time interval .
2019-01-30 16:18:44 +01:00
This feature could be used instead of synthetic modules if you only want to see a graph . '
),
true
) . '</b></td>' ;
echo " <td class='datos2'> " . html_print_checkbox ( 'summatory_series' , 1 , $summatory_series , true ) . " </td>
< td class = 'datos2' >< b > " .__('Add average series').'</b></td>';
echo " <td class='datos2'> " . html_print_checkbox ( 'average_series' , 1 , $average_series , true ) . '</td></tr>' ;
echo " <tr><td class='datos2'><b> " . __ ( 'Modules and series' ) . '</b></td>' ;
echo " <td class='datos2'> " . html_print_checkbox ( 'modules_series' , 1 , $modules_series , true ) . '</td>' ;
echo " <td class='datos2'><b> " . __ ( 'Show full scale graph (TIP)' ) . ui_print_help_tip ( __ ( 'This option may cause performance issues' ), true ) . '</td>' ;
echo " <td class='datos2'> " . html_print_checkbox ( 'fullscale' , 1 , $fullscale , true ) . '</td>' ;
echo '</tr>' ;
echo '</table>' ;
2015-06-12 15:50:46 +02:00
2010-06-21 17:59:37 +02:00
if ( $edit_graph ) {
2019-01-30 16:18:44 +01:00
echo " <div style='width:100%'><input style='float:right;' type=submit name='store' class='sub upd' value=' " . __ ( 'Update' ) . " '></div> " ;
} else {
echo " <div style='width:100%'><input style='float:right;' type=submit name='store' class='sub next' value=' " . __ ( 'Create' ) . " '></div> " ;
2010-06-21 17:59:37 +02:00
}
2019-01-30 16:18:44 +01:00
echo '</form>' ;
2015-11-04 17:42:45 +01:00
echo ' < script type = " text/javascript " >
2016-08-23 08:50:23 +02:00
$ ( document ) . ready ( function () {
2019-01-30 16:18:44 +01:00
if ( $ ( " #stacked " ) . val () == '.CUSTOM_GRAPH_BULLET_CHART.' ) {
2016-08-23 08:50:23 +02:00
$ ( " #thresholdDiv " ) . show ();
} else {
$ ( " #thresholdDiv " ) . hide ();
}
2017-11-07 12:27:25 +01:00
if ( ! $ ( " #checkbox-summatory_series " ) . is ( " :checked " ) && ! $ ( " #checkbox-average_series " ) . is ( " :checked " )){
$ ( " #checkbox-modules_series " ) . attr ( " disabled " , true );
$ ( " #checkbox-modules_series " ) . attr ( " checked " , false );
}
2016-08-23 08:50:23 +02:00
});
2015-11-04 17:42:45 +01:00
$ ( " #stacked " ) . change ( function (){
2019-01-30 16:18:44 +01:00
if ( $ ( this ) . val () == '.CUSTOM_GRAPH_GAUGE.' ) {
2016-08-23 08:50:23 +02:00
$ ( " [name=threshold] " ) . prop ( " checked " , false );
2015-11-04 17:42:45 +01:00
$ ( " .stacked " ) . hide ();
$ ( " input[name= \ 'width \ '] " ) . hide ();
2016-08-23 08:50:23 +02:00
$ ( " #thresholdDiv " ) . hide ();
2019-01-30 16:18:44 +01:00
} else if ( $ ( this ) . val () == '.CUSTOM_GRAPH_BULLET_CHART.' ) {
2016-08-23 08:50:23 +02:00
$ ( " #thresholdDiv " ) . show ();
$ ( " .stacked " ) . show ();
$ ( " input[name= \ 'width \ '] " ) . show ();
} else {
$ ( " [name=threshold] " ) . prop ( " checked " , false );
2015-11-04 17:42:45 +01:00
$ ( " .stacked " ) . show ();
$ ( " input[name= \ 'width \ '] " ) . show ();
2016-08-23 08:50:23 +02:00
$ ( " #thresholdDiv " ) . hide ();
2015-11-04 17:42:45 +01:00
}
});
2017-11-07 12:27:25 +01:00
$ ( " #checkbox-summatory_series " ) . change ( function () {
if ( $ ( " #checkbox-summatory_series " ) . is ( " :checked " ) && $ ( " #checkbox-modules_series " ) . is ( " :disabled " )) {
$ ( " #checkbox-modules_series " ) . removeAttr ( " disabled " );
} else if ( ! $ ( " #checkbox-average_series " ) . is ( " :checked " )) {
$ ( " #checkbox-modules_series " ) . attr ( " disabled " , true );
$ ( " #checkbox-modules_series " ) . attr ( " checked " , false );
}
});
$ ( " #checkbox-average_series " ) . change ( function () {
if ( $ ( " #checkbox-average_series " ) . is ( " :checked " ) && $ ( " #checkbox-modules_series " ) . is ( " :disabled " )) {
$ ( " #checkbox-modules_series " ) . removeAttr ( " disabled " );
} else if ( ! $ ( " #checkbox-summatory_series " ) . is ( " :checked " )) {
$ ( " #checkbox-modules_series " ) . attr ( " disabled " , true );
$ ( " #checkbox-modules_series " ) . attr ( " checked " , false );
}
});
2015-11-04 17:42:45 +01:00
</ script > ' ;