<?php
/*
script: includes/login.inc.php
purpose: included by the includes/config.inc.php script, this script processes login / logout attempts
				and initializes the $user variable if the user is logged in.
copyright: copyright 2004 Php Image Host. All Rights Reserved. You may modify this file for use on your
					site running a licenced copy of the Php Image Host scripts.
					You must not distribute this file or derivations of it.
Nullified By CrAcKlOvE

*/
$userid = 0;
$user = 0;
$loggedin = false;
$suspended = false;
$unconfirmed = false;
$loginerror = '';
$banned = false;

if( $ace->config->ban_ips && $ace->ipbanned() ){
	$banned = true;
}else{

	if( $ace->getstr('login', $_POST) != '' ){
		$uname = $ace->getstr('username', $_POST);
		$upass = $ace->getstr('password', $_POST);
		$user = $users->getuser(array('username'=>$uname, 'password'=>$upass));
		if( $user != 0 ){
			if( $user->status == 1 ){
				$_SESSION['user_loggedin'] = true;
				$_SESSION['user_userid'] = $user->user_id;
				$loggedin = true;
				$ip = isset($_SERVER['X_FORWARDED_FOR']) ? $_SERVER['X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'];
				$ups = array('lastlogin'=>date('Y-m-d H:i:s'), 'loginip'=>$ip);
				if( $user->account_type == 'paid' && $user->paid_until < date('Y-m-d') ){
					$ups['account_type'] = 'free';
				}
				$users->updateusers(array($user->user_id),$ups);
			}elseif( $user->status == 0 ){
				$unconfirmed = true;
			}else{
				$suspended = true;
			}
		}else{
			$loginerror = 'Invalid username / password.';
		}
	}elseif( $ace->getint('logout', $_REQUEST) != 0 ){
		unset($_SESSION['user_loggedin']);
		unset($_SESSION['user_userid']);
	}

}

if( !$banned && !$loggedin && isset($_SESSION['user_loggedin']) ){
	$userid = (int)$_SESSION['user_userid'];
	$user = $users->getuser(array('id'=>$userid));
	if( $user != 0 ){
		switch( $user->status ){
			case 1: $loggedin = true; break;
			case 0: $unconfirmed = true; $user = $userid = 0; break;
			case 2: $suspended = true; $user = $userid = 0; break;
		}
	}else{
		$userid = 0;
		unset($_SESSION['user_loggedin']);
		unset($_SESSION['user_userid']);
	}
}

?>
