<?PHP
$table = "$prefix" . "USERS";

$SQL = "SELECT * from $table WHERE MATCH (USERNAME, EMAIL) AGAINST ('$_POST[search]' IN BOOLEAN MODE)";
$result = mysql_query( $SQL );
$row = mysql_fetch_array( $result );

if (!empty($row[USERNAME])) {
        $body = "This is a lost password recovery system for $row[FIRSTNAME] $row[LASTNAME].
        <br><br>Your username is: $row[USERNAME]
        <br>Your password is: $row[PASSWORD]
        <br><br>
        <a href=\"http://$_SERVER[HTTP_HOST]$_SERVER[SCRIPT_NAME]?page=login&qun=$row[USERNAME]&qpw=$row[PASSWORD]\">Click here to log in automatically</a>.
        <hr>
        Thank you<br>
        - $rowxxx[TITLE]";
        $error = "Password sent to: $row[EMAIL]";
        
        sendmail("$row[EMAIL]", "$rowxxx[ADMINEMAIL]","Lost password recovery for $rowxxx[TITLE]", "$body");
}

if (empty($row[USERNAME])) {
        $error = "Sorry! We could not find that username or email address in our records.";
}

?>

<?PHP $link = h1; $desc = "Edit main heading style."; include "dmtop.php"; ?>
<h1><?PHP /* (LANGUAGE) */ $t = "Lost Password Recovery"; $f = "lostpwheader"; $altpage = homefront; include "langinc.php"; /* (LANGUAGE) */ ?></h1>
<?php include "dmbot.php"; ?>

<?PHP $link = formbox; $desc = "Edit form style."; include "dmtop.php"; ?>
<?php include "dmbot.php"; ?>

<?PHP $link = h3; $desc = "Edit field box heading (h3) style."; include "dmtop.php"; ?>
<?php include "dmbot.php"; ?>

<?PHP $link = fieldbox; $desc = "Edit form field box style."; include "dmtop.php"; ?>
<?php include "dmbot.php"; ?>

<form class="formbox" style="width: 100%;" name="form" method="post" action="index.php?page=lostpassword">

<h3><?PHP /* (LANGUAGE) */ $t = "Username or Email Address"; $f = "lostpwusername"; $altpage = homefront; include "langinc.php"; /* (LANGUAGE) */ ?></h3>

<input type="text" name="search" class="fieldbox" style="width: 50%;">

<br>

<input style="margin-top: 15px;" class="sparklybutton" type="submit" value="<?PHP /* (LANGUAGE) */ $t = "Resend Recovery"; $f = "lostpwsubmit"; $altpage = homefront; include "langinc.php"; /* (LANGUAGE) */ ?>" name="Submit" />

<?PHP
if (!empty($_POST[search])) {
?>

<?PHP $t = "$error"; include "langinc.php"; ?>

<?PHP } ?>

</form>
