2 /***************************************************************************
3 * Copyright (C) 2003-2009 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 require_once('user.func.inc.php');
68 $matricule_X = get_X_mat($matricule);
70 $page->assign('full_name', $user->fullName());
71 $page->assign('promo', $user->promo());
72 $page->assign('matricule', $matricule);
73 $page->assign('matricule_X',$matricule_X);
75 // Applies in-parameter action to the user.
76 if ($action == 'del') {
77 S
::assert_xsrf_token();
78 Marketing
::clear($user->id(), $value);
81 if ($action == 'rel') {
82 $market = Marketing
::get($user->id(), $value);
83 if ($market == null
) {
84 $page->trigWarning("Aucun marketing n'a été effectué vers $value");
86 $to = $market->user
['to'];
87 $title = $market->getTitle();
88 $text = $market->getText();
89 $from = $market->sender_mail
;
90 $page->assign('rel_from_user', $from);
91 $page->assign('rel_from_staff',
92 '"Equipe Polytechnique.org" <register@' . $globals->mail
->domain
. '>');
93 $page->assign('rel_to', $to);
94 $page->assign('rel_title', $title);
95 $page->assign('rel_text', $text);
96 $page->assign('rel_email', $value);
100 if ($action == 'relforce') {
101 S
::assert_xsrf_token();
103 $market = Marketing
::get($user->id(), Post
::v('to'));
104 if (is_null($market)) {
105 $market = new Marketing($user->id(), Post
::v('to'), 'default', null
, 'staff');
107 $market->send(Post
::v('title'), Post
::v('message'));
108 $page->trigSuccess("Email envoyé");
111 if ($action == 'insrel') {
112 S
::assert_xsrf_token();
113 if (Marketing
::relance($user->id())) {
114 $page->trigSuccess('relance faite');
118 if ($action == 'add' && Post
::has('email') && Post
::has('type')) {
119 $market = new Marketing($user->id(), Post
::v('email'), 'default', null
, Post
::v('type'), S
::v('uid'));
123 // Retrieves and display the existing marketing attempts.
124 $res = XDB
::iterator(
126 FROM register_marketing AS r
127 LEFT JOIN aliases AS a ON (r.sender=a.id AND a.type = 'a_vie')
129 ORDER BY date", $user->id());
130 $page->assign('addr', $res);
132 $res = XDB
::query("SELECT date, relance FROM register_pending
133 WHERE uid = {?}", $user->id());
134 if (list($pending, $relance) = $res->fetchOneRow()) {
135 $page->assign('pending', $pending);
136 $page->assign('relance', $relance);
139 $page->assign('path', 'marketing/private/' . $user->login());
142 function handler_broken(&$page, $uid = null
)
144 $page->changeTpl('marketing/broken.tpl');
150 $user = User
::get($uid);
153 } elseif ($user->login() == S
::user()->login()) {
154 pl_redirect('emails/redirect');
157 $res = XDB
::query('SELECT p.deathdate IS NULL AS alive, e.last,
158 IF(e.email IS NOT NULL, e.email,
159 IF(FIND_IN_SET(\'googleapps\', eo.storage), \'googleapps\', NULL)) AS email
160 FROM email_options AS eo
161 LEFT JOIN account_profiles AS ap ON (ap.uid = eo.uid AND FIND_IN_SET(\'owner\', ap.perms))
162 LEFT JOIN profiles AS p ON (p.pid = ap.pid)
163 LEFT JOIN emails AS e ON (e.flags = \'active\' AND e.uid = eo.uid)
165 ORDER BY e.panne_level, e.last', $user->id());
166 if (!$res->numRows()) {
169 $user->addProperties($res->fetchOneAssoc());
170 $page->assign('user', $user);
173 require_once 'emails.inc.php';
174 if (Post
::has('mail')) {
175 $email = valide_email(Post
::v('mail'));
177 if (Post
::has('valide') && isvalid_email_redirection($email)) {
178 S
::assert_xsrf_token();
181 check_email($email, "Proposition d'une adresse surveillee pour " . $user->login() . " par " . S
::user()->login());
182 $res = XDB
::query("SELECT flags
184 WHERE email = {?} AND uid = {?}", $email, $user->id());
185 $state = $res->numRows() ?
$res->fetchOneCell() : null
;
186 if ($state == 'panne') {
187 $page->trigWarning("L'adresse que tu as fournie est l'adresse actuelle de {$user->fullName()} et est en panne.");
188 } elseif ($state == 'active') {
189 $page->trigWarning("L'adresse que tu as fournie est l'adresse actuelle de {$user->fullName()}");
190 } elseif ($user->email
&& !trim(Post
::v('comment'))) {
191 $page->trigError("Il faut que tu ajoutes un commentaire à ta proposition pour justifier le "
192 . "besoin de changer la redirection de {$user->fullName()}.");
194 require_once 'validations.inc.php';
195 $valid = new BrokenReq(S
::user(), $user, $email, trim(Post
::v('comment')));
197 $page->assign('sent', true
);
200 $page->trigError("L'adresse proposée n'est pas une adresse acceptable pour une redirection");
204 function handler_promo(&$page, $promo = null
)
206 $page->changeTpl('marketing/promo.tpl');
208 if (is_null($promo)) {
209 $promo = S
::v('promo');
211 $page->assign('promo', $promo);
213 $uf = new UserFilter(new UFC_And(new UFC_Promo('=', UserFilter
::DISPLAY
, $promo),
214 new UFC_Not(new UFC_Registered())),
215 array(new UFO_Name(UserFilter
::LASTNAME
), new UFO_Name(UserFilter
::FIRSTNAME
)));
216 $users = $uf->getUsers();
217 $page->assign('nonins', $users);
220 function handler_public(&$page, $hruid = null
)
222 $page->changeTpl('marketing/public.tpl');
224 // Retrieves the user info, and checks the user is not yet registered.
225 $user = User
::getSilent($hruid);
226 if (!$user ||
!$user->hasProfile()) {
230 if ($user->state
!= 'pending') {
231 $page->kill('Cet utilisateur est déjà inscrit');
234 // Displays the page, and handles the eventual user actions.
235 $page->assign('full_name', $user->fullName());
236 $page->assign('promo', $user->promo());
238 if (Post
::has('valide')) {
239 S
::assert_xsrf_token();
240 $email = trim(Post
::v('mail'));
242 require_once 'emails.inc.php';
243 if (!isvalid_email_redirection($email)) {
244 $page->trigError("Email invalide !");
246 // On cherche les marketings précédents sur cette adresse
247 // email, en se restreignant au dernier mois
249 if (Marketing
::get($user->id(), $email, true
)) {
250 $page->assign('already', true
);
252 $page->assign('ok', true
);
253 check_email($email, "Une adresse surveillée est proposée au marketing par " . S
::user()->login());
254 $market = new Marketing($user->id(), $email, 'default', null
, Post
::v('origine'), S
::v('uid'));
261 function handler_week(&$page, $sorting = 'per_promo')
263 $page->changeTpl('marketing/this_week.tpl');
265 $sort = $sorting == 'per_promo' ?
new UFO_Promo() : new UFO_Registration();
267 $uf = new UserFilter(new UFC_Registered(false
, '>', strtotime('1 week ago')), $sort);
268 $page->assign('users', $uf->getUsers());
271 function handler_volontaire(&$page, $promo = null
)
273 $page->changeTpl('marketing/volontaire.tpl');
276 'SELECT DISTINCT pd.promo
277 FROM register_marketing AS m
278 INNER JOIN account_profiles AS ap ON (m.uid = ap.uid AND FIND_IN_SET(\'owner\', ap.perms))
279 INNER JOIN profile_display AS pd ON (pd.pid = ap.pid)
281 $page->assign('promos', $res->fetchColumn());
284 if (!is_null($promo)) {
285 $it = XDB
::iterator('SELECT m.uid, m.email
286 FROM register_marketing AS m
287 INNER JOIN account_profiles AS ap ON (m.uid = ap.uid AND FIND_IN_SET(\'owner\', ap.perms))
288 INNER JOIN profile_display AS pd ON (pd.pid = ap.pid)
289 WHERE pd.promo = {?}', $promo);
290 $page->assign('addr', $it);
294 function handler_relance(&$page)
296 $page->changeTpl('marketing/relance.tpl');
298 if (Post
::has('relancer')) {
299 $nbdix = Marketing
::getAliveUsersCount();
302 $users = User
::getBulkUsersWithUIDs($_POST['relance']);
303 foreach ($users as $user) {
304 if ($tmp = Marketing
::relance($user, $nbdix)) {
305 $sent[] = $tmp . ' a été relancé.';
308 $page->assign('sent', $sent);
311 $page->assign('relance', XDB
::iterator('SELECT r.date, r.relance, r.uid
312 FROM register_pending AS r
313 WHERE hash != \'INSCRIT\'
314 ORDER BY date DESC'));
318 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: