	<?php
	/**
	* Created by PhpStorm.
	* User: ahmad
	* Date: 20/08/2019
	* Time: 11:48 AM
	* Location profil -> login
	*/
	
	
	require_once("../connection.php");
		include "classes/class.phpmailer.php";
		
		$username=mysqli_real_escape_string($connect, $_POST['user']);
		$email=mysqli_real_escape_string($connect, $_POST['email']);

	class usr{}
		
	$tanggal	= gmdate("Y-m-d", time()+60*60*7);
	$jam	= gmdate("H:i", time()+60*60*7);

	
	if ((empty($username)) || (empty($email))) {
		$response = new usr();
		$response->status 	= 'true';
		$response->errCode 	= '00';
		$response->msg 		= "Column cannot be empty"; 
		die(json_encode($response));
	}
	
	$query = "SELECT * FROM users WHERE phone_number='$username' AND email='$email' AND blokir='N'";
	$hasil = mysqli_query($connect,$query);
	
	if(mysqli_num_rows($hasil) > 0 ){
	$x = mysqli_fetch_array($hasil);
		$password="123456";
		$pass=md5("$password");
	mysqli_query($connect,"UPDATE users SET password = '$pass'
                             WHERE phone_number = '$username'");
		
	$mail = new PHPMailer;
	$mail->IsSMTP();
	$mail->SMTPSecure = 'null';
	$mail->Host = "mail.bluepage.ng"; //hostname masing-masing provider email
	$mail->SMTPDebug = false;
	$mail->Port = 587;
	$mail->SMTPAuth = true;
	$mail->Username = "support@bluepage.ng"; //user email
	$mail->Password = "bluepage11005000"; //password email
	$mail->SetFrom("support@bluepage.ng","iRESTO"); //set email pengirim
	$mail->Subject = "Your password changed"; //subyek email
	$mail->AddAddress("$x[email]","$x[full_name]"); //tujuan email
	$mail->MsgHTML("Hallo, <b>$x[full_name] </b><br>You have used the Forgot Password feature</p>
<h3 class='heading-mosaic'>Your new password: $password</h3>
</div>
       <p>Please Login and change this password with your new password in the Account menu -> Change password.</p>
       <p>Immediately contact the admin if this is not you who did it.</p>
	   <br>
        Your Growth Partners at WPOS<br>");
							
	if($mail->Send()){
		
	$json = array(
    'status' 	=> 'true',
    'errCode' 	=> '01',
	'msg' 		=> 'Please check your email, the password has been sent Password'
	);
	
    echo json_encode($json);

	}else{
	$json = array(
    'status' 	=> 'true',
    'errCode' 	=> '02',
	'msg' 		=> 'Failed to sending message, please contact admin'
	);
	}
		
	}else {
	$response = array(
    'status' 	=> 'true',
    'errCode' 	=> '02',
	'msg' 		=> 'Invalid email or phone number or inactive account'
	);
	echo json_encode($response);
	}
	

?>