You are here

function userprotect_protections_bypass_submit in User protect 7

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

Processes the submitted user protection form.

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

File

./userprotect.admin.inc, line 227
Administration functions for userprotect module.

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) {
      $fields = 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) {
        $fields[$protection] = $protections[$protection] ? 1 : 0;
      }

      // Update the user's protections.
      db_update('userprotect')
        ->fields($fields)
        ->condition('uid', $uid)
        ->condition('up_type', $type)
        ->execute();
    }
    if ($type == 'user') {
      drupal_set_message(t('Protection settings updated.'));
    }
    elseif ($type == 'admin') {
      drupal_set_message(t('Bypass settings updated.'));
    }
  }
}