You are here

public function filedepot::deleteFolder in filedepot 6

Same name and namespace in other branches
  1. 7 filedepot.class.php \filedepot::deleteFolder()

File

./filedepot.class.php, line 586
filedepot.class.php Main class for the Filedepot module

Class

filedepot
@file filedepot.class.php Main class for the Filedepot module

Code

public function deleteFolder($nid) {
  $deleteFolderId = db_result(db_query("SELECT cid FROM {filedepot_categories} WHERE nid=%d", $nid));

  /* Test for valid folder and admin permission one more time
   * We are going to override the permission test in the function filedepot_getRecursiveCatIDs()
   * and return all subfolders in case hidden folders exist for this user.
   * If this user has admin permission for parent -- then they should be able to delete it
   * and any subfolders.
   */
  if ($deleteFolderId > 0 and $this
    ->checkPermission($deleteFolderId, 'admin')) {

    // Need to delete all files in the folder

    /* Build an array of all linked categories under this category the user has admin access to */
    $list = array();
    array_push($list, $deleteFolderId);

    // Passing in permission check over-ride as noted above to filedepot_getRecursiveCatIDs()
    $list = filedepot_getRecursiveCatIDs($list, $deleteFolderId, 'admin', TRUE);
    foreach ($list as $cid) {
      $query = db_query("SELECT fid FROM {filedepot_files} WHERE cid=%d", $cid);
      while ($A = db_fetch_array($query)) {
        $this
          ->deleteFile($A['fid']);
      }
      $deleteNodeId = db_result(db_query("SELECT nid FROM {filedepot_categories} WHERE cid=%d", $cid));
      db_query("DELETE FROM {filedepot_categories} WHERE cid=%d", $cid);
      db_query("DELETE FROM {filedepot_access} WHERE catid=%d", $cid);
      db_query("DELETE FROM {filedepot_recentfolders} WHERE cid=%d", $cid);
      db_query("DELETE FROM {filedepot_notifications} WHERE cid=%d", $cid);
      db_query("DELETE FROM {filedepot_filesubmissions} WHERE cid=%d", $cid);
      db_query("DELETE FROM {node} WHERE nid=%d", $deleteNodeId);
      $catdir = $this->root_storage_path . $cid;
      if (file_exists($catdir)) {
        @unlink($this->root_storage_path . "{$cid}/.htaccess");
        @unlink($this->root_storage_path . "{$cid}/submissions/.htaccess");
        @rmdir("{$catdir}/submissions");
        @rmdir($catdir);
      }
    }
    return TRUE;
  }
  else {
    return FALSE;
  }
}