reply.php 9.9 KB

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