editpost.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. <?php
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2004-2008 Dokeos SPRL
  6. Copyright (c) 2003 Ghent University (UGent)
  7. Copyright (c) 2001 Universite catholique de Louvain (UCL)
  8. Copyright (c) various contributors
  9. For a full list of contributors, see "credits.txt".
  10. The full license can be read in "license.txt".
  11. This program is free software; you can redistribute it and/or
  12. modify it under the terms of the GNU General Public License
  13. as published by the Free Software Foundation; either version 2
  14. of the License, or (at your option) any later version.
  15. See the GNU General Public License for more details.
  16. Contact address: Dokeos, rue du Corbeau, 108, B-1030 Brussels, Belgium
  17. Mail: info@dokeos.com
  18. ==============================================================================
  19. */
  20. /**
  21. * These files are a complete rework of the forum. The database structure is
  22. * based on phpBB but all the code is rewritten. A lot of new functionalities
  23. * are added:
  24. * - forum categories and forums can be sorted up or down, locked or made invisible
  25. * - consistent and integrated forum administration
  26. * - forum options: are students allowed to edit their post?
  27. * moderation of posts (approval)
  28. * reply only forums (students cannot create new threads)
  29. * multiple forums per group
  30. * - sticky messages
  31. * - new view option: nested view
  32. * - quoting a message
  33. *
  34. * @Author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  35. * @Copyright Ghent University
  36. * @Copyright Patrick Cool
  37. *
  38. * @package dokeos.forum
  39. */
  40. /**
  41. **************************************************************************
  42. * IMPORTANT NOTICE
  43. * Please do not change anything is this code yet because there are still
  44. * some significant code that need to happen and I do not have the time to
  45. * merge files and test it all over again. So for the moment, please do not
  46. * touch the code
  47. * -- Patrick Cool <patrick.cool@UGent.be>
  48. **************************************************************************
  49. */
  50. /*
  51. ==============================================================================
  52. INIT SECTION
  53. ==============================================================================
  54. */
  55. // name of the language file that needs to be included
  56. $language_file = array (
  57. 'forum',
  58. 'group'
  59. );
  60. // including the global dokeos file
  61. require ('../inc/global.inc.php');
  62. require_once('../gradebook/lib/gradebook_functions.inc.php');
  63. require_once('../gradebook/lib/be/gradebookitem.class.php');
  64. require_once('../gradebook/lib/be/evaluation.class.php');
  65. require_once('../gradebook/lib/be/abstractlink.class.php');
  66. require_once('../gradebook/lib/gradebook_functions.inc.php');
  67. // the section (tabs)
  68. $this_section=SECTION_COURSES;
  69. // notice for unauthorized people.
  70. api_protect_course_script(true);
  71. // including additional library scripts
  72. require_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
  73. include_once (api_get_path(LIBRARY_PATH).'groupmanager.lib.php');
  74. $nameTools=get_lang('Forum');
  75. /*
  76. -----------------------------------------------------------
  77. Including necessary files
  78. -----------------------------------------------------------
  79. */
  80. include('forumconfig.inc.php');
  81. include('forumfunction.inc.php');
  82. // javascript
  83. $htmlHeadXtra[] = '<script>
  84. function advanced_parameters() {
  85. if(document.getElementById(\'id_qualify\').style.display == \'none\') {
  86. document.getElementById(\'id_qualify\').style.display = \'block\';
  87. 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').'\';
  88. } else {
  89. document.getElementById(\'id_qualify\').style.display = \'none\';
  90. 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').'\';
  91. }
  92. }
  93. </script>';
  94. /*
  95. ==============================================================================
  96. MAIN DISPLAY SECTION
  97. ==============================================================================
  98. */
  99. /*
  100. -----------------------------------------------------------
  101. Retrieving forum and forum categorie information
  102. -----------------------------------------------------------
  103. */
  104. // we are getting all the information about the current forum and forum category.
  105. // note pcool: I tried to use only one sql statement (and function) for this
  106. // but the problem is that the visibility of the forum AND forum cateogory are stored in the item_property table
  107. $current_thread=get_thread_information($_GET['thread']); // note: this has to be validated that it is an existing thread
  108. $current_forum=get_forum_information($_GET['forum']); // note: this has to be validated that it is an existing forum.
  109. $current_forum_category=get_forumcategory_information($current_forum['forum_category']);
  110. $current_post=get_post_information($_GET['post']);
  111. /*
  112. -----------------------------------------------------------
  113. Header and Breadcrumbs
  114. -----------------------------------------------------------
  115. */
  116. if (isset($_SESSION['gradebook'])){
  117. $gradebook= $_SESSION['gradebook'];
  118. }
  119. if (!empty($gradebook) && $gradebook=='view') {
  120. $interbreadcrumb[]= array (
  121. 'url' => '../gradebook/'.$_SESSION['gradebook_dest'],
  122. 'name' => get_lang('Gradebook')
  123. );
  124. }
  125. if (!empty($_SESSION['toolgroup'])) {
  126. $_clean['toolgroup']=(int)$_SESSION['toolgroup'];
  127. $group_properties = GroupManager :: get_group_properties($_clean['toolgroup']);
  128. $interbreadcrumb[] = array ("url" => "../group/group.php", "name" => get_lang('Groups'));
  129. $interbreadcrumb[] = array ("url"=>"../group/group_space.php?gidReq=".$_SESSION['toolgroup'], "name"=> get_lang('GroupSpace').' ('.$group_properties['name'].')');
  130. $interbreadcrumb[] = array("url" => "viewforum.php?origin=".$origin."&amp;gidReq=".$_SESSION['toolgroup']."&amp;forum=".Security::remove_XSS($_GET['forum']),"name" => prepare4display($current_forum['forum_title']));
  131. $interbreadcrumb[] = array("url" => "javascript: void (0);","name" => get_lang('EditPost'));
  132. } else {
  133. $interbreadcrumb[]=array("url" => "index.php?gradebook=$gradebook","name" => $nameTools);
  134. $interbreadcrumb[]=array("url" => "viewforumcategory.php?forumcategory=".$current_forum_category['cat_id'],"name" => prepare4display($current_forum_category['cat_title']));
  135. $interbreadcrumb[]=array("url" => "viewforum.php?origin=".$origin."&amp;forum=".Security::remove_XSS($_GET['forum']),"name" => prepare4display($current_forum['forum_title']));
  136. $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']));
  137. $interbreadcrumb[]=array("url" => "javascript: void (0);","name" => get_lang('EditPost'));
  138. }
  139. /*
  140. -----------------------------------------------------------
  141. Resource Linker
  142. -----------------------------------------------------------
  143. */
  144. if (isset($_POST['add_resources']) AND $_POST['add_resources']==get_lang('Resources')) {
  145. $_SESSION['formelements']=$_POST;
  146. $_SESSION['origin']=$_SERVER['REQUEST_URI'];
  147. $_SESSION['breadcrumbs']=$interbreadcrumb;
  148. header("Location: ../resourcelinker/resourcelinker.php");
  149. }
  150. $table_link = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
  151. /*
  152. -----------------------------------------------------------
  153. Header
  154. -----------------------------------------------------------
  155. */
  156. //are we in a lp ?
  157. $origin = '';
  158. if (isset($_GET['origin'])) {
  159. $origin = Security::remove_XSS($_GET['origin']);
  160. }
  161. if ($origin=='learnpath') {
  162. include(api_get_path(INCLUDE_PATH).'reduced_header.inc.php');
  163. } else {
  164. Display :: display_header(null);
  165. //api_display_tool_title($nameTools);
  166. }
  167. //echo '<link href="forumstyles.css" rel="stylesheet" type="text/css" />';
  168. /*
  169. -----------------------------------------------------------
  170. Is the user allowed here?
  171. -----------------------------------------------------------
  172. */
  173. // the user is not allowed here if
  174. // 1. the forumcategory, forum or thread is invisible (visibility==0)
  175. // 2. the forumcategory, forum or thread is locked (locked <>0)
  176. // 3. if anonymous posts are not allowed
  177. // 4. if editing of replies is not allowed
  178. // The only exception is the course manager
  179. // I have split this is several pieces for clarity.
  180. //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)))
  181. if (!api_is_allowed_to_edit(null,true) AND (($current_forum_category['visibility']==0 OR $current_forum['visibility']==0))) {
  182. forum_not_allowed_here();
  183. }
  184. if (!api_is_allowed_to_edit(null,true) AND ($current_forum_category['locked']<>0 OR $current_forum['locked']<>0 OR $current_thread['locked']<>0)) {
  185. forum_not_allowed_here();
  186. }
  187. if (!$_user['user_id'] AND $current_forum['allow_anonymous']==0) {
  188. forum_not_allowed_here();
  189. }
  190. if (!api_is_allowed_to_edit(null,true) AND $current_forum['allow_edit']==0) {
  191. forum_not_allowed_here();
  192. }
  193. // action links
  194. if ($origin!='learnpath') {
  195. echo '<div class="actions">';
  196. echo '<span style="float:right;">'.search_link().'</span>';
  197. echo '<a href="index.php?gradebook='.$gradebook.'">'.Display::return_icon('back.png').' '.get_lang('BackToForumOverview').'</a>';
  198. echo '<a href="viewforum.php?forum='.Security::remove_XSS($_GET['forum']).'">'.Display::return_icon('forum.gif').' '.get_lang('BackToForum').'</a>';
  199. echo '</div>';
  200. }
  201. /*
  202. -----------------------------------------------------------
  203. Display Forum Category and the Forum information
  204. -----------------------------------------------------------
  205. */
  206. echo "<table class=\"data_table\" width='100%'>\n";
  207. // the forum category
  208. echo "\t<tr>\n\t\t<th align=\"left\" colspan=\"2\">";
  209. echo '<a href="viewforum.php?&origin='.$origin.'&forum='.$current_forum['forum_id'].'" '.class_visible_invisible($current_forum['visibility']).'>'.prepare4display($current_forum['forum_title']).'</a><br />';
  210. echo '<span class="forum_description">'.prepare4display($current_forum['forum_comment']).'</span>';echo "</th>\n";
  211. echo "</th>\n";
  212. echo "\t</tr>\n";
  213. echo '</table>';
  214. // the form for the reply
  215. $values=show_edit_post_form($current_post, $current_thread, $current_forum, isset($_SESSION['formelements'])?$_SESSION['formelements']:'');
  216. if (!empty($values) and isset($_POST['SubmitPost'])) {
  217. store_edit_post($values);
  218. $option_chek=isset($values['thread_qualify_gradebook'])?$values['thread_qualify_gradebook']:null;// values 1 or 0
  219. if ( 1== $option_chek ) {
  220. $id=$values['thread_id'];
  221. $title_gradebook=$values['calification_notebook_title'];
  222. $value_calification=$values['numeric_calification'];
  223. $weight_calification=$values['weight_calification'];
  224. $description="";
  225. $session_id=api_get_session_id();
  226. $link_id=is_resource_in_course_gradebook(api_get_course_id(),5,$id,$session_id);
  227. if ($link_id==false) {
  228. add_resource_to_course_gradebook(api_get_course_id(), 5, $id, $title_gradebook,$weight_calification,$value_calification,$description,time(),1,api_get_session_id());
  229. } else {
  230. Database::query('UPDATE '.$table_link.' SET weight='.$weight_calification.' WHERE id='.$link_id.'');
  231. }
  232. }
  233. }
  234. // footer
  235. if ($origin!='learnpath') {
  236. Display :: display_footer();
  237. }