function search_sessions($needle, $type)
{
    global $_configuration, $tbl_session_rel_access_url, $tbl_session, $user_id;
    $xajax_response = new XajaxResponse();
    $return = '';
    if (!empty($needle) && !empty($type)) {
        // xajax send utf8 datas... datas in db can be non-utf8 datas
        $charset = api_get_system_encoding();
        $needle = api_convert_encoding($needle, $charset, 'utf-8');
        $assigned_sessions_to_hrm = SessionManager::get_sessions_followed_by_drh($user_id);
        $assigned_sessions_id = array_keys($assigned_sessions_to_hrm);
        $without_assigned_sessions = '';
        if (count($assigned_sessions_id) > 0) {
            $without_assigned_sessions = " AND s.id NOT IN(" . implode(',', $assigned_sessions_id) . ")";
        }
        if ($_configuration['multiple_access_urls']) {
            $sql = " SELECT s.id, s.name FROM {$tbl_session} s LEFT JOIN {$tbl_session_rel_access_url} a ON (s.id = a.session_id)\n\t\t\t\t\t\tWHERE  s.name LIKE '{$needle}%' {$without_assigned_sessions} AND access_url_id = " . api_get_current_access_url_id() . "";
        } else {
            $sql = "SELECT s.id, s.name FROM {$tbl_session} s\n\t\t\t\tWHERE  s.name LIKE '{$needle}%' {$without_assigned_sessions} ";
        }
        $rs = Database::query($sql);
        $return .= '<select id="origin" name="NoAssignedSessionsList[]" multiple="multiple" size="20" style="width:340px;">';
        while ($session = Database::fetch_array($rs)) {
            $return .= '<option value="' . $session['id'] . '" title="' . htmlspecialchars($session['name'], ENT_QUOTES) . '">' . $session['name'] . '</option>';
        }
        $return .= '</select>';
        $xajax_response->addAssign('ajax_list_sessions_multiple', 'innerHTML', api_utf8_encode($return));
    }
    return $xajax_response;
}
function search_sessions($needle, $type)
{
    global $tbl_session_rel_access_url, $tbl_session, $user_id;
    $xajax_response = new xajaxResponse();
    $return = '';
    if (!empty($needle) && !empty($type)) {
        $needle = Database::escape_string($needle);
        $assigned_sessions_to_hrm = SessionManager::get_sessions_followed_by_drh($user_id);
        $assigned_sessions_id = array_keys($assigned_sessions_to_hrm);
        $without_assigned_sessions = '';
        if (count($assigned_sessions_id) > 0) {
            $without_assigned_sessions = " AND s.id NOT IN(" . implode(',', $assigned_sessions_id) . ")";
        }
        if (api_is_multiple_url_enabled()) {
            $sql = " SELECT s.id, s.name FROM {$tbl_session} s\n                        LEFT JOIN {$tbl_session_rel_access_url} a ON (s.id = a.session_id)\n                        WHERE  s.name LIKE '{$needle}%' {$without_assigned_sessions} AND access_url_id = " . api_get_current_access_url_id() . "";
        } else {
            $sql = "SELECT s.id, s.name FROM {$tbl_session} s\n                    WHERE  s.name LIKE '{$needle}%' {$without_assigned_sessions} ";
        }
        $rs = Database::query($sql);
        $return .= '<select class="form-control" id="origin" name="NoAssignedSessionsList[]" multiple="multiple" size="20">';
        while ($session = Database::fetch_array($rs)) {
            $return .= '<option value="' . $session['id'] . '" title="' . htmlspecialchars($session['name'], ENT_QUOTES) . '">' . $session['name'] . '</option>';
        }
        $return .= '</select>';
        $xajax_response->addAssign('ajax_list_sessions_multiple', 'innerHTML', api_utf8_encode($return));
    }
    return $xajax_response;
}
 /**
  * Constructor
  */
 public function __construct($user_id)
 {
     $this->user_id = $user_id;
     $this->path = 'block_session';
     if ($this->is_block_visible_for_user($user_id)) {
         $this->sessions = SessionManager::get_sessions_followed_by_drh($user_id);
     }
 }
 /**
  * Constructor
  */
 public function __construct($user_id)
 {
     $this->user_id = $user_id;
     $this->path = 'block_session';
     if ($this->is_block_visible_for_user($user_id)) {
         /*if (api_is_platform_admin()) {
          		$this->sessions = SessionManager::get_sessions_list();
          	} else {*/
         $this->sessions = SessionManager::get_sessions_followed_by_drh($user_id);
         //}
     }
 }
	/**
	 * Constructor
	 */
    public function __construct($user_id)
    {
    	$this->path = 'block_evaluation_graph';
    	$this->user_id 	= $user_id;
    	$this->bg_width = 450;
    	$this->bg_height = 350;
    	if ($this->is_block_visible_for_user($user_id)) {
            if (!api_is_session_admin()) {
                $this->courses  = CourseManager::get_courses_followed_by_drh($user_id);
            }
            $this->sessions = SessionManager::get_sessions_followed_by_drh($user_id);
    	}
    }
