<?php
class statControl extends skymvc{
	public $userInfo;
	public function __construct(){
		parent::__construct();
		$this->loadModel(array("statistics","login"));
		$this->userInfo=$this->login->getUser();
		$this->userid=$this->login->getUserId();	
	}
	
	public function OnTao(){
		if(strpos($_SERVER['HTTP_REFERER'],$_SERVER['HTTP_HOST'])===false) exit();
		$data['from_url']=htmlspecialchars($_SERVER['HTTP_REFERER']);
		preg_match("/[^\w]id[=-](\d+)/",$data['from_url'],$ids);
		$from_user_id=0;
		if(isset($ids[1])){
			$this->loadmodel("product");
			$pro=$this->product->selectRow(array("where"=>"id=".intval($ids[1])));
			$from_user_id=$pro['userid'];
		}
		$data['to_url']=get_post('url','h');
		$data['dateline']=time();
		$data['ip']=realip();
		$data['userid']=$this->userid;
		$data['month']=date("m");
		$data['from_userid']=$from_user_id;
		$this->statistics->insert($data);
		echo json_encode(array("message"=>"success","error"=>0));
		
	}
	
	public function onMy(){
		$this->login->checkLogin();
		$rscount=true;
		$url="".APPADMIN."?m=admin_statistics&a=default";
		$where['from_userid']=$this->login->userid;
		if($userid=get('userid','i')){
			$where['userid']=$userid;
			$url.="&userid=$userid";
		}
		if(get('start_time')){
			$where['dateline>=']=strtotime(get('start_time'));
			$url.="&start_time=".get('start_time');
		}
		if(get('end_time')){
			$where['dateline<=']=strtotime(get('end_time'));
			$url.="&end_time=".get('end_time');
		}
		if($from_url=get('from_url','h')){
			$where['from_url']=$from_url;
			$url.="&from_url".$from_url;
		}
		$option=array(
			"start"=>get('per_page','i'),
			"limit"=>50,
			"order"=>" id desc",
			"where"=>$where
			
		);
		$data=$this->statistics->select($option,$rscount);
		$pagelist=$this->pagelist($rscount,50,$url);
		$this->smarty->assign(array(
			"data"=>$data,
			"rscount"=>$rscount,
			"pagelist"=>$pagelist
		));
		$this->smarty->display("user/stat.html");	
	}
		
}
?>