2019-09-09 23:48:52 +00:00
|
|
|
|
<?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);
|
|
|
|
|
|
2019-09-10 18:25:26 +00:00
|
|
|
|
$headers = "From: \"Contact Corres2Math\" <" . $from . "@" . $MAIL_DOMAIN . ">\r\n";
|
|
|
|
|
$headers .= "Reply-To: \"Contact corres2Math\" <contact@" . $MAIL_DOMAIN . ">\r\n";
|
2019-09-09 23:48:52 +00:00
|
|
|
|
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";
|
|
|
|
|
|
2019-09-10 18:25:26 +00:00
|
|
|
|
ensure(mail($email, $subject, $content, $headers), "Un problème est survenu dans l'envoi d'un mail. Veuiller contacter votre administrateur.");
|
2019-09-09 23:48:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
2019-09-10 18:25:26 +00:00
|
|
|
|
self::sendMail($new_user->email, "Inscription aux Correspondances des Jeunes Mathématicien·ne·s $YEAR", $content);
|
2019-09-09 23:48:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
2019-09-10 18:25:26 +00:00
|
|
|
|
self::sendMail($user->getEmail(), "Confirmation d'adresse e-mail – Correspondances des Jeunes Mathématicien·ne·s $YEAR", $content);
|
2019-09-09 23:48:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
2019-09-10 18:25:26 +00:00
|
|
|
|
self::sendMail($user->getEmail(), "Changement d'adresse e-mail – Correspondances des Jeunes Mathématicien·ne·s", $content);
|
2019-09-09 23:48:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
2019-09-10 18:25:26 +00:00
|
|
|
|
self::sendMail($user->getEmail(), "Mot de passe oublié – Correspondances des Jeunes Mathématicien·ne·s", $content);
|
2019-09-09 23:48:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
2019-09-10 18:25:26 +00:00
|
|
|
|
self::sendMail($user->getEmail(), "Mot de passe changé – Correspondances des Jeunes Mathématicien·ne·s", $content);
|
2019-09-09 23:48:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-09-12 14:19:47 +00:00
|
|
|
|
public static function sendAddAdminMail(NewAdmin $new_admin)
|
|
|
|
|
{
|
|
|
|
|
global $YEAR;
|
|
|
|
|
|
|
|
|
|
$content = self::getTemplate("add_admin");
|
|
|
|
|
$content = preg_replace("#{FIRST_NAME}#", $new_admin->first_name, $content);
|
|
|
|
|
$content = preg_replace("#{SURNAME}#", $new_admin->surname, $content);
|
|
|
|
|
$content = preg_replace("#{PASSWORD}#", $new_admin->password, $content);
|
|
|
|
|
|
|
|
|
|
self::sendMail($new_admin->email, "Ajout d'un administrateur – Correspondances des Jeunes Mathématicien·ne·s $YEAR", $content);
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-11 16:41:45 +00:00
|
|
|
|
public static function sendAddTeamMail(User $user, Team $team)
|
2019-09-09 23:48:52 +00:00
|
|
|
|
{
|
|
|
|
|
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);
|
2019-09-11 16:41:45 +00:00
|
|
|
|
$content = preg_replace("#{PROBLEM}#", $team->getProblem(), $content);
|
2019-09-09 23:48:52 +00:00
|
|
|
|
$content = preg_replace("#{ACCESS_CODE}#", $team->getAccessCode(), $content);
|
|
|
|
|
|
2019-09-10 18:25:26 +00:00
|
|
|
|
self::sendMail($user->getEmail(), "Ajout d'une équipe Correspondances des Jeunes Mathématicien·ne·s $YEAR", $content);
|
2019-09-09 23:48:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-09-11 16:41:45 +00:00
|
|
|
|
public static function sendJoinTeamMail(User $user, Team $team)
|
2019-09-09 23:48:52 +00:00
|
|
|
|
{
|
|
|
|
|
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);
|
2019-09-11 16:41:45 +00:00
|
|
|
|
$content = preg_replace("#{PROBLEM}#", $team->getProblem(), $content);
|
2019-09-09 23:48:52 +00:00
|
|
|
|
|
2019-09-10 18:25:26 +00:00
|
|
|
|
self::sendMail($user->getEmail(), "Équipe rejointe Correspondances des Jeunes Mathématicien·ne·s $YEAR", $content);
|
2019-09-09 23:48:52 +00:00
|
|
|
|
}
|
|
|
|
|
}
|