diff --git a/page-dashboard.php b/page-dashboard.php index 978f722..f7fee87 100644 --- a/page-dashboard.php +++ b/page-dashboard.php @@ -122,6 +122,14 @@ if ($campaign_count > 0) { $onboard_steps[3] = true; } +// Enqueue styles and scripts for modal +wp_enqueue_style('mailferno-modal-style', '/wp-content/plugins/rl-mailwarmer/css/modal.css', array(), '1.0.0'); +wp_enqueue_script('dashboard-modal', '/wp-content/plugins/rl-mailwarmer/js/dashboard-modal.js', array('jquery'), '1.0.1', true); +wp_localize_script('dashboard-modal', 'dashboard_modal_vars', array( + 'ajax_url' => admin_url('admin-ajax.php'), + 'nonce' => wp_create_nonce('dashboard_modal_nonce'), +)); + get_header(); ?>
> @@ -278,6 +286,50 @@ get_header(); ?> + + +
+
+ + +
+
+
+

Create New

+ +
+
+ +
+
+
+ + +
+

What would you like to create?

+
+
+ + Domain +
+
+ + Email Account +
+
+ + Campaign +
+
+
+ + +
+ +
+
@@ -326,4 +378,4 @@ get_header(); ?> generate_construct_sidebars(); - get_footer(); + get_footer(); \ No newline at end of file diff --git a/page-edit-campaign.php b/page-edit-campaign.php index 427f140..5c61257 100644 --- a/page-edit-campaign.php +++ b/page-edit-campaign.php @@ -8,166 +8,21 @@ if (!defined('ABSPATH')) { exit; } -// log_to_file("Campaign Edit template - Loaded"); - $current_user_id = get_current_user_id(); -$calculate_timeline = true; -$message = false; $new_post = true; $campaign_enabled = true; $professions = []; - -// log_to_file("Campaign Edit template - Current user ID: $current_user_id"); -// log_to_file("Campaign Edit template - Server Request Method: ", $_SERVER['REQUEST_METHOD']); -// log_to_file("Campaign Edit template - Post Data: ", $_POST); - -// Handle form submission -if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['campaign_submit'])) { - - // log_to_file("Campaign Edit template - Handling post request"); - - $post_data = array( - 'post_title' => sanitize_text_field($_POST['campaign_name']), - 'post_type' => 'campaign', - 'post_status' => 'publish' - ); - $calculate_timeline = isset($_POST['calculate_timeline']) ? true : false; - - if (isset($_POST['post_id']) && !empty($_POST['post_id'])) { - - // log_to_file("Campaign Edit template - Updating campaign"); - $post_data['ID'] = intval($_POST['post_id']); - $post_id = wp_update_post($post_data); - $new_post = false; - $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) { - RL_MailWarmer_Campaign_Helper::generate_campaign_tracking_id($post_id); - } - } else { - // log_to_file("Campaign Edit template - Creating new campaign"); - $post_id = wp_insert_post($post_data); - RL_MailWarmer_Campaign_Helper::generate_campaign_tracking_id($post_id); - $message = ['status' => 'success', 'message' => 'Campaign added successfully.']; - } - - if (!is_wp_error($post_id)) { - - // log_to_file("Campaign Edit template - Create/update successful!"); - - $campaign_enabled = isset($_POST['enabled']) ? true : false; - // log_to_file("Campaign Edit template - 1 Campaign Enabled: {$campaign_enabled} New Post: {$new_post}"); - // var_dump($campaign_enabled); - update_post_meta($post_id, 'enabled', $campaign_enabled); - - $acf_fields = [ - 'domain_id', - // 'enabled', - 'email_accounts', - // 'num_additional_emails', - 'start_date', - 'warmup_period', - 'starting_volume', - 'target_volume', - 'weekend_reduction_factor', - 'target_profession', - 'target_profession_other', - 'campaign_conversation_topics' - ]; - - foreach ($acf_fields as $field) { - if (isset($_POST[$field])) { - // log_to_file("Campaign Edit template - Checking for $field in POST: ", $_POST[$field]); - switch ($field) { - case 'email_accounts': - $campaign_email_accounts = $_POST[$field]; - $is_limited = false; - - // Iterate through each email account ID - foreach ($campaign_email_accounts as $account_id) { - // Retrieve the 'limited_access' meta value for the current account ID - $limited_access = get_post_meta($account_id, 'limited_access', true); - - // Check if 'limited_access' is true - if ($limited_access === true || $limited_access === '1') { - $is_limited = true; - break; // Exit the loop early as we only need one true value - } - } - - // Update 'campaign_limited' for $post_id if any account is limited - if ($is_limited) { - update_post_meta($post_id, 'campaign_limited', true); - } else { - update_post_meta($post_id, 'campaign_limited', false); - } - - // Update the field as usual - update_field($field, $campaign_email_accounts, $post_id); - break; - - case 'domain_id': - // log_to_file("Campaign Edit template - Found domain in POST", $_POST['domain_id']); - try { - update_field('domain', $_POST['domain_id'], $post_id); - } catch (Exception $e) { - throw new Exception(__('fetch_dns_records - Campaign Edit template: Unable to update domain field for Campaign', 'rl-mailwarmer') . $e->getMessage()); - } - - break; - - default: - update_field($field, sanitize_text_field($_POST[$field]), $post_id); - break; - } - } - } - - - - // log_to_file("Campaign Edit template - Setting campaign owner_id to $current_user_id"); - update_post_meta($post_id, 'owner_id', $current_user_id); - - // 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); - // log_to_file("Campaign Edit template - Campaign timeline: ", $campaign_timeline); - } - - - } else { - $message = ['status' => 'error', 'message' => 'Error: ' . $post_id->get_error_message()]; - } - - if ( !(isset($_POST['stay_on_page']) && ($_POST['stay_on_page'] === 'on')) ) { - // log_to_file("Domain Edit template - stay_on_page not set; redirecting!"); - wp_redirect( get_permalink( $post_id ) ); - exit; - } - -} else { - // log_to_file("Campaign Edit template - Post request not set"); -} - // Get existing post data if editing if (isset($_GET['edit'])) { $post_id = intval($_GET['edit']); $new_post = false; $campaign_enabled = get_post_meta($post_id, 'enabled') ? get_post_meta($post_id, 'enabled', true) : false; - // log_to_file("Campaign Edit template - 2 Campaign Enabled: {$campaign_enabled} New Post: {$new_post}"); - // var_dump($campaign_enabled); - // update_post_meta($post_id, 'enabled', $campaign_enabled); } else { $post_id = 0; } $campaign_data = [ 'campaign_name' => '', - // 'enabled' => '', 'domain_id' => '', 'email_accounts' => [], 'num_additional_emails' => '', @@ -187,7 +42,6 @@ if ($post_id > 0) { $campaign_data['campaign_name'] = $post_item->post_title; foreach ($campaign_data as $key => $value) { if ($key !== 'campaign_name') { - switch ($key) { case 'domain_id': $domain_id = get_field('domain', $post_id) ? get_field('domain', $post_id) : ''; @@ -198,7 +52,6 @@ if ($post_id > 0) { case 'email_accounts': $email_accounts = get_field($key, $post_id) ? get_field($key, $post_id) : ''; - // log_to_file("Campaign Edit template - Email accounts: ", $email_accounts); $campaign_data[$key] = $email_accounts; break; @@ -211,20 +64,11 @@ if ($post_id > 0) { $campaign_data[$key] = get_field($key, $post_id); break; } - // if ($key === 'domain_id') { - // $domain_id = get_field('domain', $post_id); - // $campaign_data[$key] = $domain_id->ID; - // } else { - // $campaign_data[$key] = get_field($key, $post_id); - // } - } } } } -// log_to_file("Campaign Edit template - Campaign data: ", $campaign_data); - // Get domains for current user $domains = get_posts([ 'orderby' => 'title', @@ -238,16 +82,18 @@ $domains = get_posts([ ] ] ]); -// log_to_file("Campaign Edit template - Domains: ", $domains); // Get the list of default professions $professions = rl_get_textarea_meta_as_array('option', 'default_profession_pool'); -// log_to_file("Campaign Edit template - Professions: ", $professions); - -// log_to_file("Campaign Edit template - 3 Campaign Enabled: {$campaign_enabled} New Post: {$new_post}"); - - +// Enqueue Scripts +wp_enqueue_script('campaign-form', '/wp-content/plugins/rl-mailwarmer/js/campaign-form.js', array('jquery'), '1.0', true); +wp_localize_script('campaign-form', 'campaign_form_vars', array( + 'ajax_url' => admin_url('admin-ajax.php'), + 'nonce' => wp_create_nonce('campaign_form_nonce'), + 'delete_nonce' => wp_create_nonce('campaign_delete_nonce'), + 'campaigns_page' => site_url('/campaigns/'), +)); get_header(); ?> @@ -262,14 +108,8 @@ get_header(); ?>
>
> - -
-

