<?php

require_once '../../vendor/autoload.php';
require_once '../../include/DatabaseConn.php';

$db = new DatabaseConn();
$link = $db->connect();

$std = new stdClass();

$email = filter_input(INPUT_GET, "user", FILTER_VALIDATE_EMAIL);
$option = filter_input(INPUT_GET, "option", FILTER_SANITIZE_STRING);

header("content-type: application/json");

if ($email == null || $email == FALSE) {
    $error = 'Email is not valid';
    $std->error = $error;
    echo (json_encode($std));
    die();
} else {
    mysqli_query($link, "update `users` set `wSettings` = '$option' where `email` = '$email'");
    if (mysqli_affected_rows($link) == 1) {
        $std->msg = "Operation was successful";
        echo (json_encode($std));
        die();
    } else {
        $error = 'Already updated.';
        $std->error = $error;
        echo (json_encode($std));
        die();
    }
}

