forumqualify.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.forum
  5. * @todo fix all this qualify files avoid including files, use classes POO jmontoya
  6. */
  7. // name of the language file that needs to be included
  8. $language_file = array('admin', 'forum');
  9. require_once '../inc/global.inc.php';
  10. require_once 'forumconfig.inc.php';
  11. require_once 'forumfunction.inc.php';
  12. $nameTools = get_lang('ToolForum');
  13. $this_section = SECTION_COURSES;
  14. $allowed_to_edit = api_is_allowed_to_edit(null,true);
  15. if (!$allowed_to_edit) {
  16. api_not_allowed(true);
  17. }
  18. //are we in a lp ?
  19. $origin = '';
  20. if (isset($_GET['origin'])) {
  21. $origin = Security::remove_XSS($_GET['origin']);
  22. }
  23. $user_id = isset($_GET['user_id']) ? intval($_GET['user_id']) : null;
  24. api_block_course_item_locked_by_gradebook($_GET['thread'], LINK_FORUM_THREAD);
  25. $nameTools = get_lang('ToolForum');
  26. /* Including necessary files */
  27. $htmlHeadXtra[] = '<script type="text/javascript" language="javascript">
  28. $(document).ready(function(){ $(\'.hide-me\').slideUp() });
  29. function hidecontent(content){ $(content).slideToggle(\'normal\'); }
  30. </script>';
  31. /* MAIN DISPLAY SECTION */
  32. /*
  33. Retrieving forum and forum categorie information
  34. */
  35. // we are getting all the information about the current forum and forum category.
  36. // note pcool: I tried to use only one sql statement (and function) for this
  37. // but the problem is that the visibility of the forum AND forum cateogory are stored in the item_property table
  38. $current_thread=get_thread_information($_GET['thread']); // note: this has to be validated that it is an existing thread
  39. $current_forum=get_forum_information($current_thread['forum_id']); // note: this has to be validated that it is an existing forum.
  40. $current_forum_category=get_forumcategory_information($current_forum['forum_category']);
  41. $group_id = api_get_group_id();
  42. /*
  43. Header and Breadcrumbs
  44. */
  45. if (isset($_SESSION['gradebook'])){
  46. $gradebook= $_SESSION['gradebook'];
  47. }
  48. if (!empty($gradebook) && $gradebook=='view') {
  49. $interbreadcrumb[]= array (
  50. 'url' => '../gradebook/'.$_SESSION['gradebook_dest'],
  51. 'name' => get_lang('ToolGradebook')
  52. );
  53. }
  54. if ($origin=='learnpath') {
  55. Display::display_reduced_header();
  56. } else {
  57. if (!empty($group_id)) {
  58. $group_properties = GroupManager :: get_group_properties($_clean['toolgroup']);
  59. $interbreadcrumb[] = array ("url" => "../group/group.php", "name" => get_lang('Groups'));
  60. $interbreadcrumb[] = array ("url"=>"../group/group_space.php?gidReq=".$group_id, "name"=> get_lang('GroupSpace').' ('.$group_properties['name'].')');
  61. $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']));
  62. if ($message<>'PostDeletedSpecial') {
  63. $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']));
  64. }
  65. $interbreadcrumb[]=array("url" => "#","name" => get_lang('QualifyThread'));
  66. // the last element of the breadcrumb navigation is already set in interbreadcrumb, so give empty string
  67. Display :: display_header('');
  68. api_display_tool_title($nameTools);
  69. } else {
  70. $info_thread=get_thread_information(Security::remove_XSS($_GET['thread']));
  71. $interbreadcrumb[]=array("url" => "index.php?gradebook=$gradebook&amp;search=".Security::remove_XSS(urlencode($_GET['search'])),"name" => $nameTools);
  72. $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']));
  73. $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']));
  74. if ($message<>'PostDeletedSpecial') {
  75. if (isset($_GET['gradebook']) and $_GET['gradebook']=='view') {
  76. $info_thread=get_thread_information(Security::remove_XSS($_GET['thread']));
  77. $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']));
  78. } else {
  79. $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']));
  80. }
  81. }
  82. // the last element of the breadcrumb navigation is already set in interbreadcrumb, so give empty string
  83. $interbreadcrumb[]=array("url" => "#","name" => get_lang('QualifyThread'));
  84. Display :: display_header('');
  85. }
  86. }
  87. /*
  88. Is the user allowed here?
  89. */
  90. // if the user is not a course administrator and the forum is hidden
  91. // then the user is not allowed here.
  92. if (!api_is_allowed_to_edit(false,true) AND ($current_forum['visibility']==0 OR $current_thread['visibility']==0)) {
  93. $forum_allow = forum_not_allowed_here();
  94. if ($forum_allow === false) {
  95. exit;
  96. }
  97. }
  98. /*
  99. Actions
  100. */
  101. if ($_GET['action']=='delete' && isset($_GET['content']) && isset($_GET['id']) && api_is_allowed_to_edit(false,true)) {
  102. $message=delete_post($_GET['id']); // note: this has to be cleaned first
  103. }
  104. if (($_GET['action']=='invisible' || $_GET['action']=='visible') && isset($_GET['id']) && api_is_allowed_to_edit(false,true)) {
  105. $message=approve_post($_GET['id'],$_GET['action']); // note: this has to be cleaned first
  106. }
  107. if ($_GET['action']=='move' and isset($_GET['post'])) {
  108. $message = move_post_form();
  109. }
  110. /*
  111. Display the action messages
  112. */
  113. if (!empty($message)) {
  114. Display :: display_confirmation_message(get_lang($message));
  115. }
  116. if ($message<>'PostDeletedSpecial') {// in this case the first and only post of the thread is removed
  117. // this increases the number of times the thread has been viewed
  118. increase_thread_view($_GET['thread']);
  119. /*
  120. Action Links
  121. */
  122. // 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.
  123. // if one of the three levels is locked then the link should not be displayed
  124. if (($current_forum_category && $current_forum_category['locked']==0) AND $current_forum['locked']==0 AND $current_thread['locked']==0 OR api_is_allowed_to_edit(false,true)) {
  125. // The link should only appear when the user is logged in or when anonymous posts are allowed.
  126. if ($_user['user_id'] OR ($current_forum['allow_anonymous']==1 AND !$_user['user_id'])) {
  127. //reply link
  128. /*echo '<a href="reply.php?'.api_get_cidreq().'&amp;forum='.Security::remove_XSS($_GET['forum']).'&amp;thread='.Security::remove_XSS($_GET['thread']).'&amp;action=replythread&amp;origin='.$origin.'">'.get_lang('ReplyToThread').'</a>';*/
  129. //new thread link
  130. 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)) {
  131. if ($current_forum['locked'] <> 1 AND $current_forum['locked'] <> 1) {
  132. echo '&nbsp;&nbsp;';
  133. } else {
  134. echo get_lang('ForumLocked');
  135. }
  136. }
  137. }
  138. }
  139. // note: this is to prevent that some browsers display the links over the table (FF does it but Opera doesn't)
  140. echo '&nbsp;';
  141. /*
  142. Display Forum Category and the Forum information
  143. */
  144. if (!$_SESSION['view']) {
  145. $viewmode=$current_forum['default_view'];
  146. } else {
  147. $viewmode=$_SESSION['view'];
  148. }
  149. $viewmode_whitelist=array('flat', 'threaded', 'nested');
  150. if (isset($_GET['view']) and in_array($_GET['view'],$viewmode_whitelist)) {
  151. $viewmode=Database::escape_string($_GET['view']);
  152. $_SESSION['view']=$viewmode;
  153. }
  154. if (empty($viewmode)) {
  155. $viewmode = 'flat';
  156. }
  157. /*
  158. Display Forum Category and the Forum information
  159. */
  160. // we are getting all the information about the current forum and forum category.
  161. // note pcool: I tried to use only one sql statement (and function) for this
  162. // but the problem is that the visibility of the forum AND forum cateogory are stored in the item_property table
  163. echo "<table class=\"data_table\">";
  164. // the thread
  165. echo "<tr><th style=\"padding-left:5px;\" align=\"left\" colspan=\"6\">";
  166. echo '<span class="forum_title">'.prepare4display($current_thread['thread_title']).'</span><br />';
  167. if ($origin!='learnpath') {
  168. echo '<span class="forum_low_description">'.prepare4display($current_forum_category['cat_title']).' - ';
  169. }
  170. echo prepare4display($current_forum['forum_title']).'<br />';
  171. echo "</th>";
  172. echo "</tr>";
  173. echo '<span>'.prepare4display($current_thread['thread_comment']).'</span>';
  174. echo "</table>";
  175. include_once 'viewpost.inc.php';
  176. } // if ($message<>'PostDeletedSpecial') // in this case the first and only post of the thread is removed
  177. if ($allowed_to_edit) {
  178. $current_thread=get_thread_information($_GET['thread']);
  179. $threadid=$current_thread['thread_id'];
  180. //show current qualify in my form
  181. $qualify=current_qualify_of_thread($threadid, api_get_session_id());
  182. //show max qualify in my form
  183. $max_qualify=show_qualify('2',$user_id,$threadid);
  184. require_once 'forumbody.inc.php';
  185. $value_return = store_theme_qualify($user_id,$threadid,$_REQUEST['idtextqualify'],api_get_user_id(),date("Y-m-d H:i:s"),api_get_session_id());
  186. $url='cidReq='.Security::remove_XSS($_GET['cidReq']).'&amp;forum='.Security::remove_XSS($_GET['forum']).'&amp;thread='.Security::remove_XSS($_GET['thread']).'&amp;post='.Security::remove_XSS($_GET['post']).'&amp;origin='.$origin.'&amp;user_id='.Security::remove_XSS($_GET['user_id']);
  187. $current_qualify_thread=show_qualify('1',$user_id,$threadid);
  188. if ($value_return[0]!=$_REQUEST['idtextqualify'] && $value_return[1]=='update') {
  189. store_qualify_historical('1','',$_GET['forum'],$user_id,$threadid,$_REQUEST['idtextqualify'],api_get_user_id());
  190. }
  191. if (!empty($_REQUEST['idtextqualify']) && $_REQUEST['idtextqualify'] > $max_qualify) {
  192. $return_message = get_lang('QualificationCanNotBeGreaterThanMaxScore');
  193. Display :: display_error_message($return_message,false);
  194. }
  195. // show qualifications history
  196. $qualify_historic = get_historical_qualify($user_id, $threadid, $_GET['type']);
  197. $counter = count($qualify_historic);
  198. $act_qualify = $_REQUEST['idtextqualify'];
  199. if ($counter>0) {
  200. if (isset($_GET['gradebook'])){
  201. $view_gradebook='&amp;gradebook=view';
  202. }
  203. echo '<h4>'.get_lang('QualificationChangesHistory').'</h4>';
  204. if ($_GET['type'] == 'false') {
  205. $buttons = '<a class="btn" href="forumqualify.php?'.api_get_cidreq().'&amp;forum='.Security::remove_XSS($_GET['forum']).'&amp;origin='.$origin.'&amp;thread='.$threadid.'&amp;user='.Security::remove_XSS($_GET['user']).'&amp;user_id='.Security::remove_XSS($_GET['user_id']).'&amp;type=true&amp;idtextqualify='.$act_qualify.$view_gradebook.'#history">'.
  206. get_lang('MoreRecent').'</a> <a class="btn disabled" >'.get_lang('Older').'</a>';
  207. } else {
  208. $buttons = '<a class="btn disabled">'.get_lang('MoreRecent').'</a>
  209. <a class="btn" href="forumqualify.php?'.api_get_cidreq().'&amp;forum='.Security::remove_XSS($_GET['forum']).'&amp;origin='.$origin.'&amp;thread='.$threadid.'&amp;user='.Security::remove_XSS($_GET['user']).'&amp;user_id='.Security::remove_XSS($_GET['user_id']).'&amp;type=false&amp;idtextqualify='.$act_qualify.$view_gradebook.'#history">'.
  210. get_lang('Older').'</a>';
  211. }
  212. $table_list.= '<br /><div class="btn-group">'.$buttons.'</div>';
  213. $table_list.= '<br /><table class="data_table">';
  214. $table_list.= '<tr>';
  215. $table_list.= '<th width="50%">'.get_lang('WhoChanged').'</th>';
  216. $table_list.= '<th width="10%">'.get_lang('NoteChanged').'</th>';
  217. $table_list.= '<th width="40%">'.get_lang('DateChanged').'</th>';
  218. $table_list.= '</tr>';
  219. for ($i=0;$i<count($qualify_historic);$i++) {
  220. $my_user_info=api_get_user_info($qualify_historic[$i]['qualify_user_id']);
  221. $name = api_get_person_name($my_user_info['firstName'], $my_user_info['lastName']);
  222. $table_list.= '<tr class="'.$class.'"><td>'.$name.'</td>';
  223. $table_list.= '<td>'.$qualify_historic[$i]['qualify'].'</td>';
  224. $table_list.= '<td>'.api_convert_and_format_date($qualify_historic[$i]['qualify_time'], DATE_TIME_FORMAT_LONG).'</td></tr>';
  225. }
  226. $table_list.= '</table>';
  227. echo $table_list;
  228. } else {
  229. //echo get_lang('NotChanged');
  230. }
  231. } else {
  232. api_not_allowed();
  233. }
  234. /* FOOTER */
  235. if ($origin!='learnpath') {
  236. Display :: display_footer();
  237. }