forumqualify.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. <?php
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2008 Dokeos Latinoamerica SAC
  6. For a full list of contributors, see "credits.txt".
  7. The full license can be read in "license.txt".
  8. This program is free software; you can redistribute it and/or
  9. modify it under the terms of the GNU General Public License
  10. as published by the Free Software Foundation; either version 2
  11. of the License, or (at your option) any later version.
  12. See the GNU General Public License for more details.
  13. Contact address: Dokeos, 108 rue du Corbeau, B-1030 Brussels, Belgium
  14. Mail: info@dokeos.com
  15. ==============================================================================
  16. */
  17. /**
  18. * @package dokeos.forum
  19. */
  20. // name of the language file that needs to be included
  21. $language_file=array('admin','forum');
  22. require '../inc/global.inc.php';
  23. require_once 'forumconfig.inc.php';
  24. require_once 'forumfunction.inc.php';
  25. $nameTools = get_lang('Forum');
  26. $this_section = SECTION_COURSES;
  27. $allowed_to_edit = api_is_allowed_to_edit(null,true);
  28. if (!$allowed_to_edit) {
  29. api_not_allowed(true);
  30. }
  31. $origin = '';
  32. $origin_string='';
  33. if (isset($_GET['origin'])) {
  34. $origin = Security::remove_XSS($_GET['origin']);
  35. }
  36. // including additional library scripts
  37. require_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
  38. include_once (api_get_path(LIBRARY_PATH).'groupmanager.lib.php');
  39. //require_once (api_get_path(LIBRARY_PATH).'resourcelinker.lib.php');
  40. $nameTools=get_lang('Forum');
  41. /*
  42. -----------------------------------------------------------
  43. Including necessary files
  44. -----------------------------------------------------------
  45. */
  46. $htmlHeadXtra[] = '<script type="text/javascript" src="'.api_get_path(WEB_CODE_PATH).'inc/lib/javascript/jquery.js" ></script>';
  47. $htmlHeadXtra[] = '<script type="text/javascript" language="javascript">
  48. $(document).ready(function(){ $(\'.hide-me\').slideUp() });
  49. function hidecontent(content){ $(content).slideToggle(\'normal\'); }
  50. </script>';
  51. //are we in a lp ?
  52. $origin = '';
  53. if (isset($_GET['origin'])) {
  54. $origin = Security::remove_XSS($_GET['origin']);
  55. }
  56. /*
  57. ==============================================================================
  58. MAIN DISPLAY SECTION
  59. ==============================================================================
  60. */
  61. /*
  62. -----------------------------------------------------------
  63. Retrieving forum and forum categorie information
  64. -----------------------------------------------------------
  65. */
  66. // we are getting all the information about the current forum and forum category.
  67. // note pcool: I tried to use only one sql statement (and function) for this
  68. // but the problem is that the visibility of the forum AND forum cateogory are stored in the item_property table
  69. $current_thread=get_thread_information($_GET['thread']); // note: this has to be validated that it is an existing thread
  70. $current_forum=get_forum_information($current_thread['forum_id']); // note: this has to be validated that it is an existing forum.
  71. $current_forum_category=get_forumcategory_information($current_forum['forum_category']);
  72. $whatsnew_post_info=$_SESSION['whatsnew_post_info'];
  73. /*
  74. -----------------------------------------------------------
  75. Header and Breadcrumbs
  76. -----------------------------------------------------------
  77. */
  78. if (isset($_SESSION['gradebook'])){
  79. $gradebook= $_SESSION['gradebook'];
  80. }
  81. if (!empty($gradebook) && $gradebook=='view') {
  82. $interbreadcrumb[]= array (
  83. 'url' => '../gradebook/'.$_SESSION['gradebook_dest'],
  84. 'name' => get_lang('Gradebook')
  85. );
  86. }
  87. if ($origin=='learnpath') {
  88. include(api_get_path(INCLUDE_PATH).'reduced_header.inc.php');
  89. } else {
  90. if (!empty($_SESSION['toolgroup'])) {
  91. $_clean['toolgroup']=(int)$_SESSION['toolgroup'];
  92. $group_properties = GroupManager :: get_group_properties($_clean['toolgroup']);
  93. $interbreadcrumb[] = array ("url" => "../group/group.php", "name" => get_lang('Groups'));
  94. $interbreadcrumb[] = array ("url"=>"../group/group_space.php?gidReq=".$_SESSION['toolgroup'], "name"=> get_lang('GroupSpace').' ('.$group_properties['name'].')');
  95. $interbreadcrumb[]=array("url" => "viewforum.php?forum=".Security::remove_XSS($_GET['forum'])."&amp;origin=".$origin."&amp;search=".Security::remove_XSS(urlencode($_GET['search'])),"name" => prepare4display($current_forum['forum_title']));
  96. if ($message<>'PostDeletedSpecial') {
  97. $interbreadcrumb[]=array("url" => "viewthread.php?forum=".Security::remove_XSS($_GET['forum'])."&amp;gradebook=".$gradebook."&amp;thread=".Security::remove_XSS($_GET['thread']),"name" => prepare4display($current_thread['thread_title']));
  98. }
  99. $interbreadcrumb[]=array("url" => "#","name" => get_lang('QualifyThread'));
  100. // the last element of the breadcrumb navigation is already set in interbreadcrumb, so give empty string
  101. Display :: display_header('');
  102. api_display_tool_title($nameTools);
  103. } else {
  104. $info_thread=get_thread_information(Security::remove_XSS($_GET['thread']));
  105. $interbreadcrumb[]=array("url" => "index.php?gradebook=$gradebook&search=".Security::remove_XSS(urlencode($_GET['search'])),"name" => $nameTools);
  106. $interbreadcrumb[]=array("url" => "viewforumcategory.php?forumcategory=".$current_forum_category['cat_id']."&amp;search=".Security::remove_XSS(urlencode($_GET['search'])),"name" => prepare4display($current_forum_category['cat_title']));
  107. $interbreadcrumb[]=array("url" => "viewforum.php?forum=".Security::remove_XSS($_GET['forum'])."&amp;origin=".$origin."&amp;search=".Security::remove_XSS(urlencode($_GET['search'])),"name" => prepare4display($current_forum['forum_title']));
  108. if ($message<>'PostDeletedSpecial') {
  109. if (isset($_GET['gradebook']) and $_GET['gradebook']=='view') {
  110. $info_thread=get_thread_information(Security::remove_XSS($_GET['thread']));
  111. $interbreadcrumb[]=array("url" => "viewthread.php?forum=".$info_thread['forum_id']."&amp;gradebook=".$gradebook."&amp;thread=".Security::remove_XSS($_GET['thread']),"name" => prepare4display($current_thread['thread_title']));
  112. } else {
  113. $interbreadcrumb[]=array("url" => "viewthread.php?forum=".Security::remove_XSS($_GET['forum'])."&amp;gradebook=".$gradebook."&amp;thread=".Security::remove_XSS($_GET['thread']),"name" => prepare4display($current_thread['thread_title']));
  114. }
  115. }
  116. // the last element of the breadcrumb navigation is already set in interbreadcrumb, so give empty string
  117. $interbreadcrumb[]=array("url" => "#","name" => get_lang('QualifyThread'));
  118. Display :: display_header('');
  119. api_display_tool_title($nameTools);
  120. }
  121. }
  122. /*
  123. -----------------------------------------------------------
  124. Is the user allowed here?
  125. -----------------------------------------------------------
  126. */
  127. // if the user is not a course administrator and the forum is hidden
  128. // then the user is not allowed here.
  129. if (!api_is_allowed_to_edit(false,true) AND ($current_forum['visibility']==0 OR $current_thread['visibility']==0)) {
  130. forum_not_allowed_here();
  131. }
  132. /*
  133. -----------------------------------------------------------
  134. Actions
  135. -----------------------------------------------------------
  136. */
  137. if ($_GET['action']=='delete' && isset($_GET['content']) && isset($_GET['id']) && api_is_allowed_to_edit(false,true)) {
  138. $message=delete_post($_GET['id']); // note: this has to be cleaned first
  139. }
  140. if (($_GET['action']=='invisible' || $_GET['action']=='visible') && isset($_GET['id']) && api_is_allowed_to_edit(false,true)) {
  141. $message=approve_post($_GET['id'],$_GET['action']); // note: this has to be cleaned first
  142. }
  143. if ($_GET['action']=='move' and isset($_GET['post'])) {
  144. $message=move_post_form();
  145. }
  146. /*
  147. -----------------------------------------------------------
  148. Display the action messages
  149. -----------------------------------------------------------
  150. */
  151. if (!empty($message)) {
  152. Display :: display_confirmation_message(get_lang($message));
  153. }
  154. if ($message<>'PostDeletedSpecial') {// in this case the first and only post of the thread is removed
  155. // this increases the number of times the thread has been viewed
  156. increase_thread_view($_GET['thread']);
  157. /*
  158. -----------------------------------------------------------
  159. Action Links
  160. -----------------------------------------------------------
  161. */
  162. /* echo '<div style="float:right;">';
  163. $my_url = '<a href="viewthread.php?'.api_get_cidreq().'&amp;forum='.Security::remove_XSS($_GET['forum']).'&amp;thread='.Security::remove_XSS($_GET['thread']).'&amp;origin='.$origin.'&amp;search='.Security::remove_XSS(urlencode($_GET['search']));
  164. echo $my_url.'&amp;view=flat&origin='.$origin.'">'.get_lang('FlatView').'</a> | ';
  165. echo $my_url.'&amp;view=threaded&origin='.$origin.'">'.get_lang('ThreadedView').'</a> | ';
  166. echo $my_url.'&amp;view=nested&origin='.$origin.'">'.get_lang('NestedView').'</a>';
  167. $my_url = null;
  168. echo '</div>';*/
  169. // the reply to thread link should only appear when the forum_category is not locked AND the forum is not locked AND the thread is not locked.
  170. // if one of the three levels is locked then the link should not be displayed
  171. if ($current_forum_category['locked']==0 AND $current_forum['locked']==0 AND $current_thread['locked']==0 OR api_is_allowed_to_edit(false,true)) {
  172. // The link should only appear when the user is logged in or when anonymous posts are allowed.
  173. if ($_user['user_id'] OR ($current_forum['allow_anonymous']==1 AND !$_user['user_id'])) {
  174. //reply link
  175. /*echo '<a href="reply.php?'.api_get_cidreq().'&forum='.Security::remove_XSS($_GET['forum']).'&amp;thread='.Security::remove_XSS($_GET['thread']).'&amp;action=replythread&origin='.$origin.'">'.get_lang('ReplyToThread').'</a>';*/
  176. //new thread link
  177. if (api_is_allowed_to_edit(false,true) OR ($current_forum['allow_new_threads']==1 AND isset($_user['user_id'])) OR ($current_forum['allow_new_threads']==1 AND !isset($_user['user_id']) AND $current_forum['allow_anonymous']==1)) {
  178. if ($current_forum['locked'] <> 1 AND $current_forum['locked'] <> 1) {
  179. echo '&nbsp;&nbsp;';
  180. /*echo '<a href="newthread.php?'.api_get_cidreq().'&forum='.Security::remove_XSS($_GET['forum']).$origin_string.'">'.Display::return_icon('forumthread_new.gif').' '.get_lang('NewTopic').'</a>';*/
  181. } else {
  182. echo get_lang('ForumLocked');
  183. }
  184. }
  185. }
  186. }
  187. // note: this is to prevent that some browsers display the links over the table (FF does it but Opera doesn't)
  188. echo '&nbsp;';
  189. /*
  190. -----------------------------------------------------------
  191. Display Forum Category and the Forum information
  192. -----------------------------------------------------------
  193. */
  194. if (!$_SESSION['view']) {
  195. $viewmode=$current_forum['default_view'];
  196. } else {
  197. $viewmode=$_SESSION['view'];
  198. }
  199. $viewmode_whitelist=array('flat', 'threaded', 'nested');
  200. if (isset($_GET['view']) and in_array($_GET['view'],$viewmode_whitelist)) {
  201. $viewmode=Database::escape_string($_GET['view']);
  202. $_SESSION['view']=$viewmode;
  203. }
  204. if (empty($viewmode)) {
  205. $viewmode = 'flat';
  206. }
  207. /*
  208. -----------------------------------------------------------
  209. Display Forum Category and the Forum information
  210. -----------------------------------------------------------
  211. */
  212. // we are getting all the information about the current forum and forum category.
  213. // note pcool: I tried to use only one sql statement (and function) for this
  214. // but the problem is that the visibility of the forum AND forum cateogory are stored in the item_property table
  215. echo "<table class=\"data_table\" width=\"100%\">\n";
  216. // the thread
  217. echo "\t<tr>\n\t\t<th style=\"padding-left:5px;\" align=\"left\" colspan=\"6\">";
  218. echo '<span class="forum_title">'.prepare4display($current_thread['thread_title']).'</span><br />';
  219. if ($origin!='learnpath') {
  220. echo '<span class="forum_low_description">'.prepare4display($current_forum_category['cat_title']).' - ';
  221. }
  222. echo prepare4display($current_forum['forum_title']).'<br />';
  223. echo "</th>\n";
  224. echo "\t</tr>\n";
  225. echo '<span>'.prepare4display($current_thread['thread_comment']).'</span>';
  226. echo "</table>";
  227. include_once('viewpost.inc.php');
  228. } // if ($message<>'PostDeletedSpecial') // in this case the first and only post of the thread is removed
  229. $userinf=api_get_user_info(api_get_user_id());
  230. if ($allowed_to_edit) {
  231. //echo "<strong>".get_lang('QualifyThread')."</strong>";
  232. //echo "<br />";
  233. $current_thread=get_thread_information($_GET['thread']);
  234. $userid=(int)$_GET['user_id'];
  235. $threadid=$current_thread['thread_id'];
  236. //show current qualify in my form
  237. $qualify=current_qualify_of_thread($threadid,api_get_session_id());
  238. //show max qualify in my form
  239. $max_qualify=show_qualify('2',$_GET['cidReq'],$_GET['forum'],$userid,$threadid);
  240. require_once 'forumbody.inc.php';
  241. $value_return = store_theme_qualify($userid,$threadid,$_REQUEST['idtextqualify'],api_get_user_id(),date("Y-m-d H:i:s"),api_get_session_id());
  242. $url='cidReq='.Security::remove_XSS($_GET['cidReq']).'&forum='.Security::remove_XSS($_GET['forum']).'&thread='.Security::remove_XSS($_GET['thread']).'&post='.Security::remove_XSS($_GET['post']).'&origin='.$origin.'&user_id='.Security::remove_XSS($_GET['user_id']);
  243. $current_qualify_thread=show_qualify('1',$_GET['cidReq'],$_GET['forum'],$userid,$threadid);
  244. if ($value_return[0]!=$_REQUEST['idtextqualify'] && $value_return[1]=='update') {
  245. store_qualify_historical('1','',$_GET['forum'],$userid,$threadid,$_REQUEST['idtextqualify'],api_get_user_id());
  246. }
  247. if (!empty($_REQUEST['idtextqualify']) && $_REQUEST['idtextqualify'] > $max_qualify) {
  248. $return_message = get_lang('QualificationCanNotBeGreaterThanMaxScore');
  249. Display :: display_error_message($return_message,false);
  250. }
  251. // show qualifications history
  252. $user_id_thread = (int)$_GET['user_id'];
  253. $opt=Database::escape_string($_GET['type']);
  254. $qualify_historic = get_historical_qualify($user_id_thread, $threadid, $opt);
  255. $counter= count($qualify_historic);
  256. $act_qualify = $_REQUEST['idtextqualify'];
  257. if ($counter>0) {
  258. if (isset($_GET['gradebook'])){
  259. $view_gradebook='&gradebook=view';
  260. }
  261. echo '<h4>'.get_lang('QualificationChangesHistory').'</h4>';
  262. if ($_GET['type'] == 'false') {
  263. echo '<div style="float:left; clear:left">'.get_lang('OrderBy').'&nbsp;:<a href="forumqualify.php?'.api_get_cidreq().'&forum='.Security::remove_XSS($_GET['forum']).'&origin='.$origin.'&thread='.$threadid.'&user='.Security::remove_XSS($_GET['user']).'&user_id='.Security::remove_XSS($_GET['user_id']).'&type=true&idtextqualify='.$act_qualify.$view_gradebook.'#history">'.get_lang('MoreRecent').'</a>&nbsp;|
  264. '.get_lang('Older').'
  265. </div>';
  266. } else {
  267. echo '<div style="float:left; clear:left">'.get_lang('OrderBy').'&nbsp;:'.get_lang('MoreRecent').' |
  268. <a href="forumqualify.php?'.api_get_cidreq().'&forum='.Security::remove_XSS($_GET['forum']).'&origin='.$origin.'&thread='.$threadid.'&user='.Security::remove_XSS($_GET['user']).'&user_id='.Security::remove_XSS($_GET['user_id']).'&type=false&idtextqualify='.$act_qualify.$view_gradebook.'#history">'.get_lang('Older').'</a>&nbsp;
  269. </div>';
  270. }
  271. $table_list.= '<a name="history" /><br /><br /><table class="data_table" style="width:100%">';
  272. $table_list.= '<tr>';
  273. $table_list.= '<th width="50%">'.get_lang('WhoChanged').'</th>';
  274. $table_list.= '<th width="10%">'.get_lang('NoteChanged').'</th>';
  275. $table_list.= '<th width="40%">'.get_lang('DateChanged').'</th>';
  276. $table_list.= '</tr>';
  277. for($i=0;$i<count($qualify_historic);$i++) {
  278. $my_user_info=api_get_user_info($qualify_historic[$i]['qualify_user_id']);
  279. $name = api_get_person_name($my_user_info['firstName'], $my_user_info['lastName']);
  280. $table_list.= '<tr class="'.$class.'"><td>'.$name.'</td>';
  281. $table_list.= '<td>'.$qualify_historic[$i]['qualify'].'</td>';
  282. $table_list.= '<td>'.$qualify_historic[$i]['qualify_time'].'</td></tr>';
  283. }
  284. $table_list.= '</table>';
  285. echo $table_list;
  286. } else {
  287. echo get_lang('NotChanged');
  288. }
  289. } else {
  290. api_not_allowed();
  291. }
  292. /*
  293. ==============================================================================
  294. FOOTER
  295. ==============================================================================
  296. */
  297. if ($origin!='learnpath') {
  298. Display :: display_footer();
  299. }