Fix certificate reports page 500 error
This commit addresses the 500 error on the certificate-reports page by: 1. Adding proper error handling to certificate templates 2. Ensuring required classes are loaded in the right order 3. Adding try-catch blocks for better error reporting 4. Creating diagnostic and troubleshooting tools 5. Fixing method signature issues in the certificate manager The issues were caused by missing database tables or classes not being loaded in the correct order. Additional improvements: - Added certificate system diagnostic scripts - Added comprehensive troubleshooting documentation - Added automated fix deploy script
This commit is contained in:
parent
5d08f8d28e
commit
31dae475a6
9 changed files with 1150 additions and 80 deletions
197
wordpress-dev/CERTIFICATE_TROUBLESHOOTING.md
Normal file
197
wordpress-dev/CERTIFICATE_TROUBLESHOOTING.md
Normal file
|
|
@ -0,0 +1,197 @@
|
|||
# Certificate System Troubleshooting Guide
|
||||
|
||||
This guide provides steps to diagnose and fix issues with the certificate functionality in the HVAC Community Events plugin.
|
||||
|
||||
## Common Issues
|
||||
|
||||
1. **500 Error on Certificate Reports Page**
|
||||
- Database table might not exist or has incorrect structure
|
||||
- Certificate directory might not exist or has incorrect permissions
|
||||
- Plugin hooks might not be firing correctly
|
||||
- PHP error in the template file
|
||||
|
||||
2. **Certificate Generation Issues**
|
||||
- PDF generation library might not be installed or configured
|
||||
- Temporary directory might not be writable
|
||||
- File permissions issues
|
||||
|
||||
3. **Certificate Email Issues**
|
||||
- Email configuration might be incorrect
|
||||
- Attendee email might not exist in the database
|
||||
|
||||
## Diagnostic Scripts
|
||||
|
||||
We've provided several scripts to help diagnose and fix certificate system issues:
|
||||
|
||||
### 1. Debug Certificate System
|
||||
|
||||
This script checks all components of the certificate system and identifies issues:
|
||||
|
||||
```bash
|
||||
cd wordpress-dev
|
||||
./bin/debug-certificate-system.sh
|
||||
```
|
||||
|
||||
The script performs the following checks:
|
||||
- Plugin files existence
|
||||
- Database table structure
|
||||
- Certificate storage directory
|
||||
- Certificate configuration settings
|
||||
|
||||
### 2. Check and Fix Database Tables
|
||||
|
||||
This script specifically focuses on the database tables needed for certificates:
|
||||
|
||||
```bash
|
||||
cd wordpress-dev
|
||||
php bin/check-and-fix-certificate-tables.php
|
||||
```
|
||||
|
||||
The script:
|
||||
- Checks if certificate table exists
|
||||
- Creates the table if it doesn't exist
|
||||
- Verifies the table has the correct structure
|
||||
- Fixes any missing columns
|
||||
|
||||
### 3. Debug Certificate Reports
|
||||
|
||||
This script tests the certificate reports functionality:
|
||||
|
||||
```bash
|
||||
cd wordpress-dev
|
||||
php bin/debug-certificate-reports.php
|
||||
```
|
||||
|
||||
It:
|
||||
- Simulates loading the certificate reports page
|
||||
- Runs the same database queries that would run on the page
|
||||
- Shows detailed output for each query
|
||||
- Helps identify SQL errors
|
||||
|
||||
### 4. Deploy Certificate Fixes
|
||||
|
||||
This script automates the deployment of fixes for the certificate system:
|
||||
|
||||
```bash
|
||||
cd wordpress-dev
|
||||
./bin/deploy-certificate-fixes.sh
|
||||
```
|
||||
|
||||
The script:
|
||||
- Runs the database fix script
|
||||
- Fixes certificate directory permissions
|
||||
- Clears WordPress cache
|
||||
- Checks plugin status
|
||||
- Flushes rewrite rules
|
||||
|
||||
## Manual Fixing Steps
|
||||
|
||||
If the automatic scripts don't resolve the issue, follow these manual steps:
|
||||
|
||||
### 1. Check Plugin Activation
|
||||
|
||||
Deactivate and reactivate the plugin:
|
||||
|
||||
```php
|
||||
// In WordPress wp-admin > Plugins
|
||||
// Or via WP-CLI:
|
||||
wp plugin deactivate hvac-community-events
|
||||
wp plugin activate hvac-community-events
|
||||
```
|
||||
|
||||
### 2. Check Database Table
|
||||
|
||||
Connect to the database and check if the certificate table exists and has the right structure:
|
||||
|
||||
```sql
|
||||
DESCRIBE wp_hvac_certificates;
|
||||
```
|
||||
|
||||
The table should have the following columns:
|
||||
- `certificate_id` (BIGINT)
|
||||
- `event_id` (BIGINT)
|
||||
- `attendee_id` (BIGINT)
|
||||
- `user_id` (BIGINT)
|
||||
- `certificate_number` (VARCHAR)
|
||||
- `file_path` (VARCHAR)
|
||||
- `date_generated` (DATETIME)
|
||||
- `generated_by` (BIGINT)
|
||||
- `revoked` (TINYINT)
|
||||
- `revoked_date` (DATETIME)
|
||||
- `revoked_by` (BIGINT)
|
||||
- `revoked_reason` (TEXT)
|
||||
- `email_sent` (TINYINT)
|
||||
- `email_sent_date` (DATETIME)
|
||||
|
||||
If the table is missing or has incorrect structure, run:
|
||||
|
||||
```php
|
||||
// Get certificate installer
|
||||
require_once WP_PLUGIN_DIR . '/hvac-community-events/includes/certificates/class-certificate-installer.php';
|
||||
$installer = HVAC_Certificate_Installer::instance();
|
||||
$installer->create_tables();
|
||||
```
|
||||
|
||||
### 3. Check Certificate Directory
|
||||
|
||||
Make sure the certificate directory exists and is writable:
|
||||
|
||||
```php
|
||||
$upload_dir = wp_upload_dir();
|
||||
$cert_dir = $upload_dir['basedir'] . '/hvac-certificates';
|
||||
|
||||
// Check if directory exists
|
||||
if (!file_exists($cert_dir)) {
|
||||
wp_mkdir_p($cert_dir);
|
||||
}
|
||||
|
||||
// Set permissions
|
||||
chmod($cert_dir, 0755);
|
||||
```
|
||||
|
||||
### 4. Debug Template Errors
|
||||
|
||||
If you're still getting a 500 error, check the PHP error log for detailed errors.
|
||||
|
||||
You can also add debug output to the template file:
|
||||
|
||||
```php
|
||||
// At the top of template-certificate-reports.php
|
||||
ini_set('display_errors', 1);
|
||||
error_reporting(E_ALL);
|
||||
|
||||
// Add debug output throughout the template
|
||||
echo "Debug: Got to line X";
|
||||
var_dump($variable); // Inspect variables
|
||||
```
|
||||
|
||||
### 5. Check for JavaScript Errors
|
||||
|
||||
Open your browser's developer console (F12) and check for JavaScript errors when loading the certificate pages.
|
||||
|
||||
## Testing Certificate Functionality
|
||||
|
||||
After applying fixes, test the certificate functionality with these steps:
|
||||
|
||||
1. **Login** as a trainer user
|
||||
2. **Navigate** to the Generate Certificates page
|
||||
3. **Select** an event from the dropdown
|
||||
4. **Generate** certificates for some attendees
|
||||
5. **Navigate** to the Certificate Reports page
|
||||
6. **View** the generated certificates
|
||||
7. **Test** the email functionality
|
||||
8. **Test** the revoke functionality
|
||||
|
||||
## Still Having Issues?
|
||||
|
||||
If you continue to experience issues after following this guide:
|
||||
|
||||
1. Check the PHP error logs
|
||||
2. Enable WordPress debugging in wp-config.php:
|
||||
```php
|
||||
define('WP_DEBUG', true);
|
||||
define('WP_DEBUG_LOG', true);
|
||||
define('WP_DEBUG_DISPLAY', true);
|
||||
```
|
||||
3. Test with a basic WordPress theme to rule out theme conflicts
|
||||
4. Try deactivating other plugins to check for conflicts
|
||||
287
wordpress-dev/bin/check-and-fix-certificate-tables.php
Executable file
287
wordpress-dev/bin/check-and-fix-certificate-tables.php
Executable file
|
|
@ -0,0 +1,287 @@
|
|||
<?php
|
||||
/**
|
||||
* Certificate Database Table Check and Repair Script
|
||||
*
|
||||
* This script checks if the certificate database tables exist and creates them if they don't.
|
||||
* It's meant to be run via WP-CLI or directly on the server.
|
||||
*
|
||||
* Usage (via WP-CLI):
|
||||
* wp eval-file check-and-fix-certificate-tables.php
|
||||
*/
|
||||
|
||||
// Bootstrap WordPress
|
||||
if (!defined('ABSPATH')) {
|
||||
// Try to find the WordPress config file
|
||||
$wp_load_paths = [
|
||||
// Running from plugin directory
|
||||
'../../../wp-load.php',
|
||||
// Running from wp-content directory
|
||||
'../../wp-load.php',
|
||||
// Running from WordPress root
|
||||
'./wp-load.php',
|
||||
// Running from bin directory in plugin repo
|
||||
'../wordpress/wp-load.php'
|
||||
];
|
||||
|
||||
$wp_loaded = false;
|
||||
foreach ($wp_load_paths as $path) {
|
||||
if (file_exists($path)) {
|
||||
require_once $path;
|
||||
$wp_loaded = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$wp_loaded) {
|
||||
echo "Error: Could not locate wp-load.php. Please run this script via WP-CLI or from the WordPress root directory.\n";
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
// Check if this is a WP-CLI request
|
||||
$is_cli = defined('WP_CLI') && WP_CLI;
|
||||
|
||||
/**
|
||||
* Print status message
|
||||
*/
|
||||
function print_status($message, $status = 'info') {
|
||||
global $is_cli;
|
||||
|
||||
$prefix = '';
|
||||
if ($is_cli) {
|
||||
switch ($status) {
|
||||
case 'success':
|
||||
$prefix = "\033[32m[SUCCESS]\033[0m ";
|
||||
break;
|
||||
case 'error':
|
||||
$prefix = "\033[31m[ERROR]\033[0m ";
|
||||
break;
|
||||
case 'warning':
|
||||
$prefix = "\033[33m[WARNING]\033[0m ";
|
||||
break;
|
||||
default:
|
||||
$prefix = "\033[34m[INFO]\033[0m ";
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
switch ($status) {
|
||||
case 'success':
|
||||
$prefix = '<span style="color: green;">[SUCCESS]</span> ';
|
||||
break;
|
||||
case 'error':
|
||||
$prefix = '<span style="color: red;">[ERROR]</span> ';
|
||||
break;
|
||||
case 'warning':
|
||||
$prefix = '<span style="color: orange;">[WARNING]</span> ';
|
||||
break;
|
||||
default:
|
||||
$prefix = '<span style="color: blue;">[INFO]</span> ';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
echo $prefix . $message . ($is_cli ? "\n" : "<br>\n");
|
||||
}
|
||||
|
||||
// Setup utility functions
|
||||
if (!function_exists('hvac_get_certificate_table_name')) {
|
||||
function hvac_get_certificate_table_name() {
|
||||
global $wpdb;
|
||||
return $wpdb->prefix . 'hvac_certificates';
|
||||
}
|
||||
}
|
||||
|
||||
// Check if hvac-community-events plugin is active
|
||||
if (!function_exists('is_plugin_active')) {
|
||||
include_once(ABSPATH . 'wp-admin/includes/plugin.php');
|
||||
}
|
||||
|
||||
if (!is_plugin_active('hvac-community-events/hvac-community-events.php')) {
|
||||
print_status("HVAC Community Events plugin is not active. Checking for plugin files...", 'warning');
|
||||
|
||||
// Check if plugin files exist
|
||||
$plugin_file = WP_PLUGIN_DIR . '/hvac-community-events/hvac-community-events.php';
|
||||
if (!file_exists($plugin_file)) {
|
||||
print_status("HVAC Community Events plugin files not found. Cannot proceed.", 'error');
|
||||
exit(1);
|
||||
}
|
||||
|
||||
print_status("Plugin files found. Proceeding with table check...", 'info');
|
||||
} else {
|
||||
print_status("HVAC Community Events plugin is active. Proceeding with table check...", 'success');
|
||||
}
|
||||
|
||||
// Check if certificate installer class exists
|
||||
$certificate_installer_file = WP_PLUGIN_DIR . '/hvac-community-events/includes/certificates/class-certificate-installer.php';
|
||||
if (!file_exists($certificate_installer_file)) {
|
||||
print_status("Certificate installer class not found. Cannot proceed.", 'error');
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// Load the certificate installer
|
||||
require_once $certificate_installer_file;
|
||||
|
||||
// Get database object
|
||||
global $wpdb;
|
||||
|
||||
// Get table name
|
||||
$table_name = hvac_get_certificate_table_name();
|
||||
|
||||
// Check if the table exists
|
||||
$table_exists = $wpdb->get_var("SHOW TABLES LIKE '$table_name'") === $table_name;
|
||||
|
||||
if ($table_exists) {
|
||||
print_status("Certificate table exists: $table_name", 'success');
|
||||
|
||||
// Check if the table has the expected structure
|
||||
print_status("Checking table structure...", 'info');
|
||||
|
||||
// Get columns
|
||||
$columns = $wpdb->get_results("DESCRIBE $table_name");
|
||||
$column_names = array_map(function($col) { return $col->Field; }, $columns);
|
||||
|
||||
// Expected columns
|
||||
$expected_columns = [
|
||||
'certificate_id',
|
||||
'event_id',
|
||||
'attendee_id',
|
||||
'user_id',
|
||||
'certificate_number',
|
||||
'file_path',
|
||||
'date_generated',
|
||||
'generated_by',
|
||||
'revoked',
|
||||
'revoked_date',
|
||||
'revoked_by',
|
||||
'revoked_reason',
|
||||
'email_sent',
|
||||
'email_sent_date'
|
||||
];
|
||||
|
||||
$missing_columns = array_diff($expected_columns, $column_names);
|
||||
|
||||
if (!empty($missing_columns)) {
|
||||
print_status("Table is missing columns: " . implode(', ', $missing_columns), 'warning');
|
||||
print_status("Attempting to recreate the table with the correct structure...", 'info');
|
||||
|
||||
// Try to recreate the table
|
||||
$installer = HVAC_Certificate_Installer::instance();
|
||||
$installer->create_tables();
|
||||
|
||||
// Check if recreation was successful
|
||||
$table_exists = $wpdb->get_var("SHOW TABLES LIKE '$table_name'") === $table_name;
|
||||
|
||||
if ($table_exists) {
|
||||
// Recheck columns
|
||||
$columns = $wpdb->get_results("DESCRIBE $table_name");
|
||||
$column_names = array_map(function($col) { return $col->Field; }, $columns);
|
||||
$missing_columns = array_diff($expected_columns, $column_names);
|
||||
|
||||
if (empty($missing_columns)) {
|
||||
print_status("Table structure successfully repaired!", 'success');
|
||||
} else {
|
||||
print_status("Failed to repair table structure. Still missing columns: " . implode(', ', $missing_columns), 'error');
|
||||
}
|
||||
} else {
|
||||
print_status("Failed to recreate the certificate table.", 'error');
|
||||
}
|
||||
} else {
|
||||
print_status("Table structure is correct.", 'success');
|
||||
}
|
||||
} else {
|
||||
print_status("Certificate table does not exist. Creating table...", 'warning');
|
||||
|
||||
// Create the table
|
||||
$installer = HVAC_Certificate_Installer::instance();
|
||||
$installer->create_tables();
|
||||
|
||||
// Check if creation was successful
|
||||
$table_exists = $wpdb->get_var("SHOW TABLES LIKE '$table_name'") === $table_name;
|
||||
|
||||
if ($table_exists) {
|
||||
print_status("Certificate table created successfully!", 'success');
|
||||
} else {
|
||||
print_status("Failed to create certificate table.", 'error');
|
||||
}
|
||||
}
|
||||
|
||||
// Check certificate storage directory
|
||||
$upload_dir = wp_upload_dir();
|
||||
$cert_storage_path = get_option('hvac_certificate_storage_path', 'hvac-certificates');
|
||||
$cert_dir = $upload_dir['basedir'] . '/' . $cert_storage_path;
|
||||
|
||||
if (!file_exists($cert_dir)) {
|
||||
print_status("Certificate storage directory does not exist. Creating directory...", 'warning');
|
||||
|
||||
// Create directory
|
||||
if (wp_mkdir_p($cert_dir)) {
|
||||
print_status("Certificate storage directory created: $cert_dir", 'success');
|
||||
} else {
|
||||
print_status("Failed to create certificate storage directory: $cert_dir", 'error');
|
||||
}
|
||||
} else {
|
||||
print_status("Certificate storage directory exists: $cert_dir", 'success');
|
||||
|
||||
// Check if directory is writable
|
||||
if (is_writable($cert_dir)) {
|
||||
print_status("Certificate storage directory is writable.", 'success');
|
||||
} else {
|
||||
print_status("Certificate storage directory is not writable!", 'error');
|
||||
}
|
||||
}
|
||||
|
||||
// Check htaccess file
|
||||
$htaccess_file = $cert_dir . '/.htaccess';
|
||||
if (!file_exists($htaccess_file)) {
|
||||
print_status("Certificate storage .htaccess file does not exist. Creating file...", 'warning');
|
||||
|
||||
// Create .htaccess file
|
||||
$htaccess_content = "# Disable directory browsing
|
||||
Options -Indexes
|
||||
|
||||
# Deny access to php files
|
||||
<FilesMatch \"\.(php|php5|phtml|php7)$\">
|
||||
Order Allow,Deny
|
||||
Deny from all
|
||||
</FilesMatch>
|
||||
|
||||
# Allow PDF downloads only via WordPress
|
||||
<FilesMatch \"\.(pdf)$\">
|
||||
Order Allow,Deny
|
||||
Deny from all
|
||||
</FilesMatch>
|
||||
|
||||
# Restrict direct access
|
||||
<IfModule mod_rewrite.c>
|
||||
RewriteEngine On
|
||||
RewriteCond %{HTTP_REFERER} !^" . get_site_url() . " [NC]
|
||||
RewriteRule \\.(pdf)$ - [NC,F,L]
|
||||
</IfModule>";
|
||||
|
||||
if (file_put_contents($htaccess_file, $htaccess_content)) {
|
||||
print_status("Certificate storage .htaccess file created.", 'success');
|
||||
} else {
|
||||
print_status("Failed to create certificate storage .htaccess file.", 'error');
|
||||
}
|
||||
} else {
|
||||
print_status("Certificate storage .htaccess file exists.", 'success');
|
||||
}
|
||||
|
||||
// Check certificate settings
|
||||
if (false === get_option('hvac_certificate_counter')) {
|
||||
print_status("Certificate counter not set. Setting to 0...", 'warning');
|
||||
add_option('hvac_certificate_counter', 0);
|
||||
}
|
||||
|
||||
if (false === get_option('hvac_certificate_prefix')) {
|
||||
print_status("Certificate prefix not set. Setting to default 'HVAC-'...", 'warning');
|
||||
add_option('hvac_certificate_prefix', 'HVAC-');
|
||||
}
|
||||
|
||||
if (false === get_option('hvac_certificate_storage_path')) {
|
||||
print_status("Certificate storage path not set. Setting to default 'hvac-certificates'...", 'warning');
|
||||
add_option('hvac_certificate_storage_path', 'hvac-certificates');
|
||||
}
|
||||
|
||||
// Final status
|
||||
print_status("Certificate system check completed.", 'success');
|
||||
238
wordpress-dev/bin/debug-certificate-reports.php
Executable file
238
wordpress-dev/bin/debug-certificate-reports.php
Executable file
|
|
@ -0,0 +1,238 @@
|
|||
<?php
|
||||
/**
|
||||
* Debug Certificate Reports
|
||||
*
|
||||
* This script helps debug issues with the certificate reports page.
|
||||
* It simulates loading the template and running the queries with debug output.
|
||||
*/
|
||||
|
||||
// Load WordPress
|
||||
if (file_exists('../wordpress/wp-load.php')) {
|
||||
require_once '../wordpress/wp-load.php';
|
||||
} elseif (file_exists('./wordpress/wp-load.php')) {
|
||||
require_once './wordpress/wp-load.php';
|
||||
} else {
|
||||
echo "Could not find wp-load.php\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// Enable error reporting
|
||||
error_reporting(E_ALL);
|
||||
ini_set('display_errors', 1);
|
||||
|
||||
// Output header
|
||||
echo "=== Certificate Reports Debug ===\n\n";
|
||||
|
||||
// Check if HVAC_CE_PLUGIN_DIR is defined
|
||||
if (!defined('HVAC_CE_PLUGIN_DIR')) {
|
||||
echo "Error: HVAC_CE_PLUGIN_DIR is not defined. Plugin files may not be loaded correctly.\n";
|
||||
echo "Attempting to define it...\n";
|
||||
|
||||
// Try to determine the plugin directory
|
||||
$plugin_dir = WP_PLUGIN_DIR . '/hvac-community-events/';
|
||||
if (is_dir($plugin_dir)) {
|
||||
define('HVAC_CE_PLUGIN_DIR', $plugin_dir);
|
||||
echo "Defined HVAC_CE_PLUGIN_DIR as: $plugin_dir\n";
|
||||
} else {
|
||||
echo "Error: Could not find the hvac-community-events plugin directory.\n";
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
// Check if HVAC_CE_PLUGIN_URL is defined
|
||||
if (!defined('HVAC_CE_PLUGIN_URL')) {
|
||||
echo "Warning: HVAC_CE_PLUGIN_URL is not defined.\n";
|
||||
echo "Attempting to define it...\n";
|
||||
|
||||
$plugin_url = plugins_url() . '/hvac-community-events/';
|
||||
define('HVAC_CE_PLUGIN_URL', $plugin_url);
|
||||
echo "Defined HVAC_CE_PLUGIN_URL as: $plugin_url\n";
|
||||
}
|
||||
|
||||
// Check if required classes are loaded
|
||||
echo "\nChecking required classes:\n";
|
||||
|
||||
// Certificate Manager
|
||||
$manager_file = HVAC_CE_PLUGIN_DIR . 'includes/certificates/class-certificate-manager.php';
|
||||
if (file_exists($manager_file)) {
|
||||
require_once $manager_file;
|
||||
echo "✓ Certificate Manager class loaded\n";
|
||||
} else {
|
||||
echo "✗ Certificate Manager class not found at: $manager_file\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// Certificate Security
|
||||
$security_file = HVAC_CE_PLUGIN_DIR . 'includes/certificates/class-certificate-security.php';
|
||||
if (file_exists($security_file)) {
|
||||
require_once $security_file;
|
||||
echo "✓ Certificate Security class loaded\n";
|
||||
} else {
|
||||
echo "✗ Certificate Security class not found at: $security_file\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// Certificate Installer
|
||||
$installer_file = HVAC_CE_PLUGIN_DIR . 'includes/certificates/class-certificate-installer.php';
|
||||
if (file_exists($installer_file)) {
|
||||
require_once $installer_file;
|
||||
echo "✓ Certificate Installer class loaded\n";
|
||||
} else {
|
||||
echo "✗ Certificate Installer class not found at: $installer_file\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// Check database table
|
||||
echo "\nChecking certificate database table:\n";
|
||||
$installer = HVAC_Certificate_Installer::instance();
|
||||
$table_exists = $installer->check_tables();
|
||||
|
||||
if ($table_exists) {
|
||||
echo "✓ Certificate table exists and has correct structure\n";
|
||||
} else {
|
||||
echo "! Certificate table did not exist or was outdated. It has been created/updated.\n";
|
||||
}
|
||||
|
||||
// Get current user ID
|
||||
$current_user_id = get_current_user_id();
|
||||
echo "\nCurrent user ID: $current_user_id\n";
|
||||
|
||||
// Get certificate manager instance
|
||||
$certificate_manager = HVAC_Certificate_Manager::instance();
|
||||
echo "Certificate Manager instance created\n";
|
||||
|
||||
// Get certificate security instance
|
||||
$certificate_security = HVAC_Certificate_Security::instance();
|
||||
echo "Certificate Security instance created\n";
|
||||
|
||||
// Get filtering parameters (simulating GET request)
|
||||
$filter_event = 0;
|
||||
$filter_status = 'active';
|
||||
$page = 1;
|
||||
$per_page = 20;
|
||||
|
||||
echo "\nFilter parameters:\n";
|
||||
echo "- Event ID: $filter_event\n";
|
||||
echo "- Status: $filter_status\n";
|
||||
echo "- Page: $page\n";
|
||||
echo "- Per Page: $per_page\n";
|
||||
|
||||
// Build filter args
|
||||
$filter_args = array(
|
||||
'page' => $page,
|
||||
'per_page' => $per_page,
|
||||
'orderby' => 'date_generated',
|
||||
'order' => 'DESC',
|
||||
);
|
||||
|
||||
// Add status filter
|
||||
if ($filter_status === 'active') {
|
||||
$filter_args['revoked'] = 0;
|
||||
} elseif ($filter_status === 'revoked') {
|
||||
$filter_args['revoked'] = 1;
|
||||
}
|
||||
|
||||
// Generate the SQL for the query (debugging only)
|
||||
global $wpdb;
|
||||
$table_name = $wpdb->prefix . 'hvac_certificates';
|
||||
|
||||
// Check the SQL query
|
||||
echo "\nQueries that will be executed:\n";
|
||||
|
||||
// Get events query (for filtering)
|
||||
$events_query = new WP_Query(array(
|
||||
'post_type' => Tribe__Events__Main::POSTTYPE,
|
||||
'posts_per_page' => -1,
|
||||
'post_status' => 'publish',
|
||||
'author' => $current_user_id,
|
||||
'orderby' => 'meta_value',
|
||||
'meta_key' => '_EventStartDate',
|
||||
'order' => 'DESC',
|
||||
'fields' => 'ids'
|
||||
));
|
||||
|
||||
$event_ids = $events_query->posts;
|
||||
|
||||
echo "1. WP_Query for user events (SQL):\n";
|
||||
echo $events_query->request . "\n";
|
||||
echo "Found " . count($event_ids) . " events for the current user\n";
|
||||
|
||||
// If there are no events, user can't have certificates
|
||||
if (empty($event_ids)) {
|
||||
echo "\nNo events found for the current user, therefore no certificates.\n";
|
||||
exit(0);
|
||||
}
|
||||
|
||||
// Get certificates query
|
||||
echo "\n2. Certificate query:\n";
|
||||
$event_ids_string = implode(',', array_map('intval', $event_ids));
|
||||
echo "Event IDs: $event_ids_string\n";
|
||||
|
||||
// Only include revoked filter if relevant
|
||||
$where_clause = "WHERE event_id IN ($event_ids_string)";
|
||||
if (isset($filter_args['revoked'])) {
|
||||
$where_clause .= " AND revoked = " . intval($filter_args['revoked']);
|
||||
}
|
||||
|
||||
$order_by = sanitize_sql_orderby('date_generated DESC');
|
||||
$offset = ($filter_args['page'] - 1) * $filter_args['per_page'];
|
||||
$limit_clause = "LIMIT $offset, " . $filter_args['per_page'];
|
||||
|
||||
$certificates_query = "SELECT * FROM $table_name $where_clause ORDER BY $order_by $limit_clause";
|
||||
echo $certificates_query . "\n";
|
||||
|
||||
// Execute and get certificates
|
||||
try {
|
||||
echo "\nExecuting certificate query...\n";
|
||||
$certificates = $wpdb->get_results($certificates_query);
|
||||
echo "Found " . count($certificates) . " certificates matching the query\n";
|
||||
|
||||
// Get the count for pagination
|
||||
$count_query = "SELECT COUNT(*) FROM $table_name $where_clause";
|
||||
echo "\n3. Count query for pagination:\n";
|
||||
echo $count_query . "\n";
|
||||
|
||||
try {
|
||||
$total_certificates = $wpdb->get_var($count_query);
|
||||
echo "Total certificates matching the filter: $total_certificates\n";
|
||||
$total_pages = ceil($total_certificates / $per_page);
|
||||
echo "Total pages: $total_pages\n";
|
||||
} catch (Exception $e) {
|
||||
echo "Error executing count query: " . $e->getMessage() . "\n";
|
||||
}
|
||||
|
||||
// Get certificate statistics
|
||||
echo "\n4. Certificate statistics query:\n";
|
||||
$stats_query = "SELECT
|
||||
COUNT(*) as total,
|
||||
SUM(CASE WHEN revoked = 0 THEN 1 ELSE 0 END) as active,
|
||||
SUM(CASE WHEN revoked = 1 THEN 1 ELSE 0 END) as revoked,
|
||||
SUM(CASE WHEN email_sent = 1 THEN 1 ELSE 0 END) as emailed
|
||||
FROM $table_name
|
||||
WHERE event_id IN ($event_ids_string)";
|
||||
echo $stats_query . "\n";
|
||||
|
||||
try {
|
||||
$result = $wpdb->get_row($stats_query);
|
||||
echo "\nCertificate Statistics:\n";
|
||||
echo "- Total: " . intval($result->total) . "\n";
|
||||
echo "- Active: " . intval($result->active) . "\n";
|
||||
echo "- Revoked: " . intval($result->revoked) . "\n";
|
||||
echo "- Emailed: " . intval($result->emailed) . "\n";
|
||||
} catch (Exception $e) {
|
||||
echo "Error executing stats query: " . $e->getMessage() . "\n";
|
||||
}
|
||||
|
||||
// Check the template file
|
||||
$template_file = HVAC_CE_PLUGIN_DIR . 'templates/certificates/template-certificate-reports.php';
|
||||
if (file_exists($template_file)) {
|
||||
echo "\n✓ Certificate reports template file exists\n";
|
||||
} else {
|
||||
echo "\n✗ Certificate reports template file not found at: $template_file\n";
|
||||
}
|
||||
|
||||
echo "\nDebugging complete\n";
|
||||
|
||||
} catch (Exception $e) {
|
||||
echo "Error executing certificate query: " . $e->getMessage() . "\n";
|
||||
}
|
||||
108
wordpress-dev/bin/debug-certificate-system.sh
Executable file
108
wordpress-dev/bin/debug-certificate-system.sh
Executable file
|
|
@ -0,0 +1,108 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Debug Certificate System
|
||||
# This script helps debug issues with the certificate functionality in the HVAC Community Events plugin.
|
||||
|
||||
# Colors
|
||||
GREEN='\033[0;32m'
|
||||
RED='\033[0;31m'
|
||||
YELLOW='\033[0;33m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# Function to print colored messages
|
||||
print_message() {
|
||||
local type=$1
|
||||
local message=$2
|
||||
local color=$BLUE
|
||||
|
||||
case $type in
|
||||
"info")
|
||||
color=$BLUE
|
||||
;;
|
||||
"success")
|
||||
color=$GREEN
|
||||
;;
|
||||
"warning")
|
||||
color=$YELLOW
|
||||
;;
|
||||
"error")
|
||||
color=$RED
|
||||
;;
|
||||
esac
|
||||
|
||||
echo -e "${color}${message}${NC}"
|
||||
}
|
||||
|
||||
# Check if we have a WordPress installation
|
||||
if [ ! -d "wordpress" ]; then
|
||||
print_message "error" "No WordPress installation found in ./wordpress directory."
|
||||
print_message "info" "Please run this script from the wordpress-dev directory."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check that we're in the right directory
|
||||
if [ ! -f "bin/debug-certificate-system.sh" ]; then
|
||||
print_message "error" "Please run this script from the wordpress-dev directory."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
print_message "info" "=== HVAC Certificate System Debug ==="
|
||||
print_message "info" ""
|
||||
|
||||
# Step 1: Check plugin files
|
||||
print_message "info" "Step 1: Checking plugin files..."
|
||||
if [ -d "wordpress/wp-content/plugins/hvac-community-events" ]; then
|
||||
print_message "success" "✓ Plugin directory found."
|
||||
else
|
||||
print_message "error" "✗ Plugin directory not found."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check critical files
|
||||
critical_files=(
|
||||
"wordpress/wp-content/plugins/hvac-community-events/hvac-community-events.php"
|
||||
"wordpress/wp-content/plugins/hvac-community-events/includes/certificates/class-certificate-manager.php"
|
||||
"wordpress/wp-content/plugins/hvac-community-events/includes/certificates/class-certificate-installer.php"
|
||||
"wordpress/wp-content/plugins/hvac-community-events/templates/certificates/template-certificate-reports.php"
|
||||
"wordpress/wp-content/plugins/hvac-community-events/templates/certificates/template-generate-certificates.php"
|
||||
)
|
||||
|
||||
missing_files=0
|
||||
for file in "${critical_files[@]}"; do
|
||||
if [ -f "$file" ]; then
|
||||
print_message "success" "✓ Found: $file"
|
||||
else
|
||||
print_message "error" "✗ Missing: $file"
|
||||
missing_files=$((missing_files+1))
|
||||
fi
|
||||
done
|
||||
|
||||
if [ $missing_files -gt 0 ]; then
|
||||
print_message "warning" "! $missing_files critical files are missing."
|
||||
else
|
||||
print_message "success" "All critical files are present."
|
||||
fi
|
||||
|
||||
# Step 2: Check and fix database tables
|
||||
print_message "info" ""
|
||||
print_message "info" "Step 2: Checking database tables..."
|
||||
php bin/check-and-fix-certificate-tables.php
|
||||
|
||||
# Step 3: Debug certificate reports
|
||||
print_message "info" ""
|
||||
print_message "info" "Step 3: Debugging certificate reports functionality..."
|
||||
php bin/debug-certificate-reports.php
|
||||
|
||||
# Final summary
|
||||
print_message "info" ""
|
||||
print_message "info" "=== Debug Summary ==="
|
||||
print_message "info" "1. Check the output above for errors or warnings."
|
||||
print_message "info" "2. If there are database issues, try deactivating and reactivating the plugin."
|
||||
print_message "info" "3. Check PHP error logs for detailed error messages."
|
||||
print_message "info" "4. If issues persist, the problem might be in the frontend JavaScript or CSS."
|
||||
print_message "info" ""
|
||||
print_message "success" "Debug process completed."
|
||||
|
||||
chmod +x bin/check-and-fix-certificate-tables.php
|
||||
chmod +x bin/debug-certificate-reports.php
|
||||
127
wordpress-dev/bin/deploy-certificate-fixes.sh
Executable file
127
wordpress-dev/bin/deploy-certificate-fixes.sh
Executable file
|
|
@ -0,0 +1,127 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Deploy Certificate Fixes Script
|
||||
# This script deploys fixes for the certificate functionality in the HVAC Community Events plugin.
|
||||
|
||||
# Colors
|
||||
GREEN='\033[0;32m'
|
||||
RED='\033[0;31m'
|
||||
YELLOW='\033[0;33m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# Function to print colored messages
|
||||
print_message() {
|
||||
local type=$1
|
||||
local message=$2
|
||||
local color=$BLUE
|
||||
|
||||
case $type in
|
||||
"info")
|
||||
color=$BLUE
|
||||
;;
|
||||
"success")
|
||||
color=$GREEN
|
||||
;;
|
||||
"warning")
|
||||
color=$YELLOW
|
||||
;;
|
||||
"error")
|
||||
color=$RED
|
||||
;;
|
||||
esac
|
||||
|
||||
echo -e "${color}${message}${NC}"
|
||||
}
|
||||
|
||||
# Check if we have a WordPress installation
|
||||
if [ ! -d "wordpress" ]; then
|
||||
print_message "error" "No WordPress installation found in ./wordpress directory."
|
||||
print_message "info" "Please run this script from the wordpress-dev directory."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check that we're in the right directory
|
||||
if [ ! -f "bin/debug-certificate-system.sh" ]; then
|
||||
print_message "error" "Please run this script from the wordpress-dev directory."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
print_message "info" "=== Deploying Certificate Fixes ==="
|
||||
print_message "info" ""
|
||||
|
||||
# Step 1: Deactivate plugin to clear any cached code
|
||||
print_message "info" "Step 1: Running check and fix database script..."
|
||||
php bin/check-and-fix-certificate-tables.php
|
||||
|
||||
# Step 2: Fix certificate directory permissions
|
||||
print_message "info" ""
|
||||
print_message "info" "Step 2: Fixing certificate directory permissions..."
|
||||
|
||||
# Get the certificate directory path
|
||||
UPLOAD_DIR=$(php -r "echo wp_upload_dir()['basedir'];")
|
||||
CERT_DIR="$UPLOAD_DIR/hvac-certificates"
|
||||
|
||||
if [ -d "$CERT_DIR" ]; then
|
||||
chmod -R 755 "$CERT_DIR"
|
||||
print_message "success" "✓ Fixed permissions for certificate directory: $CERT_DIR"
|
||||
else
|
||||
print_message "warning" "! Certificate directory not found at: $CERT_DIR"
|
||||
print_message "info" "Creating certificate directory..."
|
||||
mkdir -p "$CERT_DIR"
|
||||
chmod -R 755 "$CERT_DIR"
|
||||
|
||||
if [ -d "$CERT_DIR" ]; then
|
||||
print_message "success" "✓ Created certificate directory: $CERT_DIR"
|
||||
else
|
||||
print_message "error" "✗ Failed to create certificate directory"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Step 3: Clear cache
|
||||
print_message "info" ""
|
||||
print_message "info" "Step 3: Clearing cache..."
|
||||
|
||||
# Clear WordPress transients
|
||||
php -r "include_once './wordpress/wp-load.php'; wp_cache_flush(); delete_transient('hvac_certificate_cache');"
|
||||
print_message "success" "✓ WordPress cache cleared"
|
||||
|
||||
# Step 4: Check plugin status
|
||||
print_message "info" ""
|
||||
print_message "info" "Step 4: Checking plugin status..."
|
||||
|
||||
# Check if the plugin is active
|
||||
PLUGIN_ACTIVE=$(php -r "include_once './wordpress/wp-load.php'; include_once(ABSPATH . 'wp-admin/includes/plugin.php'); echo (int)is_plugin_active('hvac-community-events/hvac-community-events.php');")
|
||||
|
||||
if [ "$PLUGIN_ACTIVE" -eq "1" ]; then
|
||||
print_message "success" "✓ Plugin is active."
|
||||
else
|
||||
print_message "warning" "! Plugin is not active. Attempting to activate..."
|
||||
php -r "include_once './wordpress/wp-load.php'; include_once(ABSPATH . 'wp-admin/includes/plugin.php'); activate_plugin('hvac-community-events/hvac-community-events.php');"
|
||||
|
||||
# Check again
|
||||
PLUGIN_ACTIVE=$(php -r "include_once './wordpress/wp-load.php'; include_once(ABSPATH . 'wp-admin/includes/plugin.php'); echo (int)is_plugin_active('hvac-community-events/hvac-community-events.php');")
|
||||
|
||||
if [ "$PLUGIN_ACTIVE" -eq "1" ]; then
|
||||
print_message "success" "✓ Plugin activated successfully."
|
||||
else
|
||||
print_message "error" "✗ Failed to activate plugin."
|
||||
fi
|
||||
fi
|
||||
|
||||
# Final step: Flush rewrite rules
|
||||
print_message "info" ""
|
||||
print_message "info" "Final step: Flushing rewrite rules..."
|
||||
php -r "include_once './wordpress/wp-load.php'; flush_rewrite_rules();"
|
||||
print_message "success" "✓ Rewrite rules flushed"
|
||||
|
||||
# Summary
|
||||
print_message "info" ""
|
||||
print_message "info" "=== Deployment Summary ==="
|
||||
print_message "info" "1. Database table checked and fixed (if needed)"
|
||||
print_message "info" "2. Certificate directory permissions fixed"
|
||||
print_message "info" "3. Cache cleared"
|
||||
print_message "info" "4. Plugin status checked"
|
||||
print_message "info" "5. Rewrite rules flushed"
|
||||
print_message "info" ""
|
||||
print_message "success" "Certificate fixes deployed successfully. Please test the functionality."
|
||||
|
|
@ -188,12 +188,12 @@ class HVAC_Certificate_Manager {
|
|||
* Revoke a certificate.
|
||||
*
|
||||
* @param int $certificate_id The certificate ID.
|
||||
* @param string $reason The reason for revocation.
|
||||
* @param int $revoked_by The ID of the user who revoked the certificate.
|
||||
* @param string $reason The reason for revocation.
|
||||
*
|
||||
* @return bool True if successful, false otherwise.
|
||||
*/
|
||||
public function revoke_certificate($certificate_id, $reason = '', $revoked_by = 0) {
|
||||
public function revoke_certificate($certificate_id, $revoked_by = 0, $reason = '') {
|
||||
global $wpdb;
|
||||
|
||||
// Get current user if not specified
|
||||
|
|
|
|||
|
|
@ -404,10 +404,20 @@ class HVAC_Community_Events {
|
|||
return '<div class="hvac-error">You do not have permission to view certificate reports.</div>';
|
||||
}
|
||||
|
||||
// Include the certificate reports template
|
||||
// Make sure certificate manager is loaded
|
||||
require_once HVAC_CE_PLUGIN_DIR . 'includes/certificates/class-certificate-manager.php';
|
||||
|
||||
// Make sure certificate security is loaded
|
||||
require_once HVAC_CE_PLUGIN_DIR . 'includes/certificates/class-certificate-security.php';
|
||||
|
||||
// Include the certificate reports template with error handling
|
||||
try {
|
||||
ob_start();
|
||||
include HVAC_CE_PLUGIN_DIR . 'templates/certificates/template-certificate-reports.php';
|
||||
return ob_get_clean();
|
||||
} catch (Exception $e) {
|
||||
return '<div class="hvac-error">Error loading certificate reports: ' . esc_html($e->getMessage()) . '</div>';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -440,10 +450,23 @@ class HVAC_Community_Events {
|
|||
}
|
||||
}
|
||||
|
||||
// Include the generate certificates template
|
||||
// Make sure certificate manager is loaded
|
||||
require_once HVAC_CE_PLUGIN_DIR . 'includes/certificates/class-certificate-manager.php';
|
||||
|
||||
// Make sure certificate security is loaded
|
||||
require_once HVAC_CE_PLUGIN_DIR . 'includes/certificates/class-certificate-security.php';
|
||||
|
||||
// Make sure certificate generator is loaded
|
||||
require_once HVAC_CE_PLUGIN_DIR . 'includes/certificates/class-certificate-generator.php';
|
||||
|
||||
// Include the generate certificates template with error handling
|
||||
try {
|
||||
ob_start();
|
||||
include HVAC_CE_PLUGIN_DIR . 'templates/certificates/template-generate-certificates.php';
|
||||
return ob_get_clean();
|
||||
} catch (Exception $e) {
|
||||
return '<div class="hvac-error">Error loading certificate generation: ' . esc_html($e->getMessage()) . '</div>';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -6,58 +6,75 @@
|
|||
* @subpackage Templates/Certificates
|
||||
*/
|
||||
|
||||
// Enable error reporting for debugging
|
||||
if (WP_DEBUG) {
|
||||
error_reporting(E_ALL);
|
||||
ini_set('display_errors', 1);
|
||||
}
|
||||
|
||||
// Exit if accessed directly
|
||||
if (\!defined('ABSPATH')) {
|
||||
if (!defined('ABSPATH')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
// Get current user ID
|
||||
$current_user_id = get_current_user_id();
|
||||
|
||||
// Get certificate manager instance
|
||||
require_once HVAC_CE_PLUGIN_DIR . 'includes/certificates/class-certificate-manager.php';
|
||||
$certificate_manager = HVAC_Certificate_Manager::instance();
|
||||
// Error handling wrapper for the whole template
|
||||
try {
|
||||
// Get certificate manager instance
|
||||
if (!class_exists('HVAC_Certificate_Manager')) {
|
||||
require_once HVAC_CE_PLUGIN_DIR . 'includes/certificates/class-certificate-manager.php';
|
||||
}
|
||||
$certificate_manager = HVAC_Certificate_Manager::instance();
|
||||
|
||||
// Get certificate security instance
|
||||
require_once HVAC_CE_PLUGIN_DIR . 'includes/certificates/class-certificate-security.php';
|
||||
$certificate_security = HVAC_Certificate_Security::instance();
|
||||
// Get certificate security instance
|
||||
if (!class_exists('HVAC_Certificate_Security')) {
|
||||
require_once HVAC_CE_PLUGIN_DIR . 'includes/certificates/class-certificate-security.php';
|
||||
}
|
||||
$certificate_security = HVAC_Certificate_Security::instance();
|
||||
|
||||
// Get filtering parameters
|
||||
$filter_event = isset($_GET['filter_event']) ? absint($_GET['filter_event']) : 0;
|
||||
$filter_status = isset($_GET['filter_status']) ? sanitize_text_field($_GET['filter_status']) : 'active';
|
||||
$page = isset($_GET['certificate_page']) ? absint($_GET['certificate_page']) : 1;
|
||||
$per_page = 20;
|
||||
// Check if certificate tables exist
|
||||
if (!class_exists('HVAC_Certificate_Installer')) {
|
||||
require_once HVAC_CE_PLUGIN_DIR . 'includes/certificates/class-certificate-installer.php';
|
||||
}
|
||||
$installer = HVAC_Certificate_Installer::instance();
|
||||
$tables_exist = $installer->check_tables();
|
||||
|
||||
// Build filter args
|
||||
$filter_args = array(
|
||||
if (!$tables_exist) {
|
||||
echo '<div class="hvac-error">Certificate database tables are not properly set up. Please contact the administrator.</div>';
|
||||
return;
|
||||
}
|
||||
|
||||
// Get filtering parameters
|
||||
$filter_event = isset($_GET['filter_event']) ? absint($_GET['filter_event']) : 0;
|
||||
$filter_status = isset($_GET['filter_status']) ? sanitize_text_field($_GET['filter_status']) : 'active';
|
||||
$page = isset($_GET['certificate_page']) ? absint($_GET['certificate_page']) : 1;
|
||||
$per_page = 20;
|
||||
|
||||
// Build filter args
|
||||
$filter_args = array(
|
||||
'page' => $page,
|
||||
'per_page' => $per_page,
|
||||
'orderby' => 'date_generated',
|
||||
'order' => 'DESC',
|
||||
);
|
||||
);
|
||||
|
||||
// Add event filter if selected
|
||||
if ($filter_event > 0) {
|
||||
// Add event filter if selected
|
||||
if ($filter_event > 0) {
|
||||
$filter_args['event_id'] = $filter_event;
|
||||
}
|
||||
}
|
||||
|
||||
// Add status filter
|
||||
if ($filter_status === 'active') {
|
||||
// Add status filter
|
||||
if ($filter_status === 'active') {
|
||||
$filter_args['revoked'] = 0;
|
||||
} elseif ($filter_status === 'revoked') {
|
||||
} elseif ($filter_status === 'revoked') {
|
||||
$filter_args['revoked'] = 1;
|
||||
}
|
||||
// Default 'all' doesn't add a filter
|
||||
}
|
||||
// Default 'all' doesn't add a filter
|
||||
|
||||
// Get certificates for the current user with filters
|
||||
$certificates = $certificate_manager->get_user_certificates($current_user_id, $filter_args);
|
||||
|
||||
// Get total certificate count for pagination
|
||||
$total_certificates = $certificate_manager->get_user_certificate_count($current_user_id, $filter_args);
|
||||
$total_pages = ceil($total_certificates / $per_page);
|
||||
|
||||
// Get user's events for filtering
|
||||
$args = array(
|
||||
// Get user's events for filtering
|
||||
$args = array(
|
||||
'post_type' => Tribe__Events__Main::POSTTYPE,
|
||||
'posts_per_page' => -1,
|
||||
'post_status' => 'publish',
|
||||
|
|
@ -65,20 +82,45 @@ $args = array(
|
|||
'orderby' => 'meta_value',
|
||||
'meta_key' => '_EventStartDate',
|
||||
'order' => 'DESC',
|
||||
);
|
||||
);
|
||||
|
||||
// Allow admins to see all events
|
||||
if (current_user_can('edit_others_posts')) {
|
||||
// Allow admins to see all events
|
||||
if (current_user_can('edit_others_posts')) {
|
||||
unset($args['author']);
|
||||
}
|
||||
|
||||
$events = get_posts($args);
|
||||
|
||||
// Check if user has any events
|
||||
if (empty($events)) {
|
||||
// No certificates to show since user has no events
|
||||
$certificates = array();
|
||||
$total_certificates = 0;
|
||||
$total_pages = 0;
|
||||
$certificate_stats = array(
|
||||
'total' => 0,
|
||||
'active' => 0,
|
||||
'revoked' => 0,
|
||||
'emailed' => 0
|
||||
);
|
||||
} else {
|
||||
// Get certificates for the current user with filters
|
||||
$certificates = $certificate_manager->get_user_certificates($current_user_id, $filter_args);
|
||||
|
||||
// Get total certificate count for pagination
|
||||
$total_certificates = $certificate_manager->get_user_certificate_count($current_user_id, $filter_args);
|
||||
$total_pages = ceil($total_certificates / $per_page);
|
||||
|
||||
// Get certificate statistics
|
||||
$certificate_stats = $certificate_manager->get_user_certificate_stats($current_user_id);
|
||||
}
|
||||
|
||||
// Get header and footer
|
||||
get_header();
|
||||
} catch (Exception $e) {
|
||||
echo '<div class="hvac-error">Error initializing certificate system: ' . esc_html($e->getMessage()) . '</div>';
|
||||
return;
|
||||
}
|
||||
|
||||
$events = get_posts($args);
|
||||
|
||||
// Get certificate statistics
|
||||
$certificate_stats = $certificate_manager->get_user_certificate_stats($current_user_id);
|
||||
|
||||
// Get header and footer
|
||||
get_header();
|
||||
?>
|
||||
|
||||
<div class="hvac-container">
|
||||
|
|
@ -279,6 +321,14 @@ wp_localize_script('hvac-certificate-actions-js', 'hvacCertificateData', array(
|
|||
'revokeNonce' => wp_create_nonce('hvac_revoke_certificate')
|
||||
));
|
||||
|
||||
// Close the try block
|
||||
get_footer();
|
||||
?>
|
||||
|
||||
<?php
|
||||
// Catch any late exceptions
|
||||
} catch (Exception $e) {
|
||||
echo '<div class="hvac-error">Error in certificate reports: ' . esc_html($e->getMessage()) . '</div>';
|
||||
}
|
||||
?>
|
||||
EOFPHP < /dev/null
|
||||
|
|
@ -11,20 +11,53 @@ if (!defined('ABSPATH')) {
|
|||
exit;
|
||||
}
|
||||
|
||||
// Enable error reporting for debugging
|
||||
if (WP_DEBUG) {
|
||||
error_reporting(E_ALL);
|
||||
ini_set('display_errors', 1);
|
||||
}
|
||||
|
||||
// Get current user ID
|
||||
$current_user_id = get_current_user_id();
|
||||
|
||||
// Get event ID from URL if available
|
||||
$event_id = isset($_GET['event_id']) ? absint($_GET['event_id']) : 0;
|
||||
// Error handling wrapper for the whole template
|
||||
try {
|
||||
// Get event ID from URL if available
|
||||
$event_id = isset($_GET['event_id']) ? absint($_GET['event_id']) : 0;
|
||||
|
||||
// Get certificate manager instance
|
||||
$certificate_manager = HVAC_Certificate_Manager::instance();
|
||||
// Check if certificate classes are loaded
|
||||
if (!class_exists('HVAC_Certificate_Manager')) {
|
||||
require_once HVAC_CE_PLUGIN_DIR . 'includes/certificates/class-certificate-manager.php';
|
||||
}
|
||||
|
||||
// Get certificate generator instance
|
||||
$certificate_generator = HVAC_Certificate_Generator::instance();
|
||||
if (!class_exists('HVAC_Certificate_Generator')) {
|
||||
require_once HVAC_CE_PLUGIN_DIR . 'includes/certificates/class-certificate-generator.php';
|
||||
}
|
||||
|
||||
// Get certificate template instance
|
||||
$certificate_template = HVAC_Certificate_Template::instance();
|
||||
if (!class_exists('HVAC_Certificate_Template')) {
|
||||
require_once HVAC_CE_PLUGIN_DIR . 'includes/certificates/class-certificate-template.php';
|
||||
}
|
||||
|
||||
// Get certificate manager instance
|
||||
$certificate_manager = HVAC_Certificate_Manager::instance();
|
||||
|
||||
// Get certificate generator instance
|
||||
$certificate_generator = HVAC_Certificate_Generator::instance();
|
||||
|
||||
// Get certificate template instance
|
||||
$certificate_template = HVAC_Certificate_Template::instance();
|
||||
|
||||
// Check if certificate tables exist
|
||||
if (!class_exists('HVAC_Certificate_Installer')) {
|
||||
require_once HVAC_CE_PLUGIN_DIR . 'includes/certificates/class-certificate-installer.php';
|
||||
}
|
||||
$installer = HVAC_Certificate_Installer::instance();
|
||||
$tables_exist = $installer->check_tables();
|
||||
|
||||
if (!$tables_exist) {
|
||||
echo '<div class="hvac-error">Certificate database tables are not properly set up. Please contact the administrator.</div>';
|
||||
return;
|
||||
}
|
||||
|
||||
// Handle certificate generation form submission
|
||||
$generation_results = null;
|
||||
|
|
@ -365,4 +398,11 @@ get_header();
|
|||
});
|
||||
</script>
|
||||
|
||||
<?php get_footer(); ?>
|
||||
<?php
|
||||
get_footer();
|
||||
|
||||
// End try-catch block
|
||||
} catch (Exception $e) {
|
||||
echo '<div class="hvac-error">Error in certificate generation: ' . esc_html($e->getMessage()) . '</div>';
|
||||
}
|
||||
?>
|
||||
Loading…
Reference in a new issue