<?php
require 'db.php';
header( 'Content-Type: text/html; charset=utf-8' ); 
$data = json_decode(file_get_contents('php://input'), true);

$pin = $data['mobile'];
$password = $data['password'];
if ($pin =='' or $password =='')
{
    $returnArr = array("ResponseCode"=>"401","Result"=>"false","ResponseMsg"=>"Something Went wrong try again!");
}
else 
{
    $pin = strip_tags(mysqli_real_escape_string($con,$pin));
    $password = strip_tags(mysqli_real_escape_string($con,$password));
    
    $counter = $con->query("select * from shop_settings where mobile_no='$pin'");
    
    if($counter->num_rows != 0)
    {
        $hash_password = md5($password);
        $con->query("update shop_settings set password='$password' and hash_password = '$hash_password' where mobile='$pin'");
        
        $chek = $con->query("SELECT 
                shop_details.shop_name,
                shop_settings.shop_id,
                shop_settings.shop_code
                FROM shop_settings
                INNER JOIN shop_details ON
                shop_settings.shop_id = shop_details.shop_id
                WHERE shop_settings.mobile_no = '$pin' and shop_settingspassword='$password'");
        if($chek->num_rows !=0)
        {
            $c = $chek->fetch_assoc();
            $returnArr = array("merchant"=>$c,"ResponseCode"=>"200","Result"=>"true","ResponseMsg"=>"Password Changed Successfully!");
        }
    }
    else
    {
        $returnArr = array("ResponseCode"=>"401","Result"=>"false","ResponseMsg"=>"Mobile Not Registered!");  
    }
}

echo json_encode($returnArr);
?>

