2006 => 2007 Happy New Year\!
[platal.git] / modules / marketing.php
index d2ede2a..0235efa 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /***************************************************************************
- *  Copyright (C) 2003-2006 Polytechnique.org                              *
+ *  Copyright (C) 2003-2007 Polytechnique.org                              *
  *  http://opensource.polytechnique.org/                                   *
  *                                                                         *
  *  This program is free software; you can redistribute it and/or modify   *
@@ -32,13 +32,12 @@ class MarketingModule extends PLModule
 
             'marketing/private'    => $this->make_hook('private',    AUTH_MDP, 'admin'),
             'marketing/public'     => $this->make_hook('public',     AUTH_COOKIE),
+            'marketing/broken'     => $this->make_hook('broken',     AUTH_COOKIE),
         );
     }
 
     function handler_marketing(&$page)
     {
-        global $globals;
-
         $page->changeTpl('marketing/index.tpl');
 
         $page->assign('xorg_title','Polytechnique.org - Marketing');
@@ -80,8 +79,6 @@ class MarketingModule extends PLModule
     function handler_private(&$page, $uid = null,
                              $action = null, $value = null)
     {
-        global $globals;
-
         $page->changeTpl('marketing/private.tpl');
 
         if (is_null($uid)) {
@@ -95,7 +92,7 @@ class MarketingModule extends PLModule
                                       WHERE user_id={?} AND perms='pending'", $uid);
 
         if (list($nom, $prenom, $promo, $matricule) = $res->fetchOneRow()) {
-            require_once('register.inc.php');
+            require_once('user.func.inc.php');
             $matricule_X = get_X_mat($matricule);
             $page->assign('nom', $nom);
             $page->assign('prenom', $prenom);
@@ -126,9 +123,9 @@ class MarketingModule extends PLModule
 
         if ($action == 'relforce') {
             require_once('marketing.inc.php');
-            mark_send_mail($uid, $value, Post::get('from'), Post::get('to'),
-                           Post::get('title'), Post::get('message'));
-            $page->trig("Mail envoyé");
+            mark_send_mail($uid, $value, Post::v('from'), Post::v('to'),
+                           Post::v('title'), Post::v('message'));
+            $page->trig("Mail envoyé");
         }
 
         if ($action == 'insrel') {
@@ -143,7 +140,7 @@ class MarketingModule extends PLModule
                 "INSERT INTO register_marketing
                          SET uid = {?}, sender = {?}, email = {?},
                              date = NOW(), type = {?}",
-                $uid, Session::get('uid'), Post::get('email'), Post::get('type')); 
+                $uid, S::v('uid'), Post::v('email'), Post::v('type')); 
         }
 
         $res = XDB::iterator(
@@ -156,20 +153,60 @@ class MarketingModule extends PLModule
 
         $res = XDB::query("SELECT date, relance FROM register_pending
                                       WHERE uid = {?}", $uid);
-        if (list($pending, $relance) = $res->fetchOneCell()) {
+        if (list($pending, $relance) = $res->fetchOneRow()) {
             $page->assign('pending', $pending);
             $page->assign('relance', $relance);
         }
     }
 
-    function handler_promo(&$page, $promo = null)
+    function handler_broken(&$page, $uid = null)
     {
-        global $globals;
+        require_once('user.func.inc.php');
+        $page->changeTpl('marketing/broken.tpl');
+
+        if (is_null($uid)) {
+            return PL_NOT_FOUND;
+        }
+        $forlife = get_user_forlife($uid);
+        if (!$forlife) {
+            return PL_NOT_FOUND;
+        } elseif ($forlife == S::v('forlife')) {
+            pl_redirect('emails/redirect');
+        }
+
+        $res = Xdb::query("SELECT  u.nom, u.prenom, u.promo, a.alias AS forlife
+                             FROM  auth_user_md5 AS u
+                       INNER JOIN  aliases       AS a ON a.id = u.user_id
+                            WHERE  a.alias = {?}", $forlife);
+        if (!$res->numRows()) {
+            return PL_NOT_FOUND;
+        }
+        $user = $res->fetchOneAssoc();
+        $page->assign('user', $user);
+
+        $email = trim(Post::v('mail'));
+        if (Post::has('valide') && strlen($email) > 0) {
+            $mailer = new PlMailer();
+            $mailer->setFrom(S::v('bestalias') . '@polytechnique.org');
+            $mailer->addTo('resetpass@polytechnique.org');
+            $mailer->setSubject("Proposition d'adresse mail pour " . $user['forlife']);
+
+            $message = S::v('nom') . ' ' . S::v('prenom') . ' (X' . S::v('promo') . ') '
+                     . 'propose l\'adresse suivante pour un camarade qui n\'a plus de '
+                     . 'redirections actives :' . "\n\n"
+                     . '* ' . $user['forlife'] . ' => ' . $email . "\n";
+            $mailer->setTxtBody(wordwrap($message, 78));
+            $mailer->send();
+            $page->assign('sent', true);
+        }
+    }
 
+    function handler_promo(&$page, $promo = null)
+    {
         $page->changeTpl('marketing/promo.tpl');
 
         if (is_null($promo)) {
-            $promo = Session::getInt('promo');
+            $promo = S::v('promo');
         }
         $page->assign('promo', $promo);
 
@@ -186,8 +223,6 @@ class MarketingModule extends PLModule
 
     function handler_public(&$page, $uid = null)
     {
-        global $globals;
-
         $page->changeTpl('marketing/public.tpl');
 
         if (is_null($uid)) {
@@ -205,7 +240,7 @@ class MarketingModule extends PLModule
             if (Post::has('valide')) {
                 require_once('xorg.misc.inc.php');
 
-                $email = trim(Post::get('mail'));
+                $email = trim(Post::v('mail'));
                 $res   = XDB::query('SELECT COUNT(*) FROM register_marketing
                                                 WHERE uid={?} AND email={?}', $uid, $email);
 
@@ -218,10 +253,10 @@ class MarketingModule extends PLModule
                     XDB::execute(
                             "INSERT INTO  register_marketing (uid,sender,email,date,last,nb,type,hash)
                                   VALUES  ({?}, {?}, {?}, NOW(), 0, 0, {?}, '')",
-                            $uid, Session::getInt('uid'), $email, Post::get('origine'));
+                            $uid, S::v('uid'), $email, Post::v('origine'));
                     require_once('validations.inc.php');
-                    $req = new MarkReq(Session::getInt('uid'), $uid, $email,
-                                       Post::get('origine')=='user');
+                    $req = new MarkReq(S::v('uid'), $uid, $email,
+                                       Post::v('origine')=='user');
                     $req->submit();
                 }
             }
@@ -230,8 +265,6 @@ class MarketingModule extends PLModule
 
     function handler_week(&$page, $sorting = 'per_promo')
     {
-        global $globals;
-
         $page->changeTpl('marketing/this_week.tpl');
 
         $sort = $sorting == 'per_promo' ? 'promo' : 'date_ins';
@@ -246,8 +279,6 @@ class MarketingModule extends PLModule
 
     function handler_volontaire(&$page, $promo = null)
     {
-        global $globals;
-
         $page->changeTpl('marketing/volontaire.tpl');
 
         $res = XDB::query(
@@ -272,8 +303,6 @@ class MarketingModule extends PLModule
 
     function handler_relance(&$page)
     {
-        global $globals;
-
         $page->changeTpl('marketing/relance.tpl');
 
         if (Post::has('relancer')) {
@@ -285,7 +314,7 @@ class MarketingModule extends PLModule
             $sent  = Array();
             foreach (array_keys($_POST['relance']) as $uid) {
                 if ($tmp = relance($uid, $nbdix)) {
-                    $sent[] = $tmp.' a été relancé';
+                    $sent[] = $tmp.' a été relancé';
                 }
             }
             $page->assign('sent', $sent);