course.php 12 KB

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