function userprotect_up_add_validate in User protect 5
Same name and namespace in other branches
- 6 userprotect.module \userprotect_up_add_validate()
- 7 userprotect.admin.inc \userprotect_up_add_validate()
Custom validation function for adding a user for protection.
Parameters
$form The textfield to validate.:
File
- ./
userprotect.module, line 579
Code
function userprotect_up_add_validate($form) {
// If a user has been submitted
if ($username = $form['#value']) {
$type = $form['#userprotect_type'];
// If the user is valid, and they are not already being protected...
if ($uid = db_result(db_query("SELECT uid FROM {users} WHERE name = '%s'", $username))) {
if (!db_num_rows(db_query("SELECT uid FROM {userprotect} WHERE uid = %d AND up_type = '%s'", $uid, $type))) {
if ($uid != 1 && $type == 'admin' && !db_num_rows(db_query("SELECT u.uid FROM {users} u INNER JOIN {users_roles} ur ON u.uid = ur.uid LEFT JOIN {permission} p ON ur.rid = p.rid WHERE p.perm IS NOT NULL AND p.perm LIKE '%%administer users%%' AND u.uid = %d", $uid))) {
form_set_error('up_add', t('%user does not have user administration privileges.', array(
'%user' => $username,
)));
}
else {
// Transform the username into a uid.
form_set_value($form, $uid);
}
}
else {
form_set_error('up_add', t('%user is already on this list.', array(
'%user' => $username,
)));
}
}
else {
form_set_error('up_add', t('The username is invalid.'));
}
}
}