Browse Source

Merge branch 'ofaj_dev' of https://github.com/chamilo/chamilo-lms into ofaj_dev

Alex Aragón 6 years ago
parent
commit
5971051716

+ 6 - 5
load_search.php

@@ -148,17 +148,18 @@ $extraFieldValue = new ExtraFieldValue('session');
 $extraFieldValueUser = new ExtraFieldValue('user');
 
 $theme = 'theme_fr';
-$lang = api_get_interface_language();
+$lang = $defaultLangCible = api_get_interface_language();
 
 if ($userToLoadInfo) {
     $lang = $userToLoadInfo['language'];
-    /*$targetLanguageInfo = $extraFieldValueUser->get_values_by_handler_and_field_variable(
+    $targetLanguageInfo = $extraFieldValueUser->get_values_by_handler_and_field_variable(
         $userToLoad,
         'langue_cible'
     );
+
     if (!empty($targetLanguageInfo)) {
-        $lang = strtolower($targetLanguageInfo['value']);
-    }*/
+        $defaultLangCible = $targetLanguageInfo['value'];
+    }
 
     switch ($lang) {
         case 'italian':
@@ -935,7 +936,7 @@ if (!empty($filterToSend)) {
     }
 
     // Language
-    $lang = isset($params['extra_langue_cible']) ? $params['extra_langue_cible'] : $lang;
+    $lang = isset($params['extra_langue_cible']) ? $params['extra_langue_cible'] : $defaultLangCible;
     $lang = strtolower($lang);
 
     if ($userStartDate && !empty($userStartDate)) {

+ 7 - 0
main/course_info/infocours.php

@@ -864,8 +864,15 @@ $group = [
 ];
 $myButton = $form->addButtonSave(get_lang('SaveSettings'), 'submit_save', true);
 
+// Forum settings
+$groupNotification = [
+    $form->createElement('radio', 'hide_forum_notifications', null, get_lang('Yes'), 1),
+    $form->createElement('radio', 'hide_forum_notifications', null, get_lang('No'), 2),
+];
+
 $globalGroup = [
     get_lang('EnableForumAutoLaunch') => $group,
+    get_lang('HideForumNotifications') => $groupNotification,
     '' => $myButton,
 ];
 

+ 59 - 18
main/forum/forumfunction.inc.php

@@ -2324,12 +2324,17 @@ function get_post_information($post_id)
     $table_posts = Database::get_course_table(TABLE_FORUM_POST);
     $table_users = Database::get_main_table(TABLE_MAIN_USER);
     $course_id = api_get_course_int_id();
+    $post_id = (int) $post_id;
+
+    if (empty($post_id)) {
+        return [];
+    }
 
     $sql = "SELECT posts.*, email FROM ".$table_posts." posts, ".$table_users." users
             WHERE
                 c_id = $course_id AND
                 posts.poster_id=users.user_id AND
-                posts.post_id = ".intval($post_id);
+                posts.post_id = ".$post_id;
     $result = Database::query($sql);
     $row = Database::fetch_array($result, 'ASSOC');
 
@@ -2855,11 +2860,9 @@ function store_thread(
     }
 
     $post_date = new DateTime(api_get_utc_datetime(), new DateTimeZone('UTC'));
-
+    $visible = 1;
     if ($current_forum['approval_direct_post'] == '1' && !api_is_allowed_to_edit(null, true)) {
         $visible = 0; // The post has not been approved yet.
-    } else {
-        $visible = 1;
     }
     $clean_post_title = $values['post_title'];
 
@@ -2993,7 +2996,6 @@ function store_thread(
 
     $em->persist($lastPost);
     $em->flush();
-
     $lastPostId = $lastPost->getIid();
 
     $logInfo = [
@@ -3180,8 +3182,22 @@ function show_add_post_form($current_forum, $forum_setting, $action, $id = '', $
             'UserStatus' => 'student',
         ]
     );
-
     $form->addRule('post_text', get_lang('ThisFieldIsRequired'), 'required');
+
+    if (in_array($action, ['replythread', 'replymessage', 'quote'])) {
+        $extraFields = new ExtraField('forum_post');
+        $extraFields->addElements(
+            $form,
+            null,
+            [], //exclude
+            false, // filter
+            false, // tag as select
+            ['ask_for_revision'], //show only fields
+            [], // order fields
+            [] // extra data);
+        );
+    }
+
     $iframe = null;
     $myThread = Security::remove_XSS($myThread);
     if ($forum_setting['show_thread_iframe_on_reply'] && $action != 'newthread' && !empty($myThread)) {
@@ -3376,18 +3392,34 @@ function show_add_post_form($current_forum, $forum_setting, $action, $id = '', $
                 case 'replymessage':
                     $postId = store_reply($current_forum, $values);
 
-                    if ($postId && isset($values['give_revision']) && $values['give_revision'] == 1) {
-                        $extraFieldValues = new ExtraFieldValue('forum_post');
-                        $params = [
-                            'item_id' => $postId,
-                            'extra_revision_language' => $values['extra_revision_language'],
-                        ];
-                        $extraFieldValues->saveFieldValues(
-                            $params,
-                            false,
-                            false,
-                            ['revision_language']
-                        );
+                    if ($postId) {
+                        if (isset($values['give_revision']) && $values['give_revision'] == 1) {
+                            $extraFieldValues = new ExtraFieldValue('forum_post');
+                            $params = [
+                                'item_id' => $postId,
+                                'extra_revision_language' => $values['extra_revision_language'],
+                            ];
+                            $extraFieldValues->saveFieldValues(
+                                $params,
+                                false,
+                                false,
+                                ['revision_language']
+                            );
+                        }
+
+                        if (in_array($action, ['replythread', 'replymessage', 'quote'])) {
+                            $extraFieldValues = new ExtraFieldValue('forum_post');
+                            $params = [
+                                'item_id' => $postId,
+                                'extra_ask_for_revision' => $values['extra_ask_for_revision'],
+                            ];
+                            $extraFieldValues->saveFieldValues(
+                                $params,
+                                false,
+                                false,
+                                ['ask_for_revision']
+                            );
+                        }
                     }
                     break;
             }
@@ -5672,6 +5704,15 @@ function get_notifications($content, $id)
 function send_notifications($forum_id = 0, $thread_id = 0, $post_id = 0)
 {
     $_course = api_get_course_info();
+
+    $forumCourseId = api_get_configuration_value('global_forums_course_id');
+    if (!empty($forumCourseId)) {
+        if ($_course['real_id'] == $forumCourseId) {
+
+            return false;
+        }
+    }
+
     $forum_id = (int) $forum_id;
 
     // The content of the mail

+ 26 - 20
main/forum/index.php

@@ -47,6 +47,9 @@ $_course = api_get_course_info();
 $sessionId = api_get_session_id();
 $_user = api_get_user_info();
 
+$hideNotifications = api_get_course_setting('hide_forum_notifications');
+$hideNotifications = $hideNotifications == 1;
+
 // Including necessary files.
 require_once 'forumconfig.inc.php';
 require_once 'forumfunction.inc.php';
@@ -456,25 +459,28 @@ if (is_array($forumCategories)) {
 
                         $toolActions = null;
                         $forumInfo['alert'] = null;
-                        // The number of topics and posts.
-                        if ($forum['forum_of_group'] !== '0') {
-                            if (is_array($mywhatsnew_post_info) && !empty($mywhatsnew_post_info)) {
-                                $forumInfo['alert'] = ' '.
-                                Display::return_icon(
-                                    'alert.png',
-                                    get_lang('Forum'),
-                                    null,
-                                    ICON_SIZE_SMALL
-                                );
-                            }
-                        } else {
-                            if (is_array($mywhatsnew_post_info) && !empty($mywhatsnew_post_info)) {
-                                $forumInfo['alert'] = ' '.Display::return_icon(
-                                    'alert.png',
-                                    get_lang('Forum'),
-                                    null,
-                                    ICON_SIZE_SMALL
-                                );
+
+                        if ($hideNotifications == false) {
+                            // The number of topics and posts.
+                            if ($forum['forum_of_group'] !== '0') {
+                                if (is_array($mywhatsnew_post_info) && !empty($mywhatsnew_post_info)) {
+                                    $forumInfo['alert'] = ' '.
+                                        Display::return_icon(
+                                            'alert.png',
+                                            get_lang('Forum'),
+                                            null,
+                                            ICON_SIZE_SMALL
+                                        );
+                                }
+                            } else {
+                                if (is_array($mywhatsnew_post_info) && !empty($mywhatsnew_post_info)) {
+                                    $forumInfo['alert'] = ' '.Display::return_icon(
+                                            'alert.png',
+                                            get_lang('Forum'),
+                                            null,
+                                            ICON_SIZE_SMALL
+                                        );
+                                }
                             }
                         }
                         $poster_id = null;
@@ -551,7 +557,7 @@ if (is_array($forumCategories)) {
                             }
                         }
 
-                        if (!api_is_anonymous() && api_is_allowed_to_session_edit(false, true)) {
+                        if (!api_is_anonymous() && api_is_allowed_to_session_edit(false, true) && $hideNotifications == false) {
                             $toolActions .= '<a href="'.api_get_self().'?'.api_get_cidreq()
                                 .'&action=notify&content=forum&id='.$forum['forum_id'].'">'
                                 .Display::return_icon($iconnotify, get_lang('NotifyMe'), null, ICON_SIZE_SMALL)

+ 6 - 4
main/forum/viewforum.php

@@ -49,6 +49,9 @@ $courseId = api_get_course_int_id();
 $groupInfo = GroupManager::get_group_properties($groupId);
 $isTutor = GroupManager::is_tutor_of_group($userId, $groupInfo, $courseId);
 
+$hideNotifications = api_get_course_setting('hide_forum_notifications');
+$hideNotifications = $hideNotifications == 1;
+
 $isAllowedToEdit = api_is_allowed_to_edit(false, true) && api_is_allowed_to_session_edit(false, true);
 
 /* MAIN DISPLAY SECTION */
@@ -434,10 +437,9 @@ if (is_array($threads)) {
                 $my_whatsnew_post_info = $whatsnew_post_info[$my_forum][$row['thread_id']];
             }
 
-            if (is_array($my_whatsnew_post_info) && !empty($my_whatsnew_post_info)) {
+            $newPost = '';
+            if ($hideNotifications == false && is_array($my_whatsnew_post_info) && !empty($my_whatsnew_post_info)) {
                 $newPost = ' '.Display::return_icon('alert.png', get_lang('Forum'), null, ICON_SIZE_SMALL);
-            } else {
-                $newPost = '';
             }
 
             $name = api_get_person_name($row['firstname'], $row['lastname']);
@@ -639,7 +641,7 @@ if (is_array($threads)) {
                 }
             }
             $icon_liststd = 'user.png';
-            if (!api_is_anonymous() && api_is_allowed_to_session_edit(false, true)) {
+            if (!api_is_anonymous() && api_is_allowed_to_session_edit(false, true) && $hideNotifications == false) {
                 $iconsEdit .= '<a href="'.api_get_self().'?'.$cidreq.'&forum='
                     .$my_forum
                     ."&action=notify&content=thread&id={$row['thread_id']}"

+ 24 - 8
main/inc/ajax/lang.ajax.php

@@ -15,7 +15,11 @@ switch ($action) {
         $languageList = api_get_languages();
         $hideAll = '';
         foreach ($languageList['all'] as $language) {
-            $hideAll .= '$("span:lang('.$language['isocode'].')").hide();';
+            $hideAll .= '$("span:lang('.$language['isocode'].')").filter(
+            function() {
+                // Ignore ckeditor classes
+                return !this.className.match(/cke(.*)/);
+            }).hide();';
         }
 
         $userInfo = api_get_user_info();
@@ -24,14 +28,21 @@ switch ($action) {
 
         echo '
             $(document).ready(function() {
-                '.$hideAll.'
-                var defaultLanguageFromUser = "'.$languageInfo['isocode'].'";
-                
-                $("span:lang('.$languageInfo['isocode'].')").show();
+                 '.$hideAll.'                 
+                var defaultLanguageFromUser = "'.$languageInfo['isocode'].'";                                
+                $("span:lang('.$languageInfo['isocode'].')").filter(
+                    function() {
+                        // Ignore ckeditor classes
+                        return !this.className.match(/cke(.*)/);
+                }).show();
                 
                 var defaultLanguage = "";
                 var langFromUserFound = false;
-                $(this).find("span").each(function() {
+                $(this).find("span").filter(
+                    function() {
+                        // Ignore ckeditor classes
+                        return !this.className.match(/cke(.*)/);
+                }).each(function() {
                     defaultLanguage = $(this).attr("lang");                            
                     if (defaultLanguage) {
                         $(this).before().next("br").remove();                
@@ -43,8 +54,13 @@ switch ($action) {
                 
                 // Show default language
                 if (langFromUserFound == false && defaultLanguage) {
-                    $("span:lang("+defaultLanguage+")").show();
-                }                   
+                    $("span:lang("+defaultLanguage+")").filter(
+                    function() {
+                            // Ignore ckeditor classes
+                            return !this.className.match(/cke(.*)/);
+                    }).show();
+                }                  
+
             });
         ';
         break;

+ 1 - 0
main/inc/lib/course.lib.php

@@ -5577,6 +5577,7 @@ class CourseManager
             'show_course_in_user_language',
             'email_to_teachers_on_new_work_feedback',
             'student_delete_own_publication',
+            'hide_forum_notifications',
         ];
 
         $courseModels = ExerciseLib::getScoreModels();