<?php

/******************************************************************************
 *
 *	PROJECT: Flynax Classifieds Software
 *	VERSION: 4.0
 *	LISENSE: http://www.flynax.com/license-agreement.html
 *	PRODUCT: General Classifieds
 *	
 *	FILE: CONFIRM.INC.PHP
 *
 *	This script is a commercial software and any kind of using it must be 
 *	coordinate with Flynax Owners Team and be agree to Flynax License Agreement
 *
 *	This block may not be removed from this file or any other files with out 
 *	permission of Flynax respective owners.
 *
 *	Copyrights Flynax Classifieds Software | 2012
 *	http://www.flynax.com/
 *
 ******************************************************************************/

/* get account key from GET */ 
$key = $rlValid -> xSql( $_GET['key'] );

/* get account with requested key */
$account = $rlDb -> fetch( array('ID', 'Status', 'Username', 'Password', 'Password_tmp', 'First_name', 'Last_name'), array( 'Confirm_code' => $key ), null, null, 'accounts', 'row' );

if ( empty($account) || empty($key) )
{
	$sError = true;
}
else
{
	$login_link = $config['mod_rewrite'] ? SEO_BASE . $pages['login'] .'.html' : RL_URL_HOME . '?page='. $pages['login'];

	if ( $account['Status'] == 'incomplete' )
	{
		$reefless -> loadClass('Account');
		$reefless -> loadClass('Mail');
		
		$rlAccount -> confirmAccount( $account['ID'], $account );
		
		if ( $config['account_auto_login'] && !$config['account_admin_confirmation'] )
		{
			$rlAccount -> login( $account['Username'], $account['Password_tmp'] );
			
			$reefless -> loadClass('Notice');
			$rlNotice -> saveNotice($lang['account_confirmed_auto_login']);
			
			$url = SEO_BASE;
			$url .= $config['mod_rewrite'] ? $pages['login'].'.html' : '?page=' .$pages['login'];
			$reefless -> redirect( null, $url );
		}
		
		if ( $config['account_admin_confirmation'] && $account['Status'] != 'active' )
		{
			$message = $lang['account_confirmed_pending'];
		}
		else
		{
			$message = str_replace( array( '{link}' ), array( "<a href=\"{$login_link}\">{$lang['here']}</a>" ), $lang['account_confirmed'] );
		}
	}
	else
	{
		if ( $config['account_admin_confirmation'] )
		{
			$message = $lang['account_already_confirmed_pending'];
		}
		else
		{
			$message = str_replace( array( '{link}' ), array( "<a href=\"{$login_link}\">{$lang['here']}</a>" ), $lang['account_already_confirmed'] );
		}
	}
	
	$rlSmarty -> assign_by_ref( 'message', $message );
}