forumqualify.php 15 KB

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