<?php
/*
script: remind.php
purpose: email a password reminder to a member who has forgotten their login details.
copyright: copyright 2004 Php Image Host. All Rights Reserved. You may modify this file for use on your
					site running a licenced copy of the Php Image Host scripts.
					You must not distribute this file or derivations of it.
Nullified By CrAcKlOvE


*/

// include configuration & initialization settings

require_once(dirname(__FILE__).'/includes/config.inc.php');

$remindererror = '';

// include the site header

require_once(dirname(__FILE__).'/header.php');

if( $loggedin ){

	// if already logged in, just display standard "your account" page.

	require(dirname(__FILE__).'/includes/loggedin.inc.php');
}

if( $banned ){

	$pagecontent->display('IP Banned');

}else{

	// init variables

	$username = $ace->getstr('username', $_REQUEST);
	$email = $ace->getstr('email', $_REQUEST);
	$reminded = false;

	if( $email != '' ) $username = '';

	// process the reminder form submission

	if( $ace->getstr('remind', $_POST) != '' ){
		$criteria = array();
		if( $username != '' ){
			$criteria['username'] = $username;
		}else{
			$criteria['email'] = $email;
		}
		$user = $users->getuser($criteria);
		if( $user != 0 ){
			$reminded = true;
			$from = $config->reminder_email_from;
			$subject = $config->reminder_email_subject;
			$message = $config->reminder_email_template;
			if( $config->email_confirmation == 0 || $user->status == 1){
				$message = preg_replace('/<confirm>.*?<\/confirm>/is', '', $message);
			}else{
				$message = preg_replace('/<[\/]{0,1}confirm>/is', '', $message);
			}
			$cid = substr(md5($user->email.$user->username.$config->email_confirmation_key),0,12);
			$message = str_replace(array('{confirmid}', '{name}', '{username}', '{password}', '{sitename}',
																			'{siteurl}'),
																array($cid, $user->name, $user->username, $user->pass, $config->sitename, $config->siteurl),
																$message);
			$headers = "From: $from\r\nReply-To: $from\r\nReturn-Path: $from\r\nErrors-To: $from";
			@mail($user->email, $subject, $message, $headers);
		}else{
			$remindererror = 'The email address or username "'.addslashes($email == '' ? $username : $email).'" is not in our database.';
		}
	}

	if( $reminded ){

		// reminder has been sent - display relevant message.

		$pagecontent->display('Reminder Sent');

	}else{

		// display instructions and reminder form.

		$pagecontent->display('Remind');

		if( $remindererror != '' ){
?>
<div class="errors"><?php echo $remindererror;?></div>
<?php

		}

?>
<form name="reminderform" action="<?php echo $_SERVER['SCRIPT_NAME'];?>" method="post">
<div class="memberform">
<table align="center" class="membertable" cellspacing="1" cellpadding="0" border="0">
<tr>
	<td colspan="2" class="memberheading">Request Password Reminder</td>
</tr>
<tr>
	<td class="memberlabel"><b>Either</b> Username:</td>
	<td class="memberfield"><input class="memberinput" type="text" name="username" value="<?php echo htmlspecialchars($username);?>" />
		<br />Enter the username you chose when you signed up.
	</td>
</tr>
<tr>
	<td class="memberlabel"><b>Or</b> Email:</td>
	<td class="memberfield"><input class="memberinput" type="text" name="email" value="<?php echo htmlspecialchars($email);?>" />
		<br />Enter the email address you entered when you signed up.
	</td>
</tr>
<tr>
	<td class="memberlabel">&nbsp;</td>
	<td class="memberfield"><input class="memberinput" type="submit" name="remind" value="Send Password Reminder" /></td>
</tr>
</table>
</div>
</form>
<script language="JavaScript" type="text/javascript">
<!--
document.forms.reminderform['username'].focus();
//-->
</script>

<?php

	}

}

// include the site footer.

require_once(dirname(__FILE__).'/footer.php');

?>
