viewthread_threaded.inc.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  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. $rows = get_posts($_GET['thread']); // Note: This has to be cleaned first.
  24. $rows = calculate_children($rows);
  25. if ($_GET['post']) {
  26. $display_post_id = intval($_GET['post']); // note: this has to be cleaned first
  27. } else {
  28. // we need to display the first post
  29. reset($rows);
  30. $current = current($rows);
  31. $display_post_id = $current['post_id'];
  32. }
  33. // Are we in a lp ?
  34. $origin = '';
  35. if(isset($_GET['origin'])) {
  36. $origin = Security::remove_XSS($_GET['origin']);
  37. }
  38. // Delete attachment file.
  39. if ((isset($_GET['action']) && $_GET['action']=='delete_attach') && isset($_GET['id_attach'])) {
  40. delete_attachment(0,$_GET['id_attach']);
  41. }
  42. // Displaying the thread (structure)
  43. $thread_structure="<div class=\"structure\">".get_lang('Structure')."</div>";
  44. $counter=0;
  45. $count=0;
  46. $prev_next_array=array();
  47. $clean_forum_id = intval($_GET['forum']);
  48. $clean_thread_id = intval($_GET['thread']);
  49. $group_id = api_get_group_id();
  50. foreach ($rows as $post) {
  51. $counter++;
  52. $indent=$post['indent_cnt']*'20';
  53. $thread_structure.= "<div style=\"margin-left: ".$indent."px;\">";
  54. if (isset($whatsnew_post_info[$current_forum['forum_id']][$current_thread['thread_id']][$post['post_id']]) and !empty($whatsnew_post_info[$current_forum['forum_id']][$current_thread['thread_id']][$post['post_id']]) and !empty($whatsnew_post_info[$_GET['forum']][$post['thread_id']])) {
  55. $post_image=Display::return_icon('forumpostnew.gif');
  56. } else {
  57. $post_image=Display::return_icon('forumpost.gif');
  58. }
  59. $thread_structure.= $post_image;
  60. if ($_GET['post']==$post['post_id'] OR ($counter==1 AND !isset($_GET['post']))) {
  61. $thread_structure.='<strong>'.prepare4display($post['post_title']).'</strong></div>';
  62. $prev_next_array[]=$post['post_id'];
  63. } else {
  64. if ($post['visible']=='0') {
  65. $class=' class="invisible"';
  66. } else {
  67. $class='';
  68. }
  69. $count_loop=($count==0)?'&amp;id=1' : '';
  70. $thread_structure.= "<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;post=".$post['post_id']."&amp;origin=$origin$count_loop\" $class>".prepare4display($post['post_title'])."</a></div>";
  71. $prev_next_array[]=$post['post_id'];
  72. }
  73. $count++;
  74. }
  75. $locked = api_resource_is_locked_by_gradebook($clean_thread_id, LINK_FORUM_THREAD);
  76. /* NAVIGATION CONTROLS */
  77. $current_id=array_search($display_post_id,$prev_next_array);
  78. $max=count($prev_next_array);
  79. $next_id=$current_id+1;
  80. $prev_id=$current_id-1;
  81. // text
  82. $first_message=get_lang('FirstMessage');
  83. $last_message=get_lang('LastMessage');
  84. $next_message=get_lang('NextMessage');
  85. $prev_message=get_lang('PrevMessage');
  86. // images
  87. $first_img = Display::return_icon('action_first.png',get_lang('FirstMessage'), array('style' => 'vertical-align: middle;'));
  88. $last_img = Display::return_icon('action_last.png',get_lang('LastMessage'), array('style' => 'vertical-align: middle;'));
  89. $prev_img = Display::return_icon('action_prev.png',get_lang('PrevMessage'), array('style' => 'vertical-align: middle;'));
  90. $next_img = Display::return_icon('action_next.png',get_lang('NextMessage'), array('style' => 'vertical-align: middle;'));
  91. // links
  92. $first_href = 'viewthread.php?'.api_get_cidreq().'&amp;forum='.$clean_forum_id.'&amp;thread='.$clean_thread_id.'&amp;gradebook='.$gradebook.'&amp;origin='.$origin.'&amp;id=1&amp;post='.$prev_next_array[0];
  93. $last_href = 'viewthread.php?'.api_get_cidreq().'&amp;forum='.$clean_forum_id.'&amp;thread='.$clean_thread_id.'&amp;gradebook='.$gradebook.'&amp;origin='.$origin.'&amp;post='.$prev_next_array[$max-1];
  94. $prev_href = 'viewthread.php?'.api_get_cidreq().'&amp;forum='.$clean_forum_id.'&amp;thread='.$clean_thread_id.'&amp;gradebook='.$gradebook.'&amp;origin='.$origin.'&amp;post='.$prev_next_array[$prev_id];
  95. $next_href = 'viewthread.php?'.api_get_cidreq().'&amp;forum='.$clean_forum_id.'&amp;thread='.$clean_thread_id.'&amp;gradebook='.$gradebook.'&amp;origin='.$origin.'&amp;post='.$prev_next_array[$next_id];
  96. echo '<center style="margin-top: 10px; margin-bottom: 10px;">';
  97. //go to: first and previous
  98. if ((int)$current_id > 0) {
  99. echo '<a href="'.$first_href.'" '.$class.' title='.$first_message.'>'.$first_img.' '.$first_message.'</a>';
  100. echo '<a href="'.$prev_href.'" '.$class_prev.' title='.$prev_message.'>'.$prev_img.' '.$prev_message.'</a>';
  101. } else {
  102. echo '<b><span class="invisible">'.$first_img.' '.$first_message.'</b></span>';
  103. echo '<b><span class="invisible">'.$prev_img.' '.$prev_message.'</b></span>';
  104. }
  105. // current counter
  106. echo ' [ '.($current_id+1).' / '.$max.' ] ';
  107. // go to: next and last
  108. if (($current_id+1) < $max) {
  109. echo '<a href="'.$next_href.'" '.$class_next.' title='.$next_message.'>'.$next_message.' '.$next_img.'</a>';
  110. echo '<a href="'.$last_href.'" '.$class.' title='.$last_message.'>'.$last_message.' '.$last_img.'</a>';
  111. } else {
  112. echo '<b><span class="invisible">'.$next_message.' '.$next_img.'</b></span>';
  113. echo '<b><span class="invisible">'.$last_message.' '.$last_img.'</b></span>';
  114. }
  115. echo '</center>';
  116. // the style depends on the status of the message: approved or not
  117. if ($rows[$display_post_id]['visible']=='0') {
  118. $titleclass='forum_message_post_title_2_be_approved';
  119. $messageclass='forum_message_post_text_2_be_approved';
  120. $leftclass='forum_message_left_2_be_approved';
  121. } else {
  122. $titleclass='forum_message_post_title';
  123. $messageclass='forum_message_post_text';
  124. $leftclass='forum_message_left';
  125. }
  126. // Displaying the message
  127. // we mark the image we are displaying as set
  128. unset($whatsnew_post_info[$current_forum['forum_id']][$current_thread['thread_id']][$rows[$display_post_id]['post_id']]);
  129. echo "<table width=\"100%\" class=\"forum_table\" cellspacing=\"5\" border=\"0\">";
  130. echo "<tr>";
  131. echo "<td rowspan=\"3\" class=\"$leftclass\">";
  132. $username = sprintf(get_lang('LoginX'), $rows[$display_post_id]['username']);
  133. if ($rows[$display_post_id]['user_id']=='0') {
  134. $name=prepare4display($rows[$display_post_id]['poster_name']);
  135. } else {
  136. $name=api_get_person_name($rows[$display_post_id]['firstname'], $rows[$display_post_id]['lastname']);
  137. }
  138. if (api_get_course_setting('allow_user_image_forum')) {echo '<br />'.display_user_image($rows[$display_post_id]['user_id'],$name, $origin).'<br />'; }
  139. echo display_user_link($rows[$display_post_id]['user_id'], $name, $origin, $username)."<br />";
  140. echo api_convert_and_format_date($rows[$display_post_id]['post_date']).'<br /><br />';
  141. // get attach id
  142. $attachment_list=get_attachment($display_post_id);
  143. $id_attach = !empty($attachment_list)?$attachment_list['id']:'';
  144. // The user who posted it can edit his thread only if the course admin allowed this in the properties of the forum
  145. // The course admin him/herself can do this off course always
  146. //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']))) {
  147. 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']))) {
  148. if ($locked == false) {
  149. echo "<a href=\"editpost.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;post=".$rows[$display_post_id]['post_id']."&amp;id_attach=".$id_attach."\">".Display::return_icon('edit.png',get_lang('Edit'), array(), ICON_SIZE_SMALL)."</a>";
  150. }
  151. }
  152. if (GroupManager::is_tutor_of_group(api_get_user_id(), $group_id) OR api_is_allowed_to_edit(false,true) && !(api_is_course_coach() && $current_forum['session_id']!=$_SESSION['id_session'])) {
  153. if ($locked == false) {
  154. echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&amp;gidReq=".Security::remove_XSS($_GET['gidReq'])."&amp;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>";
  155. }
  156. 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']) ));
  157. echo "";
  158. //verified the post minor
  159. $my_post=get_posts($_GET['thread']);
  160. $id_posts=array();
  161. foreach ($my_post as $post_value) {
  162. $id_posts[]=$post_value['post_id'];
  163. }
  164. sort($id_posts,SORT_NUMERIC);
  165. reset($id_posts);
  166. //the post minor
  167. $post_minor=(int)$id_posts[0];
  168. $post_id = isset($_GET['post'])?(int)$_GET['post']:0;
  169. if (!isset($_GET['id']) && $post_id>$post_minor) {
  170. 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>";
  171. }
  172. }
  173. $userinf=api_get_user_info($rows[$display_post_id]['user_id']);
  174. $user_status=api_get_status_of_user_in_course($rows[$display_post_id]['user_id'],api_get_course_int_id());
  175. if (api_is_allowed_to_edit(null,true)) {
  176. if ($post_id > $post_minor ) {
  177. //if ($user_status!=1) {
  178. $current_qualify_thread=show_qualify('1', $rows[$display_post_id]['user_id'],$_GET['thread']);
  179. if ($locked == false) {
  180. 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>";
  181. }
  182. //}
  183. }
  184. }
  185. 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)) {
  186. if ($_user['user_id'] OR ($current_forum['allow_anonymous']==1 AND !$_user['user_id'])) {
  187. if (!api_is_anonymous() && api_is_allowed_to_session_edit(false,true)) {
  188. 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>";
  189. 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>";
  190. }
  191. }
  192. } else {
  193. if ($current_forum_category && $current_forum_category['locked']==1) {
  194. echo get_lang('ForumcategoryLocked').'<br />';
  195. }
  196. if ($current_forum['locked']==1) {
  197. echo get_lang('ForumLocked').'<br />';
  198. }
  199. if ($current_thread['locked']==1) {
  200. echo get_lang('ThreadLocked').'<br />';
  201. }
  202. }
  203. echo "</td>";
  204. // note: this can be removed here because it will be displayed in the tree
  205. if (isset($whatsnew_post_info[$current_forum['forum_id']][$current_thread['thread_id']][$rows[$display_post_id]['post_id']]) and !empty($whatsnew_post_info[$current_forum['forum_id']][$current_thread['thread_id']][$rows[$display_post_id]['post_id']]) and !empty($whatsnew_post_info[$_GET['forum']][$rows[$display_post_id]['thread_id']])) {
  206. $post_image=Display::return_icon('forumpostnew.gif');
  207. } else {
  208. $post_image=Display::return_icon('forumpost.gif');
  209. }
  210. if ($rows[$display_post_id]['post_notification']=='1' AND $rows[$display_post_id]['poster_id']==$_user['user_id']) {
  211. $post_image.=Display::return_icon('forumnotification.gif',get_lang('YouWillBeNotified'));
  212. }
  213. // The post title
  214. echo "<td class=\"$titleclass\">".prepare4display($rows[$display_post_id]['post_title'])."</td>";
  215. echo "</tr>";
  216. // The post message
  217. echo "<tr>";
  218. echo "<td class=\"$messageclass\">".prepare4display($rows[$display_post_id]['post_text'])."</td>";
  219. echo "</tr>";
  220. // The check if there is an attachment
  221. $attachment_list = get_attachment($display_post_id);
  222. if (!empty($attachment_list)) {
  223. echo '<tr><td height="50%">';
  224. $realname=$attachment_list['path'];
  225. $user_filename=$attachment_list['filename'];
  226. echo Display::return_icon('attachment.gif',get_lang('Attachment'));
  227. echo '<a href="download.php?file=';
  228. echo $realname;
  229. echo ' "> '.$user_filename.' </a>';
  230. echo '<span class="forum_attach_comment" >'.Security::remove_XSS($attachment_list['comment'], STUDENT).'</span>';
  231. 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']))) {
  232. 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 />';
  233. }
  234. echo '</td></tr>';
  235. }
  236. // The post has been displayed => it can be removed from the what's new array
  237. if (isset($whatsnew_post_info[$current_forum['forum_id']][$current_thread['thread_id']][$row['post_id']])) {
  238. unset($whatsnew_post_info[$current_forum['forum_id']][$current_thread['thread_id']][$row['post_id']]);
  239. unset($_SESSION['whatsnew_post_info'][$current_forum['forum_id']][$current_thread['thread_id']][$row['post_id']]);
  240. }
  241. echo "</table>";
  242. // Displaying the thread (structure)
  243. echo $thread_structure;