<?php
class IndexAction extends Action {
    public function index(){
		if($_SESSION['NR_USER_ID']){
			$this->success('登录成功!','/Main.html',0.1);
		}
		$forum = M("forum")->where("ishot != 2")->order("id desc")->limit("0,10")->select();
		$hotuser = M("user_date")->order("money desc")->limit(0,16)->select();
		$newuser = M("user")->order("id desc")->limit(0,16)->select();
		$this->assign("newuser",$newuser);
		$this->assign("hotuser",$hotuser);
		$this->assign("forum",$forum);
        $this->display();
    }
	function register(){
		$this->display();
	}
	function doregister(){
		$check = new UserModel();
		$check->register();
		$this->success('注册成功!','/U_data.html',3);
	}
	function Login(){
		$login = new UserModel();
		$login->login();
		$this->success('登录成功!','/Main.html',3);
		$this->display();
	}
	function forum(){
		if(!$_GET['id']){
			exit();
		}
		if($_POST['subreply']){
			$reply = new UserModel();
			$reply->reply();
			$this->success('回复成功!','/Forum_'.$_GET['id'].'.html',3);
		}
		M("forum")->where('id= '.$_GET['id'])->setInc('hot');
		$forum    = M("forum")->select($_GET['id']);
		$xunzhang = M("xunzhang")->where("uid = ".$forum[0]['pid'])->select();
		$cate=M('memu');
		$memu     = $cate->field("id,fid,title,path,concat(path,'-',id) as bpath")->order('bpath')->select();
		foreach($memu as $key=>$value){
			$memu[$key]['count']=count(explode('-',$value['bpath']));
		}
		$reply = M("reply")->where("fid = ".$_GET['id'])->select();
		$this->assign("reply",$reply);
		$this->assign("xunzhang",$xunzhang);
		$this->assign("memu",$memu);
		$this->assign("forum",$forum);
		$this->display();
	}
	function follower(){
		if(!$_GET['id']){
			exit();
		}
		$u 		= M("user_date")->where("uid = ".$_SESSION['NR_USER_ID'])->select();
		$fensi  = M("follower")->where("uid = ".$_GET['id'])->select();
		$cate=M('memu');
		$memu     = $cate->field("id,fid,title,path,concat(path,'-',id) as bpath")->order('bpath')->select();
		foreach($memu as $key=>$value){
			$memu[$key]['count']=count(explode('-',$value['bpath']));
		}
		$this->assign("memu",$memu);
		$this->assign("fensi",$fensi);
		$this->assign("u",$u);
		$this->display();
	}
	function Space(){
		if(!$_GET['id']){
			exit();
		}
		$uid    = $_GET['id'];
		$u 		= M("user_date")->where("uid = ".$uid)->select();
		$forum  = M("forum")->where("pid = ".$uid)->select();
		$cate=M('memu');
		$memu     = $cate->field("id,fid,title,path,concat(path,'-',id) as bpath")->order('bpath')->select();
		foreach($memu as $key=>$value){
			$memu[$key]['count']=count(explode('-',$value['bpath']));
		}
		$this->assign("memu",$memu);
		$this->assign("u",$u);
		$this->assign("forum",$forum);
		$this->display();
	}
	function following(){
		if(!$_GET['id']){
			exit();
		}
		$u 		= M("user_date")->where("uid = ".$_SESSION['NR_USER_ID'])->select();
		$gz		= M("follower")->where("fid = ".$_GET['id'])->select();
		$cate=M('memu');
		$memu     = $cate->field("id,fid,title,path,concat(path,'-',id) as bpath")->order('bpath')->select();
		foreach($memu as $key=>$value){
			$memu[$key]['count']=count(explode('-',$value['bpath']));
		}
		$this->assign("memu",$memu);
		$this->assign("gz",$gz);
		$this->assign("u",$u);
		$this->display();
	}
}
?>