<?php
ob_start();
include("../connect.php");
if(isset($_POST['email_id']) && isset($_POST['password']) && isset($_POST['imei_no']) && isset($_POST['ip_address']) && isset($_POST['carrier_name']) && isset($_POST['app_version']) && isset($_POST['phone_model']) && isset($_POST['phone_manufacturer']) && isset($_POST['sdk_phone_version']) && isset($_POST['device_id']))
{	
	$mac_id = $_POST['imei_no'];
	$device_id = $_POST['device_id'];
	$email1 = $_POST['email_id'];
	$pass = $_POST['password'];
	$ip_address = $_POST['ip_address'];
	$carrier_name = $_POST['carrier_name'];
	$app_version = $_POST['app_version'];
	$phone_model = $_POST['phone_model'];
	$phone_manufacturer = $_POST['phone_manufacturer'];
	$sdk_phone_version = $_POST['sdk_phone_version'];
	
	if($mac_id=="")
	{
		$response['success']=0;
		$response['details']="IMEI No not received. Please contact administrator!!";
	}
	else
	{
		$res = mysqli_query($con,"Select * from tbl_manager where password='$pass' and (manager_phone='$email1' or manager_email='$email1') and status='Active'");
		$row=mysqli_fetch_assoc($res);
		$response = array();
		if(mysqli_num_rows($res)>0)
		{	
			// $temp_device_id = $row['imei_no'];
			// if(($temp_device_id=="") || ($temp_device_id==$mac_id))
			// {
				$temp_uid=$row['manager_id'];
				$dis_id = $row['admin_id'];
				$response['manager_id'] = $row['manager_id'];
				$que2=mysqli_query($con,"update tbl_manager set imei_no='$mac_id',ip_address='$ip_address',carrier_name='$carrier_name',app_version='$app_version',phone_model='$phone_model',phone_manufacturer='$phone_manufacturer',sdk_phone_version='$sdk_phone_version',device_id='$device_id' where manager_id='$temp_uid' and admin_id='$dis_id'");
				$response['manager_name'] = $row['manager_name'];
				$res11 = mysqli_query($con,"Select * from tbl_admin_panel where admin_id='$dis_id'");
				$row11=mysqli_fetch_assoc($res11);
				$response['next_renew_date'] = $row11['next_renew_date'];
				$response['admin_id'] = $row['admin_id'];
				$response['manager_phone'] = $row['manager_phone'];
				$response['manager_email'] = $row['manager_email'];
				$response['address'] = $row['address'];
				$response['manage_type'] = $row['manage_type'];
				$response['success']=1;	
				$response['details']="Data Success";
			// }
			// else
			// {
			// 	$response['success']=0;	
			// 	$response['details']="You are already logged in. Please logout from another device or contact admin!!";
			// }
		}
		else
		{
			$response['success']=0;
			$response['details']="Your password or mail id or phone number is not correct !";
		}
	}
}
else
{	
	$response['success']=0;
	$response['details']="Error in Loggin in!! Please update app from Google Play Store and try again!!";
}
echo json_encode($response);
?> 