You are here

function filedepot_recursiveAccessArray in filedepot 6

Same name and namespace in other branches
  1. 7 lib-common.php \filedepot_recursiveAccessArray()

Returns a formatted listbox of categories user has access First checks for View access so that delegated admin can be just for sub-categories

Parameters

string|array $perms Single perm 'admin' or array of permissions as required by $filedepot->checkPermission():

int $selected Will make this item the selected item in the listbox:

string $id Parent category to start at and then recursively check:

string $level Used by this function as it calls itself to control the indent formatting:

Return value

string Return an array of folder options

1 call to filedepot_recursiveAccessArray()
filedepot_form in ./filedepot.module
Implementation of hook_form().

File

./lib-common.php, line 25
lib-common.php Common library of functions for the applications

Code

function filedepot_recursiveAccessArray($perms, $id = 0, $level = 1) {
  $filedepot = filedepot_filedepot();
  $options_tree = array();
  $query = db_query("SELECT cid,pid,name FROM {filedepot_categories} WHERE pid=%d ORDER BY cid", $id);
  while ($A = db_fetch_array($query)) {
    list($cid, $pid, $name) = array_values($A);
    $indent = ' ';

    // Check if user has access to this category
    if ($filedepot
      ->checkPermission($cid, 'view')) {

      // Check and see if this category has any sub categories - where a category record has this cid as it's parent
      $tempcid = db_result(db_query("SELECT cid FROM {filedepot_categories} WHERE pid=%d", $cid));
      if ($tempcid > 0) {
        if ($level > 1) {
          for ($i = 2; $i <= $level; $i++) {
            $indent .= "--";
          }
          $indent .= ' ';
        }
        if ($filedepot
          ->checkPermission($cid, $perms)) {
          if ($indent != '') {
            $name = " {$name}";
          }
          $options_tree[$cid] = $indent . $name;
          $options_tree += filedepot_recursiveAccessArray($perms, $cid, $level + 1);
        }
        else {

          // Need to check for any folders with admin even subfolders of parents that user does not have access
          $options_tree += filedepot_recursiveAccessArray($perms, $cid, $level + 1);
        }
      }
      else {
        if ($level > 1) {
          for ($i = 2; $i <= $level; $i++) {
            $indent .= "--";
          }
          $indent .= ' ';
        }
        if ($filedepot
          ->checkPermission($cid, $perms)) {
          if ($indent != '') {
            $name = " {$name}";
          }
          $options_tree[$cid] = $indent . $name;
        }
      }
    }
  }
  return $options_tree;
}