Allows capitalization to be modified by administrators.
authorStéphane Jacob <sj@m4x.org>
Tue, 29 Nov 2011 10:03:33 +0000 (11:03 +0100)
committerStéphane Jacob <sj@m4x.org>
Sun, 4 Dec 2011 15:04:09 +0000 (16:04 +0100)
Signed-off-by: Stéphane Jacob <sj@m4x.org>
modules/admin.php
templates/admin/admin_name.tpl [new file with mode: 0644]
templates/admin/index.tpl
templates/profile/general.tpl

index a993a9c..7bdd213 100644 (file)
@@ -55,6 +55,7 @@ class AdminModule extends PLModule
             'admin/jobs'                   => $this->make_hook('jobs',                   AUTH_PASSWD, 'admin,edit_directory'),
             'admin/profile'                => $this->make_hook('profile',                AUTH_PASSWD, 'admin,edit_directory'),
             'admin/phd'                    => $this->make_hook('phd',                    AUTH_PASSWD, 'admin'),
+            'admin/name'                   => $this->make_hook('admin_name',             AUTH_PASSWD, 'admin'),
             'admin/add_secondary_edu'      => $this->make_hook('add_secondary_edu',      AUTH_PASSWD, 'admin')
         );
     }
@@ -2012,6 +2013,107 @@ class AdminModule extends PLModule
         }
 
     }
+
+    function handler_admin_name($page, $hruid = null)
+    {
+        $page->changeTpl('admin/admin_name.tpl');
+
+        if (Post::has('id')) {
+            $user = User::get(Post::t('id'));
+            if (is_null($user)) {
+                $page->trigError("L'identifiant donné ne correspond à personne ou est ambigu.");
+                exit();
+            }
+            pl_redirect('admin/name/' . $user->hruid);
+        }
+
+        $user = User::getSilent($hruid);
+        if (!is_null($user)) {
+            require_once 'name.func.inc.php';
+
+            if ($user->hasProfile()) {
+                $name_types = array(
+                    'lastname_main'      => 'Nom patronymique',
+                    'lastname_marital'   => 'Nom marital',
+                    'lastname_ordinary'  => 'Nom usuel',
+                    'firstname_main'     => 'Prénom',
+                    'firstname_ordinary' => 'Prénom usuel',
+                    'pseudonym'          => 'Pseudonyme'
+                );
+                $names = XDB::fetchOneAssoc('SELECT  lastname_main, lastname_marital, lastname_ordinary,
+                                                     firstname_main, firstname_ordinary, pseudonym
+                                               FROM  profile_public_names
+                                              WHERE  pid = {?}',
+                                            $user->profile()->id());
+            } else {
+                $name_types = array(
+                    'lastname'  => 'Nom',
+                    'firstname' => 'Prénom'
+                );
+                $names = XDB::fetchOneAssoc('SELECT  lastname, firstname
+                                               FROM  accounts
+                                              WHERE  uid = {?}',
+                                            $user->id());
+            }
+
+            if (Post::has('correct')) {
+                $new_names = array();
+                $update = true;
+                foreach ($name_types as $key => $fullname) {
+                    $new_names[$key] = Post::t($key);
+                    if (mb_strtolower($new_names[$key]) != mb_strtolower($names[$key])) {
+                        $update = false;
+                    }
+                }
+
+                if ($update) {
+                    if ($user->hasProfile()) {
+                        update_public_names($user->profile()->id(), $new_names);
+                        update_display_names($user->profile(), $new_names);
+                    } else {
+                        $new_names['full_name'] = build_full_name($new_names['firstname'], $new_names['lastname']);
+                        $new_names['directory_name'] = build_directory_name($new_names['firstname'], $new_names['lastname']);
+                        $new_names['sort_name'] = build_sort_name($new_names['firstname'], $new_names['lastname']);
+                        XDB::execute('UPDATE  accounts
+                                         SET  lastname = {?}, firstname = {?}, full_name = {?},
+                                              directory_name = {?}, sort_name = {?}
+                                       WHERE  uid = {?}',
+                                     $new_names['lastname'], $new_names['firstname'], $new_names['full_name'],
+                                     $new_names['directory_name'], $new_names['sort_name'], $user->id());
+                    }
+                    $page->trigSuccess('Mise à jour réussie.');
+                } else {
+                    $page->trigError('Seuls des changements de casse sont autorisés ici.');
+                }
+            }
+
+            if ($user->hasProfile()) {
+                $names = XDB::fetchOneAssoc('SELECT  lastname_main, lastname_marital, lastname_ordinary,
+                                                     firstname_main, firstname_ordinary, pseudonym
+                                               FROM  profile_public_names
+                                              WHERE  pid = {?}',
+                                            $user->profile()->id());
+            } else {
+                $names = XDB::fetchOneAssoc('SELECT  lastname, firstname
+                                               FROM  accounts
+                                              WHERE  uid = {?}',
+                                            $user->id());
+            }
+
+            foreach ($names as $key => $name) {
+                $names[$key] = array(
+                    'value'    => $name,
+                    'standard' => capitalize_name($name)
+                );
+                $names[$key]['different'] = ($names[$key]['value'] != $names[$key]['standard']);
+            }
+
+            $page->assign('uid', $user->id());
+            $page->assign('hruid', $user->hruid);
+            $page->assign('names', $names);
+            $page->assign('name_types', $name_types);
+        }
+    }
 }
 
 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
