forumqualify.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.forum
  5. *
  6. * @todo fix all this qualify files avoid including files, use classes POO jmontoya
  7. */
  8. require_once __DIR__.'/../inc/global.inc.php';
  9. require_once 'forumfunction.inc.php';
  10. api_protect_course_script(true);
  11. $nameTools = get_lang('Forums');
  12. $this_section = SECTION_COURSES;
  13. $message = '';
  14. //are we in a lp ?
  15. $origin = api_get_origin();
  16. $currentUserId = api_get_user_id();
  17. $userIdToQualify = isset($_GET['user_id']) ? intval($_GET['user_id']) : null;
  18. $forumId = isset($_GET['forum']) ? intval($_GET['forum']) : 0;
  19. api_block_course_item_locked_by_gradebook($_GET['thread'], LINK_FORUM_THREAD);
  20. $nameTools = get_lang('Forums');
  21. $allowed_to_edit = api_is_allowed_to_edit(null, true);
  22. $currentThread = get_thread_information($forumId, $_GET['thread']);
  23. $forumId = $currentThread['forum_id'];
  24. $currentForum = get_forums($currentThread['forum_id']);
  25. $threadId = $currentThread['thread_id'];
  26. $allowToQualify = false;
  27. if ($allowed_to_edit) {
  28. $allowToQualify = true;
  29. } else {
  30. $allowToQualify = $currentThread['thread_peer_qualify'] == 1 && $currentForum['visibility'] == 1 && $userIdToQualify != $currentUserId;
  31. }
  32. if (!$allowToQualify) {
  33. api_not_allowed(true);
  34. }
  35. // Show max qualify in my form
  36. $maxQualify = showQualify('2', $userIdToQualify, $threadId);
  37. $score = 0;
  38. if (isset($_POST['idtextqualify'])) {
  39. $score = floatval($_POST['idtextqualify']);
  40. if ($score <= $maxQualify) {
  41. saveThreadScore(
  42. $currentThread,
  43. $userIdToQualify,
  44. $threadId,
  45. $score,
  46. api_get_utc_datetime(),
  47. api_get_session_id()
  48. );
  49. header(
  50. 'Location: '.api_get_path(WEB_CODE_PATH).'forum/viewforum.php?'.api_get_cidreq().'&'
  51. .http_build_query([
  52. 'forum' => $forumId,
  53. 'action' => 'liststd',
  54. 'content' => 'thread',
  55. 'id' => $threadId,
  56. 'list' => 'qualify',
  57. ])
  58. );
  59. exit;
  60. }
  61. Display::addFlash(
  62. Display::return_message(get_lang('Grade cannot exceed max score'), 'error')
  63. );
  64. }
  65. /* Including necessary files */
  66. $htmlHeadXtra[] = '<script>
  67. $(function() {
  68. $(\'.hide-me\').slideUp()
  69. });
  70. function hidecontent(content){
  71. $(content).slideToggle(\'normal\');
  72. }
  73. </script>';
  74. $currentForumCategory = get_forumcategory_information(
  75. $currentForum['forum_category']
  76. );
  77. $groupId = api_get_group_id();
  78. if (api_is_in_gradebook()) {
  79. $interbreadcrumb[] = [
  80. 'url' => Category::getUrl(),
  81. 'name' => get_lang('Assessments'),
  82. ];
  83. }
  84. $search = isset($_GET['search']) ? Security::remove_XSS(urlencode($_GET['search'])) : '';
  85. if ($origin == 'learnpath') {
  86. Display::display_reduced_header();
  87. } else {
  88. if (!empty($groupId)) {
  89. $group_properties = GroupManager::get_group_properties($groupId);
  90. $interbreadcrumb[] = [
  91. "url" => "../group/group.php?".api_get_cidreq(),
  92. "name" => get_lang('Groups'),
  93. ];
  94. $interbreadcrumb[] = [
  95. "url" => "../group/group_space.php?".api_get_cidreq(),
  96. "name" => get_lang('Group area').' ('.$group_properties['name'].')',
  97. ];
  98. $interbreadcrumb[] = [
  99. "url" => "viewforum.php?".api_get_cidreq()."&forum=".intval($_GET['forum'])."&search=".$search,
  100. "name" => prepare4display($currentForum['forum_title']),
  101. ];
  102. if ($message != 'PostDeletedSpecial') {
  103. $interbreadcrumb[] = [
  104. "url" => "viewthread.php?".api_get_cidreq()."&forum=".intval($_GET['forum'])."&thread=".intval($_GET['thread']),
  105. "name" => prepare4display($currentThread['thread_title']),
  106. ];
  107. }
  108. $interbreadcrumb[] = [
  109. "url" => "#",
  110. "name" => get_lang('Grade thread'),
  111. ];
  112. // the last element of the breadcrumb navigation is already set in interbreadcrumb, so give empty string
  113. Display::display_header('');
  114. api_display_tool_title($nameTools);
  115. } else {
  116. $info_thread = get_thread_information($currentForum['forum_id'], $_GET['thread']);
  117. $interbreadcrumb[] = [
  118. "url" => "index.php?".api_get_cidreq()."&search=".$search,
  119. "name" => $nameTools,
  120. ];
  121. $interbreadcrumb[] = [
  122. "url" => "viewforumcategory.php?".api_get_cidreq()."&forumcategory=".$currentForumCategory['cat_id']."&search=".$search,
  123. "name" => prepare4display($currentForumCategory['cat_title']),
  124. ];
  125. $interbreadcrumb[] = [
  126. "url" => "viewforum.php?".api_get_cidreq()."&forum=".intval($_GET['forum'])."&search=".$search,
  127. "name" => prepare4display($currentForum['forum_title']),
  128. ];
  129. if ($message != 'PostDeletedSpecial') {
  130. $interbreadcrumb[] = [
  131. "url" => "viewthread.php?".api_get_cidreq()."&forum=".$info_thread['forum_id']."&thread=".intval($_GET['thread']),
  132. "name" => prepare4display($currentThread['thread_title']),
  133. ];
  134. }
  135. // the last element of the breadcrumb navigation is already set in interbreadcrumb, so give empty string
  136. $interbreadcrumb[] = [
  137. "url" => "#",
  138. "name" => get_lang('Grade thread'),
  139. ];
  140. Display::display_header('');
  141. }
  142. }
  143. /*
  144. Actions
  145. */
  146. $action = isset($_GET['action']) ? $_GET['action'] : '';
  147. if ($action == 'delete' &&
  148. isset($_GET['content']) &&
  149. isset($_GET['id']) && api_is_allowed_to_edit(false, true)
  150. ) {
  151. $message = delete_post($_GET['id']);
  152. }
  153. if (($action == 'invisible' || $action == 'visible') &&
  154. isset($_GET['id']) && api_is_allowed_to_edit(false, true)
  155. ) {
  156. $message = approve_post($_GET['id'], $action);
  157. }
  158. if ($action == 'move' && isset($_GET['post'])) {
  159. $message = move_post_form();
  160. }
  161. /*
  162. Display the action messages
  163. */
  164. if (!empty($message)) {
  165. echo Display::return_message(get_lang($message), 'confirm');
  166. }
  167. // show qualifications history
  168. $type = isset($_GET['type']) ? $_GET['type'] : '';
  169. $historyList = getThreadScoreHistory(
  170. $userIdToQualify,
  171. $threadId,
  172. $type
  173. );
  174. $counter = count($historyList);
  175. // Show current qualify in my form
  176. $qualify = current_qualify_of_thread(
  177. $threadId,
  178. api_get_session_id(),
  179. $_GET['user']
  180. );
  181. $result = get_statistical_information(
  182. $threadId,
  183. $_GET['user_id'],
  184. api_get_course_int_id()
  185. );
  186. $url = api_get_path(WEB_CODE_PATH).'forum/forumqualify.php?'.
  187. api_get_cidreq().'&forum='.intval($_GET['forum']).'&thread='.$threadId.'&user='.intval($_GET['user']).'&user_id='.intval($_GET['user']);
  188. $userToQualifyInfo = api_get_user_info($userIdToQualify);
  189. $form = new FormValidator('forum-thread-qualify', 'post', $url);
  190. $form->addHeader($userToQualifyInfo['complete_name']);
  191. $form->addLabel(get_lang('Thread'), $currentThread['thread_title']);
  192. $form->addLabel(get_lang('Users in course'), $result['user_course']);
  193. $form->addLabel(get_lang('Number of posts'), $result['post']);
  194. $form->addLabel(get_lang('Number of posts for this user'), $result['user_post']);
  195. $form->addLabel(
  196. get_lang('Posts by user'),
  197. round($result['user_post'] / $result['post'], 2)
  198. );
  199. $form->addText(
  200. 'idtextqualify',
  201. [get_lang('Score'), get_lang('Max score').' '.$maxQualify],
  202. $qualify
  203. );
  204. $course = api_get_course_info();
  205. $rows = get_thread_user_post($course['code'], $currentThread['thread_id'], $_GET['user']);
  206. if (isset($rows)) {
  207. $counter = 1;
  208. foreach ($rows as $row) {
  209. if ($row['status'] == '0') {
  210. $style = " id = 'post".$post_en."' class=\"hide-me\" style=\"border:1px solid red; display:none; background-color:#F7F7F7; width:95%; margin: 0px 0px 4px 40px; \" ";
  211. } else {
  212. $style = '';
  213. $post_en = $row['post_parent_id'];
  214. }
  215. if ($row['user_id'] == '0') {
  216. $name = prepare4display($row['poster_name']);
  217. } else {
  218. $name = api_get_person_name($row['firstname'], $row['lastname']);
  219. }
  220. if ($counter == 1) {
  221. echo Display::page_subheader($name);
  222. }
  223. echo "<div ".$style."><table class=\"data_table\">";
  224. if ($row['visible'] == '0') {
  225. $titleclass = 'forum_message_post_title_2_be_approved';
  226. $messageclass = 'forum_message_post_text_2_be_approved';
  227. $leftclass = 'forum_message_left_2_be_approved';
  228. } else {
  229. $titleclass = 'forum_message_post_title';
  230. $messageclass = 'forum_message_post_text';
  231. $leftclass = 'forum_message_left';
  232. }
  233. echo "<tr>";
  234. echo "<td rowspan=\"3\" class=\"$leftclass\">";
  235. echo '<br /><b>'.api_convert_and_format_date($row['post_date'], DATE_TIME_FORMAT_LONG).'</b><br />';
  236. echo "</td>";
  237. // The post title
  238. echo "<td class=\"$titleclass\">".prepare4display($row['post_title'])."</td>";
  239. echo "</tr>";
  240. // The post message
  241. echo "<tr >";
  242. echo "<td class=\"$messageclass\">".prepare4display($row['post_text'])."</td>";
  243. echo "</tr>";
  244. // The check if there is an attachment
  245. $attachment_list = get_attachment($row['post_id']);
  246. if (!empty($attachment_list)) {
  247. echo '<tr ><td height="50%">';
  248. $realname = $attachment_list['path'];
  249. $user_filename = $attachment_list['filename'];
  250. echo Display::return_icon('attachment.gif', get_lang('Attachment'));
  251. echo '<a href="download.php?file=';
  252. echo $realname;
  253. echo ' "> '.$user_filename.' </a>';
  254. echo '<span class="forum_attach_comment" >'.$attachment_list['comment'].'</span><br />';
  255. echo '</td></tr>';
  256. }
  257. echo "</table></div>";
  258. $counter++;
  259. }
  260. }
  261. $form->addButtonSave(get_lang('Grade this thread'));
  262. $form->setDefaults(['idtextqualify' => $qualify]);
  263. $form->display();
  264. // Show past data
  265. if (api_is_allowed_to_edit() && $counter > 0) {
  266. echo '<h4>'.get_lang('ScoreChangesHistory').'</h4>';
  267. if (isset($_GET['type']) && $_GET['type'] === 'false') {
  268. $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.'#history">'.
  269. get_lang('more recent').'</a> <a class="btn btn-default disabled" >'.get_lang('older').'</a>';
  270. } else {
  271. $buttons = '<a class="btn btn-default">'.get_lang('more recent').'</a>
  272. <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.'#history">'.
  273. get_lang('older').'</a>';
  274. }
  275. $table_list = '<br /><div class="btn-group">'.$buttons.'</div>';
  276. $table_list .= '<br /><table class="table">';
  277. $table_list .= '<tr>';
  278. $table_list .= '<th width="50%">'.get_lang('Who changed').'</th>';
  279. $table_list .= '<th width="10%">'.get_lang('Note changed').'</th>';
  280. $table_list .= '<th width="40%">'.get_lang('Date changed').'</th>';
  281. $table_list .= '</tr>';
  282. for ($i = 0; $i < count($historyList); $i++) {
  283. $userInfo = api_get_user_info($historyList[$i]['qualify_user_id']);
  284. $table_list .= '<tr><td>'.$userInfo['complete_name'].'</td>';
  285. $table_list .= '<td>'.$historyList[$i]['qualify'].'</td>';
  286. $table_list .= '<td>'.api_convert_and_format_date(
  287. $historyList[$i]['qualify_time'],
  288. DATE_TIME_FORMAT_LONG
  289. );
  290. $table_list .= '</td></tr>';
  291. }
  292. $table_list .= '</table>';
  293. echo $table_list;
  294. }
  295. if ($origin != 'learnpath') {
  296. Display:: display_footer();
  297. }