viewforumcategory.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  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 chamilo.forum
  22. */
  23. // Language file that needs to be included.
  24. $language_file = 'forum';
  25. // Including the global initialization file.
  26. //require_once '../inc/global.inc.php';
  27. $htmlHeadXtra[] = '<script>
  28. $(document).ready(function(){
  29. $(\'.hide-me\').slideUp()
  30. });
  31. function hidecontent(content){
  32. $(content).slideToggle(\'normal\');
  33. }
  34. </script>';
  35. // The section (tabs)
  36. $this_section = SECTION_COURSES;
  37. // Notification for unauthorized people.
  38. api_protect_course_script(true);
  39. // Including additional library scripts.
  40. $nameTools = get_lang('ToolForum');
  41. // Including necessary files
  42. require 'forumconfig.inc.php';
  43. require_once 'forumfunction.inc.php';
  44. /* MAIN DISPLAY SECTION */
  45. /* Header and Breadcrumbs */
  46. if (isset($_SESSION['gradebook'])) {
  47. $gradebook= $_SESSION['gradebook'];
  48. }
  49. if (!empty($gradebook) && $gradebook == 'view') {
  50. $interbreadcrumb[] = array (
  51. 'url' => '../gradebook/'.$_SESSION['gradebook_dest'],
  52. 'name' => get_lang('ToolGradebook')
  53. );
  54. }
  55. $current_forum_category = get_forum_categories($_GET['forumcategory']);
  56. $interbreadcrumb[] = array('url' => 'index.php?gradebook='.$gradebook.'&amp;search='.Security::remove_XSS(urlencode(isset($_GET['search'])?$_GET['search']:'')),'name' => get_lang('Forum'));
  57. if (!empty($_GET['action']) && !empty($_GET['content'])) {
  58. if ($_GET['action']=='add' && $_GET['content']=='forum' ) {
  59. $interbreadcrumb[] = array('url' =>'viewforumcategory.php?forumcategory='.$current_forum_category['cat_id'].'&amp;origin='.$origin,'name' => $current_forum_category['cat_title']);
  60. $interbreadcrumb[] = array('url' =>'#', 'name' => get_lang('AddForum'));
  61. }
  62. } else {
  63. $interbreadcrumb[] = array('url' => '#','name' => $current_forum_category['cat_title']);
  64. }
  65. // Are we in a lp ?
  66. $origin = '';
  67. if (isset($_GET['origin'])) {
  68. $origin = Security::remove_XSS($_GET['origin']);
  69. }
  70. if ($origin=='learnpath') {
  71. Display::display_reduced_header();
  72. } else {
  73. Display::display_header(null);
  74. }
  75. /* ACTIONS */
  76. $whatsnew_post_info = isset($_SESSION['whatsnew_post_info']) ? $_SESSION['whatsnew_post_info'] : null;
  77. /* Is the user allowed here? */
  78. // if the user is not a course administrator and the forum is hidden
  79. // then the user is not allowed here.
  80. if (!api_is_allowed_to_edit(false,true) AND ($current_forum_category && $current_forum_category['visibility']==0)) {
  81. api_not_allowed();
  82. }
  83. /* Action Links */
  84. echo '<div class="actions">';
  85. echo '<span style="float:right;">'.search_link().'</span>';
  86. echo '<a href="index.php?gradebook='.$gradebook.'">'.Display::return_icon('back.png', get_lang('BackToForumOverview'), '', ICON_SIZE_MEDIUM).'</a>';
  87. if (api_is_allowed_to_edit(false,true)) {
  88. echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&forumcategory='.$current_forum_category['cat_id'].'&amp;action=add&amp;content=forum"> '.Display::return_icon('new_forum.png', get_lang('AddForum'),'',ICON_SIZE_MEDIUM).'</a>';
  89. }
  90. echo '</div>';
  91. /* ACTIONS */
  92. $action_forums = isset($_GET['action']) ? $_GET['action'] : '';
  93. if (api_is_allowed_to_edit(false, true)) {
  94. handle_forum_and_forumcategories();
  95. }
  96. // Notification
  97. if ($action_forums == 'notify' && isset($_GET['content']) && isset($_GET['id'])) {
  98. $return_message = set_notification($_GET['content'], $_GET['id']);
  99. Display :: display_confirmation_message($return_message, false);
  100. }
  101. if ($action_forums != 'add') {
  102. /*
  103. RETRIEVING ALL THE FORUM CATEGORIES AND FORUMS
  104. Note: We do this here just after het handling of the actions to be sure that we already incorporate the
  105. latest changes.
  106. */
  107. // Step 1: We store all the forum categories in an array $forum_categories.
  108. $forum_categories = array();
  109. $forum_category = get_forum_categories($_GET['forumcategory']);
  110. // Step 2: We find all the forums.
  111. $forum_list = array();
  112. $forum_list = get_forums();
  113. /* RETRIEVING ALL GROUPS AND THOSE OF THE USER */
  114. // The groups of the user.
  115. $groups_of_user = array();
  116. $groups_of_user = GroupManager::get_group_ids($_course['real_id'], $_user['user_id']);
  117. // All groups in the course (and sorting them as the id of the group = the key of the array.
  118. $all_groups = GroupManager::get_group_list();
  119. if (is_array($all_groups)) {
  120. foreach ($all_groups as $group) {
  121. $all_groups[$group['id']] = $group;
  122. }
  123. }
  124. /* CLEAN GROUP ID FOR AJAXFILEMANAGER */
  125. if (isset($_SESSION['_gid'])) {
  126. unset($_SESSION['_gid']);
  127. }
  128. /* Display Forum Categories and the Forums in it */
  129. echo '<table class="forum_table" width="100%">';
  130. $my_session = isset($_SESSION['id_session']) ? $_SESSION['id_session'] : null;
  131. if ((!isset($_SESSION['id_session']) || $_SESSION['id_session'] == 0) && !empty($forum_category['session_name'])) {
  132. $session_displayed = ' ('.Security::remove_XSS($forum_category['session_name']).')';
  133. } else {
  134. $session_displayed = '';
  135. }
  136. $forum_categories_list = '';
  137. echo '<thead>';
  138. echo '<tr><th class="forum_head" '.(api_is_allowed_to_edit(null, true) ? 'colspan="5"' : 'colspan="6"').'>';
  139. echo '<a href="viewforumcategory.php?'.api_get_cidreq().'&amp;forumcategory='.strval(intval($forum_category['cat_id'])).'" '.class_visible_invisible(strval(intval($forum_category['visibility']))).'>'.prepare4display($forum_category['cat_title']).$session_displayed.'</a>'. $session_img .'<br />';
  140. echo '<span class="forum_description">'.prepare4display($forum_category['cat_comment']).'</span>';
  141. if (api_is_allowed_to_edit(false, true) && !($forum_category['session_id'] == 0 && intval($my_session) != 0)) {
  142. echo '<th style="vertical-align: top;" align="center">';
  143. echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;forumcategory='.Security::remove_XSS($_GET['forumcategory']).'&amp;action=edit&amp;content=forumcategory&amp;id='.$forum_category['cat_id'].'">'.Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL).'</a>';
  144. echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;forumcategory='.Security::remove_XSS($_GET['forumcategory']).'&amp;action=delete&amp;content=forumcategory&amp;amp;id='.$forum_category['cat_id']."\" onclick=\"javascript:if(!confirm('".addslashes(api_htmlentities(get_lang('DeleteForumCategory'), ENT_QUOTES))."')) return false;\">".Display::return_icon('delete.png', get_lang('Delete'), array(), ICON_SIZE_SMALL).'</a>';
  145. display_visible_invisible_icon('forumcategory', $forum_category['cat_id'], $forum_category['visibility'], array('forumcategory' => $_GET['forumcategory']));
  146. display_lock_unlock_icon('forumcategory', $forum_category['cat_id'], $forum_category['locked'], array('forumcategory' => $_GET['forumcategory']));
  147. display_up_down_icon('forumcategory', $forum_category['cat_id'], $forum_categories_list);
  148. echo '</th>';
  149. }
  150. echo '</tr>';
  151. // Step 3: The interim headers (for the forum).
  152. echo '<tr class="forum_header">';
  153. echo '<td colspan="2">'.get_lang('Forum').'</td>';
  154. echo '<td>'.get_lang('ForumThreads').'</td>';
  155. echo '<td>'.get_lang('Posts').'</td>';
  156. echo '<td>'.get_lang('LastPosts').'</td>';
  157. echo '<td>'.get_lang('Actions').'</td>';
  158. echo '</tr>';
  159. echo '</thead>';
  160. // The forums in this category.
  161. $forums_in_category = get_forums_in_category($forum_category['cat_id']);
  162. // Step 4: We display all the forums in this category.
  163. $forum_count = 0;
  164. foreach ($forum_list as $key => $forum) {
  165. if ($forum['forum_category'] == $forum_category['cat_id']) {
  166. // The forum has to be showed if
  167. // 1.v it is a not a group forum (teacher and student)
  168. // 2.v it is a group forum and it is public (teacher and student)
  169. // 3. it is a group forum and it is private (always for teachers only if the user is member of the forum
  170. // 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
  171. //if (!($forum['forum_group_public_private']=='private' AND !is_null($forum['forum_of_group']) AND !in_array($forum['forum_of_group'], $groups_of_user))) {
  172. $show_forum = false;
  173. // SHOULD WE SHOW THIS PARTICULAR FORUM
  174. // you are teacher => show forum
  175. if (api_is_allowed_to_edit(false,true)) {
  176. //echo 'teacher';
  177. $show_forum = true;
  178. } else {
  179. // you are not a teacher
  180. //echo 'student';
  181. // it is not a group forum => show forum (invisible forums are already left out see get_forums function)
  182. if ($forum['forum_of_group'] == '0') {
  183. //echo '-gewoon forum';
  184. $show_forum = true;
  185. } else {
  186. // it is a group forum
  187. //echo '-groepsforum';
  188. // it is a group forum but it is public => show
  189. if ($forum['forum_group_public_private'] == 'public') {
  190. $show_forum = true;
  191. //echo '-publiek';
  192. } else {
  193. // it is a group forum and it is private
  194. //echo '-prive';
  195. // it is a group forum and it is private but the user is member of the group
  196. if (in_array($forum['forum_of_group'], $groups_of_user)) {
  197. //echo '-is lid';
  198. $show_forum = true;
  199. } else {
  200. //echo '-is GEEN lid';
  201. $show_forum = false;
  202. }
  203. }
  204. }
  205. }
  206. //echo '<hr />';
  207. $form_count = isset($form_count) ? $form_count : 0;
  208. if ($show_forum === true) {
  209. $form_count++;
  210. echo '<tr class="forum">';
  211. echo '<td width="20">';
  212. $my_whatsnew_post_info = isset($whatsnew_post_info[$forum['forum_id']]) ? $whatsnew_post_info[$forum['forum_id']] : null;
  213. if ($forum['forum_of_group'] !== '0') {
  214. if (is_array($my_whatsnew_post_info) && !empty($my_whatsnew_post_info)) {
  215. echo Display::return_icon('forumgroupnew.gif');
  216. } else {
  217. echo Display::return_icon('forumgroup.gif', get_lang('GroupForum'));
  218. }
  219. } else {
  220. if (is_array($my_whatsnew_post_info) && !empty($my_whatsnew_post_info)) {
  221. echo Display::return_icon('forum.gif', get_lang('Forum'));
  222. } else {
  223. echo Display::return_icon('forum.gif');
  224. }
  225. }
  226. echo '</td>';
  227. if ($forum['forum_of_group'] != '0') {
  228. $my_all_groups_forum_name = isset($all_groups[$forum['forum_of_group']]['name']) ? $all_groups[$forum['forum_of_group']]['name'] : null;
  229. $my_all_groups_forum_id = isset($all_groups[$forum['forum_of_group']]['id']) ? $all_groups[$forum['forum_of_group']]['id'] : null;
  230. $group_title = api_substr($my_all_groups_forum_name, 0, 30);
  231. $forum_title_group_addition = ' (<a href="../group/group_space.php?'.api_get_cidreq().'&amp;gidReq='.$my_all_groups_forum_id.'" class="forum_group_link">'.get_lang('GoTo').' '.$group_title.'</a>)';
  232. } else {
  233. $forum_title_group_addition = '';
  234. }
  235. if ((!isset($_SESSION['id_session']) || $_SESSION['id_session'] == 0) && !empty($forum['session_name'])) {
  236. $session_displayed = ' ('.$forum['session_name'].')';
  237. } else {
  238. $session_displayed = '';
  239. }
  240. echo '<td><a href="viewforum.php?'.api_get_cidreq().'&amp;gidReq='.$forum['forum_of_group'].'&amp;forum='.$forum['forum_id'].'&amp;origin='.$origin.'&amp;search='.Security::remove_XSS(urlencode(isset($_GET['search']) ? $_GET['search'] : '')).'" '.class_visible_invisible($forum['visibility']).'>'.prepare4display($forum['forum_title']).$session_displayed.'</a>'.$forum_title_group_addition.'<br />'.prepare4display($forum['forum_comment']).'</td>';
  241. //$number_forum_topics_and_posts=get_post_topics_of_forum($forum['forum_id']); // deprecated
  242. // the number of topics and posts
  243. $my_number_threads = isset($forum['number_of_threads']) ? $forum['number_of_threads'] : '';
  244. $my_number_posts = isset($forum['number_of_posts']) ? $forum['number_of_posts'] : '';
  245. echo '<td>'.$my_number_threads.'</td>';
  246. echo '<td>'.$my_number_posts.'</td>';
  247. // the last post in the forum
  248. if ($forum['last_poster_name'] != '') {
  249. $name = $forum['last_poster_name'];
  250. $poster_id = 0;
  251. } else {
  252. $name = api_get_person_name($forum['last_poster_firstname'], $forum['last_poster_lastname']);
  253. $poster_id = $forum['last_poster_id'];
  254. }
  255. echo '<td>';
  256. if (!empty($forum['last_post_id'])) {
  257. echo $forum['last_post_date'].' '.get_lang('By').' '.display_user_link($poster_id, $name);
  258. }
  259. echo '</td>';
  260. echo '<td class="td_actions">';
  261. if (api_is_allowed_to_edit(false, true) && !($forum['session_id'] == 0 && intval(isset($_SESSION['id_session']) ? $_SESSION['id_session'] : null) != 0)) {
  262. echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;forumcategory='.Security::remove_XSS($_GET['forumcategory']).'&amp;action=edit&amp;content=forum&amp;id='.$forum['forum_id'].'">'.Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL).'</a>';
  263. echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;forumcategory='.Security::remove_XSS($_GET['forumcategory']).'&amp;action=delete&amp;content=forum&amp;id='.$forum['forum_id']."\" onclick=\"javascript:if(!confirm('".addslashes(api_htmlentities(get_lang('DeleteForum'), ENT_QUOTES))."')) return false;\">".Display::return_icon('delete.png', get_lang('Delete'), array(), ICON_SIZE_SMALL).'</a>';
  264. display_visible_invisible_icon('forum', $forum['forum_id'], $forum['visibility'], array('forumcategory' => $_GET['forumcategory']));
  265. display_lock_unlock_icon('forum', $forum['forum_id'], $forum['locked'], array('forumcategory' => $_GET['forumcategory']));
  266. display_up_down_icon('forum', $forum['forum_id'], $forums_in_category);
  267. }
  268. $iconnotify = 'send_mail.gif';
  269. if (is_array(isset($_SESSION['forum_notification']['forum']) ? $_SESSION['forum_notification']['forum'] : null)) {
  270. if (in_array($forum['forum_id'],$_SESSION['forum_notification']['forum'])) {
  271. $iconnotify = 'send_mail_checked.gif';
  272. }
  273. }
  274. if (!api_is_anonymous()) {
  275. echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;forumcategory='.Security::remove_XSS($_GET['forumcategory']).'&amp;action=notify&amp;content=forum&amp;id='.$forum['forum_id'].'">'.Display::return_icon($iconnotify, get_lang('NotifyMe')).'</a>';
  276. }
  277. echo '</td></tr>';
  278. }
  279. }
  280. }
  281. if (count($forum_list) == 0) {
  282. echo '<tr><td>'.get_lang('NoForumInThisCategory').'</td></tr>';
  283. }
  284. echo '</table>';
  285. }
  286. /* FOOTER */
  287. if ($origin != 'learnpath') {
  288. Display :: display_footer();
  289. }