<?php
/*
秀影EasyFramework框架
qq:24498936
msn:jdzcn_net@hotmail.com
website:http://www.vodcms.com
系统日志记录
*/
class systemlog{
	public static $name = VODCMS_SYSTEMLOG;
	public static $error;
	public static $printpage;
	/*
	写入系统日志
	*/
	public static function  set($message, $admin=null, $DB=null){
		if (is_null($DB)){
			$DB = $GLOBALS['DB'];
		}
		$array = array();
		$Response = new Easy_Controller_Request();
		$array['admin'] = $admin ? $admin : $Response->getCookie('admin');
		$array['addtime'] = time();
		$array['userip'] = $_SERVER['REMOTE_ADDR'];
		$array['message'] = $_SERVER['REQUEST_METHOD'].$message;
		$array['uri'] = $_SERVER['REQUEST_URI'];
		return $DB->insert(self::$name, $array);
	}
	public static function getAll(){
		$DB = $GLOBALS['DB'];
		$select = $DB->select();
		$sql = $select->from(self::$name)->order('id DESC');
		$total = $DB->getCount($sql);
		$page = new Page();
		$page->set($total);
		$result = $DB->FetAll($sql.$page->limit());
		self::$printpage = $page->PrintPage();
		return $result;
	}
	public static function search($where){
		$DB = $GLOBALS['DB'];
		$select = $DB->select();
		$sql = $select->from(self::$name)->where($where)->order('id DESC');
		$total = $DB->getCount($sql);
		$page = new Page();
		//echo $sql;
		$page->set($total);
		$result = $DB->FetAll($sql.$page->limit());
		self::$printpage = $page->PrintPage();
		return $result;
	}
	public static function delete($id){
		$DB = $GLOBALS['DB'];
		$lifetime = time() - (30 * 86400);
		return $DB->delete(self::$name, 'id='.(int)$id.' AND addtime<='.$lifetime);
	}
}