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

// Test the improved path logic used in admit card
$student_id = 6193;

// Get student details
$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 improved photo path logic for student 6193:\n";
echo "Photo path from DB: " . ($student['photo'] ? $student['photo'] : 'None') . "\n";

if ($student['photo']) {
    // Simulate the improved logic from admit card
    $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 . " -> " . (file_exists($path) ? 'Exists' : 'Not found') . "\n";
        if (file_exists($path)) {
            $valid_photo_path = $path;
            break;
        }
    }
    
    if ($valid_photo_path) {
        echo "Valid photo path found: " . $valid_photo_path . "\n";
        echo "Photo will be displayed on admit card!\n";
    } else {
        echo "No valid photo path found.\n";
    }
}
?>