viewforumcategory.php 20 KB

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