2019-09-06 11:48:50 +00:00
< ? php
2019-09-06 23:33:05 +00:00
if ( ! isset ( $_SESSION [ " user_id " ]) || $_SESSION [ " role " ] != Role :: ORGANIZER && $_SESSION [ " role " ] != Role :: ADMIN )
2019-09-07 11:42:36 +00:00
require_once " server_files/403.php " ;
2019-09-06 23:33:05 +00:00
2019-09-06 11:48:50 +00:00
$trigram = htmlspecialchars ( $_GET [ " trigram " ]);
2019-09-06 23:33:05 +00:00
$team = Team :: fromTrigram ( $trigram );
2019-09-07 23:35:05 +00:00
$tournament = Tournament :: fromId ( $team -> getTournamentId ());
2019-09-06 23:33:05 +00:00
if ( $team === null )
2019-09-07 11:42:36 +00:00
require_once " server_files/404.php " ;
2019-09-06 23:33:05 +00:00
2019-09-06 11:48:50 +00:00
if ( isset ( $_POST [ " validate " ])) {
2019-09-06 23:33:05 +00:00
$team -> setValidationStatus ( ValidationStatus :: VALIDATED );
2019-09-06 11:48:50 +00:00
}
if ( isset ( $_POST [ " select " ])) {
2019-09-06 23:33:05 +00:00
$team -> selectForFinal ( true );
$team -> setValidationStatus ( ValidationStatus :: NOT_READY );
2019-09-07 12:31:28 +00:00
/** @noinspection SqlAggregates */
$sols_req = $DB -> prepare ( " SELECT `file_id`, `problem`, COUNT(`problem`) AS `version` FROM `solutions` WHERE `team` = ? AND `tournament` = ? GROUP BY `problem` ORDER BY `problem`, `uploaded_at` DESC; " );
2019-09-06 23:33:05 +00:00
$sols_req -> execute ([ $team -> getId (), $team -> getTournamentId ()]);
2019-09-06 11:48:50 +00:00
while (( $sol_data = $sols_req -> fetch ()) !== false ) {
$old_id = $sol_data [ " file_id " ];
$alphabet = " abcdefghijklmnopqrstuvwxyz0123456789 " ;
do {
$id = " " ;
for ( $i = 0 ; $i < 64 ; ++ $i ) {
$id .= $alphabet [ rand ( 0 , strlen ( $alphabet ) - 1 )];
}
}
while ( file_exists ( " $LOCAL_PATH /files/ $id " ));
copy ( " $LOCAL_PATH /files/ $old_id " , " $LOCAL_PATH /files/ $id " );
2019-09-07 23:35:05 +00:00
$req = $DB -> prepare ( " INSERT INTO `solutions`(`file_id`, `team`, `tournament`, `problem`) VALUES (?, ?, ?, ?); " );
2019-09-06 23:33:05 +00:00
$req -> execute ([ $id , $team -> getId (), $_SESSION [ " final_id " ], $sol_data [ " problem " ]]);
2019-09-06 11:48:50 +00:00
}
}
2019-09-07 23:35:05 +00:00
// TODO Télécharger en zip les documents personnels
2019-09-06 11:48:50 +00:00
2019-09-07 23:35:05 +00:00
$documents = $tournament -> getAllDocuments ( $team -> getId ());
$documents_final = null ;
2019-09-06 11:48:50 +00:00
2019-09-07 23:35:05 +00:00
if ( $team -> isSelectedForFinal ())
$documents_final = $FINAL -> getAllDocuments ( $team -> getId ());
2019-09-06 23:33:05 +00:00
2019-09-07 11:42:36 +00:00
require_once " server_files/views/equipe.php " ;