viewforumcategory.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  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('sanity.inc.php');
  70. include('forumfunction.inc.php');
  71. /*
  72. ==============================================================================
  73. MAIN DISPLAY SECTION
  74. ==============================================================================
  75. */
  76. /*
  77. -----------------------------------------------------------
  78. Header and Breadcrumbs
  79. -----------------------------------------------------------
  80. */
  81. $current_forum_category=get_forum_categories($_GET['forumcategory']);
  82. $interbreadcrumb[]=array("url" => "index.php","name" => $nameTools);
  83. $interbreadcrumb[]=array("url" => "viewforumcategory.php?forumcategory=".$current_forum_category['cat_id'],"name" => prepare4display($current_forum_category['cat_title']));
  84. Display :: display_header();
  85. api_display_tool_title($nameTools);
  86. /*
  87. ------------------------------------------------------------------------------------------------------
  88. ACTIONS
  89. ------------------------------------------------------------------------------------------------------
  90. */
  91. $whatsnew_post_info=$_SESSION['whatsnew_post_info'];
  92. /*
  93. -----------------------------------------------------------
  94. Is the user allowed here?
  95. -----------------------------------------------------------
  96. */
  97. // if the user is not a course administrator and the forum is hidden
  98. // then the user is not allowed here.
  99. if (!api_is_allowed_to_edit() AND $current_forum_category['visibility']==0)
  100. {
  101. forum_not_allowed_here();
  102. }
  103. /*
  104. ------------------------------------------------------------------------------------------------------
  105. ACTIONS
  106. ------------------------------------------------------------------------------------------------------
  107. */
  108. if (api_is_allowed_to_edit())
  109. {
  110. handle_forum_and_forumcategories();
  111. }
  112. /*
  113. ------------------------------------------------------------------------------------------------------
  114. RETRIEVING ALL THE FORUM CATEGORIES AND FORUMS
  115. ------------------------------------------------------------------------------------------------------
  116. note: we do this here just after het handling of the actions to be sure that we already incorporate the
  117. latest changes
  118. */
  119. // Step 1: We store all the forum categories in an array $forum_categories
  120. $forum_categories=array();
  121. $forum_category=get_forum_categories($_GET['forumcategory']);
  122. // step 2: we find all the forums
  123. $forum_list=array();
  124. $forum_list=get_forums();
  125. /*
  126. ------------------------------------------------------------------------------------------------------
  127. RETRIEVING ALL GROUPS OF THE USER
  128. ------------------------------------------------------------------------------------------------------
  129. */
  130. $groups_of_user=array();
  131. $groups_of_user=GroupManager::get_group_ids($_course['dbName'], $_uid);
  132. //my_print_r($groups_of_user);
  133. /*
  134. -----------------------------------------------------------
  135. Action Links
  136. -----------------------------------------------------------
  137. */
  138. if (api_is_allowed_to_edit())
  139. {
  140. //echo '<a href="'.$_SERVER['PHP_SELF'].'?forumcategory='.$_GET['forumcategory'].'&amp;action=add&amp;content=forumcategory">'.get_lang('AddForumCategory').'</a> | ';
  141. echo '<a href="'.$_SERVER['PHP_SELF'].'?forumcategory='.$_GET['forumcategory'].'&amp;action=add&amp;content=forum">'.get_lang('AddForum').'</a>';
  142. }
  143. /*
  144. -----------------------------------------------------------
  145. Display Forum Categories and the Forums in it
  146. -----------------------------------------------------------
  147. */
  148. echo "<table width='100%'>\n";
  149. echo "\t<tr class=\"forum_category\">\n\t\t<td colspan=\"5\">";
  150. echo '<a href="#" '.class_visible_invisible($forum_category['visibility']).'>'.prepare4display($forum_category['cat_title']).'</a><br />';
  151. echo '<span>'.prepare4display($forum_category['cat_comment']).'</span>';
  152. echo "</td>\n";
  153. if (api_is_allowed_to_edit())
  154. {
  155. echo "\t\t<td>";
  156. echo "<a href=\"".$_SERVER['PHP_SELF']."?forumcategory=".$_GET['forumcategory']."&amp;action=edit&amp;content=forumcategory&amp;id=".$forum_category['cat_id']."\">".icon('../img/edit.gif',get_lang('Edit'))."</a>";
  157. echo "<a href=\"".$_SERVER['PHP_SELF']."?forumcategory=".$_GET['forumcategory']."&amp;action=delete&amp;content=forumcategory&amp;amp;id=".$forum_category['cat_id']."\" onclick=\"javascript:if(!confirm('".addslashes(htmlentities(get_lang("DeleteForumCategory")))."')) return false;\">".icon('../img/delete.gif',get_lang('Delete'))."</a>";
  158. display_visible_invisible_icon('forumcategory', $forum_category['cat_id'], $forum_category['visibility'], array("forumcategory"=>$_GET['forumcategory']));
  159. display_lock_unlock_icon('forumcategory',$forum_category['cat_id'], $forum_category['locked'], array("forumcategory"=>$_GET['forumcategory']));
  160. display_up_down_icon('forumcategory',$forum_category['cat_id'], $forum_categories_list);
  161. echo "</td>\n";
  162. }
  163. echo "\t</tr>\n";
  164. // step 3: the interim headers (for the forum)
  165. echo "\t<tr class=\"forum_header\">\n";
  166. echo "\t\t<td colspan='2'>".get_lang('Forum')."</td>\n";
  167. echo "\t\t<td>".get_lang('Topics')."</td>\n";
  168. echo "\t\t<td>".get_lang('Posts')."</td>\n";
  169. echo "\t\t<td>".get_lang('LastPosts')."</td>\n";
  170. if (api_is_allowed_to_edit())
  171. {
  172. echo "\t\t<td>".get_lang('Actions')."</td>\n";
  173. }
  174. echo "\t</tr>\n";
  175. // the forums in this category
  176. $forums_in_category=get_forums_in_category($forum_category['cat_id']);
  177. // step 4: we display all the forums in this category.
  178. $forum_count=0;
  179. foreach ($forum_list as $key=>$forum)
  180. {
  181. if ($forum['forum_category']==$forum_category['cat_id'])
  182. {
  183. // the forum has to be showed if
  184. // 1.v it is a not a group forum (teacher and student)
  185. // 2.v it is a group forum and it is public (teacher and student)
  186. // 3. it is a group forum and it is private (always for teachers only if the user is member of the forum
  187. // if the forum is private and it is a group forum and the user is not a member of the group forum then it cannot be displayed
  188. //if (!($forum['forum_group_public_private']=='private' AND !is_null($forum['forum_of_group']) AND !in_array($forum['forum_of_group'], $groups_of_user)))
  189. //{
  190. $show_forum=false;
  191. // SHOULD WE SHOW THIS PARTICULAR FORUM
  192. // you are teacher => show forum
  193. if (api_is_allowed_to_edit())
  194. {
  195. //echo 'teacher';
  196. $show_forum=true;
  197. }
  198. // you are not a teacher
  199. else
  200. {
  201. //echo 'student';
  202. // it is not a group forum => show forum (invisible forums are already left out see get_forums function)
  203. if ($forum['forum_of_group']=='0')
  204. {
  205. //echo '-gewoon forum';
  206. $show_forum=true;
  207. }
  208. // it is a group forum
  209. else
  210. {
  211. //echo '-groepsforum';
  212. // it is a group forum but it is public => show
  213. if ($forum['forum_group_public_private']=='public')
  214. {
  215. $show_forum=true;
  216. //echo '-publiek';
  217. }
  218. // it is a group forum and it is private
  219. else
  220. {
  221. //echo '-prive';
  222. // it is a group forum and it is private but the user is member of the group
  223. if (in_array($forum['forum_of_group'],$groups_of_user))
  224. {
  225. //echo '-is lid';
  226. $show_forum=true;
  227. }
  228. else
  229. {
  230. //echo '-is GEEN lid';
  231. $show_forum=false;
  232. }
  233. }
  234. }
  235. }
  236. //echo '<hr>';
  237. if ($show_forum)
  238. {
  239. $form_count++;
  240. echo "\t<tr class=\"forum\">\n";
  241. echo "\t\t<td width=\"20\">";
  242. if ($forum['forum_of_group']!=='0')
  243. {
  244. if (is_array($whatsnew_post_info[$forum['forum_id']]) and !empty($whatsnew_post_info[$forum['forum_id']]))
  245. {
  246. echo icon('../img/forumgroupnew.gif');
  247. }
  248. else
  249. {
  250. echo icon('../img/forumgroup.gif');
  251. }
  252. }
  253. else
  254. {
  255. if (is_array($whatsnew_post_info[$forum['forum_id']]) and !empty($whatsnew_post_info[$forum['forum_id']]))
  256. {
  257. echo icon('../img/forumnew.gif');
  258. }
  259. else
  260. {
  261. echo icon('../img/forum.gif');
  262. }
  263. }
  264. echo "</td>\n";
  265. echo "\t\t<td><a href=\"viewforum.php?forum=".$forum['forum_id']."\" ".class_visible_invisible($forum['visibility']).">".prepare4display($forum['forum_title']).'</a><br />'.prepare4display($forum['forum_comment'])."</td>\n";
  266. //$number_forum_topics_and_posts=get_post_topics_of_forum($forum['forum_id']); // deprecated
  267. // the number of topics and posts
  268. echo "\t\t<td>".$forum['number_of_threads']."</td>\n";
  269. echo "\t\t<td>".$forum['number_of_posts']."</td>\n";
  270. // the last post in the forum
  271. if ($forum['last_poster_name']<>'')
  272. {
  273. $name=$forum['last_poster_name'];
  274. $poster_id=0;
  275. }
  276. else
  277. {
  278. $name=$forum['last_poster_firstname'].' '.$forum['last_poster_lastname'];
  279. $poster_id=$forum['last_poster_id'];
  280. }
  281. echo "\t\t<td>";
  282. if (!empty($forum['last_post_id']))
  283. {
  284. echo $forum['last_post_date']." ".get_lang('By').' '.display_user_link($poster_id, $name);
  285. }
  286. echo "</td>\n";
  287. if (api_is_allowed_to_edit())
  288. {
  289. echo "\t\t<td NOWRAP>";
  290. echo "<a href=\"".$_SERVER['PHP_SELF']."?forumcategory=".$_GET['forumcategory']."&amp;action=edit&amp;content=forum&amp;id=".$forum['forum_id']."\">".icon('../img/edit.gif',get_lang('Edit'))."</a>";
  291. echo "<a href=\"".$_SERVER['PHP_SELF']."?forumcategory=".$_GET['forumcategory']."&amp;action=delete&amp;content=forum&amp;id=".$forum['forum_id']."\" onclick=\"javascript:if(!confirm('".addslashes(htmlentities(get_lang("DeleteForum")))."')) return false;\">".icon('../img/delete.gif',get_lang('Delete'))."</a>";
  292. display_visible_invisible_icon('forum',$forum['forum_id'], $forum['visibility'], array("forumcategory"=>$_GET['forumcategory']));
  293. display_lock_unlock_icon('forum',$forum['forum_id'], $forum['locked'], array("forumcategory"=>$_GET['forumcategory']));
  294. display_up_down_icon('forum',$forum['forum_id'], $forums_in_category);
  295. echo "</td>\n";
  296. }
  297. echo "\t</tr>";
  298. }
  299. }
  300. }
  301. if (count($forum_list)==0)
  302. {
  303. echo "\t<tr><td>".get_lang('NoForumInThisCategory')."</td></tr>\n";
  304. }
  305. echo "</table>\n";
  306. /*
  307. ==============================================================================
  308. FOOTER
  309. ==============================================================================
  310. */
  311. Display :: display_footer();
  312. ?>