coaches.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /*
  4. * Coaches reporting
  5. * @package chamilo.reporting
  6. */
  7. /**
  8. * Code
  9. */
  10. ob_start();
  11. // name of the language file that needs to be included
  12. $language_file = array ('registration', 'index', 'tracking', 'admin');
  13. $cidReset = true;
  14. require '../inc/global.inc.php';
  15. require_once api_get_path(SYS_CODE_PATH).'mySpace/myspace.lib.php';
  16. $this_section = SECTION_TRACKING;
  17. $nameTools = get_lang('Tutors');
  18. api_block_anonymous_users();
  19. $interbreadcrumb[] = array ("url" => "index.php", "name" => get_lang('MySpace'));
  20. if (isset($_GET["id_student"])) {
  21. $interbreadcrumb[] = array ("url" => "student.php", "name" => get_lang('Students'));
  22. }
  23. Display :: display_header($nameTools);
  24. api_display_tool_title($nameTools);
  25. // Database Table Definitions
  26. $tbl_course = Database :: get_main_table(TABLE_MAIN_COURSE);
  27. $tbl_course_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  28. $tbl_user = Database :: get_main_table(TABLE_MAIN_USER);
  29. $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
  30. $tbl_session_rel_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
  31. $tbl_session_rel_course_rel_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  32. $tbl_session_rel_user = Database :: get_main_table(TABLE_MAIN_SESSION_USER);
  33. $tbl_track_login = Database :: get_main_table(TABLE_STATISTIC_TRACK_E_LOGIN);
  34. if (isset($_POST['export'])) {
  35. $order_clause = api_is_western_name_order(PERSON_NAME_DATA_EXPORT) ? ' ORDER BY firstname, lastname' : ' ORDER BY lastname, firstname';
  36. } else {
  37. $order_clause = api_sort_by_first_name() ? ' ORDER BY firstname, lastname' : ' ORDER BY lastname, firstname';
  38. }
  39. if (isset($_GET["id_student"])) {
  40. $id_student = intval($_GET["id_student"]);
  41. $sql_coachs = "SELECT DISTINCT srcru.id_user as id_coach" .
  42. "FROM $tbl_session_rel_course_rel_user as srcru " .
  43. "WHERE srcru.id_user='$id_student' AND srcru.status=2";
  44. } else {
  45. if (api_is_platform_admin()) {
  46. $sql_coachs = "SELECT DISTINCT srcru.id_user as id_coach, user_id, lastname, firstname
  47. FROM $tbl_user, $tbl_session_rel_course_rel_user srcru
  48. WHERE srcru.id_user=user_id AND srcru.status=2 ".$order_clause;
  49. } else {
  50. $sql_coachs = "SELECT DISTINCT id_user as id_coach, $tbl_user.user_id, lastname, firstname
  51. FROM $tbl_user as user, $tbl_session_rel_course_user as srcu, $tbl_course_user as course_rel_user, $tbl_course course
  52. WHERE course_rel_user.c_id = course.id AND srcu.c_id = course.id AND
  53. course_rel_user.status='1' AND
  54. course_rel_user.user_id='".api_get_user_id()."' AND
  55. srcu.id_user=user.user_id AND srcu.status=2 ".$order_clause;
  56. }
  57. }
  58. $result_coachs = Database::query($sql_coachs);
  59. if (api_is_western_name_order()) {
  60. echo '<table class="data_table"><tr><th>'.get_lang('FirstName').'</th><th>'.get_lang('LastName').'</th><th>'.get_lang('ConnectionTime').'</th><th>'.get_lang('AdminCourses').'</th><th>'.get_lang('Students').'</th></tr>';
  61. } else {
  62. echo '<table class="data_table"><tr><th>'.get_lang('LastName').'</th><th>'.get_lang('FirstName').'</th><th>'.get_lang('ConnectionTime').'</th><th>'.get_lang('AdminCourses').'</th><th>'.get_lang('Students').'</th></tr>';
  63. }
  64. if (api_is_western_name_order(PERSON_NAME_DATA_EXPORT)) {
  65. $header[] = get_lang('FirstName', '');
  66. $header[] = get_lang('LastName', '');
  67. } else {
  68. $header[] = get_lang('LastName', '');
  69. $header[] = get_lang('FirstName', '');
  70. }
  71. $header[] = get_lang('ConnectionTime', '');
  72. if (Database::num_rows($result_coachs) > 0) {
  73. while ($coachs = Database::fetch_array($result_coachs)) {
  74. $id_coach = $coachs["id_coach"];
  75. if (isset($_GET["id_student"])) {
  76. $sql_infos_coach = "SELECT lastname, firstname FROM $tbl_user WHERE user_id = '$id_coach'";
  77. $result_coachs_infos = Database::query($sql_infos_coach);
  78. $lastname = Database::result($result_coachs_infos, 0, "lastname");
  79. $firstname = Database::result($result_coachs_infos, 0, "firstname");
  80. } else {
  81. $lastname = $coachs["lastname"];
  82. $firstname = $coachs["firstname"];
  83. }
  84. $sql_connection_time = "SELECT login_date, logout_date FROM $tbl_track_login WHERE login_user_id ='$id_coach' AND logout_date <> 'null'";
  85. $result_connection_time = Database::query($sql_connection_time);
  86. $nb_seconds = 0;
  87. while ($connections = Database::fetch_array($result_connection_time)) {
  88. $login_date = $connections["login_date"];
  89. $logout_date = $connections["logout_date"];
  90. $timestamp_login_date = strtotime($login_date);
  91. $timestamp_logout_date = strtotime($logout_date);
  92. $nb_seconds += ($timestamp_logout_date - $timestamp_login_date);
  93. }
  94. if ($nb_seconds == 0) {
  95. $s_connection_time = '';
  96. } else {
  97. $s_connection_time = api_time_to_hms($nb_seconds);
  98. }
  99. if ($i % 2 == 0) {
  100. $css_class = "row_odd";
  101. if ($i % 20 == 0 && $i != 0) {
  102. if (api_is_western_name_order()) {
  103. echo '<tr><th>'.get_lang('FirstName').'</th><th>'.get_lang('LastName').'</th><th>'.get_lang('ConnectionTime').'</th><th>'.get_lang('AdminCourses').'</th><th>'.get_lang('Students').'</th></tr>';
  104. } else {
  105. echo '<tr><th>'.get_lang('LastName').'</th><th>'.get_lang('FirstName').'</th><th>'.get_lang('ConnectionTime').'</th><th>'.get_lang('AdminCourses').'</th><th>'.get_lang('Students').'</th></tr>';
  106. }
  107. }
  108. } else {
  109. $css_class = "row_even";
  110. }
  111. $i++;
  112. if (api_is_western_name_order()) {
  113. echo '<tr class="'.$css_class.'"><td>'.$firstname.'</td><td>'.$lastname.'</td><td>'.$s_connection_time.'</td><td><a href="course.php?type=coach&user_id='.$id_coach.'"><img src="'.api_get_path(WEB_IMG_PATH).'2rightarrow.gif" border="0" /></a></td><td><a href="student.php?type=coach&user_id='.$id_coach.'"><img src="'.api_get_path(WEB_IMG_PATH).'2rightarrow.gif" border="0" /></a></td></tr>';
  114. } else {
  115. echo '<tr class="'.$css_class.'"><td>'.$lastname.'</td><td>'.$firstname.'</td><td>'.$s_connection_time.'</td><td><a href="course.php?type=coach&user_id='.$id_coach.'"><img src="'.api_get_path(WEB_IMG_PATH).'2rightarrow.gif" border="0" /></a></td><td><a href="student.php?type=coach&user_id='.$id_coach.'"><img src="'.api_get_path(WEB_IMG_PATH).'2rightarrow.gif" border="0" /></a></td></tr>';
  116. }
  117. if (api_is_western_name_order(PERSON_NAME_DATA_EXPORT)) {
  118. $data[$id_coach]["firstname"] = $firstname;
  119. $data[$id_coach]["lastname"] = $lastname;
  120. } else {
  121. $data[$id_coach]["lastname"] = $lastname;
  122. $data[$id_coach]["firstname"] = $firstname;
  123. }
  124. $data[$id_coach]["connection_time"] = $s_connection_time;
  125. }
  126. } else {
  127. // No results
  128. echo '<tr><td colspan="5">'.get_lang("NoResult").'</td></tr>';
  129. }
  130. echo '</table>';
  131. if (isset($_POST['export'])){
  132. export_csv($header, $data, 'coaches.csv');
  133. }
  134. echo "<br /><br />";
  135. echo "<form method='post' action='coaches.php'><button type='submit' class='save' name='export' value='".get_lang('exportExcel')."'>".get_lang('exportExcel')."</button><form>";
  136. Display::display_footer();