<?
/*
* ===========================================*
* 项目: Ourplus网站流量统计分析系统*
* 版本: Bate1*
* 开发: 看海*
* ===========================================*
* Copyright (c) 2004 - 2005*
* 主页: http://stat.ourplus.com*
* 信箱: fantasysisky@hotmail.com*
* 版权信息: 本软体为共享软体(shareware)提供个人网站免费使用，
                作者看海 (stat.ourplus.com) 保留全部权力，受相关法律和国际
				公约保护，请勿非法修改、转载、散播，或用于其他赢利行为，
				并请勿删除版权声明。*
* ===========================================*
*/
	session_start();
	include_once './include.inc/config.inc.php';
	include_once 'session.php';

	include_once './include.inc/conn.db.inc.php';
	include_once './include.inc/global.inc.php';
	include_once './include.inc/tpl.inc.php';
	include_once './include.inc/function.php';

	Initialize( $_GET, array( 'Date_Year'=>'intval' ) );

	$UserId = intval( $_SESSION[ourplus_userid] );

	if( isset( $_GET[Date_Year] ) )
	{
		$Year = isset( $_GET[Date_Year] ) ? intval( $_GET[Date_Year] ) : date('Y');
		$YearTime = mktime (0,0,0,1,1,$Year);
	}
	else
	{
		$YearTime = mktime (0,0,0,1,1,date("Y"));
		$Year = date( 'Y', $YearTime );
	}

	//年统计信息处理
	$EndTime = mktime (0,0,0,1,0,$Year+1 );
	$Res = mysql_query( " select * from $TableList[month_data] where times <= $EndTime and times >= $YearTime" );

	while( $Tmp = mysql_fetch_array( $Res, MYSQL_ASSOC ) )
	{
		$TmpMonth = intval( date( 'm', $Tmp[times] ) );
		$StatIp[$TmpMonth] = intval( $Tmp[month_count_ip] );
		$Stat[$TmpMonth] = intval( $Tmp[month_count] );

		$CountIpAll += $StatIp[$TmpMonth];
		$CountAll += $Stat[$TmpMonth];
		$MaxCount = $Stat[$TmpMonth] > $MaxCount ? $Stat[$TmpMonth] : $MaxCount;
	}

	$CountIpAll = $CountIpAll > 0 ? $CountIpAll : 0;
	$CountAll = $CountAll > 0 ? $CountAll : 0;
	$MaxCount = $MaxCount > 0 ? $MaxCount : 0;

	$Quotiety = $MaxCount == 0 ? 0 : PILLAR_HEIGHT / $MaxCount;
	$MonthLineCount = intval( $MaxCount / 5 );

	for( $i = 1; $i <= 12; $i++ )
	{

		$MonthIpPercent = $CountIpAll == 0 ? 0 : sprintf("%01.2f", ( $StatIp[$i]/$CountIpAll ) * 100 );
		$MonthIpPillarHeight = $Quotiety * $StatIp[$i];
		$MonthIpPillarHeight = $MonthIpPillarHeight < 1 ? 1 : $MonthIpPillarHeight;

		$MonthPercent = $CountAll == 0 ? 0 : sprintf("%01.2f", ( $Stat[$i]/$CountAll ) * 100 );
		$MonthPillarHeight = ( $Quotiety * $Stat[$i] ) - $MonthIpPillarHeight;
		$MonthPillarHeight = $MonthPillarHeight < 1 ? 1 : $MonthPillarHeight;


		$MonthData[$i] = array(
									'MonthIpPercent' => $MonthIpPercent,
									'MonthIpPillarHeight' => $MonthIpPillarHeight,
									'MonthPercent' => $MonthPercent,
									'MonthPillarHeight' => $MonthPillarHeight,
									'MonthIpCount' => intval( $StatIp[$i] ),
									'MonthCount' => intval( $Stat[$i] ),
								);

		$YearMonth[$i] = $i;

	}

	$Tpl->assign( 'PillarTdWidth', PILLAR_WIDTH/count($MonthData)  );
	$Tpl->assign( 'PillarWidth', ( PILLAR_WIDTH/count($MonthData) ) - 20  );
	$Tpl->assign( 'YearMonth', $YearMonth );
	$Tpl->assign( 'MonthData', $MonthData );
	$Tpl->assign( 'MonthLineCount', $MonthLineCount );

	$Tpl->assign( 'CountIpAll', $CountIpAll );
	$Tpl->assign( 'CountAll', $CountAll );

	//当年统计信息处理结束

	$Tpl->assign( 'Year', $Year );
	$Tpl->assign( 'DataTime', $YearTime );

	$ScriptCode = "<script language=\"javascript\" type=\"text/javascript\">\ncallm(1,0);\n</script>";

	$Tpl->assign( 'Main', $Tpl->fetch( 'stat_year.html' ) . $ScriptCode );

	$Tpl->assign( 'Title', '月分析 - Ourplus Counter' );
	$Tpl->assign( 'NowView', '月分析' );
	$Tpl->assign( 'QuickLink', '<a href="stat_day.php">时段分析</a> <a href="stat_month.php">日段分析</a> <a href="stat_year.php">月分析 </a>' );
	_out( $Tpl->fetch( 'main.html' )  );

?>