viewforum.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693
  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. use ChamiloSession as Session;
  24. // Including the global initialization file.
  25. require_once '../inc/global.inc.php';
  26. $current_course_tool = TOOL_FORUM;
  27. // Notification for unauthorized people.
  28. api_protect_course_script(true);
  29. // The section (tabs).
  30. $this_section = SECTION_COURSES;
  31. $nameTools = get_lang('ToolForum');
  32. // Are we in a lp ?
  33. $origin = '';
  34. $origin_string = '';
  35. if (isset($_GET['origin'])) {
  36. $origin = Security::remove_XSS($_GET['origin']);
  37. $origin_string = '&origin='.$origin;
  38. }
  39. /* Including necessary files */
  40. require 'forumconfig.inc.php';
  41. require_once 'forumfunction.inc.php';
  42. $userid = api_get_user_id();
  43. /* MAIN DISPLAY SECTION */
  44. $groupId = api_get_group_id();
  45. $my_forum = isset($_GET['forum']) ? $_GET['forum'] : '';
  46. // Note: This has to be validated that it is an existing forum.
  47. $current_forum = get_forum_information($my_forum);
  48. if (empty($current_forum)) {
  49. api_not_allowed();
  50. }
  51. $current_forum_category = get_forumcategory_information($current_forum['forum_category']);
  52. $is_group_tutor = false;
  53. if (!empty($groupId)) {
  54. //Group info & group category info
  55. $group_properties = GroupManager::get_group_properties($groupId);
  56. //User has access in the group?
  57. $user_has_access_in_group = GroupManager::user_has_access($userid, $groupId, GroupManager::GROUP_TOOL_FORUM);
  58. $is_group_tutor = GroupManager::is_tutor_of_group(api_get_user_id(), $groupId);
  59. //Course
  60. if (
  61. !api_is_allowed_to_edit(false, true) AND //is a student
  62. (($current_forum_category && $current_forum_category['visibility'] == 0) OR
  63. $current_forum['visibility'] == 0 OR !$user_has_access_in_group)
  64. ) {
  65. api_not_allowed(true);
  66. }
  67. } else {
  68. //Course
  69. if (
  70. !api_is_allowed_to_edit(false, true) AND //is a student
  71. (
  72. ($current_forum_category && $current_forum_category['visibility'] == 0) OR
  73. $current_forum['visibility'] == 0
  74. ) //forum category or forum visibility is false
  75. ) {
  76. api_not_allowed();
  77. }
  78. }
  79. /* Header and Breadcrumbs */
  80. $my_search = isset($_GET['search']) ? $_GET['search'] : '';
  81. $my_action = isset($_GET['action']) ? $_GET['action'] : '';
  82. $gradebook = null;
  83. if (isset($_SESSION['gradebook'])){
  84. $gradebook = $_SESSION['gradebook'];
  85. }
  86. if (!empty($gradebook) && $gradebook == 'view') {
  87. $interbreadcrumb[] = array (
  88. 'url' => '../gradebook/'.$_SESSION['gradebook_dest'],
  89. 'name' => get_lang('ToolGradebook')
  90. );
  91. }
  92. if (!empty($_GET['gidReq'])) {
  93. $toolgroup = Database::escape_string($_GET['gidReq']);
  94. Session::write('toolgroup',$toolgroup);
  95. }
  96. $forumUrl = api_get_path(WEB_CODE_PATH).'forum/';
  97. if ($origin == 'group') {
  98. $interbreadcrumb[] = array(
  99. 'url' => api_get_path(WEB_CODE_PATH) . 'group/group.php',
  100. 'name' => get_lang('Groups')
  101. );
  102. $interbreadcrumb[] = array(
  103. 'url' => api_get_path(WEB_CODE_PATH) . 'group/group_space.php?' . api_get_cidreq(),
  104. 'name' => get_lang('GroupSpace') . ' ' . $group_properties['name']
  105. );
  106. $interbreadcrumb[] = array(
  107. 'url' => '#',
  108. 'name' => get_lang('Forum') . ' ' . Security::remove_XSS($current_forum['forum_title'])
  109. );
  110. } else {
  111. $interbreadcrumb[] = array(
  112. 'url' => $forumUrl . 'index.php?search=' . Security::remove_XSS($my_search),
  113. 'name' => get_lang('ForumCategories')
  114. );
  115. $interbreadcrumb[] = array(
  116. 'url' => $forumUrl . 'viewforumcategory.php?forumcategory=' . $current_forum_category['cat_id']
  117. . '&search=' . Security::remove_XSS(urlencode($my_search)),
  118. 'name' => prepare4display($current_forum_category['cat_title'])
  119. );
  120. $interbreadcrumb[] = array(
  121. 'url' => '#',
  122. 'name' => Security::remove_XSS($current_forum['forum_title'])
  123. );
  124. }
  125. if ($origin == 'learnpath') {
  126. Display::display_reduced_header();
  127. } else {
  128. // The last element of the breadcrumb navigation is already set in interbreadcrumb, so give empty string.
  129. Display::display_header('');
  130. }
  131. /* Actions */
  132. // Change visibility of a forum or a forum category.
  133. if (
  134. ($my_action == 'invisible' OR $my_action == 'visible') AND
  135. isset($_GET['content']) AND
  136. isset($_GET['id']) AND
  137. api_is_allowed_to_edit(false, true) &&
  138. api_is_allowed_to_session_edit(false, true)
  139. ) {
  140. $message = change_visibility($_GET['content'], $_GET['id'], $_GET['action']);
  141. }
  142. // Locking and unlocking.
  143. if (
  144. ($my_action == 'lock' OR $my_action == 'unlock') AND
  145. isset($_GET['content']) AND isset($_GET['id']) AND
  146. api_is_allowed_to_edit(false, true) &&
  147. api_is_allowed_to_session_edit(false, true)
  148. ) {
  149. $message = change_lock_status($_GET['content'], $_GET['id'], $my_action);
  150. }
  151. // Deleting.
  152. if (
  153. $my_action == 'delete' AND
  154. isset($_GET['content']) AND
  155. isset($_GET['id']) AND
  156. api_is_allowed_to_edit(false, true) &&
  157. api_is_allowed_to_session_edit(false, true)
  158. ) {
  159. $locked = api_resource_is_locked_by_gradebook($_GET['id'], LINK_FORUM_THREAD);
  160. if ($locked == false) {
  161. $message = deleteForumCategoryThread($_GET['content'], $_GET['id']);
  162. // Delete link
  163. $link_info = GradebookUtils::is_resource_in_course_gradebook(
  164. api_get_course_id(),
  165. 5,
  166. intval($_GET['id']),
  167. api_get_session_id()
  168. );
  169. $link_id = $link_info['id'];
  170. if ($link_info !== false) {
  171. GradebookUtils::remove_resource_from_course_gradebook($link_id);
  172. }
  173. }
  174. }
  175. // Moving.
  176. if ($my_action == 'move' && isset($_GET['thread']) &&
  177. api_is_allowed_to_edit(false, true ) &&
  178. api_is_allowed_to_session_edit(false, true)
  179. ) {
  180. $message = move_thread_form();
  181. }
  182. // Notification.
  183. if (
  184. $my_action == 'notify' &&
  185. isset($_GET['content']) &&
  186. isset($_GET['id']) &&
  187. api_is_allowed_to_session_edit(false, true)
  188. ) {
  189. $return_message = set_notification($_GET['content'], $_GET['id']);
  190. Display::display_confirmation_message($return_message, false);
  191. }
  192. // Student list
  193. if (
  194. $my_action == 'liststd' &&
  195. isset($_GET['content']) &&
  196. isset($_GET['id']) &&
  197. (api_is_allowed_to_edit(null, true) || $is_group_tutor)
  198. ) {
  199. $active = null;
  200. $listType = isset($_GET['list']) ? $_GET['list'] : null;
  201. switch ($listType) {
  202. case 'qualify':
  203. $student_list = get_thread_users_qualify($_GET['id']);
  204. $nrorow3 = -2;
  205. $active = 2;
  206. break;
  207. case 'notqualify':
  208. $student_list = get_thread_users_not_qualify($_GET['id']);
  209. $nrorow3 = -2;
  210. $active = 3;
  211. break;
  212. default:
  213. $student_list = get_thread_users_details($_GET['id']);
  214. $nrorow3 = Database::num_rows($student_list);
  215. $active = 1;
  216. break;
  217. }
  218. $table_list = Display::page_subheader(get_lang('ThreadUsersList') . ': ' . get_name_thread_by_id($_GET['id']));
  219. if ($nrorow3 > 0 || $nrorow3 == -2) {
  220. $url = 'cidReq=' . Security::remove_XSS($_GET['cidReq']) .
  221. '&forum=' . Security::remove_XSS($my_forum) . '&action='
  222. . Security::remove_XSS($_GET['action']) . '&content='
  223. . Security::remove_XSS($_GET['content'], STUDENT) . '&id=' . intval($_GET['id']);
  224. $tabs = array(
  225. array(
  226. 'content' => get_lang('AllStudents'),
  227. 'url' => $forumUrl . 'viewforum.php?' . $url . '&origin=' . $origin . '&list=all'
  228. ),
  229. array(
  230. 'content' => get_lang('StudentsQualified'),
  231. 'url' => $forumUrl . 'viewforum.php?' . $url . '&origin=' . $origin . '&list=qualify'
  232. ),
  233. array(
  234. 'content' => get_lang('StudentsNotQualified'),
  235. 'url' => $forumUrl . 'viewforum.php?' . $url . '&origin=' . $origin . '&list=notqualify'
  236. ),
  237. );
  238. $table_list .= Display::tabsOnlyLink($tabs, $active);
  239. $icon_qualify = 'blog_new.gif';
  240. $table_list .= '<center><br /><table class="data_table" style="width:50%">';
  241. // The column headers (TODO: Make this sortable).
  242. $table_list .= '<tr >';
  243. $table_list .= '<th height="24">' . get_lang('NamesAndLastNames') . '</th>';
  244. if ($listType == 'qualify') {
  245. $table_list .= '<th>' . get_lang('Qualification') . '</th>';
  246. }
  247. if (api_is_allowed_to_edit(null, true)) {
  248. $table_list .= '<th>' . get_lang('Qualify') . '</th>';
  249. }
  250. $table_list .= '</tr>';
  251. $max_qualify = showQualify('2', $userid, $_GET['id']);
  252. $counter_stdlist = 0;
  253. if (Database::num_rows($student_list) > 0) {
  254. while ($row_student_list=Database::fetch_array($student_list)) {
  255. $userInfo = api_get_user_info($row_student_list['id']);
  256. if ($counter_stdlist % 2 == 0) {
  257. $class_stdlist = 'row_odd';
  258. } else {
  259. $class_stdlist = 'row_even';
  260. }
  261. $table_list .= '<tr class="' . $class_stdlist . '"><td>';
  262. $table_list .= UserManager::getUserProfileLink($userInfo);
  263. $table_list .= '</td>';
  264. if ($listType == 'qualify') {
  265. $table_list .= '<td>' . $row_student_list['qualify'] . '/' . $max_qualify . '</td>';
  266. }
  267. if (api_is_allowed_to_edit(null, true)) {
  268. $current_qualify_thread = showQualify(
  269. '1',
  270. $row_student_list['id'],
  271. $_GET['id']
  272. );
  273. $table_list .= '<td>
  274. <a href="' . $forumUrl . 'forumqualify.php?' . api_get_cidreq()
  275. . '&forum=' . Security::remove_XSS($my_forum) . '&thread='
  276. . Security::remove_XSS($_GET['id']) . '&user=' . $row_student_list['id']
  277. . '&user_id=' . $row_student_list['id'] . '&idtextqualify='
  278. . $current_qualify_thread . '&origin=' . $origin . '">'
  279. . Display::return_icon($icon_qualify, get_lang('Qualify')) . '</a></td></tr>';
  280. }
  281. $counter_stdlist++;
  282. }
  283. } else {
  284. if ($listType == 'qualify') {
  285. $table_list .= '<tr><td colspan="2">' . get_lang('ThereIsNotQualifiedLearners') . '</td></tr>';
  286. } else {
  287. $table_list .= '<tr><td colspan="2">' . get_lang('ThereIsNotUnqualifiedLearners') . '</td></tr>';
  288. }
  289. }
  290. $table_list .= '</table></center>';
  291. $table_list .= '<br />';
  292. } else {
  293. $table_list .= Display::return_message(get_lang('NoParticipation'), 'warning');
  294. }
  295. }
  296. if ($origin == 'learnpath') {
  297. echo '<div style="height:15px">&nbsp;</div>';
  298. }
  299. /* Display the action messages */
  300. if (!empty($message)) {
  301. Display::display_confirmation_message($message);
  302. }
  303. /* Action links */
  304. echo '<div class="actions">';
  305. if ($origin != 'learnpath') {
  306. if ($origin=='group') {
  307. echo '<a href"=' . api_get_path(WEB_CODE_PATH) . 'group/group_space.php?'
  308. . api_get_cidreq() . '&gradebook=' . $gradebook . '">'
  309. . Display::return_icon('back.png', get_lang('BackTo')
  310. . ' ' . get_lang('Groups'), '', ICON_SIZE_MEDIUM) . '</a>';
  311. } else {
  312. echo '<span style="float:right;">'.search_link().'</span>';
  313. echo '<a href="' . $forumUrl . 'index.php?' . api_get_cidreq() . '">'
  314. . Display::return_icon('back.png', get_lang('BackToForumOverview'), '', ICON_SIZE_MEDIUM)
  315. . '</a>';
  316. }
  317. }
  318. // The link should appear when
  319. // 1. the course admin is here
  320. // 2. the course member is here and new threads are allowed
  321. // 3. a visitor is here and new threads AND allowed AND anonymous posts are allowed
  322. if (
  323. api_is_allowed_to_edit(false, true) OR
  324. ($current_forum['allow_new_threads'] == 1 AND isset($_user['user_id'])) OR
  325. ($current_forum['allow_new_threads'] == 1 AND !isset($_user['user_id']) AND $current_forum['allow_anonymous'] == 1)
  326. ) {
  327. if ($current_forum['locked'] <> 1 AND $current_forum['locked'] <> 1) {
  328. if (!api_is_anonymous() && !api_is_invitee()) {
  329. if ($my_forum == strval(intval($my_forum))) {
  330. echo '<a href="' . $forumUrl . 'newthread.php?' . api_get_cidreq() . '&forum='
  331. . Security::remove_XSS($my_forum) . $origin_string . '">'
  332. . Display::return_icon('new_thread.png', get_lang('NewTopic'), '', ICON_SIZE_MEDIUM)
  333. . '</a>';
  334. } else {
  335. $my_forum = strval(intval($my_forum));
  336. echo '<a href="' . $forumUrl . 'newthread.php?' . api_get_cidreq()
  337. . '&forum=' . $my_forum . $origin_string . '">'
  338. . Display::return_icon('new_thread.png', get_lang('NewTopic'), '', ICON_SIZE_MEDIUM)
  339. . '</a>';
  340. }
  341. }
  342. } else {
  343. echo get_lang('ForumLocked');
  344. }
  345. }
  346. echo '</div>';
  347. /* Display */
  348. $titleForum = $current_forum['forum_title'];
  349. $descriptionForum = $current_forum['forum_comment'];
  350. $iconForum = Display::return_icon(
  351. 'forum_yellow.png',
  352. get_lang('Forum'),
  353. null,
  354. ICON_SIZE_MEDIUM
  355. );
  356. $html = '';
  357. $html .= '<div class="topic-forum">';
  358. // The current forum
  359. if ($origin != 'learnpath') {
  360. $html .= Display::tag(
  361. 'h3',
  362. $iconForum .' '. $titleForum,
  363. array(
  364. 'class' => 'title-forum')
  365. );
  366. if (!empty($descriptionForum)) {
  367. $html .= Display::tag(
  368. 'p',
  369. strip_tags($descriptionForum),
  370. array(
  371. 'class' => 'description',
  372. )
  373. );
  374. }
  375. }
  376. $html .= '</div>';
  377. echo $html;
  378. // Getting al the threads
  379. $threads = get_threads($my_forum);
  380. $whatsnew_post_info = isset($_SESSION['whatsnew_post_info']) ? $_SESSION['whatsnew_post_info'] : null;
  381. $course_id = api_get_course_int_id();
  382. echo '<div class="forum_display">';
  383. if (is_array($threads)) {
  384. $html = '';
  385. $count = 1;
  386. foreach ($threads as $row) {
  387. // Thread who have no replies yet and the only post is invisible should not be displayed to students.
  388. if (api_is_allowed_to_edit(false, true) ||
  389. !($row['thread_replies'] == '0' AND $row['visibility'] == '0')
  390. ) {
  391. $my_whatsnew_post_info = null;
  392. if (isset($whatsnew_post_info[$my_forum][$row['thread_id']])) {
  393. $my_whatsnew_post_info = $whatsnew_post_info[$my_forum][$row['thread_id']];
  394. }
  395. if (is_array($my_whatsnew_post_info) && !empty($my_whatsnew_post_info)) {
  396. $newPost = ' ' . Display::return_icon('alert.png', get_lang('Forum'), null, ICON_SIZE_SMALL);
  397. } else {
  398. $newPost = '';
  399. }
  400. if ($row['thread_sticky'] == 1) {
  401. //$sticky = Display::return_icon('exclamation.gif');
  402. }
  403. $name = api_get_person_name($row['firstname'], $row['lastname']);
  404. $linkPostForum = '<a href="viewthread.php?' . api_get_cidreq() . '&forum=' . Security::remove_XSS($my_forum)
  405. . "&origin=$origin&thread={$row['thread_id']}$origin_string&search="
  406. . Security::remove_XSS(urlencode($my_search)) . '">'
  407. . $row['thread_title'] . '</a>';
  408. $html = '';
  409. $html .= '<div class="panel panel-default forum '.($row['thread_sticky']?'sticky':'').'">';
  410. $html .= '<div class="panel-body">';
  411. $html .= '<div class="row">';
  412. $html .= '<div class="col-md-6">';
  413. $html .= '<div class="row">';
  414. $html .= '<div class="col-md-2">';
  415. // display the author name
  416. $tab_poster_info = api_get_user_info($row['user_id']);
  417. $poster_username = sprintf(get_lang('LoginX'), $tab_poster_info['username']);
  418. $authorName = '';
  419. if ($origin != 'learnpath') {
  420. $authorName = display_user_link(
  421. $row['user_id'],
  422. api_get_person_name($row['firstname'],
  423. $row['lastname']),
  424. '',
  425. $poster_username
  426. );
  427. } else {
  428. $authorName = Display::tag(
  429. 'span',
  430. api_get_person_name(
  431. $row['firstname'],
  432. $row['lastname']
  433. ),
  434. array(
  435. "title" => api_htmlentities($poster_username, ENT_QUOTES)
  436. )
  437. );
  438. }
  439. $html .= '<div class="thumbnail">' . display_user_image($row['user_id'], $name) . '</div>';
  440. $html .= '</div>';
  441. $html .= '<div class="col-md-10">';
  442. $html .= Display::tag(
  443. 'h3',
  444. $linkPostForum,
  445. array(
  446. 'class' => 'title'
  447. )
  448. );
  449. $html .= '<p>'. get_lang('By') .' ' .$authorName.'</p>';
  450. $html .= '<p>' . api_convert_and_format_date($row['insert_date']) . '</p>';
  451. $html .= '</div>';
  452. $html .= '</div>';
  453. $html .= '</div>';
  454. $html .= '<div class="col-md-6">';
  455. $html .= '<div class="row">';
  456. $html .= '<div class="col-md-4">'
  457. . Display::return_icon('post-forum.png', null, null, ICON_SIZE_SMALL)
  458. . " {$row['thread_replies']} " . get_lang('Replies') . '<br>';
  459. $html .= Display::return_icon(
  460. 'post-forum.png',
  461. null,
  462. null,
  463. ICON_SIZE_SMALL
  464. ) . ' ' . $row['thread_views'] . ' ' . get_lang('Views') . '<br>' . $newPost;
  465. $html .= '</div>';
  466. $last_post_info = get_last_post_by_thread(
  467. $row['c_id'],
  468. $row['thread_id'],
  469. $row['forum_id'],
  470. api_is_allowed_to_edit()
  471. );
  472. $last_post = null;
  473. if ($last_post_info) {
  474. $poster_info = api_get_user_info($last_post_info['poster_id']);
  475. $post_date = api_convert_and_format_date($last_post_info['post_date']);
  476. $last_post = $post_date . '<br>' . get_lang('By') . ' ' . display_user_link(
  477. $last_post_info['poster_id'],
  478. $poster_info['complete_name'],
  479. '',
  480. $poster_info['username']
  481. );
  482. }
  483. $html .= '<div class="col-md-5">'
  484. . Display::return_icon('post-item.png', null, null, ICON_SIZE_TINY)
  485. . ' ' . $last_post;
  486. $html .= '</div>';
  487. /*
  488. if ($row['last_poster_user_id'] == '0') {
  489. $name = $row['poster_name'];
  490. $last_poster_username = "";
  491. } else {
  492. $name = api_get_person_name($row['last_poster_firstname'], $row['last_poster_lastname']);
  493. $tab_last_poster_info = api_get_user_info($row['last_poster_user_id']);
  494. $last_poster_username = sprintf(get_lang('LoginX'), $tab_last_poster_info['username']);
  495. }
  496. // If the last post is invisible and it is not the teacher who is looking then we have to find the last visible post of the thread.
  497. if (($row['visible'] == '1' OR api_is_allowed_to_edit(false, true)) && $origin != 'learnpath') {
  498. $last_post = $post_date.' '.get_lang('By').' '.display_user_link($row['last_poster_user_id'], $name, '', $last_poster_username);
  499. } elseif ($origin != 'learnpath') {
  500. $last_post_sql = "SELECT post.*, user.firstname, user.lastname, user.username FROM $table_posts post, $table_users user WHERE post.poster_id=user.user_id AND visible='1' AND thread_id='".$row['thread_id']."' AND post.c_id=".api_get_course_int_id()." ORDER BY post_id DESC";
  501. $last_post_result = Database::query($last_post_sql);
  502. $last_post_row = Database::fetch_array($last_post_result);
  503. $name = api_get_person_name($last_post_row['firstname'], $last_post_row['lastname']);
  504. $last_post_info_username = sprintf(get_lang('LoginX'), $last_post_row['username']);
  505. $last_post = api_convert_and_format_date($last_post_row['post_date']).' '.get_lang('By').' '.display_user_link($last_post_row['poster_id'], $name, '', $last_post_info_username);
  506. } else {
  507. $last_post_sql = "SELECT post.*, user.firstname, user.lastname, user.username FROM $table_posts post, $table_users user WHERE post.poster_id=user.user_id AND visible='1' AND thread_id='".$row['thread_id']."' AND post.c_id=".api_get_course_int_id()." ORDER BY post_id DESC";
  508. $last_post_result = Database::query($last_post_sql);
  509. $last_post_row = Database::fetch_array($last_post_result);
  510. $last_post_info_username = sprintf(get_lang('LoginX'), $last_post_row['username']);
  511. $name = api_get_person_name($last_post_row['firstname'], $last_post_row['lastname']);
  512. $last_post = api_convert_and_format_date($last_post_row['post_date']).' '.get_lang('By').' '.Display::tag('span', $name, array("title"=>api_htmlentities($last_post_info_username, ENT_QUOTES)));
  513. }*/
  514. $html .= '<div class="col-md-3">';
  515. // Get attachment id.
  516. if (isset($row['post_id'])) {
  517. $attachment_list = get_attachment($row['post_id']);
  518. }
  519. $id_attach = !empty($attachment_list) ? $attachment_list['id'] : '';
  520. $sql_post_id = "SELECT post_id
  521. FROM $table_posts
  522. WHERE
  523. c_id = $course_id AND
  524. post_title='" . Database::escape_string($row['thread_title']) . "'";
  525. $result_post_id = Database::query($sql_post_id);
  526. $row_post_id = Database::fetch_array($result_post_id);
  527. $iconsEdit = '';
  528. if ($origin != 'learnpath') {
  529. if (api_is_allowed_to_edit(false, true) && !(api_is_course_coach() && $current_forum['session_id'] != $_SESSION['id_session'])) {
  530. $iconsEdit .= '<a href="' . $forumUrl . 'editpost.php?' . api_get_cidreq()
  531. . '&forum=' . Security::remove_XSS($my_forum) . '&thread='
  532. . Security::remove_XSS($row['thread_id']) . '&post=' . $row_post_id['post_id']
  533. . '&id_attach=' . $id_attach . '">'
  534. . Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL) . '</a>';
  535. if (api_resource_is_locked_by_gradebook($row['thread_id'], LINK_FORUM_THREAD)) {
  536. $iconsEdit .= Display::return_icon(
  537. 'delete_na.png',
  538. get_lang('ResourceLockedByGradebook'),
  539. array(),
  540. ICON_SIZE_SMALL
  541. );
  542. } else {
  543. $iconsEdit.= '<a href="' . api_get_self() . '?' . api_get_cidreq() . '&forum='
  544. . Security::remove_XSS($my_forum) . '&action=delete&content=thread&id='
  545. . $row['thread_id'] . $origin_string
  546. . "\" onclick=\"javascript:if(!confirm('"
  547. . addslashes(api_htmlentities(get_lang('DeleteCompleteThread'), ENT_QUOTES))
  548. . "')) return false;\">"
  549. . Display::return_icon('delete.png', get_lang('Delete'), array(), ICON_SIZE_SMALL) . '</a>';
  550. }
  551. $iconsEdit .= return_visible_invisible_icon(
  552. 'thread',
  553. $row['thread_id'],
  554. $row['visibility'],
  555. array(
  556. 'forum' => $my_forum,
  557. 'origin' => $origin,
  558. 'gidReq' => $groupId
  559. )
  560. );
  561. $iconsEdit .= return_lock_unlock_icon(
  562. 'thread',
  563. $row['thread_id'],
  564. $row['locked'],
  565. array(
  566. 'forum' => $my_forum,
  567. 'origin' => $origin,
  568. 'gidReq' => api_get_group_id()
  569. )
  570. );
  571. $iconsEdit .= '<a href="viewforum.php?' . api_get_cidreq() . '&forum='
  572. . Security::remove_XSS($my_forum)
  573. . '&action=move&thread=' . $row['thread_id'] . $origin_string . '">'
  574. . Display::return_icon('move.png', get_lang('MoveThread'), array(), ICON_SIZE_SMALL)
  575. . '</a>';
  576. }
  577. }
  578. $iconnotify = 'notification_mail_na.png';
  579. if (
  580. is_array(
  581. isset($_SESSION['forum_notification']['thread']) ? $_SESSION['forum_notification']['thread'] : null
  582. )
  583. ) {
  584. if (in_array($row['thread_id'], $_SESSION['forum_notification']['thread'])) {
  585. $iconnotify = 'notification_mail.png';
  586. }
  587. }
  588. $icon_liststd = 'user.png';
  589. if (!api_is_anonymous() && api_is_allowed_to_session_edit(false, true)) {
  590. $iconsEdit .= '<a href="' . api_get_self() . '?' . api_get_cidreq() . '&forum='
  591. . Security::remove_XSS($my_forum)
  592. . "&origin=$origin&action=notify&content=thread&id={$row['thread_id']}"
  593. . '">' . Display::return_icon($iconnotify, get_lang('NotifyMe')) . '</a>';
  594. }
  595. if (api_is_allowed_to_edit(null,true) && $origin != 'learnpath') {
  596. $iconsEdit .= '<a href="' . api_get_self() . '?' . api_get_cidreq() . '&forum='
  597. . Security::remove_XSS($my_forum)
  598. . "&origin=$origin&action=liststd&content=thread&id={$row['thread_id']}"
  599. . '">' . Display::return_icon($icon_liststd, get_lang('StudentList'), array(), ICON_SIZE_SMALL)
  600. . '</a>';
  601. }
  602. $html .= $iconsEdit;
  603. $html .= '</div>';
  604. $html .= '</div>';
  605. $html .= '</div>';
  606. $html .= '</div>';
  607. $html .= '</div>';
  608. $html .= '</div>';
  609. echo $html;
  610. }
  611. $count++;
  612. }
  613. }
  614. echo '</div>';
  615. echo isset($table_list) ? $table_list : '';
  616. /* FOOTER */
  617. if ($origin != 'learnpath') {
  618. Display::display_footer();
  619. }