<?php
include("../connect.php"); 
$response = array();
if(isset($_POST['email_address']))
{
	date_default_timezone_set('Asia/Calcutta');
	$scro = date("h:i:sa");
	$da  = date("Y-m-d");
	$cdateTime=date("Y-m-d H:i:s");
	$email = $_POST['email_address']; 
	
	$res_search = mysqli_query($con,"select * from tbl_master_customer where status='Active' and email_address='$email'");
	$row_search = mysqli_num_rows($res_search);
	if($row_search!='0') 
	{
	  $a21=mysqli_fetch_array($res_search);
      $id=$a21['customer_id'];
      $dis_name=$a21['customer_name'];
      $user_type='Customer';	  
	}
	else 
	{
	 $res_search = mysqli_query($con,"select * from tbl_distributor_users where status='Active' and distributor_email='$email'");
     $a21=mysqli_fetch_array($res_search);
     $id=$a21['distributor_user_id'];
     $dis_name=$a21['distributor_name'];
     $user_type='Admin';	 
	}
	
	if($id!="") 
	{
		if( $user_type=='Customer')
		{
		  $uq1=mysqli_query($con,"UPDATE tbl_master_customer SET update_datetime='$cdateTime',password='tarkash@1234',imei_no='' where customer_id='$id'");
		}
		else
		{
		  $uq1=mysqli_query($con,"UPDATE tbl_distributor_users SET update_datetime='$cdateTime',password='tarkash@1234',imei_no='' where distributor_user_id='$id'");	
		} 
		
		$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='https://tarkashcorp.appexperts.net/assets/pages/img/app_logo2.png' alt='TARKASH'></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'>
			You had requested for password reset of your account. Your new password is tarkash@1234. 
			</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'>TARKASH Corp</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' 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. TARKASH 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 = "tarkashcorp@appexperts.net";                 
			$mail->Password = "ai]oeKHU^GaD";                           
			//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 = "tarkashcorp@appexperts.net";
			$mail->FromName = "TARKASH Corp";
			$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 send 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);

?>