94 lines
3.0 KiB
PHP
94 lines
3.0 KiB
PHP
<?php
|
|
$content = file_get_contents('includes/app.php');
|
|
|
|
$content = str_replace(
|
|
'\'notes\' => \'',
|
|
'\'notes\' => \'',
|
|
'\'subjects\' => [],
|
|
$content
|
|
);
|
|
|
|
$old_loop = <<<'EOD'
|
|
foreach ($data as $key => $_value) {
|
|
$data[$key] = clean_text((string) ($input[$key] ?? ''), $key === 'notes' ? 1000 : 190);
|
|
}
|
|
EOD;
|
|
|
|
$new_loop = <<<'EOD'
|
|
foreach ($data as $key => $_value) {
|
|
if ($key === 'subjects') {
|
|
$data[$key] = is_array($input[$key] ?? []) ? $input[$key] : [];
|
|
continue;
|
|
}
|
|
$data[$key] = clean_text((string) ($input[$key] ?? ''), $key === 'notes' ? 1000 : 190);
|
|
}
|
|
EOD;
|
|
$content = str_replace($old_loop, $new_loop, $content);
|
|
|
|
$old_val = <<<'EOD'
|
|
if ($startDate !== '' && $endDate !== '' && strtotime($endDate) < strtotime($startDate)) {
|
|
$errors['end_date'] = 'يجب أن يكون تاريخ النهاية بعد البداية.';
|
|
}
|
|
EOD;
|
|
|
|
$new_val = $old_val . <<<'EOD'
|
|
|
|
if (empty($data['subjects'])) {
|
|
$errors['subjects'] = 'يرجى اختيار مادة واحدة على الأقل.';
|
|
} else {
|
|
$data['subjects'] = array_map('intval', $data['subjects']);
|
|
}
|
|
EOD;
|
|
$content = str_replace($old_val, $new_val, $content);
|
|
|
|
$old_insert_sql = <<<'EOD'
|
|
'INSERT INTO center_applications (
|
|
center_name, city, center_type, gender_scope, director_name, phone, email,
|
|
expected_students, start_date, end_date, notes, status, submitted_at, updated_at
|
|
) VALUES (
|
|
:center_name, :city, :center_type, :gender_scope, :director_name, :phone, :email,
|
|
:expected_students, :start_date, :end_date, :notes, :status, NOW(), NOW()
|
|
)'
|
|
EOD;
|
|
|
|
$new_insert_sql = <<<'EOD'
|
|
'INSERT INTO center_applications (
|
|
center_name, city, center_type, gender_scope, director_name, phone, email,
|
|
expected_students, start_date, end_date, notes, subjects, status, submitted_at, updated_at
|
|
) VALUES (
|
|
:center_name, :city, :center_type, :gender_scope, :director_name, :phone, :email,
|
|
:expected_students, :start_date, :end_date, :notes, :subjects, :status, NOW(), NOW()
|
|
)'
|
|
EOD;
|
|
$content = str_replace($old_insert_sql, $new_insert_sql, $content);
|
|
|
|
$old_execute = <<<'EOD'
|
|
':notes' => $data['notes'],
|
|
':status' => 'submitted',
|
|
]);
|
|
EOD;
|
|
|
|
$new_execute = <<<'EOD'
|
|
':notes' => $data['notes'],
|
|
':subjects' => json_encode($data['subjects']),
|
|
':status' => 'submitted',
|
|
]);
|
|
EOD;
|
|
$content = str_replace($old_execute, $new_execute, $content);
|
|
|
|
if (strpos($content, "function get_enabled_subjects") === false) {
|
|
$content .= <<<'EOD'
|
|
|
|
function get_enabled_subjects(): array
|
|
{
|
|
$pdo = db_connection();
|
|
$stmt = $pdo->query("SELECT id, name, description FROM subjects WHERE status = 'enabled' ORDER BY name ASC");
|
|
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
return $result !== false ? $result : [];
|
|
}
|
|
EOD;
|
|
}
|
|
|
|
file_put_contents('includes/app.php', $content);
|
|
echo "Patch applied.";
|