<?php 
$pageName = 'Forget Password';

require_once('config/config.php');
require_once(CLASS_DIR.'dbClass.php');
require_once(INCLUDES_DIR.'header.php');

include('hitCounter.php');

$obj = new DBClass();
$obj1 = new DBClass();


if(isset($_POST['submit']) && $_POST['submit'] == 'Submit'){
	$valid = checkEmail($_POST['email'], "Email"); if(isset($valid) && $valid != ''){ $error[] = $valid;}
	$sql2 = "SELECT * FROM ".TBL_USER." WHERE email = '".$_POST['email']."'";
	$rs2 = $obj1->executeQry($sql2,$link);
	$rownum2 = $obj1->getRow();
	$row2 = $obj1->fetchRow();	 
	if($rownum2 < 1){
        	$error[] = "No account found with this email.";
	}
	else
	{
		// *********************** start  mail to admin *****************
		$to        	= 	$row2['email'];
		$subject	=	"Coalbazaar.com password request";
		$message	= 	"Dear ".$row2['fname']."  <br>".
		"Following is the passowrd for you account with coalbazaar.com<br>".
		"password - ".$row2['password']."<br>".
		"Regards<br>".
		"Administrator<br>".
		"coalbazaar.com<br>";
		
						
		// To send HTML mail, the Content-type header must be set
		$headers  = 'MIME-Version: 1.0' . "\r\n";
		$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
		
		// Additional headers
		//$headers .= 'To: ' "\r\n";
		$headers .= 'From: <info@coalbazaar.com>' . "\r\n";
		
		@$sended=mail($to, $subject, $message, $headers);	
		
		if($sended!='')	
		{
			@header('Location: fpass.php?action=done');		
		}
	}
}

?>


<div class="workarea">
	<div class="workareatop">
		<img src="images/workareatopcorner_03.PNG" alt="" />
	</div>
    <!--workareamid start--------------------->
	<div class="workareamid">
		<div id="floatleft" style="width:590px; float:left;">
			<div class="welcomediv">
            
				<h2>Forgot Password</h2>

				<?php ShowError($error); ShowInfo($info);?>
				
				<?php if(isset($_GET['action']) && $_GET['action'] == 'done') { ?>
					<div>Your password has been mailed to your registered email id.</div>
				<?php } else { ?>
				<table>
						<tr>
								<td colspan="2" class="heading">Please enter your registered email, your password will be mailed to you.</td>
						</tr>
						 <tr>
								<td>&nbsp;</td>
					 	</tr>
				</table>  
				<form method="post" action="">
				<table>
						<tr>
								<td width="100" align="left">Email<span class="style1">*</span></td>
								<td width="180" align="left"><input type="text" name="email" id="email" class="txt_box2" value="<?php echo $_POST['email']; ?>" /></td>
						</tr>
						<tr align="left">
								<td><input type="submit" class="login_btn" name="submit" id="submit" value="Submit" style="width: 75px;height: 27px;" /></td>
								<td align="left">&nbsp;</td>
						</tr>
				</form>	
				</table>

				<?php } ?>
				
				
				
				
						</div>
				</div>
				<?php require_once(INCLUDES_DIR.'left_bar.php');?>
                <!--floatright close-------------------->
                <div style="clear:both;"></div>
            </div>
            <!--workareamid close--------------------->
            <div class="workareabottom">
                <img src="images/workareabottomcorner_03.PNG" alt="" />
            </div>
        </div>
    <!--workarea close------------------------->
<?php require_once(INCLUDES_DIR.'footer.php');?>