viewforumcategory.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495
  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. $htmlHeadXtra[] = '<script>
  24. $(document).ready(function(){
  25. $(\'.hide-me\').slideUp()
  26. });
  27. function hidecontent(content){
  28. $(content).slideToggle(\'normal\');
  29. }
  30. </script>';
  31. // The section (tabs)
  32. $this_section = SECTION_COURSES;
  33. // Notification for unauthorized people.
  34. api_protect_course_script(true);
  35. // Including additional library scripts.
  36. $nameTools = get_lang('ToolForum');
  37. // Including necessary files
  38. require 'forumconfig.inc.php';
  39. require_once 'forumfunction.inc.php';
  40. // Are we in a lp ?
  41. $origin = '';
  42. if (isset($_GET['origin'])) {
  43. $origin = Security::remove_XSS($_GET['origin']);
  44. }
  45. /* Header and Breadcrumbs */
  46. if (api_is_in_gradebook()) {
  47. $interbreadcrumb[]= array(
  48. 'url' => api_get_path(WEB_CODE_PATH).'gradebook/index.php?'.api_get_cidreq(),
  49. 'name' => get_lang('ToolGradebook')
  50. );
  51. }
  52. $sessionId = api_get_session_id();
  53. $current_forum_category = get_forum_categories($_GET['forumcategory']);
  54. $interbreadcrumb[] = array(
  55. 'url' => 'index.php?'.api_get_cidreq().'&search='
  56. . Security::remove_XSS(urlencode(isset($_GET['search']) ? $_GET['search'] : '')),
  57. 'name' => get_lang('Forum')
  58. );
  59. if (!empty($_GET['action']) && !empty($_GET['content'])) {
  60. if ($_GET['action']=='add' && $_GET['content']=='forum' ) {
  61. $interbreadcrumb[] = array(
  62. 'url' => 'viewforumcategory.php?forumcategory='
  63. . $current_forum_category['cat_id'] . '&origin=' . $origin,
  64. 'name' => $current_forum_category['cat_title']
  65. );
  66. $interbreadcrumb[] = array(
  67. 'url' =>'#',
  68. 'name' => get_lang('AddForum')
  69. );
  70. }
  71. } else {
  72. $interbreadcrumb[] = array(
  73. 'url' => '#',
  74. 'name' => $current_forum_category['cat_title']
  75. );
  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 (
  88. !api_is_allowed_to_edit(false, true) AND
  89. ( $current_forum_category && $current_forum_category['visibility'] == 0)
  90. ) {
  91. api_not_allowed();
  92. }
  93. /* Action Links */
  94. $html = '';
  95. $html .= '<div class="actions">';
  96. $html .= '<a href="index.php?'.api_get_cidreq().'">'.
  97. Display::return_icon('back.png', get_lang('BackToForumOverview'), '', ICON_SIZE_MEDIUM).'</a>';
  98. if (api_is_allowed_to_edit(false,true)) {
  99. $html .= '<a href="' . api_get_self() . '?' . api_get_cidreq() . '&forumcategory='
  100. . $current_forum_category['cat_id'] . '&action=add&content=forum"> '
  101. . Display::return_icon('new_forum.png', get_lang('AddForum'), '', ICON_SIZE_MEDIUM) . '</a>';
  102. }
  103. $html .= search_link();
  104. $html .= '</div>';
  105. /* ACTIONS */
  106. echo $html;
  107. $action_forums = isset($_GET['action']) ? $_GET['action'] : '';
  108. if (api_is_allowed_to_edit(false, true)) {
  109. handle_forum_and_forumcategories();
  110. }
  111. // Notification
  112. if ($action_forums == 'notify' && isset($_GET['content']) && isset($_GET['id'])) {
  113. $return_message = set_notification($_GET['content'], $_GET['id']);
  114. Display::display_confirmation_message($return_message, false);
  115. }
  116. if ($action_forums != 'add') {
  117. /*
  118. RETRIEVING ALL THE FORUM CATEGORIES AND FORUMS
  119. Note: We do this here just after het handling of the actions to be sure that we already incorporate the
  120. latest changes.
  121. */
  122. // Step 1: We store all the forum categories in an array $forum_categories.
  123. $forum_categories = array();
  124. $forum_category = get_forum_categories($_GET['forumcategory']);
  125. // Step 2: We find all the forums.
  126. $forum_list = get_forums();
  127. /* RETRIEVING ALL GROUPS AND THOSE OF THE USER */
  128. // The groups of the user.
  129. $groups_of_user = array();
  130. $groups_of_user = GroupManager::get_group_ids($_course['real_id'], $_user['user_id']);
  131. // All groups in the course (and sorting them as the id of the group = the key of the array.
  132. $all_groups = GroupManager::get_group_list();
  133. if (is_array($all_groups)) {
  134. foreach ($all_groups as $group) {
  135. $all_groups[$group['id']] = $group;
  136. }
  137. }
  138. /* Display Forum Categories and the Forums in it */
  139. $html = '';
  140. $html .= '<div class="category-forum">';
  141. if (
  142. (!isset($sessionId) || $sessionId == 0) &&
  143. !empty($forum_category['session_name'])
  144. ) {
  145. $session_displayed = ' ('.Security::remove_XSS($forum_category['session_name']).')';
  146. } else {
  147. $session_displayed = '';
  148. }
  149. $forum_categories_list = '';
  150. $forumId = $forum_category['cat_id'];
  151. $forumTitle = $forum_category['cat_title'];
  152. $linkForumCategory = 'viewforumcategory.php?' . api_get_cidreq() . '&forumcategory=' . strval(intval($forumId));
  153. $descriptionCategory = $forum_category['cat_comment'];
  154. $icoCategory = Display::return_icon(
  155. 'forum_blue.png',
  156. get_lang($forum_category['cat_title']),
  157. array('class' => ''),
  158. ICON_SIZE_MEDIUM
  159. );
  160. if (api_is_allowed_to_edit(false, true) && !($forum_category['session_id'] == 0 && $sessionId != 0)) {
  161. $iconsEdit = '<a href="' . api_get_self() . '?' . api_get_cidreq() . '&forumcategory='
  162. . Security::remove_XSS($_GET['forumcategory']) . '&action=edit&content=forumcategory&id='
  163. . '' . $forumId . '">'
  164. . Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL) . '</a>';
  165. $iconsEdit .= '<a href="' . api_get_self() . '?' . api_get_cidreq() . '&forumcategory='
  166. . Security::remove_XSS($_GET['forumcategory'])
  167. . '&action=delete&content=forumcategory&id=' . $forumId
  168. . "\" onclick=\"javascript:if(!confirm('"
  169. . addslashes(api_htmlentities(get_lang('DeleteForumCategory'), ENT_QUOTES))
  170. . "')) return false;\">" . Display::return_icon('delete.png', get_lang('Delete'), array(), ICON_SIZE_SMALL)
  171. . '</a>';
  172. $iconsEdit .= return_visible_invisible_icon(
  173. 'forumcategory', $forum_category['cat_id'],
  174. $forum_category['visibility'],
  175. array('forumcategory' => $_GET['forumcategory'])
  176. );
  177. $iconsEdit .= return_lock_unlock_icon(
  178. 'forumcategory', $forum_category['cat_id'],
  179. $forum_category['locked'],
  180. array('forumcategory' => $_GET['forumcategory'])
  181. );
  182. $iconsEdit .= return_up_down_icon(
  183. 'forumcategory', $forum_category['cat_id'],
  184. $forum_categories_list
  185. );
  186. $html .= Display::tag(
  187. 'div',
  188. $iconsEdit,
  189. array('class' => 'pull-right')
  190. );
  191. }
  192. $session_img = api_get_session_image($forum_category['session_id'], $_user['status']);
  193. $html .= Display::tag(
  194. 'h3',
  195. $icoCategory.
  196. Display::tag(
  197. 'a',
  198. $forumTitle,
  199. array(
  200. 'href'=>$linkForumCategory,
  201. 'class' => empty($forum_category['visibility']) ? 'text-muted' : null
  202. )
  203. ).$session_displayed.$session_img,
  204. null
  205. );
  206. if ($descriptionCategory != '' && trim($descriptionCategory)!= '&nbsp;') {
  207. $html .= '<div class="forum-description">'.$descriptionCategory.'</div>';
  208. }
  209. $html .= '</div>';
  210. echo $html;
  211. echo '<div class="forum_display">';
  212. // The forums in this category.
  213. $forums_in_category = get_forums_in_category($forum_category['cat_id']);
  214. // Step 4: We display all the forums in this category.
  215. $forum_count = 0;
  216. foreach ($forum_list as $key => $forum) {
  217. if ($forum['forum_category'] == $forum_category['cat_id']) {
  218. // The forum has to be showed if
  219. // 1.v it is a not a group forum (teacher and student)
  220. // 2.v it is a group forum and it is public (teacher and student)
  221. // 3. it is a group forum and it is private (always for teachers only if the user is member of the forum
  222. // 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
  223. //if (!($forum['forum_group_public_private']=='private' AND !is_null($forum['forum_of_group']) AND !in_array($forum['forum_of_group'], $groups_of_user))) {
  224. $show_forum = false;
  225. // SHOULD WE SHOW THIS PARTICULAR FORUM
  226. // you are teacher => show forum
  227. if (api_is_allowed_to_edit(false,true)) {
  228. //echo 'teacher';
  229. $show_forum = true;
  230. } else {
  231. // you are not a teacher
  232. //echo 'student';
  233. // it is not a group forum => show forum (invisible forums are already left out see get_forums function)
  234. if ($forum['forum_of_group'] == '0') {
  235. //echo '-gewoon forum';
  236. $show_forum = true;
  237. } else {
  238. // it is a group forum
  239. //echo '-groepsforum';
  240. // it is a group forum but it is public => show
  241. if ($forum['forum_group_public_private'] == 'public') {
  242. $show_forum = true;
  243. //echo '-publiek';
  244. } else {
  245. // it is a group forum and it is private
  246. //echo '-prive';
  247. // it is a group forum and it is private but the user is member of the group
  248. if (in_array($forum['forum_of_group'], $groups_of_user)) {
  249. //echo '-is lid';
  250. $show_forum = true;
  251. } else {
  252. //echo '-is GEEN lid';
  253. $show_forum = false;
  254. }
  255. }
  256. }
  257. }
  258. //echo '<hr />';
  259. $form_count = isset($form_count) ? $form_count : 0;
  260. if ($show_forum === true) {
  261. $form_count++;
  262. $html = '<div class="panel panel-default forum">';
  263. $html .= '<div class="panel-body">';
  264. $my_whatsnew_post_info = isset($whatsnew_post_info[$forum['forum_id']]) ? $whatsnew_post_info[$forum['forum_id']] : null;
  265. if ($forum['forum_of_group'] == '0') {
  266. $forum_image = Display::return_icon(
  267. 'forum_group.png',
  268. get_lang('GroupForum'),
  269. null,
  270. ICON_SIZE_LARGE
  271. );
  272. } else {
  273. $forum_image = Display::return_icon(
  274. 'forum.png',
  275. get_lang('Forum'),
  276. null,
  277. ICON_SIZE_LARGE
  278. );
  279. }
  280. if ($forum['forum_of_group'] != '0') {
  281. $my_all_groups_forum_name = isset($all_groups[$forum['forum_of_group']]['name'])
  282. ? $all_groups[$forum['forum_of_group']]['name']
  283. : null;
  284. $my_all_groups_forum_id = isset($all_groups[$forum['forum_of_group']]['id'])
  285. ? $all_groups[$forum['forum_of_group']]['id']
  286. : null;
  287. $group_title = api_substr($my_all_groups_forum_name, 0, 30);
  288. $forum_title_group_addition = ' (<a href="../group/group_space.php?' . api_get_cidreq()
  289. . '&gidReq=' . $my_all_groups_forum_id . '" class="forum_group_link">'
  290. . get_lang('GoTo') . ' ' . $group_title . '</a>)';
  291. } else {
  292. $forum_title_group_addition = '';
  293. }
  294. if (!empty($sessionId) && !empty($forum['session_name'])) {
  295. $session_displayed = ' ('.$forum['session_name'].')';
  296. } else {
  297. $session_displayed = '';
  298. }
  299. // the number of topics and posts
  300. $my_number_threads = isset($forum['number_of_threads']) ? $forum['number_of_threads'] : 0;
  301. $my_number_posts = isset($forum['number_of_posts']) ? $forum['number_of_posts'] : 0;
  302. $html .= '<div class="row">';
  303. $html .= '<div class="col-md-6">';
  304. $html .= '<div class="col-md-3">';
  305. $html .= '<div class="number-post">'.$forum_image .'<p>' . $my_number_threads . ' ' . get_lang('ForumThreads') . '</p></div>';
  306. $html .= '</div>';
  307. $html .= '<div class="col-md-9">';
  308. $iconForum = Display::return_icon(
  309. 'forum_yellow.png',
  310. get_lang($forum_category['cat_title']),
  311. null,
  312. ICON_SIZE_MEDIUM
  313. );
  314. $linkForum = '';
  315. $linkForum .= Display::tag(
  316. 'a',
  317. $forum['forum_title'].$session_displayed,
  318. array(
  319. 'href' => 'viewforum.php?' . api_get_cidreq()
  320. . "&gidReq={$forum['forum_of_group']}&forum={$forum['forum_id']}&search="
  321. . Security::remove_XSS(urlencode(isset($_GET['search']) ? $_GET['search'] : '')),
  322. 'class' => empty($forum['visibility']) ? 'text-muted' : null
  323. )
  324. );
  325. $html .= Display::tag(
  326. 'h3',
  327. $linkForum . ' ' . $forum_title_group_addition,
  328. array(
  329. 'class' => 'title'
  330. )
  331. );
  332. $html .= Display::tag(
  333. 'p',
  334. strip_tags($forum['forum_comment']),
  335. array(
  336. 'class' => 'description'
  337. )
  338. );
  339. $html .= '</div>';
  340. $html .= '</div>';
  341. $html .= '<div class="col-md-6">';
  342. $iconEmpty='';
  343. // The number of topics and posts.
  344. if ($forum['forum_of_group'] !== '0') {
  345. $newPost = '';
  346. if (is_array($my_whatsnew_post_info) && !empty($my_whatsnew_post_info)) {
  347. $newPost = ' ' . Display::return_icon('alert.png', get_lang('Forum'), null, ICON_SIZE_SMALL);
  348. } else {
  349. $newPost = $iconEmpty;
  350. }
  351. } else {
  352. if (is_array($my_whatsnew_post_info) && !empty($my_whatsnew_post_info)) {
  353. $newPost = ' ' . Display::return_icon('alert.png', get_lang('Forum'), null, ICON_SIZE_SMALL);
  354. } else {
  355. $newPost = $iconEmpty;
  356. }
  357. }
  358. $html .= '<div class="row">';
  359. $html .= '<div class="col-md-2">';
  360. $html .= $newPost . '</div>';
  361. $poster_id = 0;
  362. $name = '';
  363. // the last post in the forum
  364. if (isset($forum['last_poster_name']) && $forum['last_poster_name'] != '') {
  365. $name = $forum['last_poster_name'];
  366. } else {
  367. if (isset($forum['last_poster_lastname'])) {
  368. $name = api_get_person_name($forum['last_poster_firstname'], $forum['last_poster_lastname']);
  369. $poster_id = $forum['last_poster_id'];
  370. }
  371. }
  372. $html .= '<div class="col-md-6">';
  373. if (!empty($forum['last_post_id'])) {
  374. $html .= Display::return_icon('post-item.png', null, null, ICON_SIZE_TINY) . ' ';
  375. $html .= api_convert_and_format_date($forum['last_post_date'])
  376. . ' ' . get_lang('By') . ' '
  377. . display_user_link($poster_id, $name);
  378. }
  379. $html .= '</div>';
  380. $html .= '<div class="col-md-4">';
  381. if (
  382. api_is_allowed_to_edit(false, true) &&
  383. !($forum['session_id'] == 0 && $sessionId != 0)
  384. ) {
  385. $html .= '<a href="' . api_get_self() . '?' . api_get_cidreq() . '&forumcategory='
  386. . Security::remove_XSS($_GET['forumcategory'])
  387. . '&action=edit&content=forum&id=' . $forum['forum_id'] . '">'
  388. . Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL) . '</a>';
  389. $html .= '<a href="' . api_get_self() . '?' . api_get_cidreq() . '&forumcategory='
  390. . Security::remove_XSS($_GET['forumcategory'])
  391. . '&action=delete&content=forum&id=' . $forum['forum_id']
  392. . "\" onclick=\"javascript:if(!confirm('"
  393. . addslashes(api_htmlentities(get_lang('DeleteForum'), ENT_QUOTES))
  394. . "')) return false;\">"
  395. . Display::return_icon('delete.png', get_lang('Delete'), array(), ICON_SIZE_SMALL)
  396. . '</a>';
  397. $html .= return_visible_invisible_icon(
  398. 'forum',
  399. $forum['forum_id'],
  400. $forum['visibility'],
  401. array('forumcategory' => $_GET['forumcategory'])
  402. );
  403. $html .= return_lock_unlock_icon(
  404. 'forum',
  405. $forum['forum_id'],
  406. $forum['locked'],
  407. array('forumcategory' => $_GET['forumcategory'])
  408. );
  409. $html .= return_up_down_icon('forum', $forum['forum_id'], $forums_in_category);
  410. }
  411. $iconnotify = 'notification_mail_na.png';
  412. if (is_array(isset($_SESSION['forum_notification']['forum']) ? $_SESSION['forum_notification']['forum'] : null)) {
  413. if (in_array($forum['forum_id'],$_SESSION['forum_notification']['forum'])) {
  414. $iconnotify = 'notification_mail.png';
  415. }
  416. }
  417. if (!api_is_anonymous()) {
  418. $html .= '<a href="' . api_get_self() . '?' . api_get_cidreq() . '&forumcategory='
  419. . Security::remove_XSS($_GET['forumcategory']) . '&action=notify&content=forum&id='
  420. . $forum['forum_id'] . '">' . Display::return_icon($iconnotify, get_lang('NotifyMe')) . '</a>';
  421. }
  422. $html .= '</div>';
  423. $html .= '</div>';
  424. $html .= '</div>';
  425. $html .= '</div>';
  426. $html .= '</div></div>';
  427. }
  428. echo $html;
  429. }
  430. }
  431. if (count($forum_list) == 0) {
  432. echo '<div class="alert alert-warning">'.get_lang('NoForumInThisCategory').'</div>';
  433. }
  434. echo '</div>';
  435. }
  436. /* FOOTER */
  437. if ($origin != 'learnpath') {
  438. Display::display_footer();
  439. }