cours.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. <?php
  2. /*
  3. * Created on 28 juil. 2006 by Elixir Interactive http://www.elixir-interactive.com
  4. */
  5. $nameTools= 'Cours';
  6. $langFile = array ('registration', 'index','trad4all', 'tracking');
  7. $cidReset=true;
  8. require ('../inc/global.inc.php');
  9. $this_section = "session_my_space";
  10. api_block_anonymous_users();
  11. $interbreadcrumb[] = array ("url" => "index.php", "name" => get_lang('MySpace'));
  12. Display :: display_header($nameTools);
  13. $tbl_course = Database :: get_main_table(MAIN_COURSE_TABLE);
  14. $tbl_user_course = Database :: get_main_table(MAIN_COURSE_USER_TABLE);
  15. $tbl_user = Database :: get_main_table(MAIN_USER_TABLE);
  16. $tbl_session_course = Database :: get_main_table(MAIN_SESSION_COURSE_TABLE);
  17. $tbl_session = Database :: get_main_table(MAIN_SESSION_TABLE);
  18. /*
  19. ===============================================================================
  20. FUNCTION
  21. ===============================================================================
  22. */
  23. function exportCsv($a_header,$a_data)
  24. {
  25. global $archiveDirName;
  26. $fileName = 'courses.csv';
  27. $archivePath = api_get_path(SYS_PATH).$archiveDirName.'/';
  28. $archiveURL = api_get_path(WEB_CODE_PATH).'course_info/download.php?archive=';
  29. if(!$open = fopen($archivePath.$fileName,'w+'))
  30. {
  31. $message = get_lang('noOpen');
  32. }
  33. else
  34. {
  35. $info = '';
  36. foreach($a_header as $header)
  37. {
  38. $info .= $header.';';
  39. }
  40. $info .= "\r\n";
  41. foreach($a_data as $data)
  42. {
  43. foreach($data as $infos)
  44. {
  45. $info .= $infos.';';
  46. }
  47. $info .= "\r\n";
  48. }
  49. fwrite($open,$info);
  50. fclose($open);
  51. chmod($fileName,0777);
  52. header("Location:".$archiveURL.$fileName);
  53. }
  54. return $message;
  55. }
  56. /*
  57. ===============================================================================
  58. MAIN CODE
  59. ===============================================================================
  60. */
  61. if(isset($_GET["user_id"]) && $_GET["user_id"]!=""){
  62. $i_user_id=$_GET["user_id"];
  63. //We want to display the course where this user is a coach
  64. if(isset($_GET["type"]) && $_GET["type"]=="coach"){
  65. $sqlCourse="SELECT title,code " .
  66. "FROM $tbl_course as course, $tbl_session_course as src " .
  67. "WHERE course.code=src.course_code AND id_coach='$i_user_id'";
  68. }
  69. //It's a teacher
  70. else{
  71. $sqlCourse = " SELECT title,code
  72. FROM $tbl_course as course, $tbl_user_course as cru
  73. WHERE course.code=cru.course_code AND cru.user_id='$i_user_id' AND cru.status='1'
  74. ORDER BY title ASC
  75. ";
  76. }
  77. }
  78. else{
  79. $sqlCourse = " SELECT title,code
  80. FROM $tbl_course as course
  81. ORDER BY title ASC
  82. ";
  83. }
  84. $resultCourse = api_sql_query($sqlCourse);
  85. $a_header[]=get_lang('Title');
  86. $a_header[]=get_lang('Tutor');
  87. $a_header[]=get_lang('Teachers');
  88. if(mysql_num_rows($resultCourse)>0)
  89. {
  90. echo '<table class="data_table">
  91. <tr>
  92. <th>
  93. '.get_lang('Title').'
  94. </th>
  95. <th>
  96. '.get_lang('Tutor').'
  97. </th>
  98. <th>
  99. '.get_lang('Teachers').'
  100. </th>
  101. </tr>
  102. ';
  103. while($a_course= mysql_fetch_array($resultCourse))
  104. {
  105. $sqlCoach = "SELECT CONCAT(user.firstname,' ',user.lastname) as tutor_name
  106. FROM $tbl_user
  107. INNER JOIN $tbl_session_course as sessionCourse
  108. ON sessionCourse.course_code = '".$a_course['code']."'
  109. AND sessionCourse.id_coach = user.user_id
  110. ";
  111. $resultCoach = api_sql_query($sqlCoach);
  112. $a_coach = mysql_fetch_array($resultCoach);
  113. /*$sqlFormateur = " SELECT CONCAT(user.firstname,' ',user.lastname) as formateur_name
  114. FROM $tbl_user
  115. INNER JOIN $tbl_session_course as sessionCourse
  116. ON sessionCourse.course_code = '".$a_course['code']."'
  117. INNER JOIN $tbl_session AS session
  118. ON session.id = sessionCourse.id_session
  119. AND session.id_coach = user.user_id
  120. ";*/
  121. $sqlFormateur = " SELECT CONCAT(user.firstname,' ',user.lastname) as formateur_name
  122. FROM $tbl_user as user, $tbl_user_course as cru
  123. WHERE user.user_id=cru.user_id AND cru.status='1' AND cru.course_code='".$a_course['code']."'
  124. ";
  125. $resultFormateur = api_sql_query($sqlFormateur);
  126. $a_formateur = mysql_fetch_array($resultFormateur);
  127. if($i%2==0){
  128. $s_css_class="row_odd";
  129. if($i%20==0 && $i!=0){
  130. echo '<tr>
  131. <th>
  132. '.get_lang('Title').'
  133. </th>
  134. <th>
  135. '.get_lang('Tutor').'
  136. </th>
  137. <th>
  138. '.get_lang('Teachers').'
  139. </th>
  140. </tr>';
  141. }
  142. }
  143. else{
  144. $s_css_class="row_even";
  145. }
  146. $i++;
  147. echo '<tr class="'.$s_css_class.'">
  148. <td>
  149. '.$a_course['title'].'</td>
  150. <td>
  151. '.$a_coach['tutor_name'].'
  152. </td>
  153. <td>
  154. '.$a_formateur['formateur_name'].'
  155. </td>
  156. </tr>
  157. ';
  158. $a_data[$index]["title"]=$a_course['title'];
  159. $a_data[$index]["tutor_name"]=$a_coach['tutor_name'];
  160. $a_data[$index]["formateur_name"]=$a_formateur['formateur_name'];
  161. $index++;
  162. }
  163. echo '</table>';
  164. }
  165. else
  166. {
  167. echo get_lang('NoCourse');
  168. }
  169. if(isset($_POST['export'])){
  170. exportCsv($a_header,$a_data);
  171. }
  172. echo "<br /><br />";
  173. echo "<form method='post' action='cours.php'>
  174. <input type='submit' name='export' value='".get_lang('exportExcel')."'/>
  175. <form>";
  176. /*
  177. ==============================================================================
  178. FOOTER
  179. ==============================================================================
  180. */
  181. Display :: display_footer();
  182. ?>