/** * Saves file, fetched from $_FILES to specified upload path. * * @global ilObjUser $ilUser */ public function uploadFile() { global $ilCtrl; if (!ilChatroom::checkUserPermissions('read', $this->gui->ref_id)) { $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", ROOT_FOLDER_ID); $ilCtrl->redirectByClass("ilrepositorygui", ""); } $upload_path = $this->getUploadPath(); $this->checkUploadPath($upload_path); /** * @todo: filename must be unique. */ $file = $_FILES['file_to_upload']['tmp_name']; $filename = $_FILES['file_to_upload']['name']; $type = $_FILES['file_to_upload']['type']; $target = $upload_path . $filename; if (ilUtil::moveUploadedFile($file, $filename, $target)) { global $ilUser; require_once 'Modules/Chatroom/classes/class.ilChatroom.php'; require_once 'Modules/Chatroom/classes/class.ilChatroomUser.php'; $room = ilChatroom::byObjectId($this->gui->object->getId()); $chat_user = new ilChatroomUser($ilUser, $room); $user_id = $chat_user->getUserId(); if (!$room) { throw new Exception('unkown room'); } else { if (!$room->isSubscribed($chat_user->getUserId())) { throw new Exception('not subscribed'); } } $room->saveFileUploadToDb($user_id, $filename, $type); $this->displayLinkToUploadedFile($room, $chat_user); } }
public function storeUploadedFile($a_http_post_file) { if ($this->image_current != '') { $this->unlinkFile($this->image_current); } if (isset($a_http_post_file) && $a_http_post_file['size']) { if (ilUtil::moveUploadedFile($a_http_post_file['tmp_name'], $a_http_post_file['name'], $this->shop_path . '/' . $a_http_post_file['name'])) { ilUtil::resizeImage('"' . $this->shop_path . '/' . $a_http_post_file['name'] . '"', '"' . $this->shop_path . '/' . $a_http_post_file['name'] . '"', 100, 75); return $this->image_new = $a_http_post_file['name']; } } return false; }
/** * Imports rooms and bookings from a given daVinci file * * @param type $file daVinci text file from file upload form * @param boolean $import_rooms true to import rooms * @param boolean $import_bookings true to import bookings * @param int $default_cap sets the default room capacity */ public function importBookingsFromDaVinciFile($file, $import_rooms, $import_bookings, $default_cap) { $this->count_Bookings_without_Room = 0; $this->count_Rooms_created = 0; $this->count_Bookings_created = 0; $file_name = ilUtil::getASCIIFilename($file["name"]); $file_name_mod = str_replace(" ", "_", $file_name); $file_path = "templates" . "/" . $file_name_mod; // construct file path ilUtil::moveUploadedFile($file["tmp_name"], $file_name_mod, $file_path); $fileAsString = file_get_contents($file_path); ilUtil::sendInfo($this->lng->txt("rep_robj_xrs_daVinci_import_message_start"), true); foreach (preg_split("/((\r?\n)|(\r\n?))/", $fileAsString) as $line) { $this->checkForKey($line); } ilUtil::sendInfo($this->createInfoMessage($import_rooms, $import_bookings), true); if ($import_rooms === "1") { foreach ($this->rooms as $room) { if (!($this->ilRoomSharingDatabase->getRoomWithName($room['name']) !== array())) { if ($room['cap'] == 0) { $room['cap'] = (int) $default_cap; } //$a_name, $a_type, $a_min_alloc, $a_max_alloc, $a_file_id, $a_building_id $this->ilRoomSharingDatabase->insertRoom($room['name'], $room['type'], 1, $room['cap'], array(), array()); $this->count_Rooms_created++; } } } if ($import_bookings === "1") { foreach ($this->appointments as $booking) { if ($booking['day'] != 0) { $usedWeek = clone $this->startingDate; for ($i = 0; $i < strlen($this->activeWeeks); $i++) { if ($booking['week'] != NULL) { if ($booking['week'][$i] === 'X') { $this->addDaVinciBooking($booking['day'], $booking['start'], $booking['end'], $booking['room'], $booking['prof'], $booking['subject'], $booking['classes'], $usedWeek); } } else { if ($this->activeWeeks[$i] === 'X') { $this->addDaVinciBooking($booking['day'], $booking['start'], $booking['end'], $booking['room'], $booking['prof'], $booking['subject'], $booking['classes'], $usedWeek); } } $usedWeek->add(new DateInterval('P7D')); } } } } $this->displayInfo(); }
/** * 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; } }
/** * store uploaded file in filesystem * @param array HTTP_POST_FILES * @access public * @return bool */ function storeUploadedFile($a_http_post_file) { // TODO: // CHECK UPLOAD LIMIT // if (isset($a_http_post_file) && $a_http_post_file['size']) { // DELETE OLD FILES $this->unlinkLast(); // CHECK IF FILE WITH SAME NAME EXISTS ilUtil::moveUploadedFile($a_http_post_file['tmp_name'], $a_http_post_file['name'], $this->getPath() . '/' . $a_http_post_file['name']); //move_uploaded_file($a_http_post_file['tmp_name'],$this->getPath().'/'.$a_http_post_file['name']); // UPDATE FILES LIST $this->__readFiles(); return true; } else { return false; } }
/** * Upload appointments */ protected function uploadAppointments() { // @todo permission check $form = $this->initImportForm(); if ($form->checkInput()) { $file = $form->getInput('file'); $tmp = ilUtil::ilTempnam(); ilUtil::moveUploadedFile($file['tmp_name'], $file['name'], $tmp); $num = $this->doImportFile($tmp, (int) $_REQUEST['category_id']); ilUtil::sendSuccess(sprintf($this->lng->txt('cal_imported_success'), (int) $num), true); $this->ctrl->redirect($this, 'manage'); } ilUtil::sendFailure($this->lng->txt('cal_err_file_upload'), true); $this->initImportForm($form); }
/** * 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(); } } }
/** * Import repository object export file * * @param string absolute filename of temporary upload file */ public final function importObject($a_new_obj, $a_tmp_file, $a_filename, $a_type, $a_comp = "", $a_copy_file = false) { // create temporary directory $tmpdir = ilUtil::ilTempnam(); ilUtil::makeDir($tmpdir); if ($a_copy_file) { copy($a_tmp_file, $tmpdir . "/" . $a_filename); } else { ilUtil::moveUploadedFile($a_tmp_file, $a_filename, $tmpdir . "/" . $a_filename); } ilUtil::unzip($tmpdir . "/" . $a_filename); $dir = $tmpdir . "/" . substr($a_filename, 0, strlen($a_filename) - 4); $GLOBALS['ilLog']->write(__METHOD__ . ': do import with dir ' . $dir); $new_id = $this->doImportObject($dir, $a_type, $a_comp, $tmpdir); // delete temporary directory ilUtil::delDir($tmpdir); return $new_id; }
/** * Import */ function import($a_file) { parent::create(); $im_dir = $this->createImportDirectory(); // handle uploaded files if (is_array($a_file)) { ilUtil::moveUploadedFile($a_file["tmp_name"], $a_file["name"], $im_dir . "/" . $a_file["name"]); $file_name = $a_file["name"]; } else { $pi = pathinfo($a_file); $file_name = $pi["basename"]; copy($a_file, $im_dir . "/" . $file_name); } $file = pathinfo($file_name); // unzip file if (strtolower($file["extension"] == "zip")) { ilUtil::unzip($im_dir . "/" . $file_name); $subdir = basename($file["basename"], "." . $file["extension"]); if (!is_dir($im_dir . "/" . $subdir)) { $subdir = "style"; // check style subdir } $xml_file = $im_dir . "/" . $subdir . "/style.xml"; } else { $xml_file = $im_dir . "/" . $file_name; } // load information from xml file //echo "-$xml_file-"; $this->createFromXMLFile($xml_file, true); // copy images $this->createImagesDirectory(); if (is_dir($im_dir . "/" . $subdir . "/images")) { ilUtil::rCopy($im_dir . "/" . $subdir . "/images", $this->getImagesDirectory()); } ilObjStyleSheet::_addMissingStyleClassesToStyle($this->getId()); $this->read(); $this->writeCSSFile(); }
/** * update media item from form * * @param IlObjectMediaObject $mob * @param IlMediaItem $mediaItem * @return string file */ private function updateMediaItem($mob, &$mediaItem) { $purpose = $mediaItem->getPurpose(); $url_gui = $this->form_gui->getInput("url_" . $purpose); $file_gui = $this->form_gui->getInput("file_" . $purpose); if ($url_gui) { // http $file = $this->form_gui->getInput("url_" . $purpose); $title = basename($file); $location = $this->form_gui->getInput("url_" . $purpose); $locationType = "Reference"; } elseif ($file_gui["size"] > 0) { // lokal // determine and create mob directory, move uploaded file to directory $mob_dir = ilObjMediaObject::_getDirectory($mob->getId()); if (!is_dir($mob_dir)) { $mob->createDirectory(); } $file_name = ilUtil::getASCIIFilename($_FILES['file_' . $purpose]['name']); $file_name = str_replace(" ", "_", $file_name); $file = $mob_dir . "/" . $file_name; $title = $file_name; $locationType = "LocalFile"; $location = $title; ilUtil::moveUploadedFile($_FILES['file_' . $purpose]['tmp_name'], $file_name, $file); ilUtil::renameExecutables($mob_dir); } // check if not automatic mimetype detection if ($_POST["mimetype_" . $purpose] != "") { $mediaItem->setFormat($_POST["mimetype_" . $purpose]); } elseif ($mediaItem->getLocation() != "") { $format = ilObjMediaObject::getMimeType($mediaItem->getLocation()); $mediaItem->setFormat($format); } if (isset($file)) { // get mime type, if not already set! if (!isset($format)) { $format = ilObjMediaObject::getMimeType($file); } // set real meta and object data $mediaItem->setFormat($format); $mediaItem->setLocation($location); $mediaItem->setLocationType($locationType); $mediaItem->setHAlign("Left"); $mediaItem->setHeight(self::isAudio($format) ? 0 : 180); } if ($purpose == "Standard") { if (isset($title)) { $mob->setTitle($title); } if (isset($format)) { $mob->setDescription($format); } } return $file; }
/** * form for new survey object import */ public function importFileObject() { global $tpl, $ilErr; $parent_id = $_GET["ref_id"]; $new_type = $_REQUEST["new_type"]; // create permission is already checked in createObject. This check here is done to prevent hacking attempts if (!$this->checkPermissionBool("create", "", $new_type)) { $ilErr->raiseError($this->lng->txt("no_create_permission")); } $this->lng->loadLanguageModule($new_type); $this->ctrl->setParameter($this, "new_type", $new_type); $form = $this->initImportForm($new_type); if ($form->checkInput()) { include_once "./Modules/SurveyQuestionPool/classes/class.ilObjSurveyQuestionPool.php"; $newObj = new ilObjSurveyQuestionPool(); $newObj->setType($new_type); $newObj->setTitle("dummy"); $newObj->create(true); $this->putObjectInTree($newObj); $newObj->createImportDirectory(); // copy uploaded file to import directory $upload = $_FILES["importfile"]; $file = pathinfo($upload["name"]); $full_path = $newObj->getImportDirectory() . "/" . $upload["name"]; include_once "./Services/Utilities/classes/class.ilUtil.php"; ilUtil::moveUploadedFile($upload["tmp_name"], $upload["name"], $full_path); // import qti data $qtiresult = $newObj->importObject($full_path); ilUtil::sendSuccess($this->lng->txt("object_imported"), true); ilUtil::redirect("ilias.php?ref_id=" . $newObj->getRefId() . "&baseClass=ilObjSurveyQuestionPoolGUI"); } // display form to correct errors $form->setValuesByPost(); $tpl->setContent($form->getHtml()); }
function updateSocialBookmarkObject() { global $ilAccess, $rbacreview, $lng, $ilCtrl; if (!$ilAccess->checkAccess("write", "", $this->object->getRefId())) { $this->ilias->raiseError($this->lng->txt("permission_denied"), $this->ilias->error_obj->MESSAGE); } include_once './Services/Administration/classes/class.ilSocialBookmarks.php'; $form = ilSocialBookmarks::_initForm($this, 'update'); if ($form->checkInput()) { $title = $form->getInput('title'); $link = $form->getInput('link'); $file = $form->getInput('image_file'); $active = $form->getInput('activate'); $id = $form->getInput('sbm_id'); if (!$file['name']) { ilSocialBookmarks::_updateSocialBookmark($id, $title, $link, $active); } else { $extension = pathinfo($file['name'], PATHINFO_EXTENSION); $icon_path = ilUtil::getWebspaceDir() . DIRECTORY_SEPARATOR . 'social_bm_icons' . DIRECTORY_SEPARATOR . time() . '.' . $extension; $path = ilUtil::getWebspaceDir() . DIRECTORY_SEPARATOR . 'social_bm_icons'; if (!is_dir($path)) { ilUtil::createDirectory($path); } ilSocialBookmarks::_deleteImage($id); ilSocialBookmarks::_updateSocialBookmark($id, $title, $link, $active, $icon_path); ilUtil::moveUploadedFile($file['tmp_name'], $file['name'], $icon_path); } $this->editSocialBookmarksObject(); } else { $this->__initSubTabs("editSocialBookmarks"); $form->setValuesByPost(); $this->tpl->setVariable('ADM_CONTENT', $form->getHTML()); } }
/** * Uploads a new rooms agreement by using the ILIAS MediaObject Service. * If the old file id is given, the old file will be deleted. * * @param array $a_newfile an array containing the input values of the form * @param string $a_oldFileId to delete trash * * @return string uploaded file id */ public function uploadRoomsAgreement($a_newfile, $a_oldFileId = "0") { if (!empty($a_oldFileId) && $a_oldFileId != "0") { $agreementFile = new ilObjMediaObject($a_oldFileId); $agreementFile->delete(); } $mediaObj = new ilObjMediaObject(); $mediaObj->setTitle("RoomSharingRoomsAgreement"); $mediaObj->setDescription("RoomSharingRoomsAgreement"); $mediaObj->create(); $mob_dir = ilObjMediaObject::_getDirectory($mediaObj->getId()); if (!is_dir($mob_dir)) { $mediaObj->createDirectory(); } $file_name = ilUtil::getASCIIFilename($a_newfile["name"]); $file_name_mod = str_replace(" ", "_", $file_name); $file = $mob_dir . "/" . $file_name_mod; ilUtil::moveUploadedFile($a_newfile["tmp_name"], $file_name_mod, $file); ilUtil::renameExecutables($mob_dir); $format = ilObjMediaObject::getMimeType($file); $media_item = new ilMediaItem(); $mediaObj->addMediaItem($media_item); $media_item->setPurpose("Standard"); $media_item->setFormat($format); $media_item->setLocation($file_name_mod); $media_item->setLocationType("LocalFile"); $mediaObj->update(); return $mediaObj->getId(); }
/** * 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; }
/** * 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; }
/** * imports question(s) into the questionpool */ function uploadQplObject($questions_only = false) { $this->ctrl->setParameter($this, 'new_type', $_REQUEST['new_type']); if ($_FILES["xmldoc"]["error"] > UPLOAD_ERR_OK) { ilUtil::sendFailure($this->lng->txt("error_upload"), true); if (!$questions_only) { $this->ctrl->redirect($this, 'create'); } return false; } // create import directory include_once "./Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php"; $basedir = ilObjQuestionPool::_createImportDirectory(); // copy uploaded file to import directory $file = pathinfo($_FILES["xmldoc"]["name"]); $full_path = $basedir . "/" . $_FILES["xmldoc"]["name"]; $GLOBALS['ilLog']->write(__METHOD__ . ": full path " . $full_path); include_once "./Services/Utilities/classes/class.ilUtil.php"; ilUtil::moveUploadedFile($_FILES["xmldoc"]["tmp_name"], $_FILES["xmldoc"]["name"], $full_path); $GLOBALS['ilLog']->write(__METHOD__ . ": full path " . $full_path); if (strcmp($_FILES["xmldoc"]["type"], "text/xml") == 0) { $qti_file = $full_path; ilObjTest::_setImportDirectory($basedir); } else { // unzip file ilUtil::unzip($full_path); // determine filenames of xml files $subdir = basename($file["basename"], "." . $file["extension"]); ilObjQuestionPool::_setImportDirectory($basedir); $xml_file = ilObjQuestionPool::_getImportDirectory() . '/' . $subdir . '/' . $subdir . ".xml"; $qti_file = ilObjQuestionPool::_getImportDirectory() . '/' . $subdir . '/' . str_replace("qpl", "qti", $subdir) . ".xml"; } // start verification of QTI files include_once "./Services/QTI/classes/class.ilQTIParser.php"; $qtiParser = new ilQTIParser($qti_file, IL_MO_VERIFY_QTI, 0, ""); $result = $qtiParser->startParsing(); $founditems =& $qtiParser->getFoundItems(); if (count($founditems) == 0) { // nothing found // delete import directory ilUtil::delDir($basedir); ilUtil::sendFailure($this->lng->txt("qpl_import_no_items"), true); if (!$questions_only) { $this->ctrl->redirect($this, 'create'); } return false; } $complete = 0; $incomplete = 0; foreach ($founditems as $item) { if (strlen($item["type"])) { $complete++; } else { $incomplete++; } } if ($complete == 0) { // delete import directory ilUtil::delDir($basedir); ilUtil::sendFailure($this->lng->txt("qpl_import_non_ilias_files"), true); if (!$questions_only) { $this->ctrl->redirect($this, 'create'); } return false; } $_SESSION["qpl_import_xml_file"] = $xml_file; $_SESSION["qpl_import_qti_file"] = $qti_file; $_SESSION["qpl_import_subdir"] = $subdir; // display of found questions $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.qpl_import_verification.html", "Modules/TestQuestionPool"); $row_class = array("tblrow1", "tblrow2"); $counter = 0; foreach ($founditems as $item) { $this->tpl->setCurrentBlock("verification_row"); $this->tpl->setVariable("ROW_CLASS", $row_class[$counter++ % 2]); $this->tpl->setVariable("QUESTION_TITLE", $item["title"]); $this->tpl->setVariable("QUESTION_IDENT", $item["ident"]); include_once "./Services/QTI/classes/class.ilQTIItem.php"; switch ($item["type"]) { case CLOZE_TEST_IDENTIFIER: $type = $this->lng->txt("assClozeTest"); break; case IMAGEMAP_QUESTION_IDENTIFIER: $type = $this->lng->txt("assImagemapQuestion"); break; case JAVAAPPLET_QUESTION_IDENTIFIER: $type = $this->lng->txt("assJavaApplet"); break; case MATCHING_QUESTION_IDENTIFIER: $type = $this->lng->txt("assMatchingQuestion"); break; case MULTIPLE_CHOICE_QUESTION_IDENTIFIER: $type = $this->lng->txt("assMultipleChoice"); break; case KPRIM_CHOICE_QUESTION_IDENTIFIER: $type = $this->lng->txt("assKprimChoice"); break; case SINGLE_CHOICE_QUESTION_IDENTIFIER: $type = $this->lng->txt("assSingleChoice"); break; case ORDERING_QUESTION_IDENTIFIER: $type = $this->lng->txt("assOrderingQuestion"); break; case TEXT_QUESTION_IDENTIFIER: $type = $this->lng->txt("assTextQuestion"); break; case NUMERIC_QUESTION_IDENTIFIER: $type = $this->lng->txt("assNumeric"); break; case TEXTSUBSET_QUESTION_IDENTIFIER: $type = $this->lng->txt("assTextSubset"); break; default: $type = $this->lng->txt($item["type"]); break; } if (strcmp($type, "-" . $item["type"] . "-") == 0) { global $ilPluginAdmin; $pl_names = $ilPluginAdmin->getActivePluginsForSlot(IL_COMP_MODULE, "TestQuestionPool", "qst"); foreach ($pl_names as $pl_name) { $pl = ilPlugin::getPluginObject(IL_COMP_MODULE, "TestQuestionPool", "qst", $pl_name); if (strcmp($pl->getQuestionType(), $item["type"]) == 0) { $type = $pl->getQuestionTypeTranslation(); } } } $this->tpl->setVariable("QUESTION_TYPE", $type); $this->tpl->parseCurrentBlock(); } $this->tpl->setCurrentBlock("import_qpl"); if (is_file($xml_file)) { // read file into a string $fh = @fopen($xml_file, "r") or die(""); $xml = @fread($fh, filesize($xml_file)); @fclose($fh); if (preg_match("/<ContentObject.*?MetaData.*?General.*?Title[^>]*?>([^<]*?)</", $xml, $matches)) { $this->tpl->setVariable("VALUE_NEW_QUESTIONPOOL", $matches[1]); } } $this->tpl->setVariable("TEXT_CREATE_NEW_QUESTIONPOOL", $this->lng->txt("qpl_import_create_new_qpl")); $this->tpl->parseCurrentBlock(); $this->tpl->setCurrentBlock("adm_content"); $this->tpl->setVariable("TEXT_TYPE", $this->lng->txt("question_type")); $this->tpl->setVariable("TEXT_TITLE", $this->lng->txt("question_title")); $this->tpl->setVariable("FOUND_QUESTIONS_INTRODUCTION", $this->lng->txt("qpl_import_verify_found_questions")); if ($questions_only) { $this->tpl->setVariable("VERIFICATION_HEADING", $this->lng->txt("import_questions_into_qpl")); $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this)); } else { $this->tpl->setVariable("VERIFICATION_HEADING", $this->lng->txt("import_qpl")); $this->ctrl->setParameter($this, "new_type", $this->type); $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this)); //$this->tpl->setVariable("FORMACTION", $this->getFormAction("save","adm_object.php?cmd=gateway&ref_id=".$_GET["ref_id"]."&new_type=".$this->type)); } $this->tpl->setVariable("ARROW", ilUtil::getImagePath("arrow_downright.svg")); $this->tpl->setVariable("VALUE_IMPORT", $this->lng->txt("import")); $this->tpl->setVariable("VALUE_CANCEL", $this->lng->txt("cancel")); $value_questions_only = 0; if ($questions_only) { $value_questions_only = 1; } $this->tpl->setVariable("VALUE_QUESTIONS_ONLY", $value_questions_only); $this->tpl->parseCurrentBlock(); return true; }
private function handleFileUpload(ilAssKprimChoiceAnswer $answer, $fileData) { $imagePath = $this->getImagePath(); if (!file_exists($imagePath)) { ilUtil::makeDirParents($imagePath); } $filename = $this->createNewImageFileName($fileData['name'], true); $answer->setImageFsDir($imagePath); $answer->setImageFile($filename); if (!ilUtil::moveUploadedFile($fileData['tmp_name'], $fileData['name'], $answer->getImageFsPath())) { return 2; } return 0; }
/** * imports test and question(s) */ function uploadTstObject() { if ($_FILES["xmldoc"]["error"] > UPLOAD_ERR_OK) { ilUtil::sendFailure($this->lng->txt("error_upload")); $this->createObject(); return; } include_once "./Modules/Test/classes/class.ilObjTest.php"; // create import directory $basedir = ilObjTest::_createImportDirectory(); // copy uploaded file to import directory $file = pathinfo($_FILES["xmldoc"]["name"]); $full_path = $basedir . "/" . $_FILES["xmldoc"]["name"]; ilUtil::moveUploadedFile($_FILES["xmldoc"]["tmp_name"], $_FILES["xmldoc"]["name"], $full_path); // unzip file ilUtil::unzip($full_path); // determine filenames of xml files $subdir = basename($file["basename"], "." . $file["extension"]); ilObjTest::_setImportDirectory($basedir); $xml_file = ilObjTest::_getImportDirectory() . '/' . $subdir . '/' . $subdir . ".xml"; $qti_file = ilObjTest::_getImportDirectory() . '/' . $subdir . '/' . preg_replace("/test|tst/", "qti", $subdir) . ".xml"; $results_file = ilObjTest::_getImportDirectory() . '/' . $subdir . '/' . preg_replace("/test|tst/", "results", $subdir) . ".xml"; if (!is_file($qti_file)) { ilUtil::delDir($basedir); ilUtil::sendFailure($this->lng->txt("tst_import_non_ilias_zip")); $this->createObject(); return; } // start verification of QTI files include_once "./Services/QTI/classes/class.ilQTIParser.php"; $qtiParser = new ilQTIParser($qti_file, IL_MO_VERIFY_QTI, 0, ""); $result = $qtiParser->startParsing(); $founditems =& $qtiParser->getFoundItems(); if (count($founditems) == 0) { // nothing found // delete import directory ilUtil::delDir($basedir); ilUtil::sendInfo($this->lng->txt("tst_import_no_items")); $this->createObject(); return; } $complete = 0; $incomplete = 0; foreach ($founditems as $item) { if (strlen($item["type"])) { $complete++; } else { $incomplete++; } } if ($complete == 0) { // delete import directory ilUtil::delDir($basedir); ilUtil::sendInfo($this->lng->txt("qpl_import_non_ilias_files")); $this->createObject(); return; } $_SESSION["tst_import_results_file"] = $results_file; $_SESSION["tst_import_xml_file"] = $xml_file; $_SESSION["tst_import_qti_file"] = $qti_file; $_SESSION["tst_import_subdir"] = $subdir; // display of found questions $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.tst_import_verification.html", "Modules/Test"); $row_class = array("tblrow1", "tblrow2"); $counter = 0; foreach ($founditems as $item) { $this->tpl->setCurrentBlock("verification_row"); $this->tpl->setVariable("ROW_CLASS", $row_class[$counter++ % 2]); $this->tpl->setVariable("QUESTION_TITLE", $item["title"]); $this->tpl->setVariable("QUESTION_IDENT", $item["ident"]); include_once "./Services/QTI/classes/class.ilQTIItem.php"; switch ($item["type"]) { case "MULTIPLE CHOICE QUESTION": case QT_MULTIPLE_CHOICE_MR: //$this->tpl->setVariable("QUESTION_TYPE", $this->lng->txt("qt_multiple_choice")); $this->tpl->setVariable("QUESTION_TYPE", $this->lng->txt("assMultipleChoice")); break; case "SINGLE CHOICE QUESTION": case QT_MULTIPLE_CHOICE_SR: $this->tpl->setVariable("QUESTION_TYPE", $this->lng->txt("assSingleChoice")); break; case KPRIM_CHOICE_QUESTION_IDENTIFIER: case QT_KPRIM_CHOICE: $this->tpl->setVariable("QUESTION_TYPE", $this->lng->txt("assKprimChoice")); break; case "NUMERIC QUESTION": case QT_NUMERIC: $this->tpl->setVariable("QUESTION_TYPE", $this->lng->txt("assNumeric")); break; case "TEXTSUBSET QUESTION": case QT_TEXTSUBSET: $this->tpl->setVariable("QUESTION_TYPE", $this->lng->txt("assTextSubset")); break; case "CLOZE QUESTION": case QT_CLOZE: $this->tpl->setVariable("QUESTION_TYPE", $this->lng->txt("assClozeTest")); break; case "IMAGE MAP QUESTION": case QT_IMAGEMAP: $this->tpl->setVariable("QUESTION_TYPE", $this->lng->txt("assImagemapQuestion")); break; case "JAVA APPLET QUESTION": case QT_JAVAAPPLET: $this->tpl->setVariable("QUESTION_TYPE", $this->lng->txt("assJavaApplet")); break; case "MATCHING QUESTION": case QT_MATCHING: $this->tpl->setVariable("QUESTION_TYPE", $this->lng->txt("assMatchingQuestion")); break; case "ORDERING QUESTION": case QT_ORDERING: $this->tpl->setVariable("QUESTION_TYPE", $this->lng->txt("assOrderingQuestion")); break; case "TEXT QUESTION": case QT_TEXT: $this->tpl->setVariable("QUESTION_TYPE", $this->lng->txt("assTextQuestion")); break; } $this->tpl->parseCurrentBlock(); } // on import creation screen the pool was chosen (-1 for no pool) // BUT when no pool is available the input on creation screen is missing, so the field value -1 for no pool is not submitted. $QplOrTstID = isset($_POST["qpl"]) && (int) $_POST["qpl"] != 0 ? $_POST["qpl"] : -1; $this->tpl->setCurrentBlock("adm_content"); $this->tpl->setVariable("TEXT_TYPE", $this->lng->txt("question_type")); $this->tpl->setVariable("TEXT_TITLE", $this->lng->txt("question_title")); $this->tpl->setVariable("FOUND_QUESTIONS_INTRODUCTION", $this->lng->txt("tst_import_verify_found_questions")); $this->tpl->setVariable("VERIFICATION_HEADING", $this->lng->txt("import_tst")); $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this)); $this->tpl->setVariable("ARROW", ilUtil::getImagePath("arrow_downright.svg")); $this->tpl->setVariable("QUESTIONPOOL_ID", $QplOrTstID); $this->tpl->setVariable("VALUE_IMPORT", $this->lng->txt("import")); $this->tpl->setVariable("VALUE_CANCEL", $this->lng->txt("cancel")); $this->tpl->parseCurrentBlock(); }
/** * 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); }
function createImportFile($a_tmp_name, $a_name) { ilUtil::moveUploadedFile($a_tmp_name, $a_name, $this->getGroupPath() . '/import/' . $a_name); $this->import_file_info = pathinfo($this->getGroupPath() . '/import/' . $a_name); }
/** * 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()); } }
/** * Upload multi feedback file * * @param array * @return */ function uploadMultiFeedbackFile($a_file) { global $lng, $ilUser; include_once "./Modules/Exercise/exceptions/class.ilExerciseException.php"; if (!is_file($a_file["tmp_name"])) { throw new ilExerciseException($lng->txt("exc_feedback_file_could_not_be_uploaded")); } include_once "./Modules/Exercise/classes/class.ilFSStorageExercise.php"; $storage = new ilFSStorageExercise($this->getExerciseId(), $this->getId()); $mfu = $storage->getMultiFeedbackUploadPath($ilUser->getId()); ilUtil::delDir($mfu, true); ilUtil::moveUploadedFile($a_file["tmp_name"], "multi_feedback.zip", $mfu . "/" . "multi_feedback.zip"); ilUtil::unzip($mfu . "/multi_feedback.zip", true); $subdirs = ilUtil::getDir($mfu); $subdir = "notfound"; foreach ($subdirs as $s => $j) { if ($j["type"] == "dir" && substr($s, 0, 14) == "multi_feedback") { $subdir = $s; } } if (!is_dir($mfu . "/" . $subdir)) { throw new ilExerciseException($lng->txt("exc_no_feedback_dir_found_in_zip")); } return true; }
/** * move uploaded files * * @access public * @param string tmp name * @return int creation time of newly created file. 0 on error */ public function moveUploadedFile($a_temp_name) { $creation_time = time(); $file_name = $this->getImportDirectory() . '/' . self::IMPORT_NAME . '_' . $creation_time . '.xml'; if (!ilUtil::moveUploadedFile($a_temp_name, '', $file_name, false)) { return false; } return $creation_time; }
/** * Imports a survey from XML into the ILIAS database * * @return boolean True, if the import succeeds, false otherwise * @access public */ function importObject($file_info, $svy_qpl_id) { if ($svy_qpl_id < 1) { $svy_qpl_id = -1; } // check if file was uploaded $source = $file_info["tmp_name"]; $error = ""; if ($source == 'none' || !$source || $file_info["error"] > UPLOAD_ERR_OK) { $error = $this->lng->txt("import_no_file_selected"); } // check correct file type $isXml = FALSE; $isZip = FALSE; if (strcmp($file_info["type"], "text/xml") == 0 || strcmp($file_info["type"], "application/xml") == 0) { $isXml = TRUE; } // too many different mime-types, so we use the suffix $suffix = pathinfo($file_info["name"]); if (strcmp(strtolower($suffix["extension"]), "zip") == 0) { $isZip = TRUE; } if (!$isXml && !$isZip) { $error = $this->lng->txt("import_wrong_file_type"); global $ilLog; $ilLog->write("Survey: Import error. Filetype was \"" . $file_info["type"] . "\""); } if (strlen($error) == 0) { // import file as a survey $import_dir = $this->getImportDirectory(); $import_subdir = ""; $importfile = ""; include_once "./Services/Utilities/classes/class.ilUtil.php"; if ($isZip) { $importfile = $import_dir . "/" . $file_info["name"]; ilUtil::moveUploadedFile($source, $file_info["name"], $importfile); ilUtil::unzip($importfile); $found = $this->locateImportFiles($import_dir); if (!(strlen($found["dir"]) > 0 && strlen($found["xml"]) > 0)) { $error = $this->lng->txt("wrong_import_file_structure"); return $error; } $importfile = $found["xml"]; $import_subdir = $found["dir"]; } else { $importfile = tempnam($import_dir, "survey_import"); ilUtil::moveUploadedFile($source, $file_info["name"], $importfile); } $fh = fopen($importfile, "r"); if (!$fh) { $error = $this->lng->txt("import_error_opening_file"); return $error; } $xml = fread($fh, filesize($importfile)); $result = fclose($fh); if (!$result) { $error = $this->lng->txt("import_error_closing_file"); return $error; } unset($_SESSION["import_mob_xhtml"]); if (strpos($xml, "questestinterop")) { include_once "./Services/Survey/classes/class.SurveyImportParserPre38.php"; $import = new SurveyImportParserPre38($svy_qpl_id, "", TRUE); $import->setSurveyObject($this); $import->setXMLContent($xml); $import->startParsing(); } else { include_once "./Services/Survey/classes/class.SurveyImportParser.php"; $import = new SurveyImportParser($svy_qpl_id, "", TRUE); $import->setSurveyObject($this); $import->setXMLContent($xml); $import->startParsing(); } if (is_array($_SESSION["import_mob_xhtml"])) { include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php"; include_once "./Services/RTE/classes/class.ilRTE.php"; include_once "./Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php"; foreach ($_SESSION["import_mob_xhtml"] as $mob) { $importfile = $import_subdir . "/" . $mob["uri"]; if (file_exists($importfile)) { $media_object =& ilObjMediaObject::_saveTempFileAsMediaObject(basename($importfile), $importfile, FALSE); ilObjMediaObject::_saveUsage($media_object->getId(), "svy:html", $this->getId()); $this->setIntroduction(str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $this->getIntroduction())); $this->setOutro(str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $this->getOutro())); } else { global $ilLog; $ilLog->write("Error: Could not open XHTML mob file for test introduction during test import. File {$importfile} does not exist!"); } } $this->setIntroduction(ilRTE::_replaceMediaObjectImageSrc($this->getIntroduction(), 1)); $this->setOutro(ilRTE::_replaceMediaObjectImageSrc($this->getOutro(), 1)); $this->saveToDb(); } // delete import directory ilUtil::delDir($this->getImportDirectory()); } return $error; }
/** * Process an uploaded language file */ function uploadObject() { // save form inputs for next display $this->session["import"]["mode_existing"] = ilUtil::stripSlashes($_POST['mode_existing']); if ($_POST['cmd']['upload']) { $file = $_FILES['userfile']['tmp_name'] . 'x'; if (ilUtil::moveUploadedFile($_FILES['userfile']['tmp_name'], $_FILES['userfile']['name'], $file)) { $this->object->importLanguageFile($file, $_POST['mode_existing']); ilUtil::sendSuccess(sprintf($this->lng->txt("language_file_imported"), $_FILES['userfile']['name']), true); } } $this->ctrl->redirect($this, 'import'); }
/** * 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); }
/** * 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_filename, $image_tempfilename = "") { $result = 0; if (!empty($image_tempfilename)) { $image_filename = str_replace(" ", "_", $image_filename); $imagepath = $this->getImagePath(); if (!file_exists($imagepath)) { ilUtil::makeDirParents($imagepath); } //if (!move_uploaded_file($image_tempfilename, $imagepath . $image_filename)) if (!ilUtil::moveUploadedFile($image_tempfilename, $image_filename, $imagepath . $image_filename)) { $result = 2; } else { include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php"; $mimetype = ilObjMediaObject::getMimeType($imagepath . $image_filename); if (!preg_match("/^image/", $mimetype)) { unlink($imagepath . $image_filename); $result = 1; } else { // create thumbnail file if ($this->isSingleline && $this->getThumbSize()) { $this->generateThumbForFile($imagepath, $image_filename); } } } } return $result; }
/** * display status information or report errors messages * in case of error * * @access public */ function uploadObject() { global $_FILES, $rbacsystem; include_once 'Services/FileSystem/classes/class.ilUploadFiles.php'; // check create permission if (!$rbacsystem->checkAccess("create", $_GET["ref_id"], "sahs")) { $this->ilias->raiseError($this->lng->txt("no_create_permission"), $this->ilias->error_obj->WARNING); } elseif ($_FILES["scormfile"]["name"]) { // check if file was uploaded $source = $_FILES["scormfile"]["tmp_name"]; if ($source == 'none' || !$source) { $this->ilias->raiseError($this->lng->txt("msg_no_file"), $this->ilias->error_obj->MESSAGE); } // get_cfg_var("upload_max_filesize"); // get the may filesize form t he php.ini switch ($__FILES["scormfile"]["error"]) { case UPLOAD_ERR_INI_SIZE: $this->ilias->raiseError($this->lng->txt("err_max_file_size_exceeds"), $this->ilias->error_obj->MESSAGE); break; case UPLOAD_ERR_FORM_SIZE: $this->ilias->raiseError($this->lng->txt("err_max_file_size_exceeds"), $this->ilias->error_obj->MESSAGE); break; case UPLOAD_ERR_PARTIAL: $this->ilias->raiseError($this->lng->txt("err_partial_file_upload"), $this->ilias->error_obj->MESSAGE); break; case UPLOAD_ERR_NO_FILE: $this->ilias->raiseError($this->lng->txt("err_no_file_uploaded"), $this->ilias->error_obj->MESSAGE); break; } $file = pathinfo($_FILES["scormfile"]["name"]); } elseif ($_POST["uploaded_file"]) { // check if the file is in the upload directory and readable if (!ilUploadFiles::_checkUploadFile($_POST["uploaded_file"])) { $this->ilias->raiseError($this->lng->txt("upload_error_file_not_found"), $this->ilias->error_obj->MESSAGE); } $file = pathinfo($_POST["uploaded_file"]); } else { $this->ilias->raiseError($this->lng->txt("msg_no_file"), $this->ilias->error_obj->MESSAGE); } $name = substr($file["basename"], 0, strlen($file["basename"]) - strlen($file["extension"]) - 1); if ($name == "") { $name = $this->lng->txt("no_title"); } // create and insert object in objecttree switch ($_POST["sub_type"]) { case "scorm2004": include_once "./Modules/Scorm2004/classes/class.ilObjSCORM2004LearningModule.php"; $newObj = new ilObjSCORM2004LearningModule(); $newObj->setEditable($_POST["editable"] == 'y'); $newObj->setImportSequencing($_POST["import_sequencing"]); $newObj->setSequencingExpertMode($_POST["import_sequencing"]); break; case "scorm": include_once "./Modules/ScormAicc/classes/class.ilObjSCORMLearningModule.php"; $newObj = new ilObjSCORMLearningModule(); break; case "aicc": include_once "./Modules/ScormAicc/classes/class.ilObjAICCLearningModule.php"; $newObj = new ilObjAICCLearningModule(); break; case "hacp": include_once "./Modules/ScormAicc/classes/class.ilObjHACPLearningModule.php"; $newObj = new ilObjHACPLearningModule(); break; } $newObj->setTitle($name); $newObj->setSubType($_POST["sub_type"]); $newObj->setDescription(""); $newObj->create(true); $newObj->createReference(); $newObj->putInTree($_GET["ref_id"]); $newObj->setPermissions($_GET["ref_id"]); $newObj->notify("new", $_GET["ref_id"], $_GET["parent_non_rbac_id"], $_GET["ref_id"], $newObj->getRefId()); // create data directory, copy file to directory $newObj->createDataDirectory(); if ($_FILES["scormfile"]["name"]) { // copy uploaded file to data directory $file_path = $newObj->getDataDirectory() . "/" . $_FILES["scormfile"]["name"]; ilUtil::moveUploadedFile($_FILES["scormfile"]["tmp_name"], $_FILES["scormfile"]["name"], $file_path); } else { // copy uploaded file to data directory $file_path = $newObj->getDataDirectory() . "/" . $_POST["uploaded_file"]; ilUploadFiles::_copyUploadFile($_POST["uploaded_file"], $file_path); } ilUtil::unzip($file_path); ilUtil::renameExecutables($newObj->getDataDirectory()); $title = $newObj->readObject(); if ($title != "") { ilObject::_writeTitle($newObj->getId(), $title); /*$md = new ilMD($newObj->getId(),0, $newObj->getType()); if(is_object($md_gen = $md->getGeneral())) { $md_gen->setTitle($title); $md_gen->update(); }*/ } ilUtil::sendInfo($this->lng->txt($newObj->getType() . "_added"), true); ilUtil::redirect("ilias.php?baseClass=ilSAHSEditGUI&ref_id=" . $newObj->getRefId()); }
/** * 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); } }
/** * Process an uploaded language file */ function uploadObject() { if ($_POST['cmd']['upload']) { $file = $_FILES['userfile']['tmp_name'] . 'x'; if (ilUtil::moveUploadedFile($_FILES['userfile']['tmp_name'], $_FILES['userfile']['name'], $file)) { $this->object->importLanguageFile($file, $_POST['mode_existing']); ilUtil::sendSuccess(sprintf($this->lng->txt("language_file_imported"), $_FILES['userfile']['name']), false); $this->importObject(); } else { $this->importObject(); } } else { $this->cancelObject(); } }