<!-- PACK503I_ACTIVE_SIDEBAR_LINKS role=<?php echo htmlspecialchars((string)($_SESSION['conference_role'] ?? $_SESSION['role'] ?? $_SESSION['user_role'] ?? ''), ENT_QUOTES, 'UTF-8'); ?> -->
<?php
/*
 * Pack503H
 * Clean legacy sidebar links partial.
 * No nested if/endif wrappers.
 * Every link is checked by ec_can_menu() through li().
 */

if (session_status() !== PHP_SESSION_ACTIVE) {
    @session_start();
}

if (defined('BASE_PATH') && file_exists(BASE_PATH . '/app/helpers/permissions.php')) {
    require_once BASE_PATH . '/app/helpers/permissions.php';
}

if (!function_exists('base_path')) {
    function base_path(string $path = ''): string
    {
        return '/easychair/' . ltrim($path, '/');
    }
}

if (!function_exists('ec_sidebar_h')) {
    function ec_sidebar_h($v): string
    {
        return htmlspecialchars((string)$v, ENT_QUOTES, 'UTF-8');
    }
}

if (!function_exists('ec_sidebar_lang')) {
    function ec_sidebar_lang(): string
    {
        if (function_exists('ec_lang')) {
            return ec_lang();
        }
        return $_SESSION['lang'] ?? 'ar';
    }
}

if (!function_exists('ec_sidebar_t')) {
    function ec_sidebar_t(string $ar, string $en): string
    {
        return ec_sidebar_lang() === 'en' ? $en : $ar;
    }
}

if (!function_exists('ec_legacy_can_menu')) {
    function ec_legacy_can_menu(string $url): bool
    {
        $url = trim($url);

        if ($url === '') {
            return true;
        }

        if (strpos($url, '/easychair/') !== 0) {
            $url = '/easychair/' . ltrim($url, '/');
        }

        $sensitive = [
            '/easychair/admin/email-templates',
            '/easychair/admin/test-email',
            '/easychair/admin/rbac-matrix',
        ];

        if (function_exists('ec_can_menu')) {
            return ec_can_menu($url);
        }

        /*
         * Safe default:
         * if permission helper is not loaded, hide sensitive admin tools.
         */
        return !in_array($url, $sensitive, true);
    }
}

if (!function_exists('li')) {
    function li(string $url, string $icon, string $label, string $match = ''): void
    {
        $fullUrl = $url;

        if (strpos($fullUrl, '/easychair/') !== 0) {
            $fullUrl = '/easychair/' . ltrim($fullUrl, '/');
        }

        if (!ec_legacy_can_menu($fullUrl)) {
            return;
        }

        $requestPath = parse_url($_SERVER['REQUEST_URI'] ?? '', PHP_URL_PATH) ?: '';
        $matchPath = $match ?: $fullUrl;

        if (strpos($matchPath, '/easychair/') !== 0) {
            $matchPath = '/easychair/' . ltrim($matchPath, '/');
        }

        $active = rtrim($requestPath, '/') === rtrim($matchPath, '/');

        echo '<li class="nav-item ec-sidebar-item">';
        echo '<a class="nav-link ec-sidebar-link ' . ($active ? 'active' : '') . '" href="' . ec_sidebar_h($fullUrl) . '">';
        echo '<i class="' . ec_sidebar_h($icon) . '"></i> ';
        echo '<span>' . ec_sidebar_h($label) . '</span>';
        echo '</a>';
        echo '</li>';
    }
}

$role = $_SESSION['conference_role'] ?? $_SESSION['role'] ?? $_SESSION['user_role'] ?? '';
?>

<?php li(base_path('admin/dashboard'), 'fa-solid fa-gauge-high', ec_sidebar_t('لوحة التحكم', 'Dashboard'), '/admin/dashboard'); ?>

<?php li(base_path('admin/conferences'), 'fa-solid fa-folder-open', ec_sidebar_t('المؤتمرات', 'Conferences'), '/admin/conferences'); ?>

<?php li(base_path('admin/submission-search'), 'fa-solid fa-magnifying-glass', ec_sidebar_t('بحث التقديمات', 'Submission Search'), '/admin/submission-search'); ?>

