Allows the marketer to add some personal text to the marketing email (Closes #946).
authorStéphane Jacob <sj@m4x.org>
Thu, 5 Nov 2009 15:17:30 +0000 (16:17 +0100)
committerStéphane Jacob <sj@m4x.org>
Sat, 7 Nov 2009 13:05:24 +0000 (14:05 +0100)
ChangeLog
include/marketing.inc.php
include/validations/marketing.inc.php
modules/marketing.php
templates/marketing/marketing.mail.tpl
templates/marketing/public.tpl
upgrade/0.10.2/03_marketing.sql [new file with mode: 0644]

index 8c8636a..ed76879 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -26,6 +26,9 @@ Bug/Wish:
     * Mail:
         - #988: Gets rid of <h1> 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
index 7a53989..00f6eb7 100644 (file)
@@ -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))) {
index 9f2161c..9fd6f45 100644 (file)
@@ -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;
     }
 
     // }}}
index a0123ef..a703131 100644 (file)
@@ -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<span id=\"sender\">" . $perso_signature . '</span>', $text);
+            $text = str_replace('%%hash%%', '', $text);
+            $text = str_replace('%%personal_notes%%', '<em id="personal_notes_display"></em>', $text);
+            $text = str_replace('%%sender%%',
+                                "<span id=\"sender\">" . $sender->fullName() . '</span>', $text);
             $page->assign('text', nl2br($text));
-            $page->assign('xorg_signature', str_replace("\n", '<br />', $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,<br />Le portail des élèves & anciens élèves de l'École polytechnique");
+            $page->assign('perso_signature', $sender->fullName());
         }
     }
 
index c00a55d..60a863a 100644 (file)
@@ -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 <https://www.polytechnique.org>,
 
 Bien cordialement,
-
 -- 
 {$sign}
 
index a810568..10272c6 100644 (file)
@@ -89,16 +89,24 @@ peut sans aucun doute l'aider à se décider&nbsp;!
       <td>
         <label>
           <input type="radio" name="origine" value="user" checked="checked"
-                 onclick="$('#sender').html('{$perso_signature}');" />
+                 onclick="$('#sender').html('{$perso_signature}'); $('#tr_perso').show();
+                          $('#personal_notes_display').show();" />
           en ton nom
         </label><br />
         <label>
           <input type="radio" name="origine" value="staff"
-                 onclick='$("#sender").html("{$xorg_signature}");' />
+                 onclick='$("#sender").html("{$xorg_signature}"); $("#tr_perso").hide();
+                          $("#personal_notes_display").hide();' />
           au nom de l'équipe Polytechnique.org
         </label>
       </td>
     </tr>
+    <tr class="pair" id="tr_perso">
+      <td>Texte à ajouter à l'email&nbsp;:</td>
+      <td><textarea cols="60" rows="5" name="personal_notes" id="textarea_perso"
+                    onkeyup="$('#personal_notes_display').html('<br />' + $('#textarea_perso').val().replace(/\n/g,
+                    '<br />') + '<br />');"></textarea>
+    </tr>
   </table>
   <div class="center">
     <br />
diff --git a/upgrade/0.10.2/03_marketing.sql b/upgrade/0.10.2/03_marketing.sql
new file mode 100644 (file)
index 0000000..7be3b88
--- /dev/null
@@ -0,0 +1,3 @@
+ALTER TABLE register_marketing ADD COLUMN personal_notes TEXT DEFAULT NULL;
+
+-- vim:set syntax=mysql: