coaches.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. <?php
  2. /*
  3. * Created on 18 October 2006 by Elixir Interactive http://www.elixir-interactive.com
  4. */
  5. ob_start();
  6. $langFile = array ('registration', 'index','trad4all', 'tracking', 'admin');
  7. $cidReset=true;
  8. require ('../inc/global.inc.php');
  9. $this_section = "session_my_space";
  10. $nameTools= get_lang('Tutors');
  11. api_block_anonymous_users();
  12. $interbreadcrumb[] = array ("url" => "index.php", "name" => get_lang('MySpace'));
  13. Display :: display_header($nameTools);
  14. api_display_tool_title($nameTools);
  15. $tbl_course = Database :: get_main_table(MAIN_COURSE_TABLE);
  16. $tbl_user = Database :: get_main_table(MAIN_USER_TABLE);
  17. $tbl_session = Database :: get_main_table(MAIN_SESSION_TABLE);
  18. $tbl_session_rel_course = Database :: get_main_table(MAIN_SESSION_COURSE_TABLE);
  19. $tbl_session_rel_course_rel_user = Database :: get_main_table(MAIN_SESSION_COURSE_USER_TABLE);
  20. $tbl_session_rel_user = Database :: get_main_table(MAIN_SESSION_USER_TABLE);
  21. $tbl_track_login = Database :: get_statistic_table(STATISTIC_TRACK_E_LOGIN_TABLE);
  22. /*
  23. ===============================================================================
  24. FUNCTION
  25. ===============================================================================
  26. */
  27. function exportCsv($a_header,$a_data)
  28. {
  29. global $archiveDirName;
  30. $fileName = 'coaches.csv';
  31. $archivePath = api_get_path(SYS_PATH).$archiveDirName.'/';
  32. $archiveURL = api_get_path(WEB_CODE_PATH).'course_info/download.php?archive=';
  33. if(!$open = fopen($archivePath.$fileName,'w+'))
  34. {
  35. $message = get_lang('noOpen');
  36. }
  37. else
  38. {
  39. $info = '';
  40. foreach($a_header as $header)
  41. {
  42. $info .= $header.';';
  43. }
  44. $info .= "\r\n";
  45. foreach($a_data as $data)
  46. {
  47. foreach($data as $infos)
  48. {
  49. $info .= $infos.';';
  50. }
  51. $info .= "\r\n";
  52. }
  53. fwrite($open,$info);
  54. fclose($open);
  55. chmod($fileName,0777);
  56. header("Location:".$archiveURL.$fileName);
  57. }
  58. return $message;
  59. }
  60. function calculHours($seconds)
  61. {
  62. //combien d'heures ?
  63. $hours = floor($seconds / 3600);
  64. //combien de minutes ?
  65. $min = floor(($seconds - ($hours * 3600)) / 60);
  66. if ($min < 10)
  67. $min = "0".$min;
  68. //combien de secondes
  69. $sec = $seconds - ($hours * 3600) - ($min * 60);
  70. if ($sec < 10)
  71. $sec = "0".$sec;
  72. //echo $hours."h".$min."m".$sec."s";
  73. return $hours."h".$min."m".$sec."s" ;
  74. }
  75. /**
  76. * MAIN PART
  77. */
  78. /*
  79. * liste nominative avec coordonnées et lien vers les cours et
  80. les stagiaires dont il est le
  81. responsable.
  82. */
  83. if(isset($_GET["id_student"])){
  84. $i_id_student=$_GET["id_student"];
  85. $sqlCoachs = "SELECT DISTINCT src.id_coach " .
  86. "FROM $tbl_session_rel_course as src, $tbl_session_rel_course_rel_user as srcru, $tbl_user as user " .
  87. "WHERE src.id_coach<>'0' AND src.course_code=srcru.course_code AND srcru.id_user='$i_id_student' AND srcru.id_user=user.user_id
  88. ";
  89. }
  90. else{
  91. $sqlCoachs = " SELECT DISTINCT id_coach, user_id, lastname, firstname
  92. FROM $tbl_user, $tbl_session_rel_course
  93. WHERE id_coach=user_id
  94. ORDER BY lastname ASC
  95. ";
  96. }
  97. $resultCoachs = api_sql_query($sqlCoachs);
  98. echo '<table class="data_table">
  99. <tr>
  100. <th>
  101. '.get_lang('Lastname').'
  102. </th>
  103. <th>
  104. '.get_lang('Firstname').'
  105. </th>
  106. <th>
  107. '.get_lang('ConnectionTime').'
  108. </th>
  109. <th>
  110. '.get_lang('AdminCourses').'
  111. </th>
  112. <th>
  113. '.get_lang('Students').'
  114. </th>
  115. </tr>
  116. ';
  117. $a_header[]=get_lang('Lastname');
  118. $a_header[]=get_lang('Firstname');
  119. $a_header[]=get_lang('ConnectionTime');
  120. if(mysql_num_rows($resultCoachs)>0){
  121. while($a_coachs=mysql_fetch_array($resultCoachs)){
  122. $i_id_coach=$a_coachs["id_coach"];
  123. if(isset($_GET["id_student"])){
  124. $sql_infos_coach="SELECT lastname, firstname FROM $tbl_user WHERE user_id='$i_id_coach'";
  125. $resultCoachsInfos = api_sql_query($sql_infos_coach);
  126. $s_lastname=mysql_result($resultCoachsInfos,0,"lastname");
  127. $s_firstname=mysql_result($resultCoachsInfos,0,"firstname");
  128. }
  129. else{
  130. $s_lastname=$a_coachs["lastname"];
  131. $s_firstname=$a_coachs["firstname"];
  132. }
  133. $s_sql_connection_time="SELECT login_date, logout_date FROM $tbl_track_login WHERE login_user_id ='$i_id_coach' AND logout_date <> 'null'";
  134. $q_result_connection_time=api_sql_query($s_sql_connection_time);
  135. $i_nb_seconds=0;
  136. while($a_connections=mysql_fetch_array($q_result_connection_time)){
  137. $s_login_date=$a_connections["login_date"];
  138. $s_logout_date=$a_connections["logout_date"];
  139. $i_timestamp_login_date=strtotime($s_login_date);
  140. $i_timestamp_logout_date=strtotime($s_logout_date);
  141. $i_nb_seconds+=($i_timestamp_logout_date-$i_timestamp_login_date);
  142. }
  143. $s_connection_time=calculHours($i_nb_seconds);
  144. if($s_connection_time=="0h00m00s"){
  145. $s_connection_time="";
  146. }
  147. if($i%2==0){
  148. $s_css_class="row_odd";
  149. if($i%20==0 && $i!=0){
  150. echo '<tr>
  151. <th>
  152. '.get_lang('Lastname').'
  153. </th>
  154. <th>
  155. '.get_lang('Firstname').'
  156. </th>
  157. <th>
  158. '.get_lang('ConnectionTime').'
  159. </th>
  160. <th>
  161. '.get_lang('AdminCourses').'
  162. </th>
  163. <th>
  164. '.get_lang('Students').'
  165. </th>
  166. </tr>';
  167. }
  168. }
  169. else{
  170. $s_css_class="row_even";
  171. }
  172. $i++;
  173. $a_data[$i_id_coach]["lastname"]=$s_lastname;
  174. $a_data[$i_id_coach]["firstname"]=$s_firstname;
  175. $a_data[$i_id_coach]["connection_time"]=$s_connection_time;
  176. echo '<tr class="'.$s_css_class.'"><td>'.$s_lastname.'</td><td>'.$s_firstname.'</td><td>'.$s_connection_time.'</td><td><a href="cours.php?type=coach&user_id='.$i_id_coach.'">-></a></td><td><a href="myStudents.php?type=coach&user_id='.$i_id_coach.'">-></a></td></tr>';
  177. }
  178. }
  179. //No results
  180. else{
  181. echo '<tr><td colspan="5" "align=center">'.get_lang("NoResult").'</td></tr>';
  182. }
  183. echo '</table>';
  184. if(isset($_POST['export'])){
  185. exportCsv($a_header,$a_data);
  186. }
  187. echo "<br /><br />";
  188. echo "<form method='post' action='coaches.php'>
  189. <input type='submit' name='export' value='".get_lang('exportExcel')."'/>
  190. <form>";
  191. /*
  192. ==============================================================================
  193. FOOTER
  194. ==============================================================================
  195. */
  196. Display::display_footer();
  197. ?>