You are here

function userprotect_up_add_validate in User protect 6

Same name and namespace in other branches
  1. 5 userprotect.module \userprotect_up_add_validate()
  2. 7 userprotect.admin.inc \userprotect_up_add_validate()

Custom validation function for adding a user for protection.

1 string reference to 'userprotect_up_add_validate'
userprotect_protections_bypass in ./userprotect.module
Helper funtion. Builds tables for protected users and admin bypass.

File

./userprotect.module, line 644

Code

function userprotect_up_add_validate($form, &$form_state) {

  // 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_fetch_array(db_query("SELECT uid FROM {userprotect} WHERE uid = %d AND up_type = '%s'", $uid, $type))) {
        if ($uid != 1 && $type == 'admin' && !db_fetch_array(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, $form_state);
        }
      }
      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.'));
    }
  }
}