<?php

/**
 * Copyright (C) 2009 Wskm Inc.All rights reserved.  
 * [Gart] www.wskmphp.com 
 * $Id: class_auth.php 105 2010-10-02 14:10:44Z ws99 $ 
 */

!defined('IN_ART') && exit('Access Denied');

class admin_auth extends wskm_page_abstract
{	
	public $adminaccess='';
	public function __construct()
	{
		parent::__construct();
	}
	
	public function login($password)
	{
		$user=tigerUser();
		if ($user->samePassword($password)) {
			$this->insertSessiong();
			
			return true;
		}
		return false;
	}
	
	public function logout()
	{
		$this->db->exec('DELETE FROM '.TABLE_PREFIX.'adminsessions WHERE uid = \''.$this->getUid().'\' ');
		$this->islogin=false;
	}
	
	public function readSession($life=1200)
	{
		$this->db->exec('DELETE FROM '.TABLE_PREFIX."adminsessions WHERE gotime < '".(WSKM_TIME-$life)."' ");		
		return $this->db->fetch_first('SELECT logintime,gotime,ip FROM '.TABLE_PREFIX."adminsessions WHERE uid='{$this->getUid()}' AND uname='{$this->getUname()}' AND adminid='{$this->getAdminid()}'  ");
	}

	public function insertSessiong()
	{
		$time=WSKM_TIME;
		return $this->db->exec('INSERT INTO '.TABLE_PREFIX."adminsessions (uid,uname,adminid,gotime,logintime,ip)VALUES('{$this->getUid()}','{$this->getUname()}','{$this->getAdminid()}','$time','$time','{$this->user->getIp()}')  ")  !== false;
	}

	public function updateSession()
	{		
		$this->db->exec('UPDATE '.TABLE_PREFIX."adminsessions SET  gotime='".WSKM_TIME."' WHERE uid='{$this->getUid()}' ") ;
	}
	
	public function isManageAccess(){
		if (ADMINID != 1) {
			return false;
		}
		return true;
	}

}


?>