Bladeren bron

drh can see all users/courses inside the session if the configuration['drh_can_access_all_session_content'] is set see BT#6770

Julio Montoya 11 jaren geleden
bovenliggende
commit
c03fe190e4
6 gewijzigde bestanden met toevoegingen van 341 en 264 verwijderingen
  1. 42 1
      main/inc/lib/sessionmanager.lib.php
  2. 86 67
      main/mySpace/course.php
  3. 3 4
      main/mySpace/myStudents.php
  4. 64 74
      main/mySpace/student.php
  5. 108 75
      main/mySpace/teachers.php
  6. 38 43
      main/tracking/courseLog.php

+ 42 - 1
main/inc/lib/sessionmanager.lib.php

@@ -2345,11 +2345,52 @@ class SessionManager
         $result = Database::query($sql);
 
         $coaches = array();
-        if (Database::num_rows($result) > 0){
+        if (Database::num_rows($result) > 0) {
             while ($row = Database::fetch_row($result)) {
                 $coaches[] = $row[0];
             }
         }
         return $coaches;
     }
+
+    /**
+     * @param int $userId
+     * @return array
+     */
+    public static function getAllCoursesFromAllSessionFromDrh($userId)
+    {
+        $sessions = SessionManager::get_sessions_followed_by_drh($userId);
+        $coursesFromSession = array();
+        if (!empty($sessions)) {
+            foreach ($sessions as $session) {
+                $courseList = SessionManager::get_course_list_by_session_id($session['id']);
+                foreach ($courseList as $course) {
+                    $coursesFromSession[] = $course['code'];
+                }
+            }
+        }
+        return $coursesFromSession;
+    }
+
+    /**
+     * @param int $userId
+     * @return array
+     */
+    public static function getAllUsersFromCoursesFromAllSessionFromDrh($userId)
+    {
+        $sessions = SessionManager::get_sessions_followed_by_drh($userId);
+        $userList = array();
+        if (!empty($sessions)) {
+            foreach ($sessions as $session) {
+                $courseList = SessionManager::get_course_list_by_session_id($session['id']);
+                foreach ($courseList as $course) {
+                    $users = CourseManager::get_user_list_from_course_code($course['code'], $session['id']);
+                    foreach ($users as $user) {
+                        $userList[] = $user['user_id'];
+                    }
+                }
+            }
+        }
+        return $userList;
+    }
 }

+ 86 - 67
main/mySpace/course.php

