From: x2003bruneau Date: Wed, 11 Oct 2006 12:22:27 +0000 (+0000) Subject: Remove duplicated code for checking a list of login X-Git-Tag: xorg/0.9.12~210 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=e7545178032651fe335123197ed06671bfa10b26;p=platal.git Remove duplicated code for checking a list of login Can add a list a login in list creation form git-svn-id: svn+ssh://murphy/home/svn/platal/trunk@969 839d8a87-29fc-0310-9880-83ba4fa771e5 --- diff --git a/include/user.func.inc.php b/include/user.func.inc.php index 42ac932..f5af491 100644 --- a/include/user.func.inc.php +++ b/include/user.func.inc.php @@ -150,6 +150,29 @@ function get_user_forlife($data) { } // }}} +// {{{ function get_users_forlife_list() + +function get_users_forlife_list($members, $strict = false) +{ + if (strlen(trim($members)) == 0) { + return null; + } + $members = explode(' ', $members); + if ($members) { + $list = array(); + foreach ($members as $i => $alias) { + if (($login = get_user_forlife($alias)) !== false) { + $list[$i] = $login; + } else if(!$strict) { + $list[$i] = $alias; + } + } + return $list; + } + return null; +} + +// }}} // {{{ function has_user_right() function has_user_right($pub, $view = 'private') { if ($pub == $view) return true; diff --git a/modules/lists.php b/modules/lists.php index cef424c..f31b51b 100644 --- a/modules/lists.php +++ b/modules/lists.php @@ -100,29 +100,31 @@ class ListsModule extends PLModule require_once('user.func.inc.php'); // if we want to add an owner and then type , then both // add_owner_sub and add_owner are filled. - if (Post::v('add_owner') != "") { - if (($forlife = get_user_forlife(Post::v('add_owner'))) !== false) { - $owners [] = $forlife; - } - // if we want to add a member and then type , then - // add_owner_sub is filled, whereas add_owner is empty. - } else if (Post::has('add_member')) { - if (($forlife = get_user_forlife(Post::v('add_member'))) !== false) { - $members[] = $forlife; - } + $oforlifes = get_users_forlife_list(Post::v('add_owner'), true); + $mforlifes = get_users_forlife_list(Post::v('add_member'), true); + if (!is_null($oforlifes)) { + $owners = array_merge($owners, $oforlifes); + } + // if we want to add a member and then type , then + // add_owner_sub is filled, whereas add_owner is empty. + if (!is_null($mforlifes)) { + $members = array_merge($members, $mforlifes); } } // click on validate button 'add_member_sub' if (Post::has('add_member_sub') && Post::has('add_member')) { require_once('user.func.inc.php'); - if (($forlife = get_user_forlife(Post::v('add_member'))) !== false) { - $members[] = $forlife; + $forlifes = get_users_forlife_list(Post::v('add_member'), true); + if (!is_null($forlifes)) { + $members = array_merge($members, $forlifes); } } - ksort($owners); array_unique($owners); - ksort($members); array_unique($members); + ksort($owners); + $owners = array_unique($owners); + ksort($members); + $members = array_unique($members); $page->assign('owners', join(' ', $owners)); $page->assign('members', join(' ', $members)); @@ -421,15 +423,8 @@ class ListsModule extends PLModule $page->changeTpl('listes/admin.tpl'); if (Env::has('add_member')) { - require_once('user.func.inc.php'); - $members = explode(' ', Env::v('add_member')); - if ($members) foreach ($members as $i => $alias) { - if (($login = get_user_forlife($alias)) !== false) {; - $members[$i] = $login; - } - } - + $members = get_users_forlife_list(Env::v('add_member')); $arr = $this->client->mass_subscribe($liste, $members); if (is_array($arr)) { foreach($arr as $addr) { @@ -450,16 +445,12 @@ class ListsModule extends PLModule if (Env::has('add_owner')) { require_once('user.func.inc.php'); - - $owners = explode(' ', Env::v('add_owner')); - - if ($owners) foreach ($owners as $alias) { - if (($login = get_user_forlife($alias)) === false) {; - $login = $alias; - } - - if ($this->client->add_owner($liste, $login)) { - $page->trig($alias." ajouté aux modérateurs."); + $owners = get_users_forlife_list(Env::v('add_owner')); + if ($owners) { + foreach ($owners as $login) { + if ($this->client->add_owner($liste, $login)) { + $page->trig($alias." ajouté aux modérateurs."); + } } } } diff --git a/templates/listes/create.tpl b/templates/listes/create.tpl index 6f9ac86..d917cda 100644 --- a/templates/listes/create.tpl +++ b/templates/listes/create.tpl @@ -107,6 +107,11 @@ liste : + + + Tu peux entrer une liste de membres en entrant plusieurs adresses séparées par des espaces + +

La création de la liste sera soumise à un contrôle manuel avant d'être validée. Ce contrôle a