<?php
session_start();
require_once '../config/database.php';

// Check if user is logged in
if (!isset($_SESSION['user_id'])) {
    header('Location: ../login.php');
    exit();
}

$user_role = $_SESSION['user_role'];
$user_name = $_SESSION['user_name'];

echo "<h2>Debug Information</h2>";
echo "<p>User ID: " . $_SESSION['user_id'] . "</p>";
echo "<p>User Role: " . $user_role . "</p>";
echo "<p>User Name: " . $user_name . "</p>";

// Check assignments
try {
    $stmt = $pdo->query("SELECT COUNT(*) FROM assignments");
    $count = $stmt->fetchColumn();
    echo "<p>Total assignments in database: " . $count . "</p>";
    
    if ($count > 0) {
        echo "<h3>Sample assignments:</h3>";
        $stmt = $pdo->query("SELECT id, title, status FROM assignments LIMIT 5");
        $assignments = $stmt->fetchAll(PDO::FETCH_ASSOC);
        echo "<ul>";
        foreach ($assignments as $assignment) {
            echo "<li>ID: " . $assignment['id'] . ", Title: " . htmlspecialchars($assignment['title']) . ", Status: " . $assignment['status'] . "</li>";
        }
        echo "</ul>";
    }
} catch (Exception $e) {
    echo "<p>Error fetching assignments: " . $e->getMessage() . "</p>";
}

echo "<p><a href='assignments.php'>Back to Assignments</a></p>";
?>