upskill-event-manager/templates/page-tec-edit-event.php
ben ef206a7228 feat: complete event edit page modernization with feature parity
Major architectural upgrade replacing legacy iframe-based edit forms with
native HVAC form builder integration, achieving complete feature parity
with the create page.

## Core Infrastructure Extensions

### HVAC_Event_Form_Builder Extensions
- Added edit_event_form() method for edit mode initialization
- Added load_event_data() for fetching and formatting existing event data
- Added populate_form_fields() for pre-populating form with event data
- Added edit mode tracking with is_edit_mode and editing_event_id properties

### HVAC_Event_Form_Handler Extensions
- Added update_event() method for processing edit form submissions
- Added validate_update_permissions() for secure edit access control
- Added get_event_data_for_editing() for formatted data retrieval
- Added validate_and_sanitize_update() for edit-specific validation

## Template Modernization

### Legacy Architecture Replacement
- Replaced iframe embedding with native HVAC form builder
- Updated page-tec-edit-event.php with modern form integration
- Fixed template loading in class-hvac-community-events.php
- Resolved URL routing and content injection issues

### Security Enhancements
- Fixed nonce mismatch between form generation and validation
- Implemented proper permission checking for event editing
- Added comprehensive error handling and user feedback
- Ensured secure form submission processing

## Feature Parity Achievement

### Modern Features Integration
- AI-powered content generation for event descriptions
- Featured image editing with WordPress media integration
- Searchable selectors with autocomplete for venues/organizers
- Advanced options toggle with field visibility controls
- Modal creation forms for inline venue/organizer management
- TinyMCE rich text editor for event descriptions
- Comprehensive input validation with real-time feedback

### User Experience Improvements
- Consistent form styling and interaction patterns
- Pre-populated form fields with existing event data
- Modern navigation and breadcrumb integration
- Success/error feedback with user-friendly messages
- Quick action buttons for common workflows

## Technical Implementation

### Files Modified
- includes/class-hvac-event-form-builder.php (extended with edit methods)
- includes/class-hvac-event-form-handler.php (added update functionality)
- templates/page-tec-edit-event.php (complete modernization)
- includes/class-hvac-community-events.php (fixed template loading)
- Status.md (updated implementation status)
- docs/EDIT-PAGE-REFACTORING-ANALYSIS.md (comprehensive analysis)

### Architecture Improvements
- Native form builder replaces iframe limitations
- Event data pre-population and field mapping
- WordPress TinyMCE editor integration
- Modern JavaScript event handling
- Improved error handling and validation

## Testing & Validation

### Comprehensive Testing Completed
- Form rendering with real event data validation
- Form submission and update processing verification
- All modern features tested (AI, images, selectors, modals)
- Permission system verified with different user roles
- Security nonce validation and CSRF protection confirmed
- Template loading and URL routing validated

### Issues Resolved
- Security nonce mismatch causing form submission failures
- Template loading mechanism for edit page URL routing
- Event data pre-population and field mapping
- Form builder constructor parameter consistency
- Content injection system integration

## Impact & Results

### Refactoring Analysis Results
- 14 identified refactoring opportunities: ALL RESOLVED
- 4 Critical issues: FIXED (missing edit methods, update methods, legacy architecture, data pre-population)
- 5 High Priority gaps: IMPLEMENTED (AI assistance, featured images, searchable selectors, advanced options, modal creation)
- 4 Medium Priority issues: ADDRESSED (TinyMCE editor, form validation, error handling, styling consistency)
- 1 Low Priority item: COMPLETED

### Feature Parity Metrics
-  Native form builder replaces iframe approach
-  Complete feature parity with create page achieved
-  All 14 identified issues resolved
-  Backward URL compatibility maintained
-  TEC integration preserved
-  Modern features accessible (AI, images, advanced options)
-  Real-time validation and error feedback implemented

This modernization eliminates the legacy iframe limitations and provides
users with the same advanced functionality available on the create page,
ensuring a consistent and powerful event management experience.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-28 08:12:14 -03:00

265 lines
No EOL
7.4 KiB
PHP

