2019-09-06 11:48:50 +00:00
< ? php
2019-09-07 11:42:36 +00:00
if ( ! isset ( $_SESSION [ " team " ]))
require_once " server_files/403.php " ;
2019-09-06 11:48:50 +00:00
2019-09-07 17:01:23 +00:00
/**
* @ var Team $team
* @ var Tournament $tournament
*/
2019-09-07 11:42:36 +00:00
$team = $_SESSION [ " team " ];
2019-09-07 23:35:05 +00:00
$tournament = Tournament :: fromId ( $team -> getTournamentId ());
2019-09-07 11:42:36 +00:00
2019-09-07 23:35:05 +00:00
if ( isset ( $_POST [ " send_synthesis " ])) {
2019-09-09 23:02:13 +00:00
$save_synthesis = new SaveSynthesis ();
try {
$save_synthesis -> makeVerifications ();
$save_synthesis -> saveSynthesis ();
} catch ( AssertionError $e ) {
$has_error = true ;
$error_message = $e -> getMessage ();
}
2019-09-07 17:01:23 +00:00
}
2019-09-06 11:48:50 +00:00
2019-09-07 23:35:05 +00:00
$syntheses = $tournament -> getAllSyntheses ( $team -> getId ());
$syntheses_final = null ;
if ( $team -> isSelectedForFinal ())
$syntheses_final = $FINAL -> getAllSyntheses ( $team -> getId ());
2019-09-06 11:48:50 +00:00
2019-09-09 23:02:13 +00:00
class SaveSynthesis
{
private $dest ;
2020-05-04 23:06:57 +00:00
private $round ;
2019-09-09 23:02:13 +00:00
private $file ;
public function __construct ()
{
2019-12-19 12:02:01 +00:00
$this -> file = $_FILES [ " synthese " ];
2020-05-04 23:06:57 +00:00
$this -> round = htmlspecialchars ( $_POST [ " round " ]);
2019-12-19 12:02:01 +00:00
$this -> dest = DestType :: fromName ( strtoupper ( htmlspecialchars ( $_POST [ " dest " ])));
2019-09-09 23:02:13 +00:00
}
public function makeVerifications ()
{
2020-05-04 23:06:57 +00:00
global $LOCAL_PATH , $tournament ;
2019-09-09 23:02:13 +00:00
2020-05-04 23:06:57 +00:00
ensure ( $this -> dest != DestType :: DEFENSEUR , " La source est invalide. " );
ensure ( $this -> round == 1 || $this -> round == 2 , " Le tour est invalide. " );
$now = date ( " Y-m-d H:i " );
ensure ( $this -> round == 1 && $now < $tournament -> getSynthesesDate () || $this -> round == 2 && $now < $tournament -> getSynthesesDate2 (), " Vous ne pouvez plus rendre de note de synthèse pour le tour $this->round . " );
2019-09-09 23:02:13 +00:00
ensure ( $this -> file [ " size " ] <= 2e6 , " Le fichier doit peser moins que 2 Mo. " );
ensure ( ! $this -> file [ " error " ], " Une erreur est survenue. " );
ensure ( finfo_file ( finfo_open ( FILEINFO_MIME_TYPE ), $this -> file [ " tmp_name " ]) == " application/pdf " , " Le fichier doit être au format PDF. " );
ensure ( is_dir ( " $LOCAL_PATH /files " ) || mkdir ( " $LOCAL_PATH /files " ), " Un problème est survenue dans l'envoi du fichier. Veuillez contacter l'administrateur du serveur. " );
}
public function saveSynthesis ()
{
global $LOCAL_PATH , $DB , $team , $tournament , $FINAL ;
do
$id = genRandomPhrase ( 64 );
while ( file_exists ( " $LOCAL_PATH /files/ $id " ));
if ( ! rename ( $this -> file [ " tmp_name " ], " $LOCAL_PATH /files/ $id " ))
throw new AssertionError ( " Une erreur est survenue lors de l'envoi du fichier. " );
2020-05-04 23:06:57 +00:00
$req = $DB -> prepare ( " INSERT INTO `syntheses`(`file_id`, `team`, `tournament`, `round`, `dest`) VALUES (?, ?, ?, ?, ?); " );
$req -> execute ([ $id , $team -> getId (), $team -> isSelectedForFinal () ? $FINAL -> getId () : $tournament -> getId (), $this -> round , $this -> dest ]);
2019-09-09 23:02:13 +00:00
return false ;
}
2019-09-06 11:48:50 +00:00
}
2019-09-07 11:42:36 +00:00
require_once " server_files/views/syntheses.php " ;