editpost.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  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. /**
  24. **************************************************************************
  25. * IMPORTANT NOTICE
  26. * Please do not change anything is this code yet because there are still
  27. * some significant code that need to happen and I do not have the time to
  28. * merge files and test it all over again. So for the moment, please do not
  29. * touch the code
  30. * -- Patrick Cool <patrick.cool@UGent.be>
  31. **************************************************************************
  32. */
  33. /*
  34. ==============================================================================
  35. INIT SECTION
  36. ==============================================================================
  37. */
  38. // name of the language file that needs to be included
  39. $language_file = array (
  40. 'forum',
  41. 'group'
  42. );
  43. // including the global dokeos file
  44. require ('../inc/global.inc.php');
  45. require_once('../gradebook/lib/gradebook_functions.inc.php');
  46. require_once('../gradebook/lib/be/gradebookitem.class.php');
  47. require_once('../gradebook/lib/be/evaluation.class.php');
  48. require_once('../gradebook/lib/be/abstractlink.class.php');
  49. require_once('../gradebook/lib/gradebook_functions.inc.php');
  50. // the section (tabs)
  51. $this_section=SECTION_COURSES;
  52. // notice for unauthorized people.
  53. api_protect_course_script(true);
  54. // including additional library scripts
  55. require_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
  56. include_once (api_get_path(LIBRARY_PATH).'groupmanager.lib.php');
  57. $nameTools=get_lang('ToolForum');
  58. /*
  59. -----------------------------------------------------------
  60. Including necessary files
  61. -----------------------------------------------------------
  62. */
  63. include('forumconfig.inc.php');
  64. include('forumfunction.inc.php');
  65. // javascript
  66. $htmlHeadXtra[] = '<script>
  67. function advanced_parameters() {
  68. if(document.getElementById(\'id_qualify\').style.display == \'none\') {
  69. document.getElementById(\'id_qualify\').style.display = \'block\';
  70. 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').'\';
  71. } else {
  72. document.getElementById(\'id_qualify\').style.display = \'none\';
  73. 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').'\';
  74. }
  75. }
  76. </script>';
  77. /*
  78. ==============================================================================
  79. MAIN DISPLAY SECTION
  80. ==============================================================================
  81. */
  82. /*
  83. -----------------------------------------------------------
  84. Retrieving forum and forum categorie information
  85. -----------------------------------------------------------
  86. */
  87. // we are getting all the information about the current forum and forum category.
  88. // note pcool: I tried to use only one sql statement (and function) for this
  89. // but the problem is that the visibility of the forum AND forum cateogory are stored in the item_property table
  90. $current_thread=get_thread_information($_GET['thread']); // note: this has to be validated that it is an existing thread
  91. $current_forum=get_forum_information($_GET['forum']); // note: this has to be validated that it is an existing forum.
  92. $current_forum_category=get_forumcategory_information($current_forum['forum_category']);
  93. $current_post=get_post_information($_GET['post']);
  94. /*
  95. -----------------------------------------------------------
  96. Header and Breadcrumbs
  97. -----------------------------------------------------------
  98. */
  99. if (isset($_SESSION['gradebook'])){
  100. $gradebook= $_SESSION['gradebook'];
  101. }
  102. if (!empty($gradebook) && $gradebook=='view') {
  103. $interbreadcrumb[]= array (
  104. 'url' => '../gradebook/'.$_SESSION['gradebook_dest'],
  105. 'name' => get_lang('ToolGradebook')
  106. );
  107. }
  108. if (!empty($_SESSION['toolgroup'])) {
  109. $_clean['toolgroup']=(int)$_SESSION['toolgroup'];
  110. $group_properties = GroupManager :: get_group_properties($_clean['toolgroup']);
  111. $interbreadcrumb[] = array ("url" => "../group/group.php", "name" => get_lang('Groups'));
  112. $interbreadcrumb[] = array ("url"=>"../group/group_space.php?gidReq=".$_SESSION['toolgroup'], "name"=> get_lang('GroupSpace').' ('.$group_properties['name'].')');
  113. $interbreadcrumb[] = array("url" => "viewforum.php?origin=".$origin."&amp;gidReq=".$_SESSION['toolgroup']."&amp;forum=".Security::remove_XSS($_GET['forum']),"name" => prepare4display($current_forum['forum_title']));
  114. $interbreadcrumb[] = array("url" => "javascript: void (0);","name" => get_lang('EditPost'));
  115. } else {
  116. $interbreadcrumb[]=array("url" => "index.php?gradebook=$gradebook","name" => $nameTools);
  117. $interbreadcrumb[]=array("url" => "viewforumcategory.php?forumcategory=".$current_forum_category['cat_id'],"name" => prepare4display($current_forum_category['cat_title']));
  118. $interbreadcrumb[]=array("url" => "viewforum.php?origin=".$origin."&amp;forum=".Security::remove_XSS($_GET['forum']),"name" => prepare4display($current_forum['forum_title']));
  119. $interbreadcrumb[]=array("url" => "viewthread.php?gradebook=$gradebook&amp;origin=".$origin."&amp;forum=".Security::remove_XSS($_GET['forum'])."&amp;thread=".$_GET['thread'],"name" => prepare4display($current_thread['thread_title']));
  120. $interbreadcrumb[]=array("url" => "javascript: void (0);","name" => get_lang('EditPost'));
  121. }
  122. /*
  123. -----------------------------------------------------------
  124. Resource Linker
  125. -----------------------------------------------------------
  126. */
  127. if (isset($_POST['add_resources']) AND $_POST['add_resources']==get_lang('Resources')) {
  128. $_SESSION['formelements']=$_POST;
  129. $_SESSION['origin']=$_SERVER['REQUEST_URI'];
  130. $_SESSION['breadcrumbs']=$interbreadcrumb;
  131. header("Location: ../resourcelinker/resourcelinker.php");
  132. }
  133. $table_link = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
  134. /*
  135. -----------------------------------------------------------
  136. Header
  137. -----------------------------------------------------------
  138. */
  139. //are we in a lp ?
  140. $origin = '';
  141. if (isset($_GET['origin'])) {
  142. $origin = Security::remove_XSS($_GET['origin']);
  143. }
  144. if ($origin=='learnpath') {
  145. include(api_get_path(INCLUDE_PATH).'reduced_header.inc.php');
  146. } else {
  147. Display :: display_header(null);
  148. //api_display_tool_title($nameTools);
  149. }
  150. //echo '<link href="forumstyles.css" rel="stylesheet" type="text/css" />';
  151. /*
  152. -----------------------------------------------------------
  153. Is the user allowed here?
  154. -----------------------------------------------------------
  155. */
  156. // the user is not allowed here if
  157. // 1. the forumcategory, forum or thread is invisible (visibility==0)
  158. // 2. the forumcategory, forum or thread is locked (locked <>0)
  159. // 3. if anonymous posts are not allowed
  160. // 4. if editing of replies is not allowed
  161. // The only exception is the course manager
  162. // I have split this is several pieces for clarity.
  163. //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)))
  164. if (!api_is_allowed_to_edit(null,true) AND (($current_forum_category['visibility']==0 OR $current_forum['visibility']==0))) {
  165. $forum_allow = forum_not_allowed_here();
  166. if ($forum_allow === false) {
  167. exit;
  168. }
  169. }
  170. if (!api_is_allowed_to_edit(null,true) AND ($current_forum_category['locked']<>0 OR $current_forum['locked']<>0 OR $current_thread['locked']<>0)) {
  171. $forum_allow = forum_not_allowed_here();
  172. if ($forum_allow === false) {
  173. exit;
  174. }
  175. }
  176. if (!$_user['user_id'] AND $current_forum['allow_anonymous']==0) {
  177. $forum_allow = forum_not_allowed_here();
  178. if ($forum_allow === false) {
  179. exit;
  180. }
  181. }
  182. if (!api_is_allowed_to_edit(null,true) AND $current_forum['allow_edit']==0) {
  183. $forum_allow = forum_not_allowed_here();
  184. if ($forum_allow === false) {
  185. exit;
  186. }
  187. }
  188. // action links
  189. if ($origin!='learnpath') {
  190. echo '<div class="actions">';
  191. echo '<span style="float:right;">'.search_link().'</span>';
  192. echo '<a href="index.php?gradebook='.$gradebook.'">'.Display::return_icon('back.png').' '.get_lang('BackToForumOverview').'</a>';
  193. echo '<a href="viewforum.php?forum='.Security::remove_XSS($_GET['forum']).'">'.Display::return_icon('forum.gif').' '.get_lang('BackToForum').'</a>';
  194. echo '</div>';
  195. }
  196. /*
  197. -----------------------------------------------------------
  198. Display Forum Category and the Forum information
  199. -----------------------------------------------------------
  200. */
  201. echo "<table class=\"data_table\" width='100%'>\n";
  202. // the forum category
  203. echo "\t<tr>\n\t\t<th align=\"left\" colspan=\"2\">";
  204. echo '<a href="viewforum.php?&origin='.$origin.'&forum='.$current_forum['forum_id'].'" '.class_visible_invisible($current_forum['visibility']).'>'.prepare4display(Security::remove_XSS($current_forum['forum_title'])).'</a><br />';
  205. echo '<span class="forum_description">'.prepare4display(Security::remove_XSS($current_forum['forum_comment'],STUDENT)).'</span>';echo "</th>\n";
  206. echo "</th>\n";
  207. echo "\t</tr>\n";
  208. echo '</table>';
  209. // the form for the reply
  210. $values=show_edit_post_form($current_post, $current_thread, $current_forum, isset($_SESSION['formelements'])?$_SESSION['formelements']:'');
  211. if (!empty($values) and isset($_POST['SubmitPost'])) {
  212. store_edit_post($values);
  213. $option_chek=isset($values['thread_qualify_gradebook'])?$values['thread_qualify_gradebook']:null;// values 1 or 0
  214. if ( 1== $option_chek ) {
  215. $id=$values['thread_id'];
  216. $title_gradebook=$values['calification_notebook_title'];
  217. $value_calification=$values['numeric_calification'];
  218. $weight_calification=$values['weight_calification'];
  219. $description="";
  220. $session_id=api_get_session_id();
  221. $link_id=is_resource_in_course_gradebook(api_get_course_id(),5,$id,$session_id);
  222. if ($link_id==false) {
  223. add_resource_to_course_gradebook(api_get_course_id(), 5, $id, $title_gradebook,$weight_calification,$value_calification,$description,time(),1,api_get_session_id());
  224. } else {
  225. Database::query('UPDATE '.$table_link.' SET weight='.$weight_calification.' WHERE id='.$link_id.'');
  226. }
  227. }
  228. }
  229. // footer
  230. if ($origin!='learnpath') {
  231. Display :: display_footer();
  232. }