forumqualify.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  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('ToolForum');
  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('ToolForum');
  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('ToolGradebook')
  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_allow = forum_not_allowed_here();
  131. if ($forum_allow === false) {
  132. exit;
  133. }
  134. }
  135. /*
  136. -----------------------------------------------------------
  137. Actions
  138. -----------------------------------------------------------
  139. */
  140. if ($_GET['action']=='delete' && isset($_GET['content']) && isset($_GET['id']) && api_is_allowed_to_edit(false,true)) {
  141. $message=delete_post($_GET['id']); // note: this has to be cleaned first
  142. }
  143. if (($_GET['action']=='invisible' || $_GET['action']=='visible') && isset($_GET['id']) && api_is_allowed_to_edit(false,true)) {
  144. $message=approve_post($_GET['id'],$_GET['action']); // note: this has to be cleaned first
  145. }
  146. if ($_GET['action']=='move' and isset($_GET['post'])) {
  147. $message=move_post_form();
  148. }
  149. /*
  150. -----------------------------------------------------------
  151. Display the action messages
  152. -----------------------------------------------------------
  153. */
  154. if (!empty($message)) {
  155. Display :: display_confirmation_message(get_lang($message));
  156. }
  157. if ($message<>'PostDeletedSpecial') {// in this case the first and only post of the thread is removed
  158. // this increases the number of times the thread has been viewed
  159. increase_thread_view($_GET['thread']);
  160. /*
  161. -----------------------------------------------------------
  162. Action Links
  163. -----------------------------------------------------------
  164. */
  165. /* echo '<div style="float:right;">';
  166. $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']));
  167. echo $my_url.'&amp;view=flat&origin='.$origin.'">'.get_lang('FlatView').'</a> | ';
  168. echo $my_url.'&amp;view=threaded&origin='.$origin.'">'.get_lang('ThreadedView').'</a> | ';
  169. echo $my_url.'&amp;view=nested&origin='.$origin.'">'.get_lang('NestedView').'</a>';
  170. $my_url = null;
  171. echo '</div>';*/
  172. // 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.
  173. // if one of the three levels is locked then the link should not be displayed
  174. if ($current_forum_category['locked']==0 AND $current_forum['locked']==0 AND $current_thread['locked']==0 OR api_is_allowed_to_edit(false,true)) {
  175. // The link should only appear when the user is logged in or when anonymous posts are allowed.
  176. if ($_user['user_id'] OR ($current_forum['allow_anonymous']==1 AND !$_user['user_id'])) {
  177. //reply link
  178. /*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>';*/
  179. //new thread link
  180. 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)) {
  181. if ($current_forum['locked'] <> 1 AND $current_forum['locked'] <> 1) {
  182. echo '&nbsp;&nbsp;';
  183. /*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>';*/
  184. } else {
  185. echo get_lang('ForumLocked');
  186. }
  187. }
  188. }
  189. }
  190. // note: this is to prevent that some browsers display the links over the table (FF does it but Opera doesn't)
  191. echo '&nbsp;';
  192. /*
  193. -----------------------------------------------------------
  194. Display Forum Category and the Forum information
  195. -----------------------------------------------------------
  196. */
  197. if (!$_SESSION['view']) {
  198. $viewmode=$current_forum['default_view'];
  199. } else {
  200. $viewmode=$_SESSION['view'];
  201. }
  202. $viewmode_whitelist=array('flat', 'threaded', 'nested');
  203. if (isset($_GET['view']) and in_array($_GET['view'],$viewmode_whitelist)) {
  204. $viewmode=Database::escape_string($_GET['view']);
  205. $_SESSION['view']=$viewmode;
  206. }
  207. if (empty($viewmode)) {
  208. $viewmode = 'flat';
  209. }
  210. /*
  211. -----------------------------------------------------------
  212. Display Forum Category and the Forum information
  213. -----------------------------------------------------------
  214. */
  215. // we are getting all the information about the current forum and forum category.
  216. // note pcool: I tried to use only one sql statement (and function) for this
  217. // but the problem is that the visibility of the forum AND forum cateogory are stored in the item_property table
  218. echo "<table class=\"data_table\" width=\"100%\">\n";
  219. // the thread
  220. echo "\t<tr>\n\t\t<th style=\"padding-left:5px;\" align=\"left\" colspan=\"6\">";
  221. echo '<span class="forum_title">'.prepare4display($current_thread['thread_title']).'</span><br />';
  222. if ($origin!='learnpath') {
  223. echo '<span class="forum_low_description">'.prepare4display($current_forum_category['cat_title']).' - ';
  224. }
  225. echo prepare4display($current_forum['forum_title']).'<br />';
  226. echo "</th>\n";
  227. echo "\t</tr>\n";
  228. echo '<span>'.prepare4display($current_thread['thread_comment']).'</span>';
  229. echo "</table>";
  230. include_once('viewpost.inc.php');
  231. } // if ($message<>'PostDeletedSpecial') // in this case the first and only post of the thread is removed
  232. $userinf=api_get_user_info(api_get_user_id());
  233. if ($allowed_to_edit) {
  234. //echo "<strong>".get_lang('QualifyThread')."</strong>";
  235. //echo "<br />";
  236. $current_thread=get_thread_information($_GET['thread']);
  237. $userid=(int)$_GET['user_id'];
  238. $threadid=$current_thread['thread_id'];
  239. //show current qualify in my form
  240. $qualify=current_qualify_of_thread($threadid,api_get_session_id());
  241. //show max qualify in my form
  242. $max_qualify=show_qualify('2',$_GET['cidReq'],$_GET['forum'],$userid,$threadid);
  243. require_once 'forumbody.inc.php';
  244. $value_return = store_theme_qualify($userid,$threadid,$_REQUEST['idtextqualify'],api_get_user_id(),date("Y-m-d H:i:s"),api_get_session_id());
  245. $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']);
  246. $current_qualify_thread=show_qualify('1',$_GET['cidReq'],$_GET['forum'],$userid,$threadid);
  247. if ($value_return[0]!=$_REQUEST['idtextqualify'] && $value_return[1]=='update') {
  248. store_qualify_historical('1','',$_GET['forum'],$userid,$threadid,$_REQUEST['idtextqualify'],api_get_user_id());
  249. }
  250. if (!empty($_REQUEST['idtextqualify']) && $_REQUEST['idtextqualify'] > $max_qualify) {
  251. $return_message = get_lang('QualificationCanNotBeGreaterThanMaxScore');
  252. Display :: display_error_message($return_message,false);
  253. }
  254. // show qualifications history
  255. $user_id_thread = (int)$_GET['user_id'];
  256. $opt=Database::escape_string($_GET['type']);
  257. $qualify_historic = get_historical_qualify($user_id_thread, $threadid, $opt);
  258. $counter= count($qualify_historic);
  259. $act_qualify = $_REQUEST['idtextqualify'];
  260. if ($counter>0) {
  261. if (isset($_GET['gradebook'])){
  262. $view_gradebook='&gradebook=view';
  263. }
  264. echo '<h4>'.get_lang('QualificationChangesHistory').'</h4>';
  265. if ($_GET['type'] == 'false') {
  266. 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;|
  267. '.get_lang('Older').'
  268. </div>';
  269. } else {
  270. echo '<div style="float:left; clear:left">'.get_lang('OrderBy').'&nbsp;:'.get_lang('MoreRecent').' |
  271. <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;
  272. </div>';
  273. }
  274. $table_list.= '<a name="history" /><br /><br /><table class="data_table" style="width:100%">';
  275. $table_list.= '<tr>';
  276. $table_list.= '<th width="50%">'.get_lang('WhoChanged').'</th>';
  277. $table_list.= '<th width="10%">'.get_lang('NoteChanged').'</th>';
  278. $table_list.= '<th width="40%">'.get_lang('DateChanged').'</th>';
  279. $table_list.= '</tr>';
  280. for($i=0;$i<count($qualify_historic);$i++) {
  281. $my_user_info=api_get_user_info($qualify_historic[$i]['qualify_user_id']);
  282. $name = api_get_person_name($my_user_info['firstName'], $my_user_info['lastName']);
  283. $table_list.= '<tr class="'.$class.'"><td>'.$name.'</td>';
  284. $table_list.= '<td>'.$qualify_historic[$i]['qualify'].'</td>';
  285. $table_list.= '<td>'.$qualify_historic[$i]['qualify_time'].'</td></tr>';
  286. }
  287. $table_list.= '</table>';
  288. echo $table_list;
  289. } else {
  290. echo get_lang('NotChanged');
  291. }
  292. } else {
  293. api_not_allowed();
  294. }
  295. /*
  296. ==============================================================================
  297. FOOTER
  298. ==============================================================================
  299. */
  300. if ($origin!='learnpath') {
  301. Display :: display_footer();
  302. }