viewthread_nested.inc.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  5. * @author Julio Montoya <gugli100@gmail.com> UI Improvements + lots of bugfixes
  6. * @copyright Ghent University
  7. * @package chamilo.forum
  8. */
  9. // Are we in a lp ?
  10. $origin = '';
  11. if (isset($_GET['origin'])) {
  12. $origin = Security::remove_XSS($_GET['origin']);
  13. }
  14. //delete attachment file
  15. if (isset($_GET['action']) &&
  16. $_GET['action'] == 'delete_attach' &&
  17. isset($_GET['id_attach'])
  18. ) {
  19. delete_attachment(0, $_GET['id_attach']);
  20. }
  21. $sortDirection = isset($_GET['posts_order']) && $_GET['posts_order'] === 'desc' ? 'DESC' : 'ASC';
  22. $rows = getPosts($_GET['thread'], $sortDirection, true);
  23. $count = 0;
  24. $clean_forum_id = intval($_GET['forum']);
  25. $clean_thread_id = intval($_GET['thread']);
  26. $group_id = api_get_group_id();
  27. $locked = api_resource_is_locked_by_gradebook($clean_thread_id, LINK_FORUM_THREAD);
  28. $sessionId = api_get_session_id();
  29. $currentThread = get_thread_information($_GET['thread']);
  30. $userId = api_get_user_id();
  31. foreach ($rows as $post) {
  32. // The style depends on the status of the message: approved or not.
  33. if ($post['visible'] == '0') {
  34. $titleclass = 'forum_message_post_title_2_be_approved';
  35. $messageclass = 'forum_message_post_text_2_be_approved';
  36. $leftclass = 'forum_message_left_2_be_approved';
  37. } else {
  38. $titleclass = 'forum_message_post_title';
  39. $messageclass = 'forum_message_post_text';
  40. $leftclass = 'forum_message_left';
  41. }
  42. /*
  43. echo '<pre>';
  44. print_r($post);
  45. echo '</pre>';
  46. */
  47. $indent = $post['indent_cnt'];
  48. $html = '';
  49. $html .= '<div class="col-md-offset-' . $indent . '" >';
  50. $html .= '<div class="panel panel-default forum-post">';
  51. $html .= '<div class="panel-body">';
  52. $html .= '<div class="row">';
  53. $html .= '<div class="col-md-2">';
  54. $username = sprintf(get_lang('LoginX'), $post['username']);
  55. if ($post['user_id'] == '0') {
  56. $name = $post['poster_name'];
  57. } else {
  58. $name = api_get_person_name($post['firstname'], $post['lastname']);
  59. }
  60. if (api_get_course_setting('allow_user_image_forum')) {
  61. $html .= '<div class="thumbnail">' . display_user_image($post['user_id'], $name, $origin) . '</div>';
  62. }
  63. $html .= Display::tag(
  64. 'h4',
  65. display_user_link($post['user_id'], $name, $origin, $username),
  66. array('class' => 'title-username')
  67. );
  68. $html .= Display::tag(
  69. 'p',
  70. api_convert_and_format_date($post['post_date']),
  71. array('class' => 'post-date')
  72. );
  73. // get attach id
  74. $attachment_list = get_attachment($post['post_id']);
  75. $id_attach = !empty($attachment_list) ? $attachment_list['iid'] : '';
  76. $iconEdit = '';
  77. // The user who posted it can edit his thread only if the course admin allowed this in the properties of the forum
  78. // The course admin him/herself can do this off course always
  79. if (
  80. GroupManager::is_tutor_of_group(api_get_user_id(), $group_id) ||
  81. ($current_forum['allow_edit'] == 1 && $post['user_id'] == $userId) ||
  82. (api_is_allowed_to_edit(false, true) && !(api_is_course_coach() && $current_forum['session_id'] != $sessionId))
  83. ) {
  84. if ($locked == false) {
  85. $iconEdit .= "<a href=\"editpost.php?" . api_get_cidreq()
  86. . "&forum=$clean_forum_id&thread=$clean_thread_id&post={$post['post_id']}&id_attach=$id_attach"
  87. . "\">"
  88. . Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL)
  89. . "</a>";
  90. }
  91. }
  92. if (
  93. GroupManager::is_tutor_of_group(api_get_user_id(), $group_id) ||
  94. api_is_allowed_to_edit(false, true) &&
  95. !(api_is_course_coach() && $current_forum['session_id'] != $sessionId)
  96. ) {
  97. if ($locked == false) {
  98. $iconEdit .="<a href=\"" . api_get_self() . "?" . api_get_cidreq()
  99. . "&forum=$clean_forum_id&thread=$clean_thread_id&action=delete&content=post&id={$post['post_id']}"
  100. . "\" onclick=\"javascript:if(!confirm('"
  101. . addslashes(api_htmlentities(get_lang('DeletePost'), ENT_QUOTES)) . "')) return false;\">"
  102. . Display::return_icon('delete.png', get_lang('Delete'), array(), ICON_SIZE_SMALL)
  103. . "</a>";
  104. }
  105. }
  106. if (
  107. api_is_allowed_to_edit(false, true) &&
  108. !(
  109. api_is_course_coach() &&
  110. $current_forum['session_id'] != $sessionId
  111. )
  112. ) {
  113. $iconEdit .= return_visible_invisible_icon(
  114. 'post',
  115. $post['post_id'],
  116. $post['visible'],
  117. array(
  118. 'forum' => $clean_forum_id,
  119. 'thread' => $clean_thread_id
  120. )
  121. );
  122. if ($count > 0) {
  123. $iconEdit .= "<a href=\"viewthread.php?" . api_get_cidreq()
  124. . "&forum=$clean_forum_id&thread=$clean_thread_id&action=move&origin=$origin&post={$post['post_id']}"
  125. . "\">" . Display::return_icon('move.png', get_lang('MovePost'), array(), ICON_SIZE_SMALL) . "</a>";
  126. }
  127. }
  128. $userCanQualify = $currentThread['thread_peer_qualify'] == 1 && $post['poster_id'] != $userId;
  129. if (api_is_allowed_to_edit(null, true)) {
  130. $userCanQualify = true;
  131. }
  132. if (empty($currentThread['thread_qualify_max'])) {
  133. $userCanQualify = false;
  134. }
  135. if ($userCanQualify) {
  136. if ($count > 0) {
  137. $current_qualify_thread = showQualify(
  138. '1', $post['user_id'], $_GET['thread']
  139. );
  140. if ($locked == false) {
  141. $iconEdit .= "<a href=\"forumqualify.php?" . api_get_cidreq()
  142. . "&forum=$clean_forum_id&thread=$clean_thread_id&action=list&post={$post['post_id']}"
  143. . "&user={$post['user_id']}&user_id={$post['user_id']}&origin=$origin"
  144. . "&idtextqualify=$current_qualify_thread"
  145. . "\" >" . Display::return_icon('quiz.gif', get_lang('Qualify')) . "</a>";
  146. }
  147. }
  148. }
  149. if ($iconEdit != '') {
  150. $html .= '<div class="tools-icons">' . $iconEdit . '</div>';
  151. }
  152. if (($current_forum_category && $current_forum_category['locked'] == 0) &&
  153. $current_forum['locked'] == 0 && $current_thread['locked'] == 0 || api_is_allowed_to_edit(false, true)
  154. ) {
  155. if ($userId || ($current_forum['allow_anonymous'] == 1 && !$userId)) {
  156. if (!api_is_anonymous() && api_is_allowed_to_session_edit(false, true)) {
  157. $buttonReply = Display::tag(
  158. 'a',
  159. '<i class="fa fa-reply"></i> ' . get_lang('ReplyToMessage'),
  160. array(
  161. 'href' => 'reply.php?' . api_get_cidreq()
  162. . "&forum=$clean_forum_id'&thread=$clean_thread_id"
  163. . "&post={$post['post_id']}&action=replymessage&origin=$origin",
  164. 'class' => 'btn btn-primary'
  165. )
  166. );
  167. $buttonQuote = Display::tag(
  168. 'a',
  169. '<i class="fa fa-quote-left"></i> ' . get_lang('QuoteMessage'),
  170. array(
  171. 'href' => 'reply.php?' . api_get_cidreq()
  172. . "&forum=$clean_forum_id&thread=$clean_thread_id"
  173. . "&post={$post['post_id']}&action=quote&origin=$origin",
  174. 'class' => 'btn btn-success'
  175. )
  176. );
  177. }
  178. }
  179. } else {
  180. if ($current_forum_category && $current_forum_category['locked'] == 1) {
  181. $closedPost = Display::tag(
  182. 'div',
  183. '<i class="fa fa-exclamation-triangle"></i> ' . get_lang('ForumcategoryLocked'),
  184. array('class' => 'alert alert-warning post-closed')
  185. );
  186. }
  187. if ($current_forum['locked'] == 1) {
  188. $closedPost = Display::tag(
  189. 'div',
  190. '<i class="fa fa-exclamation-triangle"></i> ' . get_lang('ForumLocked'),
  191. array('class' => 'alert alert-warning post-closed')
  192. );
  193. }
  194. if ($current_thread['locked'] == 1) {
  195. $closedPost = Display::tag(
  196. 'div',
  197. '<i class="fa fa-exclamation-triangle"></i> ' . get_lang('ThreadLocked'),
  198. array('class' => 'alert alert-warning post-closed')
  199. );
  200. }
  201. $html .= $closedPost;
  202. }
  203. $html .= '</div>';
  204. // note: this can be removed here because it will be displayed in the tree
  205. if (
  206. isset($whatsnew_post_info[$current_forum['forum_id']][$current_thread['thread_id']][$post['post_id']]) &&
  207. !empty($whatsnew_post_info[$current_forum['forum_id']][$current_thread['thread_id']][$post['post_id']]) &&
  208. !empty($whatsnew_post_info[$_GET['forum']][$post['thread_id']])
  209. ) {
  210. $post_image = Display::return_icon('forumpostnew.gif');
  211. } else {
  212. $post_image = Display::return_icon('forumpost.gif');
  213. }
  214. if ($post['post_notification'] == '1' && $post['poster_id'] == $userId) {
  215. $post_image .= Display::return_icon(
  216. 'forumnotification.gif', get_lang('YouWillBeNotified')
  217. );
  218. }
  219. $html .= '<div class="col-md-10">';
  220. // The post title
  221. $titlePost = Display::tag('h3', $post['post_title'], array('class' => 'forum_post_title'));
  222. $html .= Display::tag('div', $titlePost, array('class' => 'post-header'));
  223. // the post body
  224. $html .= Display::tag('div', $post['post_text'], array('class' => 'post-body'));
  225. $html .= '</div>';
  226. $html .= '</div>';
  227. $html .= '<div class="row">';
  228. $html .= '<div class="col-md-6">';
  229. // The check if there is an attachment
  230. $attachment_list = getAllAttachment($post['post_id']);
  231. if (!empty($attachment_list) && is_array($attachment_list)) {
  232. foreach ($attachment_list as $attachment) {
  233. $realname = $attachment['path'];
  234. $user_filename = $attachment['filename'];
  235. $html .= Display::return_icon('attachment.gif', get_lang('Attachment'));
  236. $html .= '<a href="download.php?file=';
  237. $html .= $realname;
  238. $html .= ' "> ' . $user_filename . ' </a>';
  239. $html .= '<span class="forum_attach_comment" >' . $attachment['comment'] . '</span>';
  240. if (($current_forum['allow_edit'] == 1 && $post['user_id'] == $userId) ||
  241. (api_is_allowed_to_edit(false, true) && !(api_is_course_coach() && $current_forum['session_id'] != $sessionId))
  242. ) {
  243. $html .= '&nbsp;&nbsp;<a href="' . api_get_self() . '?' . api_get_cidreq() . '&origin='
  244. . Security::remove_XSS($_GET['origin']) . '&action=delete_attach&id_attach='
  245. . $attachment['iid'] . '&forum=' . $clean_forum_id . '&thread=' . $clean_thread_id
  246. . '" onclick="javascript:if(!confirm(\''
  247. . addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES)) . '\')) return false;">'
  248. . Display::return_icon('delete.gif', get_lang('Delete')) . '</a><br />';
  249. }
  250. }
  251. }
  252. $html .= '</div>';
  253. $html .= '<div class="col-md-6 text-right">';
  254. $html .= $buttonReply . ' ' . $buttonQuote;
  255. $html .= '</div>';
  256. $html .= '</div>';
  257. // The post has been displayed => it can be removed from the what's new array
  258. unset($whatsnew_post_info[$current_forum['forum_id']][$current_thread['thread_id']][$post['post_id']]);
  259. unset($_SESSION['whatsnew_post_info'][$current_forum['forum_id']][$current_thread['thread_id']][$post['post_id']]);
  260. $html .= '</div>';
  261. $html .= '</div>';
  262. $html .= '</div>';
  263. echo $html;
  264. $count++;
  265. }