diff --git a/page-campaigns.php b/page-campaigns.php index 078be4d..32a3ded 100644 --- a/page-campaigns.php +++ b/page-campaigns.php @@ -123,7 +123,7 @@ get_header(); ?> $list = new PostTypeList('campaign', [ 'title' => 'My Campaigns', - 'no_items' => 'You haven\'t added any campaigns yet.', + 'no_items' => 'You haven\'t added any campaigns yet. Click here to create a campaign', 'delete_confirm' => 'Are you sure you want to delete this campaign? This action cannot be undone.' ]); $list->render(); diff --git a/page-dashboard.php b/page-dashboard.php index ebc20cf..978f722 100644 --- a/page-dashboard.php +++ b/page-dashboard.php @@ -39,6 +39,72 @@ $email_account_count = count(get_posts([ 'status' => 'publish', 'meta_query' => [['key' => 'owner_id', 'value' => $current_user_id]] ])); + // Get campaigns for this user + $campaigns = get_posts([ + "post_type" => "campaign", + "posts_per_page" => -1, + "status" => "publish", + "meta_query" => [['key' => 'owner_id', 'value' => $current_user_id]] + ]); + + // Initialize message counters and delivery stats + $messages_today = 0; + $messages_this_week = 0; + $total_sent = 0; + $total_failed = 0; + + // Get message counts from database + global $wpdb; + $messages_table = $wpdb->prefix . 'rl_mailwarmer_messages'; + + // Get campaign IDs + $campaign_ids = array(); + foreach ($campaigns as $campaign) { + $campaign_ids[] = $campaign->ID; + } + + if (!empty($campaign_ids)) { + // Convert to comma-separated string for SQL + $campaign_ids_str = implode(",", $campaign_ids); + + // Messages scheduled today + $today = date("Y-m-d"); + $messages_today = $wpdb->get_var( + "SELECT COUNT(*) FROM $messages_table + WHERE campaign_id IN ($campaign_ids_str) + AND (status = 'new' OR status = 'scheduled') + AND DATE(scheduled_for_timestamp) = '$today'" + ); + + // Messages scheduled this week (next 7 days) + $week_end = date("Y-m-d", strtotime("+7 days")); + $messages_this_week = $wpdb->get_var( + "SELECT COUNT(*) FROM $messages_table + WHERE campaign_id IN ($campaign_ids_str) + AND (status = 'new' OR status = 'scheduled') + AND DATE(scheduled_for_timestamp) BETWEEN '$today' AND '$week_end'" + ); + + // Get total sent and failed messages + $total_sent = $wpdb->get_var( + "SELECT COUNT(*) FROM $messages_table + WHERE campaign_id IN ($campaign_ids_str) + AND status = 'sent'" + ); + + $total_failed = $wpdb->get_var( + "SELECT COUNT(*) FROM $messages_table + WHERE campaign_id IN ($campaign_ids_str) + AND status = 'failed'" + ); + } + + // Calculate delivery rate + $delivery_rate = 0; + if (($total_sent + $total_failed) > 0) { + $delivery_rate = round(($total_sent / ($total_sent + $total_failed)) * 100, 1); + } + if ( ($cloudflare_email || $cloudflare_key) ) { $onboard_steps[0] = true; @@ -176,9 +242,13 @@ get_header(); ?>

Campaigns

Email Accounts

Domains

-

Messages Scheduled

-

Delivery Rate

-

Delivery Errors

+

Messages Scheduled

+ + Today:
This Week:
+ +
+

Delivery Rate

%
+

Message Status

Sent:
Failed:
@@ -186,7 +256,7 @@ get_header(); ?>

Get Started:

