course.php 12 KB

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