Example #1
0
 /**
  * Defines the elements in the sidebar.
  *
  * @param String $current_entry Directory entry id of the current folder
  * @param String $current_dir   File id of the current folder
  */
 private function setupSidebar($current_entry, $current_dir, $page = 1)
 {
     $root_dir = RootDirectory::find($this->context_id);
     $root_count = $root_dir->countFiles(true, false);
     $sidebar = Sidebar::get();
     $sidebar->setImage('sidebar/files-sidebar.png');
     if (Config::get()->PERSONALDOCUMENT_OPEN_ACCESS && $GLOBALS['user']->id !== $this->context_id) {
         $title = sprintf(_('Dateien von %s'), $this->owner->getFullname());
         $sidebar->setTitle($title);
     }
     if ($this->full_access) {
         $widget = new ActionsWidget();
         $widget->addLink(_('Datei hochladen'), $this->url_for('document/files/upload/' . $current_entry . '/' . $page), Icon::create('upload', 'clickable'), $this->userConfig['forbidden'] ? array('disabled' => '', 'title' => _('Ihre Upload-Funktion wurde gesperrt.')) : array())->asDialog('size=auto');
         $widget->addLink(_('Neuen Ordner erstellen'), $this->url_for('document/folder/create/' . $current_entry), Icon::create('folder-empty+add', 'clickable'))->asDialog('size=auto');
         $attributes = $root_count > 0 ? array() : array('disabled' => true, 'title' => _('Ihr Dateibereich enthält keine Dateien'));
         $widget->addLink(_('Dateibereich leeren'), $this->url_for('document/folder/delete/all'), Icon::create('trash', 'clickable'), $attributes);
         $sidebar->addWidget($widget);
     }
     $widget = new OptionsWidget();
     $widget->setTitle(_('Darstellung anpassen'));
     foreach (self::$possible_limits as $limit) {
         $widget->addRadioButton(sprintf(_('%u Einträge pro Seite anzeigen'), $limit), $this->url_for('document/files/settings/' . $limit . '/' . $page . '/' . $current_entry), $limit == $this->limit);
     }
     $sidebar->addWidget($widget);
     // Show export options only if zip extension is loaded
     // TODO: Implement fallback
     if (extension_loaded('zip')) {
         $widget = new ExportWidget();
         $this_dir = $current_dir === $this->context_id ? $root_dir : StudipDirectory::find($current_dir);
         $attributes = $this_dir->countFiles(true, false) > 0 ? array() : array('disabled' => true, 'title' => _('Dieser Ordner enthält keine Dateien'));
         $widget->addLink(_('Inhalt dieses Ordners herunterladen'), $this->url_for('document/download/' . $current_dir), Icon::create('file-archive', 'clickable'), $attributes);
         $attributes = $root_count > 0 ? array() : array('disabled' => true, 'title' => _('Ihr Dateibereich enthält keine Dateien'));
         $widget->addLink(_('Alle Dateien herunterladen'), $this->url_for('document/download/' . $this->context_id), Icon::create('download', 'clickable'), $attributes);
         $sidebar->addWidget($widget);
     }
 }
