2 /***************************************************************************
3 * Copyright (C) 2003-2006 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
),
38 function handler_marketing(&$page)
42 $page->changeTpl('marketing/index.tpl');
44 $page->assign('xorg_title','Polytechnique.org - Marketing');
46 // Quelques statistiques
49 "SELECT COUNT(*) AS vivants,
50 COUNT(NULLIF(perms='admin' OR perms='user', 0)) AS inscrits,
51 100*COUNT(NULLIF(perms='admin' OR perms='user', 0))/COUNT(*) AS ins_rate,
52 COUNT(NULLIF(promo >= 1972, 0)) AS vivants72,
53 COUNT(NULLIF(promo >= 1972 AND (perms='admin' OR perms='user'), 0)) AS inscrits72,
54 100 * COUNT(NULLIF(promo >= 1972 AND (perms='admin' OR perms='user'), 0)) /
55 COUNT(NULLIF(promo >= 1972, 0)) AS ins72_rate,
56 COUNT(NULLIF(FIND_IN_SET('femme', flags), 0)) AS vivantes,
57 COUNT(NULLIF(FIND_IN_SET('femme', flags) AND (perms='admin' OR perms='user'), 0)) AS inscrites,
58 100 * COUNT(NULLIF(FIND_IN_SET('femme', flags) AND (perms='admin' OR perms='user'), 0)) /
59 COUNT(NULLIF(FIND_IN_SET('femme', flags), 0)) AS inse_rate
62 $stats = $res->fetchOneAssoc();
63 $page->assign('stats', $stats);
65 $res = XDB
::query("SELECT count(*) FROM auth_user_md5 WHERE date_ins > ".
66 date('Ymd000000', strtotime('1 week ago')));
67 $page->assign('nbInsSem', $res->fetchOneCell());
69 $res = XDB
::query("SELECT count(*) FROM register_pending WHERE hash != 'INSCRIT'");
70 $page->assign('nbInsEnCours', $res->fetchOneCell());
72 $res = XDB
::query("SELECT count(*) FROM register_marketing");
73 $page->assign('nbInsMarket', $res->fetchOneCell());
75 $res = XDB
::query("SELECT count(*) FROM register_mstats
76 WHERE TO_DAYS(NOW()) - TO_DAYS(success) <= 7");
77 $page->assign('nbInsMarkOK', $res->fetchOneCell());
80 function handler_private(&$page, $uid = null
,
81 $action = null
, $value = null
)
85 $page->changeTpl('marketing/private.tpl');
91 $page->assign('path', 'marketing/private/'.$uid);
93 $res = XDB
::query("SELECT nom, prenom, promo, matricule
95 WHERE user_id={?} AND perms='pending'", $uid);
97 if (list($nom, $prenom, $promo, $matricule) = $res->fetchOneRow()) {
98 require_once('register.inc.php');
99 $matricule_X = get_X_mat($matricule);
100 $page->assign('nom', $nom);
101 $page->assign('prenom', $prenom);
102 $page->assign('promo', $promo);
103 $page->assign('matricule', $matricule);
104 $page->assign('matricule_X',$matricule_X);
106 $page->kill('uid invalide');
109 if ($action == 'del') {
110 XDB
::execute('DELETE FROM register_marketing WHERE uid={?} AND email={?}',
114 if ($action == 'rel') {
115 require_once('marketing.inc.php');
116 list($to, $title, $text) = mark_text_mail($uid, $value);
117 $from = mark_from_mail($uid, $value);
118 $page->assign('rel_from_user', $from);
119 $page->assign('rel_from_staff',
120 "\"Equipe Polytechnique.org\" <register@polytechnique.org>");
121 $page->assign('rel_to', $to);
122 $page->assign('rel_title', $title);
123 $page->assign('rel_text', $text);
124 $page->assign('rel_email', $value);
127 if ($action == 'relforce') {
128 require_once('marketing.inc.php');
129 mark_send_mail($uid, $value, Post
::get('from'), Post
::get('to'),
130 Post
::get('title'), Post
::get('message'));
131 $page->trig("Mail envoyé");
134 if ($action == 'insrel') {
135 require_once 'marketing.inc.php';
137 $page->trig('relance faite');
141 if ($action == 'add' && Post
::has('email') && Post
::has('type')) {
143 "INSERT INTO register_marketing
144 SET uid = {?}, sender = {?}, email = {?},
145 date = NOW(), type = {?}",
146 $uid, Session
::get('uid'), Post
::get('email'), Post
::get('type'));
149 $res = XDB
::iterator(
151 FROM register_marketing AS r
152 INNER JOIN aliases AS a ON (r.sender=a.id AND a.type = 'a_vie')
154 ORDER BY date", $uid);
155 $page->assign('addr', $res);
157 $res = XDB
::query("SELECT date, relance FROM register_pending
158 WHERE uid = {?}", $uid);
159 if (list($pending, $relance) = $res->fetchOneCell()) {
160 $page->assign('pending', $pending);
161 $page->assign('relance', $relance);
165 function handler_promo(&$page, $promo = null
)
169 $page->changeTpl('marketing/promo.tpl');
171 if (is_null($promo)) {
172 $promo = Session
::getInt('promo');
174 $page->assign('promo', $promo);
176 $sql = "SELECT u.user_id, u.nom, u.prenom, u.last_known_email, u.matricule_ax,
177 IF(MAX(m.last)>p.relance, MAX(m.last), p.relance) AS dern_rel, p.email
178 FROM auth_user_md5 AS u
179 LEFT JOIN register_pending AS p ON p.uid = u.user_id
180 LEFT JOIN register_marketing AS m ON m.uid = u.user_id
181 WHERE u.promo = {?} AND u.deces = 0 AND u.perms='pending'
183 ORDER BY nom, prenom";
184 $page->assign('nonins', XDB
::iterator($sql, $promo));
187 function handler_public(&$page, $uid = null
)
191 $page->changeTpl('marketing/public.tpl');
197 $res = XDB
::query("SELECT nom, prenom, promo FROM auth_user_md5
198 WHERE user_id={?} AND perms='pending'", $uid);
200 if (list($nom, $prenom, $promo) = $res->fetchOneRow()) {
201 $page->assign('prenom', $prenom);
202 $page->assign('nom', $nom);
203 $page->assign('promo', $promo);
205 if (Post
::has('valide')) {
206 require_once('xorg.misc.inc.php');
208 $email = trim(Post
::get('mail'));
209 $res = XDB
::query('SELECT COUNT(*) FROM register_marketing
210 WHERE uid={?} AND email={?}', $uid, $email);
212 if (!isvalid_email_redirection($email)) {
213 $page->trig("Email invalide !");
214 } elseif ($res->fetchOneCell()) {
215 $page->assign('already', true
);
217 $page->assign('ok', true
);
219 "INSERT INTO register_marketing (uid,sender,email,date,last,nb,type,hash)
220 VALUES ({?}, {?}, {?}, NOW(), 0, 0, {?}, '')",
221 $uid, Session
::getInt('uid'), $email, Post
::get('origine'));
222 require_once('validations.inc.php');
223 $req = new MarkReq(Session
::getInt('uid'), $uid, $email,
224 Post
::get('origine')=='user');
231 function handler_week(&$page, $sorting = 'per_promo')
235 $page->changeTpl('marketing/this_week.tpl');
237 $sort = $sorting == 'per_promo' ?
'promo' : 'date_ins';
239 $sql = "SELECT a.alias AS forlife, u.date_ins, u.promo, u.nom, u.prenom
240 FROM auth_user_md5 AS u
241 INNER JOIN aliases AS a ON (u.user_id = a.id AND a.type='a_vie')
242 WHERE u.date_ins > ".date("Ymd000000", strtotime ('1 week ago'))."
243 ORDER BY u.$sort DESC";
244 $page->assign('ins', XDB
::iterator($sql));
247 function handler_volontaire(&$page, $promo = null
)
251 $page->changeTpl('marketing/volontaire.tpl');
256 FROM register_marketing AS m
257 INNER JOIN auth_user_md5 AS a ON a.user_id = m.uid
259 $page->assign('promos', $res->fetchColumn());
262 if (!is_null($promo)) {
263 $sql = "SELECT a.nom, a.prenom, a.user_id,
264 m.email, sa.alias AS forlife
265 FROM register_marketing AS m
266 INNER JOIN auth_user_md5 AS a ON a.user_id = m.uid AND a.promo = {?}
267 INNER JOIN aliases AS sa ON (m.sender = sa.id AND sa.type='a_vie')
269 $page->assign('addr', XDB
::iterator($sql, $promo));
273 function handler_relance(&$page)
277 $page->changeTpl('marketing/relance.tpl');
279 if (Post
::has('relancer')) {
280 require_once 'marketing.inc.php';
282 $res = XDB
::query("SELECT COUNT(*) FROM auth_user_md5 WHERE deces=0");
283 $nbdix = $res->fetchOneCell();
286 foreach (array_keys($_POST['relance']) as $uid) {
287 if ($tmp = relance($uid, $nbdix)) {
288 $sent[] = $tmp.' a été relancé';
291 $page->assign('sent', $sent);
294 $sql = "SELECT r.date, r.relance, r.uid, u.promo, u.nom, u.prenom
295 FROM register_pending AS r
296 INNER JOIN auth_user_md5 AS u ON r. uid = u.user_id
297 WHERE hash!='INSCRIT'
299 $page->assign('relance', XDB
::iterator($sql));