diff --git a/main/admin/course_edit.php b/main/admin/course_edit.php index 645a36dda9..5721de51a3 100755 --- a/main/admin/course_edit.php +++ b/main/admin/course_edit.php @@ -414,6 +414,8 @@ if ($form->validate()) { ]; Database::update($course_table, $params, ['id = ?' => $courseId]); + CourseManager::saveSettingChanges($courseInfo, $params); + // update the extra fields $courseFieldValue = new ExtraFieldValue('course'); $courseFieldValue->saveFieldValues($course); @@ -478,10 +480,8 @@ if ($form->validate()) { Display::addFlash(Display::return_message(get_lang('ItemUpdated').': '.$message, 'info', false)); if ($visual_code_is_used) { Display::addFlash(Display::return_message($warn)); - header('Location: course_list.php'); - } else { - header('Location: course_list.php'); } + header('Location: course_list.php'); exit; } diff --git a/main/course_info/infocours.php b/main/course_info/infocours.php index 8379fdcddb..c6488a020e 100755 --- a/main/course_info/infocours.php +++ b/main/course_info/infocours.php @@ -43,7 +43,7 @@ if (!$is_allowedToEdit) { $htmlHeadXtra[] = api_get_css_asset('cropper/dist/cropper.min.css'); $htmlHeadXtra[] = api_get_asset('cropper/dist/cropper.min.js'); $show_delete_watermark_text_message = false; -if (api_get_setting('pdf_export_watermark_by_course') == 'true') { +if (api_get_setting('pdf_export_watermark_by_course') === 'true') { if (isset($_GET['delete_watermark'])) { PDF::delete_watermark($course_code); $show_delete_watermark_text_message = true; @@ -160,7 +160,7 @@ $form->addRule( ); $form->addElement('checkbox', 'delete_picture', null, get_lang('DeletePicture')); -if (api_get_setting('pdf_export_watermark_by_course') == 'true') { +if (api_get_setting('pdf_export_watermark_by_course') === 'true') { $url = PDF::get_watermark($course_code); $form->addText('pdf_export_watermark_text', get_lang('PDFExportWatermarkTextTitle'), false, ['size' => '60']); $form->addElement('file', 'pdf_export_watermark_path', get_lang('AddWaterMark')); @@ -179,7 +179,7 @@ if (api_get_setting('pdf_export_watermark_by_course') == 'true') { ); } -if (api_get_setting('allow_course_theme') == 'true') { +if (api_get_setting('allow_course_theme') === 'true') { $group = []; $group[] = $form->createElement( 'SelectTheme', @@ -307,7 +307,7 @@ $form->addPanelOption( // Documents $globalGroup = []; -if (api_get_setting('documents_default_visibility_defined_in_course') == 'true') { +if (api_get_setting('documents_default_visibility_defined_in_course') === 'true') { $group = [ $form->createElement('radio', 'documents_default_visibility', null, get_lang('Visible'), 'visible'), $form->createElement('radio', 'documents_default_visibility', null, get_lang('Invisible'), 'invisible'), @@ -632,7 +632,7 @@ $group[] = $form->createElement( $group[] = $form->createElement('radio', 'enable_lp_auto_launch', null, get_lang('Deactivate'), 0); $form->addGroup($group, '', [get_lang('LPAutoLaunch')]); -if (api_get_setting('allow_course_theme') == 'true') { +if (api_get_setting('allow_course_theme') === 'true') { // Allow theme into Learning path $group = []; $group[] = $form->createElement( @@ -677,7 +677,7 @@ if ($allowLPReturnLink === 'true') { 2 ), ]; - $form->addGroup($group, '', [get_lang("LpReturnLink")]); + $form->addGroup($group, '', [get_lang('LpReturnLink')]); } $exerciseInvisible = api_get_setting('exercise_invisible_in_session'); @@ -965,6 +965,12 @@ if ($form->validate() && is_settings_editable()) { $picture['tmp_name'], $updateValues['picture_crop_result'] ); + + Event::addEvent( + LOG_COURSE_SETTINGS_CHANGED, + 'course_picture', + $picture['name'] + ); } $visibility = $updateValues['visibility']; @@ -1015,8 +1021,6 @@ if ($form->validate() && is_settings_editable()) { } $activeLegal = isset($updateValues['activate_legal']) ? $updateValues['activate_legal'] : 0; - $table_course = Database::get_main_table(TABLE_MAIN_COURSE); - $params = [ 'title' => $updateValues['title'], 'course_language' => $updateValues['course_language'], @@ -1031,7 +1035,9 @@ if ($form->validate() && is_settings_editable()) { 'registration_code' => $updateValues['course_registration_password'], 'show_score' => $updateValues['show_score'], ]; - Database::update($table_course, $params, ['id = ?' => $courseId]); + $table = Database::get_main_table(TABLE_MAIN_COURSE); + Database::update($table, $params, ['id = ?' => $courseId]); + CourseManager::saveSettingChanges($_course, $params); // Insert/Updates course_settings table foreach ($courseSettings as $setting) { @@ -1043,6 +1049,7 @@ if ($form->validate() && is_settings_editable()) { api_get_course_int_id() ); } + // update the extra fields $courseFieldValue = new ExtraFieldValue('course'); $courseFieldValue->saveFieldValues($updateValues); diff --git a/main/exercise/question.class.php b/main/exercise/question.class.php index d8f31d0298..b2f50f4338 100755 --- a/main/exercise/question.class.php +++ b/main/exercise/question.class.php @@ -2119,7 +2119,6 @@ abstract class Question $header .= $exercise->getQuestionRibbon($class, $scoreLabel, $score['result'], $scoreCurrent); } - if ($this->type != READING_COMPREHENSION) { // Do not show the description (the text to read) if the question is of type READING_COMPREHENSION $header .= Display::div( diff --git a/main/inc/lib/api.lib.php b/main/inc/lib/api.lib.php index 5cb975e96a..e19390dfcc 100644 --- a/main/inc/lib/api.lib.php +++ b/main/inc/lib/api.lib.php @@ -176,6 +176,7 @@ define('DIR_HOTPOTATOES', '/HotPotatoes_files'); // event logs types define('LOG_COURSE_DELETE', 'course_deleted'); define('LOG_COURSE_CREATE', 'course_created'); +define('LOG_COURSE_SETTINGS_CHANGED', 'course_settings_changed'); // @todo replace 'soc_gr' with social_group define('LOG_GROUP_PORTAL_CREATED', 'soc_gr_created'); @@ -207,7 +208,6 @@ define('LOG_SESSION_ADD_USER', 'session_add_user'); define('LOG_SESSION_DELETE_USER', 'session_delete_user'); define('LOG_SESSION_ADD_COURSE', 'session_add_course'); define('LOG_SESSION_DELETE_COURSE', 'session_delete_course'); - define('LOG_SESSION_CATEGORY_CREATE', 'session_cat_created'); //changed in 1.9.8 define('LOG_SESSION_CATEGORY_DELETE', 'session_cat_deleted'); //changed in 1.9.8 define('LOG_CONFIGURATION_SETTINGS_CHANGE', 'settings_changed'); @@ -216,20 +216,15 @@ define('LOG_SUBSCRIBE_USER_TO_COURSE', 'user_subscribed'); define('LOG_UNSUBSCRIBE_USER_FROM_COURSE', 'user_unsubscribed'); define('LOG_ATTEMPTED_FORCED_LOGIN', 'attempted_forced_login'); define('LOG_PLUGIN_CHANGE', 'plugin_changed'); - define('LOG_HOMEPAGE_CHANGED', 'homepage_changed'); - define('LOG_PROMOTION_CREATE', 'promotion_created'); define('LOG_PROMOTION_DELETE', 'promotion_deleted'); define('LOG_CAREER_CREATE', 'career_created'); define('LOG_CAREER_DELETE', 'career_deleted'); - define('LOG_USER_PERSONAL_DOC_DELETED', 'user_doc_deleted'); define('LOG_WIKI_ACCESS', 'wiki_page_view'); - // All results from an exercise define('LOG_EXERCISE_RESULT_DELETE', 'exe_result_deleted'); - // Logs only the one attempt define('LOG_EXERCISE_ATTEMPT_DELETE', 'exe_attempt_deleted'); define('LOG_LP_ATTEMPT_DELETE', 'lp_attempt_deleted'); @@ -2295,6 +2290,7 @@ function api_format_course_array($course_data) $_course['extLink']['url'] = $course_data['department_url']; $_course['extLink']['name'] = $course_data['department_name']; $_course['categoryCode'] = $course_data['faCode']; + $_course['category_code'] = $course_data['faCode']; $_course['categoryName'] = $course_data['faName']; $_course['visibility'] = $course_data['visibility']; $_course['subscribe_allowed'] = $course_data['subscribe']; diff --git a/main/inc/lib/course.lib.php b/main/inc/lib/course.lib.php index a579347a19..4f402f84e0 100755 --- a/main/inc/lib/course.lib.php +++ b/main/inc/lib/course.lib.php @@ -5707,13 +5707,23 @@ class CourseManager $value = implode(',', $value); } - if (self::hasCourseSetting($variable, $courseId)) { + $settingFromDatabase = self::getCourseSetting($variable, $courseId); + + if (!empty($settingFromDatabase)) { // Update Database::update( $courseSettingTable, ['value' => $value], ['variable = ? AND c_id = ?' => [$variable, $courseId]] ); + + if ($settingFromDatabase['value'] != $value) { + Event::addEvent( + LOG_COURSE_SETTINGS_CHANGED, + $variable, + $settingFromDatabase['value']." -> $value" + ); + } } else { // Create Database::insert( @@ -5725,29 +5735,67 @@ class CourseManager 'variable' => $variable, ] ); + + Event::addEvent( + LOG_COURSE_SETTINGS_CHANGED, + $variable, + $value + ); } return true; } /** - * Check if course setting exists. + * Get course setting. * * @param string $variable * @param int $courseId * - * @return bool + * @return array */ - public static function hasCourseSetting($variable, $courseId) + public static function getCourseSetting($variable, $courseId) { $courseSetting = Database::get_course_table(TABLE_COURSE_SETTING); $courseId = (int) $courseId; $variable = Database::escape_string($variable); - $sql = "SELECT variable FROM $courseSetting + $sql = "SELECT variable, value FROM $courseSetting WHERE c_id = $courseId AND variable = '$variable'"; $result = Database::query($sql); - return Database::num_rows($result) > 0; + return Database::fetch_array($result); + } + + public static function saveSettingChanges($courseInfo, $params) + { + if (empty($courseInfo) || empty($params)) { + return false; + } + + $userId = api_get_user_id(); + $now = api_get_utc_datetime(); + + foreach ($params as $name => $value) { + $emptyValue = ' - '; + if (isset($courseInfo[$name]) && $courseInfo[$name] != $value) { + if ('' !== $courseInfo[$name]) { + $emptyValue = $courseInfo[$name]; + } + + $changedTo = $emptyValue.' -> '.$value; + + Event::addEvent( + LOG_COURSE_SETTINGS_CHANGED, + $name, + $changedTo, + $now, + $userId, + $courseInfo['real_id'] + ); + } + } + + return true; } /**