<?php
session_start();
if (!isset($_SESSION["admin_id"])) {
    header("Location: admin.php");
    exit;
}

if (!isset($_GET["ogrenci_id"])) {
    die("Geçersiz istek.");
}

$ogrenci_id = $_GET["ogrenci_id"];

try {
    $db = new PDO("mysql:host=localhost;dbname=yenicesi_2305610353;charset=utf8", "yenicesi_2305610353", "2305610353C.");
} catch (PDOException $e) {
    die("Veritabanı bağlantı hatası: " . $e->getMessage());
}

// Dersleri getir
$sorgu = $db->query("SELECT * FROM dersler");
$dersler = $sorgu->fetchAll();
?>

<!DOCTYPE html>
<html lang="tr">
<head>
    <meta charset="UTF-8">
    <title>Ders Ata</title>
    <link rel="stylesheet" href="css/admin_dashboard.css">
</head>
<body>

<header>🎓 Öğrenciye Ders Ata</header>

<div class="container">
    <form action="ders_ata_islem.php" method="POST">
        <input type="hidden" name="ogrenci_id" value="<?= $ogrenci_id ?>">

        <label>Ders Seç:</label>
        <select name="ders_id">
            <?php foreach ($dersler as $ders): ?>
                <option value="<?= $ders['id'] ?>"><?= htmlspecialchars($ders['ders_adi']) ?> (<?= htmlspecialchars($ders['kodu']) ?>)</option>
            <?php endforeach; ?>
        </select><br><br>

        <button type="submit">Ders Ata</button>
        <a href="admin_dashboard.php" class="back-link">⬅ Geri Dön</a>
    </form>
</div>

</body>
</html>
