New evolutive marketing engine
authorx2003bruneau <x2003bruneau@839d8a87-29fc-0310-9880-83ba4fa771e5>
Mon, 19 Mar 2007 22:09:33 +0000 (22:09 +0000)
committerx2003bruneau <x2003bruneau@839d8a87-29fc-0310-9880-83ba4fa771e5>
Mon, 19 Mar 2007 22:09:33 +0000 (22:09 +0000)
#543: Adapt marketing when adding sbd to a group
Add pika in Author list
Add include/ in __autoload pathes

git-svn-id: svn+ssh://murphy/home/svn/platal/trunk@1589 839d8a87-29fc-0310-9880-83ba4fa771e5

19 files changed:
AUTHORS
ChangeLog
classes/platalpage.php
include/marketing.inc.php
include/platal.inc.php
include/validations/marketing.inc.php
modules/admin.php
modules/carnet.php
modules/marketing.php
modules/profile.php
modules/register.php
modules/search.php
modules/xnetgrp.php
templates/admin/valider.tpl
templates/include/form.valid.mark.tpl
templates/marketing/mail.marketing.tpl [new file with mode: 0644]
templates/marketing/private.tpl
templates/search/quick.tpl
upgrade/0.9.14/05_marketing.sql [new file with mode: 0644]

diff --git a/AUTHORS b/AUTHORS
index ecb0cc2..ab219df 100644 (file)
--- a/AUTHORS
+++ b/AUTHORS
@@ -1,6 +1,7 @@
 Polytechnique.org TEAM :
 
     Pierre Habouzit         <pierre.habouzit@m4x.org>       project manager
+    Aymeric Augusting       <aymeric.augusting@m4x.org>
     Jean Sébastien Bedo     <jean-sebastien.bedo@m4x.org>
     Florent Bruneau         <florent.bruneau@m4x.org>
     Sophie Charbonnier      <sophie.charbonnier@m4x.org>
@@ -8,6 +9,7 @@ Polytechnique.org TEAM :
     Jean-Marc Coic          <jean-marc.coic@m4x.org>
     Pascal Corpet           <pascal.corpet@m4x.org>
     Guillaume Gommard       <guillaume.gommard@m4x.org>
+    Fabien Laborde          <fabien.laborde@m4x.org>
     Jeremy Lainé            <jeremy.laine@m4x.org>
     Raphael Marichez        <raphael.marichez@m4x.org>
     Vincent Palatin         <vincent.palatin@m4x.org>
index e843fa8..5dfb2d7 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -60,6 +60,9 @@ Bug/Wish:
     * XnetEvents:
         - #637: Check payment before submission                            -FRU
 
+    * XnetGrp:
+        - #543: Adapt marketing                                            -FRU
+
 ================================================================================
 VERSION 0.9.13                                                        30 01 2007
 
@@ -992,6 +995,7 @@ ACRONYMS:
     * MC : Pierre Habouzit      (MadCoder)  <pierre.habouzit@m4x.org>
     * mYk: Aymeric Augustin     (mYk)       <aymeric.augustin@m4x.org>
     * OG : Olivier Guillaumin               <olivier.guillaumin@m4x.org>
+    * PIK: Fabien Laborde       (pika)      <fabien.laborde@m4x.org>
     * SHK: Jeremy Lainé         (Sharky)    <jeremy.laine@m4x.org>
     * VP : Vincent Palatin                  <vincent.palatin@m4x.org>
     * XdX: Alexandre Hô         (XandreX)   <alexandre.ho@m4x.org>
index 9e737eb..1dd77ca 100644 (file)
@@ -52,9 +52,6 @@ class PlatalPage extends Smarty
         $this->_failure   = false;
 
         $this->register_prefilter('at_to_globals');
-        $this->register_prefilter('trimwhitespace');
-        $this->register_prefilter('form_force_encodings');
-        $this->addJsLink('xorg.js');
     }
 
     // }}}
@@ -68,6 +65,16 @@ class PlatalPage extends Smarty
     }
 
     // }}}
+    // {{{ function raw()
+
+    public function raw()
+    {
+        global $globals;
+        $this->assign('globals', $globals);
+        return $this->fetch($this->_tpl);
+    }
+
+    // }}}
     // {{{ function _run()
 
     protected function _run($skin)
@@ -76,6 +83,9 @@ class PlatalPage extends Smarty
 
         session_write_close();
 
+        $this->register_prefilter('trimwhitespace');
+        $this->register_prefilter('form_force_encodings');
+        $this->addJsLink('xorg.js');
         $this->assign('xorg_errors', $this->_errors);
         $this->assign('xorg_failure', $this->_failure);
         $this->assign('globals', $globals);
