mirror of
https://gitlab.com/animath/si/plateforme.git
synced 2025-06-25 18:17:28 +02:00
Ajouts & correction de bugs
This commit is contained in:
@ -6,29 +6,110 @@ if (!isset($_SESSION["role"]))
|
||||
$id = $_GET["id"];
|
||||
$user = User::fromId($id);
|
||||
|
||||
if ($_SESSION["role"] != Role::ORGANIZER && $_SESSION["role"] != Role::ADMIN) {
|
||||
if ($user->getId() != $_SESSION["user_id"] && ($user->getTeamId() == null || $user->getTeamId() != $_SESSION["user"]->getTeamId()))
|
||||
if ($_SESSION["role"] != Role::ADMIN) {
|
||||
if ($user->getId() != $_SESSION["user_id"])
|
||||
require_once "server_files/403.php";
|
||||
}
|
||||
|
||||
if ($user === null)
|
||||
require_once "server_files/404.php";
|
||||
|
||||
if (isset($_POST["view_as"]) && $_SESSION["role"] == Role::ADMIN) {
|
||||
if (!isset($_SESSION["admin"]))
|
||||
$_SESSION["admin"] = $_SESSION["user_id"];
|
||||
$_SESSION["user_id"] = $user->getId();
|
||||
header("Location: /");
|
||||
exit();
|
||||
}
|
||||
|
||||
$team = Team::fromId($user->getTeamId());
|
||||
$tournaments = $user->getOrganizedTournaments();
|
||||
|
||||
if ($team != null) {
|
||||
$documents = $user->getAllDocuments($team->getTournamentId());
|
||||
if ($team->isSelectedForFinal())
|
||||
$documents_final = $user->getAllDocuments($FINAL->getId());
|
||||
$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();
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($_POST["view_as"]) && $_SESSION["role"] == Role::ADMIN) {
|
||||
if (!isset($_SESSION["admin"]))
|
||||
$_SESSION["admin"] = $_SESSION["user_id"];
|
||||
$_SESSION["user_id"] = $user->getId();
|
||||
header("Location: /");
|
||||
exit();
|
||||
}
|
||||
|
||||
if (isset($_POST["delete_account"]) && $team == null && $_SESSION["role"] == Role::ADMIN) {
|
||||
/** @var Document $document */
|
||||
foreach ($user->getAllDocuments($team->getTournamentId()) as $document)
|
||||
unlink($LOCAL_PATH . "/files/" . $document->getFileId());
|
||||
$DB->prepare("DELETE FROM `documents` WHERE `user` = ?;")->execute([$user->getId()]);
|
||||
$DB->prepare("DELETE FROM `users` WHERE `id` = ?;")->execute([$user->getId()]);
|
||||
header("Location: /");
|
||||
exit();
|
||||
}
|
||||
|
||||
class AttributeTeam
|
||||
{
|
||||
private $team_id;
|
||||
private $team;
|
||||
private $min_null_index;
|
||||
|
||||
public function __construct($data)
|
||||
{
|
||||
$this->team_id = $data["team"];
|
||||
$this->team = Team::fromId($this->team_id);
|
||||
}
|
||||
|
||||
public function makeVerifications()
|
||||
{
|
||||
global $user;
|
||||
|
||||
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.");
|
||||
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 ? 2 : 6; ++$i) {
|
||||
if (($role == Role::PARTICIPANT ? $this->team->getParticipants()[$i - 1] : $this->team->getEncadrants()[$i]) == 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($this->min_null_index, $user->getId());
|
||||
else
|
||||
$this->team->setParticipant($this->min_null_index, $user->getId());
|
||||
|
||||
Mailer::sendJoinTeamMail($user, $this->team, Tournament::fromId($this->team->getTournamentId()));
|
||||
|
||||
$team = $this->team;
|
||||
}
|
||||
}
|
||||
|
||||
if ($team != null)
|
||||
$documents = $user->getAllDocuments($team->getTournamentId());
|
||||
|
||||
require_once "server_files/views/informations.php";
|
||||
|
Reference in New Issue
Block a user