You are here

function asset_wizard_directory_options in Asset 5

Same name and namespace in other branches
  1. 6 asset_wizard.inc \asset_wizard_directory_options()
  2. 6 inc/asset_wizard.inc \asset_wizard_directory_options()
2 calls to asset_wizard_directory_options()
asset_import_form in asset_import/asset_import.module
asset_wizard_default_fields in ./asset_wizard.inc
This is the base form for asset types.

File

./asset_wizard.inc, line 810

Code

function asset_wizard_directory_options($dir = '') {
  global $user;

  // build directory list and filename options array
  $sql = 'SELECT DISTINCT(a.aid),a.dirname FROM {asset} a ';
  $args = array();

  // for everyone but users with 'administer assets' access control,
  // only get assets with proper permissions.
  if (user_access('administer assets')) {
    $sql .= 'WHERE a.dirname LIKE \'%s%\' ';
    $args = array(
      $dir,
    );
  }
  else {
    $sql .= 'LEFT JOIN {asset_role} r ON a.aid=r.aid ' . 'WHERE (a.uid = %d ' . 'OR a.status = 1 ' . 'OR (r.rid IN (%s) AND r.status = 1) ) ' . 'AND a.dirname LIKE \'%s%\' ';
    $args = array(
      $user->uid,
      join(array_keys($user->roles), ','),
      $dir,
    );

    // $sql .= 'WHERE a.dirname="%s" ';
    // $args = array($dir);
  }
  $sql .= ' AND a.type = \'directory\' ORDER BY a.dirname ASC';
  $result = db_query($sql, $args);
  $options = array();
  while ($asset = db_fetch_object($result)) {
    $asset = asset_load($asset->aid);
    $dir = $asset->dirname . ($asset->dirname ? '/' : '') . $asset->filename;
    $parts = explode('/', $dir);
    if (count($parts)) {
      $name = str_repeat('--', count($parts)) . ' ' . $asset->title;
    }
    else {
      $name = $asset->title;
    }
    $options[$dir] = $name;
  }
  if (user_access('administer assets')) {
    $options[''] = 'assets';
  }
  ksort($options);
  return $options;
}