Browse Source

User list to PDF, now it shows the current teacher BT#2741

Julio Montoya 12 years ago
parent
commit
e14297ff8a
2 changed files with 45 additions and 25 deletions
  1. 1 4
      main/inc/lib/course.lib.php
  2. 44 21
      main/user/user.php

+ 1 - 4
main/inc/lib/course.lib.php

@@ -1283,9 +1283,7 @@ class CourseManager {
         }
 
         // We get the session coach.
-        $rs = Database::query('SELECT id_coach FROM '.Database::get_main_table(TABLE_MAIN_SESSION).
-                ' WHERE id="'.$session_id.'"');
-        $user_info = array();
+        $rs = Database::query('SELECT id_coach FROM '.Database::get_main_table(TABLE_MAIN_SESSION).' WHERE id="'.$session_id.'"');        
         $session_id_coach = Database::result($rs, 0, 'id_coach');
         $user_info = Database::get_user_info_from_id($session_id_coach);
         $user_info['status'] = $user['status'];
@@ -1293,7 +1291,6 @@ class CourseManager {
         $user_info['tutor_id'] = $user['tutor_id'];
         $user_info['email'] = $user['email'];
         $users[$session_id_coach] = $user_info;
-
         return $users;
     }
 

+ 44 - 21
main/user/user.php

@@ -130,7 +130,7 @@ if (api_is_allowed_to_edit(null, true)) {
 								
 				// users subscribed to the course through a session
 				
-                if (api_get_session_id()) {						
+                if (api_get_session_id()) {			
                     $table_session_course_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
                     $sql_query = "SELECT DISTINCT user.user_id, ".($is_western_name_order ? "user.firstname, user.lastname" : "user.lastname, user.firstname").",  $select_email_condition phone, user.official_code, active $legal
                                   FROM $table_session_course_user as session_course_user, $table_users as user ";
@@ -242,27 +242,50 @@ if (api_is_allowed_to_edit(null, true)) {
 						Export::export_table_xls($a_users);
 						exit;
 					case 'pdf' :
-					   $header = get_lang('StudentList');
-					   $description = '<table class="data_table_no_border">';  
-                       if (api_get_session_id()) {                     
-					       $description .= '<tr><td>'.get_lang('Session').': </td><td class="highlight">'.api_get_session_name(api_get_session_id()).'</td>';
-                       }
-					   $description .= '<tr><td>'.get_lang('Course').': </td><td class="highlight">'.$course_info['name'].'</td>';
-                       
-                       $teachers = CourseManager::get_teacher_list_from_course_code_to_string($course_info['code']);
-                       $coaches  = CourseManager::get_coach_list_from_course_code_to_string($course_info['code'], $session_id);            
+                        $header = get_lang('StudentList');
+                        $description = '<table class="data_table_no_border">';  
+                        if (api_get_session_id()) {                     
+                            $description .= '<tr><td>'.get_lang('Session').': </td><td class="highlight">'.api_get_session_name(api_get_session_id()).'</td>';
+                        }
+                        $description .= '<tr><td>'.get_lang('Course').': </td><td class="highlight">'.$course_info['name'].'</td>';
                        
-                       if (!empty($teachers)) {
-					       $description .= '<tr><td>'.get_lang('Teachers').': </td><td class="highlight">'.$teachers.' </td>';                           
-                       }
-                       if (!empty($coaches)) {
-                            $description .= '<tr><td>'.get_lang('Coachs').': </td><td class="highlight">'.$coaches.' </td>';
-                       }
-					   $description .= '<tr><td>'.get_lang('Date').': </td><td class="highlight">'.api_convert_and_format_date(time(), DATE_TIME_FORMAT_LONG).'</td>';
-                       $description .= '</table>';   
-                       $params = array();                       
-                       Export::export_table_pdf($a_users, get_lang('UserList'), $header, $description, $params);
-                       exit;
+                        $teachers = CourseManager::get_teacher_list_from_course_code($course_info['code']);
+                        
+                        //If I'm a teacher in this course show just my name
+                        if (isset($teachers[$user_id])) {    
+                            if (!empty($teachers)) {
+                                $teacher_info = $teachers[$user_id];
+                                $description .= '<tr><td>'.get_lang('Teacher').': </td><td class="highlight">'.api_get_person_name($teacher_info['firstname'], $teacher_info['lastname']).'</td>';                           
+                            }
+                        } else {
+                            //If not show all teachers
+                            $teachers = CourseManager::get_teacher_list_from_course_code_to_string($course_info['code']);    
+                            if (!empty($teachers)) {
+                                $description .= '<tr><td>'.get_lang('Teachers').': </td><td class="highlight">'.$teachers.'</td>';                           
+                            }
+                        }
+                        
+                        if (!empty($session_id)) {
+                            //If I'm a coach
+                            $coaches  = CourseManager::get_coach_list_from_course_code($course_info['code'], $session_id);
+                            
+                            if (isset($coaches) && isset($coaches[$user_id])) {  
+                                $user_info = api_get_user_info($user_id);                                
+                                $description .= '<tr><td>'.get_lang('Coach').': </td><td class="highlight">'.$user_info['complete_name'].'</td>';                                                      
+                            } else {
+                               //If not show everything
+                               $teachers = CourseManager::get_coach_list_from_course_code_to_string($course_info['code'], $session_id);    
+                               if (!empty($teachers)) {
+                                   $description .= '<tr><td>'.get_lang('Coachs').': </td><td class="highlight">'.$coaches.'</td>';                           
+                               }
+                           }
+                        }          
+
+                        $description .= '<tr><td>'.get_lang('Date').': </td><td class="highlight">'.api_convert_and_format_date(time(), DATE_TIME_FORMAT_LONG).'</td>';
+                        $description .= '</table>';   
+                        $params = array();                       
+                        Export::export_table_pdf($a_users, get_lang('UserList'), $header, $description, $params);
+                        exit;
 				}
 		}
 	}