reply.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. <?php
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2006-2008 Dokeos SPRL
  6. Copyright (c) 2006 Ghent University (UGent)
  7. For a full list of contributors, see "credits.txt".
  8. The full license can be read in "license.txt".
  9. This program is free software; you can redistribute it and/or
  10. modify it under the terms of the GNU General Public License
  11. as published by the Free Software Foundation; either version 2
  12. of the License, or (at your option) any later version.
  13. See the GNU General Public License for more details.
  14. Contact address: Dokeos, 108 rue du Corbeau, B-1030 Brussels, Belgium
  15. Mail: info@dokeos.com
  16. ==============================================================================
  17. */
  18. /**
  19. * These files are a complete rework of the forum. The database structure is
  20. * based on phpBB but all the code is rewritten. A lot of new functionalities
  21. * are added:
  22. * - forum categories and forums can be sorted up or down, locked or made invisible
  23. * - consistent and integrated forum administration
  24. * - forum options: are students allowed to edit their post?
  25. * moderation of posts (approval)
  26. * reply only forums (students cannot create new threads)
  27. * multiple forums per group
  28. * - sticky messages
  29. * - new view option: nested view
  30. * - quoting a message
  31. *
  32. * @Author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  33. * @Copyright Ghent University
  34. * @Copyright Patrick Cool
  35. *
  36. * @package dokeos.forum
  37. */
  38. // name of the language file that needs to be included
  39. $language_file = array('forum','document');
  40. // including the global dokeos file
  41. require '../inc/global.inc.php';
  42. // the section (tabs)
  43. $this_section=SECTION_COURSES;
  44. // notice for unauthorized people.
  45. api_protect_course_script(true);
  46. // including additional library scripts
  47. require_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
  48. include_once (api_get_path(LIBRARY_PATH).'groupmanager.lib.php');
  49. $nameTools=get_lang('Forum');
  50. $origin = '';
  51. if(isset($_GET['origin'])) {
  52. $origin = Security::remove_XSS($_GET['origin']);
  53. $origin_string = '&origin='.$origin;
  54. }
  55. /*
  56. -----------------------------------------------------------
  57. Including necessary files
  58. -----------------------------------------------------------
  59. */
  60. require 'forumconfig.inc.php';
  61. require_once 'forumfunction.inc.php';
  62. // javascript
  63. $htmlHeadXtra[] = '<script>
  64. function advanced_parameters() {
  65. if(document.getElementById(\'id_qualify\').style.display == \'none\') {
  66. document.getElementById(\'id_qualify\').style.display = \'block\';
  67. 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').'\';
  68. } else {
  69. document.getElementById(\'id_qualify\').style.display = \'none\';
  70. 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').'\';
  71. }
  72. }
  73. </script>';
  74. /*
  75. ==============================================================================
  76. MAIN DISPLAY SECTION
  77. ==============================================================================
  78. */
  79. /*
  80. -----------------------------------------------------------
  81. Retrieving forum and forum categorie information
  82. -----------------------------------------------------------
  83. */
  84. // we are getting all the information about the current forum and forum category.
  85. // note pcool: I tried to use only one sql statement (and function) for this
  86. // but the problem is that the visibility of the forum AND forum cateogory are stored in the item_property table
  87. $current_thread=get_thread_information(Security::remove_XSS($_GET['thread'])); // note: this has to be validated that it is an existing thread
  88. $current_forum=get_forum_information($current_thread['forum_id']); // note: this has to be validated that it is an existing forum.
  89. $current_forum_category=get_forumcategory_information(Security::remove_XSS($current_forum['forum_category']));
  90. /*
  91. -----------------------------------------------------------
  92. Breadcrumbs
  93. -----------------------------------------------------------
  94. */
  95. if (isset($_SESSION['gradebook'])){
  96. $gradebook= $_SESSION['gradebook'];
  97. }
  98. if (!empty($gradebook) && $gradebook=='view') {
  99. $interbreadcrumb[]= array (
  100. 'url' => '../gradebook/'.$_SESSION['gradebook_dest'],
  101. 'name' => get_lang('Gradebook')
  102. );
  103. }
  104. if (!empty($_SESSION['toolgroup'])) {
  105. $_clean['toolgroup']=(int)$_SESSION['toolgroup'];
  106. $group_properties = GroupManager :: get_group_properties($_clean['toolgroup']);
  107. $interbreadcrumb[] = array ("url" => "../group/group.php", "name" => get_lang('Groups'));
  108. $interbreadcrumb[] = array ("url" => "../group/group_space.php?gidReq=".$_SESSION['toolgroup'], "name"=> get_lang('GroupSpace').' ('.$group_properties['name'].')');
  109. $interbreadcrumb[]=array("url" => "viewforum.php?origin=".$origin."&forum=".Security::remove_XSS($_GET['forum']),"name" => $current_forum['forum_title']);
  110. $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']);
  111. $interbreadcrumb[]=array("url" => "javascript: void(0);","name" => get_lang('Reply'));
  112. } else {
  113. $interbreadcrumb[]=array("url" => "index.php?gradebook=$gradebook","name" => $nameTools);
  114. $interbreadcrumb[]=array("url" => "viewforumcategory.php?forumcategory=".$current_forum_category['cat_id'],"name" => $current_forum_category['cat_title']);
  115. $interbreadcrumb[]=array("url" => "viewforum.php?origin=".$origin."&forum=".Security::remove_XSS($_GET['forum']),"name" => $current_forum['forum_title']);
  116. $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']);
  117. $interbreadcrumb[]=array("url" => "javascript: void(0);","name" => get_lang('Reply'));
  118. }
  119. /*
  120. -----------------------------------------------------------
  121. Resource Linker
  122. -----------------------------------------------------------
  123. */
  124. if (isset($_POST['add_resources']) AND $_POST['add_resources']==get_lang('Resources')) {
  125. $_SESSION['formelements']=$_POST;
  126. $_SESSION['origin']=$_SERVER['REQUEST_URI'];
  127. $_SESSION['breadcrumbs']=$interbreadcrumb;
  128. header("Location: ../resourcelinker/resourcelinker.php");
  129. }
  130. /*
  131. -----------------------------------------------------------
  132. Header
  133. -----------------------------------------------------------
  134. */
  135. if($origin=='learnpath') {
  136. include(api_get_path(INCLUDE_PATH).'reduced_header.inc.php');
  137. } else {
  138. // the last element of the breadcrumb navigation is already set in interbreadcrumb, so give empty string
  139. Display :: display_header('');
  140. api_display_tool_title($nameTools);
  141. }
  142. /*
  143. -----------------------------------------------------------
  144. Is the user allowed here?
  145. -----------------------------------------------------------
  146. */
  147. // The user is not allowed here if
  148. // 1. the forumcategory, forum or thread is invisible (visibility==0
  149. // 2. the forumcategory, forum or thread is locked (locked <>0)
  150. // 3. if anonymous posts are not allowed
  151. // The only exception is the course manager
  152. // I have split this is several pieces for clarity.
  153. //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)))
  154. if (!api_is_allowed_to_edit(false,true) AND (($current_forum_category['visibility']==0 OR $current_forum['visibility']==0))) {
  155. forum_not_allowed_here();
  156. }
  157. if (!api_is_allowed_to_edit(false,true) AND ($current_forum_category['locked']<>0 OR $current_forum['locked']<>0 OR $current_thread['locked']<>0)) {
  158. forum_not_allowed_here();
  159. }
  160. if (!$_user['user_id'] AND $current_forum['allow_anonymous']==0) {
  161. forum_not_allowed_here();
  162. }
  163. /*
  164. -----------------------------------------------------------
  165. Action links
  166. -----------------------------------------------------------
  167. */
  168. if ($origin != 'learnpath') {
  169. echo '<div class="actions">';
  170. echo '<span style="float:right;">'.search_link().'</span>';
  171. echo '<a href="index.php?gradebook='.$gradebook.'">'.Display::return_icon('back.png',get_lang('BackToForumOverview')).' '.get_lang('BackToForumOverview').'</a>';
  172. 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>';
  173. 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>';
  174. echo '</div>';
  175. } else {
  176. echo '<div style="height:15px">&nbsp;</div>';
  177. }
  178. /*
  179. -----------------------------------------------------------
  180. Display Forum Category and the Forum information
  181. -----------------------------------------------------------
  182. */
  183. echo "<table class=\"data_table\" width='100%'>\n";
  184. // the forum category
  185. echo "\t<tr>\n\t\t<th style=\"padding-left:5px;\" align=\"left\" colspan=\"2\">";
  186. echo '<span class="forum_title">'.prepare4display(Security::remove_XSS($current_thread['thread_title'])).'</span><br />';
  187. if (!empty ($current_forum_category['cat_title'])) {
  188. echo '<span class="forum_low_description">'.prepare4display(Security::remove_XSS($current_forum_category['cat_title']))." - </span>";
  189. }
  190. //echo '<span class="forum_low_description">'.prepare4display(Security::remove_XSS($current_forum['forum_title'])).'</span>';
  191. echo "</th>\n";
  192. echo "\t</tr>\n";
  193. echo '</table>';
  194. // the form for the reply
  195. $my_action = isset($_GET['action']) ? Security::remove_XSS($_GET['action']) : '';
  196. $my_post = isset($_GET['post']) ? Security::remove_XSS($_GET['post']) : '';
  197. $my_elements = isset($_SESSION['formelements']) ? $_SESSION['formelements'] : '';
  198. $values=show_add_post_form(Security::remove_XSS($my_action,$my_post, $my_elements)); // note: this has to be cleaned first
  199. if (!empty($values) AND isset($_POST['SubmitPost'])) {
  200. store_reply(Security::remove_XSS($values));
  201. }
  202. /*
  203. ==============================================================================
  204. FOOTER
  205. ==============================================================================
  206. */
  207. if($origin!='learnpath') {
  208. Display :: display_footer();
  209. }