4 * This file is not part of the original UserCake system, but uses it.
7 require_once("models/config.php");
8 if (!securePage($_SERVER['PHP_SELF'])){die();}
10 require_once("models/header.php");
12 $text_area="# Rows starting with '#' are ignored. Rows are of the form:\n# username, Full Name, email";
19 $current_users = fetchAllUsers();
22 if ($_POST['action'] === "Download") // Download list of users and populate the text area
25 foreach ($current_users as $u)
27 if ($u['user_name'] !== "admin")
28 $text_area=$text_area."\n".$u['user_name'].",".$u['display_name'].",".$u['email'];
31 else if ($_POST['action'] === "Upload") // Upload users in the text area
34 $text_area = $_POST['userUpload'];
37 // Iterate through each row
38 $all_rows=preg_split("/((\r?\n)|(\r\n?))/", $_POST['userUpload']);
43 foreach ($all_rows as $row)
45 if (empty($row) or $row[0] === '#')
50 $fields = preg_split("/,/", $row);
52 $user_name = trim($fields[0]);
53 $display_name = trim($fields[1]);
54 $email = trim($fields[2]);
55 // generate the temporary password
56 $password = generatePassword();
59 if(count($errors) == 0)
61 //Construct a user object
62 $user = new User($username,$displayname,$password,$email);
64 //Checking this flag tells us whether there were any errors such as possible data duplication occured
67 if($user->username_taken) $errors[] = lang("ACCOUNT_USERNAME_IN_USE",array($username));
68 if($user->displayname_taken) $errors[] = lang("ACCOUNT_DISPLAYNAME_IN_USE",array($displayname));
69 if($user->email_taken) $errors[] = lang("ACCOUNT_EMAIL_IN_USE",array($email));
73 //Attempt to add the user to the database, carry out finishing tasks like emailing the user (if required)
74 if(!$user->userCakeAddUser())
76 if($user->mail_failure) $errors[] = lang("MAIL_ERROR");
77 if($user->sql_failure) $errors[] = lang("SQL_ERROR");
81 if(count($errors) == 0)
83 $successes[] = $user->success;
86 echo resultBlock($errors,$successes);
100 /* I can't get fucking file uploads to fucking work with fucking nginx
101 echo "<p> Please provide a CSV file of usernames and email addresses. </p>
102 <p> Click <a href=\"upload_users_example.csv\">here</a> for an example file. </p>
103 <div class=\"title\">Upload</div>
104 <form action=\"".$_SERVER['PHP_SELF']."\" enctype=\"multipart/form-data\" method=\"post\">
105 <input type=\"file\" name=\"userUpload\"/>
106 <input type=\"submit\" value=\"Upload\"/>
111 <form action=\"".$_SERVER['PHP_SELF']."\" method=\"POST\">
112 <p> Action to take on adding users: </p>
113 <p> <input type=\"radio\" name=\"upload_mode\" value=\"keep\" checked/>Keep existing users and add these users</p>
114 <p> <input type=\"radio\" name=\"upload_mode\" value=\"purge\"/>Purge existing users and add these users</p>
115 <input type=\"submit\" name=\"action\" value=\"Upload\"/>
116 <input type=\"submit\" name=\"action\" value=\"Download\"/>
117 <input type=\"submit\" name=\"action\" value=\"Reset\"/>
118 <p> Enter or copy/paste user information below (resize the text area if necessary): </p>
120 <textarea name=\"userUpload\" rows=\"50\" cols=\"100\">".$text_area."</textarea> </p>