<?php
class admin_weiboControl extends skymvc{
	function __construct(){
		parent::__construct();
		if(empty($_SESSION['ssadmin'])){
			$this->gourl("".APPADMIN."?m=admin&a=login");	
		}
		$this->loadModel(array("weibo_config","weibo_souser"));
	}

	public function onDefault(){
	
	}
	public function onConfig(){
			if(!$this->weibo_config->getOne("SELECT id FROM ".table('weibo_config')."  ")){
				$this->weibo_config->insert(array("siteid"=>1));
				 
			}
			$this->smarty->assign("data",$this->weibo_config->getRow("SELECT * FROM ".table('weibo_config')."  WHERE siteid=1  "));
			$this->smarty->display("weibo/weibo_config.html");
	}
	public function onSaveconfig(){
			$id=post('id',"i");
			$data['nickname']=post('nickname',"h");
			$data['token_users']=post('token_users','h');
			$this->weibo_config->update($data,array("id"=>$id));
			$this->gourl();
	}
	
	public function  onUserlist(){
			$visible=get('visible','i');
			switch(get('order')){
				case "1":
						$order="statuses_count DESC";
					break;
				case "2":
						$order="followers_count DESC";
					break;
					
				default:
						$order="id DESC";
					break;
			}
			$limit=20;
			$page=max(1,get('page','i'));
			$start=($page-1)*$limit;
			$option=array(
				"where"=>$where,
				"start"=>$start,
				"limit"=>$limit,
				"order"=>$order,
			);
			$rscount=true;
			$list=$this->weibo_souser->select($option,$rscount); 
			$url="".APPADMIN."?m=admin_weibo&a=userlist&visible={$visible}&order=".get('order','i');
			$pagelist=$this->multipage($rscount,$limit,$page,$url);
			$this->smarty->assign("baseurl","".APPADMIN."?m=admin_weibo&a=userlist&visible={$visible}");
			$this->smarty->assign(
				array(
					"rscount"=>$rscount,
					"list"=>$list,
					"pagelist"=>$pagelist,
				)
			);
			$this->smarty->display("weibo/weibo_userlist.html");
	}
	public function onAdduser(){
			$uid=get('uid',"i");
			
			if($uid){
				$this->smarty->assign("data",$this->weibo_souser->getRow("SELECT * FROM ".table('weibo_souser')." where uid='$uid' "));
			}
			$this->smarty->display("weibo/weibo_adduser.html");
	}
	public function onSaveuser(){
			$user=array(	
						
						'screen_name'=>post('screen_name','h'),
						'location'=>post('location','h'),
						'description'=>post('description','h'),
						'avatar_large'=>post('avatar_large','h'),
						'friends_count'=>post('friends_count','h'),
						'domain'=>post('domain','h'),
						'followers_count'=>post('followers_count','h'),
						'statuses_count'=>post('statuses_count','h'),
						 
					);
				if(!$this->weibo_souser->getOne("SELECT uid FROM ".table('weibo_souser')." WHERE uid=".post('uid','i')." ")){
					$user['uid']=post('uid','i');	
					$this->weibo_souser->insert($user);
				}else{
					$this->weibo_souser->update($user,"  uid=".post('uid','i')." ");
				}
			 
				$this->gomsg("保存成功");
	}
	public function onDel(){
			$this->weibo_souser->query("DELETE FROM ".table('weibo_souser')." WHERE uid=".get('uid',"i")."  ");
	}
	public function onVisible(){
			$this->weibo_souser->query("UPDATE ".table('weibo_souser')." SET visible=".get('visible','i')." WHERE id=".get('id','i')." ");
	}
	 
}

?>