index b4387f3..997faee 100644 (file)
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                *
  ***************************************************************************/
 
-require_once("xorg.misc.inc.php");
-
-// {{{ function mark_from_mail
-
-function mark_from_mail($uid, $email) {
-    $res = XDB::query(
-        "SELECT u.nom, u.prenom, a.alias
-           FROM register_marketing  AS r
-     INNER JOIN auth_user_md5       AS u ON (r.sender = u.user_id)
-     INNER JOIN aliases             AS a ON (a.id = r.sender AND a.type='a_vie')
-          WHERE r.uid = {?} AND r.email = {?}",
-        $uid, $email);
-    $sender = $res->fetchOneAssoc();
-    return "\"".$sender['prenom']." ".$sender['nom']."\" <".$sender['alias']."@polytechnique.org>";
-}
+class Marketing
+{
+    static private $engines = array(
+        //user name  => array(class name,          require data)
+        'annuaire'   => array('AnnuaireMarketing', false),
+        'groupe'     => array('GroupMarketing',    true),
+        'liste'      => array('ListMarketing',     true),
+    );
 
-// }}}
-// {{{ function mark_text_mail
+    private $engine;
+    public $sender_mail;
+    public $user;
 
-function mark_text_mail($uid, $email)
-{
-    global $globals;
-    $title = "Annuaire en ligne des Polytechniciens";
-
-    $res = XDB::query("SELECT COUNT(*) FROM auth_user_md5 WHERE perms IN ('admin', 'user') and deces = 0");
-    $num_users = $res->fetchOneCell();
-
-    $res = XDB::query("SELECT flags, nom, prenom, promo FROM auth_user_md5 WHERE user_id = {?}", $uid);
-    $u = $res->fetchOneAssoc();
-
-    $mailorg = make_forlife($u['prenom'],$u['nom'],$u['promo']);
-
-    $to = "\"".$u['prenom']." ".$u['nom']."\" <".$email.">";
-
-    $titre = "Annuaire en ligne des Polytechniciens";
-    $text  = "   ".($u['flags']?"Chère":"Cher")." camarade,\n\n";
-    $text .= "   Ta fiche n'est pas à jour dans l'annuaire des Polytechniciens sur Internet. Pour la mettre à jour, il te suffit de visiter cette page ou de copier cette adresse dans la barre de ton navigateur :\n\n";
-    $text .= "==========================================================\n";
-    $text .= $globals->baseurl."/register/%%hash%%\n";
-    $text .= "==========================================================\n\n";
-    $text .= "Il ne te faut que 5 minutes sur http://www.polytechnique.org/ pour rejoindre les $num_users camarades branchés grâce au système de reroutage de l'X et qui permet de joindre un camarade en connaissant seulement son nom et son prénom... et de bénéficier pour la vie d'une adresse prestigieuse $mailorg@polytechnique.org et son alias discret $mailorg@m4x.org (m4x = mail for X).\n\n";
-    $text .= "Pas de nouvelle boîte aux lettres à relever, il suffit de la rerouter vers ton adresse personnelle et/ou professionnelle que tu indiques et que tu peux changer tous les jours si tu veux sans imposer à tes correspondants de modifier leur carnet d'adresses...\n\n";
-    $text .= "De plus, le site web offre les services d'annuaire (recherche multi-critères), de forums, de mailing-lists. Ce portail est géré par une dizaine de jeunes camarades, avec le soutien et les conseils de nombreux X de toutes promotions, incluant notamment des camarades de la Kès des élèves de l'X et d'autres de l'AX. Les serveurs sont hébergés au sein même de l'Ecole polytechnique, sur une connexion rapide, et les services évoluent en fonction des besoins exprimés par la communauté sur Internet.\n\n";
-    $text .="N'hésite pas à transmettre ce message à tes camarades ou à nous écrire, nous proposer toute amélioration ou suggestion pour les versions prochaines du site.\n\n";
-    $text .= "A bientôt sur http://www.polytechnique.org !\n";
-    $text .= "Bien à toi,\n";
-    $text .= "%%sender%%\n\n";
-    $text .= "--\n";
-    $text .= "Polytechnique.org\n";
-    $text .= "\"Le portail des élèves & anciens élèves de l'X\"\n";
-    $text .= "http://www.polytechnique.org/\n";
-    $text .= "http://www.polytechnique.net/\n";
-    return array($to, $title, $text);
+    private $type;
+    private $data;
+    private $from;
+    private $sender;
+
+    private $hash = '';
+
+    public function __construct($uid, $email, $type, $data, $from, $sender = 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->type   = $type;
+        $this->data   = $data;
+        $this->from   = $from;
+        $this->sender = $sender; 
+    }
+
+    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) {
+            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;
+    }
+
+    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>';
+        }
+    }
+
+    private function getEngine($type, $data, $from)
+    {
+        $class = $type . 'Marketing';
+        if (!class_exists($class, false)) {
+            $class= 'DefaultMarketing';
+        }
+        return new $class($data, $from);
+    }
+
+    public function getTitle()
+    {
+        return $this->engine->getTitle();
+    }
+
+    public function getText()
+    {
+        return $this->engine->getText($this->user);
+    }
+
+    public function send($title = null, $text = null)
+    {
+        $this->hash = rand_url_id(12);
+        if (!$title) {
+            $title = $this->engine->getTitle();
+        }
+        if (!$text) {
+            $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);
+        $mailer = new PlMailer();
+        $mailer->setFrom($this->sender_mail);
+        $mailer->addTo($this->user['mail']);
+        $mailer->setSubject($title);
+        $mailer->setTxtBody($text);
+        $mailer->send();
+        $this->incr();
+    }
+
+    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, {?}, {?}, {?}, {?})',
+                    $this->user['id'], $this->sender, $this->user['mail'], $this->from, $this->hash,
+                    $this->type, $this->data);
+        $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->submit();
+        }
+        return true;
+    }
+
+    private function incr()
+    {
+        XDB::execute('UPDATE  register_marketing
+                         SET  nb=nb+1, hash={?}, last=NOW()
+                       WHERE  uid={?} AND email={?}',
+            $this->hash, $this->user['id'], $this->user['mail']);
+    }
+
+    static public function getEngineList($exclude_data = true)
+    {
+        $array = array();
+        foreach (Marketing::$engines as $e => $d) {
+            if (!$d[1] || !$exclude_data) {
+                $array[] = $e;
+            }
+        }
+        return $array;
+    }
+
+    static public function get($uid, $email)
+    {
+        $res = XDB::query("SELECT  uid, email, message, message_data, type, sender
+                             FROM  register_marketing
+                            WHERE  uid = {?} AND email = {?}", $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);
+    }
+
+    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_subs WHERE uid = {?}", $uid);
+        }
+    }
+
+    static public function relance($uid, $nbx = -1)
+    {
+        global $globals;
+
+        if ($nbx < 0) {
+            $res = XDB::query("SELECT COUNT(*) FROM auth_user_md5 WHERE deces=0");
+            $nbx = $res->fetchOneCell();
+        }
+    
+        $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()) {
+            return false;
+        }
+    
+        require_once('secure_hash.inc.php');
+        $hash     = rand_url_id(12);
+        $pass     = rand_pass();
+        $pass_encrypted = hash_encrypt($pass);
+        $fdate    = strftime('%d %B %Y', strtotime($date));
+    
+        $mymail = new PlMailer('marketing/mail.relance.tpl');
+        $mymail->assign('nbdix',      $nbx);
+        $mymail->assign('fdate',      $fdate);
+        $mymail->assign('lusername',  $alias);
+        $mymail->assign('nveau_pass', $pass);
+        $mymail->assign('baseurl',    $globals->baseurl);
+        $mymail->assign('lins_id',    $hash);
+        $mymail->assign('lemail',     $email);
+        $mymail->assign('subj',       $alias.'@'.$globals->mail->domain);
+        $mymail->send();
+        XDB::execute('UPDATE  register_pending
+                         SET  hash={?}, password={?}, relance=NOW()
+                       WHERE uid={?}', $hash, $pass_encrypted, $uid);
+        return "$prenom $nom ($promo)";
+    }
 }
