35 lines
1.6 KiB
Python
35 lines
1.6 KiB
Python
import sys
|
|
|
|
with open('checkout.php', 'r') as f:
|
|
content = f.read()
|
|
|
|
old_code = """if ($courseIdForView > 0) {
|
|
$course = db()->query("SELECT * FROM courses WHERE id = $courseIdForView")->fetch();
|
|
}"""
|
|
|
|
new_code = """if ($courseIdForView > 0) {
|
|
$course = db()->query("SELECT * FROM courses WHERE id = $courseIdForView")->fetch();
|
|
if ($course) {
|
|
if (!$course['registration_open']) {
|
|
$msg = current_lang() === 'ar' ? 'التسجيل في هذه الدورة/الدفعة مغلق حالياً.' : 'Registration for this course/batch is currently closed.';
|
|
die("<div style='padding:2rem;text-align:center;font-family:sans-serif'><h1>" . $msg . "</h1><a href='index.php'>" . (current_lang() === 'ar' ? 'العودة' : 'Back') . "</a></div>");
|
|
}
|
|
if ($course['max_students'] > 0) {
|
|
$enrolled = db()->query("SELECT COUNT(*) FROM course_students WHERE course_id = $courseIdForView")->fetchColumn();
|
|
if ($enrolled >= $course['max_students']) {
|
|
$msg = current_lang() === 'ar' ? 'لقد وصلت هذه الدورة إلى الحد الأقصى لعدد الطلاب.' : 'This course has reached its maximum capacity.';
|
|
die("<div style='padding:2rem;text-align:center;font-family:sans-serif'><h1>" . $msg . "</h1><a href='index.php'>" . (current_lang() === 'ar' ? 'العودة' : 'Back') . "</a></div>");
|
|
}
|
|
}
|
|
} else {
|
|
die('Course not found');
|
|
}
|
|
}"""
|
|
|
|
content = content.replace(old_code, new_code)
|
|
|
|
with open('checkout.php', 'w') as f:
|
|
f.write(content)
|
|
|
|
print("Done")
|