<?php

if (!isset($_SESSION["role"]) || $_SESSION["role"] != Role::ADMIN && $_SESSION["role"] != Role::ORGANIZER)
    require_once "server_files/403.php";

if (isset($_POST["download_zip"])) {
    $id = $_POST["tournament"];
	$tournament = Tournament::fromId($id);

    $file_name = getZipFile(DocumentType::SOLUTION, $id);

	header("Content-Type: application/zip");
	header("Content-Disposition: attachment; filename=\"Solutions du tournoi de " . $tournament->getName() . ".zip\"");
	header("Content-Length: " . strval(filesize($file_name)));

	readfile($file_name);

	exit();
}

$user = $_SESSION["user"];
$tournaments = $_SESSION["role"] == Role::ADMIN ? Tournament::getAllTournaments() : $user->getOrganizedTournaments();

require_once "server_files/views/solutions_orga.php";