<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
// +----------------------------------------------------------------------+
// | PHP version 4/5                                                      |
// +----------------------------------------------------------------------+
// | This source file is a part of iScripts Multicart                     |
// +----------------------------------------------------------------------+
// | Authors: Programmer<programmer@armia.com>        		              |
// +----------------------------------------------------------------------+
// | Copyrights Armia Systems, Inc and iScripts.com � 2005                |
// | All rights reserved                                                  |
// +----------------------------------------------------------------------+
// | This script may not be distributed, sold, given away for free to     |
// | third party, or used as a part of any internet services such as      |
// | webdesign etc.                                                       |
// +----------------------------------------------------------------------+
?>
<?php
include "includes/config.php";
include "includes/session.php";
include "includes/functions.php";

if (get_magic_quotes_gpc()) {
    $_POST = array_map('stripslashes_deep', $_POST);
    $_GET = array_map('stripslashes_deep', $_GET);
    $_COOKIE = array_map('stripslashes_deep', $_COOKIE);
}



$txtEmail = $_POST["txtEmail"];

if (isset($_POST["btnResetPassword"])) {

    $message = "" ;

	if (!isNotNull($txtEmail)) {
        $message .= REGISTRATION_REQUIRED_MSG." <br>";
    }else{
		if (!isValidEmail($txtEmail)) {
	        $message .= NOT_EMAIL_REGISTERED_MSG." <br>";
	    }else{
			$sql = "SELECT first_name,last_name,user_name, user_id FROM ".$tableprefix."users WHERE email = '".addslashes($txtEmail)."' ";
			$res = mysql_query($sql);
			if(mysql_num_rows($res)!=0){
				$row = mysql_fetch_array($res);
				$firstname = $row["first_name"];
				$lastname = $row["last_name"];
				$username = $row["user_name"];
				$userid = $row["user_id"];

				$randnum1 = mt_rand();
				if(strlen($randnum1) > 6){
					$randnum1 = substr($randnum1,0,6);
				}
				$newpass = $randnum1;
				$pass = md5($newpass);
				$sqlreset = "UPDATE ".$tableprefix."users SET password = '$pass' WHERE user_id = '".addslashes($userid)."' ";

				$userfullname = $firstname;
				if($lastname != ""){
					$userfullname .= " ". $lastname;
				}
				$to = $txtEmail;
				$subject = "Your password with ".htmlentities(stripslashes(SITE_NAME)) . " reset on request!";
				
/*----------Multicart 2.0 Upgradation---------------*/				
				
				$mailmessage = readEmailTemplate('user_forgotpassword');
				
				$mailmessage = str_replace('[name]',$userfullname,$mailmessage);
				$mailmessage = str_replace('[user_name]',$username,$mailmessage);
				$mailmessage = str_replace('[password]',$newpass,$mailmessage);
				
				$mailmessage = nl2br($mailmessage);
				
				$mail_send_details = "<html><head><link href='".SITE_URL."/style/template1-admin.css' rel='stylesheet' type='text/css'></head><body><center><div align='left' id='layout'><div align='left' class='header'><div align='left' class='logo'><img src=".$logofolder."/".$logoimage." width='125' height='39'/></div></div><div>".$mailmessage."</div></div><div align='left' class='clear_float'><img src=".$imagefolder."/clear.gif width=1 height=1/></div></div></div></center></body></html>";
							
				$headers  = "MIME-Version: 1.0" . "\r\n";
				$headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";
				$headers .= "From: ".SITE_EMAIL."<".SITE_EMAIL.">" . "\r\n";
				$mailsent = @mail($to, $subject, $mail_send_details, $headers);
				
/*----------Multicart 2.0 Upgradation---------------*/												
				
				$successmessage="";
				if($mailsent){
					mysql_query($sqlreset);
					$successmessage .= PASSWORD_SEND_TO_MSG;
				}else{
					$message .= RETRY_MSG." <br>";
				}

			}else{
				$message .= EMAIL_NOT_REGISTERED_TEXT." <br>";
			}
		}

	}




    if ($message != "") { // error
        $message = "<br>".CORRECT_ERRORS_TEXT."<br>" . $message;
    }
    if($successmessage !="")
    $message=$successmessage;
}

/*display the active template*/

$active_template = displayTemplate();


include "includes/htmltop.php";

/* Top File Name */

include_once ("includes/".$active_template[0]);
?>


<div align="left" class="main_body">
<div class="reg_wrapper">
		<div class="reg_wrapper_header">
		<h2><?php echo FORGOT_PASSWORD_TEXT;?></h2>
		</div>
			<!--mainbody area start -->
	
		<form name="frmForgotPassword" action="<?php echo $_SERVER["PHP_SELF"]?>" method="POST">
		<input type="hidden" name="userid" value="<?php echo $userid;?>">
		<div class="text_information" align="center"><?php echo $message?></div>
		
		<div class="register_leftcolumn" style="background-image:none; width:750px;">
			<div class="field_wrapper_required" style="ma ">
			<input type="text" class="text_field" value="" name="txtEmail" size="55" maxlength="30" >
			<label><?php echo REGISTRATION_EMAIL_TEXT?></label>
			<input type="submit" value="<?php echo RESET_PASSWORD_BUTTON;?>" name="btnResetPassword" class="button" style=" margin:0px 37px 0 10px; ">
			</div>
		</div>
		
		
			</form>
		<!--center content area end-->	
		<div class="clear"></div>
		</div>
		<div align="left" class="clear"></div>		
		<!--mainbody area end -->
        </div>
		<div align="left" class="clear"></div>




				

<?php
include "includes/".$active_template[2];	/* Bottom File Name */
?>																																													