2006-03-27 05:37:27 +02:00
< ? php
2007-03-12 18:58:52 +01:00
// Pandora FMS - the Free monitoring system
// ========================================
// Copyright (c) 2004-2007 Sancho Lerena, slerena@gmail.com
2007-06-22 14:00:04 +02:00
// Main PHP/SQL code development, project architecture and management.
2007-03-12 18:58:52 +01:00
// Copyright (c) 2004-2007 Raul Mateos Martin, raulofpandora@gmail.com
2007-06-22 14:00:04 +02:00
// CSS and some PHP code additions
// Copyright (c) 2006 Jose Navarro <jnavarro@jnavarro.net>
// Additions to code for Pandora FMS 1.2 graph code
2006-07-06 19:06:59 +02:00
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
2007-06-22 14:00:04 +02:00
// as published by the Free Software Foundation for version 2.
2006-07-06 19:06:59 +02:00
// 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.
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
2007-06-22 14:00:04 +02:00
// Pandora FMS 1.x uses icons from famfamfam, licensed under CC Atr. 2.5
// Silk icon set 1.3 (cc) Mark James, http://www.famfamfam.com/lab/icons/silk/
// Pandora FMS 1.x uses Pear Image::Graph code
2006-03-27 05:37:27 +02:00
include ( " ../include/config.php " );
include ( " ../include/functions.php " );
include ( " ../include/functions_db.php " );
require ( " ../include/languages/language_ " . $language_code . " .php " );
2007-02-20 19:09:54 +01:00
function graphic_error () {
Header ( " Content-type: image/png " );
$imgPng = imageCreateFromPng ( " ../images/image_problem.png " );
imageAlphaBlending ( $imgPng , true );
imageSaveAlpha ( $imgPng , true );
imagePng ( $imgPng );
2006-03-27 05:37:27 +02:00
}
2007-02-20 19:09:54 +01:00
function dame_fecha_grafico ( $mh , $format ){
2006-03-27 05:37:27 +02:00
// Date 24x7x30 hours ago (one month)
$m_year = date ( " Y " , time () - $mh * 60 );
$m_month = date ( " m " , time () - $mh * 60 );
2007-02-20 19:09:54 +01:00
$m_month_word = date ( " M " , time () - $mh * 60 );
2006-03-27 05:37:27 +02:00
$m_day = date ( " d " , time () - $mh * 60 );
$m_hour = date ( " H " , time () - $mh * 60 );
$m_min = date ( " i " , time () - $mh * 60 );
2007-02-20 19:09:54 +01:00
switch ( $format ) {
case 1 : $m = $m_month . " / " . $m_day . " " . $m_hour . " : " . $m_min ;
break ;
case 2 : $m = $m_year . " - " . $m_month . " - " . $m_day ;
break ;
case 3 : $m = $m_day . " th - " . $m_month_word . " \n " . $m_year ;
break ;
case 4 : $m = $m_day . " th - " . $m_month_word ;
break ;
}
2006-03-27 05:37:27 +02:00
return $m ;
}
2007-02-20 19:09:54 +01:00
function dame_fecha ( $mh ){
// Return a MySQL timestamp date, formatted with actual date MINUS X minutes, given as parameter
$m_year = date ( " Y " , time () - $mh * 60 );
$m_month = date ( " m " , time () - $mh * 60 );
$m_day = date ( " d " , time () - $mh * 60 );
$m_hour = date ( " H " , time () - $mh * 60 );
$m_min = date ( " i " , time () - $mh * 60 );
$m = $m_year . " - " . $m_month . " - " . $m_day . " " . $m_hour . " : " . $m_min . " :00 " ;
return $m ;
}
2006-07-04 18:01:36 +02:00
2007-03-12 18:58:52 +01:00
function dame_fecha_grafico_timestamp ( $timestamp ) {
return date ( 'd/m H:i' , $timestamp );
}
2007-02-16 19:29:37 +01:00
2007-06-07 19:46:38 +02:00
function graphic_combined_module ( $module_list , $weight_list , $periodo , $width , $height , $title , $unit_name , $show_event = 0 , $show_alert = 0 , $pure = 0 ) {
2007-03-28 18:07:29 +02:00
include ( " ../include/config.php " );
require ( " ../include/languages/language_ " . $language_code . " .php " );
require_once 'Image/Graph.php' ;
$resolution = $config_graph_res * 50 ; // Number of "slices" we want in graph
//$unix_timestamp = strtotime($mysql_timestamp) // Convert MYSQL format tio utime
$fechatope = time () - $periodo ; // limit date
$horasint = $periodo / $resolution ; // Each intervalo is $horasint seconds length
$module_number = count ( $module_list );
// intervalo - This is the number of "rows" we are divided the time to fill data.
// more interval, more resolution, and slower.
// periodo - Gap of time, in seconds. This is now to (now-periodo) secs
// Init tables
for ( $y = 0 ; $y < $module_number ; $y ++ ){
$real_data [ $y ] = array ();
2007-05-30 19:32:35 +02:00
$mod_data [ $y ] = 1 ; // Data multiplier to get the same scale on all modules
2007-03-28 18:07:29 +02:00
if ( $show_event == 1 )
$real_event [ $y ] = array ();
if ( isset ( $weight_list [ $y ])){
if ( $weight_list [ $y ] == 0 )
$weight_list [ $y ] = 1 ;
} else
$weight_list [ $y ] = 1 ;
}
$max_value = 0 ;
$min_value = 0 ;
// FOR EACH MODULE IN module_list....
for ( $y = 0 ; $y < $module_number ; $y ++ ){
$id_agente_modulo = $module_list [ $y ];
$nombre_agente = dame_nombre_agente_agentemodulo ( $id_agente_modulo );
$id_agente = dame_agente_id ( $nombre_agente );
$nombre_modulo = dame_nombre_modulo_agentemodulo ( $id_agente_modulo );
2007-05-31 20:49:14 +02:00
$module_list_name [ $y ] = substr ( $nombre_agente , 0 , 8 ) . " / " . substr ( $nombre_modulo , 0 , 18 );
2007-03-28 18:07:29 +02:00
for ( $x = 0 ; $x <= $resolution ; $x ++ ) {
$valores [ $x ][ 0 ] = 0 ; // SUM of all values for this interval
$valores [ $x ][ 1 ] = 0 ; // counter
$valores [ $x ][ 2 ] = $fechatope + ( $horasint * $x ); // [2] Top limit for this range
$valores [ $x ][ 3 ] = $fechatope + ( $horasint * ( $x + 1 )); // [3] Botom limit
$valores [ $x ][ 4 ] = 0 ; // MIN
$valores [ $x ][ 5 ] = 0 ; // MAX
$valores [ $x ][ 6 ] = 0 ; // Event
}
// Init other general variables
if ( $show_event == 1 ){
// If we want to show events in graphs
$sql1 = " SELECT utimestamp FROM tevento WHERE id_agente = $id_agente AND utimestamp > $fechatope " ;
$result = mysql_query ( $sql1 );
while ( $row = mysql_fetch_array ( $result )){
$utimestamp = $row [ 0 ];
for ( $i = 0 ; $i <= $resolution ; $i ++ ) {
if ( ( $utimestamp <= $valores [ $i ][ 3 ]) && ( $utimestamp >= $valores [ $i ][ 2 ]) ){
$real_event [ $i ] = 1 ;
}
}
}
}
$alert_high = 0 ;
2007-04-18 11:58:26 +02:00
$alert_low = 10000000 ;
2007-03-28 18:07:29 +02:00
if ( $show_alert == 1 ){
// If we want to show alerts limits
$sql1 = " SELECT * FROM talerta_agente_modulo where id_agente_modulo = " . $id_agente_modulo ;
$result = mysql_query ( $sql1 );
while ( $row = mysql_fetch_array ( $result )){
if ( $row [ " dis_max " ] > $alert_high )
$alert_high = $row [ " dis_max " ];
2007-04-18 11:58:26 +02:00
if ( $row [ " dis_min " ] < $alert_low )
$alert_low = $row [ " dis_min " ];
2007-03-28 18:07:29 +02:00
}
}
$previous = 0 ;
// Get the first data outsite (to the left---more old) of the interval given
$sql1 = " SELECT datos,utimestamp FROM tagente_datos WHERE id_agente = $id_agente AND id_agente_modulo = $id_agente_modulo AND utimestamp < $fechatope ORDER BY utimestamp DESC LIMIT 1 " ;
$result = mysql_query ( $sql1 );
if ( $row = mysql_fetch_array ( $result ))
$previous = $row [ 0 ];
$sql1 = " SELECT datos,utimestamp FROM tagente_datos WHERE id_agente = $id_agente AND id_agente_modulo = $id_agente_modulo AND utimestamp > $fechatope " ;
if ( $result = mysql_query ( $sql1 ))
while ( $row = mysql_fetch_array ( $result )){
$datos = $row [ 0 ];
$utimestamp = $row [ 1 ];
2007-06-07 19:46:38 +02:00
if ( $datos >= 0 ) {
2007-03-28 18:07:29 +02:00
for ( $i = 0 ; $i <= $resolution ; $i ++ ) {
if ( ( $utimestamp <= $valores [ $i ][ 3 ]) && ( $utimestamp >= $valores [ $i ][ 2 ]) ){
$valores [ $i ][ 0 ] = $valores [ $i ][ 0 ] + $datos ;
$valores [ $i ][ 1 ] ++ ;
// Init min value
if ( $valores [ $i ][ 4 ] == 0 )
$valores [ $i ][ 4 ] = $datos ;
else {
// Check min value
if ( $datos < $valores [ $i ][ 4 ])
$valores [ $i ][ 4 ] = $datos ;
}
// Check max value
if ( $datos > $valores [ $i ][ 5 ])
$valores [ $i ][ 5 ] = $datos ;
$i = $resolution + 1 ; // BREAK FOR
}
}
}
}
// Calculate Average value for $valores[][0]
for ( $x = 0 ; $x <= $resolution ; $x ++ ) {
if ( $valores [ $x ][ 1 ] > 0 ){
$valores [ $x ][ 0 ] = $valores [ $x ][ 0 ] / $valores [ $x ][ 1 ];
$real_data [ $y ][ $x ] = $weight_list [ $y ] * ( $valores [ $x ][ 0 ] / $valores [ $x ][ 1 ]);
} else {
$valores [ $x ][ 0 ] = $previous ;
$real_data [ $y ][ $x ] = $previous * $weight_list [ $y ];
$valores [ $x ][ 4 ] = $previous ;
$valores [ $x ][ 5 ] = $previous ;
}
// Get max value for all graph
2007-05-30 19:32:35 +02:00
if ( $valores [ $x ][ 5 ] > $max_value ){
$max_value = $valores [ $x ][ 5 ];
}
// This stores in mod_data max values for each module
if ( $mod_data [ $y ] < $valores [ $x ][ 5 ]){
$mod_data [ $y ] = $valores [ $x ][ 5 ];
}
2007-03-28 18:07:29 +02:00
// Take prev. value
// TODO: CHeck if there are more than 24hours between
// data, if there are > 24h, module down.
$previous = $valores [ $x ][ 0 ];
}
}
2007-05-30 19:32:35 +02:00
for ( $y = 0 ; $y < $module_number ; $y ++ ){
$weight_list [ $y ] = ( $max_value / $mod_data [ $y ]) + ( $weight_list [ $y ] - 1 );
if ( $weight_list [ $y ] != 1 )
$module_list_name [ $y ] .= " (x " . format_numeric ( $weight_list [ $y ], 1 ) . " ) " ;
2007-05-31 20:49:14 +02:00
$module_list_name [ $y ] = $module_list_name [ $y ] . " (MAX: " . format_numeric ( $mod_data [ $y ]) . " ) " ;
2007-05-30 19:32:35 +02:00
}
2007-03-28 18:07:29 +02:00
// Create graph
// *************
$Graph =& Image_Graph :: factory ( 'graph' , array ( $width , $height ));
// add a TrueType font
2007-06-07 19:46:38 +02:00
2007-03-28 18:07:29 +02:00
if ( $periodo == 86400 )
$title_period = " Last day " ;
elseif ( $periodo == 604800 )
$title_period = " Last week " ;
elseif ( $periodo == 3600 )
$title_period = " Last hour " ;
elseif ( $periodo == 2419200 )
$title_period = " Last month " ;
else
$title_period = " Last " . format_numeric (( $periodo / ( 3600 * 24 )), 2 ) . " days " ;
2007-06-07 19:46:38 +02:00
if ( $pure == 0 ){
$Font =& $Graph -> addNew ( 'font' , $config_fontpath );
$Font -> setSize ( 6 );
$Graph -> setFont ( $Font );
$Graph -> add (
2007-05-31 20:49:14 +02:00
Image_Graph :: vertical (
2007-06-07 19:46:38 +02:00
Image_Graph :: vertical (
$Title = Image_Graph :: factory ( 'title' , array ( ' Pandora FMS Graph - ' . $title_period , 10 )),
$Subtitle = Image_Graph :: factory ( 'title' , array ( ' ' . $title , 7 )),
90
),
Image_Graph :: vertical (
$Plotarea = Image_Graph :: factory ( 'plotarea' ),
$Legend = Image_Graph :: factory ( 'legend' ),
80
),
20 )
);
$Legend -> setPlotarea ( $Plotarea );
$Title -> setAlignment ( IMAGE_GRAPH_ALIGN_LEFT );
$Subtitle -> setAlignment ( IMAGE_GRAPH_ALIGN_LEFT );
} else {
$Font =& $Graph -> addNew ( 'font' , $config_fontpath );
$Font -> setSize ( 6 );
$Graph -> setFont ( $Font );
$Graph -> add (
Image_Graph :: vertical (
$Plotarea = Image_Graph :: factory ( 'plotarea' ),
$Legend = Image_Graph :: factory ( 'legend' ),
85
)
);
$Legend -> setPlotarea ( $Plotarea );
}
2007-03-28 18:07:29 +02:00
// Create the dataset
// Merge data into a dataset object (sancho)
// $Dataset =& Image_Graph::factory('dataset');
for ( $y = 0 ; $y < $module_number ; $y ++ ){
$dataset [ $y ] = Image_Graph :: factory ( 'dataset' );
$dataset [ $y ] -> setName ( $module_list_name [ $y ]);
}
if ( $show_event == 1 ){
$dataset_event = Image_Graph :: factory ( 'dataset' );
$dataset_event -> setName ( " Event Fired " );
}
// ... and populated with data ...
2007-06-25 19:33:22 +02:00
for ( $cc = 0 ; $cc < $resolution ; $cc ++ ) {
2007-03-28 18:07:29 +02:00
$tdate = date ( 'd/m' , $valores [ $cc ][ 2 ]) . " \n " . date ( 'H:i' , $valores [ $cc ][ 2 ]);
for ( $y = 0 ; $y < $module_number ; $y ++ ){
2007-05-30 19:32:35 +02:00
$dataset [ $y ] -> addPoint ( $tdate , $real_data [ $y ][ $cc ] * $weight_list [ $y ]);
2007-03-28 18:07:29 +02:00
if (( $show_event == 1 ) AND ( isset ( $real_event [ $cc ]))) {
$dataset_event -> addPoint ( $tdate , $max_value );
}
}
}
if ( $max_value > 0 ){
// Show events !
if ( $show_event == 1 ){
$Plot =& $Plotarea -> addNew ( 'Plot_Impulse' , array ( $dataset_event ));
$Plot -> setLineColor ( 'black' );
$Marker_event =& Image_Graph :: factory ( 'Image_Graph_Marker_Cross' );
$Plot -> setMarker ( $Marker_event );
$Marker_event -> setFillColor ( 'red' );
$Marker_event -> setLineColor ( 'red' );
$Marker_event -> setSize ( 5 );
}
// Show limits (for alert or whathever you want...
if ( $show_alert == 1 ){
$Plot =& $Plotarea -> addNew ( 'Image_Graph_Axis_Marker_Area' , IMAGE_GRAPH_AXIS_Y );
$Plot -> setFillColor ( 'blue@0.1' );
$Plot -> setLowerBound ( $alert_low );
$Plot -> setUpperBound ( $alert_high );
}
// create the 1st plot as smoothed area chart using the 1st dataset
$Plot =& $Plotarea -> addNew ( 'area' , array ( & $dataset ));
$Plot -> setLineColor ( 'gray@0.4' );
$AxisX =& $Plotarea -> getAxis ( IMAGE_GRAPH_AXIS_X );
// $AxisX->Hide();
$AxisY =& $Plotarea -> getAxis ( IMAGE_GRAPH_AXIS_Y );
$AxisY -> setLabelOption ( " showtext " , true );
$AxisY -> setLabelInterval ( ceil ( $max_value / 5 ));
$AxisY -> showLabel ( IMAGE_GRAPH_LABEL_ZERO );
if ( $unit_name != " " )
$AxisY -> setTitle ( $unit_name , 'vertical' );
$AxisX -> setLabelInterval ( $resolution / 10 );
//$AxisY->forceMinimum($minvalue);
2007-06-25 19:33:22 +02:00
//$AxisY->forceMaximum($max_value+($max_value/12)) ;
2007-03-28 18:07:29 +02:00
$GridY2 =& $Plotarea -> addNew ( 'bar_grid' , IMAGE_GRAPH_AXIS_Y_SECONDARY );
$GridY2 -> setLineColor ( 'gray' );
$GridY2 -> setFillColor ( 'lightgray@0.05' );
// set line colors
$FillArray =& Image_Graph :: factory ( 'Image_Graph_Fill_Array' );
$Plot -> setFillStyle ( $FillArray );
$FillArray -> addColor ( '#BFFF51@0.6' ); // Green
$FillArray -> addColor ( 'yellow@0.6' ); // yellow
$FillArray -> addColor ( '#FF5FDF@0.6' ); // pink
$FillArray -> addColor ( 'orange@0.6' ); // orange
$FillArray -> addColor ( '#7D8AFF@0.6' ); // blue
$FillArray -> addColor ( '#FF302A@0.6' ); // red
$FillArray -> addColor ( 'brown@0.6' ); // brown
$FillArray -> addColor ( 'green@0.6' );
$AxisY_Weather =& $Plotarea -> getAxis ( IMAGE_GRAPH_AXIS_Y );
$Graph -> done ();
} else
graphic_error ();
}
2007-04-18 11:58:26 +02:00
function grafico_modulo_sparse ( $id_agente_modulo , $periodo , $show_event ,
2007-06-07 19:46:38 +02:00
$width , $height , $title , $unit_name , $show_alert , $avg_only = 0 , $pure = 0 ) {
2007-02-20 19:09:54 +01:00
2006-03-27 05:37:27 +02:00
include ( " ../include/config.php " );
require ( " ../include/languages/language_ " . $language_code . " .php " );
2007-02-20 19:09:54 +01:00
require_once 'Image/Graph.php' ;
2006-03-27 05:37:27 +02:00
2007-02-20 19:09:54 +01:00
$resolution = $config_graph_res * 50 ; // Number of "slices" we want in graph
2006-07-09 00:32:05 +02:00
2007-02-20 19:09:54 +01:00
//$unix_timestamp = strtotime($mysql_timestamp) // Convert MYSQL format tio utime
$fechatope = time () - $periodo ; // limit date
$horasint = $periodo / $resolution ; // Each intervalo is $horasint seconds length
2007-02-16 19:29:37 +01:00
$nombre_agente = dame_nombre_agente_agentemodulo ( $id_agente_modulo );
$id_agente = dame_agente_id ( $nombre_agente );
$nombre_modulo = dame_nombre_modulo_agentemodulo ( $id_agente_modulo );
2007-04-18 11:58:26 +02:00
if ( $show_event == 1 )
$real_event = array ();
if ( $show_alert == 1 ){
$alert_high = 0 ;
$alert_low = 10000000 ;
// If we want to show alerts limits
$sql1 = " SELECT * FROM talerta_agente_modulo where id_agente_modulo = " . $id_agente_modulo ;
$result = mysql_query ( $sql1 );
while ( $row = mysql_fetch_array ( $result )){
if ( $row [ " dis_max " ] > $alert_high )
$alert_high = $row [ " dis_max " ];
if ( $row [ " dis_min " ] < $alert_low )
$alert_low = $row [ " dis_min " ];
}
// if no valid alert defined to render limits, disable it
if (( $alert_low == 10000000 ) && ( $alert_high == 0 )){
$show_alert = 0 ;
}
}
// intervalo - This is the number of "rows" we are divided the time
// to fill data. more interval, more resolution, and slower.
2007-02-16 19:29:37 +01:00
// periodo - Gap of time, in seconds. This is now to (now-periodo) secs
2006-07-09 00:32:05 +02:00
2007-02-16 19:29:37 +01:00
// Init tables
2007-02-20 19:09:54 +01:00
for ( $x = 0 ; $x <= $resolution ; $x ++ ) {
$valores [ $x ][ 0 ] = 0 ; // SUM of all values for this interval
$valores [ $x ][ 1 ] = 0 ; // counter
$valores [ $x ][ 2 ] = $fechatope + ( $horasint * $x ); // [2] Top limit for this range
$valores [ $x ][ 3 ] = $fechatope + ( $horasint * ( $x + 1 )); // [3] Botom limit
$valores [ $x ][ 4 ] = 0 ; // MIN
$valores [ $x ][ 5 ] = 0 ; // MAX
2007-04-18 11:58:26 +02:00
$valores [ $x ][ 6 ] = 0 ; // Event
}
// Init other general variables
if ( $show_event == 1 ){
// If we want to show events in graphs
$sql1 = " SELECT utimestamp FROM tevento WHERE id_agente = $id_agente AND utimestamp > $fechatope " ;
$result = mysql_query ( $sql1 );
while ( $row = mysql_fetch_array ( $result )){
$utimestamp = $row [ 0 ];
for ( $i = 0 ; $i <= $resolution ; $i ++ ) {
if ( ( $utimestamp <= $valores [ $i ][ 3 ]) && ( $utimestamp >= $valores [ $i ][ 2 ]) ){
$real_event [ $i ] = 1 ;
}
}
}
2007-02-16 19:29:37 +01:00
}
// Init other general variables
$max_value = 0 ;
2007-02-20 19:09:54 +01:00
$min_value = 0 ;
2007-02-16 19:29:37 +01:00
2007-02-20 19:09:54 +01:00
// DEBUG ONLY (to get number of items for this graph)
/*
// Make "THE" query. Very HUGE.
$sql1 = " SELECT COUNT(datos) FROM tagente_datos WHERE id_agente = $id_agente AND id_agente_modulo = $id_agente_modulo AND utimestamp > $fechatope " ;
2007-02-16 19:29:37 +01:00
$result = mysql_query ( $sql1 );
$row = mysql_fetch_array ( $result );
2007-02-20 19:09:54 +01:00
$title = $title . " [C] " . $row [ 0 ];
*/
$previous = 0 ;
// Get the first data outsite (to the left---more old) of the interval given
$sql1 = " SELECT datos,utimestamp FROM tagente_datos WHERE id_agente = $id_agente AND id_agente_modulo = $id_agente_modulo AND utimestamp < $fechatope ORDER BY utimestamp DESC LIMIT 1 " ;
$result = mysql_query ( $sql1 );
if ( $row = mysql_fetch_array ( $result ))
$previous = $row [ 0 ];
$sql1 = " SELECT datos,utimestamp FROM tagente_datos WHERE id_agente = $id_agente AND id_agente_modulo = $id_agente_modulo AND utimestamp > $fechatope " ;
$result = mysql_query ( $sql1 );
while ( $row = mysql_fetch_array ( $result )){
$datos = $row [ 0 ];
$utimestamp = $row [ 1 ];
2007-06-07 19:46:38 +02:00
if ( $datos >= 0 ) {
2007-02-20 19:09:54 +01:00
for ( $i = 0 ; $i <= $resolution ; $i ++ ) {
if ( ( $utimestamp <= $valores [ $i ][ 3 ]) && ( $utimestamp >= $valores [ $i ][ 2 ]) ){
$valores [ $i ][ 0 ] = $valores [ $i ][ 0 ] + $datos ;
$valores [ $i ][ 1 ] ++ ;
// Init min value
if ( $valores [ $i ][ 4 ] == 0 )
$valores [ $i ][ 4 ] = $datos ;
else {
// Check min value
if ( $datos < $valores [ $i ][ 4 ])
$valores [ $i ][ 4 ] = $datos ;
}
// Check max value
if ( $datos > $valores [ $i ][ 5 ])
$valores [ $i ][ 5 ] = $datos ;
$i = $resolution + 1 ; // BREAK FOR
}
2007-02-16 19:29:37 +01:00
}
2007-02-20 19:09:54 +01:00
}
}
// Calculate Average value for $valores[][0]
for ( $x = 0 ; $x <= $resolution ; $x ++ ) {
if ( $valores [ $x ][ 1 ] > 0 )
$valores [ $x ][ 0 ] = $valores [ $x ][ 0 ] / $valores [ $x ][ 1 ];
else {
$valores [ $x ][ 0 ] = $previous ;
$valores [ $x ][ 4 ] = $previous ;
$valores [ $x ][ 5 ] = $previous ;
2007-02-16 19:29:37 +01:00
}
2007-02-20 19:09:54 +01:00
// Get max value for all graph
if ( $valores [ $x ][ 5 ] > $max_value )
$max_value = $valores [ $x ][ 5 ];
// Take prev. value
// TODO: CHeck if there are more than 24hours between
// data, if there are > 24h, module down.
$previous = $valores [ $x ][ 0 ];
2007-02-16 19:29:37 +01:00
}
2007-02-20 19:09:54 +01:00
// Create graph
// *************
$Graph =& Image_Graph :: factory ( 'graph' , array ( $width , $height ));
// add a TrueType font
2006-07-04 18:01:36 +02:00
$Font =& $Graph -> addNew ( 'font' , $config_fontpath );
2007-02-16 19:29:37 +01:00
$Font -> setSize ( 6 );
2006-07-04 18:01:36 +02:00
$Graph -> setFont ( $Font );
2007-02-20 19:09:54 +01:00
if ( $periodo == 86400 )
$title_period = " Last day " ;
elseif ( $periodo == 604800 )
$title_period = " Last week " ;
elseif ( $periodo == 3600 )
$title_period = " Last hour " ;
elseif ( $periodo == 2419200 )
$title_period = " Last month " ;
else
2007-03-28 18:07:29 +02:00
$title_period = " Last " . format_numeric (( $periodo / ( 3600 * 24 )), 2 ) . " days " ;
2007-06-07 19:46:38 +02:00
if ( $pure == 0 ){
$Graph -> add (
2006-07-04 18:01:36 +02:00
Image_Graph :: vertical (
2007-06-07 19:46:38 +02:00
Image_Graph :: vertical (
$Title = Image_Graph :: factory ( 'title' , array ( ' Pandora FMS Graph - ' . strtoupper ( $nombre_agente ) . " - " . $title_period , 10 )),
$Subtitle = Image_Graph :: factory ( 'title' , array ( ' ' . $title , 7 )),
90
),
Image_Graph :: horizontal (
$Plotarea = Image_Graph :: factory ( 'plotarea' ),
$Legend = Image_Graph :: factory ( 'legend' ),
85
),
15 )
);
$Legend -> setPlotarea ( $Plotarea );
$Title -> setAlignment ( IMAGE_GRAPH_ALIGN_LEFT );
$Subtitle -> setAlignment ( IMAGE_GRAPH_ALIGN_LEFT );
} else { // Pure, without title and legends
$Graph -> add ( $Plotarea = Image_Graph :: factory ( 'plotarea' ));
}
2007-02-20 19:09:54 +01:00
// Create the dataset
// Merge data into a dataset object (sancho)
// $Dataset =& Image_Graph::factory('dataset');
2007-05-20 19:12:31 +02:00
if ( $avg_only == 1 ) {
$dataset [ 0 ] = Image_Graph :: factory ( 'dataset' );
$dataset [ 0 ] -> setName ( " Avg. " );
} else {
$dataset [ 0 ] = Image_Graph :: factory ( 'dataset' );
$dataset [ 0 ] -> setName ( " Max. " );
$dataset [ 1 ] = Image_Graph :: factory ( 'dataset' );
$dataset [ 1 ] -> setName ( " Avg. " );
$dataset [ 2 ] = Image_Graph :: factory ( 'dataset' );
$dataset [ 2 ] -> setName ( " Min. " );
}
2007-04-18 11:58:26 +02:00
// Event dataset creation
if ( $show_event == 1 ){
$dataset_event = Image_Graph :: factory ( 'dataset' );
$dataset_event -> setName ( " Event Fired " );
}
2006-07-04 18:01:36 +02:00
// ... and populated with data ...
2007-02-20 19:09:54 +01:00
for ( $cc = 0 ; $cc <= $resolution ; $cc ++ ) {
$tdate = date ( 'd/m' , $valores [ $cc ][ 2 ]) . " \n " . date ( 'H:i' , $valores [ $cc ][ 2 ]);
2007-05-20 19:12:31 +02:00
if ( $avg_only == 0 ) {
$dataset [ 1 ] -> addPoint ( $tdate , $valores [ $cc ][ 0 ]);
$dataset [ 0 ] -> addPoint ( $tdate , $valores [ $cc ][ 5 ]);
$dataset [ 2 ] -> addPoint ( $tdate , $valores [ $cc ][ 4 ]);
} else {
$dataset [ 0 ] -> addPoint ( $tdate , $valores [ $cc ][ 0 ]);
}
2007-04-18 11:58:26 +02:00
if (( $show_event == 1 ) AND ( isset ( $real_event [ $cc ]))) {
$dataset_event -> addPoint ( $tdate , $valores [ $cc ][ 5 ]);
}
2006-07-11 17:33:55 +02:00
}
2007-02-20 19:09:54 +01:00
if ( $max_value > 0 ){
2007-04-18 11:58:26 +02:00
// Show alert limits
if ( $show_alert == 1 ){
$Plot =& $Plotarea -> addNew ( 'Image_Graph_Axis_Marker_Area' , IMAGE_GRAPH_AXIS_Y );
$Plot -> setFillColor ( 'blue@0.1' );
$Plot -> setLowerBound ( $alert_low );
$Plot -> setUpperBound ( $alert_high );
}
2007-02-20 19:09:54 +01:00
// create the 1st plot as smoothed area chart using the 1st dataset
$Plot =& $Plotarea -> addNew ( 'area' , array ( & $dataset ));
2007-05-20 19:12:31 +02:00
if ( $avg_only == 1 ){
2007-06-07 19:46:38 +02:00
$Plot -> setLineColor ( 'black@0.1' );
2007-05-20 19:12:31 +02:00
} else {
2007-06-07 19:46:38 +02:00
$Plot -> setLineColor ( 'yellow@0.2' );
2007-05-20 19:12:31 +02:00
}
2007-02-20 19:09:54 +01:00
$AxisX =& $Plotarea -> getAxis ( IMAGE_GRAPH_AXIS_X );
// $AxisX->Hide();
2007-04-18 11:58:26 +02:00
2007-02-20 19:09:54 +01:00
$AxisY =& $Plotarea -> getAxis ( IMAGE_GRAPH_AXIS_Y );
2007-04-18 11:58:26 +02:00
$AxisY -> setDataPreprocessor ( Image_Graph :: factory ( 'Image_Graph_DataPreprocessor_Function' , 'format_for_graph' ));
2007-02-20 19:09:54 +01:00
$AxisY -> setLabelOption ( " showtext " , true );
2007-05-24 22:03:05 +02:00
$yinterval = $height / 30 ;
$AxisY -> setLabelInterval ( ceil ( $max_value / $yinterval ));
2007-02-20 19:09:54 +01:00
$AxisY -> showLabel ( IMAGE_GRAPH_LABEL_ZERO );
if ( $unit_name != " " )
$AxisY -> setTitle ( $unit_name , 'vertical' );
2007-05-24 22:03:05 +02:00
if ( $periodo < 10000 )
$xinterval = 8 ;
else
$xinterval = $resolution / 7 ;
$AxisX -> setLabelInterval ( $xinterval ) ;
2007-02-20 19:09:54 +01:00
//$AxisY->forceMinimum($minvalue);
$AxisY -> forceMaximum ( $max_value + ( $max_value / 12 )) ;
$GridY2 =& $Plotarea -> addNew ( 'bar_grid' , IMAGE_GRAPH_AXIS_Y_SECONDARY );
$GridY2 -> setLineColor ( 'gray' );
$GridY2 -> setFillColor ( 'lightgray@0.05' );
// set line colors
$FillArray =& Image_Graph :: factory ( 'Image_Graph_Fill_Array' );
2007-05-20 19:12:31 +02:00
2007-02-20 19:09:54 +01:00
$Plot -> setFillStyle ( $FillArray );
2007-05-20 19:12:31 +02:00
if ( $avg_only == 1 ){
$FillArray -> addColor ( 'green@0.6' );
} else {
$FillArray -> addColor ( 'yellow@0.5' );
$FillArray -> addColor ( 'orange@0.6' );
2007-05-30 19:32:35 +02:00
$FillArray -> addColor ( '#e37907@0.7' );
2007-05-20 19:12:31 +02:00
$FillArray -> addColor ( 'red@0.7' );
$FillArray -> addColor ( 'blue@0.7' );
$FillArray -> addColor ( 'green@0.7' );
$FillArray -> addColor ( 'black@0.7' );
}
2007-02-20 19:09:54 +01:00
$AxisY_Weather =& $Plotarea -> getAxis ( IMAGE_GRAPH_AXIS_Y );
2007-04-18 11:58:26 +02:00
// Show events !
if ( $show_event == 1 ){
$Plot =& $Plotarea -> addNew ( 'Plot_Impulse' , array ( $dataset_event ));
$Plot -> setLineColor ( 'red' );
$Marker_event =& Image_Graph :: factory ( 'Image_Graph_Marker_Cross' );
$Plot -> setMarker ( $Marker_event );
$Marker_event -> setFillColor ( 'red' );
$Marker_event -> setLineColor ( 'red' );
$Marker_event -> setSize ( 5 );
}
2007-02-20 19:09:54 +01:00
$Graph -> done ();
} else
graphic_error ();
2006-03-27 05:37:27 +02:00
}
2007-06-21 20:58:35 +02:00
function generic_pie_graph ( $width = 300 , $height = 200 , $data , $legend ) {
require ( " ../include/config.php " );
2007-02-20 19:09:54 +01:00
require_once 'Image/Graph.php' ;
2006-03-27 05:37:27 +02:00
require ( " ../include/languages/language_ " . $language_code . " .php " );
2007-06-21 20:58:35 +02:00
if ( sizeof ( $data ) > 0 ){
2007-02-20 19:09:54 +01:00
// create the graph
2007-06-08 17:55:53 +02:00
$driver =& Image_Canvas :: factory ( 'png' , array ( 'width' => $width , 'height' => $height , 'antialias' => 'native' ));
$Graph = & Image_Graph :: factory ( 'graph' , $driver );
2007-02-20 19:09:54 +01:00
// add a TrueType font
$Font =& $Graph -> addNew ( 'font' , $config_fontpath );
// set the font size to 7 pixels
$Font -> setSize ( 7 );
$Graph -> setFont ( $Font );
// create the plotarea
$Graph -> add (
Image_Graph :: horizontal (
$Plotarea = Image_Graph :: factory ( 'plotarea' ),
$Legend = Image_Graph :: factory ( 'legend' ),
50
)
);
$Legend -> setPlotarea ( $Plotarea );
// Create the dataset
// Merge data into a dataset object (sancho)
$Dataset1 =& Image_Graph :: factory ( 'dataset' );
2007-06-21 20:58:35 +02:00
for ( $a = 0 ; $a < sizeof ( $data ); $a ++ ){
2007-06-22 14:00:04 +02:00
$Dataset1 -> addPoint ( str_pad ( $legend [ $a ], 15 ), $data [ $a ]);
2007-02-20 19:09:54 +01:00
}
$Plot =& $Plotarea -> addNew ( 'pie' , $Dataset1 );
$Plotarea -> hideAxis ();
// create a Y data value marker
$Marker =& $Plot -> addNew ( 'Image_Graph_Marker_Value' , IMAGE_GRAPH_PCT_Y_TOTAL );
// create a pin-point marker type
$PointingMarker =& $Plot -> addNew ( 'Image_Graph_Marker_Pointing_Angular' , array ( 1 , & $Marker ));
// and use the marker on the 1st plot
$Plot -> setMarker ( $PointingMarker );
// format value marker labels as percentage values
$Marker -> setDataPreprocessor ( Image_Graph :: factory ( 'Image_Graph_DataPreprocessor_Formatted' , '%0.1f%%' ));
$Plot -> Radius = 15 ;
$FillArray =& Image_Graph :: factory ( 'Image_Graph_Fill_Array' );
$Plot -> setFillStyle ( $FillArray );
$FillArray -> addColor ( 'green@0.7' );
$FillArray -> addColor ( 'yellow@0.7' );
$FillArray -> addColor ( 'red@0.7' );
$FillArray -> addColor ( 'orange@0.7' );
$FillArray -> addColor ( 'blue@0.7' );
$FillArray -> addColor ( 'purple@0.7' );
$FillArray -> addColor ( 'lightgreen@0.7' );
$FillArray -> addColor ( 'lightblue@0.7' );
$FillArray -> addColor ( 'lightred@0.7' );
$FillArray -> addColor ( 'grey@0.6' , 'rest' );
$Plot -> explode ( 6 );
2007-06-21 20:58:35 +02:00
$Plot -> setStartingAngle ( 0 );
2007-02-20 19:09:54 +01:00
// output the Graph
$Graph -> done ();
} else
graphic_error ();
2006-03-27 05:37:27 +02:00
}
2007-06-21 20:58:35 +02:00
function graphic_agentmodules ( $id_agent , $width , $height ) {
include ( " ../include/config.php " );
require_once 'Image/Graph.php' ;
require ( " ../include/languages/language_ " . $language_code . " .php " );
$sql1 = " SELECT * FROM ttipo_modulo " ;
$result = mysql_query ( $sql1 );
$ax = 0 ;
while ( $row = mysql_fetch_array ( $result )){
$data_label [ $ax ] = $row [ " nombre " ];
$data [ $ax ] = 0 ;
$data_id [ $ax ] = $row [ " id_tipo " ];
$ax ++ ;
}
$cx = 0 ;
$sql1 = " SELECT * FROM tagente_modulo WHERE id_agente = " . $id_agent ;
$result = mysql_query ( $sql1 );
while ( $row = mysql_fetch_array ( $result )){
$cx ++ ;
for ( $bx = 0 ; $bx <= $ax ; $bx ++ ){
if ( isset ( $data_id [ $bx ])){
if ( $data_id [ $bx ] == $row [ " id_tipo_modulo " ]){
$data [ $bx ] ++ ;
}
}
}
}
2007-07-28 20:11:48 +02:00
$data2 = " " ;
$data_label2 = " " ;
2007-06-21 20:58:35 +02:00
$mayor = 0 ;
$mayor_data = 0 ;
for ( $a = 0 ; $a < sizeof ( $data ); $a ++ )
if ( $data [ $a ] > $mayor_data ){
$mayor = $a ;
$mayor_data = $data [ $a ];
}
$bx = 0 ;
for ( $a = 0 ; $a < sizeof ( $data_label ); $a ++ ){
if ( $data [ $a ] > 0 ){
$data_label2 [ $bx ] = $data_label [ $a ];
$data2 [ $bx ] = $data [ $a ];
$bx ++ ;
}
}
generic_pie_graph ( $width , $height , $data2 , $data_label2 );
}
2007-02-20 19:09:54 +01:00
function graphic_agentaccess ( $id_agent , $periodo , $width , $height ){
2006-03-27 05:37:27 +02:00
include ( " ../include/config.php " );
2007-02-20 19:09:54 +01:00
require_once 'Image/Graph.php' ;
2006-03-27 05:37:27 +02:00
require ( " ../include/languages/language_ " . $language_code . " .php " );
2006-09-01 01:54:13 +02:00
$color = " #437722 " ; // Green pandora 1.1 octopus color
2007-02-20 19:09:54 +01:00
/*
2006-03-27 05:37:27 +02:00
$agent_interval = give_agentinterval ( $id_agent );
$intervalo = 30 * $config_graph_res ; // Desired interval / range between dates
$intervalo_real = ( 86400 / $agent_interval ); // 60x60x24 secs
if ( $intervalo_real < $intervalo ) {
$intervalo = $intervalo_real ;
2007-02-20 19:09:54 +01:00
} */
$intervalo = 24 ;
2006-03-27 05:37:27 +02:00
$fechatope = dame_fecha ( $periodo );
$horasint = $periodo / $intervalo ;
// $intervalo now stores "ideal" interval }
// interval is the number of rows that will store data. more rows, more resolution
// Para crear las graficas vamos a crear un array de Ax4 elementos, donde
// A es el numero de posiciones diferentes en la grafica (30 para un mes, 7 para una semana, etc)
// y los 4 valores en el ejeY serian los detallados a continuacion:
// Rellenamos la tabla con un solo select, y los calculos se hacen todos sobre memoria
// esto acelera el tiempo de calculo al maximo, aunque complica el algoritmo :-)
// Creamos la tabla (array) con los valores para el grafico. Inicializacion
for ( $x = 0 ; $x < $intervalo ; $x ++ ) {
$valores [ $x ][ 0 ] = 0 ; // [0] Valor (contador)
$valores [ $x ][ 1 ] = 0 ; // [0] Valor (contador)
$valores [ $x ][ 2 ] = dame_fecha ( $horasint * $x ); // [2] Rango superior de fecha para ese rango
$valores [ $x ][ 3 ] = dame_fecha ( $horasint * ( $x + 1 )); // [3] Rango inferior de fecha para ese rango
}
$sql1 = " SELECT * FROM tagent_access WHERE id_agent = " . $id_agent . " and timestamp > ' " . $fechatope . " ' " ;
$result = mysql_query ( $sql1 );
while ( $row = mysql_fetch_array ( $result )){
for ( $i = 0 ; $i < $intervalo ; $i ++ ){
if (( $row [ " timestamp " ] < $valores [ $i ][ 2 ]) and ( $row [ " timestamp " ] >= $valores [ $i ][ 3 ]) ){
// entra en esta fila
$valores [ $i ][ 0 ] ++ ;
}
}
}
$valor_maximo = 0 ;
for ( $i = 0 ; $i < $intervalo ; $i ++ ) { // 30 entries in graph, one by day
$grafica [] = $valores [ $i ][ 0 ];
2007-02-20 19:09:54 +01:00
if ( $valores [ $i ][ 0 ] > $valor_maximo )
$valor_maximo = $valores [ $i ][ 0 ];
}
2006-03-27 05:37:27 +02:00
2007-02-20 19:09:54 +01:00
// Create graph
// create the graph
$Graph =& Image_Graph :: factory ( 'graph' , array ( $width , $height ));
// add a TrueType font
$Font =& $Graph -> addNew ( 'font' , $config_fontpath );
$Font -> setSize ( 6 );
$Graph -> setFont ( $Font );
$Graph -> add (
Image_Graph :: vertical (
Image_Graph :: factory ( 'title' , array ( " " , 2 )),
$Plotarea = Image_Graph :: factory ( 'plotarea' ),
0 )
);
// Create the dataset
// Merge data into a dataset object (sancho)
$Dataset =& Image_Graph :: factory ( 'dataset' );
for ( $a = 0 ; $a < sizeof ( $grafica ); $a ++ ){
$Dataset -> addPoint ( $a , $grafica [ $a ]);
2006-03-27 05:37:27 +02:00
}
2007-02-20 19:09:54 +01:00
// create the 1st plot as smoothed area chart using the 1st dataset
$Plot =& $Plotarea -> addNew ( 'area' , array ( & $Dataset ));
// set a line color
$Plot -> setLineColor ( 'green' );
// set a standard fill style
$Plot -> setFillColor ( 'green@0.5' );
// $Plotarea->hideAxis();
$AxisX =& $Plotarea -> getAxis ( IMAGE_GRAPH_AXIS_X );
// $AxisX->Hide();
2006-03-27 05:37:27 +02:00
2007-02-20 19:09:54 +01:00
$AxisY =& $Plotarea -> getAxis ( IMAGE_GRAPH_AXIS_Y );
$AxisY -> setLabelOption ( " showtext " , true );
$AxisY -> setLabelInterval ( $valor_maximo / 2 );
2006-03-27 05:37:27 +02:00
2007-02-20 19:09:54 +01:00
$AxisX -> setLabelInterval ( $intervalo / 5 );
2006-03-27 05:37:27 +02:00
2007-02-20 19:09:54 +01:00
$GridY2 =& $Plotarea -> addNew ( 'bar_grid' , IMAGE_GRAPH_AXIS_Y_SECONDARY );
$GridY2 -> setLineColor ( 'green' );
$GridY2 -> setFillColor ( 'green@0.2' );
$AxisY2 =& $Plotarea -> getAxis ( IMAGE_GRAPH_AXIS_Y_SECONDARY );
$Graph -> done ();
2006-03-27 05:37:27 +02:00
}
function grafico_incidente_estados () {
include ( " ../include/config.php " );
require ( " ../include/languages/language_ " . $language_code . " .php " );
$data = array ( 0 , 0 , 0 , 0 );
// 0 - Abierta / Sin notas
// 2 - Descartada
// 3 - Caducada
// 13 - Cerrada
$sql1 = " SELECT * FROM tincidencia " ;
$result = mysql_query ( $sql1 );
while ( $row = mysql_fetch_array ( $result )){
if ( $row [ " estado " ] == 0 )
$data [ 0 ] = $data [ 0 ] + 1 ;
if ( $row [ " estado " ] == 2 )
$data [ 1 ] = $data [ 1 ] + 1 ;
if ( $row [ " estado " ] == 3 )
$data [ 2 ] = $data [ 2 ] + 1 ;
if ( $row [ " estado " ] == 13 )
$data [ 3 ] = $data [ 3 ] + 1 ;
}
$mayor = 0 ;
2007-06-21 20:58:35 +02:00
$mayor_data = 0 ;
for ( $a = 0 ; $a < sizeof ( $data ); $a ++ ){
if ( $data [ $a ] > $mayor_data ){
$mayor = $a ;
$mayor_data = $data [ $a ];
}
}
2006-03-27 05:37:27 +02:00
$legend = array ( " Open Incident " , " Closed Incident " , " Outdated " , " Invalid " );
2007-06-21 20:58:35 +02:00
generic_pie_graph ( 370 , 180 , $data , $legend );
2006-03-27 05:37:27 +02:00
}
function grafico_incidente_prioridad () {
include ( " ../include/config.php " );
require ( " ../include/languages/language_ " . $language_code . " .php " );
$data = array ( 0 , 0 , 0 , 0 , 0 , 0 );
// 0 - Abierta / Sin notas
// 2 - Descartada
// 3 - Caducada
// 13 - Cerrada
$sql1 = " SELECT * FROM tincidencia " ;
$result = mysql_query ( $sql1 );
while ( $row = mysql_fetch_array ( $result )){
if ( $row [ " prioridad " ] == 0 )
$data [ 0 ] = $data [ 0 ] + 1 ;
if ( $row [ " prioridad " ] == 1 )
$data [ 1 ] = $data [ 1 ] + 1 ;
if ( $row [ " prioridad " ] == 2 )
$data [ 2 ] = $data [ 2 ] + 1 ;
if ( $row [ " prioridad " ] == 3 )
$data [ 3 ] = $data [ 3 ] + 1 ;
if ( $row [ " prioridad " ] == 4 )
$data [ 4 ] = $data [ 4 ] + 1 ;
if ( $row [ " prioridad " ] == 10 )
$data [ 5 ] = $data [ 5 ] + 1 ;
}
$mayor = 0 ;
2007-06-21 20:58:35 +02:00
$mayor_data = 0 ;
for ( $a = 0 ; $a < sizeof ( $data ); $a ++ )
if ( $data [ $a ] > $mayor_data ){
$mayor = $a ;
$mayor_data = $data [ $a ];
}
$legend = array ( " Informative " , " Low " , " Medium " , " Serious " , " Very serious " , " Maintance " );
generic_pie_graph ( 320 , 200 , $data , $legend );
2006-03-27 05:37:27 +02:00
}
function graphic_incident_group () {
include ( " ../include/config.php " );
require ( " ../include/languages/language_ " . $language_code . " .php " );
2007-06-21 20:58:35 +02:00
$data = array ();
$legend = array ();
$sql1 = " SELECT distinct id_grupo FROM tincidencia " ;
$result = mysql_query ( $sql1 );
while ( $row = mysql_fetch_array ( $result )){
$sql1 = " SELECT COUNT(id_incidencia) FROM tincidencia WHERE id_grupo = " . $row [ 0 ];
$result2 = mysql_query ( $sql1 );
$row2 = mysql_fetch_array ( $result2 );
$data [] = $row2 [ 0 ];
$legend [] = dame_nombre_grupo ( $row [ 0 ]) . " ( " . $row2 [ 0 ] . " ) " ;
2006-03-27 05:37:27 +02:00
}
2007-06-21 20:58:35 +02:00
// Sort array by bubble method (yes, I study more methods in university, but if you want more speed, please, submit a patch :)
// or much better, pay me to do a special version for you, highly optimized :-))))
for ( $a = 0 ; $a < sizeof ( $data ); $a ++ ){
for ( $b = $a ; $b < sizeof ( $data ); $b ++ )
if ( $data [ $b ] > $data [ $a ]){
$temp = $data [ $a ];
$temp_label = $legend [ $a ];
$data [ $a ] = $data [ $b ];
$legend [ $a ] = $legend [ $b ];
$data [ $b ] = $temp ;
$legend [ $b ] = $temp_label ;
}
}
$mayor = 0 ;
$mayor_data = 0 ;
for ( $a = 0 ; $a < sizeof ( $data ); $a ++ ){
if ( $data [ $a ] > $mayor_data ){
$mayor = $a ;
$mayor_data = $data [ $a ];
}
}
generic_pie_graph ( 320 , 200 , $data , $legend );
2006-03-27 05:37:27 +02:00
}
function graphic_incident_user () {
include ( " ../include/config.php " );
require ( " ../include/languages/language_ " . $language_code . " .php " );
$data = array ();
$legend = array ();
$sql1 = " SELECT distinct id_usuario FROM tincidencia " ;
$result = mysql_query ( $sql1 );
while ( $row = mysql_fetch_array ( $result )){
2007-06-21 20:58:35 +02:00
$sql1 = " SELECT COUNT(id_incidencia) FROM tincidencia WHERE id_usuario = ' " . $row [ 0 ] . " ' " ;
$result2 = mysql_query ( $sql1 );
$row2 = mysql_fetch_array ( $result2 );
$data [] = $row2 [ 0 ];
$legend [] = $row [ 0 ] . " ( " . $row2 [ 0 ] . " ) " ;
2006-03-27 05:37:27 +02:00
}
// Sort array by bubble method (yes, I study more methods in university, but if you want more speed, please, submit a patch :)
2007-06-21 20:58:35 +02:00
// or much better, pay me to do a special version for you, highly optimized :-))))
for ( $a = 0 ; $a < sizeof ( $data ); $a ++ ){
for ( $b = $a ; $b < sizeof ( $data ); $b ++ )
if ( $data [ $b ] > $data [ $a ]){
$temp = $data [ $a ];
$temp_label = $legend [ $a ];
$data [ $a ] = $data [ $b ];
$legend [ $a ] = $legend [ $b ];
$data [ $b ] = $temp ;
$legend [ $b ] = $temp_label ;
}
}
$mayor = 0 ;
$mayor_data = 0 ;
for ( $a = 0 ; $a < sizeof ( $data ); $a ++ ){
if ( $data [ $a ] > $mayor_data ){
$mayor = $a ;
$mayor_data = $data [ $a ];
}
}
generic_pie_graph ( 320 , 200 , $data , $legend );
2006-03-27 05:37:27 +02:00
}
2007-06-22 14:00:04 +02:00
function graphic_user_activity ( $width = 350 , $height = 230 ) {
2006-03-27 05:37:27 +02:00
include ( " ../include/config.php " );
require ( " ../include/languages/language_ " . $language_code . " .php " );
$data = array ();
$legend = array ();
$sql1 = " SELECT DISTINCT ID_usuario FROM tsesion " ;
$result = mysql_query ( $sql1 );
while ( $row = mysql_fetch_array ( $result )){
2007-06-21 20:58:35 +02:00
$entrada = entrada_limpia ( $row [ 0 ]);
$sql1 = 'SELECT COUNT(ID_usuario) FROM tsesion WHERE ID_usuario = "' . $entrada . '"' ;
$result2 = mysql_query ( $sql1 );
$row2 = mysql_fetch_array ( $result2 );
$data [] = $row2 [ 0 ];
2007-06-22 14:00:04 +02:00
$legend [] = str_pad ( substr ( $row [ 0 ], 0 , 16 ) . " ( " . format_for_graph ( $row2 [ 0 ], 0 ) . " ) " , 15 );
2006-03-27 05:37:27 +02:00
}
// Sort array by bubble method (yes, I study more methods in university, but if you want more speed, please, submit a patch :)
// or much better, pay me to do a special version for you, highly optimized :-))))
for ( $a = 0 ; $a < sizeof ( $data ); $a ++ ){
for ( $b = $a ; $b < sizeof ( $data ); $b ++ )
if ( $data [ $b ] > $data [ $a ]){
$temp = $data [ $a ];
$temp_label = $legend [ $a ];
$data [ $a ] = $data [ $b ];
$legend [ $a ] = $legend [ $b ];
$data [ $b ] = $temp ;
$legend [ $b ] = $temp_label ;
}
}
2007-06-21 20:58:35 +02:00
// Take only the first 5 items
if ( sizeof ( $data ) >= 5 ){
for ( $a = 0 ; $a < 5 ; $a ++ ){
$legend2 [] = $legend [ $a ];
$data2 [] = $data [ $a ];
}
generic_pie_graph ( $width , $height , $data2 , $legend2 );
} else
generic_pie_graph ( $width , $height , $data , $legend );
2006-03-27 05:37:27 +02:00
}
2007-06-21 20:58:35 +02:00
function graphic_incident_source ( $width = 320 , $height = 200 ) {
2006-03-27 05:37:27 +02:00
include ( " ../include/config.php " );
require ( " ../include/languages/language_ " . $language_code . " .php " );
2007-06-21 20:58:35 +02:00
$data = array ();
$legend = array ();
$sql1 = " SELECT DISTINCT origen FROM tincidencia " ;
$result = mysql_query ( $sql1 );
while ( $row = mysql_fetch_array ( $result )){
$sql1 = " SELECT COUNT(id_incidencia) FROM tincidencia WHERE origen = ' " . $row [ 0 ] . " ' " ;
$result2 = mysql_query ( $sql1 );
$row2 = mysql_fetch_array ( $result2 );
$data [] = $row2 [ 0 ];
$legend [] = $row [ 0 ] . " ( " . $row2 [ 0 ] . " ) " ;
}
// Sort array by bubble method (yes, I study more methods in university, but if you want more speed, please, submit a patch :)
// or much better, pay me to do a special version for you, highly optimized :-))))
for ( $a = 0 ; $a < sizeof ( $data ); $a ++ ){
for ( $b = $a ; $b < sizeof ( $data ); $b ++ )
if ( $data [ $b ] > $data [ $a ]){
$temp = $data [ $a ];
$temp_label = $legend [ $a ];
$data [ $a ] = $data [ $b ];
$legend [ $a ] = $legend [ $b ];
$data [ $b ] = $temp ;
$legend [ $b ] = $temp_label ;
}
}
// Take only the first 5 items
if ( sizeof ( $data ) >= 5 ){
for ( $a = 0 ; $a < 5 ; $a ++ ){
$legend2 [] = $legend [ $a ];
$data2 [] = $data [ $a ];
}
generic_pie_graph ( $width , $height , $data2 , $legend2 );
} else
generic_pie_graph ( $width , $height , $data , $legend );
2006-03-27 05:37:27 +02:00
}
2007-06-21 20:58:35 +02:00
2007-06-22 14:00:04 +02:00
function grafico_db_agentes_modulos ( $width , $height ) {
2006-03-27 05:37:27 +02:00
include ( " ../include/config.php " );
require ( " ../include/languages/language_ " . $language_code . " .php " );
$data = array ();
$legend = array ();
$sql1 = " SELECT * FROM tagente " ;
$result = mysql_query ( $sql1 );
while ( $row = mysql_fetch_array ( $result )){
$sql1 = " SELECT COUNT(id_agente_modulo) FROM tagente_modulo WHERE id_agente = " . $row [ " id_agente " ];;
$result2 = mysql_query ( $sql1 );
$row2 = mysql_fetch_array ( $result2 );
$data [] = $row2 [ 0 ];
$legend [] = $row [ " nombre " ];
}
// Sort array by bubble method (yes, I study more methods in university, but if you want more speed, please, submit a patch :)
2007-06-22 14:00:04 +02:00
// or much better, pay me to do a special version for you, highly optimized :-))))
for ( $a = 0 ; $a < sizeof ( $data ); $a ++ ){
for ( $b = $a ; $b < sizeof ( $data ); $b ++ )
if ( $data [ $b ] > $data [ $a ]){
$temp = $data [ $a ];
$temp_label = $legend [ $a ];
$data [ $a ] = $data [ $b ];
$legend [ $a ] = $legend [ $b ];
$data [ $b ] = $temp ;
$legend [ $b ] = $temp_label ;
}
}
generic_bar_graph ( $width , $height , $data , $legend );
2006-03-27 05:37:27 +02:00
}
2007-06-22 14:00:04 +02:00
function grafico_eventos_usuario ( $width = 420 , $height = 200 ) {
2006-03-27 05:37:27 +02:00
include ( " ../include/config.php " );
require ( " ../include/languages/language_ " . $language_code . " .php " );
$data = array ();
$legend = array ();
$sql1 = " SELECT * FROM tusuario " ;
$result = mysql_query ( $sql1 );
while ( $row = mysql_fetch_array ( $result )){
$sql1 = " SELECT COUNT(id_evento) FROM tevento WHERE id_usuario = ' " . $row [ " id_usuario " ] . " ' " ;
$result2 = mysql_query ( $sql1 );
$row2 = mysql_fetch_array ( $result2 );
if ( $row2 [ 0 ] > 0 ){
$data [] = $row2 [ 0 ];
$legend [] = $row [ " id_usuario " ] . " ( $row2[0] ) " ;
}
}
// Sort array by bubble method (yes, I study more methods in university, but if you want more speed, please, submit a patch :)
2007-06-21 20:58:35 +02:00
// or much better, pay me to do a special version for you, highly optimized :-))))
for ( $a = 0 ; $a < sizeof ( $data ); $a ++ ){
for ( $b = $a ; $b < sizeof ( $data ); $b ++ )
if ( $data [ $b ] > $data [ $a ]){
$temp = $data [ $a ];
$temp_label = $legend [ $a ];
$data [ $a ] = $data [ $b ];
$legend [ $a ] = $legend [ $b ];
$data [ $b ] = $temp ;
$legend [ $b ] = $temp_label ;
}
2006-03-27 05:37:27 +02:00
}
2007-06-21 20:58:35 +02:00
// Take only the first 5 items
if ( sizeof ( $data ) >= 5 ){
for ( $a = 0 ; $a < 5 ; $a ++ ){
$legend2 [] = $legend [ $a ];
$data2 [] = $data [ $a ];
}
generic_pie_graph ( $width , $height , $data2 , $legend2 );
} else
generic_pie_graph ( $width , $height , $data , $legend );
2006-03-27 05:37:27 +02:00
}
function grafico_eventos_total () {
2007-06-21 20:58:35 +02:00
require ( " ../include/config.php " );
2006-03-27 05:37:27 +02:00
require ( " ../include/languages/language_ " . $language_code . " .php " );
$data = array ();
$legend = array ();
$total = 0 ;
$sql1 = " SELECT COUNT(id_evento) FROM tevento WHERE estado = 1 " ;
$result = mysql_query ( $sql1 );
$row = mysql_fetch_array ( $result );
$data [] = $row [ 0 ];
$legend [] = " Revised ( $row[0] ) " ;
$total = $row [ 0 ];
$sql1 = " SELECT COUNT(id_evento) FROM tevento WHERE estado = 0 " ;
$result = mysql_query ( $sql1 );
$row = mysql_fetch_array ( $result );
$data [] = $row [ 0 ];
$total = $total + $row [ 0 ];
$legend [] = " Not Revised ( $row[0] ) " ;
// Sort array by bubble method (yes, I study more methods in university, but if you want more speed, please, submit a patch :)
2007-06-21 20:58:35 +02:00
// or much better, pay me to do a special version for you, highly optimized :-))))
for ( $a = 0 ; $a < sizeof ( $data ); $a ++ ){
for ( $b = $a ; $b < sizeof ( $data ); $b ++ )
if ( $data [ $b ] > $data [ $a ]){
$temp = $data [ $a ];
$temp_label = $legend [ $a ];
$data [ $a ] = $data [ $b ];
$legend [ $a ] = $legend [ $b ];
$data [ $b ] = $temp ;
$legend [ $b ] = $temp_label ;
}
}
generic_pie_graph ( 320 , 200 , $data , $legend );
2006-03-27 05:37:27 +02:00
}
2007-06-21 20:58:35 +02:00
function grafico_eventos_grupo ( $width = 300 , $height = 200 ) {
2006-03-27 05:37:27 +02:00
include ( " ../include/config.php " );
require ( " ../include/languages/language_ " . $language_code . " .php " );
$data = array ();
$legend = array ();
$sql1 = " SELECT * FROM tgrupo " ;
$result = mysql_query ( $sql1 );
while ( $row = mysql_fetch_array ( $result )){
$sql1 = " SELECT COUNT(id_evento) fROM tevento WHERE id_grupo = " . $row [ " id_grupo " ];
$result2 = mysql_query ( $sql1 );
$row2 = mysql_fetch_array ( $result2 );
if ( $row2 [ 0 ] > 0 ){
$data [] = $row2 [ 0 ];
$legend [] = $row [ " nombre " ] . " ( $row2[0] ) " ;
}
}
// Sort array by bubble method (yes, I study more methods in university, but if you want more speed, please, submit a patch :)
2007-06-21 20:58:35 +02:00
// or much better, pay me to do a special version for you, highly optimized :-))))
for ( $a = 0 ; $a < sizeof ( $data ); $a ++ ){
for ( $b = $a ; $b < sizeof ( $data ); $b ++ )
if ( $data [ $b ] > $data [ $a ]){
$temp = $data [ $a ];
$temp_label = $legend [ $a ];
$data [ $a ] = $data [ $b ];
$legend [ $a ] = $legend [ $b ];
$data [ $b ] = $temp ;
$legend [ $b ] = $temp_label ;
}
}
// Take only the first x items
if ( sizeof ( $data ) >= 7 ){
for ( $a = 0 ; $a < 7 ; $a ++ ){
$legend2 [] = $legend [ $a ];
$data2 [] = $data [ $a ];
}
generic_pie_graph ( $width , $height , $data2 , $legend2 );
} else
generic_pie_graph ( $width , $height , $data , $legend );
2006-03-27 05:37:27 +02:00
}
2007-06-22 14:00:04 +02:00
2007-07-23 13:02:31 +02:00
function generic_bar_graph ( $width = 380 , $height = 200 , $data , $legend ) {
2007-06-22 14:00:04 +02:00
include ( " ../include/config.php " );
require_once 'Image/Graph.php' ;
require ( " ../include/languages/language_ " . $language_code . " .php " );
2007-07-23 13:02:31 +02:00
if ( sizeof ( $data ) > 10 ){
$height = sizeof ( $legend ) * 20 ;
}
2007-06-22 14:00:04 +02:00
// create the graph
$Graph =& Image_Graph :: factory ( 'graph' , array ( $width , $height ));
// add a TrueType font
$Font =& $Graph -> addNew ( 'font' , $config_fontpath );
2007-07-23 13:02:31 +02:00
$Font -> setSize ( 9 );
2007-06-22 14:00:04 +02:00
$Graph -> setFont ( $Font );
$Graph -> add (
Image_Graph :: vertical (
$Plotarea = Image_Graph :: factory ( 'plotarea' , array ( 'category' , 'axis' , 'horizontal' )),
$Legend = Image_Graph :: factory ( 'legend' ),
100
)
);
$Legend -> setPlotarea ( $Plotarea );
// Create the dataset
// Merge data into a dataset object (sancho)
$Dataset1 =& Image_Graph :: factory ( 'dataset' );
for ( $a = 0 ; $a < sizeof ( $data ); $a ++ ){
2007-07-23 13:02:31 +02:00
$Dataset1 -> addPoint ( substr ( $legend [ $a ], 0 , 22 ), $data [ $a ]);
2007-06-22 14:00:04 +02:00
}
$Plot =& $Plotarea -> addNew ( 'bar' , $Dataset1 );
$GridY2 =& $Plotarea -> addNew ( 'bar_grid' , IMAGE_GRAPH_AXIS_Y_SECONDARY );
$GridY2 -> setLineColor ( 'gray' );
$GridY2 -> setFillColor ( 'lightgray@0.05' );
$Plot -> setLineColor ( 'gray' );
$Plot -> setFillColor ( 'blue@0.85' );
$Graph -> done ();
}
function grafico_db_agentes_paquetes ( $width = 380 , $height = 300 ) {
2006-03-27 05:37:27 +02:00
include ( " ../include/config.php " );
require ( " ../include/languages/language_ " . $language_code . " .php " );
$data = array ();
$legend = array ();
$sql1 = " SELECT distinct (id_agente) FROM tagente_datos " ;
$result = mysql_query ( $sql1 );
while ( $row = mysql_fetch_array ( $result )){
if ( ! is_null ( $row [ " id_agente " ])){
$sql1 = " SELECT COUNT(id_agente) FROM tagente_datos WHERE id_agente = " . $row [ " id_agente " ];
$result3 = mysql_query ( $sql1 );
if ( $row3 = mysql_fetch_array ( $result3 )){
2007-07-23 13:02:31 +02:00
$agent_name = dame_nombre_agente ( $row [ 0 ]);
if ( $agent_name != " " ){
$data [] = $row3 [ 0 ];
$legend [] = str_pad ( $agent_name , 15 );
}
2006-03-27 05:37:27 +02:00
}
}
}
// Sort array by bubble method (yes, I study more methods in university, but if you want more speed, please, submit a patch :)
2007-06-22 14:00:04 +02:00
// or much better, pay me to do a special version for you, highly optimized :-))))
for ( $a = 0 ; $a < sizeof ( $data ); $a ++ ){
for ( $b = $a ; $b < sizeof ( $data ); $b ++ )
if ( $data [ $b ] > $data [ $a ]){
$temp = $data [ $a ];
$temp_label = $legend [ $a ];
$data [ $a ] = $data [ $b ];
$legend [ $a ] = $legend [ $b ];
$data [ $b ] = $temp ;
$legend [ $b ] = $temp_label ;
}
}
generic_bar_graph ( $width , $height , $data , $legend );
2006-03-27 05:37:27 +02:00
}
2007-06-22 14:00:04 +02:00
function grafico_db_agentes_purge ( $id_agent , $width , $height ) {
2006-03-27 05:37:27 +02:00
include ( " ../include/config.php " );
2007-03-28 18:07:29 +02:00
require_once 'Image/Graph.php' ;
2006-03-27 05:37:27 +02:00
require ( " ../include/languages/language_ " . $language_code . " .php " );
// All data (now)
$purge_all = date ( " Y-m-d H:i:s " , time ());
$data = array ();
$legend = array ();
2007-03-28 18:07:29 +02:00
$d90 = time () - ( 2592000 * 3 );
$d30 = time () - 2592000 ;
$d7 = time () - 604800 ;
$d1 = time () - 86400 ;
$fechas = array ( $d90 , $d30 , $d7 , $d1 );
$fechas_label = array ( " 30-90 days " , " 7-30 days " , " This week " , " Today " );
2006-03-27 05:37:27 +02:00
// Calc. total packets
$sql1 = " SELECT COUNT(id_agente_datos) FROM tagente_datos " ;;
$result2 = mysql_query ( $sql1 );
$row2 = mysql_fetch_array ( $result2 );
$total = $row2 [ 0 ];
2007-03-28 18:07:29 +02:00
for ( $a = 0 ; $a < sizeof ( $fechas ); $a ++ ){
// 4 x intervals will be enought, increase if your database is very very fast :)
2007-06-22 14:00:04 +02:00
if ( $a == 3 ){
if ( $id_agent == - 1 )
$sql1 = " SELECT COUNT(id_agente_datos) FROM tagente_datos WHERE utimestamp >= " . $fechas [ $a ];
else
$sql1 = " SELECT COUNT(id_agente_datos) FROM tagente_datos WHERE id_agente = $id_agent AND utimestamp >= " . $fechas [ $a ];
} else {
if ( $id_agent == - 1 )
$sql1 = " SELECT COUNT(id_agente_datos) FROM tagente_datos WHERE utimestamp >= " . $fechas [ $a ] . " AND utimestamp < " . $fechas [ $a + 1 ];
else
$sql1 = " SELECT COUNT(id_agente_datos) FROM tagente_datos WHERE id_agente = $id_agent AND utimestamp >= " . $fechas [ $a ] . " AND utimestamp < " . $fechas [ $a + 1 ];
}
2006-03-27 05:37:27 +02:00
$result = mysql_query ( $sql1 );
$row = mysql_fetch_array ( $result );
2007-06-22 14:00:04 +02:00
$data [] = $row [ 0 ];
$legend [] = $fechas_label [ $a ] . " ( " . format_for_graph ( $row [ 0 ], 0 ) . " ) " ;
2006-03-27 05:37:27 +02:00
}
2007-06-22 14:00:04 +02:00
generic_pie_graph ( $width , $height , $data , $legend );
2006-03-27 05:37:27 +02:00
}
2006-07-01 03:48:56 +02:00
function drawWarning ( $width , $height ) {
include ( " ../include/config.php " );
require ( " ../include/languages/language_ " . $language_code . " .php " );
2006-06-29 21:31:53 +02:00
if ( $width == 0 ) {
2006-07-01 03:48:56 +02:00
$width = 50 ;
2006-06-29 21:31:53 +02:00
}
if ( $height == 0 ) {
2006-07-01 03:48:56 +02:00
$height = 30 ;
2006-06-29 21:31:53 +02:00
}
$image = imagecreate ( $width , $height );
//colors
$back = ImageColorAllocate ( $image , 255 , 255 , 255 );
$border = ImageColorAllocate ( $image , 0 , 0 , 0 );
$red = ImageColorAllocate ( $image , 255 , 60 , 75 );
$fill = ImageColorAllocate ( $image , 44 , 81 , 150 );
2006-07-01 03:48:56 +02:00
2006-06-29 21:31:53 +02:00
ImageFilledRectangle ( $image , 0 , 0 , $width - 1 , $height - 1 , $back );
ImageRectangle ( $image , 0 , 0 , $width - 1 , $height - 1 , $border );
2006-07-01 03:48:56 +02:00
ImageTTFText ( $image , 8 , 0 , ( $width / 2 ) - ( $width / 10 ), ( $height / 2 ) + ( $height / 5 ), $border , $config_fontpath , $lang_label [ " no_data " ]);
2006-06-29 21:31:53 +02:00
imagePNG ( $image );
imagedestroy ( $image );
2006-07-01 03:48:56 +02:00
}
2007-02-16 19:29:37 +01:00
2006-07-01 03:48:56 +02:00
function progress_bar ( $progress , $width , $height ) {
// Copied from the PHP manual:
// http://us3.php.net/manual/en/function.imagefilledrectangle.php
// With some adds from sdonie at lgc dot com
// Get from official documentation PHP.net website. Thanks guys :-)
// Code ripped from Babel Project :-)
2006-11-06 16:15:34 +01:00
function drawRating ( $rating , $width , $height ) {
include ( " ../include/config.php " );
require ( " ../include/languages/language_ " . $language_code . " .php " );
if ( $width == 0 ) {
$width = 150 ;
}
if ( $height == 0 ) {
$height = 20 ;
}
//$rating = $_GET['rating'];
$ratingbar = (( $rating / 100 ) * $width ) - 2 ;
$image = imagecreate ( $width , $height );
//colors
$back = ImageColorAllocate ( $image , 255 , 255 , 255 );
$border = ImageColorAllocate ( $image , 0 , 0 , 0 );
$red = ImageColorAllocate ( $image , 255 , 60 , 75 );
$fill = ImageColorAllocate ( $image , 44 , 81 , 150 );
2007-03-12 18:58:52 +01:00
$rating = format_numeric ( $rating , 2 );
2006-11-06 16:15:34 +01:00
ImageFilledRectangle ( $image , 0 , 0 , $width - 1 , $height - 1 , $back );
2007-02-16 19:29:37 +01:00
if ( $rating > 100 )
ImageFilledRectangle ( $image , 1 , 1 , $ratingbar , $height - 1 , $red );
else
2006-11-06 16:15:34 +01:00
ImageFilledRectangle ( $image , 1 , 1 , $ratingbar , $height - 1 , $fill );
2007-02-16 19:29:37 +01:00
ImageRectangle ( $image , 0 , 0 , $width - 1 , $height - 1 , $border );
if ( $rating > 50 )
if ( $rating > 100 )
ImageTTFText ( $image , 8 , 0 , ( $width / 4 ), ( $height / 2 ) + ( $height / 5 ), $back , $config_fontpath , $lang_label [ " out_of_limits " ]);
else
ImageTTFText ( $image , 8 , 0 , ( $width / 2 ) - ( $width / 10 ), ( $height / 2 ) + ( $height / 5 ), $back , $config_fontpath , $rating . " % " );
else
ImageTTFText ( $image , 8 , 0 , ( $width / 2 ) - ( $width / 10 ), ( $height / 2 ) + ( $height / 5 ), $border , $config_fontpath , $rating . " % " );
2006-11-06 16:15:34 +01:00
imagePNG ( $image );
imagedestroy ( $image );
2007-02-16 19:29:37 +01:00
}
Header ( " Content-type: image/png " );
2006-11-06 16:15:34 +01:00
if ( $progress > 100 || $progress < 0 ){
2007-02-16 19:29:37 +01:00
// HACK: This report a static image... will increase render in about 200% :-) useful for
// high number of realtime statusbar images creation (in main all agents view, for example
2007-07-16 20:47:39 +02:00
$imgPng = imageCreateFromPng ( " ../images/outof.png " );
2006-11-06 16:15:34 +01:00
imageAlphaBlending ( $imgPng , true );
imageSaveAlpha ( $imgPng , true );
2007-02-16 19:29:37 +01:00
imagePng ( $imgPng );
} else
drawRating ( $progress , $width , $height );
2006-06-29 21:31:53 +02:00
}
2007-06-22 14:00:04 +02:00
/* NOT USED !
2007-02-16 19:29:37 +01:00
function graphic_test ( $id , $period , $interval , $label , $width , $height ){
require_once 'Image/Graph.php' ;
include ( " ../include/config.php " );
$color = " #437722 " ; // Green pandora 1.1 octopus color
2006-03-27 05:37:27 +02:00
2007-02-16 19:29:37 +01:00
$intervalo = 500 ; // We want 30 slices for graph resolution.
$now_date = dame_fecha ( 0 );
$horasint = $period / $intervalo ;
$top_date = dame_fecha ( $period );
2006-03-27 05:37:27 +02:00
2007-02-16 19:29:37 +01:00
// Para crear las graficas vamos a crear un array de Ax4 elementos, donde
// A es el numero de posiciones diferentes en la grafica (30 para un mes, 7 para una semana, etc)
// y los 4 valores en el ejeY serian los detallados a continuacion:
// Rellenamos la tabla con un solo select, y los calculos se hacen todos sobre memoria
// esto acelera el tiempo de calculo al maximo, aunque complica el algoritmo :-)
2006-03-27 05:37:27 +02:00
2007-02-16 19:29:37 +01:00
$total_items = 5000 ;
$factor = rand ( 1 , 10 ); $b = 0 ;
// This is my temporal data (only a simple static test by now)
for ( $a = 0 ; $a < $total_items ; $a ++ ){
$valor = 1 + cos ( deg2rad ( $b ));
$b = $b + $factor / 10 ;
if ( $b > 180 ){
$b = 0 ;
2006-03-27 05:37:27 +02:00
}
2007-02-16 19:29:37 +01:00
$valor = $valor * $b ;
$valores [ $a ][ 0 ] = $valor ;
$valores [ $a ][ 1 ] = $a ;
}
// Creamos la tabla (array) con los valores para el grafico. Inicializacion
$valor_maximo = 0 ;
$maxvalue = 0 ;
$minvalue = 100000000 ;
for ( $i = $intervalo - 1 ; $i > 0 ; $i -- ) { // 30 entries in graph, one by day
$grafica [] = $valores [ $i ][ 0 ];
$legend [] = $valores [ $i ][ 1 ];
if ( $valores [ $i ][ 0 ] < $minvalue )
$minvalue = $valores [ $i ][ 0 ];
if ( $valores [ $i ][ 0 ] > $maxvalue )
$maxvalue = $valores [ $i ][ 0 ];
}
// Create graph
// Create graph
// create the graph
$Graph =& Image_Graph :: factory ( 'graph' , array ( $width , $height ));
// add a TrueType font
$Font =& $Graph -> addNew ( 'font' , $config_fontpath );
$Font -> setSize ( 6 );
$Graph -> setFont ( $Font );
$Graph -> add (
Image_Graph :: vertical (
Image_Graph :: factory ( 'title' , array ( " " , 2 )),
$Plotarea = Image_Graph :: factory ( 'plotarea' ),
0 )
);
// Create the dataset
// Merge data into a dataset object (sancho)
$Dataset =& Image_Graph :: factory ( 'dataset' );
for ( $a = 0 ; $a < sizeof ( $grafica ); $a ++ ){
$Dataset -> addPoint ( $legend [ $a ], $grafica [ $a ]);
}
// create the 1st plot as smoothed area chart using the 1st dataset
$Plot =& $Plotarea -> addNew ( 'area' , array ( & $Dataset ));
// set a line color
$Plot -> setLineColor ( 'gray' );
// set a standard fill style
$Plot -> setFillColor ( 'green@0.4' );
// $Plotarea->hideAxis();
$AxisX =& $Plotarea -> getAxis ( IMAGE_GRAPH_AXIS_X );
// $AxisX->Hide();
$AxisY =& $Plotarea -> getAxis ( IMAGE_GRAPH_AXIS_Y );
$AxisY -> setLabelOption ( " showtext " , true );
$AxisY -> setLabelInterval ( ceil (( $maxvalue - $minvalue ) / 4 ));
$AxisX -> setLabelInterval ( $intervalo / 5 );
$AxisY -> forceMinimum ( $minvalue );
$GridY2 =& $Plotarea -> addNew ( 'bar_grid' , IMAGE_GRAPH_AXIS_Y_SECONDARY );
$GridY2 -> setLineColor ( 'blue' );
$GridY2 -> setFillColor ( 'blue@0.1' );
$AxisY2 =& $Plotarea -> getAxis ( IMAGE_GRAPH_AXIS_Y_SECONDARY );
$Graph -> done ();
}
2007-06-22 14:00:04 +02:00
*/
2007-02-16 19:29:37 +01:00
2007-06-08 17:55:53 +02:00
function odo_tactic ( $value1 , $value2 , $value3 ){
require_once 'Image/Graph.php' ;
include ( " ../include/config.php " );
// create the graph
$driver =& Image_Canvas :: factory ( 'png' , array ( 'width' => 350 , 'height' => 260 , 'antialias' => 'driver' ));
$Graph = & Image_Graph :: factory ( 'graph' , $driver );
// add a TrueType font
$Font =& $Graph -> addNew ( 'font' , $config_fontpath );
// set the font size to 11 pixels
$Font -> setSize ( 8 );
$Graph -> setFont ( $Font );
// create the plotarea
$Graph -> add (
Image_Graph :: vertical (
$Plotarea = Image_Graph :: factory ( 'plotarea' ),
$Legend = Image_Graph :: factory ( 'legend' ),
80
)
);
$Legend -> setPlotarea ( $Plotarea );
$Legend -> setAlignment ( IMAGE_GRAPH_ALIGN_HORIZONTAL );
2007-06-17 12:48:44 +02:00
if ( $value1 < 0 )
$value1 = 0 ;
if ( $value2 < 0 )
$value2 = 0 ;
if ( $value3 < 0 )
$value3 = 0 ;
2007-06-08 17:55:53 +02:00
/***************************Arrows************************/
$Arrows = & Image_Graph :: factory ( 'dataset' );
$Arrows -> addPoint ( 'Global Health' , $value1 , 'GLOBAL' );
$Arrows -> addPoint ( 'Data Health' , $value2 , 'DATA' );
$Arrows -> addPoint ( 'Monitor Health' , $value3 , 'MONITOR' );
/**************************PARAMATERS for PLOT*******************/
// create the plot as odo chart using the dataset
$Plot =& $Plotarea -> addNew ( 'Image_Graph_Plot_Odo' , $Arrows );
$Plot -> setRange ( 0 , 100 );
$Plot -> setAngles ( 180 , 180 );
$Plot -> setRadiusWidth ( 90 );
$Plot -> setLineColor ( 'gray' ); //for range and outline
$Marker =& $Plot -> addNew ( 'Image_Graph_Marker_Value' , IMAGE_GRAPH_VALUE_Y );
$Plot -> setArrowMarker ( $Marker );
$Plotarea -> hideAxis ();
/***************************Axis************************/
// create a Y data value marker
$Marker -> setFillColor ( 'transparent' );
$Marker -> setBorderColor ( 'transparent' );
$Marker -> setFontSize ( 7 );
$Marker -> setFontColor ( 'black' );
// create a pin-point marker type
$Plot -> setTickLength ( 14 );
$Plot -> setAxisTicks ( 5 );
/********************************color of arrows*************/
$FillArray = & Image_Graph :: factory ( 'Image_Graph_Fill_Array' );
$FillArray -> addColor ( 'red@0.8' , 'GLOBAL' );
$FillArray -> addColor ( 'black.6' , 'DATA' );
$FillArray -> addColor ( 'blue@0.6' , 'MONITOR' );
// create a line array
$LineArray =& Image_Graph :: factory ( 'Image_Graph_Line_Array' );
2007-06-16 18:21:41 +02:00
$LineArray -> addColor ( 'red' , 'GLOBAL' );
2007-06-08 17:55:53 +02:00
$LineArray -> addColor ( 'black' , 'DATA' );
2007-06-16 18:21:41 +02:00
$LineArray -> addColor ( 'blue' , 'MONITOR' );
2007-06-08 17:55:53 +02:00
$Plot -> setArrowLineStyle ( $LineArray );
$Plot -> setArrowFillStyle ( $FillArray );
/***************************MARKER OR ARROW************************/
// create a Y data value marker
$Marker =& $Plot -> addNew ( 'Image_Graph_Marker_Value' , IMAGE_GRAPH_VALUE_Y );
$Marker -> setFillColor ( 'white' );
$Marker -> setBorderColor ( 'white' );
$Marker -> setFontSize ( 7 );
$Marker -> setFontColor ( 'black' );
// create a pin-point marker type
$PointingMarker =& $Plot -> addNew ( 'Image_Graph_Marker_Pointing_Angular' , array ( 20 , & $Marker ));
// and use the marker on the plot
$Plot -> setMarker ( $PointingMarker );
/**************************RANGE*******************/
$Plot -> addRangeMarker ( 0 , 30 );
$Plot -> addRangeMarker ( 30 , 70 );
$Plot -> addRangeMarker ( 70 , 100 );
// create a fillstyle for the ranges
$FillRangeArray = & Image_Graph :: factory ( 'Image_Graph_Fill_Array' );
$FillRangeArray -> addColor ( 'red@0.8' );
$FillRangeArray -> addColor ( 'yellow@0.8' );
$FillRangeArray -> addColor ( 'green@0.8' );
$Plot -> setRangeMarkerFillStyle ( $FillRangeArray );
// output the Graph
$Graph -> done ();
}
2007-02-16 19:29:37 +01:00
// **************************************************************************
// **************************************************************************
// MAIN Code - Parse get parameters
// **************************************************************************
// **************************************************************************
// Generic parameter handling
// **************************
if ( isset ( $_GET [ " tipo " ]))
$tipo = entrada_limpia ( $_GET [ " tipo " ]);
else
$tipo = " " ; // 1 day default period
2007-06-07 19:46:38 +02:00
// Pure (Without title and legend)
if ( isset ( $_GET [ " pure " ]))
$pure = $_GET [ " pure " ];
else
$pure = 0 ;
2007-02-16 19:29:37 +01:00
2007-02-20 19:09:54 +01:00
if ( isset ( $_GET [ " period " ]))
$period = entrada_limpia ( $_GET [ " period " ]);
2007-02-16 19:29:37 +01:00
else
2007-02-20 19:09:54 +01:00
$period = 86400 ; // 1 day default period
2007-02-16 19:29:37 +01:00
if ( isset ( $_GET [ " intervalo " ]))
$intervalo = entrada_limpia ( $_GET [ " intervalo " ]);
else
$intervalo = 300 ; // 1 day default period
if ( isset ( $_GET [ " id " ]))
$id = entrada_limpia ( $_GET [ " id " ]);
else
$id = 0 ;
2007-03-28 18:07:29 +02:00
if ( isset ( $_GET [ " weight_l " ]))
$weight_l = entrada_limpia ( $_GET [ " weight_l " ]);
else
$weight_l = 0 ;
2007-02-16 19:29:37 +01:00
if ( isset ( $_GET [ " width " ]))
$width = entrada_limpia ( $_GET [ " width " ]);
else
2007-02-20 19:09:54 +01:00
$width = 450 ;
2007-02-16 19:29:37 +01:00
if ( isset ( $_GET [ " height " ]))
$height = entrada_limpia ( $_GET [ " height " ]);
else
$height = 200 ;
if ( isset ( $_GET [ " label " ]))
$label = entrada_limpia ( $_GET [ " label " ]);
else
$label = " " ;
if ( isset ( $_GET [ " color " ]))
$color = entrada_limpia ( $_GET [ " color " ]);
else
$color = " #226677 " ;
if ( isset ( $_GET [ " percent " ]))
$percent = entrada_limpia ( $_GET [ " percent " ]);
else
$percent = " 100 " ;
// Zoom
if ( isset ( $_GET [ 'zoom' ]) and
is_numeric ( $_GET [ 'zoom' ]) and
$_GET [ 'zoom' ] > 100 )
$zoom = $_GET [ 'zoom' ] / 100 ;
else
$zoom = 1 ;
2007-02-20 19:09:54 +01:00
// Unit_name
if ( isset ( $_GET [ " unit_name " ]))
$unit_name = entrada_limpia ( $_GET [ " unit_name " ]);
else
$unit_name = " " ;
2007-02-16 19:29:37 +01:00
// Draw Events ?
2007-04-18 11:58:26 +02:00
if ( isset ( $_GET [ " draw_events " ]))
$draw_events = $_GET [ " draw_events " ];
else
$draw_events = 0 ;
2007-05-20 19:12:31 +02:00
// Average values only
if ( isset ( $_GET [ " avg_only " ]))
$avg_only = $_GET [ " avg_only " ];
else
$avg_only = 0 ;
2007-04-18 11:58:26 +02:00
// Draw alert limits ?
if ( isset ( $_GET [ " draw_alerts " ]))
$draw_alerts = $_GET [ " draw_alerts " ];
else
$draw_alerts = 0 ;
2007-06-08 17:55:53 +02:00
// Values 1 2 and 3
if ( isset ( $_GET [ " value1 " ]))
$value1 = $_GET [ " value1 " ];
else
$value1 = 0 ;
if ( isset ( $_GET [ " value2 " ]))
$value2 = $_GET [ " value2 " ];
else
$value2 = 0 ;
if ( isset ( $_GET [ " value3 " ]))
$value3 = $_GET [ " value3 " ];
else
$value3 = 0 ;
2007-02-16 19:29:37 +01:00
// Image handler
// *****************
2007-02-20 19:09:54 +01:00
2007-02-16 19:29:37 +01:00
if ( isset ( $_GET [ " tipo " ])){
2007-02-20 19:09:54 +01:00
if ( $_GET [ " tipo " ] == " sparse " ){
2007-06-07 19:46:38 +02:00
grafico_modulo_sparse ( $id , $period , $draw_events , $width , $height , $label , $unit_name , $draw_alerts , $avg_only , $pure );
2006-03-27 05:37:27 +02:00
}
elseif ( $_GET [ " tipo " ] == " estado_incidente " )
grafico_incidente_estados ();
elseif ( $_GET [ " tipo " ] == " prioridad_incidente " )
grafico_incidente_prioridad ();
elseif ( $_GET [ " tipo " ] == " db_agente_modulo " )
2007-06-22 14:00:04 +02:00
grafico_db_agentes_modulos ( $width , $height );
2006-03-27 05:37:27 +02:00
elseif ( $_GET [ " tipo " ] == " db_agente_paquetes " )
2007-06-22 14:00:04 +02:00
grafico_db_agentes_paquetes ( $width , $height );
2006-03-27 05:37:27 +02:00
elseif ( $_GET [ " tipo " ] == " db_agente_purge " )
2007-06-22 14:00:04 +02:00
grafico_db_agentes_purge ( $id , $width , $height );
2006-03-27 05:37:27 +02:00
elseif ( $_GET [ " tipo " ] == " group_events " )
2007-06-21 20:58:35 +02:00
grafico_eventos_grupo ( $width , $height );
2006-03-27 05:37:27 +02:00
elseif ( $_GET [ " tipo " ] == " user_events " )
2007-06-22 14:00:04 +02:00
grafico_eventos_usuario ( $width , $height );
2006-03-27 05:37:27 +02:00
elseif ( $_GET [ " tipo " ] == " total_events " )
grafico_eventos_total ();
elseif ( $_GET [ " tipo " ] == " group_incident " )
graphic_incident_group ();
elseif ( $_GET [ " tipo " ] == " user_incident " )
2007-06-22 14:00:04 +02:00
graphic_incident_user ();
2006-03-27 05:37:27 +02:00
elseif ( $_GET [ " tipo " ] == " source_incident " )
2007-06-22 14:00:04 +02:00
graphic_incident_source ();
2006-03-27 05:37:27 +02:00
elseif ( $_GET [ " tipo " ] == " user_activity " )
2007-06-22 14:00:04 +02:00
graphic_user_activity ( $width , $height );
2006-03-27 05:37:27 +02:00
elseif ( $_GET [ " tipo " ] == " agentaccess " )
2007-02-20 19:09:54 +01:00
graphic_agentaccess ( $_GET [ " id " ], $_GET [ " periodo " ], $width , $height );
2006-03-27 05:37:27 +02:00
elseif ( $_GET [ " tipo " ] == " agentmodules " )
2007-02-20 19:09:54 +01:00
graphic_agentmodules ( $_GET [ " id " ], $width , $height );
2007-06-22 14:00:04 +02:00
//elseif ($_GET["tipo"] == "gdirect")
// graphic_test ($id, $period, $intervalo, $label, $width, $height);
2006-07-01 03:48:56 +02:00
elseif ( $_GET [ " tipo " ] == " progress " ){
$percent = $_GET [ " percent " ];
progress_bar ( $percent , $width , $height );
}
2007-06-08 17:55:53 +02:00
elseif ( $_GET [ " tipo " ] == " odo_tactic " ){
odo_tactic ( $value1 , $value2 , $value3 );
}
2007-03-28 18:07:29 +02:00
elseif ( $_GET [ " tipo " ] == " combined " ){
// Split id to get all parameters
$module_list = array ();
$module_list = split ( " , " , $id );
$weight_list = array ();
$weight_list = split ( " , " , $weight_l );
2007-06-07 19:46:38 +02:00
graphic_combined_module ( $module_list , $weight_list , $period , $width , $height , $label , $unit_name , $draw_events , $draw_alerts , $pure );
2007-03-28 18:07:29 +02:00
}
2007-02-20 19:09:54 +01:00
else
graphic_error ();
} else
graphic_error ();
2007-06-17 12:48:44 +02:00
?>