/** * Downloads a file, a folder or a bunch of either. * * @param String $entry_id Directory entry id of the file or folder or * 'flashed' for a bulk operation * @param bool $inline Indicates whether the download should be * marked as inline (to display the file in the * browser) */ public function index_action($entry_id, $inline = false) { $download_files = array(); $download_type = 'single'; $filename = null; // Download files from bulk-action? if ($entry_id === 'flashed') { foreach ($this->flash['ids'] as $id) { $entry = new DirectoryEntry($id); if ($entry->isDirectory() && !$entry->checkAccess(null, false)) { throw new AccessDeniedException(_('Sie dürfen keinen fremden Ordner herunterladen.')); } $download_files[] = $entry; } $download_type = 'multiple'; } else { try { // Get directory entry $entry = new DirectoryEntry($entry_id); // Determine download type $filename = $entry->file->filename; $download_files[] = $entry; $download_type = $entry->isDirectory() ? 'multiple' : 'single'; if (!$entry->checkAccess(null, false)) { if ($entry->isDirectory()) { throw new AccessDeniedException(_('Sie dürfen keinen fremden Ordner herunterladen.')); } elseif (false) { // TODO: Permission check inactive for now throw new AccessDeniedException(_('Sie dürfen keine fremde Datei herunterladen.')); } } } catch (InvalidArgumentException $e) { // Entry id is not a valid directory entry, // so we assume that it is a foreign folder if ($entry_id !== $GLOBALS['user']->id) { if (!User::exists($entry_id)) { throw new InvalidArgumentException(_('404 - File not found')); } elseif (!Config::get()->PERSONALDOCUMENT_OPEN_ACCESS) { throw new AccessDeniedException(_('Sie dürfen keinen fremden Ordner herunterladen.')); } } $download_files[] = new RootDirectory($entry_id); $download_type = 'multiple'; } } // Download either a zip file or single file if ($download_type === 'multiple') { $this->download_files($download_files, $filename ?: 'Stud-IP'); } else { $this->download_file(reset($download_files), $inline); } }
/** * Edits a folder. * * @param String $folder_id Directory entry id of the folder */ public function edit_action($folder_id) { if (!$this->full_access) { throw new AccessDeniedException(); } PageLayout::setTitle(_('Ordner bearbeiten')); $folder = new DirectoryEntry($folder_id); $folder->checkAccess(); if (Request::isPost()) { $name = Request::get('name'); $name = $folder->directory->ensureUniqueFilename($name, $folder->file); $folder->name = $name; $folder->description = Request::get('description'); if ($folder->isDirty()) { $folder->store(); $message = sprintf(_('Der Ordner "%s" wurde gespeichert.'), $folder->name); PageLayout::postMessage(MessageBox::success($message)); } $this->redirect($this->url_for_parent_directory($folder)); return; } $this->setDialogLayout(Icon::create('folder-' . ($folder->file->isEmpty() ? 'empty' : 'full'), 'navigation')); $this->folder = $folder; }
/** * Edits a file. * * @param String $entry_id Directory entry id of the file */ public function edit_action($entry_id) { if (!$this->full_access) { throw new AccessDeniedException(); } PageLayout::setTitle(_('Datei bearbeiten')); $entry = new DirectoryEntry($entry_id); $entry->checkAccess(); if (Request::isPost()) { $name = Request::get('filename'); $name = $entry->directory->ensureUniqueFilename($name, $entry->file); $entry->file->filename = $name; $entry->file->restricted = Request::int('restricted', 0); $entry->name = $name; $entry->description = Request::get('description'); if ($entry->file->isDirty() || $entry->isDirty()) { $entry->store(); $entry->file->store(); $message = sprintf(_('Die Datei "%s" wurde bearbeitet.'), $entry->name); PageLayout::postMessage(MessageBox::success($message)); } $this->redirect($this->url_for_parent_directory($entry)); return; } $this->setDialogLayout(Icon::create(get_icon_for_mimetype($entry->file->mime_type), 'navigation')); $this->entry = $entry; }