Exemple #6
0
 /**
  * @param int $userId
  *
  * @return array
  */
 public static function getStats($userId)
 {
     if (api_is_drh() && api_drh_can_access_all_session_content()) {
         $studentList = SessionManager::getAllUsersFromCoursesFromAllSessionFromStatus('drh_all', $userId, false, null, null, null, null, null, null, null, array(), array(), STUDENT);
         $students = array();
         foreach ($studentList as $studentData) {
             $students[] = $studentData['user_id'];
         }
         $teacherList = SessionManager::getAllUsersFromCoursesFromAllSessionFromStatus('drh_all', $userId, false, null, null, null, null, null, null, null, array(), array(), COURSEMANAGER);
         $teachers = array();
         foreach ($teacherList as $teacherData) {
             $teachers[] = $teacherData['user_id'];
         }
         $humanResources = SessionManager::getAllUsersFromCoursesFromAllSessionFromStatus('drh_all', $userId, false, null, null, null, null, null, null, null, array(), array(), DRH);
         $humanResourcesList = array();
         foreach ($humanResources as $item) {
             $humanResourcesList[] = $item['user_id'];
         }
         $platformCourses = SessionManager::getAllCoursesFollowedByUser($userId, null, null, null, null, null);
         //$platformCourses = SessionManager::getAllCoursesFromAllSessionFromDrh($userId);
         $courses = array();
         foreach ($platformCourses as $course) {
             $courses[$course['code']] = $course['code'];
         }
         $sessions = SessionManager::get_sessions_followed_by_drh($userId);
     } else {
         $studentList = UserManager::getUsersFollowedByUser($userId, STUDENT, false, false, false, null, null, null, null, null, null, COURSEMANAGER);
         $students = array();
         foreach ($studentList as $studentData) {
             $students[] = $studentData['user_id'];
         }
         $teacherList = UserManager::getUsersFollowedByUser($userId, COURSEMANAGER, false, false, false, null, null, null, null, null, null, COURSEMANAGER);
         $teachers = array();
         foreach ($teacherList as $teacherData) {
             $teachers[] = $teacherData['user_id'];
         }
         $humanResources = UserManager::getUsersFollowedByUser($userId, DRH, false, false, false, null, null, null, null, null, null, COURSEMANAGER);
         $humanResourcesList = array();
         foreach ($humanResources as $item) {
             $humanResourcesList[] = $item['user_id'];
         }
         $platformCourses = CourseManager::getCoursesFollowedByUser($userId, COURSEMANAGER);
         foreach ($platformCourses as $course) {
             $courses[$course['code']] = $course['code'];
         }
         $sessions = SessionManager::getSessionsFollowedByUser($userId, COURSEMANAGER);
     }
     return array('drh' => $humanResourcesList, 'teachers' => $teachers, 'students' => $students, 'courses' => $courses, 'sessions' => $sessions);
 }
