Group animator notifiction edition.
authorStéphane Jacob <sj@m4x.org>
Wed, 2 Nov 2011 12:34:17 +0000 (13:34 +0100)
committerStéphane Jacob <sj@m4x.org>
Wed, 2 Nov 2011 12:34:17 +0000 (13:34 +0100)
Signed-off-by: Stéphane Jacob <sj@m4x.org>
modules/xnetgrp.php
templates/xnetgrp/edit.tpl

index 8960524..21e2002 100644 (file)
@@ -192,6 +192,24 @@ class XnetGrpModule extends PLModule
             } else {
                 $site = "";
             }
+
+            $notify_all = (Post::v('notify_all') ? true : false);
+            if (!$notify_all) {
+                $to_notify = array();
+                $uf = New UserFilter(New UFC_Group($globals->asso('id'), true));
+                $uids = $uf->getIds();
+                foreach ($uids as $uid) {
+                    if (Post::b('to_notify_' . $uid)) {
+                        $to_notify[] = $uid;
+                    }
+                }
+                if (count($to_notify) == 0) {
+                    $notify_all = true;
+                    $page->trigWarning("Aucun animateur n'ayant été selectionné pour recevoir les demandes d'inscriptions, tous le seront.");
+                }
+            }
+            $flags->addFlag('notify_all', $notify_all);
+
             if (S::admin()) {
                 $page->assign('super', true);
 
@@ -300,8 +318,25 @@ class XnetGrpModule extends PLModule
                 }
             }
 
+            XDB::execute("UPDATE  group_members
+                             SET  flags = ''
+                           WHERE  asso_id = {?}",
+                         $globals->asso('id'));
+            if (!$notify_all) {
+                XDB::execute("UPDATE  group_members
+                                 SET  flags = 'notify'
+                               WHERE  asso_id = {?} AND uid IN {?}",
+                             $globals->asso('id'), $to_notify);
+            }
+
             pl_redirect('../' . Post::v('diminutif', $globals->asso('diminutif')) . '/edit');
         }
+
+        $uf = New UserFilter(New UFC_Group($globals->asso('id'), true, UFC_Group::NOTIFIED));
+        $page->assign('notified', $uf->getUsers());
+        $uf = New UserFilter(New UFC_Group($globals->asso('id'), true, UFC_Group::UNNOTIFIED));
+        $page->assign('unnotified', $uf->getUsers());
+
         $page->assign('error', $error);
         $page->assign('cat', $globals->asso('cat'));
         $page->assign('dom', $globals->asso('dom'));
@@ -309,6 +344,7 @@ class XnetGrpModule extends PLModule
         $page->assign('inscriptible', $globals->asso('inscriptible'));
         $page->assign('pub', $globals->asso('pub'));
         $page->assign('notif_unsub', $globals->asso('notif_unsub'));
+        $page->assign('notify_all', $globals->asso('notify_all'));
     }
 
     function handler_mail($page)
index b63c1bd..3ba48be 100644 (file)
 
     <tr>
       <td class="titre">
+        Notifier les demandes d'inscriptions&nbsp;:
+      </td>
+      <td>
+        <label><input type="radio" value="1" {if $notify_all}checked="checked"{/if} name="notify_all"
+          onclick="$('#notification').hide()"/>à tous les animateurs</label>
+        <label><input type="radio" value="0" {if !$notify_all}checked="checked"{/if} name="notify_all"
+          onclick="$('#notification').show()" />seulement à certains</label>
+      </td>
+    </tr>
+    <tr id="notification" {if $notify_all}style="display: none"{/if}>
+      <td></td>
+      <td>
+      {if $notified || $unnotified}
+        <ul>
+        {if $notified}
+        {foreach from=$notified item=user}
+          <li>
+            <label><input type="checkbox" name="to_notify_{$user->id()}" checked="checked" />{$user->fullName(true)}</label>
+          </li>
+        {/foreach}
+        {/if}
+        {if $unnotified}
+        {foreach from=$unnotified item=user}
+          <li>
+            <label><input type="checkbox" name="to_notify_{$user->id()}" />{$user->fullName(true)}</label>
+          </li>
+        {/foreach}
+        {/if}
+        </ul>
+      {/if}
+      </td>
+    </tr>
+
+    <tr>
+      <td class="titre">
         Lien pour l'inscription&nbsp;:<br />
         <em>laisser vide par défaut</em>
       </td>