Index: userplus.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/userplus/userplus.module,v retrieving revision 1.2 diff -u -p -r1.2 userplus.module --- userplus.module 14 Jun 2006 19:32:03 -0000 1.2 +++ userplus.module 5 Sep 2006 14:22:11 -0000 @@ -21,6 +21,10 @@ function userplus_help($section) { return t('
This web page allows you to set role membership for all users at once. You can change the number of rows that appear on this page on the %settings page.
', array('%settings' => l('userplus settings', 'admin/settings/userplus'))); case 'admin/user/userplus/deletemultiple': return t('This web page allows you to delete multiple users at one time. You can change the number of rows that appear on this page on the %settings page.
', array('%settings' => l('userplus settings', 'admin/settings/userplus'))); + case 'admin/user/userplus/move_roles': + if (!arg(4)) { + return t('Chose a role you want to move users away from.'); + } case 'admin/user/userplus/config': return t('This web page allows you to set configuration options for the "user +" module.
'); } @@ -60,6 +64,12 @@ function userplus_menu($may_cache) { 'callback' => 'userplus_delete_users', 'type' => MENU_LOCAL_TASK, 'weight' => 2); + $items[] = array('path' => 'admin/user/userplus/move_roles', + 'title' => t('role switching'), + 'access' => $admin_access, + 'callback' => 'userplus_roles_move', + 'type' => MENU_LOCAL_TASK, + 'weight' => 2); } return $items; @@ -487,3 +497,75 @@ function _userplus_validate_user($name = return true; } + +function userplus_roles_move($rid = 0) { + $roles = user_roles(1); + unset($roles[DRUPAL_AUTHENTICATED_RID]); + if ($rid) { + drupal_set_title(t("Remove users from role '%role'", array('%role' => check_plain($roles[$rid])))); + $result = pager_query('SELECT u.uid, u.name FROM {users} u INNER JOIN {users_roles} ur ON u.uid = ur.uid WHERE ur.uid > 0 AND ur.rid = %d ORDER BY u.name', 20, 0, NULL, $rid); + + $users = array(); + $form['#tree'] = TRUE; + while ($user = db_fetch_object($result)) { + $users[$user->uid] = ''; + $form['user'][$user->uid] = array('#type' => 'markup', '#value' => theme('username', $user)); + } + $form['users'] = array('#type' => 'checkboxes', '#options' => $users); + unset($roles[$rid]); + $form['roles'] = array( + '#type' => 'select', + '#title' => t('Move users to'), + '#options' => $roles, + '#description' => t('The selected users will get removed from the role shown above and assigned to the selected role.'), + ); + $form['rid'] = array('#type' => 'hidden', '#value' => $rid); + $form['submit'] = array('#type' => 'submit', '#value' => t('Move users')); + + return drupal_get_form('userplus_move_roles', $form); + } + else { + $output = array(); + foreach ($roles as $role_id => $role_name) { + $output[] = l($role_name, 'admin/user/userplus/move_roles/'. $role_id); + } + return implode(' ยท ', $output); + } +} + +/** + * Theme above form. + */ +function theme_userplus_move_roles($form) { + $header = array('', t('User')); + foreach (element_children($form['users']) as $key) { + $row = array(); + $row[] = form_render($form['users'][$key]); + $row[] = form_render($form['user'][$key]); + $rows[] = $row; + } + if (!count($rows)) { + $rows[] = array(array('data' => t('No users with this role available.'), 'colspan' => '2')); + } + $output .= theme('table', $header, $rows); + $output .= form_render($form['rid']); + if ($form['pager']['#value']) { + $output .= form_render($form['pager']); + } + + $output .= form_render($form); + return $output; +} + +function userplus_move_roles_submit($form_id, $form_values) { + $users = array(); + foreach ($form_values['users'] as $uid => $value) { + if ($uid == $value) { + $users[] = $uid; + } + } + if (count($users)) { + db_query("UPDATE {users_roles} SET rid = %d WHERE rid = %d AND uid IN (%s)", $form_values['roles'], $form_values['rid'], implode(',', $users)); + } +} +