Location: PHPKode > projects > WH Community > wh_community/forgotten.php
<?php require('layout/header.php'); ?>

    <script type="text/javascript">
    	function showSuccessMessage() {
    	showNotification({
    	type : "success",
    	message: "<?php echo $lang['success_send_pass']; ?>"
    	});    
        }                                
    
    function showErrorMessage() {
    	showNotification({
    	type : "error",
    	message: "<?php echo $lang['couldnot_send_pass']; ?>"
    	});    
        }                                
    </script>

<div id="content_wrapper">
    <div class="content"><?php

		echo '<h1>' . $lang['request_new_pass'] . '</h1><br>';
		
		if($_SERVER['REQUEST_METHOD'] != 'POST') {
		
		echo '<form name="password" action="" method="post">
    		  <input type="text" name="user_name" size="30" class="fields"> <input type="submit" name="newpass" value="' . $lang['request_password'] . ' " alt="' . $lang['request_password'] . '" class="button"><br>
    		  <small>' . $lang['enter_username'] . '</small>
    		  <br><br><br>
    		  </form>';
		
    		}else{
    		
    		$errors = array();
    		
    		if(isset($_POST['user_name'])) {
    		if(!ctype_alnum($_POST['user_name'])) {
    		$errors[] = '<p>' . $lang['invalid_name'] . '.</p>';
    		}
    		
    		if(strlen($_POST['user_name']) == "") {
    		$errors[] = '<p>' . $lang['enter_username'] . '.</p>';
    		}
		
    			}else{
    			$errors[] = '<p>' . $lang['enter_username'] . '.</p>';
    			}
		
		if(!empty($errors)) {
		
		echo '<p class="false"><u>' . $lang['not_filled_all'] . '</u></p>
		      <p>[ <a href="javascript:history.back();">' . $lang['back'] . '</a> ]</p><br>';
		echo '<ul>';
		
		foreach($errors as $key => $value) {
		echo '<li>' . $value . '</li>';
		}
		echo '</ul>';
		
			}else{
		
			$sql = "SELECT
						user_email
					FROM
						users
					WHERE
						user_name = '" . mysql_real_escape_string(trim($_POST['user_name'])) . "'";
		
			$result = mysql_query($sql) OR die(mysql_error());
			$row = mysql_fetch_assoc($result);
		
		if(!$row)
		$errors[] = '' . $lang['not_found_user'] . '.<br>';
		}
		
		if(count($errors)) {
		
		echo '<br><p class="mod"><em>' . $lang['not_sendet_pass'] . '.</em></p>
		      <br>[ <a href="forgotten.php">' . $lang['request_another_pass'] . '</a> ]<br><br>';
		
			}else{
		
			$passwort = substr(sha1(microtime()),0,8);
			$sql = "UPDATE
						users
					SET
						user_pass = '" . sha1(trim($passwort)) . "'
					WHERE
						user_name = '" . mysql_real_escape_string(trim($_POST['user_name'])) . "'";
		
			mysql_query($sql) OR die(mysql_error());
		
		
			$empfaenger = $row['user_email'];
			$titel = '' . $lang['pass_title_mail'] . '';
			$mailbody = '' . $lang['your_new_pass'] . ': ' . $passwort. ' - ' . $lang['old_pass_deleted'] . '!';
			$header = 'From: ' . $webmaster . '';
			
			if(@mail($empfaenger, $titel, $mailbody, $header)) {
			
			echo '<p class="right">' . $lang['success_send_pass'] . '</p>
			      <p>[ <a href="signin.php">' . $lang['signin_to'] . '</a> ]</p>';
			echo "<script type=\"text/javascript\">showSuccessMessage();</script>";
		
		}else{
		
		echo '<p class="false"><u>' . $lang['couldnot_send_pass'] . '</u></p>
		      <p>' . $lang['contact_our_support'] . ' [ <a href="mailto:' . $webmaster . '">Support</a> ]</p>';
		echo "<script type=\"text/javascript\">showErrorMessage();</script>";
		
        }}}
		
		echo '<div class="spacer_div">&nbsp;</div>';

		?>
    </div>
</div>

<div id="infobox_wrapper">
    <div class="infobox">
        <?php include('layout/infobox.php'); ?>
    </div>
</div>

<?php require('layout/footer.php'); ?>
Return current item: WH Community