function userprotect_protections_bypass_submit in User protect 5
Same name and namespace in other branches
- 6 userprotect.module \userprotect_protections_bypass_submit()
- 7 userprotect.admin.inc \userprotect_protections_bypass_submit()
Processes the submitted user protection form.
Parameters
$form_id The form ID.:
$form_values The submitted form values.:
File
- ./
userprotect.module, line 613
Code
function userprotect_protections_bypass_submit($form_id, $form_values) {
$type = $form_values['userprotect_type'];
// A user was added, so add them to the protected users table.
if ($uid = $form_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 (is_array($form_values['protection'])) {
// Load the defaults as a reference to all protections.
$protections_values = userprotect_user_protection_defaults();
// Loop through each user.
foreach ($form_values['protection'] as $uid => $protections) {
$updates = array();
// Loop through the submitted user's protections, setting them enabled or
// disabled as appropriate for the update query.
foreach ($protections_values as $protection => $value) {
$updates[] = "{$protection} = " . ($protections[$protection] ? '1' : '0');
}
// Update the user's protections.
db_query("UPDATE {userprotect} SET %s WHERE uid = %d AND up_type = '%s'", implode(', ', $updates), $uid, $type);
}
if ($type == 'user') {
drupal_set_message(t('Protection settings updated.'));
}
elseif ($type == 'admin') {
drupal_set_message(t('Bypass settings updated.'));
}
}
}