Selaa lähdekoodia

Add forum_post extra field, add ask/give revision in forum posts

see BT#15173

requires 2 forum_post extra fields:
ask_for_revision: yes option
revision_language: select

Improve forum UI using twig #2800
removed old views
Julio 6 vuotta sitten
vanhempi
commit
6aa5d24817

+ 155 - 24
main/forum/forumfunction.inc.php

@@ -3135,13 +3135,14 @@ function show_add_post_form($current_forum, $forum_setting, $action, $id = '', $
     $myThread = isset($_GET['thread']) ? (int) $_GET['thread'] : '';
     $forumId = isset($_GET['forum']) ? (int) $_GET['forum'] : '';
     $my_post = isset($_GET['post']) ? (int) $_GET['post'] : '';
+    $giveRevision = isset($_GET['give_revision']) && $_GET['give_revision'] == 1 ? true : false;
 
     $url = api_get_self().'?'.http_build_query([
-            'action' => $action,
-            'forum' => $forumId,
-            'thread' => $myThread,
-            'post' => $my_post,
-        ]).'&'.api_get_cidreq();
+        'action' => $action,
+        'forum' => $forumId,
+        'thread' => $myThread,
+        'post' => $my_post,
+    ]).'&'.api_get_cidreq();
 
     $form = new FormValidator(
         'thread',
@@ -3263,6 +3264,21 @@ function show_add_post_form($current_forum, $forum_setting, $action, $id = '', $
         $form->addFile('user_upload', get_lang('Attachment'));
     }
 
+    if ($giveRevision) {
+        $form->addHidden('give_revision', 1);
+        $extraField = new ExtraField('forum_post');
+        $returnParams = $extraField->addElements(
+            $form,
+            null,
+            [], //exclude
+            false, // filter
+            false, // tag as select
+            ['revision_language'], //show only fields
+            [], // order fields
+            [] // extra data
+        );
+    }
+
     // Setting the class and text of the form title and submit button.
     if ($action == 'quote') {
         $form->addButtonCreate(get_lang('QuoteMessage'), 'SubmitPost');
@@ -3274,14 +3290,13 @@ function show_add_post_form($current_forum, $forum_setting, $action, $id = '', $
         $form->addButtonCreate(get_lang('CreateThread'), 'SubmitPost');
     }
 
+    $defaults['thread_peer_qualify'] = 0;
     if (!empty($form_values)) {
         $defaults['post_title'] = prepare4display($form_values['post_title']);
         $defaults['post_text'] = prepare4display($form_values['post_text']);
         $defaults['post_notification'] = (int) $form_values['post_notification'];
         $defaults['thread_sticky'] = (int) $form_values['thread_sticky'];
         $defaults['thread_peer_qualify'] = (int) $form_values['thread_peer_qualify'];
-    } else {
-        $defaults['thread_peer_qualify'] = 0;
     }
 
     // If we are quoting a message we have to retrieve the information of the post we are quoting so that
@@ -3332,7 +3347,7 @@ function show_add_post_form($current_forum, $forum_setting, $action, $id = '', $
     if ($form->validate()) {
         $check = Security::check_token('post');
         if ($check) {
-            $values = $form->exportValues();
+            $values = $form->getSubmitValues();
             if (isset($values['thread_qualify_gradebook']) &&
                 $values['thread_qualify_gradebook'] == '1' &&
                 empty($values['weight_calification'])
@@ -3347,7 +3362,6 @@ function show_add_post_form($current_forum, $forum_setting, $action, $id = '', $
 
                 return false;
             }
-
             switch ($action) {
                 case 'newthread':
                     $myThread = store_thread($current_forum, $values);
@@ -3356,8 +3370,21 @@ function show_add_post_form($current_forum, $forum_setting, $action, $id = '', $
                 case 'quote':
                 case 'replythread':
                 case 'replymessage':
-                    store_reply($current_forum, $values);
-
+                    $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']
+                        );
+                    }
                     break;
             }
 
@@ -3507,8 +3534,8 @@ function showQualify($option, $user_id, $thread_id)
     $table_threads = Database::get_course_table(TABLE_FORUM_THREAD);
 
     $course_id = api_get_course_int_id();
-    $user_id = intval($user_id);
-    $thread_id = intval($thread_id);
+    $user_id = (int) $user_id;
+    $thread_id = (int) $thread_id;
 
     if (empty($user_id) || empty($thread_id)) {
         return false;
@@ -3555,6 +3582,9 @@ function showQualify($option, $user_id, $thread_id)
  */
 function getThreadScoreHistory($user_id, $thread_id, $opt)
 {
+    $user_id = (int) $user_id;
+    $thread_id = (int) $thread_id;
+
     $table_threads_qualify_log = Database::get_course_table(TABLE_FORUM_THREAD_QUALIFY_LOG);
     $course_id = api_get_course_int_id();
 
@@ -3562,15 +3592,15 @@ function getThreadScoreHistory($user_id, $thread_id, $opt)
         $sql = "SELECT * FROM $table_threads_qualify_log
                 WHERE
                     c_id = $course_id AND
-                    thread_id='".Database::escape_string($thread_id)."' AND
-                    user_id='".Database::escape_string($user_id)."'
+                    thread_id='".$thread_id."' AND
+                    user_id='".$user_id."'
                 ORDER BY qualify_time";
     } else {
         $sql = "SELECT * FROM $table_threads_qualify_log
                 WHERE
                     c_id = $course_id AND
-                    thread_id='".Database::escape_string($thread_id)."' AND
-                    user_id='".Database::escape_string($user_id)."'
+                    thread_id='".$thread_id."' AND
+                    user_id='".$user_id."'
                 ORDER BY qualify_time DESC";
     }
     $rs = Database::query($sql);
@@ -3686,7 +3716,7 @@ function current_qualify_of_thread($threadId, $sessionId, $userId)
  * @param int   $courseId      Optional
  * @param int   $userId        Optional
  *
- * @return array
+ * @return int post id
  *
  * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  *
@@ -3710,16 +3740,15 @@ function store_reply($current_forum, $values, $courseId = 0, $userId = 0)
         return false;
     }
 
+    $visible = 1;
     if ($current_forum['approval_direct_post'] == '1' &&
         !api_is_allowed_to_edit(null, true)
     ) {
         $visible = 0;
-    } else {
-        $visible = 1;
     }
 
     $upload_ok = 1;
-    $return = [];
+    $new_post_id = 0;
 
     if ($upload_ok) {
         // We first store an entry in the forum_post table.
@@ -3833,7 +3862,7 @@ function store_reply($current_forum, $values, $courseId = 0, $userId = 0)
         );
     }
 
-    return $return;
+    return $new_post_id;
 }
 
 /**
@@ -6568,6 +6597,108 @@ function postIsEditableByStudent($forum, $post)
     }
 }
 
+/**
+ * @param int  $postId
+ *
+ * @return bool
+ */
+function savePostRevision($postId)
+{
+    $postData = get_post_information($postId);
+
+    if (empty($postData)) {
+        return false;
+    }
+
+    $userId = api_get_user_id();
+
+    if ($postData['poster_id'] != $userId) {
+        return false;
+    }
+
+    $status = (int) !postNeedsRevision($postId);
+    $extraFieldValue = new ExtraFieldValue('forum_post');
+    $params = [
+        'item_id' => $postId,
+        'extra_ask_for_revision' => ['extra_ask_for_revision' => $status],
+    ];
+    if (empty($status)) {
+        unset($params['extra_ask_for_revision']);
+    }
+    $extraFieldValue->saveFieldValues(
+        $params,
+        true,
+        false,
+        ['ask_for_revision']
+    );
+}
+
+function getPostRevision($postId)
+{
+    $extraFieldValue = new ExtraFieldValue('forum_post');
+    $value = $extraFieldValue->get_values_by_handler_and_field_variable(
+        $postId,
+        'revision_language'
+    );
+    $revision = '';
+    if ($value && isset($value['value'])) {
+        $revision =  $value['value'];
+    }
+
+    return $revision;
+}
+
+function postNeedsRevision($postId)
+{
+    $extraFieldValue = new ExtraFieldValue('forum_post');
+    $value = $extraFieldValue->get_values_by_handler_and_field_variable(
+        $postId,
+        'ask_for_revision'
+    );
+    $hasRevision = false;
+    if ($value && isset($value['value'])) {
+        return $value['value'] == 1;
+    }
+
+    return $hasRevision;
+}
+
+function getAskRevisionButton($postId, $threadInfo)
+{
+    $postId = (int) $postId;
+
+    $status = 'btn-default';
+    if (postNeedsRevision($postId)) {
+        $status = 'btn-success';
+    }
+
+    return Display::url(
+        get_lang('AskRevision'),
+        api_get_path(WEB_CODE_PATH).'forum/viewthread.php?'.
+        api_get_cidreq().'&action=ask_revision&post_id='.$postId.'&forum='.$threadInfo['forum_id'].'&thread='.$threadInfo['thread_id'],
+        ['class' => "btn $status", 'title' => get_lang('AskRevision')]
+    );
+}
+
+function giveRevisionButton($postId, $threadInfo)
+{
+    $postId = (int) $postId;
+
+    return Display::toolbarButton(
+        get_lang('GiveRevision'),
+       api_get_path(WEB_CODE_PATH).'forum/reply.php?'.api_get_cidreq().'&'.http_build_query([
+            'forum' => $threadInfo['forum_id'],
+            'thread' => $threadInfo['thread_id'],
+            'post' => $postId = (int) $postId,
+            'action' => 'replymessage',
+            'give_revision' => 1,
+        ]),
+        'reply',
+        'primary',
+        ['id' => "reply-to-post-{$postId}"]
+    );
+}
+
 /**
  * @param int   $postId
  * @param array $threadInfo
@@ -6575,13 +6706,14 @@ function postIsEditableByStudent($forum, $post)
  */
 function getReportButton($postId, $threadInfo)
 {
+    $postId = (int) $postId;
+
     return Display::url(
         Display::returnFontAwesomeIcon('flag'),
         api_get_path(WEB_CODE_PATH).'forum/viewthread.php?'.
         api_get_cidreq().'&action=report&post_id='.$postId.'&forum='.$threadInfo['forum_id'].'&thread='.$threadInfo['thread_id'],
         ['class' => 'btn btn-danger', 'title' => get_lang('Report')]
     );
-
 }
 
 /**
@@ -6644,7 +6776,6 @@ function getReportRecepients()
     }
 
     return $users;
-
 }
 
 /**

+ 1 - 1
main/forum/index.php

@@ -218,7 +218,7 @@ $defaultUserLanguage = ucfirst($_user['language']);
 $extraFieldValues = new ExtraFieldValue('user');
 $value = $extraFieldValues->get_values_by_handler_and_field_variable(api_get_user_id(), 'langue_cible');
 
-if ($value && isset($value['value'])) {
+if ($value && isset($value['value']) && !empty($value['value'])) {
     $defaultUserLanguage = ucfirst($value['value']);
 }
 

+ 423 - 38
main/forum/viewthread.php

@@ -1,6 +1,8 @@
 <?php
 /* For licensing terms, see /license.txt */
 
+use Chamilo\CourseBundle\Entity\CForumPost;
+
 /**
  * @author Julio Montoya <gugli100@gmail.com> UI Improvements + lots of bugfixes
  *
@@ -125,6 +127,14 @@ switch ($my_action) {
         header('Location: '.$currentUrl);
         exit;
         break;
+    case 'ask_revision':
+        $postId = isset($_GET['post_id']) ? $_GET['post_id'] : 0;
+
+        $result = savePostRevision($postId, $current_forum, $current_thread);
+        Display::addFlash(Display::return_message(get_lang('Saved')));
+        header('Location: '.$currentUrl);
+        exit;
+        break;
 }
 
 if (!empty($groupId)) {
@@ -144,36 +154,36 @@ if (!empty($groupId)) {
         'url' => api_get_path(WEB_CODE_PATH).'forum/viewthread.php?forum='.intval($_GET['forum']).'&'.api_get_cidreq().'&thread='.intval($_GET['thread']),
         'name' => Security::remove_XSS($current_thread['thread_title']),
     ];
-
-    Display::display_header('');
 } else {
     $my_search = isset($_GET['search']) ? $_GET['search'] : '';
-    if ($origin == 'learnpath') {
-        Display::display_reduced_header();
-    } else {
+    if ($origin != 'learnpath') {
         $interbreadcrumb[] = [
-            'url' => api_get_path(WEB_CODE_PATH).'forum/index.php?'.api_get_cidreq().'&search='.Security::remove_XSS(urlencode($my_search)),
+            'url' => api_get_path(WEB_CODE_PATH).'forum/index.php?'.api_get_cidreq().'&search='.Security::remove_XSS(
+                    urlencode($my_search)
+                ),
             'name' => $nameTools,
         ];
         $interbreadcrumb[] = [
-            'url' => api_get_path(WEB_CODE_PATH).'forum/viewforumcategory.php?forumcategory='.$current_forum_category['cat_id']."&search=".Security::remove_XSS(urlencode($my_search)),
+            'url' => api_get_path(
+                    WEB_CODE_PATH
+                ).'forum/viewforumcategory.php?forumcategory='.$current_forum_category['cat_id']."&search=".Security::remove_XSS(
+                    urlencode($my_search)
+                ),
             'name' => Security::remove_XSS($current_forum_category['cat_title']),
         ];
         $interbreadcrumb[] = [
-            'url' => api_get_path(WEB_CODE_PATH).'forum/viewforum.php?'.api_get_cidreq().'&forum='.intval($_GET['forum'])."&search=".Security::remove_XSS(urlencode($my_search)),
+            'url' => api_get_path(WEB_CODE_PATH).'forum/viewforum.php?'.api_get_cidreq().'&forum='.intval(
+                    $_GET['forum']
+                )."&search=".Security::remove_XSS(urlencode($my_search)),
             'name' => Security::remove_XSS($current_forum['forum_title']),
         ];
         $interbreadcrumb[] = [
-            'url' => '#', 'name' => Security::remove_XSS($current_thread['thread_title']),
+            'url' => '#',
+            'name' => Security::remove_XSS($current_thread['thread_title']),
         ];
-
-        // the last element of the breadcrumb navigation is already set in interbreadcrumb, so give empty string
-        Display::display_header('');
     }
 }
 
-/* Is the user allowed here? */
-
 // If the user is not a course administrator and the forum is hidden
 // then the user is not allowed here.
 if (!api_is_allowed_to_edit(false, true) &&
@@ -184,17 +194,19 @@ if (!api_is_allowed_to_edit(false, true) &&
 
 increase_thread_view($_GET['thread']);
 
-/* Action Links */
 if ($origin == 'learnpath') {
-    echo '<div style="height:15px">&nbsp;</div>';
+    $template = new Template('', false, false, true, true, false);
+} else {
+    $template = new Template();
 }
-echo '<div class="actions">';
-echo '<span style="float:right;">'.search_link().'</span>';
+
+$actions = '<span style="float:right;">'.search_link().'</span>';
 if ($origin != 'learnpath') {
-    echo '<a href="'.$forumUrl.'viewforum.php?forum='
+    $actions .= '<a href="'.$forumUrl.'viewforum.php?forum='
         .intval($_GET['forum']).'&'.api_get_cidreq().'">'
         .Display::return_icon('back.png', get_lang('BackToForum'), '', ICON_SIZE_MEDIUM).'</a>';
 }
+
 // The reply to thread link should only appear when the forum_category is
 // not locked AND the forum is not locked AND the thread is not locked.
 // If one of the three levels is locked then the link should not be displayed.
@@ -208,7 +220,7 @@ if (($current_forum_category &&
     if ($_user['user_id'] || ($current_forum['allow_anonymous'] == 1 && !$_user['user_id'])) {
         // reply link
         if (!api_is_anonymous() && api_is_allowed_to_session_edit(false, true)) {
-            echo '<a href="'.$forumUrl.'reply.php?'.api_get_cidreq().'&forum='
+            $actions .= '<a href="'.$forumUrl.'reply.php?'.api_get_cidreq().'&forum='
                 .intval($_GET['forum']).'&thread='
                 .intval($_GET['thread']).'&action=replythread">'
                 .Display::return_icon('reply_thread.png', get_lang('ReplyToThread'), '', ICON_SIZE_MEDIUM)
@@ -223,9 +235,9 @@ if (($current_forum_category &&
             ($current_forum['allow_new_threads'] == 1 && !isset($_user['user_id']) && $current_forum['allow_anonymous'] == 1)
         ) {
             if ($current_forum['locked'] != 1 && $current_forum['locked'] != 1) {
-                echo '&nbsp;&nbsp;';
+                $actions .= '&nbsp;&nbsp;';
             } else {
-                echo get_lang('ForumLocked');
+                $actions .= get_lang('ForumLocked');
             }
         }
     }
@@ -233,19 +245,20 @@ if (($current_forum_category &&
 
 // The different views of the thread.
 if ($origin != 'learnpath') {
-    $my_url = '<a href="'.$forumUrl.'viewthread.php?'.api_get_cidreq().'&'.api_get_cidreq()
+    /*$actions .= '<a href="'.$forumUrl.'viewthread.php?'.api_get_cidreq().'&'.api_get_cidreq()
         .'&forum='.intval($_GET['forum']).'&thread='.intval($_GET['thread'])
         .'&search='.Security::remove_XSS(urlencode($my_search));
     echo $my_url.'&view=flat">'
         .Display::return_icon('forum_listview.png', get_lang('FlatView'), null, ICON_SIZE_MEDIUM)
         .'</a>';
+    /*
     echo $my_url.'&view=nested">'
         .Display::return_icon('forum_nestedview.png', get_lang('NestedView'), null, ICON_SIZE_MEDIUM)
-        .'</a>';
+        .'</a>';*/
 }
-$my_url = null;
 
-echo '</div>&nbsp;';
+$template->assign('forum_actions', $actions);
+$template->assign('origin', api_get_origin());
 
 /* Display Forum Category and the Forum information */
 if (!isset($_SESSION['view'])) {
@@ -259,27 +272,399 @@ if (isset($_GET['view']) && in_array($_GET['view'], $whiteList)) {
     $viewMode = $_GET['view'];
     $_SESSION['view'] = $viewMode;
 }
+
 if (empty($viewMode)) {
     $viewMode = 'flat';
 }
 
 if ($current_thread['thread_peer_qualify'] == 1) {
-    echo Display::return_message(get_lang('ForumThreadPeerScoringStudentComment'), 'info');
+    Display::addFlash(Display::return_message(get_lang('ForumThreadPeerScoringStudentComment'), 'info'));
 }
 
 $allowReport = reportAvailable();
 
-switch ($viewMode) {
-    case 'threaded':
-    case 'nested':
-        include_once 'viewthread_nested.inc.php';
-        break;
-    case 'flat':
-    default:
-        include_once 'viewthread_flat.inc.php';
-        break;
+// Are we in a lp ?
+$origin = api_get_origin();
+//delete attachment file
+if (isset($_GET['action']) &&
+    $_GET['action'] == 'delete_attach' &&
+    isset($_GET['id_attach'])
+) {
+    delete_attachment(0, $_GET['id_attach']);
 }
 
-if ($origin != 'learnpath') {
-    Display::display_footer();
+$origin = api_get_origin();
+$sessionId = api_get_session_id();
+$_user = api_get_user_info();
+$userId = api_get_user_id();
+$groupId = api_get_group_id();
+
+// Decide whether we show the latest post first
+$sortDirection = isset($_GET['posts_order']) && $_GET['posts_order'] === 'desc' ? 'DESC' : ($origin != 'learnpath' ? 'ASC' : 'DESC');
+$posts = getPosts($current_forum, $_GET['thread'], $sortDirection, true);
+$count = 0;
+$clean_forum_id = intval($_GET['forum']);
+$clean_thread_id = intval($_GET['thread']);
+$group_id = api_get_group_id();
+$locked = api_resource_is_locked_by_gradebook($clean_thread_id, LINK_FORUM_THREAD);
+$sessionId = api_get_session_id();
+$currentThread = get_thread_information($clean_forum_id, $_GET['thread']);
+$userId = api_get_user_id();
+$groupInfo = GroupManager::get_group_properties($group_id);
+$postCount = 1;
+$allowUserImageForum = api_get_course_setting('allow_user_image_forum');
+
+// The user who posted it can edit his thread only if the course admin allowed this in the properties
+// of the forum
+// The course admin him/herself can do this off course always
+$tutorGroup = GroupManager::is_tutor_of_group(api_get_user_id(), $groupInfo);
+
+$postList = [];
+foreach ($posts as $post) {
+    $posterId = isset($post['user_id']) ? $post['user_id'] : 0;
+    $username = '';
+    if (isset($post['username'])) {
+        $username = sprintf(get_lang('LoginX'), $post['username']);
+    }
+
+    $name = $post['complete_name'];
+    if (empty($posterId)) {
+        $name = $post['poster_name'];
+    }
+
+    $post['user_data'] = '';
+    if ($origin != 'learnpath') {
+        if ($allowUserImageForum) {
+            $post['user_data'] = '<div class="thumbnail">'.
+                display_user_image($posterId, $name, $origin).'</div>';
+        }
+
+        $post['user_data'] .= Display::tag(
+            'h4',
+            display_user_link($posterId, $name, $origin, $username),
+            ['class' => 'title-username']
+        );
+
+        $_user = api_get_user_info($posterId);
+        $urlImg = api_get_path(WEB_IMG_PATH);
+        $iconStatus = null;
+        $isAdmin = UserManager::is_admin($posterId);
+
+        if ($_user['status'] == 5) {
+            if ($_user['has_certificates']) {
+                $iconStatus = '<img src="'.$urlImg.'icons/svg/ofaj_graduated.svg" width="22px" height="22px">';
+            } else {
+                $iconStatus = '<img src="'.$urlImg.'icons/svg/ofaj_student.svg" width="22px" height="22px">';
+            }
+        } else {
+            if ($_user['status'] == 1) {
+                if ($isAdmin) {
+                    $iconStatus = '<img src="'.$urlImg.'icons/svg/ofaj_admin.svg" width="22px" height="22px">';
+                } else {
+                    $iconStatus = '<img src="'.$urlImg.'icons/svg/ofaj_teacher.svg" width="22px" height="22px">';
+                }
+            }
+        }
+
+        $post['user_data'] .= '<div class="text-center">'.$iconStatus.'</div>';
+    } else {
+        if ($allowUserImageForum) {
+            $post['user_data'] .= '<div class="thumbnail">'.
+                display_user_image($posterId, $name, $origin).'</div>';
+        }
+
+        $post['user_data'] .= Display::tag(
+            'p',
+            $name,
+            [
+                'title' => api_htmlentities($username, ENT_QUOTES),
+                'class' => 'lead',
+            ]
+        );
+    }
+
+    if ($origin != 'learnpath') {
+        $post['user_data'] .= Display::tag(
+            'p',
+            Display::dateToStringAgoAndLongDate($post['post_date']),
+            ['class' => 'post-date']
+        );
+    } else {
+        $post['user_data'] .= Display::tag(
+            'p',
+            Display::dateToStringAgoAndLongDate($post['post_date']),
+            ['class' => 'text-muted']
+        );
+    }
+
+    // get attach id
+    $attachment_list = get_attachment($post['post_id']);
+    $id_attach = !empty($attachment_list) ? $attachment_list['iid'] : '';
+
+    $iconEdit = '';
+    $editButton = '';
+    $askForRevision = '';
+
+    if ((isset($groupInfo['iid']) && $tutorGroup) ||
+        ($current_forum['allow_edit'] == 1 && $posterId == $userId) ||
+        (api_is_allowed_to_edit(false, true) &&
+        !(api_is_session_general_coach() && $current_forum['session_id'] != $sessionId))
+    ) {
+        if ($locked == false && postIsEditableByStudent($current_forum, $post)) {
+            $editUrl = api_get_path(WEB_CODE_PATH).'forum/editpost.php?'.api_get_cidreq();
+            $editUrl .= "&forum=$clean_forum_id&thread=$clean_thread_id&post={$post['post_id']}&id_attach=$id_attach";
+            $iconEdit .= "<a href='".$editUrl."'>"
+                .Display::return_icon('edit.png', get_lang('Edit'), [], ICON_SIZE_SMALL)
+                ."</a>";
+
+            $editButton = Display::toolbarButton(
+                get_lang('Edit'),
+                $editUrl,
+                'pencil',
+                'default'
+            );
+        }
+    }
+
+    if ((isset($groupInfo['iid']) && $tutorGroup) ||
+        api_is_allowed_to_edit(false, true) &&
+        !(api_is_session_general_coach() && $current_forum['session_id'] != $sessionId)
+    ) {
+        if ($locked == false) {
+            $deleteUrl = api_get_self().'?'.api_get_cidreq().'&'.http_build_query([
+                    'forum' => $clean_forum_id,
+                    'thread' => $clean_thread_id,
+                    'action' => 'delete',
+                    'content' => 'post',
+                    'id' => $post['post_id'],
+                ]);
+            $iconEdit .= Display::url(
+                Display::return_icon('delete.png', get_lang('Delete'), [], ICON_SIZE_SMALL),
+                $deleteUrl,
+                [
+                    'onclick' => "javascript:if(!confirm('"
+                        .addslashes(api_htmlentities(get_lang('DeletePost'), ENT_QUOTES))
+                        ."')) return false;",
+                    'id' => "delete-post-{$post['post_id']}",
+                ]
+            );
+        }
+    }
+
+    if (api_is_allowed_to_edit(false, true) &&
+        !(
+            api_is_session_general_coach() &&
+            $current_forum['session_id'] != $sessionId
+        )
+    ) {
+        $iconEdit .= return_visible_invisible_icon(
+            'post',
+            $post['post_id'],
+            $post['visible'],
+            [
+                'forum' => $clean_forum_id,
+                'thread' => $clean_thread_id,
+            ]
+        );
+
+        if ($count > 0) {
+            $iconEdit .= "<a href=\"viewthread.php?".api_get_cidreq()
+                ."&forum=$clean_forum_id&thread=$clean_thread_id&action=move&post={$post['post_id']}"
+                ."\">".Display::return_icon('move.png', get_lang('MovePost'), [], ICON_SIZE_SMALL)."</a>";
+        }
+    }
+
+    $userCanQualify = $currentThread['thread_peer_qualify'] == 1 && $post['poster_id'] != $userId;
+    if (api_is_allowed_to_edit(null, true)) {
+        $userCanQualify = true;
+    }
+
+    if ($post['poster_id'] == $userId) {
+        $revision = getPostRevision($post['post_id']);
+        if (empty($revision)) {
+            $askForRevision = getAskRevisionButton($post['post_id'], $current_thread);
+        } else {
+            $languageId = api_get_language_id(strtolower($revision));
+            $languageInfo = api_get_language_info($languageId);
+            if ($languageInfo) {
+                $askForRevision = '<span class="flag-icon flag-icon-'.$languageInfo['isocode'].'"></span> ';
+            }
+        }
+    } else {
+        if (postNeedsRevision($post['post_id'])) {
+            $askForRevision = giveRevisionButton($post['post_id'], $current_thread);
+        }
+    }
+
+    if (empty($currentThread['thread_qualify_max'])) {
+        $userCanQualify = false;
+    }
+
+    if ($userCanQualify) {
+        if ($count > 0) {
+            $current_qualify_thread = showQualify(
+                '1',
+                $posterId,
+                $_GET['thread']
+            );
+            if ($locked == false) {
+                $iconEdit .= "<a href=\"forumqualify.php?".api_get_cidreq()
+                    ."&forum=$clean_forum_id&thread=$clean_thread_id&action=list&post={$post['post_id']}"
+                    ."&user={$post['user_id']}&user_id={$post['user_id']}"
+                    ."&idtextqualify=$current_qualify_thread"
+                    ."\" >".Display::return_icon('quiz.png', get_lang('Qualify'))."</a>";
+            }
+        }
+    }
+
+    $reportButton = '';
+    if ($allowReport) {
+        $reportButton = getReportButton($post['post_id'], $current_thread);
+    }
+
+    $statusIcon = getPostStatus($current_forum, $post);
+    if (!empty($iconEdit)) {
+        $post['user_data'] .= "<div class='tools-icons'> $iconEdit $statusIcon </div>";
+    } else {
+        if (!empty(strip_tags($statusIcon))) {
+            $post['user_data'] .= "<div class='tools-icons'> $statusIcon </div>";
+        }
+    }
+
+    $buttonReply = '';
+    $buttonQuote = '';
+    $waitingValidation = '';
+
+    if (($current_forum_category && $current_forum_category['locked'] == 0) &&
+        $current_forum['locked'] == 0 && $current_thread['locked'] == 0 || api_is_allowed_to_edit(false, true)
+    ) {
+        if ($userId || ($current_forum['allow_anonymous'] == 1 && !$userId)) {
+            if (!api_is_anonymous() && api_is_allowed_to_session_edit(false, true)) {
+                $buttonReply = Display::toolbarButton(
+                    get_lang('ReplyToMessage'),
+                    'reply.php?'.api_get_cidreq().'&'.http_build_query([
+                        'forum' => $clean_forum_id,
+                        'thread' => $clean_thread_id,
+                        'post' => $post['post_id'],
+                        'action' => 'replymessage',
+                    ]),
+                    'reply',
+                    'primary',
+                    ['id' => "reply-to-post-{$post['post_id']}"]
+                );
+
+                $buttonQuote = Display::toolbarButton(
+                    get_lang('QuoteMessage'),
+                    'reply.php?'.api_get_cidreq().'&'.http_build_query([
+                        'forum' => $clean_forum_id,
+                        'thread' => $clean_thread_id,
+                        'post' => $post['post_id'],
+                        'action' => 'quote',
+                    ]),
+                    'quote-left',
+                    'success',
+                    ['id' => "quote-post-{$post['post_id']}"]
+                );
+
+                if ($current_forum['moderated'] && !api_is_allowed_to_edit(false, true)) {
+                    if (empty($post['status']) || $post['status'] == CForumPost::STATUS_WAITING_MODERATION) {
+                        $buttonReply = '';
+                        $buttonQuote = '';
+                    }
+                }
+            }
+        }
+    } else {
+        $closedPost = '';
+        if ($current_forum_category && $current_forum_category['locked'] == 1) {
+            $closedPost = Display::tag(
+                'div',
+                '<em class="fa fa-exclamation-triangle"></em> '.get_lang('ForumcategoryLocked'),
+                ['class' => 'alert alert-warning post-closed']
+            );
+        }
+        if ($current_forum['locked'] == 1) {
+            $closedPost = Display::tag(
+                'div',
+                '<em class="fa fa-exclamation-triangle"></em> '.get_lang('ForumLocked'),
+                ['class' => 'alert alert-warning post-closed']
+            );
+        }
+        if ($current_thread['locked'] == 1) {
+            $closedPost = Display::tag(
+                'div',
+                '<em class="fa fa-exclamation-triangle"></em> '.get_lang('ThreadLocked'),
+                ['class' => 'alert alert-warning post-closed']
+            );
+        }
+
+        $post['user_data'] .= $closedPost;
+    }
+
+    // note: this can be removed here because it will be displayed in the tree
+    if (isset($whatsnew_post_info[$current_forum['forum_id']][$current_thread['thread_id']][$post['post_id']]) &&
+        !empty($whatsnew_post_info[$current_forum['forum_id']][$current_thread['thread_id']][$post['post_id']]) &&
+        !empty($whatsnew_post_info[$_GET['forum']][$post['thread_id']])
+    ) {
+        $post_image = Display::return_icon('forumpostnew.gif');
+    } else {
+        $post_image = Display::return_icon('forumpost.gif');
+    }
+
+    if ($post['post_notification'] == '1' && $post['poster_id'] == $userId) {
+        $post_image .= Display::return_icon(
+            'forumnotification.gif',
+            get_lang('YouWillBeNotified')
+        );
+    }
+
+    $post['current'] = false;
+    if (isset($_GET['post_id']) && $_GET['post_id'] == $post['post_id']) {
+        $post['current'] = true;
+    }
+
+    // The post title
+    $titlePost = Display::tag('h3', $post['post_title'], ['class' => 'forum_post_title']);
+    $post['post_data'] = Display::tag('div', $titlePost, ['class' => 'post-header']);
+    $post['post_data'] .= '<a name="post_id_'.$post['post_id'].'"></a>';
+
+    // the post body
+    $post['post_data'] .= Display::tag('div', $post['post_text'], ['class' => 'post-body']);
+
+    // The check if there is an attachment
+    $post['post_attachments'] = '';
+    $attachment_list = getAllAttachment($post['post_id']);
+    if (!empty($attachment_list) && is_array($attachment_list)) {
+        foreach ($attachment_list as $attachment) {
+            $user_filename = $attachment['filename'];
+            $post['post_attachments'] .= Display::return_icon('attachment.gif', get_lang('Attachment'));
+            $post['post_attachments'] .= '<a href="download.php?file=';
+            $post['post_attachments'] .= $attachment['path'];
+            $post['post_attachments'] .= ' "> '.$user_filename.' </a>';
+            $post['post_attachments'] .= '<span class="forum_attach_comment" >'.$attachment['comment'].'</span>';
+            if (($current_forum['allow_edit'] == 1 && $post['user_id'] == $userId) ||
+                (api_is_allowed_to_edit(false, true) && !(api_is_session_general_coach() && $current_forum['session_id'] != $sessionId))
+            ) {
+                $post['post_attachments'] .= '&nbsp;&nbsp;<a href="'.api_get_self().'?'.api_get_cidreq().'&action=delete_attach&id_attach='
+                    .$attachment['iid'].'&forum='.$clean_forum_id.'&thread='.$clean_thread_id
+                    .'" onclick="javascript:if(!confirm(\''
+                    .addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES)).'\')) return false;">'
+                    .Display::return_icon('delete.png', get_lang('Delete')).'</a><br />';
+            }
+        }
+    }
+
+    $post['post_buttons'] = "$askForRevision $editButton $reportButton $buttonReply $buttonQuote $waitingValidation";
+    $postList[] = $post;
+
+    // The post has been displayed => it can be removed from the what's new array
+    unset($whatsnew_post_info[$current_forum['forum_id']][$current_thread['thread_id']][$post['post_id']]);
+    unset($_SESSION['whatsnew_post_info'][$current_forum['forum_id']][$current_thread['thread_id']][$post['post_id']]);
+
+    $count++;
 }
+$template->assign('posts', $postList);
+
+$layout = $template->get_template('forum/posts.tpl');
+
+$template->display($layout);

+ 0 - 395
main/forum/viewthread_flat.inc.php

@@ -1,395 +0,0 @@
-<?php
-/* For licensing terms, see /license.txt */
-
-/**
- * This script manages the display of forum threads in flat view.
- *
- * @copyright Julio Montoya <gugli100@gmail.com> UI Improvements + lots of bugfixes
- *
- * @package chamilo.forum
- */
-
-// Delete attachment file
-if ((isset($_GET['action']) &&
-    $_GET['action'] == 'delete_attach') &&
-    isset($_GET['id_attach'])
-) {
-    delete_attachment(0, $_GET['id_attach']);
-}
-
-// Are we in a lp ?
-$origin = api_get_origin();
-$sessionId = api_get_session_id();
-$_user = api_get_user_info();
-$userId = api_get_user_id();
-$groupId = api_get_group_id();
-
-// Decide whether we show the latest post first
-$sortDirection = isset($_GET['posts_order']) && $_GET['posts_order'] === 'desc' ? 'DESC' : ($origin != 'learnpath' ? 'ASC' : 'DESC');
-
-if (isset($current_thread['thread_id'])) {
-    $rows = getPosts($current_forum, $current_thread['thread_id'], $sortDirection);
-    $increment = 0;
-    $clean_forum_id = intval($_GET['forum']);
-    $clean_thread_id = intval($_GET['thread']);
-    $locked = api_resource_is_locked_by_gradebook(
-        $clean_thread_id,
-        LINK_FORUM_THREAD
-    );
-
-    $buttonReply = '';
-    $buttonQuote = '';
-    $closedPost = '';
-
-    if (!empty($rows)) {
-        $postCount = count($rows);
-        foreach ($rows as $row) {
-            $posterId = isset($row['user_id']) ? $row['user_id'] : 0;
-            $name = '';
-            if (empty($posterId)) {
-                $name = prepare4display($row['poster_name']);
-            } else {
-                if (isset($row['complete_name'])) {
-                    $name = $row['complete_name'];
-                }
-            }
-
-            $username = '';
-            if (isset($row['username'])) {
-                $username = sprintf(get_lang('LoginX'), $row['username']);
-            }
-
-            if (($current_forum_category && $current_forum_category['locked'] == 0) &&
-                $current_forum['locked'] == 0 &&
-                $current_thread['locked'] == 0 ||
-                api_is_allowed_to_edit(false, true)
-            ) {
-                if ($userId || ($current_forum['allow_anonymous'] == 1 && !$userId)) {
-                    if ((api_is_anonymous() && $current_forum['allow_anonymous'] == 1) ||
-                        (!api_is_anonymous() && api_is_allowed_to_session_edit(false, true))
-                    ) {
-                        $buttonReply = Display::toolbarButton(
-                            get_lang('ReplyToMessage'),
-                            'reply.php?'.api_get_cidreq().'&'.http_build_query([
-                                'forum' => $clean_forum_id,
-                                'thread' => $clean_thread_id,
-                                'post' => $row['post_id'],
-                                'action' => 'replymessage',
-                            ]),
-                            'reply',
-                            'primary',
-                            ['id' => "reply-to-post-{$row['post_id']}"]
-                        );
-
-                        $buttonQuote = Display::toolbarButton(
-                            get_lang('QuoteMessage'),
-                            'reply.php?'.api_get_cidreq().'&'.http_build_query([
-                                'forum' => $clean_forum_id,
-                                'thread' => $clean_thread_id,
-                                'post' => $row['post_id'],
-                                'action' => 'quote',
-                            ]),
-                            'quote-left',
-                            'success',
-                            ['id' => "quote-post-{$row['post_id']}"]
-                        );
-                    }
-                }
-            } else {
-                if (($current_forum_category && $current_forum_category['locked'] == 1)) {
-                    $closedPost = Display::tag(
-                        'div',
-                        '<em class="fa fa-exclamation-triangle"></em> '.get_lang('ForumcategoryLocked'),
-                        ['class' => 'alert alert-warning post-closed']
-                    );
-                }
-                if ($current_forum['locked'] == 1) {
-                    $closedPost = Display::tag(
-                        'div',
-                        '<em class="fa fa-exclamation-triangle"></em> '.get_lang('ForumLocked'),
-                        ['class' => 'alert alert-warning post-closed']
-                    );
-                }
-                if ($current_thread['locked'] == 1) {
-                    $closedPost = Display::tag(
-                        'div',
-                        '<em class="fa fa-exclamation-triangle"></em> '.get_lang('ThreadLocked'),
-                        ['class' => 'alert alert-warning post-closed']
-                    );
-                }
-            }
-
-            $html = '';
-            $html .= '<div class="panel panel-default forum-post">';
-            $html .= '<div class="panel-body">';
-            $html .= '<div class="row">';
-            $html .= '<div class="col-md-2">';
-
-            if ($origin != 'learnpath') {
-                if (api_get_course_setting('allow_user_image_forum')) {
-                    $html .= '<div class="thumbnail">'.display_user_image($posterId, $name, $origin).'</div>';
-                }
-                $html .= Display::tag(
-                    'h4',
-                    display_user_link($posterId, $name),
-                    ['class' => 'title-username']
-                );
-                $_user = api_get_user_info($posterId);
-                $urlImg = api_get_path(WEB_IMG_PATH);
-                $iconStatus = null;
-                $isAdmin = UserManager::is_admin($posterId);
-
-                if($_user['status']==5) {
-                    if($_user['has_certificates']){
-                        $iconStatus = '<img src="'.$urlImg.'icons/svg/ofaj_graduated.svg" width="22px" height="22px">';
-                    }else{
-                        $iconStatus = '<img src="'.$urlImg.'icons/svg/ofaj_student.svg" width="22px" height="22px">';
-                    }
-                }else if($_user['status'] == 1){
-                    if($isAdmin){
-                        $iconStatus = '<img src="'.$urlImg.'icons/svg/ofaj_admin.svg" width="22px" height="22px">';
-                    }else{
-                        $iconStatus = '<img src="'.$urlImg.'icons/svg/ofaj_teacher.svg" width="22px" height="22px">';
-                    }
-                }
-                $html .= '<div class="text-center">'.$iconStatus.'</div>';
-            } else {
-                if (api_get_course_setting('allow_user_image_forum')) {
-                    $html .= '<div class="thumbnail">'.display_user_image($posterId, $name, $origin).'</div>';
-                }
-                $name = Display::tag('strong', "#".$postCount--, ['class' => 'text-info'])." | $name";
-                $html .= Display::tag(
-                    'p',
-                    $name,
-                    [
-                        'title' => api_htmlentities($username, ENT_QUOTES),
-                        'class' => 'lead',
-                    ]
-                );
-            }
-
-            if ($origin != 'learnpath') {
-                $html .= Display::tag(
-                    'p',
-                    Display::dateToStringAgoAndLongDate($row['post_date']),
-                    ['class' => 'post-date']
-                );
-            } else {
-                $html .= Display::tag(
-                    'p',
-                    Display::dateToStringAgoAndLongDate($row['post_date']),
-                    ['class' => 'text-muted']
-                );
-            }
-
-            // get attach id
-            $attachment_list = get_attachment($row['post_id']);
-            $id_attach = !empty($attachment_list) ? $attachment_list['iid'] : '';
-            $iconEdit = '';
-            $statusIcon = '';
-            // The user who posted it can edit his thread only if the course admin allowed
-            // this in the properties of the forum
-            // The course admin him/herself can do this off course always
-            $groupInfo = GroupManager::get_group_properties($groupId);
-            if ((isset($groupInfo['iid']) && GroupManager::is_tutor_of_group($userId, $groupInfo)) ||
-                ($current_forum['allow_edit'] == 1 && $posterId == $userId) ||
-                (
-                api_is_allowed_to_edit(false, true) &&
-                !(api_is_session_general_coach() && $current_forum['session_id'] != $sessionId)
-                )
-            ) {
-                if (api_is_allowed_to_session_edit(false, true)) {
-                    if ($locked == false && postIsEditableByStudent($current_forum, $row)) {
-                        $iconEdit .= "<a href=\"editpost.php?".api_get_cidreq()."&forum=".$clean_forum_id
-                            ."&thread=".$clean_thread_id."&post=".$row['post_id']
-                            ."&edit=edition&id_attach=".$id_attach."\">"
-                            .Display::return_icon('edit.png', get_lang('Edit'), [], ICON_SIZE_SMALL)."</a>";
-                    }
-                }
-            }
-
-            if ($origin != 'learnpath') {
-                if (GroupManager::is_tutor_of_group($userId, $groupInfo) ||
-                    api_is_allowed_to_edit(false, true) &&
-                    !(api_is_session_general_coach() && $current_forum['session_id'] != $sessionId)
-                ) {
-                    if ($locked === false) {
-                        $deleteUrl = api_get_self().'?'.api_get_cidreq().'&'.http_build_query([
-                            'forum' => $clean_forum_id,
-                            'thread' => $clean_thread_id,
-                            'action' => 'delete',
-                            'content' => 'post',
-                            'id' => $row['post_id'],
-                        ]);
-                        $iconEdit .= Display::url(
-                            Display::return_icon('delete.png', get_lang('Delete'), [], ICON_SIZE_SMALL),
-                            $deleteUrl,
-                            [
-                                'onclick' => "javascript:if(!confirm('"
-                                    .addslashes(api_htmlentities(get_lang('DeletePost'), ENT_QUOTES))
-                                    ."')) return false;",
-                                'id' => "delete-post-{$row['post_id']}",
-                            ]
-                        );
-                    }
-                }
-
-                $statusIcon = getPostStatus($current_forum, $row);
-
-                if (GroupManager::is_tutor_of_group($userId, $groupInfo) ||
-                    (
-                        api_is_allowed_to_edit(false, true) &&
-                    !(api_is_session_general_coach() && $current_forum['session_id'] != $sessionId)
-                    )
-                ) {
-                    $iconEdit .= return_visible_invisible_icon(
-                        'post',
-                        $row['post_id'],
-                        $row['visible'],
-                        [
-                            'forum' => $clean_forum_id,
-                            'thread' => $clean_thread_id,
-                            'origin' => $origin,
-                        ]
-                    );
-
-                    if ($increment > 0) {
-                        $iconEdit .= "<a href=\"viewthread.php?".api_get_cidreq()."&forum=".$clean_forum_id
-                            ."&thread=".$clean_thread_id."&action=move&post=".$row['post_id']."\">"
-                            .Display::return_icon('move.png', get_lang('MovePost'), [], ICON_SIZE_SMALL)
-                            ."</a>";
-                    }
-                }
-            }
-
-            $user_status = api_get_status_of_user_in_course($posterId, api_get_course_int_id());
-            $current_qualify_thread = showQualify('1', $row['poster_id'], $_GET['thread']);
-            if (($current_thread['thread_peer_qualify'] == 1 || api_is_allowed_to_edit(null, true)) &&
-                $current_thread['thread_qualify_max'] > 0 && $origin != 'learnpath'
-            ) {
-                $my_forum_id = $clean_forum_id;
-                $info_thread = get_thread_information($clean_forum_id, $clean_thread_id);
-                $my_forum_id = $info_thread['forum_id'];
-                $userCanEdit = $current_thread['thread_peer_qualify'] == 1 && $row['poster_id'] != $userId;
-                /*if ($row['poster_id'] != $userId && $current_forum['moderated'] == 1 && $row['status']) {
-                }*/
-                if (api_is_allowed_to_edit(null, true)) {
-                    $userCanEdit = true;
-                }
-
-                if ($increment > 0 && $locked == false && $userCanEdit) {
-                    $iconEdit .= "<a href=\"forumqualify.php?".api_get_cidreq()."&forum=".$my_forum_id
-                        ."&thread=".$clean_thread_id."&action=list&post=".$row['post_id']
-                        ."&user=".$row['poster_id']."&user_id=".$row['poster_id']
-                        ."&idtextqualify=".$current_qualify_thread."\" >"
-                        .Display::return_icon('quiz.png', get_lang('Qualify'))
-                        ."</a> ";
-                }
-            }
-
-            $reportButton = '';
-            if ($allowReport) {
-                $reportButton = getReportButton($row['post_id'], $current_thread);
-            }
-
-            if (!empty($iconEdit)) {
-                $html .= "<div class='tools-icons'> $iconEdit $statusIcon </div>";
-            } else {
-                if (!empty(strip_tags($statusIcon))) {
-                    $html .= "<div class='tools-icons'> $statusIcon </div>";
-                }
-            }
-
-            $html .= $closedPost;
-            $html .= '</div>';
-
-            $highLightClass = '';
-            if (isset($_GET['post_id']) && $_GET['post_id'] == $row['post_id']) {
-                $highLightClass = 'alert alert-danger';
-            }
-
-            $html .= '<div class="col-md-10 '.$highLightClass.'">';
-
-            $titlePost = Display::tag(
-                'h3',
-                $row['post_title'],
-                ['class' => 'forum_post_title']
-            );
-
-            $html .= Display::tag(
-                'div',
-                $titlePost,
-                ['class' => 'post-header']
-            );
-
-            // see comments inside forumfunction.inc.php to lower filtering and allow more visual changes
-            $html .= Display::tag(
-                'div',
-                $row['post_text'],
-                ['class' => 'post-body']
-            );
-            $html .= '</div>';
-            $html .= '</div>';
-
-            $html .= '<div class="row">';
-            $html .= '<div class="col-md-7">';
-
-            // prepare the notification icon
-            if (isset($whatsnew_post_info[$current_forum['forum_id']][$current_thread['thread_id']][$row['post_id']]) &&
-                !empty(
-                    $whatsnew_post_info[$current_forum['forum_id']][$current_thread['thread_id']][$row['post_id']]
-                ) &&
-                !empty($whatsnew_post_info[$_GET['forum']][$row['thread_id']])
-            ) {
-                $post_image = Display::return_icon('forumpostnew.gif');
-            } else {
-                $post_image = Display::return_icon('forumpost.gif');
-            }
-
-            if ($row['post_notification'] == '1' && $row['poster_id'] == $userId) {
-                $post_image .= Display::return_icon('forumnotification.gif', get_lang('YouWillBeNotified'));
-            }
-            // The post title
-            // The check if there is an attachment
-            $attachment_list = getAllAttachment($row['post_id']);
-            if (!empty($attachment_list) && is_array($attachment_list)) {
-                foreach ($attachment_list as $attachment) {
-                    $realname = $attachment['path'];
-                    $user_filename = $attachment['filename'];
-                    $html .= Display::return_icon('attachment.gif', get_lang('Attachment'));
-                    $html .= '<a href="download.php?file='.$realname.'"> '.$user_filename.' </a>';
-
-                    if (($current_forum['allow_edit'] == 1 && $posterId == $userId) ||
-                        (api_is_allowed_to_edit(false, true) &&
-                        !(api_is_session_general_coach() && $current_forum['session_id'] != $sessionId))
-                    ) {
-                        $html .= '&nbsp;&nbsp;<a href="'.api_get_self().'?'.api_get_cidreq().'&action=delete_attach&id_attach='
-                            .$attachment['iid'].'&forum='.$clean_forum_id.'&thread='.$clean_thread_id
-                            .'" onclick="javascript:if(!confirm(\''
-                            .addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES))
-                            .'\')) return false;">'
-                            .Display::return_icon('delete.png', get_lang('Delete'), [], ICON_SIZE_SMALL)
-                            .'</a><br />';
-                    }
-                    $html .= '<span class="forum_attach_comment" >'.$attachment['comment'].'</span>';
-                }
-            }
-
-            $html .= '</div>';
-            $html .= '<div class="col-md-5 text-right">';
-            $html .= "$reportButton $buttonReply $buttonQuote";
-            $html .= '</div>';
-            $html .= '</div>';
-
-            // The post has been displayed => it can be removed from the what's new array
-            unset($whatsnew_post_info[$current_forum['forum_id']][$current_thread['thread_id']][$row['post_id']]);
-            unset($whatsnew_post_info[$current_forum['forum_id']][$current_thread['thread_id']]);
-            unset($_SESSION['whatsnew_post_info'][$current_forum['forum_id']][$current_thread['thread_id']][$row['post_id']]);
-            unset($_SESSION['whatsnew_post_info'][$current_forum['forum_id']][$current_thread['thread_id']]);
-            $increment++;
-            $html .= '</div>';
-            $html .= '</div>';
-            echo $html;
-        }
-    }
-}

+ 0 - 398
main/forum/viewthread_nested.inc.php

@@ -1,398 +0,0 @@
-<?php
-/* For licensing terms, see /license.txt */
-
-use Chamilo\CourseBundle\Entity\CForumPost;
-
-/**
- * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
- * @author Julio Montoya <gugli100@gmail.com> UI Improvements + lots of bugfixes
- * @copyright Ghent University
- *
- * @package chamilo.forum
- */
-
-// Are we in a lp ?
-$origin = api_get_origin();
-//delete attachment file
-if (isset($_GET['action']) &&
-    $_GET['action'] == 'delete_attach' &&
-    isset($_GET['id_attach'])
-) {
-    delete_attachment(0, $_GET['id_attach']);
-}
-
-// Decide whether we show the latest post first
-$sortDirection = isset($_GET['posts_order']) && $_GET['posts_order'] === 'desc' ? 'DESC' : ($origin != 'learnpath' ? 'ASC' : 'DESC');
-$posts = getPosts($current_forum, $_GET['thread'], $sortDirection, true);
-$count = 0;
-$clean_forum_id = intval($_GET['forum']);
-$clean_thread_id = intval($_GET['thread']);
-$group_id = api_get_group_id();
-$locked = api_resource_is_locked_by_gradebook($clean_thread_id, LINK_FORUM_THREAD);
-$sessionId = api_get_session_id();
-$currentThread = get_thread_information($clean_forum_id, $_GET['thread']);
-$userId = api_get_user_id();
-$groupInfo = GroupManager::get_group_properties($group_id);
-$postCount = 1;
-
-$allowUserImageForum = api_get_course_setting('allow_user_image_forum');
-
-foreach ($posts as $post) {
-
-    $posterId = isset($post['user_id']) ? $post['user_id'] : 0;
-
-    // The style depends on the status of the message: approved or not.
-    if ($post['visible'] == '0') {
-        $titleclass = 'forum_message_post_title_2_be_approved';
-        $messageclass = 'forum_message_post_text_2_be_approved';
-        $leftclass = 'forum_message_left_2_be_approved';
-    } else {
-        $titleclass = 'forum_message_post_title';
-        $messageclass = 'forum_message_post_text';
-        $leftclass = 'forum_message_left';
-    }
-
-    $indent = $post['indent_cnt'];
-
-    $html = '';
-    $html .= '<div class="col-md-offset-'.$indent.'" >';
-    $html .= '<div class="panel panel-default forum-post">';
-    $html .= '<div class="panel-body">';
-    $html .= '<div class="row">';
-    $html .= '<div class="col-md-2">';
-    $username = '';
-    if (isset($post['username'])) {
-        $username = sprintf(get_lang('LoginX'), $post['username']);
-    }
-    if (empty($posterId)) {
-        $name = $post['poster_name'];
-    } else {
-        $name = $post['complete_name'];
-    }
-
-    if ($origin != 'learnpath') {
-        if ($allowUserImageForum) {
-            $html .= '<div class="thumbnail">'.display_user_image($posterId, $name, $origin).'</div>';
-        }
-
-        $html .= Display::tag(
-            'h4',
-            display_user_link($posterId, $name, $origin, $username),
-            ['class' => 'title-username']
-        );
-
-        $_user = api_get_user_info($posterId);
-        $urlImg = api_get_path(WEB_IMG_PATH);
-        $iconStatus = null;
-        $isAdmin = UserManager::is_admin($posterId);
-
-        if($_user['status']==5) {
-            if($_user['has_certificates']){
-                $iconStatus = '<img src="'.$urlImg.'icons/svg/ofaj_graduated.svg" width="22px" height="22px">';
-            }else{
-                $iconStatus = '<img src="'.$urlImg.'icons/svg/ofaj_student.svg" width="22px" height="22px">';
-            }
-        }else if($_user['status'] == 1){
-            if($isAdmin){
-                $iconStatus = '<img src="'.$urlImg.'icons/svg/ofaj_admin.svg" width="22px" height="22px">';
-            }else{
-                $iconStatus = '<img src="'.$urlImg.'icons/svg/ofaj_teacher.svg" width="22px" height="22px">';
-            }
-        }
-        $html .= '<div class="text-center">'.$iconStatus.'</div>';
-
-    } else {
-        if ($allowUserImageForum) {
-            $html .= '<div class="thumbnail">'.display_user_image($posterId, $name, $origin).'</div>';
-        }
-
-        $html .= Display::tag(
-            'p',
-            $name,
-            [
-                'title' => api_htmlentities($username, ENT_QUOTES),
-                'class' => 'lead',
-            ]
-        );
-    }
-
-    if ($origin != 'learnpath') {
-        $html .= Display::tag(
-            'p',
-            Display::dateToStringAgoAndLongDate($post['post_date']),
-            ['class' => 'post-date']
-        );
-    } else {
-        $html .= Display::tag(
-            'p',
-            Display::dateToStringAgoAndLongDate($post['post_date']),
-            ['class' => 'text-muted']
-        );
-    }
-
-    // get attach id
-    $attachment_list = get_attachment($post['post_id']);
-    $id_attach = !empty($attachment_list) ? $attachment_list['iid'] : '';
-
-    $iconEdit = '';
-    $editButton = '';
-    // The user who posted it can edit his thread only if the course admin allowed this in the properties of the forum
-    // The course admin him/herself can do this off course always
-
-    $tutorGroup = GroupManager::is_tutor_of_group(api_get_user_id(), $groupInfo);
-
-    if ((isset($groupInfo['iid']) && $tutorGroup) ||
-        ($current_forum['allow_edit'] == 1 && $posterId == $userId) ||
-        (api_is_allowed_to_edit(false, true) &&
-        !(api_is_session_general_coach() && $current_forum['session_id'] != $sessionId))
-    ) {
-        if ($locked == false && postIsEditableByStudent($current_forum, $post)) {
-            $editUrl = api_get_path(WEB_CODE_PATH).'forum/editpost.php?'.api_get_cidreq();
-            $editUrl .= "&forum=$clean_forum_id&thread=$clean_thread_id&post={$post['post_id']}&id_attach=$id_attach";
-
-            $iconEdit .= "<a href='".$editUrl."'>"
-                .Display::return_icon('edit.png', get_lang('Edit'), [], ICON_SIZE_SMALL)
-                ."</a>";
-
-            $editButton = Display::toolbarButton(
-                get_lang('Edit'),
-                $editUrl,
-                'pencil',
-                'default'
-            );
-        }
-    }
-
-    if ((isset($groupInfo['iid']) && $tutorGroup) ||
-        api_is_allowed_to_edit(false, true) &&
-        !(api_is_session_general_coach() && $current_forum['session_id'] != $sessionId)
-    ) {
-        if ($locked == false) {
-            $deleteUrl = api_get_self().'?'.api_get_cidreq().'&'.http_build_query([
-                'forum' => $clean_forum_id,
-                'thread' => $clean_thread_id,
-                'action' => 'delete',
-                'content' => 'post',
-                'id' => $post['post_id'],
-            ]);
-            $iconEdit .= Display::url(
-                Display::return_icon('delete.png', get_lang('Delete'), [], ICON_SIZE_SMALL),
-                $deleteUrl,
-                [
-                    'onclick' => "javascript:if(!confirm('"
-                        .addslashes(api_htmlentities(get_lang('DeletePost'), ENT_QUOTES))
-                        ."')) return false;",
-                    'id' => "delete-post-{$post['post_id']}",
-                ]
-            );
-        }
-    }
-
-    if (api_is_allowed_to_edit(false, true) &&
-        !(
-            api_is_session_general_coach() &&
-            $current_forum['session_id'] != $sessionId
-        )
-    ) {
-        $iconEdit .= return_visible_invisible_icon(
-            'post',
-            $post['post_id'],
-            $post['visible'],
-            [
-                'forum' => $clean_forum_id,
-                'thread' => $clean_thread_id,
-            ]
-        );
-
-        if ($count > 0) {
-            $iconEdit .= "<a href=\"viewthread.php?".api_get_cidreq()
-                ."&forum=$clean_forum_id&thread=$clean_thread_id&action=move&post={$post['post_id']}"
-                ."\">".Display::return_icon('move.png', get_lang('MovePost'), [], ICON_SIZE_SMALL)."</a>";
-        }
-    }
-
-    $userCanQualify = $currentThread['thread_peer_qualify'] == 1 && $post['poster_id'] != $userId;
-    if (api_is_allowed_to_edit(null, true)) {
-        $userCanQualify = true;
-    }
-
-    if (empty($currentThread['thread_qualify_max'])) {
-        $userCanQualify = false;
-    }
-
-    if ($userCanQualify) {
-        if ($count > 0) {
-            $current_qualify_thread = showQualify(
-                '1',
-                $posterId,
-                $_GET['thread']
-            );
-            if ($locked == false) {
-                $iconEdit .= "<a href=\"forumqualify.php?".api_get_cidreq()
-                    ."&forum=$clean_forum_id&thread=$clean_thread_id&action=list&post={$post['post_id']}"
-                    ."&user={$post['user_id']}&user_id={$post['user_id']}"
-                    ."&idtextqualify=$current_qualify_thread"
-                    ."\" >".Display::return_icon('quiz.png', get_lang('Qualify'))."</a>";
-            }
-        }
-    }
-
-    $reportButton = '';
-    if ($allowReport) {
-        $reportButton = getReportButton($post['post_id'], $current_thread);
-    }
-
-    $statusIcon = getPostStatus($current_forum, $post);
-    if (!empty($iconEdit)) {
-        $html .= "<div class='tools-icons'> $iconEdit $statusIcon </div>";
-    } else {
-        if (!empty(strip_tags($statusIcon))) {
-            $html .= "<div class='tools-icons'> $statusIcon </div>";
-        }
-    }
-
-    $buttonReply = '';
-    $buttonQuote = '';
-    $waitingValidation = '';
-
-    if (($current_forum_category && $current_forum_category['locked'] == 0) &&
-        $current_forum['locked'] == 0 && $current_thread['locked'] == 0 || api_is_allowed_to_edit(false, true)
-    ) {
-        if ($userId || ($current_forum['allow_anonymous'] == 1 && !$userId)) {
-            if (!api_is_anonymous() && api_is_allowed_to_session_edit(false, true)) {
-                $buttonReply = Display::toolbarButton(
-                    get_lang('ReplyToMessage'),
-                    'reply.php?'.api_get_cidreq().'&'.http_build_query([
-                        'forum' => $clean_forum_id,
-                        'thread' => $clean_thread_id,
-                        'post' => $post['post_id'],
-                        'action' => 'replymessage',
-                    ]),
-                    'reply',
-                    'primary',
-                    ['id' => "reply-to-post-{$post['post_id']}"]
-                );
-
-                $buttonQuote = Display::toolbarButton(
-                    get_lang('QuoteMessage'),
-                    'reply.php?'.api_get_cidreq().'&'.http_build_query([
-                        'forum' => $clean_forum_id,
-                        'thread' => $clean_thread_id,
-                        'post' => $post['post_id'],
-                        'action' => 'quote',
-                    ]),
-                    'quote-left',
-                    'success',
-                    ['id' => "quote-post-{$post['post_id']}"]
-                );
-
-                if ($current_forum['moderated'] && !api_is_allowed_to_edit(false, true)) {
-                    if (empty($post['status']) || $post['status'] == CForumPost::STATUS_WAITING_MODERATION) {
-                        $buttonReply = '';
-                        $buttonQuote = '';
-                    }
-                }
-            }
-        }
-    } else {
-        $closedPost = '';
-        if ($current_forum_category && $current_forum_category['locked'] == 1) {
-            $closedPost = Display::tag(
-                'div',
-                '<em class="fa fa-exclamation-triangle"></em> '.get_lang('ForumcategoryLocked'),
-                ['class' => 'alert alert-warning post-closed']
-            );
-        }
-        if ($current_forum['locked'] == 1) {
-            $closedPost = Display::tag(
-                'div',
-                '<em class="fa fa-exclamation-triangle"></em> '.get_lang('ForumLocked'),
-                ['class' => 'alert alert-warning post-closed']
-            );
-        }
-        if ($current_thread['locked'] == 1) {
-            $closedPost = Display::tag(
-                'div',
-                '<em class="fa fa-exclamation-triangle"></em> '.get_lang('ThreadLocked'),
-                ['class' => 'alert alert-warning post-closed']
-            );
-        }
-
-        $html .= $closedPost;
-    }
-    $html .= '</div>';
-
-    // note: this can be removed here because it will be displayed in the tree
-    if (isset($whatsnew_post_info[$current_forum['forum_id']][$current_thread['thread_id']][$post['post_id']]) &&
-        !empty($whatsnew_post_info[$current_forum['forum_id']][$current_thread['thread_id']][$post['post_id']]) &&
-        !empty($whatsnew_post_info[$_GET['forum']][$post['thread_id']])
-    ) {
-        $post_image = Display::return_icon('forumpostnew.gif');
-    } else {
-        $post_image = Display::return_icon('forumpost.gif');
-    }
-
-    if ($post['post_notification'] == '1' && $post['poster_id'] == $userId) {
-        $post_image .= Display::return_icon(
-            'forumnotification.gif',
-            get_lang('YouWillBeNotified')
-        );
-    }
-
-    $highLightClass = '';
-    if (isset($_GET['post_id']) && $_GET['post_id'] == $post['post_id']) {
-        $highLightClass = 'alert alert-danger';
-    }
-
-    $html .= '<div class="col-md-10 '.$highLightClass.'">';
-    // The post title
-    $titlePost = Display::tag('h3', $post['post_title'], ['class' => 'forum_post_title']);
-    $html .= Display::tag('div', $titlePost, ['class' => 'post-header']);
-    $html .= '<a name="post_id_'.$post['post_id'].'"></a>';
-
-    // the post body
-    $html .= Display::tag('div', $post['post_text'], ['class' => 'post-body']);
-    $html .= '</div>';
-    $html .= '</div>';
-
-    $html .= '<div class="row">';
-    $html .= '<div class="col-md-6">';
-    // The check if there is an attachment
-    $attachment_list = getAllAttachment($post['post_id']);
-    if (!empty($attachment_list) && is_array($attachment_list)) {
-        foreach ($attachment_list as $attachment) {
-            $user_filename = $attachment['filename'];
-            $html .= Display::return_icon('attachment.gif', get_lang('Attachment'));
-            $html .= '<a href="download.php?file=';
-            $html .= $attachment['path'];
-            $html .= ' "> '.$user_filename.' </a>';
-            $html .= '<span class="forum_attach_comment" >'.$attachment['comment'].'</span>';
-            if (($current_forum['allow_edit'] == 1 && $post['user_id'] == $userId) ||
-                (api_is_allowed_to_edit(false, true) && !(api_is_session_general_coach() && $current_forum['session_id'] != $sessionId))
-            ) {
-                $html .= '&nbsp;&nbsp;<a href="'.api_get_self().'?'.api_get_cidreq().'&action=delete_attach&id_attach='
-                    .$attachment['iid'].'&forum='.$clean_forum_id.'&thread='.$clean_thread_id
-                    .'" onclick="javascript:if(!confirm(\''
-                    .addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES)).'\')) return false;">'
-                    .Display::return_icon('delete.gif', get_lang('Delete')).'</a><br />';
-            }
-        }
-    }
-
-    $html .= '</div>';
-    $html .= '<div class="col-md-6 text-right">';
-    $html .= "$editButton $reportButton $buttonReply $buttonQuote $waitingValidation";
-    $html .= '</div>';
-    $html .= '</div>';
-
-    // The post has been displayed => it can be removed from the what's new array
-    unset($whatsnew_post_info[$current_forum['forum_id']][$current_thread['thread_id']][$post['post_id']]);
-    unset($_SESSION['whatsnew_post_info'][$current_forum['forum_id']][$current_thread['thread_id']][$post['post_id']]);
-
-    $html .= '</div>';
-    $html .= '</div>';
-    $html .= '</div>';
-
-    echo $html;
-    $count++;
-}

+ 0 - 450
main/forum/viewthread_threaded.inc.php

@@ -1,450 +0,0 @@
-<?php
-/* For licensing terms, see /license.txt */
-
-/**
- * These files are a complete rework of the forum. The database structure is
- * based on phpBB but all the code is rewritten. A lot of new functionalities
- * are added:
- * - forum categories and forums can be sorted up or down, locked or made invisible
- * - consistent and integrated forum administration
- * - forum options:     are students allowed to edit their post?
- *                      moderation of posts (approval)
- *                      reply only forums (students cannot create new threads)
- *                      multiple forums per group
- * - sticky messages
- * - new view option: nested view
- * - quoting a message.
- *
- * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
- * @author Julio Montoya <gugli100@gmail.com> UI Improvements + lots of bugfixes
- *
- * @package chamilo.forum
- */
-$forumUrl = api_get_path(WEB_CODE_PATH).'forum/';
-$_user = api_get_user_info();
-$sortDirection = isset($_GET['posts_order']) && $_GET['posts_order'] === 'desc' ? 'DESC' : 'ASC';
-$rows = getPosts($current_forum, $_GET['thread'], $sortDirection, true);
-$sessionId = api_get_session_id();
-$currentThread = get_thread_information($current_forum['forum_id'], $_GET['thread']);
-$post_id = isset($_GET['post']) ? (int) $_GET['post'] : 0;
-$userId = api_get_user_id();
-
-if (isset($_GET['post']) && $_GET['post']) {
-    $display_post_id = intval($_GET['post']);
-} else {
-    // We need to display the first post
-    reset($rows);
-    $current = current($rows);
-    $display_post_id = $current['post_id'];
-}
-
-// Are we in a lp ?
-$origin = api_get_origin();
-// Delete attachment file.
-if (isset($_GET['action']) &&
-    $_GET['action'] == 'delete_attach' &&
-    isset($_GET['id_attach'])
-) {
-    delete_attachment(0, $_GET['id_attach']);
-    if (!isset($_GET['thread'])) {
-        exit;
-    }
-}
-
-// Displaying the thread (structure)
-
-$thread_structure = "<div class=\"structure\">".get_lang('Structure')."</div>";
-$counter = 0;
-$count = 0;
-$prev_next_array = [];
-
-$forumId = intval($_GET['forum']);
-$threadId = intval($_GET['thread']);
-$groupId = api_get_group_id();
-
-foreach ($rows as $post) {
-    $counter++;
-    $indent = $post['indent_cnt'] * '20';
-    $thread_structure .= "<div style=\"margin-left: ".$indent."px;\">";
-
-    if (!empty($whatsnew_post_info[$forumId][$post['thread_id']]) &&
-        isset($whatsnew_post_info[$forumId][$threadId][$post['post_id']]) &&
-        !empty($whatsnew_post_info[$forumId][$threadId][$post['post_id']])
-    ) {
-        $post_image = Display::return_icon('forumpostnew.gif');
-    } else {
-        $post_image = Display::return_icon('forumpost.gif');
-    }
-    $thread_structure .= $post_image;
-    if (isset($_GET['post']) && $_GET['post'] == $post['post_id'] ||
-        ($counter == 1 && !isset($_GET['post']))
-    ) {
-        $thread_structure .= '<strong>'.prepare4display($post['post_title']).'</strong>';
-        $prev_next_array[] = $post['post_id'];
-    } else {
-        $count_loop = ($count == 0) ? '&id=1' : '';
-        $thread_structure .= Display::url(
-            prepare4display($post['post_title']),
-            'viewthread.php?'.api_get_cidreq()."$count_loop&".http_build_query([
-                'forum' => $forumId,
-                'thread' => $threadId,
-                'post' => $post['post_id'],
-            ]),
-            ['class' => empty($post['visible']) ? 'text-muted' : null]
-        );
-        $prev_next_array[] = $post['post_id'];
-    }
-    $thread_structure .= '</div>';
-    $count++;
-}
-
-$locked = api_resource_is_locked_by_gradebook($threadId, LINK_FORUM_THREAD);
-
-/* NAVIGATION CONTROLS */
-
-$current_id = array_search($display_post_id, $prev_next_array);
-$max = count($prev_next_array);
-$next_id = $current_id + 1;
-$prev_id = $current_id - 1;
-
-// Text
-$first_message = get_lang('FirstMessage');
-$last_message = get_lang('LastMessage');
-$next_message = get_lang('NextMessage');
-$prev_message = get_lang('PrevMessage');
-
-// Images
-$first_img = Display::return_icon(
-    'action_first.png',
-    get_lang('FirstMessage'),
-    ['style' => 'vertical-align: middle;']
-);
-$last_img = Display::return_icon(
-    'action_last.png',
-    get_lang('LastMessage'),
-    ['style' => 'vertical-align: middle;']
-);
-$prev_img = Display::return_icon(
-    'action_prev.png',
-    get_lang('PrevMessage'),
-    ['style' => 'vertical-align: middle;']
-);
-$next_img = Display::return_icon(
-    'action_next.png',
-    get_lang('NextMessage'),
-    ['style' => 'vertical-align: middle;']
-);
-
-$class_prev = '';
-$class_next = '';
-
-$threadLink = $forumUrl.'viewthread.php?'.api_get_cidreq().'&forum='.$forumId.'&thread='.$threadId;
-// Links
-$first_href = $threadLink.'&id=1&post='.$prev_next_array[0];
-$last_href = $threadLink.'&post='.$prev_next_array[$max - 1];
-$prev_href = $threadLink.'&post='.$prev_next_array[$prev_id];
-$next_href = $threadLink.'&post='.$prev_next_array[$next_id];
-
-echo '<center style="margin-top: 10px; margin-bottom: 10px;">';
-// Go to: first and previous
-if (((int) $current_id) > 0) {
-    echo '<a href="'.$first_href.'" '.$class.' title='.
-        $first_message.'>'.$first_img.' '.$first_message.'</a>';
-    echo '<a href="'.$prev_href.'" '.$class_prev.' title='.
-        $prev_message.'>'.$prev_img.' '.$prev_message.'</a>';
-} else {
-    echo '<strong class="text-muted">'.
-        $first_img.' '.$first_message.'</strong>';
-    echo '<strong class="text-muted">'.
-        $prev_img.' '.$prev_message.'</strong>';
-}
-
-// Current counter
-echo ' [ '.($current_id + 1).' / '.$max.' ] ';
-
-// Go to: next and last
-if (($current_id + 1) < $max) {
-    echo '<a href="'.$next_href.'" '.$class_next.' title='.$next_message.'>'.$next_message.' '.$next_img.'</a>';
-    echo '<a href="'.$last_href.'" '.$class.' title='.$last_message.'>'.$last_message.' '.$last_img.'</a>';
-} else {
-    echo '<strong class="text-muted">'.$next_message.' '.$next_img.'</strong>';
-    echo '<strong class="text-muted">'.$last_message.' '.$last_img.'</strong>';
-}
-echo '</center>';
-
-// The style depends on the status of the message: approved or not
-if ($rows[$display_post_id]['visible'] == '0') {
-    $titleclass = 'forum_message_post_title_2_be_approved';
-    $messageclass = 'forum_message_post_text_2_be_approved';
-    $leftclass = 'forum_message_left_2_be_approved';
-} else {
-    $titleclass = 'forum_message_post_title';
-    $messageclass = 'forum_message_post_text';
-    $leftclass = 'forum_message_left';
-}
-
-// Displaying the message
-
-// We mark the image we are displaying as set
-unset($whatsnew_post_info[$forumId][$threadId][$rows[$display_post_id]['post_id']]);
-
-echo "<table width=\"100%\" class=\"forum_table\" cellspacing=\"5\" border=\"0\">";
-echo "<tr>";
-echo "<td rowspan=\"3\" class=\"$leftclass\">";
-$username = sprintf(get_lang('LoginX'), $rows[$display_post_id]['username']);
-if ($rows[$display_post_id]['user_id'] == '0') {
-    $name = prepare4display($rows[$display_post_id]['poster_name']);
-} else {
-    $name = api_get_person_name(
-        $rows[$display_post_id]['firstname'],
-        $rows[$display_post_id]['lastname']
-    );
-}
-
-if (api_get_course_setting('allow_user_image_forum')) {
-    echo '<br />'.display_user_image($rows[$display_post_id]['user_id'], $name, $origin).'<br />';
-}
-echo display_user_link(
-    $rows[$display_post_id]['user_id'],
-    $name,
-    $origin,
-    $username
-)."<br />";
-
-echo api_convert_and_format_date(
-    $rows[$display_post_id]['post_date']
-).'<br /><br />';
-// Get attach id
-$attachment_list = get_attachment($display_post_id);
-$id_attach = !empty($attachment_list) ? $attachment_list['id'] : '';
-$groupInfo = GroupManager::get_group_properties($groupId);
-
-// The user who posted it can edit his thread only if the course admin allowed this in the properties of the forum
-// The course admin him/herself can do this off course always
-if ((
-    isset($groupInfo['iid']) &&
-        GroupManager::is_tutor_of_group(api_get_user_id(), $groupInfo)
-    ) || (
-        $current_forum['allow_edit'] == 1 &&
-        $row['user_id'] == $_user['user_id']
-    ) || (
-        api_is_allowed_to_edit(false, true) && !(
-            api_is_session_general_coach() &&
-            $current_forum['session_id'] != $sessionId
-        )
-    )
-) {
-    if ($locked == false) {
-        echo "<a href=\"editpost.php?".api_get_cidreq().
-            "&forum=".$forumId."&thread=".$threadId.
-            "&post=".$rows[$display_post_id]['post_id'].
-            "&id_attach=".$id_attach."\">".
-            Display::return_icon(
-                'edit.png',
-                get_lang('Edit'),
-                [],
-                ICON_SIZE_SMALL
-            ).'</a>';
-    }
-}
-
-// Verified the post minor
-$my_post = getPosts($current_forum, $_GET['thread']);
-$id_posts = [];
-
-if (!empty($my_post) && is_array($my_post)) {
-    foreach ($my_post as $post_value) {
-        $id_posts[] = $post_value['post_id'];
-    }
-    sort($id_posts, SORT_NUMERIC);
-    reset($id_posts);
-    // The post minor
-    $post_minor = (int) $id_posts[0];
-}
-
-if ((
-    isset($groupInfo['iid']) &&
-        GroupManager::is_tutor_of_group(api_get_user_id(), $groupInfo)
-    ) ||
-    api_is_allowed_to_edit(false, true) &&
-    !(api_is_session_general_coach() && $current_forum['session_id'] != $sessionId)
-) {
-    if ($locked == false) {
-        echo "<a href=\"".api_get_self()."?".api_get_cidreq().
-            "&forum=".$forumId."&thread=".$threadId.
-            "&action=delete&content=post&id=".
-            $rows[$display_post_id]['post_id'].
-            "\" onclick=\"javascript:if(!confirm('".
-            addslashes(api_htmlentities(get_lang('DeletePost'), ENT_QUOTES)).
-            "')) return false;\">".Display::return_icon(
-                'delete.png',
-                get_lang('Delete'),
-                [],
-                ICON_SIZE_SMALL
-            )."</a>";
-    }
-    echo return_visible_invisible_icon(
-        'post',
-        $rows[$display_post_id]['post_id'],
-        $rows[$display_post_id]['visible'],
-        [
-            'forum' => $forumId,
-            'thread' => $threadId,
-            'post' => Security::remove_XSS($_GET['post']),
-        ]
-    );
-
-    if (!isset($_GET['id']) && $post_id > $post_minor) {
-        echo "<a href=\"viewthread.php?".api_get_cidreq().
-            "&forum=".$forumId."&thread=".$threadId.
-            "&action=move&post=".
-            $rows[$display_post_id]['post_id']."\">".
-            Display::return_icon(
-                'move.png',
-                get_lang('MovePost'),
-                [],
-                ICON_SIZE_SMALL
-            )."</a>";
-    }
-}
-
-$userCanQualify = $currentThread['thread_peer_qualify'] == 1 && $rows[$display_post_id]['poster_id'] != $userId;
-if (api_is_allowed_to_edit(null, true)) {
-    $userCanQualify = true;
-}
-
-if (empty($currentThread['thread_qualify_max'])) {
-    $userCanQualify = false;
-}
-
-if ($userCanQualify) {
-    if ($post_id > $post_minor) {
-        $current_qualify_thread = showQualify(
-            '1',
-            $rows[$display_post_id]['user_id'],
-            $_GET['thread']
-        );
-
-        if ($locked == false) {
-            echo "<a href=\"forumqualify.php?".api_get_cidreq().
-                "&forum=".$forumId."&thread=".$threadId.
-                "&action=list&post=".$rows[$display_post_id]['post_id'].
-                "&user=".$rows[$display_post_id]['user_id']."&user_id=".
-                $rows[$display_post_id]['user_id'].
-                "&idtextqualify=".$current_qualify_thread.
-                "\" >".Display::return_icon(
-                    'quiz.png',
-                    get_lang('Qualify')
-                )."</a>";
-        }
-    }
-}
-if (($current_forum_category && $current_forum_category['locked'] == 0) &&
-    $current_forum['locked'] == 0 &&
-    $current_thread['locked'] == 0 || api_is_allowed_to_edit(false, true)
-) {
-    if ($_user['user_id'] ||
-        ($current_forum['allow_anonymous'] == 1 && !$_user['user_id'])
-    ) {
-        if (!api_is_anonymous() && api_is_allowed_to_session_edit(false, true)) {
-            echo '<a href="reply.php?'.api_get_cidreq().
-                '&forum='.$forumId.'&thread='.$threadId.
-                '&post='.$rows[$display_post_id]['post_id'].
-                '&action=replymessage">'.
-                Display::return_icon(
-                    'message_reply_forum.png',
-                    get_lang('ReplyToMessage')
-                )."</a>";
-            echo '<a href="reply.php?'.api_get_cidreq().
-                '&forum='.$forumId.'&thread='.$threadId.
-                '&post='.$rows[$display_post_id]['post_id'].
-                '&action=quote">'.
-                Display::return_icon(
-                    'quote.gif',
-                    get_lang('QuoteMessage')
-                )."</a>";
-        }
-    }
-} else {
-    if ($current_forum_category && $current_forum_category['locked'] == 1) {
-        echo get_lang('ForumcategoryLocked').'<br />';
-    }
-    if ($current_forum['locked'] == 1) {
-        echo get_lang('ForumLocked').'<br />';
-    }
-    if ($current_thread['locked'] == 1) {
-        echo get_lang('ThreadLocked').'<br />';
-    }
-}
-
-echo "</td>";
-// Note: this can be removed here because it will be displayed in the tree
-if (isset($whatsnew_post_info[$forumId][$threadId][$rows[$display_post_id]['post_id']]) &&
-    !empty($whatsnew_post_info[$forumId][$threadId][$rows[$display_post_id]['post_id']]) &&
-    !empty($whatsnew_post_info[$_GET['forum']][$rows[$display_post_id]['thread_id']])
-) {
-    $post_image = Display::return_icon('forumpostnew.gif');
-} else {
-    $post_image = Display::return_icon('forumpost.gif');
-}
-
-if ($rows[$display_post_id]['post_notification'] == '1' &&
-    $rows[$display_post_id]['poster_id'] == $_user['user_id']
-) {
-    $post_image .= Display::return_icon('forumnotification.gif', get_lang('YouWillBeNotified'));
-}
-// The post title
-echo "<td class=\"$titleclass\">".
-    prepare4display($rows[$display_post_id]['post_title'])."</td>";
-echo "</tr>";
-
-// The post message
-echo "<tr>";
-echo "<td class=\"$messageclass\">".
-    prepare4display($rows[$display_post_id]['post_text'])."</td>";
-echo "</tr>";
-
-// The check if there is an attachment
-$attachment_list = getAllAttachment($display_post_id);
-if (!empty($attachment_list) && is_array($attachment_list)) {
-    foreach ($attachment_list as $attachment) {
-        echo '<tr><td height="50%">';
-        $realname = $attachment['path'];
-        $user_filename = $attachment['filename'];
-        echo Display::return_icon('attachment.gif', get_lang('Attachment'));
-        echo '<a href="download.php?file=';
-        echo $realname;
-        echo ' "> '.$user_filename.' </a>';
-        echo '<span class="forum_attach_comment">'.
-            Security::remove_XSS($attachment['comment'], STUDENT).'</span>';
-
-        if (($current_forum['allow_edit'] == 1 && $rows[$display_post_id]['user_id'] == $_user['user_id']) ||
-            (api_is_allowed_to_edit(false, true) &&
-            !(api_is_session_general_coach() && $current_forum['session_id'] != $sessionId))
-        ) {
-            echo '&nbsp;&nbsp;<a href="'.api_get_self().'?'.
-                api_get_cidreq().'&action=delete_attach&id_attach='.$attachment['id'].'&forum='.$forumId.
-                '&thread='.$threadId.
-                '" onclick="javascript:if(!confirm(\''.
-                addslashes(
-                    api_htmlentities(
-                    get_lang('ConfirmYourChoice'),
-                    ENT_QUOTES
-                )
-                ).'\')) return false;">'.Display::return_icon(
-                    'delete.gif',
-                    get_lang('Delete')
-                ).'</a><br />';
-        }
-        echo '</td></tr>';
-    }
-}
-
-// The post has been displayed => it can be removed from the what's new array
-if (isset($whatsnew_post_info[$forumId][$threadId][$row['post_id']])) {
-    unset($whatsnew_post_info[$forumId][$threadId][$row['post_id']]);
-    unset($_SESSION['whatsnew_post_info'][$forumId][$threadId][$row['post_id']]);
-}
-echo "</table>";
-
-echo $thread_structure;

+ 4 - 0
main/inc/lib/extra_field.lib.php

@@ -149,6 +149,9 @@ class ExtraField extends Model
             case 'forum_category':
                 $this->extraFieldType = EntityExtraField::FORUM_CATEGORY_TYPE;
                 break;
+            case 'forum_post':
+                $this->extraFieldType = EntityExtraField::FORUM_POST_TYPE;
+                break;
         }
 
         $this->pageUrl = 'extra_fields.php?type='.$this->type;
@@ -184,6 +187,7 @@ class ExtraField extends Model
             'survey',
             'terms_and_condition',
             'forum_category',
+            'forum_post',
         ];
 
         if (api_get_configuration_value('allow_scheduled_announcements')) {

+ 2 - 2
main/inc/lib/extra_field_value.lib.php

@@ -116,6 +116,8 @@ class ExtraFieldValue extends Model
         $extraField = new ExtraField($this->type);
         $extraFields = $extraField->get_all(null, 'option_order');
         $resultsExist = [];
+
+        $dirPermissions = api_get_permissions_for_new_directories();
         // Parse params
         foreach ($extraFields as $fieldDetails) {
             if ($forceSave === false) {
@@ -152,7 +154,6 @@ class ExtraFieldValue extends Model
 
             $commentVariable = 'extra_'.$field_variable.'_comment';
             $comment = isset($params[$commentVariable]) ? $params[$commentVariable] : null;
-            $dirPermissions = api_get_permissions_for_new_directories();
 
             switch ($extraFieldInfo['field_type']) {
                 case ExtraField::FIELD_TYPE_GEOLOCALIZATION:
@@ -351,7 +352,6 @@ class ExtraFieldValue extends Model
                         'value' => $fieldToSave,
                         'comment' => $comment,
                     ];
-
                     $this->save($newParams);
 
                     break;

+ 1 - 2
main/template/default/forum/list.tpl

@@ -1,8 +1,6 @@
 {% extends 'layout/layout_1_col.tpl'|get_template %}
 {% block content %}
 
-{{ form_content }}
-
 <script>
     $(document).ready(function () {
         // default
@@ -89,6 +87,7 @@
                                         <div class="forum-date">
                                             <i class="fa fa-comments" aria-hidden="true"></i>
                                             {{ subitem.last_poster_date }}
+                                            « {{ subitem.last_post_title }} »
                                             {{ "By"|get_lang }}
                                             {{ subitem.last_poster_user }}
                                         </div>

+ 44 - 0
main/template/default/forum/posts.tpl

@@ -0,0 +1,44 @@
+{% extends 'layout/layout_1_col.tpl'|get_template %}
+{% import 'macro/macro.tpl'|get_template as display %}
+
+{% block content %}
+    {% if origin == 'learnpath' %}
+        <div style="height:15px">&nbsp;</div>
+    {% endif %}
+
+    {% if forum_actions %}
+        <div class="actions">
+            {{ forum_actions }}
+        </div>
+    {% endif %}
+
+    {% for post in posts %}
+        {% set post_data %}
+            <div class="row">
+                <div class="col-md-2">
+                    {{ post.user_data }}
+                </div>
+                {% set highlight = '' %}
+                {% if post.current %}
+                    {% set highlight = 'alert alert-danger' %}
+                {% endif %}
+
+                <div class="col-md-10 {{ highlight }}">
+                    {{ post.post_data }}
+
+                    {{ post.post_attachments }}
+                </div>
+            </div>
+            <div class="row">
+                <div class="col-md-4"></div>
+                <div class="col-md-8 text-right">
+                    {{ post.post_buttons }}
+                </div>
+            </div>
+        {% endset %}
+
+        <div class="col-md-offset-{{ post.indent_cnt }} forum-post">
+            {{ display.panel('', post_data ) }}
+        </div>
+    {% endfor %}
+{% endblock %}

+ 6 - 2
main/template/default/macro/macro.tpl

@@ -89,12 +89,16 @@
 
 {% macro panel(name, content, footer = '') %}
 <div class="panel panel-default">
-    <div class="panel-heading"> {{ name }}</div>
+    {% if name %}
+        <div class="panel-heading"> {{ name }}</div>
+    {% endif %}
+
     <div class="panel-body">
         {{ content }}
     </div>
+
     {% if footer %}
         <div class="panel-footer">{{ footer }}</div>
     {% endif %}
 </div>
-{% endmacro %}
+{% endmacro %}

+ 1 - 0
src/Chamilo/CoreBundle/Entity/ExtraField.php

@@ -32,6 +32,7 @@ class ExtraField extends BaseAttribute
     const SCHEDULED_ANNOUNCEMENT = 13;
     const TERMS_AND_CONDITION_TYPE = 14;
     const FORUM_CATEGORY_TYPE = 15;
+    const FORUM_POST_TYPE = 16;
 
     /**
      * @var int