<?
/*
PTK - DFLabs
Copyright (C) 2008 - DFLabs srl - All rights reserved
hide@address.com
*/
include("check_session.php");
include("check_session_image.php");
include("sanitize.php");
include_once( '../php-ofc-library/open-flash-chart.php' );
$g = new graph();
$g->title( 'MAC trend', '{font-size: 26px;}' );
$chart_view = sanitize($_GET['view'],PARANOID);
$_SESSION['old_chart_view'] = $_SESSION['chart_view'];
$direction = sanitize($_GET['direction'],PARANOID);
$m = sanitize($_GET['m'],INT);
$a = sanitize($_GET['a'],INT);
$c = sanitize($_GET['c'],INT);
$tot_m=0;$tot_a=0;$tot_c=0;
$day = $month = $year = '';
$tot = 0;
$data_1 = array();
$data_2 = array();
$data_3 = array();
$label = array();
$timeline = $_SESSION['timeline'];
for($i=0; $i<sizeof($timeline); $i++ ){
$old_year = $year;
$old_month = $month;
$old_day = $day;
$action = $timeline[$i]['action'];
$date = $timeline[$i]['date_time'];
if(preg_match("/(\d{4})\-(\d{2})\-(\d{2}).+/", $date, $o)){
$year = $o[1];
$month = $o[2];
$day =$o[3];
}
switch($chart_view){
case "day":
$view=$day;
$old_view=$old_day;
$label[] = $year."-".$month."-".$day;
break;
case "month":
$view=$month;
$old_view=$old_month;
$label[] = $year."-".$month;
break;
case "y":
$view=$year;
$old_view=$old_year;
$label[] = $year;
break;
}
if($view==$old_view){
if(preg_match("/m/", $action)) $tot_m += 1;
if(preg_match("/a/", $action)) $tot_a += 1;
if(preg_match("/c/", $action)) $tot_c += 1;
}else{
if($i!=0){
$data_1[] = $tot_m;
$data_2[] = $tot_a;
$data_3[] = $tot_c;
$tot = $tot+1;
}
$tot_m=0;$tot_a=0;$tot_c=0;
if(preg_match("/m/", $action)) $tot_m += 1;
if(preg_match("/a/", $action)) $tot_a += 1;
if(preg_match("/c/", $action)) $tot_c += 1;
}
if($i==sizeof($timeline)-1){
$data_1[] = $tot_m;
$data_2[] = $tot_a;
$data_3[] = $tot_c;
}
}
$label = array_unique($label);
if($direction=='start'){
$_SESSION['slice']=$tot+1;
$_SESSION['start'] = 0;
}
elseif($direction=='none'){
$slice = $_SESSION['slice'];
$start = $_SESSION['start'];
}
elseif($direction=='zoom_in'){
if($_SESSION['slice']==1) $slice=10;
else $slice = $_SESSION['slice']-10;
$_SESSION['slice'] = $slice;
$start = $_SESSION['start'];
}
elseif($direction=='zoom_out'){
if($_SESSION['slice']==$tot+1) $slice=$tot+10;
else $slice = $_SESSION['slice']+10;
$_SESSION['slice'] = $slice;
$start = $_SESSION['start'];
}
elseif($direction=='back'){
if($_SESSION['start']==0) $start = 0;
else $start = $_SESSION['start']-1;
$_SESSION['start'] = $start;
$slice = $_SESSION['slice'];
}
elseif($direction=='forward'){
if($_SESSION['start']==($tot-$_SESSION['slice'])+1) $start = $tot-$_SESSION['slice']+1;
else $start = $_SESSION['start']+1;
$_SESSION['start'] = $start;
$slice = $_SESSION['slice'];
}
if($direction!='start'){
$data_1 = array_slice($data_1, $start, $slice);
$data_2 = array_slice($data_2, $start, $slice);
$data_3 = array_slice($data_3, $start, $slice);
$label = array_slice($label, $start, $slice);
}
if(($m==1)and($a==1)and($c==1)){
$g->set_data( $data_1 );
$g->set_data( $data_2 );
$g->set_data( $data_3 );
$g->line_hollow( 2, 3, '0x736AFF', 'Modified', 10 );
$g->line_hollow( 2, 3, '0xCC3399', 'Accessed', 10 );
$g->line_hollow( 2, 3, '0x80a033', 'Created', 10 );
$max = max(max($data_1), max($data_2), max($data_3));
}
elseif(($m==1)and($a==1)and($c==0)){
$g->set_data( $data_1 );
$g->set_data( $data_2 );
$g->line_hollow( 2, 3, '0x736AFF', 'Modified', 10 );
$g->line_hollow( 2, 3, '0xCC3399', 'Accessed', 10 );
$max = max(max($data_1), max($data_2));
}
elseif(($m==0)and($a==1)and($c==1)){
$g->set_data( $data_2 );
$g->set_data( $data_3 );
$g->line_hollow( 2, 3, '0xCC3399', 'Accessed', 10 );
$g->line_hollow( 2, 3, '0x80a033', 'Created', 10 );
$max = max(max($data_2), max($data_3));
}
elseif(($m==1)and($a==0)and($c==1)){
$g->set_data( $data_1 );
$g->set_data( $data_3 );
$g->line_hollow( 2, 3, '0x736AFF', 'Modified', 10 );
$g->line_hollow( 2, 3, '0x80a033', 'Created', 10 );
$max = max(max($data_1), max($data_3));
}
elseif(($m==1)and($a==0)and($c==0)){
$g->set_data( $data_1 );
$g->line_hollow( 2, 3, '0x736AFF', 'Modified', 10 );
$max = max($data_1);
}
elseif(($m==0)and($a==1)and($c==0)){
$g->set_data( $data_2 );
$g->line_hollow( 2, 3, '0xCC3399', 'Accessed', 10 );
$max = max($data_2);
}
elseif(($m==0)and($a==0)and($c==1)){
$g->set_data( $data_3 );
$g->line_hollow( 2, 3, '0x80a033', 'Created', 10 );
$max = max($data_3);
}
$g->set_tool_tip( '#key#<br>Date: #x_label#<br>Total: #val#' );
$g->set_x_label_style( 10, '#9933CC', 2, 1, '#00A000' );
$g->set_x_axis_steps(1);
$g->set_x_labels( $label );
$g->set_y_max( $max );
//if($max>30) $g->y_label_steps(30);
//else $g->y_label_steps($max);
$g->y_label_steps(0);
$g->set_y_label_style( 'none' );
echo $g->render();
?>