<?php
	!defined('DIRCMS_MANAGE') && exit('Access Denied!');
	if(!$module->roleid_check('pe',$_roleid))showmsg_nourl($lang['RETURN_NOPRI']);
	$adminlist=$db->fetch_all("SELECT `".DB_PRE."admin_cache`.`userid`,`".DB_PRE."admin_cache`.`username` FROM `".DB_PRE."admin_cache`");
	if($action=='table')
	{
		$starttime=isset($info['starttime'])?strtotime($info['starttime']):TIME-3600*24;
		$endtime=isset($info['endtime'])?strtotime($info['endtime']):TIME;

		/*
			由于本操作比较消耗资源 , 优先读取缓存
		*/
		$series=$cache->get(md5('performance examine'.$starttime.$endtime));
		
		if(!$series)
		{
			foreach($adminlist as $_r)
			{
				$key=$_r['username'];
				$series[$key]['userid']=$_r['userid'];
				$series[$key]['name']=$_r['username'];
				$series[$key]['data']=array();

				$series[$key]['data']=get_cache_counts("SELECT COUNT(*) AS count FROM `".DB_PRE."content` WHERE `".DB_PRE."content`.`userid`=".$_r['userid']." AND `".DB_PRE."content`.`inputtime` BETWEEN $starttime AND $endtime");
				$series[$key]['clicks']=get_cache_counts("SELECT SUM(clicks) AS count FROM `".DB_PRE."content` WHERE `".DB_PRE."content`.`userid`=".$_r['userid']." AND `".DB_PRE."content`.`inputtime` BETWEEN $starttime AND $endtime");
				$series[$key]['comments']=get_cache_counts("SELECT SUM(comments) AS count FROM `".DB_PRE."content` WHERE `".DB_PRE."content`.`userid`=".$_r['userid']." AND `".DB_PRE."content`.`inputtime` BETWEEN $starttime AND $endtime");
			}
			$cache->set(md5('performance examine'.$starttime.$endtime),$series);
		}
		require DIRCMS_ROOT.'/include/form.class.php';
		$form=new form();
		include admin_tlp('k','pe');
	}
	else
	{
		$y=isset($y)?$y:date('Y');
		$m=isset($m)?$m:date('m');
		if($y==date('Y') && $m==date('m'))
		{
			$month=range(1,min(date('j'),max(31,date('t'))));
		}
		else
		{
			$month=range(1,date('t',strtotime($y.'-'.$m.'-01')));
		}

		/*
			由于本操作比较消耗资源 , 优先读取缓存
		*/
		$series=$cache->get(md5('performance examine'.$y.$m));
		
		if(!$series)
		{
			foreach($adminlist as $_r)
			{
				$key=$_r['username'];
				$series[$key]['userid']=$_r['userid'];
				$series[$key]['name']=$_r['username'];
				$series[$key]['data']=array();
				
				foreach($month as $mon)
				{
					$mininputtime=strtotime(date('Y-m',strtotime($y.'-'.$m.'-01')).'-'.$mon);
					$maxinputtime=strtotime(date('Y-m',strtotime($y.'-'.$m.'-01')).'-'.($mon+1))-1;
					$series[$key]['data'][$mon]=get_cache_counts("SELECT COUNT(*) AS count FROM `".DB_PRE."content` WHERE `".DB_PRE."content`.`userid`=".$_r['userid']." AND `".DB_PRE."content`.`inputtime` BETWEEN $mininputtime AND $maxinputtime");
					$series[$key]['clicks'][$mon]=get_cache_counts("SELECT SUM(clicks) AS count FROM `".DB_PRE."content` WHERE `".DB_PRE."content`.`userid`=".$_r['userid']." AND `".DB_PRE."content`.`inputtime` BETWEEN $mininputtime AND $maxinputtime");
				}
			}
			$cache->set(md5('performance examine'.$y.$m),$series);
		}
		include admin_tlp('index','pe');
	}
?>