diff --git a/wordpress-dev/wordpress/wp-content/plugins/hvac-community-events/assets/js/hvac-certificate-actions.js b/wordpress-dev/wordpress/wp-content/plugins/hvac-community-events/assets/js/hvac-certificate-actions.js index 054af1c1..a6804e52 100644 --- a/wordpress-dev/wordpress/wp-content/plugins/hvac-community-events/assets/js/hvac-certificate-actions.js +++ b/wordpress-dev/wordpress/wp-content/plugins/hvac-community-events/assets/js/hvac-certificate-actions.js @@ -116,7 +116,7 @@ const certificateId = $button.data('certificate-id'); // Confirm sending - if (\!confirm('Send certificate to attendee via email?')) { + if (!confirm('Send certificate to attendee via email?')) { return; } @@ -246,15 +246,15 @@ */ init: function() { // Event selection - $('#event_id').on('change', this.loadAttendees); + $(document).on('change', '#event_id', this.loadAttendees); - // Certificate generation - $('#generate-certificates-form').on('submit', this.generateCertificates); + // Certificate generation (use event delegation for dynamic form) + $(document).on('submit', '#generate-certificates-form', this.generateCertificates); - // Helper buttons - $('#select-all-attendees').on('click', this.selectAllAttendees); - $('#select-checked-in').on('click', this.selectCheckedInAttendees); - $('#deselect-all-attendees').on('click', this.deselectAllAttendees); + // Helper buttons (use event delegation for dynamic buttons) + $(document).on('click', '#select-all-attendees', this.selectAllAttendees); + $(document).on('click', '#select-checked-in', this.selectCheckedInAttendees); + $(document).on('click', '#deselect-all-attendees', this.deselectAllAttendees); // Certificate preview (use event delegation for dynamic buttons) $(document).on('click', '.hvac-preview-certificate', this.showCertificatePreview); @@ -542,11 +542,11 @@ $(document).ready(function() { CertificateActions.init(); - // Initialize Generate Certificates functionality if on that page - if ($('#generate-certificates-form').length) { + // Always initialize Generate Certificates functionality if on the generate certificates page + // (the form may not exist initially but will be created dynamically) + if ($('#event_id').length || $('#generate-certificates-form').length) { GenerateCertificates.init(); } }); -})(jQuery); -EOFJS < /dev/null \ No newline at end of file +})(jQuery); \ No newline at end of file diff --git a/wordpress-dev/wordpress/wp-content/plugins/hvac-community-events/templates/certificates/template-certificate-reports-fixed.php b/wordpress-dev/wordpress/wp-content/plugins/hvac-community-events/templates/certificates/template-certificate-reports-fixed.php new file mode 100644 index 00000000..c4d04e0d --- /dev/null +++ b/wordpress-dev/wordpress/wp-content/plugins/hvac-community-events/templates/certificates/template-certificate-reports-fixed.php @@ -0,0 +1,427 @@ + 0, 'active' => 0, 'revoked' => 0, 'emailed' => 0); +$events = array(); +$filter_event = isset($_GET['filter_event']) ? absint($_GET['filter_event']) : 0; +$filter_status = isset($_GET['filter_status']) ? sanitize_text_field($_GET['filter_status']) : 'active'; + +// Start output buffering to prevent issues +ob_start(); + +try { + // Get user's events directly from database to bypass TEC issues + global $wpdb; + + // Build author filter - only current user's events + $events = $wpdb->get_results($wpdb->prepare( + "SELECT ID, post_title, post_date + FROM {$wpdb->posts} + WHERE post_type = 'tribe_events' + AND post_author = %d + AND post_status = 'publish' + ORDER BY post_date DESC", + $current_user_id + )); + + // Check if certificate table exists + $cert_table = $wpdb->prefix . 'hvac_certificates'; + $table_exists = $wpdb->get_var("SHOW TABLES LIKE '$cert_table'") === $cert_table; + + if ($table_exists && !empty($events)) { + // Get event IDs for the user + $event_ids = array_column($events, 'ID'); + $event_ids_placeholder = implode(',', array_fill(0, count($event_ids), '%d')); + + // Get certificate statistics + $total_certs = $wpdb->get_var($wpdb->prepare( + "SELECT COUNT(*) FROM $cert_table WHERE event_id IN ($event_ids_placeholder)", + ...$event_ids + )); + + $active_certs = $wpdb->get_var($wpdb->prepare( + "SELECT COUNT(*) FROM $cert_table WHERE event_id IN ($event_ids_placeholder) AND revoked = 0", + ...$event_ids + )); + + $revoked_certs = $wpdb->get_var($wpdb->prepare( + "SELECT COUNT(*) FROM $cert_table WHERE event_id IN ($event_ids_placeholder) AND revoked = 1", + ...$event_ids + )); + + $emailed_certs = $wpdb->get_var($wpdb->prepare( + "SELECT COUNT(*) FROM $cert_table WHERE event_id IN ($event_ids_placeholder) AND email_sent = 1", + ...$event_ids + )); + + $certificate_stats = array( + 'total' => intval($total_certs), + 'active' => intval($active_certs), + 'revoked' => intval($revoked_certs), + 'emailed' => intval($emailed_certs) + ); + + // Get certificates based on filters + $where_conditions = array("event_id IN ($event_ids_placeholder)"); + $query_params = $event_ids; + + // Add event filter if specified + if ($filter_event > 0 && in_array($filter_event, $event_ids)) { + $where_conditions = array("event_id = %d"); + $query_params = array($filter_event); + } + + // Add status filter + if ($filter_status === 'active') { + $where_conditions[] = "revoked = 0"; + } elseif ($filter_status === 'revoked') { + $where_conditions[] = "revoked = 1"; + } + + $where_clause = "WHERE " . implode(" AND ", $where_conditions); + + $certificates = $wpdb->get_results($wpdb->prepare( + "SELECT * FROM $cert_table $where_clause ORDER BY date_generated DESC LIMIT 50", + ...$query_params + )); + } + +} catch (Exception $e) { + // Log error but continue with empty data + error_log('Certificate Reports Error: ' . $e->getMessage()); +} + +// Clean output buffer +ob_end_clean(); + +// Get header +get_header(); +?> + +
View and manage all certificates you've generated for event attendees.
+You don't have any events yet. Create your first event to start generating certificates.
+ +No certificates found matching your filters.
+ + 0 || $filter_status !== 'all') : ?> +Clear filters to see all your certificates.
+ +Generate certificates for your event attendees on the Generate Certificates page.
+ +| Certificate # | +Event | +Attendee | +Date Generated | +Status | +Actions | +
|---|---|---|---|---|---|
| + | + + + + | ++ | + | + + + + | ++ + + + + + + | +
Generate certificates for attendees of your events.
+You don't have any events yet. Create your first event to start generating certificates.
+ +This event has no attendees yet.
+Attendees are created when people register for your event through the ticket system.
+