diff --git a/main/user/user.php b/main/user/user.php index e1762342ab..14a7966db3 100755 --- a/main/user/user.php +++ b/main/user/user.php @@ -604,7 +604,7 @@ if (api_is_allowed_to_edit(null, true)) { Display::return_icon('export_excel.png', get_lang('ExportAsXLS'), [], ICON_SIZE_MEDIUM).' '; if ($canEditUsers) { - $actions .= ''. + $actions .= ''. Display::return_icon('import_csv.png', get_lang('ImportUsersToACourse'), [], ICON_SIZE_MEDIUM).' '; } diff --git a/main/user/user_import.php b/main/user/user_import.php index e9693edfd0..8f2dee7b2a 100755 --- a/main/user/user_import.php +++ b/main/user/user_import.php @@ -13,6 +13,12 @@ if (api_get_setting('allow_user_course_subscription_by_course_admin') == 'false' } } +// Make sure we know if we're importing students or teachers into the course +$userType = STUDENT; +if (!empty($_REQUEST['type']) && $_REQUEST['type'] == COURSEMANAGER) { + $userType = COURSEMANAGER; +} + $tool_name = get_lang('ImportUsersToACourse'); $interbreadcrumb[] = array("url" => "user.php", "name" => get_lang("Users")); @@ -22,6 +28,7 @@ $form = new FormValidator('user_import', 'post', 'user_import.php'); $form->addElement('header', $tool_name); $form->addElement('file', 'import_file', get_lang('ImportCSVFileLocation')); $form->addElement('checkbox', 'unsubscribe_users', null, get_lang('UnsubscribeUsersAlreadyAddedInCourse')); +$form->addElement('hidden', 'type', $userType); $form->addButtonImport(get_lang('Import')); $course_code = api_get_course_id(); @@ -71,12 +78,24 @@ if ($form->validate()) { $message = get_lang('ListOfUsersSubscribedToCourse'); if ($unsubscribe_users) { - $current_user_list = CourseManager::get_user_list_from_course_code($course_code, $session_id); + $current_user_list = CourseManager::get_user_list_from_course_code( + $course_code, + $session_id, + null, + null, + $userType + ); if (!empty($current_user_list)) { $user_ids = array(); foreach ($current_user_list as $user) { - if (!CourseManager::is_course_teacher($user['user_id'], $course_code)) { - $user_ids[] = $user['user_id']; + if ($userType == COURSEMANAGER) { + if (CourseManager::is_course_teacher($user['user_id'], $course_code)) { + $user_ids[] = $user['user_id']; + } + } else { + if (!CourseManager::is_course_teacher($user['user_id'], $course_code)) { + $user_ids[] = $user['user_id']; + } } } CourseManager::unsubscribe_user($user_ids, $course_code, $session_id); @@ -85,7 +104,7 @@ if ($form->validate()) { foreach ($clean_users as $userId) { $userInfo = api_get_user_info($userId); - CourseManager::subscribe_user($userId, $course_code, STUDENT, $session_id); + CourseManager::subscribe_user($userId, $course_code, $userType, $session_id); if (empty($session_id)) { //just to make sure if (CourseManager :: is_user_subscribed_in_course($userId, $course_code)) {