<?php
require_once $_SERVER['DOCUMENT_ROOT']."/_includes/init.php";

//PERMISSIONS AND REQUIREMENTS
////USER MUST BE LOGGED IN
////USER MUST BE ADMIN OR MOD
////REQUIRE $_GET["id"]
if (!$_USER->Logged_In)                                 { header("location: /login"); exit(); }
if (!isset($_GET["id"]) || mb_strlen((string) $_GET["id"]) > 11) { header("location: /"); exit();          }


$Comment = $DB->execute("SELECT id,by_user,on_channel FROM channel_comments WHERE id = :ID",true,[":ID" => $_GET["id"]]);

if ($DB->Row_Num == 1) {
    $ID = $Comment["id"];
    $By = $Comment["by_user"];
    $On = $Comment["on_channel"];

    if ($By === $_USER->Username || $On === $_USER->Username || $_USER->Is_Admin || $_USER->Is_Moderator) {
        $DB->modify("DELETE FROM channel_comments WHERE id = :ID",[":ID" => $ID]);
        $DB->modify("UPDATE users SET channel_comments = channel_comments - 1 WHERE username = :ON",[":ON" => $On]);
    }
}
?>
<script type="text/javascript">window.close();</script>
