Possibilité de supprimer un participant

This commit is contained in:
Yohann 2019-10-27 00:18:50 +02:00
parent faae8613cf
commit ac1b3ec7e8
2 changed files with 43 additions and 24 deletions

View File

@ -49,6 +49,16 @@ if (isset($_POST["view_as"]) && $_SESSION["role"] == Role::ADMIN) {
exit(); exit();
} }
if (isset($_POST["delete_account"]) && $team == null && $_SESSION["role"] == Role::ADMIN) {
/** @var Document $document */
foreach ($user->getAllDocuments() 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 class AttributeTeam
{ {
private $team_id; private $team_id;

View File

@ -18,15 +18,15 @@ if (!$has_error) {
} }
?> ?>
<div class="alert alert-info"> <div class="alert alert-info">
<strong>Rôle :</strong> <?= Role::getTranslatedName($user->getRole()) ?> <strong>Rôle :</strong> <?= Role::getTranslatedName($user->getRole()) ?>
</div> </div>
<?php if ($user->getRole() == Role::PARTICIPANT || $user->getRole() == Role::ENCADRANT) { ?> <?php if ($user->getRole() == Role::PARTICIPANT || $user->getRole() == Role::ENCADRANT) { ?>
<div class="alert alert-info"> <div class="alert alert-info">
<strong>Équipe <strong>Équipe
:</strong> <?= $team === null ? "Pas d'équipe" : "<a href=\"/equipe/" . $team->getTrigram() . "\">" :</strong> <?= $team === null ? "Pas d'équipe" : "<a href=\"/equipe/" . $team->getTrigram() . "\">"
. $team->getName() . " (" . $team->getTrigram() . ")</a>" ?> . $team->getName() . " (" . $team->getTrigram() . ")</a>" ?>
<?php if ($team == null) { ?> <?php if ($team == null) { ?>
<form method="POST"> <form method="POST">
<div class="form-group row"> <div class="form-group row">
@ -34,31 +34,31 @@ if (!$has_error) {
<label for="team">Attribuer une équipe :</label> <label for="team">Attribuer une équipe :</label>
<select class="custom-select" id="team" name="team"> <select class="custom-select" id="team" name="team">
<option value="no_team">Choisir une équipe ...</option> <option value="no_team">Choisir une équipe ...</option>
<?php <?php
/** @var Team $t */ /** @var Team $t */
foreach (Team::getAllTeams(-1) as $t) { foreach (Team::getAllTeams(-1) as $t) {
if ($t->getValidationStatus() != ValidationStatus::NOT_READY) if ($t->getValidationStatus() != ValidationStatus::NOT_READY)
continue; continue;
$team_name = $t->getName() . " (" . $t->getTrigram() . "), " $team_name = $t->getName() . " (" . $t->getTrigram() . "), "
. ($t->getProblem() == 0 ? "pas de problème choisi" :"problème " . $t->getProblem()); . ($t->getProblem() == 0 ? "pas de problème choisi" : "problème " . $t->getProblem());
$team_id = $t->getId(); $team_id = $t->getId();
echo "<option value=\"$team_id\">$team_name</option>\n"; echo "<option value=\"$team_id\">$team_name</option>\n";
} }
?> ?>
</select> </select>
</div> </div>
</div> </div>
<div class="form-group row"> <div class="form-group row">
<?php if (Phase::getCurrentPhase() < Phase::PHASE2) { ?> <?php if (Phase::getCurrentPhase() < Phase::PHASE2) { ?>
<input type="submit" class="btn btn-secondary btn-lg btn-block" name="attribute_team" <input type="submit" class="btn btn-secondary btn-lg btn-block" name="attribute_team"
value="Affecter dans une équipe"/> value="Affecter dans une équipe"/>
<?php } ?> <?php } ?>
</div> </div>
</form> </form>
<?php } elseif ($team->getValidationStatus() == ValidationStatus::NOT_READY) { ?> <?php } elseif ($team->getValidationStatus() == ValidationStatus::NOT_READY) { ?>
<form method="POST"> <form method="POST">
<input type="hidden" name="kick" /> <input type="hidden" name="kick"/>
<a href="#" onclick="this.parentNode.submit()">Virer de l'équipe</a> <a href="#" onclick="this.parentNode.submit()">Virer de l'équipe</a>
</form> </form>
<?php } ?> <?php } ?>
@ -94,16 +94,25 @@ if (!$has_error) {
<div class="mt-4 mb-4"> <div class="mt-4 mb-4">
<h1 class="display-5">Autorisation de droit à l'image :</h1> <h1 class="display-5">Autorisation de droit à l'image :</h1>
</div> </div>
<?php <?php
printDocuments($documents); printDocuments($documents);
} }
if ($_SESSION["role"] == Role::ADMIN && $_SESSION["user_id"] != $user->getId()) { ?> if ($_SESSION["role"] == Role::ADMIN && $_SESSION["user_id"] != $user->getId()) {
<hr /> if ($user->getRole() != Role::ADMIN && $team == null) { ?>
<hr/>
<form method="POST">
<input type="submit" name="delete_account" class="btn btn-secondary btn-lg btn-block"
style="background-color: #ff2e34" value="Supprimer le compte"/>
</form>
<?php } ?>
<hr/>
<form method="POST"> <form method="POST">
<input type="submit" name="view_as" class="btn btn-secondary btn-lg btn-block" style="background-color: #ff2e34" <input type="submit" name="view_as" class="btn btn-secondary btn-lg btn-block" style="background-color: #2ba42b"
value="Afficher le site en tant que <?= $user->getFirstName() . " " . $user->getSurname() ?>" /> value="Afficher le site en tant que <?= $user->getFirstName() . " " . $user->getSurname() ?>"/>
</form> </form>
<?php } <?php }