]> ruin.nu Git - ndwebbie.git/blob - NDWeb/Pages/Mail.pm
858d0ded49585e663e33288b61f80f5a32e70ea4
[ndwebbie.git] / NDWeb / Pages / Mail.pm
1 #**************************************************************************
2 #   Copyright (C) 2006 by Michael Andreen <harvATruinDOTnu>               *
3 #                                                                         *
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.                                   *
8 #                                                                         *
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.                          *
13 #                                                                         *
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 #**************************************************************************/
19
20 package ND::Web::Pages::Mail;
21 use strict;
22 use warnings FATAL => 'all';
23 use CGI qw/:standard/;
24 use Mail::Sendmail;
25
26 use ND::Web::Forum;
27 use ND::Web::Include;
28
29 use base qw/ND::Web::XMLPage/;
30
31 $ND::Web::Page::PAGES{mail} = __PACKAGE__;
32
33 sub render_body {
34         my $self = shift;
35         my ($BODY) = @_;
36
37         my $DBH = $self->{DBH};
38
39         $self->{TITLE} = 'Mail members';
40
41         return $self->noAccess unless $self->isHC;
42
43         my $groups = $DBH->prepare(q{SELECT gid,groupname FROM groups ORDER BY gid});
44         $groups->execute;
45         my @groups;
46         while (my $group = $groups->fetchrow_hashref){
47                 push @groups,$group;
48         }
49         $BODY->param(Groups => \@groups);
50
51         if (defined param('cmd')){
52                 my $emails = $DBH->prepare(q{SELECT email FROM users WHERE (uid IN (SELECT uid FROM groupmembers WHERE gid = $1) OR $1 = -1) AND email is not null});
53                 $emails->execute(param('group'));
54                 my @emails;
55                 while (my $email = $emails->fetchrow_hashref){
56                         push @emails,$email->{email};
57                 }
58                 $ND::ERROR .= p (join ', ',@emails);
59
60                 my %mail = (
61                         smtp => 'ruin.nu',
62                         BCC      => (join ',',@emails),
63                         From    => 'NewDawn Command <nd@ruin.nu>',
64                         'Content-type' => 'text/plain; charset="UTF-8"',
65                         Subject => param('subject'),
66                         Message => param('message'),
67                 );
68
69                 if (sendmail %mail) {
70                         $ND::ERROR .= p "Mail sent OK.\n" 
71                 }else {
72                         $ND::ERROR .= p $Mail::Sendmail::error;
73                 }
74         }
75         return $BODY;
76 }
77 1;