You are here

function merci_permissions_settings_form_submit in MERCI (Manage Equipment Reservations, Checkout and Inventory) 8.2

Same name and namespace in other branches
  1. 6.2 modules/merci_permissions/merci_permissions.module \merci_permissions_settings_form_submit()
  2. 6 modules/merci_permissions/merci_permissions.module \merci_permissions_settings_form_submit()
  3. 7.2 modules/merci_permissions/merci_permissions.module \merci_permissions_settings_form_submit()

@todo Please document this function.

See also

http://drupal.org/node/1354

1 string reference to 'merci_permissions_settings_form_submit'
merci_permissions_form in modules/merci_permissions/merci_permissions.module
@todo Please document this function.

File

modules/merci_permissions/merci_permissions.module, line 201
Provides functions for resetting permissions on the permission page.

Code

function merci_permissions_settings_form_submit($form, &$form_state) {
  $result = db_query('SELECT * FROM {role}');
  $merci_types = merci_permissions_load_merci_type_settings();
  $merci_perms = merci_permission();
  foreach ($result as $role) {
    if (isset($form_state['values'][$role->rid])) {
      $add_perms = array();
      $revoke_perms = array();
      foreach ($form_state['values'][$role->rid] as $key => $value) {
        list($cruft, $type) = explode(' ', $key);
        $perms = array();
        if (array_key_exists($type, $merci_types)) {
          $perms[] = "edit own {$type} content";
          $perms[] = "delete own {$type} content";
          if ($value) {
            $add_perms = array_merge($perms, $add_perms);
          }
          else {
            $revoke_perms = array_merge($perms, $revoke_perms);
          }
        }
        elseif (array_key_exists($key, $merci_perms)) {
          if ($value) {
            $add_perms[] = $key;
          }
          else {
            $revoke_perms[] = $key;
          }
        }
      }
      if (!empty($add_perms)) {
        user_role_grant_permissions($role->rid, $add_perms);
      }
      if (!empty($revoke_perms)) {
        user_role_revoke_permissions($role->rid, $revoke_perms);
      }
    }
  }
}