PageRenderTime 45ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/php/main/mySpace/course.php

https://bitbucket.org/frchico/chamilo_openshift
PHP | 244 lines | 188 code | 38 blank | 18 comment | 53 complexity | 1e1918da7b36c1de370085838347f889 MD5 | raw file
  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. require_once api_get_path(LIBRARY_PATH).'thematic.lib.php';
  18. $this_section = SECTION_TRACKING;
  19. $id_session = intval($_GET['id_session']);
  20. api_block_anonymous_users();
  21. $interbreadcrumb[] = array ("url" => "index.php", "name" => get_lang('MySpace'));
  22. if (isset($_GET["id_session"]) && $_GET["id_session"] != "") {
  23. $interbreadcrumb[] = array ("url" => "session.php", "name" => get_lang('Sessions'));
  24. }
  25. if (isset($_GET["user_id"]) && $_GET["user_id"] != "" && isset($_GET["type"]) && $_GET["type"] == "coach") {
  26. $interbreadcrumb[] = array ("url" => "coaches.php", "name" => get_lang('Tutors'));
  27. }
  28. if (isset($_GET["user_id"]) && $_GET["user_id"] != "" && isset($_GET["type"]) && $_GET["type"] == "student") {
  29. $interbreadcrumb[] = array ("url" => "student.php", "name" => get_lang('Students'));
  30. }
  31. if (isset($_GET["user_id"]) && $_GET["user_id"] != "" && !isset($_GET["type"])) {
  32. $interbreadcrumb[] = array ("url" => "teachers.php", "name" => get_lang('Teachers'));
  33. }
  34. function count_courses() {
  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 FROM '.Database :: get_main_table(TABLE_MAIN_SESSION).' WHERE id='.$id_session;
  43. $rs = Database::query($sql);
  44. if (Database::result($rs, 0, 0) != $_user['user_id']) {
  45. api_not_allowed(true);
  46. } else {
  47. $show_import_icon=true;
  48. }
  49. }
  50. }
  51. Display :: display_header($nameTools);
  52. $a_courses = array();
  53. if (api_is_drh() || api_is_session_admin() || api_is_platform_admin()) {
  54. $title = '';
  55. if (empty($id_session)) {
  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($_user['user_id']);
  64. }
  65. } else {
  66. $session_name = api_get_session_name($id_session);
  67. $title = api_htmlentities($session_name,ENT_QUOTES,$charset).' : '.get_lang('CourseListInSession');
  68. $courses = Tracking::get_courses_list_from_session($id_session);
  69. }
  70. $a_courses = array_keys($courses);
  71. if (!api_is_session_admin()) {
  72. $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" );
  73. $menu_items[] = Display::url(Display::return_icon('user.png', get_lang('Students'), array(), 32), "index.php?view=drh_students&amp;display=yourstudents");
  74. $menu_items[] = Display::url(Display::return_icon('teacher.png', get_lang('Trainers'), array(), 32), 'teachers.php');
  75. $menu_items[] = Display::return_icon('course_na.png', get_lang('Courses'), array(), 32);
  76. $menu_items[] = Display::url(Display::return_icon('session.png', get_lang('Sessions'), array(), 32), 'session.php');
  77. }
  78. echo '<div class="actions">';
  79. $nb_menu_items = count($menu_items);
  80. if ($nb_menu_items > 1) {
  81. foreach ($menu_items as $key => $item) {
  82. echo $item;
  83. }
  84. }
  85. if (count($a_courses) > 0) {
  86. echo '<span style="float:right">';
  87. echo Display::url(Display::return_icon('printer.png', get_lang('Print'), array(), 32), 'javascript: void(0);', array('onclick'=>'javascript: window.print();'));
  88. echo '</span>';
  89. }
  90. echo '</div>';
  91. echo Display::page_header($title);
  92. }
  93. // Database Table Definitions
  94. $tbl_session_course_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  95. $tbl_user_course = Database::get_main_table(TABLE_MAIN_COURSE_USER);
  96. if (isset($_GET['action'])) {
  97. if ($_GET['action'] == 'show_message') {
  98. Display :: display_normal_message(stripslashes($_GET['message']), false);
  99. }
  100. if ($_GET['action'] == 'error_message') {
  101. Display :: display_error_message(stripslashes($_GET['message']), false);
  102. }
  103. }
  104. if ($show_import_icon) {
  105. echo "<div align=\"right\">";
  106. echo '<a href="user_import.php?id_session='.$id_session.'&action=export&amp;type=xml">'.Display::return_icon('excel.gif', get_lang('ImportUserListXMLCSV')).'&nbsp;'.get_lang('ImportUserListXMLCSV').'</a>';
  107. echo "</div><br />";
  108. }
  109. if (!api_is_drh() && !api_is_session_admin() && !api_is_platform_admin()) {
  110. $courses = Tracking::get_courses_followed_by_coach($_user['user_id'], $id_session);
  111. $a_courses = array_keys($courses);
  112. }
  113. $nb_courses = count($a_courses);
  114. $table = new SortableTable('tracking_list_course', 'count_courses');
  115. $table -> set_header(0, get_lang('CourseTitle'), false);
  116. $table -> set_header(1, get_lang('NbStudents'), false);
  117. $table -> set_header(2, get_lang('TimeSpentInTheCourse').Display :: return_icon('info3.gif', get_lang('TimeOfActiveByTraining'), array('align' => 'absmiddle', 'hspace' => '3px')), false);
  118. $table -> set_header(3, get_lang('ThematicAdvance'), false);
  119. $table -> set_header(4, get_lang('AvgStudentsProgress').Display :: return_icon('info3.gif', get_lang('AvgAllUsersInAllCourses'), array('align' => 'absmiddle', 'hspace' => '3px')), false);
  120. $table -> set_header(5, get_lang('AvgCourseScore').Display :: return_icon('info3.gif', get_lang('AvgAllUsersInAllCourses'), array('align' => 'absmiddle', 'hspace' => '3px')), false);
  121. //$table -> set_header(5, get_lang('AvgExercisesScore'), false);// no code for this?
  122. $table -> set_header(6, get_lang('AvgMessages'), false);
  123. $table -> set_header(7, get_lang('AvgAssignments'), false);
  124. $table -> set_header(8, get_lang('Details'), false);
  125. $csv_header[] = array(
  126. get_lang('CourseTitle', ''),
  127. get_lang('NbStudents', ''),
  128. get_lang('TimeSpentInTheCourse', ''),
  129. get_lang('ThematicAdvance', ''),
  130. get_lang('AvgStudentsProgress', ''),
  131. get_lang('AvgCourseScore', ''),
  132. //get_lang('AvgExercisesScore', ''),
  133. get_lang('AvgMessages', ''),
  134. get_lang('AvgAssignments', '')
  135. );
  136. if (is_array($a_courses)) {
  137. foreach ($a_courses as $course_code) {
  138. $nb_students_in_course = 0;
  139. $course = CourseManager :: get_course_information($course_code);
  140. $avg_assignments_in_course = $avg_messages_in_course = $avg_progress_in_course = $avg_score_in_course = $avg_time_spent_in_course = 0;
  141. // students directly subscribed to the course
  142. if (empty($id_session)) {
  143. $sql = "SELECT user_id FROM $tbl_user_course as course_rel_user WHERE course_rel_user.status='5' AND course_rel_user.course_code='$course_code'";
  144. } else {
  145. $sql = "SELECT id_user as user_id FROM $tbl_session_course_user srcu WHERE srcu. course_code='$course_code' AND id_session = '$id_session' AND srcu.status<>2";
  146. }
  147. $rs = Database::query($sql);
  148. $users = array();
  149. while ($row = Database::fetch_array($rs)) { $users[] = $row['user_id']; }
  150. if (count($users) > 0) {
  151. $nb_students_in_course = count($users);
  152. // tracking datas
  153. $avg_progress_in_course = Tracking :: get_avg_student_progress ($users, $course_code, array(), $id_session);
  154. $avg_score_in_course = Tracking :: get_avg_student_score ($users, $course_code, array(), $id_session);
  155. $avg_time_spent_in_course = Tracking :: get_time_spent_on_the_course ($users, $course_code, $id_session);
  156. $messages_in_course = Tracking :: count_student_messages ($users, $course_code, $id_session);
  157. $assignments_in_course = Tracking :: count_student_assignments ($users, $course_code, $id_session);
  158. $avg_time_spent_in_course = api_time_to_hms($avg_time_spent_in_course / $nb_students_in_course);
  159. $avg_progress_in_course = round($avg_progress_in_course / $nb_students_in_course, 2);
  160. if (is_numeric($avg_score_in_course)) {
  161. $avg_score_in_course = round($avg_score_in_course / $nb_students_in_course, 2).'%';
  162. }
  163. } else {
  164. $avg_time_spent_in_course = null;
  165. $avg_progress_in_course = null;
  166. $avg_score_in_course = null;
  167. $messages_in_course = null;
  168. $assignments_in_course = null;
  169. }
  170. $tematic_advance_progress = 0;
  171. $thematic = new Thematic();
  172. $tematic_advance = $thematic->get_total_average_of_thematic_advances($course_code, $id_session);
  173. if (!empty($tematic_advance)) {
  174. $tematic_advance_csv = $tematic_advance_progress.'%';
  175. $tematic_advance_progress = '<a title="'.get_lang('GoToThematicAdvance').'" href="'.api_get_path(WEB_CODE_PATH).'course_progress/index.php?cidReq='.$course_code.'&id_session='.$id_session.'">'.$tematic_advance.'%</a>';
  176. } else {
  177. $tematic_advance_progress = '-';
  178. }
  179. $table_row = array();
  180. $table_row[] = $course['title'];
  181. $table_row[] = $nb_students_in_course;
  182. $table_row[] = is_null($avg_time_spent_in_course)?'-':$avg_time_spent_in_course;
  183. $table_row[] = $tematic_advance_progress;
  184. $table_row[] = is_null($avg_progress_in_course) ? '-' : $avg_progress_in_course.'%';
  185. $table_row[] = is_null($avg_score_in_course) ? '-' : $avg_score_in_course;
  186. $table_row[] = is_null($messages_in_course)?'-':$messages_in_course;
  187. $table_row[] = is_null($assignments_in_course)?'-':$assignments_in_course;
  188. $table_row[] = '<a href="../tracking/courseLog.php?cidReq='.$course_code.'&id_session='.$id_session.'"><img src="'.api_get_path(WEB_IMG_PATH).'2rightarrow.gif" border="0" /></a>';
  189. $csv_content[] = array (
  190. $course['title'],
  191. $nb_students_in_course,
  192. $avg_time_spent_in_course,
  193. $tematic_advance_csv,
  194. is_null($avg_progress_in_course) ? null : $avg_progress_in_course.'%',
  195. is_null($avg_score_in_course) ? null : $avg_score_in_course,
  196. $messages_in_course,
  197. $assignments_in_course,
  198. );
  199. $table -> addRow($table_row, 'align="right"');
  200. }
  201. // $csv_content = array_merge($csv_header, $csv_content); // Before this statement you are allowed to sort (in different way) the array $csv_content.
  202. }
  203. //$table -> setColAttributes(0);
  204. //$table -> setColAttributes(7);
  205. $table -> display();
  206. Display :: display_footer();