<?php
include("../connect.php"); 
$response = array();
if(isset($_POST['email']) && isset($_POST['phoneno']))
{
	date_default_timezone_set('Asia/Calcutta');
	$scro = date("h:i:sa");
	$da  = date("Y-m-d");
	$email = $_POST['email'];
	$phoneno = $_POST['phoneno'];
	$cdate  = date("Y-m-d")." ".date('H:i:s');
	$token = bin2hex(openssl_random_pseudo_bytes(30));
	$link = "http://www.btcover.appexperts.net/api/password_reset.php?id=".$token;

	$res_search = mysqli_query($con,"select * from tbl_manager where status='Active' and manager_email='$email' && manager_phone='$phoneno'");
	$row_search  = mysqli_num_rows($res_search);
	$a21=mysqli_fetch_array($res_search);
	if($row_search>0)
	{
		$ver=$a21['manager_id'];
		$dis_name=$a21['manager_name'];
		$uq1=mysqli_query($con,"UPDATE tbl_manager SET token='$token', token_datetime='$cdate',imei_no='' where manager_id='$ver'");	
			
		$user_mail_body="<tr><td style='padding:20px'>
<table style='max-width:730px' align='center' bgcolor='#ffffff' border='0' cellpadding='0' cellspacing='0' width='100%'>
<tbody>
<tr>
<td style='font-size:1px;line-height:1px;height:1px' colspan='3' bgcolor='#d6d6d6' height='1'>  </td>
</tr>
<tr>
<td bgcolor='#d6d6d6' width='1'>&nbsp;</td>
<td><table align='center' border='0' cellpadding='0' cellspacing='0' width='100%'>
<tbody>
<tr>
<td colspan='4' height='20'>&nbsp;</td>
</tr>
<tr>
<td width='24'>&nbsp;</td>
<td width='293'>&nbsp;</td>
<td width='155'><a style='text-decoration:none;font-family:Arial,Helvetica,sans-serif;font-size:20px;font-weight:bold;color:#6ac451'><img class='CToWUd' src='http://www.btcover.appexperts.net/images/ic_app_logo.png' width='100px' height='100px' alt='BTCover'></a></td>
<td width='26'>&nbsp;</td>
</tr>
<tr>
<td colspan='4' height='17'>&nbsp;</td>
</tr>
<tr>
<td style='min-height:1px;line-height:0px;font-size:0px' colspan='4' bgcolor='#d6d6d6' height='1'>  </td>
</tr>
<tr>
<td colspan='4' height='10'>&nbsp;</td>
</tr>
<tr>
<td width='24'>&nbsp;</td>
<td style='font-family:Arial,Helvetica,sans-serif;font-size:14px;color:#666666' colspan='2'>
<p>Dear $dis_name</p>
</td>
<td width='26'>&nbsp;</td>
</tr>
<tr>
<td colspan='4' height='0'>&nbsp;</td>
</tr>
<tr>
<td width='24'>&nbsp;</td>
<td style='font-family:Arial,Helvetica,sans-serif;font-size:14px;color:#666666;line-height:20px' colspan='2'>
We had received your request for Password Reset. Please click below button to reset password. It is valid for 24 Hours. 
<a href='{$link}' class='btn btn-info' role='button' style=' display: block;
    width: 115px;
    height: 25px;
    background: #4E9CAF;
    padding: 10px;
    text-align: center;
    border-radius: 5px;
    color: white;
    font-weight: bold;'>Reset Password</a>
</td>
<td>&nbsp;</td>
</tr>
<tr>
<td colspan='4' height='5'>&nbsp;</td>
</tr>

<tr>
<td colspan='4' height='15'>&nbsp;</td>
</tr>
<tr>
<td width='24'>&nbsp;</td>
<td style='font-family:Arial,Helvetica,sans-serif;font-size:14px;font-weight:bold;color:#000;line-height:24px' colspan='2'>Best Regards,</td>
<td>&nbsp;</td>
</tr>
<tr>
<td width='24'>&nbsp;</td>
<td style='font-family:Arial,Helvetica,sans-serif;font-size:14px;color:#000;line-height:24px' colspan='2'>BTCover Support</td>
<td>&nbsp;</td>
</tr>
<tr>
<td width='24'>&nbsp;</td>
<td style='font-family:Arial,Helvetica,sans-serif;font-size:14px;color:#000;line-height:24px' colspan='2'>+91-7340040171</td>
<td>&nbsp;</td>
</tr>
<tr>
<td colspan='4' height='10'>&nbsp;</td>
</tr>
<tr>
<td style='line-height:1px' colspan='4' bgcolor='#d6d6d6' height='1'>  </td>
</tr>
<tr>
<td colspan='4' bgcolor='#f3f3f3' height='10'>&nbsp;</td>
</tr>
<tr>
<td colspan='4' bgcolor='#f3f3f3'>
<table border='0' cellpadding='0' cellspacing='0'>
<tbody>
<tr>
<td width='15'>&nbsp;</td>
<td style='font-family:Arial,Helvetica,sans-serif;font-size:14px;color:#666666;line-height:20px' colspan='2'>If you have any issues, feel free to contact us at <a style='text-decoration:none;color:#ea8a00' href='mailto:http://www.belltechnology.in/' target='_blank'>http://www.belltechnology.in/</a></td>
<td width='12'>&nbsp;</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td colspan='4' bgcolor='#f3f3f3' height='10'>&nbsp;</td>
</tr>
</tbody>
</table>
</td>
<td bgcolor='#d6d6d6' width='1'>&nbsp;</td>
</tr>
<tr>
<td style='line-height:1px' colspan='3' bgcolor='#d6d6d6' height='1'>  </td>
</tr>
</tbody>
</table>
</td>
</tr><br><br><hr>Disclaimer:This E-Mail may contain Confidential and/or legally privileged Information and is meant for the intended recipient(s) only. If you have received this e-mail in error and are not the intended recipient/s, Kindly notify the sender and then delete this e-mail immediately from your system. You are also hereby notified that any use, any form of reproduction, dissemination, copying, disclosure, modification, distribution and/or publication of this e-mail, its contents or its attachment/s other than by its intended recipient/s is strictly prohibited and may be unlawful.

Internet Communications cannot be guaranteed to be secure or error-free as information could be delayed, intercepted, corrupted, lost, or contain viruses. BTCover does not accept any liability for any errors, omissions, viruses or computer problems experienced by any recipient as a result of this e-mail.";
			
			require '../../bthawk/PHPMailer-master/PHPMailerAutoload.php';
			$mail = new PHPMailer;
			$mail->isSMTP();            
			//Set SMTP host name                          
			$mail->Host = "server1.appexperts.net";
			//Set this to true if SMTP host requires authentication to send email
			$mail->SMTPAuth = true;                         
			//Provide username and password     
			$mail->Username = "btcover@appexperts.net";                 
			$mail->Password = "vjEXl3qJ_0C8";                           
			//If SMTP requires TLS encryption then set it
			$mail->SMTPSecure = "tls";                           
			//Set TCP port to connect to 
			$mail->Port = 587;   
			//From email address and name
			$mail->From = "btcover@appexperts.net";
			$mail->FromName = "RIS";
			$mail->CharSet = 'UTF-8';
			//To address and name
			$mail->addAddress($email);
			$mail->isHTML(true);
			$mail->Subject = "Forgot Password";
			$mail->Body = "<i>$user_mail_body</i>";
			if($mail->send()) 
			{
				$response['success']='1';
				$response['details']="Mail sent successfully";
			}
			else
			{
				$response['success']='0';
				$response['details']="Mail not send";
			}
	}
	else
	{
		$response['success']='0';
		$response['details']="Email and phone does not match. Please check and try again later!!!!";
	}
}
else
{
	$response['success']='0';
	$response['details']="Required field missing";
}	
echo json_encode($response);

?>