public function getXmlRepresentation($a_entity, $a_schema_version, $a_id) { ilUtil::makeDirParents($this->getAbsoluteExportDirectory()); $this->ds->setExportDirectories($this->dir_relative, $this->dir_absolute); $this->ds->exportLibraryFile($a_id); return $this->ds->getXmlRepresentation($a_entity, $a_schema_version, $a_id, '', true, true); }
public function create() { if (!file_exists($this->getPath())) { ilUtil::makeDirParents($this->getPath()); } return true; }
function importXmlRepresentation($a_entity, $a_id, $a_xml, $a_mapping) { // see ilStyleExporter::getXmlRepresentation() if (preg_match("/<StyleSheetExport><ImagePath>(.+)<\\/ImagePath>/", $a_xml, $hits)) { $path = $hits[1]; $a_xml = str_replace($hits[0], "", $a_xml); $a_xml = str_replace("</StyleSheetExport>", "", $a_xml); } // temp xml-file $tmp_file = $this->getImportDirectory() . "/sty_" . $a_id . ".xml"; file_put_contents($tmp_file, $a_xml); include_once "./Services/Style/classes/class.ilObjStyleSheet.php"; $style = new ilObjStyleSheet(); $style->createFromXMLFile($tmp_file); $new_id = $style->getId(); unlink($tmp_file); // images if ($path) { $source = $this->getImportDirectory() . "/" . $path; if (is_dir($source)) { $target = $style->getImagesDirectory(); if (!is_dir($target)) { ilUtil::makeDirParents($target); } ilUtil::rCopy($source, $target); } } $a_mapping->addMapping("Services/Style", "sty", $a_id, $new_id); }
private function initDirectory() { if (is_writable($this->getPath())) { if (ilUtil::makeDirParents($this->shop_path)) { return true; } } return false; }
public function getXmlRepresentation($a_entity, $a_schema_version, $a_id) { include_once "Services/Style/classes/class.ilObjStyleSheet.php"; $style = new ilObjStyleSheet($a_id, false); // images $target = $this->getAbsoluteExportDirectory(); if ($target && !is_dir($target)) { ilUtil::makeDirParents($target); } ilUtil::rCopy($style->getImagesDirectory(), $target); return "<StyleSheetExport>" . "<ImagePath>" . $this->getRelativeExportDirectory() . "</ImagePath>" . $style->getXML() . "</StyleSheetExport>"; }
/** * Get xml representation * * @param string entity * @param string target release * @param string id * @return string xml string */ public function getXmlRepresentation($a_entity, $a_schema_version, $a_id) { $xml = ''; include_once 'Modules/Forum/classes/class.ilForumXMLWriter.php'; if (ilObject::_lookupType($a_id) == 'frm') { $writer = new ilForumXMLWriter(); $writer->setForumId($a_id); ilUtil::makeDirParents($this->getAbsoluteExportDirectory()); $writer->setFileTargetDirectories($this->getRelativeExportDirectory(), $this->getAbsoluteExportDirectory()); $writer->start(); $xml .= $writer->getXml(); } return $xml; }
public function saveImage($data, $filename) { $image =& base64_decode($data); $imagepath = $this->object->getImagePath(); include_once "./Services/Utilities/classes/class.ilUtil.php"; if (!file_exists($imagepath)) { ilUtil::makeDirParents($imagepath); } $imagepath .= $filename; $fh = fopen($imagepath, "wb"); if ($fh == false) { } else { $imagefile = fwrite($fh, $image); fclose($fh); } }
/** * Get xml representation * * @param string entity * @param string target release * @param string id * @return string xml string */ public function getXmlRepresentation($a_entity, $a_schema_version, $a_id) { include_once "./Modules/File/classes/class.ilObjFile.php"; include_once "./Modules/File/classes/class.ilFileXMLWriter.php"; if (ilObject::_lookupType($a_id) == "file") { $file = new ilObjFile($a_id, false); $writer = new ilFileXMLWriter(); $writer->setFile($file); $writer->setOmitHeader(true); $writer->setAttachFileContents(ilFileXMLWriter::$CONTENT_ATTACH_COPY); ilUtil::makeDirParents($this->getAbsoluteExportDirectory()); $writer->setFileTargetDirectories($this->getRelativeExportDirectory(), $this->getAbsoluteExportDirectory()); $writer->start(); $xml .= $writer->getXml(); } return $xml; }
/** * Generate the report for given certificate * * @param srCertificate $cert * @throws ilException * @return bool */ public function generate(srCertificate $cert) { if (!$this->isAvailable()) { throw new ilException("Generating certificates with TemplateTypeJasper is only available if the JasperReport service is installed"); } require_once self::JASPER_CLASS; $template = $cert->getDefinition()->getType()->getCertificateTemplatesPath(true); // A template is required, so quit early if it does not exist for some reason if (!is_file($template)) { return false; } $placeholders = $cert->getPlaceholders(); try { $defined_placeholders = $this->parseDefinedPlaceholders($template); } catch (Exception $e) { // XML is not valid return false; } // Only send defined placeholders to jasper, otherwise the template file is not considered as valid $placeholders = array_intersect_key($placeholders, $defined_placeholders); $placeholders = $this->nl2br($placeholders); $report = new JasperReport($template, $cert->getFilename(false)); if ($locale = $this->pl->config('jasper_locale')) { $report->setLocale($this->pl->config('jasper_locale')); } if ($java = $this->pl->config('jasper_path_java')) { $report->setPathJava($java); } $report->setDataSource(JasperReport::DATASOURCE_EMPTY); $report->setParameters($placeholders); try { $report->generateOutput(); $report_file = $report->getOutputFile(); // Move pdf to correct certificate location $cert_path = $cert->getCertificatePath(); if (!file_exists($cert_path)) { ilUtil::makeDirParents($cert_path); } $from = $report_file . '.pdf'; $to = $cert->getFilePath(); return ilUtil::moveUploadedFile($from, '', $to, false, 'rename'); } catch (JasperReportException $e) { $this->log->write("srCertificateTemplyteTypeJasper::generate() Report file of certificate with ID {$cert->getId()} was not created by Jasper: " . implode(', ', $e->getErrors())); return false; } }
/** * * @param ilTestExportFilename $filename */ protected function buildExportFile(ilTestExportFilename $filename) { // Creating Files with Charts using PHPExcel require_once './Customizing/global/plugins/Modules/Test/Export/TestStatisticsExport/classes/PHPExcel-1.8/Classes/PHPExcel.php'; $objPHPExcel = new PHPExcel(); // Create the first sheet with general data about the test $objWorksheet = $objPHPExcel->getActiveSheet(); $this->createFrameSheet1($objWorksheet); $this->fillInQuestionDataSheet1($objWorksheet); $this->calculateSummarySheet1($objWorksheet); // Create the second sheet, with questionspecific data //Durch neue Trennschärfeformel überflüssig //$this->createProductArray ( $objPHPExcel); //Durch neue Trennschärfeformel überflüssig //$this->createTrueFalseArrayAndProductArray($objPHPExcel); $this->calculateDiscrimationIndex($objPHPExcel); // Save XSLX file ilUtil::makeDirParents(dirname($filename->getPathname('xlsx', 'statistics'))); $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); $objWriter->setIncludeCharts(TRUE); $objWriter->save(str_replace(__FILE__, $filename->getPathname('xlsx', 'statistics'), __FILE__)); }
/** * Checks if smiley folder is available; if not * it will try to create folder and performs * actions for an initial smiley set * * @global ilLanguage $lng * @return boolean */ public static function _checkSetup() { global $lng; $path = self::_getSmileyDir(); if (!is_dir($path)) { ilUtil::sendInfo($lng->txt('chatroom_smilies_dir_not_exists')); ilUtil::makeDirParents($path); if (!is_dir($path)) { ilUtil::sendFailure($lng->txt('chatroom_smilies_dir_not_available')); return false; } else { $smilies = array("icon_smile.gif", "icon_wink.gif", "icon_laugh.gif", "icon_sad.gif", "icon_shocked.gif", "icon_tongue.gif", "icon_cool.gif", "icon_eek.gif", "icon_angry.gif", "icon_flush.gif", "icon_idea.gif", "icon_thumbup.gif", "icon_thumbdown.gif"); foreach ($smilies as $smiley) { copy("templates/default/images/emoticons/{$smiley}", $path . "/{$smiley}"); } self::_insertDefaultValues(); ilUtil::sendSuccess($lng->txt('chatroom_smilies_initialized')); } } if (!is_writable($path)) { ilUtil::sendInfo($lng->txt('chatroom_smilies_dir_not_writable')); } return true; }
/** * init function: create import directory, delete old files * * @access private * */ private function init() { if (!@is_dir($this->import_dir)) { ilUtil::makeDirParents($this->import_dir); } }
/** * get user import directory name */ function getImportDir() { // For each user session a different directory must be used to prevent // that one user session overwrites the import data that another session // is currently importing. global $ilUser; $importDir = ilUtil::getDataDir() . '/user_import/usr_' . $ilUser->getId() . '_' . session_id(); ilUtil::makeDirParents($importDir); return $importDir; }
/** * Allows to add suggested solutions for questions * * @access public */ public function suggestedsolution() { global $ilUser; global $ilAccess; if ($_POST["deleteSuggestedSolution"] == 1) { $this->object->deleteSuggestedSolutions(); ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true); $this->ctrl->redirect($this, "suggestedsolution"); } $save = is_array($_POST["cmd"]) && array_key_exists("suggestedsolution", $_POST["cmd"]) ? TRUE : FALSE; $output = ""; $solution_array = $this->object->getSuggestedSolution(0); $options = array("lm" => $this->lng->txt("obj_lm"), "st" => $this->lng->txt("obj_st"), "pg" => $this->lng->txt("obj_pg"), "git" => $this->lng->txt("glossary_term"), "file" => $this->lng->txt("fileDownload"), "text" => $this->lng->txt("solutionText")); if (strcmp($_POST["solutiontype"], "file") == 0 && strcmp($solution_array["type"], "file") != 0) { $solution_array = array("type" => "file"); } elseif (strcmp($_POST["solutiontype"], "text") == 0 && strcmp($solution_array["type"], "text") != 0) { $solution_array = array("type" => "text", "value" => $this->getSolutionOutput(0, NULL, FALSE, FALSE, TRUE, FALSE, TRUE)); } if ($save && strlen($_POST["filename"])) { $solution_array["value"]["filename"] = $_POST["filename"]; } if ($save && strlen($_POST["solutiontext"])) { $solution_array["value"] = $_POST["solutiontext"]; } include_once "./Services/Form/classes/class.ilPropertyFormGUI.php"; if (count($solution_array)) { $form = new ilPropertyFormGUI(); $form->setFormAction($this->ctrl->getFormAction($this)); $form->setTitle($this->lng->txt("solution_hint")); $form->setMultipart(TRUE); $form->setTableWidth("100%"); $form->setId("suggestedsolutiondisplay"); // suggested solution output include_once "./Modules/TestQuestionPool/classes/class.ilSolutionTitleInputGUI.php"; $title = new ilSolutionTitleInputGUI($this->lng->txt("showSuggestedSolution"), "solutiontype"); $template = new ilTemplate("tpl.il_as_qpl_suggested_solution_input_presentation.html", TRUE, TRUE, "Modules/TestQuestionPool"); if (strlen($solution_array["internal_link"])) { $href = assQuestion::_getInternalLinkHref($solution_array["internal_link"]); $template->setCurrentBlock("preview"); $template->setVariable("TEXT_SOLUTION", $this->lng->txt("suggested_solution")); $template->setVariable("VALUE_SOLUTION", " <a href=\"{$href}\" target=\"content\">" . $this->lng->txt("view") . "</a> "); $template->parseCurrentBlock(); } elseif (strcmp($solution_array["type"], "file") == 0 && is_array($solution_array["value"])) { $href = $this->object->getSuggestedSolutionPathWeb() . $solution_array["value"]["name"]; $template->setCurrentBlock("preview"); $template->setVariable("TEXT_SOLUTION", $this->lng->txt("suggested_solution")); $template->setVariable("VALUE_SOLUTION", " <a href=\"{$href}\" target=\"content\">" . ilUtil::prepareFormOutput(strlen($solution_array["value"]["filename"]) ? $solution_array["value"]["filename"] : $solution_array["value"]["name"]) . "</a> "); $template->parseCurrentBlock(); } $template->setVariable("TEXT_TYPE", $this->lng->txt("type")); $template->setVariable("VALUE_TYPE", $options[$solution_array["type"]]); $title->setHtml($template->get()); $deletesolution = new ilCheckboxInputGUI("", "deleteSuggestedSolution"); $deletesolution->setOptionTitle($this->lng->txt("deleteSuggestedSolution")); $title->addSubItem($deletesolution); $form->addItem($title); if (strcmp($solution_array["type"], "file") == 0) { // file $file = new ilFileInputGUI($this->lng->txt("fileDownload"), "file"); $file->setRequired(TRUE); $file->enableFileNameSelection("filename"); //$file->setSuffixes(array("doc","xls","png","jpg","gif","pdf")); if ($_FILES["file"]["tmp_name"] && $file->checkInput()) { if (!file_exists($this->object->getSuggestedSolutionPath())) { ilUtil::makeDirParents($this->object->getSuggestedSolutionPath()); } $res = ilUtil::moveUploadedFile($_FILES["file"]["tmp_name"], $_FILES["file"]["name"], $this->object->getSuggestedSolutionPath() . $_FILES["file"]["name"]); if ($res) { ilUtil::renameExecutables($this->object->getSuggestedSolutionPath()); // remove an old file download if (is_array($solution_array["value"])) { @unlink($this->object->getSuggestedSolutionPath() . $solution_array["value"]["name"]); } $file->setValue($_FILES["file"]["name"]); $this->object->saveSuggestedSolution("file", "", 0, array("name" => $_FILES["file"]["name"], "type" => $_FILES["file"]["type"], "size" => $_FILES["file"]["size"], "filename" => $_POST["filename"])); $originalexists = $this->object->_questionExistsInPool($this->object->original_id); if (($_GET["calling_test"] || isset($_GET['calling_consumer']) && (int) $_GET['calling_consumer']) && $originalexists && assQuestion::_isWriteable($this->object->original_id, $ilUser->getId())) { return $this->originalSyncForm("suggestedsolution"); } else { ilUtil::sendSuccess($this->lng->txt("suggested_solution_added_successfully"), TRUE); $this->ctrl->redirect($this, "suggestedsolution"); } } else { // BH: $res as info string? wtf? it holds a bool or something else!!? ilUtil::sendInfo($res); } } else { if (is_array($solution_array["value"])) { $file->setValue($solution_array["value"]["name"]); $file->setFilename(strlen($solution_array["value"]["filename"]) ? $solution_array["value"]["filename"] : $solution_array["value"]["name"]); } } $form->addItem($file); $hidden = new ilHiddenInputGUI("solutiontype"); $hidden->setValue("file"); $form->addItem($hidden); } else { if (strcmp($solution_array["type"], "text") == 0) { $question = new ilTextAreaInputGUI($this->lng->txt("solutionText"), "solutiontext"); $question->setValue($this->object->prepareTextareaOutput($solution_array["value"])); $question->setRequired(TRUE); $question->setRows(10); $question->setCols(80); $question->setUseRte(TRUE); $question->addPlugin("latex"); $question->addButton("latex"); $question->setRTESupport($this->object->getId(), "qpl", "assessment"); $hidden = new ilHiddenInputGUI("solutiontype"); $hidden->setValue("text"); $form->addItem($hidden); $form->addItem($question); } } if ($ilAccess->checkAccess("write", "", $_GET['ref_id'])) { $form->addCommandButton("suggestedsolution", $this->lng->txt("save")); } if ($save) { if ($form->checkInput()) { switch ($solution_array["type"]) { case "file": $this->object->saveSuggestedSolution("file", "", 0, array("name" => $solution_array["value"]["name"], "type" => $solution_array["value"]["type"], "size" => $solution_array["value"]["size"], "filename" => $_POST["filename"])); break; case "text": $this->object->saveSuggestedSolution("text", "", 0, $solution_array["value"]); break; } $originalexists = $this->object->_questionExistsInPool($this->object->original_id); if (($_GET["calling_test"] || isset($_GET['calling_consumer']) && (int) $_GET['calling_consumer']) && $originalexists && assQuestion::_isWriteable($this->object->original_id, $ilUser->getId())) { return $this->originalSyncForm("suggestedsolution"); } else { ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true); $this->ctrl->redirect($this, "suggestedsolution"); } } } $output = $form->getHTML(); } $savechange = strcmp($this->ctrl->getCmd(), "saveSuggestedSolution") == 0 ? TRUE : FALSE; $changeoutput = ""; if ($ilAccess->checkAccess("write", "", $_GET['ref_id'])) { $formchange = new ilPropertyFormGUI(); $formchange->setFormAction($this->ctrl->getFormAction($this)); $formchange->setTitle(count($solution_array) ? $this->lng->txt("changeSuggestedSolution") : $this->lng->txt("addSuggestedSolution")); $formchange->setMultipart(FALSE); $formchange->setTableWidth("100%"); $formchange->setId("suggestedsolution"); $solutiontype = new ilRadioGroupInputGUI($this->lng->txt("suggestedSolutionType"), "solutiontype"); foreach ($options as $opt_value => $opt_caption) { $solutiontype->addOption(new ilRadioOption($opt_caption, $opt_value)); } if (count($solution_array)) { $solutiontype->setValue($solution_array["type"]); } $solutiontype->setRequired(TRUE); $formchange->addItem($solutiontype); $formchange->addCommandButton("saveSuggestedSolution", $this->lng->txt("select")); if ($savechange) { $formchange->checkInput(); } $changeoutput = $formchange->getHTML(); } $this->tpl->setVariable("ADM_CONTENT", $changeoutput . $output); }
protected function cloneAnswerImages($sourceQuestionId, $sourceParentId, $targetQuestionId, $targetParentId) { global $ilLog; $sourcePath = $this->buildImagePath($sourceQuestionId, $sourceParentId); $targetPath = $this->buildImagePath($targetQuestionId, $targetParentId); foreach ($this->getAnswers() as $answer) { $filename = $answer->getImageFile(); if (strlen($filename)) { if (!file_exists($targetPath)) { ilUtil::makeDirParents($targetPath); } if (!@copy($sourcePath . $filename, $targetPath . $filename)) { $ilLog->write("image could not be duplicated!!!!", $ilLog->ERROR); $ilLog->write("object: " . print_r($this, TRUE), $ilLog->ERROR); } if (@file_exists($sourcePath . $this->getThumbPrefix() . $filename)) { if (!@copy($sourcePath . $this->getThumbPrefix() . $filename, $targetPath . $this->getThumbPrefix() . $filename)) { $ilLog->write("image thumbnail could not be duplicated!!!!", $ilLog->ERROR); $ilLog->write("object: " . print_r($this, TRUE), $ilLog->ERROR); } } } } }
/** * store paragraph into file directory * files/codefile_$pg_id_$paragraph_id/downloadtitle */ function handleCodeParagraph($page_id, $paragraph_id, $title, $text) { $directory = $this->getOfflineDirectory() . "/codefiles/" . $page_id . "/" . $paragraph_id; ilUtil::makeDirParents($directory); $file = $directory . "/" . $title; if (!($fp = @fopen($file, "w+"))) { die("<b>Error</b>: Could not open \"" . $file . "\" for writing" . " in <b>" . __FILE__ . "</b> on line <b>" . __LINE__ . "</b><br />"); } chmod($file, 0770); fwrite($fp, $text); fclose($fp); }
/** * Creates a question from a QTI file * * Receives parameters from a QTI parser and creates a valid ILIAS question object * * @param object $item The QTI item object * @param integer $questionpool_id The id of the parent questionpool * @param integer $tst_id The id of the parent test if the question is part of a test * @param object $tst_object A reference to the parent test object * @param integer $question_counter A reference to a question counter to count the questions of an imported question pool * @param array $import_mapping An array containing references to included ILIAS objects * @access public */ function fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping) { global $ilUser; // empty session variable for imported xhtml mobs unset($_SESSION["import_mob_xhtml"]); $presentation = $item->getPresentation(); $duration = $item->getDuration(); $now = getdate(); $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']); $feedbacksgeneric = array(); $this->object->setTitle($item->getTitle()); $this->object->setNrOfTries($item->getMaxattempts()); $this->object->setComment($item->getComment()); $this->object->setAuthor($item->getAuthor()); $this->object->setOwner($ilUser->getId()); $this->object->setQuestion($this->object->QTIMaterialToString($item->getQuestiontext())); $this->object->setObjId($questionpool_id); $this->object->setEstimatedWorkingTime($duration["h"], $duration["m"], $duration["s"]); $this->object->setWidth($item->getMetadataEntry("width")); $this->object->setHeight($item->getMetadataEntry("height")); $this->object->setApplet($item->getMetadataEntry("applet")); $this->object->setParameters(unserialize($item->getMetadataEntry("params"))); $this->object->setPoints($item->getMetadataEntry("points")); $this->object->saveToDb(); $flashapplet =& base64_decode($item->getMetadataEntry("swf")); if (!file_exists($this->object->getFlashPath())) { include_once "./Services/Utilities/classes/class.ilUtil.php"; ilUtil::makeDirParents($this->object->getFlashPath()); } $filename = $this->object->getFlashPath() . $this->object->getApplet(); $fh = fopen($filename, "wb"); if ($fh == false) { // global $ilErr; // $ilErr->raiseError($this->object->lng->txt("error_save_image_file") . ": $php_errormsg", $ilErr->MESSAGE); // return; } else { fwrite($fh, $flashapplet); fclose($fh); } $feedbacksgeneric = $this->getFeedbackGeneric($item); // handle the import of media objects in XHTML code $questiontext = $this->object->getQuestion(); if (is_array($_SESSION["import_mob_xhtml"])) { include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php"; include_once "./Services/RTE/classes/class.ilRTE.php"; foreach ($_SESSION["import_mob_xhtml"] as $mob) { if ($tst_id > 0) { $importfile = $this->getTstImportArchivDirectory() . '/' . $mob["uri"]; } else { $importfile = $this->getQplImportArchivDirectory() . '/' . $mob["uri"]; } $GLOBALS['ilLog']->write(__METHOD__ . ': import mob from dir: ' . $importfile); $media_object =& ilObjMediaObject::_saveTempFileAsMediaObject(basename($importfile), $importfile, FALSE); ilObjMediaObject::_saveUsage($media_object->getId(), "qpl:html", $this->object->getId()); $questiontext = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $questiontext); foreach ($feedbacksgeneric as $correctness => $material) { $feedbacksgeneric[$correctness] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material); } } } $this->object->setQuestion(ilRTE::_replaceMediaObjectImageSrc($questiontext, 1)); foreach ($feedbacksgeneric as $correctness => $material) { $this->object->saveFeedbackGeneric($correctness, ilRTE::_replaceMediaObjectImageSrc($material, 1)); } $this->object->saveToDb(); if (count($item->suggested_solutions)) { foreach ($item->suggested_solutions as $suggested_solution) { $this->object->setSuggestedSolution($suggested_solution["solution"]->getContent(), $suggested_solution["gap_index"], true); } $this->object->saveToDb(); } if ($tst_id > 0) { $q_1_id = $this->object->getId(); $question_id = $this->object->duplicate(true, null, null, null, $tst_id); $tst_object->questions[$question_counter++] = $question_id; $import_mapping[$item->getIdent()] = array("pool" => $q_1_id, "test" => $question_id); } else { $import_mapping[$item->getIdent()] = array("pool" => $this->object->getId(), "test" => 0); } }
/** * Sets the image file and uploads the image to the object's image directory. * * @param string $image_filename Name of the original image file * @param string $image_tempfilename Name of the temporary uploaded image file * @return integer An errorcode if the image upload fails, 0 otherwise * @access public */ function setImageFile($image_tempfilename, $image_filename, $previous_filename) { $result = TRUE; if (strlen($image_tempfilename)) { $image_filename = str_replace(" ", "_", $image_filename); $imagepath = $this->getImagePath(); if (!file_exists($imagepath)) { ilUtil::makeDirParents($imagepath); } $savename = $image_filename; if (!ilUtil::moveUploadedFile($image_tempfilename, $savename, $imagepath . $savename)) { $result = FALSE; } else { // create thumbnail file $thumbpath = $imagepath . $this->getThumbPrefix() . $savename; ilUtil::convertImage($imagepath . $savename, $thumbpath, "JPEG", $this->getThumbGeometry()); } if ($result && strcmp($image_filename, $previous_filename) != 0 && strlen($previous_filename)) { $this->deleteImagefile($previous_filename); } } return $result; }
/** * Sync images of a MC question on synchronisation with the original question **/ protected function syncImages() { global $ilLog; $question_id = $this->getOriginalId(); $imagepath = $this->getImagePath(); $imagepath_original = str_replace("/{$this->id}/images", "/{$question_id}/images", $imagepath); ilUtil::delDir($imagepath_original); foreach ($this->answers as $answer) { $filename = $answer->getImage(); if (strlen($filename)) { if (@file_exists($imagepath . $filename)) { if (!file_exists($imagepath)) { ilUtil::makeDirParents($imagepath); } if (!file_exists($imagepath_original)) { ilUtil::makeDirParents($imagepath_original); } if (!@copy($imagepath . $filename, $imagepath_original . $filename)) { $ilLog->write("image could not be duplicated!!!!", $ilLog->ERROR); $ilLog->write("object: " . print_r($this, TRUE), $ilLog->ERROR); } } if (@file_exists($imagepath . $this->getThumbPrefix() . $filename)) { if (!@copy($imagepath . $this->getThumbPrefix() . $filename, $imagepath_original . $this->getThumbPrefix() . $filename)) { $ilLog->write("image thumbnail could not be duplicated!!!!", $ilLog->ERROR); $ilLog->write("object: " . print_r($this, TRUE), $ilLog->ERROR); } } } } }
/** * Sets the java applet file name * * @param string $javaapplet_file. * @access public * @see $javaapplet_filename */ function setJavaAppletFilename($javaapplet_filename, $javaapplet_tempfilename = "") { if (!empty($javaapplet_filename)) { $this->javaapplet_filename = $javaapplet_filename; } if (!empty($javaapplet_tempfilename)) { $javapath = $this->getJavaPath(); if (!file_exists($javapath)) { ilUtil::makeDirParents($javapath); } if (!ilUtil::moveUploadedFile($javaapplet_tempfilename, $javaapplet_filename, $javapath . $javaapplet_filename)) { $ilLog->write("ERROR: java applet question: java applet not uploaded: {$javaapplet_filename}"); } else { $this->setJavaCodebase(); $this->setJavaArchive(); } } }
/** * Checks if given upload path exists, is readable or can be created. * * @param string $path */ public function checkUploadPath($path) { $err = false; switch (true) { case !file_exists($path): if (!ilUtil::makeDirParents($path)) { $err = true; $msg = 'Error: Upload path could not be created!'; } break; case !is_dir($path): $err = true; $msg = 'Error: Upload path is not a directory!'; break; case !is_readable($path): $err = true; $msg = 'Error: Upload path is not readable!'; break; default: } if ($err) { throw new Exception($msg); } }
public function sendAndCreateSimpleExportFile() { $orgu_id = ilObjOrgUnit::getRootOrgId(); $orgu_ref_id = ilObjOrgUnit::getRootOrgRefId(); ilExport::_createExportDirectory($orgu_id, "xml", "orgu"); $export_dir = ilExport::_getExportDirectory($orgu_id, "xml", "orgu"); $ts = time(); // Workaround for test assessment $sub_dir = $ts . '__' . IL_INST_ID . '__' . "orgu" . '_' . $orgu_id . ""; $new_file = $sub_dir . '.zip'; $export_run_dir = $export_dir . "/" . $sub_dir; ilUtil::makeDirParents($export_run_dir); $writer = $this->simpleExport($orgu_ref_id); $writer->xmlDumpFile($export_run_dir . "/manifest.xml", false); // zip the file ilUtil::zip($export_run_dir, $export_dir . "/" . $new_file); ilUtil::delDir($export_run_dir); // Store info about export include_once './Services/Export/classes/class.ilExportFileInfo.php'; $exp = new ilExportFileInfo($orgu_id); $exp->setVersion(ILIAS_VERSION_NUMERIC); $exp->setCreationDate(new ilDateTime($ts, IL_CAL_UNIX)); $exp->setExportType('xml'); $exp->setFilename($new_file); $exp->create(); ilUtil::deliverFile($export_dir . "/" . $new_file, $new_file); return array("success" => true, "file" => $new_file, "directory" => $export_dir); }
/** * build xml export file */ function buildExportFileXML() { global $ilBench; $ilBench->start("QuestionpoolExport", "buildExportFile"); include_once "./Services/Xml/classes/class.ilXmlWriter.php"; $this->xml = new ilXmlWriter(); // set dtd definition $this->xml->xmlSetDtdDef("<!DOCTYPE Test SYSTEM \"http://www.ilias.uni-koeln.de/download/dtd/ilias_co.dtd\">"); // set generated comment $this->xml->xmlSetGenCmt("Export of ILIAS Test Questionpool " . $this->qpl_obj->getId() . " of installation " . $this->inst . "."); // set xml header $this->xml->xmlHeader(); // create directories include_once "./Services/Utilities/classes/class.ilUtil.php"; ilUtil::makeDir($this->export_dir . "/" . $this->subdir); ilUtil::makeDir($this->export_dir . "/" . $this->subdir . "/objects"); // get Log File $expDir = $this->qpl_obj->getExportDirectory(); ilUtil::makeDirParents($expDir); include_once "./Services/Logging/classes/class.ilLog.php"; $expLog = new ilLog($expDir, "export.log"); $expLog->delete(); $expLog->setLogFormat(""); $expLog->write(date("[y-m-d H:i:s] ") . "Start Export"); // write qti file $qti_file = fopen($this->export_dir . "/" . $this->subdir . "/" . $this->qti_filename, "w"); fwrite($qti_file, $this->qpl_obj->toXML($this->questions)); fclose($qti_file); // get xml content $ilBench->start("QuestionpoolExport", "buildExportFile_getXML"); $this->qpl_obj->exportPagesXML($this->xml, $this->inst_id, $this->export_dir . "/" . $this->subdir, $expLog, $this->questions); $ilBench->stop("QuestionpoolExport", "buildExportFile_getXML"); // dump xml document to screen (only for debugging reasons) /* echo "<PRE>"; echo htmlentities($this->xml->xmlDumpMem($format)); echo "</PRE>"; */ // dump xml document to file $ilBench->start("QuestionpoolExport", "buildExportFile_dumpToFile"); $this->xml->xmlDumpFile($this->export_dir . "/" . $this->subdir . "/" . $this->filename, false); $ilBench->stop("QuestionpoolExport", "buildExportFile_dumpToFile"); // add media objects which were added with tiny mce $ilBench->start("QuestionpoolExport", "buildExportFile_saveAdditionalMobs"); $this->exportXHTMLMediaObjects($this->export_dir . "/" . $this->subdir); $ilBench->stop("QuestionpoolExport", "buildExportFile_saveAdditionalMobs"); // zip the file $ilBench->start("QuestionpoolExport", "buildExportFile_zipFile"); ilUtil::zip($this->export_dir . "/" . $this->subdir, $this->export_dir . "/" . $this->subdir . ".zip"); if (@is_dir($this->export_dir . "/" . $this->subdir)) { // Do not delete this dir, since it is required for container exports #ilUtil::delDir($this->export_dir."/".$this->subdir); } $ilBench->stop("QuestionpoolExport", "buildExportFile_zipFile"); // destroy writer object $this->xml->_XmlWriter; $expLog->write(date("[y-m-d H:i:s] ") . "Finished Export"); $ilBench->stop("QuestionpoolExport", "buildExportFile"); return $this->export_dir . "/" . $this->subdir . ".zip"; }
public function fromXML(&$item, &$questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping) { global $ilUser; unset($_SESSION["import_mob_xhtml"]); $duration = $item->getDuration(); $shuffle = 0; $answers = array(); $presentation = $item->getPresentation(); foreach ($presentation->order as $entry) { switch ($entry["type"]) { case "response": $response = $presentation->response[$entry["index"]]; $rendertype = $response->getRenderType(); switch (strtolower(get_class($response->getRenderType()))) { case "ilqtirenderchoice": $shuffle = $rendertype->getShuffle(); $answerorder = 0; $foundimage = FALSE; foreach ($rendertype->response_labels as $response_label) { $ident = $response_label->getIdent(); $answertext = ""; $answerimage = array(); foreach ($response_label->material as $mat) { $embedded = false; for ($m = 0; $m < $mat->getMaterialCount(); $m++) { $foundmat = $mat->getMaterial($m); if (strcmp($foundmat["type"], "mattext") == 0) { } if (strcmp($foundmat["type"], "matimage") == 0) { if (strlen($foundmat["material"]->getEmbedded())) { $embedded = true; } } } if ($embedded) { for ($m = 0; $m < $mat->getMaterialCount(); $m++) { $foundmat = $mat->getMaterial($m); if (strcmp($foundmat["type"], "mattext") == 0) { $answertext .= $foundmat["material"]->getContent(); } if (strcmp($foundmat["type"], "matimage") == 0) { $foundimage = TRUE; $answerimage = array("imagetype" => $foundmat["material"]->getImageType(), "label" => $foundmat["material"]->getLabel(), "content" => $foundmat["material"]->getContent()); } } } else { $answertext = $this->object->QTIMaterialToString($mat); } } $answers[$ident] = array("answertext" => $answertext, "imagefile" => $answerimage, "answerorder" => $ident); } break; } break; } } $feedbacks = array(); $feedbacksgeneric = array(); foreach ($item->resprocessing as $resprocessing) { foreach ($resprocessing->outcomes->decvar as $decvar) { if ($decvar->getVarname() == 'SCORE') { $this->object->setPoints($decvar->getMaxvalue()); if ($decvar->getMinvalue() > 0) { $this->object->setScorePartialSolutionEnabled(true); } } } foreach ($resprocessing->respcondition as $respcondition) { if (!count($respcondition->setvar)) { foreach ($respcondition->getConditionvar()->varequal as $varequal) { $ident = $varequal->respident; $answers[$ident]['correctness'] = (bool) $varequal->getContent(); break; } foreach ($respcondition->displayfeedback as $feedbackpointer) { if (strlen($feedbackpointer->getLinkrefid())) { foreach ($item->itemfeedback as $ifb) { if (strcmp($ifb->getIdent(), $feedbackpointer->getLinkrefid()) == 0) { // found a feedback for the identifier if (count($ifb->material)) { foreach ($ifb->material as $material) { $feedbacks[$ident] = $material; } } if (count($ifb->flow_mat) > 0) { foreach ($ifb->flow_mat as $fmat) { if (count($fmat->material)) { foreach ($fmat->material as $material) { $feedbacks[$ident] = $material; } } } } } } } } } else { foreach ($respcondition->displayfeedback as $feedbackpointer) { if (strlen($feedbackpointer->getLinkrefid())) { foreach ($item->itemfeedback as $ifb) { if ($ifb->getIdent() == "response_allcorrect") { // found a feedback for the identifier if (count($ifb->material)) { foreach ($ifb->material as $material) { $feedbacksgeneric[1] = $material; } } if (count($ifb->flow_mat) > 0) { foreach ($ifb->flow_mat as $fmat) { if (count($fmat->material)) { foreach ($fmat->material as $material) { $feedbacksgeneric[1] = $material; } } } } } else { if ($ifb->getIdent() == "response_onenotcorrect") { // found a feedback for the identifier if (count($ifb->material)) { foreach ($ifb->material as $material) { $feedbacksgeneric[0] = $material; } } if (count($ifb->flow_mat) > 0) { foreach ($ifb->flow_mat as $fmat) { if (count($fmat->material)) { foreach ($fmat->material as $material) { $feedbacksgeneric[0] = $material; } } } } } } } } } } } } $this->addGeneralMetadata($item); $this->object->setTitle($item->getTitle()); $this->object->setNrOfTries($item->getMaxattempts()); $this->object->setComment($item->getComment()); $this->object->setAuthor($item->getAuthor()); $this->object->setOwner($ilUser->getId()); $this->object->setQuestion($this->object->QTIMaterialToString($item->getQuestiontext())); $this->object->setObjId($questionpool_id); $this->object->setEstimatedWorkingTime($duration["h"], $duration["m"], $duration["s"]); $this->object->setShuffleAnswersEnabled($shuffle); $this->object->setAnswerType($item->getMetadataEntry("answer_type")); $this->object->setOptionLabel($item->getMetadataEntry("option_label_setting")); $this->object->setCustomTrueOptionLabel($item->getMetadataEntry("custom_true_option_label")); $this->object->setCustomFalseOptionLabel($item->getMetadataEntry("custom_false_option_label")); $this->object->setThumbSize($item->getMetadataEntry("thumb_size")); $this->object->saveToDb(); foreach ($answers as $answerData) { $answer = new ilAssKprimChoiceAnswer(); $answer->setImageFsDir($this->object->getImagePath()); $answer->setImageWebDir($this->object->getImagePathWeb()); $answer->setPosition($answerData['answerorder']); $answer->setAnswertext($answerData['answertext']); $answer->setCorrectness($answerData['correctness']); if (isset($answerData['imagefile']['label'])) { $answer->setImageFile($answerData['imagefile']['label']); } $this->object->addAnswer($answer); } // additional content editing mode information $this->object->setAdditionalContentEditingMode($this->fetchAdditionalContentEditingModeInformation($item)); $this->object->saveToDb(); foreach ($answers as $answer) { if (is_array($answer["imagefile"]) && count($answer["imagefile"]) > 0) { $image =& base64_decode($answer["imagefile"]["content"]); $imagepath = $this->object->getImagePath(); include_once "./Services/Utilities/classes/class.ilUtil.php"; if (!file_exists($imagepath)) { ilUtil::makeDirParents($imagepath); } $imagepath .= $answer["imagefile"]["label"]; if ($fh = fopen($imagepath, "wb")) { $imagefile = fwrite($fh, $image); fclose($fh); } } } $feedbackSetting = $item->getMetadataEntry('feedback_setting'); if (!is_null($feedbackSetting)) { $this->object->feedbackOBJ->saveSpecificFeedbackSetting($this->object->getId(), $feedbackSetting); } // handle the import of media objects in XHTML code foreach ($feedbacks as $ident => $material) { $m = $this->object->QTIMaterialToString($material); $feedbacks[$ident] = $m; } foreach ($feedbacksgeneric as $correctness => $material) { $m = $this->object->QTIMaterialToString($material); $feedbacksgeneric[$correctness] = $m; } $questiontext = $this->object->getQuestion(); $answers =& $this->object->getAnswers(); if (is_array($_SESSION["import_mob_xhtml"])) { include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php"; include_once "./Services/RTE/classes/class.ilRTE.php"; foreach ($_SESSION["import_mob_xhtml"] as $mob) { if ($tst_id > 0) { $importfile = $this->getTstImportArchivDirectory() . '/' . $mob["uri"]; } else { $importfile = $this->getQplImportArchivDirectory() . '/' . $mob["uri"]; } $GLOBALS['ilLog']->write(__METHOD__ . ': import mob from dir: ' . $importfile); $media_object =& ilObjMediaObject::_saveTempFileAsMediaObject(basename($importfile), $importfile, FALSE); ilObjMediaObject::_saveUsage($media_object->getId(), "qpl:html", $this->object->getId()); $questiontext = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $questiontext); foreach ($answers as $key => $value) { $answer_obj =& $answers[$key]; $answer_obj->setAnswertext(str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $answer_obj->getAnswertext())); } foreach ($feedbacks as $ident => $material) { $feedbacks[$ident] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material); } foreach ($feedbacksgeneric as $correctness => $material) { $feedbacksgeneric[$correctness] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material); } } } $this->object->setQuestion(ilRTE::_replaceMediaObjectImageSrc($questiontext, 1)); foreach ($answers as $key => $value) { $answer_obj =& $answers[$key]; $answer_obj->setAnswertext(ilRTE::_replaceMediaObjectImageSrc($answer_obj->getAnswertext(), 1)); } foreach ($feedbacks as $ident => $material) { $this->object->feedbackOBJ->importSpecificAnswerFeedback($this->object->getId(), $ident, ilRTE::_replaceMediaObjectImageSrc($material, 1)); } foreach ($feedbacksgeneric as $correctness => $material) { $this->object->feedbackOBJ->importGenericFeedback($this->object->getId(), $correctness, ilRTE::_replaceMediaObjectImageSrc($material, 1)); } $this->object->saveToDb(); if (count($item->suggested_solutions)) { foreach ($item->suggested_solutions as $suggested_solution) { $this->object->setSuggestedSolution($suggested_solution["solution"]->getContent(), $suggested_solution["gap_index"], true); } $this->object->saveToDb(); } if ($tst_id > 0) { $q_1_id = $this->object->getId(); $question_id = $this->object->duplicate(true, null, null, null, $tst_id); $tst_object->questions[$question_counter++] = $question_id; $import_mapping[$item->getIdent()] = array("pool" => $q_1_id, "test" => $question_id); } else { $import_mapping[$item->getIdent()] = array("pool" => $this->object->getId(), "test" => 0); } //$ilLog->write(strftime("%D %T") . ": finished import multiple choice question (single response)"); }
/** * Copies/Moves a question from the clipboard * * @access private */ function pasteFromClipboard() { global $ilDB; if (array_key_exists("qpl_clipboard", $_SESSION)) { foreach ($_SESSION["qpl_clipboard"] as $question_object) { if (strcmp($question_object["action"], "move") == 0) { $result = $ilDB->queryF("SELECT obj_fi FROM qpl_questions WHERE question_id = %s", array('integer'), array($question_object["question_id"])); if ($result->numRows() == 1) { $row = $ilDB->fetchAssoc($result); $source_questionpool = $row["obj_fi"]; // change the questionpool id in the qpl_questions table $affectedRows = $ilDB->manipulateF("UPDATE qpl_questions SET obj_fi = %s WHERE question_id = %s", array('integer', 'integer'), array($this->getId(), $question_object["question_id"])); // move question data to the new target directory $source_path = CLIENT_WEB_DIR . "/assessment/" . $source_questionpool . "/" . $question_object["question_id"] . "/"; if (@is_dir($source_path)) { $target_path = CLIENT_WEB_DIR . "/assessment/" . $this->getId() . "/"; if (!@is_dir($target_path)) { include_once "./Services/Utilities/classes/class.ilUtil.php"; ilUtil::makeDirParents($target_path); } @rename($source_path, $target_path . $question_object["question_id"]); } // update question count of source question pool ilObjQuestionPool::_updateQuestionCount($source_questionpool); } } else { $this->copyQuestion($question_object["question_id"], $this->getId()); } } } // update question count of question pool ilObjQuestionPool::_updateQuestionCount($this->getId()); unset($_SESSION["qpl_clipboard"]); }
/** * Creates a question from a QTI file * * Receives parameters from a QTI parser and creates a valid ILIAS question object * * @param object $item The QTI item object * @param integer $questionpool_id The id of the parent questionpool * @param integer $tst_id The id of the parent test if the question is part of a test * @param object $tst_object A reference to the parent test object * @param integer $question_counter A reference to a question counter to count the questions of an imported question pool * @param array $import_mapping An array containing references to included ILIAS objects * @access public */ function fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping) { global $ilUser; // empty session variable for imported xhtml mobs unset($_SESSION["import_mob_xhtml"]); $presentation = $item->getPresentation(); $duration = $item->getDuration(); $now = getdate(); $applet = NULL; $maxpoints = 0; $javacode = ""; $javacodebase = ""; $javaarchive = ""; $params = array(); $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']); $answers = array(); foreach ($presentation->order as $entry) { switch ($entry["type"]) { case "material": $material = $presentation->material[$entry["index"]]; for ($i = 0; $i < $material->getMaterialCount(); $i++) { $mat = $material->getMaterial($i); if (strcmp($mat["type"], "mattext") == 0) { $mattext = $mat["material"]; if (strlen($mattext->getLabel()) == 0 && strlen($this->object->QTIMaterialToString($item->getQuestiontext())) == 0) { $item->setQuestiontext($mattext->getContent()); } if (strcmp($mattext->getLabel(), "points") == 0) { $maxpoints = $mattext->getContent(); } else { if (strcmp($mattext->getLabel(), "java_code") == 0) { $javacode = $mattext->getContent(); } else { if (strcmp($mattext->getLabel(), "java_codebase") == 0) { $javacodebase = $mattext->getContent(); } else { if (strcmp($mattext->getLabel(), "java_archive") == 0) { $javaarchive = $mattext->getContent(); } else { if (strlen($mattext->getLabel()) > 0) { array_push($params, array("key" => $mattext->getLabel(), "value" => $mattext->getContent())); } } } } } } elseif (strcmp($mat["type"], "matapplet") == 0) { $applet = $mat["material"]; } } break; } } $feedbacksgeneric = array(); foreach ($item->resprocessing as $resprocessing) { foreach ($resprocessing->respcondition as $respcondition) { foreach ($respcondition->displayfeedback as $feedbackpointer) { if (strlen($feedbackpointer->getLinkrefid())) { foreach ($item->itemfeedback as $ifb) { if (strcmp($ifb->getIdent(), "response_allcorrect") == 0) { // found a feedback for the identifier if (count($ifb->material)) { foreach ($ifb->material as $material) { $feedbacksgeneric[1] = $material; } } if (count($ifb->flow_mat) > 0) { foreach ($ifb->flow_mat as $fmat) { if (count($fmat->material)) { foreach ($fmat->material as $material) { $feedbacksgeneric[1] = $material; } } } } } else { if (strcmp($ifb->getIdent(), "response_onenotcorrect") == 0) { // found a feedback for the identifier if (count($ifb->material)) { foreach ($ifb->material as $material) { $feedbacksgeneric[0] = $material; } } if (count($ifb->flow_mat) > 0) { foreach ($ifb->flow_mat as $fmat) { if (count($fmat->material)) { foreach ($fmat->material as $material) { $feedbacksgeneric[0] = $material; } } } } } } } } } } } $this->object->setTitle($item->getTitle()); $this->object->setNrOfTries($item->getMaxattempts()); $this->object->setComment($item->getComment()); $this->object->setAuthor($item->getAuthor()); $this->object->setOwner($ilUser->getId()); $this->object->setQuestion($this->object->QTIMaterialToString($item->getQuestiontext())); $this->object->setObjId($questionpool_id); $this->object->setEstimatedWorkingTime($duration["h"], $duration["m"], $duration["s"]); $this->object->setJavaAppletFilename($applet->getUri()); $this->object->setJavaWidth($applet->getWidth()); $this->object->setJavaHeight($applet->getHeight()); $this->object->setJavaCode($javacode); $this->object->setJavaCodebase($javacodebase); $this->object->setJavaArchive($javaarchive); $this->object->setPoints($maxpoints); foreach ($params as $pair) { $this->object->addParameter($pair["key"], $pair["value"]); } $this->object->saveToDb(); if (count($item->suggested_solutions)) { foreach ($item->suggested_solutions as $suggested_solution) { $this->object->setSuggestedSolution($suggested_solution["solution"]->getContent(), $suggested_solution["gap_index"], true); } $this->object->saveToDb(); } $javaapplet =& base64_decode($applet->getContent()); $javapath = $this->object->getJavaPath(); if (!file_exists($javapath)) { include_once "./Services/Utilities/classes/class.ilUtil.php"; ilUtil::makeDirParents($javapath); } $javapath .= $this->object->getJavaAppletFilename(); $fh = fopen($javapath, "wb"); if ($fh == false) { // global $ilErr; // $ilErr->raiseError($this->object->lng->txt("error_save_image_file") . ": $php_errormsg", $ilErr->MESSAGE); // return; } else { $javafile = fwrite($fh, $javaapplet); fclose($fh); } // handle the import of media objects in XHTML code foreach ($feedbacksgeneric as $correctness => $material) { $m = $this->object->QTIMaterialToString($material); $feedbacksgeneric[$correctness] = $m; } $questiontext = $this->object->getQuestion(); if (is_array($_SESSION["import_mob_xhtml"])) { include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php"; include_once "./Services/RTE/classes/class.ilRTE.php"; foreach ($_SESSION["import_mob_xhtml"] as $mob) { if ($tst_id > 0) { $importfile = $this->getTstImportArchivDirectory() . '/' . $mob["uri"]; } else { $importfile = $this->getQplImportArchivDirectory() . '/' . $mob["uri"]; } $GLOBALS['ilLog']->write(__METHOD__ . ': import mob from dir: ' . $importfile); $media_object =& ilObjMediaObject::_saveTempFileAsMediaObject(basename($importfile), $importfile, FALSE); ilObjMediaObject::_saveUsage($media_object->getId(), "qpl:html", $this->object->getId()); $questiontext = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $questiontext); foreach ($feedbacksgeneric as $correctness => $material) { $feedbacksgeneric[$correctness] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material); } } } $this->object->setQuestion(ilRTE::_replaceMediaObjectImageSrc($questiontext, 1)); foreach ($feedbacksgeneric as $correctness => $material) { $this->object->saveFeedbackGeneric($correctness, ilRTE::_replaceMediaObjectImageSrc($material, 1)); } $this->object->saveToDb(); if ($tst_id > 0) { $q_1_id = $this->object->getId(); $question_id = $this->object->duplicate(true, null, null, null, $tst_id); $tst_object->questions[$question_counter++] = $question_id; $import_mapping[$item->getIdent()] = array("pool" => $q_1_id, "test" => $question_id); } else { $import_mapping[$item->getIdent()] = array("pool" => $this->object->getId(), "test" => 0); } }
/** * Copies/Moves a question from the clipboard */ public function pasteFromClipboard() { global $ilDB; if (array_key_exists("spl_clipboard", $_SESSION)) { foreach ($_SESSION["spl_clipboard"] as $question_object) { if (strcmp($question_object["action"], "move") == 0) { $result = $ilDB->queryF("SELECT obj_fi FROM svy_question WHERE question_id = %s", array('integer'), array($question_object["question_id"])); if ($result->numRows() == 1) { $row = $ilDB->fetchAssoc($result); $source_questionpool = $row["obj_fi"]; if ($this->getId() != $source_questionpool) { // change the questionpool id in the qpl_questions table $affectedRows = $ilDB->manipulateF("UPDATE svy_question SET obj_fi = %s WHERE question_id = %s", array('integer', 'integer'), array($this->getId(), $question_object["question_id"])); // move question data to the new target directory $source_path = CLIENT_WEB_DIR . "/survey/" . $source_questionpool . "/" . $question_object["question_id"] . "/"; if (@is_dir($source_path)) { $target_path = CLIENT_WEB_DIR . "/survey/" . $this->getId() . "/"; if (!@is_dir($target_path)) { include_once "./Services/Utilities/classes/class.ilUtil.php"; ilUtil::makeDirParents($target_path); } @rename($source_path, $target_path . $question_object["question_id"]); } } else { ilUtil::sendFailure($this->lng->txt("spl_move_same_pool"), true); return; } } } else { $this->copyQuestion($question_object["question_id"], $this->getId()); } } } ilUtil::sendSuccess($this->lng->txt("spl_paste_success"), true); unset($_SESSION["spl_clipboard"]); }
/** * get import directory of survey */ function getImportDirectory() { include_once "./Services/Utilities/classes/class.ilUtil.php"; $import_dir = ilUtil::getDataDir() . "/svy_data" . "/svy_" . $this->getId() . "/import"; if (!is_dir($import_dir)) { ilUtil::makeDirParents($import_dir); } if (@is_dir($import_dir)) { return $import_dir; } else { return false; } }
/** * Sets the image file name * * @param string $image_file name. * @access public * @see $image_filename */ function setImageFilename($image_filename, $image_tempfilename = "") { if (!empty($image_filename)) { $image_filename = str_replace(" ", "_", $image_filename); $this->image_filename = $image_filename; } if (!empty($image_tempfilename)) { $imagepath = $this->getImagePath(); if (!file_exists($imagepath)) { ilUtil::makeDirParents($imagepath); } if (!ilUtil::moveUploadedFile($image_tempfilename, $image_filename, $imagepath . $image_filename)) { $this->ilias->raiseError("The image could not be uploaded!", $this->ilias->error_obj->MESSAGE); } global $ilLog; $ilLog->write("gespeichert: " . $imagepath . $image_filename); } }
/** * Create new media object and update page in db and return new media object */ function uploadAdditionalFile($a_name, $tmp_name, $a_subdir = "") { $a_subdir = str_replace("..", "", $a_subdir); $dir = $mob_dir = ilObjMediaObject::_getDirectory($this->getId()); if ($a_subdir != "") { $dir .= "/" . $a_subdir; } ilUtil::makeDirParents($dir); ilUtil::moveUploadedFile($tmp_name, $a_name, $dir . "/" . $a_name); ilUtil::renameExecutables($mob_dir); }