<?php
	require_once "pageBase.php";
	require_once "../dal/count_lastDAL.php";
	require_once "../bin/web/repeater.php";

	class _countIP2 extends pageBase{

		//覆蓋父類load()方法
		public function load(){
			if(!parent::chkUserLimit('13')){
				parent::alert2('您沒有使用此頁面的權限!如有疑問請洽主管理者!','index.php');
				exit;
			}

			$this->loadData();
			parent::load();
		}
		public function loadData(){
			$dalL = new count_lastDAL();

			$ip = parent::getPageParameter("ip", "");
			$ym = parent::getPageParameter("ym", date("Y-m"));
			parent::addParameter("ip", $ip);
			parent::addParameter("ym", $ym);
			
			$filter = "a.`Time` LIKE '".$ym."%' AND a.`IP`='".$ip."'";
			$orderExp = "a.`CountID` DESC";
			$dataL = $dalL->executeRecordset($filter, $orderExp);
			for($i=0;$i<count($dataL);$i++){
				if(mb_strpos($dataL[$i]["RefererHost"], "yahoo.com", 0, "utf-8") !== false){
					$dataL[$i]["SearchEngine"] = "Yahoo";
				}else if(mb_strpos($dataL[$i]["RefererHost"], "google.com", 0, "utf-8") !== false){
					$dataL[$i]["SearchEngine"] = "Google";
				}else if(mb_strpos($dataL[$i]["RefererHost"], "baidu.com", 0, "utf-8") !== false){
					$dataL[$i]["SearchEngine"] = "百度";
				}
			}
			$listL = new repeater();
			$listL->id = "listL";
			$listL->dataSource = $dataL;
			parent::addControl($listL);
			parent::addParameter("ipcount", "".count($dataL));

			parent::loadTemplateFile(dirname(__FILE__)."/templates/countIP2.html");
			parent::loadData();
		}
	}

	$page = new _countIP2();
	$page->load();
	$page->render();
?>