- -
- + +
@@ -280,11 +120,11 @@ get_header(); ?> -
+ - +
@@ -338,9 +178,6 @@ get_header(); ?> ]); - // log_to_file("Selected email accounts: ", $selected_accounts ); - // log_to_file("User email accounts: ", $user_email_accounts); - if ($user_email_accounts) : foreach ($user_email_accounts as $account) : $account_id = $account->ID; @@ -351,14 +188,6 @@ get_header(); ?> - @@ -448,11 +277,13 @@ get_header(); ?>

- + + Delete Campaign +

-
@@ -476,73 +307,7 @@ get_header(); ?> do_action('generate_after_main_content'); ?>
- $post_title, - 'post_type' => 'domain', - 'post_status' => 'publish' - ); - - // Check if editing existing post - if (isset($_POST['post_id']) && !empty($_POST['post_id'])) { - $post_data['ID'] = intval($_POST['post_id']); - $post_id = wp_update_post($post_data); - $new_post = false; - $message = ['status' => 'success', 'message' => 'Domain updated successfully.']; - } else { - // Prepare WP_Query to check for an existing post with the same title - $args = [ - 'post_type' => 'domain', // Replace with your post type - 'post_status' => 'any', - 'title' => $post_title, - 'fields' => 'id', - 'posts_per_page' => 1 - ]; - - $query = new WP_Query($args); - - if ($query->have_posts()) { - log_to_file("Domain Edit template - Domain {$post_title} already exists: "); - $message = ['status' => 'error', 'message' => 'Domain already exists.']; - } else { - $post_id = wp_insert_post($post_data); - $new_post = true; - $message = ['status' => 'success', 'message' => 'Domain added successfully.']; - if (!is_wp_error($post_id)) { - update_post_meta($post_id, 'cloudflare_api_email', $cloudflare_email); - update_post_meta($post_id, 'cloudflare_api_key', $cloudflare_key); - update_post_meta($post_id, 'domain_in_use', $domain_in_use); - if ($new_post) { - // set the owner_id to the creator of the post if this is a new domain - update_post_meta($post_id, 'owner_id', $current_user_id); - - // Run a domain health check - $domain_report_id = RL_MailWarmer_Domain_Helper::save_domain_health_report($post_id); - } - } else { - $message = ['status' => 'error', 'message' => 'Error: ' . $post_id->get_error_message()]; - // $message = 'Error: ' . $post_id->get_error_message(); - } - - if (isset($_POST['update_dns']) && !empty($_POST['update_dns'])) { - log_to_file("Domain Edit template - Running Fix Domain"); - $results = RL_MailWarmer_Domain_Helper::fix_deliverability_dns_issues($post_id); - log_to_file("Domain Edit template - Results: ", $results); - } - - if ($domain_in_use) { - log_to_file("Domain Edit template - Domain in use: {$post_title}. Not modifying MX records"); - } else { - log_to_file("Domain Edit template - Domain not in use: {$post_title}. Setting MX to Mailferno server "); - // Set MX to 'server' of $post_id - $server = get_field('defaut_mailferno_mx', 'option'); - log_to_file("Domain Edit template - Default Mailferno MX Server: ", $server); - $update_MX_result = RL_MailWarmer_Domain_Helper::update_mx_record($post_id, $server->post_title, 0, $ttl = 3600); - log_to_file("Domain Edit template - CloudFlare Response: {$update_MX_result}"); - } - - if ( !(isset($_POST['stay_on_page']) && ($_POST['stay_on_page'] === 'on')) ) { - // log_to_file("Domain Edit template - stay_on_page not set; redirecting!"); - wp_redirect( get_permalink( $post_id ) ); - exit; - } - } - - // Reset post data - wp_reset_postdata(); - } - - -} - // Get existing post data if editing if (isset($_GET['edit'])) { $post_id = intval($_GET['edit']); - $new_post = false; + $new_post = false; } else { $post_id = 0; } @@ -120,6 +34,15 @@ if ($post_id > 0) { } } +// Enqueue Scripts +wp_enqueue_script('domain-form', '/wp-content/plugins/rl-mailwarmer/js/domain-form.js', array('jquery'), '1.0', true); +wp_localize_script('domain-form', 'domain_form_vars', array( + 'ajax_url' => admin_url('admin-ajax.php'), + 'nonce' => wp_create_nonce('domain_form_nonce'), + 'delete_nonce' => wp_create_nonce('domain_delete_nonce'), + 'domains_page' => site_url('/domains/'), +)); + get_header(); ?>
> @@ -161,21 +84,6 @@ get_header(); ?> */ do_action( 'generate_before_entry_title' ); - if ($message): ?> -
-

