Clear mentor entry of the user when is expertise is empty.
[platal.git] / modules / marketing.php
index 6a5f744..a272c31 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /***************************************************************************
- *  Copyright (C) 2003-2007 Polytechnique.org                              *
+ *  Copyright (C) 2003-2008 Polytechnique.org                              *
  *  http://opensource.polytechnique.org/                                   *
  *                                                                         *
  *  This program is free software; you can redistribute it and/or modify   *
@@ -79,6 +79,7 @@ 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)) {
@@ -118,7 +119,7 @@ class MarketingModule extends PLModule
                 $from  = $market->sender_mail;
                 $page->assign('rel_from_user', $from);
                 $page->assign('rel_from_staff',
-                              '"Equipe Polytechnique.org" <register@' . $globals->mails->domain . '>');
+                              '"Equipe Polytechnique.org" <register@' . $globals->mail->domain . '>');
                 $page->assign('rel_to', $to);
                 $page->assign('rel_title', $title);
                 $page->assign('rel_text', $text);
@@ -178,7 +179,8 @@ class MarketingModule extends PLModule
         }
 
         $res = Xdb::query("SELECT  u.nom, u.prenom, u.promo, FIND_IN_SET('femme', u.flags) AS sexe,
-                                   a.alias AS forlife, b.alias AS bestalias, e.email, e.last
+                                   u.deces = '0000-00-00' AS alive, a.alias AS forlife, b.alias AS bestalias,
+                                   IF(e.email IS NOT NULL, e.email, IF(FIND_IN_SET('googleapps', u.mail_storage), 'googleapps', NULL)) AS email, e.last
                              FROM  auth_user_md5 AS u
                        INNER JOIN  aliases       AS a ON (a.id = u.user_id AND a.type = 'a_vie')
                        INNER JOIN  aliases       AS b ON (b.id = u.user_id AND FIND_IN_SET('bestalias', b.flags))
@@ -261,16 +263,21 @@ class MarketingModule extends PLModule
             if (Post::has('valide')) {
                 require_once('xorg.misc.inc.php');
                 $email = trim(Post::v('mail'));
-                $market = Marketing::get($uid, $emails);
+
                 if (!isvalid_email_redirection($email)) {
                     $page->trig("Email invalide !");
-                } 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'));
-                    $market = new Marketing($uid, $email, 'default', null, Post::v('origine'), S::v('uid'));
-                    $market->add();
+                    // On cherche les marketings précédents sur cette adresse
+                    // email, en se restreignant au dernier mois
+
+                    if (Marketing::get($uid, $email, true)) {
+                        $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'));
+                        $market = new Marketing($uid, $email, 'default', null, Post::v('origine'), S::v('uid'));
+                        $market->add();
+                    }
                 }
             }
         }