diff --git a/server_files/controllers/informations.php b/server_files/controllers/informations.php
index 6863dec..6d9cb91 100644
--- a/server_files/controllers/informations.php
+++ b/server_files/controllers/informations.php
@@ -16,6 +16,12 @@ if ($user === null)
$team = Team::fromId($user->getTeamId());
+if ($team != null) {
+ $documents = $user->getAllDocuments($team->getTournamentId());
+ $payment = $user->getPayment();
+ $tournament = Tournament::fromId($team->getTournamentId());
+}
+
$has_error = false;
$error_message = null;
@@ -41,6 +47,17 @@ if (isset($_POST["attribute_team"])) {
}
}
+if (isset($_POST["validate_payment"])) {
+ $validate_payment = new ValidatePayment($_POST);
+ try {
+ $validate_payment->makeVerifications();
+ $validate_payment->validate();
+ } 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"];
@@ -109,7 +126,39 @@ class AttributeTeam
}
}
-if ($team != null)
- $documents = $user->getAllDocuments($team->getTournamentId());
+class ValidatePayment
+{
+ private $accept, $reject;
+ private $message;
+ private $payment;
+
+ public function __construct($data)
+ {
+ global $user;
+
+ foreach ($data as $key => $value)
+ $this->$key = $value;
+
+ $this->payment = $user->getPayment();
+ }
+
+ public function makeVerifications()
+ {
+ ensure($this->payment->getValidationStatus() == ValidationStatus::WAITING, "Le paiement n'était pas en attente.");
+ ensure(isset($this->accept) ^ isset($this->reject), "La sélection de validation est invalide.");
+ }
+
+ public function validate()
+ {
+ global $user, $team, $tournament;
+
+ if ($this->accept)
+ $this->payment->setValidationStatus(ValidationStatus::VALIDATED);
+ else
+ $this->payment->setValidationStatus(ValidationStatus::NOT_READY);
+
+ Mailer::sendValidatePayment($user, $team, $tournament, $this->payment, $this->message);
+ }
+}
require_once "server_files/views/informations.php";
diff --git a/server_files/controllers/mon_compte.php b/server_files/controllers/mon_compte.php
index 69ec017..4f709ca 100644
--- a/server_files/controllers/mon_compte.php
+++ b/server_files/controllers/mon_compte.php
@@ -11,7 +11,8 @@ if (!isset($_SESSION["user_id"]))
$user = $_SESSION["user"];
$team = $_SESSION["team"];
-$tournament = Tournament::fromId($team->getTournamentId());
+if ($team != null)
+ $tournament = Tournament::fromId($team->getTournamentId());
$has_error = false;
$error_message = null;
@@ -208,8 +209,10 @@ class SendDocument
}
}
-$documents = $user->getAllDocuments($team->getTournamentId());
-if ($team->isSelectedForFinal())
- $documents_final = $user->getAllDocuments($FINAL->getId());
+if ($team != null) {
+ $documents = $user->getAllDocuments($team->getTournamentId());
+ if ($team->isSelectedForFinal())
+ $documents_final = $user->getAllDocuments($FINAL->getId());
+}
require_once "server_files/views/mon_compte.php";
diff --git a/server_files/services/mail.php b/server_files/services/mail.php
index 18be95b..e3a1a83 100644
--- a/server_files/services/mail.php
+++ b/server_files/services/mail.php
@@ -127,4 +127,47 @@ class Mailer
self::sendMail($organizer->getEmail(), "Ajout d'un organisateur pour le tournoi " . $tournament->getName() . " – TFJM² $YEAR", $content);
}
+
+ public static function requestPaymentValidation(User $user, Team $team, Tournament $tournament, Payment $payment)
+ {
+ global $YEAR, $URL_BASE;
+
+ $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("#{TEAM_NAME}#", $team->getName(), $content);
+ $content = preg_replace("#{TRIGRAM}#", $team->getTrigram(), $content);
+ $content = preg_replace("#{TOURNAMENT_NAME}#", $tournament->getName(), $content);
+ $content = preg_replace("#{AMOUNT}#", $payment->getAmount(), $content);
+ $content = preg_replace("#{PAYMENT_METHOD}#", PaymentMethod::getTranslatedName($payment->getMethod()), $content);
+ if ($payment->getMethod() == PaymentMethod::SCHOLARSHIP)
+ $content = preg_replace("#{PAYMENT_INFOS}#", "getTransactionInfos() . "\">Voir la notification de bourse", $content);
+ 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);
+ }
+
+ public static function sendValidatePayment(User $user, Team $team, Tournament $tournament, Payment $payment, $message)
+ {
+ global $YEAR, $URL_BASE;
+
+ $content = self::getTemplate($payment->getValidationStatus() == ValidationStatus::VALIDATED ? "validate_payment" : "unvalidate_payment");
+ $content = preg_replace("#{FIRST_NAME}#", $user->getFirstName(), $content);
+ $content = preg_replace("#{SURNAME}#", $user->getSurname(), $content);
+ $content = preg_replace("#{TEAM_NAME}#", $team->getName(), $content);
+ $content = preg_replace("#{TRIGRAM}#", $team->getTrigram(), $content);
+ $content = preg_replace("#{TOURNAMENT_NAME}#", $tournament->getName(), $content);
+ $content = preg_replace("#{AMOUNT}#", $payment->getAmount(), $content);
+ $content = preg_replace("#{PAYMENT_METHOD}#", PaymentMethod::getTranslatedName($payment->getMethod()), $content);
+ if ($payment->getMethod() == PaymentMethod::SCHOLARSHIP)
+ $content = preg_replace("#{PAYMENT_INFOS}#", "getTransactionInfos() . "\">Voir la notification de bourse", $content);
+ else
+ $content = preg_replace("#{PAYMENT_INFOS}#", $payment->getTransactionInfos(), $content);
+ if (isset($message) && strlen($message) > 0) {
+ $content = preg_replace("#{MESSAGE}#", "L'équipe d'organisation vous transmet les informations suivantes :
" . $message . "
", $content);
+ }
+
+ self::sendMail($user->getEmail(), "Paiement pour le tournoi " . $tournament->getName() . " – TFJM² $YEAR", $content);
+ }
}
diff --git a/server_files/services/mail_templates/unvalidate_payment.html b/server_files/services/mail_templates/unvalidate_payment.html
new file mode 100644
index 0000000..c6e99ff
--- /dev/null
+++ b/server_files/services/mail_templates/unvalidate_payment.html
@@ -0,0 +1,24 @@
+
+
+
+