1
0
mirror of https://gitlab.com/animath/si/plateforme.git synced 2024-12-27 06:22:23 +00:00
plateforme-tfjm2/server_files/services/mail.php
2019-09-09 00:41:52 +02:00

131 lines
5.1 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
class Mailer
{
private static function sendMail($email, $subject, $content, $from = "contact")
{
global $MAIL_DOMAIN, $URL_BASE, $YEAR;
$content = preg_replace("#{URL_BASE}#", $URL_BASE, $content);
$content = preg_replace("#{YEAR}#", $YEAR, $content);
$headers = "From: \"Contact TFJM²\" <" . $from . "@" . $MAIL_DOMAIN . ">\r\n";
$headers .= "Reply-To: \"Contact TFJM²\" <contact@" . $MAIL_DOMAIN . ">\r\n";
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";
mail($email, $subject, $content, $headers);
}
private static function getTemplate($name)
{
global $LOCAL_PATH;
return file_get_contents("$LOCAL_PATH/server_files/services/mail_templates/$name.html");
}
public static function sendRegisterMail(NewUser $new_user)
{
global $YEAR;
$content = self::getTemplate("register");
$content = preg_replace("#{FIRST_NAME}#", $new_user->first_name, $content);
$content = preg_replace("#{SURNAME}#", $new_user->surname, $content);
$content = preg_replace("#{TOKEN}#", $new_user->confirm_email_token, $content);
self::sendMail($new_user->email, "Inscription au TFJM² $YEAR", $content);
}
public static function sendConfirmEmail(User $user)
{
global $YEAR;
$content = self::getTemplate("confirm_email");
$content = preg_replace("#{FIRST_NAME}#", $user->getFirstName(), $content);
$content = preg_replace("#{SURNAME}#", $user->getSurname(), $content);
$content = preg_replace("#{TOKEN}#", $user->getConfirmEmailToken(), $content);
self::sendMail($user->getEmail(), "Confirmation d'adresse e-mail TFJM² $YEAR", $content);
}
public static function sendChangeEmailAddressMail(User $user)
{
$content = self::getTemplate("change_email_address");
$content = preg_replace("#{FIRST_NAME}#", $user->getFirstName(), $content);
$content = preg_replace("#{SURNAME}#", $user->getSurname(), $content);
$content = preg_replace("#{TOKEN}#", $user->getConfirmEmailToken(), $content);
self::sendMail($user->getEmail(), "Changement d'adresse e-mail TFJM²", $content);
}
public static function sendForgottenPasswordProcedureMail(User $user)
{
$content = self::getTemplate("forgotten_password");
$content = preg_replace("#{FIRST_NAME}#", $user->getFirstName(), $content);
$content = preg_replace("#{SURNAME}#", $user->getSurname(), $content);
$content = preg_replace("#{TOKEN}#", $user->getForgottenPasswordToken(), $content);
self::sendMail($user->getEmail(), "Mot de passe oublié TFJM²", $content);
}
public static function sendChangePasswordMail(User $user)
{
$content = self::getTemplate("change_password");
$content = preg_replace("#{FIRST_NAME}#", $user->getFirstName(), $content);
$content = preg_replace("#{SURNAME}#", $user->getSurname(), $content);
self::sendMail($user->getEmail(), "Mot de passe changé TFJM²", $content);
}
public static function sendAddTeamMail(User $user, Team $team, Tournament $tournament)
{
global $YEAR;
$content = self::getTemplate("add_team");
$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("#{ACCESS_CODE}#", $team->getAccessCode(), $content);
self::sendMail($user->getEmail(), "Ajout d'une équipe TFJM² $YEAR", $content);
}
public static function sendJoinTeamMail(User $user, Team $team, Tournament $tournament)
{
global $YEAR;
$content = self::getTemplate("join_team");
$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);
self::sendMail($user->getEmail(), "Équipe rejointe TFJM² $YEAR", $content);
}
public static function sendAddOrganizerMail(NewOrganizer $new_orga)
{
global $YEAR;
$content = self::getTemplate("add_organizer");
$content = preg_replace("#{FIRST_NAME}#", $new_orga->first_name, $content);
$content = preg_replace("#{SURNAME}#", $new_orga->surname, $content);
$content = preg_replace("#{PASSWORD}#", $new_orga->password, $content);
self::sendMail($new_orga->email, "Ajout d'un organisateur TFJM² $YEAR", $content);
}
public static function sendAddOrganizerForTournamentMail(User $organizer, Tournament $tournament)
{
global $YEAR;
$content = self::getTemplate("add_organizer_for_tournament");
$content = preg_replace("#{FIRST_NAME}#", $organizer->getFirstName(), $content);
$content = preg_replace("#{SURNAME}#", $organizer->getSurname(), $content);
$content = preg_replace("#{TOURNAMENT_NAME}#", $tournament->getName(), $content);
self::sendMail($organizer->getEmail(), "Ajout d'un organisateur pour le tournoi " . $tournament->getName() . " TFJM² $YEAR", $content);
}
}