__( 'Report', 'email-subscribers' ), // singular name of the listed records 'plural' => __( 'Reports', 'email-subscribers' ), // plural name of the listed records 'ajax' => false, // does this table support ajax?, 'screen' => 'es_reports', ) ); add_action( 'admin_footer', array( $this, 'display_preview_email' ), 10 ); } public function es_reports_callback() { $campaign_id = ig_es_get_request_data( 'campaign_id' ); $campaign_type = ''; // Since, currently we are not passing campaign_id with broadcast $campaign_type will remain empty for broadcast if ( ! empty( $campaign_id ) ) { $campaign_type = ES()->campaigns_db->get_campaign_type_by_id( $campaign_id ); } $campaign_types = array( 'sequence', 'sequence_message', 'workflow', 'workflow_email' ); // Only if it is sequence then control will transfer to Sequence Reports class. if ( ! empty( $campaign_type ) && in_array( $campaign_type, $campaign_types, true ) ) { if ( ES()->is_pro() ) { $reports = ES_Pro_Sequence_Reports::get_instance(); $reports->es_sequence_reports_callback(); } else { do_action( 'ig_es_view_report_data' ); } } else { $action = ig_es_get_request_data( 'action' ); if ( 'view' === $action ) { $view_report = new ES_Campaign_Report(); $view_report->es_campaign_report_callback(); } else { ?>