Exemple #7
0
api_block_anonymous_users();
$htmlHeadXtra[] = api_get_jqgrid_js();
$interbreadcrumb[] = array("url" => "index.php", "name" => get_lang('MySpace'));
Display::display_header(get_lang('Sessions'));
$export_csv = false;
if (isset($_GET['export']) && $_GET['export'] == 'csv') {
    $export_csv = true;
}
/*	MAIN CODE */
if (isset($_GET['id_coach']) && $_GET['id_coach'] != '') {
    $id_coach = intval($_GET['id_coach']);
} else {
    $id_coach = api_get_user_id();
}
if (api_is_drh() || api_is_session_admin() || api_is_platform_admin()) {
    $a_sessions = SessionManager::get_sessions_followed_by_drh(api_get_user_id());
    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(), ICON_SIZE_MEDIUM), "index.php?view=drh_students&amp;display=yourstudents");
        $menu_items[] = Display::url(Display::return_icon('teacher.png', get_lang('Trainers'), array(), ICON_SIZE_MEDIUM), 'teachers.php');
        $menu_items[] = Display::url(Display::return_icon('course.png', get_lang('Courses'), array(), ICON_SIZE_MEDIUM), 'course.php');
        $menu_items[] = Display::url(Display::return_icon('session_na.png', get_lang('Sessions'), array(), ICON_SIZE_MEDIUM), '#');
    }
    $actionsLeft = '';
    $nb_menu_items = count($menu_items);
    if ($nb_menu_items > 1) {
        foreach ($menu_items as $key => $item) {
            $actionsLeft .= $item;
        }
    }
    $actionsRight = '';
     $columns = array('student', 'works');
     $result = getWorkUserListData($workId, api_get_course_id(), api_get_session_id(), api_get_group_id(), $start, $limit, $sidx, $sord);
     break;
 case 'get_hotpotatoes_exercise_results':
     $course = api_get_course_info();
     $documentPath = api_get_path(SYS_COURSE_PATH) . $course['path'] . "/document";
     if (api_is_allowed_to_edit(null, true) || api_is_drh()) {
         $columns = array('firstname', 'lastname', 'username', 'group_name', 'exe_date', 'score', 'actions');
     } else {
         $columns = array('exe_date', 'score', 'actions');
     }
     $result = ExerciseLib::get_exam_results_hotpotatoes_data($start, $limit, $sidx, $sord, $hotpot_path, $whereCondition);
     break;
 case 'get_sessions_tracking':
     if (api_is_drh()) {
         $sessions = SessionManager::get_sessions_followed_by_drh(api_get_user_id(), $start, $limit, false, false, false, null, $keyword, $description);
     } else {
         // Sessions for the coach
         $sessions = Tracking::get_sessions_coached_by_user(api_get_user_id(), $start, $limit, false, $keyword, $description);
     }
     $columns = array('name', 'date', 'course_per_session', 'student_per_session', 'details');
     $result = array();
     if (!empty($sessions)) {
         foreach ($sessions as $session) {
             if (api_drh_can_access_all_session_content()) {
                 $count_courses_in_session = count(SessionManager::get_course_list_by_session_id($session['id']));
             } else {
                 $count_courses_in_session = count(Tracking::get_courses_followed_by_coach($user_id, $session['id']));
             }
             $count_users_in_session = count(SessionManager::get_users_by_session($session['id'], 0));
             $session_date = array();
 /**
  * Gives a list of courses for the given user in the given session
  * @param integer $user_id
  * @param integer $session_id
  * @return array  list of statuses (session_id-course_code => status)
  */
 public static function get_courses_list_by_session($user_id, $session_id)
 {
     // Database Table Definitions
     $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
     $tableCourse = Database::get_main_table(TABLE_MAIN_COURSE);
     $tbl_session_course_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
     $tbl_session_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
     $user_id = intval($user_id);
     $session_id = intval($session_id);
     //we filter the courses from the URL
     $join_access_url = $where_access_url = '';
     if (api_get_multiple_access_url()) {
         $urlId = api_get_current_access_url_id();
         if ($urlId != -1) {
             $tbl_url_session = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
             $join_access_url = " ,  {$tbl_url_session} url_rel_session ";
             $where_access_url = " AND access_url_id = {$urlId} AND url_rel_session.session_id = {$session_id} ";
         }
     }
     $personal_course_list = array();
     $courses = array();
     /* This query is very similar to the query below, but it will check the
        session_rel_course_user table if there are courses registered
        to our user or not */
     $sql = "SELECT DISTINCT\n                    c.visibility,\n                    c.id as real_id\n                FROM {$tbl_session_course_user} as scu\n                INNER JOIN {$tbl_session_course} sc\n                ON (scu.session_id = sc.session_id AND scu.c_id = sc.c_id)\n                INNER JOIN {$tableCourse} as c\n                ON (scu.c_id = c.id)\n                {$join_access_url}\n                WHERE\n                    scu.user_id = {$user_id} AND\n                    scu.session_id = {$session_id}\n                    {$where_access_url}\n                ORDER BY sc.position ASC";
     $result = Database::query($sql);
     if (Database::num_rows($result) > 0) {
         while ($result_row = Database::fetch_array($result, 'ASSOC')) {
             $result_row['status'] = 5;
             if (!in_array($result_row['real_id'], $courses)) {
                 $personal_course_list[] = $result_row;
                 $courses[] = $result_row['real_id'];
             }
         }
     }
     if (api_is_allowed_to_create_course()) {
         $sql = "SELECT DISTINCT\n                        c.visibility, c.id as real_id\n                    FROM {$tbl_session_course_user} as scu\n                    INNER JOIN {$tbl_session} as s\n                    ON (scu.session_id = s.id)\n                    INNER JOIN {$tbl_session_course} sc\n                    ON (scu.session_id = sc.session_id AND scu.c_id = sc.c_id)\n                    INNER JOIN {$tableCourse} as c\n                    ON (scu.c_id = c.id)\n                    {$join_access_url}\n                    WHERE\n                      s.id = {$session_id} AND\n                      (\n                        (scu.user_id={$user_id} AND scu.status=2) OR\n                        s.id_coach = {$user_id}\n                      )\n                    {$where_access_url}\n                    ORDER BY sc.position ASC";
         $result = Database::query($sql);
         if (Database::num_rows($result) > 0) {
             while ($result_row = Database::fetch_array($result, 'ASSOC')) {
                 $result_row['status'] = 2;
                 if (!in_array($result_row['real_id'], $courses)) {
                     $personal_course_list[] = $result_row;
                     $courses[] = $result_row['real_id'];
                 }
             }
         }
     }
     if (api_is_drh()) {
         $session_list = SessionManager::get_sessions_followed_by_drh($user_id);
         $session_list = array_keys($session_list);
         if (in_array($session_id, $session_list)) {
             $course_list = SessionManager::get_course_list_by_session_id($session_id);
             if (!empty($course_list)) {
                 foreach ($course_list as $course) {
                     $personal_course_list[] = $course;
                 }
             }
         }
     } else {
         //check if user is general coach for this session
         $s = api_get_session_info($session_id);
         if ($s['id_coach'] == $user_id) {
             $course_list = SessionManager::get_course_list_by_session_id($session_id);
             if (!empty($course_list)) {
                 foreach ($course_list as $course) {
                     if (!in_array($course['id'], $courses)) {
                         $personal_course_list[] = $course;
                     }
                 }
             }
         }
     }
     return $personal_course_list;
 }
 /**
  * Get agenda events
  * @param int $start
  * @param int $end
  * @param int $course_id
  * @param int $groupId
  * @param int $user_id
  * @param string $format
  *
  * @return array|string
  */
 public function getEvents($start, $end, $course_id = null, $groupId = null, $user_id = 0, $format = 'json')
 {
     switch ($this->type) {
         case 'admin':
             $this->getPlatformEvents($start, $end);
             break;
         case 'course':
             $session_id = $this->sessionId;
             $courseInfo = api_get_course_info_by_id($course_id);
             // Session coach can see all events inside a session.
             if (api_is_coach()) {
                 // Own course
                 $this->getCourseEvents($start, $end, $courseInfo, $groupId, $session_id, $user_id);
                 // Others
                 $this->getSessionEvents($start, $end, api_get_session_id(), $user_id, $this->eventOtherSessionColor);
             } else {
                 $this->getCourseEvents($start, $end, $courseInfo, $groupId, $session_id, $user_id);
             }
             break;
         case 'personal':
         default:
             $sessionFilterActive = false;
             if (!empty($this->sessionId)) {
                 $sessionFilterActive = true;
             }
             if ($sessionFilterActive == false) {
                 // Getting personal events
                 $this->getPersonalEvents($start, $end);
                 // Getting platform/admin events
                 $this->getPlatformEvents($start, $end);
             }
             // Getting course events
             $my_course_list = array();
             if (!api_is_anonymous()) {
                 $session_list = SessionManager::get_sessions_by_user(api_get_user_id());
                 $my_course_list = CourseManager::get_courses_list_by_user_id(api_get_user_id(), false);
             }
             if (api_is_drh()) {
                 if (api_drh_can_access_all_session_content()) {
                     $session_list = array();
                     $sessionList = SessionManager::get_sessions_followed_by_drh(api_get_user_id(), null, null, null, true, false);
                     if (!empty($sessionList)) {
                         foreach ($sessionList as $sessionItem) {
                             $sessionId = $sessionItem['id'];
                             $courses = SessionManager::get_course_list_by_session_id($sessionId);
                             $sessionInfo = array('session_id' => $sessionId, 'courses' => $courses);
                             $session_list[] = $sessionInfo;
                         }
                     }
                 }
             }
             if (!empty($session_list)) {
                 foreach ($session_list as $session_item) {
                     if ($sessionFilterActive) {
                         if ($this->sessionId != $session_item['session_id']) {
                             continue;
                         }
                     }
                     $my_courses = $session_item['courses'];
                     $my_session_id = $session_item['session_id'];
                     if (!empty($my_courses)) {
                         foreach ($my_courses as $course_item) {
                             $courseInfo = api_get_course_info_by_id($course_item['real_id']);
                             $this->getCourseEvents($start, $end, $courseInfo, 0, $my_session_id);
                         }
                     }
                     $this->getSessionEvents($start, $end, $my_session_id, $user_id, $this->eventOtherSessionColor);
                 }
             }
             if (!empty($my_course_list) && $sessionFilterActive == false) {
                 foreach ($my_course_list as $courseInfoItem) {
                     $courseInfo = api_get_course_info_by_id($courseInfoItem['real_id']);
                     if (isset($course_id) && !empty($course_id)) {
                         if ($courseInfo['real_id'] == $course_id) {
                             $this->getCourseEvents($start, $end, $courseInfo);
                         }
                     } else {
                         $this->getCourseEvents($start, $end, $courseInfo);
                     }
                 }
             }
             break;
     }
     if (!empty($this->events)) {
         switch ($format) {
             case 'json':
                 return json_encode($this->events);
                 break;
             case 'array':
                 return $this->events;
                 break;
         }
     }
     return '';
 }
Exemple #11
0
 $courses = CourseManager::get_course_list_as_coach($user_id, false);
 if (isset($courses[0])) {
     $courses = $courses[0];
 }
 //Getting students from courses and courses in sessions (To show the total students that the user follows)
 $students = CourseManager::get_user_list_from_courses_as_coach($user_id);
 // Sessions for the coach
 $sessions = SessionManager::get_sessions_coached_by_user($user_id);
 //If is drh
 if ($is_drh) {
     $students = array_keys(UserManager::get_users_followed_by_drh($user_id, STUDENT));
     $courses_of_the_platform = CourseManager::get_courses_followed_by_drh($user_id);
     foreach ($courses_of_the_platform as $course) {
         $courses[$course['real_id']] = $course['real_id'];
     }
     $sessions = SessionManager::get_sessions_followed_by_drh($user_id);
 }
 //Courses for the user
 $count_courses = count($courses);
 //Sessions for the user
 $count_sessions = count($sessions);
 //Students
 $nb_students = count($students);
 $total_time_spent = 0;
 $total_courses = 0;
 $avg_total_progress = 0;
 $avg_results_to_exercises = 0;
 $nb_inactive_students = 0;
 $nb_posts = $nb_assignments = 0;
 if (!empty($students)) {
     foreach ($students as $student_id) {
 /**
  * Get teachers followed by a user
  * @param int $userId
  * @param int $active
  * @param string $lastConnectionDate
  * @param bool $getCount
  * @param array $sessionIdList
  * @return array|int
  */
 public static function getTeacherTracking($userId, $active = 1, $lastConnectionDate = null, $getCount = false, $sessionIdList = array())
 {
     $teacherListId = array();
     if (api_is_drh() || api_is_platform_admin()) {
         // Followed teachers by drh
         if (api_drh_can_access_all_session_content()) {
             if (empty($sessionIdList)) {
                 $sessions = SessionManager::get_sessions_followed_by_drh($userId);
                 $sessionIdList = array();
                 foreach ($sessions as $session) {
                     $sessionIdList[] = $session['id'];
                 }
             }
             $sessionIdList = array_map('intval', $sessionIdList);
             $sessionToString = implode("', '", $sessionIdList);
             $course = Database::get_main_table(TABLE_MAIN_COURSE);
             $sessionCourse = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
             $courseUser = Database::get_main_table(TABLE_MAIN_COURSE_USER);
             // Select the teachers.
             $sql = "SELECT DISTINCT(cu.user_id) FROM {$course} c\n                        INNER JOIN {$sessionCourse} src ON c.id = src.c_id\n                        INNER JOIN {$courseUser} cu ON (cu.c_id = c.id)\n\t\t                WHERE src.session_id IN ('{$sessionToString}') AND cu.status = 1";
             $result = Database::query($sql);
             while ($row = Database::fetch_array($result, 'ASSOC')) {
                 $teacherListId[$row['user_id']] = $row['user_id'];
             }
         } else {
             $teacherResult = UserManager::get_users_followed_by_drh($userId, COURSEMANAGER);
             foreach ($teacherResult as $userInfo) {
                 $teacherListId[] = $userInfo['user_id'];
             }
         }
     }
     if (!empty($teacherListId)) {
         $tableUser = Database::get_main_table(TABLE_MAIN_USER);
         $select = "SELECT DISTINCT u.* ";
         if ($getCount) {
             $select = "SELECT count(DISTINCT(u.user_id)) as count";
         }
         $sql = "{$select} FROM {$tableUser} u";
         if (!empty($lastConnectionDate)) {
             $tableLogin = Database::get_main_table(TABLE_STATISTIC_TRACK_E_LOGIN);
             //$sql .= " INNER JOIN $tableLogin l ON (l.login_user_id = u.user_id) ";
         }
         $active = intval($active);
         $teacherListId = implode("','", $teacherListId);
         $where = " WHERE u.active = {$active} AND u.user_id IN ('{$teacherListId}') ";
         if (!empty($lastConnectionDate)) {
             $lastConnectionDate = Database::escape_string($lastConnectionDate);
             //$where .= " AND l.login_date <= '$lastConnectionDate' ";
         }
         $sql .= $where;
         $result = Database::query($sql);
         if (Database::num_rows($result)) {
             if ($getCount) {
                 $row = Database::fetch_array($result);
                 return $row['count'];
             } else {
                 return Database::store_result($result, 'ASSOC');
             }
         }
     }
     return 0;
 }
}
// user info
$user_info = api_get_user_info($student_id);
$courses_in_session = array();
//See #4676
$drh_can_access_all_courses = false;
if (api_is_drh() || api_is_platform_admin() || api_is_student_boss()) {
    $drh_can_access_all_courses = true;
}
$courses = CourseManager::get_course_list_of_user_as_course_admin(api_get_user_id());
$courses_in_session_by_coach = array();
$sessions_coached_by_user = Tracking::get_sessions_coached_by_user(api_get_user_id());
// RRHH or session admin
if (api_is_session_admin() || api_is_drh()) {
    $courses = CourseManager::get_courses_followed_by_drh(api_get_user_id());
    $session_by_session_admin = SessionManager::get_sessions_followed_by_drh(api_get_user_id());
    if (!empty($session_by_session_admin)) {
        foreach ($session_by_session_admin as $session_coached_by_user) {
            $courses_followed_by_coach = Tracking::get_courses_list_from_session($session_coached_by_user['id']);
            $courses_in_session_by_coach[$session_coached_by_user['id']] = $courses_followed_by_coach;
        }
    }
}
// Teacher or admin
if (!empty($sessions_coached_by_user)) {
    foreach ($sessions_coached_by_user as $session_coached_by_user) {
        $sid = intval($session_coached_by_user['id']);
        $courses_followed_by_coach = Tracking::get_courses_followed_by_coach(api_get_user_id(), $sid);
        $courses_in_session_by_coach[$sid] = $courses_followed_by_coach;
    }
}
 /**
  * Gives a list of courses for the given user in the given session
  * @param integer $user_id
  * @return array  list of statuses (session_id-course_code => status)
  */
 public static function get_courses_list_by_session($user_id, $session_id)
 {
     // Database Table Definitions
     $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
     $tbl_session_course_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
     $user_id = intval($user_id);
     $session_id = intval($session_id);
     //we filter the courses from the URL
     $join_access_url = $where_access_url = '';
     if (api_get_multiple_access_url()) {
         $access_url_id = api_get_current_access_url_id();
         if ($access_url_id != -1) {
             $tbl_url_session = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
             $join_access_url = " ,  {$tbl_url_session} url_rel_session ";
             $where_access_url = " AND access_url_id = {$access_url_id} AND url_rel_session.session_id = {$session_id} ";
         }
     }
     $personal_course_list = array();
     $courses = array();
     // this query is very similar to the above query, but it will check the session_rel_course_user table if there are courses registered to our user or not
     $personal_course_list_sql = "SELECT DISTINCT scu.c_id as id\n                                    FROM {$tbl_session_course_user} as scu {$join_access_url}\n                                    WHERE scu.id_user = {$user_id} AND scu.id_session = {$session_id} {$where_access_url}\n                                    ORDER BY c_id";
     $course_list_sql_result = Database::query($personal_course_list_sql);
     if (Database::num_rows($course_list_sql_result) > 0) {
         while ($result_row = Database::fetch_array($course_list_sql_result)) {
             $result_row['status'] = 5;
             if (!in_array($result_row['id'], $courses)) {
                 $personal_course_list[] = $result_row;
                 $courses[] = $result_row['id'];
             }
         }
     }
     if (api_is_allowed_to_create_course()) {
         $personal_course_list_sql = "SELECT DISTINCT scu.c_id as id\n                                        FROM {$tbl_session_course_user} as scu, {$tbl_session} as s {$join_access_url}\n                                        WHERE s.id = {$session_id} AND scu.id_session = s.id AND ((scu.id_user={$user_id} AND scu.status=2) OR s.id_coach = {$user_id})\n                                        {$where_access_url}\n                                        ORDER BY c_id";
         $course_list_sql_result = Database::query($personal_course_list_sql);
         if (Database::num_rows($course_list_sql_result) > 0) {
             while ($result_row = Database::fetch_array($course_list_sql_result)) {
                 $result_row['status'] = 2;
                 if (!in_array($result_row['id'], $courses)) {
                     $personal_course_list[] = $result_row;
                     $courses[] = $result_row['id'];
                 }
             }
         }
     }
     if (api_is_drh()) {
         $session_list = SessionManager::get_sessions_followed_by_drh($user_id);
         $session_list = array_keys($session_list);
         if (in_array($session_id, $session_list)) {
             $course_list = SessionManager::get_course_list_by_session_id($session_id);
             if (!empty($course_list)) {
                 foreach ($course_list as $course) {
                     $personal_course_list[] = $course;
                 }
             }
         }
     } else {
         //check if user is general coach for this session
         $s = api_get_session_info($session_id);
         if ($s['id_coach'] == $user_id) {
             $course_list = SessionManager::get_course_list_by_session_id($session_id);
             if (!empty($course_list)) {
                 foreach ($course_list as $course) {
                     if (!in_array($course['id'], $courses)) {
                         $personal_course_list[] = $course;
                     }
                 }
             }
         }
     }
     return $personal_course_list;
 }
    /**
     * Gives a list of courses for the given user in the given session
     * @param integer $user_id
     * @param integer $session_id
     * @return array  list of statuses (session_id-course_code => status)
     */
    public static function get_courses_list_by_session($user_id, $session_id)
    {
        // Database Table Definitions
        $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
        $tableCourse = Database :: get_main_table(TABLE_MAIN_COURSE);
        $tbl_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
        $tbl_session_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);

        $user_id = intval($user_id);
        $session_id = intval($session_id);
        //we filter the courses from the URL
        $join_access_url = $where_access_url = '';

        if (api_get_multiple_access_url()) {
            $access_url_id = api_get_current_access_url_id();
            if ($access_url_id != -1) {
                $tbl_url_session = Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
                $join_access_url = " ,  $tbl_url_session url_rel_session ";
                $where_access_url = " AND access_url_id = $access_url_id AND url_rel_session.session_id = $session_id ";
            }
        }

        $personal_course_list = array();
        $courses = array();

        /* This query is very similar to the above query,but it will check the
        session_rel_course_user table if there are courses registered
        to our user or not*/

        $sql = "SELECT DISTINCT
                    scu.course_code as code, c.visibility, c.id as real_id
                FROM $tbl_session_course_user as scu
                INNER JOIN $tbl_session_course sc
                ON (scu.id_session = sc.id_session AND scu.course_code = sc.course_code)
                INNER JOIN $tableCourse as c
                ON (scu.course_code = c.code)
                $join_access_url
                WHERE
                    scu.id_user = $user_id AND
                    scu.id_session = $session_id
                    $where_access_url";

        $orderBy = " ORDER BY code ";
        if (SessionManager::orderCourseIsEnabled()) {
            $orderBy =  ' ORDER BY position';
        }
        $sql .= $orderBy;

        $result = Database::query($sql);

        if (Database::num_rows($result) > 0) {
            while ($result_row = Database::fetch_array($result)) {
                $result_row['status'] = 5;
                if (!in_array($result_row['code'], $courses)) {
                    $personal_course_list[] = $result_row;
                    $courses[] = $result_row['code'];
                }
            }
        }

        if (api_is_allowed_to_create_course()) {
            $sql = "SELECT DISTINCT
                        scu.course_code as code, c.visibility, c.id as real_id
                    FROM $tbl_session_course_user as scu
                    INNER JOIN $tbl_session as s
                    ON (scu.id_session = s.id)
                    INNER JOIN $tbl_session_course sc
                    ON (scu.id_session = sc.id_session AND scu.course_code = sc.course_code)
                    INNER JOIN $tableCourse as c
                    ON (scu.course_code = c.code)
                    $join_access_url
                    WHERE
                      s.id = $session_id AND
                      (
                        (scu.id_user=$user_id AND scu.status=2) OR
                        s.id_coach = $user_id
                      )
                    $where_access_url
                    $orderBy";
            $result = Database::query($sql);

            if (Database::num_rows($result) > 0) {
                while ($result_row = Database::fetch_array($result)) {
                    $result_row['status'] = 2;
                    if (!in_array($result_row['code'], $courses)) {
                        $personal_course_list[] = $result_row;
                        $courses[] = $result_row['code'];
                    }
                }
            }
        }

        if (api_is_drh()) {
            $session_list = SessionManager::get_sessions_followed_by_drh($user_id);
            $session_list = array_keys($session_list);
            if (in_array($session_id, $session_list)) {
                $course_list = SessionManager::get_course_list_by_session_id($session_id);
                if (!empty($course_list)) {
                    foreach ($course_list as $course) {
                        $personal_course_list[] = $course;
                    }
                }
            }
        } else {
            //check if user is general coach for this session
            $s = api_get_session_info($session_id);
            if ($s['id_coach'] == $user_id) {
                $course_list = SessionManager::get_course_list_by_session_id($session_id);
                if (!empty($course_list)) {
                    foreach ($course_list as $course) {
                        if (!in_array($course['code'], $courses)) {
                            $personal_course_list[] = $course;
                        }
                    }
                }
            }
        }

        return $personal_course_list;
    }