39669-vm/patch_cycles_switcher.py
2026-04-16 16:39:04 +00:00

41 lines
1.7 KiB
Python

import re
import glob
files = ['students.php', 'teachers.php', 'assessments.php', 'attendance.php']
for file in files:
with open(file, 'r', encoding='utf-8') as f:
content = f.read()
# Change <div class="col-lg-7"> to conditionally be 12
# But wait, is it col-lg-7?
content = re.sub(r'<div class="col-lg-7">', r'<div class="col-lg-<?= is_super_admin() ? \'7\' : \'12\' ?>', content)
# Wrap col-lg-5 in is_super_admin
# We will find the start of col-lg-5 that contains "التبديل بين الدورات"
# and ends at the closing div
# Let's find:
# <div class="col-lg-5">
# <div class="app-card sidebar-card h-100">
# <div class="section-title mb-3">التبديل بين الدورات</div>
# ...
# </div>
# </div>
pattern = r'(<div class="col-lg-5">\s*<div class="app-card sidebar-card h-100">\s*<div class="section-title mb-3">التبديل بين الدورات</div>.*?</div>\s*</div>)'
def replacer(match):
return f"<?php if (is_super_admin()): ?>\n{match.group(1)}\n<?php endif; ?>"
content = re.sub(pattern, replacer, content, flags=re.DOTALL)
# Also restrict the button "إدارة الدورات الموسمية"
# <a class="btn btn-outline-secondary" href="<?= e($approvedSchoolUrl) ?>#cycles">إدارة الدورات الموسمية</a>
# We should hide this button for center_admin
btn_pattern = r'(<a class="btn btn-outline-secondary" href="<\?= e\(\$approvedSchoolUrl\) \?>#cycles">إدارة الدورات الموسمية</a>)'
content = re.sub(btn_pattern, r'<?php if (is_super_admin()): ?>\1<?php endif; ?>', content)
with open(file, 'w', encoding='utf-8') as f:
f.write(content)