2019-09-09 23:48:52 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
if (!isset($_SESSION["role"]))
|
|
|
|
require_once "server_files/403.php";
|
|
|
|
|
|
|
|
$id = $_GET["id"];
|
|
|
|
$user = User::fromId($id);
|
|
|
|
|
2019-09-11 16:41:45 +00:00
|
|
|
if ($_SESSION["role"] != Role::ADMIN) {
|
2019-09-24 22:57:41 +00:00
|
|
|
if ($user->getId() != $_SESSION["user_id"])
|
2019-09-09 23:48:52 +00:00
|
|
|
require_once "server_files/403.php";
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($user === null)
|
|
|
|
require_once "server_files/404.php";
|
|
|
|
|
|
|
|
$team = Team::fromId($user->getTeamId());
|
|
|
|
|
2019-09-27 22:48:30 +00:00
|
|
|
$has_error = false;
|
|
|
|
$error_message = null;
|
|
|
|
|
|
|
|
if (isset($_POST["kick"])) {
|
|
|
|
if ($team == null) {
|
|
|
|
$has_error = true;
|
|
|
|
$error_message = "La personne à expulser n'est dans aucune équipe.";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
quitTeam($id);
|
|
|
|
$team = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($_POST["attribute_team"])) {
|
|
|
|
$attribute_team = new AttributeTeam($_POST);
|
|
|
|
try {
|
|
|
|
$attribute_team->makeVerifications();
|
|
|
|
$attribute_team->attribute();
|
|
|
|
} catch (AssertionError $e) {
|
|
|
|
$has_error = true;
|
|
|
|
$error_message = $e->getMessage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class AttributeTeam
|
|
|
|
{
|
2019-10-04 22:24:31 +00:00
|
|
|
private $team_id;
|
2019-09-27 22:48:30 +00:00
|
|
|
private $team;
|
|
|
|
private $min_null_index;
|
|
|
|
|
|
|
|
public function __construct($data)
|
|
|
|
{
|
2019-10-04 22:24:31 +00:00
|
|
|
$this->team_id = $data["team"];
|
|
|
|
$this->team = Team::fromId($this->team_id);
|
2019-09-27 22:48:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function makeVerifications()
|
|
|
|
{
|
|
|
|
global $user;
|
|
|
|
|
2019-10-04 22:24:31 +00:00
|
|
|
ensure($user->getConfirmEmailToken() == null, "Ce participant n'a pas encore validé son adresse e-mail.");
|
|
|
|
ensure($this->team_id != "no_team", "Vous n'avez pas choisi d'équipe.");
|
2019-09-27 22:48:30 +00:00
|
|
|
ensure($this->team != null, "Cette équipe n'existe pas.");
|
|
|
|
ensure($this->team->getValidationStatus() == ValidationStatus::NOT_READY, "Cette équipe est déjà validée ou en cours de validation.");
|
|
|
|
|
|
|
|
$role = $user->getRole();
|
|
|
|
for ($i = 1; $i <= $role == Role::ENCADRANT ? 1 : 5; ++$i) {
|
|
|
|
if (($role == Role::PARTICIPANT ? $this->team->getParticipants()[$i - 1] : $this->team->getEncadrantId()) == NULL)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->min_null_index = $i;
|
|
|
|
|
|
|
|
ensure($role == Role::PARTICIPANT && $this->min_null_index <= 5 || $role == Role::ENCADRANT && $this->min_null_index <= 2,
|
|
|
|
"Il n'y a plus de place pour vous dans l'équipe.");
|
|
|
|
}
|
|
|
|
|
|
|
|
public function attribute()
|
|
|
|
{
|
|
|
|
global $user, $team;
|
|
|
|
|
|
|
|
$user->setTeamId($this->team->getId());
|
|
|
|
|
|
|
|
if ($user->getRole() == Role::ENCADRANT)
|
|
|
|
$this->team->setEncadrant($user->getId());
|
|
|
|
else
|
|
|
|
$this->team->setParticipant($this->min_null_index, $user->getId());
|
|
|
|
|
|
|
|
Mailer::sendJoinTeamMail($user, $this->team);
|
|
|
|
|
|
|
|
$team = $this->team;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-12 10:18:15 +00:00
|
|
|
if ($team != null)
|
2019-10-06 11:29:20 +00:00
|
|
|
$documents = $user->getAllDocuments();
|
2019-09-09 23:48:52 +00:00
|
|
|
|
|
|
|
require_once "server_files/views/informations.php";
|