<?php 
require 'db.php';
$data = json_decode(file_get_contents('php://input'), true);
if($data['name'] == '' or $data['email'] == '' or $data['mobile'] == '' or $data['imei']==''  or $data['password'] == '' || $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']));
    $shop_id = strip_tags(mysqli_real_escape_string($con,$data['shop_id']));
    $shop_code = strip_tags(mysqli_real_escape_string($con,$data['shop_code']));
    
    $checkmob = $con->query("select * from user where mobile='$mobile' and shop_id = '$shop_id' and shop_code = '$shop_code'");
    $checkemail = $con->query("select * from user where email='$email' and shop_id = '$shop_id' and shop_code = '$shop_code'");
    
    if($checkmob->num_rows != 0)
    {
        $returnArr = array("ResponseCode"=>"401","Result"=>"false","ResponseMsg"=>"Mobile Number Already Registered!");
    }
    else if($checkemail->num_rows != 0)
    {
        $returnArr = array("ResponseCode"=>"401","Result"=>"false","ResponseMsg"=>"Email Address Already Registered!");
    }
    else
    {
        $timestamp = date("Y-m-d H:i:s");
        $hash_password = md5($password);
        $con->query("insert into user(`shop_id`,`shop_code`,`name`,`imei`,`email`,`mobile`,`use_date`,`password`,`hash_password`)values('$shop_id','$shop_code','$name','$imei','$email','$mobile','$timestamp','$password','$hash_password')");
        
        $chek = $con->query("select * from user where (mobile='$mobile' or email='$mobile') and password='$password' and shop_id = '$shop_id' and shop_code = '$shop_code'");
        $status = $con->query("select * from user where status = '1' and (mobile='$mobile' or email='$mobile') and shop_id = '$shop_id' and shop_code = '$shop_code'");
        
        if($status->num_rows !=0)
        {
            if($chek->num_rows != 0)
            {
                $c = $con->query("select * from user where (mobile='$mobile' or email='$mobile')  and status = 1 and password='$password' and shop_id = '$shop_id' and shop_code = '$shop_code'");
                $user_details = $c->fetch_assoc();
                
                $returnArr = array("user"=>$user_details,"ResponseCode"=>"200","Result"=>"true","ResponseMsg"=>"Registration successfully!");
            }
        }
    }
    
    
}

echo json_encode($returnArr);