-// }}}
-// {{{ function mark_send_mail()
 
-function mark_send_mail($uid, $email, $perso, $to='', $title='', $text='') 
+interface MarketingEngine
 {
-    $hash = rand_url_id(12);
-    XDB::execute('UPDATE register_marketing SET nb=nb+1,hash={?},last=NOW() WHERE uid={?} AND email={?}', $hash, $uid, $email);
-    if ($to == '')
-        list($to, $title, $text) = mark_text_mail($uid, $email);
-
-    if ($perso == 'staff')
-        $from = "\"Equipe Polytechnique.org\" <register@polytechnique.org>";
-    else
-        $from = mark_from_mail($uid, $email);
-    
-    $sender = substr($from, 1, strpos($from, '"', 2)-1);
-    $text = str_replace(array("%%hash%%", "%%sender%%"), array($hash, $sender), $text);
-
-    $mailer = new PlMailer();
-    $mailer->setFrom($from);
-    $mailer->addTo($to);
-    $mailer->setSubject($title);
-    $mailer->setTxtBody(wordwrap($text, 80));
-    $mailer->send();
+    public function __construct($data, $from);
+    public function getTitle();
+    public function getText(array $user);
+    public function process(array $user);
 }
 
-// }}}
-// {{{ function relance
+// 
+class AnnuaireMarketing implements MarketingEngine
+{
+    protected $titre;
+    protected $intro;
 
-function relance($uid, $nbx = -1)
+    public function __construct($data, $from)
+    {
+        $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 "
+                     . "dans la barre de ton navigateur :";
+    }
+
+    public function getTitle()
+    {
+        return $this->titre;
+    }
+
+    private function getIntro()
+    {
+        return $this->intro;
+    }
+
+    protected function prepareText(PlatalPage &$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());
+    }
+
+    public function getText(array $user)
+    {
+        $page = new PlatalPage('marketing/mail.marketing.tpl', NO_SKIN);
+        $this->prepareText($page, $user);
+        return $page->raw();
+    }
+
+    public function process(array $user)
+    {
+    }
+}
+
+class ListMarketing extends AnnuaireMarketing
 {
-    global $globals;
+    private $name;
+    private $domain;
+    public function __construct($data, $from)
+    {
+        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";
+        } 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 :";
+    }
 
