<?php
// ¹«¸æÄ£¿é¿ØÖÆÆ÷
class AnnouncementAction extends BaseAction {
	protected function _initializeMore() {
		$this -> obj = M('announcement');
		$this -> assign('config', C('', 0, 'announcement'));
		//exit($this -> action);
	}
	public function defaults() {
		$page = intval(R('page'));
		$pageSize = 20;
		$this -> assign('data', $this -> obj -> getList($page, $pageSize));
		$this -> assign('pages', $this -> obj -> pages());
		$this -> assign('jmpurl', '?' . del_query_string('page'));
		$this -> display('announcement');
	}
	public function add() {
		if ($this -> isSubmit) {
			$rs = $this -> obj -> save();
			if ($rs) {
				$msg = L('OPERATE_SUCCESS') . '<iframe width=1 height=1 border=0 frameborder=0 src="index.php?c=html&a=update_by_id&m=announcement&id=' . $this -> loginInfo['userid'] . '&hash=' . $this -> loginInfo['hash'] . '&selids=' . $rs . '"></iframe>';
			} else $msg = L('OPERATE_FAIL');
			$this -> showMsg($msg);
		}
		$this -> assign('data', array('id' => 0));
		$this -> display('announcement');
	}
	public function edit() {
		if ($this -> isSubmit) {
			$rs = $this -> obj -> save();
			if ($rs) {
				$msg = L('OPERATE_SUCCESS') . '<iframe width=1 height=1 border=0 frameborder=0 src="index.php?c=html&a=update_by_id&m=announcement&id=' . $this -> loginInfo['userid'] . '&hash=' . $this -> loginInfo['hash'] . '&selids=' . $rs . '"></iframe>';
			} else $msg = L('OPERATE_FAIL');
			$this -> showMsg($msg, $this -> forward);
		}
		$id = intval(R('id'));
		$this -> assign('data', $this -> obj -> find($id));
		$this -> display('announcement');
	}
	// É¾³ý
	public function del() {
		if($this -> obj -> del()) $this -> showMsg(L('OPERATE_SUCCESS'), $this -> referer);
		else $this -> showMsg($this -> error);
	}
}
