Sindbad~EG File Manager

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

<?php
require_once 'config/database.php';

// Enable error reporting
error_reporting(E_ALL);
ini_set('display_errors', 1);

try {
    $database = new CopMadinaDB();
    $conn = $database->getConnection();
    
    if (!$conn) {
        die("❌ Database connection failed");
    }
    
    // Direct SQL updates using PDO
    echo "<h2>🔧 Fixing Events Status</h2>";
    
    // 1. Check current events status
    $check_query = "SELECT id, title, status, start_date FROM events";
    $stmt = $conn->prepare($check_query);
    $stmt->execute();
    $events = $stmt->fetchAll(PDO::FETCH_ASSOC);
    
    echo "<h3>📋 Current Events:</h3>";
    echo "<table border='1' style='border-collapse: collapse; margin: 10px 0;'>";
    echo "<tr><th style='padding: 8px;'>ID</th><th style='padding: 8px;'>Title</th><th style='padding: 8px;'>Status</th><th style='padding: 8px;'>Start Date</th></tr>";
    
    foreach ($events as $event) {
        echo "<tr>";
        echo "<td style='padding: 8px;'>" . $event['id'] . "</td>";
        echo "<td style='padding: 8px;'>" . htmlspecialchars($event['title']) . "</td>";
        echo "<td style='padding: 8px; color: " . ($event['status'] == 'active' ? 'green' : 'red') . ";'>" . $event['status'] . "</td>";
        echo "<td style='padding: 8px;'>" . $event['start_date'] . "</td>";
        echo "</tr>";
    }
    echo "</table>";
    
    // 2. Update status from 'published' to 'active'
    $update_status = "UPDATE events SET status = 'active' WHERE status = 'published'";
    $stmt = $conn->prepare($update_status);
    $result1 = $stmt->execute();
    $affected1 = $stmt->rowCount();
    
    echo "<br>✅ Status Update: " . ($result1 ? "Success" : "Failed") . " - Rows affected: " . $affected1 . "<br>";
    
    // 3. Update past dates to future dates
    $update_dates = "UPDATE events SET start_date = DATE_ADD(CURDATE(), INTERVAL 15 DAY), end_date = DATE_ADD(CURDATE(), INTERVAL 17 DAY) WHERE start_date < CURDATE()";
    $stmt = $conn->prepare($update_dates);
    $result2 = $stmt->execute();
    $affected2 = $stmt->rowCount();
    
    echo "✅ Date Update: " . ($result2 ? "Success" : "Failed") . " - Rows affected: " . $affected2 . "<br>";
    
    // 4. Check final results
    $final_query = "SELECT COUNT(*) as active_count FROM events WHERE status = 'active' AND start_date >= CURDATE()";
    $stmt = $conn->prepare($final_query);
    $stmt->execute();
    $result = $stmt->fetch(PDO::FETCH_ASSOC);
    
    echo "<br><h3>📊 Final Results:</h3>";
    echo "Active upcoming events: <strong style='color: green;'>" . $result['active_count'] . "</strong><br>";
    
    // 5. Show updated events
    $updated_query = "SELECT id, title, status, start_date FROM events ORDER BY start_date";
    $stmt = $conn->prepare($updated_query);
    $stmt->execute();
    $updated_events = $stmt->fetchAll(PDO::FETCH_ASSOC);
    
    echo "<h3>📅 Updated Events:</h3>";
    echo "<table border='1' style='border-collapse: collapse; margin: 10px 0;'>";
    echo "<tr><th style='padding: 8px;'>ID</th><th style='padding: 8px;'>Title</th><th style='padding: 8px;'>Status</th><th style='padding: 8px;'>Start Date</th></tr>";
    
    foreach ($updated_events as $event) {
        $is_upcoming = strtotime($event['start_date']) >= strtotime(date('Y-m-d'));
        $row_color = ($event['status'] == 'active' && $is_upcoming) ? 'background-color: #d4edda;' : '';
        
        echo "<tr style='$row_color'>";
        echo "<td style='padding: 8px;'>" . $event['id'] . "</td>";
        echo "<td style='padding: 8px;'>" . htmlspecialchars($event['title']) . "</td>";
        echo "<td style='padding: 8px; color: " . ($event['status'] == 'active' ? 'green' : 'red') . ";'>" . $event['status'] . "</td>";
        echo "<td style='padding: 8px;'>" . $event['start_date'] . "</td>";
        echo "</tr>";
    }
    echo "</table>";
    
    echo "<br><a href='index.php' style='background: #28a745; color: white; padding: 12px 24px; text-decoration: none; border-radius: 8px; font-weight: bold;'>🏠 View Landing Page</a>";
    
} catch (Exception $e) {
    echo "❌ Error: " . $e->getMessage();
}
?>

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