coaches.php 7.5 KB

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