50 lines
1.2 KiB
PHP
50 lines
1.2 KiB
PHP
<?php
|
|
ob_start();
|
|
header('Content-Type: application/json');
|
|
|
|
$rootPath = dirname(dirname(__DIR__));
|
|
require_once($rootPath . "/src/config/env.php");
|
|
require_once($rootPath . '/src/config/functions.php');
|
|
require_once($rootPath . '/src/config/connection.php');
|
|
|
|
// Check admin status
|
|
session_start();
|
|
if (empty($_SESSION['user_id'])) {
|
|
ob_end_clean();
|
|
echo json_encode(['status' => 'error', 'message' => 'Unauthorized access']);
|
|
exit;
|
|
}
|
|
|
|
$user_role = getUserRole();
|
|
if (!in_array($user_role, ['admin', 'superadmin'])) {
|
|
ob_end_clean();
|
|
echo json_encode(['status' => 'error', 'message' => 'Unauthorized access']);
|
|
exit;
|
|
}
|
|
|
|
try {
|
|
$course_id = intval($_POST['course_id'] ?? 0);
|
|
|
|
if ($course_id <= 0) {
|
|
throw new Exception('Invalid course ID');
|
|
}
|
|
|
|
$stmt = $conn->prepare("DELETE FROM courses WHERE course_id = ?");
|
|
$stmt->bind_param("i", $course_id);
|
|
|
|
if (!$stmt->execute()) {
|
|
throw new Exception('Failed to delete course: ' . $stmt->error);
|
|
}
|
|
|
|
$stmt->close();
|
|
|
|
ob_end_clean();
|
|
echo json_encode(['status' => 'success', 'message' => 'Course deleted successfully']);
|
|
|
|
} catch (Exception $e) {
|
|
ob_end_clean();
|
|
echo json_encode(['status' => 'error', 'message' => $e->getMessage()]);
|
|
}
|
|
|
|
?>
|