student.php 16 KB

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