<?php
include("../connect.php"); 
$response = array();
if(isset($_POST['manager_id']) && isset($_POST['oldpass']) && isset($_POST['newpass']))
{
	date_default_timezone_set('Asia/Calcutta');
	$cdate11  = date("Y-m-d")." ".date("H:i:s");
	$ver = $_POST['manager_id'];
	$oldpass=$_POST['oldpass'];
	$newpass=$_POST['newpass'];													
	$rs=mysqli_query($con,"select manager_id from tbl_manager where manager_id='$ver' and password ='$oldpass'");
	$num=mysqli_num_rows($rs);
	if($num>0)
	{
		$rs_data=mysqli_query($con,"select * from tbl_manager where manager_id='$ver'");
		while($fetch_dis_check=mysqli_fetch_assoc($rs_data))
		{
			$adminid=$fetch_dis_check['admin_id'];
			$pname1=$fetch_dis_check['manager_name'];
			$distri_email1=$fetch_dis_check['manager_email'];
			$dis_password=$fetch_dis_check['password'];
			$dis_phone=$fetch_dis_check['manager_phone'];
			$dis_address=$fetch_dis_check['address'];
			$query = mysqli_query($con,"INSERT INTO `tbl_manager_history`(`manager_id`, `admin_id`, `manager_name`, `manager_phone`, `manager_email`, `address`, `password`, `insert_datetime`, `remark`, `update_by`) VALUES ('$ver','$adminid','$pname1','$dis_phone','$distri_email1','$dis_address','$dis_password','$cdate11','Password Changed','$ver')");									
		}
		$uq1=mysqli_query($con,"update tbl_manager set password='$newpass',update_datetime='$cdate11',imei_no='',session_id='' where manager_id='$ver'");  
		$response['success']='1';
		$response['details']="Password changed successfully";
	}
	else
	{
		$response['success']='0';
		$response['details']="Password not changed..Please check and try again later!!";
	}
}
else
{
	$response['success']='0';
	$response['details']="Required field missing";
}	
echo json_encode($response);

?>