37 lines
1.6 KiB
Python
37 lines
1.6 KiB
Python
import re
|
|
|
|
with open('includes/app.php', 'r', encoding='utf-8') as f:
|
|
content = f.read()
|
|
|
|
# 1. Add is_super_admin()
|
|
role_func = """
|
|
function is_super_admin(): bool {
|
|
if (isset($_GET['role'])) {
|
|
$_SESSION['role'] = $_GET['role'];
|
|
}
|
|
return ($_SESSION['role'] ?? 'super_admin') === 'super_admin';
|
|
}
|
|
"""
|
|
if 'function is_super_admin' not in content:
|
|
content = content.replace("function env_value", role_func + "\nfunction env_value", 1)
|
|
|
|
# 2. Update the header
|
|
header_old = '<span class="header-chip">صلاحية: المشرف العام</span>'
|
|
header_new = """<?php
|
|
$isSuperAdmin = is_super_admin();
|
|
$roleName = $isSuperAdmin ? 'المشرف العام' : 'مدير المركز';
|
|
$nextRole = $isSuperAdmin ? 'center_admin' : 'super_admin';
|
|
$currentUrl = $_SERVER['REQUEST_URI'];
|
|
$roleSwitchUrl = strpos($currentUrl, '?') !== false
|
|
? preg_replace('/([?&])role=[^&]*(&|$)/', '$1', $currentUrl)
|
|
: $currentUrl;
|
|
$roleSwitchUrl = rtrim($roleSwitchUrl, '?&');
|
|
$roleSwitchUrl .= (strpos($roleSwitchUrl, '?') !== false ? '&' : '?') . 'role=' . $nextRole;
|
|
?>
|
|
<a href=\"<?= e($roleSwitchUrl) ?>\" class=\"header-chip text-decoration-none bg-primary text-white\" style=\"cursor:pointer;\" title=\"اضغط للتبديل\">صلاحية: <?= e($roleName) ?> ⟳</a>"""
|
|
content = content.replace(header_old, header_new)
|
|
|
|
with open('includes/app.php', 'w', encoding='utf-8') as f:
|
|
f.write(content)
|
|
|