<?php
$rules = [
    'customers/index.php' => 'require_role_access(\'customer:view\');',
    'customers/create.php' => 'require_role_access(\'customer:create\');',
    'products/index.php' => 'require_role_access(\'product:view\');',
    'products/create.php' => 'require_admin();',
    'products/edit.php' => 'require_admin();',
    'products/import.php' => 'require_admin();',
    'products/import-preview.php' => 'require_admin();',
    'price-list/index.php' => 'require_role_access(\'product:view\');',
    'reports/index.php' => 'require_admin();',
    'settings/index.php' => 'require_admin();',
    'settings/quotation-branding.php' => 'require_admin();',
    'backups/index.php' => 'require_admin();',
    'users/index.php' => 'require_admin();',
    'activity-logs/index.php' => 'require_admin();'
];

$base = 'c:/xampp/htdocs/Fortunes_Quotation/public/';

foreach ($rules as $file => $rule) {
    $path = $base . $file;
    if (file_exists($path)) {
        $content = file_get_contents($path);
        if (strpos($content, $rule) === false) {
            $content = preg_replace('/<\?php\s+/', "<?php\n" . $rule . "\n", $content, 1);
            file_put_contents($path, $content);
            echo "Updated $file\n";
        }
    }
}
