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

require_once "includes/db.php"; // Veritabanı bağlantısı

// Ders silme işlemi
if (isset($_GET["course_id"])) {
    $course_id = $_GET["course_id"];
    $stmt = $conn->prepare("DELETE FROM courses WHERE id = ?");
    $stmt->execute([$course_id]);
    header("Location: admin_dashboard.php");
    exit;
}

$stmt = $conn->prepare("SELECT * FROM courses");
$stmt->execute();
$courses = $stmt->fetchAll();
?>

<!DOCTYPE html>
<html lang="tr">
<head>
    <meta charset="UTF-8">
    <title>Ders Sil</title>
    <link rel="stylesheet" href="css/style.css">
</head>
<body>
    <h2>Ders Sil</h2>
    <table>
        <thead>
            <tr>
                <th>Ders Adı</th>
                <th>Açıklama</th>
                <th>İşlem</th>
            </tr>
        </thead>
        <tbody>
            <?php foreach ($courses as $course): ?>
            <tr>
                <td><?= htmlspecialchars($course["name"]) ?></td>
                <td><?= htmlspecialchars($course["description"]) ?></td>
                <td><a href="delete_course.php?course_id=<?= $course['id'] ?>">Sil</a></td>
            </tr>
            <?php endforeach; ?>
        </tbody>
    </table>
    <p><a href="admin_dashboard.php">Geri dön</a></p>
</body>
</html>
