Payment takes into account the amount when it is given (Closes #1567)
[platal.git] / modules / xnetgrp.php
index 8960524..47f4a8d 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)
@@ -416,9 +452,15 @@ class XnetGrpModule extends PLModule
             $filename = $globals->asso('diminutif') . '.csv';
         }
         $users = $globals->asso()->getMembersFilter(null, new UFO_Name())->getUsers();
-        pl_cached_content_headers('text/x-csv', 1);
-        $page->changeTpl('xnetgrp/annuaire-csv.tpl', NO_SKIN);
-        $page->assign('users', $users);
+        pl_cached_content_headers('text/x-csv', 'iso-8859-1', 1);
+
+        echo utf8_decode("Nom;Prénom;Sexe;Promotion;Commentaire\n");
+        foreach ($users as $user) {
+            $line = $user->lastName() . ';' . $user->firstName() . ';' . ($user->isFemale() ? 'F' : 'M')
+                  . ';' . $user->promo() . ';' . strtr($user->group_comm, ';', ',');
+            echo utf8_decode($line) . "\n";
+        }
+        exit();
     }
 
     function handler_directory_sync($page)
@@ -701,8 +743,7 @@ class XnetGrpModule extends PLModule
             XDB::execute('DELETE FROM  group_former_members
                                 WHERE  uid = {?} AND asso_id = {?}',
                          S::i('uid'), $globals->asso('id'));
-            $uf = New UserFilter(New UFC_Group($globals->asso('id'), true));
-            $admins = $uf->iterUsers();
+            $admins = $globals->asso()->iterToNotify();
             $admin = $admins->next();
             $to = $admin->bestEmail();
             while ($admin = $admins->next()) {
@@ -882,7 +923,7 @@ class XnetGrpModule extends PLModule
             $user = User::getSilent($email);
 
             // Wrong email and no user: failure.
-            if (is_null($user) && !$is_valid_email) {
+            if (is_null($user) && (!$is_valid_email || !User::isForeignEmailAddress($email))) {
                 $page->trigError('«&nbsp;<strong>' . $email . '</strong>&nbsp;» n\'est pas une adresse email valide.');
                 return;
             }
@@ -1036,7 +1077,7 @@ class XnetGrpModule extends PLModule
 
         if ($globals->asso('notif_unsub')) {
             $mailer = new PlMailer('xnetgrp/unsubscription-notif.mail.tpl');
-            $admins = $globals->asso()->iterAdmins();
+            $admins = $globals->asso()->iterToNotify();
             while ($admin = $admins->next()) {
                 $mailer->addTo($admin);
             }