123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542 |
- <?php
- /*
- * Created on 28 juil. 2006 by Elixir Interactive http://www.elixir-interactive.com
- */
-
- ob_start();
- // name of the language file that needs to be included
- $language_file = array ('registration', 'index', 'tracking');
- $cidReset=true;
- require ('../inc/global.inc.php');
-
- $nameTools= get_lang("Students");
-
- $this_section = "session_my_space";
-
- api_block_anonymous_users();
-
- $interbreadcrumb[] = array ("url" => "index.php", "name" => get_lang('MySpace'));
-
- if(isset($_GET["user_id"]) && $_GET["user_id"]!="" && !isset($_GET["type"])){
- $interbreadcrumb[] = array ("url" => "teachers.php", "name" => get_lang('Teachers'));
- }
-
- if(isset($_GET["user_id"]) && $_GET["user_id"]!="" && isset($_GET["type"]) && $_GET["type"]=="coach"){
- $interbreadcrumb[] = array ("url" => "coaches.php", "name" => get_lang('Tutors'));
- }
-
- Display :: display_header($nameTools);
- // Database Table Definitions
- $tbl_course = Database :: get_main_table(TABLE_MAIN_COURSE);
- $tbl_user = Database :: get_main_table(TABLE_MAIN_USER);
- $tbl_course_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
- $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
- $tbl_session_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
- $tbl_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
- $tbl_session_rel_user = Database :: get_main_table(TABLE_MAIN_SESSION_USER);
- /*
- ===============================================================================
- FUNCTION
- ===============================================================================
- */
-
- function exportCsv($a_header,$a_data)
- {
- global $archiveDirName;
- $fileName = 'students.csv';
- $archivePath = api_get_path(SYS_PATH).$archiveDirName.'/';
- $archiveURL = api_get_path(WEB_CODE_PATH).'course_info/download.php?archive=';
-
- if(!$open = fopen($archivePath.$fileName,'w+'))
- {
- $message = get_lang('noOpen');
- }
- else
- {
- $info = '';
-
- foreach($a_header as $header)
- {
- $info .= $header.';';
- }
- $info .= "\r\n";
-
-
- foreach($a_data as $data)
- {
- foreach($data as $infos)
- {
- $info .= $infos.';';
- }
- $info .= "\r\n";
- }
-
- fwrite($open,$info);
- fclose($open);
- chmod($fileName,0777);
-
- header("Location:".$archiveURL.$fileName);
- }
-
- return $message;
- }
-
- /**
- * Returns an array of students of courses (who belong to no sessions) which in the given user is a teacher
- * @param int teacher_id The id of the teacher
- */
- function getStudentsFromCoursesNoSession($i_teacher_id, $a_students){
-
- $tbl_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
- $tbl_course_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
- $tbl_user = Database :: get_main_table(TABLE_MAIN_USER);
- $tbl_session_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
-
-
- //$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";
- $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'";
- $result_courses=api_sql_query($sql_select_courses);
-
- while($a_courses=mysql_fetch_array($result_courses)){
-
- $s_course_code=$a_courses["course_code"];
- $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'";
- $result_students=api_sql_query($sqlStudents);
- if(mysql_num_rows($result_students)>0){
-
- while($a_students_temp=mysql_fetch_array($result_students)){
-
- $a_current_student=array();
-
- //If the user has already been added to the table
- if(!array_key_exists($a_students,$a_students_temp["user_id"])){
-
- $a_current_student[]=$a_students_temp["user_id"];
- $a_current_student[]=$a_students_temp["lastname"];
- $a_current_student[]=$a_students_temp["firstname"];
- $a_current_student[]=$a_students_temp["email"];
-
- $a_students[$a_students_temp["user_id"]]=$a_current_student;
- $a_students[$a_students_temp["user_id"]]["teacher"]=true;
-
- }
-
- }
-
- }
-
- }
-
- return $a_students;
-
- }
-
-
- /**
- * Returns an array of students of courses (who belong to at least one session) which in the given user is a teacher
- * @param int teacher_id The id of the teacher
- */
- function getStudentsFromCoursesFromSessions($i_teacher_id, $a_students){
-
- $tbl_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
- $tbl_course_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
- $tbl_user = Database :: get_main_table(TABLE_MAIN_USER);
- $tbl_session_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
-
- $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";
- $result_courses=api_sql_query($sql_select_courses);
- while($a_courses=mysql_fetch_array($result_courses)){
-
- $s_course_code=$a_courses["course_code"];
- $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'";
- $result_students=api_sql_query($sqlStudents);
- if(mysql_num_rows($result_students)>0){
-
- while($a_students_temp=mysql_fetch_array($result_students)){
-
- $a_current_student=array();
-
- //If the user has already been added to the table
- if(!array_key_exists($a_students,$a_students_temp["user_id"])){
-
- $a_current_student[]=$a_students_temp["user_id"];
- $a_current_student[]=$a_students_temp["lastname"];
- $a_current_student[]=$a_students_temp["firstname"];
- $a_current_student[]=$a_students_temp["email"];
-
- $a_students[$a_students_temp["user_id"]]=$a_current_student;
- $a_students[$a_students_temp["user_id"]]["teacher"]=true;
-
- }
-
- }
-
- }
-
- }
-
- return $a_students;
-
- }
-
-
- /**
- * Returns an array of students of courses which in the given user is a coach
- * @param int coach_id The id of the coach
- */
- function getStudentsFromCoursesFromSessionsCoach($i_coach_id, $a_students){
-
- $tbl_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
- $tbl_course_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
- $tbl_user = Database :: get_main_table(TABLE_MAIN_USER);
- $tbl_session_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
-
- $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'";
- $result_courses=api_sql_query($sql_select_courses);
- while($a_courses=mysql_fetch_array($result_courses)){
-
- $s_course_code=$a_courses["course_code"];
- $i_id_session=$a_courses["id_session"];
-
- $sqlStudents="SELECT user.user_id,lastname,firstname,email
- FROM $tbl_session_course_user as srcru, $tbl_user as user
- WHERE srcru.course_code='$s_course_code' AND srcru.id_session='$i_id_session' AND srcru.id_user=user.user_id
- ";
- $result_students=api_sql_query($sqlStudents);
- if(mysql_num_rows($result_students)>0){
-
- while($a_students_temp=mysql_fetch_array($result_students)){
-
- $a_current_student=array();
-
- //If the user has already been added to the table
- if(!array_key_exists($a_students,$a_students_temp["user_id"])){
-
- $a_current_student[]=$a_students_temp["user_id"];
- $a_current_student[]=$a_students_temp["lastname"];
- $a_current_student[]=$a_students_temp["firstname"];
- $a_current_student[]=$a_students_temp["email"];
-
- $a_students[$a_students_temp["user_id"]]=$a_current_student;
- $a_students[$a_students_temp["user_id"]]["teacher"]=false;
-
- }
-
- }
-
- }
-
- }
-
- return $a_students;
-
- }
-
-
- function mysort($a , $b){
- if($a[1]>$b[1]){
- return 1;
- }
- else if($b[1]>$a[1]){
- return -1;
- }
- else {
- return 0;
- }
-
- }
-
- /*
- ===============================================================================
- MAIN CODE
- ===============================================================================
- */
- $a_students=array();
-
- //La personne est admin
- if(api_is_platform_admin() && !isset($_GET["user_id"])){
-
- $sqlStudent = " SELECT user_id,lastname,firstname,email
- FROM $tbl_user
- WHERE status = '5'
- ORDER BY lastname ASC
- ";
- $resultStudent = api_sql_query($sqlStudent);
-
- while($a_students_temp=mysql_fetch_array($resultStudent)){
-
- $a_current_student=array();
-
- //If the user has already been added to the table
-
- $a_current_student[]=$a_students_temp["user_id"];
- $a_current_student[]=$a_students_temp["lastname"];
- $a_current_student[]=$a_students_temp["firstname"];
- $a_current_student[]=$a_students_temp["email"];
-
- $a_students[$a_students_temp["user_id"]]=$a_current_student;
- $a_students[$a_students_temp["user_id"]]["teacher"]=true;
-
- }
- }
-
- elseif(api_is_platform_admin() && isset($_GET["user_id"])){
-
- $sqlStudent = " SELECT user_id,lastname,firstname,email
- FROM $tbl_user
- WHERE user_id='".$_GET["user_id"]."'
- ORDER BY lastname ASC
- ";
- $resultStudent = api_sql_query($sqlStudent);
-
- $a_current_student[]=mysql_result($resultStudent,0,"user_id");
- $a_current_student[]=mysql_result($resultStudent,0,"lastname");
- $a_current_student[]=mysql_result($resultStudent,0,"firstname");
- $a_current_student[]=mysql_result($resultStudent,0,"email");
-
- $a_students[$_GET["user_id"]]=$a_current_student;
- $a_students[$_GET["user_id"]]["teacher"]=true;
- }
-
- else{
- if(isset($_GET["user_id"])){
-
- //It's a teacher
- if(!isset($_GET["type"])){
-
- $a_students=getStudentsFromCoursesNoSession($_GET["user_id"], $a_students);
-
- $a_students=getStudentsFromCoursesFromSessions($_GET["user_id"], $a_students);
-
- }
-
- //It's a coach
- else{
- $a_students=getStudentsFromCoursesFromSessionsCoach($_user['user_id'], $a_students);
- }
-
- }
-
- else{
-
- $a_students=getStudentsFromCoursesNoSession($_user['user_id'], $a_students);
-
- $a_students=getStudentsFromCoursesFromSessions($_user['user_id'], $a_students);
-
- $a_students=getStudentsFromCoursesFromSessionsCoach($_user['user_id'], $a_students);
-
- }
-
- }
-
- usort($a_students,"mysort");
-
- $a_header[]=get_lang('LastName');
- $a_header[]=get_lang('FirstName');
- $a_header[]=get_lang('Email');
-
- $a_data=array();
- if(count($a_students)>0)
- {
- echo '<table class="data_table">
- <tr>
- <th>
- '.get_lang('LastName').'
- </th>
- <th>
- '.get_lang('FirstName').'
- </th>
- <th>
- '.get_lang('Email').'
- </th>
- <th>
- '.get_lang('Tracking').'
- </th>
- </tr>
- ';
-
- foreach($a_students as $a_current_student)
- {
-
- if($i%2==0){
- $s_css_class="row_odd";
-
- if($i%20==0 && $i!=0){
- /*echo '<tr>
- <th>
- '.get_lang('Lastname').'
- </th>
- <th>
- '.get_lang('Firstname').'
- </th>
- <th>
- '.get_lang('Email').'
- </th>
- <th>
- '.get_lang('Tutor').'
- </th>
- <th>
- '.get_lang('Courses').'
- </th>
- <th>
- '.get_lang('TakenSessions').'
- </th>
- </tr>
- ';*/
- echo '<tr>
- <th>
- '.get_lang('LastName').'
- </th>
- <th>
- '.get_lang('FirstName').'
- </th>
- <th>
- '.get_lang('Email').'
- </th>
- <th>
- '.get_lang('Tracking').'
- </th>
- </tr>
- ';
- }
- }
- else{
- $s_css_class="row_even";
- }
-
- $i++;
-
- echo '<tr class="'.$s_css_class.'">
- <td>
- ';
- echo "<a href='myStudents.php?student=".$a_current_student[0]."#infosStudent'>".$a_current_student[1]."</a>";
- echo ' </td>
- <td>
- <a href="myStudents.php?student='.$a_current_student[0].'#infosStudent">'.$a_current_student[2].'</a>
- </td>
- <td>
- ';
- if(!empty($a_current_student[3]))
- {
- echo '<a href="mailto:'.$a_current_student[3].'">'.$a_current_student[3].'</a>';
- }
- else
- {
- //echo get_lang('NoEmail');
- }
- echo ' </td>';
-
-
- if($a_current_student["teacher"]==true){
- echo '<td align="center">';
- if(api_get_setting('use_session_mode')=='true'){
- 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> <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> ';
- }
- 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>';
- }
- else{
- echo '<td></td>';
- }
- echo '</tr>';
-
- $a_data[$a_student['user_id']]["lastname"]=$a_student['lastname'];
- $a_data[$a_student['user_id']]["firstname"]=$a_student['firstname'];
- $a_data[$a_student['user_id']]["email"]=$a_student['email'];
- }
- echo '</table>';
- }
- else
- {
- echo get_lang('NoStudent');
- }
-
- if(isset($_POST['export'])){
-
- exportCsv($a_header,$a_data);
-
- }
-
- echo "<br /><br />";
- echo "<form method='post' action='student.php'>
- <input type='submit' name='export' value='".get_lang('exportExcel')."'/>
- <form>";
- if(!empty($_GET['student']))
- {
- $sqlSessionSuivie = " SELECT session.name
- FROM $tbl_session as session
- INNER JOIN $tbl_session_rel_user as relUser
- ON session.id = relUser.id_session
- AND relUser.id_user = ".$_GET['student']
- ;
-
- $resultSessionSuivie = api_sql_query($sqlSessionSuivie);
- echo "<br /><br />";
- echo "<a name='sessionSuivie'></a>";
-
- if(mysql_num_rows($resultSessionSuivie)>0)
- {
- echo "<table class='data_table'>
- <tr class='tableName'>
- <td colspan='2'>
- <strong>".get_lang('TakenSessions')."</strong>
- </td>
- </tr>
- <tr>
- <th>
- ".get_lang('Session')."
- </th>
- <th>
- ".get_lang('FollowUp')."
- </th>
- </tr>
- ";
- while($a_sessionSuivie = mysql_fetch_array($resultSessionSuivie))
- {
- echo "<tr>
- <td>
- ".$a_sessionSuivie['name']."
- </td>
- <td align='center'>
- <a href='../../myStudents.php?student=".$_GET['student']."#infosStudent'> -> </a>
- </td>
- </tr>
- ";
- }
- echo "</table>";
- }
- else
- {
- echo "<h4>".get_lang('TakenSessions')."</h4><br />";
- echo get_lang('NoSession');
- }
- }
- /*
- ==============================================================================
- FOOTER
- ==============================================================================
- */
-
- Display :: display_footer();
- ?>
|