Imports AX names.
[platal.git] / modules / xnet.php
index 44094d8..6964996 100644 (file)
@@ -27,15 +27,15 @@ class XnetModule extends PLModule
             'index'        => $this->make_hook('index',        AUTH_PUBLIC),
             'exit'         => $this->make_hook('exit',         AUTH_PUBLIC),
 
-            'admin'        => $this->make_hook('admin',        AUTH_MDP, 'admin'),
+            '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_MDP, 'groups'),
-            'autologin'    => $this->make_hook('autologin',    AUTH_MDP, 'groups'),
-            'edit'         => $this->make_hook('edit',         AUTH_MDP, 'groups'),
+            '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(),
         );
     }
@@ -250,27 +250,37 @@ class XnetModule extends PLModule
                 }
             }
 
+            require_once 'emails.inc.php';
+            require_once 'name.func.inc.php';
+
             // Update user info
-            $full_name = Post::t('firstname') . ' ' . Post::t('lastname');
-            $directory_name = mb_strtoupper(Post::t('lastname')) . ' ' . Post::t('firstname');
+            $lastname = capitalize_name(Post::t('lastname'));
+            $firstname = capitalize_name(Post::t('firstname'));
+            $full_name = build_full_name($firstname, $lastname);
+            $directory_name = build_directory_name($firstname, $lastname);
+            $sort_name = build_sort_name($firstname, $lastname);
             XDB::query('UPDATE  accounts
-                           SET  full_name = {?}, directory_name = {?}, display_name = {?},
-                                firstname = {?}, lastname = {?}, sex = {?}, email = {?}
+                           SET  full_name = {?}, directory_name = {?}, sort_name = {?}, display_name = {?},
+                                firstname = {?}, lastname = {?}, sex = {?}
                          WHERE  uid = {?}',
-                       $full_name, $directory_name, Post::t('display_name'),
+                       $full_name, $directory_name, $sort_name, Post::t('display_name'),
                        Post::t('firstname'), Post::t('lastname'),
-                       (Post::t('sex') == 'male') ? 'male' : 'female', Post::t('email'), $user->id());
-            if (XDB::affectedRows()) {
-                require_once 'emails.inc.php';
-                if (require_email_update($user, Post::t('email'))) {
+                       (Post::t('sex') == 'male') ? 'male' : 'female', $user->id());
+
+            // Updates email.
+            $new_email = strtolower(Post::t('email'));
+            if (require_email_update($user, $new_email)) {
+                    XDB::query('UPDATE  accounts
+                                   SET  email = {?}
+                                 WHERE  uid = {?}',
+                               $new_email, $user->id());
                     $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.');
+                    $listClient->change_user_email($user->forlifeEmail(), $new_email);
+                    update_alias_user($user->forlifeEmail(), $new_email);
             }
+            $user = User::getWithUID($user->id());
+            S::set('user', $user);
+            $page->trigSuccess('Données mises à jour.');
         }
 
         $page->addJsLink('password.js');