viewthread_threaded.inc.php 14 KB

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