Broken marketing becomes a validation
[platal.git] / include / validations / broken.inc.php
1 <?php
2 /***************************************************************************
3 * Copyright (C) 2003-2007 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the Free Software *
18 * Foundation, Inc., *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
21
22
23 class BrokenReq extends Validate
24 {
25 // {{{ properties
26
27 var $m_forlife;
28 var $m_bestalias;
29 var $m_prenom;
30 var $m_nom;
31 var $m_promo;
32 var $m_sexe;
33 var $m_email;
34 var $old_email;
35 var $m_comment;
36
37 var $rules = "Accepter si l'adresse mail parait correcte, et pas absurde (ou si le marketeur est de confiance).
38 Si le demandeur marque sa propre adresse mail, refuser dans tous les cas.
39 Si l'adresse proposée est surveillée, refuser.
40 Si le compte associé est désactivé, étudier le cas en fonction de la raison de la désactivation";
41 // }}}
42 // {{{ constructor
43
44 function BrokenReq($sender, $user, $email, $comment = null)
45 {
46 $this->Validate($sender, false, 'broken');
47 $this->m_email = $email;
48 $this->m_comment = trim($comment);
49 $this->m_forlife = $user['forlife'];
50 $this->m_bestalias = $user['bestalias'];
51 $this->m_prenom = $user['prenom'];
52 $this->m_nom = $user['nom'];
53 $this->m_promo = $user['promo'];
54 $this->m_sexe = $user['sexe'];
55 $this->old_email = $user['email'];
56 }
57
58 // }}}
59 // {{{ function formu()
60
61 function formu()
62 {
63 return 'include/form.valid.broken.tpl';
64 }
65
66 // }}}
67 // {{{ function _mail_subj
68
69 function _mail_subj()
70 {
71 return "[Polytechnique.org] Récupération de {$this->m_prenom} {$this->m_nom} ({$this->m_promo})";
72 }
73
74 // }}}
75 // {{{ function _mail_body
76
77 function _mail_body($isok)
78 {
79 if ($isok) {
80 return " Un mail de contact vient d'être envoyé "
81 ." à {$this->m_prenom} {$this->m_nom} ({$this->m_promo}) pour confirmer sa volonté de"
82 ." mettre à jour sa redirection Polytechnique.org!\n\n"
83 ."Merci de ta participation !\n";
84 } else {
85 return " Nous n'avons pas jugé bon d'envoyer de mail de contact à {$this->m_prenom} {$this->m_nom} ({$this->m_promo}).";
86 }
87 }
88
89 // }}}
90 // {{{ function commit()
91
92 function commit()
93 {
94 global $globals;
95 $email = $this->m_bestalias . '@' . $globals->mail->domain;
96 if ($this->old_email) {
97 $subject = "Ton adresse $email semble ne plus fonctionner";
98 $reason = "Nous avons été informés que ton adresse $email ne fonctionne plus correctement par un camarade";
99 } else {
100 $res = XDB::iterRow("SELECT email
101 FROM emails AS e
102 INNER JOIN aliases AS a ON (a.id = e.uid)
103 WHERE a.alias = {?} AND e.flags = 'panne'", $this->m_forlife);
104 $redirect = array();
105 while (list($red) = $res->next()) {
106 list(, $redirect[]) = explode('@', $red);
107 }
108 $subject = "Ton adresse $email ne fonctionne plus";
109 $reason = "Ton adresse $email ne fonctionne plus ";
110 if (!count($redirect)) {
111 $reason .= '.';
112 } elseif (count($redirect) == 1) {
113 $reason .= ' car sa redirection vers ' . $redirect[0] . ' est hors-service depuis plusiers mois.';
114 } else {
115 $reason .= ' cas ses redirections vers ' . implode(', ', $redirect)
116 . ' sont hors-services depuis plusieurs mois.';
117 }
118 }
119 $body = ($this->m_sexe ? 'Chère ' : 'Cher ') . $this->m_prenom . ",\n\n"
120 . $reason . "\n\n"
121 . "L'adresse {$this->m_email} nous a été communiquée, veux-tu que cette adresse devienne ta nouvelle "
122 . "adresse devienne ta nouvelle adresse de redirection ? Si oui, envoie nous des informations qui "
123 . "nous permettrons de nous assurer de ton identité (par exemple ta date de naissance et ta promotion)\n"
124 . "-- \nTrès Cordialement,\nL'Equipe de Polytechnique.org\n";
125 $body = wordwrap($body, 78);
126 $mailer = new PlMailer();
127 $mailer->setFrom('"Association Polytechnique.org" <register@polytechnique.org>');
128 $mailer->addTo($this->m_email);
129 $mailer->setSubject($subject);
130 $mailer->setTxtBody($body);
131 return $mailer->send();
132 }
133
134 // }}}
135 }
136
137 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker:
138 ?>