X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=testing%2FMCTXWeb%2Fpublic_html%2Fusers%2Fadmin_upload_users.php;h=53c71ce9ee8d8ac12f5fcc585d15eb7f6c44928e;hb=4c11eff00a00e4b744eff9a6633c1b5608844632;hp=d068f71b84e6f4e216f3c760c51f000ea48dfd76;hpb=dd239d26439d97188aa6cad06573a6584dc250a6;p=matches%2FMCTX3420.git diff --git a/testing/MCTXWeb/public_html/users/admin_upload_users.php b/testing/MCTXWeb/public_html/users/admin_upload_users.php index d068f71..53c71ce 100644 --- a/testing/MCTXWeb/public_html/users/admin_upload_users.php +++ b/testing/MCTXWeb/public_html/users/admin_upload_users.php @@ -1,24 +1,125 @@ Uploaded!

"; + + $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); + } + + + + + + } + + } -else + +if ($show_form) { + /* I can't get fucking file uploads to fucking work with fucking nginx echo "

Please provide a CSV file of usernames and email addresses.

+

Click here for an example file.

Upload
-
- + +
"; + */ + echo " + +
+

Action to take on adding users:

+

Keep existing users and add these users

+

Purge existing users and add these users

+ + + +

Enter or copy/paste user information below (resize the text area if necessary):

+

+

+ +
"; } ?>