<?php

include('init.php');
include('libs/functions.php');

if (isset($_REQUEST['c'])) { 
$c = scrub_sql(scrub_white_list($_REQUEST['c'], 'ALPHANUMERICONLY'), 32);

$sql = "SELECT user_id FROM tb_email_confirmation WHERE confirmation='$c' AND confirmed=0";
$rs = $db->Execute($sql);
$record_count = $rs->RecordCount();
if ($record_count == 1) {
$user_id = $rs->fields('user_id');

$sql = "UPDATE tb_email_confirmation SET confirmed=1 WHERE user_id=$user_id";
$rs = $db->Execute($sql);

$sql = "UPDATE tb_user SET status=9 WHERE user_id=$user_id AND status=0";
$rs = $db->Execute($sql);


$sql = "INSERT INTO tb_audit (user_id, event, event_date) VALUES ($user_id, 'User confirmed email address', getdate())";
$rs = $db->Execute($sql);


$sql = "SELECT username, user_id, email FROM tb_user WHERE user_id='$user_id'";
$rs = $db->Execute($sql);
$user = $rs->fields('username');
$email = $rs->fields('email');



$message = ("

<HTML>
<BODY>


VRSS Admin,
<BR><BR>
The user $user ( $email ) has registered for the Veterans Re-Entry Search Service.
Please log-in to the VRSS Admin application to approve this user's account.
<BR><BR>
Very Best,
<BR>
VRSS Administrator
<BR><HR><BR>
</BODY></HTML>

");

$headers = "To: VRSS Admin <iit@vba.domain>\n" . "From: Veterans Re-Entry Search Service <noreply@domain>\n" . "MIME-Version: 1.0\n" . "Content-type: text/html; charset=iso-8859-1";


mail( "iit@vba.domain", "TEST: A New User has Registered for the Veterans Re-Entry Search Service!",
	$message, $headers );







print_header();

?>
<table width=800 align=center>
<tr><td>
<BR>
<HR>
<H1 align=center>Thank You!</H1>
<BR>
<HR>
<H3 align=center>Your email address has been confirmed. Your account must now be reviewed and approved by the VRSS Administrator. You will receive an email confirmation once your account has been approved.</H3>
<BR>
<HR>
</td></tr></table>

<?

print_footer();

}

else {
print_header();

?>

<table width=800 align=center>
<tr><td>
<BR>
<HR>
<H1 align=center>Error</H1>
<BR>
<HR>
<H3 align=center>Invalid confirmation code</H3>
<BR>
<HR>
</td></tr></table>

<?

print_footer();
}

}

else {
print_header();

?>

<table width=800 align=center>
<tr><td>
<BR>
<HR>
<H1 align=center>Error</H1>
<BR>
<HR>
<H3 align=center>Confirmation code required</H3>
<BR>
<HR>
</td></tr></table>

<?
print_footer();
}
?>