/** * Get files * * @access public * */ public function getFiles() { if (!@is_dir($this->export_dir)) { return array(); } foreach (ilUtil::getDir($this->export_dir) as $file_name => $file_data) { $files[$file_name] = $file_data; } return $files ? $files : array(); }
/** * Get files */ function getFiles($a_files) { $files = array(); foreach ($a_files as $f) { if (is_file($this->upload_dir . "/" . $f)) { $files[] = $f; } else { if (is_dir($this->upload_dir . "/" . $f)) { $dir = ilUtil::getDir($this->upload_dir . "/" . $f, true); foreach ($dir as $d) { if ($d["type"] == "file") { $files[] = $f . $d["subdir"] . "/" . $d["entry"]; } } } } } return $files; }
/** * Get entries */ function getEntries() { if (is_dir($this->cur_dir)) { $entries = ilUtil::getDir($this->cur_dir); } else { $entries = array(array("type" => "dir", "entry" => "..")); } $items = array(); //var_dump($entries); foreach ($entries as $e) { if ($e["entry"] == "." || $e["entry"] == ".." && empty($this->cur_subdir)) { continue; } $cfile = !empty($this->cur_subdir) ? $this->cur_subdir . "/" . $e["entry"] : $e["entry"]; if ($this->label_enable) { $label = is_array($this->file_labels[$cfile]) ? implode($this->file_labels[$cfile], ", ") : ""; } $pref = $e["type"] == "dir" ? $this->getOrderDirection() != "desc" ? "1_" : "9_" : "5_"; $items[] = array("file" => $cfile, "entry" => $e["entry"], "type" => $e["type"], "label" => $label, "size" => $e["size"], "name" => $pref . $e["entry"]); } $this->setData($items); }
/** * Get images of style */ function getImages() { $dir = $this->getImagesDirectory(); $images = array(); if (is_dir($dir)) { $entries = ilUtil::getDir($dir); foreach ($entries as $entry) { if (substr($entry["entry"], 0, 1) == ".") { continue; } if ($entry["type"] != "dir") { $images[] = $entry; } } } return $images; }
/** * Get srt files */ function getSrtFiles() { $srt_dir = ilObjMediaObject::_getDirectory($this->getId()) . "/srt"; if (!is_dir($srt_dir)) { return array(); } $items = ilUtil::getDir($srt_dir); $srt_files = array(); foreach ($items as $i) { if (!in_array($i["entry"], array(".", "..")) && $i["type"] == "file") { $name = explode(".", $i["entry"]); if ($name[1] == "srt" && substr($name[0], 0, 9) == "subtitle_") { $srt_files[] = array("file" => $i["entry"], "full_path" => "srt/" . $i["entry"], "language" => substr($name[0], 9, 2)); } } } return $srt_files; }
/** * Get multi feedback files (of uploader) * * @param int $a_user_id user id of uploader * @return array array of user files (keys: lastname, firstname, user_id, login, file) */ function getMultiFeedbackFiles($a_user_id = 0) { global $ilUser; if ($a_user_id == 0) { $a_user_id = $ilUser->getId(); } $mf_files = array(); // get members $exc = new ilObjExercise($this->getExerciseId(), false); include_once "./Modules/Exercise/classes/class.ilExerciseMembers.php"; $exmem = new ilExerciseMembers($exc); $mems = $exmem->getMembers(); // read mf directory include_once "./Modules/Exercise/classes/class.ilFSStorageExercise.php"; $storage = new ilFSStorageExercise($this->getExerciseId(), $this->getId()); $mfu = $storage->getMultiFeedbackUploadPath($ilUser->getId()); // get subdir that starts with multi_feedback $subdirs = ilUtil::getDir($mfu); $subdir = "notfound"; foreach ($subdirs as $s => $j) { if ($j["type"] == "dir" && substr($s, 0, 14) == "multi_feedback") { $subdir = $s; } } $items = ilUtil::getDir($mfu . "/" . $subdir); foreach ($items as $k => $i) { // check directory if ($i["type"] == "dir" && !in_array($k, array(".", ".."))) { // check if valid member id is given $parts = explode("_", $i["entry"]); $user_id = (int) $parts[count($parts) - 1]; if (in_array($user_id, $mems)) { // read dir of user $name = ilObjUser::_lookupName($user_id); $files = ilUtil::getDir($mfu . "/" . $subdir . "/" . $k); foreach ($files as $k2 => $f) { // append files to array if ($f["type"] == "file" && substr($k2, 0, 1) != ".") { $mf_files[] = array("lastname" => $name["lastname"], "firstname" => $name["firstname"], "login" => $name["login"], "user_id" => $name["user_id"], "full_path" => $mfu . "/" . $subdir . "/" . $k . "/" . $k2, "file" => $k2); } } } } } return $mf_files; }
/** * Import lm from zip file * * @param * @return */ function importFromZipFile($a_tmp_file, $a_filename, $a_validate = true, $a_import_into_help_module = 0) { global $lng; // create import directory $this->createImportDirectory(); // copy uploaded file to import directory $file = pathinfo($a_filename); $full_path = $this->getImportDirectory() . "/" . $a_filename; ilUtil::moveUploadedFile($a_tmp_file, $a_filename, $full_path); // unzip file ilUtil::unzip($full_path); $subdir = basename($file["basename"], "." . $file["extension"]); $mess = $this->importFromDirectory($this->getImportDirectory() . "/" . $subdir, $a_validate); // this should only be true for help modules if ($a_import_into_help_module > 0) { // search the zip file $dir = $this->getImportDirectory() . "/" . $subdir; $files = ilUtil::getDir($dir); foreach ($files as $file) { if (is_int(strpos($file["entry"], "__help_")) && is_int(strpos($file["entry"], ".zip"))) { include_once "./Services/Export/classes/class.ilImport.php"; $imp = new ilImport(); $imp->getMapping()->addMapping('Services/Help', 'help_module', 0, $a_import_into_help_module); include_once "./Modules/LearningModule/classes/class.ilLMObject.php"; $chaps = ilLMObject::getObjectList($this->getId(), "st"); foreach ($chaps as $chap) { $chap_arr = explode("_", $chap["import_id"]); $imp->getMapping()->addMapping('Services/Help', 'help_chap', $chap_arr[count($chap_arr) - 1], $chap["obj_id"]); } $imp->importEntity($dir . "/" . $file["entry"], $file["entry"], "help", "Services/Help", true); } } } // delete import directory ilUtil::delDir($this->getImportDirectory()); return $mess; }
protected function cleanImagefiles() { if ($this->getOrderingType() == OQ_PICTURES) { if (@file_exists($this->getImagePath())) { $contents = ilUtil::getDir($this->getImagePath()); foreach ($contents as $f) { if (strcmp($f['type'], 'file') == 0) { $found = false; foreach ($this->getAnswers() as $answer) { if (strcmp($f['entry'], $answer->getAnswertext()) == 0) { $found = true; } if (strcmp($f['entry'], $this->getThumbPrefix() . $answer->getAnswertext()) == 0) { $found = true; } } if (!$found) { if (@file_exists($this->getImagePath() . $f['entry'])) { @unlink($this->getImagePath() . $f['entry']); } } } } } } else { if (@file_exists($this->getImagePath())) { ilUtil::delDir($this->getImagePath()); } } }
/** * administrate files of media object */ function editFilesObject() { // standard item $std_item =& $this->object->getMediaItem("Standard"); if ($this->object->hasFullscreenItem()) { $full_item =& $this->object->getMediaItem("Fullscreen"); } // create table require_once "./Services/Table/classes/class.ilTableGUI.php"; $tbl = new ilTableGUI(); // determine directory $cur_subdir = $_GET["cdir"]; if ($_GET["newdir"] == "..") { $cur_subdir = substr($cur_subdir, 0, strrpos($cur_subdir, "/")); } else { if (!empty($_GET["newdir"])) { if (!empty($cur_subdir)) { $cur_subdir = $cur_subdir . "/" . $_GET["newdir"]; } else { $cur_subdir = $_GET["newdir"]; } } } $cur_subdir = str_replace(".", "", $cur_subdir); $mob_dir = ilUtil::getWebspaceDir() . "/mobs/mm_" . $this->object->getId(); $cur_dir = !empty($cur_subdir) ? $mob_dir . "/" . $cur_subdir : $mob_dir; // load files templates $this->tpl->addBlockfile("ADM_CONTENT", "adm_content", "tpl.mob_files.html", "Services/MediaObjects"); $this->ctrl->setParameter($this, "cdir", urlencode($cur_subdir)); $this->tpl->setVariable("FORMACTION1", $this->ctrl->getFormAction($this)); //echo "--".$this->getTargetScript(). //"&hier_id=".$_GET["hier_id"]."&cdir=".$cur_subdir."&cmd=post"."--<br>"; $this->tpl->setVariable("TXT_NEW_DIRECTORY", $this->lng->txt("cont_new_dir")); $this->tpl->setVariable("TXT_NEW_FILE", $this->lng->txt("cont_new_file")); $this->tpl->setVariable("CMD_NEW_DIR", "createDirectory"); $this->tpl->setVariable("CMD_NEW_FILE", "uploadFile"); $this->tpl->setVariable("BTN_NEW_DIR", $this->lng->txt("create")); $this->tpl->setVariable("BTN_NEW_FILE", $this->lng->txt("upload")); // $this->tpl->addBlockfile("FILE_TABLE", "files", "tpl.table.html"); // load template for table content data $this->tpl->addBlockfile("TBL_CONTENT", "tbl_content", "tpl.mob_file_row.html", "Services/MediaObjects"); $num = 0; $obj_str = $this->call_by_reference ? "" : "&obj_id=" . $this->obj_id; $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this)); $tbl->setTitle($this->lng->txt("cont_files") . " " . $cur_subdir); //$tbl->setHelp("tbl_help.php","icon_help.gif",$this->lng->txt("help")); $tbl->setHeaderNames(array("", "", $this->lng->txt("cont_dir_file"), $this->lng->txt("cont_size"), $this->lng->txt("cont_purpose"))); $cols = array("", "", "dir_file", "size", "purpose"); $header_params = array("ref_id" => $_GET["ref_id"], "obj_id" => $_GET["obj_id"], "cmd" => "editFiles", "hier_id" => $_GET["hier_id"], "item_id" => $_GET["item_id"]); $tbl->setHeaderVars($cols, $header_params); $tbl->setColumnWidth(array("1%", "1%", "33%", "33%", "32%")); // control $tbl->setOrderColumn($_GET["sort_by"]); $tbl->setOrderDirection($_GET["sort_order"]); $tbl->setLimit($_GET["limit"]); $tbl->setOffset($_GET["offset"]); $tbl->setMaxCount($this->maxcount); // ??? //$tbl->setMaxCount(30); // ??? $this->tpl->setVariable("COLUMN_COUNTS", 5); // delete button $this->tpl->setVariable("IMG_ARROW", ilUtil::getImagePath("arrow_downright.svg")); $this->tpl->setCurrentBlock("tbl_action_btn"); $this->tpl->setVariable("BTN_NAME", "deleteFile"); $this->tpl->setVariable("BTN_VALUE", $this->lng->txt("delete")); $this->tpl->parseCurrentBlock(); $this->tpl->setCurrentBlock("tbl_action_btn"); $this->tpl->setVariable("BTN_NAME", "assignStandard"); $this->tpl->setVariable("BTN_VALUE", $this->lng->txt("cont_assign_std")); $this->tpl->parseCurrentBlock(); $this->tpl->setCurrentBlock("tbl_action_btn"); $this->tpl->setVariable("BTN_NAME", "assignFullscreen"); $this->tpl->setVariable("BTN_VALUE", $this->lng->txt("cont_assign_full")); $this->tpl->parseCurrentBlock(); // footer $tbl->setFooter("tblfooter", $this->lng->txt("previous"), $this->lng->txt("next")); //$tbl->disable("footer"); $entries = ilUtil::getDir($cur_dir); //$objs = ilUtil::sortArray($objs, $_GET["sort_by"], $_GET["sort_order"]); $tbl->setMaxCount(count($entries)); $entries = array_slice($entries, $_GET["offset"], $_GET["limit"]); $tbl->render(); if (count($entries) > 0) { $i = 0; foreach ($entries as $entry) { if ($entry["entry"] == "." || $entry["entry"] == ".." && empty($cur_subdir)) { continue; } //$this->tpl->setVariable("ICON", $obj["title"]); if ($entry["type"] == "dir") { $this->tpl->setCurrentBlock("FileLink"); $this->ctrl->setParameter($this, "cdir", $cur_subdir); $this->ctrl->setParameter($this, "newdir", rawurlencode($entry["entry"])); $this->tpl->setVariable("LINK_FILENAME", $this->ctrl->getLinkTarget($this, "editFiles")); $this->tpl->setVariable("TXT_FILENAME", $entry["entry"]); $this->tpl->parseCurrentBlock(); $this->tpl->setVariable("ICON", "<img src=\"" . ilUtil::getImagePath("icon_cat.svg") . "\">"); } else { $this->tpl->setCurrentBlock("File"); $this->tpl->setVariable("TXT_FILENAME2", $entry["entry"]); $this->tpl->parseCurrentBlock(); } $this->tpl->setCurrentBlock("tbl_content"); $css_row = ilUtil::switchColor($i++, "tblrow1", "tblrow2"); $this->tpl->setVariable("CSS_ROW", $css_row); $this->tpl->setVariable("TXT_SIZE", $entry["size"]); $this->tpl->setVariable("CHECKBOX_ID", $entry["entry"]); $compare = !empty($cur_subdir) ? $cur_subdir . "/" . $entry["entry"] : $entry["entry"]; $purpose = array(); if ($std_item->getLocation() == $compare) { $purpose[] = $this->lng->txt("cont_std_view"); } if ($this->object->hasFullscreenItem()) { if ($full_item->getLocation() == $compare) { $purpose[] = $this->lng->txt("cont_fullscreen"); } } $this->tpl->setVariable("TXT_PURPOSE", implode($purpose, ", ")); $this->tpl->parseCurrentBlock(); } } else { $this->tpl->setCurrentBlock("notfound"); $this->tpl->setVariable("TXT_OBJECT_NOT_FOUND", $this->lng->txt("obj_not_found")); $this->tpl->setVariable("NUM_COLS", 4); $this->tpl->parseCurrentBlock(); } $this->tpl->parseCurrentBlock(); }
/** * get the path of a specific attachment * @param string md5 encrypted filename * @param integer mail_id * @access public * @return string path */ public function getAttachmentPathByMD5Filename($a_filename, $a_mail_id) { global $ilDB; /* $query = "SELECT path FROM mail_attachment ". "WHERE mail_id = ".$ilDB->quote($a_mail_id).""; $row = $this->ilias->db->getRow($query,DB_FETCHMODE_OBJECT); $path = $this->getMailPath().'/'.$row->path; */ $query = $ilDB->query("SELECT path FROM mail_attachment \n\t\t\t\t WHERE mail_id = " . $ilDB->quote($a_mail_id, 'integer') . ""); $rel_path = ""; while ($row = $ilDB->fetchObject($query)) { $rel_path = $row->path; $path = $this->getMailPath() . '/' . $row->path; } $files = ilUtil::getDir($path); foreach ((array) $files as $file) { if ($file['type'] == 'file' && md5($file['entry']) == $a_filename) { return array('path' => $this->getMailPath() . '/' . $rel_path . '/' . $file['entry'], 'filename' => $file['entry']); } } return ''; }
/** * Get files of directory * * @param string $a_subdir subdirectry * @return array array of files */ function getFilesOfDirectory($a_subdir = "") { $a_subdir = str_replace("..", "", $a_subdir); $dir = ilObjMediaObject::_getDirectory($this->getId()); if ($a_subdir != "") { $dir .= "/" . $a_subdir; } $files = array(); if (is_dir($dir)) { $entries = ilUtil::getDir($dir); foreach ($entries as $e) { if (is_file($dir . "/" . $e["entry"]) && $e["entry"] != "." && $e["entry"] != "..") { $files[] = $e["entry"]; } } } return $files; }
/** * Reads an import ZIP file and creates a certificate of it * * @return boolean TRUE if the import succeeds, FALSE otherwise */ public function importCertificate($zipfile, $filename) { include_once "./Services/Utilities/classes/class.ilUtil.php"; $importpath = $this->createArchiveDirectory(); if (!ilUtil::moveUploadedFile($zipfile, $filename, $importpath . $filename)) { ilUtil::delDir($importpath); return FALSE; } ilUtil::unzip($importpath . $filename, TRUE); $subdir = str_replace(".zip", "", strtolower($filename)) . "/"; $copydir = ""; if (is_dir($importpath . $subdir)) { $dirinfo = ilUtil::getDir($importpath . $subdir); $copydir = $importpath . $subdir; } else { $dirinfo = ilUtil::getDir($importpath); $copydir = $importpath; } $xmlfiles = 0; $otherfiles = 0; foreach ($dirinfo as $file) { if (strcmp($file["type"], "file") == 0) { if (strpos($file["entry"], ".xml") !== FALSE) { $xmlfiles++; } else { if (strpos($file["entry"], ".zip") !== FALSE) { } else { $otherfiles++; } } } } // if one XML file is in the archive, we try to import it if ($xmlfiles == 1) { foreach ($dirinfo as $file) { if (strcmp($file["type"], "file") == 0) { if (strpos($file["entry"], ".xml") !== FALSE) { $xsl = file_get_contents($copydir . $file["entry"]); // as long as we cannot make RPC calls in a given directory, we have // to add the complete path to every url $xsl = preg_replace("/url\\([']{0,1}(.*?)[']{0,1}\\)/", "url(" . $this->getAdapter()->getCertificatePath() . "\${1})", $xsl); $this->saveCertificate($xsl); } else { if (strpos($file["entry"], ".zip") !== FALSE) { } else { @copy($copydir . $file["entry"], $this->getAdapter()->getCertificatePath() . $file["entry"]); if (strcmp($this->getBackgroundImagePath(), $this->getAdapter()->getCertificatePath() . $file["entry"]) == 0) { // upload of the background image, create a preview ilUtil::convertImage($this->getBackgroundImagePath(), $this->getBackgroundImageThumbPath(), "JPEG", 100); } } } } } } else { ilUtil::delDir($importpath); return FALSE; } ilUtil::delDir($importpath); return TRUE; }
/** * Get personal data export file * * @param * @return */ function getPersonalDataExportFile() { include_once "./Services/Export/classes/class.ilExport.php"; $dir = ilExport::_getExportDirectory($this->getId(), "xml", "usr", "personal_data"); if (!is_dir($dir)) { return ""; } foreach (ilUtil::getDir($dir) as $entry) { if (is_int(strpos($entry["entry"], ".zip"))) { return $entry["entry"]; } } return ""; }
/** * get file data of a specific attachment * @param string|array md5 encrypted filename or array of multiple md5 encrypted files * @access public * @return boolean status */ function unlinkFilesByMD5Filenames($a_md5_filename) { $files = ilUtil::getDir($this->forum_path); if (is_array($a_md5_filename)) { foreach ((array) $files as $file) { if ($file['type'] == 'file' && in_array(md5($file['entry']), $a_md5_filename)) { unlink($this->forum_path . '/' . $file['entry']); } } return true; } else { foreach ((array) $files as $file) { if ($file['type'] == 'file' && md5($file['entry']) == $a_md5_filename) { return unlink($this->forum_path . '/' . $file['entry']); } } } return false; }
public function dbImportSco($slm, $sco, $asset = false) { $qtis = array(); $d = ilUtil::getDir($this->packageFolder); foreach ($d as $f) { //continue; if ($f[type] == 'file' && substr($f[entry], 0, 4) == 'qti_') { include_once "./Services/QTI/classes/class.ilQTIParser.php"; include_once "./Modules/Test/classes/class.ilObjTest.php"; $qtiParser = new ilQTIParser($this->packageFolder . "/" . $f[entry], IL_MO_VERIFY_QTI, 0, ""); $result = $qtiParser->startParsing(); $founditems =& $qtiParser->getFoundItems(); // die(print_r($founditems)); foreach ($founditems as $qp) { $newObj = new ilObjTest(0, true); // This creates a lot of invalid repository objects for each question // question are not repository objects (see e.g. table object_data), alex 29 Sep 2009 // $newObj->setType ( $qp ['type'] ); // $newObj->setTitle ( $qp ['title'] ); // $newObj->create ( true ); // $newObj->createReference (); // $newObj->putInTree ($_GET ["ref_id"]); // $newObj->setPermissions ( $sco->getId ()); // $newObj->notify ("new", $_GET["ref_id"], $sco->getId (), $_GET["ref_id"], $newObj->getRefId () ); // $newObj->mark_schema->flush (); $qtiParser = new ilQTIParser($this->packageFolder . "/" . $f[entry], IL_MO_PARSE_QTI, 0, ""); $qtiParser->setTestObject($newObj); $result = $qtiParser->startParsing(); // $newObj->saveToDb (); $qtis = array_merge($qtis, $qtiParser->getImportMapping()); } } } //exit; include_once 'Modules/Scorm2004/classes/class.ilSCORM2004Page.php'; $doc = new SimpleXMLElement($this->imsmanifest->saveXml()); $l = $doc->xpath("/ContentObject/MetaData"); if ($l[0]) { include_once 'Services/MetaData/classes/class.ilMDXMLCopier.php'; $mdxml =& new ilMDXMLCopier($l[0]->asXML(), $slm->getId(), $sco->getId(), $sco->getType()); $mdxml->startParsing(); $mdxml->getMDObject()->update(); } $l = $doc->xpath("/ContentObject/PageObject"); foreach ($l as $page_xml) { $tnode = $page_xml->xpath('MetaData/General/Title'); $page = new ilSCORM2004PageNode($slm); $page->setTitle($tnode[0]); $page->setSLMId($slm->getId()); $page->create(true); ilSCORM2004Node::putInTree($page, $sco->getId(), $target); $pmd = $page_xml->xpath("MetaData"); if ($pmd[0]) { include_once 'Services/MetaData/classes/class.ilMDXMLCopier.php'; $mdxml =& new ilMDXMLCopier($pmd[0]->asXML(), $slm->getId(), $page->getId(), $page->getType()); $mdxml->startParsing(); $mdxml->getMDObject()->update(); } $tnode = $page_xml->xpath("//MediaObject/MediaAlias | //InteractiveImage/MediaAlias"); foreach ($tnode as $ttnode) { include_once './Services/MediaObjects/classes/class.ilObjMediaObject.php'; $OriginId = $ttnode[OriginId]; $medianodes = $doc->xpath("//MediaObject[MetaData/General/Identifier/@Entry='" . $OriginId . "']"); $medianode = $medianodes[0]; if ($medianode) { $media_object = new ilObjMediaObject(); $media_object->setTitle($medianode->MetaData->General->Title); $media_object->setDescription($medianode->MetaData->General->Description); $media_object->create(false); $mmd = $medianode->xpath("MetaData"); if ($mmd[0]) { include_once 'Services/MetaData/classes/class.ilMDXMLCopier.php'; $mdxml =& new ilMDXMLCopier($mmd[0]->asXML(), 0, $media_object->getId(), $media_object->getType()); $mdxml->startParsing(); $mdxml->getMDObject()->update(); } // determine and create mob directory, move uploaded file to directory $media_object->createDirectory(); $mob_dir = ilObjMediaObject::_getDirectory($media_object->getId()); foreach ($medianode->MediaItem as $xMediaItem) { $media_item =& new ilMediaItem(); $media_object->addMediaItem($media_item); $media_item->setPurpose($xMediaItem[Purpose]); $media_item->setFormat($xMediaItem->Format); $media_item->setLocation($xMediaItem->Location); $media_item->setLocationType($xMediaItem->Location[Type]); $media_item->setWidth($xMediaItem->Layout[Width]); $media_item->setHeight($xMediaItem->Layout[Height]); $media_item->setHAlign($xMediaItem->Layout[HorizontalAlign]); $media_item->setCaption($xMediaItem->Caption); $media_item->setTextRepresentation($xMediaItem->TextRepresentation); $nr = 0; // add map areas (external links only) foreach ($xMediaItem->MapArea as $n => $v) { if ($v->ExtLink[Href] != "") { include_once "./Services/MediaObjects/classes/class.ilMapArea.php"; $ma = new ilMapArea(); $map_area = new ilMapArea(); $map_area->setShape($v[Shape]); $map_area->setCoords($v[Coords]); $map_area->setLinkType(IL_EXT_LINK); $map_area->setTitle($v->ExtLink); $map_area->setHref($v->ExtLink[Href]); $media_item->addMapArea($map_area); } } if ($media_item->getLocationType() == "LocalFile") { // $tmp_name = $this->packageFolder."/objects/".$OriginId."/".$xMediaItem->Location; // copy($tmp_name, $mob_dir."/".$xMediaItem->Location); } } // copy whole directory ilUtil::rCopy($this->packageFolder . "/objects/" . $OriginId, $mob_dir); // alex: fixed media import: these lines have been // behind the next curly bracket which makes it fail // when no medianode is given. (id=0 -> fatal error) ilUtil::renameExecutables($mob_dir); $media_object->update(true); $ttnode[OriginId] = "il__mob_" . $media_object->getId(); } } include_once "./Modules/File/classes/class.ilObjFile.php"; include_once "./Services/Utilities/classes/class.ilFileUtils.php"; include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php"; $intlinks = $page_xml->xpath("//IntLink"); foreach ($intlinks as $intlink) { if ($intlink[Type] != "File") { continue; } $path = $this->packageFolder . "/objects/" . str_replace('dfile', 'file', $intlink[Target]); if (!is_dir($path)) { continue; } $ffiles = array(); ilFileUtils::recursive_dirscan($path, $ffiles); $filename = $ffiles[file][0]; $fileObj = new ilObjFile(); $fileObj->setType("file"); $fileObj->setTitle(ilFileUtils::utf8_encode(ilUtil::stripSlashes($filename))); $fileObj->setFileName(ilFileUtils::utf8_encode(ilUtil::stripSlashes($filename))); // better use this, mime_content_type is deprecated $fileObj->setFileType(ilObjMediaObject::getMimeType($path . "/" . $filename)); $fileObj->setFileSize(filesize($path . "/" . $filename)); $fileObj->create(); $fileObj->createReference(); //$fileObj->putInTree($_GET["ref_id"]); //$fileObj->setPermissions($slm->getId ()); $fileObj->createDirectory(); $fileObj->storeUnzipedFile($path . "/" . $filename, ilFileUtils::utf8_encode(ilUtil::stripSlashes($filename))); $intlink[Target] = "il__dfile_" . $fileObj->getId(); } $fileitems = $page_xml->xpath("//FileItem/Identifier"); foreach ($fileitems as $fileitem) { $path = $this->packageFolder . "/objects/" . $fileitem[Entry]; if (!is_dir($path)) { continue; } $ffiles = array(); ilFileUtils::recursive_dirscan($path, $ffiles); $filename = $ffiles[file][0]; $fileObj = new ilObjFile(); $fileObj->setType("file"); $fileObj->setTitle(ilFileUtils::utf8_encode(ilUtil::stripSlashes($filename))); $fileObj->setFileName(ilFileUtils::utf8_encode(ilUtil::stripSlashes($filename))); // better use this, mime_content_type is deprecated $fileObj->setFileType(ilObjMediaObject::getMimeType($path . "/" . $filename)); $fileObj->setFileSize(filesize($path . "/" . $filename)); $fileObj->create(); $fileObj->createReference(); //$fileObj->putInTree($_GET["ref_id"]); //$fileObj->setPermissions($slm->getId ()); $fileObj->createDirectory(); $fileObj->storeUnzipedFile($path . "/" . $filename, ilFileUtils::utf8_encode(ilUtil::stripSlashes($filename))); $fileitem[Entry] = "il__file_" . $fileObj->getId(); } $pagex = new ilSCORM2004Page($page->getId()); $ddoc = new DOMDocument(); $ddoc->async = false; $ddoc->preserveWhiteSpace = false; $ddoc->formatOutput = false; $ddoc->loadXML($page_xml->asXML()); $xpath = new DOMXPath($ddoc); $tnode = $xpath->query('PageContent'); $t = "<PageObject>"; foreach ($tnode as $ttnode) { $t .= $ddoc->saveXML($ttnode); } $t .= "</PageObject>"; foreach ($qtis as $old => $q) { $t = str_replace($old, 'il__qst_' . $q['pool'], $t); } $pagex->setXMLContent($t); $pagex->updateFromXML(); } }
/** * delete object file */ function downloadFile() { if (!isset($_POST["file"])) { $this->ilias->raiseError($this->lng->txt("no_checkbox"), $this->ilias->error_obj->MESSAGE); } if (count($_POST["file"]) > 1) { $this->ilias->raiseError($this->lng->txt("cont_select_max_one_item"), $this->ilias->error_obj->MESSAGE); } $cur_subdir = str_replace(".", "", ilUtil::stripSlashes($_GET["cdir"])); $cur_dir = !empty($cur_subdir) ? $this->main_dir . "/" . $cur_subdir : $this->main_dir; $file = $cur_dir . "/" . $_POST["file"][0]; // validate against files of current directory $valid = false; foreach (ilUtil::getDir($cur_dir) as $entry) { if ($entry["type"] == "file" && $cur_dir . "/" . $entry["entry"] == $file) { $valid = true; break; } } if (@is_file($file) && !@is_dir($file) && $valid) { ilUtil::deliverFile($file, $_POST["file"][0]); exit; } else { $this->ctrl->saveParameter($this, "cdir"); $this->ctrl->redirect($this, "listFiles"); } }
/** * display form for user import */ function importUserRoleAssignmentObject() { global $ilUser, $rbacreview, $tpl, $lng, $ilCtrl; // Blind out tabs for local user import if ($_GET["baseClass"] == 'ilRepositoryGUI') { $this->tabs_gui->clearTargets(); } $this->initUserImportForm(); if ($this->form->checkInput()) { include_once './Services/AccessControl/classes/class.ilObjRole.php'; include_once './Services/User/classes/class.ilUserImportParser.php'; global $rbacreview, $rbacsystem, $tree, $lng; $this->tpl->addBlockfile("ADM_CONTENT", "adm_content", "tpl.usr_import_roles.html", "Services/User"); $import_dir = $this->getImportDir(); // recreate user import directory if (@is_dir($import_dir)) { ilUtil::delDir($import_dir); } ilUtil::makeDir($import_dir); // move uploaded file to user import directory $file_name = $_FILES["importFile"]["name"]; $parts = pathinfo($file_name); $full_path = $import_dir . "/" . $file_name; // check if import file exists if (!is_file($_FILES["importFile"]["tmp_name"])) { ilUtil::delDir($import_dir); $this->ilias->raiseError($this->lng->txt("no_import_file_found"), $this->ilias->error_obj->MESSAGE); } ilUtil::moveUploadedFile($_FILES["importFile"]["tmp_name"], $_FILES["importFile"]["name"], $full_path); // handle zip file if (strtolower($parts["extension"]) == "zip") { // unzip file ilUtil::unzip($full_path); $xml_file = null; $file_list = ilUtil::getDir($import_dir); foreach ($file_list as $a_file) { if (substr($a_file['entry'], -4) == '.xml') { $xml_file = $import_dir . "/" . $a_file['entry']; break; } } if (is_null($xml_file)) { $subdir = basename($parts["basename"], "." . $parts["extension"]); $xml_file = $import_dir . "/" . $subdir . "/" . $subdir . ".xml"; } } else { $xml_file = $full_path; } // check xml file if (!is_file($xml_file)) { ilUtil::delDir($import_dir); $this->ilias->raiseError($this->lng->txt("no_xml_file_found_in_zip") . " " . $subdir . "/" . $subdir . ".xml", $this->ilias->error_obj->MESSAGE); } require_once "./Services/User/classes/class.ilUserImportParser.php"; // Verify the data // --------------- $importParser = new ilUserImportParser($xml_file, IL_VERIFY); $importParser->startParsing(); switch ($importParser->getErrorLevel()) { case IL_IMPORT_SUCCESS: break; case IL_IMPORT_WARNING: $this->tpl->setVariable("IMPORT_LOG", $importParser->getProtocolAsHTML($lng->txt("verification_warning_log"))); break; case IL_IMPORT_FAILURE: ilUtil::delDir($import_dir); $this->ilias->raiseError($lng->txt("verification_failed") . $importParser->getProtocolAsHTML($lng->txt("verification_failure_log")), $this->ilias->error_obj->MESSAGE); return; } // Create the role selection form // ------------------------------ $this->tpl->setCurrentBlock("role_selection_form"); $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this)); $this->tpl->setVariable("TXT_IMPORT_USERS", $this->lng->txt("import_users")); $this->tpl->setVariable("TXT_IMPORT_FILE", $this->lng->txt("import_file")); $this->tpl->setVariable("IMPORT_FILE", $file_name); $this->tpl->setVariable("TXT_USER_ELEMENT_COUNT", $this->lng->txt("num_users")); $this->tpl->setVariable("USER_ELEMENT_COUNT", $importParser->getUserCount()); $this->tpl->setVariable("TXT_ROLE_ASSIGNMENT", $this->lng->txt("role_assignment")); $this->tpl->setVariable("BTN_IMPORT", $this->lng->txt("import")); $this->tpl->setVariable("BTN_CANCEL", $this->lng->txt("cancel")); $this->tpl->setVariable("XML_FILE_NAME", $xml_file); // Extract the roles $importParser = new ilUserImportParser($xml_file, IL_EXTRACT_ROLES); $importParser->startParsing(); $roles = $importParser->getCollectedRoles(); // get global roles $all_gl_roles = $rbacreview->getRoleListByObject(ROLE_FOLDER_ID); $gl_roles = array(); $roles_of_user = $rbacreview->assignedRoles($ilUser->getId()); foreach ($all_gl_roles as $obj_data) { // check assignment permission if called from local admin if ($this->object->getRefId() != USER_FOLDER_ID) { if (!in_array(SYSTEM_ROLE_ID, $roles_of_user) && !ilObjRole::_getAssignUsersStatus($obj_data['obj_id'])) { continue; } } // exclude anonymous role from list if ($obj_data["obj_id"] != ANONYMOUS_ROLE_ID) { // do not allow to assign users to administrator role if current user does not has SYSTEM_ROLE_ID if ($obj_data["obj_id"] != SYSTEM_ROLE_ID or in_array(SYSTEM_ROLE_ID, $roles_of_user)) { $gl_roles[$obj_data["obj_id"]] = $obj_data["title"]; } } } // global roles $got_globals = false; foreach ($roles as $role_id => $role) { if ($role["type"] == "Global") { if (!$got_globals) { $got_globals = true; $this->tpl->setCurrentBlock("global_role_section"); $this->tpl->setVariable("TXT_GLOBAL_ROLES_IMPORT", $this->lng->txt("roles_of_import_global")); $this->tpl->setVariable("TXT_GLOBAL_ROLES", $this->lng->txt("assign_global_role")); } // pre selection for role $pre_select = array_search($role[name], $gl_roles); if (!$pre_select) { switch ($role["name"]) { case "Administrator": // ILIAS 2/3 Administrator $pre_select = array_search("Administrator", $gl_roles); break; case "Autor": // ILIAS 2 Author $pre_select = array_search("User", $gl_roles); break; case "Lerner": // ILIAS 2 Learner $pre_select = array_search("User", $gl_roles); break; case "Gast": // ILIAS 2 Guest $pre_select = array_search("Guest", $gl_roles); break; default: $pre_select = array_search("User", $gl_roles); break; } } $this->tpl->setCurrentBlock("global_role"); $role_select = ilUtil::formSelect($pre_select, "role_assign[" . $role_id . "]", $gl_roles, false, true); $this->tpl->setVariable("TXT_IMPORT_GLOBAL_ROLE", $role["name"] . " [" . $role_id . "]"); $this->tpl->setVariable("SELECT_GLOBAL_ROLE", $role_select); $this->tpl->parseCurrentBlock(); } } // Check if local roles need to be assigned $got_locals = false; foreach ($roles as $role_id => $role) { if ($role["type"] == "Local") { $got_locals = true; break; } } if ($got_locals) { $this->tpl->setCurrentBlock("local_role_section"); $this->tpl->setVariable("TXT_LOCAL_ROLES_IMPORT", $this->lng->txt("roles_of_import_local")); $this->tpl->setVariable("TXT_LOCAL_ROLES", $this->lng->txt("assign_local_role")); // get local roles if ($this->object->getRefId() == USER_FOLDER_ID) { // The import function has been invoked from the user folder // object. In this case, we show only matching roles, // because the user folder object is considered the parent of all // local roles and may contains thousands of roles on large ILIAS // installations. $loc_roles = array(); foreach ($roles as $role_id => $role) { if ($role["type"] == "Local") { $searchName = substr($role['name'], 0, 1) == '#' ? $role['name'] : '#' . $role['name']; $matching_role_ids = $rbacreview->searchRolesByMailboxAddressList($searchName); foreach ($matching_role_ids as $mid) { if (!in_array($mid, $loc_roles)) { $loc_roles[] = array('obj_id' => $mid); } } } } } else { // The import function has been invoked from a locally // administrated category. In this case, we show all roles // contained in the subtree of the category. $loc_roles = $rbacreview->getAssignableRolesInSubtree($this->object->getRefId()); } $l_roles = array(); // create a search array with . $l_roles_mailbox_searcharray = array(); foreach ($loc_roles as $key => $loc_role) { // fetch context path of role $rolf = $rbacreview->getFoldersAssignedToRole($loc_role["obj_id"], true); // only process role folders that are not set to status "deleted" // and for which the user has write permissions. // We also don't show the roles which are in the ROLE_FOLDER_ID folder. // (The ROLE_FOLDER_ID folder contains the global roles). if (!$rbacreview->isDeleted($rolf[0]) && $rbacsystem->checkAccess('write', $tree->getParentId($rolf[0])) && $rolf[0] != ROLE_FOLDER_ID) { // A local role is only displayed, if it is contained in the subtree of // the localy administrated category. If the import function has been // invoked from the user folder object, we show all local roles, because // the user folder object is considered the parent of all local roles. // Thus, if we start from the user folder object, we initialize the // isInSubtree variable with true. In all other cases it is initialized // with false, and only set to true if we find the object id of the // locally administrated category in the tree path to the local role. $isInSubtree = $this->object->getRefId() == USER_FOLDER_ID; $path = ""; if ($this->tree->isInTree($rolf[0])) { // Create path. Paths which have more than 4 segments // are truncated in the middle. $tmpPath = $this->tree->getPathFull($rolf[0]); for ($i = 1, $n = count($tmpPath) - 1; $i < $n; $i++) { if ($i > 1) { $path = $path . ' > '; } if ($i < 3 || $i > $n - 3) { $path = $path . $tmpPath[$i]['title']; } else { if ($i == 3 || $i == $n - 3) { $path = $path . '...'; } } $isInSubtree |= $tmpPath[$i]['obj_id'] == $this->object->getId(); } } else { $path = "<b>Rolefolder " . $rolf[0] . " not found in tree! (Role " . $loc_role["obj_id"] . ")</b>"; } $roleMailboxAddress = $rbacreview->getRoleMailboxAddress($loc_role['obj_id']); $l_roles[$loc_role['obj_id']] = $roleMailboxAddress . ', ' . $path; } } //foreach role $l_roles[""] = ""; natcasesort($l_roles); $l_roles[""] = $this->lng->txt("usrimport_ignore_role"); foreach ($roles as $role_id => $role) { if ($role["type"] == "Local") { $this->tpl->setCurrentBlock("local_role"); $this->tpl->setVariable("TXT_IMPORT_LOCAL_ROLE", $role["name"]); $searchName = substr($role['name'], 0, 1) == '#' ? $role['name'] : '#' . $role['name']; $matching_role_ids = $rbacreview->searchRolesByMailboxAddressList($searchName); $pre_select = count($matching_role_ids) == 1 ? $matching_role_ids[0] : ""; if ($this->object->getRefId() == USER_FOLDER_ID) { // There are too many roles in a large ILIAS installation // that's why whe show only a choice with the the option "ignore", // and the matching roles. $selectable_roles = array(); $selectable_roles[""] = $this->lng->txt("usrimport_ignore_role"); foreach ($matching_role_ids as $id) { $selectable_roles[$id] = $l_roles[$id]; } $role_select = ilUtil::formSelect($pre_select, "role_assign[" . $role_id . "]", $selectable_roles, false, true); } else { $role_select = ilUtil::formSelect($pre_select, "role_assign[" . $role_id . "]", $l_roles, false, true); } $this->tpl->setVariable("SELECT_LOCAL_ROLE", $role_select); $this->tpl->parseCurrentBlock(); } } } // $this->tpl->setVariable("TXT_CONFLICT_HANDLING", $lng->txt("conflict_handling")); $handlers = array(IL_IGNORE_ON_CONFLICT => "ignore_on_conflict", IL_UPDATE_ON_CONFLICT => "update_on_conflict"); $this->tpl->setVariable("TXT_CONFLICT_HANDLING_INFO", str_replace('\\n', '<br>', $this->lng->txt("usrimport_conflict_handling_info"))); $this->tpl->setVariable("TXT_CONFLICT_CHOICE", $lng->txt("conflict_handling")); $this->tpl->setVariable("SELECT_CONFLICT", ilUtil::formSelect(IL_IGNORE_ON_CONFLICT, "conflict_handling_choice", $handlers, false, false)); // new account mail $this->lng->loadLanguageModule("mail"); include_once './Services/User/classes/class.ilObjUserFolder.php'; $amail = ilObjUserFolder::_lookupNewAccountMail($this->lng->getDefaultLanguage()); if (trim($amail["body"]) != "" && trim($amail["subject"]) != "") { $this->tpl->setCurrentBlock("inform_user"); $this->tpl->setVariable("TXT_ACCOUNT_MAIL", $lng->txt("mail_account_mail")); if (true) { $this->tpl->setVariable("SEND_MAIL", " checked=\"checked\""); } $this->tpl->setVariable("TXT_INFORM_USER_MAIL", $this->lng->txt("user_send_new_account_mail")); $this->tpl->parseCurrentBlock(); } } else { $this->form->setValuesByPost(); $tpl->setContent($this->form->getHtml()); } }
/** * get directory * * @static * */ public static function getDir($a_dir, $a_rec = false, $a_sub_dir = "") { $current_dir = opendir($a_dir . $a_sub_dir); $dirs = array(); $files = array(); $subitems = array(); while ($entry = readdir($current_dir)) { if (is_dir($a_dir . "/" . $entry)) { $dirs[$entry] = array("type" => "dir", "entry" => $entry, "subdir" => $a_sub_dir); if ($a_rec && $entry != "." && $entry != "..") { $si = ilUtil::getDir($a_dir, true, $a_sub_dir . "/" . $entry); $subitems = array_merge($subitems, $si); } } else { if ($entry != "." && $entry != "..") { $size = filesize($a_dir . $a_sub_dir . "/" . $entry); $files[$entry] = array("type" => "file", "entry" => $entry, "size" => $size, "subdir" => $a_sub_dir); } } } ksort($dirs); ksort($files); return array_merge($dirs, $files, $subitems); }