2019-09-09 23:48:52 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
if (isset($_POST["leave_team"])) {
|
|
|
|
quitTeam();
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
$has_error = false;
|
|
|
|
$error_message = null;
|
|
|
|
|
|
|
|
if (isset($_POST["team_edit"])) {
|
|
|
|
$my_team = new MyTeam($_POST);
|
|
|
|
try {
|
|
|
|
$my_team->makeVerifications();
|
|
|
|
$my_team->updateTeam();
|
|
|
|
}
|
|
|
|
catch (AssertionError $e) {
|
|
|
|
$has_error = true;
|
|
|
|
$error_message = $e->getMessage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($_POST["request_validation"])) {
|
2019-09-24 23:08:38 +00:00
|
|
|
if (!canValidate($_SESSION["team"])) {
|
2019-09-23 22:47:04 +00:00
|
|
|
$has_error = true;
|
2019-09-09 23:48:52 +00:00
|
|
|
$error_message = "Votre équipe ne peut pas demander la validation : il manque soit des participants, soit des documents.";
|
2019-09-23 22:47:04 +00:00
|
|
|
}
|
|
|
|
else if (!isset($_POST["engage"])) {
|
|
|
|
$has_error = true;
|
|
|
|
$error_message = "Vous devez cocher la case qui vous engage à participer à l'intégralité des Correspondances.";
|
|
|
|
}
|
2019-09-09 23:48:52 +00:00
|
|
|
else
|
|
|
|
$_SESSION["team"]->setValidationStatus(ValidationStatus::WAITING);
|
|
|
|
}
|
|
|
|
|
2019-09-24 08:42:20 +00:00
|
|
|
/** @var Question[][] $questions_received */
|
|
|
|
$questions_received = [];
|
|
|
|
|
2019-09-09 23:48:52 +00:00
|
|
|
if (isset($_SESSION["user_id"]) && isset($_SESSION["team"]) && $_SESSION["team"] !== null) {
|
|
|
|
/**
|
|
|
|
* @var User $user
|
|
|
|
* @var Team $team
|
|
|
|
*/
|
|
|
|
$user = $_SESSION["user"];
|
|
|
|
$team = $_SESSION["team"];
|
|
|
|
|
2019-10-04 19:31:34 +00:00
|
|
|
$documents = $user->getAllDocuments();
|
2019-09-09 23:48:52 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
require_once "server_files/403.php";
|
|
|
|
|
2019-09-24 08:08:53 +00:00
|
|
|
if (isset($_GET["publish_videos"])) {
|
|
|
|
$team->setAllowPublish(!$team->allowPublish());
|
|
|
|
header("Location: /mon-equipe");
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
2019-09-09 23:48:52 +00:00
|
|
|
class MyTeam
|
|
|
|
{
|
|
|
|
public $name;
|
|
|
|
public $trigram;
|
2019-09-11 16:41:45 +00:00
|
|
|
public $problem;
|
|
|
|
/** @var Team */
|
2019-09-09 23:48:52 +00:00
|
|
|
private $team;
|
|
|
|
|
|
|
|
public function __construct($data)
|
|
|
|
{
|
|
|
|
foreach ($data as $key => $value)
|
|
|
|
$this->$key = htmlspecialchars($value);
|
|
|
|
|
|
|
|
$this->trigram = strtoupper($this->trigram);
|
|
|
|
$this->team = $_SESSION["team"];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function makeVerifications()
|
|
|
|
{
|
2019-09-24 08:08:53 +00:00
|
|
|
global $CONFIG;
|
|
|
|
|
2019-09-09 23:48:52 +00:00
|
|
|
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.");
|
2019-10-04 20:36:23 +00:00
|
|
|
ensure(preg_match("#^[\p{L} \d]+$#ui", $this->name), "Le nom de l'équipe ne doit pas comporter de caractères spéciaux.");
|
2019-09-09 23:48:52 +00:00
|
|
|
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.");
|
2019-10-04 19:41:12 +00:00
|
|
|
ensure(preg_match("#^[0-4]$#", $this->problem), "Le problème indiqué n'existe pas.");
|
2019-09-24 08:08:53 +00:00
|
|
|
ensure(date("Y-m-d H:i:s") <= $CONFIG->getInscriptionDate(), "Les inscriptions sont terminées.");
|
2019-09-09 23:48:52 +00:00
|
|
|
ensure($this->team->getValidationStatus() == ValidationStatus::NOT_READY, "Votre équipe est déjà validée ou en cours de validation.");
|
|
|
|
}
|
|
|
|
|
|
|
|
public function updateTeam()
|
|
|
|
{
|
2019-10-02 23:38:37 +00:00
|
|
|
global $DB, $URL_BASE;
|
2019-09-09 23:48:52 +00:00
|
|
|
|
|
|
|
$this->team->setName($this->name);
|
|
|
|
$this->team->setTrigram($this->trigram);
|
2019-09-11 16:41:45 +00:00
|
|
|
$this->team->setProblem($this->problem);
|
2019-09-09 23:48:52 +00:00
|
|
|
|
2019-10-02 23:38:37 +00:00
|
|
|
$DB->exec("UPDATE `teams` SET `problem` = " . $this->problem . " WHERE `id` = " . $this->team->getId() . ";");
|
|
|
|
|
2019-09-16 22:19:01 +00:00
|
|
|
header("Location: $URL_BASE/mon-equipe");
|
2019-09-09 23:48:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
require_once "server_files/views/mon_equipe.php";
|