0 ) { $cron_url = ES()->cron->url( true ); /* translators: %s: Cron url */ $content = '' . esc_html__( 'Send Queued Emails Now', 'email-subscribers' ) . ''; } else { $content = '' . esc_html__( 'Send Queued Emails Now', 'email-subscribers' ) . ''; $content .= '
' . esc_html__( 'No emails found in queue', 'email-subscribers' ) . ''; } ?>
0 && ES()->is_starter(); if ( $show_campaign_notice ) { ?>

', ' ' ); ?>


prepare_items(); ?>
display(); ?>

__( 'Reports', 'email-subscribers' ), 'default' => 10, 'option' => 'reports_per_page', ); add_screen_option( $option, $args ); } /** Text displayed when no list data is available */ public function no_items() { esc_html_e( 'No Reports avaliable.', 'email-subscribers' ); } /** * Generates content for a single row of the table. * Overrides WP_List_Table class single_row function. * * @since 4.7.8 * * @param object|array $item The current item */ public function single_row( $item ) { echo ''; $this->single_row_columns( $item ); echo ''; } /** * Render a column when no column specific method exist. * * @param array $item * @param string $column_name * * @return mixed */ public function column_default( $item, $column_name ) { global $wpdb; switch ( $column_name ) { case 'start_at': case 'finish_at': return ig_es_format_date_time( $item[ $column_name ] ); case 'type': if ( empty( $item['campaign_id'] ) ) { $type = __( 'Post Notification', 'email-subscribers' ); } else { $type = ES()->campaigns_db->get_campaign_type_by_id( $item['campaign_id'] ); $type = strtolower( $type ); $type = ( 'newsletter' === $type ) ? __( 'Broadcast', 'email-subscribers' ) : $type; } $type = ucwords( str_replace( '_', ' ', $type ) ); return $type; case 'subject': // case 'type': // return ucwords($item[ $column_name ]); case 'count': return $item[ $column_name ]; case 'total_sent': $total_emails_sent = ES()->actions_db->get_count_based_on_id_type( $item['campaign_id'], $item['id'], IG_MESSAGE_SENT ); return number_format_i18n( $total_emails_sent ); case 'total_opened': $total_emails_sent = ES()->actions_db->get_count_based_on_id_type( $item['campaign_id'], $item['id'], IG_MESSAGE_SENT ); $total_emails_opened = ES()->actions_db->get_count_based_on_id_type( $item['campaign_id'], $item['id'], IG_MESSAGE_OPEN ); $open_rate = ! empty( $total_emails_sent) ? number_format_i18n( ( ( $total_emails_opened * 100 ) / $total_emails_sent ), 2 ) : 0; return number_format_i18n( $total_emails_opened ) . esc_html( ' (' . $open_rate . '%)' ); default: $column_data = isset( $item[ $column_name ] ) ? $item[ $column_name ] : '-'; return $column_data; } } public function column_status( $item ) { $report_status = $item['status']; $status_html = ''; if ( IG_ES_MAILING_QUEUE_STATUS_SENT === $report_status ) { $status_html = sprintf( ' %s ', __( 'Sent', 'email-subscribers' ) ); } else { if ( IG_ES_MAILING_QUEUE_STATUS_SENDING === $report_status ) { $status_html = sprintf( ' %s ', __( 'Sending', 'email-subscribers' ) ); } elseif ( IG_ES_MAILING_QUEUE_STATUS_PAUSED === $report_status ) { $status_html = sprintf( ' %s ', __( 'Paused', 'email-subscribers' ) ); } elseif ( IG_ES_MAILING_QUEUE_STATUS_QUEUED === $report_status ) { $status_html = sprintf( ' %s ', __( 'Scheduled', 'email-subscribers' ) ); } elseif ( IG_ES_MAILING_QUEUE_STATUS_FAILED === $report_status ) { $status_html = sprintf( ' %s ', __( 'Failed', 'email-subscribers' ) ); } $actions = array(); if ( in_array( $report_status, array( IG_ES_MAILING_QUEUE_STATUS_QUEUED, IG_ES_MAILING_QUEUE_STATUS_SENDING, IG_ES_MAILING_QUEUE_STATUS_FAILED ), true ) ) { $actions['send_now'] = $this->prepare_send_now_url( $item ); } $actions = apply_filters( 'ig_es_report_row_actions', $actions, $item ); $status_html = $status_html . $this->row_actions( $actions, true ); } return $status_html; } /** * Render the bulk edit checkbox * * @param array $item * * @return string */ public function column_cb( $item ) { return sprintf( '', $item['id'] ); } /** * Method for name column * * @param array $item an array of DB data * * @return string */ public function column_subject( $item ) { $es_nonce = wp_create_nonce( 'es_notification' ); $page = ig_es_get_request_data( 'page' ); $title = '' . $item['subject'] . ''; $actions = array( 'view' => sprintf( '%s', esc_attr( $page ), 'view', $item['hash'], $es_nonce, __( 'View', 'email-subscribers' ) ), 'delete' => sprintf( '%s', esc_attr( $page ), 'delete', absint( $item['id'] ), $es_nonce, __( 'Delete', 'email-subscribers' ) ), 'preview_email' => sprintf( '%s', absint( $item['id'] ), __( 'Preview', 'email-subscribers' ), esc_url( ES_PLUGIN_URL ) . 'lite/admin/images/spinner-2x.gif' ), ); return $title . $this->row_actions( $actions ); } /** * Associative array of columns * * @return array */ public function get_columns() { $columns = array( 'cb' => '', 'subject' => __( 'Subject', 'email-subscribers' ), 'type' => __( 'Type', 'email-subscribers' ), 'status' => __( 'Status', 'email-subscribers' ), 'start_at' => __( 'Start Date', 'email-subscribers' ), 'finish_at' => __( 'End Date', 'email-subscribers' ), 'count' => __( 'Total contacts', 'email-subscribers' ), 'total_sent' => __( 'Total sent', 'email-subscribers' ), 'total_opened' => __( 'Total Opened', 'email-subscribers' ), ); return $columns; } public function column_count( $item ) { $campaign_hash = $item['hash']; $total_emails_sent = $item['count']; $total_emails_to_be_sent = $item['count']; // if ( ! empty( $campaign_hash ) ) { // $total_emails_sent = ES_DB_Sending_Queue::get_total_emails_sent_by_hash( $campaign_hash ); // } // $content = $total_emails_sent . "/" . $total_emails_to_be_sent; return number_format_i18n( $total_emails_to_be_sent ); } public function prepare_send_now_url( $item ) { $campaign_hash = $item['hash']; $cron_url = ''; if ( ! empty( $campaign_hash ) ) { $cron_url = ES()->cron->url( true, false, $campaign_hash ); } $content = ''; if ( ! empty( $cron_url ) ) { /* translators: %s: Cron url */ $content = sprintf( ' %s ', $cron_url, __( 'Send now', 'email-subscribers' ) ); } return $content; } /** * Columns to make sortable. * * @return array */ public function get_sortable_columns() { $sortable_columns = array( 'subject' => array( 'subject', true ), 'status' => array( 'status', true ), 'start_at' => array( 'start_at', true ), 'finish_at' => array( 'finish_at', true ), 'count' => array( 'count', true ), ); return $sortable_columns; } /** * Returns an associative array containing the bulk action * * @return array */ public function get_bulk_actions() { $actions = array( 'bulk_delete' => __( 'Delete', 'email-subscribers' ), ); return $actions; } /** * Handles data query and filter, sorting, and pagination. */ public function prepare_items() { $this->_column_headers = $this->get_column_info(); /** Process bulk action */ $this->process_bulk_action(); // Search box $search = ig_es_get_request_data( 's' ); $this->search_box( $search, 'reports-search-input' ); $per_page = $this->get_items_per_page( 'reports_per_page', 20 ); $current_page = $this->get_pagenum(); $total_items = $this->get_notifications( 0, 0, true ); $this->set_pagination_args( array( 'total_items' => $total_items, // WE have to calculate the total number of items 'per_page' => $per_page, // WE have to determine how many items to show on a page ) ); $this->items = $this->get_notifications( $per_page, $current_page, false ); } public function get_notifications( $per_page = 5, $page_number = 1, $do_count_only = false ) { global $wpdb, $wpbd; $order_by = sanitize_sql_orderby( ig_es_get_request_data( 'orderby' ) ); $order = ig_es_get_request_data( 'order' ); $campaign_id = ig_es_get_request_data( 'campaign_id' ); $search = ig_es_get_request_data( 's' ); $filter_reports_by_campaign_status = ig_es_get_request_data( 'filter_reports_by_status' ); $filter_reports_by_campaign_type = ig_es_get_request_data( 'filter_reports_by_campaign_type' ); $filter_reports_by_month_year = ig_es_get_request_data( 'filter_reports_by_date' ); $ig_mailing_queue_table = IG_MAILING_QUEUE_TABLE; if ( $do_count_only ) { $sql = "SELECT count(*) as total FROM {$ig_mailing_queue_table}"; } else { $sql = "SELECT * FROM {$ig_mailing_queue_table}"; } $where_columns = array(); $where_args = array(); $add_where_clause = true; if ( ! empty( $campaign_id ) && is_numeric( $campaign_id ) ) { $where_columns[] = 'campaign_id = %d'; $where_args[] = $campaign_id; } if ( ! empty( $filter_reports_by_month_year ) ) { if ( preg_match('/^[0-9]{6}$/', $filter_reports_by_month_year) ) { $year_val = substr($filter_reports_by_month_year, 0, 4); $month_val = substr($filter_reports_by_month_year, 4 ); $date_string = $year_val . '-' . $month_val; $date = new DateTime($date_string); $start_date = $date->format('Y-m-01 H:i:s') ; $end_date = $date->format('Y-m-t H:i:s'); array_push( $where_columns, 'start_at >= %s', 'start_at <= %s' ); array_push($where_args, $start_date, $end_date); } } $where_query = ''; if ( ! empty( $where_columns ) ) { $where_query = implode( ' AND ', $where_columns ); $where_query = $wpbd->prepare( $where_query, $where_args ); } if ( ! empty( $where_query ) ) { $sql .= ' WHERE ' . $where_query; $add_where_clause = false; } if ( ! empty( $filter_reports_by_campaign_status ) || ( '0' === $filter_reports_by_campaign_status ) ) { if ( ! $add_where_clause ) { $sql .= $wpdb->prepare( ' AND status = %s', $filter_reports_by_campaign_status ); } else { $sql .= $wpdb->prepare( ' WHERE status = %s', $filter_reports_by_campaign_status ); $add_where_clause = false; } } if ( ! empty( $filter_reports_by_campaign_type ) ) { if ( ! $add_where_clause ) { $sql .= $wpdb->prepare( ' AND meta LIKE %s', '%' . $wpdb->esc_like( $filter_reports_by_campaign_type ) . '%' ); } else { $sql .= $wpdb->prepare( ' WHERE meta LIKE %s', '%' . $wpdb->esc_like( $filter_reports_by_campaign_type ) . '%' ); } } if ( ! $do_count_only ) { // Prepare Order by clause $order = ! empty( $order ) ? strtolower( $order ) : 'desc'; $expected_order_values = array( 'asc', 'desc' ); if ( ! in_array( $order, $expected_order_values ) ) { $order = 'desc'; } $default_order_by = esc_sql( 'created_at' ); $expected_order_by_values = array( 'subject', 'type', 'status', 'start_at', 'count', 'created_at' ); if ( ! in_array( $order_by, $expected_order_by_values ) ) { $order_by_clause = " ORDER BY {$default_order_by} DESC"; } else { $order_by = esc_sql( $order_by ); $order_by_clause = " ORDER BY {$order_by} {$order}, {$default_order_by} DESC"; } $sql .= $order_by_clause; $sql .= " LIMIT $per_page"; $sql .= ' OFFSET ' . ( $page_number - 1 ) * $per_page; $result = $wpbd->get_results( $sql, 'ARRAY_A' ); } else { $result = $wpbd->get_var( $sql ); } return $result; } public function process_bulk_action() { $allowedtags = ig_es_allowed_html_tags_in_esc(); // Detect when a bulk action is being triggered... if ( 'view' === $this->current_action() ) { // In our file that handles the request, verify the nonce. $nonce = ig_es_get_request_data( '_wpnonce' ); if ( ! wp_verify_nonce( $nonce, 'es_notification' ) ) { $message = __( 'You do not have permission to view notification', 'email-subscribers' ); ES_Common::show_message( $message, 'error' ); } } elseif ( 'delete' === $this->current_action() ) { // In our file that handles the request, verify the nonce. $nonce = ig_es_get_request_data( '_wpnonce' ); if ( ! wp_verify_nonce( $nonce, 'es_notification' ) ) { $message = __( 'You do not have permission to delete notification', 'email-subscribers' ); ES_Common::show_message( $message, 'error' ); } else { $notification_ids = absint( ig_es_get_request_data( 'list' ) ); ES_DB_Mailing_Queue::delete_notifications( array( $notification_ids ) ); ES_DB_Sending_Queue::delete_by_mailing_queue_id( array( $notification_ids ) ); $message = __( 'Report deleted successfully!', 'email-subscribers' ); ES_Common::show_message( $message, 'success' ); } } $action = ig_es_get_request_data( 'action' ); $action2 = ig_es_get_request_data( 'action2' ); // If the delete bulk action is triggered if ( ( 'bulk_delete' === $action ) || ( 'bulk_delete' === $action2 ) ) { $notification_ids = ig_es_get_request_data( 'bulk_delete' ); if ( count( $notification_ids ) > 0 ) { ES_DB_Mailing_Queue::delete_notifications( $notification_ids ); ES_DB_Sending_Queue::delete_by_mailing_queue_id( $notification_ids ); $message = __( 'Reports deleted successfully!', 'email-subscribers' ); ES_Common::show_message( $message, 'success' ); } } } /* * Display the preview of the email content */ public function display_preview_email() { ?>