course.php 13 KB

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