diff --git a/page-domains.php b/page-domains.php index 1dc75a0..8d8cf32 100644 --- a/page-domains.php +++ b/page-domains.php @@ -123,7 +123,7 @@ get_header(); ?> $list = new PostTypeList('domain', [ 'title' => 'My Domains', - 'no_items' => 'You haven\'t added any domains yet.', + 'no_items' => 'You haven\'t added any domains yet. Click here to create a domain', 'delete_confirm' => 'Are you sure you want to delete this domain? This action cannot be undone.' ]); $list->render(); diff --git a/page-edit-campaign.php b/page-edit-campaign.php index 0c99880..427f140 100644 --- a/page-edit-campaign.php +++ b/page-edit-campaign.php @@ -43,7 +43,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['campaign_submit'])) { $message = ['status' => 'success', 'message' => 'Campaign updated successfully.']; $campaign_tracking_id = get_post_meta($post_id, 'campaign_tracking_id', true); // log_to_file("Campaign Edit template - Campaign Tracking ID: $campaign_tracking_id"); - if ($campaign_tracking_id == '') { + if (!$campaign_tracking_id) { RL_MailWarmer_Campaign_Helper::generate_campaign_tracking_id($post_id); } } else { @@ -132,9 +132,10 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['campaign_submit'])) { // Calculate a timeline if ($new_post || $calculate_timeline) { + // log_to_file("Campaign Edit template - Recalculating timeline"); RL_MailWarmer_DB_Helper::delete_all_conversations_messages($post_id); RL_MailWarmer_Campaign_Helper::calculate_campaign_timeline($post_id); - RL_MailWarmer_Campaign_Helper::fill_campaign_timeline($post_id); + // RL_MailWarmer_Campaign_Helper::fill_campaign_timeline($post_id); // log_to_file("Campaign Edit template - Campaign timeline: ", $campaign_timeline); } @@ -222,7 +223,7 @@ if ($post_id > 0) { } } -log_to_file("Campaign Edit template - Campaign data: ", $campaign_data); +// log_to_file("Campaign Edit template - Campaign data: ", $campaign_data); // Get domains for current user $domains = get_posts([ @@ -376,7 +377,7 @@ get_header(); ?> + class="small-text" min="1" max="52" placeholder="8" required> @@ -392,7 +393,7 @@ get_header(); ?> + class="small-text" min="5" max="1000" placeholder="50" required> diff --git a/page-email-accounts.php b/page-email-accounts.php index 2414a9f..68b4fea 100644 --- a/page-email-accounts.php +++ b/page-email-accounts.php @@ -123,7 +123,7 @@ get_header(); ?> $list = new PostTypeList('email-account', [ 'title' => 'Email Accounts', - 'no_items' => 'You haven\'t added any email accounts yet.', + 'no_items' => 'You haven\'t added any email accounts yet. Click here to create a email-account', 'delete_confirm' => 'Are you sure you want to delete this email-account? This action cannot be undone.' ]); $list->render(); diff --git a/single-campaign.php b/single-campaign.php index 735ee23..03ca530 100644 --- a/single-campaign.php +++ b/single-campaign.php @@ -1,4 +1,4 @@ -
> prefix . 'rl_mailwarmer_messages'; + $conversations_table = $wpdb->prefix . 'rl_mailwarmer_conversations'; + + // Total stats + $total_messages = $wpdb->get_var($wpdb->prepare( + "SELECT COUNT(*) FROM $messages_table WHERE campaign_id = %d", + $post_id + )); + + $sent_messages = $wpdb->get_var($wpdb->prepare( + "SELECT COUNT(*) FROM $messages_table WHERE campaign_id = %d AND status = 'sent'", + $post_id + )); + + $failed_messages = $wpdb->get_var($wpdb->prepare( + "SELECT COUNT(*) FROM $messages_table WHERE campaign_id = %d AND status = 'failed'", + $post_id + )); + + $pending_messages = $wpdb->get_var($wpdb->prepare( + "SELECT COUNT(*) FROM $messages_table WHERE campaign_id = %d AND status = 'new'", + $post_id + )); + + $total_conversations = $wpdb->get_var($wpdb->prepare( + "SELECT COUNT(*) FROM $conversations_table WHERE campaign_id = %d", + $post_id + )); + + // Email accounts used in this campaign + $email_accounts = $wpdb->get_results($wpdb->prepare( + "SELECT DISTINCT email_account_id FROM $conversations_table WHERE campaign_id = %d", + $post_id + )); + + // Upcoming messages (next 7 days) + $today = current_time('Y-m-d'); + $next_week = date('Y-m-d', strtotime('+7 days')); + $upcoming_messages = $wpdb->get_results($wpdb->prepare( + // "SELECT COUNT(*) + "SELECT id, scheduled_for_timestamp, from_email, to_email, subject + FROM $messages_table + WHERE campaign_id = %d + AND (status = 'new' OR status = 'scheduled') + AND scheduled_for_timestamp BETWEEN %s AND %s + ORDER BY scheduled_for_timestamp ASC + LIMIT 20", + $post_id, $today, $next_week + )); + + // Recently sent messages + $sent_message_list = $wpdb->get_results($wpdb->prepare( + "SELECT id, scheduled_for_timestamp, from_email, to_email, subject, status + FROM $messages_table + WHERE campaign_id = %d + AND (status = 'sent' OR status = 'failed') + ORDER BY scheduled_for_timestamp DESC + LIMIT 20", + $post_id + )); + ?> + +
+

Campaign Stats

+ + + + + + + + + + + + + + + + + + + + + +
Total Messages
Sent Messages
Failed Messages
Pending Messages
Total Conversations
+ +

Email Accounts

+ +

No email accounts associated with this campaign.

+ +
    + email_account_id); + if (!empty($email)) : + ?> +
  • + +
