Commit e03d40b4 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Enforce max user account limit on csv upload

parent f26f85b1
......@@ -263,8 +263,7 @@ function uploadcsv_validate(Pieform $form, $values) {
function uploadcsv_submit(Pieform $form, $values) {
log_info('Inserting users from the CSV file');
$formatkeylookup = array_flip($FORMAT);
// Don't be tempted to use 'explode' here. There may be > 1 underscore.
......@@ -273,6 +272,20 @@ function uploadcsv_submit(Pieform $form, $values) {
$institution = substr($values['authinstance'], $break+1);
$institution = new Institution($institution);
$maxusers = $institution->maxuseraccounts;
if (!empty($maxusers)) {
$members = count_records_sql('
SELECT COUNT(*) FROM {usr} u INNER JOIN {usr_institution} i ON = i.usr
WHERE i.institution = ? AND u.deleted = 0', array($institution->name));
if ($members + count($CSVDATA) > $maxusers) {
$SESSION->add_error_msg(get_string('uploadcsvfailedusersexceedmaxallowed', 'admin'));
log_info('Inserting users from the CSV file');
foreach ($CSVDATA as $record) {
log_debug('adding user ' . $record[$formatkeylookup['username']]);
$user = new StdClass;
......@@ -210,6 +210,7 @@ $string['uploadcsvpagedescription'] = '<p>You may use this facility to upload ne
$string['uploadcsvusersaddedsuccessfully'] = 'The users in the file have been added successfully';
$string['uploadcsvfailedusersexceedmaxallowed'] = 'No users have been added because there are too many users in your file. The number of users in the institution would have exceeded the maximum number allowed.';
// Admin Users
$string['adminuserspagedescription'] = '<p>Here you can choose which users are administrators for the site. The current administrators are listed on the right, and potential administrators are on the left.</p><p>The system must have at least one administrator.</p>';
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment