viewforumcategory.php 21 KB

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