From 232577de412b7ad4f29f1aeed23a2181c198f3cd Mon Sep 17 00:00:00 2001 From: =?utf8?q?St=C3=A9phane=20Jacob?= Date: Thu, 5 Nov 2009 16:17:30 +0100 Subject: [PATCH] Allows the marketer to add some personal text to the marketing email (Closes #946). --- ChangeLog | 3 ++ include/marketing.inc.php | 50 +++++++++++++++++++++------------- include/validations/marketing.inc.php | 4 ++- modules/marketing.php | 17 +++++++----- templates/marketing/marketing.mail.tpl | 3 +- templates/marketing/public.tpl | 12 ++++++-- upgrade/0.10.2/03_marketing.sql | 3 ++ 7 files changed, 61 insertions(+), 31 deletions(-) create mode 100644 upgrade/0.10.2/03_marketing.sql diff --git a/ChangeLog b/ChangeLog index 8c8636a..ed76879 100644 --- a/ChangeLog +++ b/ChangeLog @@ -26,6 +26,9 @@ Bug/Wish: * Mail: - #988: Gets rid of

tags in the mails we send -JAC + * Marketing: + - #946: Displays marketing email and allows the sender to edit it -JAC + * Newsletter: - #986: Improves the nl edition page -JAC - #991: Adds the text of the article in the mail when refused -JAC diff --git a/include/marketing.inc.php b/include/marketing.inc.php index 7a53989..00f6eb7 100644 --- a/include/marketing.inc.php +++ b/include/marketing.inc.php @@ -36,19 +36,21 @@ class Marketing 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' ? $sender : null); + $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->personal_notes = $personal_notes; } private function getUser($uid, $email) @@ -80,13 +82,13 @@ class Marketing 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'; } - $engine = new $class($data, $from); + $engine = new $class($data, $from, $personal_notes); if (!$engine instanceof MarketingEngine) { $engine = null; } @@ -113,9 +115,8 @@ class Marketing $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']); @@ -128,15 +129,15 @@ class Marketing 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(User::getSilent($this->sender), $this->user['user'], $this->user['mail'], - $this->from == 'user', $this->type, $this->data); + $this->from == 'user', $this->type, $this->data, $this->personal_notes); $valid->submit(); } return true; @@ -163,7 +164,7 @@ class Marketing 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 = {?}".( @@ -172,8 +173,8 @@ class Marketing 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) @@ -229,20 +230,20 @@ class Marketing 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 = "Rejoins la communauté polytechnicienne sur Internet"; $this->intro = " Tu n'as pas de fiche dans l'annuaire des polytechniciens sur Internet. " @@ -254,6 +255,11 @@ class AnnuaireMarketing implements MarketingEngine } 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() @@ -271,6 +277,11 @@ class AnnuaireMarketing implements MarketingEngine return $this->signature; } + public function getPersonalNotes() + { + return $this->personal_notes; + } + protected function prepareText(PlPage &$page, array $user) { $page->assign('intro', $this->getIntro()); @@ -278,6 +289,7 @@ class AnnuaireMarketing implements MarketingEngine $page->assign('sign', $this->getSignature()); $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('personal_notes', $this->getPersonalNotes()); } public function getText(array $user) @@ -297,7 +309,7 @@ class ListMarketing extends AnnuaireMarketing { private $name; private $domain; - public function __construct($data, $from) + public function __construct($data, $from, $personal_notes = null) { list($this->name, $this->domain) = explode('@', $data); if ($from && ($user = User::getSilent($from))) { @@ -328,7 +340,7 @@ class ListMarketing extends AnnuaireMarketing class GroupMarketing extends AnnuaireMarketing { private $group; - public function __construct($data, $from) + public function __construct($data, $from, $personal_notes = null) { $this->group = $data; if ($from && ($user = User::getSilent($from))) { diff --git a/include/validations/marketing.inc.php b/include/validations/marketing.inc.php index 9f2161c..9fd6f45 100644 --- a/include/validations/marketing.inc.php +++ b/include/validations/marketing.inc.php @@ -31,6 +31,7 @@ class MarkReq extends Validate public $m_relance; public $m_type; public $m_data; + public $m_personal_notes; public $rules = "Accepter si l'adresse email parait correcte, et pas absurde (ou si le marketeur est de confiance). Si le demandeur marque sa propre adresse email, refuser dans tous les cas. @@ -39,7 +40,7 @@ class MarkReq extends Validate // }}} // {{{ constructor - public function __construct(User &$sender, User &$mark, $email, $perso, $type, $data) + public function __construct(User &$sender, User &$mark, $email, $perso, $type, $data, $personal_notes) { parent::__construct($sender, false, 'marketing'); $this->m_user = &$mark; @@ -47,6 +48,7 @@ class MarkReq extends Validate $this->perso = $perso; $this->m_type = $type; $this->m_data = $data; + $this->m_personal_notes = $personal_notes; } // }}} diff --git a/modules/marketing.php b/modules/marketing.php index a0123ef..a703131 100644 --- a/modules/marketing.php +++ b/modules/marketing.php @@ -307,7 +307,8 @@ class MarketingModule extends PLModule } else { $page->assign('ok', true); check_email($email, "Une adresse surveillée est proposée au marketing par " . S::user()->login()); - $market = new Marketing($user->id(), $email, 'default', null, Post::v('origine'), S::v('uid')); + $market = new Marketing($user->id(), $email, 'default', null, Post::v('origine'), S::v('uid'), + Post::v('origine') == 'user' ? Post::v('personal_notes') : null); $market->add(); } } @@ -316,18 +317,20 @@ class MarketingModule extends PLModule require_once 'marketing.inc.php'; $sender = User::getSilent(S::v('uid')); - $market = new AnnuaireMarketing(null, null); + $market = new AnnuaireMarketing(null, true); $text = $market->getText(array( 'sexe' => $user->isFemale(), 'forlife_email' => $user->login() . '@' . $globals->mail->domain, 'forlife_email2' => $user->login() . '@' . $globals->mail->domain2 )); - $perso_signature = '"' . $sender->fullName() . '" <' . $sender->bestEmail() . '>'; - $text = preg_replace("{-- (.|\n)*}", - "-- \n" . $perso_signature . '', $text); + $text = str_replace('%%hash%%', '', $text); + $text = str_replace('%%personal_notes%%', '', $text); + $text = str_replace('%%sender%%', + "" . $sender->fullName() . '', $text); $page->assign('text', nl2br($text)); - $page->assign('xorg_signature', str_replace("\n", '
', $market->getSignature())); - $page->assign('perso_signature', $perso_signature); + // TODO (JAC): define a unique Xorg signature for all the emails we send. + $page->assign('xorg_signature', "L'équipe de Polytechnique.org,
Le portail des élèves & anciens élèves de l'École polytechnique"); + $page->assign('perso_signature', $sender->fullName()); } } diff --git a/templates/marketing/marketing.mail.tpl b/templates/marketing/marketing.mail.tpl index c00a55d..60a863a 100644 --- a/templates/marketing/marketing.mail.tpl +++ b/templates/marketing/marketing.mail.tpl @@ -34,11 +34,10 @@ Pas de nouvelle boîte aux lettres à relever, il suffit de la rediriger vers to De plus, le site web offre des services d'annuaire avec recherche multi-critères, de forums, de listes de diffusion. Ce portail est géré par une vingtaine de jeunes camarades, avec le soutien et les conseils de nombreux X de toutes promotions, incluant notamment des camarades de la Kès et de l'AX. Les serveurs sont hébergés au sein même de l'École polytechnique, sur une connexion rapide, et les services évoluent en fonction des besoins exprimés par la communauté sur Internet. N'hésite pas à parler de Polytechnique.org à nos camarades pas encore inscrits et à nous écrire pour nous proposer toute amélioration ou suggestion. - +{$personal_notes} À bientôt sur Polytechnique.org , Bien cordialement, - -- {$sign} diff --git a/templates/marketing/public.tpl b/templates/marketing/public.tpl index a810568..10272c6 100644 --- a/templates/marketing/public.tpl +++ b/templates/marketing/public.tpl @@ -89,16 +89,24 @@ peut sans aucun doute l'aider à se décider !
+ + Texte à ajouter à l'email : + +

diff --git a/upgrade/0.10.2/03_marketing.sql b/upgrade/0.10.2/03_marketing.sql new file mode 100644 index 0000000..7be3b88 --- /dev/null +++ b/upgrade/0.10.2/03_marketing.sql @@ -0,0 +1,3 @@ +ALTER TABLE register_marketing ADD COLUMN personal_notes TEXT DEFAULT NULL; + +-- vim:set syntax=mysql: -- 2.1.4