viewforumcategory.php 17 KB

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