
<?php
session_start();
include 'dbconnection.php';

if (!isset($_SESSION['emp_type']) || $_SESSION['emp_type'] !== 'admin') {
    die("Unauthorized access");
}

if (isset($_GET['id'])) {
    $id = intval($_GET['id']);
    
    // Optional: Check if student exists
    $check = $con->query("SELECT * FROM teacher WHERE t_id = $id");
    if ($check->num_rows > 0) {
        $con->query("DELETE FROM teacher WHERE t_id = $id");
    }
    
    header("Location: view_teacher.php");
    exit;
} else {
    die("Invalid request");
}
?>
<div class="back-button" style="margin-top: 10px;">
    <a href="#" onclick="confirmDelete(<?php echo $id; ?>)" style="background: #d9534f;">
        🗑 حذف استاد
    </a>
</div>
<script>
function confirmDelete(id) {
    if (confirm("آیا مطمئن هستید که می‌خواهید این استاد را حذف کنید؟")) {
        window.location.href = "delete_teacher.php?id=" + id;
    }
}
</script>
