viewforumcategory.php 17 KB

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