|
|
|
@ -2,15 +2,17 @@ |
|
|
|
|
/* For licensing terms, see /license.txt */ |
|
|
|
|
|
|
|
|
|
$language_file = array('registration', 'admin', 'userInfo'); |
|
|
|
|
require_once '../inc/global.inc.php'; |
|
|
|
|
|
|
|
|
|
require_once '../inc/global.inc.php'; |
|
|
|
|
require_once api_get_path(LIBRARY_PATH).'import.lib.php'; |
|
|
|
|
|
|
|
|
|
$this_section = SECTION_COURSES; |
|
|
|
|
|
|
|
|
|
// notice for unauthorized people. |
|
|
|
|
api_protect_course_script(true); |
|
|
|
|
|
|
|
|
|
$tool_name = get_lang('ImportUsersToACourse'); |
|
|
|
|
|
|
|
|
|
$interbreadcrumb[] = array ("url" => "user.php", "name" => get_lang("Users")); |
|
|
|
|
$interbreadcrumb[] = array ("url" => "#", "name" => get_lang("ImportUsersToACourse")); |
|
|
|
|
|
|
|
|
@ -35,39 +37,40 @@ $type = ''; |
|
|
|
|
|
|
|
|
|
if ($form->validate()) { |
|
|
|
|
if (isset($_FILES['import_file']['size']) && $_FILES['import_file']['size'] !== 0) { |
|
|
|
|
|
|
|
|
|
$users = Import::csv_to_array($_FILES['import_file']['tmp_name']); |
|
|
|
|
$invalid_users = array(); |
|
|
|
|
$clean_users = array(); |
|
|
|
|
$users_in_file = array(); |
|
|
|
|
|
|
|
|
|
$invalid_users = array(); |
|
|
|
|
$clean_users = array(); |
|
|
|
|
$users_in_file = array(); |
|
|
|
|
|
|
|
|
|
if (!empty($users)) { |
|
|
|
|
foreach($users as $user) { |
|
|
|
|
var_dump($users); |
|
|
|
|
foreach ($users as $user) { |
|
|
|
|
$user_info = api_get_user_info($user['id']); |
|
|
|
|
$clean_users[$user['id']] = $user_info; |
|
|
|
|
$users_in_file[$user['id']] = $user; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
foreach($users as $user) { |
|
|
|
|
if (!UserManager::is_user_id_valid($user['id'])) { |
|
|
|
|
if (!empty($user_info)) { |
|
|
|
|
$clean_users[$user['id']] = $user_info; |
|
|
|
|
$users_in_file[$user['id']] = $user; |
|
|
|
|
} else { |
|
|
|
|
$invalid_users[] = $user['id']; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//var_dump($clean_users); |
|
|
|
|
if (empty($invalid_users)) { |
|
|
|
|
$type = 'confirmation'; |
|
|
|
|
$message = get_lang('ListOfUsersSubscribedToCourse'); |
|
|
|
|
foreach($users as $user) { |
|
|
|
|
foreach ($users as $user) { |
|
|
|
|
$result = CourseManager :: subscribe_user($user['id'], $course_code, STUDENT); |
|
|
|
|
//just to make sure |
|
|
|
|
if (CourseManager :: is_user_subscribed_in_course($user['id'], $course_code)) { |
|
|
|
|
$user_to_show []= $clean_users[$user['id']]['complete_name']; |
|
|
|
|
$user_to_show[]= $clean_users[$user['id']]['complete_name']; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
$message = get_lang('CheckUsersWithId'); |
|
|
|
|
$type = 'warning'; |
|
|
|
|
foreach($invalid_users as $invalid_user) { |
|
|
|
|
$user_to_show []= $invalid_user; |
|
|
|
|
foreach ($invalid_users as $invalid_user) { |
|
|
|
|
$user_to_show[]= $invalid_user; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -75,11 +78,16 @@ if ($form->validate()) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Display::display_header(); |
|
|
|
|
|
|
|
|
|
if (!empty($message)) { |
|
|
|
|
if ($type == 'confirmation') { |
|
|
|
|
Display::display_confirmation_message($message.': '.implode(', ', $user_to_show)); |
|
|
|
|
if (!empty($user_to_show)) { |
|
|
|
|
if ($type == 'confirmation') { |
|
|
|
|
Display::display_confirmation_message($message.': <br />'.implode(', ', $user_to_show), false); |
|
|
|
|
} else { |
|
|
|
|
Display::display_warning_message($message.': '.implode(', ', $user_to_show)); |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
Display::display_warning_message($message.': '.implode(', ', $user_to_show)); |
|
|
|
|
Display::display_error_message(get_lang('ErrorsWhenImportingFile')); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|