Example #2
0
 /**
  * Saves given files (dragged into the textarea) and returns the link to the
  * file to the user as json.
  * @throws AccessDeniedException
  */
 public function post_files_action()
 {
     $context = Request::option("context") ? Request::get("context") : $GLOBALS['user']->id;
     $context_type = Request::option("context_type");
     if (!Request::isPost() || $context_type === "course" && !$GLOBALS['perm']->have_studip_perm("autor", $context)) {
         throw new AccessDeniedException();
     }
     //check folders
     $db = DBManager::get();
     $folder_id = md5("Blubber_" . $context . "_" . $GLOBALS['user']->id);
     $parent_folder_id = md5("Blubber_" . $context);
     if ($context_type !== "course") {
         $folder_id = $parent_folder_id;
     }
     $folder = $db->query("SELECT * " . "FROM folder " . "WHERE folder_id = " . $db->quote($folder_id) . " " . "")->fetch(PDO::FETCH_COLUMN, 0);
     if (!$folder) {
         $folder = $db->query("SELECT * " . "FROM folder " . "WHERE folder_id = " . $db->quote($parent_folder_id) . " " . "")->fetch(PDO::FETCH_COLUMN, 0);
         if (!$folder) {
             $db->exec("INSERT IGNORE INTO folder " . "SET folder_id = " . $db->quote($parent_folder_id) . ", " . "range_id = " . $db->quote($context) . ", " . "seminar_id = " . $db->quote($context) . ", " . "user_id = " . $db->quote($GLOBALS['user']->id) . ", " . "name = " . $db->quote("BlubberDateien") . ", " . "permission = '7', " . "mkdate = " . $db->quote(time()) . ", " . "chdate = " . $db->quote(time()) . " " . "");
         }
         if ($context_type === "course") {
             $db->exec("INSERT IGNORE INTO folder " . "SET folder_id = " . $db->quote($folder_id) . ", " . "range_id = " . $db->quote($parent_folder_id) . ", " . "seminar_id = " . $db->quote($context) . ", " . "user_id = " . $db->quote($GLOBALS['user']->id) . ", " . "name = " . $db->quote(get_fullname()) . ", " . "permission = '7', " . "mkdate = " . $db->quote(time()) . ", " . "chdate = " . $db->quote(time()) . " " . "");
         }
     }
     $output = array();
     foreach ($_FILES as $file) {
         $GLOBALS['msg'] = '';
         validate_upload($file);
         if ($GLOBALS['msg']) {
             $output['errors'][] = $file['name'] . ': ' . decodeHTML(trim(substr($GLOBALS['msg'], 6), '§'));
             continue;
         }
         if ($file['size']) {
             $document['name'] = $document['filename'] = studip_utf8decode(strtolower($file['name']));
             $document['user_id'] = $GLOBALS['user']->id;
             $document['author_name'] = get_fullname();
             $document['seminar_id'] = $context;
             $document['range_id'] = $context_type === "course" ? $folder_id : $parent_folder_id;
             $document['filesize'] = $file['size'];
             if ($context === $GLOBALS['user']->id && Config::get()->PERSONALDOCUMENT_ENABLE) {
                 try {
                     $root_dir = RootDirectory::find($GLOBALS['user']->id);
                     $blubber_directory = $root_dir->listDirectories()->findOneBy('name', 'Blubber');
                     if (!$blubber_directory) {
                         $blubber_directory = $root_dir->mkdir('Blubber', _('Ihre Dateien aus Blubberstreams'));
                     }
                     $newfile = $blubber_directory->file->createFile($document['name']);
                     $newfile->name = $document['name'];
                     $newfile->store();
                     $handle = $newfile->file;
                     $handle->restricted = 0;
                     $handle->mime_type = $file['type'];
                     $handle->setContentFromFile($file['tmp_name']);
                     $handle->update();
                     $url = $newfile->getDownloadLink(true, true);
                     $success = true;
                 } catch (Exception $e) {
                     $output['error'][] = $e->getMessage();
                     $success = false;
                 }
             } else {
                 $newfile = StudipDocument::createWithFile($file['tmp_name'], $document);
                 $success = (bool) $newfile;
                 if ($success) {
                     $url = GetDownloadLink($newfile->getId(), $newfile['filename']);
                 }
             }
             if ($success) {
                 $type = null;
                 strpos($file['type'], 'image') === false || ($type = "img");
                 strpos($file['type'], 'video') === false || ($type = "video");
                 if (strpos($file['type'], 'audio') !== false || strpos($document['filename'], '.ogg') !== false) {
                     $type = "audio";
                 }
                 if ($type) {
                     $output['inserts'][] = "[" . $type . "]" . $url;
                 } else {
                     $output['inserts'][] = "[" . $document['filename'] . "]" . $url;
                 }
             }
         }
     }
     $this->render_json($output);
 }
Example #3
0
 /**
  * Deletes a folder.
  *
  * @param String $folder_id Directory entry id of the folder
  */
 public function delete_action($folder_id)
 {
     if (!$this->full_access) {
         throw new AccessDeniedException();
     }
     FileHelper::checkAccess($folder_id);
     $parent_id = FileHelper::getParentId($folder_id) ?: $this->context_id;
     if (!Request::isPost()) {
         $message = $folder_id === 'all' ? _('Soll der gesamte Dateibereich inklusive aller Order und Dateien wirklich gelöscht werden?') : _('Soll der Ordner inklusive aller darin enthaltenen Dateien wirklich gelöscht werden?');
         $question = createQuestion2($message, array(), array(), $this->url_for('document/folder/delete/' . $folder_id));
         $this->flash['question'] = $question;
     } elseif (Request::isPost() && Request::submitted('yes')) {
         if ($folder_id === 'all') {
             $entry = RootDirectory::find($this->context_id);
             foreach ($entry->listFiles() as $file) {
                 $entry->unlink($file->name);
             }
             PageLayout::postMessage(MessageBox::success(_('Der Dateibereich wurde geleert.')));
         } else {
             $entry = DirectoryEntry::find($folder_id);
             $entry->directory->unlink($entry->name);
             PageLayout::postMessage(MessageBox::success(_('Der Ordner wurde gelöscht.')));
         }
     }
     $this->redirect('document/files/index/' . $parent_id);
 }