Fixes nationalities deletion.
[platal.git] / modules / xnetgrp.php
index 1f58fd5..215f45b 100644 (file)
@@ -163,11 +163,17 @@ class XnetGrpModule extends PLModule
             } else {
                 $site = "";
             }
-            if (S::has_perms()) {
+            if (S::admin()) {
+                $page->assign('super', true);
+
                 if (Post::v('mail_domain') && (strstr(Post::v('mail_domain'), '.') === false)) {
                     $page->trigError('Le domaine doit être un FQDN (aucune modification effectuée) !!!');
                     return;
                 }
+                if (Post::t('nom') == '' || Post::t('diminutif') == '') {
+                    $page->trigError('Ni le nom ni le diminutif du groupe ne peuvent être vide.');
+                    return;
+                }
                 XDB::execute(
                     "UPDATE  groups
                         SET  nom={?}, diminutif={?}, cat={?}, dom={?},
@@ -216,11 +222,13 @@ class XnetGrpModule extends PLModule
                 }
             }
 
-            pl_redirect('../'.Post::v('diminutif', $globals->asso('diminutif')).'/edit');
+            pl_redirect('../' . Post::v('diminutif', $globals->asso('diminutif')) . '/edit');
         }
 
         if (S::admin()) {
-            $dom = XDB::iterator('SELECT * FROM group_dom ORDER BY nom');
+            $dom = XDB::iterator('SELECT  *
+                                    FROM  group_dom
+                                ORDER BY  nom');
             $page->assign('dom', $dom);
             $page->assign('super', true);
         }
@@ -282,10 +290,7 @@ class XnetGrpModule extends PLModule
     {
         global $globals;
 
-        if ($action == 'search') {
-            http_redirect("https://www.polytechnique.org/search/adv?rechercher=Chercher&groupex={$globals->asso('id')}"
-                        . "&cityid=" . Env::v('cityid') . "&mapid=" . Env::v('mapid'));
-        } else if ($action == 'geoloc' || $action == 'trombi') {
+        if ($action == 'trombi') {
             __autoload('userset');
             if ($action == 'trombi') {
                 $view = new ProfileSet(new UFC_Group($globals->asso('id')));
@@ -293,15 +298,12 @@ class XnetGrpModule extends PLModule
                 $view = new UserSet(new UFC_Group($globals->asso('id')));
             }
             $view->addMod('trombi', 'Trombinoscope');
-            // TODO: Reactivate when the new map is completed.
-            // $view->addMod('geoloc', 'Planisphère', false, array('with_annu' => 'annuaire/search'));
             $view->apply('annuaire', $page, $action, $subaction);
-            if ($action == 'geoloc' && $subaction) {
-                return;
-            }
+            $page->changeTpl('xnetgrp/annuaire.tpl');
+            return;
         }
-        $page->changeTpl('xnetgrp/annuaire.tpl');
 
+        $page->changeTpl('xnetgrp/annuaire.tpl');
         $sort = Env::s('order', 'directory_name');
         $ofs  = Env::i('offset');
         if ($ofs < 0) {
@@ -729,18 +731,20 @@ class XnetGrpModule extends PLModule
 
         $may_update = may_update();
         $warning    = false;
-        foreach ($listes as $liste) {
-            if ($liste['sub'] == 2) {
-                if ($may_update) {
-                    $mmlist->mass_unsubscribe($liste['list'], Array($user->forlifeEmail()));
-                } else {
-                    $mmlist->unsubscribe($liste['list']);
+        if (is_array($listes)) {
+            foreach ($listes as $liste) {
+                if ($liste['sub'] == 2) {
+                    if ($may_update) {
+                        $mmlist->mass_unsubscribe($liste['list'], Array($user->forlifeEmail()));
+                    } else {
+                        $mmlist->unsubscribe($liste['list']);
+                    }
+                } elseif ($liste['sub']) {
+                    Platal::page()->trigWarning($user->fullName() . " a une"
+                                               ." demande d'inscription en cours sur la"
+                                               ." liste {$liste['list']}@ !");
+                    $warning = true;
                 }
-            } elseif ($liste['sub']) {
-                Platal::page()->trigWarning($user->fullName() . " a une"
-                                           ." demande d'inscription en cours sur la"
-                                           ." liste {$liste['list']}@ !");
-                $warning = true;
             }
         }
 
@@ -807,16 +811,15 @@ class XnetGrpModule extends PLModule
                             WHERE  a.alias = {?}",
                           $login);
         if ($res->numRows() == 0) {
-            // TODO: replace this call to a removed function.
-            $x = get_not_registered_user($login);
-            if (!$x) {
-                $page->trigError("Le login $login ne correspond à aucun X.");
+            $accounts = User::getPendingAccounts($login);
+            if (!$accounts) {
+                $page->trigError("L'identifiant $login ne correspond à aucun X.");
                 return false;
-            } else if (count($x) > 1) {
-                $page->trigError("Le login $login correspond a plusieurs camarades.");
+            } else if (count($accounts) > 1) {
+                $page->trigError("L'identifiant $login correspond à plusieurs camarades.");
                 return false;
             }
-            $uid = $x[0]['uid'];
+            $uid = $accounts[0]['uid'];
             $sub = false;
         } else {
             list($uid, $login) = $res->fetchOneRow();