forumqualify.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  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. /*
  78. Header and Breadcrumbs
  79. */
  80. if (isset($_SESSION['gradebook'])) {
  81. $gradebook = $_SESSION['gradebook'];
  82. }
  83. if (!empty($gradebook) && $gradebook == 'view') {
  84. $interbreadcrumb[] = array(
  85. 'url' => '../gradebook/'.$_SESSION['gradebook_dest'],
  86. 'name' => get_lang('ToolGradebook')
  87. );
  88. }
  89. if ($origin == 'learnpath') {
  90. Display::display_reduced_header();
  91. } else {
  92. if (!empty($groupId)) {
  93. $group_properties = GroupManager::get_group_properties($groupId);
  94. $interbreadcrumb[] = array(
  95. "url" => "../group/group.php?".api_get_cidreq(),
  96. "name" => get_lang('Groups')
  97. );
  98. $interbreadcrumb[] = array(
  99. "url" => "../group/group_space.php?".api_get_cidreq(),
  100. "name" => get_lang('GroupSpace').' ('.$group_properties['name'].')'
  101. );
  102. $interbreadcrumb[] = array(
  103. "url" => "viewforum.php?".api_get_cidreq()."&forum=".intval($_GET['forum'])."&search=".Security::remove_XSS(urlencode($_GET['search'])),
  104. "name" => prepare4display($currentForum['forum_title'])
  105. );
  106. if ($message <> 'PostDeletedSpecial') {
  107. $interbreadcrumb[] = array(
  108. "url" => "viewthread.php?".api_get_cidreq()."&forum=".intval($_GET['forum'])."&gradebook=".$gradebook."&thread=".intval($_GET['thread']),
  109. "name" => prepare4display($currentThread['thread_title'])
  110. );
  111. }
  112. $interbreadcrumb[] = array(
  113. "url" => "#",
  114. "name" => get_lang('QualifyThread')
  115. );
  116. // the last element of the breadcrumb navigation is already set in interbreadcrumb, so give empty string
  117. Display::display_header('');
  118. api_display_tool_title($nameTools);
  119. } else {
  120. $search = isset($_GET['search']) ? Security::remove_XSS(urlencode($_GET['search'])) : '';
  121. $info_thread = get_thread_information($currentForum['forum_id'], $_GET['thread']);
  122. $interbreadcrumb[] = array(
  123. "url" => "index.php?".api_get_cidreq()."&search=".$search,
  124. "name" => $nameTools
  125. );
  126. $interbreadcrumb[] = array(
  127. "url" => "viewforumcategory.php?".api_get_cidreq()."&forumcategory=".$currentForumCategory['cat_id']."&search=".$search,
  128. "name" => prepare4display($currentForumCategory['cat_title'])
  129. );
  130. $interbreadcrumb[] = array(
  131. "url" => "viewforum.php?".api_get_cidreq()."&forum=".intval($_GET['forum'])."&search=".$search,
  132. "name" => prepare4display($currentForum['forum_title'])
  133. );
  134. if ($message <> 'PostDeletedSpecial') {
  135. if (isset($_GET['gradebook']) && $_GET['gradebook'] == 'view') {
  136. $info_thread = get_thread_information($currentForum['forum_id'], $_GET['thread']);
  137. $interbreadcrumb[] = array(
  138. "url" => "viewthread.php?".api_get_cidreq()."&forum=".$info_thread['forum_id']."&thread=".intval($_GET['thread']),
  139. "name" => prepare4display($currentThread['thread_title'])
  140. );
  141. } else {
  142. $interbreadcrumb[] = array(
  143. "url" => "viewthread.php?".api_get_cidreq()."&forum=".intval($_GET['forum'])."&thread=".intval($_GET['thread']),
  144. "name" => prepare4display($currentThread['thread_title'])
  145. );
  146. }
  147. }
  148. // the last element of the breadcrumb navigation is already set in interbreadcrumb, so give empty string
  149. $interbreadcrumb[] = array("url" => "#", "name" => get_lang('QualifyThread'));
  150. Display::display_header('');
  151. }
  152. }
  153. /*
  154. Actions
  155. */
  156. $action = isset($_GET['action']) ? $_GET['action'] : '';
  157. if ($action == 'delete' &&
  158. isset($_GET['content']) &&
  159. isset($_GET['id']) && api_is_allowed_to_edit(false, true)
  160. ) {
  161. $message = delete_post($_GET['id']);
  162. }
  163. if (($action == 'invisible' || $action == 'visible') &&
  164. isset($_GET['id']) && api_is_allowed_to_edit(false, true)
  165. ) {
  166. $message = approve_post($_GET['id'], $action);
  167. }
  168. if ($action == 'move' && isset($_GET['post'])) {
  169. $message = move_post_form();
  170. }
  171. /*
  172. Display the action messages
  173. */
  174. if (!empty($message)) {
  175. echo Display::return_message(get_lang($message), 'confirm');
  176. }
  177. // show qualifications history
  178. $type = isset($_GET['type']) ? $_GET['type'] : '';
  179. $historyList = getThreadScoreHistory(
  180. $userIdToQualify,
  181. $threadId,
  182. $type
  183. );
  184. $counter = count($historyList);
  185. // Show current qualify in my form
  186. $qualify = current_qualify_of_thread(
  187. $threadId,
  188. api_get_session_id(),
  189. $_GET['user']
  190. );
  191. $result = get_statistical_information(
  192. $threadId,
  193. $_GET['user_id'],
  194. api_get_course_int_id()
  195. );
  196. $url = api_get_path(WEB_CODE_PATH).'forum/forumqualify.php?'.
  197. api_get_cidreq().'&forum='.intval($_GET['forum']).'&thread='.$threadId.'&user='.intval($_GET['user']).'&user_id='.intval($_GET['user']);
  198. $userToQualifyInfo = api_get_user_info($userIdToQualify);
  199. $form = new FormValidator('forum-thread-qualify', 'post', $url);
  200. $form->addHeader($userToQualifyInfo['complete_name']);
  201. $form->addLabel(get_lang('Thread'), $currentThread['thread_title']);
  202. $form->addLabel(get_lang('CourseUsers'), $result['user_course']);
  203. $form->addLabel(get_lang('PostsNumber'), $result['post']);
  204. $form->addLabel(get_lang('NumberOfPostsForThisUser'), $result['user_post']);
  205. $form->addLabel(
  206. get_lang('AveragePostPerUser'),
  207. round($result['user_post'] / $result['post'], 2)
  208. );
  209. $form->addText(
  210. 'idtextqualify',
  211. array(get_lang('Qualification'), get_lang('MaxScore').' '.$maxQualify),
  212. $qualify
  213. );
  214. $course = api_get_course_info();
  215. $rows = get_thread_user_post($course['code'], $currentThread['thread_id'], $_GET['user']);
  216. if (isset($rows)) {
  217. $counter = 1;
  218. foreach ($rows as $row) {
  219. if ($row['status'] == '0') {
  220. $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; \" ";
  221. } else {
  222. $style = '';
  223. $post_en = $row['post_parent_id'];
  224. }
  225. if ($row['user_id'] == '0') {
  226. $name = prepare4display($row['poster_name']);
  227. } else {
  228. $name = api_get_person_name($row['firstname'], $row['lastname']);
  229. }
  230. if ($counter == 1) {
  231. echo Display::page_subheader($name);
  232. }
  233. echo "<div ".$style."><table class=\"data_table\">";
  234. if ($row['visible'] == '0') {
  235. $titleclass = 'forum_message_post_title_2_be_approved';
  236. $messageclass = 'forum_message_post_text_2_be_approved';
  237. $leftclass = 'forum_message_left_2_be_approved';
  238. } else {
  239. $titleclass = 'forum_message_post_title';
  240. $messageclass = 'forum_message_post_text';
  241. $leftclass = 'forum_message_left';
  242. }
  243. echo "<tr>";
  244. echo "<td rowspan=\"3\" class=\"$leftclass\">";
  245. echo '<br /><b>'.api_convert_and_format_date($row['post_date'], DATE_TIME_FORMAT_LONG).'</b><br />';
  246. echo "</td>";
  247. // The post title
  248. echo "<td class=\"$titleclass\">".prepare4display($row['post_title'])."</td>";
  249. echo "</tr>";
  250. // The post message
  251. echo "<tr >";
  252. echo "<td class=\"$messageclass\">".prepare4display($row['post_text'])."</td>";
  253. echo "</tr>";
  254. // The check if there is an attachment
  255. $attachment_list = get_attachment($row['post_id']);
  256. if (!empty($attachment_list)) {
  257. echo '<tr ><td height="50%">';
  258. $realname = $attachment_list['path'];
  259. $user_filename = $attachment_list['filename'];
  260. echo Display::return_icon('attachment.gif', get_lang('Attachment'));
  261. echo '<a href="download.php?file=';
  262. echo $realname;
  263. echo ' "> '.$user_filename.' </a>';
  264. echo '<span class="forum_attach_comment" >'.$attachment_list['comment'].'</span><br />';
  265. echo '</td></tr>';
  266. }
  267. echo "</table></div>";
  268. $counter++;
  269. }
  270. }
  271. $form->addButtonSave(get_lang('QualifyThisThread'));
  272. $form->setDefaults(array('idtextqualify' => $qualify));
  273. $form->display();
  274. // Show past data
  275. if (api_is_allowed_to_edit() && $counter > 0) {
  276. if (isset($_GET['gradebook'])) {
  277. $view_gradebook = '&gradebook=view';
  278. }
  279. echo '<h4>'.get_lang('QualificationChangesHistory').'</h4>';
  280. if (isset($_GET['type']) && $_GET['type'] === 'false') {
  281. $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">'.
  282. get_lang('MoreRecent').'</a> <a class="btn btn-default disabled" >'.get_lang('Older').'</a>';
  283. } else {
  284. $buttons = '<a class="btn btn-default">'.get_lang('MoreRecent').'</a>
  285. <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">'.
  286. get_lang('Older').'</a>';
  287. }
  288. $table_list = '<br /><div class="btn-group">'.$buttons.'</div>';
  289. $table_list .= '<br /><table class="table">';
  290. $table_list .= '<tr>';
  291. $table_list .= '<th width="50%">'.get_lang('WhoChanged').'</th>';
  292. $table_list .= '<th width="10%">'.get_lang('NoteChanged').'</th>';
  293. $table_list .= '<th width="40%">'.get_lang('DateChanged').'</th>';
  294. $table_list .= '</tr>';
  295. for ($i = 0; $i < count($historyList); $i++) {
  296. $userInfo = api_get_user_info($historyList[$i]['qualify_user_id']);
  297. $table_list .= '<tr><td>'.$userInfo['complete_name'].'</td>';
  298. $table_list .= '<td>'.$historyList[$i]['qualify'].'</td>';
  299. $table_list .= '<td>'.api_convert_and_format_date(
  300. $historyList[$i]['qualify_time'],
  301. DATE_TIME_FORMAT_LONG
  302. );
  303. $table_list .= '</td></tr>';
  304. }
  305. $table_list .= '</table>';
  306. echo $table_list;
  307. }
  308. if ($origin != 'learnpath') {
  309. Display:: display_footer();
  310. }