|
180 | 180 | get_lang('Delete picture') |
181 | 181 | ); |
182 | 182 |
|
183 | | - |
184 | 183 | if ('true' === api_get_setting('pdf_export_watermark_by_course')) { |
185 | 184 | $url = PDF::get_watermark($course_code); |
186 | 185 | $form->addText('pdf_export_watermark_text', get_lang('PDF watermark text'), false, ['size' => '60']); |
|
256 | 255 | true |
257 | 256 | ); |
258 | 257 |
|
259 | | - |
260 | 258 | // --- End of legacy block, from here panels start as usual --- |
261 | 259 |
|
262 | 260 | $url = api_get_path(WEB_CODE_PATH)."auth/inscription.php?c=$course_code&e=1"; |
|
1066 | 1064 | ), |
1067 | 1065 | ]; |
1068 | 1066 |
|
| 1067 | +// --------------------------------------------------------------------- |
| 1068 | +// Default values |
| 1069 | +// When a course setting is not stored yet, api_get_course_setting() returns -1. |
| 1070 | +// We still want radios/selects to have a clear default selected in the UI. |
| 1071 | +// This does NOT write anything to the database; it only affects form defaults. |
| 1072 | +// --------------------------------------------------------------------- |
| 1073 | +$defaultCourseSettings = [ |
| 1074 | + // Documents (only used if the corresponding platform setting enables these fields) |
| 1075 | + 'documents_default_visibility' => 'visible', |
| 1076 | + 'show_system_folders' => 1, |
| 1077 | + |
| 1078 | + // E-mail notifications (default to disabled) |
| 1079 | + 'email_alert_to_teacher_on_new_user_in_course' => 0, |
| 1080 | + 'email_alert_student_on_manual_subscription' => 0, |
| 1081 | + 'email_alert_students_on_new_homework' => 0, |
| 1082 | + 'email_alert_manager_on_new_doc' => 0, |
| 1083 | + 'email_alert_on_new_doc_dropbox' => 0, |
| 1084 | + 'email_to_teachers_on_new_work_feedback' => 2, // Yes=1, No=2 |
| 1085 | + |
| 1086 | + // User rights (default to disabled) |
| 1087 | + 'allow_user_edit_agenda' => 0, |
| 1088 | + 'allow_user_edit_announcement' => 0, |
| 1089 | + 'allow_user_image_forum' => 0, |
| 1090 | + 'allow_user_view_user_list' => 0, |
| 1091 | + |
| 1092 | + // Chat settings |
| 1093 | + 'allow_open_chat_window' => 0, |
| 1094 | + |
| 1095 | + // Learning path settings |
| 1096 | + 'allow_learning_path_theme' => 0, |
| 1097 | + 'lp_return_link' => 0, // Redirect to Course home |
| 1098 | + 'exercise_invisible_in_session' => 0, |
| 1099 | + |
| 1100 | + // Thematic |
| 1101 | + 'display_info_advance_inside_homecourse' => 0, |
| 1102 | + |
| 1103 | + // Certificates |
| 1104 | + 'allow_public_certificates' => 0, |
| 1105 | + |
| 1106 | + // Forum settings (Yes=1, No=2) |
| 1107 | + 'hide_forum_notifications' => 2, |
| 1108 | + 'subscribe_users_to_forum_notifications' => 2, |
| 1109 | + |
| 1110 | + // Assignments / Student publications |
| 1111 | + 'show_score' => 0, |
| 1112 | + 'student_delete_own_publication' => 0, |
| 1113 | + |
| 1114 | + // Auto-launch (UI helper radio) |
| 1115 | + 'auto_launch_option' => 'disable_auto_launch', |
| 1116 | + 'show_course_in_user_language' => 2, |
| 1117 | +]; |
| 1118 | + |
1069 | 1119 | // Set default values |
1070 | 1120 | $values = []; |
1071 | 1121 | $values['title'] = $courseEntity->getTitle(); |
|
1083 | 1133 | $courseSettings = CourseManager::getCourseSettingVariables(); |
1084 | 1134 | foreach ($courseSettings as $setting) { |
1085 | 1135 | $result = api_get_course_setting($setting); |
1086 | | - if ('-1' != $result) { |
| 1136 | + |
| 1137 | + // Stored setting: use it. |
| 1138 | + if ('-1' !== (string) $result) { |
1087 | 1139 | $values[$setting] = $result; |
| 1140 | + continue; |
| 1141 | + } |
| 1142 | + |
| 1143 | + // Not stored yet: fallback to UI defaults when available. |
| 1144 | + if (!array_key_exists($setting, $values) && array_key_exists($setting, $defaultCourseSettings)) { |
| 1145 | + $values[$setting] = $defaultCourseSettings[$setting]; |
1088 | 1146 | } |
1089 | 1147 | } |
1090 | 1148 |
|
|
1097 | 1155 | $values['email_alert_student_on_manual_subscription'] = 0; |
1098 | 1156 | } |
1099 | 1157 |
|
| 1158 | +// Auto-launch: compute the selected UI option from stored flags |
1100 | 1159 | $documentAutoLaunch = api_get_course_setting('enable_document_auto_launch'); |
1101 | 1160 | $lpAutoLaunch = api_get_course_setting('enable_lp_auto_launch'); |
1102 | 1161 | $exerciseAutoLaunch = api_get_course_setting('enable_exercise_auto_launch'); |
|
1119 | 1178 |
|
1120 | 1179 | $values['auto_launch_option'] = $defaultAutoLaunchOption; |
1121 | 1180 |
|
| 1181 | +// AI helpers: api_get_course_setting() can also return -1 for new courses. |
| 1182 | +// We want radios to default to "No" ("false") to avoid an empty state. |
1122 | 1183 | if ($enableAiHelpers) { |
1123 | 1184 | foreach ($aiOptions as $key => $label) { |
1124 | | - $values[$key] = api_get_course_setting($key); |
| 1185 | + $v = api_get_course_setting($key); |
| 1186 | + $values[$key] = ('-1' === (string) $v || $v === null || $v === '') ? 'false' : (string) $v; |
1125 | 1187 | } |
1126 | 1188 | } |
1127 | 1189 |
|
|
0 commit comments