Commit | Line | Data |
---|---|---|
0337d704 | 1 | <?php |
2 | /*************************************************************************** | |
9f5bd98e | 3 | * Copyright (C) 2003-2010 Polytechnique.org * |
0337d704 | 4 | * http://opensource.polytechnique.org/ * |
5 | * * | |
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. * | |
10 | * * | |
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. * | |
15 | * * | |
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 * | |
18 | * Foundation, Inc., * | |
19 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * | |
20 | ***************************************************************************/ | |
21 | ||
0337d704 | 22 | // {{{ get_all_redirects |
23 | ||
892083ef | 24 | function get_all_redirects($membres, $mls, &$client) |
0337d704 | 25 | { |
26 | global $globals; | |
eaf30d86 | 27 | |
0337d704 | 28 | $tos = array(); |
eaf30d86 | 29 | |
22c8c0c3 | 30 | // TODO: add more filters to choose users |
06db561e | 31 | if (!empty($membres)) { |
1eaaa62d | 32 | $uf = new UserFilter(new UFC_Group($globals->asso('id'))); |
22c8c0c3 | 33 | $tos = $uf->getUsers(); |
0337d704 | 34 | } |
35 | ||
36 | foreach ($mls as $ml) { | |
5c9c7889 RB |
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); | |
40 | if ($list_members) { | |
41 | foreach ($list_members[1] as $mem) { | |
07a85e79 | 42 | $uf = new UserFilter(new UFC_Email($mem[1])); |
5c9c7889 | 43 | $user = $uf->getUser(); |
22c8c0c3 FB |
44 | if ($user) { |
45 | $tos[] = $user; | |
0337d704 | 46 | } else { |
22c8c0c3 | 47 | $tos[] = $mem[1]; |
0337d704 | 48 | } |
49 | } | |
50 | } | |
51 | } | |
52 | ||
53 | return $tos; | |
54 | } | |
55 | ||
56 | // }}} | |
57 | // {{{ _send_xnet_mail | |
58 | ||
5b21237d | 59 | function _send_xnet_mail($user, $body, $wiki, $mailer, $replyto = null) |
0337d704 | 60 | { |
22c8c0c3 | 61 | if ($user instanceof PlUser) { |
b41fa03a SJ |
62 | $dear = $user->isFemale() ? 'Chère' : 'Cher'; |
63 | $lastname = $user->lastName(); | |
64 | $firstname = $user->firstName(); | |
22c8c0c3 | 65 | } else { |
b41fa03a SJ |
66 | $dear = 'Cher(e)'; |
67 | $lastname = ''; | |
68 | $firstname = $user; | |
22c8c0c3 | 69 | } |
eaf30d86 | 70 | |
1f759655 | 71 | $text = str_ireplace(array('<cher>', '<nom>', '<prenom>'), |
b41fa03a | 72 | array($dear, $lastname, $firstname), $body); |
c469507d | 73 | $mailer->setTo($user); |
9898b36e | 74 | if ($replyto) { |
75 | $mailer->addHeader('Reply-To', $replyto); | |
76 | } | |
5b21237d | 77 | if ($wiki) { |
78 | $mailer->setWikiBody($text); | |
79 | } else { | |
80 | $mailer->setTxtBody(wordwrap($text, 72)); | |
81 | } | |
91a14f73 | 82 | $mailer->send(); |
0337d704 | 83 | } |
84 | ||
85 | // }}} | |
86 | // {{{ send_xnet_mails | |
87 | ||
5b21237d | 88 | function send_xnet_mails($from, $sujet, $body, $wiki, $tos, $replyto = null, $upload = null, $name = null) |
0337d704 | 89 | { |
bdccfd95 | 90 | global $globals; |
0337d704 | 91 | $sent = array(); |
92 | ||
1e33266a | 93 | $mailer = new PlMailer(); |
0337d704 | 94 | $mailer->setSubject($sujet); |
95 | $mailer->setFrom($from); | |
13627bef | 96 | if ($upload && $upload->exists()) { |
97 | $mailer->addUploadAttachment($upload, $name); | |
91a14f73 | 98 | } |
0337d704 | 99 | |
100 | foreach ($tos as $user) { | |
b1a22c84 | 101 | if ($user instanceof User) { |
22c8c0c3 FB |
102 | $email = $user->bestEmail(); |
103 | } else { | |
104 | $email = $user; | |
105 | } | |
965221bf VZ |
106 | |
107 | if (!isset($sent[$email])) { | |
108 | _send_xnet_mail($user, $body, $wiki, $mailer, $replyto); | |
109 | $sent[$email] = true; | |
22c8c0c3 | 110 | } |
0337d704 | 111 | } |
112 | } | |
113 | ||
114 | // }}} | |
115 | ||
a7de4ef7 | 116 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
0337d704 | 117 | ?> |