viewforumcategory.php 20 KB

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