<?php

class AKB_CHART {

	/**
	* Contains an array of chart information that is used to display the chart.
	* This is shared by a few functions so it's easier to reference a class variable rather than a global variable or passing it around everywhere.
	*
	* @see Process
	* @see SetupChartDates
	* @see SetupChart_Subscribers
	* @see SetupChart
	*
	* @var Array
	*/
	var $chart = array();

	/**
	* More chart information.
	* This holds descriptions and so on for the chart.
	*
	* @see Process
	* @see SetupChartDates
	* @see SetupChart_Subscribers
	* @see SetupChart
	*/
	var $chart_details = array('bold' => false);

	/**
	* CONSTRUCTOR
	* Sets up the default looking and feel of the chart. The different options in 'Process' will override this if need be.
	*
	* Return Void
	*/
	function AKB_CHART() {
		$this->chart['chart_value_text'] = array();
		$this->chart['chart_value_text'][1] = array();

		$this->chart['chart_grid_h'] = array(
			'thickness' => 1
		);

		$this->chart['chart_grid_v'] = array(
			'thickness' => 1
		);	
	

		$this->chart['legend_label'] = array ( 'layout'=>"horizontal", 'bullet'=>"circle", 'font'=>"arial", 'bold'=>true, 'size'=>10, 'color'=>"000000", 'alpha'=>85 );
		$this->chart['series_color'] = array ("F98F25", "FFBE21", "84B221", "6379AD", "F74F25", "2579F7", "A925F5", "E54572", "429CBD", "9CBD42");

		$this->chart['legend_rect'] = array ( 'y'=> 170 );
		$this->chart['chart_rect'] = array ( 'y'=>10 );

		$this->chart['chart_bg'] = array (
			'positive_color'=>"000000",
			'positive_alpha'=>0,
			'negative_color'=>"FFFFFF",
			'negative_alpha'=>0
		);

		$this->chart['chart_border'] = array (
			'top_thickness'     =>  0,
			'bottom_thickness'  =>  0,
			'left_thickness'    =>  0,
			'right_thickness'   =>  0,
			'color'             =>  "CCCCCC"
		);
		
		$this->chart_details['hide_zero'] = false;
		$this->chart_details['chart_position'] = 'inside';
		$this->chart_details['prefix'] = '';		
		
		$this->chart['chart_value'] = array(
			'prefix' => $this->chart_details['prefix'],
			'decimals' => 0,
			'decimal_char' => GetLang('NumberFormat_Dec'),
			'separator' => GetLang('NumberFormat_Thousands'),
			'bold' => $this->chart_details['bold'],
			'position' => $this->chart_details['chart_position'],
			'hide_zero' => $this->chart_details['hide_zero']
		);

		$this->chart['chart_value']['size'] = 10;
		$this->chart['axis_value'] = array ('size' => 10);
		$this->chart['axis_category']['size'] = 10;		
	}
	
	function Process() {
	
		//Get the type of chart we want.
		
		$type = $_GET['type'];
		
		switch ($type) {
			
			case "MostPopularQuestionsFull":
				
				$this->chart['chart_type'] = "pie";
				
				$headerArray = array("",GetLang("StatQuestionTotalPosvotes"),GetLang("StatQuestionTotalNegvotes"));
				$dataArray = array(
					"",
					(int)$_GET['totalposvotes'],
					(int)$_GET['totalnegvotes']
				);
				
				$this->chart['chart_data'] = array($headerArray,$dataArray);

				$this->chart['axis_category']['skip'] = 0;

				$this->chart['axis_category']['skip'] = 0;

				$this->chart['chart_grid_h']['thickness'] = 0;
				$this->chart['chart_grid_v']['thickness'] = 0;
				$this->chart['legend_rect'] = array ( 'y'=> 20, 'height' => '20' );
				$this->chart['chart_rect'] = array ( 'y'=> 20 );				
				
				break;
			
			case "UserSummary":

				$this->chart['chart_type'] = "pie";
				
				$headerArray = array("",GetLang("StatActiveUsers"),GetLang("StatInactiveUsers"));
				$dataArray = array(
					"",
					number_format($_GET['ActiveUsers']),
					(int)$_GET['InactiveUsers']
				);
				
				$this->chart['chart_data'] = array($headerArray,$dataArray);

				$this->chart['axis_category']['skip'] = 0;

				$this->chart['chart_grid_h']['thickness'] = 0;
				$this->chart['chart_grid_v']['thickness'] = 0;
				$this->chart['legend_rect'] = array ( 'y'=> 20, 'height' => '20' );
				$this->chart['chart_rect'] = array ( 'y'=> 20 );
			
				break;
				
			case "CategorySummary":
				
				$this->chart['chart_type'] = "pie";
				
				$headerArray = array("");
				$dataArray = array("");
				
				$catstr = urldecode($_GET['catarray']);
				$catArray = unserialize(str_replace('\"', '"', $catstr));
				
				foreach ($catArray as $catName=>$catData) {
					$headerArray[] = $catName;
					$dataArray[] = $catData;
				}
				
				$this->chart['chart_data'] = array($headerArray,$dataArray);

				$this->chart['axis_category']['skip'] = 0;
				$this->chart['chart_grid_h']['thickness'] = 0;
				$this->chart['chart_grid_v']['thickness'] = 0;
				$this->chart['legend_rect'] = array ( 'y'=> 20, 'height' => '20' );
				$this->chart['chart_rect'] = array ( 'y'=> 20 );
				
				
				break;
				
			default:
				//No type specified, kill the script.
				die();
		}
		
		SendChartData($this->chart);
	}
}

?>