You are here

function _regcode_voucher_accesscheck in Registration codes 6.2

Same name and namespace in other branches
  1. 6 regcode_voucher/regcode_voucher.module \_regcode_voucher_accesscheck()
  2. 7.2 regcode_voucher/regcode_voucher.module \_regcode_voucher_accesscheck()
  3. 7 regcode_voucher/regcode_voucher.module \_regcode_voucher_accesscheck()

Check whether an account has access to the voucher system

1 call to _regcode_voucher_accesscheck()
regcode_voucher_user in regcode_voucher/regcode_voucher.module
Implementation of hook_user().
1 string reference to '_regcode_voucher_accesscheck'
regcode_voucher_menu in regcode_voucher/regcode_voucher.module
Implementation of hook_menu().

File

regcode_voucher/regcode_voucher.module, line 223

Code

function _regcode_voucher_accesscheck($account, $context = '') {

  // Do not show for other users
  global $user;
  if ($account->uid != $user->uid) {
    return FALSE;
  }

  // Pages enabled
  $enabled = array_filter(variable_get('regcode_voucher_display', array()));
  if (!in_array($context, $enabled)) {
    return FALSE;
  }

  // Role based access
  $allowed = array_filter(variable_get('regcode_voucher_allowed_roles', array()));
  $disallowed = array_filter(variable_get('regcode_voucher_disallowed_roles', array()));
  $access = FALSE;
  foreach ($account->roles as $rid => $role) {
    if (isset($allowed[$rid])) {
      $access = TRUE;
    }
  }
  foreach ($account->roles as $rid => $role) {
    if (isset($disallowed[$rid])) {
      $access = FALSE;
    }
  }
  return $access;
}