viewforumcategory.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  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" language="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. /* MAIN DISPLAY SECTION */
  52. /* Header and Breadcrumbs */
  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 = $_SESSION['whatsnew_post_info'];
  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.'">'.Display::return_icon('back.png', get_lang('BackToForumOverview'), '', ICON_SIZE_MEDIUM).'</a>';
  94. if (api_is_allowed_to_edit(false,true)) {
  95. 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>';
  96. }
  97. echo '</div>';
  98. /* ACTIONS */
  99. $action_forums = isset($_GET['action']) ? $_GET['action'] : '';
  100. if (api_is_allowed_to_edit(false, true)) {
  101. handle_forum_and_forumcategories();
  102. }
  103. // Notification
  104. if ($action_forums == 'notify' && isset($_GET['content']) && isset($_GET['id'])) {
  105. $return_message = set_notification($_GET['content'], $_GET['id']);
  106. Display :: display_confirmation_message($return_message, false);
  107. }
  108. if ($action_forums != 'add') {
  109. /*
  110. RETRIEVING ALL THE FORUM CATEGORIES AND FORUMS
  111. Note: We do this here just after het handling of the actions to be sure that we already incorporate the
  112. latest changes.
  113. */
  114. // Step 1: We store all the forum categories in an array $forum_categories.
  115. $forum_categories = array();
  116. $forum_category = get_forum_categories($_GET['forumcategory']);
  117. // Step 2: We find all the forums.
  118. $forum_list = array();
  119. $forum_list = get_forums();
  120. /* RETRIEVING ALL GROUPS AND THOSE OF THE USER */
  121. // The groups of the user.
  122. $groups_of_user = array();
  123. $groups_of_user = GroupManager::get_group_ids($_course['real_id'], $_user['user_id']);
  124. // All groups in the course (and sorting them as the id of the group = the key of the array.
  125. $all_groups = GroupManager::get_group_list();
  126. if (is_array($all_groups)) {
  127. foreach ($all_groups as $group) {
  128. $all_groups[$group['id']] = $group;
  129. }
  130. }
  131. /* CLEAN GROUP ID FOR AJAXFILEMANAGER */
  132. if (isset($_SESSION['_gid'])) {
  133. unset($_SESSION['_gid']);
  134. }
  135. /* Display Forum Categories and the Forums in it */
  136. echo '<table class="forum_table" width="100%">';
  137. $my_session = isset($_SESSION['id_session']) ? $_SESSION['id_session'] : null;
  138. if ((!isset($_SESSION['id_session']) || $_SESSION['id_session'] == 0) && !empty($forum_category['session_name'])) {
  139. $session_displayed = ' ('.Security::remove_XSS($forum_category['session_name']).')';
  140. } else {
  141. $session_displayed = '';
  142. }
  143. $forum_categories_list = '';
  144. echo '<thead>';
  145. echo '<tr><th class="forum_head" '.(api_is_allowed_to_edit(null, true) ? 'colspan="5"' : 'colspan="6"').'>';
  146. 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 />';
  147. echo '<span class="forum_description">'.prepare4display($forum_category['cat_comment']).'</span>';
  148. if (api_is_allowed_to_edit(false, true) && !($forum_category['session_id'] == 0 && intval($my_session) != 0)) {
  149. echo '<th style="vertical-align: top;" align="center">';
  150. 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>';
  151. 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>';
  152. display_visible_invisible_icon('forumcategory', $forum_category['cat_id'], $forum_category['visibility'], array('forumcategory' => $_GET['forumcategory']));
  153. display_lock_unlock_icon('forumcategory', $forum_category['cat_id'], $forum_category['locked'], array('forumcategory' => $_GET['forumcategory']));
  154. display_up_down_icon('forumcategory', $forum_category['cat_id'], $forum_categories_list);
  155. echo '</th>';
  156. }
  157. echo '</tr>';
  158. // Step 3: The interim headers (for the forum).
  159. echo '<tr class="forum_header">';
  160. echo '<td colspan="2">'.get_lang('Forum').'</td>';
  161. echo '<td>'.get_lang('ForumThreads').'</td>';
  162. echo '<td>'.get_lang('Posts').'</td>';
  163. echo '<td>'.get_lang('LastPosts').'</td>';
  164. echo '<td>'.get_lang('Actions').'</td>';
  165. echo '</tr>';
  166. echo '</thead>';
  167. // The forums in this category.
  168. $forums_in_category = get_forums_in_category($forum_category['cat_id']);
  169. // Step 4: We display all the forums in this category.
  170. $forum_count = 0;
  171. foreach ($forum_list as $key => $forum) {
  172. if ($forum['forum_category'] == $forum_category['cat_id']) {
  173. // The forum has to be showed if
  174. // 1.v it is a not a group forum (teacher and student)
  175. // 2.v it is a group forum and it is public (teacher and student)
  176. // 3. it is a group forum and it is private (always for teachers only if the user is member of the forum
  177. // 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
  178. //if (!($forum['forum_group_public_private']=='private' AND !is_null($forum['forum_of_group']) AND !in_array($forum['forum_of_group'], $groups_of_user))) {
  179. $show_forum = false;
  180. // SHOULD WE SHOW THIS PARTICULAR FORUM
  181. // you are teacher => show forum
  182. if (api_is_allowed_to_edit(false,true)) {
  183. //echo 'teacher';
  184. $show_forum = true;
  185. } else {
  186. // you are not a teacher
  187. //echo 'student';
  188. // it is not a group forum => show forum (invisible forums are already left out see get_forums function)
  189. if ($forum['forum_of_group'] == '0') {
  190. //echo '-gewoon forum';
  191. $show_forum = true;
  192. } else {
  193. // it is a group forum
  194. //echo '-groepsforum';
  195. // it is a group forum but it is public => show
  196. if ($forum['forum_group_public_private'] == 'public') {
  197. $show_forum = true;
  198. //echo '-publiek';
  199. } else {
  200. // it is a group forum and it is private
  201. //echo '-prive';
  202. // it is a group forum and it is private but the user is member of the group
  203. if (in_array($forum['forum_of_group'], $groups_of_user)) {
  204. //echo '-is lid';
  205. $show_forum = true;
  206. } else {
  207. //echo '-is GEEN lid';
  208. $show_forum = false;
  209. }
  210. }
  211. }
  212. }
  213. //echo '<hr />';
  214. $form_count = isset($form_count) ? $form_count : 0;
  215. if ($show_forum === true) {
  216. $form_count++;
  217. echo '<tr class="forum">';
  218. echo '<td width="20">';
  219. $my_whatsnew_post_info = isset($whatsnew_post_info[$forum['forum_id']]) ? $whatsnew_post_info[$forum['forum_id']] : null;
  220. if ($forum['forum_of_group'] !== '0') {
  221. if (is_array($my_whatsnew_post_info) && !empty($my_whatsnew_post_info)) {
  222. echo Display::return_icon('forumgroupnew.gif');
  223. } else {
  224. echo Display::return_icon('forumgroup.gif', get_lang('GroupForum'));
  225. }
  226. } else {
  227. if (is_array($my_whatsnew_post_info) && !empty($my_whatsnew_post_info)) {
  228. echo Display::return_icon('forum.gif', get_lang('Forum'));
  229. } else {
  230. echo Display::return_icon('forum.gif');
  231. }
  232. }
  233. echo '</td>';
  234. if ($forum['forum_of_group'] != '0') {
  235. $my_all_groups_forum_name = isset($all_groups[$forum['forum_of_group']]['name']) ? $all_groups[$forum['forum_of_group']]['name'] : null;
  236. $my_all_groups_forum_id = isset($all_groups[$forum['forum_of_group']]['id']) ? $all_groups[$forum['forum_of_group']]['id'] : null;
  237. $group_title = api_substr($my_all_groups_forum_name, 0, 30);
  238. $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>)';
  239. } else {
  240. $forum_title_group_addition = '';
  241. }
  242. if ((!isset($_SESSION['id_session']) || $_SESSION['id_session'] == 0) && !empty($forum['session_name'])) {
  243. $session_displayed = ' ('.$forum['session_name'].')';
  244. } else {
  245. $session_displayed = '';
  246. }
  247. 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>';
  248. //$number_forum_topics_and_posts=get_post_topics_of_forum($forum['forum_id']); // deprecated
  249. // the number of topics and posts
  250. $my_number_threads = isset($forum['number_of_threads']) ? $forum['number_of_threads'] : '';
  251. $my_number_posts = isset($forum['number_of_posts']) ? $forum['number_of_posts'] : '';
  252. echo '<td>'.$my_number_threads.'</td>';
  253. echo '<td>'.$my_number_posts.'</td>';
  254. // the last post in the forum
  255. if ($forum['last_poster_name'] != '') {
  256. $name = $forum['last_poster_name'];
  257. $poster_id = 0;
  258. } else {
  259. $name = api_get_person_name($forum['last_poster_firstname'], $forum['last_poster_lastname']);
  260. $poster_id = $forum['last_poster_id'];
  261. }
  262. echo '<td>';
  263. if (!empty($forum['last_post_id'])) {
  264. echo $forum['last_post_date'].' '.get_lang('By').' '.display_user_link($poster_id, $name);
  265. }
  266. echo '</td>';
  267. echo '<td class="td_actions">';
  268. if (api_is_allowed_to_edit(false, true) && !($forum['session_id'] == 0 && intval(isset($_SESSION['id_session']) ? $_SESSION['id_session'] : null) != 0)) {
  269. 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>';
  270. 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>';
  271. display_visible_invisible_icon('forum', $forum['forum_id'], $forum['visibility'], array('forumcategory' => $_GET['forumcategory']));
  272. display_lock_unlock_icon('forum', $forum['forum_id'], $forum['locked'], array('forumcategory' => $_GET['forumcategory']));
  273. display_up_down_icon('forum', $forum['forum_id'], $forums_in_category);
  274. }
  275. $iconnotify = 'send_mail.gif';
  276. if (is_array(isset($_SESSION['forum_notification']['forum']) ? $_SESSION['forum_notification']['forum'] : null)) {
  277. if (in_array($forum['forum_id'],$_SESSION['forum_notification']['forum'])) {
  278. $iconnotify = 'send_mail_checked.gif';
  279. }
  280. }
  281. if (!api_is_anonymous()) {
  282. 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>';
  283. }
  284. echo '</td></tr>';
  285. }
  286. }
  287. }
  288. if (count($forum_list) == 0) {
  289. echo '<tr><td>'.get_lang('NoForumInThisCategory').'</td></tr>';
  290. }
  291. echo '</table>';
  292. }
  293. /* FOOTER */
  294. if ($origin != 'learnpath') {
  295. Display :: display_footer();
  296. }