Non significant spaces suck.
[platal.git] / include / validations / marketing.inc.php
CommitLineData
0337d704 1<?php
2/***************************************************************************
5ddeb07c 3 * Copyright (C) 2003-2007 Polytechnique.org *
0337d704 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
0337d704 22
23class MarkReq extends Validate
24{
25 // {{{ properties
26
612a2d8a 27 public $perso;
0337d704 28
612a2d8a 29 public $m_id;
30 public $m_email;
31 public $m_nom;
32 public $m_prenom;
33 public $m_promo;
34 public $m_relance;
e654517d 35 public $m_type;
36 public $m_data;
0337d704 37
eaf30d86 38 public $rules = "Accepter si l'adresse mail parait correcte, et pas absurde (ou si le marketeur est de confiance). Si le
0337d704 39 demandeur marque sa propre adresse mail, refuser dans tous les cas.
eaf30d86 40 Ne pas marqueter au nom de Polytechnique.org plus d'une
0337d704 41 fois par an.";
42 // }}}
43 // {{{ constructor
44
e654517d 45 public function __construct($sender, $mark_id, $email, $perso, $type, $data)
612a2d8a 46 {
47 parent::__construct($sender, false, 'marketing');
0337d704 48 $this->m_id = $mark_id;
49 $this->m_email = $email;
50 $this->perso = $perso;
e654517d 51 $this->m_type = $type;
52 $this->m_data = $data;
0337d704 53
c3ae3d01 54 $res = XDB::query('SELECT u.nom, u.prenom, u.promo
9ac41f81 55 FROM auth_user_md5 AS u
9ac41f81 56 WHERE user_id = {?}
57 GROUP BY u.user_id', $mark_id);
eaf30d86 58 list ($this->m_nom, $this->m_prenom, $this->m_promo) = $res->fetchOneRow();
0337d704 59 }
60
61 // }}}
62 // {{{ function formu()
63
612a2d8a 64 public function formu()
6e112b58 65 {
66 $res = XDB::query('SELECT IF(MAX(m.last)>p.relance, MAX(m.last), p.relance)
67 FROM auth_user_md5 AS u
68 LEFT JOIN register_pending AS p ON p.uid = u.user_id
69 LEFT JOIN register_marketing AS m ON m.uid = u.user_id
70 WHERE user_id = {?}',
71 $this->m_id);
72 $this->m_relance = $res->fetchOneCell();
73 return 'include/form.valid.mark.tpl';
74 }
0337d704 75
76 // }}}
77 // {{{ function _mail_subj
eaf30d86 78
612a2d8a 79 protected function _mail_subj()
0337d704 80 {
81 return "[Polytechnique.org] Marketing de {$this->m_prenom} {$this->m_nom} ({$this->m_promo})";
82 }
83
84 // }}}
85 // {{{ function _mail_body
86
612a2d8a 87 protected function _mail_body($isok)
0337d704 88 {
89 if ($isok) {
a7de4ef7 90 return " Un mail de marketing vient d'être envoyé "
0337d704 91 .($this->perso ? 'en ton nom' : 'en notre nom')
a7de4ef7 92 ." à {$this->m_prenom} {$this->m_nom} ({$this->m_promo}) pour l'encourager à s'inscrire !\n\n"
0337d704 93 ."Merci de ta participation !\n";
94 } else {
a7de4ef7 95 return " Nous n'avons pas jugé bon d'envoyer de mail de marketing à {$this->m_prenom} {$this->m_nom} ({$this->m_promo}).";
0337d704 96 }
97 }
98
99 // }}}
100 // {{{ function commit()
101
612a2d8a 102 public function commit()
0337d704 103 {
e654517d 104 $market = Marketing::get($this->m_id, $this->m_email);
105 if ($market == null) {
106 return false;
107 }
eaf30d86 108 $market->send();
0337d704 109 return true;
110 }
111
112 // }}}
113}
114
a7de4ef7 115// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
0337d704 116?>