<?php li(base_path('admin/submissions'), 'fa-solid fa-inbox', ec_sidebar_t('التقديمات', 'Submissions'), '/admin/submissions'); ?>

<?php li(base_path('admin/reviewer-assignments'), 'fa-solid fa-user-plus', ec_sidebar_t('توزيع المحكمين', 'Reviewer Assignments'), '/admin/reviewer-assignments'); ?>

<?php li(base_path('admin/reviewers'), 'fa-solid fa-user-check', ec_sidebar_t('المحكمون', 'Reviewers'), '/admin/reviewers'); ?>

<?php li(base_path('admin/reviewer-expertise'), 'fa-solid fa-brain', ec_sidebar_t('خبرات المحكمين', 'Reviewer Expertise'), '/admin/reviewer-expertise'); ?>

<?php li(base_path('admin/review-form'), 'fa-solid fa-clipboard-list', ec_sidebar_t('نموذج التحكيم', 'Review Form'), '/admin/review-form'); ?>

<?php li(base_path('admin/review-monitor'), 'fa-solid fa-chart-line', ec_sidebar_t('مراقبة التحكيم', 'Review Monitor'), '/admin/review-monitor'); ?>

<?php li(base_path('admin/decisions'), 'fa-solid fa-gavel', ec_sidebar_t('القرارات', 'Decisions'), '/admin/decisions'); ?>

<?php li(base_path('admin/workflow'), 'fa-solid fa-diagram-project', ec_sidebar_t('سير العمل', 'Workflow'), '/admin/workflow'); ?>

<?php li(base_path('admin/submission-stage-rules'), 'fa-solid fa-list-ol', ec_sidebar_t('قواعد مراحل التقديم', 'Submission Stage Rules'), '/admin/submission-stage-rules'); ?>

<?php li(base_path('admin/workflow-notifications'), 'fa-solid fa-bell', ec_sidebar_t('تنبيهات سير العمل', 'Workflow Notifications'), '/admin/workflow-notifications'); ?>

<?php li(base_path('admin/conference-home'), 'fa-solid fa-palette', ec_sidebar_t('الصفحة الذكية', 'Smart Homepage'), '/admin/conference-home'); ?>

<?php li(base_path('admin/branding'), 'fa-solid fa-image', ec_sidebar_t('الشعارات والهوية', 'Branding'), '/admin/branding'); ?>

<?php li(base_path('admin/committee-images'), 'fa-solid fa-images', ec_sidebar_t('صور اللجان والمشاركين', 'Committee Images'), '/admin/committee-images'); ?>

<?php li(base_path('admin/conference-business'), 'fa-solid fa-calendar-days', ec_sidebar_t('الأعمال والجلسات', 'Conference Business'), '/admin/conference-business'); ?>

<?php li(base_path('admin/production'), 'fa-solid fa-industry', ec_sidebar_t('الإنتاج والنسخة النهائية', 'Production'), '/admin/production'); ?>

<?php li(base_path('admin/issues'), 'fa-solid fa-book', ec_sidebar_t('الإصدارات والوقائع', 'Issues / Proceedings'), '/admin/issues'); ?>

<?php li(base_path('admin/certificates'), 'fa-solid fa-certificate', ec_sidebar_t('الشهادات', 'Certificates'), '/admin/certificates'); ?>

<?php li(base_path('admin/conference-mail'), 'fa-solid fa-envelope-circle-check', ec_sidebar_t('بريد المؤتمر', 'Conference Mail'), '/admin/conference-mail'); ?>

<?php li(base_path('admin/email-templates'), 'fa-solid fa-envelope-open-text', ec_sidebar_t('قوالب البريد', 'Email Templates'), '/admin/email-templates'); ?>

<?php li(base_path('admin/org-smtp'), 'fa-solid fa-server', ec_sidebar_t('SMTP المؤسسة', 'Organization SMTP'), '/admin/org-smtp'); ?>

<?php li(base_path('admin/test-email'), 'fa-solid fa-paper-plane', ec_sidebar_t('اختبار البريد', 'Test Email'), '/admin/test-email'); ?>

