<?php

session_start();

if( isset($_SESSION['dy_nickname']) )
{
	define('CURSCRIPT', 'logging');

		require_once './include/common.inc.php';
		require_once DISCUZ_ROOT.'./include/misc.func.php';


		/*
		if($discuz_uid) 
		{
			showmessage('login_succeed', 'index.php');
		}*/

		$field = 'username';

		$query = $db->query("SELECT m.uid AS discuz_uid, m.username AS discuz_user, m.password AS discuz_pw, m.secques AS discuz_secques,
					m.adminid, m.groupid, m.styleid AS styleidmem, m.lastvisit, m.lastpost, u.allowinvisible
					FROM {$tablepre}members m LEFT JOIN {$tablepre}usergroups u USING (groupid)
					WHERE m.$field='" . $_SESSION['dy_nickname'] . "' LIMIT 1 ");

		$member = $db->fetch_array($query);

		extract($member);

		$discuz_userss = $discuz_user;
		$discuz_user = addslashes($discuz_user);

		if(($allowinvisible && $loginmode == 'invisible') || $loginmode == 'normal') 
		{
			$db->query("UPDATE {$tablepre}members SET invisible='".($loginmode == 'invisible' ? 1 : 0)."' WHERE uid='$member[discuz_uid]'", 'UNBUFFERED');
		}

		$styleid = intval(empty($_POST['styleid']) ? ($styleidmem ? $styleidmem :
				$_DCACHE['settings']['styleid']) : $_POST['styleid']);

		$cookietime = intval(isset($_POST['cookietime']) ? $_POST['cookietime'] :
				($_DCOOKIE['cookietime'] ? $_DCOOKIE['cookietime'] : 0));

		dsetcookie('cookietime', $cookietime, 31536000);
		dsetcookie('auth', authcode("$discuz_pw\t$discuz_secques\t$discuz_uid", 'ENCODE'), $cookietime);

		$sessionexists = 0;

		if($groupid == 8) 
		{
			showmessage('login_succeed_inactive_member', 'memcp.php');
		} 
		else 
		{
			if( isset( $_REQUEST['forward'] ) )
				header( "Location: " . basename( $_REQUEST['forward'] ) );
			else
				header( "Location: index.php" );
			exit;
			//showmessage('login_succeed', 'index.php');
		}

		showmessage('login_invalid', NULL, 'HALTED');


}

header( "Location: index.php" );


?>