PluginProbe
Email Log / 0.7
Email Log v0.7
2.63 2.4.8 2.4.9 2.6 2.61 2.62 trunk 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.8.1 0.9 0.9.1 0.9.2 1.1 1.5 1.5.1 1.5.2 1.5.3 1.5.4 All 61 releases
email-log / email-log.php

email-log.php in Email Log 0.7, at email-log.php

681 lines 29.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 Plugin Name: Email Log
4 Plugin URI: http://sudarmuthu.com/wordpress/email-log
5 Description: Logs every email sent through WordPress. Compatiable with WPMU too.
6 Donate Link: http://sudarmuthu.com/if-you-wanna-thank-me
7 Author: Sudar
8 Version: 0.7
9 Author URI: http://sudarmuthu.com/
10 Text Domain: email-log
11
12 === RELEASE NOTES ===
13 2009-10-08 - v0.1 - Initial Release
14 2009-10-15 - v0.2 - Added compatability for MySQL 4
15 2009-10-19 - v0.3 - Added compatability for MySQL 4 (Thanks Frank)
16 2010-01-02 - v0.4 - Added german translation (Thanks Frank)
17 2012-01-01 - v0.5 - Fixed a deprecation notice
18 2012-04-29 - v0.6 - (Dev time: 2 hours)
19 - Added option to delete individual email logs
20 - Moved pages per screen option to Screen options panel
21 - Added information to the screen help tab
22 - Added Lithuanian translations
23 2012-06-23 - v0.7 - (Dev time: 1 hour)
24 - Changed Timestamp(n) MySQL datatype to Timestamp (now compatible with MySQL 5.5+)
25 - Added the ability to bulk delete checkboxes
26
27 */
28 /* Copyright 2009 Sudar Muthu (email : sudar@sudarmuthu.com)
29
30 This program is free software; you can redistribute it and/or modify
31 it under the terms of the GNU General Public License, version 2, as
32 published by the Free Software Foundation.
33
34 This program is distributed in the hope that it will be useful,
35 but WITHOUT ANY WARRANTY; without even the implied warranty of
36 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
37 GNU General Public License for more details.
38
39 You should have received a copy of the GNU General Public License
40 along with this program; if not, write to the Free Software
41 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
42 */
43
44 global $wpdb;
45 global $smel_table_name;
46 $smel_table_name = $wpdb->prefix . "email_log";
47
48 // TODO - Should find some way to get away with these global variables.
49 global $smel_db_version;
50 $smel_db_version = "0.1";
51
52 class EmailLog {
53
54 private $table_name ; /* Database table name */
55 private $db_version ; /* Database version */
56 private $admin_page;
57 private $admin_screen;
58
59 /**
60 * Initalize the plugin by registering the hooks
61 */
62 function __construct() {
63
64 global $wpdb;
65 global $smel_table_name;
66 global $smel_db_version;
67
68 // Load localization domain
69 load_plugin_textdomain( 'email-log', false, dirname(plugin_basename(__FILE__)) . '/languages' );
70
71 // Register hooks
72 add_action( 'admin_menu', array(&$this, 'register_settings_page') );
73
74 // Register Filter
75 add_filter('wp_mail', array(&$this, 'log_email'));
76 add_filter('set-screen-option', array(&$this, 'save_screen_options'), 10, 3);
77
78 $plugin = plugin_basename(__FILE__);
79 add_filter("plugin_action_links_$plugin", array(&$this, 'add_action_links'));
80
81 // Initialize Variables
82 $this->table_name = $smel_table_name;
83 $this->db_version = $smel_db_version;
84 }
85
86 /**
87 * Register the settings page
88 */
89 function register_settings_page() {
90 //Save the handle to your admin page - you'll need it to create a WP_Screen object
91 $this->admin_page = add_options_page( __('Email Log', 'email-log'), __('Email Log', 'email-log'), 'manage_options', 'email-log', array(&$this, 'settings_page') );
92
93 add_action("load-{$this->admin_page}",array(&$this,'create_settings_panel'));
94 }
95
96 /**
97 * Add settings Panel
98 */
99 function create_settings_panel() {
100
101 /**
102 * Create the WP_Screen object against your admin page handle
103 * This ensures we're working with the right admin page
104 */
105 $this->admin_screen = WP_Screen::get($this->admin_page);
106
107 /**
108 * Content specified inline
109 */
110 $this->admin_screen->add_help_tab(
111 array(
112 'title' => __('About Plugin', 'email-log'),
113 'id' => 'about_tab',
114 'content' => '<p>' . __('Email Log WordPress Plugin, allows you to log all emails that are sent through WordPress.', 'email-log') . '</p>',
115 'callback' => false
116 )
117 );
118
119 // Add help sidebar
120 $this->admin_screen->set_help_sidebar(
121 '<p><strong>' . __('More information', 'email-log') . '</strong></p>' .
122 '<p><a href = "http://sudarmuthu.com/wordpress/email-log">' . __('Plugin Homepage/support', 'email-log') . '</a></p>' .
123 '<p><a href = "http://sudarmuthu.com/blog">' . __("Plugin author's blog", 'email-log') . '</a></p>' .
124 '<p><a href = "http://sudarmuthu.com/wordpress/">' . __("Other Plugin's by Author", 'email-log') . '</a></p>'
125 );
126
127 // Add screen options
128 $this->admin_screen->add_option(
129 'per_page',
130 array(
131 'label' => __('Entries per page', 'email-log'),
132 'default' => 20,
133 'option' => 'per_page'
134 )
135 );
136 }
137
138 /**
139 * Save Screen option
140 */
141 function save_screen_options($status, $option, $value) {
142 if ( 'per_page' == $option ) return $value;
143 }
144
145 /**
146 * Get the per page option
147 */
148 private function get_per_page() {
149 $screen = get_current_screen();
150 $option = $screen->get_option('per_page', 'option');
151
152 $per_page = get_user_meta(get_current_user_id(), $option, TRUE);
153
154 if ( empty ( $per_page) || $per_page < 1 ) {
155 $per_page = $screen->get_option( 'per_page', 'default' );
156 }
157
158 return $per_page;
159 }
160
161 /**
162 * hook to add action links
163 *
164 * @param <type> $links
165 * @return <type>
166 */
167 function add_action_links( $links ) {
168 // Add a link to this plugin's settings page
169 $settings_link = '<a href="options-general.php?page=email-log">' . __("Settings", 'email-log') . '</a>';
170 array_unshift( $links, $settings_link );
171 return $links;
172 }
173
174 /**
175 * Adds Footer links. Based on http://striderweb.com/nerdaphernalia/2008/06/give-your-wordpress-plugin-credit/
176 */
177 function add_footer_links() {
178 $plugin_data = get_plugin_data( __FILE__ );
179 printf('%1$s ' . __("plugin", 'email-log') .' | ' . __("Version", 'email-log') . ' %2$s | '. __('by', 'email-log') . ' %3$s<br />', $plugin_data['Title'], $plugin_data['Version'], $plugin_data['Author']);
180 }
181
182 /**
183 * Dipslay the Settings page
184 *
185 * Some parts of this function is based on the wp-rattings Plugin http://wordpress.org/extend/plugins/email-log/
186 */
187 function settings_page() {
188 global $wpdb;
189 global $text_direction;
190
191 $base_name = plugin_basename('email-log');
192 $base_page = 'admin.php?page='.$base_name;
193
194 $email_log_page = intval($_GET['emaillog_page']);
195 $emaillogs_filterid = trim(addslashes($_GET['id']));
196 $emaillogs_filter_to_email = trim(addslashes($_GET['to_email']));
197 $emaillogs_filter_subject = trim(addslashes($_GET['subject']));
198 $emaillog_sort_by = trim($_GET['by']);
199 $emaillog_sortby_text = '';
200 $emaillog_sortorder = trim($_GET['order']);
201 $emaillog_sortorder_text = '';
202 $email_log_perpage = intval($this->get_per_page());
203 $emaillog_sort_url = '';
204
205 ### Form Processing
206 if(!empty($_POST['do'])) {
207 // Decide What To Do
208 switch($_POST['do']) {
209 case __('Delete Logs', 'email-log'):
210 $delete_datalog = intval($_POST['delete_datalog']);
211 switch($delete_datalog) {
212 case 1:
213 // delete selected entries
214 $selected_ids = implode(',', $_POST['selected_ids']);
215 $delete_logs = $wpdb->query("DELETE FROM $this->table_name where id IN ($selected_ids)");
216
217 if($delete_logs) {
218 $text = '<font color="green">' . __('The selected Email Logs have been deleted.', 'email-log') . '</font>';
219 } else {
220 $text = '<font color="red">' . __('An error has occurred while deleting the selected Email logs', 'email-log') . '</font>';
221 }
222 break;
223 case 2:
224 // Delete based on condition
225 $to_email = trim(addslashes( $_POST['delete_to_email']));
226 if ('' != $to_email) {
227 $delete_logs = $wpdb->query("DELETE FROM $this->table_name where to_email = '$to_email'");
228 if($delete_logs) {
229 $text = '<font color="green">'.sprintf(__('All Email Logs For email id %s Have Been Deleted.', 'email-log'), $to_email).'</font>';
230 } else {
231 $text = '<font color="red">'.sprintf(__('An error has occurred while deleting All Email Logs For email id %s.', 'email-log'), $to_email).'</font>';
232 }
233 }
234
235 $subject = trim(addslashes( $_POST['delete_subject']));
236 if ('' != $subject) {
237 $delete_logs = $wpdb->query("DELETE FROM $this->table_name where subject = '$subject'");
238 if($delete_logs) {
239 $text .= '<font color="green">'.sprintf(__('All Email Logs With Subject %s Have Been Deleted.', 'email-log'), $subject).'</font>';
240 } else {
241 $text .= '<font color="red">'.sprintf(__('An Error Has Occurred While Deleting All Email Logs With Subject %s.', 'email-log'), $subject).'</font>';
242 }
243 }
244 break;
245 case 3:
246 // Delete all
247 $delete_logs = $wpdb->query("DELETE FROM $this->table_name ");
248 if ($delete_logs) {
249 $text = '<font color="green">'.__('All Email log Has Been Deleted.', 'email-log').'</font><br />';
250 } else {
251 $text = '<font color="red">'.__('An Error Has Occurred While Deleting All Email Logs', 'email-log').'</font>';
252 }
253 break;
254 }
255 break;
256 }
257 }
258
259 ### Form Sorting URL
260 if(!empty($emaillogs_filterid)) {
261 $emaillogs_filterid = intval($emaillogs_filterid);
262 $emaillog_sort_url .= '&amp;id='.$emaillogs_filterid;
263 }
264 if(!empty($emaillogs_filter_to_email)) {
265 $emaillog_sort_url .= '&amp;to_email='.$emaillogs_filter_to_email;
266 }
267 if(!empty($emaillogs_filter_subject)) {
268 $emaillog_sort_url .= '&amp;subject='.$emaillogs_filter_subject;
269 }
270 if(!empty($emaillog_sort_by)) {
271 $emaillog_sort_url .= '&amp;by='.$emaillog_sort_by;
272 }
273 if(!empty($emaillog_sortorder)) {
274 $emaillog_sort_url .= '&amp;order='.$emaillog_sortorder;
275 }
276
277 ### Get Order By
278 switch($emaillog_sort_by) {
279 case 'id':
280 $emaillog_sort_by = 'id';
281 $emaillog_sortby_text = __('ID', 'email-log');
282 break;
283 case 'to_email':
284 $emaillog_sort_by = 'to_email';
285 $emaillog_sortby_text = __('To Email', 'email-log');
286 break;
287 case 'subject':
288 $emaillog_sort_by = 'subject';
289 $emaillog_sortby_text = __('Subject', 'email-log');
290 break;
291 case 'date':
292 default:
293 $emaillog_sort_by = 'sent_date';
294 $emaillog_sortby_text = __('Date', 'email-log');
295 }
296
297 ### Get Sort Order
298 switch($emaillog_sortorder) {
299 case 'asc':
300 $emaillog_sortorder = 'ASC';
301 $emaillog_sortorder_text = __('Ascending', 'email-log');
302 break;
303 case 'desc':
304 default:
305 $emaillog_sortorder = 'DESC';
306 $emaillog_sortorder_text = __('Descending', 'email-log');
307 }
308
309 // Where
310 $emaillog_where = '';
311 if(!empty($emaillogs_filterid)) {
312 $emaillog_where = "AND id =$emaillogs_filterid";
313 }
314 if(!empty($emaillogs_filter_to_email)) {
315 $emaillog_where .= " AND to_email like '%$emaillogs_filter_to_email%'";
316 }
317 if(!empty($emaillogs_filter_subject)) {
318 $emaillog_where .= " AND subject like '%$emaillogs_filter_subject%'";
319 }
320
321 // Get email Logs Data
322 $total_logs = $wpdb->get_var("SELECT COUNT(id) FROM $this->table_name WHERE 1=1 $emaillog_where");
323
324 // Checking $postratings_page and $offset
325 if(empty($email_log_page) || $email_log_page == 0) { $email_log_page = 1; }
326 if(empty($offset)) { $offset = 0; }
327
328 // Determin $offset
329 $offset = ($email_log_page-1) * $email_log_perpage;
330
331 // Determine Max Number Of Logs To Display On Page
332 if(($offset + $email_log_perpage) > $total_logs) {
333 $max_on_page = $total_logs;
334 } else {
335 $max_on_page = ($offset + $email_log_perpage);
336 }
337
338 // Determine Number Of Logs To Display On Page
339 if (($offset + 1) > ($total_logs)) {
340 $display_on_page = $total_logs;
341 } else {
342 $display_on_page = ($offset + 1);
343 }
344
345 // Determing Total Amount Of Pages
346 $total_pages = ceil($total_logs / $email_log_perpage);
347
348 // Get The Logs
349 $email_logs = $wpdb->get_results("SELECT * FROM $this->table_name WHERE 1=1 $emaillog_where ORDER BY $emaillog_sort_by $emaillog_sortorder LIMIT $offset, $email_log_perpage");
350
351 // TODO: Should move this to a seperate js file
352 ?>
353 <script type = "text/javascript">
354 jQuery('document').ready(function() {
355 jQuery('.selectall').click(function (e) {
356 if (jQuery(e.target).is(':checked')) {
357 jQuery('.select_box').attr('checked', 'checked');
358 } else {
359 jQuery('.select_box').removeAttr('checked');
360 }
361 });
362 });
363 </script>
364 <?php if(!empty($text)) { echo '<!-- Last Action --><div id="message" class="updated fade"><p>'.$text.'</p></div>'; } ?>
365 <div class="wrap">
366 <?php screen_icon(); ?>
367 <h2><?php _e( 'Email Log Settings', 'email-log' ); ?></h2>
368
369 <p>&nbsp;</p>
370
371 <form action="<?php echo esc_url($_SERVER['PHP_SELF']); ?>" method="get">
372 <input type="hidden" name="page" value="<?php echo $base_name; ?>" />
373 <table class="widefat">
374 <tr>
375 <th><?php _e('Filter Options:', 'email-log'); ?></th>
376 <td>
377 <?php _e('ID:', 'email-log'); ?>&nbsp;<input type="text" name="id" value="<?php echo $emaillogs_filterid; ?>" size="5" maxlength="5" />
378 &nbsp;&nbsp;&nbsp;
379 <?php _e('To Email:', 'email-log'); ?>&nbsp;<input type="text" name="to_email" value="<?php echo $emaillogs_filter_to_email; ?>" size="40" maxlength="50" />
380 &nbsp;&nbsp;&nbsp;
381 <?php _e('Subject:', 'email-log'); ?>&nbsp;<input type="text" name="subject" value="<?php echo $emaillogs_filter_subject; ?>" size="40" maxlength="50" />
382 &nbsp;&nbsp;&nbsp;
383 </td>
384 </tr>
385 <tr class="alternate">
386 <th><?php _e('Sort Options:', 'email-log'); ?></th>
387 <td>
388 <select name="by" size="1">
389 <option value="id"<?php if($emaillog_sort_by == 'id') { echo ' selected="selected"'; }?>><?php _e('ID', 'email-log'); ?></option>
390 <option value="to_email"<?php if($emaillog_sort_by == 'to_email') { echo ' selected="selected"'; }?>><?php _e('To Email', 'email-log'); ?></option>
391 <option value="subject"<?php if($emaillog_sort_by == 'subject') { echo ' selected="selected"'; }?>><?php _e('Subject', 'email-log'); ?></option>
392 <option value="sent_date"<?php if($emaillog_sort_by == 'sent_date') { echo ' selected="selected"'; }?>><?php _e('Date', 'email-log'); ?></option>
393 </select>
394 &nbsp;&nbsp;&nbsp;
395 <select name="order" size="1">
396 <option value="asc"<?php if($emaillog_sortorder == 'ASC') { echo ' selected="selected"'; }?>><?php _e('Ascending', 'email-log'); ?></option>
397 <option value="desc"<?php if($emaillog_sortorder == 'DESC') { echo ' selected="selected"'; } ?>><?php _e('Descending', 'email-log'); ?></option>
398 </select>
399 </td>
400 </tr>
401 <tr>
402 <td colspan="2" align="center"><input type="submit" value="<?php _e('Filter', 'email-log'); ?>" class="button" /></td>
403 </tr>
404 </table>
405 </form>
406
407 <p><?php printf(__('Displaying <strong>%s</strong> to <strong>%s</strong> of <strong>%s</strong> Email log entries.', 'email-log'), number_format_i18n($display_on_page), number_format_i18n($max_on_page), number_format_i18n($total_logs)); ?></p>
408 <p><?php printf(__('Sorted by <strong>%s</strong> in <strong>%s</strong> order.', 'email-log'), $emaillog_sortby_text, $emaillog_sortorder_text); ?></p>
409
410 <form method="post" action="<?php echo esc_url($_SERVER['PHP_SELF']); ?>?page=<?php echo $base_name; ?>">
411 <?php
412 if($total_pages > 1) {
413 ?>
414 <br />
415 <table class="widefat">
416 <tr>
417 <td align="<?php echo ('rtl' == $text_direction) ? 'right' : 'left'; ?>" width="40%">
418 <?php
419 if($email_log_page > 1 && ((($email_log_page*$email_log_perpage)-($email_log_perpage-1)) <= $total_logs)) {
420 echo '<strong>&laquo;</strong> <a href="'.$base_page.'&amp;emaillog_page='.($email_log_page-1).$emaillog_sort_url.'" title="&laquo; '.__('Previous Page', 'email-log').'">'.__('Previous Page', 'email-log').'</a>';
421 } else {
422 echo '&nbsp;';
423 }
424 ?>
425 </td>
426 <td align="center" width="20%">
427 <?php printf(__('Pages (%s): ', 'email-log'), number_format_i18n($total_pages)); ?>
428 <?php
429 if ($email_log_page >= 4) {
430 echo '<strong><a href="'.$base_page.'&amp;emaillog_page=1'.$emaillog_sort_url.$emaillog_sort_url.'" title="'.__('Go to First Page', 'email-log').'">&laquo; '.__('First', 'email-log').'</a></strong> ... ';
431 }
432 if($email_log_page > 1) {
433 echo ' <strong><a href="'.$base_page.'&amp;emaillog_page='.($email_log_page-1).$emaillog_sort_url.'" title="&laquo; '.__('Go to Page', 'email-log').' '.number_format_i18n($email_log_page-1).'">&laquo;</a></strong> ';
434 }
435 for($i = $email_log_page - 2 ; $i <= $email_log_page +2; $i++) {
436 if ($i >= 1 && $i <= $total_pages) {
437 if($i == $email_log_page) {
438 echo '<strong>['.number_format_i18n($i).']</strong> ';
439 } else {
440 echo '<a href="'.$base_page.'&amp;emaillog_page='.($i).$emaillog_sort_url.'" title="'.__('Page', 'email-log').' '.number_format_i18n($i).'">'.number_format_i18n($i).'</a> ';
441 }
442 }
443 }
444 if($email_log_page < $total_pages) {
445 echo ' <strong><a href="'.$base_page.'&amp;emaillog_page='.($email_log_page+1).$emaillog_sort_url.'" title="'.__('Go to Page', 'email-log').' '.number_format_i18n($email_log_page+1).' &raquo;">&raquo;</a></strong> ';
446 }
447 if (($email_log_page+2) < $total_pages) {
448 echo ' ... <strong><a href="'.$base_page.'&amp;emaillog_page='.($total_pages).$emaillog_sort_url.'" title="'.__('Go to Last Page', 'email-log').'">'.__('Last', 'email-log').' &raquo;</a></strong>';
449 }
450 ?>
451 </td>
452 <td align="<?php echo ('rtl' == $text_direction) ? 'left' : 'right'; ?>" width="40%">
453 <?php
454 if($email_log_page >= 1 && ((($email_log_page*$email_log_perpage)+1) <= $total_logs)) {
455 echo '<a href="'.$base_page.'&amp;emaillog_page='.($email_log_page+1).$emaillog_sort_url.'" title="'.__('Next Page', 'email-log').' &raquo;">'.__('Next Page', 'email-log').'</a> <strong>&raquo;</strong>';
456 } else {
457 echo '&nbsp;';
458 }
459 ?>
460 </td>
461 </tr>
462 </table>
463 <!-- </Paging> -->
464 <?php
465 }
466 ?>
467 <table class="widefat">
468 <thead>
469 <tr>
470 <td width="5%"><input type = "checkbox" name = "selectall" class = "selectall" ></td>
471 <th width="5%"><?php _e('ID', 'email-log'); ?></th>
472 <th width="20%"><?php _e('Date / Time', 'email-log'); ?></th>
473 <th width="30%"><?php _e('To', 'email-log'); ?></th>
474 <th width="40%"><?php _e('Subject', 'email-log'); ?></th>
475 </tr>
476 </thead>
477 <tbody>
478 <?php
479 if($email_logs) {
480 $i = 0;
481 foreach($email_logs as $email_log) {
482 if($i%2 == 0) {
483 $style = 'class="alternate"';
484 } else {
485 $style = '';
486 }
487 $email_id = intval($email_log->id);
488 $email_date = mysql2date(sprintf(__('%s @ %s', 'email-log'), get_option('date_format'), get_option('time_format')), $email_log->sent_date);
489 $email_to = stripslashes($email_log->to_email);
490 $email_subject = stripslashes($email_log->subject);
491 echo "<tr $style>\n";
492 echo '<td><input type = "checkbox" class = "select_box" name = "selected_ids[]" value = "' . $email_id . '"></td>'."\n";
493 echo '<td>'.$email_id.'</td>'."\n";
494 echo "<td>$email_date</td>\n";
495 echo "<td>$email_to</td>\n";
496 echo "<td>$email_subject</td>\n";
497 echo '</tr>';
498 $i++;
499 }
500 } else {
501 echo '<tr><td colspan="7" align="center"><strong>'.__('No email Logs Found', 'email-log').'</strong></td></tr>';
502 }
503 ?>
504 </tbody>
505 <tfoot>
506 <tr>
507 <td width="5%"><input type = "checkbox" name = "selectall" class = "selectall" ></td>
508 <th width="5%"><?php _e('ID', 'email-log'); ?></th>
509 <th width="20%"><?php _e('Date / Time', 'email-log'); ?></th>
510 <th width="30%"><?php _e('To', 'email-log'); ?></th>
511 <th width="40%"><?php _e('Subject', 'email-log'); ?></th>
512 </tr>
513 </tfoot>
514 </table>
515 <?php
516 if($total_pages > 1) {
517 ?>
518 <table class="widefat">
519 <tr>
520 <td align="<?php echo ('rtl' == $text_direction) ? 'right' : 'left'; ?>" width="40%">
521 <?php
522 if($email_log_page > 1 && ((($email_log_page*$email_log_perpage)-($email_log_perpage-1)) <= $total_logs)) {
523 echo '<strong>&laquo;</strong> <a href="'.$base_page.'&amp;emaillog_page='.($email_log_page-1).$emaillog_sort_url.'" title="&laquo; '.__('Previous Page', 'email-log').'">'.__('Previous Page', 'email-log').'</a>';
524 } else {
525 echo '&nbsp;';
526 }
527 ?>
528 </td>
529 <td align="center" width="20%">
530 <?php printf(__('Pages (%s): ', 'email-log'), number_format_i18n($total_pages)); ?>
531 <?php
532 if ($email_log_page >= 4) {
533 echo '<strong><a href="'.$base_page.'&amp;emaillog_page=1'.$emaillog_sort_url.$emaillog_sort_url.'" title="'.__('Go to First Page', 'email-log').'">&laquo; '.__('First', 'email-log').'</a></strong> ... ';
534 }
535 if($email_log_page > 1) {
536 echo ' <strong><a href="'.$base_page.'&amp;emaillog_page='.($email_log_page-1).$emaillog_sort_url.'" title="&laquo; '.__('Go to Page', 'email-log').' '.number_format_i18n($email_log_page-1).'">&laquo;</a></strong> ';
537 }
538 for($i = $email_log_page - 2 ; $i <= $email_log_page +2; $i++) {
539 if ($i >= 1 && $i <= $total_pages) {
540 if($i == $email_log_page) {
541 echo '<strong>['.number_format_i18n($i).']</strong> ';
542 } else {
543 echo '<a href="'.$base_page.'&amp;emaillog_page='.($i).$emaillog_sort_url.'" title="'.__('Page', 'email-log').' '.number_format_i18n($i).'">'.number_format_i18n($i).'</a> ';
544 }
545 }
546 }
547 if($email_log_page < $total_pages) {
548 echo ' <strong><a href="'.$base_page.'&amp;emaillog_page='.($email_log_page+1).$emaillog_sort_url.'" title="'.__('Go to Page', 'email-log').' '.number_format_i18n($email_log_page+1).' &raquo;">&raquo;</a></strong> ';
549 }
550 if (($email_log_page+2) < $total_pages) {
551 echo ' ... <strong><a href="'.$base_page.'&amp;emaillog_page='.($total_pages).$emaillog_sort_url.'" title="'.__('Go to Last Page', 'email-log').'">'.__('Last', 'email-log').' &raquo;</a></strong>';
552 }
553 ?>
554 </td>
555 <td align="<?php echo ('rtl' == $text_direction) ? 'left' : 'right'; ?>" width="40%">
556 <?php
557 if($email_log_page >= 1 && ((($email_log_page*$email_log_perpage)+1) <= $total_logs)) {
558 echo '<a href="'.$base_page.'&amp;emaillog_page='.($email_log_page+1).$emaillog_sort_url.'" title="'.__('Next Page', 'email-log').' &raquo;">'.__('Next Page', 'email-log').'</a> <strong>&raquo;</strong>';
559 } else {
560 echo '&nbsp;';
561 }
562 ?>
563 </td>
564 </tr>
565 <tr class="alternate">
566 </tr>
567 </table>
568 <!-- </Paging> -->
569 <?php
570 }
571 ?>
572
573 <!-- Delete Email Logs -->
574 <h3><?php _e('Delete Logs', 'email-log'); ?></h3>
575 <div align="center">
576 <table class="widefat">
577 <tr>
578 <td valign="top"><b><?php _e('Delete Type : ', 'email-log'); ?></b></td>
579 <td valign="top">
580 <select size="1" name="delete_datalog">
581 <option value="1"><?php _e('Selected entries', 'email-log'); ?></option>
582 <option value="2"><?php _e('Based on', 'email-log'); ?></option>
583 <option value="3"><?php _e('All Logs', 'email-log'); ?></option>
584 </select>
585 </td>
586 </tr>
587 <tr>
588 <td valign="top"><b><?php _e('Condition:', 'email-log'); ?></b></td>
589 <td valign="top">
590 <label for ="delete_to_email"><?php _e('To Email', 'email-log');?> <input type="text" name="delete_to_email" size="20" dir="ltr" /></label>
591 <?php _e('or', 'email-log');?>
592 <label for ="delete_subject"><?php _e('Subject', 'email-log');?> <input type="text" name="delete_subject" size="20" dir="ltr" /></label>
593 </td>
594 </tr>
595 <tr>
596 <td colspan="2" align="center">
597 <input type="submit" name="do" value="<?php _e('Delete Logs', 'email-log'); ?>" class="button" onclick="return confirm('<?php _e('You Are About To Delete Email Logs.\nThis Action Is Not Reversible.\n\n Choose \\\'Cancel\\\' to stop, \\\'OK\\\' to delete.', 'email-log'); ?>')" />
598 </td>
599 </tr>
600 </table>
601 </div>
602 </form>
603 </div>
604 <?php
605 // Display credits in Footer
606 add_action( 'in_admin_footer', array(&$this, 'add_footer_links'));
607 }
608
609 /**
610 * Log all email to database
611 *
612 * @global object $wpdb
613 * @param array $mail_info Information about email
614 * @return array Information about email
615 */
616 function log_email($mail_info) {
617
618 global $wpdb;
619
620 $attachment_present = (count ($mail_info['attachments']) > 0) ? "true" : "false";
621
622 // Log into the database
623 $wpdb->insert($this->table_name, array(
624 'to_email' => $mail_info['to'],
625 'subject' => $mail_info['subject'],
626 'message' => $mail_info['message'],
627 'headers' => $mail_info['headers'],
628 'attachments' => $attachment_present
629 ));
630
631 // return unmodifiyed array
632 return $mail_info;
633 }
634
635 // PHP4 compatibility
636 function EmailLog() {
637 $this->__construct();
638 }
639 }
640
641 /**
642 * Create database table when the Plugin is installed for the first time
643 *
644 * @global object $wpdb
645 * @global string $smel_table_name Table Name
646 * @global string $smel_db_version DB Version
647 */
648 function smel_on_install() {
649
650 global $wpdb;
651 global $smel_table_name;
652 global $smel_db_version;
653
654 if($wpdb->get_var("show tables like '{$smel_table_name}'") != $smel_table_name) {
655
656 $sql = "CREATE TABLE " . $smel_table_name . " (
657 id mediumint(9) NOT NULL AUTO_INCREMENT,
658 to_email VARCHAR(100) NOT NULL,
659 subject VARCHAR(250) NOT NULL,
660 message TEXT NOT NULL,
661 headers TEXT NOT NULL,
662 attachments TEXT NOT NULL,
663 sent_date timestamp NOT NULL,
664 PRIMARY KEY (id)
665 );";
666
667 require_once(ABSPATH . 'wp-admin/upgrade-functions.php');
668 dbDelta($sql);
669
670 add_option("email-log-db", $smel_db_version);
671 }
672 }
673
674 // When installed
675 register_activation_hook(__FILE__, 'smel_on_install');
676
677 // Start this plugin once all other plugins are fully loaded
678 add_action( 'init', 'EmailLog' ); function EmailLog() { global $EmailLog; $EmailLog = new EmailLog(); }
679
680 ?>
681