You are here

function forena_block_access in Forena Reports 6

Same name and namespace in other branches
  1. 7 forena.common.inc \forena_block_access()

Check access control using the block in a data block. In this case public assess returns true.

Parameters

$block Repository block used to test access:

$path xpath to user right within xml data.:

$access Access to test:

Return value

unknown_type

1 call to forena_block_access()
FrxDataProvider::access in ./FrxDataProvider.inc
Implements the basic default security check of calling an access method.

File

./forena.common.inc, line 89
Common functions used throughout the project but loaded in this file to keep the module file lean.

Code

function forena_block_access($block, $path, $access, $cache = TRUE) {
  if ($access == 'PUBLIC') {
    return TRUE;
  }
  if (!isset($_SESSION['forena_access'])) {
    $_SESSION['forena_access'] = array();
  }
  if ($cache && isset($_SESSION['forena_access'][$block])) {
    $rights = $_SESSION['forena_access'][$block];
  }
  else {
    $rights = array();

    // Get the block from the repository
    $data = forena_invoke_data_provider($block, array(), null);
    if ($data) {
      if (!$path) {
        $path = '*/*';
      }
      $nodes = $data
        ->xpath($path);
      if ($nodes) {
        foreach ($nodes as $node) {
          $rights[] = (string) $node;
        }
      }
      $_SESSION['forena_access'][$block] = $rights;
    }
  }
  foreach ($rights as $right) {
    if ($access == $right) {
      return TRUE;
    }
  }
  return FALSE;
}