function userprotect_protections_bypass in User protect 5
Same name and namespace in other branches
- 6 userprotect.module \userprotect_protections_bypass()
- 7 userprotect.admin.inc \userprotect_protections_bypass()
Helper funtion. Builds tables for protected users and admin bypass.
Return value
A form array representing the table.
2 calls to userprotect_protections_bypass()
- userprotect_administrator_bypass in ./
userprotect.module - Builds a table of user admin bypass values.
- userprotect_protected_users in ./
userprotect.module - Builds a table of protected users, and their protections.
File
- ./
userprotect.module, line 458
Code
function userprotect_protections_bypass($type) {
// Build the header.
$header = array(
array(
'data' => t('User'),
'field' => 'name',
'sort' => 'asc',
),
);
$protect_columns = userprotect_get_protection_display();
foreach ($protect_columns as $field => $data) {
$header[] = array(
'data' => $data,
'field' => $field,
);
}
$header[] = array(
'data' => t('Operations'),
);
// Grab the protected users.
$protected_users = pager_query("SELECT up.*, u.name FROM {userprotect} up INNER JOIN {users} u ON up.uid = u.uid WHERE up_type = '%s'" . tablesort_sql($header), 25, 0, NULL, $type);
// Set some initial values.
$delete = t('delete');
$options = array();
// These are all available protections.
$protections = array_keys(userprotect_user_protection_defaults());
// Pass in the header and list of protections to the form so they'll be available
// to the theming function.
$form = array();
$form['protection']['#tree'] = TRUE;
$form['#header'] = $header;
$form['#protections'] = $protections;
$form['#base'] = 'userprotect_protections_bypass';
// Build the checkboxes options.
foreach ($protections as $protection) {
$options[$protection] = '';
}
// For each protected user, build their table row.
while ($protected_user = db_fetch_object($protected_users)) {
$defaults = array();
$user = user_load(array(
'uid' => $protected_user->uid,
));
$form['user'][$user->uid]['uid'] = array(
'#type' => 'value',
'#value' => $user->uid,
);
$form[$user->uid]['name'] = array(
'#value' => theme('username', $user),
);
$form[$user->uid]['operations'] = array(
'#value' => $user->uid ? l($delete, "userprotect/delete/{$user->uid}/{$type}") : '',
);
// Build the protections for the user row.
foreach ($protections as $protection) {
if ($protected_user->{$protection}) {
$defaults[] = $protection;
}
}
// The checkboxes for this user.
$form['protection'][$user->uid] = array(
'#type' => 'checkboxes',
'#options' => $options,
'#default_value' => $defaults,
);
}
// An autocomplete field to add new users for protection.
// This needs a custom validation function to check the user
// to be added.
$form['up_add'] = array(
'#type' => 'textfield',
'#maxlength' => 60,
'#autocomplete_path' => 'user/autocomplete',
'#validate' => array(
'userprotect_up_add_validate' => array(),
),
'#userprotect_type' => $type,
);
$form['up_add_text'] = array(
'#value' => t('Add user'),
);
$form['userprotect_type'] = array(
'#type' => 'value',
'#value' => $type,
);
if ($pager = theme('pager', array(), 25, 0)) {
$form['pager'] = array(
'#value' => $pager,
);
}
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
);
return $form;
}