+ + +

Upcoming Messages (Next 7 Days)

+ +

No upcoming messages scheduled for the next 7 days.

+ + + + + + + + + + + + + + + + + + + + + +
Scheduled ForFromToSubject
scheduled_for_timestamp ? esc_html(date('Y-m-d H:i', strtotime($message->scheduled_for_timestamp))) : ''; ?>from_email ? esc_html($message->from_email) : '[Not Set Yet]'; ?>to_email ? esc_html($message->to_email) : '[Not Set Yet]'; ?>subject ? esc_html($message->subject) : '[Not Set Yet]'; ?>
+ + +

Recent Messages

+ +

No messages have been sent yet.

+ + + + + + + + + + + + + + + + + + + + + + +
Sent AtFromToSubjectStatus
scheduled_for_timestamp))); ?>from_email); ?>to_email); ?>subject); ?>status)); ?>
+ +
+ + generate_construct_sidebars(); - get_footer(); + get_footer(); \ No newline at end of file diff --git a/single-domain.php b/single-domain.php index 8e64cf1..90c8e8d 100644 --- a/single-domain.php +++ b/single-domain.php @@ -93,12 +93,15 @@ get_header(); ?>
>
+
+ +
@@ -115,14 +118,131 @@ get_header(); ?>
- -
- + prefix . 'rl_mailwarmer_conversations'; + + // First, get all email accounts for this domain + $email_account_ids = array(); + if (!empty($email_accounts)) { + foreach ($email_accounts as $account) { + $email_account_ids[] = $account->ID; + } + } + + if (!empty($email_account_ids)) { + // Convert to a comma-separated string for SQL + $email_account_ids_str = implode(',', $email_account_ids); + + // Find campaign IDs that use these email accounts + $campaign_ids = $wpdb->get_col(" + SELECT DISTINCT campaign_id + FROM $conversations_table + WHERE email_account_id IN ($email_account_ids_str) + "); + + if (!empty($campaign_ids)) { + // Get campaign details + $campaigns = get_posts([ + 'post_type' => 'campaign', + 'posts_per_page' => -1, + 'post__in' => $campaign_ids + ]); + + if (!empty($campaigns)) { + echo '

Campaigns (' . count($campaigns) . ')

'; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + + foreach ($campaigns as $campaign) { + $tracking_id = get_post_meta($campaign->ID, 'campaign_tracking_id', true); + $start_date = get_post_meta($campaign->ID, 'start_date', true); + $target_volume = get_post_meta($campaign->ID, 'target_volume', true); + + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + } + + echo '
Campaign NameTracking IDStart DateTarget VolumeActions
' . esc_html($campaign->post_title) . '' . esc_html($tracking_id) . '' . esc_html($start_date) . '' . esc_html($target_volume) . ''; + echo 'View '; + echo 'Edit'; + echo '
'; + } + } else { + echo '

No campaigns found that use email accounts from this domain.

'; + } + } else { + echo '

No campaigns found since there are no email accounts for this domain.

'; + } + + echo '

Create New Campaign

