From 0baf0741b59974981aced47c7196a7a319b7f3e8 Mon Sep 17 00:00:00 2001 From: x2003bruneau Date: Wed, 21 Mar 2007 08:33:26 +0000 Subject: [PATCH] Close #428: Propose list subscription on site subscription git-svn-id: svn+ssh://murphy/home/svn/platal/trunk@1592 839d8a87-29fc-0310-9880-83ba4fa771e5 --- ChangeLog | 3 ++ include/marketing.inc.php | 1 - include/user.func.inc.php | 61 +++++++++++++++++++++++++++++++------- modules/lists.php | 58 +++++++++++++++++++++++++++++++++--- modules/profile.php | 12 ++++++++ modules/register.php | 17 +++++++++++ modules/xnetgrp.php | 37 +++++++++++++---------- templates/lists/admin.tpl | 62 +++++++++++++++++++++++++++++++++++++++ templates/marketing/private.tpl | 18 +++++++----- templates/register/success.tpl | 17 +++++++++++ templates/xnetgrp/membres-add.tpl | 8 +++-- 11 files changed, 253 insertions(+), 41 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5dfb2d7..93ad4e4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -49,6 +49,9 @@ Bug/Wish: - #636: Remove non-X from trombi -FRU - #638: Sort trombi by promo then name -FRU + * Register: + - #428: Can propose subscription to lists -FRU + * Search: - #132: Better french soundex -FRU - #173: Show only countries where there is a user -FRU diff --git a/include/marketing.inc.php b/include/marketing.inc.php index 997faee..3765729 100644 --- a/include/marketing.inc.php +++ b/include/marketing.inc.php @@ -180,7 +180,6 @@ class Marketing XDB::execute("DELETE FROM register_marketing WHERE uid = {?}", $uid); } else { XDB::execute("DELETE FROM register_marketing WHERE uid = {?} AND email = {?}", $uid, $email); - XDB::execute("DELETE FROM register_subs WHERE uid = {?}", $uid); } } diff --git a/include/user.func.inc.php b/include/user.func.inc.php index ac14221..e1b3b88 100644 --- a/include/user.func.inc.php +++ b/include/user.func.inc.php @@ -76,7 +76,16 @@ function user_clear_all_subs($user_id, $really_del=true) // }}} // {{{ function get_user_login() -function get_user_login($data, $get_forlife = false) { +// Defaut callback to call when a login is not found +function _default_user_callback($login) +{ + global $page; + $page->trig("Il n'y a pas d'utilisateur avec l'identifiant : $login"); + return; +} + +function get_user_login($data, $get_forlife = false, $callback = '_default_user_callback') +{ global $globals, $page; if (is_numeric($data)) { @@ -84,7 +93,7 @@ function get_user_login($data, $get_forlife = false) { if ($res->numRows()) { return $res->fetchOneCell(); } else { - $page->trig("il n'y a pas d'utilisateur avec cet id"); + call_user_func($callback, $data); return false; } } @@ -116,7 +125,7 @@ function get_user_login($data, $get_forlife = false) { return $res->fetchOneCell(); } } - $page->trig("il n'y a pas d'utilisateur avec ce login"); + call_user_func($callback, $data); return false; } elseif ($fqdn == $globals->mail->alias_dom || $fqdn == $globals->mail->alias_dom2) { @@ -128,11 +137,10 @@ function get_user_login($data, $get_forlife = false) { if ($redir = $res->fetchOneCell()) { list($alias) = explode('@', $redir); } else { - $page->trig("il n'y a pas d'utilisateur avec cet alias"); + call_user_func($callback, $data); $alias = false; } return $alias; - } else { $res = XDB::query("SELECT alias @@ -141,7 +149,7 @@ function get_user_login($data, $get_forlife = false) { WHERE e.email={?} AND a.type='a_vie'", $data); switch ($i = $res->numRows()) { case 0: - $page->trig("il n'y a pas d'utilisateur avec cette addresse mail"); + call_user_func($callback, $data); return false; case 1: @@ -163,14 +171,15 @@ function get_user_login($data, $get_forlife = false) { // }}} // {{{ function get_user_forlife() -function get_user_forlife($data) { - return get_user_login($data, true); +function get_user_forlife($data, $callback = '_default_user_callback') +{ + return get_user_login($data, true, $callback); } // }}} // {{{ function get_users_forlife_list() -function get_users_forlife_list($members, $strict = false) +function get_users_forlife_list($members, $strict = false, $callback = '_default_user_callback') { if (strlen(trim($members)) == 0) { return null; @@ -179,7 +188,7 @@ function get_users_forlife_list($members, $strict = false) if ($members) { $list = array(); foreach ($members as $i => $alias) { - if (($login = get_user_forlife($alias)) !== false) { + if (($login = get_user_forlife($alias, $callback)) !== false) { $list[$i] = $login; } else if(!$strict) { $list[$i] = $alias; @@ -202,6 +211,38 @@ function has_user_right($pub, $view = 'private') { return false; } // }}} +// {{{ function get_not_registered_user() + +function get_not_registered_user($login, $iterator = false) +{ + global $globals; + @list($login, $domain) = explode('@', $login); + if ($domain && $domain != $globals->mail->domain && $domain != $globals->mail->domain2) { + return null; + } + @list($prenom, $nom, $promo) = explode('.', $login); + $where = 'REPLACE(REPLACE(REPLACE(nom, " ", ""), "-", ""), "\'", "") LIKE CONCAT("%", {?}, "%") + AND REPLACE(REPLACE(REPLACE(prenom, " ", ""), "-", ""), "\'", "") LIKE CONCAT("%", {?}, "%")'; + if ($promo) { + if (preg_match('/^[0-9]{2}$/', $promo)) { + $where .= 'AND MOD(promo, 100) = {?}'; + } elseif (preg_match('/^[0-9]{4}$/', $promo)) { + $where .= 'AND promo = {?}'; + } + } + $sql = "SELECT user_id, nom, prenom, promo + FROM auth_user_md5 + WHERE $where + ORDER BY promo, nom, prenom"; + if ($iterator) { + return XDB::iterator($sql, $nom, $prenom, $promo); + } else { + $res = XDB::query($sql, $nom, $prenom, $promo); + return $res->fetchAllAssoc(); + } +} + +// }}} // {{{ function get_user_details_pro() function get_user_details_pro($uid, $view = 'private') diff --git a/modules/lists.php b/modules/lists.php index 009950b..c6fb9dc 100644 --- a/modules/lists.php +++ b/modules/lists.php @@ -21,7 +21,7 @@ class ListsModule extends PLModule { - var $client; + protected $client; function handlers() { @@ -533,6 +533,22 @@ class ListsModule extends PLModule } } + static public function no_login_callback($login) + { + require_once 'user.func.inc.php'; + global $list_unregistered; + + $users = get_not_registered_user($login, true); + if ($users->total()) { + if (!isset($list_unregistered)) { + $list_unregistered = array(); + } + $list_unregistered[$login] = $users; + } else { + _default_user_callback($login); + } + } + function handler_admin(&$page, $liste = null) { global $globals; @@ -541,13 +557,43 @@ class ListsModule extends PLModule return PL_NOT_FOUND; } - $this->prepare_client($page); + $domain = $this->prepare_client($page); $this->changeTpl('lists/admin.tpl'); + if (Env::has('send_mark')) { + $actions = Env::v('mk_action'); + $uids = Env::v('mk_uid'); + $mails = Env::v('mk_email'); + foreach ($actions as $key=>$action) { + switch ($action) { + case 'none': + break; + + case 'marketu': case 'markets': + require_once 'emails.inc.php'; + $mail = valide_email($mails[$key]); + if (isvalid_email_redirection($mail)) { + $from = ($action == 'marketu') ? 'user' : 'staff'; + $market = Marketing::get($uids[$key], $mail); + if (!$market) { + $market = new Marketing($uids[$key], $mail, 'list', "$liste@$domain", $from, S::v('uid')); + $market->add(); + break; + } + } + + default: + XDB::execute('INSERT IGNORE INTO register_subs (uid, type, sub, domain) + VALUES ({?}, \'list\', {?}, {?})', + $uids[$key], $liste, $domain); + } + } + } + if (Env::has('add_member')) { require_once('user.func.inc.php'); - $members = get_users_forlife_list(Env::v('add_member')); + $members = get_users_forlife_list(Env::v('add_member'), false, array('ListsModule', 'no_login_callback')); $arr = $this->client->mass_subscribe($liste, $members); if (is_array($arr)) { foreach($arr as $addr) { @@ -568,7 +614,7 @@ class ListsModule extends PLModule if (Env::has('add_owner')) { require_once('user.func.inc.php'); - $owners = get_users_forlife_list(Env::v('add_owner')); + $owners = get_users_forlife_list(Env::v('add_owner'), false, array('ListsModule', 'no_login_callback')); if ($owners) { foreach ($owners as $login) { if ($this->client->add_owner($liste, $login)) { @@ -588,6 +634,10 @@ class ListsModule extends PLModule } if (list($det,$mem,$own) = $this->client->get_members($liste)) { + global $list_unregistered; + if ($list_unregistered) { + $page->assign_by_ref('unregistered', $list_unregistered); + } $membres = list_sort_members($mem, @$tri_promo); $moderos = list_sort_owners($own, @$tri_promo); diff --git a/modules/profile.php b/modules/profile.php index 3e00705..88e850f 100644 --- a/modules/profile.php +++ b/modules/profile.php @@ -293,6 +293,18 @@ class ProfileModule extends PLModule $mmlist = new MMList(S::v('uid'), S::v('password')); $mmlist->subscribe("promo".S::v('promo')); } + if (Post::v('sub_ml')) { + $subs = array_keys(Post::v('sub_ml')); + $current_domain = null; + foreach ($subs as $list) { + list($sub, $domain) = explode('@', $list); + if ($domain != $current_domain) { + $current_domain = $domain; + $client = new MMList(S::v('uid'), S::v('password'), $domain); + } + $client->subscribe($sub); + } + } if (is_ax_key_missing()) { $page->assign('no_private_key', true); diff --git a/modules/register.php b/modules/register.php index cbf425e..77dff4d 100644 --- a/modules/register.php +++ b/modules/register.php @@ -377,6 +377,23 @@ class RegisterModule extends PLModule $page->assign('mdpok', true); } + $res = XDB::iterRow("SELECT sub, domain + FROM register_subs + WHERE uid = {?} AND type = 'list' + ORDER BY domain", + S::i('uid')); + $current_domain = null; + $lists = array(); + while (list($sub, $domain) = $res->next()) { + if ($current_domain != $domain) { + $current_domain = $domain; + $client = new MMList(S::v('uid'), S::v('password'), $domain); + } + list($details, ) = $client->get_members($sub); + $lists["$sub@$domain"] = $details; + } + $page->assign_by_ref('lists', $lists); + $page->addJsLink('motdepasse.js'); } } diff --git a/modules/xnetgrp.php b/modules/xnetgrp.php index 9eb51e0..42c70c0 100644 --- a/modules/xnetgrp.php +++ b/modules/xnetgrp.php @@ -744,22 +744,29 @@ class XnetGrpModule extends PLModule { header('Content-Type: text/html; charset="UTF-8"'); $page->changeTpl('xnetgrp/membres-new-search.tpl', NO_SKIN); - list($nom, $prenom) = str_replace(array('-', ' ', "'"), '%', array(Env::v('nom'), Env::v('prenom'))); - $where = "perms = 'pending'"; - if (!empty($nom)) { - $where .= " AND nom LIKE '%$nom%'"; - } - if (!empty($prenom)) { - $where .= " AND prenom LIKE '%$prenom%'"; - } - if (preg_match('/^[0-9]{4}$/', Env::v('promo'))) { - $where .= " AND promo = " . Env::i('promo'); - } elseif (Env::has('promo')) { - return; + if (Env::has('login')) { + require_once 'user.func.inc.php'; + $res = get_not_registered_user(Env::v('login'), true); + } else { + list($nom, $prenom) = str_replace(array('-', ' ', "'"), '%', array(Env::v('nom'), Env::v('prenom'))); + $where = "perms = 'pending'"; + if (!empty($nom)) { + $where .= " AND nom LIKE '%$nom%'"; + } + if (!empty($prenom)) { + $where .= " AND prenom LIKE '%$prenom%'"; + } + if (preg_match('/^[0-9]{4}$/', Env::v('promo'))) { + $where .= " AND promo = " . Env::i('promo'); + } elseif (preg_match('/^[0-9]{2}$/', Env::v('promo'))) { + $where .= " AND MOD(promo, 100) = " . Env::i('promo'); + } elseif (Env::has('promo')) { + return; + } + $res = XDB::iterator("SELECT user_id, nom, prenom, promo + FROM auth_user_md5 + WHERE $where"); } - $res = XDB::iterator("SELECT user_id, nom, prenom, promo - FROM auth_user_md5 - WHERE $where"); if ($res->total() < 30) { $page->assign("choix", $res); } diff --git a/templates/lists/admin.tpl b/templates/lists/admin.tpl index 3a73559..b511363 100644 --- a/templates/lists/admin.tpl +++ b/templates/lists/admin.tpl @@ -36,6 +36,68 @@ L'icône {icon name=cross title='retirer membre'} permet de désinscrire de la l qui y était abonné.

