<?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 = array();
$data = json_decode(file_get_contents('php://input'), true);


$sql = "SELECT * FROM global_settings ";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
    while ($row = mysqli_fetch_assoc($result)) {
        $sql_two = "UPDATE global_settings SET
                technical_mentor_rate='" . $_GET["technical_mentor_rate"] . "',
                assistant_mentor_rate='" . $_GET["assistant_mentor_rate"] . "',
                digifunzi_pay_rate='" . $_GET["digifunzi_pay_rate"] . "',
                online_mentor_rate='" . $_GET["online_mentor_rate"] . "',
                externaltrainer='" . $_GET["online_mentor_rate"] . "'
                WHERE global_settings_id='" . $row["global_settings_id"] . "'
                ";

        if (mysqli_query($conn, $sql_two)) {
            $new_array = array(
                'Success' => "true",
                'Reason' => "You have succesfully Updated settings",
            );
            echo json_encode($new_array);
        } else {
            $new_array = array(
                'Success' => "false",
                'Reason' => "You were unable to succesfully Update settings",
            );
            echo json_encode($new_array);
        }
    }
} else {
    $sql_two = "INSERT INTO global_settings VALUES(NULL,
        '" . $_GET["technical_mentor_rate"] . "',
        '" . $_GET["assistant_mentor_rate"] . "',
        '" . $_GET["online_mentor_rate"] . "',
        '" . $_GET["online_mentor_rate"] . "',
        '" . $_GET["digifunzi_pay_rate"] . "',
        '0', '0', '0',
        'KES', '0', '0',
        '0', '0', '0', '0', '0', '0','0', 'false', 'false', 'false', 'false',   now() )";
    if (mysqli_query($conn, $sql_two)) {
        $new_array = array(
            'Success' => "true",
            'Reason' => "You have succesfully Updated settings",
        );
        echo json_encode($new_array);
    } else {
        $new_array = array(
            'Success' => "false",
            'Reason' => "You were unable to succesfully Update settings",
        );
        echo json_encode($new_array);
    }
}
