
<?php
header('content-type:application/json');
include($_SERVER['DOCUMENT_ROOT'] . "/API-Others/connection/conn.php");

$country = $_GET['user_nationality'];
if (!empty($country)) {
    $query = mysqli_query($conn, "SELECT * FROM config WHERE config_type_id = '10' AND amount > 0 AND name IN (SELECT name FROM config_charges_by_countries) ");
    $charges = array();
    while ($spec = mysqli_fetch_assoc($query)) {
        $charges[] =  $spec;
    }

    $query1 = mysqli_query($conn, "SELECT * FROM config WHERE config_type_id = '10' AND amount = 0");
    $charges = array();
    while ($spec1 = mysqli_fetch_assoc($query1)) {
        $name = $spec1['name'];
        $query = mysqli_query($conn, "SELECT * FROM config_charges_by_countries WHERE country = '$country' AND name = '$name' AND amount > 0 ");
        while ($spec = mysqli_fetch_assoc($query)) {
            $id = $spec['id'];
            $charges[] =  $spec;
        }
        if(empty($id)){
            $query = mysqli_query($conn, "SELECT * FROM config WHERE config_type_id = '10' ");
            $charges = array();
            while ($spec = mysqli_fetch_assoc($query)) {
                $charges[] =  $spec;
            }
        }
    }
} else {
    $query = mysqli_query($conn, "SELECT * FROM config WHERE config_type_id = '10' ");
    $charges = array();
    while ($spec = mysqli_fetch_assoc($query)) {
        $charges[] =  $spec;
    }
}

$statusCode = 200;
$statusMessage = "Signed In Successfully";

$resultData = array('code' => $statusCode, 'message' => $statusMessage, 'charges' => $charges);
echo json_encode($resultData);

?>