X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=include%2Fname.func.inc.php;h=8ac831de039255739b9746ebc79dde6fd82a74b8;hb=73b2b930263ff19715540307aba38a7981f3cecf;hp=7b761da9f03fc9caac4c6d49e0b3575f856e2dcf;hpb=e8a7cf31258ca08662a91f7db64f17d056d8a6a4;p=platal.git diff --git a/include/name.func.inc.php b/include/name.func.inc.php index 7b761da..8ac831d 100644 --- a/include/name.func.inc.php +++ b/include/name.func.inc.php @@ -1,6 +1,6 @@ id()); + + $owner = $profile->owner(); + if ($owner) { + XDB::execute('UPDATE accounts + SET full_name = {?}, directory_name = {?} + WHERE uid = {?}', + $display_names['public_name'], $display_names['directory_name'], $owner->id()); + } } function build_sn_pub($pid) @@ -220,22 +228,40 @@ function build_sn_pub($pid) return $sn_old; } -function set_alias_names(&$sn_new, $sn_old, $pid, $uid, $update_new = false, $new_alias = null) +/** Transform a name to its canonical value so it can be compared + * to another form (different case, with accents or with - instead + * of blanks). + * @see compare_basename to compare + */ +function name_to_basename($value) { + $value = mb_strtoupper(replace_accent($value)); + return preg_replace('/[^A-Z]/', ' ', $value); +} + +/** Compares two strings and check if they are two forms of the + * same name (different case, with accents or with - instead of + * blanks). + * @see name_to_basename to retreive the compared string + */ +function compare_basename($a, $b) { + return name_to_basename($a) == name_to_basename($b); +} + +function set_alias_names(&$sn_new, $sn_old, $pid, PlUser $user, $update_new = false, $new_alias = null) { $has_new = false; foreach ($sn_new as $typeid => $sn) { - if (isset($sn['pub'])) { - if (isset($sn_old[$typeid]) && ($sn_old[$typeid]['fullname'] == $sn['fullname'] && $update_new)) { + if (isset($sn['pub']) && !is_null($sn['fullname'])) { + if (isset($sn_old[$typeid]) && $update_new) { XDB::execute("UPDATE profile_name SET particle = {?}, name = {?}, typeid = {?} WHERE id = {?} AND pid = {?}", $sn['particle'], $sn['name'], $typeid, $sn_old[$typeid]['id'], $pid); unset($sn_old[$typeid]); - } elseif ($update_new - || (isset($sn_old[$typeid]) && $sn_old[$typeid]['fullname'] == $sn['fullname'])) { - XDB::execute("INSERT INTO profile_name (particle, name, typeid, pid) - VALUES ({?}, {?}, {?}, {?})", - $sn['particle'], $sn['name'], $typeid, $pid); + } elseif ($sn['fullname'] == $sn_old[$typeid]['fullname'] && $sn['name'] == $sn_old[$typeid]['name']) { + XDB::execute('INSERT INTO profile_name (particle, name, typeid, pid) + VALUES ({?}, {?}, {?}, {?})', + $sn_old[$typeid]['particle'], $sn_old[$typeid]['name'], $typeid, $pid); unset($sn_old[$typeid]); } else { $has_new = true; @@ -272,16 +298,18 @@ function set_alias_names(&$sn_new, $sn_old, $pid, $uid, $update_new = false, $ne } } if ($update_new) { - XDB::execute("DELETE FROM aliases - WHERE FIND_IN_SET('usage', flags) AND uid = {?}", - $uid); + XDB::execute('DELETE FROM email_source_account + WHERE FIND_IN_SET(\'usage\', flags) AND uid = {?} AND type = \'alias\'', + $user->id()); } if ($new_alias) { - XDB::execute("INSERT INTO aliases (alias, type, flags, uid) - VALUES ({?}, 'alias', 'usage', {?})", - $new_alias, $uid); + XDB::execute('INSERT INTO email_source_account (email, uid, type, flags, domain) + SELECT {?}, {?}, \'alias\', \'usage\', id + FROM email_virtual_domains + WHERE name = {?}', + $new_alias, $user->id(), $user->mainEmailDomain()); } - Profile::rebuildSearchTokens($pid); + Profile::rebuildSearchTokens($pid, false); return $has_new; }