示例#1
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);
 }
示例#2
0
    }
} else {
    api_protect_admin_script();
}
// Database table definitions
$table_admin = Database::get_main_table(TABLE_MAIN_ADMIN);
$table_user = Database::get_main_table(TABLE_MAIN_USER);
$database = Database::get_main_database();
$userId = isset($_REQUEST['user_id']) ? intval($_REQUEST['user_id']) : '';
$userInfo = api_get_user_info($userId);
if (empty($userInfo)) {
    api_not_allowed(true);
}
$userIsFollowed = UserManager::is_user_followed_by_drh($userId, api_get_user_id());
if (api_drh_can_access_all_session_content()) {
    $students = SessionManager::getAllUsersFromCoursesFromAllSessionFromStatus('drh_all', api_get_user_id(), false, 0, null, null, 'desc', null, null, null, null, null, STUDENT);
    if (empty($students)) {
        api_not_allowed(true);
    }
    $userIdList = array();
    foreach ($students as $student) {
        $userIdList[] = $student['user_id'];
    }
    if (!in_array($userId, $userIdList)) {
        api_not_allowed(true);
    }
} else {
    if (!$userIsFollowed) {
        api_not_allowed(true);
    }
}
示例#3
0
         if (!empty($userList)) {
             $userIdList = array_keys($userList);
         }
         $courseList = CourseManager::get_courses_followed_by_drh(api_get_user_id());
         if (!empty($courseList)) {
             $courseCodeList = array_keys($courseList);
         }
     }
     if (empty($userIdList) || empty($courseCodeList)) {
         exit;
     }
 } elseif (api_is_student_boss()) {
     $searchByGroups = true;
 } elseif (api_is_platform_admin()) {
     if ($sessionId == -1) {
         $userIdList = SessionManager::getAllUsersFromCoursesFromAllSessionFromStatus('admin', null);
         $userIdList = array_column($userIdList, 'user_id');
         $sessionList = SessionManager::get_sessions_list();
         $sessionIdList = array_column($sessionList, 'id');
         $courseCodeList = array();
         foreach ($sessionList as $session) {
             $courses = SessionManager::get_course_list_by_session_id($session['id']);
             $courseCodeList = array_merge($courseCodeList, array_column($courses, 'code'));
         }
     }
     $searchByGroups = true;
 }
 if ($searchByGroups) {
     $userGroup = new UserGroup();
     $userIdList = array_merge($userIdList, $userGroup->getGroupUsersByUser(api_get_user_id()));
 }
