Adapts new autocomplete to jobterms.
[platal.git] / modules / xnet.php
index e0b5f00..ae6edc4 100644 (file)
@@ -24,18 +24,19 @@ class XnetModule extends PLModule
     function handlers()
     {
         return array(
-            'index'       => $this->make_hook('index',     AUTH_PUBLIC),
-            'exit'        => $this->make_hook('exit',      AUTH_PUBLIC),
-
-            'admin'       => $this->make_hook('admin',     AUTH_MDP, 'admin'),
-            'groups'      => $this->make_hook('groups',    AUTH_PUBLIC),
-            'groupes.php' => $this->make_hook('groups2',   AUTH_PUBLIC),
-            'plan'        => $this->make_hook('plan',      AUTH_PUBLIC),
-            'photo'       => $this->make_hook('photo',     AUTH_MDP),
-            'autologin'   => $this->make_hook('autologin', AUTH_MDP),
-            'edit'        => $this->make_hook('edit',      AUTH_MDP, 'user'),
-
-            'Xnet'        => $this->make_wiki_hook(),
+            'index'        => $this->make_hook('index',        AUTH_PUBLIC),
+            'exit'         => $this->make_hook('exit',         AUTH_PUBLIC),
+
+            'admin'        => $this->make_hook('admin',        AUTH_PASSWD, 'admin'),
+            'groups'       => $this->make_hook('groups',       AUTH_PUBLIC),
+            'groupes.php'  => $this->make_hook('groups2',      AUTH_PUBLIC),
+            'plan'         => $this->make_hook('plan',         AUTH_PUBLIC),
+            // Should be removed in a future release as links will have expired anyway.
+            'register/ext' => $this->make_hook('register_ext', AUTH_PUBLIC),
+            'photo'        => $this->make_hook('photo',        AUTH_PASSWD, 'groups'),
+            'autologin'    => $this->make_hook('autologin',    AUTH_PASSWD, 'groups'),
+            'edit'         => $this->make_hook('edit',         AUTH_PASSWD, 'groups'),
+            'Xnet'         => $this->make_wiki_hook(),
         );
     }
 
@@ -225,7 +226,7 @@ class XnetModule extends PLModule
         exit;
     }
 
-    function handler_edit(&$page)
+    function handler_edit($page)
     {
         global $globals;
 
@@ -241,13 +242,6 @@ class XnetModule extends PLModule
         if (Post::has('change')) {
             S::assert_xsrf_token();
 
-            if ($user->groupCount() == 0 && Post::t('delete') == 'OUI') {
-                XDB::execute('DELETE FROM  accounts
-                                    WHERE  uid = {?}',
-                             $user->id());
-                pl_redirect('index');
-            }
-
             // Convert user status to X
             if (!Post::blank('login_X')) {
                 $forlife = $this->changeLogin($page, $user, Post::t('login_X'));
@@ -257,20 +251,24 @@ class XnetModule extends PLModule
             }
 
             // Update user info
+            $full_name = Post::t('firstname') . ' ' . Post::t('lastname');
+            $directory_name = mb_strtoupper(Post::t('lastname')) . ' ' . Post::t('firstname');
             XDB::query('UPDATE  accounts
                            SET  full_name = {?}, directory_name = {?}, display_name = {?},
-                                sex = {?}, email = {?}
+                                firstname = {?}, lastname = {?}, sex = {?}, email = {?}
                          WHERE  uid = {?}',
-                       Post::t('full_name'), Post::t('directory_name'), Post::t('display_name'),
+                       $full_name, $directory_name, Post::t('display_name'),
+                       Post::t('firstname'), Post::t('lastname'),
                        (Post::t('sex') == 'male') ? 'male' : 'female', Post::t('email'), $user->id());
-            // If user is of type xnet and new password is given.
-            if (!Post::blank('pwhash')) {
-                XDB::query('UPDATE  accounts
-                               SET  password = {?}
-                             WHERE  uid = {?}',
-                           Post::t('pwhash'), $user->id());
-            }
             if (XDB::affectedRows()) {
+                require_once 'emails.inc.php';
+                if (require_email_update($user, Post::t('email'))) {
+                    $listClient = new MMList(S::user());
+                    $listClient->change_user_email($user->forlifeEmail(), Post::t('email'));
+                    update_alias_user($user->forlifeEmail(), Post::t('email'));
+                }
+                $user = User::getWithUID($user->id());
+                S::set('user', $user);
                 $page->trigSuccess('Données mises à jour.');
             }
         }
@@ -278,6 +276,11 @@ class XnetModule extends PLModule
         $page->addJsLink('password.js');
         $page->assign('user', $user);
     }
+
+    function handler_register_ext($page, $hash = null)
+    {
+        http_redirect(Platal::globals()->xnet->xorg_baseurl . 'register/ext/' . $hash);
+    }
 }
 
 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: