coaches.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. <?php
  2. /*
  3. * Created on 18 October 2006 by Elixir Interactive http://www.elixir-interactive.com
  4. */
  5. ob_start();
  6. // name of the language file that needs to be included
  7. $language_file = array ('registration', 'index', 'tracking', 'admin');
  8. $cidReset=true;
  9. require ('../inc/global.inc.php');
  10. $this_section = "session_my_space";
  11. $nameTools= get_lang('Tutors');
  12. api_block_anonymous_users();
  13. $interbreadcrumb[] = array ("url" => "index.php", "name" => get_lang('MySpace'));
  14. if(isset($_GET["id_student"])){
  15. $interbreadcrumb[] = array ("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_statistic_table(TABLE_STATISTIC_TRACK_E_LOGIN);
  28. /*
  29. ===============================================================================
  30. FUNCTION
  31. ===============================================================================
  32. */
  33. function exportCsv($a_header,$a_data)
  34. {
  35. global $archiveDirName;
  36. $fileName = 'coaches.csv';
  37. $archivePath = api_get_path(SYS_PATH).$archiveDirName.'/';
  38. $archiveURL = api_get_path(WEB_CODE_PATH).'course_info/download.php?archive=';
  39. if(!$open = fopen($archivePath.$fileName,'w+'))
  40. {
  41. $message = get_lang('noOpen');
  42. }
  43. else
  44. {
  45. $info = '';
  46. foreach($a_header as $header)
  47. {
  48. $info .= $header.';';
  49. }
  50. $info .= "\r\n";
  51. foreach($a_data as $data)
  52. {
  53. foreach($data as $infos)
  54. {
  55. $info .= $infos.';';
  56. }
  57. $info .= "\r\n";
  58. }
  59. fwrite($open,$info);
  60. fclose($open);
  61. $perm = api_get_setting('permissions_for_new_files');
  62. $perm = octdec(!empty($perm)?$perm:'0660');
  63. chmod($fileName,$perm);
  64. header("Location:".$archiveURL.$fileName);
  65. }
  66. return $message;
  67. }
  68. function calculHours($seconds)
  69. {
  70. //combien d'heures ?
  71. $hours = floor($seconds / 3600);
  72. //combien de minutes ?
  73. $min = floor(($seconds - ($hours * 3600)) / 60);
  74. if ($min < 10)
  75. $min = "0".$min;
  76. //combien de secondes
  77. $sec = $seconds - ($hours * 3600) - ($min * 60);
  78. if ($sec < 10)
  79. $sec = "0".$sec;
  80. //echo $hours."h".$min."m".$sec."s";
  81. return $hours."h".$min."m".$sec."s" ;
  82. }
  83. function is_coach(){
  84. global $tbl_session_course;
  85. $sql="SELECT course_code FROM $tbl_session_course WHERE id_coach='".$_SESSION["_uid"]."'";
  86. $result=api_sql_query($sql);
  87. if(mysql_num_rows($result)>0){
  88. return true;
  89. }
  90. else{
  91. return false;
  92. }
  93. }
  94. /**
  95. * MAIN PART
  96. */
  97. if(isset($_GET["id_student"])){
  98. $i_id_student=$_GET["id_student"];
  99. $sqlCoachs = "SELECT DISTINCT src.id_coach " .
  100. "FROM $tbl_session_rel_course as src, $tbl_session_rel_course_rel_user as srcru " .
  101. "WHERE src.id_coach<>'0' AND src.course_code=srcru.course_code AND srcru.id_user='$i_id_student' AND srcru.id_session=src.id_session
  102. ";
  103. }
  104. else{
  105. if(api_is_platform_admin()){
  106. $sqlCoachs = " SELECT DISTINCT id_coach, user_id, lastname, firstname
  107. FROM $tbl_user, $tbl_session_rel_course
  108. WHERE id_coach=user_id
  109. ORDER BY lastname ASC
  110. ";
  111. }
  112. else{
  113. $sqlCoachs = " SELECT DISTINCT id_coach, $tbl_user.user_id, lastname, firstname
  114. FROM $tbl_user as user, $tbl_session_rel_course as session_rel_course, $tbl_course_user as course_rel_user
  115. WHERE course_rel_user.course_code=session_rel_course.course_code AND course_rel_user.status='1' AND course_rel_user.user_id='".$_SESSION["_uid"]."'
  116. AND session_rel_course.id_coach=user.user_id
  117. ORDER BY lastname ASC
  118. ";
  119. }
  120. }
  121. $resultCoachs = api_sql_query($sqlCoachs);
  122. echo '<table class="data_table">
  123. <tr>
  124. <th>
  125. '.get_lang('FirstName').'
  126. </th>
  127. <th>
  128. '.get_lang('LastName').'
  129. </th>
  130. <th>
  131. '.get_lang('ConnectionTime').'
  132. </th>
  133. <th>
  134. '.get_lang('AdminCourses').'
  135. </th>
  136. <th>
  137. '.get_lang('Students').'
  138. </th>
  139. </tr>
  140. ';
  141. $a_header[]=get_lang('FirstName');
  142. $a_header[]=get_lang('LastName');
  143. $a_header[]=get_lang('ConnectionTime');
  144. if(mysql_num_rows($resultCoachs)>0){
  145. while($a_coachs=mysql_fetch_array($resultCoachs)){
  146. $i_id_coach=$a_coachs["id_coach"];
  147. if(isset($_GET["id_student"])){
  148. $sql_infos_coach="SELECT lastname, firstname FROM $tbl_user WHERE user_id='$i_id_coach'";
  149. $resultCoachsInfos = api_sql_query($sql_infos_coach);
  150. $s_lastname=mysql_result($resultCoachsInfos,0,"lastname");
  151. $s_firstname=mysql_result($resultCoachsInfos,0,"firstname");
  152. }
  153. else{
  154. $s_lastname=$a_coachs["lastname"];
  155. $s_firstname=$a_coachs["firstname"];
  156. }
  157. $s_sql_connection_time="SELECT login_date, logout_date FROM $tbl_track_login WHERE login_user_id ='$i_id_coach' AND logout_date <> 'null'";
  158. $q_result_connection_time=api_sql_query($s_sql_connection_time);
  159. $i_nb_seconds=0;
  160. while($a_connections=mysql_fetch_array($q_result_connection_time)){
  161. $s_login_date=$a_connections["login_date"];
  162. $s_logout_date=$a_connections["logout_date"];
  163. $i_timestamp_login_date=strtotime($s_login_date);
  164. $i_timestamp_logout_date=strtotime($s_logout_date);
  165. $i_nb_seconds+=($i_timestamp_logout_date-$i_timestamp_login_date);
  166. }
  167. $s_connection_time=calculHours($i_nb_seconds);
  168. if($s_connection_time=="0h00m00s"){
  169. $s_connection_time="";
  170. }
  171. if($i%2==0){
  172. $s_css_class="row_odd";
  173. if($i%20==0 && $i!=0){
  174. echo '<tr>
  175. <th>
  176. '.get_lang('LastName').'
  177. </th>
  178. <th>
  179. '.get_lang('FirstName').'
  180. </th>
  181. <th>
  182. '.get_lang('ConnectionTime').'
  183. </th>
  184. <th>
  185. '.get_lang('AdminCourses').'
  186. </th>
  187. <th>
  188. '.get_lang('Students').'
  189. </th>
  190. </tr>';
  191. }
  192. }
  193. else{
  194. $s_css_class="row_even";
  195. }
  196. $i++;
  197. $a_data[$i_id_coach]["firstname"]=$s_firstname;
  198. $a_data[$i_id_coach]["lastname"]=$s_lastname;
  199. $a_data[$i_id_coach]["connection_time"]=$s_connection_time;
  200. echo '<tr class="'.$s_css_class.'"><td>'.$s_firstname.'</td><td>'.$s_lastname.'</td><td>'.$s_connection_time.'</td><td><a href="course.php?type=coach&user_id='.$i_id_coach.'">-></a></td><td><a href="student.php?type=coach&user_id='.$i_id_coach.'">-></a></td></tr>';
  201. }
  202. }
  203. //No results
  204. else{
  205. echo '<tr><td colspan="5" "align=center">'.get_lang("NoResult").'</td></tr>';
  206. }
  207. echo '</table>';
  208. if(isset($_POST['export'])){
  209. exportCsv($a_header,$a_data);
  210. }
  211. echo "<br /><br />";
  212. echo "<form method='post' action='coaches.php'>
  213. <input type='submit' name='export' value='".get_lang('exportExcel')."'/>
  214. <form>";
  215. /*
  216. ==============================================================================
  217. FOOTER
  218. ==============================================================================
  219. */
  220. Display::display_footer();
  221. ?>