coaches.php 7.2 KB

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