X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;ds=sidebyside;f=modules%2Fmarketing.php;h=ac5cff5fbb35a3a28f7a6e300197bb2609b4b37b;hb=c9566e01c2add8f12a858abe0fbb0bc6b8e3c0d4;hp=cb280ae78b8c088a58b359ed655f459c17bbd98d;hpb=7c86602c3188d5be8e17bb587654dae452538dc0;p=platal.git
diff --git a/modules/marketing.php b/modules/marketing.php
index cb280ae..ac5cff5 100644
--- a/modules/marketing.php
+++ b/modules/marketing.php
@@ -1,6 +1,6 @@
$this->make_hook('marketing', AUTH_MDP, 'admin'),
- 'marketing/promo' => $this->make_hook('promo', AUTH_MDP, 'admin'),
- 'marketing/relance' => $this->make_hook('relance', AUTH_MDP, 'admin'),
- 'marketing/this_week' => $this->make_hook('week', AUTH_MDP, 'admin'),
- 'marketing/volontaire' => $this->make_hook('volontaire', AUTH_MDP, 'admin'),
-
- 'marketing/private' => $this->make_hook('private', AUTH_MDP, 'admin'),
- 'marketing/public' => $this->make_hook('public', AUTH_COOKIE),
- 'marketing/broken' => $this->make_hook('broken', AUTH_COOKIE),
+ 'marketing' => $this->make_hook('marketing', AUTH_PASSWD, 'admin'),
+ 'marketing/promo' => $this->make_hook('promo', AUTH_PASSWD, 'admin'),
+ 'marketing/relance' => $this->make_hook('relance', AUTH_PASSWD, 'admin'),
+ 'marketing/this_week' => $this->make_hook('week', AUTH_PASSWD, 'admin'),
+ 'marketing/volontaire' => $this->make_hook('volontaire', AUTH_PASSWD, 'admin'),
+
+ 'marketing/private' => $this->make_hook('private', AUTH_PASSWD, 'admin'),
+ 'marketing/public' => $this->make_hook('public', AUTH_COOKIE, 'user'),
+ 'marketing/broken' => $this->make_hook('broken', AUTH_COOKIE, 'user'),
);
}
- function handler_marketing(&$page)
+ function handler_marketing($page)
{
$page->changeTpl('marketing/index.tpl');
-
$page->setTitle('Marketing');
- // Some statistics
- $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(*) AS count
- FROM register_marketing
- GROUP BY sender = 0');
- $nbInsMarketNo = $res->fetchAllAssoc();
- $res = XDB::query('SELECT COUNT(*)
- FROM register_marketing
- WHERE TO_DAYS(NOW()) - TO_DAYS(last) <= 7');
- $page->assign('nbInsMarketNoPerso', $nbInsMarketNo[0]['count']);
- $page->assign('nbInsMarketNoXorg', $nbInsMarketNo[1]['count']);
- $page->assign('nbInsMarketNoWeek', $res->fetchOneCell());
-
- $res = XDB::query('SELECT COUNT(*) AS count
- FROM register_mstats
- GROUP BY sender = 0');
- $nbInsMarketOk = $res->fetchAllAssoc();
- $res = XDB::query('SELECT COUNT(*)
- FROM register_mstats
- WHERE TO_DAYS(NOW()) - TO_DAYS(success) <= 7');
- $page->assign('nbInsMarketOkPerso', $nbInsMarketOk[0]['count']);
- $page->assign('nbInsMarketOkXorg', $nbInsMarketOk[1]['count']);
- $page->assign('nbInsMarketOkWeek', $res->fetchOneCell());
+ $alive = array(
+ 'all' => new ProfileFilter(new PFC_Not(new UFC_Dead())),
+ 'women' => new ProfileFilter(new PFC_And(new UFC_Sex(User::GENDER_FEMALE) , new PFC_Not(new UFC_Dead()))),
+ 'x' => new ProfileFilter(new PFC_And(new PFC_Not(new UFC_Dead()), new UFC_AccountType('x'))),
+ '72' => new ProfileFilter(new PFC_And(new UFC_Promo('>=', UserFilter::GRADE_ING, 1972), new PFC_Not(new UFC_Dead()))),
+ 'master' => new ProfileFilter(new PFC_And(new PFC_Not(new UFC_Dead()), new UFC_AccountType('master'))),
+ 'phd' => new ProfileFilter(new PFC_And(new PFC_Not(new UFC_Dead()), new UFC_AccountType('phd')))
+ );
+ $registered = array(
+ 'all' => new ProfileFilter(new PFC_And(new UFC_Registered(true), new PFC_Not(new UFC_Dead()))),
+ 'women' => new ProfileFilter(new PFC_And(new UFC_Registered(true), new UFC_Sex(User::GENDER_FEMALE), new PFC_Not(new UFC_Dead()))),
+ 'x' => new ProfileFilter(new PFC_And(new UFC_Registered(true), new PFC_Not(new UFC_Dead()), new UFC_AccountType('x'))),
+ '72' => new ProfileFilter(new PFC_And(new UFC_Registered(true), new UFC_Promo('>=', UserFilter::GRADE_ING, 1972), new PFC_Not(new UFC_Dead()))),
+ 'master' => new ProfileFilter(new PFC_And(new UFC_Registered(true), new PFC_Not(new UFC_Dead()), new UFC_AccountType('master'))),
+ 'phd' => new ProfileFilter(new PFC_And(new UFC_Registered(true), new PFC_Not(new UFC_Dead()), new UFC_AccountType('phd')))
+ );
+ $statistics = array(
+ 'all' => array('description' => "Ãtudiants et anciens de l'X"),
+ 'women' => array('description' => "Ãtudiantes et anciennes de l'X"),
+ 'x' => array('description' => 'X'),
+ '72' => array('description' => 'X vivants depuis la promo 1972'),
+ 'master' => array('description' => "Masters de l'X"),
+ 'phd' => array('description' => "Docteurs de l'X")
+ );
+ foreach ($statistics as $key => &$data) {
+ $data['alive'] = $alive[$key]->getTotalCount();
+ $data['registered'] = $registered[$key]->getTotalCount();
+ $data['rate'] = round($data['registered'] / $data['alive'] * 100, 2);
+ }
+
+ $registeredWeek = new ProfileFilter(new PFC_And(new UFC_Registered(true, '>=', strtotime('1 week ago')), new PFC_Not(new UFC_Dead())));
+ $registrationPending = XDB::fetchOneCell('SELECT COUNT(*)
+ FROM register_pending');
+ $registrations = array(
+ 'week' => $registeredWeek->getTotalCount(),
+ 'pending' => $registrationPending,
+ );
+
+ $ok = XDB::fetchOneCell('SELECT COUNT(*)
+ FROM register_mstats
+ WHERE success != \'0000-00-00\'');
+ $okWeek = XDB::fetchOneCell('SELECT COUNT(*)
+ FROM register_mstats
+ WHERE success >= {?}', strtotime('1 week ago'));
+ $res = XDB::fetchAllAssoc('SELECT type, COUNT(*) as count
+ FROM register_marketing
+ GROUP BY type');
+ $no = array();
+ foreach ($res as $value) {
+ $no[$value['type']] = $value['count'];
+ }
+ $no['week'] = XDB::fetchOneCell('SELECT COUNT(*)
+ FROM register_marketing
+ WHERE last >= {?}', strtotime('1 week ago'));
+ $marketings = array(
+ 'ok' => $ok,
+ 'okWeek' => $okWeek,
+ 'noPerso' => (isset($no['user']) ? $no['user'] : 0),
+ 'noXorg' => (isset($no['staff']) ? $no['staff'] : 0),
+ 'noAX' => (isset($no['ax']) ? $no['ax'] : 0),
+ 'noWeek' => $no['week'],
+ );
+
+ $page->assign('statistics', $statistics);
+ $page->assign('registrations', $registrations);
+ $page->assign('marketings', $marketings);
}
- function handler_private(&$page, $hruid = null,
+ function handler_private($page, $hruid = null,
$action = null, $value = null)
{
global $globals;
@@ -105,17 +121,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());
@@ -172,10 +186,10 @@ class MarketingModule extends PLModule
// Retrieves and display the existing marketing attempts.
$res = XDB::iterator(
- "SELECT r.*, a.alias
- FROM register_marketing AS r
- LEFT JOIN aliases AS a ON (r.sender=a.id AND a.type = 'a_vie')
- WHERE uid={?}
+ "SELECT r.*, s.email AS alias
+ FROM register_marketing AS r
+ LEFT JOIN email_source_account AS s ON (r.sender = s.uid AND s.type = 'forlife')
+ WHERE r.uid = {?}
ORDER BY date", $user->id());
$page->assign('addr', $res);
@@ -189,7 +203,7 @@ class MarketingModule extends PLModule
$page->assign('path', 'marketing/private/' . $user->login());
}
- function handler_broken(&$page, $uid = null)
+ function handler_broken($page, $uid = null)
{
$page->changeTpl('marketing/broken.tpl');
@@ -204,13 +218,14 @@ 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, r.last, IF(r.type = \'googleapps\', \'googleapps\', r.redirect) AS active_email
+ FROM accounts AS a
+ LEFT JOIN email_redirect_account AS r ON (a.uid = r.uid AND r.type IN (\'smtp\', \'googleapps\') AND r.flags = \'active\')
+ LEFT JOIN account_profiles AS ap ON (ap.uid = r.uid AND FIND_IN_SET(\'owner\', ap.perms))
+ LEFT JOIN profiles AS p ON (p.pid = ap.pid)
+ WHERE a.uid = {?}
+ ORDER BY r.broken_level, r.last',
+ $user->id());
if (!$res->numRows()) {
return PL_NOT_FOUND;
}
@@ -222,69 +237,61 @@ class MarketingModule extends PLModule
if (Post::has('mail')) {
$email = valide_email(Post::v('mail'));
}
- if (Post::has('valide') && isvalid_email_redirection($email)) {
+ if (Post::has('valide') && isvalid_email_redirection($email, $user)) {
S::assert_xsrf_token();
// security stuff
check_email($email, "Proposition d'une adresse surveillee pour " . $user->login() . " par " . S::user()->login());
- $res = XDB::query("SELECT flags
- FROM emails
- WHERE email = {?} AND uid = {?}", $email, $user->id());
- $state = $res->numRows() ? $res->fetchOneCell() : null;
- if ($state == 'panne') {
+ $state = XDB::fetchOneCell('SELECT flags
+ FROM email_redirect_account
+ WHERE redirect = {?} AND uid = {?}',
+ $email, $user->id());
+ if ($state == 'broken') {
$page->trigWarning("L'adresse que tu as fournie est l'adresse actuelle de {$user->fullName()} et est en panne.");
} elseif ($state == 'active') {
$page->trigWarning("L'adresse que tu as fournie est l'adresse actuelle de {$user->fullName()}");
- } elseif ($user->email && !trim(Post::v('comment'))) {
+ } elseif ($user->email && !Post::t('comment')) {
$page->trigError("Il faut que tu ajoutes un commentaire à ta proposition pour justifier le "
. "besoin de changer la redirection de {$user->fullName()}.");
} else {
- require_once 'validations.inc.php';
$valid = new BrokenReq(S::user(), $user, $email, trim(Post::v('comment')));
$valid->submit();
$page->assign('sent', true);
}
} elseif ($email) {
- $page->trigError("L'adresse proposée n'est pas une adresse acceptable pour une redirection");
+ $page->trigError("L'adresse proposée n'est pas une adresse acceptable pour une redirection.");
}
}
- function handler_promo(&$page, $promo = null)
+ function handler_promo($page, $promo = null)
{
$page->changeTpl('marketing/promo.tpl');
if (is_null($promo)) {
- $promo = S::v('promo');
+ $promo = S::v('promo', S::user()->promo());
}
$page->assign('promo', $promo);
- $sql = "SELECT u.user_id, u.hruid, u.nom, u.prenom, u.last_known_email,
- 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()),
+ new PFC_Not(new UFC_Dead())),
+ array(new UFO_Name()));
+ $users = $uf->getUsers();
+ $page->assign('nonins', $users);
}
- function handler_public(&$page, $hruid = null)
+ function handler_public($page, $hruid = null)
{
$page->changeTpl('marketing/public.tpl');
// 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.
@@ -296,8 +303,8 @@ class MarketingModule extends PLModule
$email = trim(Post::v('mail'));
require_once 'emails.inc.php';
- if (!isvalid_email_redirection($email)) {
- $page->trigError("Email invalide !");
+ if (!isvalid_email_redirection($email, $user)) {
+ $page->trigError('Email invalide !');
} else {
// On cherche les marketings précédents sur cette adresse
// email, en se restreignant au dernier mois
@@ -307,74 +314,90 @@ 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'));
+ $perso_signature = 'Cordialement,
--
' . $sender->fullName();
+ $market = new AnnuaireMarketing(null, true);
+ $text = $market->getText(array(
+ 'sexe' => $user->isFemale(),
+ 'forlife_email' => $user->forlifeEmail(),
+ 'forlife_email2' => $user->forlifeEmailAlternate()
+ ));
+ $text = str_replace('%%hash%%', '', $text);
+ $text = str_replace('%%personal_notes%%', '', $text);
+ $text = str_replace('%%sender%%',
+ '' . $perso_signature . '', $text);
+ $page->assign('text', nl2br($text));
+ $page->assign('perso_signature', $perso_signature);
+ $page->assign('mail_part', 'escaped_html');
}
}
- function handler_week(&$page, $sorting = 'per_promo')
+ function handler_week($page, $sorting = 'per_promo')
{
$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)
+ function handler_volontaire($page, $promo = null)
{
$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, s.email AS forlife
+ 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)
+ LEFT JOIN email_source_account AS s ON (m.sender = s.uid AND s.type = \'forlife\')
+ WHERE pd.promo = {?}
+ ORDER BY pd.sort_name', $promo);
+ $page->assign('addr', $it);
}
}
- function handler_relance(&$page)
+ function handler_relance($page)
{
$page->changeTpl('marketing/relance.tpl');
if (Post::has('relancer')) {
- $res = XDB::query("SELECT COUNT(*) FROM auth_user_md5 WHERE deces=0");
- $nbdix = $res->fetchOneCell();
+ global $globals;
+ $nbdix = $globals->core->NbIns;
$sent = Array();
- foreach (array_keys($_POST['relance']) as $uid) {
- if ($tmp = Marketing::relance($uid, $nbdix)) {
+ $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'));
}
}