Export des données

This commit is contained in:
Yohann 2019-10-18 22:23:00 +02:00
parent d989b1bf1a
commit 54fc6fd395
7 changed files with 264 additions and 56 deletions

View File

@ -42,6 +42,7 @@ $ROUTES["^connexion/?$"] = ["server_files/controllers/connexion.php"];
$ROUTES["^deconnexion/?$"] = ["server_files/controllers/deconnexion.php"];
$ROUTES["^envoyer-video-1$"] = ["server_files/controllers/envoyer_video.php"];
$ROUTES["^equipe/([A-Z]{3})/?$"] = ["server_files/controllers/equipe.php", "trigram"];
$ROUTES["^exporter-donnees/?$"] = ["server_files/controllers/exporter_donnees.php"];
$ROUTES["^file/([a-z0-9]{64})/?$"] = ["server_files/controllers/view_file.php", "file_id"];
$ROUTES["^informations/([0-9]*)/.*?$"] = ["server_files/controllers/informations.php", "id"];
$ROUTES["^inscription/?$"] = ["server_files/controllers/inscription.php"];

View File

@ -8,22 +8,26 @@ class SchoolClass
public static function getTranslatedName($class) {
switch ($class) {
case null:
return "Adulte";
case self::SECONDE:
return "Seconde ou inférieur";
case self::PREMIERE:
return "Première";
default:
case self::TERMINALE:
return "Terminale";
}
}
public static function getName($class) {
switch ($class) {
case null:
return null;
case self::SECONDE:
return "SECONDE";
case self::PREMIERE:
return "PREMIERE";
default:
case self::TERMINALE:
return "TERMINALE";
}
}
@ -34,8 +38,10 @@ class SchoolClass
return self::SECONDE;
case "PREMIERE":
return self::PREMIERE;
default:
case "TERMINALE":
return self::TERMINALE;
default:
return null;
}
}
}

View File

@ -0,0 +1,42 @@
<?php
if (!isset($_SESSION["user_id"]) || $_SESSION["role"] != Role::ADMIN)
require_once "server_files/403.php";
if (isset($_POST["export_user_data"])) {
$file_name = exportUserData();
header("Content-Type: text/csv");
header("Content-Disposition: inline; filename=\"Données utilisateurs.csv\"");
header("Content-Length: " . strval(filesize($file_name)));
readfile($file_name);
exit();
}
if (isset($_POST["export_team_data"])) {
$file_name = exportTeamData();
header("Content-Type: text/csv");
header("Content-Disposition: inline; filename=\"Données équipes.csv\"");
header("Content-Length: " . strval(filesize($file_name)));
readfile($file_name);
exit();
}
if (isset($_POST["export_problems_data"])) {
$file_name = exportProblemsData();
header("Content-Type: text/csv");
header("Content-Disposition: inline; filename=\"Données problèmes.csv\"");
header("Content-Length: " . strval(filesize($file_name)));
readfile($file_name);
exit();
}
require_once "server_files/views/exporter_donnees.php";

View File

