aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/admin/admin_email.php
blob: e1e6af523d87ed8e3492e7ef551e8682bea2bbcd (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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
<?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.
 *
 ***************************************************************************/

if ( !empty($setmodules) )
{
	if ( !$acl->get_acl_admin('general') )
	{
		return;
	}

	$filename = basename(__FILE__);
	$module['General']['Mass_Email'] = $filename . $SID;
	
	return;
}

define('IN_PHPBB', 1);
//
// Include files
//
$phpbb_root_path = '../';
require($phpbb_root_path . 'extension.inc');
require('pagestart.' . $phpEx);

//
// Do we have general admin permissions?
//
if ( !$acl->get_acl_admin('general') )
{
	return;
}

//
// Set some vars
// 
$message = '';
$subject = '';

//
// Do the job ...
//
if ( isset($HTTP_POST_VARS['submit']) )
{
	//
	// 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);

	$group_id = intval($HTTP_POST_VARS['g']);

	$sql = ( $group_id != -1 ) ? "SELECT u.user_email FROM " . USERS_TABLE . " u, " . USER_GROUP_TABLE . " ug WHERE ug.group_id = $group_id AND ug.user_pending <> " . TRUE . " AND u.user_id = ug.user_id" : "SELECT user_email FROM " . USERS_TABLE;
	$result = $db->sql_query($sql);

	if ( !($email_list = $db->sql_fetchrowset($g_result)) )
	{
		//
		// Output a relevant GENERAL_MESSAGE about users/group
		// not existing
		//
	}

	$subject = stripslashes($HTTP_POST_VARS['subject']);
	$message = stripslashes($HTTP_POST_VARS['message']);
	
	//
	// Error checking needs to go here ... if no subject and/or
	// no message then skip over the send and return to the form
	//
	$error = FALSE;

	if ( !$error )
	{
		include($phpbb_root_path . 'includes/emailer.'.$phpEx);
		//
		// Let's do some checking to make sure that mass mail functions
		// are working in win32 versions of php.
		//
		if ( preg_match('/[c-z]:\\\.*/i', getenv('PATH')) && !$board_config['smtp_delivery'])
		{
			// We are running on windows, force delivery to use
			// our smtp functions since php's are broken by default
			$board_config['smtp_delivery'] = 1;
			$board_config['smtp_host'] = get_cfg_var('SMTP');
		}
		$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++)
		{
			$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 - ' . $user_ip . "\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();

		message_die(MESSAGE, $lang['Email_sent']);
	}
}	

//
// Initial selection
//

$sql = "SELECT group_id, group_name 
	FROM ".GROUPS_TABLE;
$result = $db->sql_query($sql);

$select_list = '<select name = "g"><option value = "-1">' . $lang['All_users'] . '</option>';
if ( $row = $db->sql_fetchrow($result) )
{
	do
	{
		$select_list .= '<option value = "' . $row['group_id'] . '">' . $row['group_name'] . '</option>';
	}
	while ( $row = $db->sql_fetchrow($result) );
}
$select_list .= '</select>';

page_header($lang['Mass_Email']);

?>

<h1><?php echo $lang['Mass_Email']; ?></h1>

<p><?php echo $lang['Mass_email_explain']; ?></p>

<form method="post" action="<?php echo "admin_mass_email.$phpEx$SID"; ?>"><table cellspacing="1" cellpadding="4" border="0" align="center" bgcolor="#98AAB1">
	<tr> 
		<th colspan="2"><?php echo $lang['Compose']; ?></th>
	</tr>
	<tr> 
		<td class="row1" align="right"><b><?php echo $lang['Recipients']; ?></b></td>
		<td class="row2" align="left"><?php echo $select_list; ?></td>
	</tr>
	<tr> 
		<td class="row1" align="right"><b><?php echo $lang['Subject']; ?></b></td>
		<td class="row2"><span class="gen"><input type="text" name="subject" size="45" maxlength="100" tabindex="2" class="post" value="<?php echo $subject; ?>" /></span></td>
	</tr>
	<tr> 
		<td class="row1" align="right" valign="top"><span class="gen"><b><?php echo $lang['Message']; ?></b></span> 
		<td class="row2"><textarea class="post" name="message" rows="15" cols="35" wrap="virtual" style="width:450px" tabindex="3"><?php echo $message; ?></textarea></td> 
	</tr>
	<tr> 
		<td class="cat" colspan="2" align="center"><input type="submit" value="<?php echo $lang['Email']; ?>" name="submit" class="mainoption" /></td>
	</tr>
</table></form>

<?php

page_footer();

?>