You are here

function filedepot_recursiveAccessOptions in filedepot 6

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

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:

boolean $addRootOpt Add the 'Top Level Folder' option, when appropriate. Defaults to @c TRUE.:

Return value

string Return a formatted HTML Select listbox of categories

7 calls to filedepot_recursiveAccessOptions()
filedepotAjaxServer_loadFileDetails in ./lib-ajaxserver.php
template_preprocess_filedepot_activefolder_admin in ./lib-theme.php
template_preprocess_filedepot_main_page in ./filedepot.module
template_preprocess_filedepot_movefiles_form in ./lib-theme.php
template_preprocess_filedepot_moveincoming_form in ./lib-theme.php

... See full list

File

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

Code

function filedepot_recursiveAccessOptions($perms, $selected = '', $id = '0', $level = '1', $addRootOpt = TRUE) {
  $filedepot = filedepot_filedepot();
  $selectlist = '';
  if ($addRootOpt and $level == 1 and user_access('administer filedepot')) {
    $selectlist = '<option value="0">' . t('Top Level Folder') . '</option>' . LB;
  }
  $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);
    $name = filter_xss($name);
    $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}";
          }
          $selectlist .= '<option value="' . $cid;
          if ($cid == $selected) {
            $selectlist .= '" selected="selected">' . $indent . $name . '</option>' . LB;
          }
          else {
            $selectlist .= '">' . $indent . $name . '</option>' . LB;
          }
          $selectlist .= filedepot_recursiveAccessOptions($perms, $selected, $cid, $level + 1, $addRootOpt);
        }
        else {

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