<?php 
$active = 'My Shop';
$pageName = 'Change Password';

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

include('hitCounter.php');
include('checklogin.php');

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

$sql = "SELECT * FROM ".TBL_USER." WHERE (id = '".$_COOKIE['memberID']."' OR id = '".$_SESSION['memberID']."')";
$rs = $obj->executeQry($sql,$link);
$row = $obj->fetchrow();	 

if(isset($_POST['submit']) && $_POST['submit'] == 'Change'){
	
	if($row['password'] != $_POST['opassword']){
				$error[] = "Please enter correct old password..";
	} 
	else {

		$valid = validmess($_POST['password'], "Password"); if(isset($valid) && $valid != ''){ $error[] = $valid;}        
		$valid = validmess($_POST['cpassword'], "Confirm Password"); if(isset($valid) && $valid != ''){ $error[] = $valid;}
		if($_POST['password'] != $_POST['cpassword']){ $error[] = 'Password and confirm password should be same...!';}
		
		if($error == ''){
			$sql2 = "UPDATE ".TBL_USER." SET password = '".trim($_POST['password'])."' WHERE (id = '".$_COOKIE['memberID']."' OR id = '".$_SESSION['memberID']."')"; 
			$rs2 = $obj->executeQry($sql2,$link);
			if($rs2){
				// *********************** start  mail from admin to user *****************
                $to        	= 	$row['email'];
        		$subject	=	"Coalbazaar.com password changed conformation";
        		$message	= 	"Dear ".$row['fname']."  <br>".
        		"Your password has been changed.<br>".
        		"<br>".
                "Your new password is : ".$_POST['password'].".<br><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: change_password.php?action=done');	
					exit;
				}
			}
		}		
	}
}	 
?>


<!--workarea start------------------------->
<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>Change Password</h2>
			
		<?php ShowError($error); ShowInfo($info);?>

		<?php if(isset($_GET['action']) && $_GET['action'] == 'done') { ?>
				<div>Password has been changed</div>
		<?php } else { ?>
			<form action="" method="post">
				<table>
					<tr>
						<td colspan="2" class="heading">Only password can be edited</td>
					</tr>
					<tr>
						<td colspan="2" height="10"></td>
					</tr>
				
					<tr>
						<td>User name</td>
						<td class="form_field"><input readonly="readonly" type="text" name="email" id="email" class="txt_box2" value="<?php echo $row['email']; ?>" /></td>
					</tr>
					<tr>
						<td colspan="2"></td>
					</tr>
					<tr>
						<td>Old Password<span class="style1">*</span></td>
						<td class="form_field"><input type="password" name="opassword" id="opassword" class="txt_box2"/></td>
					</tr>
					<tr>
						<td>Password<span class="style1">*</span></td>
						<td class="form_field"><input type="password" name="password" id="password" class="txt_box2"/></td>
					</tr>
					<tr>
						<td colspan="2"></td>
					</tr>
					<tr>
						<td>Confirm Password<span class="style1">*</span></td>
						<td align="left" class="form_field"><input type="password" name="cpassword" id="cpassword" class="txt_box2"/></td>
					</tr>
					<tr>
						<td colspan="2" height="10"></td>
					</tr>
					<tr>
						<td align="left" colspan="2"><input type="submit" class="login_btn" name="submit" id="submit" value="Change" style="margin-left:10px;" /></td>
					</tr>
				</table>
			</form>
		<?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');?>