function user_admin_perm in Drupal 5
Same name and namespace in other branches
- 4 modules/user.module \user_admin_perm()
- 6 modules/user/user.admin.inc \user_admin_perm()
Menu callback: administer permissions.
1 string reference to 'user_admin_perm'
- user_menu in modules/
user/ user.module - Implementation of hook_menu().
File
- modules/
user/ user.module, line 1817 - Enables the user registration and login system.
Code
function user_admin_perm($rid = NULL) {
if (is_numeric($rid)) {
$result = db_query('SELECT r.rid, p.perm FROM {role} r LEFT JOIN {permission} p ON r.rid = p.rid WHERE r.rid = %d', $rid);
}
else {
$result = db_query('SELECT r.rid, p.perm FROM {role} r LEFT JOIN {permission} p ON r.rid = p.rid ORDER BY name');
}
// Compile role array:
// Add a comma at the end so when searching for a permission, we can
// always search for "$perm," to make sure we do not confuse
// permissions that are substrings of each other.
while ($role = db_fetch_object($result)) {
$role_permissions[$role->rid] = $role->perm . ',';
}
if (is_numeric($rid)) {
$result = db_query('SELECT rid, name FROM {role} r WHERE r.rid = %d ORDER BY name', $rid);
}
else {
$result = db_query('SELECT rid, name FROM {role} ORDER BY name');
}
$role_names = array();
while ($role = db_fetch_object($result)) {
$role_names[$role->rid] = $role->name;
}
// Render role/permission overview:
$options = array();
foreach (module_list(FALSE, FALSE, TRUE) as $module) {
if ($permissions = module_invoke($module, 'perm')) {
$form['permission'][] = array(
'#value' => $module,
);
asort($permissions);
foreach ($permissions as $perm) {
$options[$perm] = '';
$form['permission'][$perm] = array(
'#value' => t($perm),
);
foreach ($role_names as $rid => $name) {
// Builds arrays for checked boxes for each role
if (strpos($role_permissions[$rid], $perm . ',') !== FALSE) {
$status[$rid][] = $perm;
}
}
}
}
}
// Have to build checkboxes here after checkbox arrays are built
foreach ($role_names as $rid => $name) {
$form['checkboxes'][$rid] = array(
'#type' => 'checkboxes',
'#options' => $options,
'#default_value' => $status[$rid],
);
$form['role_names'][$rid] = array(
'#value' => $name,
'#tree' => TRUE,
);
}
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save permissions'),
);
return $form;
}