<?php
	if(!defined("ROOT_PATH")) exit("die Access ");
	class admin_hotareaControl extends skymvc{
		
		public function __construct(){
			parent::__construct();
			$this->loadmodel(array("hotarea"));
		}
		
		public function onDefault(){
			$where="";
			$url="/index.php?m=admin_hotarea&a=default";
			$limit=20;
			$start=get("per_page","i");
			$option=array(
				"start"=>intval(get_post('per_page')),
				"limit"=>$limit,
				"order"=>" id DESC",
				"where"=>$where
			);
			$rscount=true;
			$data=$this->hotarea->select($option,$rscount);
			$pagelist=$this->pagelist($rscount,$limit,$url);
			$this->smarty->assign(
				array(
					"data"=>$data,
					"pagelist"=>$pagelist,
					"rscount"=>$rscount,
					"url"=>$url
				)
			);
			$this->smarty->display("hotarea/index.html");
		}
		
		public function onList(){
			$where="";
			$url="/index.php?m=admin_hotarea&a=default";
			$limit=20;
			$start=get("per_page","i");
			$option=array(
				"start"=>intval(get_post('per_page')),
				"limit"=>$limit,
				"order"=>" id DESC",
				"where"=>$where
			);
			$rscount=true;
			$data=$this->hotarea->select($option,$rscount);
			$pagelist=$this->pagelist($rscount,$limit,$url);
			$this->smarty->assign(
				array(
					"data"=>$data,
					"pagelist"=>$pagelist,
					"rscount"=>$rscount,
					"url"=>$url
				)
			);
			$this->smarty->display("hotarea/index.html");
		}
		
		public function onShow(){
			$id=get_post("id","i");
			if($id){
				$data=$this->hotarea->selectRow(array("where"=>"id={$id}"));
				
			}
			$this->smarty->assign(array(
				"data"=>$data
			));
			$this->smarty->display("hotarea/show.html");
		}
		public function onAdd(){
			$id=get_post("id","i");
			if($id){
				$data=$this->hotarea->selectRow(array("where"=>"id={$id}"));
				
			}
			$this->smarty->assign(array(
				"data"=>$data
			));
			$this->smarty->display("hotarea/add.html");
		}
		
		public function onSave(){
			
			$id=get_post("id","h");
			$data["siteid"]=post("siteid","i");
			$data["title"]=post("title","h");
			if(empty($data['title'])){
				$this->gomsg("区域名称不能为空");
			}
			$data["lat"]=post("lat","r",6);
			$data["lng"]=post("lng","r",6);
			$data['status']=post('status','i');
			$data['info']=post('info','h');
			$data["orderindex"]=post("orderindex","i");
			$data['bounds']=post('bounds','h');
			$data['content']=post('content','x');	
			if($id){
				$this->hotarea->update($data,"id='$id'");
			}else{
				$this->hotarea->insert($data);
			}
			$this->gomsg("保存成功");
		}
		
		public function onStatus(){
			$id=get_post('id',"i");
			$status=get_post("status","i");
			$this->hotarea->update(array("status"=>$status),"id=$id");
			exit(json_encode(array("error"=>0,"message"=>"状态修改成功")));
		}
		
		
		public function onRecommend(){
			$id=get_post('id',"i");
			$status=get_post("status","i");
			$this->hotarea->update(array("isrecommend"=>$status),"id=$id");
			exit(json_encode(array("error"=>0,"message"=>"状态修改成功")));
		}
		
		public function onDelete(){
			$id=get_post('id',"i");
			$this->hotarea->delete("id={$id}");
			exit(json_encode(array("error"=>0,"message"=>"删除成功")));
		}
		
		
	}

?>