diff --git a/dispatcher.php b/dispatcher.php index 1a7e57c..274617e 100644 --- a/dispatcher.php +++ b/dispatcher.php @@ -46,6 +46,7 @@ $ROUTES["^file/([a-z0-9]{64})/?$"] = ["server_files/controllers/view_file.php", $ROUTES["^informations/([0-9]*)/.*?$"] = ["server_files/controllers/informations.php", "id"]; $ROUTES["^inscription/?$"] = ["server_files/controllers/inscription.php"]; $ROUTES["^mon-compte/?$"] = ["server_files/controllers/mon_compte.php"]; +$ROUTES["^mon-equipe/(diffusion-videos)/?$"] = ["server_files/controllers/mon_equipe.php", "publish_videos"]; $ROUTES["^mon-equipe/(modifier)/?$"] = ["server_files/controllers/mon_equipe.php", "modifier"]; $ROUTES["^mon-equipe/?$"] = ["server_files/controllers/mon_equipe.php"]; $ROUTES["^poser-questions-2$"] = ["server_files/controllers/poser_questions.php"]; diff --git a/server_files/classes/Team.php b/server_files/classes/Team.php index 6ddfe70..d8ccf03 100644 --- a/server_files/classes/Team.php +++ b/server_files/classes/Team.php @@ -9,6 +9,7 @@ class Team private $encadrant; private $participants; private $inscription_date; + private $allow_publish; private $validation_status; private $video_team_ids; private $access_code; @@ -95,6 +96,7 @@ class Team $this->encadrant = $data["encadrant"]; $this->participants = [$data["participant_1"], $data["participant_2"], $data["participant_3"], $data["participant_4"], $data["participant_5"]]; $this->inscription_date = $data["inscription_date"]; + $this->allow_publish = $data["allow_publish"]; $this->validation_status = ValidationStatus::fromName($data["validation_status"]); $this->video_team_ids = [$data["video_team1"], $data["video_team2"]]; $this->access_code = $data["access_code"]; @@ -173,6 +175,18 @@ class Team return $this->inscription_date; } + public function allowPublish() + { + return $this->allow_publish; + } + + public function setAllowPublish($allow_publish) + { + global $DB; + $this->allow_publish = $allow_publish; + $DB->prepare("UPDATE `teams` SET `allow_publish` = ? WHERE `id` = ?;")->execute([$allow_publish ? 1 : 0, $this->id]); + } + public function getValidationStatus() { return $this->validation_status; diff --git a/server_files/controllers/ajouter_equipe.php b/server_files/controllers/ajouter_equipe.php index 74a7829..46d9226 100644 --- a/server_files/controllers/ajouter_equipe.php +++ b/server_files/controllers/ajouter_equipe.php @@ -22,6 +22,7 @@ class NewTeam { public $name; public $trigram; public $problem; + public $allow_publish; public $access_code; public function __construct($data) @@ -30,6 +31,8 @@ class NewTeam { $this->$key = htmlspecialchars($value); $this->trigram = strtoupper($this->trigram); + + $this->allow_publish = $this->allow_publish == "on"; } public function makeVerifications() { @@ -50,10 +53,10 @@ class NewTeam { $this->access_code = genRandomPhrase(6); - $req = $DB->prepare("INSERT INTO `teams` (`name`, `trigram`, `problem`, `encadrant`, `participant_1`, `validation_status`, `access_code`, `year`) - VALUES (?, ?, ?, ?, ?, ?, ?, ?);"); + $req = $DB->prepare("INSERT INTO `teams` (`name`, `trigram`, `problem`, `encadrant`, `participant_1`, `allow_publish`, `validation_status`, `access_code`, `year`) + VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?);"); $req->execute([$this->name, $this->trigram, $this->problem, $_SESSION["role"] == Role::ENCADRANT ? $_SESSION["user_id"] : NULL, - $_SESSION["role"] == Role::PARTICIPANT ? $_SESSION["user_id"] : NULL, ValidationStatus::getName(ValidationStatus::NOT_READY), $this->access_code, $YEAR]); + $_SESSION["role"] == Role::PARTICIPANT ? $_SESSION["user_id"] : NULL, $this->allow_publish, ValidationStatus::getName(ValidationStatus::NOT_READY), $this->access_code, $YEAR]); $_SESSION["team"] = Team::fromTrigram($this->trigram); $_SESSION["user"]->setTeamId($_SESSION["team"]->getId()); diff --git a/server_files/controllers/mon_equipe.php b/server_files/controllers/mon_equipe.php index fcba0ef..8e446af 100644 --- a/server_files/controllers/mon_equipe.php +++ b/server_files/controllers/mon_equipe.php @@ -58,6 +58,12 @@ if (isset($_SESSION["user_id"]) && isset($_SESSION["team"]) && $_SESSION["team"] else require_once "server_files/403.php"; +if (isset($_GET["publish_videos"])) { + $team->setAllowPublish(!$team->allowPublish()); + header("Location: /mon-equipe"); + exit(); +} + class SendDocument { private $file; @@ -115,13 +121,15 @@ class MyTeam public function makeVerifications() { + global $CONFIG; + ensure($this->name != "" && $this->name != null, "Veuillez spécifier un nom d'équipe."); ensure($this->name == $this->team->getName() || !teamExists($this->name), "Une équipe existe déjà avec ce nom."); ensure(preg_match("#^[\p{L} ]+$#ui", $this->name), "Le nom de l'équipe ne doit pas comporter de caractères spéciaux."); ensure(preg_match("#^[A-Z]{3}$#", $this->trigram), "Le trigramme n'est pas valide."); ensure($this->trigram == $this->team->getTrigram() || !trigramExists($this->trigram), "Une équipe a déjà choisi ce trigramme."); ensure(preg_match("#^[1-4]$#", $this->problem), "Le problème indiqué n'existe pas."); - // ensure(date("y-m-d H:i:s") <= $this->tournament->getInscriptionDate(), "Les inscriptions sont terminées."); + ensure(date("Y-m-d H:i:s") <= $CONFIG->getInscriptionDate(), "Les inscriptions sont terminées."); ensure($this->team->getValidationStatus() == ValidationStatus::NOT_READY, "Votre équipe est déjà validée ou en cours de validation."); } diff --git a/server_files/services/mail_templates/video_accepted_answer.html b/server_files/services/mail_templates/video_accepted_answer.html index 4ea80f9..de8c748 100644 --- a/server_files/services/mail_templates/video_accepted_answer.html +++ b/server_files/services/mail_templates/video_accepted_answer.html @@ -5,14 +5,16 @@