diff --git a/templates/admin/admin_name.tpl b/templates/admin/admin_name.tpl
new file mode 100644 (file)
index 0000000..7317529
--- /dev/null
@@ -0,0 +1,58 @@
+{**************************************************************************}
+{*                                                                        *}
+{*  Copyright (C) 2003-2011 Polytechnique.org                             *}
+{*  http://opensource.polytechnique.org/                                  *}
+{*                                                                        *}
+{*  This program is free software; you can redistribute it and/or modify  *}
+{*  it under the terms of the GNU General Public License as published by  *}
+{*  the Free Software Foundation; either version 2 of the License, or     *}
+{*  (at your option) any later version.                                   *}
+{*                                                                        *}
+{*  This program is distributed in the hope that it will be useful,       *}
+{*  but WITHOUT ANY WARRANTY; without even the implied warranty of        *}
+{*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *}
+{*  GNU General Public License for more details.                          *}
+{*                                                                        *}
+{*  You should have received a copy of the GNU General Public License     *}
+{*  along with this program; if not, write to the Free Software           *}
+{*  Foundation, Inc.,                                                     *}
+{*  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA               *}
+{*                                                                        *}
+{**************************************************************************}
+
+<h1>Gestion des noms{if t($hruid)} de {profile user=$uid promo=true directory=false}{/if}</h1>
+
+{if t($hruid)}
+<form method="post" action="{$platal->ns}admin/name/{$hruid}">
+  <table class="bicol">
+    <tr>
+      <th></th>
+      <th>Version actuelle</th>
+      <th>Version suggérée</th>
+    </tr>
+    {foreach from=$names item=name key=type}
+    <tr>
+      <th>{$name_types.$type}</th>
+      <td><input type="text" size="40" name="{$type}" value="{$name.value}" {if $name.different}class="warning"{/if} /></td>
+      <td>{$name.standard}</td>
+    </tr>
+    {/foreach}
+  </table>
+  <p class="center">
+    <input type="submit" name="correct" value="Corriger" />
+  </p>
+</form>
+<p>
+  <a href="admin/name">Retour à la gestion des noms.</a>
+</p>
+{else}
+<form method="post" action="{$platal->ns}admin/name">
+  <p>
+    Il est possible d'entrer ici n'importe quelle adresse email&nbsp;: redirection, melix ou alias.<br />
+    <input type="text" size="60" name="id" />
+    <input type="submit" value="Chercher" />
+  </p>
+</form>
+{/if}
+
+{* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *}
index a29b211..74d07d1 100644 (file)
       <a href="admin/homonyms">Homonymes</a>
       &nbsp;&nbsp;|&nbsp;&nbsp;
       <a href="admin/deaths">Décès</a>
+      &nbsp;&nbsp;|&nbsp;&nbsp;
+      <a href="admin/name">Noms</a>
     </td>
   </tr>
   <tr class="pair">
index 450fc2d..4ee4407 100644 (file)
       </div>
     </td>
   </tr>
+  <tr class="names_advanced_private" {if !$errors.search_names}style="display: none"{/if}>
+    <td class="center" colspan="2">
+      <small>Si la casse de ton nom est erronée et que tu n'arrives pas à la corriger,
+      <a href="mailto:support@{#globals.mail.domain#}">contacte-nous</a>.</small>
+    </td>
+  </tr>
 </table>
 
 <table class="bicol" style="margin-bottom: 1em"