<?php
class CommonAction extends Action{
	function _initialize(){
		header("Content-Type:text/html; charset=utf-8");
		checkCatch();
		$this->open();
		$this->showLoginInfo();
		$this->defaultGroup();
		$this->assign('website',getDadengPath());
		$this->assign('webpath',getDadengPath(3));
    }
	//普通提示
	public function islogin()
	{
		if(!$this->isloginbool())
		{
			$this->error('您还没有登陆或者登陆已经超时，请重新登陆系统！');
			exit;
		}
	}
	public function isloginbool()
	{
		if(!Session::is_set(C('USER_AUTH_KEY')))
		{
			return FALSE;
		}	
		else
			return TRUE;
	}
	//用于ajax
	public function notlogin()
	{
		if(!$this->isloginbool())
		{
			echo "您还没有登陆系统";
			exit;
		}
	}
	protected function checkNotLoginCookie($userid,$pwd)
	{
		$user=M('user');
		$rs=$user->where("userid='".$userid."' and passwd='".$pwd."'")->find();
		if(!$rs)
		{
			echo "您未登陆系统";exit;
		}
	}
	protected function showLoginInfo()
	{
		$msg=$isadmin=$islogin="";
		if($this->isloginbool())
		{
			$user=M('user');
			$rs=$user->field('id,userid,roleid')->find(getUserID());
			$msg="<li><a href='".U('public/logout')."'>退出系统</a></li><li><a href='".U("user/index")."'>控制面板</a></li><li><a href='".getDadengPath().$rs['homepage']."'>个人首页</a></li>";
			$islogin=1;
			if($rs['roleid']==9)
				$isadmin=1;
			else
				$isadmin=0;
		}
		else
		{
			$islogin=0;
			$isadmin=0;
			$msg="<li><a href='".U('public/signup')."'>用户注册</a></li><li><a href='".U('public/login')."'>登陆系统</a></li>";
		}
		$this->assign('msg',$msg);
		$this->assign('isadmin',$isadmin);
		$this->assign('islogin',$islogin);
	}
	public function open()
	{
		$sconfig=F('site');
		if(!$sconfig['login_check'])
		{
			if(!$this->isloginbool())
			{
				$this->redirect('/public/login');
			}
		}
	}
	protected function showSiteInfo($title="",$key="",$des="",$copy="")
	{
		$site=F('site');
		$data['title']=$title?$title.'--'.$site['title']:$site['title'];
		$data['keyword']=$key?$key.'--'.$site['keyword']:$site['keyword'];
		$data['description']=$des?$des.'--'.$site['description']:$site['description'];
		$data['copyright']=$copy?$copy.'--'.$site['copyright']:$site['copyright'];
		$this->assign('site',array_merge($site,$data));
	}
	private function defaultGroup()
	{
		$tg=M('topic_group');
		$rs=$tg->field('id,`is_default`,groupname')->where('`is_default`=1')->find();
		$this->assign('dg',$rs);
	}
}
?>