<?php
// 内链模块控制器
class RelatedlinkAction extends BaseAction {
	protected function _initializeMore() {
		$this -> obj = M('relatedlink');
	}
	public function defaults() {
		$page = intval(R('page'));
		$pageSize = 20;
		if (R('field')) {
			$order = R('order')?strtoupper(R('order')):'DESC';
			$order = R('field') . ' ' . $order;
		} else $order = '';
		$this -> assign('data', $this -> obj -> getList($page, $pageSize, '', $order));
		$this -> assign('pages', $this -> obj -> pages());
		$this -> assign('jmpurl', '?' . del_query_string('page'));
		$this -> assign('orderurl', '?' . del_query_string('order|field'));
		$this -> assign('order', strtoupper(R('order'))=='DESC'?'ASC':'DESC');
		$this -> display('relatedlink');
	}
	public function add() {
		if ($this -> isSubmit) {
			$msg = $this -> obj -> save()?L('OPERATE_SUCCESS'):L('OPERATE_FAIL');
			$this -> showMsg($msg, $this -> referer);
		}
		$this -> assign('data', array('id' => 0, 'priority' => 0));
		$this -> display('relatedlink');
	}
	public function edit() {
		if ($this -> isSubmit) {
			$msg = $this -> obj -> save(false)?L('OPERATE_SUCCESS'):L('OPERATE_FAIL');
			$this -> showMsg($msg, $this -> forward);
		}
		$id = intval(R('id'));
		$this -> assign('data', $this -> obj -> find($id));
		$this -> display('relatedlink');
	}
	public function addMore() {
		if ($this -> isSubmit) {
			$msg = $this -> obj -> addMore();
			if(!$msg) $msg = $this -> obj -> error;
			$this -> showMsg($msg, $this -> referer);
		}
		$this -> display('relatedlink');
	}
	// 删除
	public function del() {
		if($this -> obj -> del()) $this -> showMsg(L('OPERATE_SUCCESS'), $this -> referer);
		else $this -> showMsg($this -> error);
	}
	// 析构函数
	public function __destruct() {
		$this -> obj -> cache();
	}
}