<?php
if ( !defined( 'SMARTY_DIR' ) ) {
	include_once( 'init.php' );
}

if ( isset( $_GET['txtconfcode'] ) && $_GET['txtconfcode'] ) {
	$confcode = $_GET['txtconfcode'];
} else {
	$confcode = $_GET['confcode'];
}


$row =& $osDB->getRow( 'SELECT id, username, firstname, lastname, level FROM ! WHERE  actkey = ?', array( USER_TABLE, $confcode ) );

if ( $row['id'] > 0 ) {

	if ($config['default_active_status'] == 'Y') {

		$status = 'active';

	} else {

		$status = 'approval';

	}

	$osDB->query( 'UPDATE ! SET active=?, status = ?,  actkey=?,  lastvisit=?  WHERE id = ?', array( USER_TABLE, '1', $status, 'Confirmed',  time(), $row['id'] ) );

	$osDB->query( 'DELETE FROM ! WHERE userid = ?', array( ONLINE_USERS_TABLE, $row['id'] ) );

	$osDB->query( 'INSERT INTO ! ( userid, lastactivitytime , session_id ) VALUES ( ?, ?, ?)', array( ONLINE_USERS_TABLE, $row['id'], time(), session_id() ) );

	session_destroy();

	header('location: index.php?page=login&err='.MODIFY_COMPLETED);

} else {

	header( 'location: index.php?page=login&err='.INVALID_ACTIVATION_CODE );

}
exit;
?>