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(); ?>
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.