You are here

function user_admin_perm_submit in Drupal 6

Same name and namespace in other branches
  1. 4 modules/user.module \user_admin_perm_submit()
  2. 5 modules/user/user.module \user_admin_perm_submit()

File

modules/user/user.admin.inc, line 571
Admin page callback file for the user module.

Code

function user_admin_perm_submit($form, &$form_state) {

  // Save permissions:
  $result = db_query('SELECT * FROM {role}');
  while ($role = db_fetch_object($result)) {
    if (isset($form_state['values'][$role->rid])) {

      // Delete, so if we clear every checkbox we reset that role;
      // otherwise permissions are active and denied everywhere.
      db_query('DELETE FROM {permission} WHERE rid = %d', $role->rid);
      $form_state['values'][$role->rid] = array_filter($form_state['values'][$role->rid]);
      if (count($form_state['values'][$role->rid])) {
        db_query("INSERT INTO {permission} (rid, perm) VALUES (%d, '%s')", $role->rid, implode(', ', array_keys($form_state['values'][$role->rid])));
      }
    }
  }
  drupal_set_message(t('The changes have been saved.'));

  // Clear the cached pages
  cache_clear_all();
}