<?php
/**
* Template Name: TEC Edit Event
* Description: Native HVAC form builder for editing training events
*/
// Define constant to indicate we are in a page template
define('HVAC_IN_PAGE_TEMPLATE', true);
// Check if user is logged in
if (!is_user_logged_in()) {
wp_redirect(home_url('/training-login/'));
exit;
}
get_header();
// Get event ID from URL
$event_id = isset($_GET['event_id']) ? intval($_GET['event_id']) : 0;
if (!$event_id) {
// Try to get from URL path
$url_path = trim(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH), '/');
if (preg_match('/edit\/(\d+)/', $url_path, $matches)) {
$event_id = intval($matches[1]);
}
}
// Handle form submission
$form_success = false;
$form_error = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['form_mode']) && $_POST['form_mode'] === 'edit') {
// Verify nonce
if (wp_verify_nonce($_POST['hvac_event_form_nonce'], 'hvac_event_form')) {
// Process the form using the form handler
$result = HVAC_Event_Form_Handler::update_event($event_id, $_POST);
if (is_wp_error($result)) {
$form_error = $result->get_error_message();
} else {
$form_success = true;
// Redirect to prevent resubmission
wp_redirect(add_query_arg('updated', '1', $_SERVER['REQUEST_URI']));
exit;
}
} else {
$form_error = 'Security check failed. Please try again.';
}
}
// Verify user can edit this event using the form handler's permission system
$can_edit = false;
$event = null;
if ($event_id) {
$can_edit = HVAC_Event_Form_Handler::validate_update_permissions($event_id, get_current_user_id());
if ($can_edit) {
$event = get_post($event_id);
}
}
?>
<style>
.hvac-tec-wrapper {
max-width: 1200px;
margin: 0 auto;
padding: 20px;
}
.hvac-tec-wrapper .hvac-page-header {
margin-bottom: 30px;
}
.hvac-tec-wrapper h1 {
color: #1a1a1a;
font-size: 32px;
margin-bottom: 10px;
}
.hvac-page-description {
color: #666;
font-size: 16px;
margin-bottom: 30px;
}
.hvac-event-meta {
background: #f7f7f7;
padding: 15px;
border-radius: 4px;
margin-bottom: 20px;
}
.hvac-event-meta span {
display: inline-block;
margin-right: 20px;
color: #666;
}
.hvac-event-meta strong {
color: #333;
}
/* Style the TEC form */
.hvac-tec-wrapper .tribe-community-events {
background: #fff;
padding: 30px;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.hvac-error-notice {
background: #fff5f5;
border-left: 4px solid #dc3232;
padding: 15px;
margin-bottom: 20px;
}
.hvac-success-notice {
background: #f0f8ff;
border-left: 4px solid #0073aa;
padding: 15px;
margin-bottom: 20px;
}
/* Quick action buttons */
.hvac-quick-actions {
display: flex;
gap: 15px;
margin-bottom: 20px;
}
.hvac-quick-actions .button {
padding: 8px 16px;
background: #f7f7f7;
border: 1px solid #ddd;
border-radius: 4px;
text-decoration: none;
color: #333;
transition: all 0.3s;
}
.hvac-quick-actions .button:hover {
background: #0073aa;
color: white;
border-color: #0073aa;
}
.hvac-quick-actions .button.active {
background: #0073aa;
color: white;
border-color: #0073aa;
}
.hvac-quick-actions .button.danger {
background: #dc3232;
color: white;
border-color: #dc3232;
}
</style>
<div class="hvac-tec-wrapper">
<?php
// Display trainer navigation menu
if (class_exists('HVAC_Menu_System')) {
HVAC_Menu_System::instance()->render_trainer_menu();
}
// Display breadcrumbs
if (class_exists('HVAC_Breadcrumbs')) {
echo HVAC_Breadcrumbs::instance()->render_breadcrumbs();
}
?>
<div class="hvac-page-header">
<h1>Edit Training Event</h1>
<?php if ($event_id && $event) : ?>
<p class="hvac-page-description">
Editing: <strong><?php echo esc_html($event->post_title); ?></strong>
</p>
<?php endif; ?>
</div>
<?php if (isset($_GET['updated'])) : ?>
<div class="hvac-success-notice">
<p>✅ Event updated successfully!</p>
</div>
<?php endif; ?>
<?php if ($form_error) : ?>
<div class="hvac-error-notice">
<p>❌ <?php echo esc_html($form_error); ?></p>
</div>
<?php endif; ?>
<?php if ($event_id && $can_edit) : ?>
<div class="hvac-event-meta">
<span><strong>Status:</strong> <?php echo ucfirst($event->post_status); ?></span>
<span><strong>Created:</strong> <?php echo date('M j, Y', strtotime($event->post_date)); ?></span>
<span><strong>Last Modified:</strong> <?php echo date('M j, Y', strtotime($event->post_modified)); ?></span>
</div>
<div class="hvac-quick-actions">
<a href="<?php echo home_url('/trainer/events/my-events/'); ?>" class="button">My Events</a>
<a href="<?php echo home_url('/trainer/events/create/'); ?>" class="button">Create New</a>
<a href="<?php echo get_permalink($event_id); ?>" class="button" target="_blank">View Event</a>
<a href="<?php echo home_url('/trainer/dashboard/'); ?>" class="button">Dashboard</a>
</div>
<div class="hvac-event-form-container">
<?php
// Create the native HVAC event form for editing
if (class_exists('HVAC_Event_Form_Builder')) {
$form_builder = new HVAC_Event_Form_Builder('hvac_event_form', true);
// Configure form for editing with all modern features
$config = [
'enable_ai_assistance' => true,
'enable_featured_image' => true,
'enable_searchable_selectors' => true,
'enable_advanced_options' => true,
'enable_modal_creation' => true,
'enable_template_mode' => true,
'rich_text_editor' => true,
'form_classes' => 'hvac-event-form hvac-edit-form',
'submit_button_text' => 'Update Event',
'submit_button_class' => 'hvac-btn hvac-btn-primary hvac-btn-large'
];
// Build and render the edit form
echo $form_builder->edit_event_form($event_id, $config)->render();
} else {
echo '<div class="hvac-error-notice"><p>❌ Form builder not available. Please contact support.</p></div>';
}
?>
</div>
<?php elseif ($event_id && !$can_edit) : ?>
<div class="hvac-error-notice">
<p>❌ You don't have permission to edit this event.</p>
</div>
<div class="hvac-quick-actions">
<a href="<?php echo home_url('/trainer/events/my-events/'); ?>" class="button">Back to My Events</a>
</div>
<?php else : ?>
<div class="hvac-error-notice">
<p>❌ No event specified or event not found.</p>
</div>
<div class="hvac-quick-actions">
<a href="<?php echo home_url('/trainer/events/my-events/'); ?>" class="button">View My Events</a>
<a href="<?php echo home_url('/trainer/events/create/'); ?>" class="button">Create New Event</a>
</div>
<?php endif; ?>
</div>
<?php
get_footer();
?>