viewthread_threaded.inc.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * These files are a complete rework of the forum. The database structure is
  5. * based on phpBB but all the code is rewritten. A lot of new functionalities
  6. * are added:
  7. * - forum categories and forums can be sorted up or down, locked or made invisible
  8. * - consistent and integrated forum administration
  9. * - forum options: are students allowed to edit their post?
  10. * moderation of posts (approval)
  11. * reply only forums (students cannot create new threads)
  12. * multiple forums per group
  13. * - sticky messages
  14. * - new view option: nested view
  15. * - quoting a message
  16. *
  17. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  18. * @author Julio Montoya <gugli100@gmail.com> UI Improvements + lots of bugfixes
  19. *
  20. * @package chamilo.forum
  21. */
  22. require_once api_get_path(SYS_CODE_PATH).'forum/forumfunction.inc.php';
  23. $forumUrl = api_get_path(WEB_CODE_PATH).'forum/';
  24. $rows = get_posts($_GET['thread']);
  25. $rows = calculate_children($rows);
  26. if (isset($_GET['post']) && $_GET['post']) {
  27. $display_post_id = intval($_GET['post']);
  28. } else {
  29. // we need to display the first post
  30. reset($rows);
  31. $current = current($rows);
  32. $display_post_id = $current['post_id'];
  33. }
  34. // Are we in a lp ?
  35. $origin = '';
  36. if(isset($_GET['origin'])) {
  37. $origin = Security::remove_XSS($_GET['origin']);
  38. }
  39. // Delete attachment file.
  40. if ((isset($_GET['action']) && $_GET['action']=='delete_attach') && isset($_GET['id_attach'])) {
  41. delete_attachment(0, $_GET['id_attach']);
  42. }
  43. // Displaying the thread (structure)
  44. $thread_structure="<div class=\"structure\">".get_lang('Structure')."</div>";
  45. $counter=0;
  46. $count=0;
  47. $prev_next_array=array();
  48. $clean_forum_id = intval($_GET['forum']);
  49. $clean_thread_id = intval($_GET['thread']);
  50. $group_id = api_get_group_id();
  51. foreach ($rows as $post) {
  52. $counter++;
  53. $indent=$post['indent_cnt']*'20';
  54. $thread_structure.= "<div style=\"margin-left: ".$indent."px;\">";
  55. if (isset($whatsnew_post_info[$current_forum['forum_id']][$current_thread['thread_id']][$post['post_id']]) AND
  56. !empty($whatsnew_post_info[$current_forum['forum_id']][$current_thread['thread_id']][$post['post_id']]) AND
  57. !empty($whatsnew_post_info[$_GET['forum']][$post['thread_id']])
  58. ) {
  59. $post_image = Display::return_icon('forumpostnew.gif');
  60. } else {
  61. $post_image = Display::return_icon('forumpost.gif');
  62. }
  63. $thread_structure.= $post_image;
  64. if (isset($_GET['post']) &&
  65. $_GET['post'] == $post['post_id'] OR
  66. ($counter==1 AND !isset($_GET['post']))
  67. ) {
  68. $thread_structure .= '<strong>'.prepare4display($post['post_title']).'</strong></div>';
  69. $prev_next_array[]= $post['post_id'];
  70. } else {
  71. if ($post['visible']=='0') {
  72. $class=' class="invisible"';
  73. } else {
  74. $class='';
  75. }
  76. $count_loop=($count==0)?'&amp;id=1' : '';
  77. $thread_structure.= "<a href=\"viewthread.php?".api_get_cidreq()."&forum=".$clean_forum_id."&thread=".$clean_thread_id."&post=".$post['post_id']."&amp;origin=$origin$count_loop\" $class>".
  78. prepare4display($post['post_title'])."</a></div>";
  79. $prev_next_array[]=$post['post_id'];
  80. }
  81. $count++;
  82. }
  83. $locked = api_resource_is_locked_by_gradebook($clean_thread_id, LINK_FORUM_THREAD);
  84. /* NAVIGATION CONTROLS */
  85. $current_id = array_search($display_post_id, $prev_next_array);
  86. $max = count($prev_next_array);
  87. $next_id = $current_id + 1;
  88. $prev_id = $current_id - 1;
  89. // text
  90. $first_message = get_lang('FirstMessage');
  91. $last_message = get_lang('LastMessage');
  92. $next_message = get_lang('NextMessage');
  93. $prev_message = get_lang('PrevMessage');
  94. // images
  95. $first_img = Display::return_icon(
  96. 'action_first.png',
  97. get_lang('FirstMessage'),
  98. array('style' => 'vertical-align: middle;')
  99. );
  100. $last_img = Display::return_icon(
  101. 'action_last.png',
  102. get_lang('LastMessage'),
  103. array('style' => 'vertical-align: middle;')
  104. );
  105. $prev_img = Display::return_icon(
  106. 'action_prev.png',
  107. get_lang('PrevMessage'),
  108. array('style' => 'vertical-align: middle;')
  109. );
  110. $next_img = Display::return_icon(
  111. 'action_next.png',
  112. get_lang('NextMessage'),
  113. array('style' => 'vertical-align: middle;')
  114. );
  115. // links
  116. $first_href = $forumUrl.'viewthread.php?'.api_get_cidreq().'&amp;forum='.$clean_forum_id.'&amp;thread='.$clean_thread_id.'&amp;gradebook='.$gradebook.'&id=1&amp;post='.$prev_next_array[0];
  117. $last_href = $forumUrl.'viewthread.php?'.api_get_cidreq().'&amp;forum='.$clean_forum_id.'&amp;thread='.$clean_thread_id.'&amp;gradebook='.$gradebook.'&post='.$prev_next_array[$max-1];
  118. $prev_href = $forumUrl.'viewthread.php?'.api_get_cidreq().'&amp;forum='.$clean_forum_id.'&amp;thread='.$clean_thread_id.'&amp;gradebook='.$gradebook.'&post='.$prev_next_array[$prev_id];
  119. $next_href = $forumUrl.'viewthread.php?'.api_get_cidreq().'&amp;forum='.$clean_forum_id.'&amp;thread='.$clean_thread_id.'&amp;gradebook='.$gradebook.'&post='.$prev_next_array[$next_id];
  120. echo '<center style="margin-top: 10px; margin-bottom: 10px;">';
  121. //go to: first and previous
  122. if ((int)$current_id > 0) {
  123. echo '<a href="'.$first_href.'" '.$class.' title='.$first_message.'>'.$first_img.' '.$first_message.'</a>';
  124. echo '<a href="'.$prev_href.'" '.$class_prev.' title='.$prev_message.'>'.$prev_img.' '.$prev_message.'</a>';
  125. } else {
  126. echo '<b><span class="invisible">'.$first_img.' '.$first_message.'</b></span>';
  127. echo '<b><span class="invisible">'.$prev_img.' '.$prev_message.'</b></span>';
  128. }
  129. // current counter
  130. echo ' [ '.($current_id+1).' / '.$max.' ] ';
  131. // go to: next and last
  132. if (($current_id+1) < $max) {
  133. echo '<a href="'.$next_href.'" '.$class_next.' title='.$next_message.'>'.$next_message.' '.$next_img.'</a>';
  134. echo '<a href="'.$last_href.'" '.$class.' title='.$last_message.'>'.$last_message.' '.$last_img.'</a>';
  135. } else {
  136. echo '<b><span class="invisible">'.$next_message.' '.$next_img.'</b></span>';
  137. echo '<b><span class="invisible">'.$last_message.' '.$last_img.'</b></span>';
  138. }
  139. echo '</center>';
  140. // the style depends on the status of the message: approved or not
  141. if ($rows[$display_post_id]['visible'] == '0') {
  142. $titleclass = 'forum_message_post_title_2_be_approved';
  143. $messageclass = 'forum_message_post_text_2_be_approved';
  144. $leftclass = 'forum_message_left_2_be_approved';
  145. } else {
  146. $titleclass = 'forum_message_post_title';
  147. $messageclass = 'forum_message_post_text';
  148. $leftclass = 'forum_message_left';
  149. }
  150. // Displaying the message
  151. // we mark the image we are displaying as set
  152. unset($whatsnew_post_info[$current_forum['forum_id']][$current_thread['thread_id']][$rows[$display_post_id]['post_id']]);
  153. echo "<table width=\"100%\" class=\"forum_table\" cellspacing=\"5\" border=\"0\">";
  154. echo "<tr>";
  155. echo "<td rowspan=\"3\" class=\"$leftclass\">";
  156. $username = sprintf(get_lang('LoginX'), $rows[$display_post_id]['username']);
  157. if ($rows[$display_post_id]['user_id']=='0') {
  158. $name = prepare4display($rows[$display_post_id]['poster_name']);
  159. } else {
  160. $name = api_get_person_name($rows[$display_post_id]['firstname'], $rows[$display_post_id]['lastname']);
  161. }
  162. if (api_get_course_setting('allow_user_image_forum')) {
  163. echo '<br />'.display_user_image($rows[$display_post_id]['user_id'],$name, $origin).'<br />';
  164. }
  165. echo display_user_link($rows[$display_post_id]['user_id'], $name, $origin, $username)."<br />";
  166. echo api_convert_and_format_date($rows[$display_post_id]['post_date']).'<br /><br />';
  167. // get attach id
  168. $attachment_list=get_attachment($display_post_id);
  169. $id_attach = !empty($attachment_list)?$attachment_list['id']:'';
  170. // The user who posted it can edit his thread only if the course admin allowed this in the properties of the forum
  171. // The course admin him/herself can do this off course always
  172. if (GroupManager::is_tutor_of_group(api_get_user_id(), $group_id) OR ($current_forum['allow_edit']==1 AND $row['user_id']==$_user['user_id']) or (api_is_allowed_to_edit(false,true) && !(api_is_course_coach() && $current_forum['session_id']!=$_SESSION['id_session']))) {
  173. if ($locked == false) {
  174. echo "<a href=\"editpost.php?".api_get_cidreq()."&forum=".$clean_forum_id."&thread=".$clean_thread_id."&post=".$rows[$display_post_id]['post_id']."&amp;id_attach=".$id_attach."\">".
  175. Display::return_icon('edit.png',get_lang('Edit'), array(), ICON_SIZE_SMALL).'</a>';
  176. }
  177. }
  178. if (GroupManager::is_tutor_of_group(api_get_user_id(), $group_id) OR
  179. api_is_allowed_to_edit(false,true) &&
  180. !(api_is_course_coach() && $current_forum['session_id']!=$_SESSION['id_session'])
  181. ) {
  182. if ($locked == false) {
  183. echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&forum=".$clean_forum_id."&amp;thread=".$clean_thread_id."&amp;action=delete&amp;content=post&amp;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'), array(), ICON_SIZE_SMALL)."</a>";
  184. }
  185. display_visible_invisible_icon('post', $rows[$display_post_id]['post_id'], $rows[$display_post_id]['visible'],array('forum'=>$clean_forum_id,'thread'=>$clean_thread_id, 'post'=>Security::remove_XSS($_GET['post']) ));
  186. echo "";
  187. //verified the post minor
  188. $my_post=get_posts($_GET['thread']);
  189. $id_posts=array();
  190. foreach ($my_post as $post_value) {
  191. $id_posts[]=$post_value['post_id'];
  192. }
  193. sort($id_posts,SORT_NUMERIC);
  194. reset($id_posts);
  195. //the post minor
  196. $post_minor=(int)$id_posts[0];
  197. $post_id = isset($_GET['post'])?(int)$_GET['post']:0;
  198. if (!isset($_GET['id']) && $post_id>$post_minor) {
  199. echo "<a href=\"viewthread.php?".api_get_cidreq()."&amp;gidReq=".Security::remove_XSS($_GET['gidReq'])."&amp;forum=".$clean_forum_id."&amp;thread=".$clean_thread_id."&amp;origin=".$origin."&amp;action=move&amp;post=".$rows[$display_post_id]['post_id']."\">".Display::return_icon('move.png',get_lang('MovePost'), array(), ICON_SIZE_SMALL)."</a>";
  200. }
  201. }
  202. $userinf = api_get_user_info($rows[$display_post_id]['user_id']);
  203. $user_status = api_get_status_of_user_in_course(
  204. $rows[$display_post_id]['user_id'],
  205. api_get_course_id()
  206. );
  207. if (api_is_allowed_to_edit(null,true)) {
  208. if ($post_id > $post_minor) {
  209. $current_qualify_thread=show_qualify('1', $rows[$display_post_id]['user_id'],$_GET['thread']);
  210. if ($locked == false) {
  211. echo "<a href=\"forumqualify.php?".api_get_cidreq()."&amp;forum=".$clean_forum_id."&amp;thread=".$clean_thread_id."&amp;action=list&amp;post=".$rows[$display_post_id]['post_id']."&amp;user=".$rows[$display_post_id]['user_id']."&amp;user_id=".$rows[$display_post_id]['user_id']."&amp;origin=".$origin."&amp;idtextqualify=".$current_qualify_thread."\" >".Display::return_icon('new_test_small.gif',get_lang('Qualify'))."</a>";
  212. }
  213. }
  214. }
  215. if (($current_forum_category && $current_forum_category['locked']==0) AND $current_forum['locked']==0 AND $current_thread['locked']==0 OR api_is_allowed_to_edit(false,true)) {
  216. if ($_user['user_id'] OR ($current_forum['allow_anonymous']==1 AND !$_user['user_id'])) {
  217. if (!api_is_anonymous() && api_is_allowed_to_session_edit(false,true)) {
  218. echo '<a href="reply.php?'.api_get_cidreq().'&amp;forum='.$clean_forum_id.'&amp;thread='.$clean_thread_id.'&amp;post='.$rows[$display_post_id]['post_id'].'&amp;action=replymessage&amp;origin='. $origin .'">'.Display :: return_icon('message_reply_forum.png', get_lang('ReplyToMessage'))."</a>";
  219. echo '<a href="reply.php?'.api_get_cidreq().'&amp;forum='.$clean_forum_id.'&amp;thread='.$clean_thread_id.'&amp;post='.$rows[$display_post_id]['post_id'].'&amp;action=quote&amp;origin='. $origin .'">'.Display :: return_icon('quote.gif', get_lang('QuoteMessage'))."</a>";
  220. }
  221. }
  222. } else {
  223. if ($current_forum_category && $current_forum_category['locked']==1) {
  224. echo get_lang('ForumcategoryLocked').'<br />';
  225. }
  226. if ($current_forum['locked']==1) {
  227. echo get_lang('ForumLocked').'<br />';
  228. }
  229. if ($current_thread['locked']==1) {
  230. echo get_lang('ThreadLocked').'<br />';
  231. }
  232. }
  233. echo "</td>";
  234. // note: this can be removed here because it will be displayed in the tree
  235. if (isset($whatsnew_post_info[$current_forum['forum_id']][$current_thread['thread_id']][$rows[$display_post_id]['post_id']]) AND
  236. !empty($whatsnew_post_info[$current_forum['forum_id']][$current_thread['thread_id']][$rows[$display_post_id]['post_id']]) AND
  237. !empty($whatsnew_post_info[$_GET['forum']][$rows[$display_post_id]['thread_id']])
  238. ) {
  239. $post_image=Display::return_icon('forumpostnew.gif');
  240. } else {
  241. $post_image=Display::return_icon('forumpost.gif');
  242. }
  243. if ($rows[$display_post_id]['post_notification']=='1' AND $rows[$display_post_id]['poster_id']==$_user['user_id']) {
  244. $post_image.=Display::return_icon('forumnotification.gif',get_lang('YouWillBeNotified'));
  245. }
  246. // The post title
  247. echo "<td class=\"$titleclass\">".prepare4display($rows[$display_post_id]['post_title'])."</td>";
  248. echo "</tr>";
  249. // The post message
  250. echo "<tr>";
  251. echo "<td class=\"$messageclass\">".prepare4display($rows[$display_post_id]['post_text'])."</td>";
  252. echo "</tr>";
  253. // The check if there is an attachment
  254. $attachment_list = get_attachment($display_post_id);
  255. if (!empty($attachment_list)) {
  256. echo '<tr><td height="50%">';
  257. $realname = $attachment_list['path'];
  258. $user_filename = $attachment_list['filename'];
  259. echo Display::return_icon('attachment.gif',get_lang('Attachment'));
  260. echo '<a href="download.php?file=';
  261. echo $realname;
  262. echo ' "> '.$user_filename.' </a>';
  263. echo '<span class="forum_attach_comment" >'.Security::remove_XSS($attachment_list['comment'], STUDENT).'</span>';
  264. if (($current_forum['allow_edit']==1 AND $rows[$display_post_id]['user_id']==$_user['user_id']) or (api_is_allowed_to_edit(false,true) && !(api_is_course_coach() && $current_forum['session_id']!=$_SESSION['id_session']))) {
  265. echo '&nbsp;&nbsp;<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;origin='.Security::remove_XSS($_GET['origin']).'&amp;action=delete_attach&amp;id_attach='.$attachment_list['id'].'&amp;forum='.$clean_forum_id.'&amp;thread='.$clean_thread_id.'" onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTESt)).'\')) return false;">'.Display::return_icon('delete.gif',get_lang('Delete')).'</a><br />';
  266. }
  267. echo '</td></tr>';
  268. }
  269. // The post has been displayed => it can be removed from the what's new array
  270. if (isset($whatsnew_post_info[$current_forum['forum_id']][$current_thread['thread_id']][$row['post_id']])) {
  271. unset($whatsnew_post_info[$current_forum['forum_id']][$current_thread['thread_id']][$row['post_id']]);
  272. unset($_SESSION['whatsnew_post_info'][$current_forum['forum_id']][$current_thread['thread_id']][$row['post_id']]);
  273. }
  274. echo "</table>";
  275. echo $thread_structure;