Merge branch 'xorg/maint' into xorg/master
[platal.git] / include / validations / homonymes.inc.php
index c51467a..33e8da1 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /***************************************************************************
- *  Copyright (C) 2003-2009 Polytechnique.org                              *
+ *  Copyright (C) 2003-2011 Polytechnique.org                              *
  *  http://opensource.polytechnique.org/                                   *
  *                                                                         *
  *  This program is free software; you can redistribute it and/or modify   *
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                *
  ***************************************************************************/
 
-require_once 'validations.inc.php';
 // {{{ class HomonymeReq
 
 class HomonymeReq extends Validate
 {
     // {{{ properties
 
-    public $loginbis;
-
-    public $warning = true;
-
+    public $email;
     public $homonymes_hruid;
-
+    public $warning = true;
     public $rules = "Accepter, sauf cas particulier d'utilisateur dont l'homonymie est traité plus &hellip; manuellement.";
 
     // }}}
     // {{{ constructor
 
-    public function __construct(User &$_user, $_loginbis, $_homonymes_hruid, $warning=true)
+    public function __construct(User $_user, $_email, $_homonymes_hruid, $warning = true)
     {
         $this->warning = $warning;
 
         parent::__construct($_user, true, $this->title());
 
         $this->refuse = false;
-        $this->loginbis = $_loginbis;
+        $this->email = $_email;
         $this->homonymes_hruid = $_homonymes_hruid;
     }
 
@@ -69,10 +65,9 @@ class HomonymeReq extends Validate
 
     protected function _mail_subj()
     {
-        global $globals;
         return "[Polytechnique.org/Support] "
             . ($this->warning ? "Dans une semaine : suppression de l'alias " : "Mise en place du robot")
-            . " $loginbis@" . $globals->mail->domain;
+            . " $email@" . $this->user->mainEmailDomain();
     }
 
     // }}}
@@ -80,16 +75,15 @@ class HomonymeReq extends Validate
 
     protected function _mail_body($isok)
     {
-        global $globals;
         return
 "
 Comme nous t'en avons informé par email il y a quelques temps,
 pour respecter nos engagements en terme d'adresses email devinables,
-tu te verras bientôt retirer l'alias ".$this->loginbis."@".$globals->mail->domain." pour
+tu te verras bientôt retirer l'alias " . $this->email . "@" . $this->user->mainEmailDomain() . " pour
 ne garder que " . $this->user->forlifeEmail() . ".
 
-Toute personne qui écrira à ".$this->loginbis."@".$globals->mail->domain." recevra la
-réponse d'un robot qui l'informera que ".$this->loginbis."@".$globals->mail->domain."
+Toute personne qui écrira à " . $this->email . "@" . $this->user->mainEmailDomain() . " recevra la
+réponse d'un robot qui l'informera que " . $this->email . "@" . $this->user->mainEmailDomain() . "
 est ambigu pour des raisons d'homonymie et signalera ton email exact.";
     }
 
@@ -98,34 +92,25 @@ est ambigu pour des raisons d'homonymie et signalera ton email exact.";
 
     protected function sendmail($isok)
     {
-        if (!$isok) return false;
-        global $globals;
-        $mailer = new PlMailer;
-        $cc = "support+homonyme@" . $globals->mail->domain;
-        $from = "\"Support Polytechnique.org\" <$cc>";
-        $mailer->setSubject($this->_mail_subj());
-        $mailer->setFrom($from);
-        $mailer->addTo("\"{$this->user->fullName()}\" <{$this->user->bestEmail()}>");
-        $mailer->addCc($cc);
-
-        $body = $this->user->displayName() . ",\n\n"
-              . $this->_mail_body($isok)
-              . (Env::has('comm') ? "\n\n".Env::v('comm') : '')
-              . "\n\nCordialement,\n\n-- \nL'équipe de Polytechnique.org\n";
-
-        $mailer->setTxtBody(wordwrap($body));
-        $mailer->send();
+        if (!$isok) {
+            return false;
+        }
+
+        Platal::load('admin', 'homonyms.inc.php');
+        if ($this->warning) {
+            send_warning_homonym($this->user, $this->email);
+        } else {
+            send_robot_homonym($this->user, $this->email);
+        }
     }
     // }}}
     // {{{ function commit()
 
     public function commit()
     {
-        Platal::load('admin', 'homonyms.inc.php');
-        switch_bestalias($this->user, $this->loginbis);
         if (!$this->warning) {
-            XDB::execute("UPDATE aliases SET type = 'homonyme', expire = NOW() WHERE alias = {?}", $this->loginbis);
-            XDB::execute("REPLACE INTO homonymes (homonyme_id, user_id) VALUES({?}, {?})", $this->user->id(), $this->user->id());
+            Platal::load('admin', 'homonyms.inc.php');
+            fix_homonym($this->user, $this->email);
         }
 
         return true;