<?php
 /**
 *      [XCECP] (C) COLNET Inc.
 *      This is NOT a freeware, use is subject to license terms
 */
if(!defined("IN_QKWEB")){exit("Access Denied");}
class ConfigModel extends BaseModel{
	public $msg="";
	function del($id){
		$sql = "delete from `qk_config` where id='$id' limit 1";
		return $this->db->query($sql);
	}
	function getInfo($id){
		$sql = "select * from `qk_config` where id='$id'";
		$info = $this->db->getRow($sql);
		if(!$info){return false;}
		return $info;
	}
	function edit($param){
		return $this->query($param);
	}
	function add($param){
		return $this->query($param);
	}
	function query($param){
		$act = $param['act'];
		$id = $param['id'];
		$name = $param['name'];
		$amount = $param['amount'];
		$remark = $param['remark'];
		$iStatus = $param['iStatus'];
		if($act=="add"){
			$sql = "insert into `qk_config` set ";
			$sqlEnd = ",posttime=UNIX_TIMESTAMP()";
		}else if($act=="edit" && $id && settype($id,"integer")){
			$config = $this->db->getOne("select config from qk_config where id='$id'");
			$config = unserialize($config);
			$i = 0;
			foreach($config as $item){
				$configname = $item['name'];
				$config[$i]['value'] = $param[$configname];
				$i++;
			}
			$config = serialize($config);
			$sql = "update `qk_config` set ";
			$sqlEnd = " where id='$id'";
		}
		$sql .= " remark='$remark',config='$config',iStatus='$iStatus'";
		$sql .= $sqlEnd;
		if($this->db->query($sql)){
			if($act=='add'){$this->msg='添加成功';}else if($act=='edit'){$this->msg='修改成功';}	
			return true;
		}
		return false;
	}
	function ajaxEdit($params){
		$id = $params['id'];
		$act = $params['act'];
		$col = $params['col'];
		$val = $params['val'];
		$oldval = $params['oldval'];
		if($id && is_numeric($id) && $col){
			$sql = "update `qk_config` set  $col='$val' where id='$id'";
			if($this->db->query($sql)){
				return true;
			}
		}
		return false;
	}
}
?>
