coaches.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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_statistic_table(TABLE_STATISTIC_TRACK_E_LOGIN);
  34. /*
  35. FUNCTIONS
  36. */
  37. /*Posible Deprecated*/
  38. function is_coach() {
  39. global $tbl_session_course;
  40. $sql = "SELECT course_code FROM $tbl_session_course WHERE id_coach='".intval($_SESSION["_uid"])."'";
  41. $result = Database::query($sql);
  42. if (Database::num_rows($result) > 0) {
  43. return true;
  44. }
  45. return false;
  46. }
  47. /**
  48. * MAIN PART
  49. */
  50. if (isset($_POST['export'])) {
  51. $order_clause = api_is_western_name_order(PERSON_NAME_DATA_EXPORT) ? ' ORDER BY firstname, lastname' : ' ORDER BY lastname, firstname';
  52. } else {
  53. $order_clause = api_sort_by_first_name() ? ' ORDER BY firstname, lastname' : ' ORDER BY lastname, firstname';
  54. }
  55. if (isset($_GET["id_student"])) {
  56. $id_student = intval($_GET["id_student"]);
  57. $sql_coachs = "SELECT DISTINCT srcru.id_user as id_coach" .
  58. "FROM $tbl_session_rel_course_rel_user as srcru " .
  59. "WHERE srcru.id_user='$id_student' AND srcru.status=2";
  60. } else {
  61. if (api_is_platform_admin()) {
  62. $sql_coachs = "SELECT DISTINCT srcru.id_user as id_coach, user_id, lastname, firstname
  63. FROM $tbl_user, $tbl_session_rel_course_rel_user srcru
  64. WHERE srcru.id_user=user_id AND srcru.status=2 ".$order_clause;
  65. } else {
  66. $sql_coachs = "SELECT DISTINCT id_user as id_coach, $tbl_user.user_id, lastname, firstname
  67. FROM $tbl_user as user, $tbl_session_rel_course_user as srcu, $tbl_course_user as course_rel_user
  68. WHERE course_rel_user.course_code=srcu.course_code AND course_rel_user.status='1' AND course_rel_user.user_id='".intval($_SESSION["_uid"])."'
  69. AND srcu.id_user=user.user_id AND srcu.status=2 ".$order_clause;
  70. }
  71. }
  72. $result_coachs = Database::query($sql_coachs);
  73. if (api_is_western_name_order()) {
  74. 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>';
  75. } else {
  76. 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>';
  77. }
  78. if (api_is_western_name_order(PERSON_NAME_DATA_EXPORT)) {
  79. $header[] = get_lang('FirstName', '');
  80. $header[] = get_lang('LastName', '');
  81. } else {
  82. $header[] = get_lang('LastName', '');
  83. $header[] = get_lang('FirstName', '');
  84. }
  85. $header[] = get_lang('ConnectionTime', '');
  86. if (Database::num_rows($result_coachs) > 0) {
  87. while ($coachs = Database::fetch_array($result_coachs)) {
  88. $id_coach = $coachs["id_coach"];
  89. if (isset($_GET["id_student"])) {
  90. $sql_infos_coach = "SELECT lastname, firstname FROM $tbl_user WHERE user_id='$id_coach'";
  91. $result_coachs_infos = Database::query($sql_infos_coach);
  92. $lastname = Database::result($result_coachs_infos, 0, "lastname");
  93. $firstname = Database::result($result_coachs_infos, 0, "firstname");
  94. } else {
  95. $lastname = $coachs["lastname"];
  96. $firstname = $coachs["firstname"];
  97. }
  98. $sql_connection_time = "SELECT login_date, logout_date FROM $tbl_track_login WHERE login_user_id ='$id_coach' AND logout_date <> 'null'";
  99. $result_connection_time = Database::query($sql_connection_time);
  100. $nb_seconds = 0;
  101. while ($connections = Database::fetch_array($result_connection_time)) {
  102. $login_date = $connections["login_date"];
  103. $logout_date = $connections["logout_date"];
  104. $timestamp_login_date = strtotime($login_date);
  105. $timestamp_logout_date = strtotime($logout_date);
  106. $nb_seconds += ($timestamp_logout_date - $timestamp_login_date);
  107. }
  108. if ($nb_seconds == 0) {
  109. $s_connection_time = '';
  110. } else {
  111. $s_connection_time = api_time_to_hms($nb_seconds);
  112. }
  113. if ($i % 2 == 0) {
  114. $css_class = "row_odd";
  115. if ($i % 20 == 0 && $i != 0) {
  116. if (api_is_western_name_order()) {
  117. 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>';
  118. } else {
  119. 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>';
  120. }
  121. }
  122. } else {
  123. $css_class = "row_even";
  124. }
  125. $i++;
  126. if (api_is_western_name_order()) {
  127. 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>';
  128. } else {
  129. 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>';
  130. }
  131. if (api_is_western_name_order(PERSON_NAME_DATA_EXPORT)) {
  132. $data[$id_coach]["firstname"] = $firstname;
  133. $data[$id_coach]["lastname"] = $lastname;
  134. } else {
  135. $data[$id_coach]["lastname"] = $lastname;
  136. $data[$id_coach]["firstname"] = $firstname;
  137. }
  138. $data[$id_coach]["connection_time"] = $s_connection_time;
  139. }
  140. } else {
  141. // No results
  142. echo '<tr><td colspan="5">'.get_lang("NoResult").'</td></tr>';
  143. }
  144. echo '</table>';
  145. if (isset($_POST['export'])){
  146. export_csv($header, $data, 'coaches.csv');
  147. }
  148. echo "<br /><br />";
  149. echo "<form method='post' action='coaches.php'><button type='submit' class='save' name='export' value='".get_lang('exportExcel')."'>".get_lang('exportExcel')."</button><form>";
  150. Display::display_footer();