<?php
/***************************************************************************
- * Copyright (C) 2003-2010 Polytechnique.org *
+ * Copyright (C) 2003-2011 Polytechnique.org *
* http://opensource.polytechnique.org/ *
* *
* This program is free software; you can redistribute it and/or modify *
$i++;
}
if (isset($search_names[$sn_types['name_other']])
- || isset($search_names[$sn_types['name_other']])) {
+ || isset($search_names[$sn_types['firstname_other']])) {
$name .= ", ";
}
}
return $name;
}
-function set_profile_display(&$display_names, $pid)
+function set_profile_display(&$display_names, Profile $profile)
{
XDB::execute("UPDATE profile_display
SET public_name = {?}, private_name = {?},
WHERE pid = {?}",
$display_names['public_name'], $display_names['private_name'],
$display_names['directory_name'], $display_names['short_name'],
- $display_names['sort_name'], $pid);
+ $display_names['sort_name'], $profile->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)
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;
}
}
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;
}