coaches.php 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /*
  4. * Coaches reporting
  5. * @package chamilo.reporting
  6. */
  7. ob_start();
  8. $cidReset = true;
  9. require_once __DIR__.'/../inc/global.inc.php';
  10. $this_section = SECTION_TRACKING;
  11. $nameTools = get_lang('Tutors');
  12. api_block_anonymous_users();
  13. $interbreadcrumb[] = ["url" => "index.php", "name" => get_lang('MySpace')];
  14. if (isset($_GET["id_student"])) {
  15. $interbreadcrumb[] = ["url" => "student.php", "name" => get_lang('Students')];
  16. }
  17. Display :: display_header($nameTools);
  18. api_display_tool_title($nameTools);
  19. // Database Table Definitions
  20. $tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
  21. $tbl_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER);
  22. $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
  23. $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
  24. $tbl_session_rel_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
  25. $tbl_session_rel_course_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  26. $tbl_session_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_USER);
  27. $tbl_track_login = Database::get_main_table(TABLE_STATISTIC_TRACK_E_LOGIN);
  28. /**
  29. * MAIN PART.
  30. */
  31. if (isset($_POST['export'])) {
  32. $order_clause = api_is_western_name_order(PERSON_NAME_DATA_EXPORT) ? ' ORDER BY firstname, lastname' : ' ORDER BY lastname, firstname';
  33. } else {
  34. $order_clause = api_sort_by_first_name() ? ' ORDER BY firstname, lastname' : ' ORDER BY lastname, firstname';
  35. }
  36. if (isset($_GET["id_student"])) {
  37. $id_student = intval($_GET["id_student"]);
  38. $sql_coachs = "SELECT DISTINCT srcru.user_id as id_coach
  39. FROM $tbl_session_rel_course_rel_user as srcru
  40. WHERE srcru.user_id='$id_student' AND srcru.status=2";
  41. } else {
  42. if (api_is_platform_admin()) {
  43. $sql_coachs = "SELECT DISTINCT
  44. srcru.user_id as id_coach, user_id, lastname, firstname
  45. FROM $tbl_user, $tbl_session_rel_course_rel_user srcru
  46. WHERE
  47. srcru.user_id=user_id AND
  48. srcru.status=2 ".$order_clause;
  49. } else {
  50. $sql_coachs = "SELECT DISTINCT user_id as id_coach, user.user_id, lastname, firstname
  51. FROM
  52. $tbl_user as user,
  53. $tbl_session_rel_course_user as srcu,
  54. $tbl_course_user as course_rel_user,
  55. $tbl_course as c
  56. WHERE
  57. c.id = course_rel_user.c_id AND
  58. c.id = srcu.c_id AND
  59. course_rel_user.status='1' AND
  60. course_rel_user.user_id='".api_get_user_id()."' AND
  61. srcu.user_id = user.user_id AND
  62. srcu.status = 2
  63. ".$order_clause;
  64. }
  65. }
  66. $result_coachs = Database::query($sql_coachs);
  67. if (api_is_western_name_order()) {
  68. echo '<table class="data_table">
  69. <tr>
  70. <th>'.get_lang('FirstName').'</th>
  71. <th>'.get_lang('LastName').'</th>
  72. <th>'.get_lang('ConnectionTime').'</th>
  73. <th>'.get_lang('AdminCourses').'</th>
  74. <th>'.get_lang('Students').'</th>
  75. </tr>';
  76. } else {
  77. echo '<table class="data_table">
  78. <tr>
  79. <th>'.get_lang('LastName').'</th>
  80. <th>'.get_lang('FirstName').'</th>
  81. <th>'.get_lang('ConnectionTime').'</th>
  82. <th>'.get_lang('AdminCourses').'</th>
  83. <th>'.get_lang('Students').'</th>
  84. </tr>';
  85. }
  86. if (api_is_western_name_order(PERSON_NAME_DATA_EXPORT)) {
  87. $header[] = get_lang('FirstName', '');
  88. $header[] = get_lang('LastName', '');
  89. } else {
  90. $header[] = get_lang('LastName', '');
  91. $header[] = get_lang('FirstName', '');
  92. }
  93. $header[] = get_lang('ConnectionTime', '');
  94. if (Database::num_rows($result_coachs) > 0) {
  95. while ($coachs = Database::fetch_array($result_coachs)) {
  96. $id_coach = $coachs["id_coach"];
  97. if (isset($_GET["id_student"])) {
  98. $sql_infos_coach = "SELECT lastname, firstname
  99. FROM $tbl_user
  100. WHERE user_id='$id_coach'";
  101. $result_coachs_infos = Database::query($sql_infos_coach);
  102. $lastname = Database::result($result_coachs_infos, 0, "lastname");
  103. $firstname = Database::result($result_coachs_infos, 0, "firstname");
  104. } else {
  105. $lastname = $coachs["lastname"];
  106. $firstname = $coachs["firstname"];
  107. }
  108. $sql_connection_time = "SELECT login_date, logout_date
  109. FROM $tbl_track_login
  110. WHERE login_user_id ='$id_coach' AND logout_date <> 'null'";
  111. $result_connection_time = Database::query($sql_connection_time);
  112. $nb_seconds = 0;
  113. while ($connections = Database::fetch_array($result_connection_time)) {
  114. $login_date = $connections["login_date"];
  115. $logout_date = $connections["logout_date"];
  116. $timestamp_login_date = strtotime($login_date);
  117. $timestamp_logout_date = strtotime($logout_date);
  118. $nb_seconds += ($timestamp_logout_date - $timestamp_login_date);
  119. }
  120. if ($nb_seconds == 0) {
  121. $s_connection_time = '';
  122. } else {
  123. $s_connection_time = api_time_to_hms($nb_seconds);
  124. }
  125. if ($i % 2 == 0) {
  126. $css_class = "row_odd";
  127. if ($i % 20 == 0 && $i != 0) {
  128. if (api_is_western_name_order()) {
  129. echo '<tr>
  130. <th>'.get_lang('FirstName').'</th>
  131. <th>'.get_lang('LastName').'</th>
  132. <th>'.get_lang('ConnectionTime').'</th>
  133. <th>'.get_lang('AdminCourses').'</th>
  134. <th>'.get_lang('Students').'</th>
  135. </tr>';
  136. } else {
  137. echo '<tr>
  138. <th>'.get_lang('LastName').'</th>
  139. <th>'.get_lang('FirstName').'</th>
  140. <th>'.get_lang('ConnectionTime').'</th>
  141. <th>'.get_lang('AdminCourses').'</th>
  142. <th>'.get_lang('Students').'</th>
  143. </tr>';
  144. }
  145. }
  146. } else {
  147. $css_class = "row_even";
  148. }
  149. $i++;
  150. if (api_is_western_name_order()) {
  151. echo '<tr class="'.$css_class.'">
  152. <td>'.$firstname.'</td><td>'.$lastname.'</td><td>'.$s_connection_time.'</td>
  153. <td>
  154. <a href="course.php?type=coach&user_id='.$id_coach.'">
  155. '.Display::return_icon('2rightarrow.png', get_lang('Details')).'
  156. </a>
  157. </td>
  158. <td>
  159. <a href="student.php?type=coach&user_id='.$id_coach.'">
  160. '.Display::return_icon('2rightarrow.png', get_lang('Details')).'
  161. </a>
  162. </td>
  163. </tr>';
  164. } else {
  165. echo '<tr class="'.$css_class.'">
  166. <td>'.$lastname.'</td><td>'.$firstname.'</td>
  167. <td>'.$s_connection_time.'</td>
  168. <td>
  169. <a href="course.php?type=coach&user_id='.$id_coach.'">
  170. '.Display::return_icon('2rightarrow.png', get_lang('Details')).'</a></td>
  171. <td>
  172. <a href="student.php?type=coach&user_id='.$id_coach.'">
  173. '.Display::return_icon('2rightarrow.png', get_lang('Details')).'</a>
  174. </td>
  175. </tr>';
  176. }
  177. if (api_is_western_name_order(PERSON_NAME_DATA_EXPORT)) {
  178. $data[$id_coach]["firstname"] = $firstname;
  179. $data[$id_coach]["lastname"] = $lastname;
  180. } else {
  181. $data[$id_coach]["lastname"] = $lastname;
  182. $data[$id_coach]["firstname"] = $firstname;
  183. }
  184. $data[$id_coach]["connection_time"] = $s_connection_time;
  185. }
  186. } else {
  187. // No results
  188. echo '<tr><td colspan="5">'.get_lang("NoResult").'</td></tr>';
  189. }
  190. echo '</table>';
  191. if (isset($_POST['export'])) {
  192. export_csv($header, $data, 'coaches.csv');
  193. }
  194. echo "<br /><br />";
  195. echo "
  196. <br /><br />
  197. <form method='post' action='coaches.php'>
  198. <button type='submit' class='save' name='export' value='".get_lang('ExportExcel')."'>
  199. ".get_lang('ExportExcel')."
  200. </button>
  201. <form>
  202. ";
  203. Display::display_footer();