'; + ?>
@@ -137,7 +257,7 @@ get_header(); ?>
generate_construct_sidebars(); - get_footer(); + get_footer(); \ No newline at end of file diff --git a/single-email-account.php b/single-email-account.php index 30579ed..2b95aae 100644 --- a/single-email-account.php +++ b/single-email-account.php @@ -25,6 +25,72 @@ get_header(); ?> while ( have_posts() ) : the_post(); + $post_id = get_the_ID(); + $domain_id = get_post_meta($post_id, 'domain', true); + $domain_post = get_post($domain_id); + $full_name = get_post_meta($post_id, 'full_name', true); + $email_signature = get_post_meta($post_id, 'email_signature', true); + $smtp_status = get_post_meta($post_id, 'smtp_status', true); + $imap_status = get_post_meta($post_id, 'imap_status', true); + + // Get email messages for this account + global $wpdb; + $messages_table = $wpdb->prefix . 'rl_mailwarmer_messages'; + + // Count total messages + $total_messages = $wpdb->get_var($wpdb->prepare( + "SELECT COUNT(*) FROM $messages_table WHERE email_account_id = %d", + $post_id + )); + + // Count sent messages + $sent_messages = $wpdb->get_var($wpdb->prepare( + "SELECT COUNT(*) FROM $messages_table WHERE email_account_id = %d AND status = 'sent'", + $post_id + )); + + // Count failed messages + $failed_messages = $wpdb->get_var($wpdb->prepare( + "SELECT COUNT(*) FROM $messages_table WHERE email_account_id = %d AND status = 'failed'", + $post_id + )); + + // Count pending messages + $pending_messages = $wpdb->get_var($wpdb->prepare( + "SELECT COUNT(*) FROM $messages_table WHERE email_account_id = %d AND (status = 'new' OR status = 'scheduled')", + $post_id + )); + + // Calculate delivery rate + $delivery_rate = 0; + if (($sent_messages + $failed_messages) > 0) { + $delivery_rate = round(($sent_messages / ($sent_messages + $failed_messages)) * 100, 1); + } + + // Get upcoming messages (next 7 days) + $today = current_time('Y-m-d'); + $next_week = date('Y-m-d', strtotime('+7 days')); + $upcoming_messages = $wpdb->get_results($wpdb->prepare( + "SELECT id, scheduled_for_timestamp, from_email, to_email, subject + FROM $messages_table + WHERE email_account_id = %d + AND (status = 'new' OR status = 'scheduled') + AND scheduled_for_timestamp BETWEEN %s AND %s + ORDER BY scheduled_for_timestamp ASC + LIMIT 20", + $post_id, $today, $next_week + )); + + // Recently sent or failed messages + $recent_messages = $wpdb->get_results($wpdb->prepare( + "SELECT id, scheduled_for_timestamp, from_email, to_email, subject, status + FROM $messages_table + WHERE email_account_id = %d + AND (status = 'sent' OR status = 'failed') + ORDER BY scheduled_for_timestamp DESC + LIMIT 20", + $post_id + )); ?> @@ -53,8 +119,13 @@ get_header(); ?> if ( generate_show_title() ) { $params = generate_get_the_title_parameters(); - - the_title( $params['before'], $params['after'] ); + $edit_url = "/dashboard/email-accounts/edit-email-account?edit={$post_id}"; + + echo $params['before']; // Output the title before markup + echo ''; // Begin the link + the_title(); // Display the title + echo ''; // Close the link + echo $params['after']; // Output the title after markup } /** @@ -87,7 +158,153 @@ get_header(); ?> ?>
> - Hi, Bob. +
+ +
+

Account Information

+ + + + + + + + + + + + + + + + + + + + + +
Email Address
Full Name
Domain + + + post_title); ?> + + + Not set + +
SMTP Status
IMAP Status
+ + +

Email Signature

+ + +
+ +
+

Email Delivery Statistics

+ + + + + + + + + + + + + + + + + + + + + +
Total Messages
Sent Successfully
Pending Messages
Failed Messages
Delivery Rate%
+
+ +
+

Upcoming Messages (Next 7 Days)

+ +

No upcoming messages scheduled for the next 7 days.

+ + + + + + + + + + + + + + + + + + + + +
Scheduled ForFromToSubject
scheduled_for_timestamp ? esc_html(date('Y-m-d H:i', strtotime($message->scheduled_for_timestamp))) : ''; ?>from_email ? esc_html($message->from_email) : '[Not Set Yet]'; ?>to_email ? esc_html($message->to_email) : '[Not Set Yet]'; ?>subject ? esc_html($message->subject) : '[Not Set Yet]'; ?>
+ +
+ +
+

Recent Messages

+ +

No messages have been sent or failed yet.

+ + + + + + + + + + + + + + + + + + + + + + +
DateFromToSubjectStatus
scheduled_for_timestamp))); ?>from_email); ?>to_email); ?>subject); ?> + status)); ?> +
+ +
+
+
+ +
+
+ +
+
+ +
+
+
+ ?>
+ + + + generate_construct_sidebars(); - get_footer(); + get_footer(); \ No newline at end of file