mailferno-theme/single-domain.php
ruben efc50f3b4e Implement AJAX forms and dashboard modal workflow
- Added dashboard modal with multi-step entity creation
- Updated form pages to use AJAX submission
- Improved validation and user feedback on form actions

🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-03-07 07:33:32 -06:00

354 lines
No EOL
16 KiB
PHP

<?php
/**
* The Template for displaying all single domain 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 = get_the_post();
$post_id = get_the_ID();
$credentials = RL_MailWarmer_Domain_Helper::get_cloudflare_credentials($post);
?>
<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();
the_title( $params['before'], $params['after'] );
}
/**
* 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="domain-tabs">
<ul>
<li><a href="#report_tab">Health Report</a></li>
<li><a href="#account_tab">Email Accounts</a></li>
<li><a href="#campaign_tab">Campaigns</a></li>
<li><a href="#info_tab">Info</a></li>
<li><a href="#tools_tab">Tools</a></li>
</ul>
<div id="report_tab">
<?php rl_mailwarmer_render_domain_metadata_table($post); ?>
</div>
<div id="info_tab">
<table class="credentials-table">
<tr>
<th>API Email</th>
<th>API Key</th>
<th>Zone ID</th>
<th>CloudFlare Connection</th>
</tr>
<tr>
<td><?php echo $credentials ? htmlspecialchars($credentials['api_email']) : ''; ?></td>
<td><?php echo $credentials ? htmlspecialchars(mask_api_key($credentials['api_key'])) : ''; ?></td>
<td><?php echo $credentials ? htmlspecialchars($credentials['zone_id']) : ''; ?></td>
<td><?php echo htmlspecialchars(get_connection_status($credentials)); ?></td>
</tr>
</table>
</div>
<div id="account_tab">
<?php
// Get email accounts for this domain
$email_accounts = get_posts([
'post_type' => 'email-account',
'posts_per_page' => -1,
'meta_query' => [
[
'key' => 'domain',
'value' => $post_id,
'compare' => '='
]
]
]);
if (!empty($email_accounts)) {
echo '<h3>Email Accounts (' . count($email_accounts) . ')</h3>';
echo '<table class="wp-list-table widefat fixed striped">';
echo '<thead><tr>';
echo '<th>Email Address</th>';
echo '<th>Full Name</th>';
echo '<th>SMTP Status</th>';
echo '<th>IMAP Status</th>';
echo '<th>Actions</th>';
echo '</tr></thead>';
echo '<tbody>';
foreach ($email_accounts as $account) {
$full_name = get_post_meta($account->ID, 'full_name', true);
$smtp_status = get_post_meta($account->ID, 'smtp_status', true);
$imap_status = get_post_meta($account->ID, 'imap_status', true);
echo '<tr>';
echo '<td>' . esc_html($account->post_title) . '</td>';
echo '<td>' . esc_html($full_name) . '</td>';
echo '<td>' . esc_html($smtp_status) . '</td>';
echo '<td>' . esc_html($imap_status) . '</td>';
echo '<td>';
echo '<a href="' . esc_url(get_permalink($account->ID)) . '" class="button button-small">View</a> ';
echo '<a href="/dashboard/email-accounts/edit-email-account?edit=' . esc_attr($account->ID) . '" class="button button-small">Edit</a>';
echo '</td>';
echo '</tr>';
}
echo '</tbody></table>';
} else {
echo '<p>No email accounts found for this domain.</p>';
}
echo '<p><a href="/dashboard/email-accounts/edit-email-account?domain_id=' . esc_attr($post_id) . '" class="button button-primary">Create New Email Account</a></p>';
?>
</div>
<div id="campaign_tab">
<?php
// Get campaigns that use this domain's email accounts
global $wpdb;
$conversations_table = $wpdb->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 '<h3>Campaigns (' . count($campaigns) . ')</h3>';
echo '<table class="wp-list-table widefat fixed striped">';
echo '<thead><tr>';
echo '<th>Campaign Name</th>';
echo '<th>Tracking ID</th>';
echo '<th>Start Date</th>';
echo '<th>Target Volume</th>';
echo '<th>Actions</th>';
echo '</tr></thead>';
echo '<tbody>';
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 '<tr>';
echo '<td>' . esc_html($campaign->post_title) . '</td>';
echo '<td>' . esc_html($tracking_id) . '</td>';
echo '<td>' . esc_html($start_date) . '</td>';
echo '<td>' . esc_html($target_volume) . '</td>';
echo '<td>';
echo '<a href="' . esc_url(get_permalink($campaign->ID)) . '" class="button button-small">View</a> ';
echo '<a href="/dashboard/campaigns/edit-campaign?edit=' . esc_attr($campaign->ID) . '" class="button button-small">Edit</a>';
echo '</td>';
echo '</tr>';
}
echo '</tbody></table>';
}
} else {
echo '<p>No campaigns found that use email accounts from this domain.</p>';
}
} else {
echo '<p>No campaigns found since there are no email accounts for this domain.</p>';
}
echo '<p><a href="/dashboard/campaigns/edit-campaign" class="button button-primary">Create New Campaign</a></p>';
?>
</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>
</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>
jQuery(document).ready(function($) {
$('#domain-tabs').tabs();
// $('#check-domain-health-button').on('click', function (e) {
// e.preventDefault();
// var postId = <?php echo $post_id; ?>; // Get the current post ID
// var postData = {
// action: 'rl_mailwarmer_check_domain_health',
// post_id: rlMailWarmer_healthcheck.post_id,
// security: rlMailWarmer_healthcheck.nonce,
// };
// // console.log("AJAX URL: " + rlMailWarmer.ajax_url);
// // console.log("Post Action: " + postData.action);
// console.log("Post postId: " + rlMailWarmer_healthcheck.post_id);
// console.log("Post security: " + rlMailWarmer_healthcheck.post_id.nonce);
// $('#domain-health-result').html('<p>Checking domain health...</p>');
// // $.ajax({
// // url: rlMailWarmer_healthcheck.ajax_url,
// // type: 'POST',
// // data: postData,
// // success: function (response) {
// // if (response.success) {
// // $('#domain-health-result').html('<p>Report saved successfully. Post ID: ' + response.data + '</p>');
// // } else {
// // $('#domain-health-result').html('<p>Error: ' + response.data + '</p>');
// // }
// // },
// // error: function (xhr, status, error) {
// // $('#domain-health-result').html('<p>AJAX Error: ' + error + '</p>');
// // },
// // });
// });
});
</script>
<?php
/**
* generate_after_primary_content_area hook.
*
* @since 2.0
*/
do_action( 'generate_after_primary_content_area' );
generate_construct_sidebars();
get_footer();