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

// Simple test - just show the search form
$classes = $pdo->query("SELECT id, name, section FROM classes WHERE status = 'active' ORDER BY name ASC")->fetchAll(PDO::FETCH_ASSOC);
$sessions = $pdo->query("SELECT DISTINCT session FROM students WHERE session IS NOT NULL AND session != '' ORDER BY session DESC LIMIT 10")->fetchAll(PDO::FETCH_COLUMN);
?>
<!DOCTYPE html>
<html>
<head>
    <title>Simple Search Test</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
</head>
<body>
    <div class="container mt-4">
        <h2>Simple Search Form Test</h2>
        
        <div class="alert alert-info">
            <p>If you can see this message and the form below, then the issue is not with the form itself, but with how it's integrated in public_home.php.</p>
        </div>
        
        <div class="card">
            <div class="card-body">
                <h5 class="mb-3" style="color: #006747;">
                    <i class="fas fa-search"></i> উন্নত সার্চ
                </h5>
                <form method="GET" class="row g-3">
                    <div class="col-md-3">
                        <label class="form-label">নাম</label>
                        <input type="text" name="name" class="form-control" placeholder="শিক্ষার্থীর নাম">
                    </div>
                    <div class="col-md-2">
                        <label class="form-label">রোল নম্বর</label>
                        <input type="text" name="roll" class="form-control" placeholder="রোল নম্বর">
                    </div>
                    <div class="col-md-3">
                        <label class="form-label">ক্লাস</label>
                        <select name="class" class="form-select">
                            <option value="">সকল ক্লাস</option>
                            <?php foreach ($classes as $cls): ?>
                                <option value="<?php echo $cls['id']; ?>">
                                    <?php echo htmlspecialchars($cls['name'] . ' - ' . $cls['section']); ?>
                                </option>
                            <?php endforeach; ?>
                        </select>
                    </div>
                    <div class="col-md-2">
                        <label class="form-label">সেশন</label>
                        <select name="session" class="form-select">
                            <option value="">সকল সেশন</option>
                            <?php foreach ($sessions as $session): ?>
                                <option value="<?php echo $session; ?>"><?php echo $session; ?></option>
                            <?php endforeach; ?>
                        </select>
                    </div>
                    <div class="col-md-2 d-flex align-items-end">
                        <button type="submit" class="btn btn-primary w-100">
                            <i class="fas fa-search"></i> Search
                        </button>
                    </div>
                </form>
            </div>
        </div>
        
        <div class="mt-4">
            <h4>Debug Info:</h4>
            <p>Classes found: <?php echo count($classes); ?></p>
            <p>Sessions found: <?php echo count($sessions); ?></p>
            
            <?php if (!empty($classes)): ?>
                <h5>Available Classes:</h5>
                <ul>
                <?php foreach ($classes as $cls): ?>
                    <li><?php echo htmlspecialchars($cls['name'] . ' - ' . $cls['section']); ?></li>
                <?php endforeach; ?>
                </ul>
            <?php endif; ?>
            
            <?php if (!empty($sessions)): ?>
                <h5>Available Sessions:</h5>
                <ul>
                <?php foreach ($sessions as $sess): ?>
                    <li><?php echo htmlspecialchars($sess); ?></li>
                <?php endforeach; ?>
                </ul>
            <?php endif; ?>
        </div>
    </div>
</body>
</html>