Ajouts & correction de bugs

This commit is contained in:
Yohann D'ANELLO 2019-12-26 22:30:42 +01:00
parent e9f10ca14f
commit da8efde057
16 changed files with 363 additions and 32 deletions

View File

@ -41,6 +41,9 @@ $ROUTES["^inscription/?$"] = ["server_files/controllers/inscription.php"];
$ROUTES["^mon-compte/?$"] = ["server_files/controllers/mon_compte.php"];
$ROUTES["^mon-equipe/(modifier)/?$"] = ["server_files/controllers/mon_equipe.php", "modifier"];
$ROUTES["^mon-equipe/?$"] = ["server_files/controllers/mon_equipe.php"];
$ROUTES["^organisateurs"] = ["server_files/controllers/organisateurs.php"];
$ROUTES["^profils/?$"] = ["server_files/controllers/profils.php"];
$ROUTES["^profils-(orphelins)/?$"] = ["server_files/controllers/profils.php", "orphans"];
$ROUTES["^rejoindre_equipe/?$"] = ["server_files/controllers/rejoindre_equipe.php"];
$ROUTES["^solutions/?$"] = ["server_files/controllers/solutions.php"];
$ROUTES["^solutions_orga/?$"] = ["server_files/controllers/solutions_orga.php"];

View File

@ -4,9 +4,13 @@ require_once "config.php";
require_once "views/header.php";
http_response_code(403);
?>
echo "<h1>Vous n'êtes pas autorisé à accéder à cette page.</h1>";
<div class="alert alert-danger mt-4 mb-4">
<h2 class="display-5">
Vous n'êtes pas autorisé à accéder à cette page.
</h2>
</div>
<?php
require_once "views/footer.php";
exit();

View File

@ -4,9 +4,13 @@ require_once "config.php";
require_once "views/header.php";
http_response_code(404);
?>
echo "<h1>Cette page n'existe pas.</h1>";
<div class="alert alert-danger mt-4 mb-4">
<h2 class="display-5">
Cette page n'existe pas.
</h2>
</div>
<?php
require_once "views/footer.php";
exit();

View File

@ -182,4 +182,20 @@ class Team
{
return $this->year;
}
public static function getAllTeams($only_not_validated = false)
{
global $DB, $YEAR;
$req = $DB->query("SELECT * FROM `teams` WHERE " . ($only_not_validated ? "`validation_status` = 'NOT_READY' AND " : "") . "`year` = $YEAR;");
$teams = [];
while (($data = $req->fetch()) != false) {
$team = new Team();
$team->fill($data);
$teams[] = $team;
}
return $teams;
}
}

View File

@ -86,6 +86,52 @@ class User
$this->forgotten_password = $data["forgotten_password"];
$this->inscription_date = $data["inscription_date"];
}
public static function getOrganizers()
{
global $DB, $YEAR;
$admins = [];
$req = $DB->query("SELECT * FROM `users` WHERE `role` = 'ORGANIZER' OR `role` = 'ADMIN' AND `year` = $YEAR;");
while (($data = $req->fetch()) !== false) {
$admin = new User();
$admin->fill($data);
$admins[] = $admin;
}
return $admins;
}
public static function getAllUsers()
{
global $DB, $YEAR;
$users = [];
$req = $DB->query("SELECT * FROM `users` WHERE (`role` = 'PARTICIPANT' OR `role` = 'ENCADRANT') "
. "AND `year` = $YEAR ORDER BY `role`, `inscription_date`;");
while (($data = $req->fetch()) !== false) {
$orphan = new User();
$orphan->fill($data);
$users[] = $orphan;
}
return $users;
}
public static function getOrphanUsers()
{
global $DB, $YEAR;
$orphans = [];
$req = $DB->query("SELECT * FROM `users` WHERE `role` != 'ADMIN' AND `team_id` IS NULL "
. "AND `year` = $YEAR ORDER BY `role`, `inscription_date`;");
while (($data = $req->fetch()) !== false) {
$orphan = new User();
$orphan->fill($data);
$orphans[] = $orphan;
}
return $orphans;
}
public function getEmail()
{

View File

@ -6,14 +6,41 @@ 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";
$team = Team::fromId($user->getTeamId());
$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"];
@ -22,13 +49,67 @@ if (isset($_POST["view_as"]) && $_SESSION["role"] == Role::ADMIN) {
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());
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";

View File

@ -3,7 +3,7 @@
$has_error = false;
$error_message = null;
if (isset($_POST["submitted"])) {
if (isset($_POST["register"])) {
$user = new NewUser($_POST);
try {

View File

@ -0,0 +1,8 @@
<?php
if ($_SESSION["role"] != Role::ADMIN)
require_once "server_files/403.php";
$organizers = User::getOrganizers();
require_once "server_files/views/organisateurs.php";

View File

@ -0,0 +1,9 @@
<?php
if (!isset($_SESSION["user_id"]) || $_SESSION["role"] != Role::ADMIN)
require_once "server_files/403.php";
$orphans = isset($_GET["orphans"]);
$users = $orphans ? User::getOrphanUsers() : User::getAllUsers();
require_once "server_files/views/profils.php";

View File

@ -30,7 +30,7 @@ function loadUserValues()
}
}
function quitTeam()
function quitTeam($user_id = -1)
{
global $DB, $URL_BASE;
@ -38,7 +38,10 @@ function quitTeam()
/** @var User $user */
$user = $_SESSION["user"];
if ($user_id == -1)
$user_id = $user->getId();
else
$user = User::fromId($user_id);
$role = $user->getRole();
if ($role == Role::ADMIN || $role == Role::ORGANIZER)
@ -161,17 +164,22 @@ function canValidate(Team $team, Tournament $tournament)
function printDocuments($documents)
{
global $URL_BASE;
if (sizeof($documents) == 0) {
echo "<div class=\"alert alert-warning\">\nPas de document envoyé pour le moment.\n</div>\n";
return;
}
echo "<div class=\"alert alert-info\">\n";
foreach ($documents as $document) {
$file_id = $document->getFileId();
$user = User::fromId($document->getUserId());
$surname = $user->getSurname();
$first_name = $user->getFirstName();
$name = DocumentType::getTranslatedName($document->getType());
$name = "Autorisation de droit à l'image";
$version = $document->getVersion();
echo "$name de $first_name $surname (version $version) : <a href=\"/file/$file_id\">Télécharger</a><br />";
echo "$name de $first_name $surname (version $version) : <a href=\"/file/$file_id\"><strong>Télécharger</strong></a><br />\n";
}
echo "</div>\n";
}
function getZipFile($document_type, $tournament_id, $team_id = -1)

View File

@ -35,8 +35,16 @@ require_once "header.php";
</div>
</div>
<div class="form-row">
<div class="form-group col-md-12">
<label for="admin">Compte administrateur :</label>
<input type="checkbox" id="admin" name="admin"
value="<?php if (isset($orga)) echo $orga->admin ?>"/>
</div>
</div>
<div class="form-group row">
<input class="btn btn-primary btn-lg btn-block" name="add_admin" type="submit" value="Ajouter un administrateur" />
<input class="btn btn-primary btn-lg btn-block" name="add_admin" type="submit" value="Ajouter un organisateur" />
</div>
</form>

View File

@ -39,7 +39,7 @@
<div class="alert alert-info">
<?php
for ($i = 1; $i <= 2; ++$i) {
if ($team->getEncadrants()[$i] == NULL)
if ($team->getEncadrants()[$i - 1] == NULL)
continue;
$encadrant = User::fromId($team->getEncadrants()[$i - 1]);
$id = $encadrant->getId();

View File

@ -28,6 +28,11 @@
</li>
<li class="nav-item active">
<a class="nav-link" href="/tournois">Liste des tournois</a>
<ul class="deroule">
<li class="nav-item active"><a class="nav-link" href="/profils-orphelins">Profils orphelins</a></li>
<li class="nav-item active"><a class="nav-link" href="/profils">Tous les profils</a></li>
<li class="nav-item active"><a class="nav-link" href="/organisateurs">Organisateurs</a></li>
</ul>
</li>
<?php if (isset($_SESSION["user_id"])) { ?>
<li class="nav-item active">

View File

@ -112,7 +112,7 @@ if ($user->getRole() == Role::ADMIN || $user->getRole() == Role::ORGANIZER) {
echo "<div class=\"alert alert-info\">Organise le tournoi <a href=\"/tournoi/" . $tournament->getName(). "\">" . $tournament->getName() . "</a></div>";
}
}
elseif ($user->getRole() == Role::PARTICIPANT || $user->getRole() == Role::ENCADRANT) { ?>
elseif (($user->getRole() == Role::PARTICIPANT || $user->getRole() == Role::ENCADRANT) && $user->getTeamId() !== NULL) { ?>
<h2>Autorisations</h2>
<?php

View File

@ -0,0 +1,76 @@
<?php
require_once "header.php";
?>
<div class="mt-4 mb-4">
<h1 class="display-4">Liste des organisateurs</h1>
</div>
<hr />
<table class="table table-striped table-bordered table-hover">
<thead>
<tr>
<th scope="col">
Nom
</th>
<th scope="col">
Prénom
</th>
<th scope="col">
Adresse e-mail
</th>
<th>
Est administrateur
</th>
</tr>
</thead>
<tbody>
<?php
/** @var User $orga */
foreach ($organizers as $orga) {
?>
<tr>
<td>
<a href="/informations/<?= $orga->getId() ?>/<?= $orga->getFirstName() . " " . $orga->getSurname() ?>">
<?= $orga->getSurname() ?>
</a>
</td>
<td>
<a href="/informations/<?= $orga->getId() ?>/<?= $orga->getFirstName() . " " . $orga->getSurname() ?>">
<?= $orga->getFirstName() ?>
</a>
</td>
<td>
<a href="mailto:<?= $orga->getEmail() ?>">
<?= $orga->getEmail() ?>
</a>
</td>
<td>
<?= $orga->getRole() == Role::ADMIN ? "oui" : "non" ?>
</td>
</tr>
<?php
}
?>
</tbody>
<tfoot>
<tr>
<th>
Nom
</th>
<th>
Prénom
</th>
<th>
Adresse e-mail
</th>
<th>
Est administrateur
</th>
</tr>
</tfoot>
</table>
<?php
require_once "footer.php";

View File

@ -0,0 +1,63 @@
<?php
require_once "header.php";
?>
<div class="mt-4 mb-4">
<h2 class="display-3"><?= $orphans ? "Profils orphelins" : "Tous les profils" ?></h2>
</div>
<div>
Cette page recense tous les utilisateurs inscrits<?= $orphans ? " mais qui n'ont pas rejoint d'équipe" : "" ?>.
</div>
<br />
<table class="table table-striped table-bordered table-hover">
<thead>
<tr>
<th scope="col">
Nom
</th>
<th scope="col">
Rôle
</th>
<th scope="col">
Inscrit le
</th>
</tr>
</thead>
<tbody>
<?php
/** @var User $user */
foreach ($users as $user) {
?>
<tr>
<th scope="row">
<a href="/informations/<?= $user->getId() . "/" . $user->getFirstName() . " " . $user->getSurname() ?>">
<?= $user->getFirstName() . " " . $user->getSurname() ?>
</a>
</th>
<td><?= Role::getTranslatedName($user->getRole()) ?></td>
<td><?= formatDate($user->getInscriptionDate(), true) ?></td>
</tr>
<?php
}
?>
</tbody>
<tfoot>
<tr>
<th scope="col">
Nom
</th>
<th scope="col">
Rôle
</th>
<th scope="col">
Inscrit le
</th>
</tr>
</tfoot>
</table>
<?php
require_once "footer.php";