<?php
	if(!defined("ROOT_PATH")) exit("die Access ");
	class admin_activityControl extends skymvc{
		
		public function __construct(){
			parent::__construct();
			$this->loadmodel(array("activity","activity_data","user","login"));
			$this->smarty->assign("type_id_list",$this->activity->type_id_list());
		}
		
		public function onDefault(){
			$where="";
			$url="/index.php?m=admin_activity&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->activity->select($option,$rscount);
			if($data){
				foreach($data as $k=>$v){
					$u=$this->user->selectRow(array("where"=>"userid=".$v['userid']));
					$v['nickname']=$u['nickname'];
					$v['user_head']=$u['user_head'];
					$data[$k]=$v;
				}
			}
			$pagelist=$this->pagelist($rscount,$limit,$url);
			$this->smarty->assign(
				array(
					"data"=>$data,
					"pagelist"=>$pagelist,
					"rscount"=>$rscount,
					"url"=>$url
				)
			);
			$this->smarty->display("activity/index.html");
		}
		
		public function onShow(){
			$id=get_post("id","i");
			if($id){
				$data=$this->activity->selectRow(array("where"=>"id={$id}"));
				
			}
			$this->smarty->assign(array(
				"data"=>$data
			));
			$this->smarty->display("activity/show.html");
		}
		public function onAdd(){
			$id=get_post("id","i");
			if($id){
				$data=$this->activity->selectRow(array("where"=>"id={$id}"));
				$data['content']=$this->activity_data->selectOne(array("where"=>"id='$id' ","fields"=>"content"));
				$data['nickname']=$this->user->selectOne(array("where"=>"userid=".$data['userid'],"fields"=>"nickname"));
			}
			$this->smarty->assign(array(
				"data"=>$data
			));
			$this->smarty->display("activity/add.html");
		}
		
		public function onSave(){
			
			$id=get_post("id","i");
			$data["title"]=post("title","h");
			$data["siteid"]=post("siteid","i");
			$data["logo"]=post("logo","h");
			
			$data["keywords"]=post("keywords","h");
			$data["description"]=post("description","h");
			$data["info"]=post("info","h");
			$data["status"]=post("status","i");
			
			$data["click_num"]=post("click_num","i");
			$data["topic_num"]=post("topic_num","i");
			$sdata["content"]=post("content","x");
			$data["starttime"]=strtotime(post("starttime"));
			$data["endtime"]=strtotime(post("endtime"));
			$data["address"]=post("address","h");
			$data["join_num"]=post("join_num","i");
			$data["gid"]=post("gid","i");
			$data["type_id"]=post("type_id","i");

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

?>