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) { | |
37 | if (list(,$members) = $client->get_members($ml)) { | |
38 | foreach ($members as $mem) { | |
22c8c0c3 FB |
39 | $uf = new UserFilter(new UFC_Mail($mem[1])); |
40 | $user = $uf->getUsers(); | |
41 | if ($user) { | |
42 | $tos[] = $user; | |
0337d704 | 43 | } else { |
22c8c0c3 | 44 | $tos[] = $mem[1]; |
0337d704 | 45 | } |
46 | } | |
47 | } | |
48 | } | |
49 | ||
50 | return $tos; | |
51 | } | |
52 | ||
53 | // }}} | |
54 | // {{{ _send_xnet_mail | |
55 | ||
5b21237d | 56 | function _send_xnet_mail($user, $body, $wiki, $mailer, $replyto = null) |
0337d704 | 57 | { |
22c8c0c3 FB |
58 | if ($user instanceof PlUser) { |
59 | $cher = $user->isFemale() ? 'Chère' : 'Cher'; | |
60 | $nom = $user->displayName(); | |
61 | $pnom = ''; | |
62 | } else { | |
63 | $cher = 'Cher(e)'; | |
64 | $nom = $user; | |
65 | $pnom = ''; | |
66 | } | |
eaf30d86 | 67 | |
1f759655 FB |
68 | $text = str_ireplace(array('<cher>', '<nom>', '<prenom>'), |
69 | array($cher, $nom, $pnom), $body); | |
22c8c0c3 | 70 | $mailer->addTo($user); |
9898b36e | 71 | if ($replyto) { |
72 | $mailer->addHeader('Reply-To', $replyto); | |
73 | } | |
5b21237d | 74 | if ($wiki) { |
75 | $mailer->setWikiBody($text); | |
76 | } else { | |
77 | $mailer->setTxtBody(wordwrap($text, 72)); | |
78 | } | |
91a14f73 | 79 | $mailer->send(); |
0337d704 | 80 | } |
81 | ||
82 | // }}} | |
83 | // {{{ send_xnet_mails | |
84 | ||
5b21237d | 85 | function send_xnet_mails($from, $sujet, $body, $wiki, $tos, $replyto = null, $upload = null, $name = null) |
0337d704 | 86 | { |
bdccfd95 | 87 | global $globals; |
0337d704 | 88 | $sent = array(); |
89 | ||
1e33266a | 90 | $mailer = new PlMailer(); |
0337d704 | 91 | $mailer->setSubject($sujet); |
92 | $mailer->setFrom($from); | |
13627bef | 93 | if ($upload && $upload->exists()) { |
94 | $mailer->addUploadAttachment($upload, $name); | |
91a14f73 | 95 | } |
0337d704 | 96 | |
97 | foreach ($tos as $user) { | |
22c8c0c3 FB |
98 | if ($user instanceof $user) { |
99 | $email = $user->bestEmail(); | |
100 | } else { | |
101 | $email = $user; | |
102 | } | |
103 | if ($sent[$email]) { | |
104 | continue; | |
105 | } | |
5b21237d | 106 | _send_xnet_mail($user, $body, $wiki, $mailer, $replyto); |
22c8c0c3 | 107 | $sent[$email] = true; |
0337d704 | 108 | } |
109 | } | |
110 | ||
111 | // }}} | |
112 | ||
a7de4ef7 | 113 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
0337d704 | 114 | ?> |