student.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483
  1. <?php
  2. /*
  3. * Created on 28 juil. 2006 by Elixir Interactive http://www.elixir-interactive.com
  4. */
  5. ob_start();
  6. $nameTools= 'Students';
  7. $langFile = array ('registration', 'index','trad4all', 'tracking');
  8. $cidReset=true;
  9. require ('../inc/global.inc.php');
  10. $this_section = "session_my_space";
  11. api_block_anonymous_users();
  12. $interbreadcrumb[] = array ("url" => "index.php", "name" => get_lang('MySpace'));
  13. Display :: display_header($nameTools);
  14. $tbl_course = Database :: get_main_table(TABLE_MAIN_COURSE);
  15. $tbl_user = Database :: get_main_table(TABLE_MAIN_USER);
  16. $tbl_course_user = Database :: get_main_table(MAIN_COURSE_USER_TABLE);
  17. $tbl_session = Database :: get_main_table(MAIN_SESSION_TABLE);
  18. $tbl_session_course = Database :: get_main_table(MAIN_SESSION_COURSE_TABLE);
  19. $tbl_session_course_user = Database :: get_main_table(MAIN_SESSION_COURSE_USER_TABLE);
  20. $tbl_session_rel_user = Database :: get_main_table(MAIN_SESSION_USER_TABLE);
  21. /*
  22. ===============================================================================
  23. FUNCTION
  24. ===============================================================================
  25. */
  26. function exportCsv($a_header,$a_data)
  27. {
  28. global $archiveDirName;
  29. $fileName = 'students.csv';
  30. $archivePath = api_get_path(SYS_PATH).$archiveDirName.'/';
  31. $archiveURL = api_get_path(WEB_CODE_PATH).'course_info/download.php?archive=';
  32. if(!$open = fopen($archivePath.$fileName,'w+'))
  33. {
  34. $message = get_lang('noOpen');
  35. }
  36. else
  37. {
  38. $info = '';
  39. foreach($a_header as $header)
  40. {
  41. $info .= $header.';';
  42. }
  43. $info .= "\r\n";
  44. foreach($a_data as $data)
  45. {
  46. foreach($data as $infos)
  47. {
  48. $info .= $infos.';';
  49. }
  50. $info .= "\r\n";
  51. }
  52. fwrite($open,$info);
  53. fclose($open);
  54. chmod($fileName,0777);
  55. header("Location:".$archiveURL.$fileName);
  56. }
  57. return $message;
  58. }
  59. /**
  60. * Returns an array of students of courses (who belong to no sessions) which in the given user is a teacher
  61. * @param int teacher_id The id of the teacher
  62. */
  63. function getStudentsFromCoursesNoSession($i_teacher_id, $a_students){
  64. $tbl_session_course_user = Database :: get_main_table(MAIN_SESSION_COURSE_USER_TABLE);
  65. $tbl_course_user = Database :: get_main_table(MAIN_COURSE_USER_TABLE);
  66. $tbl_user = Database :: get_main_table(TABLE_MAIN_USER);
  67. $tbl_session_course = Database :: get_main_table(MAIN_SESSION_COURSE_TABLE);
  68. $sql_select_courses="SELECT course_rel_user.course_code FROM $tbl_course_user as course_rel_user LEFT OUTER JOIN $tbl_session_course as src ON course_rel_user.course_code=src.course_code WHERE user_id='$i_teacher_id' AND status='1' AND src.course_code IS NULL";
  69. $result_courses=api_sql_query($sql_select_courses);
  70. while($a_courses=mysql_fetch_array($result_courses)){
  71. $s_course_code=$a_courses["course_code"];
  72. $sqlStudents = "SELECT user.user_id,lastname,firstname,email FROM $tbl_course_user as course_rel_user, $tbl_user as user WHERE course_rel_user.user_id=user.user_id AND course_rel_user.status='5' AND course_rel_user.course_code='$s_course_code'";
  73. $result_students=api_sql_query($sqlStudents);
  74. if(mysql_num_rows($result_students)>0){
  75. while($a_students_temp=mysql_fetch_array($result_students)){
  76. $a_current_student=array();
  77. //If the user has already been added to the table
  78. if(!array_key_exists($a_students,$a_students_temp["user_id"])){
  79. $a_current_student[]=$a_students_temp["user_id"];
  80. $a_current_student[]=$a_students_temp["lastname"];
  81. $a_current_student[]=$a_students_temp["firstname"];
  82. $a_current_student[]=$a_students_temp["email"];
  83. $a_students[$a_students_temp["user_id"]]=$a_current_student;
  84. $a_students[$a_students_temp["user_id"]]["teacher"]=true;
  85. }
  86. }
  87. }
  88. }
  89. return $a_students;
  90. }
  91. /**
  92. * Returns an array of students of courses (who belong to at least one session) which in the given user is a teacher
  93. * @param int teacher_id The id of the teacher
  94. */
  95. function getStudentsFromCoursesFromSessions($i_teacher_id, $a_students){
  96. $tbl_session_course_user = Database :: get_main_table(MAIN_SESSION_COURSE_USER_TABLE);
  97. $tbl_course_user = Database :: get_main_table(MAIN_COURSE_USER_TABLE);
  98. $tbl_user = Database :: get_main_table(TABLE_MAIN_USER);
  99. $tbl_session_course = Database :: get_main_table(MAIN_SESSION_COURSE_TABLE);
  100. $sql_select_courses="SELECT course_rel_user.course_code FROM $tbl_course_user as course_rel_user, $tbl_session_course as session_rel_course WHERE user_id='$i_teacher_id' AND status='1' AND session_rel_course.course_code=course_rel_user.course_code";
  101. $result_courses=api_sql_query($sql_select_courses);
  102. while($a_courses=mysql_fetch_array($result_courses)){
  103. $s_course_code=$a_courses["course_code"];
  104. $sqlStudents = "SELECT DISTINCT user.user_id,lastname,firstname,email FROM $tbl_session_course_user as srcru, $tbl_user as user WHERE srcru.id_user=user.user_id AND srcru.course_code='$s_course_code'";
  105. $result_students=api_sql_query($sqlStudents);
  106. if(mysql_num_rows($result_students)>0){
  107. while($a_students_temp=mysql_fetch_array($result_students)){
  108. $a_current_student=array();
  109. //If the user has already been added to the table
  110. if(!array_key_exists($a_students,$a_students_temp["user_id"])){
  111. $a_current_student[]=$a_students_temp["user_id"];
  112. $a_current_student[]=$a_students_temp["lastname"];
  113. $a_current_student[]=$a_students_temp["firstname"];
  114. $a_current_student[]=$a_students_temp["email"];
  115. $a_students[$a_students_temp["user_id"]]=$a_current_student;
  116. $a_students[$a_students_temp["user_id"]]["teacher"]=true;
  117. }
  118. }
  119. }
  120. }
  121. return $a_students;
  122. }
  123. /**
  124. * Returns an array of students of courses which in the given user is a coach
  125. * @param int coach_id The id of the coach
  126. */
  127. function getStudentsFromCoursesFromSessionsCoach($i_coach_id, $a_students){
  128. $tbl_session_course_user = Database :: get_main_table(MAIN_SESSION_COURSE_USER_TABLE);
  129. $tbl_course_user = Database :: get_main_table(MAIN_COURSE_USER_TABLE);
  130. $tbl_user = Database :: get_main_table(TABLE_MAIN_USER);
  131. $tbl_session_course = Database :: get_main_table(MAIN_SESSION_COURSE_TABLE);
  132. $sql_select_courses="SELECT course_code, id_session FROM $tbl_session_course as session_rel_course WHERE session_rel_course.id_coach='$i_coach_id'";
  133. $result_courses=api_sql_query($sql_select_courses);
  134. while($a_courses=mysql_fetch_array($result_courses)){
  135. $s_course_code=$a_courses["course_code"];
  136. $i_id_session=$a_courses["id_session"];
  137. $sqlStudents="SELECT user.user_id,lastname,firstname,email
  138. FROM $tbl_session_course_user as srcru, $tbl_user as user
  139. WHERE srcru.course_code='$s_course_code' AND srcru.id_session='$i_id_session' AND srcru.id_user=user.user_id
  140. ";
  141. $result_students=api_sql_query($sqlStudents);
  142. if(mysql_num_rows($result_students)>0){
  143. while($a_students_temp=mysql_fetch_array($result_students)){
  144. $a_current_student=array();
  145. //If the user has already been added to the table
  146. if(!array_key_exists($a_students,$a_students_temp["user_id"])){
  147. $a_current_student[]=$a_students_temp["user_id"];
  148. $a_current_student[]=$a_students_temp["lastname"];
  149. $a_current_student[]=$a_students_temp["firstname"];
  150. $a_current_student[]=$a_students_temp["email"];
  151. $a_students[$a_students_temp["user_id"]]=$a_current_student;
  152. $a_students[$a_students_temp["user_id"]]["teacher"]=false;
  153. }
  154. }
  155. }
  156. }
  157. return $a_students;
  158. }
  159. function mysort($a , $b){
  160. if($a[1]>$b[1]){
  161. return 1;
  162. }
  163. else if($b[1]>$a[1]){
  164. return -1;
  165. }
  166. else {
  167. return 0;
  168. }
  169. }
  170. /*
  171. ===============================================================================
  172. MAIN CODE
  173. ===============================================================================
  174. */
  175. $a_students=array();
  176. //La personne est admin
  177. if(api_is_platform_admin()){
  178. $sqlStudent = " SELECT user_id,lastname,firstname,email
  179. FROM $tbl_user
  180. WHERE status = '5'
  181. ORDER BY lastname ASC
  182. ";
  183. $resultStudent = api_sql_query($sqlStudent);
  184. while($a_students_temp=mysql_fetch_array($resultStudent)){
  185. $a_current_student=array();
  186. //If the user has already been added to the table
  187. $a_current_student[]=$a_students_temp["user_id"];
  188. $a_current_student[]=$a_students_temp["lastname"];
  189. $a_current_student[]=$a_students_temp["firstname"];
  190. $a_current_student[]=$a_students_temp["email"];
  191. $a_students[$a_students_temp["user_id"]]=$a_current_student;
  192. $a_students[$a_students_temp["user_id"]]["teacher"]=true;
  193. }
  194. }
  195. else{
  196. $a_students=getStudentsFromCoursesNoSession($_user['user_id'], $a_students);
  197. $a_students=getStudentsFromCoursesFromSessions($_user['user_id'], $a_students);
  198. $a_students=getStudentsFromCoursesFromSessionsCoach($_user['user_id'], $a_students);
  199. }
  200. usort($a_students,"mysort");
  201. $a_header[]=get_lang('Lastname');
  202. $a_header[]=get_lang('Firstname');
  203. $a_header[]=get_lang('Email');
  204. $a_data=array();
  205. if(count($a_students)>0)
  206. {
  207. echo '<table class="data_table">
  208. <tr>
  209. <th>
  210. '.get_lang('Lastname').'
  211. </th>
  212. <th>
  213. '.get_lang('Firstname').'
  214. </th>
  215. <th>
  216. '.get_lang('Email').'
  217. </th>
  218. <th>
  219. '.get_lang('Tracking').'
  220. </th>
  221. </tr>
  222. ';
  223. foreach($a_students as $a_current_student)
  224. {
  225. if($i%2==0){
  226. $s_css_class="row_odd";
  227. if($i%20==0 && $i!=0){
  228. /*echo '<tr>
  229. <th>
  230. '.get_lang('Lastname').'
  231. </th>
  232. <th>
  233. '.get_lang('Firstname').'
  234. </th>
  235. <th>
  236. '.get_lang('Email').'
  237. </th>
  238. <th>
  239. '.get_lang('Tutor').'
  240. </th>
  241. <th>
  242. '.get_lang('Courses').'
  243. </th>
  244. <th>
  245. '.get_lang('TakenSessions').'
  246. </th>
  247. </tr>
  248. ';*/
  249. echo '<tr>
  250. <th>
  251. '.get_lang('Lastname').'
  252. </th>
  253. <th>
  254. '.get_lang('Firstname').'
  255. </th>
  256. <th>
  257. '.get_lang('Email').'
  258. </th>
  259. <th>
  260. '.get_lang('Tracking').'
  261. </th>
  262. </tr>
  263. ';
  264. }
  265. }
  266. else{
  267. $s_css_class="row_even";
  268. }
  269. $i++;
  270. echo '<tr class="'.$s_css_class.'">
  271. <td>
  272. ';
  273. echo "<a href='myStudents.php?student=".$a_current_student[0]."#infosStudent'>".$a_current_student[1]."</a>";
  274. echo ' </td>
  275. <td>
  276. <a href="myStudents.php?student='.$a_current_student[0].'#infosStudent">'.$a_current_student[2].'</a>
  277. </td>
  278. <td>
  279. ';
  280. if(!empty($a_current_student[3]))
  281. {
  282. echo '<a href="mailto:'.$a_current_student[3].'">'.$a_current_student[3].'</a>';
  283. }
  284. else
  285. {
  286. //echo get_lang('NoEmail');
  287. }
  288. echo ' </td>';
  289. if($a_current_student["teacher"]==true){
  290. echo '<td align="center"><a href="coaches.php?id_student='.$a_current_student[0].'"><img src="'.api_get_path(WEB_IMG_PATH).'coachs.gif" alt="'.get_lang("StudentTutors").'" title="'.get_lang("StudentTutors").'"></a>&nbsp;<a href="cours.php?type=student&user_id='.$a_current_student[0].'"><img src="'.api_get_path(WEB_IMG_PATH).'course.gif" alt="'.get_lang("StudentCourses").'" title="'.get_lang("StudentCourses").'"></a>&nbsp;<a href="'.$_SERVER['PHP_SELF'].'?student='.$a_current_student[0].'#sessionSuivie"><img src="'.api_get_path(WEB_IMG_PATH).'agenda.gif" alt="'.get_lang("StudentSessions").'" title="'.get_lang("StudentSessions").'"></a>';
  291. }
  292. else{
  293. echo '<td></td>';
  294. }
  295. echo '</tr>';
  296. $a_data[$a_student['user_id']]["lastname"]=$a_student['lastname'];
  297. $a_data[$a_student['user_id']]["firstname"]=$a_student['firstname'];
  298. $a_data[$a_student['user_id']]["email"]=$a_student['email'];
  299. }
  300. echo '</table>';
  301. }
  302. else
  303. {
  304. echo get_lang('NoStudent');
  305. }
  306. if(isset($_POST['export'])){
  307. exportCsv($a_header,$a_data);
  308. }
  309. echo "<br /><br />";
  310. echo "<form method='post' action='student.php'>
  311. <input type='submit' name='export' value='".get_lang('exportExcel')."'/>
  312. <form>";
  313. if(!empty($_GET['student']))
  314. {
  315. $sqlSessionSuivie = " SELECT session.name
  316. FROM $tbl_session as session
  317. INNER JOIN $tbl_session_rel_user as relUser
  318. ON session.id = relUser.id_session
  319. AND relUser.id_user = ".$_GET['student']
  320. ;
  321. $resultSessionSuivie = api_sql_query($sqlSessionSuivie);
  322. echo "<br /><br />";
  323. echo "<a name='sessionSuivie'></a>";
  324. if(mysql_num_rows($resultSessionSuivie)>0)
  325. {
  326. echo "<table class='data_table'>
  327. <tr class='tableName'>
  328. <td colspan='2'>
  329. <strong>".get_lang('TakenSessions')."</strong>
  330. </td>
  331. </tr>
  332. <tr>
  333. <th>
  334. ".get_lang('Session')."
  335. </th>
  336. <th>
  337. ".get_lang('FollowUp')."
  338. </th>
  339. </tr>
  340. ";
  341. while($a_sessionSuivie = mysql_fetch_array($resultSessionSuivie))
  342. {
  343. echo "<tr>
  344. <td>
  345. ".$a_sessionSuivie['name']."
  346. </td>
  347. <td align='center'>
  348. <a href='../../myStudents.php?student=".$_GET['student']."#infosStudent'> -> </a>
  349. </td>
  350. </tr>
  351. ";
  352. }
  353. echo "</table>";
  354. }
  355. else
  356. {
  357. echo "<h4>".get_lang('TakenSessions')."</h4><br />";
  358. echo get_lang('NoSession');
  359. }
  360. }
  361. /*
  362. ==============================================================================
  363. FOOTER
  364. ==============================================================================
  365. */
  366. Display :: display_footer();
  367. ?>