<?
/*
 
 本软件版权归作者所有,在投入使用之前注意获取许可
 作者：程威（wiwiboy）
 项目：PHPStat流量统计 1.0
 电话：13553166317
 邮箱：wiwiboy@126.com
 QQ号：158839753
 网址：http://www.phpstat.net
 phpstat.net保留全部权力，受相关法律和国际		  		
		公约保护，请勿非法修改、转载、散播，或用于其他赢利行为，		
		并请勿删除版权声明。
*/
/*	
	verson:v1.0 20060618
	author:wiwiboy
	last update:2006/06/10	
*/
	session_start();
	include_once './include.inc/config.inc.php';
	include_once './include.inc/global.inc.php';
	include_once './session.php';
	include_once './include.inc/conn.db.inc.php';
	include_once './include.inc/tpl.inc.php';
	include_once './include.inc/function.php';
	include_once './parse_site.php';
	include_once './include.inc/function_system.php';
	include_once './include.inc/function_timezone.php';
	include_once './include.inc/function_language.php';
	Initialize( $_GET, array( 'options1'=>'strval','options2'=>'strval','options3'=>'strval','regexp'=>'strval' ,'website'=>'strval','page'=>'intval') );
	$website = $_GET[website];
	include_once 'initmenu.php';
	$options1 = $_GET[options1];
	$options2 = $_GET[options2];
	$options3 = $_GET[options3];
	$regexp = $_GET[regexp];
		
	if($options1 == 'referer')
	{
		$types = '4';
		$titlesub = "以独立IP访问量为单位 列出 来源统计为“".$options2."” 的所有历史访问数据。";
		$counts = 'pvcounts';
	}
	if($options1 == 'page')
	{	
		if($options3 == '4')
		{
			$types = '4';
			$titlesub = "以独立IP访问量为单位 列出 入口页面为“".$options2."”的所有历史访问数据。";
			$counts = 'ipcounts';
		}
		elseif($options3 == '5')
		{
			$types = '5';
			$titlesub = "以独立IP访问量为单位 列出 离开页面为“".$options2."”的所有历史访问数据。";
		}
		else
		{
			$types = '3';
			$titlesub = "以独立IP访问量为单位 列出 受访页面为“".$options2."(".$options3.")”的所有历史访问数据。";
			$counts = 'pvcounts';
		}
	}
	if($options1 == 'country')
	{
		$types = '3';
		$titlesub = "以独立IP访问量为单位 列出 国家统计为“".$options2."”的所有历史访问数据。";
		$counts = 'ipcounts';
	}
	if($options1 == 'province')
	{
		$types = '3';
		$titlesub = "以独立IP访问量为单位 列出 省份统计为“".$options2."”的所有历史访问数据。";
		$counts = 'ipcounts';
	}
	if($options1 == 'city')
	{
		$types = '3';
		$titlesub = "以独立IP访问量为单位 列出 城市统计为“".$options2."”的所有历史访问数据。";
		$counts = 'ipcounts';
	}
	if($options1 == 'area')
	{
		$types = '3';
		$titlesub = "以独立IP访问量为单位 列出 地区统计为“".$options2."”的所有历史访问数据。";
		$counts = 'ipcounts';
	}
	if($options1 == 'language')
	{
		$types = '3';
		$titlesub = "以独立IP访问量为单位 列出 语言统计为“".GetLanguage( $options2 )."”的所有历史访问数据。 ";
	} 
	if($options1 == 'timezone')
	{
		$types = '3';
		$array = GetTimeZone( $options2 );
		$titlesub = "以独立IP访问量为单位 列出 时区统计为“".$array[0]."”的所有历史访问数据。";
	} 
	if($options1 == 'screen')
	{
		$types = '3';		
		$titlesub = "以独立IP访问量为单位 列出 屏幕分辨率为“".$options2."”的所有历史访问数据。";
	} 
	if($options1 == 'color')
	{
		$types = '3';		
		$titlesub = "以独立IP访问量为单位 列出 屏幕颜色位数为“".$options2."”的所有历史访问数据。";
	} 
	if($options1 == 'browser')
	{
		$types = '3';		
		$titlesub = "以独立IP访问量为单位 列出 浏览器统计为“".$options2."”的所有历史访问数据。";
	} 
	if($options1 == 'system')
	{
		$types = '3';		
		$titlesub = "以独立IP访问量为单位 列出 操作系统统计为“".GetSystem($options2)."”的所有历史访问数据。";
	} 
	if($options1 == 'bot')
	{
		$types = '3';		
		$titlesub = "以独立IP访问量为单位 列出 网络蜘蛛 计为“".$options2."” 的所有历史访问数据。";
		$counts = 'pvcounts';
	} 
	if($options1 == 'keyword')
	{
		$types = '3';		
		$titlesub = "以独立IP访问量为单位 列出 关键字统计为“".$options2."”的所有历史访问数据。";    
		$counts = 'pvcounts';
	} 
	if($options1 == 'plug')
	{
		$types = '3';		
		$titlesub = "以独立IP访问量为单位 列出 插件统计为“".$options2."”的所有历史访问数据。";    
		$counts = 'pvcounts';
	} 
	if($regexp == 'true')
	{$Res = $Conn->Execute( " select sum(counts) as total_count from $TableList[$options1] where $options1 like '$options2%' and website = '$website'  and types = $types " );}
	else
	{$Res = $Conn->Execute( " select sum(counts) as total_count from $TableList[$options1] where $options1 = '$options2' and website = '$website'  and types = $types " );}
	$Row = $Res->FetchRow();	
	$total_count = $Row[total_count] <= 0 ? 1 : $Row[total_count];	
	$Quotietyip = PILLAR_WIDTH_2 / ($total_count);	
	unset($Row);unset($Res);
	
	if($regexp == 'true')
	{$Res = $Conn->Execute( " select count(*) as total  from $TableList[$options1] where $options1 like '$options2%' and website = '$website' and types = $types  order by times desc" );}
	else
	{$Res = $Conn->Execute( " select count(*)  as total  from $TableList[$options1] where $options1 = '$options2' and website = '$website' and types = $types  order by times desc" );}
	$CountRow = $Res->FetchRow();
	$Count = $CountRow[total];
	$PageSize = 30;	
	if( $Count > 0 )
	{
		include_once ( './include.inc/page.inc.php' );
		$PageItems = MakePageItems ( $Count, $PageSize );
		$PageLinks = MakePageLinks ( $PageItems, '记录','条' );
		$Tpl->assign( 'PageLinks', $PageLinks );
	}
	if($PageItems[Offset] == "")$PageItems[Offset] = 0;
	if($regexp == 'true')
	{$Res = $Conn->SelectLimit( " select *  from $TableList[$options1] where $options1 like '$options2%' and website = '$website' and types = $types  order by times desc", $PageSize ,$PageItems[Offset] );}
	else
	{$Res = $Conn->SelectLimit( " select *  from $TableList[$options1] where $options1 = '$options2' and website = '$website' and types = $types  order by times desc", $PageSize ,$PageItems[Offset] );}
	while($Row = $Res->FetchRow())
	{	
		$Datetime = $Row[times];
		$Month = date('n',$Datetime);
		$Day = date('j',$Datetime);
		$Date = $Month.".".$Day;
		$Res2 = $Conn->Execute( " select name from $TableList[holiday] where  datetime = '$Date'  ",'1','0' );
		$Row2 = $Res2->FetchRow();		
		$Row[holiday] = $Row2[name];
		$Row[week] = date('w',$Datetime);
		$Row[counts] = $Row[counts];
		$Row[precent] = sprintf("%01.2f", ( $Row[counts]/$total_count) * 100 );
		$Row[width] = $Row[counts]*$Quotietyip;		
		$Row[times] = date("Y-m-d",$Row[times]);
		$Datas[] = $Row;
		$SqlDatas[] = array('datetimes'=>$Row[times],$counts=>$Row[counts]);
	}	
	
	$Tpl->assign( 'total_count', $total_count );
	$Tpl->assign( 'Titlesub', $titlesub  );	
	$Tpl->assign( 'Referer', $options2 );
	$Tpl->assign( 'Datas', $Datas );

	$Tpl->assign( 'SqlDatas', urlencode(serialize ($SqlDatas) ));
	$Tpl->assign( 'FieldType', ( ($options2) ));
	$Tpl->assign( 'SqlDatasTitle', urlencode(serialize (array('日期','唯一访客IP','点击数PV')) ));
	if($DataCount > $PageSize)
	$Tpl->assign( 'Sql', urlencode("  select times as datetimes ,counts as $counts from $TableList[$options1] where $options1 = '$options2' and website = '$website' and types = $types  order by times desc") );
	$Tpl->assign( 'fname', $options1 . '_history' );
	$Tpl->assign( 'textexport', 'true' );
	$Tpl->assign( 'xmlexport', 'true' );
	$Tpl->assign( 'cvsexport', 'true' );

	$Tpl->assign( 'website', $website );
	$Tpl->assign( 'Main', $Tpl->fetch( 'options_history.html' ) );
	$Tpl->assign( 'Title', '列出所有历史访问数据 - '.$SoftWareName .$SoftWareVersion  );		
	$Tpl->assign( 'NowView', '列出所有历史访问数据');
	//$Tpl->assign( 'QuickLink', "<a href=\"?type=1\">今日统计</a> <a href=\"?type=2\">昨日统计</a> <a href=\"?type=0\">所有统计</a>" );
	$Tpl->assign( 'CopyRight', $PHPStatBottomRight );
	_out( $Tpl->fetch( 'main.html' )  );

?>
