<?php
class LinkAction extends Action {
	public function defaults() {
		$this -> assign('title', get_module('link', 'title'));
		$this -> display('link');
	}
	public function add() {
		if ($this -> isSubmit) {
			$obj = M('link');
			if ($obj -> save()) $this -> showMsg(L('ADD_LINK_SUCCESS'), $this -> forward?$this -> forward:ROOT_PATH);
			else {
				$msg = $obj -> error?$obj -> error:L('OPERATE_FAIL');
				$this -> showMsg($msg, $this -> referer);
			}
		}
		$this -> assign('title', L('ADD_LINK'));
		$this -> display('link');
	}
	public function checkurl() {
		$url = iconv('utf-8', C('APP_CHARSET', 1), $_POST['info']['url']);
		$obj = M('link');
		$data = $obj -> where('url=' . $url) -> find();
		$tmp = $data?iconv(C('APP_CHARSET', 1), 'utf-8', L('LINK_IS_EXIST')):'success';
		exit($tmp);
	}
}