function edit_item($item_id, $type, $name, $description, $protected = 0, $url = '', $filesize = '') { global $SessionSeminar; $folder_tree = TreeAbstract::GetInstance('StudipDocumentTree', array('range_id' => $SessionSeminar)); if ($url != '') { $url_parts = parse_url($url); $the_file_name = basename($url_parts['path']); } if ($type) { $query = "UPDATE folder SET description = ?, name = IFNULL(?, name) WHERE folder_id = ?"; $statement = DBManager::get()->prepare($query); $statement->execute(array( $description, strlen($name) ? $name : null, $item_id, )); if ($GLOBALS['perm']->have_studip_perm('tutor', $SessionSeminar)) { if ($folder_tree->permissions_activated) { foreach(array('r' => 'read', 'w' => 'write', 'x' => 'exec') as $p => $v){ if (Request::get('perm_' . $v)) { $folder_tree->setPermission($item_id, $p); } else { $folder_tree->unsetPermission($item_id, $p); } } } if (Request::get('perm_folder')) { $folder_tree->setPermission($item_id, 'f'); } else { $folder_tree->unsetPermission($item_id, 'f'); } } return $statement->rowCount() > 0; } else { $doc = new StudipDocument($item_id); $doc->setData(compact(words('name description protected'))); if ($url != '') { $doc['url'] = $url; $doc['filename'] = $the_file_name; } return !!$doc->store(); } }
public function upload_attachment_action() { if ($GLOBALS['user']->id === "nobody") { throw new AccessDeniedException(); } if (!$GLOBALS['ENABLE_EMAIL_ATTACHMENTS']) { throw new AccessDeniedException(_('Mailanhänge sind nicht erlaubt.')); } $file = studip_utf8decode($_FILES['file']); $output = array('name' => $file['name'], 'size' => $file['size']); $output['message_id'] = Request::option("message_id"); if (!validate_upload($file)) { list($type, $error) = explode("§", $GLOBALS['msg']); throw new Exception($error); } $document = new StudipDocument(); $document->setValue('range_id', 'provisional'); $document->setValue('seminar_id', $GLOBALS['user']->id); $document->setValue('name', $output['name']); $document->setValue('filename', $document->getValue('name')); $document->setValue('filesize', (int) $output['size']); $document->setValue('autor_host', $_SERVER['REMOTE_ADDR']); $document->setValue('user_id', $GLOBALS['user']->id); $document->setValue('description', Request::option('message_id')); $success = $document->store(); if (!$success) { throw new Exception("Unable to handle uploaded file."); } $file_moved = move_uploaded_file($file['tmp_name'], get_upload_file_path($document->getId())); if (!$file_moved) { throw new Exception("No permission to move file to destination."); } $output['document_id'] = $document->getId(); $output['icon'] = GetFileIcon(getFileExtension($output['name']))->asImg(['class' => "text-bottom"]); $this->render_json($output); }
'range_id' => Request::get("copyintofolder"), 'user_id' => $user->id, 'seminar_id' => $SessSemName[1], 'name' => $result['name'], 'description' => $result['description'], 'filename' => $result['filename'], 'mkdate' => $result['mkdate'], 'chdate' => time(), 'filesize' => $result['filesize'], 'autor_host' => $result['autor_host'], 'download' => 0, 'url' => $result['url'], 'protected' => $result['protected'], 'priority' => 0 )); $doc->store(); } } $output = ob_get_clean(); print studip_utf8encode($output); page_close(); die(); } /////////////////////////////////////////////////////////// //Ende Ajax-Funktionen /////////////////////////////////////////////////////////// // Start of Output PageLayout::setHelpKeyword("Basis.Dateien"); PageLayout::setTitle($SessSemName["header_line"]. " - " . _("Dateien"));
/** * Saves the content as a file in the filesystem and returns a Stud.IP-document object. * @param string $filename name of the future file without the extension. * @param mixed $folder_id md5-id of a given folder in database or null for nothing * @return StudipDocument of the exported file or false if creation of StudipDocument failed. */ public function save($filename, $folder_id = null) { global $user; $db = DBManager::get(); $doc = new StudipDocument(); $doc['folder_id'] = $folder_id; if ($folder_id) { $query = "SELECT range_id FROM folder WHERE folder_id = ?"; $statement = DBManager::get()->prepare($query); $statement->execute(array($folder_id)); $doc['range_id'] = $statement->fetchColumn(); } $doc['user_id'] = $user->id; $doc['name'] = $filename; $doc['filename'] = $filename . ".pdf"; $doc['description'] = ""; $doc['author_host'] = getenv('REMOTE_ADDR'); $doc['author_name'] = get_fullname($user->id); if ($doc->store()) { $path = get_upload_file_path($doc->getId()); $this->Output($path, 'F'); $doc['filesize'] = filesize($path); $doc->store(); return $doc; } return false; }