forumqualify.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  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. $forumId = isset($_GET['forum']) ? intval($_GET['forum']) : 0;
  21. api_block_course_item_locked_by_gradebook($_GET['thread'], LINK_FORUM_THREAD);
  22. $nameTools = get_lang('ToolForum');
  23. $allowed_to_edit = api_is_allowed_to_edit(null, true);
  24. $currentThread = get_thread_information($forumId, $_GET['thread']);
  25. $currentForum = get_forum_information($currentThread['forum_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. /* Including necessary files */
  36. $htmlHeadXtra[] = '<script>
  37. $(document).ready(function(){
  38. $(\'.hide-me\').slideUp()
  39. });
  40. function hidecontent(content){
  41. $(content).slideToggle(\'normal\');
  42. }
  43. </script>';
  44. $currentForumCategory = get_forumcategory_information(
  45. $currentForum['forum_category']
  46. );
  47. $groupId = api_get_group_id();
  48. /*
  49. Header and Breadcrumbs
  50. */
  51. if (api_is_in_gradebook()) {
  52. $interbreadcrumb[]= array(
  53. 'url' => api_get_path(WEB_CODE_PATH).'gradebook/index.php?'.api_get_cidreq(),
  54. 'name' => get_lang('ToolGradebook')
  55. );
  56. }
  57. if ($origin == 'learnpath') {
  58. Display::display_reduced_header();
  59. } else {
  60. if (!empty($groupId)) {
  61. $group_properties = GroupManager::get_group_properties($groupId);
  62. $interbreadcrumb[] = array(
  63. "url" => "../group/group.php?".api_get_cidreq(),
  64. "name" => get_lang('Groups'),
  65. );
  66. $interbreadcrumb[] = array(
  67. "url" => "../group/group_space.php?".api_get_cidreq(),
  68. "name"=> get_lang('GroupSpace').' ('.$group_properties['name'].')'
  69. );
  70. $interbreadcrumb[] = array(
  71. "url" => "viewforum.php?".api_get_cidreq()."&forum=".intval($_GET['forum'])."&search=".Security::remove_XSS(urlencode($_GET['search'])),
  72. "name" => prepare4display($currentForum['forum_title'])
  73. );
  74. if ($message <> 'PostDeletedSpecial') {
  75. $interbreadcrumb[]= array(
  76. "url" => "viewthread.php?".api_get_cidreq()."&forum=".intval($_GET['forum'])."&gradebook=".$gradebook."&thread=".intval($_GET['thread']),
  77. "name" => prepare4display($currentThread['thread_title'])
  78. );
  79. }
  80. $interbreadcrumb[] = array(
  81. "url" => "#",
  82. "name" => get_lang('QualifyThread')
  83. );
  84. // the last element of the breadcrumb navigation is already set in interbreadcrumb, so give empty string
  85. Display :: display_header('');
  86. api_display_tool_title($nameTools);
  87. } else {
  88. $search = isset($_GET['search']) ? Security::remove_XSS(urlencode($_GET['search'])) : '';
  89. $info_thread = get_thread_information($currentForum['forum_id'], $_GET['thread']);
  90. $interbreadcrumb[] = array(
  91. "url" => "index.php?".api_get_cidreq()."&search=".$search,
  92. "name" => $nameTools);
  93. $interbreadcrumb[] = array(
  94. "url" => "viewforumcategory.php?".api_get_cidreq()."&forumcategory=".$currentForumCategory['cat_id']."&search=".$search,
  95. "name" => prepare4display($currentForumCategory['cat_title'])
  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. if (isset($_GET['gradebook']) && $_GET['gradebook'] == 'view') {
  103. $info_thread = get_thread_information($currentForum['forum_id'], $_GET['thread']);
  104. $interbreadcrumb[] = array(
  105. "url" => "viewthread.php?".api_get_cidreq()."&forum=".$info_thread['forum_id']."&thread=".intval($_GET['thread']),
  106. "name" => prepare4display($currentThread['thread_title'])
  107. );
  108. } else {
  109. $interbreadcrumb[] = array(
  110. "url" => "viewthread.php?".api_get_cidreq()."&forum=".intval($_GET['forum'])."&thread=".intval($_GET['thread']),
  111. "name" => prepare4display($currentThread['thread_title'])
  112. );
  113. }
  114. }
  115. // the last element of the breadcrumb navigation is already set in interbreadcrumb, so give empty string
  116. $interbreadcrumb[]=array("url" => "#","name" => get_lang('QualifyThread'));
  117. Display :: display_header('');
  118. }
  119. }
  120. /*
  121. Actions
  122. */
  123. $action = isset($_GET['action']) ? $_GET['action'] : '';
  124. if ($action =='delete' &&
  125. isset($_GET['content']) &&
  126. isset($_GET['id']) && api_is_allowed_to_edit(false, true)
  127. ) {
  128. $message = delete_post($_GET['id']);
  129. }
  130. if (($action == 'invisible' || $action == 'visible') &&
  131. isset($_GET['id']) && api_is_allowed_to_edit(false, true)
  132. ) {
  133. $message = approve_post($_GET['id'], $action);
  134. }
  135. if ($action == 'move' && isset($_GET['post'])) {
  136. $message = move_post_form();
  137. }
  138. /*
  139. Display the action messages
  140. */
  141. if (!empty($message)) {
  142. Display :: display_confirmation_message(get_lang($message));
  143. }
  144. if ($allowToQualify) {
  145. $currentThread = get_thread_information($currentForum['forum_id'], $_GET['thread']);
  146. $threadId = $currentThread['thread_id'];
  147. // Show max qualify in my form
  148. $maxQualify = showQualify('2', $userIdToQualify, $threadId);
  149. $score = isset($_POST['idtextqualify']) ? Security::remove_XSS($_POST['idtextqualify']) : '';
  150. if ($score > $maxQualify) {
  151. Display:: display_error_message(
  152. get_lang('QualificationCanNotBeGreaterThanMaxScore'),
  153. false
  154. );
  155. }
  156. if (!empty($score)) {
  157. $saveResult = saveThreadScore(
  158. $currentThread,
  159. $userIdToQualify,
  160. $threadId,
  161. $score,
  162. api_get_utc_datetime(),
  163. api_get_session_id()
  164. );
  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. if (isset($_GET['gradebook'])) {
  266. $view_gradebook='&gradebook=view';
  267. }
  268. echo '<h4>'.get_lang('QualificationChangesHistory').'</h4>';
  269. if (isset($_GET['type']) && $_GET['type'] === 'false') {
  270. $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">'.
  271. get_lang('MoreRecent').'</a> <a class="btn btn-default disabled" >'.get_lang('Older').'</a>';
  272. } else {
  273. $buttons = '<a class="btn btn-default">'.get_lang('MoreRecent').'</a>
  274. <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">'.
  275. get_lang('Older').'</a>';
  276. }
  277. $table_list = '<br /><div class="btn-group">'.$buttons.'</div>';
  278. $table_list .= '<br /><table class="table">';
  279. $table_list .= '<tr>';
  280. $table_list .= '<th width="50%">'.get_lang('WhoChanged').'</th>';
  281. $table_list .= '<th width="10%">'.get_lang('NoteChanged').'</th>';
  282. $table_list .= '<th width="40%">'.get_lang('DateChanged').'</th>';
  283. $table_list .= '</tr>';
  284. for ($i = 0; $i < count($historyList); $i++) {
  285. $userInfo = api_get_user_info($historyList[$i]['qualify_user_id']);
  286. $table_list .= '<tr><td>'.$userInfo['complete_name'].'</td>';
  287. $table_list .= '<td>'.$historyList[$i]['qualify'].'</td>';
  288. $table_list .= '<td>'.api_convert_and_format_date(
  289. $historyList[$i]['qualify_time'],
  290. DATE_TIME_FORMAT_LONG
  291. );
  292. $table_list .= '</td></tr>';
  293. }
  294. $table_list.= '</table>';
  295. echo $table_list;
  296. }
  297. }
  298. if ($origin!='learnpath') {
  299. Display :: display_footer();
  300. }