X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=include%2Fvalidations%2Fnames.inc.php;h=8590eb7f47896fcfcfe38d4dc4f7836e11ccd8ef;hb=304cdf32d7c38afbd381909545021fc44c8a0e05;hp=f39f13944ad8e24962ae91db99a568db21dc3967;hpb=ce0d7be772306674fadaf020511871aba1683816;p=platal.git diff --git a/include/validations/names.inc.php b/include/validations/names.inc.php index f39f139..8590eb7 100644 --- a/include/validations/names.inc.php +++ b/include/validations/names.inc.php @@ -26,50 +26,40 @@ class NamesReq extends ProfileValidate // {{{ properties public $unique = true; - - public $sn_old; - public $sn_new; - public $display_names; - public $old_alias; - public $new_alias; - public $sn_types; - + public $public_names; + public $old_public_names; + public $old_alias = null; + public $new_alias = null; + public $descriptions = array('lastname_main' => 'Nom patronymique', 'lastname_marital' => 'Nom marital', 'lastname_ordinary' => 'Nom usuel', 'firstname_main' => 'Prénom', 'firstname_ordinary' => 'Prénom usuel', 'pseudonym' => 'Pseudonyme (nom de plume)'); public $rules = "Refuser tout ce qui n'est visiblement pas un nom de famille (ce qui est extremement rare car à peu près n'importe quoi peut être un nom de famille)."; // }}} // {{{ constructor - public function __construct(User &$_user, Profile &$_profile, $_search_names, $_private_name_end) + public function __construct(User $_user, Profile $_profile, array $_public_names, array $_old_public_names) { parent::__construct($_user, $_profile, true, 'usage'); - require_once 'name.func.inc.php'; - $this->sn_types = build_types(); - $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, - $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]); - } - } + $this->public_names = $_public_names; + $this->old_public_names = $_old_public_names; if (!is_null($this->profileOwner)) { - $res = XDB::query("SELECT alias - FROM aliases - 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()) { + 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; } } @@ -97,16 +87,15 @@ class NamesReq extends ProfileValidate protected function _mail_body($isok) { - global $globals; if ($isok) { $res = " Le changement de nom que tu as demandé vient d'être effectué."; 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."; + $res .= "\n\n L'alias {$this->old_alias}@{$this->mail_domain} a été supprimé."; } if ($this->new_alias) { - $res .= "\n\n Les alias {$this->new_alias}@{$globals->mail->domain} et @{$globals->mail->domain2} sont maintenant à ta disposition !"; + $res .= "\n\n L'alias {$this->new_alias}@{$this->mail_domain} est maintenant à ta disposition !"; } } if ($globals->mailstorage->googleapps_domain) { @@ -130,11 +119,24 @@ class NamesReq extends ProfileValidate { require_once 'name.func.inc.php'; - set_profile_display($this->display_names, $this->profile); + update_public_names($this->profile->id(), $this->public_names); + update_display_names($this->profile, $this->public_names); if (!is_null($this->profileOwner)) { - set_alias_names($this->sn_new, $this->sn_old, $this->profile->id(), - $this->profileOwner->id(), true, $this->new_alias); + if (!is_null($this->old_alias)) { + XDB::execute('DELETE FROM email_source_account + WHERE FIND_IN_SET(\'usage\', flags) AND uid = {?} AND type = \'alias\'', + $this->profileOwner->id()); + } + if (!is_null($this->new_alias)) { + XDB::execute('INSERT INTO email_source_account (email, uid, type, flags, domain) + SELECT {?}, {?}, \'alias\', \'usage\', id + FROM email_virtual_domains + WHERE name = {?}', + $this->new_alias, $this->profileOwner->id(), $this->profileOwner->mainEmailDomain()); + } + require_once 'emails.inc.php'; + fix_bestalias($this->profileOwner); // Update the local User object, to pick up the new bestalias. $this->profileOwner = User::getSilentWithUID($this->profileOwner->id()); @@ -144,6 +146,18 @@ class NamesReq extends ProfileValidate } // }}} + // {{{ function getPublicNames() + + static public function getPublicNames($pid) + { + if ($request = parent::get_typed_request($pid, 'usage')) { + return $request->public_names; + } + return false; + } + + // }}} + } // }}}