<?php
session_start();
include('../../Server/connection.php');
include('../includes/session.php');
$CurrentPassword = MD5(addslashes($_POST['CurrentPassword']));
$password = MD5(addslashes($_POST['password']));
$password11 = addslashes($_POST['password']);
$fromEmail = 'info@kreenlogistics.co.tz';
$space = " ";

$sql = "SELECT * FROM users where password='$CurrentPassword' and user_id='$user_id'";

  $check = $conn->query($sql);

  $check2 = mysqli_num_rows($check);
   
   
   if($check2 == 0){
  
   
   $_SESSION['success_message'] = "Current Password You Have Entered Is Not Correct";
                        header("Location: ../change_password.php");
                             exit();
   
   
   
   }else{
	   
	 $sql22 = "Select * from staff where staff_id ='$staff_id'";
	            $result22 = $conn->query($sql22);
	            $row22 = $result22->fetch_array();
                $toEmail = $row22['email'];  
				$name = $row22['firstname'].$space.$row22['lastname']; 
				
						
				
	$message = "Hello".$space.$name.$space."Your New Password is".$space.$password11;
    $subject = "New Password";
	
	$result8=$conn->query("UPDATE users SET password = '$password'  WHERE user_id = '$user_id'");
	
   
                               if($result8){
								   
						if(@mail($toEmail,$subject,$message,"From:" . $fromEmail)){
								   
						$_SESSION['success_message'] = "Your Password Has Been Changed Successfully";
                        header("Location: ../change_password.php");
                             exit();			   
					
								   
						             }
								 
									 }
	   
}

?>