reply.php 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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. // name of the language file that needs to be included
  20. $language_file = array('forum','document');
  21. // including the global dokeos file
  22. require_once '../inc/global.inc.php';
  23. // the section (tabs)
  24. $this_section=SECTION_COURSES;
  25. // notice for unauthorized people.
  26. api_protect_course_script(true);
  27. // including additional library scripts
  28. require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php';
  29. require_once api_get_path(LIBRARY_PATH).'groupmanager.lib.php';
  30. $nameTools=get_lang('ToolForum');
  31. $origin = '';
  32. if(isset($_GET['origin'])) {
  33. $origin = Security::remove_XSS($_GET['origin']);
  34. $origin_string = '&origin='.$origin;
  35. }
  36. /* Including necessary files */
  37. require_once 'forumconfig.inc.php';
  38. require_once 'forumfunction.inc.php';
  39. // javascript
  40. $htmlHeadXtra[] = '<script>
  41. function advanced_parameters() {
  42. if(document.getElementById(\'id_qualify\').style.display == \'none\') {
  43. document.getElementById(\'id_qualify\').style.display = \'block\';
  44. 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').'\';
  45. } else {
  46. document.getElementById(\'id_qualify\').style.display = \'none\';
  47. 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').'\';
  48. }
  49. }
  50. </script>';
  51. /* MAIN DISPLAY SECTION */
  52. /* Retrieving forum and forum categorie information */
  53. // We are getting all the information about the current forum and forum category.
  54. // note pcool: I tried to use only one sql statement (and function) for this
  55. // but the problem is that the visibility of the forum AND forum cateogory are stored in the item_property table
  56. $current_thread = get_thread_information($_GET['thread']); // note: this has to be validated that it is an existing thread
  57. $current_forum = get_forum_information($current_thread['forum_id']); // note: this has to be validated that it is an existing forum.
  58. $current_forum_category = get_forumcategory_information(Security::remove_XSS($current_forum['forum_category']));
  59. /* Breadcrumbs */
  60. if (isset($_SESSION['gradebook'])){
  61. $gradebook = Security::remove_XSS($_SESSION['gradebook']);
  62. }
  63. if (!empty($gradebook) && $gradebook == 'view') {
  64. $interbreadcrumb[]= array (
  65. 'url' => '../gradebook/'.Security::remove_XSS($_SESSION['gradebook_dest']),
  66. 'name' => get_lang('ToolGradebook')
  67. );
  68. }
  69. if ($origin=='group') {
  70. $_clean['toolgroup']=(int)$_SESSION['toolgroup'];
  71. $group_properties = GroupManager :: get_group_properties($_clean['toolgroup']);
  72. $interbreadcrumb[] = array ("url" => "../group/group.php", "name" => get_lang('Groups'));
  73. $interbreadcrumb[] = array ("url" => "../group/group_space.php?gidReq=".$_SESSION['toolgroup'], "name"=> get_lang('GroupSpace').' '.$group_properties['name']);
  74. $interbreadcrumb[]=array("url" => "viewforum.php?origin=".$origin."&forum=".Security::remove_XSS($_GET['forum']),"name" => $current_forum['forum_title']);
  75. $interbreadcrumb[]=array("url" => "viewthread.php?origin=".$origin."&gradebook=".$gradebook."&forum=".Security::remove_XSS($_GET['forum'])."&amp;thread=".Security::remove_XSS($_GET['thread']),"name" => $current_thread['thread_title']);
  76. $interbreadcrumb[]=array("url" => "javascript: void(0);","name" => get_lang('Reply'));
  77. } else {
  78. $interbreadcrumb[]=array("url" => "index.php?gradebook=$gradebook","name" => $nameTools);
  79. $interbreadcrumb[]=array("url" => "viewforumcategory.php?forumcategory=".$current_forum_category['cat_id'],"name" => $current_forum_category['cat_title']);
  80. $interbreadcrumb[]=array("url" => "viewforum.php?origin=".$origin."&forum=".Security::remove_XSS($_GET['forum']),"name" => $current_forum['forum_title']);
  81. $interbreadcrumb[]=array("url" => "viewthread.php?origin=".$origin."&gradebook=".$gradebook."&forum=".Security::remove_XSS($_GET['forum'])."&amp;thread=".Security::remove_XSS($_GET['thread']),"name" => $current_thread['thread_title']);
  82. $interbreadcrumb[]=array("url" => "javascript: void(0);","name" => get_lang('Reply'));
  83. }
  84. /* Resource Linker */
  85. if (isset($_POST['add_resources']) AND $_POST['add_resources']==get_lang('Resources')) {
  86. $_SESSION['formelements'] = $_POST;
  87. $_SESSION['origin'] = $_SERVER['REQUEST_URI'];
  88. $_SESSION['breadcrumbs'] = $interbreadcrumb;
  89. header("Location: ../resourcelinker/resourcelinker.php");
  90. }
  91. /* Header */
  92. if($origin=='learnpath') {
  93. include(api_get_path(INCLUDE_PATH).'reduced_header.inc.php');
  94. } else {
  95. // the last element of the breadcrumb navigation is already set in interbreadcrumb, so give empty string
  96. Display :: display_header('');
  97. api_display_tool_title($nameTools);
  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']).'&gradebook='.$gradebook.'">'.Display::return_icon('back.png',get_lang('BackTo').' '.get_lang('Groups')).get_lang('BackTo').' '.get_lang('GroupSpace').'</a>';
  131. }
  132. else{
  133. echo '<a href="index.php?gradebook='.$gradebook.'">'.Display::return_icon('back.png',get_lang('BackToForumOverview')).' '.get_lang('BackToForumOverview').'</a>';
  134. }
  135. echo '<a href="viewforum.php?forum='.Security::remove_XSS($_GET['forum']).'&amp;gidReq='.Security::remove_XSS($_GET['gidReq']).'&origin=group">'.Display::return_icon('forum.gif',get_lang('BackToForum')).' '.get_lang('BackToForum').'</a>';
  136. 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']).'&origin=group">'.Display::return_icon('forumthread.gif',get_lang('BackToThread')).' '.get_lang('BackToThread').'</a>';
  137. echo '</div>';
  138. } else {
  139. echo '<div style="height:15px">&nbsp;</div>';
  140. }
  141. /* Display Forum Category and the Forum information */
  142. echo "<table class=\"data_table\" width='100%'>\n";
  143. // the forum category
  144. echo "\t<tr>\n\t\t<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>\n";
  150. echo "\t</tr>\n";
  151. echo '</table>';
  152. // the form for the reply
  153. $my_action = isset($_GET['action']) ? Security::remove_XSS($_GET['action']) : '';
  154. $my_post = isset($_GET['post']) ? Security::remove_XSS($_GET['post']) : '';
  155. $my_elements = isset($_SESSION['formelements']) ? $_SESSION['formelements'] : '';
  156. $values = show_add_post_form($my_action,$my_post, $my_elements); // note: this has to be cleaned first
  157. if (!empty($values) AND isset($_POST['SubmitPost'])) {
  158. store_reply($values);
  159. }
  160. if($origin!='learnpath') {
  161. Display :: display_footer();
  162. }