forumqualify.php 12 KB

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