-
Notifications
You must be signed in to change notification settings - Fork 13
/
AP_Broadcast_Email.php
215 lines (179 loc) · 6.11 KB
/
AP_Broadcast_Email.php
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
<?php
/**
* The Broadcast Email plugin allows administrators to broadcast e-mail to all
* registered users via the administration interface.
*
* Copyright (C) 2005 Terrell Russell ([email protected])
* License: http://www.gnu.org/licenses/gpl.html GPL version 2 or higher
*/
// Make sure no one attempts to run this script "directly"
if (!defined('PUN'))
exit;
// Tell admin_loader.php that this is indeed a plugin and that it is loaded
define('PUN_PLUGIN_LOADED', 1);
// --------------------------------------------------------------------
// Confirm Page
if (isset($_POST['confirm']))
{
// Make sure message subject was entered
if (trim($_POST['message_subject']) == '')
{
// Display the admin navigation menu
generate_admin_menu($plugin);
message('You didn\'t enter a subject!');
}
// Make sure message body was entered
if (trim($_POST['message_body']) == '')
{
// Display the admin navigation menu
generate_admin_menu($plugin);
message('You didn\'t enter a message body!');
}
// Display the admin navigation menu
generate_admin_menu($plugin);
$preview_message_body = nl2br(pun_htmlspecialchars($_POST['message_body']));
$sql = "SELECT count(*) AS usercount
FROM ".$db->prefix."users
WHERE username != 'Guest'
ORDER BY username";
$result = $db->query($sql) or error('Could not get user count from database', __FILE__, __LINE__, $db->error());
$row = $db->fetch_assoc($result);
?>
<div id="exampleplugin" class="plugin blockform">
<h2><span>Broadcast Email - Confirm</span></h2>
<div class="box">
<div class="inbox">
<p>Please confirm your message below.<br /><br />If something is not correct, please <a href="javascript: history.go(-1)">Go Back</a>.</p>
</div>
</div>
</div>
<div class="blockform">
<h2 class="block2"><span>Confirm Message</span></h2>
<div class="box">
<form id="broadcastemail" method="post" action="<?php echo $_SERVER['REQUEST_URI'] ?>">
<div class="inform">
<input type="hidden" name="message_subject" value="<?php echo pun_htmlspecialchars($_POST['message_subject']) ?>" />
<input type="hidden" name="message_body" value="<?php echo pun_htmlspecialchars($_POST['message_body']) ?>" />
<fieldset>
<legend>Message Recipients</legend>
<div class="infldset">
[ <strong><?php echo $row['usercount'] ?></strong> ] Registered Users will receive this message (including the Administrator).
</div>
</fieldset>
</div>
<div class="inform">
<fieldset>
<legend>Message Contents</legend>
<div class="infldset">
<table class="aligntop" cellspacing="0">
<tr>
<th scope="row">Subject</th>
<td>
<?php echo pun_htmlspecialchars($_POST['message_subject']) ?>
</td>
</tr>
<tr>
<th scope="row">Body</th>
<td>
<?php echo $preview_message_body ?>
</td>
</tr>
</table>
<p class="submittop"><input type="submit" name="send_message" value="Confirmed - Send It." tabindex="3" /></p>
<p class="topspace">Please hit this button only once. Patience is key.</p>
</div>
</fieldset>
</div>
</form>
</div>
</div>
<?php
}
// --------------------------------------------------------------------
// Send the Message
else if (isset($_POST['send_message']))
{
require_once PUN_ROOT.'include/email.php';
// Display the admin navigation menu
generate_admin_menu($plugin);
$sql = "SELECT username, email
FROM ".$db->prefix."users
WHERE username != 'Guest'
ORDER BY username";
$result = $db->query($sql) or error('Could not get users from the database', __FILE__, __LINE__, $db->error());
while($row = $db->fetch_assoc($result))
{
$addresses[$row['username']] = $row['email'];
}
$usercount = count($addresses);
foreach ($addresses as $recipientname => $recipientemail)
{
$mail_to = $recipientname." <".$recipientemail.">";
$mail_subject = pun_htmlspecialchars($_POST['message_subject']);
$mail_message = pun_htmlspecialchars($_POST['message_body']);
pun_mail($mail_to, $mail_subject, $mail_message);
}
?>
<div id="exampleplugin" class="plugin blockform">
<h2><span>Broadcast Email - Message Sent</span></h2>
<div class="box">
<div class="inbox">
<p>The message was sent to [ <strong><?php echo $usercount ?></strong> ] Registered Users.</p>
<p>You should receive the Administrator's copy in a few moments.</p>
<p>Please use the Administrator's copy as a record of this event.</p>
</div>
</div>
</div>
<?php
}
// --------------------------------------------------------------------
// Display the Main Page
else
{
// Display the admin navigation menu
generate_admin_menu($plugin);
?>
<div id="exampleplugin" class="plugin blockform">
<h2><span>Broadcast Email</span></h2>
<div class="box">
<div class="inbox">
<p>This plugin allows the Administrator to send a Broadcast Email to all registered users.</p>
<p>There will be a confirmation page after this one - to make sure you have not made any mistakes.</p>
</div>
</div>
</div>
<div class="blockform">
<h2 class="block2"><span>Compose Message</span></h2>
<div class="box">
<form id="broadcastemail" method="post" action="<?php echo $_SERVER['REQUEST_URI'] ?>">
<div class="inform">
<fieldset>
<legend>Message Contents</legend>
<div class="infldset">
<table class="aligntop" cellspacing="0">
<tr>
<th scope="row">Subject</th>
<td>
<input type="text" name="message_subject" size="50" tabindex="1" />
</td>
</tr>
<tr>
<th scope="row">Body</th>
<td>
<textarea name="message_body" rows="14" cols="48" tabindex="2"></textarea>
</td>
</tr>
</table>
<p class="submittop">
<input type="submit" name="confirm" value="Continue to Confirmation" tabindex="3" />
</p>
</div>
</fieldset>
</div>
</form>
</div>
</div>
<?php
}
// --------------------------------------------------------------------
// Note that the script just ends here. The footer will be included by admin_loader.php.