From 108d1d90ce02c0ffe28b8d795f948b4eaba48bba Mon Sep 17 00:00:00 2001 From: Florent Bruneau Date: Sat, 28 Jun 2008 17:59:37 +0200 Subject: [PATCH] Can add member to a list using a file (one line per email, one email per line) (Closes #756) Signed-off-by: Florent Bruneau --- include/user.func.inc.php | 6 +++++- modules/lists.php | 17 +++++++++++++++++ modules/lists/lists.inc.php | 2 +- templates/lists/admin.tpl | 32 ++++++++++++++++++++++++-------- 4 files changed, 47 insertions(+), 10 deletions(-) diff --git a/include/user.func.inc.php b/include/user.func.inc.php index b903654..a363394 100644 --- a/include/user.func.inc.php +++ b/include/user.func.inc.php @@ -198,11 +198,15 @@ function get_users_forlife_list($members, $strict = false, $callback = '_default if (strlen(trim($members)) == 0) { return null; } - $members = explode(' ', $members); + $members = split("[; ,\r\n\|]+", $members); } if ($members) { $list = array(); foreach ($members as $i => $alias) { + $alias = trim($alias); + if (empty($alias)) { + continue; + } if (($login = get_user_forlife($alias, $callback)) !== false) { $list[$i] = $login; } else if(!$strict) { diff --git a/modules/lists.php b/modules/lists.php index 4012711..132c179 100644 --- a/modules/lists.php +++ b/modules/lists.php @@ -599,6 +599,23 @@ class ListsModule extends PLModule } } + if (isset($_FILES['add_member_file']) && $_FILES['add_member_file']['tmp_name']) { + $upload =& PlUpload::get($_FILES['add_member_file'], S::v('forlife'), 'list.addmember', true); + if (!$upload) { + $page->trigError('Une erreur s\'est produite lors du téléchargement du fichier'); + } else { + $members = get_users_forlife_list($upload->getContents(), + false, + array('ListsModule', 'no_login_callback')); + $arr = $this->client->mass_subscribe($liste, $members); + if (is_array($arr)) { + foreach($arr as $addr) { + $page->trigSuccess("{$addr[0]} inscrit."); + } + } + } + } + if (Env::has('del_member')) { if (strpos(Env::v('del_member'), '@') === false) { $this->client->mass_unsubscribe( diff --git a/modules/lists/lists.inc.php b/modules/lists/lists.inc.php index c3a5abf..2fcb84e 100644 --- a/modules/lists/lists.inc.php +++ b/modules/lists/lists.inc.php @@ -53,7 +53,7 @@ function list_sort_owners(&$members, $tri_promo = true) { LEFT JOIN auth_user_md5 AS u ON(m2.origine = "X" AND m2.uid = u.user_id) WHERE m1.email={?}', $globals->asso('id'), $mem); if (list($uid, $prenom, $nom, $promo) = $res->fetchOneRow()) { - $key = $tri_promo ? ($promo != 'non-X' ? $promo : 0) : strtoupper($nom{0}); + $key = $tri_promo ? ($promo != 'non-X' ? $promo : 0) : strtoupper(@$nom{0}); if ($tri_promo) { $promo = null; } diff --git a/templates/lists/admin.tpl b/templates/lists/admin.tpl index d0efb02..0adaf22 100644 --- a/templates/lists/admin.tpl +++ b/templates/lists/admin.tpl @@ -112,7 +112,7 @@ mails de marketing. Une fois inscrits à Polytechnique.org, l'inscription à la {if $promo && strpos($x.l, '@') === false} {$x.n} {elseif $x.x} - {$x.n} + {if $x.n|trim}{$x.n}{else}{$x.l}{/if} {elseif $x.n} {$x.n} {else} @@ -124,11 +124,10 @@ mails de marketing. Une fois inscrits à Polytechnique.org, l'inscription à la {/foreach} - - Ajouter ... + + Ajouter -   @@ -140,7 +139,7 @@ mails de marketing. Une fois inscrits à Polytechnique.org, l'inscription à la {$np_m|default:"0"} membre{if $np_m > 1}s{/if} dans la liste -
+ {foreach from=$members item=xs key=promo} @@ -150,7 +149,7 @@ mails de marketing. Une fois inscrits à Polytechnique.org, l'inscription à la {if $promo && strpos($x.l, '@') === false} {$x.n} {elseif $x.x} - {$x.n} + {if $x.n|trim}{$x.n}{else}{$x.l}{/if} {elseif $x.n} {$x.n} {else} @@ -163,15 +162,32 @@ mails de marketing. Une fois inscrits à Polytechnique.org, l'inscription à la {/foreach} - + + + + + + + + + + +
Ajouter ...Ajouter
Liste -   +
ou fichier(*) + * +
+
+ * Le fichier doit contenir une adresse e-mail par ligne. Les X doivent être identifiés par une adresse + @polytechnique.org, @m4x.org ou @melix.net/org. +
+ {* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *} -- 2.1.4