<?php
namespace App\Controllers;

use App\Core\Controller;
use App\Core\Database;

class ReviewerController extends Controller
{
    public function score()
    {
        $db = Database::getInstance();
        $conf = $_SESSION['conference_id'];

        $stage = $db->query("SELECT status FROM conferences WHERE id=$conf")->fetchColumn();

        if($stage !== 'reviewing'){
            die("Review phase is not active.");
        }

        $db->prepare("INSERT INTO review_scores
        (assignment_id,originality,quality,relevance,comments)
        VALUES (?,?,?,?,?)")
        ->execute([
            $_POST['assignment_id'],
            $_POST['originality'],
            $_POST['quality'],
            $_POST['relevance'],
            $_POST['comments']
        ]);

        $db->prepare("UPDATE assignments SET status='completed' WHERE id=?")
           ->execute([$_POST['assignment_id']]);

        header("Location: /easychair/reviewer/dashboard");
        exit;
    }
}
