window.location.href='$path';"; } exit; } // Permission helpers function canView($page = null) { if (isAdmin()) return true; if ($page) { return $_SESSION['permissions'][$page]['view'] ?? false; } return $_SESSION['can_view'] ?? false; } function canAdd($page = null) { if (isAdmin()) return true; if ($page) { return $_SESSION['permissions'][$page]['add'] ?? false; } return $_SESSION['can_add'] ?? false; } function canEdit($page = null) { if (isAdmin()) return true; if ($page) { return $_SESSION['permissions'][$page]['edit'] ?? false; } return $_SESSION['can_edit'] ?? false; } function canDelete($page = null) { if (isAdmin()) return true; if ($page) { return $_SESSION['permissions'][$page]['delete'] ?? false; } return $_SESSION['can_delete'] ?? false; } function canViewInternal() { return canView('internal'); } // Added for auditing display function getAuditUserName($user_id) { // Debugging modification to see what was actually passed if ($user_id === null || $user_id === '') return 'غير متوفر (Empty)'; static $userCache = null; if ($userCache === null) { $userCache = []; try { $stmt = db()->query("SELECT id, username, full_name FROM users"); while ($u = $stmt->fetch()) { $userCache[$u['id']] = $u['full_name'] ?: $u['username']; } } catch(Exception $e) {} } return $userCache[$user_id] ?? 'غير معروف (ID: ' . htmlspecialchars($user_id ?? '') . ')'; }