<?php
/***************************************************************************
- * Copyright (C) 2003-2007 Polytechnique.org *
+ * Copyright (C) 2003-2010 Polytechnique.org *
* http://opensource.polytechnique.org/ *
* *
* This program is free software; you can redistribute it and/or modify *
private $data;
private $from;
private $sender;
+ private $personal_notes;
private $hash = '';
- public function __construct($uid, $email, $type, $data, $from, $sender = null)
+ public function __construct($uid, $email, $type, $data, $from, $sender = null, $personal_notes = null)
{
$this->user = $this->getUser($uid, $email);
$this->sender_mail = $this->getFrom($from, $sender);
- $this->engine =& $this->getEngine($type, $data, $from == 'user' ? null : $this->sender);
+ $this->engine =& $this->getEngine($type, $data, $from == 'user' ? $sender : null, $personal_notes);
$this->type = $type;
$this->data = $data;
$this->from = $from;
- $this->sender = $sender;
+ $this->sender = $sender;
+ $this->personal_notes = $personal_notes;
}
private function getUser($uid, $email)
{
- require_once("xorg.misc.inc.php");
- $res = XDB::query("SELECT FIND_IN_SET('femme', flags) AS sexe, nom, prenom, promo
- FROM auth_user_md5
- WHERE user_id = {?}", $uid);
- if ($res->numRows() == 0) {
+ $user = User::getSilent($uid);
+ if (!$user) {
return null;
- }
- $user = $res->fetchOneAssoc();
- $user['id'] = $uid;
- $user['forlife'] = make_forlife($user['prenom'], $user['nom'], $user['promo']);
- $user['mail'] = $email;
- $user['to'] = '"' . $user['prenom'] . ' ' . $user['nom'] . '" <' . $email . '>';
- return $user;
+ }
+
+ global $globals;
+ return array(
+ 'user' => $user,
+ 'id' => $user->id(),
+ 'sexe' => $user->isFemale(),
+ 'mail' => $email,
+ 'to' => '"' . $user->fullName() . '" <' . $email . '>',
+ 'forlife_email' => $user->login() . '@' . $globals->mail->domain,
+ 'forlife_email2' => $user->login() . '@' . $globals->mail->domain2,
+ );
}
private function getFrom($from, $sender)
{
- if ($from == 'staff') {
- return '"Equipe Polytechnique.org" <register@polytechnique.org>';
- } else {
- $res = XDB::query("SELECT u.nom, u.prenom, a.alias
- FROM auth_user_md5 AS u
- INNER JOIN aliases AS a ON (a.id = u.user_id AND FIND_IN_SET('bestalias', a.flags))
- WHERE u.user_id = {?}", $sender);
- if (!$res->numRows()) {
- return '"Equipe Polytechnique.org" <register@polytechnique.org>';
- }
- $sender = $res->fetchOneAssoc();
- return '"' . $sender['prenom'] . ' ' . $sender['nom'] . '" <' . $sender['alias'] . '@polytechnique.org>';
+ global $globals;
+
+ if ($from == 'staff' || !($user = User::getSilent($sender))) {
+ return '"L\'équipe de Polytechnique.org" <register@' . $globals->mail->domain . '>';
}
+ return '"' . $user->fullName() . '" <' . $user->bestEmail() . '>';
}
- private function &getEngine($type, $data, $from)
+ private function &getEngine($type, $data, $from, $personal_notes)
{
$class = $type . 'Marketing';
if (!class_exists($class, false)) {
$class= 'DefaultMarketing';
}
- if (!is_subclass_of($class, 'MarketingEngine')) {
+ $engine = new $class($data, $from, $personal_notes);
+ if (!$engine instanceof MarketingEngine) {
$engine = null;
- } else {
- $engine = new $class($data, $from);
}
return $engine;
}
$text = $this->engine->getText($this->user);
}
$sender = substr($this->sender_mail, 1, strpos($this->sender_mail, '"', 2)-1);
- $text = str_replace(array("%%hash%%", "%%sender%%"),
- array($this->hash, $this->sender_mail),
- $text);
+ $text = str_replace(array('%%hash%%', '%%sender%%', '%%personal_notes%%'),
+ array($this->hash, $this->sender_mail, ''), $text);
$mailer = new PlMailer();
$mailer->setFrom($this->sender_mail);
$mailer->addTo($this->user['mail']);
public function add($valid = true)
{
XDB::execute('INSERT IGNORE INTO register_marketing
- (uid, sender, email, date, last, nb, type, hash, message, message_data)
- VALUES ({?}, {?}, {?}, NOW(), 0, 0, {?}, {?}, {?}, {?})',
+ (uid, sender, email, date, last, nb, type, hash, message, message_data, personal_notes)
+ VALUES ({?}, {?}, {?}, NOW(), 0, 0, {?}, {?}, {?}, {?}, {?})',
$this->user['id'], $this->sender, $this->user['mail'], $this->from, $this->hash,
- $this->type, $this->data);
+ $this->type, $this->data, $this->personal_notes);
$this->engine->process($this->user);
if ($valid) {
require_once 'validations.inc.php';
- $valid = new MarkReq($this->sender, $this->user['id'], $this->user['mail'],
- $this->from == 'user', $this->type, $this->data);
+ $valid = new MarkReq(User::getSilent($this->sender), $this->user['user'], $this->user['mail'],
+ $this->from == 'user', $this->type, $this->data, $this->personal_notes);
$valid->submit();
}
return true;
return $array;
}
- static public function get($uid, $email)
+ static public function get($uid, $email, $recentOnly = false)
{
- $res = XDB::query("SELECT uid, email, message, message_data, type, sender
+ $res = XDB::query("SELECT uid, email, message, message_data, type, sender, personal_notes
FROM register_marketing
- WHERE uid = {?} AND email = {?}", $uid, $email);
+ WHERE uid = {?}
+ AND email = {?}".(
+ $recentOnly ? ' AND DATEDIFF(NOW(), last) < 30' : ''), $uid, $email);
+
if ($res->numRows() == 0) {
return null;
}
- list ($uid, $email, $type, $data, $from, $sender) = $res->fetchOneRow();
- return new Marketing($uid, $email, $type, $data, $from, $sender);
+ list ($uid, $email, $type, $data, $from, $senderi, $personal_notes) = $res->fetchOneRow();
+ return new Marketing($uid, $email, $type, $data, $from, $sender, $personal_notes);
}
static public function clear($uid, $email = null)
if (!$email) {
XDB::execute("DELETE FROM register_marketing WHERE uid = {?}", $uid);
} else {
- XDB::execute("DELETE FROM register_marketing WHERE uid = {?} AND email = {?}", $uid, $email);
+ XDB::execute("DELETE FROM register_marketing WHERE uid = {?} AND email = {?}", $uid, $email);
}
}
- static public function relance($uid, $nbx = -1)
+ static public function getAliveUsersCount()
+ {
+ $uf = new UserFilter(new PFC_Not(new UFC_Dead()));
+ return $uf->getTotalCount();
+ }
+
+ static public function relance(PlUser &$user, $nbx = -1)
{
global $globals;
if ($nbx < 0) {
- $res = XDB::query("SELECT COUNT(*) FROM auth_user_md5 WHERE deces=0");
- $nbx = $res->fetchOneCell();
+ $nbx = self::getAliveUsersCount();
}
-
- $res = XDB::query("SELECT r.date, u.promo, u.nom, u.prenom, r.email, r.bestalias
- FROM register_pending AS r
- INNER JOIN auth_user_md5 AS u ON u.user_id = r.uid
- WHERE hash!='INSCRIT' AND uid={?} AND TO_DAYS(relance) < TO_DAYS(NOW())", $uid);
- if (!list($date, $promo, $nom, $prenom, $email, $alias) = $res->fetchOneRow()) {
+
+ $res = XDB::fetchOneCell('SELECT r.date, r.email, r.bestalias
+ FROM register_pending
+ WHERE r.hash = \'INSCRIT\' AND uid = {?}',
+ $user->id());
+ if (!$res) {
return false;
+ } else {
+ list($date, $email, $alias) = $res;
}
-
- require_once('secure_hash.inc.php');
+
$hash = rand_url_id(12);
$pass = rand_pass();
- $pass_encrypted = hash_encrypt($pass);
+ $pass_encrypted = sha1($pass);
$fdate = strftime('%d %B %Y', strtotime($date));
-
- $mymail = new PlMailer('marketing/mail.relance.tpl');
+
+ $mymail = new PlMailer('marketing/relance.mail.tpl');
$mymail->assign('nbdix', $nbx);
$mymail->assign('fdate', $fdate);
$mymail->assign('lusername', $alias);
$mymail->send();
XDB::execute('UPDATE register_pending
SET hash={?}, password={?}, relance=NOW()
- WHERE uid={?}', $hash, $pass_encrypted, $uid);
- return "$prenom $nom ($promo)";
+ WHERE uid={?}', $hash, $pass_encrypted, $user->id());
+ return $user->fullName();
}
}
interface MarketingEngine
{
- public function __construct($data, $from);
+ public function __construct($data, $from, $personal_notes = null);
public function getTitle();
public function getText(array $user);
public function process(array $user);
}
-//
class AnnuaireMarketing implements MarketingEngine
{
protected $titre;
protected $intro;
+ protected $signature;
+ protected $personal_notes;
- public function __construct($data, $from)
+ public function __construct($data, $from, $personal_notes = null)
{
- $this->titre = "Annuaire en ligne des Polytechniciens";
- $this->intro = " Ta fiche n'est pas à jour dans l'annuaire des Polytechniciens sur Internet. "
- . "Pour la mettre à jour, il te it de visiter cette page ou de copier cette adresse "
+ $this->titre = "Rejoins la communauté polytechnicienne sur Internet";
+ $this->intro = " Tu n'as pas de fiche dans l'annuaire des polytechniciens sur Internet. "
+ . "Pour y figurer, il te suffit de visiter cette page ou de copier cette adresse "
. "dans la barre de ton navigateur :";
+ if ($from === null) {
+ $this->signature = "L'équipe de Polytechnique.org,\n"
+ . "Le portail des élèves & anciens élèves de l'École polytechnique";
+ } else {
+ $this->signature = "%%sender%%";
+ }
+ if (is_null($personal_notes) || $personal_notes == '') {
+ $this->personal_notes = '%%personal_notes%%';
+ } else {
+ $this->personal_notes = "\n" . $personal_notes . "\n";
+ }
}
public function getTitle()
return $this->intro;
}
- protected function prepareText(PlatalPage &$page, array $user)
+ public function getSignature()
+ {
+ return $this->signature;
+ }
+
+ public function getPersonalNotes()
+ {
+ return $this->personal_notes;
+ }
+
+ protected function prepareText(PlPage &$page, array $user)
{
$page->assign('intro', $this->getIntro());
$page->assign('u', $user);
- $res = XDB::query("SELECT COUNT(*) FROM auth_user_md5 WHERE perms IN ('user', 'admin') AND deces = 0");
- $page->assign('num_users', $res->fetchOneCell());
+ $page->assign('sign', $this->getSignature());
+ $page->assign('num_users', Marketing::getAliveUsersCount());
+ $page->assign('personal_notes', $this->getPersonalNotes());
}
public function getText(array $user)
{
- $page = new PlatalPage('marketing/mail.marketing.tpl', NO_SKIN);
+ $page = new XorgPage();
+ $page->changeTpl('marketing/marketing.mail.tpl', NO_SKIN);
$this->prepareText($page, $user);
return $page->raw();
}
{
private $name;
private $domain;
- public function __construct($data, $from)
+ public function __construct($data, $from, $personal_notes = null)
{
list($this->name, $this->domain) = explode('@', $data);
- $res = XDB::query("SELECT prenom, IF (nom_usage != '', nom_usage, nom)
- FROM auth_user_md5
- WHERE user_id = {?} AND user_id != 0", $from ? $from : 0);
- if ($res->numRows()) {
- list($prenom, $nom) = $res->fetchOneRow();
- $from = "$prenom $nom";
+ if ($from && ($user = User::getSilent($from))) {
+ $from = $user->fullName();
} else {
$from = "Je";
}
$this->titre = "Un camarade solicite ton inscription à $data";
- $this->intro = "Polytechnique.org, l'annuaire des Polytechniciens sur internet, "
- . "fournit de nombreux services aux groupes X, ainsi que des listes "
- . "de diffusion pour les X en faisant la demande.\n\n"
- . "$from solicite ton inscription à la liste <$data>. "
- . "Cependant, seuls les X inscrits sur Polytechnique.org peuvent "
- . "profiter de l'ensemble de nos services, c'est pourquoi nous te "
- . "proposons auparavant de t'inscrire sur notre site. Pour cela, il "
- . "te suffit de visiter cette page ou de copier cette adresse dans "
- . "la barre de ton navigateur :";
+ $this->intro = "Polytechnique.org, l'annuaire des polytechniciens sur internet, "
+ . "fournit de nombreux services aux groupes X, ainsi que des listes "
+ . "de diffusion pour les X en faisant la demande.\n\n"
+ . "$from solicite ton inscription à la liste <$data>. "
+ . "Cependant, seuls les X inscrits sur Polytechnique.org peuvent "
+ . "profiter de l'ensemble de nos services, c'est pourquoi nous te "
+ . "proposons auparavant de t'inscrire sur notre site. Pour cela, il "
+ . "te suffit de visiter cette page ou de copier cette adresse dans "
+ . "la barre de ton navigateur :";
}
public function process(array $user)
{
return XDB::execute("REPLACE INTO register_subs (uid, type, sub, domain)
- VALUES ({?}, 'list', {?}, {?})",
- $user['id'], $this->name, $this->domain);
+ VALUES ({?}, 'list', {?}, {?})",
+ $user['id'], $this->name, $this->domain);
}
}
class GroupMarketing extends AnnuaireMarketing
{
private $group;
- public function __construct($data, $from)
+ public function __construct($data, $from, $personal_notes = null)
{
$this->group = $data;
- $res = XDB::query("SELECT prenom, IF (nom_usage != '', nom_usage, nom)
- FROM auth_user_md5
- WHERE user_id = {?} AND user_id != 0", $from ? $from : 0);
- if ($res->numRows()) {
- list($prenom, $nom) = $res->fetchOneRow();
- $from = "$prenom $nom vient";
+ if ($from && ($user = User::getSilent($from))) {
+ $from = $user->fullName() . " vient";
} else {
$from = "Je viens";
}
$this->titre = "Profite de ton inscription au groupe \"$data\" pour découvrir Polytechnique.org";
- $this->intro = "Polytechnique.org, l'annuaire des Polytechniciens sur internet, fournit "
- . "de nombreux services aux groupes X ( listes de diffusion, paiement en "
- . "ligne, sites internet...), en particulier pour le groupe \"$data\"\n\n"
- . "$from de t'inscrire dans l'annuaire du groupe \"$data\". "
- . "Cependant, seuls les X inscrits sur Polytechnique.org peuvent profiter "
- . "de l'ensemble de nos services, c'est pourquoi nous te proposons de "
- . "t'inscrire sur notre site . Pour cela, il te suffit de visiter cette page "
- . "ou de copier cette adresse dans la barre de ton navigateur :";
+ $this->intro = "Polytechnique.org, l'annuaire des polytechniciens sur internet, fournit "
+ . "de nombreux services aux groupes X ( listes de diffusion, paiement en "
+ . "ligne, sites internet...), en particulier pour le groupe \"$data\"\n\n"
+ . "$from de t'inscrire dans l'annuaire du groupe \"$data\". "
+ . "Cependant, seuls les X inscrits sur Polytechnique.org peuvent profiter "
+ . "de l'ensemble de nos services, c'est pourquoi nous te proposons de "
+ . "t'inscrire sur notre site . Pour cela, il te suffit de visiter cette page "
+ . "ou de copier cette adresse dans la barre de ton navigateur :";
}
public function process(array $user)
{
return XDB::execute("REPLACE INTO register_subs (uid, type, sub, domain)
- VALUES ({?}, 'group', {?}, '')",
- $user['id'], $this->group);
+ VALUES ({?}, 'group', {?}, '')",
+ $user['id'], $this->group);
}
}