diff --git a/koneksi.php b/koneksi.php index a876d1f..206d781 100644 --- a/koneksi.php +++ b/koneksi.php @@ -1,50 +1,50 @@ -connect_error) { - die(json_encode(['status'=>'error','message'=>'Koneksi DB gagal: '.$conn->connect_error])); -} -$conn->set_charset('utf8mb4'); - -// Helper: sanitasi -function bersih($str, $conn) { - return $conn->real_escape_string(htmlspecialchars(strip_tags(trim($str)))); -} - -// Helper: cek login -function cekLogin() { - if (!isset($_SESSION['user_id'])) { - header('Location: login.php'); - exit; - } -} - -// Helper: cek role -function cekRole(...$roles) { - if (!in_array($_SESSION['role'] ?? '', $roles)) { - header('Location: index.php?error=akses_ditolak'); - exit; - } -} - -// Helper: format rupiah -function rupiah($angka) { - return 'Rp ' . number_format($angka, 0, ',', '.'); -} - -// Helper: usia dari tanggal lahir -function hitungUsia($tgl) { - if (!$tgl || $tgl === '0000-00-00') return '-'; - $lahir = new DateTime($tgl); - $sekarang = new DateTime(); - return $lahir->diff($sekarang)->y . ' th'; +connect_error) { + die(json_encode(['status'=>'error','message'=>'Koneksi DB gagal: '.$conn->connect_error])); +} +$conn->set_charset('utf8mb4'); + +// Helper: sanitasi +function bersih($str, $conn) { + return $conn->real_escape_string(htmlspecialchars(strip_tags(trim($str)))); +} + +// Helper: cek login +function cekLogin() { + if (!isset($_SESSION['user_id'])) { + header('Location: login.php'); + exit; + } +} + +// Helper: cek role +function cekRole(...$roles) { + if (!in_array($_SESSION['role'] ?? '', $roles)) { + header('Location: index.php?error=akses_ditolak'); + exit; + } +} + +// Helper: format rupiah +function rupiah($angka) { + return 'Rp ' . number_format($angka, 0, ',', '.'); +} + +// Helper: usia dari tanggal lahir +function hitungUsia($tgl) { + if (!$tgl || $tgl === '0000-00-00') return '-'; + $lahir = new DateTime($tgl); + $sekarang = new DateTime(); + return $lahir->diff($sekarang)->y . ' th'; } \ No newline at end of file