course.php 12 KB

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