<?php 
require 'db.php';
header('Content-type: text/json');
$data = json_decode(file_get_contents('php://input'), true);
if($data['name'] == '' or $data['email'] == '' or $data['mobile'] == '' or $data['imei']==''  or $data['password'] == '' or $data['shop_id'] == '')
{
    
    $returnArr = array("ResponseCode"=>"401","Result"=>"false","ResponseMsg"=>"Something Went Wrong!");
}
else
{
    $name = strip_tags(mysqli_real_escape_string($con,$data['name']));
    $email = strip_tags(mysqli_real_escape_string($con,$data['email']));
    $mobile = strip_tags(mysqli_real_escape_string($con,$data['mobile']));
    $imei = strip_tags(mysqli_real_escape_string($con,$data['imei']));
    $password = strip_tags(mysqli_real_escape_string($con,$data['password']));
    $uid =  strip_tags(mysqli_real_escape_string($con,$data['uid']));
    $shop_id = strip_tags(mysqli_real_escape_string($con,$data['shop_id']));
    $shop_code = strip_tags(mysqli_real_escape_string($con,$data['shop_code']));
    
    $checkimei = mysqli_num_rows(mysqli_query($con,"select * from user where id ='$uid' and shop_id = '$shop_id' and shop_code = '$shop_code'"));
    
    if($checkimei != 0)
    {
        $h_password = md5($password);
        $con->query("update user set name='$name',email='$email',mobile='$mobile',password='$password',hash_password='$h_password' where id='$uid' and shop_id = '$shop_id' and shop_code = '$shop_code'");
        $c = $con->query("select * from user where id='$uid'");
        $c = $c->fetch_assoc();
        $returnArr = array("user"=>$c,"ResponseCode"=>"200","Result"=>"true","ResponseMsg"=>"Update successfully!");
    }
    else
    {
        $returnArr = array("ResponseCode"=>"401","Result"=>"false","ResponseMsg"=>"Request To Update Own Device!!!!");  
    }
    
}

echo json_encode($returnArr);
?>