/**
  * private functions which iterates through all folders and files 
  * and create an according file structure in a temporary directory. This function works recursive. 
  *
  * @param integer $refid reference it
  * @param tmpdictory $tmpdir
  * @return returns first created directory
  */
 private static function recurseFolder($refid, $title, $tmpdir)
 {
     global $rbacsystem, $tree, $ilAccess;
     $tmpdir = $tmpdir . DIRECTORY_SEPARATOR . ilUtil::getASCIIFilename($title);
     ilUtil::makeDir($tmpdir);
     $subtree = $tree->getChildsByTypeFilter($refid, array("fold", "file"));
     foreach ($subtree as $child) {
         if (!$ilAccess->checkAccess("read", "", $child["ref_id"])) {
             continue;
         }
         if (ilObject::_isInTrash($child["ref_id"])) {
             continue;
         }
         if ($child["type"] == "fold") {
             ilObjFolder::recurseFolder($child["ref_id"], $child["title"], $tmpdir);
         } else {
             $newFilename = $tmpdir . DIRECTORY_SEPARATOR . ilUtil::getASCIIFilename($child["title"]);
             // copy to temporal directory
             $oldFilename = ilObjFile::_lookupAbsolutePath($child["obj_id"]);
             if (!copy($oldFilename, $newFilename)) {
                 throw new ilFileException("Could not copy " . $oldFilename . " to " . $newFilename);
             }
             touch($newFilename, filectime($oldFilename));
         }
     }
 }
 private static function copyFile($obj_id, $title, $tmpdir)
 {
     $newFilename = $tmpdir . DIRECTORY_SEPARATOR . ilUtil::getASCIIFilename($title);
     // copy to temporary directory
     $oldFilename = ilObjFile::_lookupAbsolutePath($obj_id);
     if (!copy($oldFilename, $newFilename)) {
         throw new ilFileException("Could not copy " . $oldFilename . " to " . $newFilename);
     }
     touch($newFilename, filectime($oldFilename));
 }