<?php
// Cek apakah user punya akses ke URL tertentu
function has_access($url) {
    $db = \Config\Database::connect();
    $id_role = session()->get('id_role');
    
    // Superadmin (1) bypass semua
    if ($id_role == 1) return true;
    
    $query = $db->table('role_permissions')
                ->join('menus', 'menus.id = role_permissions.id_menu')
                ->where('role_permissions.id_role', $id_role)
                ->where('menus.url', $url)
                ->countAllResults();
                
    return $query > 0;
}