Sindbad~EG File Manager

Current Path : /home/copmadinaarea/thecopmadinaarea.org/conference/
Upload File :
Current File : /home/copmadinaarea/thecopmadinaarea.org/conference/apply_schema_changes.php

<?php
// Apply database schema changes for check-in/check-out functionality
require_once 'config/database.php';

try {
    $db = new CopMadinaDB();
    $conn = $db->getConnection();
    
    echo "Applying database schema changes...\n";
    
    // Add columns to event_registrations table
    echo "Adding columns to event_registrations table...\n";
    $conn->exec("ALTER TABLE `event_registrations` 
                 ADD COLUMN `checked_in_at` timestamp NULL DEFAULT NULL,
                 ADD COLUMN `checked_out_at` timestamp NULL DEFAULT NULL");
    echo "✓ Added check-in/check-out columns to event_registrations\n";
    
    // Add columns to nonmember_registrations table
    echo "Adding columns to nonmember_registrations table...\n";
    $conn->exec("ALTER TABLE `nonmember_registrations`
                 ADD COLUMN `checked_in_at` timestamp NULL DEFAULT NULL,
                 ADD COLUMN `checked_out_at` timestamp NULL DEFAULT NULL");
    echo "✓ Added check-in/check-out columns to nonmember_registrations\n";
    
    // Create attendance_logs table
    echo "Creating attendance_logs table...\n";
    $conn->exec("CREATE TABLE IF NOT EXISTS `attendance_logs` (
      `id` int(11) NOT NULL AUTO_INCREMENT,
      `event_id` int(11) NOT NULL,
      `user_id` int(11) NULL,
      `registration_code` varchar(50) NOT NULL,
      `registration_type` enum('member','nonmember') NOT NULL,
      `action` enum('check_in','check_out') NOT NULL,
      `action_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
      `duration_minutes` int(11) NULL,
      `ip_address` varchar(45),
      `user_agent` text,
      `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
      PRIMARY KEY (`id`),
      KEY `idx_event_id` (`event_id`),
      KEY `idx_user_id` (`user_id`),
      KEY `idx_registration_code` (`registration_code`),
      KEY `idx_action_time` (`action_time`),
      CONSTRAINT `fk_attendance_logs_event` FOREIGN KEY (`event_id`) REFERENCES `events` (`id`) ON DELETE CASCADE,
      CONSTRAINT `fk_attendance_logs_user` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE SET NULL
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci");
    echo "✓ Created attendance_logs table\n";
    
    echo "\nAll schema changes applied successfully!\n";
    echo "You can now use the check-in/check-out functionality.\n";
    
} catch (PDOException $e) {
    if (strpos($e->getMessage(), 'Duplicate column name') !== false) {
        echo "✓ Columns already exist, skipping...\n";
    } elseif (strpos($e->getMessage(), 'Table') !== false && strpos($e->getMessage(), 'already exists') !== false) {
        echo "✓ Table already exists, skipping...\n";
    } else {
        echo "Error: " . $e->getMessage() . "\n";
        exit(1);
    }
} catch (Exception $e) {
    echo "Error: " . $e->getMessage() . "\n";
    exit(1);
}
?>

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists