From 606ad5886f8af5828c5edaa7826de7f9074810a8 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Tue, 14 Jan 2020 17:16:27 +0100 Subject: [PATCH] Validation des paiements faites par les admins --- server_files/classes/User.php | 16 ++++++++++++ server_files/controllers/paiement.php | 6 +++-- server_files/services/mail.php | 7 ++++- .../request_payment_validation.html | 26 +++++++++++++++++++ 4 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 server_files/services/mail_templates/request_payment_validation.html diff --git a/server_files/classes/User.php b/server_files/classes/User.php index 64b3b8a..96b310f 100644 --- a/server_files/classes/User.php +++ b/server_files/classes/User.php @@ -101,6 +101,22 @@ class User return $admins; } + public static function getAdmins() + { + global $DB, $YEAR; + $users = []; + $req = $DB->query("SELECT * FROM `users` WHERE (`role` = 'ADMIN') " + . "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 getAllUsers() { global $DB, $YEAR; diff --git a/server_files/controllers/paiement.php b/server_files/controllers/paiement.php index 6224f8f..e0804f3 100644 --- a/server_files/controllers/paiement.php +++ b/server_files/controllers/paiement.php @@ -46,13 +46,13 @@ class Pay { ensure($payment->getValidationStatus() == ValidationStatus::NOT_READY, "Un paiement est déjà initié."); ensure($this->method != PaymentMethod::NOT_PAID, "Vous n'avez pas payé."); - ensure($this->method == PaymentMethod::SCHOLARSHIP || ($this->infos != null && sizeof($this->infos) > 0), "Merci d'indiquer des informations pour retrouver votre paiement."); + ensure($this->method == PaymentMethod::SCHOLARSHIP || ($this->infos != null && strlen($this->infos) > 0), "Merci d'indiquer des informations pour retrouver votre paiement."); ensure($this->method != PaymentMethod::SCHOLARSHIP || ($this->scholarship != null && !$this->scholarship["error"]), "Si vous êtes boursier, vous devez indiquer votre notifcation de bourse (une erreur est survenue)."); } public function submit() { - global $DB, $LOCAL_PATH, $payment, $tournament; + global $DB, $LOCAL_PATH, $payment, $user, $team, $tournament; $payment->setMethod($this->method); $payment->setAmount($this->method == PaymentMethod::SCHOLARSHIP ? 0 : $tournament->getPrice()); @@ -72,6 +72,8 @@ class Pay { } else $payment->setTransactionInfos($this->infos); + + Mailer::requestPaymentValidation($user, $team, $tournament, $payment); } } diff --git a/server_files/services/mail.php b/server_files/services/mail.php index e3a1a83..4c927ae 100644 --- a/server_files/services/mail.php +++ b/server_files/services/mail.php @@ -135,6 +135,7 @@ class Mailer $content = self::getTemplate("request_payment_validation"); $content = preg_replace("#{USER_FIRST_NAME}#", $user->getFirstName(), $content); $content = preg_replace("#{USER_SURNAME}#", $user->getSurname(), $content); + $content = preg_replace("#{USER_ID}#", $user->getId(), $content); $content = preg_replace("#{TEAM_NAME}#", $team->getName(), $content); $content = preg_replace("#{TRIGRAM}#", $team->getTrigram(), $content); $content = preg_replace("#{TOURNAMENT_NAME}#", $tournament->getName(), $content); @@ -145,7 +146,11 @@ class Mailer else $content = preg_replace("#{PAYMENT_INFOS}#", $payment->getTransactionInfos(), $content); - self::sendMail($user->getEmail(), "Demande de validation de paiement pour le tournoi " . $tournament->getName() . " – TFJM² $YEAR", $content); + foreach (User::getAdmins() as $admin) { + $content = preg_replace("#{FIRST_NAME}#", $admin->getFirstName(), $content); + $content = preg_replace("#{SURNAME}#", $admin->getSurname(), $content); + self::sendMail($admin->getEmail(), "Demande de validation de paiement pour le tournoi " . $tournament->getName() . " – TFJM² $YEAR", $content); + } } public static function sendValidatePayment(User $user, Team $team, Tournament $tournament, Payment $payment, $message) diff --git a/server_files/services/mail_templates/request_payment_validation.html b/server_files/services/mail_templates/request_payment_validation.html new file mode 100644 index 0000000..8c23f21 --- /dev/null +++ b/server_files/services/mail_templates/request_payment_validation.html @@ -0,0 +1,26 @@ + + + + + + Demande de validation de paiement pour le TFJM² {YEAR} + + +Bonjour {FIRST_NAME} {SURNAME},
+
+{USER_FIRST_NAME} {USER_SURNAME} de l'équipe {TEAM_NAME} ({TRIGRAM}) annonce avoir réglé sa participation pour le tournoi {TOURNAMENT_NAME}. +Les informations suivantes ont été communiquées :

+Équipe : {TEAM_NAME} ({TRIGRAM})
+Tournoi : {TOURNAMENT_NAME}
+Moyen de paiement : {PAYMENT_METHOD}
+Montant : {AMOUNT} €
+Informations sur le paiement : {PAYMENT_INFOS}
+
+Vous pouvez désormais vérifier ces informations, puis valider (ou non) le paiement sur +la page associée à ce participant. +
+Cordialement, +
+Le comité national d'organisation du TFJM2 + + \ No newline at end of file