Sindbad~EG File Manager

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

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

error_reporting(E_ALL);
ini_set('display_errors', 1);

echo "<h2>🚀 Force Fix Events</h2>";

try {
    $database = new CopMadinaDB();
    $pdo = $database->getConnection();
    
    // Get today's date
    $today = date('Y-m-d');
    $future_date = date('Y-m-d', strtotime('+20 days'));
    $future_end = date('Y-m-d', strtotime('+22 days'));
    
    echo "Today: {$today}<br>";
    echo "Setting events to: {$future_date}<br><br>";
    
    // Force update all events
    $sql = "UPDATE events SET 
            status = 'active',
            start_date = '{$future_date} 09:00:00',
            end_date = '{$future_end} 17:00:00'";
    
    $stmt = $pdo->prepare($sql);
    $result = $stmt->execute();
    $affected = $stmt->rowCount();
    
    echo "✅ Force updated {$affected} events<br><br>";
    
    // Test the exact landing page query
    $test_query = "SELECT COUNT(*) as count FROM events WHERE status = 'active' AND DATE(start_date) >= CURDATE()";
    $stmt = $pdo->prepare($test_query);
    $stmt->execute();
    $count = $stmt->fetch(PDO::FETCH_ASSOC);
    
    echo "<h3>📊 Test Results:</h3>";
    echo "Query: {$test_query}<br>";
    echo "Active future events: <strong style='color: green;'>{$count['count']}</strong><br>";

    require_once 'includes/functions.php';

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

    $db = new CopMadinaDB();
    $conn = $db->getConnection();

    echo "<h2>Fixing Admin Form Issues</h2>";

    // Check if user is logged in
    if (!isLoggedIn()) {
        echo "❌ Please login first<br>";
        echo '<a href="login.php">Login</a>';
        exit();
    }

    $user = getCurrentUser();
    echo "Current user: " . $user['username'] . " (ID: " . $user['id'] . ")<br>";

    // Test the exact same code as in areas.php
    if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['test_create'])) {
        echo "<h3>Testing Area Creation</h3>";
        
        $name = trim($_POST['name']);
        $location = trim($_POST['location']);
        $description = trim($_POST['description']);
        $contact_person = trim($_POST['contact_person']);
        $contact_email = trim($_POST['contact_email']);
        $contact_phone = trim($_POST['contact_phone']);
        
        echo "Form data received:<br>";
        echo "Name: " . $name . "<br>";
        echo "Location: " . $location . "<br>";
        
        // Use direct PDO instead of executeQuery
        try {
            $stmt = $conn->prepare("INSERT INTO areas (name, location, description, contact_person, contact_email, contact_phone, created_by, status) VALUES (?, ?, ?, ?, ?, ?, ?, 'active')");
            $result = $stmt->execute([$name, $location, $description, $contact_person, $contact_email, $contact_phone, $user['id']]);
            
            if ($result) {
                $insertId = $conn->lastInsertId();
                echo "✅ Area created successfully! ID: " . $insertId . "<br>";
            } else {
                echo "❌ Failed to create area<br>";
                print_r($stmt->errorInfo());
            }
        } catch (Exception $e) {
            echo "❌ Error: " . $e->getMessage() . "<br>";
        }
    }

    // Show test form
    echo '<h3>Test Form</h3>
    <form method="POST">
        <input type="hidden" name="test_create" value="1">
        <p>Name: <input type="text" name="name" value="Test Area ' . date('H:i:s') . '" required></p>
        <p>Location: <input type="text" name="location" value="Test Location"></p>
        <p>Description: <textarea name="description">Test Description</textarea></p>
        <p>Contact Person: <input type="text" name="contact_person" value="Test Person"></p>
        <p>Contact Email: <input type="email" name="contact_email" value="test@example.com"></p>
        <p>Contact Phone: <input type="tel" name="contact_phone" value="1234567890"></p>
        <p><button type="submit">Create Test Area</button></p>
    </form>';

    // Show current areas
    echo "<h3>Current Areas</h3>";
    $stmt = $conn->query("SELECT * FROM areas ORDER BY id DESC LIMIT 5");
    $areas = $stmt->fetchAll();
    foreach ($areas as $area) {
        echo "ID: " . $area['id'] . ", Name: " . $area['name'] . "<br>";
    }

    // Show all events
    $stmt = $pdo->prepare("SELECT id, title, status, start_date FROM events");
    $stmt->execute();
    $events = $stmt->fetchAll(PDO::FETCH_ASSOC);
    
    echo "<h3>📅 All Events:</h3>";
    foreach ($events as $event) {
        $is_future = strtotime($event['start_date']) > strtotime($today);
        $color = ($event['status'] == 'active' && $is_future) ? 'green' : 'red';
        echo "<span style='color: {$color};'>ID: {$event['id']}, Title: {$event['title']}, Status: {$event['status']}, Date: {$event['start_date']}</span><br>";
    }
    
    echo "<br><a href='index.php' style='background: #007bff; color: white; padding: 12px 24px; text-decoration: none; border-radius: 8px;'>🏠 Test Landing Page</a>";
    
} catch (Exception $e) {
    echo "❌ Error: " . $e->getMessage();
}
?>

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