Adds option to invert a subset definition in axletter (Closes #980).
authorRaphaël Barrois <raphael.barrois@polytechnique.org>
Fri, 18 Sep 2009 11:06:38 +0000 (13:06 +0200)
committerRaphaël Barrois <raphael.barrois@polytechnique.org>
Fri, 18 Sep 2009 11:06:38 +0000 (13:06 +0200)
Signed-off-by: Raphaël Barrois <raphael.barrois@polytechnique.org>
modules/axletter.php
modules/axletter/axletter.inc.php
templates/axletter/edit.tpl
upgrade/0.10.2/00_axletter.sql [new file with mode: 0644]

index b27dc7d..9eb253a 100644 (file)
@@ -92,6 +92,7 @@ class AXLetterModule extends PLModule
         $promo_max  = Post::i('promo_max');
         $subset_to  = preg_split("/[ ,;\:\n\r]+/", Post::v('subset_to'), -1, PREG_SPLIT_NO_EMPTY);
         $subset     = (count($subset_to) > 0);
+        $subset_rm  = Post::b('subset_rm');
         $echeance   = Post::has('echeance_date') ?
               preg_replace('/^(\d\d\d\d)(\d\d)(\d\d)$/', '\1-\2-\3', Post::v('echeance_date')) . ' ' . Post::v('echeance_time')
             : Post::v('echeance');
@@ -155,15 +156,15 @@ class AXLetterModule extends PLModule
               case 'Aperçu':
                 $this->load('axletter.inc.php');
                 $al = new AXLetter(array($id, $short_name, $subject, $title, $body, $signature,
-                                         $promo_min, $promo_max, $subset, $echeance, 0, 'new'));
+                                         $promo_min, $promo_max, $subset, $subset_rm, $echeance, 0, 'new'));
                 $al->toHtml($page, S::v('prenom'), S::v('nom'), S::v('femme'));
                 break;
 
               case 'Confirmer':
                 XDB::execute("REPLACE INTO  axletter
                                        SET  id = {?}, short_name = {?}, subject = {?}, title = {?}, body = {?},
-                                            signature = {?}, promo_min = {?}, promo_max = {?}, echeance = {?}, subset = {?}",
-                             $id, $short_name, $subject, $title, $body, $signature, $promo_min, $promo_max, $echeance, $subset ? implode("\n", $subset_to) : null);
+                                            signature = {?}, promo_min = {?}, promo_max = {?}, echeance = {?}, subset = {?}, subset_rm = {?}",
+                             $id, $short_name, $subject, $title, $body, $signature, $promo_min, $promo_max, $echeance, $subset ? implode("\n", $subset_to) : null, $subset_rm);
                 if (!$saved) {
                     global $globals;
                     $mailer = new PlMailer();
@@ -207,6 +208,7 @@ class AXLetterModule extends PLModule
         $page->assign('promo_max', $promo_max);
         $page->assign('subset_to', implode("\n", $subset_to));
         $page->assign('subset', $subset);
+        $page->assign('subset_rm', $subset_rm);
         $page->assign('echeance', $echeance);
         $page->assign('echeance_date', $echeance_date);
         $page->assign('echeance_time', $echeance_time);
index d85d25f..f007160 100644 (file)
@@ -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,7 +57,7 @@ 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;
         }
@@ -206,7 +207,11 @@ class AXLetter extends MassMailer
             $ids = ids_from_mails($this->_subset_to);
             $ids_list = implode(',', $ids);
             if(count($ids) > 0) {
-                $where[] = "ni.user_id IN ($ids_list)";
+                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";
index 5d71278..1ed192b 100644 (file)
     {include file="include/field.promo.tpl" prefix=""}
     <tr>
       <td class="titre">Envoyer à une liste d'adresses</td>
-      <td><textarea name="subset_to" rows="7" cols="78">{$subset_to}</textarea><br />
+      <td>
+      <textarea name="subset_to" rows="7" cols="78">{$subset_to}</textarea><br />
       <span class="smaller">Indiquez une liste d'adresses emails : la lettre sera envoyée uniquement aux personnes des promotions sélectionnées, dont l'adresse figure dans la liste, et qui souhaitent recevoir les emails de l'AX.</span>
       </td>
     </tr>
+    <tr>
+      <td class="titre">Sélection inversée</td>
+      <td>
+      <input type="checkbox" name="subset_rm" {if $subset_rm}checked{/if} /><span class="smaller">En cochant cette case, la liste sera envoyée à tous les inscrits de l'intervalle de promotions sélectionné, sauf ceux indiqués dans la liste ci-dessus.</span>
+      </td>
+    </tr>
     {if !$saved}
     <tr>
       <td class="titre">Echéance d'envoi</td>
diff --git a/upgrade/0.10.2/00_axletter.sql b/upgrade/0.10.2/00_axletter.sql
new file mode 100644 (file)
index 0000000..d418eeb
--- /dev/null
@@ -0,0 +1,3 @@
+ALTER TABLE axletter ADD subset_rm boolean DEFAULT false AFTER subset;
+
+-- vim:set syntax=mysql: