<?php
/**
	* 公告管理类
	* @author muhongwei
	* @copyright			(C) 2009-2011 DirCMS
	* @lastmodify			2011-08-24 15:16
*/

class notice
{
	public $pagestring='';
	private $db;
	private $table;

	function __construct()
	{
		global $db;
		$this->db=$db;
		$this->table=DB_PRE.'notice';
	}

	function datalist()
	{
		global $page;
		include DIRCMS_ROOT.'include/datalist.class.php';
		$datalist = new datalist();
		$where='siteid='.SITEID;
		$orderby='orderby ASC';
		$page=max(isset($page)?intval($page):1,1);
		$pagesize=15;
		$result=$datalist->getlist($this->table,$where,$orderby,$page,$pagesize);
		$this->pagestring=$datalist->pagestring;
		return $result;
	}

	function delete($id)
	{
		$this->db->mysql_delete($this->table,intval($id));
		return true;
	}

	function add($info)
	{
		$info['time']=TIME;
		$info['siteid']=SITEID;
		$insertid=$this->db->insert($this->table,$info);
		$this->db->update($this->table,array('orderby'=>intval($insertid)),'id='.intval($insertid));
		return true;
	}

	function edit($info,$id)
	{
		$info['time']=TIME;
		$info['siteid']=SITEID;
		$this->db->update($this->table,$info,'id='.intval($id));
		return true;
	}

	function notice_editorderby($orderbys,$titles)
	{
		foreach($orderbys as $id => $orderby)
		{
			$this->db->update($this->table,array('orderby'=>intval($orderby),'title'=>trim($titles[$id])),'id='.intval($id));
		}
		return true;
	}

	function info($id)
	{
		return $this->db->fetch_one("SELECT * FROM `$this->table` WHERE `$this->table`.`id`=".intval($id));
	}

	function show($id)
	{
		global $DIRCMS,$noticelang;
		$data=$this->info($id);
		if(!$data)show404($noticelang['msg-noexists'],$DIRCMS['site_url']);
		@extract($data);
		$dir_postion='<a href="'.$DIRCMS['site_url'].'">'.$noticelang['website'].'</a> > '.$noticelang['notice'];
		include template('show','notice');
	}
}
?>