forked from nodesman/wp-autoresponder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
all_mailouts.php
233 lines (204 loc) · 6.24 KB
/
all_mailouts.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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
<?php
function wpr_all_mailouts()
{
switch ($_GET['action'])
{
case 'edit':
_wpr_edit_mailout();
break;
case 'show_broadcast':
_wpr_show_broadcast();
break;
default:
?>
<?php
_wpr_pending_mailouts();
?>
<br />
<input type="button" class="button" value="Create Broadcast" onclick="window.location='admin.php?page=wpresponder/newmail.php';"/>
<br />
<br />
<?php
_wpr_finished_mailouts();
}
}
function _wpr_edit_mailout()
{
global $wpdb;
$id = $_GET['id'];
$query = "select * from ".$wpdb->prefix."wpr_newsletter_mailouts where id=$id and status=0";
$mailouts = $wpdb->get_results($query);
if (count($mailouts) ==0)
{
?>
This newsletter has been sent. It cannot be edited.<br />
<br />
<a href="admin.php?page=allbroadcasts" class="button">« Back </a>
<?php
return;
}
$param = $mailouts[0];
$param->htmlenabled = (empty($param->htmlbody))?0:1;
if (isset($_POST['subject']))
{
$subject = $_POST['subject'];
$nid = $_POST['newsletter'];
$textbody = trim($_POST['body']);
$htmlbody = trim($_POST['htmlbody']);
$whentosend = $_POST['whentosend'];
$date = $_POST['date'];
$attachimages = (isset($_POST['attachimages']) && $_POST['attachimages'] ==1)?1:0;
$htmlenabled = (isset($_POST['htmlenabled']) && $_POST['htmlenabled'] == "on");
$recipients = $_POST['recipients'];
$hour = $_POST['hour'];
$min = $_POST['minute'];
$id = $_POST['mid'];
if ($whentosend == "now")
$timeToSend = time();
else
{
$timeToSend = $_POST['actualTime'];
}
if (!(trim($subject) && trim($textbody)))
{
$error = "Subject and the Text Body are mandatory.";
}
if ($timeToSend < time() && !$error)
{
$error = "The time mentioned is in the past. Please enter a time in the future.";
}
if ($htmlenabled && !$error)
{
if (empty($htmlbody))
{
$error = "HTML Body is empty. Enter the HTML body of this email";
}
}
//if html body is present, it will be sent.
if (!$htmlenabled)
{
$htmlbody = "";
}
$htmlenabled = ($htmlenabled)?1:0;
if (!$error)
{
$query = "UPDATE ".$wpdb->prefix."wpr_newsletter_mailouts set subject='$subject', textbody='$textbody', htmlbody='$htmlbody',time='$timeToSend',attachimages='$attachimages',recipients='$recipients', nid='$nid' where id=$id;";
$wpdb->query($query);
_wpr_mail_sending();
return;
}
$param = (object) array("nid"=>$nid,"textbody"=>$textbody,"subject"=>$subject,"htmlbody"=>$htmlbody,"htmlenabled"=>!empty($htmlbody),"whentosend"=>$whentosend,"time"=>$timeToSend,"title"=>"New Mail","buttontext"=>"Save Broadcast");
}
wpr_mail_form($param,"new",$error);
}
function _wpr_pending_mailouts()
{
global $wpdb;
$offset = get_option('gmt_offset');
$query = "SELECT * FROM ".$wpdb->prefix."wpr_newsletter_mailouts where status=0;";
$mailouts = $wpdb->get_results($query);
?>
<script>
var delurl = '<?php bloginfo("url") ?>/?wpr-admin-action=delete_mailout';
var currentDeletion;
function deleteMailout(id)
{
currentDeletion = id;
if (window.confirm("Are you sure you want to cancel this broadcast? "))
{
jQuery.ajax({
type: "GET",
url: delurl+'&mid='+id,
cache: false,
success: removeRow
});
}
}
function removeRow()
{
var row = document.getElementById('mailout_'+currentDeletion);
par = row.parentNode;
par.removeChild(row);
}
</script>
<div class="wrap"><h2>Pending Broadcasts</h2></div>
<table class="widefat">
<tr>
<thead>
<th>Subject</th>
<th>Newsletter</th>
<th>To Be Sent at*</th>
<th>Recipients</th>
<th>Actions</th>
</thead>
</tr>
<?php
foreach ($mailouts as $mailout)
{
?>
<tr id="mailout_<?php echo $mailout->id ?>">
<td><?php echo $mailout->subject ?></td>
<td><?php $newsletter = _wpr_newsletter_get($mailout->nid);
echo $newsletter->name ?></td>
<td><?php
echo date("g:ia \o\\n dS F Y",$mailout->time + ($offset * 3600)); ?>
</td>
<td><?php $recipients = implode("<br>",explode("%set%",$mailout->recipients));
echo ($recipients)?$recipients:"All Subscribers";?></td>
<td><input type="button" value="Edit" class="button" onclick="window.location='admin.php?page=wpresponder/allmailouts.php&action=edit&id=<?php echo $mailout->id ?>';" /><input type="button" value="Cancel" class="button" onclick="deleteMailout(<?php echo $mailout->id ?>)" /></td>
</tr>
<?php
}
?>
</table>
<?php
}
function _wpr_finished_mailouts()
{
global $wpdb;
$query = "SELECT * FROM ".$wpdb->prefix."wpr_newsletter_mailouts where status=1;";
$mailouts = $wpdb->get_results($query);
$offset = get_option('gmt_offset');
?>
<div class="wrap"><h2>Sent Broadcasts</h2></div>
<table class="widefat">
<tr>
<thead>
<th>Subject</th>
<th>Newsletter</th>
<th>Sent at*</th>
<th>Recipients</th>
<th>Actions</th>
</thead>
</tr>
<?php
foreach ($mailouts as $mailout)
{
?>
<tr>
<td><?php echo $mailout->subject ?></td>
<td><?php $newsletter = _wpr_newsletter_get($mailout->nid);
echo $newsletter->name ?></td>
<td><?php echo date("g:ia d F Y",$mailout->time + ($offset * 3600)); ?></td>
<td><?php $recipients = implode("<br>",explode("%set%",$mailout->recipients));
echo ($recipients)?$recipients:"All Subscribers";
?></td>
<td><a href="<?php echo $_SERVER['REQUEST_URI']?>&action=show_broadcast&id=<?php echo $mailout->id ?>" class="button" style="margin:10px; margin-top:20px;" >View Broadcast</a></td>
</tr>
<?php
}
?>
</table>
<br />
* Time is approximate. Actual send time depends on the frequency you set for the wordpress cron job or amount of traffic you get.
<?php
}
function _wpr_show_broadcast()
{
global $wpdb;
$id = $_GET['id'];
require "viewbroadcast.php";
// $query = "SELECT * FROM ".$wpdb->prefix."wpr_newsletter_mailouts where id=$";
?>
<?php
}