course.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Courses reporting.
  5. *
  6. * @package chamilo.reporting
  7. */
  8. ob_start();
  9. $cidReset = true;
  10. require_once __DIR__.'/../inc/global.inc.php';
  11. $this_section = SECTION_TRACKING;
  12. $sessionId = isset($_GET['session_id']) ? intval($_GET['session_id']) : null;
  13. api_block_anonymous_users();
  14. $allowToTrack = api_is_platform_admin(true, true) || api_is_teacher();
  15. if (!$allowToTrack) {
  16. api_not_allowed(true);
  17. }
  18. $interbreadcrumb[] = ["url" => "index.php", "name" => get_lang('MySpace')];
  19. if (isset($_GET["id_session"]) && $_GET["id_session"] != "") {
  20. $interbreadcrumb[] = ["url" => "session.php", "name" => get_lang('Sessions')];
  21. }
  22. if (isset($_GET["user_id"]) && $_GET["user_id"] != "" && isset($_GET["type"]) && $_GET["type"] == "coach") {
  23. $interbreadcrumb[] = ["url" => "coaches.php", "name" => get_lang('Tutors')];
  24. }
  25. if (isset($_GET["user_id"]) && $_GET["user_id"] != "" && isset($_GET["type"]) && $_GET["type"] == "student") {
  26. $interbreadcrumb[] = ["url" => "student.php", "name" => get_lang('Students')];
  27. }
  28. if (isset($_GET["user_id"]) && $_GET["user_id"] != "" && !isset($_GET["type"])) {
  29. $interbreadcrumb[] = ["url" => "teachers.php", "name" => get_lang('Teachers')];
  30. }
  31. function count_courses()
  32. {
  33. global $nb_courses;
  34. return $nb_courses;
  35. }
  36. // Checking if the current coach is the admin coach
  37. $showImportIcon = false;
  38. if (api_get_setting('add_users_by_coach') == 'true') {
  39. if (!api_is_platform_admin()) {
  40. $isGeneralCoach = SessionManager::user_is_general_coach(
  41. api_get_user_id(),
  42. $sessionId
  43. );
  44. if ($isGeneralCoach) {
  45. $showImportIcon = true;
  46. }
  47. }
  48. }
  49. Display :: display_header(get_lang('Courses'));
  50. $user_id = 0;
  51. $a_courses = [];
  52. $menu_items = [];
  53. if (api_is_platform_admin(true, true)) {
  54. $title = '';
  55. if (empty($sessionId)) {
  56. if (isset($_GET['user_id'])) {
  57. $user_id = intval($_GET['user_id']);
  58. $user_info = api_get_user_info($user_id);
  59. $title = get_lang('AssignedCoursesTo').' '.api_get_person_name($user_info['firstname'], $user_info['lastname']);
  60. $courses = CourseManager::get_course_list_of_user_as_course_admin($user_id);
  61. } else {
  62. $title = get_lang('YourCourseList');
  63. $courses = CourseManager::get_courses_followed_by_drh(api_get_user_id());
  64. }
  65. } else {
  66. $session_name = api_get_session_name($sessionId);
  67. $title = $session_name.' : '.get_lang('CourseListInSession');
  68. $courses = Tracking::get_courses_list_from_session($sessionId);
  69. }
  70. $a_courses = array_keys($courses);
  71. if (!api_is_session_admin()) {
  72. $menu_items[] = Display::url(
  73. Display::return_icon('statistics.png', get_lang('MyStats'), '', ICON_SIZE_MEDIUM),
  74. api_get_path(WEB_CODE_PATH)."auth/my_progress.php"
  75. );
  76. $menu_items[] = Display::url(
  77. Display::return_icon('user.png', get_lang('Students'), [], ICON_SIZE_MEDIUM),
  78. "index.php?view=drh_students&amp;display=yourstudents"
  79. );
  80. $menu_items[] = Display::url(
  81. Display::return_icon('teacher.png', get_lang('Trainers'), [], ICON_SIZE_MEDIUM),
  82. 'teachers.php'
  83. );
  84. $menu_items[] = Display::url(
  85. Display::return_icon('course_na.png', get_lang('Courses'), [], ICON_SIZE_MEDIUM),
  86. '#'
  87. );
  88. $menu_items[] = Display::url(
  89. Display::return_icon('session.png', get_lang('Sessions'), [], ICON_SIZE_MEDIUM),
  90. 'session.php'
  91. );
  92. if (api_can_login_as($user_id)) {
  93. $link = '<a href="'.api_get_path(WEB_CODE_PATH).'admin/user_list.php?action=login_as&amp;user_id='.$user_id.'&amp;sec_token='.Security::get_existing_token().'">'.
  94. Display::return_icon('login_as.png', get_lang('LoginAs'), null, ICON_SIZE_MEDIUM).'</a>&nbsp;&nbsp;';
  95. $menu_items[] = $link;
  96. }
  97. }
  98. $actionsLeft = $actionsRight = '';
  99. $nb_menu_items = count($menu_items);
  100. if ($nb_menu_items > 1) {
  101. foreach ($menu_items as $key => $item) {
  102. $actionsLeft .= $item;
  103. }
  104. }
  105. if (count($a_courses) > 0) {
  106. $actionsRight .= Display::url(
  107. Display::return_icon('printer.png', get_lang('Print'), [], 32),
  108. 'javascript: void(0);',
  109. ['onclick' => 'javascript: window.print();']
  110. );
  111. }
  112. $toolbar = Display::toolbarAction('toolbar-course', [$actionsLeft, $actionsRight]);
  113. echo $toolbar;
  114. echo Display::page_header($title);
  115. }
  116. if ($showImportIcon) {
  117. echo "<div align=\"right\">";
  118. echo '<a href="user_import.php?id_session='.$sessionId.'&action=export&amp;type=xml">'.
  119. Display::return_icon('excel.gif', get_lang('ImportUserListXMLCSV')).'&nbsp;'.get_lang('ImportUserListXMLCSV').'</a>';
  120. echo "</div><br />";
  121. }
  122. /**
  123. * @return int
  124. */
  125. function get_count_courses()
  126. {
  127. $userId = api_get_user_id();
  128. $sessionId = isset($_GET['session_id']) ? intval($_GET['session_id']) : null;
  129. $keyword = isset($_GET['keyword']) ? $_GET['keyword'] : null;
  130. $drhLoaded = false;
  131. if (api_is_drh()) {
  132. if (api_drh_can_access_all_session_content()) {
  133. if (empty($sessionId)) {
  134. $count = SessionManager::getAllCoursesFollowedByUser(
  135. $userId,
  136. null,
  137. null,
  138. null,
  139. null,
  140. null,
  141. true,
  142. $keyword
  143. );
  144. } else {
  145. $count = SessionManager::getCourseCountBySessionId(
  146. $sessionId,
  147. $keyword
  148. );
  149. }
  150. $drhLoaded = true;
  151. }
  152. }
  153. if ($drhLoaded == false) {
  154. $isGeneralCoach = SessionManager::user_is_general_coach(
  155. api_get_user_id(),
  156. $sessionId
  157. );
  158. if ($isGeneralCoach) {
  159. $courseList = SessionManager::getCoursesInSession($sessionId);
  160. $count = count($courseList);
  161. } else {
  162. $count = CourseManager::getCoursesFollowedByUser(
  163. $userId,
  164. COURSEMANAGER,
  165. null,
  166. null,
  167. null,
  168. null,
  169. true,
  170. $keyword,
  171. $sessionId
  172. );
  173. }
  174. }
  175. return $count;
  176. }
  177. /**
  178. * @param $from
  179. * @param $limit
  180. * @param $column
  181. * @param $direction
  182. *
  183. * @return array
  184. */
  185. function get_courses($from, $limit, $column, $direction)
  186. {
  187. $userId = api_get_user_id();
  188. $sessionId = isset($_GET['session_id']) ? intval($_GET['session_id']) : 0;
  189. $keyword = isset($_GET['keyword']) ? $_GET['keyword'] : null;
  190. $follow = isset($_GET['follow']) ? true : false;
  191. $drhLoaded = false;
  192. if (api_is_drh()) {
  193. if (api_drh_can_access_all_session_content()) {
  194. $courses = SessionManager::getAllCoursesFollowedByUser(
  195. $userId,
  196. $sessionId,
  197. $from,
  198. $limit,
  199. $column,
  200. $direction,
  201. false,
  202. $keyword
  203. );
  204. $drhLoaded = true;
  205. }
  206. }
  207. if ($drhLoaded == false) {
  208. $isGeneralCoach = SessionManager::user_is_general_coach(
  209. api_get_user_id(),
  210. $sessionId
  211. );
  212. // General coach can see all reports
  213. if ($isGeneralCoach) {
  214. $courseList = SessionManager::getCoursesInSession($sessionId);
  215. $courses = [];
  216. if (!empty($courseList)) {
  217. foreach ($courseList as $courseId) {
  218. $courses[] = api_get_course_info_by_id($courseId);
  219. }
  220. }
  221. } else {
  222. $courses = CourseManager::getCoursesFollowedByUser(
  223. $userId,
  224. COURSEMANAGER,
  225. $from,
  226. $limit,
  227. $column,
  228. $direction,
  229. false,
  230. $keyword,
  231. $sessionId,
  232. $follow
  233. );
  234. }
  235. }
  236. $courseList = [];
  237. if (!empty($courses)) {
  238. foreach ($courses as $data) {
  239. $courseCode = $data['code'];
  240. $courseInfo = api_get_course_info($courseCode);
  241. if (empty($sessionId)) {
  242. $userList = CourseManager::get_user_list_from_course_code($data['code']);
  243. } else {
  244. $userList = CourseManager::get_user_list_from_course_code(
  245. $data['code'],
  246. $sessionId,
  247. null,
  248. null,
  249. 0
  250. );
  251. }
  252. $userIdList = [];
  253. if (!empty($userList)) {
  254. foreach ($userList as $user) {
  255. $userIdList[] = $user['user_id'];
  256. }
  257. }
  258. $messagesInCourse = 0;
  259. $assignmentsInCourse = 0;
  260. $avgTimeSpentInCourse = 0;
  261. $avgProgressInCourse = 0;
  262. $countStudents = 0;
  263. $avgScoreInCourse = 0;
  264. if (count($userIdList) > 0) {
  265. $countStudents = count($userIdList);
  266. // tracking data
  267. $avgProgressInCourse = Tracking :: get_avg_student_progress($userIdList, $courseCode, [], $sessionId);
  268. $avgScoreInCourse = Tracking :: get_avg_student_score($userIdList, $courseCode, [], $sessionId);
  269. $avgTimeSpentInCourse = Tracking :: get_time_spent_on_the_course($userIdList, $courseInfo['real_id'], $sessionId);
  270. $messagesInCourse = Tracking :: count_student_messages($userIdList, $courseCode, $sessionId);
  271. $assignmentsInCourse = Tracking :: count_student_assignments($userIdList, $courseCode, $sessionId);
  272. $avgTimeSpentInCourse = api_time_to_hms($avgTimeSpentInCourse / $countStudents);
  273. $avgProgressInCourse = round($avgProgressInCourse / $countStudents, 2);
  274. if (is_numeric($avgScoreInCourse)) {
  275. $avgScoreInCourse = round($avgScoreInCourse / $countStudents, 2).'%';
  276. }
  277. }
  278. $thematic = new Thematic();
  279. $tematic_advance = $thematic->get_total_average_of_thematic_advances($courseCode, $sessionId);
  280. $tematicAdvanceProgress = '-';
  281. if (!empty($tematic_advance)) {
  282. $tematicAdvanceProgress = '<a title="'.get_lang('GoToThematicAdvance').'" href="'.api_get_path(WEB_CODE_PATH).'course_progress/index.php?cidReq='.$courseCode.'&id_session='.$sessionId.'">'.
  283. $tematic_advance.'%</a>';
  284. }
  285. $courseIcon = '<a href="'.api_get_path(WEB_CODE_PATH).'tracking/courseLog.php?cidReq='.$courseCode.'&id_session='.$sessionId.'">
  286. '.Display::return_icon('2rightarrow.png', get_lang('Details')).'
  287. </a>';
  288. $title = Display::url(
  289. $data['title'],
  290. $courseInfo['course_public_url'].'?id_session='.$sessionId
  291. );
  292. $attendanceLink = Display::url(
  293. Display::return_icon('attendance_list.png', get_lang('Attendance'), [], ICON_SIZE_MEDIUM),
  294. api_get_path(WEB_CODE_PATH).'attendance/index.php?cidReq='.$courseCode.'&id_session='.$sessionId.'&action=calendar_logins'
  295. );
  296. $courseList[] = [
  297. $title,
  298. $countStudents,
  299. is_null($avgTimeSpentInCourse) ? '-' : $avgTimeSpentInCourse,
  300. $tematicAdvanceProgress,
  301. is_null($avgProgressInCourse) ? '-' : $avgProgressInCourse.'%',
  302. is_null($avgScoreInCourse) ? '-' : $avgScoreInCourse,
  303. is_null($messagesInCourse) ? '-' : $messagesInCourse,
  304. is_null($assignmentsInCourse) ? '-' : $assignmentsInCourse,
  305. $attendanceLink,
  306. $courseIcon,
  307. ];
  308. }
  309. }
  310. return $courseList;
  311. }
  312. $table = new SortableTable(
  313. 'tracking_course',
  314. 'get_count_courses',
  315. 'get_courses',
  316. 1,
  317. 10
  318. );
  319. $table->set_header(0, get_lang('CourseTitle'), false);
  320. $table->set_header(1, get_lang('NbStudents'), false);
  321. $table->set_header(2, get_lang('TimeSpentInTheCourse').Display::return_icon('info.png', get_lang('TimeOfActiveByTraining'), ['align' => 'absmiddle', 'hspace' => '3px']), false);
  322. $table->set_header(3, get_lang('ThematicAdvance'), false);
  323. $table->set_header(4, get_lang('AvgStudentsProgress').Display::return_icon('info.png', get_lang('AvgAllUsersInAllCourses'), ['align' => 'absmiddle', 'hspace' => '3px']), false);
  324. $table->set_header(5, get_lang('AvgCourseScore').Display::return_icon('info.png', get_lang('AvgAllUsersInAllCourses'), ['align' => 'absmiddle', 'hspace' => '3px']), false);
  325. $table->set_header(6, get_lang('AvgMessages'), false);
  326. $table->set_header(7, get_lang('AvgAssignments'), false);
  327. $table->set_header(8, get_lang('Attendances'), false);
  328. $table->set_header(9, get_lang('Details'), false);
  329. $form = new FormValidator('search_course', 'get', api_get_path(WEB_CODE_PATH).'mySpace/course.php');
  330. $form->addElement('text', 'keyword', get_lang('Keyword'));
  331. $form->addButtonSearch(get_lang('Search'));
  332. $form->addElement('hidden', 'session_id', $sessionId);
  333. $keyword = isset($_GET['keyword']) ? Security::remove_XSS($_GET['keyword']) : null;
  334. $params = [
  335. 'session_id' => $sessionId,
  336. 'keyword' => $keyword,
  337. ];
  338. $table->set_additional_parameters($params);
  339. $form->setDefaults($params);
  340. $form->display();
  341. $table->display();
  342. Display :: display_footer();