|
|
|
@ -244,90 +244,6 @@ function updateUsers($users) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Save the imported data |
|
|
|
|
* @param array $users List of users |
|
|
|
|
* @return void |
|
|
|
|
* @uses global variable $inserted_in_course, which returns the list of courses the user was inserted in |
|
|
|
|
*/ |
|
|
|
|
function save_data($users) |
|
|
|
|
{ |
|
|
|
|
global $inserted_in_course; |
|
|
|
|
// Not all scripts declare the $inserted_in_course array (although they should). |
|
|
|
|
if (!isset($inserted_in_course)) { |
|
|
|
|
$inserted_in_course = array(); |
|
|
|
|
} |
|
|
|
|
require_once api_get_path(LIBRARY_PATH).'mail.lib.inc.php'; |
|
|
|
|
$usergroup = new UserGroup(); |
|
|
|
|
$send_mail = $_POST['sendMail'] ? true : false; |
|
|
|
|
if (is_array($users)) { |
|
|
|
|
foreach ($users as $user) { |
|
|
|
|
$user = complete_missing_data($user); |
|
|
|
|
$user['Status'] = api_status_key($user['Status']); |
|
|
|
|
$user_id = UserManager :: create_user( |
|
|
|
|
$user['FirstName'], |
|
|
|
|
$user['LastName'], |
|
|
|
|
$user['Status'], |
|
|
|
|
$user['Email'], |
|
|
|
|
$user['UserName'], |
|
|
|
|
$user['Password'], |
|
|
|
|
$user['OfficialCode'], |
|
|
|
|
$user['language'], |
|
|
|
|
$user['PhoneNumber'], |
|
|
|
|
'', |
|
|
|
|
$user['AuthSource'], |
|
|
|
|
null, |
|
|
|
|
1, |
|
|
|
|
0, |
|
|
|
|
null, |
|
|
|
|
null, |
|
|
|
|
$send_mail |
|
|
|
|
); |
|
|
|
|
if (!is_array($user['Courses']) && !empty($user['Courses'])) { |
|
|
|
|
$user['Courses'] = array($user['Courses']); |
|
|
|
|
} |
|
|
|
|
if (is_array($user['Courses'])) { |
|
|
|
|
foreach ($user['Courses'] as $course) { |
|
|
|
|
if (CourseManager::course_exists($course)) { |
|
|
|
|
CourseManager::subscribe_user($user_id, $course, $user['Status']); |
|
|
|
|
$course_info = CourseManager::get_course_information($course); |
|
|
|
|
$inserted_in_course[$course] = $course_info['title']; |
|
|
|
|
} |
|
|
|
|
if (CourseManager :: course_exists($course, true)) { |
|
|
|
|
// Also subscribe to virtual courses through check on visual code. |
|
|
|
|
$list = CourseManager :: get_courses_info_from_visual_code($course); |
|
|
|
|
foreach ($list as $vcourse) { |
|
|
|
|
if ($vcourse['code'] == $course) { |
|
|
|
|
// Ignore, this has already been inserted. |
|
|
|
|
} else { |
|
|
|
|
CourseManager :: subscribe_user($user_id, $vcourse['code'], $user['Status']); |
|
|
|
|
$inserted_in_course[$vcourse['code']] = $vcourse['title']; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (!empty($user['ClassId'])) { |
|
|
|
|
$classId = explode('|', trim($user['ClassId'])); |
|
|
|
|
foreach ($classId as $id) { |
|
|
|
|
$usergroup->subscribe_users_to_usergroup($id, array($user_id), false); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Saving extra fields. |
|
|
|
|
global $extra_fields; |
|
|
|
|
|
|
|
|
|
// We are sure that the extra field exists. |
|
|
|
|
foreach ($extra_fields as $extras) { |
|
|
|
|
if (isset($user[$extras[1]])) { |
|
|
|
|
$key = $extras[1]; |
|
|
|
|
$value = $user[$extras[1]]; |
|
|
|
|
UserManager::update_extra_field_value($user_id, $key, $value); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Read the CSV-file |
|
|
|
|