- Added Check Connection button that tests email account connectivity - Added Start Campaign button that redirects to campaign creation with email pre-selected - Added AJAX functionality to display connection test results 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
426 lines
No EOL
18 KiB
PHP
426 lines
No EOL
18 KiB
PHP
<?php
|
|
/**
|
|
* The Template for displaying all single email-account posts.
|
|
*
|
|
* @package GeneratePress
|
|
*/
|
|
|
|
if ( ! defined( 'ABSPATH' ) ) {
|
|
exit; // Exit if accessed directly.
|
|
}
|
|
|
|
get_header(); ?>
|
|
|
|
<div <?php generate_do_attr( 'content' ); ?>>
|
|
<main <?php generate_do_attr( 'main' ); ?>>
|
|
<?php
|
|
/**
|
|
* generate_before_main_content hook.
|
|
*
|
|
* @since 0.1
|
|
*/
|
|
do_action( 'generate_before_main_content' );
|
|
|
|
if ( generate_has_default_loop() ) {
|
|
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
|
|
));
|
|
|
|
?>
|
|
|
|
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?> <?php generate_do_microdata( 'article' ); ?>>
|
|
<div class="inside-article">
|
|
<?php
|
|
/**
|
|
* generate_before_content hook.
|
|
*
|
|
* @since 0.1
|
|
*
|
|
* @hooked generate_featured_page_header_inside_single - 10
|
|
*/
|
|
do_action( 'generate_before_content' );
|
|
|
|
if ( generate_show_entry_header() ) :
|
|
?>
|
|
<header <?php generate_do_attr( 'entry-header' ); ?>>
|
|
<?php
|
|
/**
|
|
* generate_before_entry_title hook.
|
|
*
|
|
* @since 0.1
|
|
*/
|
|
do_action( 'generate_before_entry_title' );
|
|
|
|
if ( generate_show_title() ) {
|
|
$params = generate_get_the_title_parameters();
|
|
$edit_url = "/dashboard/email-accounts/edit-email-account?edit={$post_id}";
|
|
|
|
echo $params['before']; // Output the title before markup
|
|
echo '<a href="' . esc_url( $edit_url ) . '">'; // Begin the link
|
|
the_title(); // Display the title
|
|
echo '</a>'; // Close the link
|
|
echo $params['after']; // Output the title after markup
|
|
}
|
|
|
|
/**
|
|
* generate_after_entry_title hook.
|
|
*
|
|
* @since 0.1
|
|
*
|
|
* @hooked generate_post_meta - 10
|
|
*/
|
|
do_action( 'generate_after_entry_title' );
|
|
?>
|
|
</header>
|
|
<?php
|
|
endif;
|
|
|
|
/**
|
|
* generate_after_entry_header hook.
|
|
*
|
|
* @since 0.1
|
|
*
|
|
* @hooked generate_post_image - 10
|
|
*/
|
|
do_action( 'generate_after_entry_header' );
|
|
|
|
$itemprop = '';
|
|
|
|
if ( 'microdata' === generate_get_schema_type() ) {
|
|
$itemprop = ' itemprop="text"';
|
|
}
|
|
?>
|
|
|
|
<div class="entry-content"<?php echo $itemprop; // phpcs:ignore -- No escaping needed. ?>>
|
|
<div id="email-account-tabs">
|
|
<ul>
|
|
<li><a href="#info_tab">Account Info</a></li>
|
|
<li><a href="#stats_tab">Stats</a></li>
|
|
<li><a href="#upcoming_tab">Upcoming Messages</a></li>
|
|
<li><a href="#recent_tab">Recent Messages</a></li>
|
|
<li><a href="#tools_tab">Tools</a></li>
|
|
</ul>
|
|
<div id="info_tab">
|
|
<h3>Account Information</h3>
|
|
<table class="wp-list-table widefat fixed striped">
|
|
<tr>
|
|
<th>Email Address</th>
|
|
<td><?php echo esc_html(get_the_title()); ?></td>
|
|
</tr>
|
|
<tr>
|
|
<th>Full Name</th>
|
|
<td><?php echo esc_html($full_name); ?></td>
|
|
</tr>
|
|
<tr>
|
|
<th>Domain</th>
|
|
<td>
|
|
<?php if ($domain_post) : ?>
|
|
<a href="<?php echo esc_url(get_permalink($domain_post->ID)); ?>">
|
|
<?php echo esc_html($domain_post->post_title); ?>
|
|
</a>
|
|
<?php else : ?>
|
|
Not set
|
|
<?php endif; ?>
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<th>SMTP Status</th>
|
|
<td><?php echo esc_html($smtp_status); ?></td>
|
|
</tr>
|
|
<tr>
|
|
<th>IMAP Status</th>
|
|
<td><?php echo esc_html($imap_status); ?></td>
|
|
</tr>
|
|
</table>
|
|
|
|
<?php if (!empty($email_signature)) : ?>
|
|
<h3>Email Signature</h3>
|
|
<div class="email-signature-preview">
|
|
<?php echo wp_kses_post($email_signature); ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
|
|
<div id="stats_tab">
|
|
<h3>Email Delivery Statistics</h3>
|
|
<table class="wp-list-table widefat fixed striped">
|
|
<tr>
|
|
<th>Total Messages</th>
|
|
<td><?php echo esc_html($total_messages); ?></td>
|
|
</tr>
|
|
<tr>
|
|
<th>Sent Successfully</th>
|
|
<td><?php echo esc_html($sent_messages); ?></td>
|
|
</tr>
|
|
<tr>
|
|
<th>Pending Messages</th>
|
|
<td><?php echo esc_html($pending_messages); ?></td>
|
|
</tr>
|
|
<tr>
|
|
<th>Failed Messages</th>
|
|
<td><?php echo esc_html($failed_messages); ?></td>
|
|
</tr>
|
|
<tr>
|
|
<th>Delivery Rate</th>
|
|
<td><?php echo esc_html($delivery_rate); ?>%</td>
|
|
</tr>
|
|
</table>
|
|
</div>
|
|
|
|
<div id="upcoming_tab">
|
|
<h3>Upcoming Messages (Next 7 Days)</h3>
|
|
<?php if (empty($upcoming_messages)) : ?>
|
|
<p>No upcoming messages scheduled for the next 7 days.</p>
|
|
<?php else : ?>
|
|
<table class="wp-list-table widefat fixed striped">
|
|
<thead>
|
|
<tr>
|
|
<th>Scheduled For</th>
|
|
<th>From</th>
|
|
<th>To</th>
|
|
<th>Subject</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ($upcoming_messages as $message) : ?>
|
|
<tr>
|
|
<td><?php echo $message->scheduled_for_timestamp ? esc_html(date('Y-m-d H:i', strtotime($message->scheduled_for_timestamp))) : ''; ?></td>
|
|
<td><?php echo $message->from_email ? esc_html($message->from_email) : '[Not Set Yet]'; ?></td>
|
|
<td><?php echo $message->to_email ? esc_html($message->to_email) : '[Not Set Yet]'; ?></td>
|
|
<td><?php echo $message->subject ? esc_html($message->subject) : '[Not Set Yet]'; ?></td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
<?php endif; ?>
|
|
</div>
|
|
|
|
<div id="recent_tab">
|
|
<h3>Recent Messages</h3>
|
|
<?php if (empty($recent_messages)) : ?>
|
|
<p>No messages have been sent or failed yet.</p>
|
|
<?php else : ?>
|
|
<table class="wp-list-table widefat fixed striped">
|
|
<thead>
|
|
<tr>
|
|
<th>Date</th>
|
|
<th>From</th>
|
|
<th>To</th>
|
|
<th>Subject</th>
|
|
<th>Status</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ($recent_messages as $message) : ?>
|
|
<tr>
|
|
<td><?php echo esc_html(date('Y-m-d H:i', strtotime($message->scheduled_for_timestamp))); ?></td>
|
|
<td><?php echo esc_html($message->from_email); ?></td>
|
|
<td><?php echo esc_html($message->to_email); ?></td>
|
|
<td><?php echo esc_html($message->subject); ?></td>
|
|
<td class="status-<?php echo esc_attr(strtolower($message->status)); ?>">
|
|
<?php echo esc_html(ucfirst($message->status)); ?>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
<?php endif; ?>
|
|
</div>
|
|
<div id="tools_tab">
|
|
<div>
|
|
<?php //rl_mailwarmer_check_domain_health_box_callback($post); ?>
|
|
</div>
|
|
<div>
|
|
<?php //rl_mailwarmer_render_fix_deliverability_dns_issues_box($post); ?>
|
|
</div>
|
|
<div class="account-tools">
|
|
<button id="check-connection-btn" class="button button-primary">Check Connection</button>
|
|
<a href="<?php echo esc_url('/dashboard/campaigns/edit-campaign?Email_ID=' . $post_id); ?>" class="button button-secondary">Start Campaign</a>
|
|
</div>
|
|
<div id="connection-check-result"></div>
|
|
</div>
|
|
</div>
|
|
|
|
<?php
|
|
the_content();
|
|
|
|
wp_link_pages(
|
|
array(
|
|
'before' => '<div class="page-links">' . __( 'Pages:', 'generatepress' ),
|
|
'after' => '</div>',
|
|
)
|
|
);
|
|
?>
|
|
</div>
|
|
|
|
<?php
|
|
/**
|
|
* generate_after_entry_content hook.
|
|
*
|
|
* @since 0.1
|
|
*
|
|
* @hooked generate_footer_meta - 10
|
|
*/
|
|
do_action( 'generate_after_entry_content' );
|
|
|
|
/**
|
|
* generate_after_content hook.
|
|
*
|
|
* @since 0.1
|
|
*/
|
|
do_action( 'generate_after_content' );
|
|
?>
|
|
</div>
|
|
</article>
|
|
|
|
<?php
|
|
|
|
endwhile;
|
|
}
|
|
|
|
/**
|
|
* generate_after_main_content hook.
|
|
*
|
|
* @since 0.1
|
|
*/
|
|
do_action( 'generate_after_main_content' );
|
|
?>
|
|
</main>
|
|
</div>
|
|
|
|
<script>
|
|
var ajaxurl = '<?php echo admin_url('admin-ajax.php'); ?>';
|
|
|
|
jQuery(document).ready(function($) {
|
|
// Initialize tabs
|
|
$('#email-account-tabs').tabs();
|
|
|
|
// Add color coding for status
|
|
$('.status-sent').css('color', 'green');
|
|
$('.status-failed').css('color', 'red');
|
|
$('.status-pending').css('color', 'orange');
|
|
|
|
// Handle Check Connection button click
|
|
$('#check-connection-btn').on('click', function(e) {
|
|
e.preventDefault();
|
|
var button = $(this);
|
|
var resultContainer = $('#connection-check-result');
|
|
|
|
// Disable button and show loading state
|
|
button.prop('disabled', true).text('Checking...');
|
|
resultContainer.html('<p>Checking connection...</p>');
|
|
|
|
// Make AJAX call to check connection
|
|
$.ajax({
|
|
url: ajaxurl,
|
|
type: 'POST',
|
|
data: {
|
|
action: 'rl_mailwarmer_check_mail_login',
|
|
post_id: <?php echo intval($post_id); ?>,
|
|
security: '<?php echo wp_create_nonce('check_mail_login_nonce'); ?>'
|
|
},
|
|
success: function(response) {
|
|
if (response.success) {
|
|
resultContainer.html('<p style="color: green;"><strong>Success:</strong> ' + JSON.stringify(response.data) + '</p>');
|
|
} else {
|
|
resultContainer.html('<p style="color: red;"><strong>Error:</strong> ' + response.data + '</p>');
|
|
}
|
|
},
|
|
error: function() {
|
|
resultContainer.html('<p style="color: red;"><strong>Error:</strong> Connection check failed. Please try again.</p>');
|
|
},
|
|
complete: function() {
|
|
// Re-enable button
|
|
button.prop('disabled', false).text('Check Connection');
|
|
}
|
|
});
|
|
});
|
|
});
|
|
</script>
|
|
|
|
<style>
|
|
.email-signature-preview {
|
|
border: 1px solid #ddd;
|
|
padding: 15px;
|
|
background-color: #f9f9f9;
|
|
margin-bottom: 20px;
|
|
}
|
|
</style>
|
|
|
|
<?php
|
|
/**
|
|
* generate_after_primary_content_area hook.
|
|
*
|
|
* @since 2.0
|
|
*/
|
|
do_action( 'generate_after_primary_content_area' );
|
|
|
|
generate_construct_sidebars();
|
|
|
|
get_footer();
|