coaches.php 7.4 KB

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