1 #**************************************************************************
2 # Copyright (C) 2006 by Michael Andreen <harvATruinDOTnu> *
4 # This program is free software; you can redistribute it and/or modify *
5 # it under the terms of the GNU General Public License as published by *
6 # the Free Software Foundation; either version 2 of the License, or *
7 # (at your option) any later version. *
9 # This program is distributed in the hope that it will be useful, *
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 # GNU General Public License for more details. *
14 # You should have received a copy of the GNU General Public License *
15 # along with this program; if not, write to the *
16 # Free Software Foundation, Inc., *
17 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
18 #**************************************************************************/
20 package NDWeb::Pages::Mail;
22 use warnings FATAL => 'all';
23 use CGI qw/:standard/;
29 use base qw/NDWeb::XMLPage/;
31 $NDWeb::Page::PAGES{mail} = __PACKAGE__;
37 my $DBH = $self->{DBH};
39 $self->{TITLE} = 'Mail members';
41 return $self->noAccess unless $self->isHC;
43 my $groups = $DBH->prepare(q{SELECT gid,groupname FROM groups WHERE gid > 0 ORDER BY gid});
46 push @groups,{gid => -1, groupname => 'Pick a group'};
47 while (my $group = $groups->fetchrow_hashref){
50 $BODY->param(Groups => \@groups);
52 if (defined param('cmd') && param('group') > 0){
53 my $emails = $DBH->prepare(q{SELECT email FROM users
54 WHERE uid IN (SELECT uid FROM groupmembers WHERE gid = $1)
55 AND email is not null});
56 $emails->execute(param('group'));
58 while (my $email = $emails->fetchrow_hashref){
59 push @emails,$email->{email};
61 $ND::ERROR .= p (join ', ',@emails);
65 BCC => (join ',',@emails),
66 From => 'NewDawn Command <nd@ruin.nu>',
67 'Content-type' => 'text/plain; charset="UTF-8"',
68 Subject => param('subject'),
69 Message => param('message'),
73 $ND::ERROR .= p "Mail sent OK.\n"
75 $ND::ERROR .= p $Mail::Sendmail::error;
77 }elsif(defined param('message')) {
78 $BODY->param(Subject => param('subject'));
79 $BODY->param(Message => param('message'));