2 /***************************************************************************
3 * Copyright (C) 2003-2011 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the Free Software *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
22 // {{{ get_all_redirects
24 function get_all_redirects($membres, $mls, $client)
30 // TODO: add more filters to choose users
31 if (!empty($membres)) {
32 $uf = new UserFilter(new UFC_Group($globals->asso('id')));
33 $tos = $uf->getUsers();
36 foreach ($mls as $ml) {
37 // $list_members is a (list_details, members, list_owners) array, where
38 // members is an array of (0 => name, 1 => email) arrays.
39 $list_members = $client->get_members($ml);
41 foreach ($list_members[1] as $mem) {
42 $uf = new UserFilter(new UFC_Email($mem[1]));
43 $user = $uf->getUser();
57 // {{{ _send_xnet_mail
59 function _send_xnet_mail($user, $body, $wiki, $mailer, $replyto = null
)
61 if ($user instanceof PlUser
) {
62 $dear = $user->isFemale() ?
'Chère' : 'Cher';
63 $lastname = $user->lastName();
64 $firstname = $user->firstName();
71 $text = str_ireplace(array('<cher>', '<nom>', '<prenom>'),
72 array($dear, $lastname, $firstname), $body);
73 $mailer->setTo($user);
75 $mailer->addHeader('Reply-To', $replyto);
78 $mailer->setWikiBody($text);
80 $mailer->setTxtBody(wordwrap($text, 72));
86 // {{{ send_xnet_mails
88 function send_xnet_mails($from, $sujet, $body, $wiki, $tos, $replyto = null
, $upload = null
, $name = null
)
93 $mailer = new PlMailer();
94 $mailer->setSubject($sujet);
95 $mailer->setFrom($from);
96 if ($upload && $upload->exists()) {
97 $mailer->addUploadAttachment($upload, $name);
100 foreach ($tos as $user) {
101 if ($user instanceof User
) {
102 $email = $user->bestEmail();
107 if (!isset($sent[$email])) {
108 _send_xnet_mail($user, $body, $wiki, $mailer, $replyto);
109 $sent[$email] = true
;
116 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: