course.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <?php
  2. /*
  3. * Created on 28 juil. 2006 by Elixir Interactive http://www.elixir-interactive.com
  4. */
  5. ob_start();
  6. $nameTools = 'Cours';
  7. // name of the language file that needs to be included
  8. $language_file = array ('admin', 'registration', 'index', 'trad4all', 'tracking');
  9. $cidReset = true;
  10. require '../inc/global.inc.php';
  11. require_once api_get_path(LIBRARY_PATH).'tracking.lib.php';
  12. require_once api_get_path(LIBRARY_PATH).'export.lib.inc.php';
  13. require_once api_get_path(LIBRARY_PATH).'course.lib.php';
  14. $this_section = "session_my_space";
  15. $id_session = intval($_GET['id_session']);
  16. api_block_anonymous_users();
  17. $interbreadcrumb[] = array ("url" => "index.php", "name" => get_lang('MySpace'));
  18. if(isset($_GET["id_session"]) && $_GET["id_session"]!=""){
  19. $interbreadcrumb[] = array ("url" => "session.php", "name" => get_lang('Sessions'));
  20. }
  21. if(isset($_GET["user_id"]) && $_GET["user_id"]!="" && isset($_GET["type"]) && $_GET["type"]=="coach"){
  22. $interbreadcrumb[] = array ("url" => "coaches.php", "name" => get_lang('Tutors'));
  23. }
  24. if(isset($_GET["user_id"]) && $_GET["user_id"]!="" && isset($_GET["type"]) && $_GET["type"]=="student"){
  25. $interbreadcrumb[] = array ("url" => "student.php", "name" => get_lang('Students'));
  26. }
  27. if(isset($_GET["user_id"]) && $_GET["user_id"]!="" && !isset($_GET["type"])){
  28. $interbreadcrumb[] = array ("url" => "teachers.php", "name" => get_lang('Teachers'));
  29. }
  30. function count_courses() {
  31. global $nb_courses;
  32. return $nb_courses;
  33. }
  34. //checking if the current coach is the admin coach
  35. $show_import_icon = false;
  36. if (api_get_setting('add_users_by_coach') == 'true') {
  37. if (!api_is_platform_admin()) {
  38. $sql = 'SELECT id_coach FROM '.Database :: get_main_table(TABLE_MAIN_SESSION).' WHERE id='.$id_session;
  39. $rs = Database::query($sql,__FILE__,__LINE__);
  40. if (Database::result($rs, 0, 0) != $_user['user_id']) {
  41. api_not_allowed(true);
  42. } else {
  43. $show_import_icon=true;
  44. }
  45. }
  46. }
  47. Display :: display_header($nameTools);
  48. // Database Table Definitions
  49. $tbl_course = Database :: get_main_table(TABLE_MAIN_COURSE);
  50. $tbl_user_course = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  51. $tbl_user = Database :: get_main_table(TABLE_MAIN_USER);
  52. $tbl_session_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
  53. $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
  54. $tbl_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  55. if (isset($_GET['action'])) {
  56. if ($_GET['action'] == 'show_message') {
  57. Display :: display_normal_message(stripslashes($_GET['message']),false);
  58. }
  59. if ($_GET['action'] == 'error_message') {
  60. Display :: display_error_message(stripslashes($_GET['message']),false);
  61. }
  62. }
  63. if ($show_import_icon) {
  64. echo "<div align=\"right\">";
  65. 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>';
  66. echo "</div><br />";
  67. }
  68. $a_courses = Tracking :: get_courses_followed_by_coach($_user['user_id'], $id_session);
  69. $nb_courses = count($a_courses);
  70. $table = new SortableTable('tracking_list_course', 'count_courses');
  71. $table -> set_header(0, get_lang('CourseTitle'), false, 'align="center"');
  72. $table -> set_header(1, get_lang('NbStudents'), false);
  73. $table -> set_header(2, get_lang('TimeSpentInTheCourse'), false);
  74. $table -> set_header(3, get_lang('AvgStudentsProgress'), false);
  75. $table -> set_header(4, get_lang('AvgCourseScore'), false);
  76. //$table -> set_header(5, get_lang('AvgExercisesScore'), false);// no code for this?
  77. $table -> set_header(5, get_lang('AvgMessages'), false);
  78. $table -> set_header(6, get_lang('AvgAssignments'), false);
  79. $table -> set_header(7, get_lang('Details'), false);
  80. $csv_content[] = array(
  81. get_lang('CourseTitle'),
  82. get_lang('NbStudents'),
  83. get_lang('TimeSpentInTheCourse'),
  84. get_lang('AvgStudentsProgress'),
  85. get_lang('AvgCourseScore'),
  86. //get_lang('AvgExercisesScore'),
  87. get_lang('AvgMessages'),
  88. get_lang('AvgAssignments')
  89. );
  90. if (is_array($a_courses)) {
  91. foreach ($a_courses as $course_code) {
  92. $nb_students_in_course = 0;
  93. $a_students = array();
  94. $course = CourseManager :: get_course_information($course_code);
  95. $avg_assignments_in_course = $avg_messages_in_course = $avg_progress_in_course = $avg_score_in_course = $avg_time_spent_in_course = 0;
  96. // students subscribed to the course throw a session
  97. if (api_get_setting('use_session_mode') == 'true') {
  98. $sql = 'SELECT id_user as user_id
  99. FROM '.$tbl_session_course_user.'
  100. WHERE course_code="'.Database :: escape_string($course_code).'"
  101. AND id_session='.$id_session;
  102. $rs = Database::query($sql, __FILE__, __LINE__);
  103. while ($row = Database::fetch_array($rs)) {
  104. if (!in_array($row['user_id'], $a_students)) {
  105. $nb_students_in_course++;
  106. // tracking datas
  107. $avg_progress_in_course += Tracking :: get_avg_student_progress ($row['user_id'], $course_code);
  108. $avg_score_in_course += Tracking :: get_avg_student_score ($row['user_id'], $course_code);
  109. $avg_time_spent_in_course += Tracking :: get_time_spent_on_the_course ($row['user_id'], $course_code);
  110. $avg_messages_in_course += Tracking :: count_student_messages ($row['user_id'], $course_code);
  111. $avg_assignments_in_course += Tracking :: count_student_assignments ($row['user_id'], $course_code);
  112. $a_students[] = $row['user_id'];
  113. }
  114. }
  115. }
  116. if ($nb_students_in_course > 0) {
  117. $avg_time_spent_in_course = api_time_to_hms($avg_time_spent_in_course / $nb_students_in_course);
  118. $avg_progress_in_course = round($avg_progress_in_course / $nb_students_in_course, 2).' %';
  119. $avg_score_in_course = round($avg_score_in_course / $nb_students_in_course, 2).' %';
  120. $avg_messages_in_course = round($avg_messages_in_course / $nb_students_in_course, 2);
  121. $avg_assignments_in_course = round($avg_assignments_in_course / $nb_students_in_course, 2);
  122. }
  123. $table_row = array();
  124. $table_row[] = $course['title'];
  125. $table_row[] = $nb_students_in_course;
  126. $table_row[] = $avg_time_spent_in_course;
  127. $table_row[] = $avg_progress_in_course;
  128. $table_row[] = $avg_score_in_course;
  129. $table_row[] = $avg_messages_in_course;
  130. $table_row[] = $avg_assignments_in_course;
  131. $table_row[] = '<a href="../tracking/courseLog.php?cidReq='.$course_code.'&studentlist=true&id_session='.$id_session.'"><img src="'.api_get_path(WEB_IMG_PATH).'2rightarrow.gif" border="0" /></a>';
  132. $csv_content[] = array(
  133. $course['title'],
  134. $nb_students_in_course,
  135. $avg_time_spent_in_course,
  136. $avg_progress_in_course,
  137. $avg_score_in_course,
  138. $avg_messages_in_course,
  139. $avg_assignments_in_course,
  140. );
  141. $table -> addRow($table_row, 'align="right"');
  142. }
  143. }
  144. $table -> setColAttributes(0, array('align'=>'left'));
  145. $table -> setColAttributes(7, array('align'=>'center'));
  146. $table -> display();
  147. /*
  148. ==============================================================================
  149. FOOTER
  150. ==============================================================================
  151. */
  152. Display :: display_footer();