coaches.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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. * MAIN PART
  36. */
  37. if (isset($_POST['export'])) {
  38. $order_clause = api_is_western_name_order(PERSON_NAME_DATA_EXPORT) ? ' ORDER BY firstname, lastname' : ' ORDER BY lastname, firstname';
  39. } else {
  40. $order_clause = api_sort_by_first_name() ? ' ORDER BY firstname, lastname' : ' ORDER BY lastname, firstname';
  41. }
  42. if (isset($_GET["id_student"])) {
  43. $id_student = intval($_GET["id_student"]);
  44. $sql_coachs = "SELECT DISTINCT srcru.id_user as id_coach" .
  45. "FROM $tbl_session_rel_course_rel_user as srcru " .
  46. "WHERE srcru.id_user='$id_student' AND srcru.status=2";
  47. } else {
  48. if (api_is_platform_admin()) {
  49. $sql_coachs = "SELECT DISTINCT srcru.id_user as id_coach, user_id, lastname, firstname
  50. FROM $tbl_user, $tbl_session_rel_course_rel_user srcru
  51. WHERE srcru.id_user=user_id AND srcru.status=2 ".$order_clause;
  52. } else {
  53. $sql_coachs = "SELECT DISTINCT id_user as id_coach, $tbl_user.user_id, lastname, firstname
  54. FROM $tbl_user as user, $tbl_session_rel_course_user as srcu, $tbl_course_user as course_rel_user
  55. WHERE course_rel_user.course_code=srcu.course_code AND course_rel_user.status='1' AND course_rel_user.user_id='".intval($_SESSION["_uid"])."'
  56. AND srcu.id_user=user.user_id AND srcu.status=2 ".$order_clause;
  57. }
  58. }
  59. $result_coachs = Database::query($sql_coachs);
  60. if (api_is_western_name_order()) {
  61. echo '<table class="data_table">
  62. <tr>
  63. <th>'.get_lang('FirstName').'</th>
  64. <th>'.get_lang('LastName').'</th>
  65. <th>'.get_lang('ConnectionTime').'</th>
  66. <th>'.get_lang('AdminCourses').'</th>
  67. <th>'.get_lang('Students').'</th>
  68. </tr>';
  69. } else {
  70. echo '<table class="data_table">
  71. <tr>
  72. <th>'.get_lang('LastName').'</th>
  73. <th>'.get_lang('FirstName').'</th>
  74. <th>'.get_lang('ConnectionTime').'</th>
  75. <th>'.get_lang('AdminCourses').'</th>
  76. <th>'.get_lang('Students').'</th>
  77. </tr>';
  78. }
  79. if (api_is_western_name_order(PERSON_NAME_DATA_EXPORT)) {
  80. $header[] = get_lang('FirstName', '');
  81. $header[] = get_lang('LastName', '');
  82. } else {
  83. $header[] = get_lang('LastName', '');
  84. $header[] = get_lang('FirstName', '');
  85. }
  86. $header[] = get_lang('ConnectionTime', '');
  87. if (Database::num_rows($result_coachs) > 0) {
  88. while ($coachs = Database::fetch_array($result_coachs)) {
  89. $id_coach = $coachs["id_coach"];
  90. if (isset($_GET["id_student"])) {
  91. $sql_infos_coach = "SELECT lastname, firstname FROM $tbl_user WHERE user_id='$id_coach'";
  92. $result_coachs_infos = Database::query($sql_infos_coach);
  93. $lastname = Database::result($result_coachs_infos, 0, "lastname");
  94. $firstname = Database::result($result_coachs_infos, 0, "firstname");
  95. } else {
  96. $lastname = $coachs["lastname"];
  97. $firstname = $coachs["firstname"];
  98. }
  99. $sql_connection_time = "SELECT login_date, logout_date FROM $tbl_track_login WHERE login_user_id ='$id_coach' AND logout_date <> 'null'";
  100. $result_connection_time = Database::query($sql_connection_time);
  101. $nb_seconds = 0;
  102. while ($connections = Database::fetch_array($result_connection_time)) {
  103. $login_date = $connections["login_date"];
  104. $logout_date = $connections["logout_date"];
  105. $timestamp_login_date = strtotime($login_date);
  106. $timestamp_logout_date = strtotime($logout_date);
  107. $nb_seconds += ($timestamp_logout_date - $timestamp_login_date);
  108. }
  109. if ($nb_seconds == 0) {
  110. $s_connection_time = '';
  111. } else {
  112. $s_connection_time = api_time_to_hms($nb_seconds);
  113. }
  114. if ($i % 2 == 0) {
  115. $css_class = "row_odd";
  116. if ($i % 20 == 0 && $i != 0) {
  117. if (api_is_western_name_order()) {
  118. echo '<tr>
  119. <th>'.get_lang('FirstName').'</th>
  120. <th>'.get_lang('LastName').'</th>
  121. <th>'.get_lang('ConnectionTime').'</th>
  122. <th>'.get_lang('AdminCourses').'</th>
  123. <th>'.get_lang('Students').'</th>
  124. </tr>';
  125. } else {
  126. echo '<tr>
  127. <th>'.get_lang('LastName').'</th>
  128. <th>'.get_lang('FirstName').'</th>
  129. <th>'.get_lang('ConnectionTime').'</th>
  130. <th>'.get_lang('AdminCourses').'</th>
  131. <th>'.get_lang('Students').'</th>
  132. </tr>';
  133. }
  134. }
  135. } else {
  136. $css_class = "row_even";
  137. }
  138. $i++;
  139. if (api_is_western_name_order()) {
  140. echo '<tr class="'.$css_class.'">
  141. <td>'.$firstname.'</td><td>'.$lastname.'</td><td>'.$s_connection_time.'</td>
  142. <td>
  143. <a href="course.php?type=coach&user_id='.$id_coach.'">
  144. <img src="'.api_get_path(WEB_IMG_PATH).'2rightarrow.gif" border="0" />
  145. </a>
  146. </td>
  147. <td>
  148. <a href="student.php?type=coach&user_id='.$id_coach.'">
  149. <img src="'.api_get_path(WEB_IMG_PATH).'2rightarrow.gif" border="0" />
  150. </a>
  151. </td>
  152. </tr>';
  153. } else {
  154. echo '<tr class="'.$css_class.'">
  155. <td>'.$lastname.'</td><td>'.$firstname.'</td>
  156. <td>'.$s_connection_time.'</td>
  157. <td>
  158. <a href="course.php?type=coach&user_id='.$id_coach.'">
  159. <img src="'.api_get_path(WEB_IMG_PATH).'2rightarrow.gif" border="0" /></a></td>
  160. <td>
  161. <a href="student.php?type=coach&user_id='.$id_coach.'">
  162. <img src="'.api_get_path(WEB_IMG_PATH).'2rightarrow.gif" border="0" /></a>
  163. </td>
  164. </tr>';
  165. }
  166. if (api_is_western_name_order(PERSON_NAME_DATA_EXPORT)) {
  167. $data[$id_coach]["firstname"] = $firstname;
  168. $data[$id_coach]["lastname"] = $lastname;
  169. } else {
  170. $data[$id_coach]["lastname"] = $lastname;
  171. $data[$id_coach]["firstname"] = $firstname;
  172. }
  173. $data[$id_coach]["connection_time"] = $s_connection_time;
  174. }
  175. } else {
  176. // No results
  177. echo '<tr><td colspan="5">'.get_lang("NoResult").'</td></tr>';
  178. }
  179. echo '</table>';
  180. if (isset($_POST['export'])){
  181. export_csv($header, $data, 'coaches.csv');
  182. }
  183. echo "<br /><br />";
  184. echo "<form method='post' action='coaches.php'>
  185. <button type='submit' class='save' name='export' value='".get_lang('exportExcel')."'>".get_lang('exportExcel')."</button><form>";
  186. Display::display_footer();