Fixes going back during registration.
[platal.git] / modules / xnetgrp.php
index 6a610a4..b004fde 100644 (file)
@@ -729,20 +729,7 @@ class XnetGrpModule extends PLModule
                 $user = User::get($hruid);
             }
 
-            // Check if the user is has a pending or active account.
-            $active = XDB::fetchOneCell('SELECT  state = \'active\'
-                                           FROM  accounts
-                                          WHERE  uid = {?}',
-                                        $user->id());
-            $pending = XDB::fetchOneCell('SELECT  uid
-                                            FROM  register_pending_xnet
-                                           WHERE  uid = {?}',
-                                         $user->id());
-            $requested = AccountReq::isPending($user->id());
-
-            if (!($active || $pending || $requested)) {
-                $suggest_account_activation = true;
-            }
+            $suggest_account_activation = $this->suggest($user);
         }
 
         if ($user) {
@@ -758,6 +745,25 @@ class XnetGrpModule extends PLModule
         }
     }
 
+    // Check if the user has a pending or active account, and thus if we should her account's activation.
+    private function suggest(PlUser $user)
+    {
+        $active = XDB::fetchOneCell('SELECT  state = \'active\'
+                                       FROM  accounts
+                                      WHERE  uid = {?}',
+                                    $user->id());
+        $pending = XDB::fetchOneCell('SELECT  uid
+                                        FROM  register_pending_xnet
+                                       WHERE  uid = {?}',
+                                     $user->id());
+        $requested = AccountReq::isPending($user->id());
+
+        if ($active || $pending || $requested) {
+            return false;
+        }
+        return true;
+    }
+
     function handler_admin_member_suggest($page, $hruid, $email)
     {
         $page->changeTpl('xnetgrp/membres-suggest.tpl');
@@ -888,11 +894,10 @@ class XnetGrpModule extends PLModule
         } else {
             $page->trigWarning('Tu as été désinscrit du groupe, mais des erreurs se sont produites lors des désinscriptions des alias et des listes de diffusion.');
         }
-        if ($user->type == 'xnet' && $hasSingleGroup && Post::has('accountDeletion')) {
-            XDB::execute('DELETE FROM  acounts
-                                WHERE  uid = {?}',
-                         $user->id());
-            $page->trigSuccess('Ton compte a bien été supprimé.');
+
+        // If user is of type xnet account and this was her last group, disable the account.
+        if ($user->type == 'xnet' && $hasSingleGroup) {
+            $user->clear(true);
         }
         $page->assign('is_member', is_member(true));
     }
@@ -928,28 +933,13 @@ class XnetGrpModule extends PLModule
             $page->trigWarning("{$user->fullName()} a été désinscrit du groupe, mais des erreurs subsistent !");
         }
 
-        // Either deletes or notifies site administrators if it was the last group
-        // of a xnet account.
+        // If user is of type xnet account and this was her last group, disable the account.
         if ($user->type == 'xnet' && $hasSingleGroup) {
-            if ($user->state == 'pending') {
-                // If the user has never logged in the site, we delete her account.
-                XDB::execute('DELETE FROM  acounts
-                                    WHERE  uid = {?}',
-                             $user->id());
-            } else {
-                // It the user has already logged in the site, we notify site
-                // administrators that there is a new xnet account without any
-                // group.
-                $mailer = new PlMailer('xnetgrp/unsubscription.mail.tpl');
-                $mailer->assign('user', $user);
-                $mailer->assign('groupId', $globals->asso('id'));
-                $mailer->assign('groupName', $globals->asso('nom'));
-                $mailer->send();
-            }
+            $user->clear(true);
         }
     }
 
-    private function changeLogin(PlPage &$page, PlUser &$user, $login)
+    private function changeLogin(PlPage $page, PlUser $user, $login)
     {
         // Search the user's uid.
         $xuser = User::getSilent($login);
@@ -1024,6 +1014,12 @@ class XnetGrpModule extends PLModule
                 $page->trigSuccess('Données de l\'utilisateur mises à jour.');
             }
 
+            if (($user->type == 'xnet' && !$user->perms) && Post::b('suggest')) {
+                $request = new AccountReq(S::user(), $user->hruid, Post::t('email'), $globals->asso('nom'));
+                $request->submit();
+                $page->trigSuccess('Le compte va bientôt être activé.');
+            }
+
             // Update group params for user
             $perms = Post::v('group_perms');
             $comm  = Post::t('comm');
@@ -1100,6 +1096,7 @@ class XnetGrpModule extends PLModule
         $positions = str_replace(array('enum(', ')', '\''), '', $res[0]['Type']);
 
         $page->assign('user', $user);
+        $page->assign('suggest', $this->suggest($user));
         $page->assign('listes', $mmlist->get_lists($user->forlifeEmail()));
         $page->assign('alias', $user->emailGroupAliases($globals->asso('mail_domain')));
         $page->assign('positions', explode(',', $positions));