<?php

// +----------------------------------------------------------------------+
// | OpenConf                                                             |
// +----------------------------------------------------------------------+
// | Copyright (c) 2002-2008 Zakon Group LLC.  All Rights Reserved.       |
// +----------------------------------------------------------------------+
// | This source file is subject to the OpenConf License, available on    |
// | the OpenConf web site: www.OpenConf.com                              |
// +----------------------------------------------------------------------+

require_once "../include.php";

printHeader("Email Username",3);

if (isset($_POST['submit']) && ($_POST['submit'] == "Email Username") && (!empty($_POST['email']))) { 
	// check for valid email
	if (!validEmail($_POST['email'])) {
		print '<center><span class="warn">Email address entered is invalid</span></center>';
		printFooter();
		exit;
	}
	$q = "SELECT reviewerid, username, email FROM " . OCC_TABLE_REVIEWER . " WHERE email='" . safeSQLstr(oc_strtolower($_POST['email'])) . "'";
	$r = ocsql_query($q) or err("Error checking email ".mysql_errno());
	if (($rnum=mysql_num_rows($r)) == 0) { print '<center><span class="warn">Invalid email.</span></center><p>'; }
	elseif ($rnum > 1) { err("multiple accounts with this email address"); }
	else {
		$e = mysql_fetch_array($r);
		$msg = '
Your username for accessing the ' . $OC_configAR['OC_confName'] . ' OpenConf system is:

	' . $e['username'] . '

';
		sendEmail($_POST['email'],"Username Recovery", $msg, $OC_configAR['OC_notifyReviewerEmailUsername']);
		print 'We have emailed your username.  Once you receive it, you may <a href="signin.php">sign in here</a>.<p>';
		printFooter();
		exit;
	}
}
else {
	print "<center><b>Please enter the email you registered with below</b></center><p>\n";
}

print '
<center>
<form method="post" action="' . $_SERVER['PHP_SELF'] . '">
<table border=0>
<tr><td><b>Email:</b></td><td><input size=20 name="email" value="' . varValue('email', $_POST) . '"></td></tr>
<tr><th align="center" colspan=2><br><input type="submit" name="submit" value="Email Username"></th></tr>
</table>
</form>
</center>
<p>
';

printFooter();

?>
