You are here

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

Same name and namespace in other branches
  1. 8.2 modules/merci_permissions/merci_permissions.module \merci_permissions_settings_form_submit()
  2. 6.2 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()
1 string reference to 'merci_permissions_settings_form_submit'
merci_permissions_add_form in modules/merci_permissions/merci_permissions.module

File

modules/merci_permissions/merci_permissions.module, line 195
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_perm();
  while ($role = db_fetch_object($result)) {
    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) = split(' ', $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);
          }
        }
        else {
          if (strstr('admin all reservations', $key)) {
            foreach ($merci_types as $type => $name) {
              $perms[] = "edit own {$type} content";
              $perms[] = "delete own {$type} content";
              $perms[] = "delete any {$type} content";
              $perms[] = "edit any {$type} content";
            }
            if ($value) {
              $add_perms = array_merge($perms, $add_perms);
            }
            else {
              $revoke_perms = array_merge($perms, $revoke_perms);
            }
          }
          else {
            if (in_array($key, $merci_perms)) {
              if ($value) {
                $add_perms[] = $key;
              }
              else {
                $revoke_perms[] = $key;
              }
            }
          }
        }
      }
      merci_permissions_revoke_permissions($role->name, $revoke_perms);
      merci_permissions_grant_permissions($role->name, $add_perms);
    }
  }
}