2 /***************************************************************************
3 * Copyright (C) 2003-2010 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
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. *
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. *
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 *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
22 class MarketingModule
extends PLModule
27 'marketing' => $this->make_hook('marketing', AUTH_MDP
, 'admin'),
28 'marketing/promo' => $this->make_hook('promo', AUTH_MDP
, 'admin'),
29 'marketing/relance' => $this->make_hook('relance', AUTH_MDP
, 'admin'),
30 'marketing/this_week' => $this->make_hook('week', AUTH_MDP
, 'admin'),
31 'marketing/volontaire' => $this->make_hook('volontaire', AUTH_MDP
, 'admin'),
33 'marketing/private' => $this->make_hook('private', AUTH_MDP
, 'admin'),
34 'marketing/public' => $this->make_hook('public', AUTH_COOKIE
),
35 'marketing/broken' => $this->make_hook('broken', AUTH_COOKIE
),
39 function handler_marketing(&$page)
41 $page->changeTpl('marketing/index.tpl');
43 $page->setTitle('Marketing');
44 $page->trigWarning("Les statistiques sont momentanéement désactivées");
47 function handler_private(&$page, $hruid = null
,
48 $action = null
, $value = null
)
51 $page->changeTpl('marketing/private.tpl');
53 $user = User
::getSilent($hruid);
58 // Retrieves marketed user details.
59 if ($user->state
!= 'pending') {
60 $page->kill('Cet utilisateur est déjà inscrit');
62 if (!$user->hasProfile()) {
63 $page->kill('Cet utilisateur n\'est pas concerné par le marketing');
65 $matricule = $user->profile()->xorg_id
;
67 $matricule_X = Profile
::getSchoolId($matricule);
69 $page->assign('full_name', $user->fullName());
70 $page->assign('promo', $user->promo());
71 $page->assign('matricule', $matricule);
72 $page->assign('matricule_X',$matricule_X);
74 // Applies in-parameter action to the user.
75 if ($action == 'del') {
76 S
::assert_xsrf_token();
77 Marketing
::clear($user->id(), $value);
80 if ($action == 'rel') {
81 $market = Marketing
::get($user->id(), $value);
82 if ($market == null
) {
83 $page->trigWarning("Aucun marketing n'a été effectué vers $value");
85 $to = $market->user
['to'];
86 $title = $market->getTitle();
87 $text = $market->getText();
88 $from = $market->sender_mail
;
89 $page->assign('rel_from_user', $from);
90 $page->assign('rel_from_staff',
91 '"Equipe Polytechnique.org" <register@' . $globals->mail
->domain
. '>');
92 $page->assign('rel_to', $to);
93 $page->assign('rel_title', $title);
94 $page->assign('rel_text', $text);
95 $page->assign('rel_email', $value);
99 if ($action == 'relforce') {
100 S
::assert_xsrf_token();
102 $market = Marketing
::get($user->id(), Post
::v('to'));
103 if (is_null($market)) {
104 $market = new Marketing($user->id(), Post
::v('to'), 'default', null
, 'staff');
106 $market->send(Post
::v('title'), Post
::v('message'));
107 $page->trigSuccess("Email envoyé");
110 if ($action == 'insrel') {
111 S
::assert_xsrf_token();
112 if (Marketing
::relance($user->id())) {
113 $page->trigSuccess('relance faite');
117 if ($action == 'add' && Post
::has('email') && Post
::has('type')) {
118 $market = new Marketing($user->id(), Post
::v('email'), 'default', null
, Post
::v('type'), S
::v('uid'));
122 // Retrieves and display the existing marketing attempts.
123 $res = XDB
::iterator(
125 FROM register_marketing AS r
126 LEFT JOIN aliases AS a ON (r.sender = a.uid AND a.type = 'a_vie')
128 ORDER BY date", $user->id());
129 $page->assign('addr', $res);
131 $res = XDB
::query("SELECT date, relance FROM register_pending
132 WHERE uid = {?}", $user->id());
133 if (list($pending, $relance) = $res->fetchOneRow()) {
134 $page->assign('pending', $pending);
135 $page->assign('relance', $relance);
138 $page->assign('path', 'marketing/private/' . $user->login());
141 function handler_broken(&$page, $uid = null
)
143 $page->changeTpl('marketing/broken.tpl');
149 $user = User
::get($uid);
152 } elseif ($user->login() == S
::user()->login()) {
153 pl_redirect('emails/redirect');
156 $res = XDB
::query('SELECT p.deathdate IS NULL AS alive, e.last,
157 IF(e.email IS NOT NULL, e.email,
158 IF(FIND_IN_SET(\'googleapps\', eo.storage), \'googleapps\', NULL)) AS email
159 FROM email_options AS eo
160 LEFT JOIN account_profiles AS ap ON (ap.uid = eo.uid AND FIND_IN_SET(\'owner\', ap.perms))
161 LEFT JOIN profiles AS p ON (p.pid = ap.pid)
162 LEFT JOIN emails AS e ON (e.flags = \'active\' AND e.uid = eo.uid)
164 ORDER BY e.panne_level, e.last', $user->id());
165 if (!$res->numRows()) {
168 $user->addProperties($res->fetchOneAssoc());
169 $page->assign('user', $user);
172 require_once 'emails.inc.php';
173 if (Post
::has('mail')) {
174 $email = valide_email(Post
::v('mail'));
176 if (Post
::has('valide') && isvalid_email_redirection($email)) {
177 S
::assert_xsrf_token();
180 check_email($email, "Proposition d'une adresse surveillee pour " . $user->login() . " par " . S
::user()->login());
181 $res = XDB
::query("SELECT flags
183 WHERE email = {?} AND uid = {?}", $email, $user->id());
184 $state = $res->numRows() ?
$res->fetchOneCell() : null
;
185 if ($state == 'panne') {
186 $page->trigWarning("L'adresse que tu as fournie est l'adresse actuelle de {$user->fullName()} et est en panne.");
187 } elseif ($state == 'active') {
188 $page->trigWarning("L'adresse que tu as fournie est l'adresse actuelle de {$user->fullName()}");
189 } elseif ($user->email
&& !trim(Post
::v('comment'))) {
190 $page->trigError("Il faut que tu ajoutes un commentaire à ta proposition pour justifier le "
191 . "besoin de changer la redirection de {$user->fullName()}.");
193 require_once 'validations.inc.php';
194 $valid = new BrokenReq(S
::user(), $user, $email, trim(Post
::v('comment')));
196 $page->assign('sent', true
);
199 $page->trigError("L'adresse proposée n'est pas une adresse acceptable pour une redirection");
203 function handler_promo(&$page, $promo = null
)
205 $page->changeTpl('marketing/promo.tpl');
207 if (is_null($promo)) {
208 $promo = S
::v('promo', S
::user()->promo());
210 $page->assign('promo', $promo);
212 $uf = new UserFilter(new PFC_And(new UFC_Promo('=', UserFilter
::DISPLAY
, $promo),
213 new PFC_Not(new UFC_Registered())),
214 array(new UFO_Name(Profile
::LASTNAME
), new UFO_Name(Profile
::FIRSTNAME
)));
215 $users = $uf->getUsers();
216 $page->assign('nonins', $users);
219 function handler_public(&$page, $hruid = null
)
221 $page->changeTpl('marketing/public.tpl');
223 // Retrieves the user info, and checks the user is not yet registered.
224 $user = User
::getSilent($hruid);
225 if (!$user ||
!$user->hasProfile()) {
229 if ($user->state
!= 'pending') {
230 $page->kill('Cet utilisateur est déjà inscrit');
233 // Displays the page, and handles the eventual user actions.
234 $page->assign('full_name', $user->fullName());
235 $page->assign('promo', $user->promo());
237 if (Post
::has('valide')) {
238 S
::assert_xsrf_token();
239 $email = trim(Post
::v('mail'));
241 require_once 'emails.inc.php';
242 if (!isvalid_email_redirection($email)) {
243 $page->trigError('Email invalide !');
245 // On cherche les marketings précédents sur cette adresse
246 // email, en se restreignant au dernier mois
248 if (Marketing
::get($user->id(), $email, true
)) {
249 $page->assign('already', true
);
251 $page->assign('ok', true
);
252 check_email($email, "Une adresse surveillée est proposée au marketing par " . S
::user()->login());
253 $market = new Marketing($user->id(), $email, 'default', null
, Post
::v('origine'), S
::v('uid'),
254 Post
::v('origine') == 'user' ? Post
::v('personal_notes') : null
);
260 require_once 'marketing.inc.php';
262 $sender = User
::getSilent(S
::v('uid'));
263 $market = new AnnuaireMarketing(null
, true
);
264 $text = $market->getText(array(
265 'sexe' => $user->isFemale(),
266 'forlife_email' => $user->login() . '@' . $globals->mail
->domain
,
267 'forlife_email2' => $user->login() . '@' . $globals->mail
->domain2
269 $text = str_replace('%%hash%%', '', $text);
270 $text = str_replace('%%personal_notes%%', '<em id="personal_notes_display"></em>', $text);
271 $text = str_replace('%%sender%%',
272 "<span id=\"sender\">" . $sender->fullName() . '</span>', $text);
273 $page->assign('text', nl2br($text));
274 // TODO (JAC): define a unique Xorg signature for all the emails we send.
275 $page->assign('xorg_signature', "L'équipe de Polytechnique.org,<br />Le portail des élèves & anciens élèves de l'École polytechnique");
276 $page->assign('perso_signature', $sender->fullName());
280 function handler_week(&$page, $sorting = 'per_promo')
282 $page->changeTpl('marketing/this_week.tpl');
284 $sort = $sorting == 'per_promo' ?
new UFO_Promo() : new UFO_Registration();
286 $uf = new UserFilter(new UFC_Registered(false
, '>', strtotime('1 week ago')), $sort);
287 $page->assign('users', $uf->getUsers());
290 function handler_volontaire(&$page, $promo = null
)
292 $page->changeTpl('marketing/volontaire.tpl');
295 'SELECT DISTINCT pd.promo
296 FROM register_marketing AS m
297 INNER JOIN account_profiles AS ap ON (m.uid = ap.uid AND FIND_IN_SET(\'owner\', ap.perms))
298 INNER JOIN profile_display AS pd ON (pd.pid = ap.pid)
300 $page->assign('promos', $res->fetchColumn());
303 if (!is_null($promo)) {
304 $it = XDB
::iterator('SELECT m.uid, m.email, s.alias AS forlife
305 FROM register_marketing AS m
306 INNER JOIN account_profiles AS ap ON (m.uid = ap.uid AND FIND_IN_SET(\'owner\', ap.perms))
307 INNER JOIN profile_display AS pd ON (pd.pid = ap.pid)
308 LEFT JOIN aliases AS s ON (m.sender = s.uid AND s.type = \'a_vie\')
310 ORDER BY pd.sort_name', $promo);
311 $page->assign('addr', $it);
315 function handler_relance(&$page)
317 $page->changeTpl('marketing/relance.tpl');
319 if (Post
::has('relancer')) {
320 $nbdix = Marketing
::getAliveUsersCount();
323 $users = User
::getBulkUsersWithUIDs($_POST['relance']);
324 foreach ($users as $user) {
325 if ($tmp = Marketing
::relance($user, $nbdix)) {
326 $sent[] = $tmp . ' a été relancé.';
329 $page->assign('sent', $sent);
332 $page->assign('relance', XDB
::iterator('SELECT r.date, r.relance, r.uid
333 FROM register_pending AS r
334 WHERE hash != \'INSCRIT\'
335 ORDER BY date DESC'));
339 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: