<?php
class loginModel extends model{
	public $userid;
	public $base;
	function __construct(&$base){
		parent::__construct($base);
		$this->base=$base;
		$this->table="user";
		$this->userid=$this->getUserId();
	}
	
	public function getUser($userid=0){
		$userid=$userid?$userid:(isset($_SESSION['ssuser']['userid'])?intval($_SESSION['ssuser']['userid']):0);
		if(!$userid) return false;
		return parent::selectRow(array("where"=>"userid=$userid"));
	}
	
	public function getUserId(){
		return (isset($_SESSION['ssuser']['userid'])?intval($_SESSION['ssuser']['userid']):0);
	}
	
	public function checklogin($ajax=0){
		if(get_post('ajax')) $ajax=1;
		if($ajax){
			if(empty($_SESSION['ssuser']['userid'])){
				exit(json_encode(array("error"=>1,"message"=>$this->base->lang['please_login']) ));
				 
			}
		}else{
			if(empty($_SESSION['ssuser']['userid'])){
				$this->base->gomsg($this->base->lang['please_login'],"/index.php?m=login&a=login");
			}
		}
	}
	
	public function getAdmin($id=0){
		$id=$id?$id:intval($_SESSION['ssadmin']['id']);
		if(!$id) return false;
		return parent::setTable('admin')->selectRow(array("where"=>"id=$id"));
	}
	
	public function checkAdminLogin($ajax=0){
		if(get_post('ajax')) $ajax=1;
		if($ajax){
			if(empty($_SESSION['ssadmin'])){
				exit(json_encode(array("error"=>1,"message"=>$this->base->lang['please_login'])));
			}
		}else{
			if(empty($_SESSION['ssadmin'])){
				$this->base->gomsg($this->base->lang['please_login'],APPADMIN."?m=admin_login");
			}
		}
	}
	
	public function getShopAdmin($adminid=0){
		$adminid=$adminid?$adminid:intval($_SESSION['ssshopadmin']['adminid']);
		if(!$adminid) return false;
		return parent::setTable('shopadmin')->selectRow(array("where"=>" adminid=$adminid "));
	}
	
	public function checkShopAdmin(){
	
	}
	
}
?>