+{if $unregistered|@count neq 0} +

Marketing d'utilisateurs non-inscrits

+ +

+{if $unregistered|@count eq 1} +L'utilisateur suivant n'est pas inscrit à Polytechnique.org. Tu peux l'y inciter en lui faisant envoyer un mail de marketing. Une fois inscrit à Polytechnique.org, l'inscription à la liste lui sera automatiquement proposée. +{else} +Les utilisateurs suivants ne sont pas inscrits à Polytechnique.org. Tu peux les y inciter en leur faisant envoyer des +mails de marketing. Une fois inscrits à Polytechnique.org, l'inscription à la liste leur sera automatique proposée. +{/if} +

+ + + +

+ + {foreach from=$unregistered key=login item=it} + + + + + {/foreach} +
{$login} + Camarade : +
+ Action* : +
+ +
+

+ +

+
+ +

+ *: La dernière action ajoute simplement la liste de diffusion aux abonnements qui seront proposés au camarade + lors de son inscription à Polytechnique.org sans pour autant lui enovyer de mail de marketing. Cette action est + automatique si tu choisis l'envoi de mail. +

+ +{/if} +

modérateurs de la liste

diff --git a/templates/marketing/private.tpl b/templates/marketing/private.tpl index 0df5d09..c74cba1 100644 --- a/templates/marketing/private.tpl +++ b/templates/marketing/private.tpl @@ -103,14 +103,16 @@ sa dernière relance date du {$relance|date_format} From: - {if $rel_from_staff neq $rel_from_user} - - {else} - {$rel_from_staff} - {/if} + + {if $rel_from_staff neq $rel_from_user} + + {else} + {$rel_from_staff} + {/if} + To: diff --git a/templates/register/success.tpl b/templates/register/success.tpl index c526f82..f8e1cc8 100644 --- a/templates/register/success.tpl +++ b/templates/register/success.tpl @@ -138,6 +138,23 @@ traitées avec la priorité minimale. + {if $lists|@count neq 0} +

+ Des camarades souhaitent que tu t'inscrives aux listes suivantes : +

+ +
+ {foreach from=$lists key=list item=details} +
{$list}* : {$details.desc}
+ {if $details.info} +
+ {$details.info|nl2br} +
+ {/if} + {/foreach} +
+ {/if} +

* décoche les cases si tu ne souhaites pas être inscrit à la liste de diffusion correspondante

diff --git a/templates/xnetgrp/membres-add.tpl b/templates/xnetgrp/membres-add.tpl index 2b34bf7..75ea89f 100644 --- a/templates/xnetgrp/membres-add.tpl +++ b/templates/xnetgrp/membres-add.tpl @@ -29,6 +29,8 @@ function xStateChange(box) document.getElementById('xprenom').style.display = state; document.getElementById('xpromo').style.display = state; document.getElementById('xsearch').style.display = state; + Ajax.update_html('search_result', + '{/literal}{$platal->ns}{literal}member/new/ajax?login=' + document.getElementById('email').value); } var nom; @@ -69,15 +71,15 @@ function searchX() -- 2.1.4
- +
- - Coche cette case si il s'agit d'un X non inscrit à Polytechnique.org + +