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