@@ -53,13 +53,13 @@ function validate_data($users, $checkUniqueEmail = false)
5353 $ errors [] = $ user ;
5454 }
5555 // 2.2. Check whether the username was used twice in import file.
56- if (isset ($ usernames [$ user [ ' UserName ' ] ])) {
56+ if (isset ($ usernames [$ username ])) {
5757 $ user ['error ' ] = get_lang ('UserNameUsedTwice ' );
5858 $ errors [] = $ user ;
5959 }
60- $ usernames [$ user [ ' UserName ' ] ] = 1 ;
60+ $ usernames [$ username ] = 1 ;
6161 // 2.3. Check whether username is already occupied.
62- if (!UserManager::is_username_available ($ user [ ' UserName ' ] )) {
62+ if (!UserManager::is_username_available ($ username )) {
6363 $ user ['error ' ] = get_lang ('UserNameNotAvailable ' );
6464 $ errors [] = $ user ;
6565 }
@@ -260,8 +260,21 @@ function save_data($users)
260260 */
261261function parse_csv_data ($ file )
262262{
263- $ users = Import :: csvToArray ($ file );
263+ $ users = Import::csvToArray ($ file );
264+ $ allowRandom = api_get_configuration_value ('generate_random_login ' );
265+ if ($ allowRandom ) {
266+ $ factory = new RandomLib \Factory ;
267+ $ generator = $ factory ->getLowStrengthGenerator ();
268+ $ chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ' ;
269+ }
270+
264271 foreach ($ users as $ index => $ user ) {
272+ if (isset ($ user ['UserName ' ])) {
273+ if ($ allowRandom ) {
274+ $ username = $ generator ->generateString (10 , $ chars );
275+ $ user ['UserName ' ] = $ username ;
276+ }
277+ }
265278 if (isset ($ user ['Courses ' ])) {
266279 $ user ['Courses ' ] = explode ('| ' , trim ($ user ['Courses ' ]));
267280 }
@@ -485,7 +498,7 @@ function parse_xml_data($file)
485498 }
486499}
487500
488- Display :: display_header ($ tool_name );
501+ Display:: display_header ($ tool_name );
489502
490503$ form = new FormValidator ('user_import ' , 'post ' , api_get_self ());
491504$ form ->addElement ('header ' , '' , $ tool_name );
0 commit comments