<?php li(base_path('admin/notification-broadcast'), 'fa-solid fa-bullhorn', ec_sidebar_t('إرسال إشعار', 'Notification Broadcast'), '/admin/notification-broadcast'); ?>

<?php li(base_path('admin/notification-digest'), 'fa-solid fa-newspaper', ec_sidebar_t('ملخص الإشعارات', 'Notification Digest'), '/admin/notification-digest'); ?>

<?php li(base_path('admin/notification-audit'), 'fa-solid fa-bell-circle-check', ec_sidebar_t('تدقيق الإشعارات', 'Notification Audit'), '/admin/notification-audit'); ?>

<?php li(base_path('admin/users'), 'fa-solid fa-users', ec_sidebar_t('إدارة المستخدمين', 'Users'), '/admin/users'); ?>

<?php li(base_path('admin/roles'), 'fa-solid fa-user-shield', ec_sidebar_t('الأدوار', 'Roles'), '/admin/roles'); ?>


<?php li(base_path('admin/rbac-scope'), 'fa-solid fa-copy', ec_sidebar_t('مدير نطاق الصلاحيات', 'RBAC Scope Manager'), '/admin/rbac-scope'); ?>

<?php li(base_path('admin/org-smtp'), 'fa-solid fa-server', ec_sidebar_t('SMTP المؤسسة', 'Organization SMTP'), '/admin/org-smtp'); ?>

<?php li(base_path('admin/conference-role-permissions'), 'fa-solid fa-user-lock', ec_sidebar_t('صلاحيات أدوار المؤتمر', 'Conference Role Permissions'), '/admin/conference-role-permissions'); ?>

<?php li(base_path('admin/conference-business-permissions'), 'fa-solid fa-shield-halved', ec_sidebar_t('صلاحيات أعمال المؤتمر', 'Conference Business Permissions'), '/admin/conference-business-permissions'); ?>

<?php li(base_path('admin/custom-rights'), 'fa-solid fa-key', ec_sidebar_t('الحقوق المخصصة', 'Custom Rights'), '/admin/custom-rights'); ?>

<?php li(base_path('admin/rbac-matrix'), 'fa-solid fa-sliders', ec_sidebar_t('مصفوفة الصلاحيات', 'RBAC Matrix'), '/admin/rbac-matrix'); ?>

<?php li(base_path('admin/profile-completion'), 'fa-solid fa-chart-pie', ec_sidebar_t('اكتمال الملف', 'Profile Completion'), '/admin/profile-completion'); ?>

<?php li(base_path('admin/profile-fields'), 'fa-solid fa-list-check', ec_sidebar_t('حقول الملف', 'Profile Fields'), '/admin/profile-fields'); ?>

<?php li(base_path('admin/dictionary'), 'fa-solid fa-language', ec_sidebar_t('قاموس الترجمة', 'Dictionary'), '/admin/dictionary'); ?>

<?php li(base_path('admin/dictionary-scan'), 'fa-solid fa-magnifying-glass', ec_sidebar_t('ماسح القاموس', 'Dictionary Scanner'), '/admin/dictionary-scan'); ?>

<?php li(base_path('admin/dictionary-replace'), 'fa-solid fa-wand-magic-sparkles', ec_sidebar_t('استبدال القاموس', 'Dictionary Replace'), '/admin/dictionary-replace'); ?>

<?php li(base_path('profile'), 'fa-solid fa-user-graduate', ec_sidebar_t('ملفي الأكاديمي', 'My Academic Profile'), '/profile'); ?>

<?php li(base_path('notifications'), 'fa-solid fa-bell', ec_sidebar_t('إشعاراتي', 'My Notifications'), '/notifications'); ?>

<?php li(base_path('select-conference'), 'fa-solid fa-building-columns', ec_sidebar_t('تغيير المؤتمر', 'Change Conference'), '/select-conference?manual=1'); ?>

<?php li(base_path('select-role'), 'fa-solid fa-building-columns', ec_sidebar_t('تغيير المؤتمر', 'Change Conference'), '/select-role?manual=1'); ?>

<?php li(base_path('logout'), 'fa-solid fa-right-from-bracket', ec_sidebar_t('تسجيل الخروج', 'Logout'), '/logout'); ?>
