- parent::__construct($_user, true, 'usage');
- require_once 'name.func.inc.php';
-
- $this->sn_types = build_types();
- $this->sn_old = build_sn_pub();
- $this->sn_new = $_search_names;
- $this->new_alias = true;
- $this->display_names = array();
-
- build_display_names($this->display_names, $_search_names, $_private_name_end, $this->new_alias);
- foreach ($this->sn_new AS $key => &$sn) {
- if (!isset($sn['pub'])) {
- unset($this->sn_new[$key]);
- }
- }
- $res = XDB::query("SELECT alias
- FROM aliases
- WHERE id = {?} AND type = 'alias' AND FIND_IN_SET('usage', flags)",
- $this->user->id());
- $this->old_alias = $res->fetchOneCell();
- if ($this->old_alias != $this->new_alias) {
- $res = XDB::query("SELECT id
- FROM aliases
- WHERE alias = {?}",
- $this->new_alias);
- if ($res->fetchOneCell()) {
- $this->new_alias = null;
+ parent::__construct($_user, $_profile, true, 'usage');
+
+ $this->public_names = $_public_names;
+ $this->old_public_names = $_old_public_names;
+
+ if (!is_null($this->profileOwner)) {
+ require_once 'name.func.inc.php';
+
+ $this->new_alias = build_email_alias($this->public_names);
+ $this->old_alias = XDB::fetchOneCell('SELECT email
+ FROM email_source_account
+ WHERE uid = {?} AND type = \'alias\' AND FIND_IN_SET(\'usage\', flags)',
+ $this->profileOwner->id());
+
+ if ($this->old_alias == $this->new_alias) {
+ $this->old_alias = $this->new_alias = null;
+ } else {
+ $used = XDB::fetchOneCell('SELECT COUNT(uid)
+ FROM email_source_account
+ WHERE email = {?} AND type != \'alias_aux\'',
+ $this->new_alias);
+ if ($used) {
+ $this->new_alias = null;
+ }