<?php
 /**
 *      [XCECP] (C) Colorful Network Inc.
 *      This is NOT a freeware, use is subject to license terms
 */

class HotkeyModel extends BaseModel{
	public $msg;
	function add($param){$param['act']='add';return $this->query($param);}
	function edit($param){$param['act']='edit';return $this->query($param);}
	function del($param){
		if($param['act']=='del' && $param['id'] && is_numeric($param['id'])){ if($this->db->query("delete from qk_hotkey where id='".$param['id']."'")){ $this->msg='删除成功';;return true;} }return false;
	}
	function query($param){
		$act = $param['act'];if(!in_array($act,array('add','edit'))){$this->msg='参数检查失败';return false;}
		$id = $param['id'];
		$name = $param['name'];
		$url = $param['url'];
		$color = $param['color'];
		$sortId = $param['sortId'];
		if(!$sortId || !is_numeric($sortId)){$sortId=50;}
		if($act=='add'){
			$sql = "insert into qk_hotkey set ";$sqlEnd=",posttime=UNIX_TIMESTAMP()";
			if(!$name){$this->msg='关键词不能为空';return false;}
		}else if($act=='edit'){
			if(!$id || !is_numeric($id)){$this->msg='缺少必要参数';return false;}
			if(!$this->db->getOne("select id from qk_hotkey where id='$id'")){$this->msg='数据不存在，可能已被删除';return false;}
			$sql = "update qk_hotkey set ";$sqlEnd = " where id='$id'";
		}
		$sql .= " name='$name',url='$url',color='$color',sortId='$sortId'";
		$sql .= $sqlEnd;
		if($this->db->query($sql)){
			if($act=='add'){$this->msg='添加成功';}else if($act=='edit'){$this->msg='修改成功';}
			return true;
		}else{
			if($act=='add'){$this->msg='添加失败';}else if($act=='edit'){$this->msg='修改成功';}
		}
		return false;
	}

}
?>