<?php
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST');
header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Authorization");
include '../../../config/index.php';
$data = file_get_contents('php://input');
$obj = json_decode($data, true);
// $sql1 = "SELECT * FROM Coupons WHERE Coupon_id='" . $_GET['Coupon_id'] . "' ";
// $result1 = mysqli_query($conn, $sql1);
// if (mysqli_num_rows($result1) > 0) {
//     while ($row1 = mysqli_fetch_assoc($result1)) {
$Active =  $obj['Active'] ? 'true' : 'false';
$sql = "UPDATE Coupons SET
            DiscountOption='" . $obj['DiscountOption'] . "',
            FixedAmount='" . $obj['FixedAmount'] . "',
            PercentageAmount='" . $obj['PercentageAmount'] . "',
            ExpiryDate='" . $obj['ExpiryDate'] . "',
            Active='" . $Active . "'
        
        WHERE Coupon_id='" . $obj['Coupon_id'] . "' ";

if (mysqli_query($conn, $sql)) {
    $curl_post_data = array(
        'Success' => 'true',
        'Reason' => 'You Have Succesfully Edited a Coupon',
    );
    echo json_encode($curl_post_data);
} else {
    $curl_post_data = array(
        'Success' => 'false',
        'Reason' => 'Failed to Update Coupon, Kindly Try Again Later',
    );
    echo json_encode($curl_post_data);
}
//     }
// }





// }


// echo json_encode($obj);
