viewforum.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. <?php
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2006 Dokeos S.A.
  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, 44 rue des palais, B-1030 Brussels, Belgium
  15. Mail: info@dokeos.com
  16. ==============================================================================
  17. */
  18. /**
  19. * These files are a complete rework of the forum. The database structure is
  20. * based on phpBB but all the code is rewritten. A lot of new functionalities
  21. * are added:
  22. * - forum categories and forums can be sorted up or down, locked or made invisible
  23. * - consistent and integrated forum administration
  24. * - forum options: are students allowed to edit their post?
  25. * moderation of posts (approval)
  26. * reply only forums (students cannot create new threads)
  27. * multiple forums per group
  28. * - sticky messages
  29. * - new view option: nested view
  30. * - quoting a message
  31. *
  32. * @Author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  33. * @Copyright Ghent University
  34. * @Copyright Patrick Cool
  35. *
  36. * @package dokeos.forum
  37. */
  38. /**
  39. **************************************************************************
  40. * IMPORTANT NOTICE
  41. * Please do not change anything is this code yet because there are still
  42. * some significant code that need to happen and I do not have the time to
  43. * merge files and test it all over again. So for the moment, please do not
  44. * touch the code
  45. * -- Patrick Cool <patrick.cool@UGent.be>
  46. **************************************************************************
  47. */
  48. /*
  49. ==============================================================================
  50. INIT SECTION
  51. ==============================================================================
  52. */
  53. /*
  54. -----------------------------------------------------------
  55. Language Initialisation
  56. -----------------------------------------------------------
  57. */
  58. $langFile = 'forum';
  59. require ('../inc/global.inc.php');
  60. require_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
  61. include_once (api_get_path(LIBRARY_PATH).'groupmanager.lib.php');
  62. $nameTools=get_lang('Forum');
  63. /*
  64. -----------------------------------------------------------
  65. Including necessary files
  66. -----------------------------------------------------------
  67. */
  68. include('forumconfig.inc.php');
  69. include('forumfunction.inc.php');
  70. /*
  71. ==============================================================================
  72. MAIN DISPLAY SECTION
  73. ==============================================================================
  74. */
  75. /*
  76. -----------------------------------------------------------
  77. Retrieving forum and forum categorie information
  78. -----------------------------------------------------------
  79. */
  80. // we are getting all the information about the current forum and forum category.
  81. // note pcool: I tried to use only one sql statement (and function) for this
  82. // but the problem is that the visibility of the forum AND forum cateogory are stored in the item_property table
  83. $current_forum=get_forum_information($_GET['forum']); // note: this has to be validated that it is an existing forum.
  84. $current_forum_category=get_forumcategory_information($current_forum['forum_category']);
  85. /*
  86. -----------------------------------------------------------
  87. Header and Breadcrumbs
  88. -----------------------------------------------------------
  89. */
  90. $interbreadcrumb[]=array("url" => "index.php","name" => $nameTools);
  91. $interbreadcrumb[]=array("url" => "viewforumcategory.php?forumcategory=".$current_forum_category['cat_id'],"name" => prepare4display($current_forum_category['cat_title']));
  92. $interbreadcrumb[]=array("url" => "viewforum.php?forum=".$_GET['forum'],"name" => prepare4display($current_forum['forum_title']));
  93. Display :: display_header();
  94. api_display_tool_title($nameTools);
  95. //echo '<link href="forumstyles.css" rel="stylesheet" type="text/css" />';
  96. /*
  97. -----------------------------------------------------------
  98. Actions
  99. -----------------------------------------------------------
  100. */
  101. // Change visibility of a forum or a forum category
  102. if (($_GET['action']=='invisible' OR $_GET['action']=='visible') AND isset($_GET['content']) AND isset($_GET['id']) AND api_is_allowed_to_edit())
  103. {
  104. $message=change_visibility($_GET['content'], $_GET['id'],$_GET['action']);// note: this has to be cleaned first
  105. }
  106. if (($_GET['action']=='lock' OR $_GET['action']=='unlock') AND isset($_GET['content']) AND isset($_GET['id']) AND api_is_allowed_to_edit())
  107. {
  108. $message=change_lock_status($_GET['content'], $_GET['id'],$_GET['action']);// note: this has to be cleaned first
  109. }
  110. if ($_GET['action']=='delete' AND isset($_GET['content']) AND isset($_GET['id']) AND api_is_allowed_to_edit())
  111. {
  112. $message=delete_forum_forumcategory_thread($_GET['content'],$_GET['id']); // note: this has to be cleaned first
  113. }
  114. if ($_GET['action']=='move' and isset($_GET['thread']))
  115. {
  116. $message=move_thread_form();
  117. }
  118. /*
  119. -----------------------------------------------------------
  120. Is the user allowed here?
  121. -----------------------------------------------------------
  122. */
  123. // if the user is not a course administrator and the forum is hidden
  124. // then the user is not allowed here.
  125. if (!api_is_allowed_to_edit() AND ($current_forum_category['visibility']==0 OR $current_forum['visibility']==0))
  126. {
  127. forum_not_allowed_here();
  128. }
  129. /*
  130. -----------------------------------------------------------
  131. Display the action messages
  132. -----------------------------------------------------------
  133. */
  134. if (isset($message))
  135. {
  136. Display :: display_normal_message($message);
  137. }
  138. /*
  139. -----------------------------------------------------------
  140. Action Links
  141. -----------------------------------------------------------
  142. */
  143. // The link should appear when
  144. // 1. the course admin is here
  145. // 2. the course member is here and new threads are allowed
  146. // 3. a visitor is here and new threads AND allowed AND anonymous posts are allowed
  147. if (api_is_allowed_to_edit() OR ($current_forum['allow_new_threads']==1 AND isset($_uid)) OR ($current_forum['allow_new_threads']==1 AND !isset($_uid) AND $current_forum['allow_anonymous']==1))
  148. {
  149. echo '<a href="newthread.php?forum='.$_GET['forum'].'">'.get_lang('NewTopic').'</a>';
  150. }
  151. /*
  152. -----------------------------------------------------------
  153. Display
  154. -----------------------------------------------------------
  155. */
  156. echo "<table width='100%'>\n";
  157. // the forum category
  158. echo "\t<tr class=\"forum_category\">\n\t\t<td colspan=\"7\">";
  159. echo '<a href="index.php" '.class_visible_invisible($current_forum_category['visibility']).'>'.prepare4display($current_forum_category['cat_title']).'</a><br />';
  160. echo '<span>'.prepare4display($current_forum_category['cat_comment']).'</span>';
  161. echo "</td>\n";
  162. echo "\t</tr>\n";
  163. // the forum
  164. echo "\t<tr class=\"forum_header\">\n";
  165. echo "\t\t<td colspan=\"7\">".prepare4display($current_forum['forum_title'])."<br />";
  166. echo '<span>'.prepare4display($current_forum['forum_comment']).'</span>';
  167. echo "</td>\n";
  168. echo "\t</tr>\n";
  169. // The column headers (to do: make this sortable)
  170. echo "\t<tr class=\"forum_threadheader\">\n";
  171. echo "\t\t<td></td>\n";
  172. echo "\t\t<td>".get_lang('Title')."</td>\n";
  173. echo "\t\t<td>".get_lang('Replies')."</td>\n";
  174. echo "\t\t<td>".get_lang('Author')."</td>\n";
  175. echo "\t\t<td>".get_lang('Views')."</td>\n";
  176. echo "\t\t<td>".get_lang('LastPost')."</td>\n";
  177. if (api_is_allowed_to_edit())
  178. {
  179. echo "\t\t<td>".get_lang('Actions')."</td>\n";
  180. }
  181. echo "\t</tr>\n";
  182. // getting al the threads
  183. $threads=get_threads($_GET['forum']); // note: this has to be cleaned first
  184. $whatsnew_post_info=$_SESSION['whatsnew_post_info'];
  185. foreach ($threads as $row)
  186. {
  187. // thread who have no replies yet and the only post is invisible should not be displayed to students.
  188. if (api_is_allowed_to_edit() OR !($row['thread_replies']=='0' AND $row['visible']=='0'))
  189. {
  190. echo "\t<tr>\n";
  191. echo "\t\t<td>";
  192. if (is_array($whatsnew_post_info[$_GET['forum']][$row['thread_id']]) and !empty($whatsnew_post_info[$_GET['forum']][$row['thread_id']]))
  193. {
  194. echo icon('../img/forumthreadnew.gif');
  195. }
  196. else
  197. {
  198. echo icon('../img/forumthread.gif');
  199. }
  200. if ($row['thread_sticky']==1)
  201. {
  202. echo icon('../img/exclamation.gif');
  203. }
  204. echo "</td>\n";
  205. echo "\t\t<td><a href=\"viewthread.php?forum=".$_GET['forum']."&amp;thread=".$row['thread_id']."\" ".class_visible_invisible($row['visibility']).">".prepare4display($row['thread_title'])."</a></td>\n";
  206. echo "\t\t<td>".$row['thread_replies']."</td>\n";
  207. if ($row['user_id']=='0')
  208. {
  209. $name=prepare4display($row['thread_poster_name']);
  210. }
  211. else
  212. {
  213. $name=$row['firstname'].' '.$row['lastname'];
  214. }
  215. echo "\t\t<td>".display_user_link($row['user_id'], $name)."</td>\n";
  216. echo "\t\t<td>".$row['thread_views']."</td>\n";
  217. if ($row['last_poster_user_id']=='0')
  218. {
  219. $name=$row['poster_name'];
  220. }
  221. else
  222. {
  223. $name=$row['last_poster_firstname'].' '.$row['last_poster_lastname'];
  224. }
  225. // if the last post is invisible and it is not the teacher who is looking then we have to find the last visible post of the thread
  226. if ($row['visible']=='1' OR api_is_allowed_to_edit())
  227. {
  228. $last_post=$row['thread_date']." ".get_lang('By').' '.display_user_link($row['last_poster_user_id'], $name);
  229. }
  230. else
  231. {
  232. $last_post_sql="SELECT post.*, user.firstname, user.lastname FROM $table_posts post, $table_users user WHERE post.poster_id=user.user_id AND visible='1' AND thread_id='".$row['thread_id']."' ORDER BY post_id DESC";
  233. $last_post_result=api_sql_query($last_post_sql, __LINE__, __FILE__);
  234. $last_post_row=mysql_fetch_array($last_post_result);
  235. $name=$last_post_row['firstname'].' '.$last_post_row['lastname'];
  236. $last_post=$last_post_row['post_date']." ".get_lang('By').' '.display_user_link($last_post_row['poster_id'], $name);
  237. }
  238. echo "\t\t<td>".$last_post."</td>\n";
  239. if (api_is_allowed_to_edit())
  240. {
  241. echo "\t\t<td>";
  242. echo "<a href=\"".$_SERVER['PHP_SELF']."?forum=".$_GET['forum']."&amp;action=delete&amp;content=thread&amp;id=".$row['thread_id']."\" onclick=\"javascript:if(!confirm('".addslashes(htmlentities(get_lang("DeleteCompleteThread")))."')) return false;\">".icon('../img/delete.gif',get_lang('Delete'))."</a>";
  243. display_visible_invisible_icon('thread', $row['thread_id'], $row['visibility'], array("forum"=>$_GET['forum']));
  244. display_lock_unlock_icon('thread',$row['thread_id'], $row['locked'], array("forum"=>$_GET['forum']));
  245. echo "<a href=\"viewforum.php?forum=".$_GET['forum']."&amp;action=move&amp;thread=".$row['thread_id']."\">".icon('../img/forummovepost.gif',get_lang('Edit'))."</a>";
  246. echo "</td>\n";
  247. }
  248. echo "\t</tr>\n";
  249. }
  250. }
  251. echo "</table>";
  252. /*
  253. ==============================================================================
  254. FOOTER
  255. ==============================================================================
  256. */
  257. Display :: display_footer();
  258. ?>