-    if ($nbx < 0) {
-        $res = XDB::query("SELECT COUNT(*) FROM auth_user_md5 WHERE deces=0");
-        $nbx = $res->fetchOneCell();
+    public function process(array $user)
+    {
+        return XDB::execute("REPLACE INTO  register_subs (uid, type, sub, domain)
+                                   VALUES  ({?}, 'list', {?}, {?})",
+                            $user['id'], $this->name, $this->domain);
     }
+}
 
-    $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()) {
-        return false;
+class GroupMarketing extends AnnuaireMarketing
+{
+    private $group;
+    public function __construct($data, $from)
+    {
+        $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";
+        } 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 :";
     }
 
-    require_once('secure_hash.inc.php');
-    
-    $hash     = rand_url_id(12);
-    $pass     = rand_pass();
-    $pass_encrypted = hash_encrypt($pass);
-    $fdate    = strftime('%d %B %Y', strtotime($date));
-    
-    $mymail = new PlMailer('marketing/mail.relance.tpl');
-    $mymail->assign('nbdix',      $nbx);
-    $mymail->assign('fdate',      $fdate);
-    $mymail->assign('lusername',  $alias);
-    $mymail->assign('nveau_pass', $pass);
-    $mymail->assign('baseurl',    $globals->baseurl);
-    $mymail->assign('lins_id',    $hash);
-    $mymail->assign('lemail',     $email);
-    $mymail->assign('subj',       $alias.'@'.$globals->mail->domain);
-    $mymail->send();
-    XDB::execute('UPDATE register_pending SET hash={?}, password={?}, relance=NOW() WHERE uid={?}', $hash, $pass_encrypted, $uid);
-
-    return "$prenom $nom ($promo)";
+    public function process(array $user)
+    {
+        return XDB::execute("REPLACE INTO  register_subs (uid, type, sub, domain)
+                                   VALUES  ({?}, 'group', {?}, '')",
+                            $user['id'], $this->group);
+    }
 }
 
-// }}}
+/// Make AnnuaireMarketing to be the default message
+class DefaultMarketing extends AnnuaireMarketing
+{
+}
 
 // vim:set et sw=4 sts=4 sws=4 enc=utf-8:
 ?>
index 42e776a..8b0b211 100644 (file)
@@ -38,7 +38,15 @@ define('DO_AUTH', 1);
 
 function __autoload($cls)
 {
-    @include dirname(dirname(__FILE__)).'/classes/'.strtolower($cls).'.php';
+    $cls  = strtolower($cls);
+    $path = dirname(dirname(__FILE__));
+    if (!@include "$path/classes/$cls.php") {
+        if (substr($cls, -1, 3) == 'req') {
+            @include 'validations.inc.php';
+            return;
+        }
+        @include "$cls.inc.php";
+    }
 }
 __autoload('Env');
 
index 83ca858..7b5c759 100644 (file)
@@ -32,6 +32,8 @@ class MarkReq extends Validate
     public $m_prenom;
     public $m_promo;
     public $m_relance;
+    public $m_type;
+    public $m_data;
 
     public $rules = "Accepter si l'adresse mail parait correcte, et pas absurde (ou si le marketeur est de confiance). Si le 
     demandeur marque sa propre adresse mail, refuser dans tous les cas.
@@ -40,12 +42,14 @@ class MarkReq extends Validate
     // }}}
     // {{{ constructor
 
