aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/admin/admin_mass_email.php
blob: 593bf62e14bf8ccac20da83e1c5638b782e221cc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
<?php
/***************************************************************************
*                             admin_email.php
*                              -------------------
*     begin                : Thu May 31, 2001
*     copyright            : (C) 2001 The phpBB Group
*     email                : support@phpbb.com
*
*     $Id$
*
****************************************************************************/

/***************************************************************************
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 ***************************************************************************/

/***************************************************************************
	Mass Mailings can be used by admin to mail either the entire board or
	all members of a specific group.
***************************************************************************/

if($setmodules == 1)
{
        $filename = basename(__FILE__);
        $module['General']['Mass_Email'] = $filename;

        return;
}

//
// Load default header
//
$phpbb_root_dir = "./../";
$no_page_header = TRUE;
require('pagestart.inc');

//
// Increase maximum execution time in case of a lot of users, but don't complain about it if it isn't
// allowed.
//
@set_time_limit(1200);

//
// Set form names
//
$f_title = 'e_title';
$f_msg = 'e_msg';

if( isset($HTTP_POST_VARS['submit']) )
{
	$group_id = intval($HTTP_POST_VARS[POST_GROUPS_URL]);

	if( $group_id != -1 )
	{
		$sql = "SELECT u.user_email 
			FROM " . USERS_TABLE . " u, " . USER_GROUP_TABLE . " g
			WHERE u.user_id = g.user_id 
				AND g.group_id = $group_id";
	}
	else
	{
		$sql = "SELECT user_email 
			FROM " . USERS_TABLE;
	}

	if( !$result = $db->sql_query($sql) )
	{
		message_die(GENERAL_ERROR, "Coult not select group members!", __LINE__, __FILE__, $sql);
	}
	$email_list = $db->sql_fetchrowset($g_result);
	
	$subject = stripslashes($HTTP_POST_VARS["$f_title"]);
	$message = stripslashes($HTTP_POST_VARS["$f_msg"]);
	
	include($phpbb_root_path . 'includes/emailer.'.$phpEx);
	$emailer = new emailer($board_config['smtp_delivery']);

	$email_headers = "From: " . $board_config['board_email'] . "\n";

	$bcc_list = "";
	for($i = 0; $i < count($email_list); $i++)
	{
		if( $bcc_list != "" )
		{
			$bcc_list .= ", ";
		}
		$bcc_list .= $email_list[$i]['user_email'];
	}
	$email_headers .= "Bcc: $bcc_list\n";
	
	$email_headers .= "Return-Path: " . $userdata['board_email'] . "\n";
	$email_headers .= "X-AntiAbuse: Board servername - " . $server_name . "\n";
	$email_headers .= "X-AntiAbuse: User_id - " . $userdata['user_id'] . "\n";
	$email_headers .= "X-AntiAbuse: Username - " . $userdata['username'] . "\n";
	$email_headers .= "X-AntiAbuse: User IP - " . decode_ip($user_ip) . "\r\n";

	$emailer->use_template("admin_send_email");
	$emailer->email_address($board_config['board_email']);
	$emailer->set_subject($subject);
	$emailer->extra_headers($email_headers);

	$emailer->assign_vars(array(
		"SITENAME" => $board_config['sitename'], 
		"BOARD_EMAIL" => $board_config['board_email'], 
		"MESSAGE" => $message)
	);
	$emailer->send();
	$emailer->reset();

	$template->assign_vars(array(
		"META" => '<meta http-equiv="refresh" content="5;url=' . append_sid("index.$phpEx") . '">')
	);

	$message = $lang['Email_sent'] . "<br /><br />" . sprintf($lang['Click_return_admin_index'],  "<a href=\"" . append_sid("index.$phpEx?pane=right") . "\">", "</a>");

	message_die(GENERAL_MESSAGE, $message);

}	

//
// Initial selection
//

$sql = "SELECT group_id, group_name 
	FROM ".GROUPS_TABLE . "  
	WHERE group_single_user <> 1";
$g_result = $db->sql_query($sql);
$group_list = $db->sql_fetchrowset($g_result);

$select_list = '<select name = "' . POST_GROUPS_URL . '">';
$select_list .= '<option value = "-1">' . $lang['All_users'] . '</option>';

for($i = 0;$i < count($group_list); $i++)
{
	$select_list .= "<option value = \"" . $group_list[$i]['group_id'];
	$select_list .= "\">" . $group_list[$i]['group_name'] . "</option>";
}
$select_list .= "</select>";

//
// Generate page
//
include('page_header_admin.'.$phpEx);

$template->set_filenames(array(
	"body" => "admin/user_email_body.tpl")
);

$template->assign_vars(array(
	"L_EMAIL_TITLE" => $lang['Email'],
	"L_EMAIL_EXPLAIN" => $lang['Mass_email_explain'],
	"L_COMPOSE" => $lang['Compose'],
	"L_RECIPIENTS" => $lang['Recipients'],
	"L_EMAIL_SUBJECT" => $lang['Subject'],
	"L_EMAIL_MSG" => $lang['Message'],
	"L_EMAIL" => $lang['Email'],
	"L_NOTICE" => $notice,

	"S_USER_ACTION" => append_sid('admin_mass_email.'.$phpEx),
	"S_GROUP_SELECT" => $select_list,
	"S_EMAIL_SUBJECT" => $f_title,
	"S_EMAIL_MSG" => $f_msg)
);

$template->pparse('body');

include('page_footer_admin.'.$phpEx);

?>