viewthread_threaded.inc.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  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. * @Copyright Ghent University
  19. * @Copyright Patrick Cool
  20. *
  21. * @package dokeos.forum
  22. */
  23. /**
  24. **************************************************************************
  25. * IMPORTANT NOTICE
  26. * Please do not change anything is this code yet because there are still
  27. * some significant code that need to happen and I do not have the time to
  28. * merge files and test it all over again. So for the moment, please do not
  29. * touch the code
  30. * -- Patrick Cool <patrick.cool@UGent.be>
  31. **************************************************************************
  32. */
  33. require_once api_get_path(SYS_CODE_PATH).'forum/forumfunction.inc.php';
  34. $rows = get_posts($_GET['thread']); // note: this has to be cleaned first
  35. $rows = calculate_children($rows);
  36. if ($_GET['post']) {
  37. $display_post_id = intval($_GET['post']); // note: this has to be cleaned first
  38. } else {
  39. // we need to display the first post
  40. reset($rows);
  41. $current=current($rows);
  42. $display_post_id=$current['post_id'];
  43. }
  44. //are we in a lp ?
  45. $origin = '';
  46. if(isset($_GET['origin'])) {
  47. $origin = Security::remove_XSS($_GET['origin']);
  48. }
  49. //delete attachment file
  50. if ((isset($_GET['action']) && $_GET['action']=='delete_attach') && isset($_GET['id_attach'])) {
  51. delete_attachment(0,$_GET['id_attach']);
  52. }
  53. // --------------------------------------
  54. // Displaying the thread (structure)
  55. // --------------------------------------
  56. $thread_structure="<div class=\"structure\">".get_lang('Structure')."</div>";
  57. $counter=0;
  58. $count=0;
  59. $prev_next_array=array();
  60. foreach ($rows as $post) {
  61. $counter++;
  62. $indent=$post['indent_cnt']*'20';
  63. $thread_structure.= "<div style=\"margin-left: ".$indent."px;\">";
  64. 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']]))
  65. {
  66. $post_image=icon('../img/forumpostnew.gif');
  67. }
  68. else
  69. {
  70. $post_image=icon('../img/forumpost.gif');
  71. }
  72. $thread_structure.= $post_image;
  73. if ($_GET['post']==$post['post_id'] OR ($counter==1 AND !isset($_GET['post'])))
  74. {
  75. $thread_structure.='<strong>'.prepare4display(Security::remove_XSS($post['post_title'],STUDENT)).'</strong></div>';
  76. $prev_next_array[]=$post['post_id'];
  77. }
  78. else
  79. {
  80. if ($post['visible']=='0')
  81. {
  82. $class=' class="invisible"';
  83. }
  84. else
  85. {
  86. $class='';
  87. }
  88. $count_loop=($count==0)?'&id=1' : '';
  89. $thread_structure.= "<a href=\"viewthread.php?".api_get_cidreq()."&forum=".Security::remove_XSS($_GET['forum'])."&amp;thread=".Security::remove_XSS($_GET['thread'])."&amp;post=".$post['post_id']."&amp;origin=$origin$count_loop\" $class>".prepare4display(Security::remove_XSS($post['post_title'],STUDENT))."</a></div>\n";
  90. $prev_next_array[]=$post['post_id'];
  91. }
  92. $count++;
  93. }
  94. /*--------------------------------------------------
  95. NAVIGATION CONTROLS
  96. ----------------------------------------------------
  97. */
  98. $current_id=array_search($display_post_id,$prev_next_array);
  99. $max=count($prev_next_array);
  100. $next_id=$current_id+1;
  101. $prev_id=$current_id-1;
  102. // text
  103. $first_message=get_lang('FirstMessage');
  104. $last_message=get_lang('LastMessage');
  105. $next_message=get_lang('NextMessage');
  106. $prev_message=get_lang('PrevMessage');
  107. // images
  108. $first_img = Display::return_icon('first.png',get_lang('FirstMessage'),array('style'=>'vertical-align: middle;'));
  109. $last_img = Display::return_icon('last.png',get_lang('LastMessage'),array('style'=>'vertical-align: middle;'));
  110. $prev_img = Display::return_icon('prev.png',get_lang('PrevMessage'),array('style'=>'vertical-align: middle;'));
  111. $next_img = Display::return_icon('next.png',get_lang('NextMessage'),array('style'=>'vertical-align: middle;'));
  112. // links
  113. $first_href = 'viewthread.php?'.api_get_cidreq().'&amp;forum='.Security::remove_XSS($_GET['forum']).'&amp;thread='.Security::remove_XSS($_GET['thread']).'&amp;gradebook='.$gradebook.'&amp;origin='.$origin.'&amp;id=1&amp;post='.$prev_next_array[0];
  114. $last_href = 'viewthread.php?'.api_get_cidreq()."&amp;forum=".Security::remove_XSS($_GET['forum'])."&amp;thread=".Security::remove_XSS($_GET['thread'])."&amp;gradebook='.$gradebook.'&amp;origin=".$origin."&amp;post=".$prev_next_array[$max-1];
  115. $prev_href = 'viewthread.php?'.api_get_cidreq().'&amp;forum='.Security::remove_XSS($_GET['forum']).'&amp;thread='.Security::remove_XSS($_GET['thread']).'&amp;gradebook='.$gradebook.'&amp;origin='.$origin.'&amp;post='.$prev_next_array[$prev_id];
  116. $next_href = 'viewthread.php?'.api_get_cidreq().'&amp;forum='.Security::remove_XSS($_GET['forum']).'&amp;thread='.Security::remove_XSS($_GET['thread']).'&amp;gradebook='.$gradebook.'&amp;origin='.$origin.'&amp;post='.$prev_next_array[$next_id];
  117. echo '<center>';
  118. //go to: first and previous
  119. if ((int)$current_id > 0)
  120. {
  121. echo '<a href="'.$first_href.'" '.$class.' title='.$first_message.'>'.$first_img.' '.$first_message.'</a>';
  122. echo '<a href="'.$prev_href.'" '.$class_prev.' title='.$prev_message.'>'.$prev_img.' '.$prev_message.'</a>';
  123. }
  124. else
  125. {
  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. {
  134. echo '<a href="'.$next_href.'" '.$class_next.' title='.$next_message.'>'.$next_message.' '.$next_img.'</a>';
  135. echo '<a href="'.$last_href.'" '.$class.' title='.$last_message.'>'.$last_message.' '.$last_img.'</a>';
  136. }
  137. else
  138. {
  139. echo '<b><span class="invisible">'.$next_message.' '.$next_img.'</b></span>';
  140. echo '<b><span class="invisible">'.$last_message.' '.$last_img.'</b></span>';
  141. }
  142. echo '</center>';
  143. //--------------------------------------------------------------------------------------------
  144. // the style depends on the status of the message: approved or not
  145. if ($rows[$display_post_id]['visible']=='0') {
  146. $titleclass='forum_message_post_title_2_be_approved';
  147. $messageclass='forum_message_post_text_2_be_approved';
  148. $leftclass='forum_message_left_2_be_approved';
  149. }
  150. else
  151. {
  152. $titleclass='forum_message_post_title';
  153. $messageclass='forum_message_post_text';
  154. $leftclass='forum_message_left';
  155. }
  156. // --------------------------------------
  157. // Displaying the message
  158. // --------------------------------------
  159. // we mark the image we are displaying as set
  160. unset($whatsnew_post_info[$current_forum['forum_id']][$current_thread['thread_id']][$rows[$display_post_id]['post_id']]);
  161. echo "<table width=\"100%\" class=\"post\" cellspacing=\"5\" border=\"0\">\n";
  162. echo "\t<tr>\n";
  163. echo "\t\t<td rowspan=\"3\" class=\"$leftclass\">";
  164. if ($rows[$display_post_id]['user_id']=='0') {
  165. $name=prepare4display($rows[$display_post_id]['poster_name']);
  166. } else {
  167. $name=api_get_person_name($rows[$display_post_id]['firstname'], $rows[$display_post_id]['lastname']);
  168. }
  169. if (api_get_course_setting('allow_user_image_forum')) {echo '<br />'.display_user_image($rows[$display_post_id]['user_id'],$name, $origin).'<br />'; }
  170. echo display_user_link($rows[$display_post_id]['user_id'], $name, $origin).'<br />';
  171. echo api_convert_and_format_date($rows[$display_post_id]['post_date'], null, date_default_timezone_get()).'<br /><br />';
  172. // get attach id
  173. $attachment_list=get_attachment($display_post_id);
  174. $id_attach = !empty($attachment_list)?$attachment_list['id']:'';
  175. // The user who posted it can edit his thread only if the course admin allowed this in the properties of the forum
  176. // The course admin him/herself can do this off course always
  177. 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'])))
  178. {
  179. echo "<a href=\"editpost.php?".api_get_cidreq()."&forum=".Security::remove_XSS($_GET['forum'])."&amp;thread=".Security::remove_XSS($_GET['thread'])."&amp;origin=".$origin."&amp;post=".$rows[$display_post_id]['post_id']."&id_attach=".$id_attach."\">".icon('../img/edit.gif',get_lang('Edit'))."</a>\n";
  180. }
  181. if (api_is_allowed_to_edit(false,true) && !(api_is_course_coach() && $current_forum['session_id']!=$_SESSION['id_session']))
  182. {
  183. echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&forum=".Security::remove_XSS($_GET['forum'])."&amp;thread=".Security::remove_XSS($_GET['thread'])."&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>\n";
  184. display_visible_invisible_icon('post', $rows[$display_post_id]['post_id'], $rows[$display_post_id]['visible'],array('forum'=>Security::remove_XSS($_GET['forum']),'thread'=>Security::remove_XSS($_GET['thread']), 'post'=>Security::remove_XSS($_GET['post']) ));
  185. echo "\n";
  186. //verified the post minor
  187. $my_post=get_posts($_GET['thread']);
  188. $id_posts=array();
  189. foreach ($my_post as $post_value) {
  190. $id_posts[]=$post_value['post_id'];
  191. }
  192. sort($id_posts,SORT_NUMERIC);
  193. reset($id_posts);
  194. //the post minor
  195. $post_minor=(int)$id_posts[0];
  196. $post_id = isset($_GET['post'])?(int)$_GET['post']:0;
  197. if (!isset($_GET['id']) && $post_id>$post_minor) {
  198. echo "<a href=\"viewthread.php?".api_get_cidreq()."&forum=".Security::remove_XSS($_GET['forum'])."&amp;thread=".Security::remove_XSS($_GET['thread'])."&amp;origin=".$origin."&amp;action=move&amp;post=".$rows[$display_post_id]['post_id']."\">".icon('../img/deplacer_fichier.gif',get_lang('MovePost'))."</a>\n";
  199. }
  200. }
  201. $userinf=api_get_user_info($rows[$display_post_id]['user_id']);
  202. $user_status=api_get_status_of_user_in_course($rows[$display_post_id]['user_id'],api_get_course_id());
  203. if (api_is_allowed_to_edit(null,true)) {
  204. if($post_id>$post_minor )
  205. {
  206. if($user_status!=1)
  207. {
  208. $current_qualify_thread=show_qualify('1',$_GET['cidReq'],$_GET['forum'],$rows[$display_post_id]['user_id'],$_GET['thread']);
  209. echo "<a href=\"forumqualify.php?".api_get_cidreq()."&forum=".Security::remove_XSS($_GET['forum'])."&amp;thread=".Security::remove_XSS($_GET['thread'])."&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>\n";
  210. }
  211. }
  212. }
  213. //echo '<br /><br />';
  214. //if (($current_forum_category['locked']==0 AND $current_forum['locked']==0 AND $current_thread['locked']==0) OR api_is_allowed_to_edit())
  215. if ($current_forum_category['locked']==0 AND $current_forum['locked']==0 AND $current_thread['locked']==0 OR api_is_allowed_to_edit(false,true))
  216. {
  217. if ($_user['user_id'] OR ($current_forum['allow_anonymous']==1 AND !$_user['user_id']))
  218. {
  219. if (!api_is_anonymous() && api_is_allowed_to_session_edit(false,true)) {
  220. echo '<a href="reply.php?'.api_get_cidreq().'&forum='.Security::remove_XSS($_GET['forum']).'&amp;thread='.Security::remove_XSS($_GET['thread']).'&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>\n";
  221. echo '<a href="reply.php?'.api_get_cidreq().'&forum='.Security::remove_XSS($_GET['forum']).'&amp;thread='.Security::remove_XSS($_GET['thread']).'&amp;post='.$rows[$display_post_id]['post_id'].'&amp;action=quote&amp;origin='. $origin .'">'.Display :: return_icon('quote.gif', get_lang('QuoteMessage'))."</a>\n";
  222. }
  223. }
  224. }
  225. else
  226. {
  227. if ($current_forum_category['locked']==1)
  228. {
  229. echo get_lang('ForumcategoryLocked').'<br />';
  230. }
  231. if ($current_forum['locked']==1)
  232. {
  233. echo get_lang('ForumLocked').'<br />';
  234. }
  235. if ($current_thread['locked']==1)
  236. {
  237. echo get_lang('ThreadLocked').'<br />';
  238. }
  239. }
  240. echo "</td>\n";
  241. // note: this can be removed here because it will be displayed in the tree
  242. 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']]))
  243. {
  244. $post_image=icon('../img/forumpostnew.gif');
  245. }
  246. else
  247. {
  248. $post_image=icon('../img/forumpost.gif');
  249. }
  250. if ($rows[$display_post_id]['post_notification']=='1' AND $rows[$display_post_id]['poster_id']==$_user['user_id'])
  251. {
  252. $post_image.=icon('../img/forumnotification.gif',get_lang('YouWillBeNotified'));
  253. }
  254. // The post title
  255. echo "\t\t<td class=\"$titleclass\">".prepare4display(Security::remove_XSS($rows[$display_post_id]['post_title'], STUDENT))."</td>\n";
  256. echo "\t</tr>\n";
  257. // The post message
  258. echo "\t<tr>\n";
  259. echo "\t\t<td class=\"$messageclass\">".prepare4display(Security::remove_XSS($rows[$display_post_id]['post_text'], STUDENT))."</td>\n";
  260. echo "\t</tr>\n";
  261. // The check if there is an attachment
  262. $attachment_list = get_attachment($display_post_id);
  263. if (!empty($attachment_list)) {
  264. echo '<tr><td height="50%">';
  265. $realname=$attachment_list['path'];
  266. $user_filename=$attachment_list['filename'];
  267. echo Display::return_icon('attachment.gif',get_lang('Attachment'));
  268. echo '<a href="download.php?file=';
  269. echo $realname;
  270. echo ' "> '.$user_filename.' </a>';
  271. echo '<span class="forum_attach_comment" >'.Security::remove_XSS($attachment_list['comment'], STUDENT).'</span>';
  272. 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']))) {
  273. 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='.Security::remove_XSS($_GET['forum']).'&amp;thread='.Security::remove_XSS($_GET['thread']).'" 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 />';
  274. }
  275. echo '</td></tr>';
  276. }
  277. // The post has been displayed => it can be removed from the what's new array
  278. unset($whatsnew_post_info[$current_forum['forum_id']][$current_thread['thread_id']][$row['post_id']]);
  279. unset($_SESSION['whatsnew_post_info'][$current_forum['forum_id']][$current_thread['thread_id']][$row['post_id']]);
  280. echo "</table>";
  281. // --------------------------------------
  282. // Displaying the thread (structure)
  283. // --------------------------------------
  284. echo $thread_structure;