You are here

function book_access_grant_check in Book access 6

Checks if a user has access to the book passed as argument.

Parameters

$bid: The ID of the book to check.

$grant: The permission to check for.

$account: The user account for which the permission is checked; if it is not passed, the permission is checked against the current logged in user.

Return value

TRUE if the user has the permission, FALSE otherwise.

2 calls to book_access_grant_check()
book_access_link_alter in ./book_access.module
Implements hook_link_alter().
book_access_outline_access in ./book_access.module
Determines if the outline tab is accessible.

File

./book_access.module, line 420
Allows access control for book nodes on a per book basis. It is based on forum_access.module and tac_lite.module.

Code

function book_access_grant_check($bid, $grant, $account = NULL) {
  if (!isset($account)) {
    $account = $GLOBALS['user'];
  }
  $roles = array_keys($account->roles);
  $result = db_result(db_query_range("SELECT 1 FROM {book_access_role} WHERE nid = %d AND rid IN (" . db_placeholders($roles) . ") AND grant_{$grant} > 0", array_merge(array(
    $bid,
  ), $roles), 0, 1)) || db_result(db_query_range("SELECT 1 FROM {book_access_user} WHERE nid = %d AND uid = %d AND grant_{$grant} > 0", $bid, $account->uid, 0, 1));
  return $result;
}