/** * Renders the specified object into images. * The images do not need to be of the preview image size. * * @param ilObjFile $obj The object to create images from. * @return array An array of ilRenderedImage containing the absolute file paths to the images. */ protected function renderImages($obj) { $filepath = $obj->getFile(); $tmpPath = $this->prepareFileForExec($filepath); $isTemporary = $tmpPath != $filepath; return array(new ilRenderedImage($tmpPath . "[0]", $isTemporary)); }
/** * Renders the specified object into images. * The images do not need to be of the preview image size. * * @param ilObjFile $obj The object to create images from. * @return array An array of ilRenderedImage containing the absolute file paths to the images. */ protected function renderImages($obj) { $numOfPreviews = $this->getMaximumNumberOfPreviews(); // get file path $filepath = $obj->getFile(); $inputFile = $this->prepareFileForExec($filepath); // create a temporary file name and remove its extension $output = str_replace(".tmp", "", ilUtil::ilTempnam()); // use '#' instead of '%' as it gets replaced by 'escapeShellArg' on windows! $outputFile = $output . "_#02d.png"; // create images with ghostscript (we use PNG here as it has better transparency quality) // gswin32c -dBATCH -dNOPAUSE -dSAFER -dFirstPage=1 -dLastPage=5 -sDEVICE=pngalpha -dEPSCrop -r72 -o $outputFile $inputFile // gswin32c -dBATCH -dNOPAUSE -dSAFER -dFirstPage=1 -dLastPage=5 -sDEVICE=jpeg -dJPEGQ=90 -r72 -o $outputFile $inputFile $args = sprintf("-dBATCH -dNOPAUSE -dSAFER -dFirstPage=1 -dLastPage=%d -sDEVICE=pngalpha -dEPSCrop -r72 -o %s %s", $numOfPreviews, str_replace("#", "%", ilUtil::escapeShellArg($outputFile)), ilUtil::escapeShellArg($inputFile)); ilUtil::execQuoted(PATH_TO_GHOSTSCRIPT, $args); // was a temporary file created? then delete it if ($filepath != $inputFile) { @unlink($inputFile); } // check each file and add it $images = array(); $outputFile = str_replace("#", "%", $outputFile); for ($i = 1; $i <= $numOfPreviews; $i++) { $imagePath = sprintf($outputFile, $i); if (!file_exists($imagePath)) { break; } $images[] = new ilRenderedImage($imagePath); } return $images; }
/** * Get head dependencies * * @param string entity * @param string target release * @param array ids * @return array array of array with keys "component", entity", "ids" */ function getXmlExportHeadDependencies($a_entity, $a_target_release, $a_ids) { if ($a_entity == "pg") { // get all media objects and files of the page include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php"; include_once "./Modules/File/classes/class.ilObjFile.php"; $mob_ids = array(); $file_ids = array(); foreach ($a_ids as $pg_id) { $pg_id = explode(":", $pg_id); // get media objects $mids = ilObjMediaObject::_getMobsOfObject($pg_id[0] . ":pg", $pg_id[1]); foreach ($mids as $mid) { if (ilObject::_lookupType($mid) == "mob") { $mob_ids[] = $mid; } } // get files $files = ilObjFile::_getFilesOfObject($pg_id[0] . ":pg", $pg_id[1]); foreach ($files as $file) { if (ilObject::_lookupType($file) == "file") { $file_ids[] = $file; } } } return array(array("component" => "Services/MediaObjects", "entity" => "mob", "ids" => $mob_ids), array("component" => "Modules/File", "entity" => "file", "ids" => $file_ids)); } return array(); }
/** * 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)); } } }
/** * update file according to filename and version and create history entry * has to be called after (!) file save for new objects, since file storage will be initialised with obj id. * */ public function updateFileContents() { if ($this->setFileContents()) { require_once "./Services/History/classes/class.ilHistory.php"; ilHistory::_createEntry($this->file->getId(), "replace", $this->file->getFilename() . "," . $this->file->getVersion()); $this->file->addNewsNotification("file_updated"); } }
function start() { $this->__buildHeader(); $attribs = array("obj_id" => "il_" . IL_INST_ID . "_file_" . $this->file->getId(), "version" => $this->file->getVersion(), "size" => $this->file->getFileSize(), "type" => $this->file->getFileType()); $this->xmlStartTag("File", $attribs); $this->xmlElement("Filename", null, $this->file->getFileName()); $this->xmlElement("Title", null, $this->file->getTitle()); $this->xmlElement("Description", null, $this->file->getDescription()); $this->xmlElement("Rating", null, (int) $this->file->hasRating()); if ($this->attachFileContents) { $filename = $this->file->getDirectory($this->file->getVersion()) . "/" . $this->file->getFileName(); if (@is_file($filename)) { if ($this->attachFileContents == ilFileXMLWriter::$CONTENT_ATTACH_COPY) { $attribs = array("mode" => "COPY"); copy($filename, $this->target_dir_absolute . "/" . $this->file->getFileName()); $content = $this->target_dir_relative . "/" . $this->file->getFileName(); $this->xmlElement("Content", $attribs, $content); } elseif ($this->attachFileContents == ilFileXMLWriter::$CONTENT_ATTACH_REST) { $attribs = array('mode' => "REST"); include_once './Services/WebServices/Rest/classes/class.ilRestFileStorage.php'; $fs = new ilRestFileStorage(); $tmpname = $fs->storeFileForRest(base64_encode(@file_get_contents($filename))); $this->xmlElement("Content", $attribs, $tmpname); } else { $content = @file_get_contents($filename); $attribs = array("mode" => "PLAIN"); if ($this->attachFileContents == ilFileXMLWriter::$CONTENT_ATTACH_ZLIB_ENCODED) { $attribs["mode"] = "ZLIB"; $content = @gzcompress($content, 9); } elseif ($this->attachFileContents == ilFileXMLWriter::$CONTENT_ATTACH_GZIP_ENCODED) { $attribs["mode"] = "GZIP"; $content = @gzencode($content, 9); } $content = base64_encode($content); $this->xmlElement("Content", $attribs, $content); } } } include_once "./Services/History/classes/class.ilHistory.php"; $versions = ilHistory::_getEntriesForObject($this->file->getId(), $this->file->getType()); if (count($versions)) { $this->xmlStartTag("Versions"); foreach ($versions as $version) { $info_params = $version["info_params"]; list($filename, $history_id) = split(",", $info_params); $attribs = array("id" => $history_id, "date" => ilUtil::date_mysql2time($version["date"]), "usr_id" => "il_" . IL_INST_ID . "_usr_" . $version["user_id"]); $this->xmlElement("Version", $attribs); } $this->xmlEndTag("Versions"); } $this->xmlEndTag("File"); $this->__buildFooter(); return true; }
/** * Determines whether the specified preview object is supported by the renderer. * * @param ilPreview $preview The preview object to check. * @return bool true, if the renderer supports the specified preview object; otherwise, false. */ public function supports($preview) { // let parent check first if (!parent::supports($preview)) { return false; } // get file extension require_once "./Modules/File/classes/class.ilObjFile.php"; include_once './Modules/File/classes/class.ilObjFileAccess.php'; $filename = ilObjFile::_lookupFileName($preview->getObjId()); $ext = ilObjFileAccess::_getFileExtension($filename); // contains that extension? return in_array($ext, $this->getSupportedFileFormats()); }
/** * add an File with id. * * @param string $session_id current session * @param int $target_id refid of parent in repository * @param string $file_xml qti xml description of test * * @return int reference id in the tree, 0 if not successful */ function addFile($sid, $target_id, $file_xml) { $this->initAuth($sid); $this->initIlias(); if (!$this->__checkSession($sid)) { return $this->__raiseError($this->__getMessage(), $this->__getMessageCode()); } global $rbacsystem, $tree, $ilLog, $ilAccess; if (!($target_obj =& ilObjectFactory::getInstanceByRefId($target_id, false))) { return $this->__raiseError('No valid target given.', 'Client'); } if (ilObject::_isInTrash($target_id)) { return $this->__raiseError("Parent with ID {$target_id} has been deleted.", 'CLIENT_TARGET_DELETED'); } // Check access $allowed_types = array('cat', 'grp', 'crs', 'fold', 'root'); if (!in_array($target_obj->getType(), $allowed_types)) { return $this->__raiseError('No valid target type. Target must be reference id of "course, group, category or folder"', 'Client'); } if (!$ilAccess->checkAccess('create', '', $target_id, "file")) { return $this->__raiseError('No permission to create Files in target ' . $target_id . '!', 'Client'); } // create object, put it into the tree and use the parser to update the settings include_once './Modules/File/classes/class.ilFileXMLParser.php'; include_once './Modules/File/classes/class.ilFileException.php'; include_once './Modules/File/classes/class.ilObjFile.php'; $file = new ilObjFile(); try { $fileXMLParser = new ilFileXMLParser($file, $file_xml); if ($fileXMLParser->start()) { global $ilLog; $ilLog->write(__METHOD__ . ': File type: ' . $file->getFileType()); $file->create(); $file->createReference(); $file->putInTree($target_id); $file->setPermissions($target_id); // we now can save the file contents since we know the obj id now. $fileXMLParser->setFileContents(); #$file->update(); return $file->getRefId(); } else { return $this->__raiseError("Could not add file", "Server"); } } catch (ilFileException $exception) { return $this->__raiseError($exception->getMessage(), $exception->getCode() == ilFileException::$ID_MISMATCH ? "Client" : "Server"); } }
/** * Import XML * * @param * @return */ function importXmlRepresentation($a_entity, $a_id, $a_xml, $a_mapping) { include_once './Modules/File/classes/class.ilObjFile.php'; // case i container if ($new_id = $a_mapping->getMapping('Services/Container', 'objs', $a_id)) { $newObj = ilObjectFactory::getInstanceByObjId($new_id, false); } else { $newObj = new ilObjFile(); $newObj->create(true); } include_once "./Modules/File/classes/class.ilFileXMLParser.php"; $parser = new ilFileXMLParser($newObj, $a_xml); $parser->setImportDirectory($this->getImportDirectory()); $parser->startParsing(); $newObj->createProperties(false, false); $parser->setFileContents(); $this->current_obj = $newObj; $newObj->update(); // this is necessary for case ii (e.g. wiki import) $a_mapping->addMapping("Modules/File", "file", $a_id, $newObj->getId()); $a_mapping->addMapping("Services/MetaData", "md", $a_id . ":0:file", $newObj->getId() . ":0:file"); }
/** * Handles the upload of a single file and adds it to the parent object. * * @param array $file_upload An array containing the file upload parameters. * @return object The response object. */ protected function handleFileUpload($file_upload) { global $ilUser; // file upload params $filename = $file_upload["name"]; $type = $file_upload["type"]; $size = $file_upload["size"]; $temp_name = $file_upload["tmp_name"]; // additional params $title = $file_upload["title"]; $description = $file_upload["description"]; $extract = $file_upload["extract"]; $keep_structure = $file_upload["keep_structure"]; // create answer object $response = new stdClass(); $response->fileName = $filename; $response->fileSize = intval($size); $response->fileType = $type; $response->fileUnzipped = $extract; $response->error = null; // extract archive? if ($extract) { $zip_file = $filename; $adopt_structure = $keep_structure; include_once "Services/Utilities/classes/class.ilFileUtils.php"; // Create unzip-directory $newDir = ilUtil::ilTempnam(); ilUtil::makeDir($newDir); // Check if permission is granted for creation of object, if necessary if ($this->id_type != self::WORKSPACE_NODE_ID) { $type = ilObject::_lookupType((int) $this->parent_id, true); } else { $type = ilObject::_lookupType($this->tree->lookupObjectId($this->parent_id), false); } $tree = $access_handler = null; switch ($type) { // workspace structure case 'wfld': case 'wsrt': $permission = $this->checkPermissionBool("create", "", "wfld"); $containerType = "WorkspaceFolder"; $tree = $this->tree; $access_handler = $this->getAccessHandler(); break; // use categories as structure // use categories as structure case 'cat': case 'root': $permission = $this->checkPermissionBool("create", "", "cat"); $containerType = "Category"; break; // use folders as structure (in courses) // use folders as structure (in courses) default: $permission = $this->checkPermissionBool("create", "", "fold"); $containerType = "Folder"; break; } try { // processZipFile ( // Dir to unzip, // Path to uploaded file, // should a structure be created (+ permission check)? // ref_id of parent // object that contains files (folder or category) // should sendInfo be persistent?) ilFileUtils::processZipFile($newDir, $temp_name, $adopt_structure && $permission, $this->parent_id, $containerType, $tree, $access_handler); } catch (ilFileUtilsException $e) { $response->error = $e->getMessage(); } catch (Exception $ex) { $response->error = $ex->getMessage(); } ilUtil::delDir($newDir); // #15404 if ($this->id_type != self::WORKSPACE_NODE_ID) { foreach (ilFileUtils::getNewObjects() as $parent_ref_id => $objects) { if ($parent_ref_id != $this->parent_id) { continue; } foreach ($objects as $object) { $this->after_creation_callback_objects[] = $object; } } } } else { if (trim($title) == "") { $title = $filename; } else { // BEGIN WebDAV: Ensure that object title ends with the filename extension $fileExtension = ilObjFileAccess::_getFileExtension($filename); $titleExtension = ilObjFileAccess::_getFileExtension($title); if ($titleExtension != $fileExtension && strlen($fileExtension) > 0) { $title .= '.' . $fileExtension; } // END WebDAV: Ensure that object title ends with the filename extension } // create and insert file in grp_tree include_once "./Modules/File/classes/class.ilObjFile.php"; $fileObj = new ilObjFile(); $fileObj->setTitle($title); $fileObj->setDescription($description); $fileObj->setFileName($filename); include_once "./Services/Utilities/classes/class.ilMimeTypeUtil.php"; $fileObj->setFileType(ilMimeTypeUtil::getMimeType("", $filename, $type)); $fileObj->setFileSize($size); $this->object_id = $fileObj->create(); $this->putObjectInTree($fileObj, $this->parent_id); // see uploadFiles() if (is_array($this->after_creation_callback_objects)) { $this->after_creation_callback_objects[] = $fileObj; } // upload file to filesystem $fileObj->createDirectory(); $fileObj->raiseUploadError(false); $fileObj->getUploadFile($temp_name, $filename); $this->handleAutoRating($fileObj); // BEGIN ChangeEvent: Record write event. require_once './Services/Tracking/classes/class.ilChangeEvent.php'; ilChangeEvent::_recordWriteEvent($fileObj->getId(), $ilUser->getId(), 'create'); // END ChangeEvent: Record write event. } return $response; }
/** * Set standard link xml (currently only glossaries) */ function setDefaultLinkXml() { $int_links = $this->getPageObject()->getInternalLinks(true); $this->glossary_links = $int_links; //var_dump($int_links); // key is il__git_18:GlossaryItem:Glossary::4 => id is il__git_18_4, $link_info = "<IntLinkInfos>"; $targetframe = "None"; $ltarget = ""; foreach ($int_links as $int_link) { $onclick = ""; $target = $int_link["Target"]; $targetframe = "None"; if (substr($target, 0, 4) == "il__") { $target_arr = explode("_", $target); $target_id = $target_arr[count($target_arr) - 1]; $type = $int_link["Type"]; switch ($type) { case "GlossaryItem": $ltarget = ""; //$href = "./goto.php?target=git_".$target_id; $href = "#"; $onclick = 'OnClick="return false;"'; $anc_par = 'Anchor=""'; $targetframe = "Glossary"; break; case "File": $ltarget = ""; if ($this->getOutputMode() == "offline") { if (ilObject::_lookupType($target_id) == "file") { include_once "./Modules/File/classes/class.ilObjFile.php"; $href = "./files/file_" . $target_id . "/" . ilObjFile::_lookupFileName($target_id); $ltarget = "_blank"; } } else { $href = str_replace("&", "&", $this->determineFileDownloadLink()) . "&file_id=il__file_" . $target_id; //echo htmlentities($href); } $anc_par = 'Anchor=""'; $targetframe = "None"; //??? break; } $link_info .= "<IntLinkInfo {$onclick} Target=\"{$target}\" Type=\"{$type}\" " . $anc_par . " " . "TargetFrame=\"{$targetframe}\" LinkHref=\"{$href}\" LinkTarget=\"{$ltarget}\" />"; } } $link_info .= "</IntLinkInfos>"; $this->setLinkXML($link_info); //var_dump($link_info); }
/** * Get material file name and goto url * * @param int $a_wsp_id * @return array caption, url */ function getMaterialInfo($a_wsp_id) { global $ilUser; if (!$this->ws_tree) { include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceTree.php"; include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceAccessHandler.php"; $this->ws_tree = new ilWorkspaceTree($ilUser->getId()); $this->ws_access = new ilWorkspaceAccessHandler($caption); } $obj_id = $this->ws_tree->lookupObjectId($a_wsp_id); $caption = ilObject::_lookupTitle($obj_id); if (!$this->offline_mode) { $url = $this->ws_access->getGotoLink($a_wsp_id, $obj_id); } else { $url = $this->offline_mode . "file_" . $obj_id . "/"; // all possible material types for now switch (ilObject::_lookupType($obj_id)) { case "tstv": include_once "Modules/Test/classes/class.ilObjTestVerification.php"; $obj = new ilObjTestVerification($obj_id, false); $url .= $obj->getOfflineFilename(); break; case "excv": include_once "Modules/Exercise/classes/class.ilObjExerciseVerification.php"; $obj = new ilObjExerciseVerification($obj_id, false); $url .= $obj->getOfflineFilename(); break; case "file": $file = new ilObjFile($obj_id, false); $url .= $file->getFilename(); break; } } return array($caption, $url); }
/** * init Form * * @param string $a_mode values: create | edit */ public function initForm() { global $lng, $ilCtrl; //table_id $hidden_prop = new ilHiddenInputGUI("table_id"); $hidden_prop->setValue($this->table_id); $this->form->addItem($hidden_prop); $ilCtrl->setParameter($this, "record_id", $this->record_id); $this->form->setFormAction($ilCtrl->getFormAction($this)); $allFields = $this->table->getRecordFields(); foreach ($allFields as $field) { $item = ilDataCollectionDatatype::getInputField($field); if ($field->getDatatypeId() == ilDataCollectionDatatype::INPUTFORMAT_REFERENCE) { $fieldref = $field->getFieldRef(); $reffield = ilDataCollectionCache::getFieldCache($fieldref); $options = array(); if (!$field->isNRef()) { $options[""] = '--'; } $reftable = ilDataCollectionCache::getTableCache($reffield->getTableId()); foreach ($reftable->getRecords() as $record) { // If the referenced field is MOB or FILE, we display the filename in the dropdown if ($reffield->getDatatypeId() == ilDataCollectionDatatype::INPUTFORMAT_FILE) { $file_obj = new ilObjFile($record->getRecordFieldValue($fieldref), false); $options[$record->getId()] = $file_obj->getFileName(); } else { if ($reffield->getDatatypeId() == ilDataCollectionDatatype::INPUTFORMAT_MOB) { $media_obj = new ilObjMediaObject($record->getRecordFieldValue($fieldref), false); $options[$record->getId()] = $media_obj->getTitle(); } else { $options[$record->getId()] = $record->getRecordFieldValue($fieldref); } } } $item->setOptions($options); } if ($this->record_id) { $record = ilDataCollectionCache::getRecordCache($this->record_id); } $item->setRequired($field->getRequired()); //WORKAROUND. If field is from type file: if it's required but already has a value it is no longer required as the old value is taken as default without the form knowing about it. if ($field->getDatatypeId() == ilDataCollectionDatatype::INPUTFORMAT_FILE || $field->getDatatypeId() == ilDataCollectionDatatype::INPUTFORMAT_MOB && ($this->record_id && $record->getId() != 0 && ($record->getRecordFieldValue($field->getId()) != "-" || $record->getRecordFieldValue($field->getId()) != ""))) { $item->setRequired(false); } if (!ilObjDataCollection::_hasWriteAccess($this->parent_obj->ref_id) && $field->getLocked()) { $item->setDisabled(true); } $this->form->addItem($item); } // Add possibility to change the owner in edit mode if ($this->record_id) { $ownerField = $this->table->getField('owner'); $inputfield = ilDataCollectionDatatype::getInputField($ownerField); $this->form->addItem($inputfield); } // save and cancel commands if (isset($this->record_id)) { $this->form->setTitle($lng->txt("dcl_update_record")); $this->form->addCommandButton("save", $lng->txt("dcl_update_record")); $this->form->addCommandButton("cancelUpdate", $lng->txt("cancel")); } else { $this->form->setTitle($lng->txt("dcl_add_new_record")); $this->form->addCommandButton("save", $lng->txt("save")); $this->form->addCommandButton("cancelSave", $lng->txt("cancel")); } $ilCtrl->setParameter($this, "table_id", $this->table_id); $ilCtrl->setParameter($this, "record_id", $this->record_id); }
/** * insert new file item */ function createFileItem() { global $lng; if ($_FILES["file"]["name"] == "") { $_GET["subCmd"] = "-"; ilUtil::sendFailure($lng->txt("upload_error_file_not_found")); return false; } include_once "./Modules/File/classes/class.ilObjFile.php"; $fileObj = new ilObjFile(); $fileObj->setType("file"); $fileObj->setTitle($_FILES["file"]["name"]); $fileObj->setDescription(""); $fileObj->setFileName($_FILES["file"]["name"]); $fileObj->setFileType($_FILES["file"]["type"]); $fileObj->setFileSize($_FILES["file"]["size"]); $fileObj->setMode("filelist"); $fileObj->create(); $fileObj->raiseUploadError(false); // upload file to filesystem $fileObj->createDirectory(); $fileObj->getUploadFile($_FILES["file"]["tmp_name"], $_FILES["file"]["name"]); return $fileObj; }
/** * init Form */ public function initForm() { $this->form = new ilPropertyFormGUI(); $prefix = $this->ctrl->isAsynch() ? 'dclajax' : 'dcl'; // Used by datacolleciton.js to select input elements $this->form->setId($prefix . $this->table_id . $this->record_id); $hidden_prop = new ilHiddenInputGUI("table_id"); $hidden_prop->setValue($this->table_id); $this->form->addItem($hidden_prop); if ($this->record_id) { $hidden_prop = new ilHiddenInputGUI("record_id"); $hidden_prop->setValue($this->record_id); $this->form->addItem($hidden_prop); } $this->ctrl->setParameter($this, "record_id", $this->record_id); $this->form->setFormAction($this->ctrl->getFormAction($this)); $allFields = $this->table->getRecordFields(); $inline_css = ''; foreach ($allFields as $field) { $item = ilDataCollectionDatatype::getInputField($field); if ($item === NULL) { continue; // Fields calculating values at runtime, e.g. ilDataCollectionFormulaField do not have input } if ($field->getDatatypeId() == ilDataCollectionDatatype::INPUTFORMAT_REFERENCE) { $fieldref = $field->getFieldRef(); $reffield = ilDataCollectionCache::getFieldCache($fieldref); $options = array(); if (!$field->isNRef()) { $options[""] = $this->lng->txt('dcl_please_select'); } $reftable = ilDataCollectionCache::getTableCache($reffield->getTableId()); foreach ($reftable->getRecords() as $record) { // If the referenced field is MOB or FILE, we display the filename in the dropdown switch ($reffield->getDatatypeId()) { case ilDataCollectionDatatype::INPUTFORMAT_FILE: $file_obj = new ilObjFile($record->getRecordFieldValue($fieldref), false); $options[$record->getId()] = $file_obj->getFileName(); break; case ilDataCollectionDatatype::INPUTFORMAT_MOB: $media_obj = new ilObjMediaObject($record->getRecordFieldValue($fieldref), false); $options[$record->getId()] = $media_obj->getTitle(); break; case ilDataCollectionDatatype::INPUTFORMAT_DATETIME: $options[$record->getId()] = $record->getRecordFieldSingleHTML($fieldref); break; default: $options[$record->getId()] = $record->getRecordFieldValue($fieldref); break; } } asort($options); $item->setOptions($options); if ($field->getDatatypeId() == ilDataCollectionDatatype::INPUTFORMAT_REFERENCE) { // FSX use this to apply to MultiSelectInputGUI // if (!$field->isNRef()) { // addCustomAttribute only defined for single selects if ($reftable->hasPermissionToAddRecord($_GET['ref_id'])) { $item->addCustomAttribute('data-ref="1"'); $item->addCustomAttribute('data-ref-table-id="' . $reftable->getId() . '"'); $item->addCustomAttribute('data-ref-field-id="' . $reffield->getId() . '"'); } // } } if ($item instanceof ilMultiSelectInputGUI) { $item->setWidth(400); $item->setHeight(100); $inline_css .= 'div#' . $item->getFieldId() . '{resize:both;} '; } } if ($this->record_id) { $record = ilDataCollectionCache::getRecordCache($this->record_id); } $item->setRequired($field->getRequired()); //WORKAROUND. If field is from type file: if it's required but already has a value it is no longer required as the old value is taken as default without the form knowing about it. if ($field->getDatatypeId() == ilDataCollectionDatatype::INPUTFORMAT_FILE || $field->getDatatypeId() == ilDataCollectionDatatype::INPUTFORMAT_MOB) { if ($this->record_id and $record->getId()) { $field_value = $record->getRecordFieldValue($field->getId()); if ($field_value) { $item->setRequired(false); } } // If this is an ajax request to return the form, input files are currently not supported if ($this->ctrl->isAsynch()) { $item->setDisabled(true); } } if (!ilObjDataCollection::_hasWriteAccess($this->parent_obj->ref_id) && $field->getLocked()) { $item->setDisabled(true); } $this->form->addItem($item); } $this->tpl->addInlineCss($inline_css); // Add possibility to change the owner in edit mode if ($this->record_id) { $ownerField = $this->table->getField('owner'); $inputfield = ilDataCollectionDatatype::getInputField($ownerField); $this->form->addItem($inputfield); } // save and cancel commands if ($this->record_id) { $this->form->setTitle($this->lng->txt("dcl_update_record")); $this->form->addCommandButton("save", $this->lng->txt("dcl_update_record")); if (!$this->ctrl->isAsynch()) { $this->form->addCommandButton("cancelUpdate", $this->lng->txt("cancel")); } } else { $this->form->setTitle($this->lng->txt("dcl_add_new_record")); $this->form->addCommandButton("save", $this->lng->txt("save")); if (!$this->ctrl->isAsynch()) { $this->form->addCommandButton("cancelSave", $this->lng->txt("cancel")); } } $this->ctrl->setParameter($this, "table_id", $this->table_id); $this->ctrl->setParameter($this, "record_id", $this->record_id); }
public function deleteFile($obj_id) { if (ilObject2::_lookupObjId($obj_id)) { $file = new ilObjFile($obj_id, false); $file->delete(); } }
/** * export files of file itmes * */ function exportFileItems($a_target_dir, &$expLog) { include_once "./Modules/File/classes/class.ilObjFile.php"; if (is_array($this->file_ids)) { foreach ($this->file_ids as $file_id) { $expLog->write(date("[y-m-d H:i:s] ") . "File Item " . $file_id); if (ilObject::_lookupType($file_id) == "file") { $file_obj = new ilObjFile($file_id, false); $file_obj->export($a_target_dir); unset($file_obj); } else { $expLog->write(date("[y-m-d H:i:s] ") . "File Item not found, ID: " . $file_id); } } } include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php"; $linked_mobs = array(); if (is_array($this->mob_ids)) { // mobs directly embedded into pages foreach ($this->mob_ids as $mob_id) { if ($mob_id > 0 && ilObject::_exists($mob_id)) { $expLog->write(date("[y-m-d H:i:s] ") . "Media Object " . $mob_id); $media_obj = new ilObjMediaObject($mob_id); $media_obj->exportFiles($a_target_dir, $expLog); $lmobs = $media_obj->getLinkedMediaObjects($this->mob_ids); $linked_mobs = array_merge($linked_mobs, $lmobs); unset($media_obj); } } // linked mobs (in map areas) foreach ($linked_mobs as $mob_id) { if ($mob_id > 0 && ilObject::_exists($mob_id)) { $expLog->write(date("[y-m-d H:i:s] ") . "Media Object " . $mob_id); $media_obj = new ilObjMediaObject($mob_id); $media_obj->exportFiles($a_target_dir); unset($media_obj); } } } //media files in questions foreach ($this->q_media as $media) { if ($media != "") { error_log($media); copy($media, $a_target_dir . "/objects/" . basename($media)); } } }
/** * export files of file itmes * */ function exportFileItems($a_target_dir, &$expLog) { include_once "./Modules/File/classes/class.ilObjFile.php"; foreach ($this->file_ids as $file_id) { $expLog->write(date("[y-m-d H:i:s] ") . "File Item " . $file_id); $file_obj = new ilObjFile($file_id, false); $file_obj->export($a_target_dir); unset($file_obj); } }
/** * send File to User */ public function sendFile() { global $ilAccess; //need read access to receive file if ($ilAccess->checkAccess("read", "", $this->parent_obj->ref_id)) { $rec_id = $_GET['record_id']; $record = ilDataCollectionCache::getRecordCache($rec_id); $field_id = $_GET['field_id']; $file_obj = new ilObjFile($record->getRecordFieldValue($field_id), false); if (!$this->recordBelongsToCollection($record, $this->parent_obj->ref_id)) { return; } ilUtil::deliverFile($file_obj->getFile(), $file_obj->getTitle()); } }
/** * Export file object */ function exportHTMLFile($a_file_id) { $file_dir = $this->files_dir . "/file_" . $a_file_id; ilUtil::makeDir($file_dir); include_once "./Modules/File/classes/class.ilObjFile.php"; $file_obj = new ilObjFile($a_file_id, false); $source_file = $file_obj->getDirectory($file_obj->getVersion()) . "/" . $file_obj->getFileName(); if (!is_file($source_file)) { $source_file = $file_obj->getDirectory() . "/" . $file_obj->getFileName(); } if (is_file($source_file)) { copy($source_file, $file_dir . "/" . $file_obj->getFileName()); } }
/** * download file of file lists */ function downloadFile() { $file = explode("_", $_GET["file_id"]); $file_id = (int) $file[count($file) - 1]; require_once "./Modules/File/classes/class.ilObjFile.php"; $fileObj = new ilObjFile($file_id, false); $fileObj->sendFile(); exit; }
function getExportResources() { $export_files = array(); require_once "./Modules/Scorm2004/classes/class.ilSCORM2004Page.php"; include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php"; include_once "./Modules/File/classes/class.ilObjFile.php"; $tree = new ilTree($this->slm_object->getId()); $tree->setTableNames('sahs_sc13_tree', 'sahs_sc13_tree_node'); $tree->setTreeTablePK("slm_id"); foreach ($tree->getSubTree($tree->getNodeData($this->node_object->getId()), true, 'page') as $page) { $page_obj = new ilSCORM2004Page($page["obj_id"]); $page_obj->buildDom(); $mob_ids = $page_obj->collectMediaObjects(false); foreach ($mob_ids as $mob_id) { if ($mob_id > 0 && ilObject::_exists($mob_id)) { $path = ilObjMediaObject::_lookupStandardItemPath($mob_id, false, false); $media_obj = new ilObjMediaObject($mob_id); $export_files[$i]["date"] = $media_obj->getCreateDate(); $export_files[$i]["size"] = @filesize($path); // could be remote, e.g. youtube video $export_files[$i]["file"] = $media_obj->getTitle(); $export_files[$i]["type"] = $media_obj->getDescription(); $export_files[$i]["path"] = $path; $this->ctrl->setParameter($this, "resource", rawurlencode(ilObjMediaObject::_lookupStandardItemPath($mob_id, false, false))); $export_files[$i]["link"] = $this->ctrl->getLinkTarget($this, "downloadResource"); $i++; } } include_once "./Services/COPage/classes/class.ilPCFileList.php"; $file_ids = ilPCFileList::collectFileItems($page_obj, $page_obj->getDomDoc()); foreach ($file_ids as $file_id) { $file_obj = new ilObjFile($file_id, false); $export_files[$i]["date"] = $file_obj->getCreateDate(); $export_files[$i]["size"] = $file_obj->getFileSize(); $export_files[$i]["file"] = $file_obj->getFileName(); $export_files[$i]["type"] = $file_obj->getFileType(); $export_files[$i]["file_id"] = $file_id; $this->ctrl->setParameter($this, "file_id", $file_id); $export_files[$i]["link"] = $this->ctrl->getLinkTarget($this, "downloadFile", ""); $i++; } unset($page_obj); } return $export_files; }
/** * function parses stored value to the variable needed to fill into the form for editing. * @param $value * @return mixed */ public function parseFormInput($value, ilDataCollectionRecordField $record_field) { switch ($this->id) { case self::INPUTFORMAT_DATETIME: if (!$value || $value == "-") { return NULL; } //$datetime = new DateTime(); $input = array("date" => substr($value, 0, -9), "time" => "00:00:00"); break; case self::INPUTFORMAT_FILE: if (!ilObject2::_exists($value) || ilObject2::_lookupType($value, false) != "file") { $input = ""; break; } $file_obj = new ilObjFile($value, false); //$input = ilObjFile::_lookupAbsolutePath($value); $input = $file_obj->getFileName(); break; case self::INPUTFORMAT_MOB: if (!ilObject2::_exists($value) || ilObject2::_lookupType($value, false) != "mob") { $input = ""; break; } $media_obj = new ilObjMediaObject($value, false); //$input = ilObjFile::_lookupAbsolutePath($value); $input = $value; break; case self::INPUTFORMAT_TEXT: $arr_properties = $record_field->getField()->getProperties(); if ($arr_properties[ilDataCollectionField::PROPERTYID_TEXTAREA]) { $breaks = array("<br />"); $input = str_ireplace($breaks, "", $value); } else { $input = $value; } break; default: $input = $value; break; } return $input; }
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)); }
/** * Save file usages */ static function saveFileUsage($a_page, $a_domdoc, $a_old_nr = 0) { $file_ids = self::collectFileItems($a_page, $a_domdoc); include_once "./Modules/File/classes/class.ilObjFile.php"; ilObjFile::_deleteAllUsages($a_page->getParentType() . ":pg", $a_page->getId(), $a_old_nr, $a_page->getLanguage()); foreach ($file_ids as $file_id) { ilObjFile::_saveUsage($file_id, $a_page->getParentType() . ":pg", $a_page->getId(), $a_old_nr, $a_page->getLanguage()); } }
public function handleFileUpload() { global $tree; include_once './Modules/Session/classes/class.ilEventItems.php'; $ev = new ilEventItems($this->object->getId()); $items = $ev->getItems(); $counter = 0; while (true) { if (!isset($_FILES['files']['name'][$counter])) { break; } if (!strlen($_FILES['files']['name'][$counter])) { $counter++; continue; } include_once './Modules/File/classes/class.ilObjFile.php'; $file = new ilObjFile(); $file->setTitle(ilUtil::stripSlashes($_FILES['files']['name'][$counter])); $file->setDescription(''); $file->setFileName(ilUtil::stripSlashes($_FILES['files']['name'][$counter])); $file->setFileType($_FILES['files']['type'][$counter]); $file->setFileSize($_FILES['files']['size'][$counter]); $file->create(); $new_ref_id = $file->createReference(); $file->putInTree($tree->getParentId($this->object->getRefId())); $file->setPermissions($tree->getParentId($this->object->getRefId())); $file->createDirectory(); $file->getUploadFile($_FILES['files']['tmp_name'][$counter], $_FILES['files']['name'][$counter]); $items[] = $new_ref_id; $counter++; } $ev->setItems($items); $ev->update(); }
function getLastUpdateOfIncludedElements() { include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php"; include_once "./Modules/File/classes/class.ilObjFile.php"; $mobs = ilObjMediaObject::_getMobsOfObject($this->getParentType() . ":pg", $this->getId()); $files = ilObjFile::_getFilesOfObject($this->getParentType() . ":pg", $this->getId()); $objs = array_merge($mobs, $files); return ilObject::_getLastUpdateOfObjects($objs); }
/** * export all pages of learning module to html file */ function exportHTMLPages(&$a_lm_gui, $a_target_dir) { global $tpl, $ilBench, $ilLocator; $pages = ilLMPageObject::getPageList($this->getId()); $lm_tree =& $this->getLMTree(); $first_page = $lm_tree->fetchSuccessorNode($lm_tree->getRootId(), "pg"); $this->first_page_id = $first_page["child"]; // iterate all learning module pages $mobs = array(); $int_links = array(); $this->offline_files = array(); include_once "./Services/COPage/classes/class.ilPageContentUsage.php"; include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php"; // get html export id mapping $lm_set = new ilSetting("lm"); $exp_id_map = array(); if ($lm_set->get("html_export_ids")) { foreach ($pages as $page) { $exp_id = ilLMPageObject::getExportId($this->getId(), $page["obj_id"]); if (trim($exp_id) != "") { $exp_id_map[$page["obj_id"]] = trim($exp_id); } } } //exit; reset($pages); foreach ($pages as $page) { if (ilLMPage::_exists($this->getType(), $page["obj_id"])) { $ilLocator->clearItems(); $ilBench->start("ExportHTML", "exportHTMLPage"); $ilBench->start("ExportHTML", "exportPageHTML"); $this->exportPageHTML($a_lm_gui, $a_target_dir, $page["obj_id"], "", $exp_id_map); $ilBench->stop("ExportHTML", "exportPageHTML"); // get all snippets of page $pcs = ilPageContentUsage::getUsagesOfPage($page["obj_id"], $this->getType() . ":pg"); foreach ($pcs as $pc) { if ($pc["type"] == "incl") { $incl_mobs = ilObjMediaObject::_getMobsOfObject("mep:pg", $pc["id"]); foreach ($incl_mobs as $incl_mob) { $mobs[$incl_mob] = $incl_mob; } } } // get all media objects of page $pg_mobs = ilObjMediaObject::_getMobsOfObject($this->getType() . ":pg", $page["obj_id"]); foreach ($pg_mobs as $pg_mob) { $mobs[$pg_mob] = $pg_mob; } // get all internal links of page $pg_links = ilInternalLink::_getTargetsOfSource($this->getType() . ":pg", $page["obj_id"]); $int_links = array_merge($int_links, $pg_links); // get all files of page include_once "./Modules/File/classes/class.ilObjFile.php"; $pg_files = ilObjFile::_getFilesOfObject($this->getType() . ":pg", $page["obj_id"]); $this->offline_files = array_merge($this->offline_files, $pg_files); $ilBench->stop("ExportHTML", "exportHTMLPage"); } } $this->offline_mobs = $mobs; $this->offline_int_links = $int_links; }
/** * Save file link */ function saveFileLink() { $mtpl =& new ilTemplate("tpl.link_help.html", true, true, "Modules/LearningModule"); $mtpl->setVariable("LOCATION_STYLESHEET", ilUtil::getStyleSheetLocation()); if ($_FILES["link_file"]["name"] != "") { include_once "./Modules/File/classes/class.ilObjFile.php"; $fileObj = new ilObjFile(); $fileObj->setType("file"); $fileObj->setTitle($_FILES["link_file"]["name"]); $fileObj->setDescription(""); $fileObj->setFileName($_FILES["link_file"]["name"]); $fileObj->setFileType($_FILES["link_file"]["type"]); $fileObj->setFileSize($_FILES["link_file"]["size"]); $fileObj->setMode("filelist"); $fileObj->create(); // upload file to filesystem $fileObj->createDirectory(); $fileObj->raiseUploadError(false); $fileObj->getUploadFile($_FILES["link_file"]["tmp_name"], $_FILES["link_file"]["name"]); $this->uploaded_file = $fileObj; } $this->showLinkHelp(); }
/** * Generate files * * @param * @return */ function generateFiles($a_test_file, $a_files_per_course = 10, $a_title_base = "File") { global $tree; include_once "./Modules/File/classes/class.ilObjFile.php"; $this->log("Creating Files"); $a_current = $a_start; // get all categories and sort them by depth $crs_ref_ids = ilUtil::_getObjectsByOperations("crs", "read", 0, $limit = 1000000); $cnt = 1; foreach ($crs_ref_ids as $rid) { for ($i = 1; $i <= $a_files_per_course; $i++) { $this->log($a_title_base . " " . $cnt); $fileObj = new ilObjFile(); $fileObj->setTitle($a_title_base . " " . $cnt); $fileObj->setFileName("file_" . $cnt . ".txt"); $fileObj->create(); $fileObj->createReference(); $fileObj->putInTree($rid); $fileObj->setPermissions($rid); $fileObj->createDirectory(); $fileObj->getUploadFile($a_test_file, "file_" . $cnt . ".txt"); $cnt++; } } }