/** * saves the form on successfull validation and redirects to showForm command * * @access private * @global ilCtrl $ilCtrl * @global ilLanguage $lng */ private function saveFormCmd() { global $ilCtrl, $lng, $ilUser; $form = $this->buildForm(); if ($form->checkInput()) { $questionHint = new ilAssQuestionHint(); if ((int) $form->getInput('hint_id')) { $questionHint->load((int) $form->getInput('hint_id')); $hintJustCreated = false; } else { $questionHint->setQuestionId($this->questionOBJ->getId()); $questionHint->setIndex(ilAssQuestionHintList::getNextIndexByQuestionId($this->questionOBJ->getId())); $hintJustCreated = true; } $questionHint->setText($form->getInput('hint_text')); $questionHint->setPoints($form->getInput('hint_points')); $questionHint->save(); ilUtil::sendSuccess($lng->txt('tst_question_hints_form_saved_msg'), true); $originalexists = $this->questionOBJ->_questionExistsInPool($this->questionOBJ->original_id); include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php"; if ($_GET["calling_test"] && $originalexists && assQuestion::_isWriteable($this->questionOBJ->original_id, $ilUser->getId())) { $ilCtrl->redirectByClass('ilAssQuestionHintsGUI', ilAssQuestionHintsGUI::CMD_CONFIRM_SYNC); } if ($hintJustCreated && $this->questionOBJ->isAdditionalContentEditingModePageObject()) { $ilCtrl->setParameterByClass('ilasshintpagegui', 'hint_id', $questionHint->getId()); $ilCtrl->redirectByClass('ilasshintpagegui', 'edit'); } else { $ilCtrl->redirectByClass('ilAssQuestionHintsGUI', ilAssQuestionHintsGUI::CMD_SHOW_LIST); } } ilUtil::sendFailure($lng->txt('tst_question_hints_form_invalid_msg')); $this->showFormCmd($form); }
/** * 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); }
public function saveReturnFQ() { global $ilUser; $old_id = $_GET["q_id"]; $result = $this->writePostData(); if ($result == 0) { $ilUser->setPref("tst_lastquestiontype", $this->object->getQuestionType()); $ilUser->writePref("tst_lastquestiontype", $this->object->getQuestionType()); $this->saveTaxonomyAssignments(); $this->object->saveToDb(); $originalexists = $this->object->_questionExistsInPool($this->object->original_id); include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php"; if (($_GET["calling_test"] || isset($_GET['calling_consumer']) && (int) $_GET['calling_consumer']) && $originalexists && assQuestion::_isWriteable($this->object->original_id, $ilUser->getId())) { $this->ctrl->redirect($this, "originalSyncForm"); return; } elseif ($_GET["calling_test"]) { require_once 'Modules/Test/classes/class.ilObjTest.php'; $test = new ilObjTest($_GET["calling_test"]); #var_dump(assQuestion::_questionExistsInTest($this->object->getId(), $test->getTestId())); $q_id = $this->object->getId(); if (!assQuestion::_questionExistsInTest($this->object->getId(), $test->getTestId())) { global $tree, $ilDB, $ilPluginAdmin; include_once "./Modules/Test/classes/class.ilObjTest.php"; $_GET["ref_id"] = $_GET["calling_test"]; $test = new ilObjTest($_GET["calling_test"], true); require_once 'Modules/Test/classes/class.ilTestQuestionSetConfigFactory.php'; $testQuestionSetConfigFactory = new ilTestQuestionSetConfigFactory($tree, $ilDB, $ilPluginAdmin, $test); $new_id = $test->insertQuestion($testQuestionSetConfigFactory->getQuestionSetConfig(), $this->object->getId()); $q_id = $new_id; if (isset($_REQUEST['prev_qid'])) { $test->moveQuestionAfter($this->object->getId() + 1, $_REQUEST['prev_qid']); } $this->ctrl->setParameter($this, 'q_id', $new_id); $this->ctrl->setParameter($this, 'calling_test', $_GET['calling_test']); #$this->ctrl->setParameter($this, 'test_ref_id', false); } ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true); if ($_REQUEST['test_express_mode']) { ilUtil::redirect(ilTestExpressPage::getReturnToPageLink($q_id)); } else { ilUtil::redirect("ilias.php?baseClass=ilObjTestGUI&cmd=questions&ref_id=" . $_GET["calling_test"]); } } else { if ($this->object->getId() != $old_id) { $this->callNewIdListeners($this->object->getId()); ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true); $this->ctrl->redirectByClass("ilobjquestionpoolgui", "questions"); } if (strcmp($_SESSION["info"], "") != 0) { ilUtil::sendSuccess($_SESSION["info"] . "<br />" . $this->lng->txt("msg_obj_modified"), true); } else { ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true); } $this->ctrl->redirectByClass("ilobjquestionpoolgui", "questions"); } } else { $ilUser->setPref("tst_lastquestiontype", $this->object->getQuestionType()); $ilUser->writePref("tst_lastquestiontype", $this->object->getQuestionType()); $this->object->saveToDb(); $this->editQuestion(); } }
/** * returns the fact wether the presentation of the question sync2pool form * is required after saving the form or not * * @access private * @return boolean $isSyncAfterSaveRequired */ private function isSyncAfterSaveRequired() { global $ilUser; if (!$_GET["calling_test"]) { return false; } if ($this->questionOBJ->isAdditionalContentEditingModePageObject()) { return false; } if (!$this->questionOBJ->_questionExistsInPool($this->questionOBJ->original_id)) { return false; } if (!assQuestion::_isWriteable($this->object->original_id, $ilUser->getId())) { return false; } return true; }
/** * saves the order based on index values passed from table's form * (the table must not be paginated, because ALL hints index values are required) * * @access private * @global ilCtrl $ilCtrl * @global ilLanguage $lng */ private function saveListOrderCmd() { global $ilCtrl, $lng; $hintIndexes = self::orderHintIndexes(self::fetchHintIndexesParameter()); if (!count($hintIndexes)) { ilUtil::sendFailure($lng->txt('tst_question_hints_save_order_unkown_failure_msg'), true); $ilCtrl->redirect($this); } $curQuestionHintList = ilAssQuestionHintList::getListByQuestionId($this->questionOBJ->getId()); $newQuestionHintList = new ilAssQuestionHintList(); foreach ($hintIndexes as $hintId => $hintIndex) { if (!$curQuestionHintList->hintExists($hintId)) { ilUtil::sendFailure($lng->txt('tst_question_hints_save_order_unkown_failure_msg'), true); $ilCtrl->redirect($this); } $questionHint = $curQuestionHintList->getHint($hintId); $newQuestionHintList->addHint($questionHint); } $newQuestionHintList->reIndex(); ilUtil::sendSuccess($lng->txt('tst_question_hints_save_order_success_msg'), true); $originalexists = $this->questionOBJ->_questionExistsInPool($this->questionOBJ->original_id); include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php"; global $ilUser; if ($_GET["calling_test"] && $originalexists && assQuestion::_isWriteable($this->questionOBJ->original_id, $ilUser->getId())) { $ilCtrl->redirectByClass('ilAssQuestionHintsGUI', ilAssQuestionHintsGUI::CMD_CONFIRM_SYNC); } $ilCtrl->redirect($this); }