@@ -48,54 +48,60 @@ function count_courses() {
 $show_import_icon = false;
 
 if (api_get_setting('add_users_by_coach') == 'true') {
-	if (!api_is_platform_admin()) {
-		$sql = 'SELECT id_coach FROM '.Database :: get_main_table(TABLE_MAIN_SESSION).' WHERE id='.$id_session;
-		$rs = Database::query($sql);
-		if (Database::result($rs, 0, 0) != $_user['user_id']) {
-			api_not_allowed(true);
-		} else {
-			$show_import_icon=true;
-		}
-	}
+    if (!api_is_platform_admin()) {
+        $sql = 'SELECT id_coach FROM '.Database :: get_main_table(TABLE_MAIN_SESSION).' WHERE id='.$id_session;
+        $rs = Database::query($sql);
+        if (Database::result($rs, 0, 0) != $_user['user_id']) {
+            api_not_allowed(true);
+        } else {
+            $show_import_icon=true;
+        }
+    }
 }
 
 Display :: display_header($nameTools);
 
 $a_courses = array();
 if (api_is_drh() || api_is_session_admin() || api_is_platform_admin()) {
-
-	$title = '';
-	if (empty($id_session)) {
-		if (isset($_GET['user_id'])) {
-			$user_id = intval($_GET['user_id']);
-			$user_info = api_get_user_info($user_id);
-			$title = get_lang('AssignedCoursesTo').' '.api_get_person_name($user_info['firstname'], $user_info['lastname']);
-			$courses  = CourseManager::get_course_list_of_user_as_course_admin($user_id);
-		} else {
-			$title = get_lang('YourCourseList');
-			$courses = CourseManager::get_courses_followed_by_drh($_user['user_id']);
-		}
-	} else {
-		$session_name = api_get_session_name($id_session);
-		$title = api_htmlentities($session_name,ENT_QUOTES,$charset).' : '.get_lang('CourseListInSession');
-		$courses = Tracking::get_courses_list_from_session($id_session);
-	}
+    $coursesFromSession = array();
+    if (api_is_drh()) {
+        if (api_drh_can_access_all_session_content()) {
+            $coursesFromSession = SessionManager::getAllCoursesFromAllSessionFromDrh(api_get_user_id());
+        }
+    }
+
+    $title = '';
+    if (empty($id_session)) {
+        if (isset($_GET['user_id'])) {
+            $user_id = intval($_GET['user_id']);
+            $user_info = api_get_user_info($user_id);
+            $title = get_lang('AssignedCoursesTo').' '.api_get_person_name($user_info['firstname'], $user_info['lastname']);
+            $courses  = CourseManager::get_course_list_of_user_as_course_admin($user_id);
+        } else {
+            $title = get_lang('YourCourseList');
+            $courses = CourseManager::get_courses_followed_by_drh($_user['user_id']);
+        }
+    } else {
+        $session_name = api_get_session_name($id_session);
+        $title = api_htmlentities($session_name, ENT_QUOTES, $charset).' : '.get_lang('CourseListInSession');
+        $courses = Tracking::get_courses_list_from_session($id_session);
+    }
 
 	$a_courses = array_keys($courses);
 
-	if (!api_is_session_admin()) {		
-		$menu_items[] = Display::url(Display::return_icon('stats.png', get_lang('MyStats'),'',ICON_SIZE_MEDIUM),api_get_path(WEB_CODE_PATH)."auth/my_progress.php" );
-		$menu_items[] = Display::url(Display::return_icon('user.png', get_lang('Students'), array(), 32), "index.php?view=drh_students&display=yourstudents");
-		$menu_items[] = Display::url(Display::return_icon('teacher.png', get_lang('Trainers'), array(), 32), 'teachers.php');
-		$menu_items[] = Display::return_icon('course_na.png', get_lang('Courses'), array(), 32);
-		$menu_items[] = Display::url(Display::return_icon('session.png', get_lang('Sessions'), array(), 32), 'session.php');
-	}
+    if (!api_is_session_admin()) {
+        $menu_items[] = Display::url(Display::return_icon('stats.png', get_lang('MyStats'),'',ICON_SIZE_MEDIUM),api_get_path(WEB_CODE_PATH)."auth/my_progress.php" );
+        $menu_items[] = Display::url(Display::return_icon('user.png', get_lang('Students'), array(), 32), "index.php?view=drh_students&display=yourstudents");
+        $menu_items[] = Display::url(Display::return_icon('teacher.png', get_lang('Trainers'), array(), 32), 'teachers.php');
+        $menu_items[] = Display::return_icon('course_na.png', get_lang('Courses'), array(), 32);
+        $menu_items[] = Display::url(Display::return_icon('session.png', get_lang('Sessions'), array(), 32), 'session.php');
+    }
 
 	echo '<div class="actions">';
 	$nb_menu_items = count($menu_items);
 	if ($nb_menu_items > 1) {
 		foreach ($menu_items as $key => $item) {
-			echo $item;		
+			echo $item;
 		}
 	}
 	if (count($a_courses) > 0) {
@@ -123,28 +129,34 @@ if (isset($_GET['action'])) {
 
 if ($show_import_icon) {
 	echo "<div align=\"right\">";
-	echo '<a href="user_import.php?id_session='.$id_session.'&action=export&amp;type=xml">'.Display::return_icon('excel.gif', get_lang('ImportUserListXMLCSV')).'&nbsp;'.get_lang('ImportUserListXMLCSV').'</a>';
+	echo '<a href="user_import.php?id_session='.$id_session.'&action=export&amp;type=xml">'.
+            Display::return_icon('excel.gif', get_lang('ImportUserListXMLCSV')).'&nbsp;'.get_lang('ImportUserListXMLCSV').'</a>';
 	echo "</div><br />";
 }
 
 if (!api_is_drh() && !api_is_session_admin() && !api_is_platform_admin()) {
 	$courses = Tracking::get_courses_followed_by_coach($_user['user_id'], $id_session);
-	$a_courses = array_keys($courses);
+    $a_courses = array_keys($courses);
+}
+
+if (api_drh_can_access_all_session_content()) {
+    if (!isset($_GET['user_id'])) {
+        $a_courses = $coursesFromSession;
+    }
 }
 
 $nb_courses = count($a_courses);
 
 $table = new SortableTable('tracking_list_course', 'count_courses');
-$table -> set_header(0, get_lang('CourseTitle'), false);
-$table -> set_header(1, get_lang('NbStudents'), false);
-$table -> set_header(2, get_lang('TimeSpentInTheCourse').Display :: return_icon('info3.gif', get_lang('TimeOfActiveByTraining'), array('align' => 'absmiddle', 'hspace' => '3px')), false);
-$table -> set_header(3, get_lang('ThematicAdvance'), false);
-$table -> set_header(4, get_lang('AvgStudentsProgress').Display :: return_icon('info3.gif', get_lang('AvgAllUsersInAllCourses'), array('align' => 'absmiddle', 'hspace' => '3px')), false);
-$table -> set_header(5, get_lang('AvgCourseScore').Display :: return_icon('info3.gif', get_lang('AvgAllUsersInAllCourses'), array('align' => 'absmiddle', 'hspace' => '3px')), false);
-//$table -> set_header(5, get_lang('AvgExercisesScore'), false);// no code for this?
-$table -> set_header(6, get_lang('AvgMessages'), false);
-$table -> set_header(7, get_lang('AvgAssignments'), false);
-$table -> set_header(8, get_lang('Details'), false);
+$table->set_header(0, get_lang('CourseTitle'), false);
+$table->set_header(1, get_lang('NbStudents'), false);
+$table->set_header(2, get_lang('TimeSpentInTheCourse').Display :: return_icon('info3.gif', get_lang('TimeOfActiveByTraining'), array('align' => 'absmiddle', 'hspace' => '3px')), false);
+$table->set_header(3, get_lang('ThematicAdvance'), false);
+$table->set_header(4, get_lang('AvgStudentsProgress').Display :: return_icon('info3.gif', get_lang('AvgAllUsersInAllCourses'), array('align' => 'absmiddle', 'hspace' => '3px')), false);
+$table->set_header(5, get_lang('AvgCourseScore').Display :: return_icon('info3.gif', get_lang('AvgAllUsersInAllCourses'), array('align' => 'absmiddle', 'hspace' => '3px')), false);
+$table->set_header(6, get_lang('AvgMessages'), false);
+$table->set_header(7, get_lang('AvgAssignments'), false);
+$table->set_header(8, get_lang('Details'), false);
 
 $csv_header[] = array(
 	get_lang('CourseTitle', ''),
@@ -153,7 +165,6 @@ $csv_header[] = array(
 	get_lang('ThematicAdvance', ''),
 	get_lang('AvgStudentsProgress', ''),
 	get_lang('AvgCourseScore', ''),
-	//get_lang('AvgExercisesScore', ''),
 	get_lang('AvgMessages', ''),
 	get_lang('AvgAssignments', '')
 );
@@ -173,20 +184,21 @@ if (is_array($a_courses)) {
 
 		$rs = Database::query($sql);
 		$users = array();
-		while ($row = Database::fetch_array($rs)) { $users[] = $row['user_id']; }
+		while ($row = Database::fetch_array($rs)) {
+            $users[] = $row['user_id'];
+        }
 
 		if (count($users) > 0) {
 			$nb_students_in_course = count($users);
-			// tracking datas
+			// tracking data
 			$avg_progress_in_course = Tracking :: get_avg_student_progress ($users, $course_code, array(), $id_session);
 			$avg_score_in_course = Tracking :: get_avg_student_score ($users, $course_code, array(), $id_session);
 			$avg_time_spent_in_course = Tracking :: get_time_spent_on_the_course ($users, $course_code, $id_session);
 			$messages_in_course = Tracking :: count_student_messages ($users, $course_code, $id_session);
 			$assignments_in_course = Tracking :: count_student_assignments ($users, $course_code, $id_session);
-
 			$avg_time_spent_in_course = api_time_to_hms($avg_time_spent_in_course / $nb_students_in_course);
 			$avg_progress_in_course = round($avg_progress_in_course / $nb_students_in_course, 2);
-			
+
 			if (is_numeric($avg_score_in_course)) {
 				$avg_score_in_course = round($avg_score_in_course / $nb_students_in_course, 2).'%';
 			}
@@ -201,7 +213,7 @@ if (is_array($a_courses)) {
 
 		$tematic_advance_progress = 0;
 		$thematic = new Thematic();
-		$tematic_advance = $thematic->get_total_average_of_thematic_advances($course_code, $id_session);		
+		$tematic_advance = $thematic->get_total_average_of_thematic_advances($course_code, $id_session);
 
 		if (!empty($tematic_advance)) {
 			$tematic_advance_csv = $tematic_advance_progress.'%';
@@ -210,16 +222,27 @@ if (is_array($a_courses)) {
 			$tematic_advance_progress = '-';
 		}
 
-		$table_row = array();
-		$table_row[] = $course['title'];
-		$table_row[] = $nb_students_in_course;
-		$table_row[] = is_null($avg_time_spent_in_course)?'-':$avg_time_spent_in_course;
-		$table_row[] = $tematic_advance_progress;
-		$table_row[] = is_null($avg_progress_in_course) ? '-' : $avg_progress_in_course.'%';
-		$table_row[] = is_null($avg_score_in_course) ? '-' : $avg_score_in_course;
-		$table_row[] = is_null($messages_in_course)?'-':$messages_in_course;
-		$table_row[] = is_null($assignments_in_course)?'-':$assignments_in_course;
-		$table_row[] = '<a href="../tracking/courseLog.php?cidReq='.$course_code.'&id_session='.$id_session.'"><img src="'.api_get_path(WEB_IMG_PATH).'2rightarrow.gif" border="0" /></a>';
+        $courseIcon = '<a href="../tracking/courseLog.php?cidReq='.$course_code.'&id_session='.$id_session.'">
+                        <img src="'.api_get_path(WEB_IMG_PATH).'2rightarrow.gif" border="0" />
+                      </a>';
+
+        if (!empty($coursesFromSession)) {
+            if (!in_array($course_code, $coursesFromSession)) {
+                $courseIcon = Display::return_icon('2rightarrow_na.gif', get_lang('Course'), array());
+            }
+        }
+
+		$table_row = array(
+            $course['title'],
+            $nb_students_in_course,
+            is_null($avg_time_spent_in_course)?'-':$avg_time_spent_in_course,
+            $tematic_advance_progress,
+            is_null($avg_progress_in_course) ? '-' : $avg_progress_in_course.'%',
+            is_null($avg_score_in_course) ? '-' : $avg_score_in_course,
+            is_null($messages_in_course)?'-':$messages_in_course,
+            is_null($assignments_in_course)?'-':$assignments_in_course,
+            $courseIcon
+        );
 
 		$csv_content[] = array (
 			$course['title'],
@@ -232,13 +255,9 @@ if (is_array($a_courses)) {
 			$assignments_in_course,
 		);
 
-		$table -> addRow($table_row, 'align="right"');
+		$table->addRow($table_row, 'align="right"');
 	}
-
-	// $csv_content = array_merge($csv_header, $csv_content); // Before this statement you are allowed to sort (in different way) the array $csv_content.
 }
-//$table -> setColAttributes(0);
-//$table -> setColAttributes(7);
 $table -> display();
 
 Display :: display_footer();

+ 3 - 4
main/mySpace/myStudents.php

@@ -257,7 +257,7 @@ while ($row = Database :: fetch_array($rs)) {
 }
 
 // Get the list of sessions where the user is subscribed as student
-$sql = 'SELECT id_session, course_code FROM ' . Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER) . '
+$sql = 'SELECT id_session, course_code FROM '.Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER).'
         WHERE id_user=' . intval($user_info['user_id']);
 $rs = Database::query($sql);
 $tmp_sessions = array();
@@ -278,9 +278,8 @@ while ($row = Database :: fetch_array($rs)) {
 
 if (!empty($student_id)) {
     if (api_drh_can_access_all_session_content()) {
-        $sessions = SessionManager::get_sessions_followed_by_drh($user_id);
-        $sessionList = array_keys($sessions);
-        if (!in_array($session_id, $sessionList)) {
+        $users = SessionManager::getAllUsersFromCoursesFromAllSessionFromDrh(api_get_user_id());
+        if (!in_array($student_id, $users)) {
             api_not_allowed();
         }
     } else {

+ 64 - 74
main/mySpace/student.php

@@ -23,14 +23,14 @@ if ($export_csv) {
 $csv_content = array();
 
 if (isset($_GET['id_coach']) && intval($_GET['id_coach']) != 0) {
-	$nameTools = get_lang("CoachStudents");
-	$sql = 'SELECT lastname, firstname FROM '.Database::get_main_table(TABLE_MAIN_USER).' WHERE user_id='.intval($_GET['id_coach']);
-	$rs = Database::query($sql);
-	$coach_name = api_get_person_name(Database::result($rs, 0, 1), Database::result($rs, 0, 0));
-	$page_title = get_lang('Students').' - '.$coach_name;
+    $nameTools = get_lang("CoachStudents");
+    $sql = 'SELECT lastname, firstname FROM '.Database::get_main_table(TABLE_MAIN_USER).' WHERE user_id='.intval($_GET['id_coach']);
+    $rs = Database::query($sql);
+    $coach_name = api_get_person_name(Database::result($rs, 0, 1), Database::result($rs, 0, 0));
+    $page_title = get_lang('Students').' - '.$coach_name;
 } else {
-	$nameTools = get_lang("Students");
-	$page_title = get_lang('Students');
+    $nameTools = get_lang("Students");
+    $page_title = get_lang('Students');
 }
 
 $this_section = SECTION_TRACKING;
@@ -46,9 +46,6 @@ if (isset($_GET["user_id"]) && $_GET["user_id"]!="" && isset($_GET["type"]) && $
 }
 
 Display :: display_header($nameTools);
-/*
-  	FUNCTION
-  */
 
 function count_student_coached() {
 	global $students;
@@ -73,10 +70,7 @@ function rsort_users($a, $b) {
 	}
 }
 
-/* MAIN CODE	 */
-
-//if ($isCoach || api_is_platform_admin() || api_is_drh()) {
-if (api_is_allowed_to_create_course() || api_is_drh()) {		
+if (api_is_allowed_to_create_course() || api_is_drh()) {
 	if ($export_csv) {
 		$is_western_name_order = api_is_western_name_order(PERSON_NAME_DATA_EXPORT);
 	} else {
@@ -91,29 +85,29 @@ if (api_is_allowed_to_create_course() || api_is_drh()) {
 		$menu_items[] = Display::url(Display::return_icon('teacher.png', get_lang('Trainers'), array(), 32), 'teachers.php');
 		$menu_items[] = Display::url(Display::return_icon('course.png', get_lang('Courses'), array(), 32), 'course.php');
 		$menu_items[] = Display::url(Display::return_icon('session.png', get_lang('Sessions'), array(), 32), 'session.php');
-		
+
 		echo '<div class="actions">';
 		$nb_menu_items = count($menu_items);
 		if ($nb_menu_items > 1) {
 			foreach ($menu_items as $key => $item) {
-				echo $item;			
+				echo $item;
 			}
 		}
-        
+
 		//if (count($students) > 0) {		//
 			echo '<span style="float:right">';
 			echo Display::url(Display::return_icon('printer.png', get_lang('Print'), array(), 32), 'javascript: void(0);', array('onclick'=>'javascript: window.print();'));
 			echo Display::url(Display::return_icon('export_csv.png', get_lang('ExportAsCSV'), array(), 32), api_get_self().'?export=csv');
-			echo '</span>';	
+			echo '</span>';
 		//}
-		echo '</div>';		
-	} else {		
+		echo '</div>';
+	} else {
 		echo '<div class="actions"><div style="float:right;">
 				<a href="javascript: void(0);" onclick="javascript: window.print();"><img align="absbottom" src="../img/printmgr.gif">&nbsp;'.get_lang('Print').'</a>
 				<a href="'.api_get_self().'?export=csv"><img align="absbottom" src="../img/excel.gif">&nbsp;'.get_lang('ExportAsCSV').'</a>
-			  </div></div>';        
+			  </div></div>';
 	}
-    
+
     echo Display::page_subheader($page_title);
 
 	if (isset($_GET['id_coach'])) {
@@ -121,10 +115,17 @@ if (api_is_allowed_to_create_course() || api_is_drh()) {
 	} else {
 		$coach_id = api_get_user_id();
 	}
+
 	if (api_is_drh()) {
+
+        if (api_drh_can_access_all_session_content()) {
+            $studentsAllowed = SessionManager::getAllUsersFromCoursesFromAllSessionFromDrh(api_get_user_id());
+        } else {
+            $studentsAllowed = array_keys(UserManager::get_users_followed_by_drh(api_get_user_id() , STUDENT));
+        }
+
 		$page_title = get_lang('YourStudents');
 		if (!isset($_GET['id_session'])) {
-		
 			if (isset($_GET['user_id'])) {
 				$user_id = intval($_GET['user_id']);
 				$user_info = api_get_user_info($user_id);
@@ -147,22 +148,22 @@ if (api_is_allowed_to_create_course() || api_is_drh()) {
 			} else {
 				$students = array_keys(UserManager::get_users_followed_by_drh(api_get_user_id() , STUDENT));
 			}
-		
+
 			$courses_of_the_platform = CourseManager :: get_real_course_list();
 			foreach ($courses_of_the_platform as $course) {
 				$courses[$course['code']] = $course['code'];
 			}
 		}
 	} else {
-		if (!isset($_GET['id_session'])) {	
-			//Getting courses
+		if (!isset($_GET['id_session'])) {
+			// Getting courses
 			$courses  = CourseManager::get_course_list_as_coach($coach_id, false);
 			if (isset($courses[0])) {
 				$courses = $courses[0];
-			}			
-			//Getting students			
+			}
+			// Getting students
 			$students = CourseManager::get_user_list_from_courses_as_coach($coach_id);
-					
+
 		} else {
 			$students = Tracking :: get_student_followed_by_coach_in_a_session($_GET['id_session'], $coach_id);
 		}
@@ -170,35 +171,26 @@ if (api_is_allowed_to_create_course() || api_is_drh()) {
 
 	$tracking_column 	= isset($_GET['tracking_column']) ? $_GET['tracking_column'] : ($is_western_name_order xor $sort_by_first_name) ? 1 : 0;
 	$tracking_direction = isset($_GET['tracking_direction']) ? $_GET['tracking_direction'] : DESC;
-	
+
 	if (count($students) > 0) {
 		$table = new SortableTable('tracking_student', 'count_student_coached', null, ($is_western_name_order xor $sort_by_first_name) ? 1 : 0);
 		if ($is_western_name_order) {
-			$table -> set_header(0, get_lang('FirstName'), false);
-			$table -> set_header(1, get_lang('LastName'), false);
+			$table->set_header(0, get_lang('FirstName'), false);
+			$table->set_header(1, get_lang('LastName'), false);
 		} else {
-			$table -> set_header(0, get_lang('LastName'), false);
-			$table -> set_header(1, get_lang('FirstName'), false);
+			$table->set_header(0, get_lang('LastName'), false);
+			$table->set_header(1, get_lang('FirstName'), false);
 		}
-	/*	$table -> set_header(2, get_lang('Time'), false);
-		$table -> set_header(3, get_lang('Progress'), false);
-		$table -> set_header(4, get_lang('Score'), false);
-		$table -> set_header(5, get_lang('Student_publication'), false);
-		$table -> set_header(6, get_lang('Messages'), false);*/
-		$table -> set_header(2, get_lang('FirstLogin'), false);
-		$table -> set_header(3, get_lang('LatestLogin'), false);
-		$table -> set_header(4, get_lang('Details'), false);
+
+		$table->set_header(2, get_lang('FirstLogin'), false);
+		$table->set_header(3, get_lang('LatestLogin'), false);
+		$table->set_header(4, get_lang('Details'), false);
 
 		if ($export_csv) {
 			if ($is_western_name_order) {
 				$csv_header[] = array (
 					get_lang('FirstName', ''),
 					get_lang('LastName', ''),
-					//get_lang('Time', ''),
-					//get_lang('Progress', ''),
-					//get_lang('Score', ''),
-					//get_lang('Student_publication', ''),
-					//get_lang('Messages', ''),
 					get_lang('FirstLogin', ''),
 					get_lang('LatestLogin', '')
 				);
@@ -206,30 +198,26 @@ if (api_is_allowed_to_create_course() || api_is_drh()) {
 				$csv_header[] = array (
 					get_lang('LastName', ''),
 					get_lang('FirstName', ''),
-					//get_lang('Time', ''),
-					//get_lang('Progress', ''),
-					//get_lang('Score', ''),
-					//get_lang('Student_publication', ''),
-					//get_lang('Messages', ''),
 					get_lang('FirstLogin', ''),
 					get_lang('LatestLogin', '')
 				);
 			}
 		}
 
-	    $all_datas = array();	  
-	      
+	    $all_datas = array();
+
 		foreach ($students as $student_id) {
 			$student_data = UserManager :: get_user_info_by_id($student_id);
+
 			if (isset($_GET['id_session'])) {
-				$courses = Tracking :: get_course_list_in_session_from_student($student_id, $_GET['id_session']);				
-			}			
+				$courses = Tracking :: get_course_list_in_session_from_student($student_id, $_GET['id_session']);
+			}
 
 			$avg_time_spent = $avg_student_score = $avg_student_progress = $total_assignments = $total_messages = 0;
 			$nb_courses_student = 0;
 			foreach ($courses as $course_code) {
 				if (CourseManager :: is_user_subscribed_in_course($student_id, $course_code, true)) {
-					$avg_time_spent 	+= Tracking :: get_time_spent_on_the_course($student_id, $course_code, $_GET['id_session']);					
+					$avg_time_spent 	+= Tracking :: get_time_spent_on_the_course($student_id, $course_code, $_GET['id_session']);
 					$my_average 		 = Tracking :: get_avg_student_score($student_id, $course_code);
 					if (is_numeric($my_average)) {
 						$avg_student_score += $my_average;
@@ -259,33 +247,36 @@ if (api_is_allowed_to_create_course() || api_is_drh()) {
 				$row[] = $student_data['lastname'];
 				$row[] = $student_data['firstname'];
 			}
-			
-			/*
-			$row[] = api_time_to_hms($avg_time_spent);
-			$row[] = is_null($avg_student_progress) ? null : round($avg_student_progress, 2).'%';
-			$row[] = is_null($avg_student_score) ? null : round($avg_student_score, 2).'%';
-			$row[] = $total_assignments;
-			$row[] = $total_messages;
-			*/
-
 			$string_date = Tracking :: get_last_connection_date($student_id, true);
 			$first_date = Tracking :: get_first_connection_date($student_id);
 			$row[] = $first_date;
 			$row[] = $string_date;
 
-			if ($export_csv) {			    
+			if ($export_csv) {
 			    $row[count($row) - 1] = strip_tags($row[count($row) - 1]);
                 $row[count($row) - 2] = strip_tags($row[count($row) - 2]);
 				$csv_content[] = $row;
 			}
 
-			if (isset($_GET['id_coach']) && intval($_GET['id_coach']) != 0) {
-				$row[] = '<a href="myStudents.php?student='.$student_id.'&id_coach='.$coach_id.'&id_session='.$_GET['id_session'].'"><img src="'.api_get_path(WEB_IMG_PATH).'2rightarrow.gif" border="0" /></a>';
-			} else {
-				$row[] = '<a href="myStudents.php?student='.$student_id.'"><img src="'.api_get_path(WEB_IMG_PATH).'2rightarrow.gif" border="0" /></a>';
-			}
 
-			$all_datas[] = $row;
+            if (isset($_GET['id_coach']) && intval($_GET['id_coach']) != 0) {
+                $detailsLink = '<a href="myStudents.php?student='.$student_id.'&id_coach='.$coach_id.'&id_session='.$_GET['id_session'].'">
+				          <img src="'.api_get_path(WEB_IMG_PATH).'2rightarrow.gif" border="0" /></a>';
+            } else {
+                $detailsLink =  '<a href="myStudents.php?student='.$student_id.'">
+				          <img src="'.api_get_path(WEB_IMG_PATH).'2rightarrow.gif" border="0" /></a>';
+            }
+
+            if (api_is_drh()) {
+                if (!in_array($student_id, $studentsAllowed)) {
+                    $detailsLink = Display::return_icon('2rightarrow_na.gif', get_lang('Details'));
+                }
+            }
+
+            $row[] = $detailsLink;
+
+
+            $all_datas[] = $row;
 		}
 
 		if ($tracking_direction == 'ASC') {
@@ -315,5 +306,4 @@ if (api_is_allowed_to_create_course() || api_is_drh()) {
 	}
 }
 
-/*		FOOTER	*/
 Display :: display_footer();

+ 108 - 75
main/mySpace/teachers.php

@@ -25,35 +25,56 @@ Display :: display_header($nameTools);
 
 $formateurs = array();
 if (api_is_drh() || api_is_platform_admin()) {
-
-	// followed teachers by drh
-	$formateurs = UserManager::get_users_followed_by_drh($_user['user_id'], COURSEMANAGER);
-    $menu_items = array();
-	$menu_items[] = Display::url(Display::return_icon('stats.png', get_lang('MyStats'),'',ICON_SIZE_MEDIUM),api_get_path(WEB_CODE_PATH)."auth/my_progress.php" );	 
-	$menu_items[] = Display::url(Display::return_icon('user.png', get_lang('Students'), array(), 32), "index.php?view=drh_students&amp;display=yourstudents");
-	$menu_items[] = Display::return_icon('teacher_na.png', get_lang('Trainers'), array(), 32);
-	$menu_items[] = Display::url(Display::return_icon('course.png', get_lang('Courses'), array(), 32), 'course.php');
-	$menu_items[] = Display::url(Display::return_icon('session.png', get_lang('Sessions'), array(), 32), 'session.php');	
-		
-	echo '<div class="actions">';
-	$nb_menu_items = count($menu_items);
-	if ($nb_menu_items > 1) {
-		foreach ($menu_items as $key => $item) {
-			echo $item;		
-		}
-	}	
-	if (count($formateurs) > 0) {
-		echo '<span style="float:right">';
-		echo Display::url(Display::return_icon('printer.png', get_lang('Print'), array(), 32), 'javascript: void(0);', array('onclick'=>'javascript: window.print();'));
-		echo Display::url(Display::return_icon('export_csv.png', get_lang('ExportAsCSV'), array(), 32), api_get_self().'?export=xls');
-		echo '</span>';			
-	}
-	echo '</div>';
-	echo Display::page_subheader(get_lang('YourTeachers'));	
+	// Followed teachers by drh
+    if (api_drh_can_access_all_session_content()) {
+        $sessions = SessionManager::get_sessions_followed_by_drh(api_get_user_id());
+        if (!empty($sessions)) {
+            $formateurs = array();
+            foreach ($sessions as $session) {
+                $coursesFromSession = SessionManager::get_course_list_by_session_id($session['id']);
+                foreach ($coursesFromSession as $course) {
+                    $teachers = CourseManager::get_teacher_list_from_course_code($course['code']);
+                    foreach ($teachers as $teacher) {
+                        if (isset($formateurs[$teacher['user_id']])) {
+                            continue;
+                        }
+                        $formateurs[$teacher['user_id']] = $teacher;
+                    }
+                }
+            }
+        }
+
+    } else {
+        $formateurs = UserManager::get_users_followed_by_drh($_user['user_id'], COURSEMANAGER);
+    }
+
+    $menu_items = array(
+        Display::url(Display::return_icon('stats.png', get_lang('MyStats'), '', ICON_SIZE_MEDIUM), api_get_path(WEB_CODE_PATH)."auth/my_progress.php" ),
+	    Display::url(Display::return_icon('user.png', get_lang('Students'), array(), 32), "index.php?view=drh_students&amp;display=yourstudents"),
+	    Display::return_icon('teacher_na.png', get_lang('Trainers'), array(), 32),
+	    Display::url(Display::return_icon('course.png', get_lang('Courses'), array(), 32), 'course.php'),
+	    Display::url(Display::return_icon('session.png', get_lang('Sessions'), array(), 32), 'session.php')
+    );
+
+    echo '<div class="actions">';
+    $nb_menu_items = count($menu_items);
+    if ($nb_menu_items > 1) {
+        foreach ($menu_items as $key => $item) {
+            echo $item;
+        }
+    }
+    if (count($formateurs) > 0) {
+        echo '<span style="float:right">';
+        echo Display::url(Display::return_icon('printer.png', get_lang('Print'), array(), 32), 'javascript: void(0);', array('onclick'=>'javascript: window.print();'));
+        echo Display::url(Display::return_icon('export_csv.png', get_lang('ExportAsCSV'), array(), 32), api_get_self().'?export=xls');
+        echo '</span>';
+    }
+    echo '</div>';
+	echo Display::page_subheader(get_lang('YourTeachers'));
 }
 
 if (!api_is_drh()) {
-	api_display_tool_title($nameTools);
+    api_display_tool_title($nameTools);
 }
 
 /**
@@ -61,31 +82,31 @@ if (!api_is_drh()) {
  */
 
 if (isset($_POST['export'])) {
-	$is_western_name_order = api_is_western_name_order(PERSON_NAME_DATA_EXPORT);
+    $is_western_name_order = api_is_western_name_order(PERSON_NAME_DATA_EXPORT);
 } else {
-	$is_western_name_order = api_is_western_name_order();
+    $is_western_name_order = api_is_western_name_order();
 }
 $sort_by_first_name = api_sort_by_first_name();
 
 if (!api_is_drh() && !api_is_platform_admin()) {
-	$order_clause = $sort_by_first_name ? ' ORDER BY firstname, lastname' : ' ORDER BY lastname, firstname';
-	if (isset($_GET["teacher_id"]) && $_GET["teacher_id"] != 0) {
-		$teacher_id = intval($_GET["teacher_id"]);
-		$sql_formateurs = "SELECT user_id,lastname,firstname,email
-			FROM $tbl_user
-			WHERE user_id='$teacher_id'".$order_clause;
-	} else {
-		$sql_formateurs = "SELECT user_id,lastname,firstname,email
-			FROM $tbl_user
-			WHERE status = 1".$order_clause;
-	}
-	
-	$result_formateurs = Database::query($sql_formateurs);
-	if (Database::num_rows($result_formateurs) > 0) {
-		while ($row_formateurs = Database::fetch_array($result_formateurs)) {
-			$formateurs[] = $row_formateurs;	
-		}
-	}
+    $order_clause = $sort_by_first_name ? ' ORDER BY firstname, lastname' : ' ORDER BY lastname, firstname';
+    if (isset($_GET["teacher_id"]) && $_GET["teacher_id"] != 0) {
+        $teacher_id = intval($_GET["teacher_id"]);
+        $sql_formateurs = "SELECT user_id,lastname,firstname,email
+            FROM $tbl_user
+            WHERE user_id='$teacher_id'".$order_clause;
+    } else {
+        $sql_formateurs = "SELECT user_id,lastname,firstname,email
+            FROM $tbl_user
+            WHERE status = 1".$order_clause;
+    }
+
+    $result_formateurs = Database::query($sql_formateurs);
+    if (Database::num_rows($result_formateurs) > 0) {
+        while ($row_formateurs = Database::fetch_array($result_formateurs)) {
+            $formateurs[] = $row_formateurs;
+        }
+    }
 }
 
 $time_filter = 'last_7_days';
@@ -99,7 +120,7 @@ $form->addRule(array ('start_date', 'end_date'), get_lang('StartDateShouldBeBefo
 
 $defaults = array();
 $defaults['start_date'] =  date('Y-m-d 12:00:00', strtotime("-7 days"));
-$defaults['end_date']   = date('Y-m-d 12:00:00',time());
+$defaults['end_date']   = date('Y-m-d 12:00:00', time());
 $start_date = $end_date = null;
 
 if ($form->validate()) {
@@ -107,7 +128,7 @@ if ($form->validate()) {
     $start_date = $defaults['start_date'] =  $values['start_date'];
     $end_date = $defaults['end_date']   =  $values['end_date'];
     $time_filter = 'custom';
-    $time_label = sprintf(get_lang('TimeSpentBetweenXAndY'), $start_date, $end_date);        
+    $time_label = sprintf(get_lang('TimeSpentBetweenXAndY'), $start_date, $end_date);
 }
 $form->setDefaults($defaults);
 $form->addelement('style_submit_button', 'submit', get_lang('Filter'));
@@ -120,11 +141,11 @@ if ($is_western_name_order) {
 }
 
 if ($is_western_name_order) {
-	$header[] = get_lang('FirstName');
-	$header[] = get_lang('LastName');
+    $header[] = get_lang('FirstName');
+    $header[] = get_lang('LastName');
 } else {
-	$header[] = get_lang('LastName');
-	$header[] = get_lang('FirstName');
+    $header[] = get_lang('LastName');
+    $header[] = get_lang('FirstName');
 }
 
 $header[] = $time_label;
@@ -134,37 +155,49 @@ $data = array();
 
 if (count($formateurs) > 0) {
 
-	$i = 1;
+    $i = 1;
 	foreach ($formateurs as $formateur) {
-		$user_id = $formateur["user_id"];
-		$lastname = $formateur["lastname"];
-		$firstname = $formateur["firstname"];
-		$email = $formateur["email"];
+        $user_id = $formateur["user_id"];
+        $lastname = $formateur["lastname"];
+        $firstname = $formateur["firstname"];
+        $email = $formateur["email"];
 
 		if ($i % 2 == 0) {
 			$css_class = "row_odd";
 
-			if ($i % 20 == 0 && $i != 0) {
-				if ($is_western_name_order) {
-					echo '<tr><th>'.get_lang('FirstName').'</th><th>'.get_lang('LastName').'</th><th>'.get_lang('Email').'</th><th>'.get_lang('AdminCourses').'</th><th>'.get_lang('Students').'</th></tr>';
-				} else {
-					echo '<tr><th>'.get_lang('LastName').'</th><th>'.get_lang('FirstName').'</th><th>'.get_lang('Email').'</th><th>'.get_lang('AdminCourses').'</th><th>'.get_lang('Students').'</th></tr>';
-				}
-			}
-		} else {
-			$css_class = "row_even";
-		}
+            if ($i % 20 == 0 && $i != 0) {
+                if ($is_western_name_order) {
+                    echo '<tr>
+                            <th>'.get_lang('FirstName').'</th>
+                            <th>'.get_lang('LastName').'</th>
+                            <th>'.get_lang('Email').'</th>
+                            <th>'.get_lang('AdminCourses').'</th>
+                            <th>'.get_lang('Students').'</th>
+                        </tr>';
+                } else {
+                    echo '<tr>
+                            <th>'.get_lang('LastName').'</th>
+                            <th>'.get_lang('FirstName').'</th>
+                            <th>'.get_lang('Email').'</th>
+                            <th>'.get_lang('AdminCourses').'</th>
+                            <th>'.get_lang('Students').'</th>
+                        </tr>';
+                }
+            }
+        } else {
+            $css_class = "row_even";
+        }
 
 		$i++;
 
-		if ($is_western_name_order) {
-			$data[$user_id]["firstname"] = $firstname;
-			$data[$user_id]["lastname"] = $lastname;
-		} else {
-			$data[$user_id]["lastname"] = $lastname;
-			$data[$user_id]["firstname"] = $firstname;
-		}
-		
+        if ($is_western_name_order) {
+            $data[$user_id]["firstname"] = $firstname;
+            $data[$user_id]["lastname"] = $lastname;
+        } else {
+            $data[$user_id]["lastname"] = $lastname;
+            $data[$user_id]["firstname"] = $firstname;
+        }
+
 		$time_on_platform = api_time_to_hms(Tracking :: get_time_spent_on_the_platform($user_id, $time_filter, $start_date, $end_date));
 		$data[$user_id]["timespentlastweek"] = $time_on_platform;
 		$data[$user_id]["email"] = $email;

+ 38 - 43
main/tracking/courseLog.php

@@ -46,12 +46,15 @@ if (!$is_allowedToTrack) {
 
 if (api_is_drh()) {
     // Blocking course for drh
-
     if (api_drh_can_access_all_session_content()) {
-        $sessions = SessionManager::get_sessions_followed_by_drh($user_id);
-        $sessionList = array_keys($sessions);
-        if (!in_array($session_id, $sessionList)) {
-            api_not_allowed();
+        $coursesFromSession = SessionManager::getAllCoursesFromAllSessionFromDrh(api_get_user_id());
+
+        $coursesFollowedList = CourseManager::get_courses_followed_by_drh(api_get_user_id());
+        $coursesFollowedList = array_keys($coursesFollowedList);
+        if (!in_array(api_get_course_id(), $coursesFollowedList)) {
+            if (!in_array(api_get_course_id(), $coursesFromSession)) {
+                api_not_allowed();
+            }
         }
     } else {
         $coursesFollowedList = CourseManager::get_courses_followed_by_drh(api_get_user_id());
@@ -83,7 +86,7 @@ if ($export_csv) {
     ob_start();
 }
 $csv_content = array();
-// Scripts for reporting array hide / unhide columns
+// Scripts for reporting array hide/show columns
 $js = "<script>
         // hide column and display the button to unhide it
         function foldup(in_id) {
@@ -116,26 +119,21 @@ $js = "<script>
     </script>";
 
 $htmlHeadXtra[] = "<style type='text/css'>
-/*<![CDATA[*/
-.secLine {background-color : #E6E6E6;}
-.content {padding-left : 15px;padding-right : 15px; }
-.specialLink{color : #0000FF;}
-/*]]>*/
-/* Style for reporting array hide / unhide columns */
-.unhide_button {
-    cursor : pointer;
-    border:1px solid black;
-    background-color: #FAFAFA;
-    padding: 5px;
-    border-radius : 3px;
-    margin-right:3px;
-}
-div#reporting_table table th {
-  vertical-align:top;
-}
-</style>
-<style media='print' type='text/css'>
-
+    .secLine {background-color : #E6E6E6;}
+    .content {padding-left : 15px;padding-right : 15px; }
+    .specialLink{color : #0000FF;}
+    /* Style for reporting array hide/show columns */
+    .unhide_button {
+        cursor : pointer;
+        border:1px solid black;
+        background-color: #FAFAFA;
+        padding: 5px;
+        border-radius : 3px;
+        margin-right:3px;
+    }
+    div#reporting_table table th {
+      vertical-align:top;
+    }
 </style>";
 $htmlHeadXtra[] .= $js;
 
@@ -166,19 +164,19 @@ Display::display_header($nameTools, 'Tracking');
 
 // getting all the students of the course
 if (empty($session_id)) {
-	// Registered students in a course outside session.
-	$a_students = CourseManager :: get_student_list_from_course_code(api_get_course_id());
+    // Registered students in a course outside session.
+    $a_students = CourseManager :: get_student_list_from_course_code(api_get_course_id());
 } else {
-	// Registered students in session.
-	$a_students = CourseManager :: get_student_list_from_course_code(api_get_course_id(), true, api_get_session_id());
+    // Registered students in session.
+    $a_students = CourseManager :: get_student_list_from_course_code(api_get_course_id(), true, api_get_session_id());
 }
 
 $nbStudents = count($a_students);
 
-// Gettting all the additional information of an additional profile field.
+// Getting all the additional information of an additional profile field.
 if (isset($_GET['additional_profile_field']) && is_numeric($_GET['additional_profile_field'])) {
     $user_array = array();
-    foreach ($a_students as $key=>$item) {
+    foreach ($a_students as $key => $item) {
         $user_array[] = $key;
     }
     // Fetching only the user that are loaded NOT ALL user in the portal.
@@ -186,7 +184,6 @@ if (isset($_GET['additional_profile_field']) && is_numeric($_GET['additional_pro
     $extra_info = UserManager::get_extra_field_information($_GET['additional_profile_field']);
 }
 
-
 /* MAIN CODE */
 
 echo '<div class="actions">';
@@ -211,7 +208,6 @@ echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&export=csv&'.$addional_pa
 '.Display::return_icon('export_csv.png', get_lang('ExportAsCSV'),'',ICON_SIZE_MEDIUM).'</a>';
 
 echo '</span>';
-
 echo '</div>';
 
 
@@ -227,8 +223,7 @@ $form_search->addElement('style_submit_button', 'submit', get_lang('SearchUsers'
 $form_search->display();
 echo '</div>';
 
-
-// BEGIN : form to remind inactives susers
+// BEGIN : form to remind inactive users
 
 if (count($a_students) > 0) {
     $form = new FormValidator('reminder_form', 'get', api_get_path(REL_CODE_PATH).'announcements/announcements.php');
@@ -249,8 +244,8 @@ if (count($a_students) > 0) {
     $el = $form -> addElement('select', 'since', '<img width="ICON_SIZE_SMALL" align="middle" src="'.api_get_path(WEB_IMG_PATH).'messagebox_warning.gif" border="0" />'.get_lang('RemindInactivesLearnersSince'), $options);
     $el -> setSelected(7);
 
-    $form -> addElement('hidden', 'action', 'add');
-    $form -> addElement('hidden', 'remindallinactives', 'true');
+    $form->addElement('hidden', 'action', 'add');
+    $form->addElement('hidden', 'remindallinactives', 'true');
 
     $course_name = get_lang('Course').' '.$course_info['name'];
 
@@ -295,10 +290,10 @@ if (count($a_students) > 0) {
     if ($is_western_name_order) {
         $table->set_header(1, get_lang('FirstName'), true);
         $tab_table_header[] = get_lang('FirstName');
-        $table->set_header(2, get_lang('LastName'),  true);
+        $table->set_header(2, get_lang('LastName'), true);
         $tab_table_header[] = get_lang('LastName');
     } else {
-        $table->set_header(1, get_lang('LastName'),  true);
+        $table->set_header(1, get_lang('LastName'), true);
         $tab_table_header[] = get_lang('LastName');
         $table->set_header(2, get_lang('FirstName'), true);
         $tab_table_header[] = get_lang('FirstName');
@@ -355,7 +350,7 @@ if (count($a_students) > 0) {
             $tab_table_header[] = get_lang('Details');
         }
     }
-    // display buttons to unhide hidden columns
+    // display buttons to un hide hidden columns
     echo "<br/><br/><div id='unhideButtons'>";
     for ($i=0; $i < count($tab_table_header); $i++) {
         $index = $i + 1;
@@ -386,8 +381,8 @@ if ($export_csv) {
     $csv_headers[] = get_lang('Login', ''); //
     $csv_headers[] = get_lang('TrainingTime', '');
     $csv_headers[] = get_lang('CourseProgress', '');
-    $csv_headers[] = get_lang('ExerciseProgress','');
-    $csv_headers[] = get_lang('ExerciseAverage','');
+    $csv_headers[] = get_lang('ExerciseProgress', '');
+    $csv_headers[] = get_lang('ExerciseAverage', '');
     $csv_headers[] = get_lang('Score', '');
     $csv_headers[] = get_lang('Student_publication', '');
     $csv_headers[] = get_lang('Messages', '');