<!DOCTYPE html>
<html lang="bn">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Photo Display Test</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Hind+Siliguri:wght@300;400;500;600;700&display=swap" rel="stylesheet">
    <style>
        body { 
            font-family: 'Hind Siliguri', sans-serif;
            background-color: #f8f9fa;
            padding: 20px;
        }
        .student-photo {
            max-width: 100%;
            height: auto;
            border-radius: 5px;
        }
    </style>
</head>
<body>
    <div class="container">
        <h2>Photo Display Test for Admit Card</h2>
        
        <?php
        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();
        
        if ($student):
        ?>
        <div class="card">
            <div class="card-header">
                <h5>Student Information with Photo</h5>
            </div>
            <div class="card-body">
                <div class="row">
                    <div class="col-md-6">
                        <p><strong>Name:</strong> <?php echo htmlspecialchars($student['first_name'] . ' ' . $student['last_name']); ?></p>
                        <p><strong>ID:</strong> <?php echo htmlspecialchars($student['student_id']); ?></p>
                        <p><strong>Class:</strong> <?php echo htmlspecialchars($student['class_name'] . ' ' . $student['section']); ?></p>
                    </div>
                    <div class="col-md-6">
                        <?php if (!empty($student['photo'])): ?>
                            <?php 
                            // 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) {
                                if (file_exists($path)) {
                                    $valid_photo_path = $path;
                                    break;
                                }
                            }
                            ?>
                            <?php if ($valid_photo_path): ?>
                                <div class="text-center mb-3">
                                    <p><strong>Student Photo:</strong></p>
                                    <img src="<?php echo htmlspecialchars($valid_photo_path); ?>" alt="ছাত্র/ছাত্রীর ছবি" class="student-photo rounded" style="max-width: 120px; max-height: 150px; border: 1px solid #ddd;">
                                </div>
                                <p class="text-success">Photo found and displayed successfully!</p>
                            <?php else: ?>
                                <p class="text-danger">Photo file not found at any expected location.</p>
                                <p>Checked paths:</p>
                                <ul>
                                    <?php foreach ($photo_paths as $path): ?>
                                        <li><?php echo htmlspecialchars($path); ?> - <?php echo file_exists($path) ? 'Found' : 'Not found'; ?></li>
                                    <?php endforeach; ?>
                                </ul>
                            <?php endif; ?>
                        <?php else: ?>
                            <p class="text-warning">No photo recorded in database for this student.</p>
                        <?php endif; ?>
                    </div>
                </div>
            </div>
        </div>
        <?php else: ?>
            <div class="alert alert-warning">
                Student not found.
            </div>
        <?php endif; ?>
    </div>
</body>
</html>