X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=modules%2Fmarketing.php;h=5068fd40c6aa14c904efcccd3f1ecc866c07087c;hb=fa9994fa46e744766e87e445413610cf3f184374;hp=9e6266719049b68fd815d5c9470ba34d501ed3ba;hpb=5daf68f6846682e439570b5245a6109ada8d9304;p=platal.git
diff --git a/modules/marketing.php b/modules/marketing.php
index 9e62667..5068fd4 100644
--- a/modules/marketing.php
+++ b/modules/marketing.php
@@ -1,6 +1,6 @@
changeTpl('marketing/index.tpl');
$page->setTitle('Marketing');
-
- // Quelques statistiques
-
- $res = XDB::query(
- "SELECT COUNT(*) AS vivants,
- COUNT(NULLIF(perms='admin' OR perms='user', 0)) AS inscrits,
- 100*COUNT(NULLIF(perms='admin' OR perms='user', 0))/COUNT(*) AS ins_rate,
- COUNT(NULLIF(promo >= 1972, 0)) AS vivants72,
- COUNT(NULLIF(promo >= 1972 AND (perms='admin' OR perms='user'), 0)) AS inscrits72,
- 100 * COUNT(NULLIF(promo >= 1972 AND (perms='admin' OR perms='user'), 0)) /
- COUNT(NULLIF(promo >= 1972, 0)) AS ins72_rate,
- COUNT(NULLIF(FIND_IN_SET('femme', flags), 0)) AS vivantes,
- COUNT(NULLIF(FIND_IN_SET('femme', flags) AND (perms='admin' OR perms='user'), 0)) AS inscrites,
- 100 * COUNT(NULLIF(FIND_IN_SET('femme', flags) AND (perms='admin' OR perms='user'), 0)) /
- COUNT(NULLIF(FIND_IN_SET('femme', flags), 0)) AS inse_rate
- FROM auth_user_md5
- WHERE deces = 0");
- $stats = $res->fetchOneAssoc();
- $page->assign('stats', $stats);
-
- $res = XDB::query("SELECT count(*) FROM auth_user_md5 WHERE date_ins > ".
- date('Ymd000000', strtotime('1 week ago')));
- $page->assign('nbInsSem', $res->fetchOneCell());
-
- $res = XDB::query("SELECT count(*) FROM register_pending WHERE hash != 'INSCRIT'");
- $page->assign('nbInsEnCours', $res->fetchOneCell());
-
- $res = XDB::query("SELECT count(*) FROM register_marketing");
- $page->assign('nbInsMarket', $res->fetchOneCell());
-
- $res = XDB::query("SELECT count(*) FROM register_mstats
- WHERE TO_DAYS(NOW()) - TO_DAYS(success) <= 7");
- $page->assign('nbInsMarkOK', $res->fetchOneCell());
+ $page->trigWarning("Les statistiques sont momentanéement désactivées");
}
function handler_private(&$page, $hruid = null,
@@ -88,17 +56,15 @@ class MarketingModule extends PLModule
}
// Retrieves marketed user details.
- $res = XDB::query(
- "SELECT matricule
- FROM auth_user_md5
- WHERE user_id = {?} AND perms = 'pending'", $user->id());
- if (!($matricule = $res->fetchOneCell())) {
- $page->kill("Cet utilisateur est déjà inscrit au site.");
+ if ($user->state != 'pending') {
+ $page->kill('Cet utilisateur est déjà inscrit');
+ }
+ if (!$user->hasProfile()) {
+ $page->kill('Cet utilisateur n\'est pas concerné par le marketing');
}
+ $matricule = $user->profile()->xorg_id;
- require_once('user.func.inc.php');
- $matricule = $res->fetchOneCell();
- $matricule_X = get_X_mat($matricule);
+ $matricule_X = Profile::getSchoolId($matricule);
$page->assign('full_name', $user->fullName());
$page->assign('promo', $user->promo());
@@ -157,8 +123,8 @@ class MarketingModule extends PLModule
$res = XDB::iterator(
"SELECT r.*, a.alias
FROM register_marketing AS r
- INNER JOIN aliases AS a ON (r.sender=a.id AND a.type = 'a_vie')
- WHERE uid={?}
+ LEFT JOIN aliases AS a ON (r.sender = a.uid AND a.type = 'a_vie')
+ WHERE r.uid = {?}
ORDER BY date", $user->id());
$page->assign('addr', $res);
@@ -187,13 +153,15 @@ class MarketingModule extends PLModule
pl_redirect('emails/redirect');
}
- $res = XDB::query(
- "SELECT u.deces = '0000-00-00' AS alive, e.last,
- IF(e.email IS NOT NULL, e.email, IF(FIND_IN_SET('googleapps', u.mail_storage), 'googleapps', NULL)) AS email
- FROM auth_user_md5 AS u
- LEFT JOIN emails AS e ON (e.flags = 'active' AND e.uid = u.user_id)
- WHERE u.user_id = {?}
- ORDER BY e.panne_level, e.last", $user->id());
+ $res = XDB::query('SELECT p.deathdate IS NULL AS alive, e.last,
+ IF(e.email IS NOT NULL, e.email,
+ IF(FIND_IN_SET(\'googleapps\', eo.storage), \'googleapps\', NULL)) AS email
+ FROM email_options AS eo
+ LEFT JOIN account_profiles AS ap ON (ap.uid = eo.uid AND FIND_IN_SET(\'owner\', ap.perms))
+ LEFT JOIN profiles AS p ON (p.pid = ap.pid)
+ LEFT JOIN emails AS e ON (e.flags = \'active\' AND e.uid = eo.uid)
+ WHERE eo.uid = {?}
+ ORDER BY e.panne_level, e.last', $user->id());
if (!$res->numRows()) {
return PL_NOT_FOUND;
}
@@ -241,15 +209,11 @@ class MarketingModule extends PLModule
}
$page->assign('promo', $promo);
- $sql = "SELECT u.user_id, u.nom, u.prenom, u.last_known_email, u.matricule_ax,
- IF(MAX(m.last) > p.relance, MAX(m.last), p.relance) AS dern_rel, p.email
- FROM auth_user_md5 AS u
- LEFT JOIN register_pending AS p ON p.uid = u.user_id
- LEFT JOIN register_marketing AS m ON m.uid = u.user_id
- WHERE u.promo = {?} AND u.deces = 0 AND u.perms='pending'
- GROUP BY u.user_id
- ORDER BY nom, prenom";
- $page->assign('nonins', XDB::iterator($sql, $promo));
+ $uf = new UserFilter(new PFC_And(new UFC_Promo('=', UserFilter::DISPLAY, $promo),
+ new PFC_Not(new UFC_Registered())),
+ array(new UFO_Name(Profile::LASTNAME), new UFO_Name(Profile::FIRSTNAME)));
+ $users = $uf->getUsers();
+ $page->assign('nonins', $users);
}
function handler_public(&$page, $hruid = null)
@@ -258,16 +222,12 @@ class MarketingModule extends PLModule
// Retrieves the user info, and checks the user is not yet registered.
$user = User::getSilent($hruid);
- if (!$user) {
+ if (!$user || !$user->hasProfile()) {
return PL_NOT_FOUND;
}
- $res = XDB::query(
- "SELECT COUNT(*)
- FROM auth_user_md5
- WHERE user_id = {?} AND perms = 'pending'", $user->id());
- if (!$res->fetchOneCell()) {
- $page->kill("Cet utilisateur est déjà inscrit au site.");
+ if ($user->state != 'pending') {
+ $page->kill('Cet utilisateur est déjà inscrit');
}
// Displays the page, and handles the eventual user actions.
@@ -280,7 +240,7 @@ class MarketingModule extends PLModule
require_once 'emails.inc.php';
if (!isvalid_email_redirection($email)) {
- $page->trigError("Email invalide !");
+ $page->trigError('Email invalide !');
} else {
// On cherche les marketings précédents sur cette adresse
// email, en se restreignant au dernier mois
@@ -290,10 +250,30 @@ class MarketingModule extends PLModule
} else {
$page->assign('ok', true);
check_email($email, "Une adresse surveillée est proposée au marketing par " . S::user()->login());
- $market = new Marketing($user->id(), $email, 'default', null, Post::v('origine'), S::v('uid'));
+ $market = new Marketing($user->id(), $email, 'default', null, Post::v('origine'), S::v('uid'),
+ Post::v('origine') == 'user' ? Post::v('personal_notes') : null);
$market->add();
}
}
+ } else {
+ global $globals;
+ require_once 'marketing.inc.php';
+
+ $sender = User::getSilent(S::v('uid'));
+ $market = new AnnuaireMarketing(null, true);
+ $text = $market->getText(array(
+ 'sexe' => $user->isFemale(),
+ 'forlife_email' => $user->login() . '@' . $globals->mail->domain,
+ 'forlife_email2' => $user->login() . '@' . $globals->mail->domain2
+ ));
+ $text = str_replace('%%hash%%', '', $text);
+ $text = str_replace('%%personal_notes%%', '', $text);
+ $text = str_replace('%%sender%%',
+ "" . $sender->fullName() . '', $text);
+ $page->assign('text', nl2br($text));
+ // TODO (JAC): define a unique Xorg signature for all the emails we send.
+ $page->assign('xorg_signature', "L'équipe de Polytechnique.org,
Le portail des élèves & anciens élèves de l'Ãcole polytechnique");
+ $page->assign('perso_signature', $sender->fullName());
}
}
@@ -301,14 +281,10 @@ class MarketingModule extends PLModule
{
$page->changeTpl('marketing/this_week.tpl');
- $sort = $sorting == 'per_promo' ? 'promo' : 'date_ins';
+ $sort = $sorting == 'per_promo' ? new UFO_Promo() : new UFO_Registration();
- $sql = "SELECT a.alias AS forlife, u.date_ins, u.promo, u.nom, u.prenom
- FROM auth_user_md5 AS u
- INNER JOIN aliases AS a ON (u.user_id = a.id AND a.type='a_vie')
- WHERE u.date_ins > ".date("Ymd000000", strtotime ('1 week ago'))."
- ORDER BY u.$sort DESC";
- $page->assign('ins', XDB::iterator($sql));
+ $uf = new UserFilter(new UFC_Registered(false, '>', strtotime('1 week ago')), $sort);
+ $page->assign('users', $uf->getUsers());
}
function handler_volontaire(&$page, $promo = null)
@@ -316,22 +292,21 @@ class MarketingModule extends PLModule
$page->changeTpl('marketing/volontaire.tpl');
$res = XDB::query(
- "SELECT
- DISTINCT a.promo
+ 'SELECT DISTINCT pd.promo
FROM register_marketing AS m
- INNER JOIN auth_user_md5 AS a ON a.user_id = m.uid
- ORDER BY a.promo");
+ INNER JOIN account_profiles AS ap ON (m.uid = ap.uid AND FIND_IN_SET(\'owner\', ap.perms))
+ INNER JOIN profile_display AS pd ON (pd.pid = ap.pid)
+ ORDER BY pd.promo');
$page->assign('promos', $res->fetchColumn());
if (!is_null($promo)) {
- $sql = "SELECT a.nom, a.prenom, a.user_id,
- m.email, sa.alias AS forlife
- FROM register_marketing AS m
- INNER JOIN auth_user_md5 AS a ON a.user_id = m.uid AND a.promo = {?}
- INNER JOIN aliases AS sa ON (m.sender = sa.id AND sa.type='a_vie')
- ORDER BY a.nom";
- $page->assign('addr', XDB::iterator($sql, $promo));
+ $it = XDB::iterator('SELECT m.uid, m.email
+ FROM register_marketing AS m
+ INNER JOIN account_profiles AS ap ON (m.uid = ap.uid AND FIND_IN_SET(\'owner\', ap.perms))
+ INNER JOIN profile_display AS pd ON (pd.pid = ap.pid)
+ WHERE pd.promo = {?}', $promo);
+ $page->assign('addr', $it);
}
}
@@ -340,24 +315,22 @@ class MarketingModule extends PLModule
$page->changeTpl('marketing/relance.tpl');
if (Post::has('relancer')) {
- $res = XDB::query("SELECT COUNT(*) FROM auth_user_md5 WHERE deces=0");
- $nbdix = $res->fetchOneCell();
+ $nbdix = Marketing::getAliveUsersCount();
$sent = Array();
- foreach (array_keys($_POST['relance']) as $uid) {
- if ($tmp = Marketing::relance($uid, $nbdix)) {
- $sent[] = $tmp.' a été relancé';
+ $users = User::getBulkUsersWithUIDs($_POST['relance']);
+ foreach ($users as $user) {
+ if ($tmp = Marketing::relance($user, $nbdix)) {
+ $sent[] = $tmp . ' a été relancé.';
}
}
$page->assign('sent', $sent);
}
- $sql = "SELECT r.date, r.relance, r.uid, u.promo, u.nom, u.prenom
- FROM register_pending AS r
- INNER JOIN auth_user_md5 AS u ON r. uid = u.user_id
- WHERE hash!='INSCRIT'
- ORDER BY date DESC";
- $page->assign('relance', XDB::iterator($sql));
+ $page->assign('relance', XDB::iterator('SELECT r.date, r.relance, r.uid
+ FROM register_pending AS r
+ WHERE hash != \'INSCRIT\'
+ ORDER BY date DESC'));
}
}