@ -151,6 +151,130 @@ function getZipFile($problem, $team_id = -1)
return $file_name;
}
function exportUserData() {
global $DB, $YEAR;
$file_name = tempnam("tmp", "corres2math-");
$csv = "Identifiant,Nom,Prénom,E-mail,École,Ville,Pays,Classe,Description,Rôle,Équipe,Autorise l'envoi de mails,Date d'inscription\n";
$req = $DB->query("SELECT `id` FROM `users` WHERE `year` = $YEAR;");
while (($data = $req->fetch()) !== false) {
$user = User::fromId($data["id"]);
$csv .= $user->getId() . ",";
$csv .= $user->getSurname() . ",";
$csv .= $user->getFirstName() . ",";
$csv .= $user->getEmail() . ",";
$csv .= $user->getSchool() . ",";
$csv .= $user->getCity() . ",";
$csv .= $user->getCountry() . ",";
$csv .= SchoolClass::getTranslatedName($user->getClass()) . ",";
$csv .= $user->getDescription() . ",";
$csv .= Role::getTranslatedName($user->getRole()) . ",";
$csv .= ($user->getTeamId() == null ? "" : Team::fromId($user->getTeamId())->getTrigram()) . ",";
$csv .= ($user->doReceiveAnimathMails() ? "oui" : "non") . ",";
$csv .= $user->getInscriptionDate() . "\n";
}
file_put_contents($file_name, $csv, FILE_APPEND);
return $file_name;
}
function exportTeamData() {
global $DB, $YEAR;
$file_name = tempnam("tmp", "corres2math-");
$csv = "Identifiant,Nom,Trigramme,Problème,Encadrant,Participant 1,Participant 2,Participant 3,Participant 4,Participant 5,"
. "Date d'inscription,Autorise la publication,État de validation,Code d'accès\n";
$req = $DB->query("SELECT `id` FROM `teams` WHERE `year` = $YEAR ORDER BY `problem`;");
while (($data = $req->fetch()) !== false) {
$team = Team::fromId($data["id"]);
$csv .= $team->getId() . ",";
$csv .= $team->getName() . ",";
$csv .= $team->getTrigram() . ",";
$csv .= $team->getProblem() . ",";
$csv .= $team->getEncadrantId() . ",";
$csv .= $team->getParticipants()[0] . ",";
$csv .= $team->getParticipants()[1] . ",";
$csv .= $team->getParticipants()[2] . ",";
$csv .= $team->getParticipants()[3] . ",";
$csv .= $team->getParticipants()[4] . ",";
$csv .= $team->getInscriptionDate() . ",";
$csv .= $team->allowPublish() . ",";
$csv .= ValidationStatus::getTranslatedName($team->getValidationStatus()) . ",";
$csv .= $team->getAccessCode() . "\n";
}
file_put_contents($file_name, $csv, FILE_APPEND);
return $file_name;
}
function exportProblemsData() {
global $DB, $URL_BASE, $YEAR;
$file_name = tempnam("tmp", "corres2math-");
$csv = "Équipe,Problème,Lien,Équipe 1 ayant reçu la vidéo,"
. "Question 1,Pièce jointe,Réponse,Pièce jointe,"
. "Question 2,Pièce jointe,Réponse,Pièce jointe,"
. "Question 3,Pièce jointe,Réponse,Pièce jointe,"
. "Question 4,Pièce jointe,Réponse,Pièce jointe,"
. "Question 5,Pièce jointe,Réponse,Pièce jointe,"
. "Question 6,Pièce jointe,Réponse,Pièce jointe,"
. "Vidéo de réponse,"
. "Équipe 2 ayant reçu la vidéo,"
. "Question 1,Pièce jointe,Réponse,Pièce jointe,"
. "Question 2,Pièce jointe,Réponse,Pièce jointe,"
. "Question 3,Pièce jointe,Réponse,Pièce jointe,"
. "Question 4,Pièce jointe,Réponse,Pièce jointe,"
. "Question 5,Pièce jointe,Réponse,Pièce jointe,"
. "Question 6,Pièce jointe,Réponse,Pièce jointe,"
. "Vidéo de réponse\n";
$req = $DB->query("SELECT `id` FROM `teams` WHERE `validation_status` = 'VALIDATED' AND `year` = $YEAR ORDER BY `problem`;");
while (($data = $req->fetch()) !== false) {
$team = Team::fromId($data["id"]);
$video = Video::getVideo(Reason::SOLUTION, $team);
$questions_received = Question::getQuestionsTo($team);
$csv .= $team->getTrigram() . ",";
$csv .= $team->getProblem() . ",";
$csv .= ($video == null ? "" : $video->getLink()) . ",";
for ($i = 0; $i < 2; ++$i) {
/** @var Question[] $questions */
$questions = $questions_received[$i];
$asker = Team::fromId($questions[0]->getFrom());
$csv .= $asker->getTrigram() . ",";
for ($j = 0; $j < 6; ++$j) {
$question = $questions[$j];
if ($question == null) {
$csv .= ",,,,";
continue;
}
$csv .= $question->getQuestion() . ",";
$csv .= ($question->getAttachedFile() == null ? "" : $URL_BASE . "/file/" . $question->getAttachedFile()) . ',';
$csv .= $question->getAnswer() . ",";
$csv .= ($question->getAttachedFileAnswer() == null ? "" : $URL_BASE . "/file/" . $question->getAttachedFileAnswer()) . ',';
}
$answer = Video::getVideo($asker->getVideoTeamIds()[0] == $team->getId() ? Reason::ANSWER1 : Reason::ANSWER2,
$asker, Video::ACCEPTED);
$csv .= $answer == null ? "" : $answer->getLink();
$csv .= ($i == 0 ? "," : "\n");
}
}
file_put_contents($file_name, $csv, FILE_APPEND);
return $file_name;
}
function displayVideo($link)
{
if (preg_match("#(https?\://|)(www\.|)youtube\.com\/watch\?v=(.*)#", $link, $matches)) {

View File

@ -18,7 +18,8 @@
<option value="0">Pas de problème choisi</option>
<?php
for ($i = 1; $i <= 4; ++$i) { ?>
<option value="<?= $i ?>" <?= $team->getProblem() == $i ? "selected" : "" ?>>Problème <?= $i ?></option>
<option value="<?= $i ?>" <?= $team->getProblem() == $i ? "selected" : "" ?>>
Problème <?= $i ?></option>
<?php } ?>
</select>
</form>
@ -33,60 +34,61 @@
:</strong> <?= ValidationStatus::getTranslatedName($team->getValidationStatus()) ?>
</div>
<div class="alert alert-info">
<?php
if ($team->getEncadrantId() !== null) {
$encadrant = User::fromId($team->getEncadrantId());
$id = $encadrant->getId();
echo "<strong>Encadrant :</strong> <a href=\"$URL_BASE/informations/$id/" . $encadrant->getFirstName() . " " . $encadrant->getSurname() . "\">" . $encadrant->getFirstName() . " " . $encadrant->getSurname() . "</a><br />";
}
for ($i = 1; $i <= 5; ++$i) {
if ($team->getParticipants()[$i - 1] == NULL)
continue;
$participant = User::fromId($team->getParticipants()[$i - 1]);
$id = $participant->getId();
echo "<strong>Participant $i :</strong> <a href=\"$URL_BASE/informations/$id/" . $participant->getFirstName() . " " . $participant->getSurname() . "\">" . $participant->getFirstName() . " " . $participant->getSurname() . "</a><br />";
}
?>
<?php
if ($team->getEncadrantId() !== null) {
$encadrant = User::fromId($team->getEncadrantId());
$id = $encadrant->getId();
echo "<strong>Encadrant :</strong> <a href=\"$URL_BASE/informations/$id/" . $encadrant->getFirstName() . " " . $encadrant->getSurname() . "\">" . $encadrant->getFirstName() . " " . $encadrant->getSurname() . "</a><br />";
}
for ($i = 1; $i <= 5; ++$i) {
if ($team->getParticipants()[$i - 1] == NULL)
continue;
$participant = User::fromId($team->getParticipants()[$i - 1]);
$id = $participant->getId();
echo "<strong>Participant $i :</strong> <a href=\"$URL_BASE/informations/$id/" . $participant->getFirstName() . " " . $participant->getSurname() . "\">" . $participant->getFirstName() . " " . $participant->getSurname() . "</a><br />";
}
?>
</div>
<div class="alert alert-info">
<strong>Autorise Animath à diffuser les vidéos :</strong> <?= $team->allowPublish() ? "oui" : "non" ?>
</div>
<?php
if ($_SESSION["role"] == Role::ADMIN) { ?>
<? if ($team->getValidationStatus() == ValidationStatus::VALIDATED) { ?>
<hr/>
<!--suppress HtmlUnknownTarget -->
<a href="/suivi-correspondances#team-<?= $team->getTrigram() ?>"><button class="btn btn-primary btn-lg btn-block">
Aller aux vidéos de l'équipe</button></a><br />
<form method="POST">
<div class="form-group row">
<div class="form-group col-md-12">
<label for="other_teams">L'équipe va recevoir les questions des équipes suivantes (merci d'en
sélectionner exactement 2) :</label>
<select class="custom-select" id="other_teams" name="other_teams[]" multiple <?= Phase::getCurrentPhase() >= Phase::PHASE2 ? "disabled" : "" ?>>
<?php
/** @var Team $other_team */
foreach ($other_teams as $other_team) {
if ($other_team->getId() == $team->getId())
continue;
<? if ($team->getValidationStatus() == ValidationStatus::VALIDATED) { ?>
<hr/>
<!--suppress HtmlUnknownTarget -->
<a href="/suivi-correspondances#team-<?= $team->getTrigram() ?>">
<button class="btn btn-primary btn-lg btn-block">
Aller aux vidéos de l'équipe
</button>
</a><br/>
<form method="POST">
<div class="form-group row">
<div class="form-group col-md-12">
<label for="other_teams">L'équipe va recevoir les questions des équipes suivantes (merci d'en
sélectionner exactement 2) :</label>
<select class="custom-select" id="other_teams" name="other_teams[]"
multiple <?= Phase::getCurrentPhase() >= Phase::PHASE2 ? "disabled" : "" ?>>
<?php
/** @var Team $other_team */
foreach ($other_teams as $other_team) {
if ($other_team->getId() == $team->getId())
continue;
$team_name = $other_team->getName() . " (" . $other_team->getTrigram() . ")";
$team_id = $other_team->getId();
echo "<option value=\"$team_id\" " . (in_array($other_team->getId(), $team->getVideoTeamIds()) ? "selected" : "") . ">$team_name</option>\n";
}
?>
</select>
</div>
$team_name = $other_team->getName() . " (" . $other_team->getTrigram() . ")";
$team_id = $other_team->getId();
echo "<option value=\"$team_id\" " . (in_array($other_team->getId(), $team->getVideoTeamIds()) ? "selected" : "") . ">$team_name</option>\n";
}
?>
</select>
</div>
<div class="form-group row">
<?php if (Phase::getCurrentPhase() < Phase::PHASE2) { ?>
<input type="submit" class="btn btn-secondary btn-lg btn-block" name="update_video_teams"
value="Mettre à jour"/>
<?php } ?>
</div>
</form>
<?php } ?>
</div>
<div class="form-group row">
<?php if (Phase::getCurrentPhase() < Phase::PHASE2) { ?>
<input type="submit" class="btn btn-secondary btn-lg btn-block" name="update_video_teams"
value="Mettre à jour"/>
<?php } ?>
</div>
</form>
<?php } ?>
<hr/>
@ -100,7 +102,7 @@ if ($_SESSION["role"] == Role::ADMIN) { ?>
value="Télécharger l'archive"/>
</form>
<?php if ($team->getValidationStatus() == ValidationStatus::WAITING && $_SESSION["role"] == Role::ADMIN) { ?>
<?php if ($team->getValidationStatus() == ValidationStatus::WAITING) { ?>
<hr/>
<form method="POST">
<div class="form-group">
@ -111,11 +113,12 @@ if ($_SESSION["role"] == Role::ADMIN) { ?>
</div>
</div>
</form>
<?php
} elseif ($team->getValidationStatus() == ValidationStatus::NOT_READY && $_SESSION["role"] == Role::ADMIN) { ?>
<?php
} elseif ($team->getValidationStatus() == ValidationStatus::NOT_READY) { ?>
<hr/>
<form method="POST">
<input type="submit" class="btn btn-primary btn-lg btn-block" name="delete_team" value="Supprimer l'équipe" style="background-color: #ff2e34"/>
<input type="submit" class="btn btn-primary btn-lg btn-block" name="delete_team" value="Supprimer l'équipe"
style="background-color: #ff2e34"/>
</form>
<?php }

View File

@ -0,0 +1,29 @@
<?php
require_once "header.php";
?>
<div class="mt-4 mb-4">
<h1 class="display-4">Exporter les données</h1>
</div>
<form method="POST">
<input class="btn btn-primary btn-lg btn-block" type="submit" name="export_user_data"
value="Exporter les données utilisateurs"/>
</form>
<hr/>
<form method="POST">
<input class="btn btn-primary btn-lg btn-block" type="submit" name="export_team_data"
value="Exporter les données équipes"/>
</form>
<hr/>
<form method="POST">
<input class="btn btn-primary btn-lg btn-block" type="submit" name="export_problems_data"
value="Exporter les données problèmes"/>
</form>
<?php
require_once "footer.php";

View File

@ -83,10 +83,13 @@
</ul>
</li>
<li class="nav-item active">
<a class="nav-link" href="/ajouter-admin">Ajouter un administrateur</a>
<a class="nav-link" href="/ajouter-admin">Ajouter un admin</a>
</li>
<li class="nav-item active">
<a class="nav-link" href="/suivi-correspondances">Suivi des Correspondances</a>
</li>
<li class="nav-item active">
<a class="nav-link" href="/exporter-donnees">Exporter les données</a>
</li>
<?php } ?>
<?php } ?>