-    public function __construct($sender, $mark_id, $email, $perso = false)
+    public function __construct($sender, $mark_id, $email, $perso, $type, $data)
     {
         parent::__construct($sender, false, 'marketing');
         $this->m_id    = $mark_id;
         $this->m_email = $email;
         $this->perso   = $perso;
+        $this->m_type  = $type;
+        $this->m_data  = $data;
 
         $res = XDB::query('SELECT  u.nom, u.prenom, u.promo
                              FROM  auth_user_md5      AS u
@@ -97,8 +101,11 @@ class MarkReq extends Validate
 
     public function commit()
     {
-        require_once('marketing.inc.php');
-        mark_send_mail($this->m_id, $this->m_email,(!$this->perso)?"staff":"user");
+        $market = Marketing::get($this->m_id, $this->m_email);
+        if ($market == null) {
+            return false;
+        }
+        $market->send(); 
         return true;
     }
 
index 6251800..5edf410 100644 (file)
@@ -788,11 +788,13 @@ class AdminModule extends PLModule
         }
     }
 
-    function handler_validate(&$page, $action = 'list', $id = null) {
+    function handler_validate(&$page, $action = 'list', $id = null)
+    {
         $page->changeTpl('admin/valider.tpl');
         $page->assign('xorg_title','Polytechnique.org - Administration - Valider une demande');
                $page->addCssLink('nl.css');
-               require_once("validations.inc.php");
+        require_once("validations.inc.php");
+
 
         if ($action == 'edit' and !is_null($id)) {
             $page->assign('preview_id', $id);
@@ -824,6 +826,7 @@ class AdminModule extends PLModule
 
         $page->assign('vit', new ValidateIterator());
     }
+
     function handler_validate_answers(&$page, $action = 'list', $id = null) {
         $page->assign('xorg_title','Polytechnique.org - Administration - Réponses automatiques de validation');
         $page->assign('title', 'Gestion des réponses automatiques');
index c593816..c968514 100644 (file)
@@ -387,8 +387,6 @@ class CarnetModule extends PLModule
         $res = XDB::query('SELECT contact
                              FROM contacts
                             WHERE uid = {?}', S::v('uid'));
-
-        require_once('vcard.inc.php');
         $vcard = new VCard($res->fetchColumn(), $photos == 'photos');
         $vcard->do_page(&$page);
     }
index 7225860..c8c5c81 100644 (file)
@@ -87,9 +87,9 @@ class MarketingModule extends PLModule
 
         $page->assign('path', 'marketing/private/'.$uid);
 
-        $res = XDB::query("SELECT nom, prenom, promo, matricule
-                                       FROM auth_user_md5
-                                      WHERE user_id={?} AND perms='pending'", $uid);
+        $res = XDB::query("SELECT  nom, prenom, promo, matricule
+                             FROM  auth_user_md5
+                            WHERE  user_id={?} AND perms='pending'", $uid);
 
         if (list($nom, $prenom, $promo, $matricule) = $res->fetchOneRow()) {
             require_once('user.func.inc.php');
@@ -104,43 +104,46 @@ class MarketingModule extends PLModule
         }
 
         if ($action == 'del') {
-            XDB::execute('DELETE FROM register_marketing WHERE uid={?} AND email={?}',
-                                   $uid, $value);
+            Marketing::clear($uid, $value);
         }
 
         if ($action == 'rel') {
-            require_once('marketing.inc.php');
-            list($to, $title, $text) = mark_text_mail($uid, $value);
-            $from = mark_from_mail($uid, $value);
-            $page->assign('rel_from_user', $from);
-            $page->assign('rel_from_staff',
-                          "\"Equipe Polytechnique.org\" <register@polytechnique.org>");
-            $page->assign('rel_to', $to);
-            $page->assign('rel_title', $title);
-            $page->assign('rel_text', $text);
-            $page->assign('rel_email', $value);
+            $market = Marketing::get($uid, $value);
+            if ($market == null) {
+                $page->trig("Aucun marketing n'a été effectué vers $value");
+            } else {
+                $to    = $market->user['to'];
+                $title = $market->getTitle();
+                $text  = $market->getText();
+                $from  = $market->sender_mail;
+                $page->assign('rel_from_user', $from);
+                $page->assign('rel_from_staff',
+                              '"Equipe Polytechnique.org" <register@polytechnique.org>');
+                $page->assign('rel_to', $to);
+                $page->assign('rel_title', $title);
+                $page->assign('rel_text', $text);
+                $page->assign('rel_email', $value);
+            }
         }
 
         if ($action == 'relforce') {
-            require_once('marketing.inc.php');
-            mark_send_mail($uid, $value, Post::v('from'), Post::v('to'),
-                           Post::v('title'), Post::v('message'));
+            $market = Marketing::get($uid, Post::v('to'));
+            if (is_null($market)) {
+                $market = new Marketing($uid, Post::v('to'), 'default', null, 'staff');
+            }
+            $market->send(Post::v('title'), Post::v('message'));
             $page->trig("Mail envoyé");
         }
 
         if ($action == 'insrel') {
-            require_once 'marketing.inc.php';
-            if (relance($uid)) {
+            if (Marketing::relance($uid)) {
                 $page->trig('relance faite');
             }
         }
 
         if ($action == 'add' && Post::has('email') && Post::has('type')) {
-            XDB::execute(
-                "INSERT INTO register_marketing
-                         SET uid = {?}, sender = {?}, email = {?},
-                             date = NOW(), type = {?}",
-                $uid, S::v('uid'), Post::v('email'), Post::v('type')); 
+            $market = new Marketing($uid, Post::v('email'), 'default', null, Post::v('type'), S::v('uid'));
+            $market->add(false);
         }
 
         $res = XDB::iterator(
@@ -152,7 +155,7 @@ class MarketingModule extends PLModule
         $page->assign('addr', $res);
 
         $res = XDB::query("SELECT date, relance FROM register_pending
-                                      WHERE uid = {?}", $uid);
+                            WHERE uid = {?}", $uid);
         if (list($pending, $relance) = $res->fetchOneRow()) {
             $page->assign('pending', $pending);
             $page->assign('relance', $relance);
@@ -229,7 +232,7 @@ class MarketingModule extends PLModule
         $page->assign('promo', $promo);
 
         $sql = "SELECT  u.user_id, u.nom, u.prenom, u.last_known_email, u.matricule_ax,
-                        IF(MAX(m.last)>p.relance, MAX(m.last), p.relance) AS dern_rel, p.email
+                        IF(MAX(m.last) > p.relance, MAX(m.last), p.relance) AS dern_rel, p.email
                   FROM  auth_user_md5      AS u
              LEFT JOIN  register_pending   AS p ON p.uid = u.user_id
              LEFT JOIN  register_marketing AS m ON m.uid = u.user_id
@@ -257,26 +260,17 @@ class MarketingModule extends PLModule
 
             if (Post::has('valide')) {
                 require_once('xorg.misc.inc.php');
-
                 $email = trim(Post::v('mail'));
-                $res   = XDB::query('SELECT COUNT(*) FROM register_marketing
-                                                WHERE uid={?} AND email={?}', $uid, $email);
-
+                $market = Marketing::get($uid, $emails);
                 if (!isvalid_email_redirection($email)) {
                     $page->trig("Email invalide !");
-                } elseif ($res->fetchOneCell()) {
+                } elseif ($market) {
                     $page->assign('already', true);
                 } else {
                     $page->assign('ok', true);
                     check_email($email, "Une adresse surveillée est proposée au marketing par " . S::v('forlife'));
-                    XDB::execute(
-                            "INSERT INTO  register_marketing (uid,sender,email,date,last,nb,type,hash)
-                                  VALUES  ({?}, {?}, {?}, NOW(), 0, 0, {?}, '')",
-                            $uid, S::v('uid'), $email, Post::v('origine'));
-                    require_once('validations.inc.php');
-                    $req = new MarkReq(S::v('uid'), $uid, $email,
-                                       Post::v('origine')=='user');
-                    $req->submit();
+                    $market = new Marketing($uid, $email, 'default', null, Post::v('origine'), S::v('uid'));
+                    $market->add();
                 }
             }
         }
@@ -325,14 +319,12 @@ class MarketingModule extends PLModule
         $page->changeTpl('marketing/relance.tpl');
 
         if (Post::has('relancer')) {
-            require_once 'marketing.inc.php';
-
             $res   = XDB::query("SELECT COUNT(*) FROM auth_user_md5 WHERE deces=0");
             $nbdix = $res->fetchOneCell();
 
             $sent  = Array();
             foreach (array_keys($_POST['relance']) as $uid) {
-                if ($tmp = relance($uid, $nbdix)) {
+                if ($tmp = Marketing::relance($uid, $nbdix)) {
                     $sent[] = $tmp.' a été relancé';
                 }
             }
index e6de2ca..3e00705 100644 (file)
@@ -702,7 +702,6 @@ class ProfileModule extends PLModule
             $x = substr($x, 0, strlen($x) - 4);
         }
 
-        require_once('vcard.inc.php');
         $vcard = new VCard($x);
         $vcard->do_page($page);
     }
index 3126d1a..cbf425e 100644 (file)
@@ -348,7 +348,7 @@ class RegisterModule extends PLModule
             $mymail->send(); 
         }
 
-        XDB::execute("DELETE FROM register_marketing WHERE uid = {?}", $uid);
+        Marketing::clear($uid);
 
         pl_redirect('register/success');
         $page->assign('uid', $uid);
index ed0e901..8aa13cf 100644 (file)
@@ -218,6 +218,7 @@ class SearchModule extends PLModule
             $page->assign('promo_min', $min);
             $page->assign('promo_max', $max); 
             $page->assign('formulaire',1);
+            $page->addJsLink('ajax.js');
         }
 
         $page->register_modifier('display_lines', 'display_lines');
index d16a08a..f37d9ba 100644 (file)
@@ -467,7 +467,6 @@ class XnetGrpModule extends PLModule
             $res = XDB::query('SELECT uid
                                  FROM groupex.membres
                                 WHERE asso_id = {?}', $globals->asso('id'));
-            require_once('vcard.inc.php');
             $vcard = new VCard($res->fetchColumn(), $photos == 'photos', 'Membre du groupe ' . $globals->asso('nom'));
             $vcard->do_page($page);
         } else {
@@ -712,22 +711,17 @@ class XnetGrpModule extends PLModule
                                          FROM auth_user_md5
                                         WHERE user_id = {?} AND perms = 'pending'", $uid);
                     if ($res->numRows() == 1) {
-                        XDB::execute('INSERT INTO groupex.membres (uid, asso_id, origine, email)
-                                           VALUES ({?}, {?}, "X", {?})',
-                                               $uid, $globals->asso('id'), $email);
                         if (Env::v('market')) {
-                            $res   = XDB::query('SELECT COUNT(*)
-                                                   FROM register_marketing
-                                                  WHERE uid={?} AND email={?}', $uid, $email);
-                            if (!$res->fetchOneCell()) {
-                                XDB::execute("INSERT INTO  register_marketing (uid,sender,email,date,last,nb,type,hash)
-                                                   VALUES  ({?}, {?}, {?}, NOW(), 0, 0, {?}, '')",
-                                             $uid, S::v('uid'), $email, Env::v('market_from')); 
-                                require_once('validations.inc.php');
-                                $req = new MarkReq(S::v('uid'), $uid, $email, Env::v('market_from') == 'user');
-                                $req->submit();
+                            $market = Marketing::get($uid, $email);
+                            if (!$market) {
+                                $market = new Marketing($uid, $email, 'group', $globals->asso('nom'),
+                                                        Env::v('market_from'), S::v('uid'));
+                                $market->add();
                             }            
                         }
+                        XDB::execute('INSERT INTO groupex.membres (uid, asso_id, origine, email)
+                                           VALUES ({?}, {?}, "X", {?})',
+                                     $uid, $globals->asso('id'), $email);
                         pl_redirect("member/$email");
                     }
                     $page->trig("Utilisateur invalide");
index 4d23082..d98d67d 100644 (file)
@@ -27,7 +27,7 @@
 
 {counter print=false start=0 assign=hidden}
 
-{iterate item=valid from=$vit|smarty:nodefaults}
+{iterate item=valid from=$vit}
 {assign var=type value=$valid->type}
 {if !$hide_requests[$type]}
 <br />
@@ -39,7 +39,7 @@
     <td class="titre" style="width: 20%">Demandeur&nbsp;:</td>
     <td>
       <a href="profile/{$valid->bestalias}" class="popup2">
-        {$valid->prenom} {$valid->nom} (X{$valid->promo})
+        {$valid->prenom|utf8_encode} {$valid->nom|utf8_encode} (X{$valid->promo})
       </a>
     </td>
   </tr>
index 0992aa1..46a9298 100644 (file)
 {*                                                                        *}
 {**************************************************************************}
 
-{if $valid->m_relance neq '0000-00-00'}
-{if $valid->m_relance neq ''} {* provided for backward compatibility, may disappear in the future *}
+{if $valid->m_relance neq '0000-00-00' && $valid->m_relance neq ''}
   <tr class="pair">
     <td class="titre">Dernière relance le :</td>
     <td>{$valid->m_relance|date_format}</td>
   </tr>
 {/if}
-{/if}
 <tr class="pair">
   <td class="titre">Marketing sur</td>
   <td><a href='marketing/private/{$valid->m_id}'>{$valid->m_prenom} {$valid->m_nom} ({$valid->m_promo})</a></td>
 </tr>
+{if $valid->m_type neq 'default'}
+<tr class="pair">
+  <td class="titre">Type de message</td>
+  <td>{$valid->m_type} {$valid->m_data}</td>
+</tr>
+{/if}
 <tr class="pair">
   <td class="titre">Mail deviné</td>
   <td>{$valid->m_email}</td>
diff --git a/templates/marketing/mail.marketing.tpl b/templates/marketing/mail.marketing.tpl
new file mode 100644 (file)
index 0000000..4d05531
--- /dev/null
@@ -0,0 +1,48 @@
+{**************************************************************************}
+{*                                                                        *}
+{*  Copyright (C) 2003-2007 Polytechnique.org                             *}
+{*  http://opensource.polytechnique.org/                                  *}
+{*                                                                        *}
+{*  This program is free software; you can redistribute it and/or modify  *}
+{*  it under the terms of the GNU General Public License as published by  *}
+{*  the Free Software Foundation; either version 2 of the License, or     *}
+{*  (at your option) any later version.                                   *}
+{*                                                                        *}
+{*  This program is distributed in the hope that it will be useful,       *}
+{*  but WITHOUT ANY WARRANTY; without even the implied warranty of        *}
+{*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *}
+{*  GNU General Public License for more details.                          *}
+{*                                                                        *}
+{*  You should have received a copy of the GNU General Public License     *}
+{*  along with this program; if not, write to the Free Software           *}
+{*  Foundation, Inc.,                                                     *}
+{*  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA               *}
+{*                                                                        *}
+{**************************************************************************}
+{if $u.sexe}Chère{else}Cher{/if} Camarade,
+
+{$intro}
+
+==========================================================
+{#globals.baseurl#}/register/%%hash%%
+==========================================================
+
+Il ne te faut que 5 minutes sur https://www.polytechnique.org/ pour rejoindre les {$num_users} camarades branchés grâce au système de reroutage de l'X et qui permet de joindre un camarade en connaissant seulement son nom et son prénom... et  de bénéficier pour la vie d'une adresse prestigieuse {$u.forlife}@polytechnique.org et son alias discret {$u.forlife}@m4x.org (m4x = ail for X).
+
+Pas de nouvelle boîte aux lettres à relever, il suffit de la rerouter vers ton adresse personnelle et/ou professionnelle que tu indiques et que tu peux changer tous les jours si tu veux sans imposer à tes correspondants de modifier leur carnet d'adresses...
+
+De plus, le site web offre les services d'annuaire (recherche multi-critères), de forums, de mailing-lists. Ce portail est géré par une dizaine de jeunes camarades, avec le soutien et les conseils de nombreux X de toutes promotions, incluant notamment des camarades de la Kès des élèves de l'X et d'autres de l'AX. Les serveurs sont hébergés au sein même de l'Ecole Polytechnique, sur une connexion rapide, et les services évoluent en fonction des besoins exprimés par la communauté sur Internet.
+
+N'hésite pas à transmettre ce message à tes camarades ou à nous écrire, nous proposer toute amélioration ou suggestion pour les versions prochaines du site.
+
+A bientôt sur https://www.polytechnique.org
+Bien à toi,
+%%sender%%
+
+-- 
+Polytechnique.org
+"Le portail des élèves & anciens élèves de l'X"
+https://www.polytechnique.org/
+http://www.polytechnique.net
+
+{* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *}
index 1adf200..0df5d09 100644 (file)
@@ -103,10 +103,14 @@ sa dernière relance date du {$relance|date_format}
     </tr>
     <tr class="pair">
       <td align="right"><strong>From:</strong></td>
+      {if $rel_from_staff neq $rel_from_user}
       <td><select name="from">
         <option value="staff">{$rel_from_staff}</option>
-        <option value="user">{$rel_from_user}</option>
+        <option value="user" selected="selected">{$rel_from_user}</option>
       </select></td>
+      {else}
+      {$rel_from_staff}<input type="hidden" name="from" value="staff" />
+      {/if}
     </tr>
     <tr class="pair">
       <td align="right"><strong>To:</strong></td>
index 43162a7..7abdf64 100644 (file)
@@ -26,7 +26,6 @@
 
 <div id="message" style="position:absolute;"></div><br />
 
-<script type="text/javascript" src="javascript/ajax.js"></script>
 <script type="text/javascript">
   {literal}
   function showPromo()
diff --git a/upgrade/0.9.14/05_marketing.sql b/upgrade/0.9.14/05_marketing.sql
new file mode 100644 (file)
index 0000000..2998d0d
--- /dev/null
@@ -0,0 +1,13 @@
+alter table register_marketing add column message varchar(16) not null default 'default';
+alter table register_marketing add column message_data varchar(64);
+create table register_subs
+(
+    uid smallint(4) unsigned not null,
+    type enum('list', 'group') not null default 'list',
+    sub varchar(32) not null,
+    domain varchar(64) not null,
+
+    primary key id (uid, type, sub, domain)
+) charset=utf8;
+
+# vim:set syntax=mysql: