/** * @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); }
/** * @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); }
function build_display_names(array $public_names, array $private_names, $isFemale) { $short_last_name = build_short_last_name($public_names); $full_last_name = build_full_last_name($public_names, $isFemale); $private_last_name_end = build_private_name($private_names); $firstname = build_first_name($public_names); $display_names = array(); $display_names['public_name'] = build_full_name($firstname, $full_last_name); $display_names['private_name'] = $display_names['public_name'] . $private_last_name_end; $display_names['directory_name'] = build_directory_name($firstname, $full_last_name); $display_names['short_name'] = build_full_name($firstname, $short_last_name); $display_names['sort_name'] = build_sort_name($firstname, $short_last_name); return $display_names; }
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); } }
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())); }
$profile = Profile::get($item['pid']); update_display_names($profile, $item); printf("\r%u / %u", $conversions, $total); $conversions++; unset($item, $profile); } printf("\r%u / %u", $conversions, $total); echo "\n{$conversions} names from profiles properly recapitalized.\n"; $conversions = 0; $names = XDB::iterator('SELECT uid, firstname, lastname FROM accounts WHERE NOT EXISTS (SELECT 1 FROM account_profiles WHERE account_profiles.uid = accounts.uid)'); $total = $names->total(); while ($item = $names->next()) { $lastname = capitalize_name_checked($item['lastname']); $firstname = capitalize_name_checked($item['firstname']); $full_name = build_full_name($firstname, $lastname); $directory_name = build_directory_name($firstname, $lastname); $sort_name = build_sort_name($firstname, $lastname); XDB::execute('UPDATE accounts SET firstname = {?}, lastname = {?}, full_name = {?}, directory_name = {?}, sort_name = {?} WHERE uid = {?}', $firstname, $lastname, $full_name, $directory_name, $sort_name, $item['uid']); printf("\r%u / %u", $conversions, $total); $conversions++; unset($item); } printf("\r%u / %u", $conversions, $total); echo "\n{$conversions} names from accounts properly recapitalized.\n"; // vim:set et sw=4 sts=4 sws=4 foldmethod=marker fenc=utf-8:
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); }