<?
ob_start();

include getenv("DOCUMENT_ROOT")."/include/session_include.php";

// Start of header
include getenv("DOCUMENT_ROOT")."/include/header.php";


// Start of menu
include getenv("DOCUMENT_ROOT")."/include/top.php";


// Start of top
//if (!strncmp($view,"signup", 5) || !strncmp($view,"login", 5) || !strncmp($view,"my", 2) || !strncmp($view,"study", 5) || !strncmp($view,"about", 5) || !strncmp($view,"resources", 9) || !strncmp($view,"contact", 7)) include getenv("DOCUMENT_ROOT")."/include/mpc-sub-top.php";
// else include getenv("DOCUMENT_ROOT")."/include/mpc-top.php";

// Start of main

if ($view != "") {
			$getFile = getenv("DOCUMENT_ROOT")."/doc/".$view.".php";
			
			if (!is_file($getFile)) {
				$msg = "SORRY, we couldn't find that page. Please Login again.";
				//$func -> alertBack($msg);
				session_destroy();
				$func -> modalMsg ($msg, "/login_intranet.php");		
				exit;		
			}
			else {
				include getenv("DOCUMENT_ROOT")."/doc/".$view.".php";		// Main
			}
}
else include getenv("DOCUMENT_ROOT")."/doc/customer_list.php";


// Start of footer	
$no_footer_pages = array("map");

if (!in_array($view, $no_footer_pages)) {
    include getenv("DOCUMENT_ROOT")."/include/footer.php";
}

?>

<?
// Counter

// Session
//if ($_SESSION['ss_LOGCHECK'] != "1") { 

// Cookie
if ($_COOKIE["LOGCHECK"] != "1") {	
	//$setTimeStr = "+1 hour";
	$today = date("YmdH");
	$todayDetail = date("YmdHis");

	$columns = array();
	$values = array();

	// existing date check
	$query = "select UID,CNT_NUMBER from tbl_counter where CNT_DATE = '$today' ";
	$result = $jdb->fQuery($query, "fetched query error");
	
	if($result['UID'] == "") {
		$columns[] = "CNT_DATE";
		$columns[] = "CNT_NUMBER";
		
		$values[] = $today;
		$values[] = 1;		
		$jdb->iQuery("tbl_counter", $columns, $values);
	}
	else {
		$nowNo = $result['CNT_NUMBER']+1;
		//echo "BEFORE[$result[CNT_NUMBER]]";
		$query = " update tbl_counter set CNT_NUMBER = '$nowNo' where UID = '".$result['UID']."' ";
		$jdb->nQuery($query, "query error");
	}

	// ����� IP ����
	$user_ip = $_SERVER["REMOTE_ADDR"];
	$referer = $_SERVER["HTTP_REFERER"];
	$user_agent = $_SERVER["HTTP_USER_AGENT"];
	
	if ($refurl == "") {
		if (!$referer) $referer="Typing or Bookmark Moving On This Site";
	}


	$rt_geo = json_decode(file_get_contents("http://ip-api.com/json/{$user_ip}"));
	//print_r ($rt_geo);
	//echo "{$rt_geo->country},{$rt_geo->city}";//CA,Rogers Communications Canada Inc.


	$columns = array();
	$values = array();

	unset($columns);
	unset($values);
	
	$columns[] = "CNT_DATE";
	$columns[] = "CNT_IP";
	$columns[] = "CNT_REFERER";
	$columns[] = "CNT_USERAGENT";
	
	$columns[] = "CNT_INFO_AS";
	$columns[] = "CNT_INFO_CITY";
	$columns[] = "CNT_INFO_COUNTRY";
	$columns[] = "CNT_INFO_COUNTRYCODE";
	$columns[] = "CNT_INFO_ISP";
	$columns[] = "CNT_INFO_LAT";
	$columns[] = "CNT_INFO_LON";
	$columns[] = "CNT_INFO_ORG";
	$columns[] = "CNT_INFO_REGION";
	$columns[] = "CNT_INFO_REGIONNAME";
	$columns[] = "CNT_INFO_STATUS";
	$columns[] = "CNT_INFO_TIMEZONE";
	$columns[] = "CNT_INFO_ZIP";
	
	
	$values[] = $todayDetail;
	$values[] = $user_ip;
	$values[] = $referer;
	$values[] = $user_agent;
	
	$values[] = $rt_geo->as;
	$values[] = $rt_geo->city;
	$values[] = $rt_geo->country;
	$values[] = $rt_geo->countryCode;
	$values[] = $rt_geo->isp;
	$values[] = $rt_geo->lat;
	$values[] = $rt_geo->lon;
	$values[] = $rt_geo->org;
	$values[] = $rt_geo->region;
	$values[] = $rt_geo->regionName;
	$values[] = $rt_geo->status;
	$values[] = $rt_geo->timezone;
	$values[] = $rt_geo->zip;
	
	
	$jdb->iQuery("tbl_count_details", $columns, $values);
	
	setcookie("LOGCHECK", "1", time()+3600);  // 1h
	//$_SESSION['ss_LOGCHECK'] = "1"; // ���ǿ� ������ �����Ѵ�. 
	
} 

//setcookie("LOGCHECK", "1", time()-3600);  // expire cookie

?>
