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

$config_id = addslashes(isset($_GET['config_id']) ? $_GET['config_id'] : '');
$name = addslashes(isset($_GET['name']) ? $_GET['name'] : '');
$amount = addslashes(isset($_GET['amount']) ? $_GET['amount'] : '');

if ($config_id == 10) {
    $query1 = mysqli_query($conn, "SELECT * FROM config WHERE id = '$config_id'");
    while ($spec1 = mysqli_fetch_assoc($query1)) {
        $oldConfigName = $spec1['name'];
    }
    $sql = ("UPDATE config_charges_by_countries SET name = '$name' WHERE name = '$oldConfigName' ");
    if (mysqli_query($conn, $sql)) {
    } else {
        $statusCode = 1042;
        $statusMessage = mysqli_error($conn);
    }
}

if ($config_id == 3) {
    $query1 = mysqli_query($conn, "SELECT * FROM config WHERE id = '$config_id'");
    while ($spec1 = mysqli_fetch_assoc($query1)) {
        $oldConfigName = $spec1['name'];
    }
    $sql = ("UPDATE config_charges_by_countries SET name = '$name' WHERE name = '$oldConfigName' ");
    if (mysqli_query($conn, $sql)) {
    } else {
        $statusCode = 1042;
        $statusMessage = mysqli_error($conn);
    }
}

$sql = ("UPDATE config SET name = '$name', amount = '$amount' WHERE id = '$config_id' ");
if (mysqli_query($conn, $sql)) {
    $statusCode = 200;
    $statusMessage = "Saved Successfully";
} else {
    $statusCode = 1042;
    $statusMessage = mysqli_error($conn);
}




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

echo json_encode($resultData);
