<?php

include 'load.php';

if(isset($_GET['emid']) && !empty($_GET['emid']))

{

		$id = $_GET['emid'];

		$stmt_edit = $DB_con->prepare('SELECT * FROM mobileemployee WHERE emid =:emid');

		$stmt_edit->execute(array(':emid'=>$id));

		$edit_row = $stmt_edit->fetch(PDO::FETCH_ASSOC);

		extract($edit_row);

}

else

{

echo "<script type='text/javascript'>window.location.href = 'employeelist.php';</script>";

}

if(isset($_POST['employee_change_password']))

	{
		
		$user_pass = $_POST['user_pass'];

        $user_pass = password_hash($user_pass, PASSWORD_DEFAULT);
		
		$reuser_pass = $_POST['reuser_pass'];

        $reuser_pass = password_hash($reuser_pass, PASSWORD_DEFAULT);
		
		if($_POST['user_pass']==$_POST['reuser_pass']){
			
			if(!isset($errMSG))

			{

			$stmt = $DB_con->prepare('UPDATE mobileemployee

									     SET user_pass=:user_pass											

								       WHERE emid=:emid');
									   
			$stmt->bindParam(':user_pass',$user_pass);

			$stmt->bindParam(':emid',$id);

			if($stmt->execute()){

				$successMSG = "Employee Account Password Successfully Updated ...";

				header("refresh:2;employeelist.php"); // redirects image view page after 5 seconds.

			}else{

				$errMSG = "Sorry Data Could Not Updated !";
				
			}

		}

		}else{

		$errMSG = "Sorry Password Could Not Matched !";
		
		}
				

	}

?>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0">
<meta name="description" content="POS - Payroll | Pos & Invetory System | Dashboard

">
<meta name="keywords" content="Payroll | Pos & Invetory System | Dashboard

">
<meta name="author" content="Payroll | Pos & Invetory System | Dashboard

">
<meta name="robots" content="noindex, nofollow">

<title>Change Employee Password  | Payroll | Pos & Invetory System | Dashboard

</title>


<?php
require_once 'headercss.php';
?>
</head>
<body>
<div id="global-loader">
<div class="whirly-loader"> </div>
</div>

<div class="main-wrapper">
<?php
require_once 'header.php';
?>

<?php
require_once 'navbar.php';
?>

<div class="page-wrapper">
<div class="content">
<div class="page-header">
<div class="page-title">
<h4>Employee Password Change</h4>
<h6>Change Employee Password</h6>
</div>
</div>

<div class="card">
<div class="card-body">
 <form method="POST" enctype="multipart/form-data">
<div class="row">
<?php

									if(isset($errMSG)){

									?>
									
									<div class="alert alert-danger border-0 bg-danger alert-dismissible fade show py-2">
									<div class="d-flex align-items-center">
										<div class="font-35 text-white"><i class="bx bxs-message-square-x"></i>
										</div>
										<div class="ms-3">
											<h6 class="mb-0 text-white">Error Alerts</h6>
											<div class="text-white"> <?php echo $errMSG; ?>!</div>
										</div>
									</div>
									<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
									</div>
									
									<?php

									}
	
									else if(isset($successMSG)){

									?>
									
									<div class="alert alert-success border-0 bg-success alert-dismissible fade show py-2">
									<div class="d-flex align-items-center">
										<div class="font-35 text-white"><i class="bx bxs-check-circle"></i>
										</div>
										<div class="ms-3">
											<h6 class="mb-0 text-white">Success Alerts</h6>
											<div class="text-white"><?php echo $successMSG; ?>!</div>
										</div>
									</div>
									<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
									</div>
									
									<?php

									}

									?>	
<div class="col-lg-4 col-sm-6 col-12">
<div class="form-group">
<label>New Password</label>
<input class="form-control" type="password" placeholder="Enter New Password" name="user_pass" required>	
</div>
</div>
<div class="col-lg-4 col-sm-6 col-12">
<div class="form-group">
<label>Confirm Password</label>
<input class="form-control" type="password" placeholder="Confirm Password" name="reuser_pass" required>	
</div>
</div>
<div class="col-lg-12">
<a href="employeelist.php" class="btn btn-cancel">Cancel</a>
<input type="submit" name="employee_change_password" class="btn btn-submit me-2" value="Change Password">
</div>
</div>
</form>
</div>
</div>

</div>
</div>
</div>

<script src="assets/js/jquery-3.6.0.min.js"></script>

<script src="assets/js/feather.min.js"></script>

<script src="assets/js/jquery.slimscroll.min.js"></script>

<script src="assets/js/jquery.dataTables.min.js"></script>
<script src="assets/js/dataTables.bootstrap4.min.js"></script>

<script src="assets/js/bootstrap.bundle.min.js"></script>

<script src="assets/plugins/select2/js/select2.min.js"></script>

<script src="assets/plugins/sweetalert/sweetalert2.all.min.js"></script>
<script src="assets/plugins/sweetalert/sweetalerts.min.js"></script>

<script src="assets/js/script.js"></script>

</body>
</html>