-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathemail-manager.php
358 lines (333 loc) · 14 KB
/
email-manager.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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
<?php
### Check Whether User Can Manage EMail
if ( ! current_user_can( 'manage_email' ) ) {
die('Access Denied');
}
### Check Nonce
if ( ! empty( $_GET['by'] ) || ! empty( $_GET['order'] ) || ! empty( $_GET['perpage'] )) {
check_admin_referer( 'wp-email_sort' );
}
### E-Mail Variables
$base_name = plugin_basename( 'wp-email/email-manager.php') ;
$base_page = 'admin.php?page='.$base_name;
$email_page = empty( $_GET['emailpage'] )? 1 : max((int) $_GET['emailpage'], 1);
$email_sortby = empty( $_GET['by'] )? '' : sanitize_key( $_GET['by'] );
$email_sortby_text = '';
$email_sortorder = empty( $_GET['order'] )? 'DESC': sanitize_key( $_GET['order'] );
$email_sortorder_text = '';
$email_log_perpage = ( empty($_GET['perpage'] ) || (int) $_GET['perpage'] < 1 ) ? 20 : (int) $_GET['perpage'];
$email_sort_url = '';
### Form Sorting URL
if ( ! empty($email_sortby ) ) {
$email_sort_url .= '&by=' . $email_sortby;
}
if ( ! empty( $email_sortorder ) ) {
$email_sort_url .= '&order=' . $email_sortorder;
}
if ( ! empty( $email_log_perpage ) ) {
$email_sort_url .= '&perpage=' . $email_log_perpage;
}
### Get Order By
switch($email_sortby) {
case 'id':
$email_sortby = 'email_id';
$email_sortby_text = __('ID', 'wp-email');
break;
case 'fromname':
$email_sortby = 'email_yourname';
$email_sortby_text = __('From Name', 'wp-email');
break;
case 'fromemail':
$email_sortby = 'email_youremail';
$email_sortby_text = __('From E-Mail', 'wp-email');
break;
case 'toname':
$email_sortby = 'email_friendname';
$email_sortby_text = __('To Name', 'wp-email');
break;
case 'toemail':
$email_sortby = 'email_friendemail';
$email_sortby_text = __('To E-Mail', 'wp-email');
break;
case 'postid':
$email_sortby = 'email_postid';
$email_sortby_text = __('Post ID', 'wp-email');
break;
case 'posttitle':
$email_sortby = 'email_posttitle';
$email_sortby_text = __('Post Title', 'wp-email');
break;
case 'ip':
$email_sortby = 'email_ip';
$email_sortby_text = __('IP', 'wp-email');
break;
case 'host':
$email_sortby = 'email_host';
$email_sortby_text = __('Host', 'wp-email');
break;
case 'status':
$email_sortby = 'email_status';
$email_sortby_text = __('Status', 'wp-email');
break;
case 'date':
default:
$email_sortby = 'email_timestamp';
$email_sortby_text = __('Date', 'wp-email');
}
### Get Sort Order
switch($email_sortorder) {
case 'asc':
$email_sortorder = 'ASC';
$email_sortorder_text = __('Ascending', 'wp-email');
break;
case 'desc':
default:
$email_sortorder = 'DESC';
$email_sortorder_text = __('Descending', 'wp-email');
}
### Form Processing
if ( ! empty( $_POST['delete_logs'] ) ) {
check_admin_referer( 'wp-email_delete-logs' );
if( trim( $_POST['delete_logs_yes'] ) === 'yes' ) {
$delete_logs = $wpdb->query( "DELETE FROM $wpdb->email" );
if( $delete_logs ) {
$text = '<p style="color: green;">'.__('All E-Mail Logs Have Been Deleted.', 'wp-email').'</p>';
} else {
$text = '<p style="color: red;">'.__('An Error Has Occured While Deleting All E-Mail Logs.', 'wp-email').'</p>';
}
}
}
### Get E-Mail Logs Data
$total_email_success = $wpdb->get_var("SELECT COUNT(email_id) FROM $wpdb->email WHERE email_status = '".__('Success', 'wp-email')."'");
$total_email_failed = $wpdb->get_var("SELECT COUNT(email_id) FROM $wpdb->email WHERE email_status = '".__('Failed', 'wp-email')."'");
$total_email = $total_email_success+$total_email_failed;
### Checking $email_page and $offset
//if(empty($email_page) || $email_page == 0) { $email_page = 1; }
//if(empty($offset)) { $offset = 0; }
//if(empty($email_log_perpage) || $email_log_perpage == 0) { $email_log_perpage = 20; }
### Determin $offset
$offset = ($email_page-1) * $email_log_perpage;
### Determine Max Number Of Polls To Display On Page
if(($offset + $email_log_perpage) > $total_email) {
$max_on_page = $total_email;
} else {
$max_on_page = ($offset + $email_log_perpage);
}
### Determine Number Of Polls To Display On Page
if (($offset + 1) > ($total_email)) {
$display_on_page = $total_email;
} else {
$display_on_page = ($offset + 1);
}
### Determing Total Amount Of Pages
$total_pages = ceil($total_email / $email_log_perpage);
### Get The Logs
$email_logs = $wpdb->get_results("SELECT * FROM $wpdb->email ORDER BY $email_sortby $email_sortorder LIMIT $offset, $email_log_perpage");
?>
<?php if(!empty($text)) { echo '<!-- Last Action --><div id="message" class="updated fade"><p>'.$text.'</p></div>'; } ?>
<!-- Manage E-Mail -->
<div class="wrap">
<h2><?php _e('Manage E-Mail', 'wp-email'); ?></h2>
<h3><?php _e('E-Mail Logs', 'wp-email'); ?></h3>
<p><?php printf(__('Displaying <strong>%s</strong> To <strong>%s</strong> Of <strong>%s</strong> E-Mail Logs', 'wp-email'), number_format_i18n($display_on_page), number_format_i18n($max_on_page), number_format_i18n($total_email)); ?></p>
<p><?php printf(__('Sorted By <strong>%s</strong> In <strong>%s</strong> Order', 'wp-email'), $email_sortby_text, $email_sortorder_text); ?></p>
<?php
$colspan = 7;
if(EMAIL_SHOW_REMARKS) {
$colspan++;
}
?>
<table class="widefat">
<thead>
<tr>
<th><?php _e('ID', 'wp-email'); ?></th>
<th><?php _e('From', 'wp-email'); ?></th>
<th><?php _e('To', 'wp-email'); ?></th>
<th><?php _e('Date / Time', 'wp-email'); ?></th>
<th><?php _e('IP / Host', 'wp-email'); ?></th>
<?php
if(EMAIL_SHOW_REMARKS) {
echo '<th>'.__('Remarks', 'wp-email').'</th>';
}
?>
<th><?php _e('Post Title', 'wp-email'); ?></th>
<th><?php _e('Status', 'wp-email'); ?></th>
</tr>
</thead>
<?php
if($email_logs) {
$i = 0;
foreach($email_logs as $email_log) {
if($i%2 == 0) {
$style = '';
} else {
$style = 'class="alternate"';
}
$email_id = (int) $email_log->email_id;
$email_yourname = stripslashes($email_log->email_yourname);
$email_youremail = stripslashes($email_log->email_youremail);
$email_friendname = stripslashes($email_log->email_friendname);
$email_friendemail = stripslashes($email_log->email_friendemail);
$email_postid = (int) $email_log->email_postid;
$email_remarks = htmlspecialchars(stripslashes($email_log->email_yourremarks));
$email_posttitle = htmlspecialchars(stripslashes($email_log->email_posttitle));
$email_date = mysql2date(sprintf(__('%s @ %s', 'wp-email'), get_option('date_format'), get_option('time_format')), gmdate('Y-m-d H:i:s', $email_log->email_timestamp));
$email_ip = $email_log->email_ip;
$email_host = $email_log->email_host;
$email_status = stripslashes($email_log->email_status);
echo "<tr $style>\n";
echo "<td>".number_format_i18n($email_id)."</td>\n";
echo "<td>$email_yourname<br />$email_youremail</td>\n";
echo "<td>$email_friendname<br />$email_friendemail</td>\n";
echo "<td>$email_date</td>\n";
echo "<td>$email_ip<br />$email_host</td>\n";
if(EMAIL_SHOW_REMARKS) {
echo '<td>'.$email_remarks.'</td>';
}
echo "<td>$email_posttitle</td>\n";
echo "<td>$email_status</td>\n";
echo '</tr>';
$i++;
}
} else {
echo '<tr><td colspan="'.$colspan.'" align="center"><strong>'.__('No E-Mail Logs Found', 'wp-email').'</strong></td></tr>';
}
?>
</table>
<!-- <Paging> -->
<?php
if($total_pages > 1) {
?>
<br />
<table class="widefat">
<tr>
<td align="<?php echo ( is_rtl() ) ? 'right' : 'left'; ?>" width="50%">
<?php
if($email_page > 1 && ((($email_page*$email_log_perpage)-($email_log_perpage-1)) <= $total_email)) {
echo '<strong>«</strong> <a href="'.$base_page.'&emailpage='.($email_page-1).$email_sort_url.'" title="« '.__('Previous Page', 'wp-email').'">'.__('Previous Page', 'wp-email').'</a>';
} else {
echo ' ';
}
?>
</td>
<td align="<?php echo ( is_rtl() ) ? 'left' : 'right'; ?>" width="50%">
<?php
if($email_page >= 1 && ((($email_page*$email_log_perpage)+1) <= $total_email)) {
echo '<a href="'.$base_page.'&emailpage='.($email_page+1).$email_sort_url.'" title="'.__('Next Page', 'wp-email').' »">'.__('Next Page', 'wp-email').'</a> <strong>»</strong>';
} else {
echo ' ';
}
?>
</td>
</tr>
<tr class="alternate">
<td colspan="2" align="center">
<?php printf(__('Pages (%s): ', 'wp-postratings'), number_format_i18n($total_pages)); ?>
<?php
if ($email_page >= 4) {
echo '<strong><a href="'.$base_page.'&emailpage=1'.$email_sort_url.'" title="'.__('Go to First Page', 'wp-email').'">« '.__('First', 'wp-email').'</a></strong> ... ';
}
if($email_page > 1) {
echo ' <strong><a href="'.$base_page.'&emailpage='.($email_page-1).$email_sort_url.'" title="« '.__('Go to Page', 'wp-email').' '.number_format_i18n($email_page-1).'">«</a></strong> ';
}
for($i = $email_page - 2 ; $i <= $email_page +2; $i++) {
if ($i >= 1 && $i <= $total_pages) {
if($i == $email_page) {
echo '<strong>['.number_format_i18n($i).']</strong> ';
} else {
echo '<a href="'.$base_page.'&emailpage='.($i).$email_sort_url.'" title="'.__('Page', 'wp-email').' '.number_format_i18n($i).'">'.number_format_i18n($i).'</a> ';
}
}
}
if($email_page < $total_pages) {
echo ' <strong><a href="'.$base_page.'&emailpage='.($email_page+1).$email_sort_url.'" title="'.__('Go to Page', 'wp-email').' '.number_format_i18n($email_page+1).' »">»</a></strong> ';
}
if (($email_page+2) < $total_pages) {
echo ' ... <strong><a href="'.$base_page.'&emailpage='.($total_pages).$email_sort_url.'" title="'.__('Go to Last Page', 'wp-email'), 'wp-email'.'">'.__('Last', 'wp-email').' »</a></strong>';
}
?>
</td>
</tr>
</table>
<!-- </Paging> -->
<?php
}
?>
<br />
<form action="<?php echo admin_url('admin.php?page='.plugin_basename(__FILE__)); ?>" method="get">
<?php wp_nonce_field( 'wp-email_sort' ); ?>
<table class="widefat">
<tr>
<td>
<input type="hidden" name="page" value="<?php echo $base_name; ?>" />
<?php _e('Sort Options:', 'wp-email'); ?>
<select name="by" size="1">
<option value="id"<?php if($email_sortby == 'email_id') { echo ' selected="selected"'; }?>><?php _e('ID', 'wp-email'); ?></option>
<option value="fromname"<?php if($email_sortby == 'email_yourname') { echo ' selected="selected"'; }?>><?php _e('From Name', 'wp-email'); ?></option>
<option value="fromemail"<?php if($email_sortby == 'email_youremail') { echo ' selected="selected"'; }?>><?php _e('From E-Mail', 'wp-email'); ?></option>
<option value="toname"<?php if($email_sortby == 'email_friendname') { echo ' selected="selected"'; }?>><?php _e('To Name', 'wp-email'); ?></option>
<option value="toemail"<?php if($email_sortby == 'email_friendemail') { echo ' selected="selected"'; }?>><?php _e('To E-Mail', 'wp-email'); ?></option>
<option value="date"<?php if($email_sortby == 'email_timestamp') { echo ' selected="selected"'; }?>><?php _e('Date', 'wp-email'); ?></option>
<option value="postid"<?php if($email_sortby == 'email_postid') { echo ' selected="selected"'; }?>><?php _e('Post ID', 'wp-email'); ?></option>
<option value="posttitle"<?php if($email_sortby == 'email_posttitle') { echo ' selected="selected"'; }?>><?php _e('Post Title', 'wp-email'); ?></option>
<option value="ip"<?php if($email_sortby == 'email_ip') { echo ' selected="selected"'; }?>><?php _e('IP', 'wp-email'); ?></option>
<option value="host"<?php if($email_sortby == 'email_host') { echo ' selected="selected"'; }?>><?php _e('Host', 'wp-email'); ?></option>
<option value="status"<?php if($email_sortby == 'email_status') { echo ' selected="selected"'; }?>><?php _e('Status', 'wp-email'); ?></option>
</select>
<select name="order" size="1">
<option value="asc"<?php if($email_sortorder == 'ASC') { echo ' selected="selected"'; }?>><?php _e('Ascending', 'wp-email'); ?></option>
<option value="desc"<?php if($email_sortorder == 'DESC') { echo ' selected="selected"'; } ?>><?php _e('Descending', 'wp-email'); ?></option>
</select>
<select name="perpage" size="1">
<?php
for($i=10; $i <= 100; $i+=10) {
if($email_log_perpage == $i) {
echo "<option value=\"$i\" selected=\"selected\">".__('Per Page', 'wp-email').": ".number_format_i18n($i)."</option>\n";
} else {
echo "<option value=\"$i\">".__('Per Page', 'wp-email').": ".number_format_i18n($i)."</option>\n";
}
}
?>
</select>
<input type="submit" value="<?php _e('Sort', 'wp-email'); ?>" class="button" />
</td>
</tr>
</table>
</form>
</div>
<p> </p>
<!-- E-Mail Stats -->
<div class="wrap">
<h3><?php _e('E-Mail Logs Stats', 'wp-email'); ?></h3>
<br style="clear" />
<table class="widefat">
<tr>
<th><?php _e('Total E-Mails:', 'wp-email'); ?></th>
<td><?php echo number_format_i18n($total_email); ?></td>
</tr>
<tr class="alternate">
<th><?php _e('Total E-Mail Sent:', 'wp-email'); ?></th>
<td><?php echo number_format_i18n($total_email_success); ?></td>
</tr>
<tr>
<th><?php _e('Total E-Mail Failed:', 'wp-email'); ?></th>
<td><?php echo number_format_i18n($total_email_failed); ?></td>
</tr>
</table>
</div>
<p> </p>
<!-- Delete E-Mail Logs -->
<div class="wrap">
<h3><?php _e('Delete E-Mail Logs', 'wp-email'); ?></h3>
<br style="clear" />
<div align="center">
<form method="post" action="<?php echo admin_url('admin.php?page='.plugin_basename(__FILE__)); ?>">
<?php wp_nonce_field('wp-email_delete-logs'); ?>
<strong><?php _e('Are You Sure You Want To Delete All E-Mail Logs?', 'wp-email'); ?></strong><br /><br />
<input type="checkbox" name="delete_logs_yes" value="yes" /> <?php _e('Yes', 'wp-email'); ?><br /><br />
<input type="submit" name="delete_logs" value="<?php _e('Delete', 'wp-email'); ?>" class="button" onclick="return confirm('<?php _e('You Are About To Delete All E-Mail Logs\nThis Action Is Not Reversible.\n\n Choose [Cancel] to stop, [OK] to delete.', 'wp-email'); ?>')" />
</form>
</div>
</div>