COMPREHENSIVE CSV IMPORT SYSTEM REDESIGN Problem Resolved: - Trainer profiles missing critical information from CSV_Trainers_Import_1Aug2025.csv - Existing import system used hardcoded data instead of reading actual CSV file - Missing 19 fields of professional information including phone numbers, websites, certifications Solution Implemented: - Complete enhanced CSV import system reading actual CSV file with 43 trainer records - Full taxonomy integration for business_type and training_audience classifications - Comprehensive field mapping for all 19 available CSV fields - Multi-value taxonomy handling for comma-separated fields - Automatic venue/organizer creation based on CSV flags Key Components Added: - includes/enhanced-csv-import-from-file.php: Main CSV import class with comprehensive processing - Updated includes/class-hvac-geocoding-ajax.php: Enhanced AJAX integration - includes/taxonomy-migration.php: Safe data migration utilities - Comprehensive error handling, progress tracking, and logging Fields Now Imported: - Contact: Name, Email, Phone, Website - Professional: Company, Role, Certification details (date, type, status) - Location: Country, State, City - Taxonomies: Business Type, Training Audience with multi-value support - System: Application Details, User ID, Venue/Organizer creation flags Testing Results: - 43 CSV rows processed successfully - 43 trainer profiles updated with enhanced data - Proper taxonomy assignments with comma-separated value handling - Automatic venue/organizer creation - Zero errors during import process - Complete data integrity preserved TAXONOMY SYSTEM ENHANCEMENTS Trainer Profile Taxonomy Implementation: - WordPress taxonomies for business_type and training_audience - Dynamic form loading from taxonomy terms with fallback support - Multi-value checkbox and radio interfaces - Safe data migration from text fields to taxonomies Template Updates: - templates/template-edit-profile.php: Dynamic taxonomy loading - templates/page-master-trainer-profile-edit.php: Enhanced taxonomy management - templates/page-master-dashboard.php: Fixed critical PHP fatal error Critical Bug Fixes: - Fixed HVAC_Community_Events::get_instance() undefined method error - Master dashboard template now uses correct instance() method - Eliminated PHP fatal errors preventing master trainer access COMPREHENSIVE TESTING & VALIDATION E2E Testing with Playwright: - 87.5% test pass rate (7/8 tests passing) - Registration form taxonomy integration verified - Profile editing with taxonomy selections confirmed - Data persistence across sessions validated - Comprehensive visual evidence captured Documentation Updates: - docs/API-REFERENCE.md: Complete CSV import AJAX endpoint documentation - docs/DEVELOPMENT-GUIDE.md: CSV import architecture and best practices - docs/README.md: Enhanced system overview with CSV import features - CLAUDE.md: Comprehensive memory entry for future reference Production Impact: - Complete trainer profiles with professional information - Enhanced business categorization through taxonomy system - Automatic event management preparation with venues/organizers - Improved master trainer dashboard functionality - Zero data loss with comprehensive error handling 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
554 lines
No EOL
28 KiB
PHP
554 lines
No EOL
28 KiB
PHP
<?php
|
|
/**
|
|
* Template Name: Master Trainer Profile Edit
|
|
* Description: Template for master trainers to edit any trainer profile
|
|
*/
|
|
|
|
// Define constant to indicate we are in a page template
|
|
define('HVAC_IN_PAGE_TEMPLATE', true);
|
|
|
|
get_header();
|
|
|
|
// Check permissions
|
|
if (!is_user_logged_in()) {
|
|
echo '<div class="container"><p>You must be logged in to view this page.</p></div>';
|
|
get_footer();
|
|
return;
|
|
}
|
|
|
|
if (!current_user_can('hvac_master_trainer') && !current_user_can('administrator')) {
|
|
echo '<div class="container"><p>You must be a master trainer or administrator to access this page.</p></div>';
|
|
get_footer();
|
|
return;
|
|
}
|
|
|
|
// Get the user ID to edit
|
|
$edit_user_id = isset($_GET['user_id']) ? intval($_GET['user_id']) : 0;
|
|
|
|
if (!$edit_user_id) {
|
|
echo '<div class="container"><p>No user specified for editing.</p></div>';
|
|
get_footer();
|
|
return;
|
|
}
|
|
|
|
// Get the profile to edit
|
|
if (!class_exists('HVAC_Trainer_Profile_Manager')) {
|
|
echo '<div class="container"><p>Profile management system is not available.</p></div>';
|
|
get_footer();
|
|
return;
|
|
}
|
|
|
|
$profile_manager = HVAC_Trainer_Profile_Manager::get_instance();
|
|
$profile = $profile_manager->get_trainer_profile($edit_user_id);
|
|
|
|
if (!$profile) {
|
|
echo '<div class="container"><p>No trainer profile found for this user.</p></div>';
|
|
get_footer();
|
|
return;
|
|
}
|
|
|
|
// Get profile metadata and user data
|
|
$profile_meta = $profile_manager->get_profile_meta($profile->ID);
|
|
$edit_user = get_userdata($edit_user_id);
|
|
|
|
if (!$edit_user) {
|
|
echo '<div class="container"><p>User not found.</p></div>';
|
|
get_footer();
|
|
return;
|
|
}
|
|
|
|
$current_user_id = get_current_user_id();
|
|
|
|
// Get coordinates if available
|
|
$coordinates = null;
|
|
$geocoding_status = ['status' => 'unknown'];
|
|
if (class_exists('HVAC_Geocoding_Service')) {
|
|
try {
|
|
$geocoding_service = HVAC_Geocoding_Service::get_instance();
|
|
$coordinates = $geocoding_service->get_coordinates($profile->ID);
|
|
$geocoding_status = $geocoding_service->get_geocoding_status($profile->ID);
|
|
} catch (Exception $e) {
|
|
// Silently handle geocoding errors
|
|
error_log('Geocoding service error in master trainer profile edit: ' . $e->getMessage());
|
|
}
|
|
}
|
|
?>
|
|
|
|
<div class="hvac-page-wrapper hvac-master-trainer-profile-edit-page">
|
|
<?php
|
|
// Display master trainer navigation menu
|
|
if (class_exists('HVAC_Menu_System')) {
|
|
HVAC_Menu_System::instance()->render_master_trainer_menu();
|
|
}
|
|
?>
|
|
|
|
<?php
|
|
// Display breadcrumbs
|
|
if (class_exists('HVAC_Breadcrumbs')) {
|
|
echo HVAC_Breadcrumbs::instance()->render_breadcrumbs();
|
|
}
|
|
?>
|
|
|
|
<div class="container">
|
|
<div class="hvac-master-trainer-profile-edit">
|
|
<div class="hvac-page-header">
|
|
<h1>Edit Trainer Profile: <?php echo esc_html($edit_user->display_name); ?></h1>
|
|
<div class="hvac-header-actions">
|
|
<a href="/master-trainer/master-dashboard/" class="hvac-button hvac-button-secondary">Back to Dashboard</a>
|
|
<?php if (get_option('hvac_default_profile_visibility') === 'public' || get_post_meta($profile->ID, 'is_public_profile', true) === '1'): ?>
|
|
<a href="<?php echo get_permalink($profile->ID); ?>" class="hvac-button hvac-button-outline" target="_blank">View Public Profile</a>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Success/Error Messages -->
|
|
<div id="hvac-profile-messages"></div>
|
|
|
|
<!-- Profile Status Overview -->
|
|
<div class="hvac-profile-status-overview">
|
|
<div class="hvac-status-grid">
|
|
<div class="hvac-status-item">
|
|
<span class="hvac-status-label">Profile Status:</span>
|
|
<span class="hvac-status-value <?php echo get_post_meta($profile->ID, 'is_public_profile', true) === '1' ? 'status-public' : 'status-private'; ?>">
|
|
<?php echo get_post_meta($profile->ID, 'is_public_profile', true) === '1' ? 'Public' : 'Private'; ?>
|
|
</span>
|
|
</div>
|
|
<div class="hvac-status-item">
|
|
<span class="hvac-status-label">Geocoding:</span>
|
|
<span class="hvac-status-value status-<?php echo esc_attr($geocoding_status['status'] ?? 'unknown'); ?>">
|
|
<?php echo esc_html(ucfirst($geocoding_status['status'] ?? 'Unknown')); ?>
|
|
</span>
|
|
</div>
|
|
<div class="hvac-status-item">
|
|
<span class="hvac-status-label">Last Updated:</span>
|
|
<span class="hvac-status-value"><?php echo human_time_diff(strtotime($profile->post_modified), current_time('timestamp')) . ' ago'; ?></span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<form id="hvac-master-profile-form" class="hvac-form" enctype="multipart/form-data">
|
|
<?php wp_nonce_field('hvac_profile_edit', 'hvac_profile_nonce'); ?>
|
|
<input type="hidden" name="edit_user_id" value="<?php echo $edit_user_id; ?>" />
|
|
<input type="hidden" name="profile_id" value="<?php echo $profile->ID; ?>" />
|
|
|
|
<!-- Profile Settings -->
|
|
<div class="hvac-form-section">
|
|
<h3>Profile Settings</h3>
|
|
|
|
<div class="hvac-form-row">
|
|
<label for="is_public_profile">Profile Visibility</label>
|
|
<select id="is_public_profile" name="is_public_profile">
|
|
<option value="0" <?php selected(get_post_meta($profile->ID, 'is_public_profile', true), '0'); ?>>Private</option>
|
|
<option value="1" <?php selected(get_post_meta($profile->ID, 'is_public_profile', true), '1'); ?>>Public</option>
|
|
</select>
|
|
<p class="hvac-field-description">Public profiles are visible in the trainer directory</p>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Certification Information -->
|
|
<div class="hvac-form-section hvac-certification-edit-section">
|
|
<h3>Certification Information <small>(Master Trainer Only)</small></h3>
|
|
|
|
<div class="hvac-form-row">
|
|
<label for="certification_status">Certification Status</label>
|
|
<select id="certification_status" name="certification_status">
|
|
<option value="">Select Status</option>
|
|
<?php
|
|
$status_options = [
|
|
'Active' => 'Active',
|
|
'Expired' => 'Expired',
|
|
'Pending' => 'Pending',
|
|
'Disabled' => 'Disabled'
|
|
];
|
|
$current_status = $profile_meta['certification_status'] ?? '';
|
|
foreach ($status_options as $value => $label) {
|
|
printf(
|
|
'<option value="%s" %s>%s</option>',
|
|
esc_attr($value),
|
|
selected($current_status, $value, false),
|
|
esc_html($label)
|
|
);
|
|
}
|
|
?>
|
|
</select>
|
|
</div>
|
|
|
|
<div class="hvac-form-row">
|
|
<label for="certification_type">Certification Type</label>
|
|
<select id="certification_type" name="certification_type">
|
|
<option value="">Select Type</option>
|
|
<?php
|
|
$type_options = [
|
|
'Certified measureQuick Trainer' => 'Certified measureQuick Trainer',
|
|
'Certified measureQuick Champion' => 'Certified measureQuick Champion'
|
|
];
|
|
$current_type = $profile_meta['certification_type'] ?? '';
|
|
foreach ($type_options as $value => $label) {
|
|
printf(
|
|
'<option value="%s" %s>%s</option>',
|
|
esc_attr($value),
|
|
selected($current_type, $value, false),
|
|
esc_html($label)
|
|
);
|
|
}
|
|
?>
|
|
</select>
|
|
</div>
|
|
|
|
<div class="hvac-form-row">
|
|
<label for="date_certified">Date Certified</label>
|
|
<input type="date" id="date_certified" name="date_certified"
|
|
value="<?php echo esc_attr($profile_meta['date_certified'] ?? ''); ?>" />
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Personal Information -->
|
|
<div class="hvac-form-section">
|
|
<h3>Personal Information</h3>
|
|
|
|
<div class="hvac-form-row hvac-form-row-half">
|
|
<div>
|
|
<label for="trainer_first_name">First Name *</label>
|
|
<input type="text" id="trainer_first_name" name="trainer_first_name" required
|
|
value="<?php echo esc_attr($profile_meta['trainer_first_name'] ?? $edit_user->first_name); ?>" />
|
|
</div>
|
|
<div>
|
|
<label for="trainer_last_name">Last Name *</label>
|
|
<input type="text" id="trainer_last_name" name="trainer_last_name" required
|
|
value="<?php echo esc_attr($profile_meta['trainer_last_name'] ?? $edit_user->last_name); ?>" />
|
|
</div>
|
|
</div>
|
|
|
|
<div class="hvac-form-row">
|
|
<label for="trainer_display_name">Display Name *</label>
|
|
<input type="text" id="trainer_display_name" name="trainer_display_name" required
|
|
value="<?php echo esc_attr($profile_meta['trainer_display_name'] ?? $edit_user->display_name); ?>" />
|
|
</div>
|
|
|
|
<div class="hvac-form-row">
|
|
<label for="linkedin_profile_url">LinkedIn Profile URL</label>
|
|
<input type="url" id="linkedin_profile_url" name="linkedin_profile_url"
|
|
value="<?php echo esc_attr($profile_meta['linkedin_profile_url'] ?? ''); ?>"
|
|
placeholder="https://linkedin.com/in/username" />
|
|
</div>
|
|
|
|
<div class="hvac-form-row">
|
|
<label for="biographical_info">Biographical Information</label>
|
|
<textarea id="biographical_info" name="biographical_info" rows="6"><?php echo esc_textarea($profile->post_content); ?></textarea>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Professional Information -->
|
|
<div class="hvac-form-section">
|
|
<h3>Professional Information</h3>
|
|
|
|
<div class="hvac-form-row">
|
|
<label for="personal_accreditation">Personal Accreditation</label>
|
|
<textarea id="personal_accreditation" name="personal_accreditation" rows="4"><?php echo esc_textarea($profile_meta['personal_accreditation'] ?? ''); ?></textarea>
|
|
</div>
|
|
|
|
<div class="hvac-form-row">
|
|
<label for="training_audience">Training Audience</label>
|
|
<div class="hvac-checkbox-group">
|
|
<?php
|
|
$audience_terms = get_terms(['taxonomy' => 'training_audience', 'hide_empty' => false]);
|
|
$current_audience_terms = get_the_terms($profile->ID, 'training_audience');
|
|
$current_audience_names = $current_audience_terms && !is_wp_error($current_audience_terms)
|
|
? wp_list_pluck($current_audience_terms, 'name') : [];
|
|
|
|
if (!is_wp_error($audience_terms) && !empty($audience_terms)) {
|
|
foreach ($audience_terms as $term) {
|
|
printf(
|
|
'<label><input type="checkbox" name="training_audience[]" value="%s" %s> %s</label>',
|
|
esc_attr($term->name),
|
|
checked(in_array($term->name, $current_audience_names), true, false),
|
|
esc_html($term->name)
|
|
);
|
|
}
|
|
}
|
|
?>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="hvac-form-row">
|
|
<label for="training_formats">Training Formats</label>
|
|
<div class="hvac-checkbox-group">
|
|
<?php
|
|
$format_terms = get_terms(['taxonomy' => 'training_formats', 'hide_empty' => false]);
|
|
$current_format_terms = get_the_terms($profile->ID, 'training_formats');
|
|
$current_format_names = $current_format_terms && !is_wp_error($current_format_terms)
|
|
? wp_list_pluck($current_format_terms, 'name') : [];
|
|
|
|
if (!is_wp_error($format_terms) && !empty($format_terms)) {
|
|
foreach ($format_terms as $term) {
|
|
printf(
|
|
'<label><input type="checkbox" name="training_formats[]" value="%s" %s> %s</label>',
|
|
esc_attr($term->name),
|
|
checked(in_array($term->name, $current_format_names), true, false),
|
|
esc_html($term->name)
|
|
);
|
|
}
|
|
}
|
|
?>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="hvac-form-row">
|
|
<label for="training_locations">Training Locations</label>
|
|
<div class="hvac-checkbox-group">
|
|
<?php
|
|
$location_terms = get_terms(['taxonomy' => 'training_locations', 'hide_empty' => false]);
|
|
$current_location_terms = get_the_terms($profile->ID, 'training_locations');
|
|
$current_location_names = $current_location_terms && !is_wp_error($current_location_terms)
|
|
? wp_list_pluck($current_location_terms, 'name') : [];
|
|
|
|
if (!is_wp_error($location_terms) && !empty($location_terms)) {
|
|
foreach ($location_terms as $term) {
|
|
printf(
|
|
'<label><input type="checkbox" name="training_locations[]" value="%s" %s> %s</label>',
|
|
esc_attr($term->name),
|
|
checked(in_array($term->name, $current_location_names), true, false),
|
|
esc_html($term->name)
|
|
);
|
|
}
|
|
}
|
|
?>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="hvac-form-row">
|
|
<label for="training_resources">Training Resources</label>
|
|
<div class="hvac-checkbox-group">
|
|
<?php
|
|
$resource_terms = get_terms(['taxonomy' => 'training_resources', 'hide_empty' => false]);
|
|
$current_resource_terms = get_the_terms($profile->ID, 'training_resources');
|
|
$current_resource_names = $current_resource_terms && !is_wp_error($current_resource_terms)
|
|
? wp_list_pluck($current_resource_terms, 'name') : [];
|
|
|
|
if (!is_wp_error($resource_terms) && !empty($resource_terms)) {
|
|
foreach ($resource_terms as $term) {
|
|
printf(
|
|
'<label><input type="checkbox" name="training_resources[]" value="%s" %s> %s</label>',
|
|
esc_attr($term->name),
|
|
checked(in_array($term->name, $current_resource_names), true, false),
|
|
esc_html($term->name)
|
|
);
|
|
}
|
|
}
|
|
?>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Business Information -->
|
|
<div class="hvac-form-section">
|
|
<h3>Business Information</h3>
|
|
|
|
<div class="hvac-form-row">
|
|
<label for="business_type">Business Type</label>
|
|
<select id="business_type" name="business_type">
|
|
<option value="">Select Business Type</option>
|
|
<?php
|
|
$business_terms = get_terms(['taxonomy' => 'business_type', 'hide_empty' => false]);
|
|
$current_terms = get_the_terms($profile->ID, 'business_type');
|
|
$current_business_type = $current_terms && !is_wp_error($current_terms) ? $current_terms[0]->name : '';
|
|
|
|
foreach ($business_terms as $term) {
|
|
printf(
|
|
'<option value="%s" %s>%s</option>',
|
|
esc_attr($term->name),
|
|
selected($current_business_type, $term->name, false),
|
|
esc_html($term->name)
|
|
);
|
|
}
|
|
?>
|
|
</select>
|
|
</div>
|
|
|
|
<div class="hvac-form-row">
|
|
<label for="annual_revenue_target">Annual Revenue Target</label>
|
|
<input type="number" id="annual_revenue_target" name="annual_revenue_target"
|
|
value="<?php echo esc_attr($profile_meta['annual_revenue_target'] ?? ''); ?>"
|
|
placeholder="Enter amount in USD" />
|
|
</div>
|
|
|
|
<div class="hvac-form-row">
|
|
<label for="application_details">Application Details</label>
|
|
<textarea id="application_details" name="application_details" rows="4"><?php echo esc_textarea($profile_meta['application_details'] ?? ''); ?></textarea>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Location Information -->
|
|
<div class="hvac-form-section">
|
|
<h3>Location Information</h3>
|
|
|
|
<div class="hvac-form-row">
|
|
<label for="trainer_city">City</label>
|
|
<input type="text" id="trainer_city" name="trainer_city"
|
|
value="<?php echo esc_attr($profile_meta['trainer_city'] ?? ''); ?>" />
|
|
</div>
|
|
|
|
<div class="hvac-form-row hvac-form-row-half">
|
|
<div>
|
|
<label for="trainer_state">State/Province</label>
|
|
<input type="text" id="trainer_state" name="trainer_state"
|
|
value="<?php echo esc_attr($profile_meta['trainer_state'] ?? ''); ?>" />
|
|
</div>
|
|
<div>
|
|
<label for="trainer_country">Country</label>
|
|
<select id="trainer_country" name="trainer_country">
|
|
<option value="">Select Country</option>
|
|
<?php
|
|
$countries = [
|
|
'United States' => 'United States',
|
|
'Canada' => 'Canada',
|
|
'United Kingdom' => 'United Kingdom',
|
|
'Australia' => 'Australia'
|
|
];
|
|
$current_country = $profile_meta['trainer_country'] ?? '';
|
|
|
|
foreach ($countries as $code => $name) {
|
|
printf(
|
|
'<option value="%s" %s>%s</option>',
|
|
esc_attr($code),
|
|
selected($current_country, $code, false),
|
|
esc_html($name)
|
|
);
|
|
}
|
|
?>
|
|
</select>
|
|
</div>
|
|
</div>
|
|
|
|
<?php if ($coordinates): ?>
|
|
<div class="hvac-form-row">
|
|
<label>Coordinates (Auto-generated)</label>
|
|
<div class="hvac-coordinates-display">
|
|
<strong>Latitude:</strong> <?php echo esc_html($coordinates['latitude']); ?><br>
|
|
<strong>Longitude:</strong> <?php echo esc_html($coordinates['longitude']); ?><br>
|
|
<strong>Formatted Address:</strong> <?php echo esc_html($coordinates['formatted_address'] ?? 'N/A'); ?><br>
|
|
<strong>Last Updated:</strong> <?php echo $coordinates['last_geocoded'] ? human_time_diff($coordinates['last_geocoded'], current_time('timestamp')) . ' ago' : 'Never'; ?>
|
|
</div>
|
|
<button type="button" id="re-geocode" class="hvac-button hvac-button-small">Re-geocode Address</button>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
|
|
<!-- Auto-save indicator -->
|
|
<div id="hvac-autosave-indicator" class="hvac-autosave-indicator" style="display: none;">
|
|
<span class="hvac-autosave-text">Auto-saved</span>
|
|
</div>
|
|
|
|
<!-- Unsaved changes indicator -->
|
|
<div id="hvac-unsaved-indicator" class="hvac-unsaved-indicator" style="display: none;">
|
|
<span class="hvac-unsaved-text">You have unsaved changes</span>
|
|
</div>
|
|
|
|
<div class="hvac-form-actions">
|
|
<button type="submit" class="hvac-button hvac-button-primary">Save Profile Changes</button>
|
|
<a href="/master-trainer/master-dashboard/" class="hvac-button hvac-button-secondary">Cancel</a>
|
|
</div>
|
|
</form>
|
|
|
|
<!-- Activity Log -->
|
|
<div class="hvac-profile-activity-log">
|
|
<h3>Recent Profile Activity</h3>
|
|
<div class="hvac-activity-list">
|
|
<div class="hvac-activity-item">
|
|
<span class="hvac-activity-message">Profile last modified by <?php echo esc_html($edit_user->display_name); ?></span>
|
|
<span class="hvac-activity-time"><?php echo human_time_diff(strtotime($profile->post_modified), current_time('timestamp')); ?> ago</span>
|
|
</div>
|
|
<?php if (!empty($geocoding_status['last_success'])): ?>
|
|
<div class="hvac-activity-item">
|
|
<span class="hvac-activity-message">Location geocoded successfully</span>
|
|
<span class="hvac-activity-time"><?php echo human_time_diff($geocoding_status['last_success'], current_time('timestamp')); ?> ago</span>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
// Initialize form state management
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
// Auto-save functionality will be added via separate JS file
|
|
const form = document.getElementById('hvac-master-profile-form');
|
|
const saveButton = form.querySelector('button[type="submit"]');
|
|
const originalButtonText = saveButton.textContent;
|
|
|
|
form.addEventListener('submit', function(e) {
|
|
e.preventDefault();
|
|
|
|
saveButton.textContent = 'Saving...';
|
|
saveButton.disabled = true;
|
|
|
|
const formData = new FormData(form);
|
|
formData.append('action', 'hvac_save_trainer_profile');
|
|
|
|
fetch(hvac_ajax.ajax_url, {
|
|
method: 'POST',
|
|
body: formData
|
|
})
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
const messagesDiv = document.getElementById('hvac-profile-messages');
|
|
|
|
if (data.success) {
|
|
messagesDiv.innerHTML = '<div class="notice notice-success"><p>Profile updated successfully!</p></div>';
|
|
|
|
// Hide unsaved changes indicator
|
|
document.getElementById('hvac-unsaved-indicator').style.display = 'none';
|
|
} else {
|
|
messagesDiv.innerHTML = '<div class="notice notice-error"><p>Error: ' + (data.data || 'Unknown error occurred') + '</p></div>';
|
|
}
|
|
|
|
// Scroll to messages
|
|
messagesDiv.scrollIntoView({ behavior: 'smooth' });
|
|
})
|
|
.catch(error => {
|
|
document.getElementById('hvac-profile-messages').innerHTML = '<div class="notice notice-error"><p>Network error occurred. Please try again.</p></div>';
|
|
})
|
|
.finally(() => {
|
|
saveButton.textContent = originalButtonText;
|
|
saveButton.disabled = false;
|
|
});
|
|
});
|
|
|
|
// Re-geocode button functionality
|
|
const regeocodeBUtton = document.getElementById('re-geocode');
|
|
if (regeocodeBUtton) {
|
|
regeocodeBUtton.addEventListener('click', function() {
|
|
this.textContent = 'Geocoding...';
|
|
this.disabled = true;
|
|
|
|
const formData = new FormData();
|
|
formData.append('action', 'hvac_regeocode_profile');
|
|
formData.append('profile_id', document.querySelector('input[name="profile_id"]').value);
|
|
formData.append('nonce', document.querySelector('input[name="hvac_profile_nonce"]').value);
|
|
|
|
fetch(hvac_ajax.ajax_url, {
|
|
method: 'POST',
|
|
body: formData
|
|
})
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
if (data.success) {
|
|
location.reload(); // Reload to show updated coordinates
|
|
} else {
|
|
alert('Geocoding failed: ' + (data.data || 'Unknown error'));
|
|
}
|
|
})
|
|
.finally(() => {
|
|
this.textContent = 'Re-geocode Address';
|
|
this.disabled = false;
|
|
});
|
|
});
|
|
}
|
|
});
|
|
</script>
|
|
|
|
<?php
|
|
get_footer();
|
|
?>
|