<?php
	!defined('DIRCMS_MANAGE') && exit('Access Denied!');
	$action=empty($action)?'login':trim($action);
	include(DIRCMS_ROOT.'include/member.class.php');
	$member=new member();
	include(DIRCMS_ROOT.'include/admin/admin.class.php');
	$a=new admin();
	switch($action)
	{
		case 'login':
			if($do_submit)
			{
				if($_SESSION['checkcode']!=trim($_POST['checkcode']))
				{
					showmsg('验证码不正确!',ADMIN_FILE.'?file=login');
				}
				$r=$member->login($username,$password);
				if(!$r)
				{
					showmsg($member->msg,ADMIN_FILE.'?file=login');
				}
				if($r['groupid']>1)
				{
					$member->logout();
					showmsg('您不是管理员，不能登录网站后台！',$DIRCMS['site_url']);
				}
				$_userid=$r['id'];
				$admin=$a->get($_userid);
				if($admin['disabled'])
				{
					$member->logout();
					showmsg('您的管理账号已被禁用！',ADMIN_FILE.'?file=login');
				}
				if(!$admin['allowmultilogin']&&$a->is_multilogin($_userid))
				{
					$member->logout();
					showmsg('您的帐号已经在别的IP下登录了！',ADMIN_FILE.'?file=login');
				}
				$_SESSION['is_admin']=true;
				showmsg('登陆后台成功！',ADMIN_FILE);
			}
			if($_userid && $_SESSION['is_admin']===true)showmsg('您已经登陆了！',ADMIN_FILE); // 如果已经登录则直接跳转到后台
			include admin_tlp('login');
			break;
		case 'logout':
			
			$member->logout();
			showmsg('退出成功！',$DIRCMS['site_url']);
			break;
	}
?>