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; }
/** * update file according to filename and version, does not update history * has to be called after (!) file save for new objects, since file storage will be initialised with obj id. * */ public function setFileContents() { global $ilLog; #$ilLog->write(__METHOD__.' '.filesize($this->tmpFilename)); if (filesize($this->tmpFilename) == 0) { return; } $filedir = $this->file->getDirectory($this->file->getVersion()); #$ilLog->write(__METHOD__.' '.$filedir); if (!is_dir($filedir)) { $this->file->createDirectory(); ilUtil::makeDir($filedir); } $filename = $filedir . "/" . $this->file->getFileName(); if (file_exists($filename)) { unlink($filename); } //echo "-".$this->tmpFilename."-".$filename."-"; exit; return rename($this->tmpFilename, $filename); // @file_put_contents($filename, $this->content); }
/** * 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()); } }
/** * 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); }
/** * create new file list in dom and update page in db */ function create() { include_once "./Modules/File/classes/class.ilObjFile.php"; // from personal workspace if (substr($_POST["file_ref_id"], 0, 4) == "wsp_") { $fileObj = new ilObjFile(substr($_POST["file_ref_id"], 4), false); } else { if ($_POST["file_ref_id"] == 0) { $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(); // upload file to filesystem $fileObj->createDirectory(); $fileObj->raiseUploadError(false); $fileObj->getUploadFile($_FILES["file"]["tmp_name"], $_FILES["file"]["name"]); } else { $fileObj = new ilObjFile($_POST["file_ref_id"]); } } $_SESSION["il_text_lang_" . $_GET["ref_id"]] = $_POST["flst_language"]; //echo "::".is_object($this->dom).":"; $this->content_obj = new ilPCFileList($this->dom); $this->content_obj->create($this->pg_obj, $this->hier_id, $this->pc_id); $this->content_obj->setListTitle(ilUtil::stripSlashes($_POST["flst_title"]), $_POST["flst_language"]); $this->content_obj->appendItem($fileObj->getId(), $fileObj->getFileName(), $fileObj->getFileType()); $this->updated = $this->pg_obj->update(); if ($this->updated === true) { $this->ctrl->returnToParent($this, "jump" . $this->hier_id); } else { $this->insert(); } }
/** * 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); }
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; }