2019-08-26 14:27:55 +00:00
< ? php
2019-09-06 23:33:05 +00:00
if ( ! isset ( $_SESSION [ " role " ]) || $_SESSION [ " role " ] != Role :: ADMIN && $_SESSION [ " role " ] != Role :: ORGANIZER )
2019-09-07 11:42:36 +00:00
require_once " server_files/403.php " ;
2019-09-06 11:48:50 +00:00
2019-09-06 23:33:05 +00:00
/** @noinspection SqlAggregates */
2019-09-06 11:48:50 +00:00
$req = $DB -> query ( " SELECT `tournaments`.`id`, `name` FROM `tournaments` JOIN `organizers` ON `tournament` = `tournaments`.`id` WHERE "
2019-09-06 23:33:05 +00:00
. ( $_SESSION [ " role " ] == Role :: ADMIN ? " " : " `organizer` = ' " . $_SESSION [ " user_id " ] . " ' AND " )
2019-09-06 11:48:50 +00:00
. " `year` = $YEAR GROUP BY `tournament` ORDER BY `name`; " );
2019-09-02 19:21:37 +00:00
2019-08-26 14:27:55 +00:00
if ( isset ( $_POST [ " download_zip " ])) {
$id = $_POST [ " tournament " ];
$tournament_name = $_POST [ " tournament_name " ];
2019-09-06 23:33:05 +00:00
/** @noinspection SqlAggregates */
$files_req = $DB -> query ( " SELECT *, COUNT(`problem`) AS `version` FROM `solutions` WHERE `tournament` = ' $id ' GROUP BY `team`, `problem` ORDER BY `team`, `problem`, `uploaded_at` DESC; " );
2019-08-26 14:27:55 +00:00
$zip = new ZipArchive ();
$temp = tempnam ( " tmp " , " tfjm- " );
if ( $zip -> open ( $temp , ZipArchive :: CREATE ) !== true ) {
die ( " Impossible de créer le fichier zip. " );
}
while (( $data_file = $files_req -> fetch ()) !== false ) {
$file_id = $data_file [ " file_id " ];
$problem = $data_file [ " problem " ];
$version = $data_file [ " version " ];
$team_id = $data_file [ " team " ];
2019-09-06 23:33:05 +00:00
$team = Team :: fromId ( $team_id );
$team_name = $team -> getName ();
$team_trigram = $team -> getTrigram ();
2019-08-26 14:27:55 +00:00
$zip -> addFile ( " $LOCAL_PATH /files/ $file_id " , " Problème $problem $team_trigram .pdf " );
}
$zip -> close ();
header ( " Content-Type: application/zip " );
header ( " Content-Disposition: attachment; filename= \" Solutions du tournoi de $tournament_name .zip \" " );
2019-09-06 11:48:50 +00:00
header ( " Content-Length: " . strval ( filesize ( $temp )));
2019-08-26 14:27:55 +00:00
readfile ( $temp );
exit ();
}
2019-09-07 11:42:36 +00:00
require_once " server_files/views/header.php " ;
2019-08-21 20:56:46 +00:00
while (( $data_tournament = $req -> fetch ()) !== false ) {
echo " <h1>Tournoi de " . $data_tournament [ " name " ] . " </h1> \n " ;
$id = $data_tournament [ " id " ];
2019-09-06 23:33:05 +00:00
/** @noinspection SqlAggregates */
$files_req = $DB -> query ( " SELECT *, COUNT(`problem`) AS `version` FROM `solutions` WHERE `tournament` = ' $id ' GROUP BY `team` ORDER BY `team`, `problem`, `uploaded_at` DESC; " );
2019-08-21 20:56:46 +00:00
while (( $data_file = $files_req -> fetch ()) !== false ) {
$file_id = $data_file [ " file_id " ];
$problem = $data_file [ " problem " ];
$version = $data_file [ " version " ];
$team_id = $data_file [ " team " ];
2019-09-06 23:33:05 +00:00
$team = Team :: fromId ( $team_id );
$team_name = $team -> getName ();
$team_trigram = $team -> getTrigram ();
2019-08-21 20:56:46 +00:00
echo " Problème n° $problem de l'équipe $team_name ( $team_trigram ), version $version : <a href= \" $URL_BASE /file/ $file_id\ " > Télécharger </ a >< br /> " ;
}
2019-08-26 14:27:55 +00:00
2019-09-06 11:48:50 +00:00
echo " <form method= \" POST \" > \n " ;
echo " <input type= \" hidden \" name= \" tournament \" value= \" $id\ " /> \n " ;
echo " <input type= \" hidden \" name= \" tournament_name \" value= \" " . $data_tournament [ " name " ] . " \" /> \n " ;
echo " <input style= \" width: 100% \" type= \" submit \" name= \" download_zip \" value= \" Télécharger l'archive \" /> \n " ;
echo " </form><hr /> \n " ;
2019-08-21 20:56:46 +00:00
}
2019-09-07 11:42:36 +00:00
require_once " server_files/views/footer.php " ;