viewthread_flat.inc.php 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <?php
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2008 Dokeos SPRL
  6. Copyright (c) 2006 Ghent University (UGent)
  7. For a full list of contributors, see "credits.txt".
  8. The full license can be read in "license.txt".
  9. This program is free software; you can redistribute it and/or
  10. modify it under the terms of the GNU General Public License
  11. as published by the Free Software Foundation; either version 2
  12. of the License, or (at your option) any later version.
  13. See the GNU General Public License for more details.
  14. Contact address: Dokeos, rue du Corbeau, 108, B-1030 Brussels, Belgium
  15. Mail: info@dokeos.com
  16. ==============================================================================
  17. */
  18. /**
  19. * @package dokeos.forum
  20. */
  21. //delete attachment file
  22. if ((isset($_GET['action']) && $_GET['action']=='delete_attach') && isset($_GET['id_attach'])) {
  23. delete_attachment(0,$_GET['id_attach']);
  24. }
  25. if (isset($current_thread['thread_id'])){
  26. $rows=get_posts($current_thread['thread_id']);
  27. $increment=0;
  28. foreach ($rows as $row) {
  29. echo "<table width=\"100%\" class=\"post\" cellspacing=\"5\" border=\"0\">\n";
  30. // the style depends on the status of the message: approved or not
  31. if ($row['visible']=='0') {
  32. $titleclass='forum_message_post_title_2_be_approved';
  33. $messageclass='forum_message_post_text_2_be_approved';
  34. $leftclass='forum_message_left_2_be_approved';
  35. } else {
  36. $titleclass='forum_message_post_title';
  37. $messageclass='forum_message_post_text';
  38. $leftclass='forum_message_left';
  39. }
  40. echo "\t<tr>\n";
  41. echo "\t\t<td rowspan=\"3\" class=\"$leftclass\">";
  42. if ($row['user_id']=='0') {
  43. $name=prepare4display($row['poster_name']);
  44. } else {
  45. $name=api_get_person_name($row['firstname'], $row['lastname']);
  46. }
  47. if($origin!='learnpath') {
  48. if (api_get_course_setting('allow_user_image_forum')) {
  49. echo '<br />'.display_user_image($row['user_id'],$name).'<br />';
  50. }
  51. echo display_user_link($row['user_id'], $name).'<br />';
  52. } else {
  53. echo $name. '<br />';
  54. }
  55. echo $row['post_date'].'<br /><br />';
  56. // get attach id
  57. $attachment_list=get_attachment($row['post_id']);
  58. $id_attach = !empty($attachment_list)?$attachment_list['id']:'';
  59. // The user who posted it can edit his thread only if the course admin allowed this in the properties of the forum
  60. // The course admin him/herself can do this off course always
  61. if (($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']))) {
  62. if (api_is_allowed_to_session_edit(false,true))
  63. echo "<a href=\"editpost.php?".api_get_cidreq()."&forum=".Security::remove_XSS($_GET['forum'])."&amp;thread=".Security::remove_XSS($_GET['thread'])."&amp;post=".$row['post_id']."&origin=".$origin."&edit=edition&id_attach=".$id_attach."\">".icon('../img/edit.gif',get_lang('Edit'))."</a>\n";
  64. }
  65. if ($origin != 'learnpath') {
  66. if (api_is_allowed_to_edit(false,true) && !(api_is_course_coach() && $current_forum['session_id']!=$_SESSION['id_session'])) {
  67. 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=".$row['post_id']."&origin=".$origin."\" onclick=\"javascript:if(!confirm('".addslashes(api_htmlentities(get_lang("DeletePost"),ENT_QUOTES,$charset))."')) return false;\">".icon('../img/delete.gif',get_lang('Delete'))."</a>\n";
  68. display_visible_invisible_icon('post', $row['post_id'], $row['visible'],array('forum'=>Security::remove_XSS($_GET['forum']),'thread'=>Security::remove_XSS($_GET['thread']), 'origin'=>$origin ));
  69. echo "\n";
  70. if ($increment>0) {
  71. echo "<a href=\"viewthread.php?".api_get_cidreq()."&forum=".Security::remove_XSS($_GET['forum'])."&amp;thread=".Security::remove_XSS($_GET['thread'])."&amp;action=move&amp;post=".$row['post_id']."&origin=".$origin."\">".icon('../img/deplacer_fichier.gif',get_lang('MovePost'))."</a>\n";
  72. }
  73. }
  74. }
  75. $userinf=api_get_user_info($row['user_id']);
  76. $user_status=api_get_status_of_user_in_course($row['user_id'],api_get_course_id());
  77. $current_qualify_thread=show_qualify('1',$_GET['cidReq'],$_GET['forum'],$row['poster_id'],$_GET['thread']);
  78. if (api_is_allowed_to_edit(null,true) && $origin != 'learnpath') {
  79. if( isset($_GET['gradebook'])){
  80. if ($increment>0 && $user_status!=1 ) {
  81. $info_thread=get_thread_information(Security::remove_XSS($_GET['thread']));
  82. echo "<a href=\"forumqualify.php?".api_get_cidreq()."&forum=".$info_thread['forum_id']."&amp;thread=".Security::remove_XSS($_GET['thread'])."&amp;action=list&amp;post=".$row['post_id']."&amp;user=".$row['poster_id']."&user_id=".$row['poster_id']."&origin=".$origin."&idtextqualify=".$current_qualify_thread."&gradebook=".Security::remove_XSS($_GET['gradebook'])."\" >".icon('../img/new_test_small.gif',get_lang('Qualify'))."</a>\n";
  83. }
  84. } else {
  85. if ($increment>0 && $user_status!=1 ) {
  86. 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=".$row['post_id']."&amp;user=".$row['poster_id']."&user_id=".$row['poster_id']."&origin=".$origin."&idtextqualify=".$current_qualify_thread."\" >".icon('../img/new_test_small.gif',get_lang('Qualify'))."</a>\n";
  87. }
  88. }
  89. }
  90. //echo '<br /><br />';
  91. if ($current_forum_category['locked']==0 AND $current_forum['locked']==0 AND $current_thread['locked']==0 OR api_is_allowed_to_edit(false,true)) {
  92. if ($_user['user_id'] OR ($current_forum['allow_anonymous']==1 AND !$_user['user_id'])) {
  93. if (!api_is_anonymous() && api_is_allowed_to_session_edit(false,true)) {
  94. echo '<a href="reply.php?'.api_get_cidreq().'&forum='.Security::remove_XSS($_GET['forum']).'&amp;thread='.Security::remove_XSS($_GET['thread']).'&amp;post='.$row['post_id'].'&amp;action=replymessage&origin='.$origin.'">'.Display :: return_icon('message_reply_forum.png', get_lang('ReplyToMessage'))."</a>\n";
  95. echo '<a href="reply.php?'.api_get_cidreq().'&forum='.Security::remove_XSS($_GET['forum']).'&amp;thread='.Security::remove_XSS($_GET['thread']).'&amp;post='.$row['post_id'].'&amp;action=quote&origin='.$origin.'">'.Display :: return_icon('quote.gif', get_lang('QuoteMessage'))."</a>\n";
  96. }
  97. }
  98. } else {
  99. if ($current_forum_category['locked']==1) {
  100. echo get_lang('ForumcategoryLocked').'<br />';
  101. }
  102. if ($current_forum['locked']==1) {
  103. echo get_lang('ForumLocked').'<br />';
  104. }
  105. if ($current_thread['locked']==1) {
  106. echo get_lang('ThreadLocked').'<br />';
  107. }
  108. }
  109. echo "</td>\n";
  110. // show the
  111. if (isset($whatsnew_post_info[$current_forum['forum_id']][$current_thread['thread_id']][$row['post_id']]) and !empty($whatsnew_post_info[$current_forum['forum_id']][$current_thread['thread_id']][$row['post_id']]) and !empty($whatsnew_post_info[$_GET['forum']][$row['thread_id']])) {
  112. $post_image=icon('../img/forumpostnew.gif');
  113. } else {
  114. $post_image=icon('../img/forumpost.gif');
  115. }
  116. if ($row['post_notification']=='1' AND $row['poster_id']==$_user['user_id']) {
  117. $post_image.=icon('../img/forumnotification.gif',get_lang('YouWillBeNotified'));
  118. }
  119. // The post title
  120. echo "\t\t<td class=\"$titleclass\">".prepare4display($row['post_title'])."</td>\n";
  121. echo "\t</tr>\n";
  122. // The post message
  123. //var_dump($messageclass);
  124. $row['post_text']= Security::remove_XSS($row['post_text']);
  125. echo "\t<tr>\n";
  126. echo "\t\t<td class=\"$messageclass\">".prepare4display($row['post_text'])."</td>\n";
  127. echo "\t</tr>\n";
  128. // The check if there is an attachment
  129. $attachment_list=get_attachment($row['post_id']);
  130. if (!empty($attachment_list)) {
  131. echo '<tr><td height="50%">';
  132. $realname=$attachment_list['path'];
  133. $user_filename=$attachment_list['filename'];
  134. echo Display::return_icon('attachment.gif',get_lang('Attachment'));
  135. echo '<a href="download.php?file=';
  136. echo $realname;
  137. echo ' "> '.$user_filename.' </a>';
  138. echo '<span class="forum_attach_comment" >'.$attachment_list['comment'].'</span>';
  139. if (($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']))) {
  140. 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 />';
  141. }
  142. echo '</td></tr>';
  143. }
  144. // The post has been displayed => it can be removed from the what's new array
  145. unset($whatsnew_post_info[$current_forum['forum_id']][$current_thread['thread_id']][$row['post_id']]);
  146. unset($whatsnew_post_info[$current_forum['forum_id']][$current_thread['thread_id']]);
  147. unset($_SESSION['whatsnew_post_info'][$current_forum['forum_id']][$current_thread['thread_id']][$row['post_id']]);
  148. unset($_SESSION['whatsnew_post_info'][$current_forum['forum_id']][$current_thread['thread_id']]);
  149. echo "</table>";
  150. $increment++;
  151. }
  152. }