Use Profile for vcards
[platal.git] / modules / axletter / axletter.inc.php
index e238c41..b42ad35 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /***************************************************************************
- *  Copyright (C) 2003-2009 Polytechnique.org                              *
+ *  Copyright (C) 2003-2010 Polytechnique.org                              *
  *  http://opensource.polytechnique.org/                                   *
  *                                                                         *
  *  This program is free software; you can redistribute it and/or modify   *
@@ -29,6 +29,7 @@ class AXLetter extends MassMailer
     public $_promo_max;
     public $_subset;
     public $_subset_to;
+    public $_subset_rm;
     public $_echeance;
     public $_date;
     public $_bits;
@@ -56,11 +57,11 @@ class AXLetter extends MassMailer
         }
         list($this->_id, $this->_shortname, $this->_title_mail, $this->_title,
              $this->_body, $this->_signature, $this->_promo_min, $this->_promo_max,
-             $this->_subset_to, $this->_echeance, $this->_date, $this->_bits) = $id;
+             $this->_subset_to, $this->_subset_rm, $this->_echeance, $this->_date, $this->_bits) = $id;
         if ($this->_date == '0000-00-00') {
             $this->_date = 0;
         }
-        $this->_subset_to = explode("\n", $this->_subset_to);
+        $this->_subset_to = ($this->_subset_to ? explode("\n", $this->_subset_to) : null);
         $this->_subset = (count($this->_subset_to) > 0);
     }
 
@@ -100,26 +101,6 @@ class AXLetter extends MassMailer
                        WHERE  id={?}", $this->_id);
     }
 
-    protected function getAllRecipients()
-    {
-        global $globals;
-        return "SELECT  ni.user_id, IF(ni.user_id = 0, NULL, u.hruid) AS hruid,
-                        IF(ni.user_id = 0, ni.email, CONCAT(a.alias, '@{$globals->mail->domain}')) AS alias,
-                        IF(ni.user_id = 0, ni.prenom, u.prenom) AS prenom,
-                        IF(ni.user_id = 0, ni.nom, IF(u.nom_usage='', u.nom, u.nom_usage)) AS nom,
-                        FIND_IN_SET('femme', IF(ni.user_id = 0, ni.flag, u.flags)) AS sexe,
-                        IF(ni.user_id = 0, 'html', q.core_mail_fmt) AS pref,
-                        IF(ni.user_id = 0, ni.hash, 0) AS hash
-                  FROM  axletter_ins  AS ni
-             LEFT JOIN  auth_user_md5   AS u  USING(user_id)
-             LEFT JOIN  auth_user_quick AS q  ON(q.user_id = u.user_id)
-             LEFT JOIN  aliases         AS a  ON(u.user_id=a.id AND FIND_IN_SET('bestalias',a.flags))
-             LEFT JOIN  emails          AS e  ON(e.uid=u.user_id AND e.flags='active')
-                 WHERE  ni.last < {?} AND {$this->subscriptionWhere()}
-                        AND (e.email IS NOT NULL OR FIND_IN_SET('googleapps', u.mail_storage) OR ni.user_id = 0)
-              GROUP BY  u.user_id";
-    }
-
     static public function subscriptionState($uid = null)
     {
         $user = is_null($uid) ? S::v('uid') : $uid;
@@ -205,8 +186,12 @@ class AXLetter extends MassMailer
             require_once("emails.inc.php");
             $ids = ids_from_mails($this->_subset_to);
             $ids_list = implode(',', $ids);
-            if(count($ids_list) > 0) {
-                $where[] = "ni.user_id IN ($ids_list)";
+            if(count($ids) > 0) {
+                if ($this->_subset_rm) {
+                    $where[] = "ni.user_id NOT IN ($ids_list)";
+                } else {
+                    $where[] = "ni.user_id IN ($ids_list)";
+                }
             } else {
                 // No valid email
                 $where[] = "0";