示例#4
0
function get_users($from, $limit, $column, $direction)
{
    $active = isset($_GET['active']) ? $_GET['active'] : 1;
    $keyword = isset($_GET['keyword']) ? Security::remove_XSS($_GET['keyword']) : null;
    $sleepingDays = isset($_GET['sleeping_days']) ? intval($_GET['sleeping_days']) : null;
    $lastConnectionDate = null;
    if (!empty($sleepingDays)) {
        $lastConnectionDate = api_get_utc_datetime(strtotime($sleepingDays . ' days ago'));
    }
    $is_western_name_order = api_is_western_name_order();
    $coach_id = api_get_user_id();
    $drhLoaded = false;
    if (api_is_drh()) {
        $column = 'u.user_id';
        if (api_drh_can_access_all_session_content()) {
            $students = SessionManager::getAllUsersFromCoursesFromAllSessionFromStatus('drh_all', api_get_user_id(), false, $from, $limit, $column, $direction, $keyword, $active, $lastConnectionDate, null, null, api_is_student_boss() ? null : STUDENT);
            $drhLoaded = true;
        }
    }
    if ($drhLoaded == false) {
        $students = UserManager::getUsersFollowedByUser(api_get_user_id(), api_is_student_boss() ? null : STUDENT, false, false, false, $from, $limit, $column, $direction, $active, $lastConnectionDate, api_is_student_boss() ? STUDENT_BOSS : COURSEMANAGER, $keyword);
    }
    $all_datas = array();
    foreach ($students as $student_data) {
        $student_id = $student_data['user_id'];
        if (isset($_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;
        if (!empty($courses)) {
            foreach ($courses as $course_code) {
                $courseInfo = api_get_course_info($course_code);
                $courseId = $courseInfo['real_id'];
                if (CourseManager::is_user_subscribed_in_course($student_id, $course_code, true)) {
                    $avg_time_spent += Tracking::get_time_spent_on_the_course($student_id, $courseId, $_GET['id_session']);
                    $my_average = Tracking::get_avg_student_score($student_id, $course_code);
                    if (is_numeric($my_average)) {
                        $avg_student_score += $my_average;
                    }
                    $avg_student_progress += Tracking::get_avg_student_progress($student_id, $course_code);
                    $total_assignments += Tracking::count_student_assignments($student_id, $course_code);
                    $total_messages += Tracking::count_student_messages($student_id, $course_code);
                    $nb_courses_student++;
                }
            }
        }
        if ($nb_courses_student > 0) {
            $avg_time_spent = $avg_time_spent / $nb_courses_student;
            $avg_student_score = $avg_student_score / $nb_courses_student;
            $avg_student_progress = $avg_student_progress / $nb_courses_student;
        } else {
            $avg_time_spent = null;
            $avg_student_score = null;
            $avg_student_progress = null;
        }
        $row = array();
        if ($is_western_name_order) {
            $row[] = $student_data['firstname'];
            $row[] = $student_data['lastname'];
        } else {
            $row[] = $student_data['lastname'];
            $row[] = $student_data['firstname'];
        }
        $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 (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>';
        }
        $row[] = $detailsLink;
        $all_datas[] = $row;
    }
    return $all_datas;
}
示例#5
0
/**
 * Checks if user can login as another user
 *
 * @param int $loginAsUserId the user id to log in
 * @param int $userId my user id
 * @return bool
 */
function api_can_login_as($loginAsUserId, $userId = null)
{
    if (empty($userId)) {
        $userId = api_get_user_id();
    }
    if ($loginAsUserId == $userId) {
        return false;
    }
    if (empty($loginAsUserId)) {
        return false;
    }
    if ($loginAsUserId != strval(intval($loginAsUserId))) {
        return false;
    }
    // Check if the user to login is an admin
    if (api_is_platform_admin_by_id($loginAsUserId)) {
        // Only super admins can login to admin accounts
        if (!api_global_admin_can_edit_admin($loginAsUserId)) {
            return false;
        }
    }
    $userInfo = api_get_user_info($userId);
    $isDrh = function () use($loginAsUserId) {
        if (api_is_drh()) {
            if (api_drh_can_access_all_session_content()) {
                $users = SessionManager::getAllUsersFromCoursesFromAllSessionFromStatus('drh_all', api_get_user_id());
                $userList = array();
                foreach ($users as $user) {
                    $userList[] = $user['user_id'];
                }
                if (in_array($loginAsUserId, $userList)) {
                    return true;
                }
            } else {
                if (api_is_drh() && UserManager::is_user_followed_by_drh($loginAsUserId, api_get_user_id())) {
                    return true;
                }
            }
        }
        return false;
    };
    return api_is_platform_admin() || api_is_session_admin() && $userInfo['status'] == 5 || $isDrh();
}
示例#6
0
if (!$sidx) {
    $sidx = 1;
}
//2. Selecting the count FIRST
//@todo rework this
switch ($action) {
    case 'get_user_course_report':
    case 'get_user_course_report_resumed':
        if (!api_is_platform_admin(false, true)) {
            //exit;
        }
        $courseCodeList = array();
        $userIdList = array();
        if (api_is_drh()) {
            if (api_drh_can_access_all_session_content()) {
                $userList = SessionManager::getAllUsersFromCoursesFromAllSessionFromStatus('drh_all', api_get_user_id());
                if (!empty($userList)) {
                    foreach ($userList as $user) {
                        $userIdList[] = $user['user_id'];
                    }
                }
                $courseList = SessionManager::getAllCoursesFollowedByUser(api_get_user_id(), null);
                if (!empty($courseList)) {
                    foreach ($courseList as $course) {
                        $courseCodeList[] = $course['code'];
                    }
                }
            } else {
                $userList = UserManager::get_users_followed_by_drh(api_get_user_id());
                if (!empty($userList)) {
                    $userIdList = array_keys($userList);