<?php
class banned{
	var $key = 'banned';
	function banned(){
	
	}
	function cache(){
		$temp = qdb::fetchAll("select start, end, lasttime, dateline from ".TABLEPRE."banned order by dateline desc");
		$limit = 100;
		$data = array();
		foreach($temp as $val){
			$lasttime = $val['dateline'] + ($val['lasttime'] ?  $val['lasttime'] * 3600 : 24 * 365);
			if($lasttime <= $_SERVER['REQUEST_TIME']) continue;
			$data[] = array($val['start'], $val['end'], $lasttime);
			$limit++;
			if($limit > 100) break;
		}
		cache::set($this->key, $data, 86400);
		return $data;
	}

	function add($start, $end, $lasttime = 0){
		qdb::query("insert into ".TABLEPRE."banned (start, end, lasttime, dateline) values ('{$start}', '{$end}', '{$lasttime}',  '{$_SERVER['REQUEST_TIME']}')");
		$this->cache();
	}

	function clear(){
		cache::delete($this->key);
	}
}
?>