reply.php 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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. * @package chamilo.forum
  18. */
  19. // Language files that need to be included.
  20. $language_file = array('forum', 'document');
  21. // Including the global initialization file.
  22. require_once '../inc/global.inc.php';
  23. // The section (tabs).
  24. $this_section = SECTION_COURSES;
  25. // Notification for unauthorized people.
  26. api_protect_course_script(true);
  27. // Including additional library scripts.
  28. require_once api_get_path(LIBRARY_PATH).'groupmanager.lib.php';
  29. $nameTools = get_lang('ForumCategories');
  30. $origin = '';
  31. if (isset($_GET['origin'])) {
  32. $origin = Security::remove_XSS($_GET['origin']);
  33. $origin_string = '&amp;origin='.$origin;
  34. }
  35. /* Including necessary files */
  36. require_once 'forumconfig.inc.php';
  37. require_once 'forumfunction.inc.php';
  38. // javascript
  39. $htmlHeadXtra[] = '<script>
  40. function advanced_parameters() {
  41. if(document.getElementById(\'id_qualify\').style.display == \'none\') {
  42. document.getElementById(\'id_qualify\').style.display = \'block\';
  43. document.getElementById(\'img_plus_and_minus\').innerHTML=\'&nbsp;'.Display::return_icon('div_hide.gif',get_lang('Hide'),array('style'=>'vertical-align:middle')).'&nbsp;'.get_lang('AdvancedParameters').'\';
  44. } else {
  45. document.getElementById(\'id_qualify\').style.display = \'none\';
  46. document.getElementById(\'img_plus_and_minus\').innerHTML=\'&nbsp;'.Display::return_icon('div_show.gif',get_lang('Show'),array('style'=>'vertical-align:middle')).'&nbsp;'.get_lang('AdvancedParameters').'\';
  47. }
  48. }
  49. </script>';
  50. /* MAIN DISPLAY SECTION */
  51. /* Retrieving forum and forum categorie information */
  52. // We are getting all the information about the current forum and forum category.
  53. // Note pcool: I tried to use only one sql statement (and function) for this,
  54. // but the problem is that the visibility of the forum AND forum cateogory are stored in the item_property table.
  55. $current_thread = get_thread_information($_GET['thread']); // Note: This has to be validated that it is an existing thread.
  56. $current_forum = get_forum_information($current_thread['forum_id']); // Note: This has to be validated that it is an existing forum.
  57. $current_forum_category = get_forumcategory_information(Security::remove_XSS($current_forum['forum_category']));
  58. /* Breadcrumbs */
  59. if (isset($_SESSION['gradebook'])){
  60. $gradebook = Security::remove_XSS($_SESSION['gradebook']);
  61. }
  62. if (!empty($gradebook) && $gradebook == 'view') {
  63. $interbreadcrumb[] = array (
  64. 'url' => '../gradebook/'.Security::remove_XSS($_SESSION['gradebook_dest']),
  65. 'name' => get_lang('ToolGradebook')
  66. );
  67. }
  68. if ($origin == 'group') {
  69. $_clean['toolgroup'] = (int)$_SESSION['toolgroup'];
  70. $group_properties = GroupManager :: get_group_properties($_clean['toolgroup']);
  71. $interbreadcrumb[] = array('url' => '../group/group.php', 'name' => get_lang('Groups'));
  72. $interbreadcrumb[] = array('url' => '../group/group_space.php?gidReq='.$_SESSION['toolgroup'], 'name' => get_lang('GroupSpace').' '.$group_properties['name']);
  73. $interbreadcrumb[] = array('url' => 'viewforum.php?origin='.$origin.'&amp;forum='.Security::remove_XSS($_GET['forum']), 'name' => $current_forum['forum_title']);
  74. $interbreadcrumb[] = array('url' => 'viewthread.php?origin='.$origin.'&amp;gradebook='.$gradebook.'&amp;forum='.Security::remove_XSS($_GET['forum']).'&amp;thread='.Security::remove_XSS($_GET['thread']), 'name' => $current_thread['thread_title']);
  75. $interbreadcrumb[] = array('url' => 'javascript: void(0);', 'name' => get_lang('Reply'));
  76. } else {
  77. $interbreadcrumb[] = array('url' => 'index.php?gradebook='.$gradebook, 'name' => $nameTools);
  78. $interbreadcrumb[] = array('url' => 'viewforumcategory.php?forumcategory='.$current_forum_category['cat_id'], 'name' => $current_forum_category['cat_title']);
  79. $interbreadcrumb[] = array('url' => 'viewforum.php?origin='.$origin.'&amp;forum='.Security::remove_XSS($_GET['forum']), 'name' => $current_forum['forum_title']);
  80. $interbreadcrumb[] = array('url' => 'viewthread.php?origin='.$origin.'&amp;gradebook='.$gradebook.'&amp;forum='.Security::remove_XSS($_GET['forum']).'&amp;thread='.Security::remove_XSS($_GET['thread']), 'name' => $current_thread['thread_title']);
  81. $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('Reply'));
  82. }
  83. /* Resource Linker */
  84. if (isset($_POST['add_resources']) AND $_POST['add_resources'] == get_lang('Resources')) {
  85. $_SESSION['formelements'] = $_POST;
  86. $_SESSION['origin'] = $_SERVER['REQUEST_URI'];
  87. $_SESSION['breadcrumbs'] = $interbreadcrumb;
  88. header('Location: ../resourcelinker/resourcelinker.php');
  89. exit;
  90. }
  91. /* Header */
  92. if ($origin == 'learnpath') {
  93. //include api_get_path(INCLUDE_PATH).'reduced_header.inc.php';
  94. Display :: display_reduced_header('');
  95. } else {
  96. // The last element of the breadcrumb navigation is already set in interbreadcrumb, so give an empty string.
  97. Display :: display_header('');
  98. }
  99. /* Is the user allowed here? */
  100. // The user is not allowed here if
  101. // 1. the forumcategory, forum or thread is invisible (visibility==0
  102. // 2. the forumcategory, forum or thread is locked (locked <>0)
  103. // 3. if anonymous posts are not allowed
  104. // The only exception is the course manager
  105. // I have split this is several pieces for clarity.
  106. //if (!api_is_allowed_to_edit() AND (($current_forum_category['visibility'] == 0 OR $current_forum['visibility'] == 0) OR ($current_forum_category['locked'] <> 0 OR $current_forum['locked'] <> 0 OR $current_thread['locked'] <> 0))) {
  107. if (!api_is_allowed_to_edit(false, true) AND (($current_forum_category['visibility'] == 0 OR $current_forum['visibility'] == 0))) {
  108. $forum_allow = forum_not_allowed_here();
  109. if ($forum_allow === false) {
  110. exit;
  111. }
  112. }
  113. if (!api_is_allowed_to_edit(false, true) AND ($current_forum_category['locked'] <> 0 OR $current_forum['locked'] <> 0 OR $current_thread['locked'] <> 0)) {
  114. $forum_allow = forum_not_allowed_here();
  115. if ($forum_allow === false) {
  116. exit;
  117. }
  118. }
  119. if (!$_user['user_id'] AND $current_forum['allow_anonymous'] == 0) {
  120. $forum_allow = forum_not_allowed_here();
  121. if ($forum_allow === false) {
  122. exit;
  123. }
  124. }
  125. /* Action links */
  126. if ($origin != 'learnpath') {
  127. echo '<div class="actions">';
  128. echo '<span style="float:right;">'.search_link().'</span>';
  129. /*if ($origin == 'group') {
  130. echo '<a href="../group/group_space.php?'.api_get_cidreq().'&amp;gidReq='.Security::remove_XSS($_GET['gidReq']).'&amp;gradebook='.$gradebook.'">'.Display::return_icon('back.png', get_lang('BackTo').' '.get_lang('Groups'), '', '32').'</a>';
  131. } else {
  132. echo '<a href="index.php?gradebook='.$gradebook.'">'.Display::return_icon('back.png', get_lang('BackToForumOverview'), '', '32').'</a>';
  133. }
  134. echo '<a href="viewforum.php?forum='.Security::remove_XSS($_GET['forum']).'&amp;gidReq='.Security::remove_XSS($_GET['gidReq']).'&amp;origin='.$origin.'">'.Display::return_icon('forum.png', get_lang('BackToForum'), '', '32').'</a>';*/
  135. echo '<a href="viewthread.php?forum='.Security::remove_XSS($_GET['forum']).'&amp;gradebook='.$gradebook.'&amp;thread='.Security::remove_XSS($_GET['thread']).'&amp;gidReq='.Security::remove_XSS($_GET['gidReq']).'&amp;origin='.$origin.'">'.Display::return_icon('back.png', get_lang('BackToThread'), '', '32').'</a>';
  136. echo '</div>';
  137. } else {
  138. echo '<div style="height:15px">&nbsp;</div>';
  139. }
  140. /* Display Forum Category and the Forum information */
  141. /*
  142. echo "<table class=\"data_table\" width=\"100%\">";
  143. // The forum category
  144. echo "<tr><th style=\"padding-left:5px;\" align=\"left\" colspan=\"2\">";
  145. echo '<span class="forum_title">'.prepare4display($current_thread['thread_title']).'</span><br />';
  146. if (!empty ($current_forum_category['cat_title'])) {
  147. echo '<span class="forum_low_description">'.prepare4display($current_forum_category['cat_title'])." - </span>";
  148. }
  149. echo "</th>";
  150. echo "</tr>";
  151. echo '</table>';
  152. */
  153. // The form for the reply
  154. $my_action = isset($_GET['action']) ? Security::remove_XSS($_GET['action']) : '';
  155. $my_post = isset($_GET['post']) ? Security::remove_XSS($_GET['post']) : '';
  156. $my_elements = isset($_SESSION['formelements']) ? $_SESSION['formelements'] : '';
  157. $values = show_add_post_form($my_action, $my_post, $my_elements); // Note: This has to be cleaned first.
  158. if (!empty($values) AND isset($_POST['SubmitPost'])) {
  159. $result = store_reply($values);
  160. //@todo split the show_add_post_form function
  161. $url = 'viewthread.php?forum='.$current_thread['forum_id'].'&gradebook='.$gradebook.'&thread='.intval($_GET['thread']).'&gidReq='.api_get_group_id().'&origin='.$origin.'&msg='.$result['msg'].'&type='.$result['type'];
  162. echo '
  163. <script type="text/javascript">
  164. window.location = "'.$url.'";
  165. </script>';
  166. //header('Location: );
  167. }
  168. if ($origin != 'learnpath') {
  169. Display :: display_footer();
  170. }