You are here

function userprotect_protections_bypass_submit in User protect 6

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

Processes the submitted user protection form.

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

File

./userprotect.module, line 675

Code

function userprotect_protections_bypass_submit($form, &$form_state) {
  $type = $form_state['values']['userprotect_type'];

  // A user was added, so add them to the protected users table.
  if ($uid = $form_state['values']['up_add']) {
    userprotect_add_user($uid, $type);
    $username = userprotect_get_username($uid);
    if ($type == 'user') {
      drupal_set_message(t('%user is now protected.', array(
        '%user' => $username,
      )));
    }
    elseif ($type == 'admin') {
      drupal_set_message(t('%user now has bypass capabilities matching the default protections for newly protected users.', array(
        '%user' => $username,
      )));
    }
  }
  if (isset($form_state['values']['protection'])) {

    // Load the defaults as a reference to all protections.
    $protections_values = userprotect_user_protection_defaults();

    // Loop through each user.
    foreach ($form_state['values']['protection'] as $uid => $protections) {
      $updates = array();
      $args = array();

      // Loop through the submitted user's protections, setting them enabled or
      // disabled as appropriate for the update query. Note: $protection is
      // a module generated string, so it's safe.
      foreach ($protections_values as $protection => $value) {
        $updates[] = "{$protection} = %d";
        $args[] = $protections[$protection] ? 1 : 0;
      }
      $args[] = $uid;
      $args[] = $type;

      // Update the user's protections.
      db_query("UPDATE {userprotect} SET " . implode(', ', $updates) . " WHERE uid = %d AND up_type = '%s'", $args);
    }
    if ($type == 'user') {
      drupal_set_message(t('Protection settings updated.'));
    }
    elseif ($type == 'admin') {
      drupal_set_message(t('Bypass settings updated.'));
    }
  }
}