course.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. <?php
  2. /* For licensing terms, see /dokeos_license.txt */
  3. /*
  4. * Created on 28 juil. 2006 by Elixir Interactive http://www.elixir-interactive.com
  5. */
  6. ob_start();
  7. $nameTools = 'Cours';
  8. // name of the language file that needs to be included
  9. $language_file = array ('admin', 'registration', 'index', 'trad4all', 'tracking');
  10. $cidReset = true;
  11. require '../inc/global.inc.php';
  12. require_once api_get_path(LIBRARY_PATH).'tracking.lib.php';
  13. require_once api_get_path(LIBRARY_PATH).'export.lib.inc.php';
  14. require_once api_get_path(LIBRARY_PATH).'course.lib.php';
  15. require_once api_get_path(LIBRARY_PATH).'course_description.lib.php';
  16. $this_section = "session_my_space";
  17. $id_session = intval($_GET['id_session']);
  18. api_block_anonymous_users();
  19. $interbreadcrumb[] = array ("url" => "index.php", "name" => get_lang('MySpace'));
  20. if (isset($_GET["id_session"]) && $_GET["id_session"] != "") {
  21. $interbreadcrumb[] = array ("url" => "session.php", "name" => get_lang('Sessions'));
  22. }
  23. if (isset($_GET["user_id"]) && $_GET["user_id"] != "" && isset($_GET["type"]) && $_GET["type"] == "coach") {
  24. $interbreadcrumb[] = array ("url" => "coaches.php", "name" => get_lang('Tutors'));
  25. }
  26. if (isset($_GET["user_id"]) && $_GET["user_id"] != "" && isset($_GET["type"]) && $_GET["type"] == "student") {
  27. $interbreadcrumb[] = array ("url" => "student.php", "name" => get_lang('Students'));
  28. }
  29. if (isset($_GET["user_id"]) && $_GET["user_id"] != "" && !isset($_GET["type"])) {
  30. $interbreadcrumb[] = array ("url" => "teachers.php", "name" => get_lang('Teachers'));
  31. }
  32. function count_courses() {
  33. global $nb_courses;
  34. return $nb_courses;
  35. }
  36. //checking if the current coach is the admin coach
  37. $show_import_icon = false;
  38. if (api_get_setting('add_users_by_coach') == 'true') {
  39. if (!api_is_platform_admin()) {
  40. $sql = 'SELECT id_coach FROM '.Database :: get_main_table(TABLE_MAIN_SESSION).' WHERE id='.$id_session;
  41. $rs = Database::query($sql);
  42. if (Database::result($rs, 0, 0) != $_user['user_id']) {
  43. api_not_allowed(true);
  44. } else {
  45. $show_import_icon=true;
  46. }
  47. }
  48. }
  49. Display :: display_header($nameTools);
  50. $a_courses = array();
  51. if (api_is_drh() || api_is_session_admin() || api_is_platform_admin()) {
  52. $title = '';
  53. if (empty($id_session)) {
  54. if (isset($_GET['user_id'])) {
  55. $user_id = intval($_GET['user_id']);
  56. $user_info = api_get_user_info($user_id);
  57. $title = get_lang('AssignedCoursesTo').' '.api_get_person_name($user_info['firstname'], $user_info['lastname']);
  58. $courses = CourseManager::get_course_list_of_user_as_course_admin($user_id);
  59. } else {
  60. $title = get_lang('YourCourseList');
  61. $courses = CourseManager::get_courses_followed_by_drh($_user['user_id']);
  62. }
  63. } else {
  64. $session_name = api_get_session_name($id_session);
  65. $title = api_htmlentities($session_name,ENT_QUOTES,$charset).' : '.get_lang('CourseListInSession');
  66. $courses = Tracking::get_courses_list_from_session($id_session);
  67. }
  68. $a_courses = array_keys($courses);
  69. if (!api_is_session_admin()) {
  70. $menu_items[] = '<a href="index.php?view=drh_students&amp;display=yourstudents">'.get_lang('Students').'</a>';
  71. $menu_items[] = '<a href="teachers.php">'.get_lang('Teachers').'</a>';
  72. if (empty($_GET['user_id']) && empty($id_session)) {
  73. $menu_items[] = get_lang('Courses');
  74. } else {
  75. $menu_items[] = '<a href="course.php">'.get_lang('Courses').'</a>';
  76. }
  77. $menu_items[] = '<a href="session.php">'.get_lang('Sessions').'</a>';
  78. }
  79. echo '<div class="actions-title" style ="font-size:10pt;">';
  80. $nb_menu_items = count($menu_items);
  81. if ($nb_menu_items > 1) {
  82. foreach ($menu_items as $key => $item) {
  83. echo $item;
  84. if ($key != $nb_menu_items - 1) {
  85. echo '&nbsp;|&nbsp;';
  86. }
  87. }
  88. }
  89. if (count($a_courses) > 0) {
  90. echo '&nbsp;&nbsp;<a href="javascript: void(0);" onclick="javascript: window.print()"><img align="absbottom" src="../img/printmgr.gif">&nbsp;'.get_lang('Print').'</a> ';
  91. }
  92. echo '</div>';
  93. echo '<h4>'.$title.'</h4>';
  94. }
  95. // Database Table Definitions
  96. $tbl_course = Database :: get_main_table(TABLE_MAIN_COURSE);
  97. $tbl_user_course = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  98. $tbl_user = Database :: get_main_table(TABLE_MAIN_USER);
  99. $tbl_session_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
  100. $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
  101. $tbl_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  102. if (isset($_GET['action'])) {
  103. if ($_GET['action'] == 'show_message') {
  104. Display :: display_normal_message(stripslashes($_GET['message']), false);
  105. }
  106. if ($_GET['action'] == 'error_message') {
  107. Display :: display_error_message(stripslashes($_GET['message']), false);
  108. }
  109. }
  110. if ($show_import_icon) {
  111. echo "<div align=\"right\">";
  112. 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>';
  113. echo "</div><br />";
  114. }
  115. if (!api_is_drh() && !api_is_session_admin() && !api_is_platform_admin()) {
  116. /*if (api_is_platform_admin()) {
  117. if (empty($id_session)) {
  118. $courses = CourseManager::get_real_course_list();
  119. } else {
  120. $courses = Tracking::get_courses_list_from_session($id_session);
  121. }
  122. } else {*/
  123. $courses = Tracking::get_courses_followed_by_coach($_user['user_id'], $id_session);
  124. //}
  125. $a_courses = array_keys($courses);
  126. }
  127. $nb_courses = count($a_courses);
  128. $table = new SortableTable('tracking_list_course', 'count_courses');
  129. $table -> set_header(0, get_lang('CourseTitle'), false, 'align="center"');
  130. $table -> set_header(1, get_lang('NbStudents'), false);
  131. $table -> set_header(2, get_lang('TimeSpentInTheCourse').Display :: return_icon('info3.gif', get_lang('TimeOfActiveByTraining'), array('align' => 'absmiddle', 'hspace' => '3px')), false);
  132. $table -> set_header(3, get_lang('ThematicAdvance'), false);
  133. $table -> set_header(4, get_lang('AvgStudentsProgress').Display :: return_icon('info3.gif', get_lang('AvgAllUsersInAllCourses'), array('align' => 'absmiddle', 'hspace' => '3px')), false);
  134. $table -> set_header(5, get_lang('AvgCourseScore').Display :: return_icon('info3.gif', get_lang('AvgAllUsersInAllCourses'), array('align' => 'absmiddle', 'hspace' => '3px')), false);
  135. //$table -> set_header(5, get_lang('AvgExercisesScore'), false);// no code for this?
  136. $table -> set_header(6, get_lang('AvgMessages'), false);
  137. $table -> set_header(7, get_lang('AvgAssignments'), false);
  138. $table -> set_header(8, get_lang('Details'), false);
  139. $csv_header[] = array(
  140. get_lang('CourseTitle', ''),
  141. get_lang('NbStudents', ''),
  142. get_lang('TimeSpentInTheCourse', ''),
  143. get_lang('ThematicAdvance', ''),
  144. get_lang('AvgStudentsProgress', ''),
  145. get_lang('AvgCourseScore', ''),
  146. //get_lang('AvgExercisesScore', ''),
  147. get_lang('AvgMessages', ''),
  148. get_lang('AvgAssignments', '')
  149. );
  150. if (is_array($a_courses)) {
  151. foreach ($a_courses as $course_code) {
  152. $nb_students_in_course = 0;
  153. $course = CourseManager :: get_course_information($course_code);
  154. $avg_assignments_in_course = $avg_messages_in_course = $avg_progress_in_course = $avg_score_in_course = $avg_time_spent_in_course = 0;
  155. // students directly subscribed to the course
  156. if (empty($id_session)) {
  157. $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'";
  158. } else {
  159. $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";
  160. }
  161. $rs = Database::query($sql);
  162. $users = array();
  163. while ($row = Database::fetch_array($rs)) { $users[] = $row['user_id']; }
  164. if (count($users) > 0) {
  165. $nb_students_in_course = count($users);
  166. // tracking datas
  167. $avg_progress_in_course = Tracking :: get_avg_student_progress ($users, $course_code, array(), $id_session);
  168. $avg_score_in_course = Tracking :: get_avg_student_score ($users, $course_code, array(), $id_session);
  169. $avg_time_spent_in_course = Tracking :: get_time_spent_on_the_course ($users, $course_code, $id_session);
  170. $messages_in_course = Tracking :: count_student_messages ($users, $course_code, $id_session);
  171. $assignments_in_course = Tracking :: count_student_assignments ($users, $course_code, $id_session);
  172. $avg_time_spent_in_course = api_time_to_hms($avg_time_spent_in_course / $nb_students_in_course);
  173. $avg_progress_in_course = round($avg_progress_in_course / $nb_students_in_course, 2);
  174. $avg_score_in_course = round($avg_score_in_course / $nb_students_in_course, 2);
  175. } else {
  176. $avg_time_spent_in_course = null;
  177. $avg_progress_in_course = null;
  178. $avg_score_in_course = null;
  179. $messages_in_course = null;
  180. $assignments_in_course = null;
  181. }
  182. $tematic_advance_progress = 0;
  183. $course_description = new CourseDescription();
  184. $course_description->set_session_id($id_session);
  185. $tematic_advance = $course_description->get_data_by_description_type(8, $course_code);
  186. if (!empty($tematic_advance)) {
  187. $tematic_advance_csv = $tematic_advance_progress.'%';
  188. $tematic_advance_progress = '<a title="'.get_lang('GoToThematicAdvance').'" href="'.api_get_path(WEB_CODE_PATH).'course_description/?cidReq='.$course_code.'#thematic_advance">'.$tematic_advance['progress'].'%</a>';
  189. } else {
  190. $tematic_advance_progress = '-';
  191. }
  192. $table_row = array();
  193. $table_row[] = $course['title'];
  194. $table_row[] = $nb_students_in_course;
  195. $table_row[] = is_null($avg_time_spent_in_course)?'-':$avg_time_spent_in_course;
  196. $table_row[] = $tematic_advance_progress;
  197. $table_row[] = is_null($avg_progress_in_course) ? '-' : $avg_progress_in_course.'%';
  198. $table_row[] = is_null($avg_score_in_course) ? '-' : $avg_score_in_course.'%';
  199. $table_row[] = is_null($messages_in_course)?'-':$messages_in_course;
  200. $table_row[] = is_null($assignments_in_course)?'-':$assignments_in_course;
  201. $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>';
  202. $csv_content[] = array (
  203. $course['title'],
  204. $nb_students_in_course,
  205. $avg_time_spent_in_course,
  206. $tematic_advance_csv,
  207. is_null($avg_progress_in_course) ? null : $avg_progress_in_course.'%',
  208. is_null($avg_score_in_course) ? null : $avg_score_in_course.'%',
  209. $messages_in_course,
  210. $assignments_in_course,
  211. );
  212. $table -> addRow($table_row, 'align="right"');
  213. }
  214. // $csv_content = array_merge($csv_header, $csv_content); // Before this statement you are allowed to sort (in different way) the array $csv_content.
  215. }
  216. $table -> setColAttributes(0, array('align' => 'left'));
  217. $table -> setColAttributes(7, array('align' => 'center'));
  218. $table -> display();
  219. /*
  220. ==============================================================================
  221. FOOTER
  222. ==============================================================================
  223. */
  224. Display :: display_footer();