Fix role issue when uploading teachers to a course through the users tool (in the course), where uploading teachers subscribed them as students - refs #2045

pull/2487/head
Yannick Warnier 8 years ago
parent 2dca649d54
commit 1948879ccf
  1. 2
      main/user/user.php
  2. 27
      main/user/user_import.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).'</a> ';
if ($canEditUsers) {
$actions .= '<a href="user_import.php?'.api_get_cidreq().'&action=import">'.
$actions .= '<a href="user_import.php?'.api_get_cidreq().'&action=import&type='.$type.'">'.
Display::return_icon('import_csv.png', get_lang('ImportUsersToACourse'), [], ICON_SIZE_MEDIUM).'</a> ';
}

@ -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)) {

Loading…
Cancel
Save