<?php
    include 'needs_login.php';
    include 'db_conn.php';

    $statement = $db->prepare("SELECT * FROM Events where event_id=:id");
    $statement->execute(array(
        "id" => $_REQUEST['event_id']
    ));

    $result = $statement->fetch(PDO::FETCH_ASSOC);

    $moderator = $_SESSION['privilege_id'] != 4;

    if ($result['user_id'] == $_SESSION['user_id'] || $moderator)
    {
        $statement = $db->prepare("UPDATE Events SET status_id=2 WHERE event_id=:id");
        $statement->execute(array("id" => $_REQUEST['event_id']));
    } else {
        http_response_code(401);
        die("You're not allowed to edit that event.");
    }
?>
