X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=include%2Fvalidations%2Fnames.inc.php;h=f39f13944ad8e24962ae91db99a568db21dc3967;hb=d645ceb701b0e8aa1de2e5271bed35e56ef169f1;hp=2c3ff1a8b7ccd77c68a86eefed978c26b8bcbdb7;hpb=40214aa65f590952c7bb2a586d6d0a9446b3c0e7;p=platal.git diff --git a/include/validations/names.inc.php b/include/validations/names.inc.php index 2c3ff1a..f39f139 100644 --- a/include/validations/names.inc.php +++ b/include/validations/names.inc.php @@ -1,6 +1,6 @@ sn_types = build_types(); - $this->sn_old = build_sn_pub(); + $this->sn_old = build_sn_pub($this->profile->id()); $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); + build_display_names($this->display_names, $_search_names, + $this->profile->isFemale(), $_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 + + if (!is_null($this->profileOwner)) { + $res = XDB::query("SELECT alias FROM aliases - WHERE alias = {?}", - $this->new_alias); - if ($res->fetchOneCell()) { - $this->new_alias = null; + WHERE uid = {?} AND type = 'alias' AND FIND_IN_SET('usage', flags)", + $this->profileOwner->id()); + $this->old_alias = $res->fetchOneCell(); + if ($this->old_alias != $this->new_alias) { + $res = XDB::query("SELECT uid + FROM aliases + WHERE alias = {?}", + $this->new_alias); + if ($res->fetchOneCell()) { + $this->new_alias = null; + } } } } @@ -96,19 +100,21 @@ class NamesReq extends Validate global $globals; if ($isok) { $res = " Le changement de nom que tu as demandé vient d'être effectué."; - if ($this->old_alias != $this->new_alias) { - if ($this->old_alias) { - $res .= "\n\n Les alias {$this->old_alias}@{$globals->mail->domain} et @{$globals->mail->domain2} ont été supprimés."; - } - if ($this->new_alias) { - $res .= "\n\n Les alias {$this->new_alias}@{$globals->mail->domain} et @{$globals->mail->domain2} sont maintenant à ta disposition !"; + if (!is_null($this->profileOwner)) { + if ($this->old_alias != $this->new_alias) { + if ($this->old_alias) { + $res .= "\n\n Les alias {$this->old_alias}@{$globals->mail->domain} et @{$globals->mail->domain2} ont été supprimés."; + } + if ($this->new_alias) { + $res .= "\n\n Les alias {$this->new_alias}@{$globals->mail->domain} et @{$globals->mail->domain2} sont maintenant à ta disposition !"; + } } - } - if ($globals->mailstorage->googleapps_domain) { - require_once 'googleapps.inc.php'; - $account = new GoogleAppsAccount($this->user); - if ($account->active()) { - $res .= "\n\n Si tu utilises Google Apps, tu peux changer ton nom d'usage sur https://mail.google.com/a/polytechnique.org/#settings/accounts."; + if ($globals->mailstorage->googleapps_domain) { + require_once 'googleapps.inc.php'; + $account = new GoogleAppsAccount($this->profileOwner); + if ($account->active()) { + $res .= "\n\n Si tu utilises Google Apps, tu peux changer ton nom d'usage sur https://mail.google.com/a/polytechnique.org/#settings/accounts."; + } } } return $res; @@ -122,12 +128,18 @@ class NamesReq extends Validate public function commit() { - require_once 'notifs.inc.php'; require_once 'name.func.inc.php'; - register_watch_op($this->user->id(), WATCH_FICHE, '', 'search_names'); - set_profile_display($this->display_names); - set_alias_names($this->sn_new, $this->sn_old, true, $this->new_alias); + set_profile_display($this->display_names, $this->profile); + + if (!is_null($this->profileOwner)) { + set_alias_names($this->sn_new, $this->sn_old, $this->profile->id(), + $this->profileOwner->id(), true, $this->new_alias); + + // Update the local User object, to pick up the new bestalias. + $this->profileOwner = User::getSilentWithUID($this->profileOwner->id()); + } + return true; }