30 lines
1.1 KiB
PHP
30 lines
1.1 KiB
PHP
<?php
|
|
$file = 'checkout.php';
|
|
$content = file_get_contents($file);
|
|
|
|
// check course limits
|
|
$limit_check = <<<PHP
|
|
if ($courseIdForView > 0) {
|
|
$course = db()->query("SELECT * FROM courses WHERE id = $courseIdForView")->fetch();
|
|
if ($course) {
|
|
if (! $course['registration_open']) {
|
|
die(t('Registration for this course is currently closed.', 'التسجيل في هذه الدورة مغلق حالياً.'));
|
|
}
|
|
if ($course['max_students'] > 0) {
|
|
$enrolled = db()->query("SELECT COUNT(*) FROM course_students WHERE course_id = $courseIdForView")->fetchColumn();
|
|
if ($enrolled >= $course['max_students']) {
|
|
die(t('This course has reached its maximum number of students.', 'لقد وصلت هذه الدورة إلى الحد الأقصى لعدد الطلاب.'));
|
|
}
|
|
}
|
|
} else {
|
|
die('Course not found');
|
|
}
|
|
}
|
|
PHP;
|
|
|
|
$content = preg_replace("/if \(\\$courseIdForView > 0\) \{\\s*\\\$course = db\(\)->query\(\"SELECT \* FROM courses WHERE id = \\\$courseIdForView\"\)->fetch\(\);\\s*\}", $limit_check, $content);
|
|
|
|
file_put_contents($file, $content);
|
|
echo "Done\n";
|
|
|