forumqualify.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  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. require_once '../inc/global.inc.php';
  8. require_once 'forumconfig.inc.php';
  9. require_once 'forumfunction.inc.php';
  10. $nameTools = get_lang('ToolForum');
  11. $this_section = SECTION_COURSES;
  12. $message = '';
  13. //are we in a lp ?
  14. $origin = '';
  15. if (isset($_GET['origin'])) {
  16. $origin = Security::remove_XSS($_GET['origin']);
  17. }
  18. $currentUserId = api_get_user_id();
  19. $userIdToQualify = isset($_GET['user_id']) ? intval($_GET['user_id']) : null;
  20. api_block_course_item_locked_by_gradebook($_GET['thread'], LINK_FORUM_THREAD);
  21. $nameTools = get_lang('ToolForum');
  22. $allowed_to_edit = api_is_allowed_to_edit(null, true);
  23. $currentThread = get_thread_information($_GET['thread']);
  24. $currentForum = get_forum_information($currentThread['forum_id']);
  25. $allowToQualify = false;
  26. if ($allowed_to_edit) {
  27. $allowToQualify = true;
  28. } else {
  29. $allowToQualify = $currentThread['thread_peer_qualify'] == 1 && $currentForum['visibility'] == 1 && $userIdToQualify != $currentUserId;
  30. }
  31. if (!$allowToQualify) {
  32. api_not_allowed(true);
  33. }
  34. /* Including necessary files */
  35. $htmlHeadXtra[] = '<script>
  36. $(document).ready(function(){
  37. $(\'.hide-me\').slideUp()
  38. });
  39. function hidecontent(content){
  40. $(content).slideToggle(\'normal\');
  41. }
  42. </script>';
  43. $currentForumCategory = get_forumcategory_information(
  44. $currentForum['forum_category']
  45. );
  46. $groupId = api_get_group_id();
  47. /*
  48. Header and Breadcrumbs
  49. */
  50. if (isset($_SESSION['gradebook'])){
  51. $gradebook= $_SESSION['gradebook'];
  52. }
  53. if (!empty($gradebook) && $gradebook=='view') {
  54. $interbreadcrumb[]= array (
  55. 'url' => '../gradebook/'.$_SESSION['gradebook_dest'],
  56. 'name' => get_lang('ToolGradebook')
  57. );
  58. }
  59. if ($origin == 'learnpath') {
  60. Display::display_reduced_header();
  61. } else {
  62. if (!empty($groupId)) {
  63. $group_properties = GroupManager::get_group_properties($groupId);
  64. $interbreadcrumb[] = array(
  65. "url" => "../group/group.php",
  66. "name" => get_lang('Groups'),
  67. );
  68. $interbreadcrumb[] = array(
  69. "url" => "../group/group_space.php?".api_get_cidreq(),
  70. "name"=> get_lang('GroupSpace').' ('.$group_properties['name'].')'
  71. );
  72. $interbreadcrumb[] = array(
  73. "url" => "viewforum.php?forum=".Security::remove_XSS($_GET['forum'])."&origin=".$origin."&search=".Security::remove_XSS(urlencode($_GET['search'])),
  74. "name" => prepare4display($currentForum['forum_title'])
  75. );
  76. if ($message <> 'PostDeletedSpecial') {
  77. $interbreadcrumb[]= array(
  78. "url" => "viewthread.php?forum=".Security::remove_XSS($_GET['forum'])."&gradebook=".$gradebook."&thread=".Security::remove_XSS($_GET['thread']),
  79. "name" => prepare4display($currentThread['thread_title'])
  80. );
  81. }
  82. $interbreadcrumb[] = array(
  83. "url" => "#",
  84. "name" => get_lang('QualifyThread'),
  85. );
  86. // the last element of the breadcrumb navigation is already set in interbreadcrumb, so give empty string
  87. Display :: display_header('');
  88. api_display_tool_title($nameTools);
  89. } else {
  90. $search = isset($_GET['search']) ? Security::remove_XSS(urlencode($_GET['search'])) : '';
  91. $info_thread = get_thread_information($_GET['thread']);
  92. $interbreadcrumb[] = array(
  93. "url" => "index.php?".api_get_cidreq()."&search=".$search,
  94. "name" => $nameTools);
  95. $interbreadcrumb[] = array(
  96. "url" => "viewforumcategory.php?forumcategory=".$currentForumCategory['cat_id']."&search=".$search,
  97. "name" => prepare4display($currentForumCategory['cat_title'])
  98. );
  99. $interbreadcrumb[] = array(
  100. "url" => "viewforum.php?forum=".Security::remove_XSS($_GET['forum'])."&origin=".$origin."&search=".$search,
  101. "name" => prepare4display($currentForum['forum_title'])
  102. );
  103. if ($message <> 'PostDeletedSpecial') {
  104. if (isset($_GET['gradebook']) and $_GET['gradebook']=='view') {
  105. $info_thread=get_thread_information(Security::remove_XSS($_GET['thread']));
  106. $interbreadcrumb[] = array(
  107. "url" => "viewthread.php?".api_get_cidreq()."&forum=".$info_thread['forum_id']."&thread=".Security::remove_XSS($_GET['thread']),
  108. "name" => prepare4display($currentThread['thread_title'])
  109. );
  110. } else {
  111. $interbreadcrumb[] = array(
  112. "url" => "viewthread.php?".api_get_cidreq()."&forum=".Security::remove_XSS($_GET['forum'])."&thread=".Security::remove_XSS($_GET['thread']),
  113. "name" => prepare4display($currentThread['thread_title'])
  114. );
  115. }
  116. }
  117. // the last element of the breadcrumb navigation is already set in interbreadcrumb, so give empty string
  118. $interbreadcrumb[]=array("url" => "#","name" => get_lang('QualifyThread'));
  119. Display :: display_header('');
  120. }
  121. }
  122. /*
  123. Actions
  124. */
  125. $action = isset($_GET['action']) ? $_GET['action'] : '';
  126. if ($action =='delete' &&
  127. isset($_GET['content']) &&
  128. isset($_GET['id']) && api_is_allowed_to_edit(false, true)
  129. ) {
  130. $message = delete_post($_GET['id']);
  131. }
  132. if (($action == 'invisible' || $action == 'visible') &&
  133. isset($_GET['id']) && api_is_allowed_to_edit(false, true)
  134. ) {
  135. $message = approve_post($_GET['id'], $action);
  136. }
  137. if ($action == 'move' && isset($_GET['post'])) {
  138. $message = move_post_form();
  139. }
  140. /*
  141. Display the action messages
  142. */
  143. if (!empty($message)) {
  144. Display :: display_confirmation_message(get_lang($message));
  145. }
  146. if ($allowToQualify) {
  147. $currentThread = get_thread_information($_GET['thread']);
  148. $threadId = $currentThread['thread_id'];
  149. // Show max qualify in my form
  150. $maxQualify = showQualify('2', $userIdToQualify, $threadId);
  151. $score = isset($_POST['idtextqualify']) ? $_POST['idtextqualify'] : '';
  152. if ($score > $maxQualify) {
  153. Display:: display_error_message(
  154. get_lang('QualificationCanNotBeGreaterThanMaxScore'),
  155. false
  156. );
  157. }
  158. if (!empty($score)) {
  159. $saveResult = saveThreadScore(
  160. $currentThread,
  161. $userIdToQualify,
  162. $threadId,
  163. $score,
  164. api_get_utc_datetime(),
  165. api_get_session_id()
  166. );
  167. }
  168. // show qualifications history
  169. $type = isset($_GET['type']) ? $_GET['type'] : '';
  170. $historyList = getThreadScoreHistory(
  171. $userIdToQualify,
  172. $threadId,
  173. $type
  174. );
  175. $counter = count($historyList);
  176. // Show current qualify in my form
  177. $qualify = current_qualify_of_thread(
  178. $threadId,
  179. api_get_session_id(),
  180. $_GET['user']
  181. );
  182. $result = get_statistical_information(
  183. $threadId,
  184. $_GET['user_id'],
  185. api_get_course_int_id()
  186. );
  187. $url = api_get_path(WEB_CODE_PATH).'forum/forumqualify.php?'.
  188. api_get_cidreq().'&forum='.intval($_GET['forum']).'&thread='.$threadId.'&user='.intval($_GET['user']).'&user_id='.intval($_GET['user']);
  189. $userToQualifyInfo = api_get_user_info($userIdToQualify);
  190. $form = new FormValidator('forum-thread-qualify', 'post', $url);
  191. $form->addHeader($userToQualifyInfo['complete_name']);
  192. $form->addLabel(get_lang('Thread'), $currentThread['thread_title']);
  193. $form->addLabel(get_lang('CourseUsers'), $result['user_course']);
  194. $form->addLabel(get_lang('PostsNumber'), $result['post']);
  195. $form->addLabel(get_lang('NumberOfPostsForThisUser'), $result['user_post']);
  196. $form->addLabel(
  197. get_lang('AveragePostPerUser'),
  198. round($result['user_post'] / $result['post'], 2)
  199. );
  200. $form->addText(
  201. 'idtextqualify',
  202. array(get_lang('Qualification'), get_lang('MaxScore').' '.$maxQualify),
  203. $qualify
  204. );
  205. include 'viewpost.inc.php';
  206. $form->addButtonSave(get_lang('QualifyThisThread'));
  207. $form->setDefaults(array('idtextqualify' => $qualify));
  208. $form->display();
  209. // Show past data
  210. if (api_is_allowed_to_edit() && $counter > 0) {
  211. if (isset($_GET['gradebook'])){
  212. $view_gradebook='&gradebook=view';
  213. }
  214. echo '<h4>'.get_lang('QualificationChangesHistory').'</h4>';
  215. if (isset($_GET['type']) && $_GET['type'] == 'false') {
  216. $buttons = '<a class="btn btn-default" href="forumqualify.php?'.api_get_cidreq().'&forum='.intval($_GET['forum']).'&origin='.$origin.'&thread='.$threadId.'&user='.intval($_GET['user']).'&user_id='.intval($_GET['user_id']).'&type=true&idtextqualify='.$score.$view_gradebook.'#history">'.
  217. get_lang('MoreRecent').'</a> <a class="btn btn-default disabled" >'.get_lang('Older').'</a>';
  218. } else {
  219. $buttons = '<a class="btn btn-default">'.get_lang('MoreRecent').'</a>
  220. <a class="btn btn-default" href="forumqualify.php?'.api_get_cidreq().'&forum='.intval($_GET['forum']).'&origin='.$origin.'&thread='.$threadId.'&user='.intval($_GET['user']).'&user_id='.intval($_GET['user_id']).'&type=false&idtextqualify='.$score.$view_gradebook.'#history">'.
  221. get_lang('Older').'</a>';
  222. }
  223. $table_list = '<br /><div class="btn-group">'.$buttons.'</div>';
  224. $table_list .= '<br /><table class="table">';
  225. $table_list .= '<tr>';
  226. $table_list .= '<th width="50%">'.get_lang('WhoChanged').'</th>';
  227. $table_list .= '<th width="10%">'.get_lang('NoteChanged').'</th>';
  228. $table_list .= '<th width="40%">'.get_lang('DateChanged').'</th>';
  229. $table_list .= '</tr>';
  230. for ($i = 0; $i < count($historyList); $i++) {
  231. $userInfo = api_get_user_info($historyList[$i]['qualify_user_id']);
  232. $table_list .= '<tr><td>'.$userInfo['complete_name'].'</td>';
  233. $table_list .= '<td>'.$historyList[$i]['qualify'].'</td>';
  234. $table_list .= '<td>'.api_convert_and_format_date(
  235. $historyList[$i]['qualify_time'],
  236. DATE_TIME_FORMAT_LONG
  237. );
  238. $table_list .= '</td></tr>';
  239. }
  240. $table_list.= '</table>';
  241. echo $table_list;
  242. }
  243. }
  244. if ($origin!='learnpath') {
  245. Display :: display_footer();
  246. }