<?php
 /**
 *      [XCECP] (C) COLNET Inc.
 *      This is NOT a freeware, use is subject to license terms
 */
if(!defined("IN_QKWEB")){exit("Access Denied");}
class BaseAction{
	function __construct(){
	}
	public static function checkLogin(){
		global $_G;
		if(!isset($_SESSION['userId']) || $_SESSION['userId']=="" || !isset($_COOKIE['account']) || $_COOKIE['account']==''){
			$inajax = getgpc("inajax","P");
			if($inajax==1){
				exit('{"success":false,"message":"'.$_G['lang']['pleaseLogin'].'","type":1,"data":"nologin"}');
			}else{
				//header("Location:/user/login\n");exit;
				Msg::show(array('msg'=>'请先登录','url'=>'/user/login/','time'=>0));
			}
		}
		return true;
	}
	public static function userLogin(){
		if(isset($_SESSION['userId']) && $_SESSION['userId']!="" && is_numeric($_SESSION['userId']) && isset($_COOKIE['account']) && $_COOKIE['account']!=''){return true;}
		return false;
	}
	public static function checkAdmin(){
		global $adminUrl;
		if(!BaseAction::adminLogin()){
			header("HTTP/1.1 401 Unauthorized");
			Msg::show(array("msg"=>"请先登录","url"=>$adminUrl."login","timer"=>10),true);
			//header("Location:".$baseUrl."qkadmin/login\n");
		}
	}
	public static function adminLogin(){
		if(isset($_SESSION['adminId']) && $_SESSION['adminId']!="" && is_numeric($_SESSION['adminId'])){return true;}
		return false;
	}
}
?>