<?php
// Simulate the exact conditions of the admit card page
require_once 'config/database.php';

// Test with student 6193 who has a photo
$student_id = 6193;

// Get student details (same query as in admit_card.php)
$stmt = $pdo->prepare("
    SELECT s.*, c.name as class_name, c.section
    FROM students s
    JOIN classes c ON s.class_id = c.id
    WHERE s.id = ?
");
$stmt->execute([$student_id]);
$student = $stmt->fetch();

echo "Testing admit card photo display for student 6193:\n";
echo "Student name: " . $student['first_name'] . " " . $student['last_name'] . "\n";
echo "Photo path from DB: " . ($student['photo'] ? $student['photo'] : 'None') . "\n";

if (!empty($student['photo'])) {
    // Exact same logic as in admit_card.php
    $photo_paths = [
        '../' . $student['photo'],  // Relative to exams directory
        $student['photo'],          // Direct path
        '../uploads/students/' . basename($student['photo']) // Alternative path
    ];
    
    $valid_photo_path = null;
    foreach ($photo_paths as $path) {
        echo "Checking path: $path -> " . (file_exists($path) ? 'FOUND' : 'NOT FOUND') . "\n";
        if (file_exists($path)) {
            $valid_photo_path = $path;
            break;
        }
    }
    
    if ($valid_photo_path) {
        echo "SUCCESS: Photo will be displayed on admit card!\n";
        echo "Photo URL: $valid_photo_path\n";
        
        // Test the HTML output that would be generated
        echo "\nGenerated HTML:\n";
        echo "<div class=\"text-center mb-3\">\n";
        echo "  <img src=\"" . htmlspecialchars($valid_photo_path) . "\" alt=\"ছাত্র/ছাত্রীর ছবি\" class=\"student-photo rounded\" style=\"max-width: 120px; max-height: 150px; border: 1px solid #ddd;\">\n";
        echo "</div>\n";
    } else {
        echo "ERROR: No valid photo path found.\n";
    }
} else {
    echo "No photo in database for this student.\n";
}
?>