<?php
 /**
 *      [XCECP] (C) Colorful Network Inc.
 *      This is NOT a freeware, use is subject to license terms
 */
if(!defined("IN_QKWEB")){exit("Access Denied");}
class AdModel extends BaseModel{
	public $msg='';
	function getInfo($id){
		global $siteConf;
		if(!$id || !settype($id,"integer")){return false;}
		$wheres='';if(defined('SITE_ID')  && !$GLOBALS['siteConf']['share']){$wheres .= " and (siteId='".SITE_ID."' or siteId=0)";}
		$sql = "select * from `qk_ad` where id='$id' $wheres";
		$info = $this->db->getRow($sql);
		return $info;
	}
	function add($param){$param['act']='add';return $this->query($param);}
	function edit($param){$param['act']='edit';return $this->query($param);}
	function query($param){
			$id = $param['id'];
			$act = $param['act'];
			$name = $param['name'];
			$iStatus = $param['iStatus'];
			$link = $param['link'];
			$sortId = $param['sortId'];
			$thumbId = $param['thumbId'];
			$placeId = $param['placeId'];
			$goodsCatId = $param['goodsCatId'];
			if(!$goodsCatId || !is_numeric($goodsCatId)){$goodsCatId=0;}
			if(settype($iStatus,"integer")===false){$iStatus=1;}
			if(settype($thumbId,"integer")===false){$thumbId=0;}
			if($thumbId){
				if($act=="edit"){
					$sql = "update qk_ad set ";
					$sqlEnd = " where id='".$id."'";
				}else if($act=="add"){
					$sql = "insert into qk_ad set ";
					$sqlEnd = ",posttime=UNIX_TIMESTAMP()";
				}else{
					$this->msg='非法访问';return false;
				}
				$sql .= " name='$name',iStatus='$iStatus',thumbId='$thumbId',link='$link',sortId='$sortId',placeId='$placeId',goodsCatId='$goodsCatId'";
				if(defined("SITE_ID") && is_numeric(SITE_ID)){$sql.=",siteId='".SITE_ID."'";}
				$sql .= $sqlEnd;
				if($GLOBALS['db']->query($sql)){
					if($act=='add'){$this->msg='添加广告成功';}else if($act=='edit'){$this->msg='修改广告成功';}
					return true;
				}else{
					$this->msg='数据存取失败';
				}
			}else{
				$this->msg='未上传广告图片';
			}
		return false;
	}
}
?>