- -
-
>
-

- - - - - - - - -
- - - - - - - - - - - - - -
- -
- - class=""> - Warning! This will attempt to update your DNS records! - -
- - class=""> - If the domain is already in use we won't change the MX records - -
-
+

+ + + + + + + + + + + +
+ + + + + + + + + + + + + +
+ +
+ + class=""> + Warning! This will attempt to update your DNS records! + +
+ + class=""> + If the domain is already in use we won't change the MX records + +
+
-
-

CloudFlare Settings

-

Only if different than the credentials in your profile

- -
- -

- -

+
+

CloudFlare Settings

+

Only if different than the credentials in your profile

+ +
+ +

+ + + Delete Domain + +

- + -
- - -
+
+ + +
- + - +
- '', - // ) - // ); - ?>
generate_construct_sidebars(); - get_footer(); + get_footer(); \ No newline at end of file diff --git a/page-edit-email-account.php b/page-edit-email-account.php index c7aaec7..dfc3a27 100644 --- a/page-edit-email-account.php +++ b/page-edit-email-account.php @@ -9,87 +9,23 @@ if (!defined('ABSPATH')) { } $current_user_id = get_current_user_id(); -$message = false; $new_post = true; -log_to_file("Email Account Edit template - Current user ID: $current_user_id"); -log_to_file("Email Account Edit template - Server Request Method: ", $_SERVER['REQUEST_METHOD']); -log_to_file("Email Account Edit template - Post Data: ", $_POST); - -// Handle form submission -if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['email_submit']) && isset($_POST['email_address'])) { - $post_title = strtolower(sanitize_email($_POST['email_address'])); - $post_data = array( - 'post_title' => $post_title, - 'post_type' => 'email-account', - 'post_status' => 'publish' - ); - - $meta_fields = [ - 'domain_id', 'mail_password', 'full_name', 'email_signature', - 'email_provider', 'smtp_password', 'smtp_server', 'smtp_port', - 'imap_password', 'imap_server', 'imap_port' - ]; - - if (isset($_POST['post_id']) && !empty($_POST['post_id'])) { - $post_data['ID'] = intval($_POST['post_id']); - $post_id = wp_update_post($post_data); - $new_post = false; - $message = ['status' => 'success', 'message' => 'Email account updated successfully.']; - } else { - // Prepare WP_Query to check for an existing post with the same title - $args = [ - 'post_type' => 'email-account', // Replace with your post type - 'post_status' => 'any', - 'title' => $post_title, - 'fields' => 'id', - 'posts_per_page' => 1 - ]; - - $query = new WP_Query($args); - - if ($query->have_posts()) { - log_to_file("Email Account Edit template - email account {$post_title} already exists: "); - $message = ['status' => 'error', 'message' => 'Email account already exists.']; - } else { - $post_id = wp_insert_post($post_data); - $new_post = true; - $message = ['status' => 'success', 'message' => 'Email account added successfully.']; - if (!is_wp_error($post_id)) { - foreach ($meta_fields as $field) { - if (isset($_POST[$field])) { - update_post_meta($post_id, $field, sanitize_text_field($_POST[$field])); - } - } - // include new accounts in the warmup pool and set the owner_id to the creator of the post - if ($new_post) { - update_post_meta($post_id, 'owner_id', $current_user_id); - update_post_meta($post_id, 'include_in_warmup_pool', $current_user_id); - } - - } else { - $message = ['status' => 'error', 'message' => 'Error: ' . $post_id->get_error_message()]; - } - - if ( !(isset($_POST['stay_on_page']) && ($_POST['stay_on_page'] === 'on')) ) { - // log_to_file("Email Account Edit template - stay_on_page not set; redirecting!"); - wp_redirect( get_permalink( $post_id ) ); - exit; - } - } - } -} - // Get existing post data if editing if (isset($_GET['edit'])) { $post_id = intval($_GET['edit']); - $new_post = false; + $new_post = false; } else { $post_id = 0; } +if (isset($_GET['domain_id'])) { + $domain_id = intval($_GET['domain_id']); +} else { + $domain_id = ''; +} $email_data = [ 'email_address' => '', - 'domain_id' => '', + 'domain_id' => $domain_id, 'mail_password' => '', 'full_name' => '', 'email_signature' => '', @@ -136,6 +72,15 @@ $providers = get_posts([ 'posts_per_page' => -1 ]); +// Enqueue Scripts +wp_enqueue_script('email-account-form', '/wp-content/plugins/rl-mailwarmer/js/email-account-form.js', array('jquery'), '1.0', true); +wp_localize_script('email-account-form', 'email_form_vars', array( + 'ajax_url' => admin_url('admin-ajax.php'), + 'nonce' => wp_create_nonce('email_form_nonce'), + 'delete_nonce' => wp_create_nonce('email_delete_nonce'), + 'email_accounts_page' => site_url('/email-accounts/'), +)); + get_header(); ?>
> @@ -148,25 +93,19 @@ get_header(); ?>
>
> - -
-

- -
- + +

-
+ - +
@@ -284,12 +223,14 @@ get_header(); ?>

- + + +

-
name="stay_on_page" class="">
-
@@ -310,38 +250,6 @@ get_header(); ?> do_action('generate_after_main_content'); ?>
- echo '

No email accounts found for this domain.

'; } - echo '

Create New Email Account

'; + echo '

Create New Email Account

'; ?>