<?php
	if(!defined("ROOT_PATH")) exit("die Access ");
	class admin_weixin_commandControl extends skymvc{
		
		public function __construct(){
			parent::__construct();
			$this->loadmodel(array("weixin_command","weixin"));
		}
		
		public function onDefault(){
			$where="";
			$url="/index.php?m=admin_weixin_command&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->weixin_command->select($option,$rscount);
			$pagelist=$this->pagelist($rscount,$limit,$url);
			$this->smarty->assign(
				array(
					"data"=>$data,
					"pagelist"=>$pagelist,
					"rscount"=>$rscount,
					"url"=>$url,
					"weixin_list"=>$this->weixin->id_list(),
				)
			);
			$this->smarty->display("weixin_command/index.html");
		}
		
		public function onList(){
			$where="";
			$url="/index.php?m=admin_weixin_command&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->weixin_command->select($option,$rscount);
			$pagelist=$this->pagelist($rscount,$limit,$url);
			$this->smarty->assign(
				array(
					"data"=>$data,
					"pagelist"=>$pagelist,
					"rscount"=>$rscount,
					"url"=>$url,
					"weixin_list"=>$this->weixin->id_list(),
					"type_list"=>$this->weixin_command->type_list,
				)
			);
			$this->smarty->display("weixin_command/index.html");
		}
		
		public function onShow(){
			$id=get_post("id","i");
			if($id){
				$data=$this->weixin_command->selectRow(array("where"=>"id={$id}"));
				
			}
			$this->smarty->assign(array(
				"data"=>$data,
				"weixin_list"=>$this->weixin->id_list(),
				"type_list"=>$this->weixin_command->type_list,
			));
			$this->smarty->display("weixin_command/show.html");
		}
		public function onAdd(){
			$id=get_post("id","i");
			if($id){
				$data=$this->weixin_command->selectRow(array("where"=>"id={$id}"));
				
			}
			$this->smarty->assign(array(
				"data"=>$data,
				"weixin_list"=>$this->weixin->id_list(),
				"type_list"=>$this->weixin_command->type_list,
			));
			$this->smarty->display("weixin_command/add.html");
		}
		
		public function onSave(){
			
			$id=get_post("id","i");
			$data["wid"]=post("wid","i");
			$data["title"]=post("title","h");
			$data["command"]=post("command","h");
			$data["type_id"]=post("type_id","i");
			$data["content"]=post("content","h");
			$data["dateline"]=time();

			if($id){
				$this->weixin_command->update($data,"id='$id'");
			}else{
				$this->weixin_command->insert($data);
			}
			$this->gomsg("保存成功");
		}
		
		public function onStatus(){
			$id=get_post('id',"i");
			$status=get_post("status","i");
			$this->weixin_command->update(array("status"=>$status),"id=$id");
			exit(json_encode(array("error"=>0,"message"=>"状态修改成功")));
		}
		
		public function onDelete(){
			$id=get_post('id',"i");
			$this->weixin_command->delete("id={$id}");
			exit(json_encode(array("error"=>0,"message"=>"删除成功")));
		}
		
		
	}

?>