Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
mahara
mahara
Commits
684ddc35
Commit
684ddc35
authored
Aug 12, 2008
by
Richard Mansfield
Browse files
Check for duplicate usernames, emails within the same CSV file
parent
fa632d87
Changes
1
Hide whitespace changes
Inline
Side-by-side
htdocs/admin/users/uploadcsv.php
View file @
684ddc35
...
...
@@ -172,6 +172,8 @@ function uploadcsv_validate(Pieform $form, $values) {
return
;
}
$usernames
=
array
();
$emails
=
array
();
$conf
=
File_CSV
::
discoverFormat
(
$values
[
'file'
][
'tmp_name'
]);
$i
=
0
;
while
(
$line
=
File_CSV
::
readQuoted
(
$values
[
'file'
][
'tmp_name'
],
$conf
))
{
...
...
@@ -233,11 +235,11 @@ function uploadcsv_validate(Pieform $form, $values) {
$form
->
set_error
(
'file'
,
get_string
(
'uploadcsverrorinvalidusername'
,
'admin'
,
$i
));
return
;
}
if
(
record_exists_select
(
'usr'
,
'LOWER(username) = ?'
,
strtolower
(
$username
)))
{
if
(
record_exists_select
(
'usr'
,
'LOWER(username) = ?'
,
strtolower
(
$username
))
||
isset
(
$usernames
[
strtolower
(
$username
)])
)
{
$form
->
set_error
(
'file'
,
get_string
(
'uploadcsverroruseralreadyexists'
,
'admin'
,
$i
,
$username
));
return
;
}
if
(
record_exists
(
'usr'
,
'email'
,
$email
))
{
if
(
record_exists
(
'usr'
,
'email'
,
$email
)
||
isset
(
$emails
[
$email
])
)
{
$form
->
set_error
(
'file'
,
get_string
(
'uploadcsverroremailaddresstaken'
,
'admin'
,
$i
,
$email
));
}
...
...
@@ -249,6 +251,9 @@ function uploadcsv_validate(Pieform $form, $values) {
return
;
}
$usernames
[
strtolower
(
$username
)]
=
1
;
$emails
[
$email
]
=
1
;
// All OK!
$CSVDATA
[]
=
$line
;
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment