Location: PHPKode > scripts > KubeStats > control/graphs.php
<?php
require_once("../includes/config.php");
require_once("../includes/functions/func.global.php");
require_once("../includes/functions/loggincheck.php");

if(!isset($_GET['cmd']))
{
	$_GET['cmd'] = 'visitors';
}

if($_GET['cmd'] == 'visitors')
{
	require_once('../includes/classes/class.postgraph.php'); 
	
	// Connect to database
	db_connect($config);
	
	$months[1] = 31;
	$months[2] = 28;
	$months[3] = 31;
	$months[4] = 30;
	$months[5] = 31;
	$months[6] = 30;
	$months[7] = 31;
	$months[8] = 31;
	$months[9] = 30;
	$months[10] = 31;
	$months[11] = 30;
	$months[12] = 31;
	
	$month_names[1] = 'Jan';
	$month_names[2] = 'Feb';
	$month_names[3] = 'Mar';
	$month_names[4] = 'Apr';
	$month_names[5] = 'May';
	$month_names[6] = 'Jun';
	$month_names[7] = 'Jul';
	$month_names[8] = 'Aug';
	$month_names[9] = 'Sep';
	$month_names[10] = 'Oct';
	$month_names[11] = 'Nov';
	$month_names[12] = 'Dec';
	
	$start_day = $_GET['start_day'];
	$start_month = $_GET['start_month'];
	$start_year = $_GET['start_year'];
	
	$end_day = $_GET['end_day'];
	$end_month = $_GET['end_month'];
	$end_year = $_GET['end_year'];
	
	if(isset($_GET['start_stamp']))
	{
		$start_stamp = $_GET['start_stamp'];
		$end_stamp = $_GET['end_stamp'];
		
		$start_day = date("j",$start_stamp);
		$start_month = date("n",$start_stamp);
		$start_year = date("y",$start_stamp);
		
		$end_day = date("j",$end_stamp);
		$end_month = date("n",$end_stamp);
		$end_year = date("y",$end_stamp);
	}
	else
	{
		$start_stamp = date("U", mktime(0, 0, 0, $start_month, $start_day, $start_year));
		$end_stamp = date("U", mktime(23, 59, 59, $end_month, $end_day, $end_year));
	}
	$stats = array();
	$days = array();
	$daynames = array();
	$data = array();
	$data2 = array();
	
	if($start_month != $end_month)
	{
		$end_monthlength = ($months[$start_month]-$start_day);
		$numdays = ($end_monthlength+$end_day);
		
		for ($i = $start_day; $i <= $months[$start_month]; $i++) 
		{
			$days[$start_month][$i] = '0';
			$data[$i.' '.$month_names[$start_month]] = '0';
			$data2[$i.' '.$month_names[$start_month]] = '0';
		}
		
		for ($i = 1; $i <= $end_day; $i++) 
		{
			$days[$end_month][$i] = '0';
			$data[$i.' '.$month_names[$end_month]] = '0';
			$data2[$i.' '.$month_names[$end_month]] = '0';
		}
	}
	else
	{
		$numdays = ($end_day-$start_day);
		
		for ($i = $start_day; $i <= $end_day; $i++) 
		{
			$days[$start_month][$i] = '0';
			$data[$i.' '.$month_names[$start_month]] = '0';
			$data2[$i.' '.$month_names[$start_month]] = '0';
		}
	}
	
	$numdays = 8;
	
	$query = "SELECT day,month,visits,`unique` FROM ".$config['db']['pre']."days WHERE site_id='".addslashes($_GET['id'])."' AND stamp>=".($start_stamp-72000)." AND stamp<=".$end_stamp." LIMIT ".$numdays;
	$query_result = @mysql_query ($query) OR error(mysql_error(), __LINE__, __FILE__, 0, '', '');
	while ($info = @mysql_fetch_array($query_result))
	{
		$stats[$info['month']][$info['day']] = $info;
		$data[$info['day'].' '.$month_names[$info['month']]] = $info['visits'];
		$data2[$info['day'].' '.$month_names[$info['month']]] = $info['unique'];
	}
	
	$graph = new PostGraph(590,400);
	
	$graph->setPadding(40,20);
	
	$graph->setGraphTitles('', '', '');
	
	$graph->setYNumberFormat('integer');
	
	$graph->setYTicks(10);
	
	$graph->setData($data,$data2);
	
	$graph->setBackgroundColor(array(255,255,255));
	
	$graph->setInsideBarColor(array(98,126,183));
	
	$graph->setXTextOrientation('horizontal');
		
	$graph->drawImage();
	
	$graph->printImage();
}
elseif($_GET['cmd'] == 'browsers')
{
	require_once('../includes/classes/class.piegraph.php'); 
	
	$col = array();
	$col[] = '#627eb7';
	$col[] = '#ff8800';
	$col[] = '#6633CC';
	$col[] = '#0066CC';
	$col[] = '#2C3D5F';
	$col[] = '#990000';
	$col[] = '#336666';
	$col[] = '#9999CC';
	$col[] = '#0066CC';
	$col[] = '#2C3D5F';
	
	// Connect to database
	db_connect($config);
	
	$data = array();
	$titles = array();
	$count = 0;
	$browser_names = getbrowserlist();
	$browser_names[0]['title'] = 'Other';
	
	$query = "SELECT browser_id,count FROM ".$config['db']['pre']."browsers WHERE site_id='".addslashes($_GET['id'])."' ORDER BY count DESC LIMIT 6";
	$query_result = @mysql_query ($query) OR error(mysql_error(), __LINE__, __FILE__, 0, '', '');
	while ($info = @mysql_fetch_array($query_result))
	{
		$data[$count] = $info['count'];
		$titles[$count] = $browser_names[$info['browser_id']]['title'];
		
		$count++;
	}
	
	$col2 = array_slice($col,0,count($data));
	
	// class call with the width, height & data
	$pie = new PieGraph(300, 200, $data);
	
	// colors for the data
	$pie->setColors($col2);
	
	// legends for the data
	$pie->setLegends($titles);
	
	// Height of the pie 3d effect
	$pie->set3dHeight(35);
	
	// Display the graph
	$pie->display();
}
?>
Return current item: KubeStats