| 1 |
<?php |
| 2 |
/** |
| 3 |
* WordPress Plugin: WP-EMail |
| 4 |
* Copyright (c) 2012 Lester "GaMerZ" Chan |
| 5 |
* |
| 6 |
* File Written By: |
| 7 |
* - Lester "GaMerZ" Chan |
| 8 |
* - http://lesterchan.net |
| 9 |
* |
| 10 |
* File Information: |
| 11 |
* - Manages Your E-Mail Logs |
| 12 |
* - wp-content/plugins/wp-email/email-manager.php |
| 13 |
*/ |
| 14 |
|
| 15 |
|
| 16 |
### Check Whether User Can Manage EMail |
| 17 |
if(!current_user_can('manage_email')) { |
| 18 |
die('Access Denied'); |
| 19 |
} |
| 20 |
|
| 21 |
|
| 22 |
### E-Mail Variables |
| 23 |
$base_name = plugin_basename('wp-email/email-manager.php'); |
| 24 |
$base_page = 'admin.php?page='.$base_name; |
| 25 |
$email_page = empty($_GET['emailpage'])? 1 : max(intval($_GET['emailpage']), 1); |
| 26 |
$email_sortby = empty($_GET['by'])? '' : trim($_GET['by']); |
| 27 |
$email_sortby_text = ''; |
| 28 |
$email_sortorder = empty($_GET['order'])? 'DESC':trim($_GET['order']); |
| 29 |
$email_sortorder_text = ''; |
| 30 |
$email_log_perpage = (empty($_GET['perpage']) || intval($_GET['perpage']) < 1)? 20 : intval($_GET['perpage']); |
| 31 |
$email_sort_url = ''; |
| 32 |
|
| 33 |
|
| 34 |
### Form Sorting URL |
| 35 |
if(!empty($email_sortby)) { |
| 36 |
$email_sort_url .= '&by='.$email_sortby; |
| 37 |
} |
| 38 |
if(!empty($email_sortorder)) { |
| 39 |
$email_sort_url .= '&order='.$email_sortorder; |
| 40 |
} |
| 41 |
if(!empty($email_log_perpage)) { |
| 42 |
$email_sort_url .= '&perpage='.$email_log_perpage; |
| 43 |
} |
| 44 |
|
| 45 |
|
| 46 |
### Get Order By |
| 47 |
switch($email_sortby) { |
| 48 |
case 'id': |
| 49 |
$email_sortby = 'email_id'; |
| 50 |
$email_sortby_text = __('ID', 'wp-email'); |
| 51 |
break; |
| 52 |
case 'fromname': |
| 53 |
$email_sortby = 'email_yourname'; |
| 54 |
$email_sortby_text = __('From Name', 'wp-email'); |
| 55 |
break; |
| 56 |
case 'fromemail': |
| 57 |
$email_sortby = 'email_youremail'; |
| 58 |
$email_sortby_text = __('From E-Mail', 'wp-email'); |
| 59 |
break; |
| 60 |
case 'toname': |
| 61 |
$email_sortby = 'email_friendname'; |
| 62 |
$email_sortby_text = __('To Name', 'wp-email'); |
| 63 |
break; |
| 64 |
case 'toemail': |
| 65 |
$email_sortby = 'email_friendemail'; |
| 66 |
$email_sortby_text = __('To E-Mail', 'wp-email'); |
| 67 |
break; |
| 68 |
case 'postid': |
| 69 |
$email_sortby = 'email_postid'; |
| 70 |
$email_sortby_text = __('Post ID', 'wp-email'); |
| 71 |
break; |
| 72 |
case 'posttitle': |
| 73 |
$email_sortby = 'email_posttitle'; |
| 74 |
$email_sortby_text = __('Post Title', 'wp-email'); |
| 75 |
break; |
| 76 |
case 'ip': |
| 77 |
$email_sortby = 'email_ip'; |
| 78 |
$email_sortby_text = __('IP', 'wp-email'); |
| 79 |
break; |
| 80 |
case 'host': |
| 81 |
$email_sortby = 'email_host'; |
| 82 |
$email_sortby_text = __('Host', 'wp-email'); |
| 83 |
break; |
| 84 |
case 'status': |
| 85 |
$email_sortby = 'email_status'; |
| 86 |
$email_sortby_text = __('Status', 'wp-email'); |
| 87 |
break; |
| 88 |
case 'date': |
| 89 |
default: |
| 90 |
$email_sortby = 'email_timestamp'; |
| 91 |
$email_sortby_text = __('Date', 'wp-email'); |
| 92 |
} |
| 93 |
|
| 94 |
|
| 95 |
### Get Sort Order |
| 96 |
switch($email_sortorder) { |
| 97 |
case 'asc': |
| 98 |
$email_sortorder = 'ASC'; |
| 99 |
$email_sortorder_text = __('Ascending', 'wp-email'); |
| 100 |
break; |
| 101 |
case 'desc': |
| 102 |
default: |
| 103 |
$email_sortorder = 'DESC'; |
| 104 |
$email_sortorder_text = __('Descending', 'wp-email'); |
| 105 |
} |
| 106 |
|
| 107 |
|
| 108 |
### Form Processing |
| 109 |
if(!empty($_POST['delete_logs'])) { |
| 110 |
if(trim($_POST['delete_logs_yes']) == 'yes') { |
| 111 |
$delete_logs = $wpdb->query("DELETE FROM $wpdb->email"); |
| 112 |
if($delete_logs) { |
| 113 |
$text = '<p style="color: green;">'.__('All E-Mail Logs Have Been Deleted.', 'wp-email').'</p>'; |
| 114 |
} else { |
| 115 |
$text = '<p style="color: red;">'.__('An Error Has Occured While Deleting All E-Mail Logs.', 'wp-email').'</p>'; |
| 116 |
} |
| 117 |
} |
| 118 |
} |
| 119 |
|
| 120 |
|
| 121 |
### Get E-Mail Logs Data |
| 122 |
$total_email_success = $wpdb->get_var("SELECT COUNT(email_id) FROM $wpdb->email WHERE email_status = '".__('Success', 'wp-email')."'"); |
| 123 |
$total_email_failed = $wpdb->get_var("SELECT COUNT(email_id) FROM $wpdb->email WHERE email_status = '".__('Failed', 'wp-email')."'"); |
| 124 |
$total_email = $total_email_success+$total_email_failed; |
| 125 |
|
| 126 |
|
| 127 |
### Checking $email_page and $offset |
| 128 |
//if(empty($email_page) || $email_page == 0) { $email_page = 1; } |
| 129 |
//if(empty($offset)) { $offset = 0; } |
| 130 |
//if(empty($email_log_perpage) || $email_log_perpage == 0) { $email_log_perpage = 20; } |
| 131 |
|
| 132 |
|
| 133 |
### Determin $offset |
| 134 |
$offset = ($email_page-1) * $email_log_perpage; |
| 135 |
|
| 136 |
|
| 137 |
### Determine Max Number Of Polls To Display On Page |
| 138 |
if(($offset + $email_log_perpage) > $total_email) { |
| 139 |
$max_on_page = $total_email; |
| 140 |
} else { |
| 141 |
$max_on_page = ($offset + $email_log_perpage); |
| 142 |
} |
| 143 |
|
| 144 |
|
| 145 |
### Determine Number Of Polls To Display On Page |
| 146 |
if (($offset + 1) > ($total_email)) { |
| 147 |
$display_on_page = $total_email; |
| 148 |
} else { |
| 149 |
$display_on_page = ($offset + 1); |
| 150 |
} |
| 151 |
|
| 152 |
### Determing Total Amount Of Pages |
| 153 |
$total_pages = ceil($total_email / $email_log_perpage); |
| 154 |
|
| 155 |
|
| 156 |
### Get The Logs |
| 157 |
$email_logs = $wpdb->get_results("SELECT * FROM $wpdb->email ORDER BY $email_sortby $email_sortorder LIMIT $offset, $email_log_perpage"); |
| 158 |
?> |
| 159 |
<?php if(!empty($text)) { echo '<!-- Last Action --><div id="message" class="updated fade"><p>'.$text.'</p></div>'; } ?> |
| 160 |
<!-- Manage E-Mail --> |
| 161 |
<div class="wrap"> |
| 162 |
<h2><?php _e('Manage E-Mail', 'wp-email'); ?></h2> |
| 163 |
<h3><?php _e('E-Mail Logs', 'wp-email'); ?></h3> |
| 164 |
<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> |
| 165 |
<p><?php printf(__('Sorted By <strong>%s</strong> In <strong>%s</strong> Order', 'wp-email'), $email_sortby_text, $email_sortorder_text); ?></p> |
| 166 |
<?php |
| 167 |
$colspan = 7; |
| 168 |
if(EMAIL_SHOW_REMARKS) { |
| 169 |
$colspan++; |
| 170 |
} |
| 171 |
?> |
| 172 |
<table class="widefat"> |
| 173 |
<thead> |
| 174 |
<tr> |
| 175 |
<th><?php _e('ID', 'wp-email'); ?></th> |
| 176 |
<th><?php _e('From', 'wp-email'); ?></th> |
| 177 |
<th><?php _e('To', 'wp-email'); ?></th> |
| 178 |
<th><?php _e('Date / Time', 'wp-email'); ?></th> |
| 179 |
<th><?php _e('IP / Host', 'wp-email'); ?></th> |
| 180 |
<?php |
| 181 |
if(EMAIL_SHOW_REMARKS) { |
| 182 |
echo '<th>'.__('Remarks', 'wp-email').'</th>'; |
| 183 |
} |
| 184 |
?> |
| 185 |
<th><?php _e('Post Title', 'wp-email'); ?></th> |
| 186 |
<th><?php _e('Status', 'wp-email'); ?></th> |
| 187 |
</tr> |
| 188 |
</thead> |
| 189 |
<?php |
| 190 |
if($email_logs) { |
| 191 |
$i = 0; |
| 192 |
foreach($email_logs as $email_log) { |
| 193 |
if($i%2 == 0) { |
| 194 |
$style = ''; |
| 195 |
} else { |
| 196 |
$style = 'class="alternate"'; |
| 197 |
} |
| 198 |
$email_id = intval($email_log->email_id); |
| 199 |
$email_yourname = stripslashes($email_log->email_yourname); |
| 200 |
$email_youremail = stripslashes($email_log->email_youremail); |
| 201 |
$email_friendname = stripslashes($email_log->email_friendname); |
| 202 |
$email_friendemail = stripslashes($email_log->email_friendemail); |
| 203 |
$email_postid = intval($email_log->email_postid); |
| 204 |
$email_remarks = htmlspecialchars(stripslashes($email_log->email_yourremarks)); |
| 205 |
$email_posttitle = htmlspecialchars(stripslashes($email_log->email_posttitle)); |
| 206 |
$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)); |
| 207 |
$email_ip = $email_log->email_ip; |
| 208 |
$email_host = $email_log->email_host; |
| 209 |
$email_status = stripslashes($email_log->email_status); |
| 210 |
echo "<tr $style>\n"; |
| 211 |
echo "<td>".number_format_i18n($email_id)."</td>\n"; |
| 212 |
echo "<td>$email_yourname<br />$email_youremail</td>\n"; |
| 213 |
echo "<td>$email_friendname<br />$email_friendemail</td>\n"; |
| 214 |
echo "<td>$email_date</td>\n"; |
| 215 |
echo "<td>$email_ip<br />$email_host</td>\n"; |
| 216 |
if(EMAIL_SHOW_REMARKS) { |
| 217 |
echo '<td>'.$email_remarks.'</td>'; |
| 218 |
} |
| 219 |
echo "<td>$email_posttitle</td>\n"; |
| 220 |
echo "<td>$email_status</td>\n"; |
| 221 |
echo '</tr>'; |
| 222 |
$i++; |
| 223 |
} |
| 224 |
} else { |
| 225 |
echo '<tr><td colspan="'.$colspan.'" align="center"><strong>'.__('No E-Mail Logs Found', 'wp-email').'</strong></td></tr>'; |
| 226 |
} |
| 227 |
?> |
| 228 |
</table> |
| 229 |
<!-- <Paging> --> |
| 230 |
<?php |
| 231 |
if($total_pages > 1) { |
| 232 |
?> |
| 233 |
<br /> |
| 234 |
<table class="widefat"> |
| 235 |
<tr> |
| 236 |
<td align="<?php echo ('rtl' == $text_direction) ? 'right' : 'left'; ?>" width="50%"> |
| 237 |
<?php |
| 238 |
if($email_page > 1 && ((($email_page*$email_log_perpage)-($email_log_perpage-1)) <= $total_email)) { |
| 239 |
echo '<strong>«</strong> <a href="'.$base_page.'&emailpage='.($email_page-1).$email_sort_url.'" title="« '.__('Previous Page', 'wp-email').'">'.__('Previous Page', 'wp-email').'</a>'; |
| 240 |
} else { |
| 241 |
echo ' '; |
| 242 |
} |
| 243 |
?> |
| 244 |
</td> |
| 245 |
<td align="<?php echo ('rtl' == $text_direction) ? 'left' : 'right'; ?>" width="50%"> |
| 246 |
<?php |
| 247 |
if($email_page >= 1 && ((($email_page*$email_log_perpage)+1) <= $total_email)) { |
| 248 |
echo '<a href="'.$base_page.'&emailpage='.($email_page+1).$email_sort_url.'" title="'.__('Next Page', 'wp-email').' »">'.__('Next Page', 'wp-email').'</a> <strong>»</strong>'; |
| 249 |
} else { |
| 250 |
echo ' '; |
| 251 |
} |
| 252 |
?> |
| 253 |
</td> |
| 254 |
</tr> |
| 255 |
<tr class="alternate"> |
| 256 |
<td colspan="2" align="center"> |
| 257 |
<?php printf(__('Pages (%s): ', 'wp-postratings'), number_format_i18n($total_pages)); ?> |
| 258 |
<?php |
| 259 |
if ($email_page >= 4) { |
| 260 |
echo '<strong><a href="'.$base_page.'&emailpage=1'.$email_sort_url.'" title="'.__('Go to First Page', 'wp-email').'">« '.__('First', 'wp-email').'</a></strong> ... '; |
| 261 |
} |
| 262 |
if($email_page > 1) { |
| 263 |
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> '; |
| 264 |
} |
| 265 |
for($i = $email_page - 2 ; $i <= $email_page +2; $i++) { |
| 266 |
if ($i >= 1 && $i <= $total_pages) { |
| 267 |
if($i == $email_page) { |
| 268 |
echo '<strong>['.number_format_i18n($i).']</strong> '; |
| 269 |
} else { |
| 270 |
echo '<a href="'.$base_page.'&emailpage='.($i).$email_sort_url.'" title="'.__('Page', 'wp-email').' '.number_format_i18n($i).'">'.number_format_i18n($i).'</a> '; |
| 271 |
} |
| 272 |
} |
| 273 |
} |
| 274 |
if($email_page < $total_pages) { |
| 275 |
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> '; |
| 276 |
} |
| 277 |
if (($email_page+2) < $total_pages) { |
| 278 |
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>'; |
| 279 |
} |
| 280 |
?> |
| 281 |
</td> |
| 282 |
</tr> |
| 283 |
</table> |
| 284 |
<!-- </Paging> --> |
| 285 |
<?php |
| 286 |
} |
| 287 |
?> |
| 288 |
<br /> |
| 289 |
<form action="<?php echo admin_url('admin.php?page='.plugin_basename(__FILE__)); ?>" method="get"> |
| 290 |
<table class="widefat"> |
| 291 |
<tr> |
| 292 |
<td> |
| 293 |
<input type="hidden" name="page" value="<?php echo $base_name; ?>" /> |
| 294 |
<?php _e('Sort Options:', 'wp-email'); ?> |
| 295 |
<select name="by" size="1"> |
| 296 |
<option value="id"<?php if($email_sortby == 'email_id') { echo ' selected="selected"'; }?>><?php _e('ID', 'wp-email'); ?></option> |
| 297 |
<option value="fromname"<?php if($email_sortby == 'email_yourname') { echo ' selected="selected"'; }?>><?php _e('From Name', 'wp-email'); ?></option> |
| 298 |
<option value="fromemail"<?php if($email_sortby == 'email_youremail') { echo ' selected="selected"'; }?>><?php _e('From E-Mail', 'wp-email'); ?></option> |
| 299 |
<option value="toname"<?php if($email_sortby == 'email_friendname') { echo ' selected="selected"'; }?>><?php _e('To Name', 'wp-email'); ?></option> |
| 300 |
<option value="toemail"<?php if($email_sortby == 'email_friendemail') { echo ' selected="selected"'; }?>><?php _e('To E-Mail', 'wp-email'); ?></option> |
| 301 |
<option value="date"<?php if($email_sortby == 'email_timestamp') { echo ' selected="selected"'; }?>><?php _e('Date', 'wp-email'); ?></option> |
| 302 |
<option value="postid"<?php if($email_sortby == 'email_postid') { echo ' selected="selected"'; }?>><?php _e('Post ID', 'wp-email'); ?></option> |
| 303 |
<option value="posttitle"<?php if($email_sortby == 'email_posttitle') { echo ' selected="selected"'; }?>><?php _e('Post Title', 'wp-email'); ?></option> |
| 304 |
<option value="ip"<?php if($email_sortby == 'email_ip') { echo ' selected="selected"'; }?>><?php _e('IP', 'wp-email'); ?></option> |
| 305 |
<option value="host"<?php if($email_sortby == 'email_host') { echo ' selected="selected"'; }?>><?php _e('Host', 'wp-email'); ?></option> |
| 306 |
<option value="status"<?php if($email_sortby == 'email_status') { echo ' selected="selected"'; }?>><?php _e('Status', 'wp-email'); ?></option> |
| 307 |
</select> |
| 308 |
|
| 309 |
<select name="order" size="1"> |
| 310 |
<option value="asc"<?php if($email_sortorder == 'ASC') { echo ' selected="selected"'; }?>><?php _e('Ascending', 'wp-email'); ?></option> |
| 311 |
<option value="desc"<?php if($email_sortorder == 'DESC') { echo ' selected="selected"'; } ?>><?php _e('Descending', 'wp-email'); ?></option> |
| 312 |
</select> |
| 313 |
|
| 314 |
<select name="perpage" size="1"> |
| 315 |
<?php |
| 316 |
for($i=10; $i <= 100; $i+=10) { |
| 317 |
if($email_log_perpage == $i) { |
| 318 |
echo "<option value=\"$i\" selected=\"selected\">".__('Per Page', 'wp-email').": ".number_format_i18n($i)."</option>\n"; |
| 319 |
} else { |
| 320 |
echo "<option value=\"$i\">".__('Per Page', 'wp-email').": ".number_format_i18n($i)."</option>\n"; |
| 321 |
} |
| 322 |
} |
| 323 |
?> |
| 324 |
</select> |
| 325 |
<input type="submit" value="<?php _e('Sort', 'wp-email'); ?>" class="button" /> |
| 326 |
</td> |
| 327 |
</tr> |
| 328 |
</table> |
| 329 |
</form> |
| 330 |
</div> |
| 331 |
<p> </p> |
| 332 |
|
| 333 |
<!-- E-Mail Stats --> |
| 334 |
<div class="wrap"> |
| 335 |
<h3><?php _e('E-Mail Logs Stats', 'wp-email'); ?></h3> |
| 336 |
<br style="clear" /> |
| 337 |
<table class="widefat"> |
| 338 |
<tr> |
| 339 |
<th><?php _e('Total E-Mails:', 'wp-email'); ?></th> |
| 340 |
<td><?php echo number_format_i18n($total_email); ?></td> |
| 341 |
</tr> |
| 342 |
<tr class="alternate"> |
| 343 |
<th><?php _e('Total E-Mail Sent:', 'wp-email'); ?></th> |
| 344 |
<td><?php echo number_format_i18n($total_email_success); ?></td> |
| 345 |
</tr> |
| 346 |
<tr> |
| 347 |
<th><?php _e('Total E-Mail Failed:', 'wp-email'); ?></th> |
| 348 |
<td><?php echo number_format_i18n($total_email_failed); ?></td> |
| 349 |
</tr> |
| 350 |
</table> |
| 351 |
</div> |
| 352 |
<p> </p> |
| 353 |
|
| 354 |
<!-- Delete E-Mail Logs --> |
| 355 |
<div class="wrap"> |
| 356 |
<h3><?php _e('Delete E-Mail Logs', 'wp-email'); ?></h3> |
| 357 |
<br style="clear" /> |
| 358 |
<div align="center"> |
| 359 |
<form method="post" action="<?php echo admin_url('admin.php?page='.plugin_basename(__FILE__)); ?>"> |
| 360 |
<strong><?php _e('Are You Sure You Want To Delete All E-Mail Logs?', 'wp-email'); ?></strong><br /><br /> |
| 361 |
<input type="checkbox" name="delete_logs_yes" value="yes" /> <?php _e('Yes', 'wp-email'); ?><br /><br /> |
| 362 |
<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'); ?>')" /> |
| 363 |
</form> |
| 364 |
</div> |
| 365 |
</div> |
| 366 |
|