Location: PHPKode > scripts > WH Social > wh_social/admin/handler/charts.php
<?php
//Sanitizing the input
$Type 	= $_GET['type'];
$Year 	= intval($_GET['year']);
$Month 	= intval($_GET['month']);
$Day 	= intval($_GET['day']);

//Months Names
$MonthsNames = array(null, 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');

//Prepare variables according to type-of-chart
switch($Type)
{
	default:
	case 'monthly':
		$Query = "SELECT MONTH(date) AS Value, COUNT(id) AS Total FROM `members` WHERE YEAR(date)={$Year} GROUP BY Value";
		$ResultArray = array_fill(1, 12, 0); // fill the Result array with 0 values for each month
		$ChartHeading = 'Monthly New members for the Year: '.$Year;
		$XaxisName = 'Months';
		break;
		
	case 'daily':
		$Query = "SELECT DAY(date) AS Value, count(id) AS Total FROM `members` WHERE YEAR(date)={$Year} AND MONTH(date)={$Month} GROUP BY Value";
		$ResultArray = array_fill(1, 31, 0);  // fill the Result array with 0 values for each day
		$ChartHeading = 'Daily New members for the Month: '.$MonthsNames[$Month].'/'.$Year;
		$XaxisName = 'Days';
		break;
		
	case 'hourly':
		$Query = "select HOUR(date) AS Value, count(id) AS Total FROM `members` WHERE YEAR(date)={$Year} AND MONTH(date)={$Month} AND DAY(date)={$Day} GROUP BY Value";
		$ResultArray = array_fill(0, 24, 0);   // fill the Result array with 0 values for each hour
		$ChartHeading = 'Hourly New members for the Date: '.$Day.'/'.$MonthsNames[$Month].'/'.$Year;
		$XaxisName = 'Hours';
		break;
}

//Query the database
$QueryResult = mysql_query($Query);

//Fetch results in the Result Array
while($Row = mysql_fetch_assoc($QueryResult))
	$ResultArray[$Row['Value']]=$Row['Total'];

//Generate Chart XML: Head Part
$Output = '<chart caption="'.$ChartHeading.'" xAxisName="'.$XaxisName.'" yAxisName="members" showNames="1" bgColor="E6E6E6,F0F0F0" bgAlpha="100,50" bgRatio="50,100" bgAngle="270" showBorder="1" borderColor="AAAAAA" baseFontSize="12">';

//Generate Chart XML: Main Body
switch($Type)
{
	default:
	case 'monthly':
		foreach($ResultArray as $MonthNumber => $value)  // MonthNumber is month number (1-12)
			$Output .= '<set value="'.$value.'" name="'.$MonthsNames[$MonthNumber].'" link="newchart-xmlurl-get-data.php?type=daily&amp;year='.$Year.'&amp;month='.$MonthNumber.'"/>';
		break;
	case 'daily':
		foreach($ResultArray as $DayNumber => $value)  // DayNumber is day (1-31)
			$Output .= '<set value="'.$value.'" name="'.$DayNumber.'" link="newchart-xmlurl-get-data.php?type=hourly&amp;year='.$Year.'&amp;month='.$Month.'&amp;day='.$key.'"/>';
		break;
	case 'hourly':
		foreach($ResultArray as $HourNumber => $value)  // HourNumber is hour (0-23)
			$Output .= '<set value="'.$value.'" name="'.$HourNumber.'"/>';
		break;
}

//Generate Chart XML: Last Part
$Output .= '</chart>';

//Set the output header to XML
header('Content-type: text/xml');

//Send output
echo $Output;
?>
Return current item: WH Social