//to show number of new notifications
$login = $_SESSION["loggedIn"];
$n_messages = countnewmessages($login);
$n_requests = countrequests($login);
echo "<h1 style=\"text-align:center\">Messages (" . $n_messages . ") and Requests (" . $n_requests . ")</h1>";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    if (!empty($_POST["acceptrequest"])) {
        $id = $_POST["acceptrequest"];
        rateLanguage($id);
        deleterateRequest($id);
        $id = "";
        $n_requests = countrequests($login);
    }
    if (!empty($_POST["rejectrequest"])) {
        $id = $_POST["rejectrequest"];
        deleterateRequest($id);
        $id = "";
        $n_requests = countrequests($login);
    }
    if (!empty($_POST["deletecomment"])) {
        $id = $_POST["deletecomment"];
        deletecomment($id);
        echo "<script>alert(\"You have deleted a comment.\")</script>";
        $n_comments = countnewcomments();
    }
    if (!empty($_POST["readcomment"])) {
        $id = $_POST["readcomment"];
        readcomment($id);
        echo "<script>alert(\"You have maked a comment as read.\")</script>";
        $n_comments = countnewcomments();
    }
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    if (empty($_POST["validrequest"]) | empty($_POST["login1"]) | empty($_POST["login2"]) | empty($_POST["ratedlevel"]) | empty($_POST["language"])) {
        $validErr = "Validation is required";
    } else {
        $validrequest = $_POST["validrequest"];
        $login1 = $_POST["login1"];
        $login2 = $_POST["login2"];
        $ratedlevel = $_POST["ratedlevel"];
        $language = $_POST["language"];
        if ($validrequest == "Accept") {
            rateLanguage($login2, $ratedlevel, $language);
            deleterateRequest($login1, $login2, $ratedlevel, $language);
            echo "You have accepted {$login1}'s rating of {$ratedlevel} for your {$language} ability.<br>";
            $validrequest = $login1 = $login2 = $ratedlevel = $language = "";
        } elseif ($validrequest == "Reject") {
            deleterateRequest($login1, $login2, $ratedlevel, $language);
            echo "You have rejected {$login1}'s rating of {$ratedlevel} for your {$language} ability.<br>";
            $validrequest = $login1 = $login2 = $ratedlevel = $language = "";
        }
    }
}
?>
                </div>
            </div>
        </div>
    </header>
    
    
    <div class="row">
        <div class="col-md-8 col-md-offset-2 aboutus">                         
            <h2><b>Ratings</b></h2>