<?
/*
* ===========================================*
* 项目: 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';

	$Tpl->assign( 'UserId', $UserId );

	$Res = mysql_query( " select site,sitename,sitedes,email,manager,all_count,all_count_ip from $TableList[users] " );
	$SiteInfo = mysql_fetch_array( $Res, MYSQL_ASSOC );
	$Tpl->assign( 'SiteInfo', $SiteInfo );

	//最大流量最小流量
	$Res = mysql_query( "SELECT max( day_count ) as maxcount , max( day_count_ip ) as maxcountip , min( day_count ) as mincount, min( day_count_ip ) as mincountip FROM $TableList[day_data]" );
	$MaxMin = mysql_fetch_array( $Res, MYSQL_ASSOC );
	$Tpl->assign( 'MaxMin', $MaxMin );

	//统计开始和统计天数
	$Res = mysql_query( " select times  from $TableList[day_data] order by times asc" );
	$FirstDay = mysql_fetch_array( $Res, MYSQL_ASSOC );
	$FirstDay[times] = intval( $FirstDay[times] ) == 0 ? time() - 1 : $FirstDay[times];
	$Tpl->assign( 'FirstDay', $FirstDay[times] );
	$Tpl->assign( 'CountDays', ceil( ( time() - $FirstDay[times] ) / 24 / 60 / 60 ) );

	//昨日统计
	$Times = mktime (0,0,0,date("m"),date("d")-1,date("Y") );
	$Res = mysql_query( " select day_count, day_count_ip  from $TableList[day_data] where times = $Times" );
	$YesterdayInfo = mysql_fetch_array( $Res, MYSQL_ASSOC );
	$Tpl->assign( 'YesterdayInfo', $YesterdayInfo );

	//今日统计
	$Times = mktime (0,0,0,date("m"),date("d"),date("Y") );
	$Res = mysql_query( " select day_count, day_count_ip  from $TableList[day_data] where times = $Times" );
	$TodayInfo = mysql_fetch_array( $Res, MYSQL_ASSOC );
	$Tpl->assign( 'TodayInfo', $TodayInfo );

	//本月统计
	$Times = mktime (0,0,0,date("m"),1,date("Y") );
	$Res = mysql_query( " select * from $TableList[month_data] where times = $Times" );
	$MonthInfo = mysql_fetch_array( $Res, MYSQL_ASSOC );
	$Tpl->assign( 'MonthInfo', $MonthInfo );

/*
	//统计在线人数
	$OnlineTime = 20;
	$Time = time() - $OnlineTime * 60;
	$Res = mysql_query( "SELECT * FROM $TableList[ip] WHERE time >= $Time GROUP BY ip" );
	$OnlineCount = intval( mysql_num_rows($Res) );
*/

	//统计链接
	$Countlink = 'http://' . $_SERVER["HTTP_HOST"] . ( $_SERVER["SERVER_PORT"] != 80 ? $_SERVER["SERVER_PORT"] : '' ) . dirname( $_SERVER["PHP_SELF"] ) . '/count/count.js';
	$Tpl->assign( 'Countlink', $Countlink );

	$Tpl->assign( 'OnlineTime', $OnlineTime );
	$Tpl->assign( 'OnlineCount', $OnlineCount [count]);
	
	$Tpl->assign( 'Main', $Tpl->fetch( 'main_info.html' ) );

	$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> <a href="stat_alexa.php">Alexa工具条</a>' );
	_out( $Tpl->fetch( 'main.html' )  );
?>