<?php
/**
 * PERMISSION ENFORCEMENT REGISTRY
 * 
 * This file maintains a registry of all admin pages and which ones need enforcement.
 * It automatically applies permission checks to admin pages.
 * 
 * To enable enforcement on a page, follow the examples in ENFORCEMENT_GUIDE.php
 */

return [
    // Feature => [pages to enforce, feature name, critical actions]
    'manage_products' => [
        'pages' => [
            'admin_add_product.php',
            'admin_edit_product.php',
            'admin_products.php',
        ],
        'feature' => 'manage_products',
        'critical_actions' => ['create', 'delete', 'edit'],
        'priority' => 'HIGH',
        'notes' => 'Delete protection is critical to prevent data loss',
        'api_handlers' => [],
    ],
    
    'manage_blogs' => [
        'pages' => [
            'admin_add_blog.php',
            'admin_edit_blog.php',
            'admin_blogs.php',
        ],
        'feature' => 'manage_blogs',
        'critical_actions' => ['create', 'delete', 'edit'],
        'priority' => 'HIGH',
        'notes' => 'Delete protection is critical to prevent data loss',
        'api_handlers' => [],
    ],
    
    'manage_news' => [
        'pages' => [
            'admin_add_news.php',
            'admin_manage_news.php',
        ],
        'feature' => 'manage_news',
        'critical_actions' => ['create', 'delete', 'edit'],
        'priority' => 'HIGH',
        'notes' => 'Delete protection is critical',
        'api_handlers' => [
            'api_manage_news.php',
        ],
    ],
    
    'manage_orders' => [
        'pages' => [
            'admin_orders.php',
        ],
        'feature' => 'manage_orders',
        'critical_actions' => ['edit', 'delete'],
        'priority' => 'HIGH',
        'notes' => 'Edit protection ensures sub-admins cannot modify order details',
        'api_handlers' => [],
    ],
    
    'manage_users' => [
        'pages' => [
            'admin_manage_users.php',
        ],
        'feature' => 'manage_users',
        'critical_actions' => ['create', 'edit', 'delete'],
        'priority' => 'HIGH',
        'notes' => 'Critical: Prevent unauthorized user creation, deletion, or privilege escalation',
        'api_handlers' => [
            'api_add_user.php',
            'admin_delete_user.php',
        ],
    ],
    
    'manage_pages' => [
        'pages' => [
            'admin_manage_pages.php',
        ],
        'feature' => 'manage_pages',
        'critical_actions' => ['create', 'edit', 'delete'],
        'priority' => 'MEDIUM',
        'notes' => 'Content management - delete protection important',
        'api_handlers' => [
            'api_manage_pages.php',
        ],
    ],
    
    'manage_carousel' => [
        'pages' => [
            'admin_manage_carousel.php',
        ],
        'feature' => 'manage_carousel',
        'critical_actions' => ['create', 'edit', 'delete'],
        'priority' => 'MEDIUM',
        'notes' => 'Carousel management',
        'api_handlers' => [],
    ],
    
    'manage_slider_images' => [
        'pages' => [
            'admin_manage_slider.php',
        ],
        'feature' => 'manage_slider_images',
        'critical_actions' => ['create', 'edit', 'delete'],
        'priority' => 'MEDIUM',
        'notes' => 'Slider image management',
        'api_handlers' => [],
    ],
    
    'manage_video' => [
        'pages' => [
            'admin_manage_video.php',
        ],
        'feature' => 'manage_video',
        'critical_actions' => ['create', 'edit', 'delete'],
        'priority' => 'MEDIUM',
        'notes' => 'Video content management',
        'api_handlers' => [],
    ],
    
    'manage_awards' => [
        'pages' => [
            'admin_manage_awards.php',
        ],
        'feature' => 'manage_awards',
        'critical_actions' => ['create', 'edit', 'delete'],
        'priority' => 'LOW',
        'notes' => 'Awards/badges management',
        'api_handlers' => [],
    ],
    
    'manage_seo' => [
        'pages' => [
            'admin_seo_manager.php',
        ],
        'feature' => 'manage_seo',
        'critical_actions' => ['edit'],
        'priority' => 'LOW',
        'notes' => 'SEO settings - typically editor access only',
        'api_handlers' => [],
    ],
    
    'manage_footer_settings' => [
        'pages' => [
            'admin_manage_footer.php',
        ],
        'feature' => 'manage_footer_settings',
        'critical_actions' => ['edit'],
        'priority' => 'LOW',
        'notes' => 'Footer configuration',
        'api_handlers' => [],
    ],
    
    'manage_homepage' => [
        'pages' => [
            'admin_manage_homepage.php',
        ],
        'feature' => 'manage_homepage',
        'critical_actions' => ['edit'],
        'priority' => 'LOW',
        'notes' => 'Homepage layout and content',
        'api_handlers' => [],
    ],
    
    'manage_marquee' => [
        'pages' => [
            'admin_manage_marquee.php',
        ],
        'feature' => 'manage_marquee',
        'critical_actions' => ['create', 'edit', 'delete'],
        'priority' => 'LOW',
        'notes' => 'Marquee management',
        'api_handlers' => [],
    ],
];

/*

=== IMPLEMENTATION INSTRUCTIONS ===

The files listed above need to be updated to include permission enforcement.
Follow the patterns in ENFORCEMENT_GUIDE.php.

For each file listed, add:

1. At the TOP (after session_start):
   require_once __DIR__ . '/helpers/admin_page_header.php';
   AdminPageHeader::requirePage('manage_products');  // Feature name

2. Get capabilities for UI rendering:
   $guard = AdminPageHeader::getGuard('manage_products');
   $caps = $guard->getCapabilities();

3. In API handlers (POST requests):
   if ($_POST['action'] === 'delete') {
       AdminPageHeader::requireAction('manage_products', 'delete');
       // Delete logic continues...
   }

4. Hide UI elements based on capabilities:
   <!-- Show delete button only if can delete -->
   <?php if ($caps['can_delete']): ?>
       <button onclick="deleteItem(...)">Delete</button>
   <?php endif; ?>

=== PRIORITY ORDER FOR IMPLEMENTATION ===

Start with HIGH priority pages first - these prevent data loss:
1. admin_products.php + admin_add_product.php + admin_edit_product.php
2. admin_blogs.php + admin_add_blog.php + admin_edit_blog.php
3. admin_manage_news.php + admin_add_news.php
4. admin_orders.php
5. admin_manage_users.php (critical: prevent privilege escalation)
6. admin_manage_pages.php

Then MEDIUM priority:
7. admin_manage_carousel.php
8. admin_manage_slider.php
9. admin_manage_video.php
10. admin_manage_awards.php

Finally LOW priority (mostly settings pages):
11. admin_seo_manager.php
12. admin_manage_footer.php
13. admin_manage_homepage.php
14. admin_manage_marquee.php

*/

?>
