diff --git a/public/main/course_info/infocours.php b/public/main/course_info/infocours.php
index cb1c24d315b..a3fbd34616c 100644
--- a/public/main/course_info/infocours.php
+++ b/public/main/course_info/infocours.php
@@ -85,7 +85,6 @@
';
-
// Course settings panel (top section of the page)
$courseSettingsPanel = [];
@@ -133,30 +132,42 @@
$showOnlyTheseFields
);
-$extraReady = isset($extra['jquery_ready_content']) ? $extra['jquery_ready_content'] : '';
+if (!empty($extra['jquery_ready_content'])) {
+ $htmlHeadXtra[] = $extra['jquery_ready_content'];
+}
-// JS: hide legacy header, open first panel, init extra-fields and picture preview
$htmlHeadXtra[] = '
+
';
@@ -215,17 +249,11 @@
// Course picture (upload + preview + delete)
$allowed_picture_types = api_get_supported_image_extensions(false);
-// Current picture preview (if any)
-if (!empty($image)) {
- // Use addElement("html", ...) so the element belongs to the form
- $picturePreviewElement = $form->addElement(
- 'html',
- $image
- );
- $courseSettingsPanel[] = $picturePreviewElement;
+$acceptPictureTypes = '';
+if (!empty($allowed_picture_types) && is_array($allowed_picture_types)) {
+ $acceptPictureTypes = '.'.implode(',.', $allowed_picture_types);
}
-// File input for new picture
$pictureElement = $form->addFile(
'picture',
get_lang('Add a picture'),
@@ -233,10 +261,19 @@
'id' => 'picture',
'class' => 'picture-form',
'crop_image' => true,
+ 'accept' => !empty($acceptPictureTypes) ? $acceptPictureTypes : 'image/*',
]
);
$courseSettingsPanel[] = $pictureElement;
+if (!empty($image)) {
+ $picturePreviewElement = $form->createElement(
+ 'html',
+ $image
+ );
+ $courseSettingsPanel[] = $picturePreviewElement;
+}
+
// Validation rules for picture type
$form->addRule(
'picture',
@@ -1147,14 +1184,17 @@
? $updateValues['course_registration_password']
: $courseEntity->getRegistrationCode();
+ $visibility = $updateValues['visibility'] ?? $courseEntity->getVisibility();
+ $deletePicture = !empty($updateValues['delete_picture'] ?? null);
+
$request = Container::getRequest();
- /** @var UploadedFile $uploadFile */
+ /** @var UploadedFile|null $uploadFile */
$uploadFile = $request->files->get('picture');
// Handle course picture upload / update
if (null !== $uploadFile) {
- $hasIllustration = $illustrationRepo->hasIllustration($courseEntity);
- if ($hasIllustration) {
+ // Replace existing illustration with the new one
+ if ($illustrationRepo->hasIllustration($courseEntity)) {
$illustrationRepo->deleteIllustration($courseEntity);
}
@@ -1179,13 +1219,14 @@
$uploadFile->getFilename()
);
}
- }
- $visibility = $updateValues['visibility'] ?? '';
- $deletePicture = $updateValues['delete_picture'] ?? '';
+ $deletePicture = false;
+ }
if ($deletePicture) {
- $illustrationRepo->deleteIllustration($courseEntity);
+ if ($illustrationRepo->hasIllustration($courseEntity)) {
+ $illustrationRepo->deleteIllustration($courseEntity);
+ }
}
$access_url_id = api_get_current_access_url_id();