Ejemplo n.º 1
0
 /**
  * @dataProvider nameProvider
  */
 public function testName($name, $capitalized_name, $sort_name)
 {
     require_once dirname(__FILE__) . '/../include/name.func.inc.php';
     $test = capitalize_name($name);
     $this->assertEquals($test, $capitalized_name);
     $this->assertEquals(build_sort_name('', $test), $sort_name);
 }
Ejemplo n.º 2
0
 /**
  * @dataProvider nameProvider
  */
 public function testName($name, $capitalized_name, $sort_name)
 {
     self::checkPlatal();
     require_once 'name.func.inc.php';
     $test = capitalize_name($name);
     $this->assertEquals($test, $capitalized_name);
     $this->assertEquals(build_sort_name('', $test), $sort_name);
 }
Ejemplo n.º 3
0
function capitalize_name_checked($name)
{
    if ($name == '') {
        return '';
    }
    $capitalized = capitalize_name($name);
    if (!$capitalized) {
        echo " - WARNING: Unable to capitalize '{$name}'.\n";
        return $name;
    }
    if (mb_strtolower($name, 'UTF-8') != mb_strtolower($capitalized, 'UTF-8')) {
        echo " - WARNING: Capitalization of '{$name}' is unexpected: '{$capitalized}'\n";
        return $name;
    }
    return $capitalized;
}
Ejemplo n.º 4
0
 public function value(ProfilePage $page, $field, $value, &$success)
 {
     require_once 'name.func.inc.php';
     $success = true;
     if (is_null($value)) {
         $request = NamesReq::getPublicNames($page->pid());
         if (!$request) {
             $value['public_names'] = XDB::fetchOneAssoc('SELECT  lastname_main, lastname_marital, lastname_ordinary,
                                                                  firstname_main, firstname_ordinary, pseudonym
                                                            FROM  profile_public_names
                                                           WHERE  pid = {?}', $page->pid());
         } else {
             $value['public_names'] = $request;
             Platal::page()->assign('validation', true);
         }
         $value['private_names'] = XDB::fetchAllAssoc('SELECT  type, name
                                                         FROM  profile_private_names
                                                        WHERE  pid = {?}
                                                     ORDER BY  type, id', $page->pid());
     } else {
         foreach ($value['public_names'] as $key => $name) {
             $value['public_names'][$key] = capitalize_name(trim($name));
         }
         if (isset($value['private_names'])) {
             foreach ($value['private_names'] as $key => $name) {
                 $value['private_names'][$key]['name'] = trim($name['name']);
                 if ($value['private_names'][$key]['name'] == '') {
                     unset($value['private_names'][$key]);
                 }
             }
         }
         if (S::user()->isMe($page->owner)) {
             $success = $this->prepare($page, $value['public_names']);
         }
     }
     $public_name = build_first_name($value['public_names']) . ' ' . build_full_last_name($value['public_names'], $page->profile->isFemale());
     if (isset($value['private_names'])) {
         $private_name_end = build_private_name($value['private_names']);
         $private_name = $public_name . $private_name_end;
     } else {
         $value['private_names'] = array();
         $private_name = $public_name;
     }
     Platal::page()->assign('public_name', $public_name);
     Platal::page()->assign('private_name', $private_name);
     return $value;
 }
Ejemplo n.º 5
0
 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);
     }
 }
Ejemplo n.º 6
0
function capitalize_name($name)
{
    // Some suffixes should not be captitalized either, eg 's' in Bennett's.
    static $suffixes = array('h', 's', 't');
    // Extracts the first token of the name.
    if (!preg_match('/^(\\pL+)(([\' -])(.*))?$/ui', $name, $m)) {
        return '';
    }
    $token = mb_strtolower($m[1]);
    $separator = isset($m[3]) ? $m[3] : false;
    $tail = isset($m[4]) ? $m[4] : false;
    // Special case for "Malloc'h".
    if ($separator == "'" && in_array(strtolower($tail[0]), $suffixes) && (strlen($tail) == 1 || $tail[1] == ' ')) {
        $token .= "'" . strtolower($tail[0]);
        $separator = strlen($tail) == 1 ? false : $tail[1];
        $tail = strlen($tail) > 2 ? substr($tail, 2) : false;
    }
    // Capitalizes the first token.
    if (!in_array($token, Particles::$particles)) {
        $token = mb_ucfirst($token);
    }
    // Capitalizes the tail of the name.
    if ($tail) {
        if ($tail = capitalize_name($tail)) {
            return $token . $separator . $tail;
        }
        return '';
    }
    return $token . $separator;
}
Ejemplo n.º 7
0
 function handler_admin_member($page, $user)
 {
     global $globals;
     $user = User::getSilent($user);
     if (empty($user)) {
         return PL_NOT_FOUND;
     }
     if (!$user->inGroup($globals->asso('id'))) {
         pl_redirect('annuaire');
     }
     $page->changeTpl('xnetgrp/membres-edit.tpl');
     $page->addJsLink('xnet_members.js');
     $mmlist = new MMList(S::user(), $globals->asso('mail_domain'));
     if (Post::has('change')) {
         S::assert_xsrf_token();
         require_once 'emails.inc.php';
         require_once 'name.func.inc.php';
         // Convert user status to X
         if (!Post::blank('x')) {
             $forlife = $this->changeLogin($page, $user, Post::i('userid'), Post::b('broken'), Post::b('marketing'), Post::v('marketing_from'));
             if ($forlife) {
                 pl_redirect('member/' . $forlife);
             }
         }
         // Update user info
         if ($user->type == 'virtual' || $user->type == 'xnet' && !$user->perms) {
             $lastname = capitalize_name(Post::t('lastname'));
             if (Post::s('type') != 'virtual') {
                 $firstname = capitalize_name(Post::t('firstname'));
             } else {
                 $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 = {?}, sort_name = {?}, display_name = {?},
                                 firstname = {?}, lastname = {?}, sex = {?}, type = {?}
                          WHERE  uid = {?}', $full_name, $directory_name, $sort_name, Post::t('display_name'), $firstname, $lastname, Post::t('sex') == 'male' ? 'male' : 'female', Post::t('type') == 'xnet' ? 'xnet' : 'virtual', $user->id());
         }
         // Updates email.
         $new_email = strtolower(Post::t('email'));
         if (($user->type == 'virtual' || $user->type == 'xnet' && !$user->perms) && require_email_update($user, $new_email)) {
             XDB::query('UPDATE  accounts
                            SET  email = {?}
                          WHERE  uid = {?}', $new_email, $user->id());
             if ($user->forlifeEmail()) {
                 $listClient = new MMList(S::user());
                 $listClient->change_user_email($user->forlifeEmail(), $new_email);
                 update_alias_user($user->forlifeEmail(), $new_email);
             }
             $user = User::getWithUID($user->id());
         }
         if (XDB::affectedRows()) {
             $page->trigSuccess('Données de l\'utilisateur mises à jour.');
         }
         if ($user->type == 'xnet' && !$user->perms) {
             if (Post::b('suggest')) {
                 $request = new AccountReq(S::user(), $user->hruid, Post::t('email'), $globals->asso('nom'), $globals->asso('diminutif'));
                 $request->submit();
                 $page->trigSuccess('Le compte va bientôt être activé.');
             }
             if (Post::b('again')) {
                 $this->again($user->id());
                 $page->trigSuccess('Relance effectuée avec succès.');
             }
         }
         // Update group params for user
         $perms = Post::v('group_perms');
         $comm = Post::t('comm');
         $position = Post::t('group_position') == '' ? null : Post::v('group_position');
         if ($user->group_perms != $perms || $user->group_comm != $comm || $user->group_position != $position) {
             XDB::query('UPDATE  group_members
                            SET  perms = {?}, comm = {?}, position = {?}
                          WHERE  uid = {?} AND asso_id = {?}', $perms == 'admin' ? 'admin' : 'membre', $comm, $position, $user->id(), $globals->asso('id'));
             if (XDB::affectedRows()) {
                 if ($perms != $user->group_perms) {
                     $page->trigSuccess('Permissions modifiées !');
                 }
                 if ($comm != $user->group_comm) {
                     $page->trigSuccess('Commentaire mis à jour.');
                 }
                 if ($position != $user->group_position) {
                     $page->trigSuccess('Poste mis à jour.');
                 }
             }
         }
         // Gets user info again as they might have change
         $user = User::getSilent($user->id());
         // Update ML subscriptions
         foreach (Env::v('ml1', array()) as $ml => $state) {
             $ask = empty($_REQUEST['ml2'][$ml]) ? 0 : 2;
             if ($ask == $state) {
                 continue;
             }
             if ($state == '1') {
                 $page->trigWarning("{$user->fullName()} a " . "actuellement une demande d'inscription en " . "cours sur <strong>{$ml}@</strong> !!!");
             } elseif ($ask) {
                 $mmlist->mass_subscribe($ml, array($user->forlifeEmail()));
                 $page->trigSuccess("{$user->fullName()} a été abonné à {$ml}@.");
             } else {
                 $mmlist->mass_unsubscribe($ml, array($user->forlifeEmail()));
                 $page->trigSuccess("{$user->fullName()} a été désabonné de {$ml}@.");
             }
         }
         // Change subscriptioin to aliases
         foreach (Env::v('ml3', array()) as $ml => $state) {
             require_once 'emails.inc.php';
             $ask = !empty($_REQUEST['ml4'][$ml]);
             list($local_part, ) = explode('@', $ml);
             if ($ask == $state) {
                 continue;
             }
             if ($ask) {
                 add_to_list_alias($user->id(), $local_part, $globals->asso('mail_domain'));
                 $page->trigSuccess("{$user->fullName()} a été abonné à {$ml}.");
             } else {
                 delete_from_list_alias($user->id(), $local_part, $globals->asso('mail_domain'));
                 $page->trigSuccess("{$user->fullName()} a été désabonné de {$ml}.");
             }
         }
         if ($globals->asso('has_nl')) {
             $nl = NewsLetter::forGroup($globals->asso('shortname'));
             // Updates group's newsletter subscription.
             if (Post::i('newsletter') == 1) {
                 $nl->subscribe($user);
             } else {
                 $nl->unsubscribe(null, $user->id());
             }
         }
     }
     $res = XDB::rawFetchAllAssoc('SHOW COLUMNS FROM group_members LIKE \'position\'');
     $positions = str_replace(array('enum(', ')', '\''), '', $res[0]['Type']);
     if ($globals->asso('has_nl')) {
         $nl = NewsLetter::forGroup($globals->asso('shortname'));
         $nl_registered = $nl->subscriptionState($user);
     } else {
         $nl_registered = false;
     }
     $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));
     $page->assign('nl_registered', $nl_registered);
     $page->assign('pending_xnet_account', XDB::fetchOneCell('SELECT  1
                                                                FROM  register_pending_xnet
                                                               WHERE  uid = {?}', $user->id()));
 }
Ejemplo n.º 8
0
 function handler_edit($page)
 {
     global $globals;
     $user = S::user();
     if (empty($user)) {
         return PL_NOT_FOUND;
     }
     if ($user->type != 'xnet') {
         pl_redirect('index');
     }
     $page->changeTpl('xnet/edit.tpl');
     if (Post::has('change')) {
         S::assert_xsrf_token();
         // Convert user status to X
         if (!Post::blank('login_X')) {
             $forlife = $this->changeLogin($page, $user, Post::t('login_X'));
             if ($forlife) {
                 pl_redirect('index');
             }
         }
         require_once 'emails.inc.php';
         require_once 'name.func.inc.php';
         // Update user info
         $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 = {?}, sort_name = {?}, display_name = {?},
                             firstname = {?}, lastname = {?}, sex = {?}
                      WHERE  uid = {?}', $full_name, $directory_name, $sort_name, Post::t('display_name'), Post::t('firstname'), Post::t('lastname'), 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(), $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');
     $page->assign('user', $user);
 }