public static function display() { $wpdb = Follow_Up_Emails::instance()->wpdb; $stats = array('total_emails_sent' => 0, 'emails_sent_today' => 0, 'emails_scheduled_total' => 0); $today = date('Y-m-d', current_time('timestamp')); $from = $today . ' 00:00:00'; $to = $today . ' 23:59:59'; $stats['total_emails_sent'] = FUE_Reports::count_emails_sent(); $stats['emails_sent_today'] = FUE_Reports::count_emails_sent(array($from, $to)); $stats['emails_scheduled_total'] = $wpdb->get_var("SELECT COUNT(*)\n FROM {$wpdb->prefix}followup_email_orders o, {$wpdb->posts} p\n WHERE o.is_sent = 0\n AND o.email_id = p.ID"); include FUE_TEMPLATES_DIR . '/dashboard-widget.php'; }
/** * Get all the entries in the excludes list * * @param null $fields * @param array $filter * @param int $page * @return array */ public function get_excludes_report($fields = null, $filter = array(), $page = 1) { $args = array('type' => 'excludes', 'page' => $page, 'limit' => !empty($filter['limit']) ? absint($filter['limit']) : get_option('posts_per_page')); $exclude_reports = FUE_Reports::get_reports($args); $exclude_data = array(); $total_rows = Follow_Up_Emails::instance()->wpdb->get_var("SELECT FOUND_ROWS()"); foreach ($exclude_reports as $report) { $exclude_data[] = array('email_name' => $report->email_name, 'email_address' => $report->email, 'date' => $this->server->format_datetime($report->date_added, true)); } // set the pagination data $query = array('page' => $page, 'single' => count($exclude_data) == 1, 'total' => $total_rows, 'total_pages' => ceil($total_rows / $args['limit'])); $this->server->add_pagination_headers($query); return array('optouts' => apply_filters('fue_api_report_response', $exclude_data, $exclude_reports, $fields, $this->server)); }
public static function user_view_html() { $email = urldecode($_GET['email']); $reports = FUE_Reports::get_reports(array('email' => $email, 'type' => 'users')); $block = ''; //echo '<pre>'. print_r($reports,true) .'</pre>'; if (empty($reports)) { $block = ' <tr scope="row"> <th colspan="2">' . __('No reports available', 'follow_up_emails') . '</th> </tr>'; } else { foreach ($reports as $report) { $block .= ' <tr scope="row"> <td class="post-title column-title">'; if ($report->user_id != 0) { $block .= '<strong><a href="edit.php?post_status=all&post_type=shop_order&_customer_user='******'">' . stripslashes($report->customer_name) . '</a></strong>'; } else { $block .= '<strong>' . stripslashes($report->customer_name) . '</strong>'; } $block .= ' </td> <td>' . stripslashes($report->email_address) . '</td> <td>'; if ($report->product_id != 0) { $block .= '<a href="' . get_permalink($report->product_id) . '">' . get_the_title($report->product_id) . '</a>'; } $block .= ' </td> <td>' . $report->email_name . '</td> <td>' . $report->email_trigger . '</td>'; $block .= ' <td>' . date(get_option('date_format') . ' ' . get_option('time_format'), strtotime($report->date_sent)) . '</td> '; if ($report->order_id != 0) { $block .= '<td><a href="post.php?post=' . $report->order_id . '&action=edit">View Order</a></td>'; } else { $block .= '<td>-</td>'; } $block .= '</tr>'; } } $html = ' <h3>' . sprintf(__('Report for %s (%s)', 'wc_folloup_emails'), $report->customer_name, $report->email_address) . '</h3> <table class="wp-list-table widefat fixed posts"> <thead> <tr> <th scope="col" id="type" class="manage-column column-type" style="">' . __('Customer Name', 'follow_up_emails') . '</th> <th scope="col" id="user_email" class="manage-column column-user_email" style="">' . __('Customer Email', 'follow_up_emails') . '</th> <th scope="col" id="product" class="manage-column column-product" style="">' . __('Product', 'wc_folloup_emails') . '</th> <th scope="col" id="email_name" class="manage-column column-email_name" style="">' . __('Email', 'wc_folloup_emails') . '</th> <th scope="col" id="trigger" class="manage-column column-trigger" style="">' . __('Trigger', 'wc_folloup_emails') . '</th> <th scope="col" id="date_sent" class="manage-column column-date_sent" style="">' . __('Date Sent', 'follow_up_emails') . '</th> <th scope="col" id="order" class="manage-column column-order" style=""> </th> </tr> </thead> <tbody id="the_list"> ' . $block . ' </tbody> </table> '; return $html; }
/** * reset_reports() method */ static function reset_reports() { $data = $_POST; FUE_Reports::reset($data); wp_redirect('admin.php?page=followup-emails-reports&cleared=1'); exit; }
/** * After the daily summary email gets sent, queue the next summary email for the next day */ public static function queue_daily_summary_email() { $next_send = get_option('fue_next_summary', false); $send_time = get_option('fue_daily_emails_time', '06:00 AM'); if (false === $next_send) { $next_send = strtotime(date('Y-m-d', current_time('timestamp')) . ' ' . $send_time); if (current_time('timestamp') > $next_send) { // already in the past. Set it for tomorrow $next_send += 86400; } update_option('fue_next_summary', $next_send); } else { update_option('fue_last_summary', current_time('timestamp')); update_option('fue_next_summary', $next_send + 86400); } $scheduler = Follow_Up_Emails::instance()->scheduler; $items = $scheduler->get_items(array('meta' => 'daily_summary', 'is_sent' => 0, 'status' => 1)); if (empty($items)) { // FUE will use the billing_email by default. Remove the hook to stop it from changing the email remove_filter('fue_insert_email_order', array($scheduler, 'get_correct_email')); $scheduler->queue_email(array('user_email' => FUE_Reports::get_summary_recipient_emails(), 'meta' => array('daily_summary' => true, 'email' => FUE_Reports::get_summary_recipient_emails(), 'subject' => __('Follow-up emails summary', 'follow_up_emails'), 'message' => ''), 'email_trigger' => 'Daily summary', 'order_id' => 0, 'product_id' => 0, 'send_on' => $next_send), null, true); update_option('fue_last_summary', current_time('timestamp')); update_option('fue_next_summary', $next_send + 86400); } }
</thead> <tbody id="the_list"> <?php if (empty($email_reports)) { ?> <tr scope="row"> <th colspan="5"><?php _e('No reports available', 'follow_up_emails'); ?> </th> </tr><?php } else { foreach ($email_reports as $report) { $sent = FUE_Reports::count_email_sends($report->email_id); $opened = FUE_Reports::count_event_occurences($report->email_id, 'open'); $clicked = FUE_Reports::count_event_occurences($report->email_id, 'click'); $meta = ''; $email_row = new FUE_Email($report->email_id); ?> <tr scope="row"> <th scope="row" class="check-column"> <input id="cb-select-106" type="checkbox" name="email_id[]" value="<?php echo $report->email_id; ?> "> <div class="locked-indicator"></div> </th> <td class="post-title column-title"> <strong><?php echo stripslashes($report->email_name); ?>
public function report_section_div() { // coupons sorting $sort['sortby'] = 'date_sent'; $sort['sort'] = 'desc'; if (isset($_GET['sortby']) && !empty($_GET['sortby'])) { $valid = array('date_sent', 'email_address', 'coupon_used'); if (in_array($_GET['sortby'], $valid)) { $sort['sortby'] = $_GET['sortby']; $sort['sort'] = isset($_GET['sort']) && $_GET['sort'] == 'asc' ? 'asc' : 'desc'; } } $coupon_reports = FUE_Reports::get_reports(array('type' => 'coupons', 'sort' => $sort)); $email_address_class = $sort['sortby'] != 'email_address' ? 'sortable' : 'sorted'; $email_address_sort = $email_address_class == 'sorted' ? $sort['sort'] : 'asc'; $email_address_dir = $email_address_sort == 'asc' ? 'desc' : 'asc'; $used_class = $sort['sortby'] != 'coupon_used' ? 'sortable' : 'sorted'; $used_sort = $used_class == 'sorted' ? $sort['sort'] : 'asc'; $used_dir = $used_sort == 'asc' ? 'desc' : 'asc'; $sent_class = $sort['sortby'] != 'date_sent' ? 'sortable' : 'sorted'; $sent_sort = $sent_class == 'sorted' ? $sort['sort'] : 'asc'; $sent_dir = $sent_sort == 'asc' ? 'desc' : 'asc'; ?> <div class="section" id="coupons"> <h3><?php _e('Coupons', 'follow_up_emails'); ?> </h3> <table class="wp-list-table widefat fixed posts"> <thead> <tr> <th scope="col" id="coupon_name" class="manage-column column-type" style=""><?php _e('Coupon Name', 'follow_up_emails'); ?> </th> <th scope="col" id="email_address" class="manage-column column-usage_count <?php echo $email_address_class . ' ' . $email_address_sort; ?> " style=""> <a href="admin.php?page=followup-emails-reports&tab=reports&sortby=email_address&sort=<?php echo $email_address_dir; ?> &v=coupons"> <span><?php _e('Email Address', 'follow_up_emails'); ?> </span> <span class="sorting-indicator"></span> </a> </th> <th scope="col" id="coupon_code" class="manage-column column-usage_count" style=""><?php _e('Coupon Code', 'follow_up_emails'); ?> <img class="help_tip" width="16" height="16" title="<?php _e('This is the unique coupon code generated by the follow-up email for this specific email address', 'follow_up_emails'); ?> " src="<?php echo FUE_TEMPLATES_URL; ?> /images/help.png" /></th> <th scope="col" id="email_name" class="manage-column column-usage_count" style=""><?php _e('Email Name', 'follow_up_emails'); ?> <img class="help_tip" width="16" height="16" title="<?php _e('This is the name of the follow-up email that generated the coupon that was sent to this specific email address', 'follow_up_emails'); ?> " src="<?php echo FUE_TEMPLATES_URL; ?> /images/help.png" /></th> <th scope="col" id="used" class="manage-column column-used <?php echo $used_class . ' ' . $used_sort; ?> " style=""> <a href="admin.php?page=followup-emails-reports&tab=reports&sortby=coupon_used&sort=<?php echo $used_dir; ?> &v=coupons"> <span><?php _e('Used', 'follow_up_emails'); ?> <img class="help_tip" width="16" height="16" title="<?php _e('This tells you if this specific coupon code generated and sent via follow-up emails has been used, and if it has, it includes the date and time', 'follow_up_emails'); ?> " src="<?php echo FUE_TEMPLATES_URL; ?> /images/help.png" /></span> <span class="sorting-indicator"></span> </a> </th> <th scope="col" id="date_sent" class="manage-column column-date_sent <?php echo $sent_class . ' ' . $sent_sort; ?> " style=""> <a href="admin.php?page=followup-emails-reports&tab=reports&sortby=date_sent&sort=<?php echo $sent_dir; ?> &v=coupons"> <span><?php _e('Date Sent', 'follow_up_emails'); ?> <img class="help_tip" width="16" height="16" title="<?php _e('This is the date and time that this specific coupon code was sent to this email address', 'follow_up_emails'); ?> " src="<?php echo FUE_TEMPLATES_URL; ?> /images/help.png" /></span> <span class="sorting-indicator"></span> </a> </th> </tr> </thead> <tbody id="the_list"> <?php if (empty($coupon_reports)) { echo ' <tr scope="row"> <th colspan="6">' . __('No reports available', 'follow_up_emails') . '</th> </tr>'; } else { foreach ($coupon_reports as $report) { $used = __('No', 'follow_up_emails'); if ($report->coupon_used == 1) { $date = date(get_option('date_format') . ' ' . get_option('time_format'), strtotime($report->date_used)); $used = sprintf(__('Yes (%s)', 'follow_up_emails'), $date); } echo ' <tr scope="row"> <td class="post-title column-title"> <strong>' . stripslashes($report->coupon_name) . '</strong> </td> <td>' . esc_html($report->email_address) . '</td> <td>' . esc_html($report->coupon_code) . '</td> <td>' . esc_html($report->email_name) . '</td> <td>' . $used . '</td> <td>' . date(get_option('date_format') . ' ' . get_option('time_format'), strtotime($report->date_sent)) . '</td> </tr> '; } } ?> </tbody> </table> </div> <?php }
/** * Log a sent email * @param $email_data */ private function log_sent_email($email_data) { $email = $this->email; $queue = $this->queue; // log this email $email_trigger = $email->get_trigger_string(); $log = array('email_id' => $email->id, 'email_order_id' => $queue->id, 'user_id' => $queue->user_id, 'email_name' => $email->name, 'date_sent' => current_time('mysql'), 'customer_name' => $email_data['cname'], 'email_address' => $email_data['email_to'], 'order_id' => $queue->order_id, 'product_id' => $queue->product_id, 'email_trigger' => $email_trigger); FUE_Reports::email_log_array($log); }
/** * View report for a customer */ public static function user_view_html() { global $wpdb; $email = $_GET['email']; $reports = FUE_Reports::get_reports(array('email' => $email, 'type' => 'users')); $user_id = !empty($_GET['user_id']) ? $_GET['user_id'] : 0; if ($user_id == 0) { $fue_user = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->prefix}followup_customers WHERE email_address = %s", $email)); if ($fue_user) { $user_id = $fue_user->user_id; } } $user_email = get_user_meta($user_id, 'billing_email', true); $sql = $wpdb->prepare("SELECT * FROM {$wpdb->prefix}followup_email_excludes WHERE email = %s", $user_email); $excludes = $wpdb->get_results($sql); $queue = $wpdb->get_results($wpdb->prepare("SELECT DISTINCT * FROM {$wpdb->prefix}followup_email_orders WHERE is_sent = 0 AND user_email = %s ORDER BY send_on ASC", $email)); include FUE_TEMPLATES_DIR . '/reports/user_view.php'; return; }