WHERE dokument_id = ?"; $statement = DBManager::get()->prepare($query); $statement->execute(array(Request::get("copyfile"))); $result = $statement->fetch(PDO::FETCH_ASSOC); if (($rechte) || ($folder_tree->isWriteable(Request::get("copyintofolder") , $user->id))) { $doc = new StudipDocument(); $doc->setData( array( '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();
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(); } }
/** * Create a new document using the given file and metadata. * This method makes sure that there are no inconsistencies between a real * file and its database entry. Only if the file were copied/moved to the * documents folder, the database entry is written. If this fails too, the * file will be unlinked again. * The first parameter can either be an uploaded file or the path to an * already existing one. This file will either be moved using * move_uploaded_file or it will be copied. * The destination is determined this way: If the second parameter $data * already contains a "dokument_id", this will be used as the file's * destination. This is usually the case when refreshing a file. * If there is no such parameter, a new "dokument_id" is generated as usual * and is used as the file's destination. * * Before a document (and its file) is created, the notification * "DocumentWillCreate" will be posted. * If the document was created successfuly, the notification * "DocumentDidCreate" will be posted. * It the document was updated rather than created (see above), the * notifications will be "DocumentWillUpdate" and "DocumentDidUpdate". * The subject of the notification will always be that document. * * @param $file string full path to a file (either uploaded or already existing) * @param $data array an array containing the metadata of the document; * just use the same way as StudipDocument::setData * @return StudipDocument|null if successful the created document, null otherwise */ static function createWithFile($file, $data) { $doc = new StudipDocument(@$data['dokument_id']); $doc->setData($data); // create new ID (and thus path) if (!$doc->getId()) { $doc->setId($doc->getNewId()); } $notifications = !isset($data['dokument_id']) ? array('DocumentWillCreate', 'DocumentDidCreate') : array('DocumentWillUpdate', 'DocumentDidUpdate'); // send DocumentWill(Create|Update) notification NotificationCenter::postNotification($notifications[0], $doc); if (!$doc->attachFile($file) || !$doc->safeStore()) { return null; } // send DocumentDid(Create|Update) notification NotificationCenter::postNotification($notifications[1], $doc); return $doc; }