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

class VariableModel{
	private $db;
	function __construct(){
		global $db;
		$this->db = $db;
	}
	function variableInfo($id=false){
		if($id && settype($id,"integer")){
			$sql = "select * from qk_variable where id='$id'";
			$res = $this->db->getRow($sql);
			if($res){
				return $res;
			}else{
				return false;
			}
		}else{
			return $this->db->getRow("select * from qk_variable where name='$id'");
		}
		return false;
	}
	function getInfo($id=false){
		if($id && is_numeric($id)){
			$sql = "select * from qk_variable where id='$id'";
			$res = $this->db->getRow($sql);
			if($res){
				return $res;
			}else{
				return false;
			}
		}else{
			return $this->db->getRow("select * from qk_variable where name='$id'");
		}
		return false;
	}
	
	function add($params){
		$name = isset($params['name'])?$params['name']:"";
		$value = isset($params['value'])?$params['value']:"";
		$remark = isset($params['remark'])?$params['remark']:"";
		if($name!=""){
			$sql = "insert into qk_variable set name='$name',value='$value',remark='$remark',posttime=UNIX_TIMESTAMP()";
			if($this->db->query($sql)){
				return true;
			}else{
				return false;
			}
		}else{
			return false;
		}
	}

	function edit($params){
		$id = isset($params['id'])?$params['id']:0;
		$name = isset($params['name'])?$params['name']:"";
		$value = isset($params['value'])?$params['value']:"";
		$remark = isset($params['remark'])?$params['remark']:"";
		if($name!="" && $id && settype($id,"integer")){
			$sql = "update qk_variable set name='$name',value='$value',remark='$remark' where id='$id'";
			if($this->db->query($sql)){
				return true;
			}else{
				return false;
			}
		}else{
			return false;
		}
	}

	function del($params){
		$id = isset($params['id'])?$params['id']:0;
		if($id && settype($id,"integer")){
			$sql = "delete from qk_variable where id='$id'";
			if($this->db->query($sql)){
				return true;
			}else{
				return false;
			}			
		}
		return false;
	}

}
?>