31 lines
811 B
PHP
31 lines
811 B
PHP
<?php
|
|
function isLoggedIn() {
|
|
return isset($_SESSION['user_id']);
|
|
}
|
|
|
|
function requireLogin() {
|
|
if (!isLoggedIn()) {
|
|
header("Location: index.php");
|
|
exit;
|
|
}
|
|
}
|
|
|
|
function requireAdmin() {
|
|
if (!isLoggedIn() || $_SESSION['role'] !== 'admin') {
|
|
echo "<script>
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
Swal.fire({
|
|
icon: 'error',
|
|
title: 'ไม่มีสิทธิ์เข้าถึงหน้านี้',
|
|
confirmButtonColor: '#4f46e5',
|
|
confirmButtonText: 'ตกลง'
|
|
}).then(() => {
|
|
window.location.href = 'dashboard.php';
|
|
});
|
|
});
|
|
</script>";
|
|
exit;
|
|
}
|
|
}
|
|
?>
|