Implements promo limits
authorx2003bruneau <x2003bruneau@839d8a87-29fc-0310-9880-83ba4fa771e5>
Fri, 19 Jan 2007 21:57:29 +0000 (21:57 +0000)
committerx2003bruneau <x2003bruneau@839d8a87-29fc-0310-9880-83ba4fa771e5>
Fri, 19 Jan 2007 21:57:29 +0000 (21:57 +0000)
git-svn-id: svn+ssh://murphy/home/svn/platal/trunk@1364 839d8a87-29fc-0310-9880-83ba4fa771e5

include/massmailer.inc.php
modules/axletter/axletter.inc.php
templates/axletter/letter.tpl
templates/axletter/unsubscribe.tpl [new file with mode: 0644]
upgrade/0.9.13/04_axletter.sql

index 02a93a8..79b0fa0 100644 (file)
@@ -141,7 +141,7 @@ abstract class MassMailer
         while (true) {
             $res = XDB::iterRow($query, $this->_id, 60);
             if (!$res->total()) {
-                exit;
+                return;
             }
             $sent = array();
             while (list($uid, $bestalias, $prenom, $nom, $sexe, $fmt, $hash) = $res->next()) {
index 9aa8cb6..0f16c36 100644 (file)
@@ -107,7 +107,8 @@ class AXLetter extends MassMailer
              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 (e.email IS NOT NULL OR ni.user_id = 0)
+                 WHERE  ni.last < {?} AND {$this->subscriptionWhere()}
+                        AND (e.email IS NOT NULL OR ni.user_id = 0)
               GROUP BY  u.user_id";
     }              
 
@@ -163,7 +164,17 @@ class AXLetter extends MassMailer
 
     protected function subscriptionWhere()
     {
-        return 'ni.last';
+        if (!$this->_promo_min && !$this->_promo_max) {
+            return '1';
+        }
+        $where = array();
+        if ($this->_promo_min) {
+            $where[] = "((ni.user_id = 0 AND ni.promo >= {$this->_promo_min}) OR (ni.user_id != 0 AND u.promo >= {$this->_promo_min}))";
+        }
+        if ($this->_promo_max) {
+            $where[] = "((ni.user_id = 0 AND ni.promo <= {$this->_promo_max}) OR (ni.user_id != 0 AND u.promo <= {$this->_promo_max}))";
+        }
+        return implode(' AND ', $where);
     }
 
     static public function awaiting()
index 7e19cc8..c9f25d0 100644 (file)
@@ -44,7 +44,7 @@
 Cette lettre est envoyée par l'AX grâce aux outils de Polytechnique.org.
 
 archives         : [https://www.polytechnique.org/ax]
-ne plus recevoir : [https://www.polytechnique.org/ax/out]
+ne plus recevoir : [https://www.polytechnique.org/ax/out{if $hash}/{$hash}{/if}]
 
 {if !$is_mail}
 </pre>
@@ -77,7 +77,7 @@ ne plus recevoir : [https://www.polytechnique.org/ax/out]
       </div>
       <div class="foot2">
         [<a href="https://www.polytechnique.org/ax">archives</a>&nbsp;|
-        <a href="https://www.polytechnique.org/ax/out">ne plus recevoir</a>]
+        <a href="https://www.polytechnique.org/ax/out{if $hash}/{$hash}{/if}">ne plus recevoir</a>]
       </div>
     </div>
 {if $is_mail}
diff --git a/templates/axletter/unsubscribe.tpl b/templates/axletter/unsubscribe.tpl
new file mode 100644 (file)
index 0000000..3407308
--- /dev/null
@@ -0,0 +1,41 @@
+{**************************************************************************}
+{*                                                                        *}
+{*  Copyright (C) 2003-2006 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               *}
+{*                                                                        *}
+{**************************************************************************}
+
+<h1>Désinscription des envois de l'AX</h1>
+
+{if $success}
+<p>
+  Votre inscription aux envois exceptionnels de l'AX a été réalisée avec
+  succès. Si vous désirez vous réinscrire, merci de contacter
+  <a href="mailto:info@amicale.polytechnique.org">l'AX</a>. Vous pouvez également
+  le faire en vous <a href="register">inscrivant à Polytechnique.org</a> (pour 
+  les X uniquement).
+</p>
+{else}
+<p>
+  Votre inscription aux envois de l'AX n'a pu être résiliée. Merci de contacter
+  au plus vite <a href="mailto:info@amicale.polytechnique.org">l'AX</a> pour faire
+  part de ce problème.
+</p>
+{/if}
+
+{* vim:set et sw=2 sts=2 sws=2: *}
index 4c14495..492e64e 100644 (file)
@@ -20,6 +20,7 @@ CREATE TABLE axletter_ins (
     flag set('femme') default '',
     prenom varchar(32) default NULL,
     nom varchar(255) default NULL,
+    promo smallint(4) default 0,
     last int(11) NOT NULL default 0,
     hash varchar(32) default NULL,