/** * Update users from 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 updateUsers($users) { global $insertedIn_course; // Not all scripts declare the $inserted_in_course array (although they should). if (!isset($inserted_in_course)) { $inserted_in_course = array(); } $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']); $userName = $user['UserName']; $userInfo = api_get_user_info_from_username($userName); $user_id = $userInfo['user_id']; if ($user_id == 0) { return false; } $firstName = isset($user['FirstName']) ? $user['FirstName'] : $userInfo['firstname']; $lastName = isset($user['LastName']) ? $user['LastName'] : $userInfo['lastname']; $userName = isset($user['NewUserName']) ? $user['NewUserName'] : $userInfo['username']; $password = isset($user['Password']) ? $user['Password'] : $userInfo['password']; $authSource = isset($user['AuthSource']) ? $user['AuthSource'] : $userInfo['auth_source']; $email = isset($user['Email']) ? $user['Email'] : $userInfo['email']; $status = isset($user['Status']) ? $user['Status'] : $userInfo['status']; $officialCode = isset($user['OfficialCode']) ? $user['OfficialCode'] : $userInfo['official_code']; $phone = isset($user['PhoneNumber']) ? $user['PhoneNumber'] : $userInfo['phone']; $pictureUrl = isset($user['PictureUri']) ? $user['PictureUri'] : $userInfo['picture_uri']; $expirationDate = isset($user['ExpiryDate']) ? $user['ExpiryDate'] : $userInfo['expiration_date']; $active = isset($user['Active']) ? $user['Active'] : $userInfo['active']; $creatorId = $userInfo['creator_id']; $hrDeptId = $userInfo['hr_dept_id']; $language = isset($user['Language']) ? $user['Language'] : $userInfo['language']; $sendEmail = isset($user['SendEmail']) ? $user['SendEmail'] : $userInfo['language']; $userUpdated = UserManager::update_user($user_id, $firstName, $lastName, $userName, $password, $authSource, $email, $status, $officialCode, $phone, $pictureUrl, $expirationDate, $active, $creatorId, $hrDeptId, null, $language, '', '', ''); 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 (!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); } } } } }
/** * Save the imported data */ function save_data($users) { $user_table = Database::get_main_table(TABLE_MAIN_USER); if (is_array($users)) { foreach ($users as $index => $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'], api_get_setting('PlatformLanguage'), $user['PhoneNumber'], '', $user['AuthSource']); foreach ($user['Courses'] as $index => $course) { if (CourseManager::course_exists($course)) { CourseManager::subscribe_user($user_id, $course, $user['Status']); } } if (strlen($user['ClassName']) > 0) { $class_id = ClassManager::get_class_id($user['ClassName']); ClassManager::add_user($user_id, $class_id); } // TODO: Hard-coded French texts. // Qualite if (!empty($user['Qualite'])) { UserManager::update_extra_field_value($user_id, 'qualite', $user['Qualite']); } // Categorie if (!empty($user['Categorie'])) { UserManager::update_extra_field_value($user_id, 'categorie', $user['Categorie']); } // Etat if (!empty($user['Etat'])) { UserManager::update_extra_field_value($user_id, 'etat', $user['Etat']); } // Niveau if (!empty($user['Niveau'])) { UserManager::update_extra_field_value($user_id, 'niveau', $user['Niveau']); } } } }
/** * 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(); } $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'], $user['ExpiryDate'], 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 (!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); } } } } }
/** * Save the imported data * @param array 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(); } $send_mail = $_POST['sendMail'] ? 1 : 0; if (is_array($users)) { foreach ($users as $index => $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 $index => $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['ClassName'])) { $class_id = ClassManager::get_class_id($user['ClassName']); ClassManager::add_user($user_id, $class_id); } // 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); } } } } }