+
+ $current_users = fetchAllUsers();
+
+ // Check form action
+ if ($_POST['action'] === "Download") // Download list of users and populate the text area
+ {
+
+ foreach ($current_users as $u)
+ {
+ if ($u['user_name'] !== "admin")
+ $text_area=$text_area."\n".$u['user_name'].",".$u['display_name'].",".$u['email'];
+ }
+ }
+ else if ($_POST['action'] === "Upload") // Upload users in the text area
+ {
+
+ $text_area = $_POST['userUpload'];
+
+
+ // Iterate through each row
+ $all_rows=preg_split("/((\r?\n)|(\r\n?))/", $_POST['userUpload']);
+
+
+
+
+ foreach ($all_rows as $row)
+ {
+ if (empty($row) or $row[0] === '#')
+ continue;
+
+ $errors = array();
+
+ $fields = preg_split("/,/", $row);
+
+ $user_name = trim($fields[0]);
+ $display_name = trim($fields[1]);
+ $email = trim($fields[2]);
+ // generate the temporary password
+ $password = generatePassword();
+
+
+ if(count($errors) == 0)
+ {
+ //Construct a user object
+ $user = new User($username,$displayname,$password,$email);
+
+ //Checking this flag tells us whether there were any errors such as possible data duplication occured
+ if(!$user->status)
+ {
+ if($user->username_taken) $errors[] = lang("ACCOUNT_USERNAME_IN_USE",array($username));
+ if($user->displayname_taken) $errors[] = lang("ACCOUNT_DISPLAYNAME_IN_USE",array($displayname));
+ if($user->email_taken) $errors[] = lang("ACCOUNT_EMAIL_IN_USE",array($email));
+ }
+ else
+ {
+ //Attempt to add the user to the database, carry out finishing tasks like emailing the user (if required)
+ if(!$user->userCakeAddUser())
+ {
+ if($user->mail_failure) $errors[] = lang("MAIL_ERROR");
+ if($user->sql_failure) $errors[] = lang("SQL_ERROR");
+ }
+ }
+ }
+ if(count($errors) == 0)
+ {
+ $successes[] = $user->success;
+ }
+
+ echo resultBlock($errors,$successes);
+ }
+
+
+
+
+
+ }
+
+