viewforumcategory.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  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. $action = isset($_GET['action']) ? $_GET['action'] : '';
  41. // Including necessary files
  42. require 'forumconfig.inc.php';
  43. require_once 'forumfunction.inc.php';
  44. // Are we in a lp ?
  45. $origin = api_get_origin();
  46. if (api_is_in_gradebook()) {
  47. $interbreadcrumb[] = array(
  48. 'url' => Category::getUrl(),
  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='.Security::remove_XSS(urlencode(isset($_GET['search']) ? $_GET['search'] : '')),
  56. 'name' => get_lang('Forum')
  57. );
  58. if (!empty($action) && !empty($_GET['content'])) {
  59. if ($action == 'add' && $_GET['content'] == 'forum') {
  60. $interbreadcrumb[] = array(
  61. 'url' => 'viewforumcategory.php?'.api_get_cidreq().'&forumcategory='.$current_forum_category['cat_id'],
  62. 'name' => $current_forum_category['cat_title']
  63. );
  64. $interbreadcrumb[] = array(
  65. 'url' =>'#',
  66. 'name' => get_lang('AddForum')
  67. );
  68. }
  69. } else {
  70. $interbreadcrumb[] = array(
  71. 'url' => '#',
  72. 'name' => $current_forum_category['cat_title']
  73. );
  74. }
  75. if ($origin == 'learnpath') {
  76. Display::display_reduced_header();
  77. } else {
  78. Display::display_header(null);
  79. }
  80. /* ACTIONS */
  81. $whatsnew_post_info = isset($_SESSION['whatsnew_post_info']) ? $_SESSION['whatsnew_post_info'] : null;
  82. /* Is the user allowed here? */
  83. // if the user is not a course administrator and the forum is hidden
  84. // then the user is not allowed here.
  85. if (!api_is_allowed_to_edit(false, true) &&
  86. ($current_forum_category && $current_forum_category['visibility'] == 0)
  87. ) {
  88. api_not_allowed();
  89. }
  90. /* Action Links */
  91. $html = '<div class="actions">';
  92. $html .= '<a href="index.php?'.api_get_cidreq().'">'.
  93. Display::return_icon('back.png', get_lang('BackToForumOverview'), '', ICON_SIZE_MEDIUM).'</a>';
  94. if (api_is_allowed_to_edit(false, true)) {
  95. $html .= '<a href="'.api_get_path(WEB_CODE_PATH).'forum/index.php?'.api_get_cidreq().'&forumcategory='
  96. . $current_forum_category['cat_id'].'&action=add&content=forum"> '
  97. . Display::return_icon('new_forum.png', get_lang('AddForum'), '', ICON_SIZE_MEDIUM).'</a>';
  98. }
  99. $html .= search_link();
  100. $html .= '</div>';
  101. /* ACTIONS */
  102. echo $html;
  103. if (api_is_allowed_to_edit(false, true)) {
  104. handle_forum_and_forumcategories();
  105. }
  106. // Notification
  107. if ($action == 'notify' && isset($_GET['content']) && isset($_GET['id'])) {
  108. $return_message = set_notification($_GET['content'], $_GET['id']);
  109. echo Display::return_message($return_message, 'confirm', false);
  110. }
  111. if ($action != 'add') {
  112. /*
  113. RETRIEVING ALL THE FORUM CATEGORIES AND FORUMS
  114. Note: We do this here just after het handling of the actions to be sure that we already incorporate the
  115. latest changes.
  116. */
  117. // Step 1: We store all the forum categories in an array $forum_categories.
  118. $forum_categories = array();
  119. $forum_category = get_forum_categories($_GET['forumcategory']);
  120. // Step 2: We find all the forums.
  121. $forum_list = get_forums();
  122. /* RETRIEVING ALL GROUPS AND THOSE OF THE USER */
  123. // The groups of the user.
  124. $groups_of_user = array();
  125. $groups_of_user = GroupManager::get_group_ids($_course['real_id'], $_user['user_id']);
  126. // All groups in the course (and sorting them as the id of the group = the key of the array.
  127. $all_groups = GroupManager::get_group_list();
  128. if (is_array($all_groups)) {
  129. foreach ($all_groups as $group) {
  130. $all_groups[$group['id']] = $group;
  131. }
  132. }
  133. /* Display Forum Categories and the Forums in it */
  134. $html = '';
  135. $html .= '<div class="category-forum">';
  136. if ((!isset($sessionId) || $sessionId == 0) &&
  137. !empty($forum_category['session_name'])
  138. ) {
  139. $session_displayed = ' ('.Security::remove_XSS($forum_category['session_name']).')';
  140. } else {
  141. $session_displayed = '';
  142. }
  143. $forum_categories_list = '';
  144. $forumId = $forum_category['cat_id'];
  145. $forumTitle = $forum_category['cat_title'];
  146. $linkForumCategory = 'viewforumcategory.php?'.api_get_cidreq().'&forumcategory='.strval(intval($forumId));
  147. $descriptionCategory = $forum_category['cat_comment'];
  148. $icoCategory = Display::return_icon(
  149. 'forum_blue.png',
  150. get_lang($forum_category['cat_title']),
  151. array('class' => ''),
  152. ICON_SIZE_MEDIUM
  153. );
  154. if (api_is_allowed_to_edit(false, true) &&
  155. !($forum_category['session_id'] == 0 && $sessionId != 0)
  156. ) {
  157. $iconsEdit = '<a href="'.api_get_self().'?'.api_get_cidreq().'&forumcategory='
  158. . Security::remove_XSS($_GET['forumcategory']).'&action=edit&content=forumcategory&id='
  159. . ''.$forumId.'">'
  160. . Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL).'</a>';
  161. $iconsEdit .= '<a href="'.api_get_self().'?'.api_get_cidreq().'&forumcategory='
  162. . Security::remove_XSS($_GET['forumcategory'])
  163. . '&action=delete&content=forumcategory&id='.$forumId
  164. . "\" onclick=\"javascript:if(!confirm('"
  165. . addslashes(api_htmlentities(get_lang('DeleteForumCategory'), ENT_QUOTES))
  166. . "')) return false;\">".Display::return_icon('delete.png', get_lang('Delete'), array(), ICON_SIZE_SMALL)
  167. . '</a>';
  168. $iconsEdit .= return_visible_invisible_icon(
  169. 'forumcategory',
  170. $forum_category['cat_id'],
  171. $forum_category['visibility'],
  172. array('forumcategory' => $_GET['forumcategory'])
  173. );
  174. $iconsEdit .= return_lock_unlock_icon(
  175. 'forumcategory',
  176. $forum_category['cat_id'],
  177. $forum_category['locked'],
  178. array('forumcategory' => $_GET['forumcategory'])
  179. );
  180. $iconsEdit .= return_up_down_icon(
  181. 'forumcategory',
  182. $forum_category['cat_id'],
  183. $forum_categories_list
  184. );
  185. $html .= Display::tag(
  186. 'div',
  187. $iconsEdit,
  188. array('class' => 'pull-right')
  189. );
  190. }
  191. $session_img = api_get_session_image($forum_category['session_id'], $_user['status']);
  192. $html .= Display::tag(
  193. 'h3',
  194. $icoCategory.
  195. Display::tag(
  196. 'a',
  197. $forumTitle,
  198. array(
  199. 'href'=>$linkForumCategory,
  200. 'class' => empty($forum_category['visibility']) ? 'text-muted' : null
  201. )
  202. ).$session_displayed.$session_img,
  203. null
  204. );
  205. if ($descriptionCategory != '' && trim($descriptionCategory) != '&nbsp;') {
  206. $html .= '<div class="forum-description">'.$descriptionCategory.'</div>';
  207. }
  208. $html .= '</div>';
  209. echo $html;
  210. echo '<div class="forum_display">';
  211. // The forums in this category.
  212. $forums_in_category = get_forums_in_category($forum_category['cat_id']);
  213. // Step 4: We display all the forums in this category.
  214. $forum_count = 0;
  215. foreach ($forum_list as $forum) {
  216. if (!empty($forum['forum_category'])) {
  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. $form_count = isset($form_count) ? $form_count : 0;
  259. if ($show_forum === true) {
  260. $form_count++;
  261. $html = '<div class="panel panel-default forum">';
  262. $html .= '<div class="panel-body">';
  263. $my_whatsnew_post_info = isset($whatsnew_post_info[$forum['forum_id']]) ? $whatsnew_post_info[$forum['forum_id']] : null;
  264. if ($forum['forum_of_group'] == '0') {
  265. $forum_image = Display::return_icon(
  266. 'forum_group.png',
  267. get_lang('GroupForum'),
  268. null,
  269. ICON_SIZE_LARGE
  270. );
  271. } else {
  272. $forum_image = Display::return_icon(
  273. 'forum.png',
  274. get_lang('Forum'),
  275. null,
  276. ICON_SIZE_LARGE
  277. );
  278. }
  279. if ($forum['forum_of_group'] != '0') {
  280. $my_all_groups_forum_name = isset($all_groups[$forum['forum_of_group']]['name'])
  281. ? $all_groups[$forum['forum_of_group']]['name']
  282. : null;
  283. $my_all_groups_forum_id = isset($all_groups[$forum['forum_of_group']]['id'])
  284. ? $all_groups[$forum['forum_of_group']]['id']
  285. : null;
  286. $group_title = api_substr($my_all_groups_forum_name, 0, 30);
  287. $forum_title_group_addition = ' (<a href="../group/group_space.php?'.api_get_cidreq()
  288. . '&gidReq='.$my_all_groups_forum_id.'" class="forum_group_link">'
  289. . get_lang('GoTo').' '.$group_title.'</a>)';
  290. } else {
  291. $forum_title_group_addition = '';
  292. }
  293. if (!empty($sessionId) && !empty($forum['session_name'])) {
  294. $session_displayed = ' ('.$forum['session_name'].')';
  295. } else {
  296. $session_displayed = '';
  297. }
  298. // the number of topics and posts
  299. $my_number_threads = isset($forum['number_of_threads']) ? $forum['number_of_threads'] : 0;
  300. $my_number_posts = isset($forum['number_of_posts']) ? $forum['number_of_posts'] : 0;
  301. $html .= '<div class="row">';
  302. $html .= '<div class="col-md-6">';
  303. $html .= '<div class="col-md-3">';
  304. $html .= '<div class="number-post">'.$forum_image.'<p>'.$my_number_threads.' '.get_lang('ForumThreads').'</p></div>';
  305. $html .= '</div>';
  306. $html .= '<div class="col-md-9">';
  307. $iconForum = Display::return_icon(
  308. 'forum_yellow.png',
  309. get_lang($forum_category['cat_title']),
  310. null,
  311. ICON_SIZE_MEDIUM
  312. );
  313. $linkForum = '';
  314. $linkForum .= Display::tag(
  315. 'a',
  316. $forum['forum_title'].$session_displayed,
  317. array(
  318. 'href' => 'viewforum.php?'.api_get_cidreq()
  319. . "&gidReq={$forum['forum_of_group']}&forum={$forum['forum_id']}&search="
  320. . Security::remove_XSS(urlencode(isset($_GET['search']) ? $_GET['search'] : '')),
  321. 'class' => empty($forum['visibility']) ? 'text-muted' : null
  322. )
  323. );
  324. $html .= Display::tag(
  325. 'h3',
  326. $linkForum.' '.$forum_title_group_addition,
  327. array(
  328. 'class' => 'title'
  329. )
  330. );
  331. $html .= Display::tag(
  332. 'p',
  333. strip_tags($forum['forum_comment']),
  334. array(
  335. 'class' => 'description'
  336. )
  337. );
  338. if ($forum['moderated'] == 1 && api_is_allowed_to_edit(false, true)) {
  339. $waitingCount = getCountPostsWithStatus(
  340. CForumPost::STATUS_WAITING_MODERATION,
  341. $forum
  342. );
  343. if (!empty($waitingCount)) {
  344. $html .= Display::label(
  345. get_lang('PostsPendingModeration').': '.$waitingCount,
  346. 'warning'
  347. );
  348. }
  349. }
  350. $html .= '</div>';
  351. $html .= '</div>';
  352. $html .= '<div class="col-md-6">';
  353. $iconEmpty = '';
  354. // The number of topics and posts.
  355. if ($forum['forum_of_group'] !== '0') {
  356. $newPost = '';
  357. if (is_array($my_whatsnew_post_info) && !empty($my_whatsnew_post_info)) {
  358. $newPost = ' '.Display::return_icon('alert.png', get_lang('Forum'), null, ICON_SIZE_SMALL);
  359. } else {
  360. $newPost = $iconEmpty;
  361. }
  362. } else {
  363. if (is_array($my_whatsnew_post_info) && !empty($my_whatsnew_post_info)) {
  364. $newPost = ' '.Display::return_icon('alert.png', get_lang('Forum'), null, ICON_SIZE_SMALL);
  365. } else {
  366. $newPost = $iconEmpty;
  367. }
  368. }
  369. $html .= '<div class="row">';
  370. $html .= '<div class="col-md-2">';
  371. $html .= $newPost.'</div>';
  372. $poster_id = 0;
  373. $name = '';
  374. // the last post in the forum
  375. if (isset($forum['last_poster_name']) && $forum['last_poster_name'] != '') {
  376. $name = $forum['last_poster_name'];
  377. } else {
  378. if (isset($forum['last_poster_lastname'])) {
  379. $name = api_get_person_name($forum['last_poster_firstname'], $forum['last_poster_lastname']);
  380. $poster_id = $forum['last_poster_id'];
  381. }
  382. }
  383. $html .= '<div class="col-md-6">';
  384. if (!empty($forum['last_post_id'])) {
  385. $html .= Display::return_icon('post-item.png', null, null, ICON_SIZE_TINY).' ';
  386. $html .= api_convert_and_format_date($forum['last_post_date'])
  387. . ' '.get_lang('By').' '
  388. . display_user_link($poster_id, $name);
  389. }
  390. $html .= '</div>';
  391. $html .= '<div class="col-md-4">';
  392. $url = api_get_path(WEB_CODE_PATH).'forum/index.php';
  393. $forumCategoryId = (int) $_GET['forumcategory'];
  394. if (api_is_allowed_to_edit(false, true) &&
  395. !($forum['session_id'] == 0 && $sessionId != 0)
  396. ) {
  397. $html .= '<a href="'.$url.'?'.api_get_cidreq().'&forumcategory='.$forumCategoryId.'&action=edit&content=forum&id='.$forum['forum_id'].'">'
  398. . Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL).'</a>';
  399. $html .= '<a href="'.$url.'?'.api_get_cidreq().'&forumcategory='.$forumCategoryId.'&action=delete&content=forum&id='.$forum['forum_id']
  400. . "\" onclick=\"javascript:if(!confirm('"
  401. . addslashes(api_htmlentities(get_lang('DeleteForum'), ENT_QUOTES))
  402. . "')) return false;\">"
  403. . Display::return_icon('delete.png', get_lang('Delete'), array(), ICON_SIZE_SMALL)
  404. . '</a>';
  405. $html .= return_visible_invisible_icon(
  406. 'forum',
  407. $forum['forum_id'],
  408. $forum['visibility'],
  409. array('forumcategory' => $_GET['forumcategory'])
  410. );
  411. $html .= return_lock_unlock_icon(
  412. 'forum',
  413. $forum['forum_id'],
  414. $forum['locked'],
  415. array('forumcategory' => $_GET['forumcategory'])
  416. );
  417. $html .= return_up_down_icon(
  418. 'forum',
  419. $forum['forum_id'],
  420. $forums_in_category
  421. );
  422. }
  423. $iconnotify = 'notification_mail_na.png';
  424. if (is_array(isset($_SESSION['forum_notification']['forum']) ? $_SESSION['forum_notification']['forum'] : null)) {
  425. if (in_array($forum['forum_id'], $_SESSION['forum_notification']['forum'])) {
  426. $iconnotify = 'notification_mail.png';
  427. }
  428. }
  429. if (!api_is_anonymous()) {
  430. $html .= '<a href="'.$url.'?'.api_get_cidreq().'&forumcategory='.$forumCategoryId.'&action=notify&content=forum&id='.$forum['forum_id'].'">'.
  431. Display::return_icon($iconnotify, get_lang('NotifyMe')).
  432. '</a>';
  433. }
  434. $html .= '</div>';
  435. $html .= '</div>';
  436. $html .= '</div>';
  437. $html .= '</div>';
  438. $html .= '</div></div>';
  439. }
  440. echo $html;
  441. }
  442. }
  443. }
  444. if (count($forum_list) == 0) {
  445. echo '<div class="alert alert-warning">'.get_lang('NoForumInThisCategory').'</div>';
  446. }
  447. echo '</div>';
  448. }
  449. /* FOOTER */
  450. if ($origin != 'learnpath') {
  451. Display::display_footer();
  452. }