30 lines
1.3 KiB
Python
30 lines
1.3 KiB
Python
import sys
|
|
|
|
with open('index.php', 'r') as f:
|
|
content = f.read()
|
|
|
|
old_button = """<a class="btn btn-dark" href="<?= h(app_url('checkout.php', ['course_id' => $course['id']])) ?>"><?= h(t('Enroll Now', 'سجل الآن')) ?></a>"""
|
|
|
|
new_button = """<?php
|
|
$isFull = false;
|
|
$isClosed = !$course['registration_open'];
|
|
if ($course['max_students'] > 0) {
|
|
$enrolled = db()->query("SELECT COUNT(*) FROM course_students WHERE course_id = " . $course['id'])->fetchColumn();
|
|
if ($enrolled >= $course['max_students']) {
|
|
$isFull = true;
|
|
}
|
|
}
|
|
if ($isClosed || $isFull):
|
|
?>
|
|
<button class="btn btn-secondary" disabled><?= h($isClosed ? t('Registration Closed', 'التسجيل مغلق') : t('Class Full', 'مكتمل العدد')) ?></button>
|
|
<?php else: ?>
|
|
<a class="btn btn-dark" href="<?= h(app_url('checkout.php', ['course_id' => $course['id']])) ?>"><?= h(t('Enroll Now', 'سجل الآن')) ?></a>
|
|
<?php endif; ?>"""
|
|
|
|
content = content.replace(old_button, new_button)
|
|
|
|
with open('index.php', 'w') as f:
|
|
f.write(content)
|
|
|
|
print("Done")
|