You are here

function imce_mkdir_rmdir_batch in IMCE Mkdir 7

Same name and namespace in other branches
  1. 6 imce_mkdir.inc \imce_mkdir_rmdir_batch()

Batch removes directories.

1 call to imce_mkdir_rmdir_batch()
imce_mkdir_rmdir_submit in ./imce_mkdir.inc
Submits rmdir form.

File

./imce_mkdir.inc, line 114

Code

function imce_mkdir_rmdir_batch(&$imce, $dirnames = array()) {
  if (!isset($imce['dirremoved'])) {
    $imce['dirremoved'] = array();
  }
  $parent = imce_dir_uri($imce);
  $prefix = $imce['dir'] == '.' ? '' : $imce['dir'] . '/';
  foreach ($dirnames as $dirname) {
    $index = array_search($dirname, $imce['subdirectories']);
    if ($index === FALSE) {
      drupal_set_message(t('Subdirectory %dir does not exist.', array(
        '%dir' => $dirname,
      )), 'error');
      continue;
    }
    if (isset($imce['directories'][$prefix . $dirname])) {
      drupal_set_message(t('Subdirectory %dir is a predefined directory and can not be removed.', array(
        '%dir' => $dirname,
      )), 'error');
      continue;
    }
    $dirpath = $parent . $dirname;
    if (!imce_mkdir_rmdir_recursive($dirpath)) {
      drupal_set_message(t('Subdirectory %dir could not be removed.', array(
        '%dir' => $dirname,
      )), 'error');
      continue;
    }
    drupal_set_message(t('Subdirectory %dir has been removed.', array(
      '%dir' => $dirname,
    )));
    $imce['dirremoved'] = array_merge($imce['dirremoved'], array_splice($imce['subdirectories'], $index, 1));
  }
}