00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 include_once "./assessment/classes/class.assQuestionGUI.php";
00025 include_once "./assessment/classes/inc.AssessmentConstants.php";
00026
00038 class assTextQuestionGUI extends assQuestionGUI
00039 {
00048 function assTextQuestionGUI(
00049 $id = -1
00050 )
00051 {
00052 $this->assQuestionGUI();
00053 include_once "./assessment/classes/class.assTextQuestion.php";
00054 $this->object = new assTextQuestion();
00055 if ($id >= 0)
00056 {
00057 $this->object->loadFromDb($id);
00058 }
00059 }
00060
00069 function getQuestionType()
00070 {
00071 return "assTextQuestion";
00072 }
00073
00081 function editQuestion()
00082 {
00083 $javascript = "<script type=\"text/javascript\">function initialSelect() {\n%s\n}</script>";
00084
00085 $this->getQuestionTemplate();
00086 $this->tpl->addBlockFile("QUESTION_DATA", "question_data", "tpl.il_as_qpl_text_question.html", true);
00087
00088 $this->outOtherQuestionData();
00089
00090 $internallinks = array(
00091 "lm" => $this->lng->txt("obj_lm"),
00092 "st" => $this->lng->txt("obj_st"),
00093 "pg" => $this->lng->txt("obj_pg"),
00094 "glo" => $this->lng->txt("glossary_term")
00095 );
00096 foreach ($internallinks as $key => $value)
00097 {
00098 $this->tpl->setCurrentBlock("internallink");
00099 $this->tpl->setVariable("TYPE_INTERNAL_LINK", $key);
00100 $this->tpl->setVariable("TEXT_INTERNAL_LINK", $value);
00101 $this->tpl->parseCurrentBlock();
00102 }
00103
00104
00105 $text_options = array(
00106 array("ci", $this->lng->txt("cloze_textgap_case_insensitive")),
00107 array("cs", $this->lng->txt("cloze_textgap_case_sensitive")),
00108 array("l1", sprintf($this->lng->txt("cloze_textgap_levenshtein_of"), "1")),
00109 array("l2", sprintf($this->lng->txt("cloze_textgap_levenshtein_of"), "2")),
00110 array("l3", sprintf($this->lng->txt("cloze_textgap_levenshtein_of"), "3")),
00111 array("l4", sprintf($this->lng->txt("cloze_textgap_levenshtein_of"), "4")),
00112 array("l5", sprintf($this->lng->txt("cloze_textgap_levenshtein_of"), "5"))
00113 );
00114 $text_rating = $this->object->getTextRating();
00115 foreach ($text_options as $text_option)
00116 {
00117 $this->tpl->setCurrentBlock("text_rating");
00118 $this->tpl->setVariable("RATING_VALUE", $text_option[0]);
00119 $this->tpl->setVariable("RATING_TEXT", $text_option[1]);
00120 if (strcmp($text_rating, $text_option[0]) == 0)
00121 {
00122 $this->tpl->setVariable("SELECTED_RATING_VALUE", " selected=\"selected\"");
00123 }
00124 $this->tpl->parseCurrentBlock();
00125 }
00126
00127 $this->tpl->setCurrentBlock("HeadContent");
00128 $this->tpl->setVariable("CONTENT_BLOCK", sprintf($javascript, "document.frm_text_question.title.focus();"));
00129 $this->tpl->parseCurrentBlock();
00130 $this->tpl->setCurrentBlock("question_data");
00131 $this->tpl->setVariable("TEXT_QUESTION_ID", $this->object->getId());
00132 $this->tpl->setVariable("VALUE_TEXT_QUESTION_TITLE", ilUtil::prepareFormOutput($this->object->getTitle()));
00133 $this->tpl->setVariable("VALUE_TEXT_QUESTION_COMMENT", ilUtil::prepareFormOutput($this->object->getComment()));
00134 $this->tpl->setVariable("VALUE_TEXT_QUESTION_AUTHOR", ilUtil::prepareFormOutput($this->object->getAuthor()));
00135 $questiontext = $this->object->getQuestion();
00136 $this->tpl->setVariable("VALUE_QUESTION", ilUtil::prepareFormOutput($this->object->prepareTextareaOutput($questiontext)));
00137 $keywords = $this->object->getKeywords();
00138 $this->tpl->setVariable("VALUE_KEYWORDS", ilUtil::prepareFormOutput($keywords));
00139 $this->tpl->setVariable("VALUE_POINTS", ilUtil::prepareFormOutput($this->object->getPoints()));
00140 if ($this->object->getMaxNumOfChars())
00141 {
00142 $this->tpl->setVariable("VALUE_MAXCHARS", ilUtil::prepareFormOutput($this->object->getMaxNumOfChars()));
00143 }
00144 $this->tpl->setVariable("TEXT_TITLE", $this->lng->txt("title"));
00145 $this->tpl->setVariable("TEXT_AUTHOR", $this->lng->txt("author"));
00146 $this->tpl->setVariable("TEXT_COMMENT", $this->lng->txt("description"));
00147 $this->tpl->setVariable("TEXT_RATING", $this->lng->txt("text_rating"));
00148 $this->tpl->setVariable("TEXT_QUESTION", $this->lng->txt("question"));
00149 $this->tpl->setVariable("TEXT_MAXCHARS", $this->lng->txt("maxchars"));
00150 $this->tpl->setVariable("TEXT_POINTS", $this->lng->txt("points"));
00151 $this->tpl->setVariable("OPTIONAL_KEYWORDS", $this->lng->txt("optional_keywords"));
00152 $this->tpl->setVariable("TEXT_KEYWORDS", $this->lng->txt("keywords"));
00153 $this->tpl->setVariable("DESCRIPTION_MAXCHARS", $this->lng->txt("description_maxchars"));
00154 $this->tpl->setVariable("TEXT_SOLUTION_HINT", $this->lng->txt("solution_hint"));
00155 $this->tpl->setVariable("TEXT_KEYWORDS_HINT", $this->lng->txt("keywords_hint"));
00156 if (count($this->object->suggested_solutions))
00157 {
00158 $solution_array = $this->object->getSuggestedSolution(0);
00159 include_once "./assessment/classes/class.assQuestion.php";
00160 $href = assQuestion::_getInternalLinkHref($solution_array["internal_link"]);
00161 $this->tpl->setVariable("TEXT_VALUE_SOLUTION_HINT", " <a href=\"$href\" target=\"content\">" . $this->lng->txt("solution_hint"). "</a> ");
00162 $this->tpl->setVariable("BUTTON_REMOVE_SOLUTION", $this->lng->txt("remove"));
00163 $this->tpl->setVariable("BUTTON_ADD_SOLUTION", $this->lng->txt("change"));
00164 $this->tpl->setVariable("VALUE_SOLUTION_HINT", $solution_array["internal_link"]);
00165 }
00166 else
00167 {
00168 $this->tpl->setVariable("BUTTON_ADD_SOLUTION", $this->lng->txt("add"));
00169 }
00170 $this->tpl->setVariable("SAVE",$this->lng->txt("save"));
00171 $this->tpl->setVariable("SAVE_EDIT", $this->lng->txt("save_edit"));
00172 $this->tpl->setVariable("CANCEL",$this->lng->txt("cancel"));
00173 $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
00174 $this->ctrl->setParameter($this, "sel_question_types", "assTextQuestion");
00175 $this->tpl->setVariable("TEXT_QUESTION_TYPE", $this->lng->txt("assTextQuestion"));
00176 $this->tpl->setVariable("ACTION_TEXT_QUESTION", $this->ctrl->getFormAction($this));
00177
00178 $this->tpl->parseCurrentBlock();
00179 include_once "./Services/RTE/classes/class.ilRTE.php";
00180 $rtestring = ilRTE::_getRTEClassname();
00181 include_once "./Services/RTE/classes/class.$rtestring.php";
00182 $rte = new $rtestring();
00183 $rte->addPlugin("latex");
00184 $rte->addButton("latex");
00185 include_once "./classes/class.ilObject.php";
00186 $obj_id = $_GET["q_id"];
00187 $obj_type = ilObject::_lookupType($_GET["ref_id"], TRUE);
00188 $rte->addRTESupport($obj_id, $obj_type, "assessment");
00189
00190 $this->tpl->setCurrentBlock("adm_content");
00191 $this->tpl->setVariable("BODY_ATTRIBUTES", " onload=\"initialSelect();\"");
00192 $this->tpl->parseCurrentBlock();
00193 }
00194
00198 function checkInput()
00199 {
00200 $cmd = $this->ctrl->getCmd();
00201
00202 if ((!$_POST["title"]) or (!$_POST["author"]) or (!$_POST["question"]) or (strlen($_POST["points"]) == 0))
00203 {
00204 return false;
00205 }
00206 return true;
00207 }
00208
00217 function writePostData()
00218 {
00219 $result = 0;
00220 if ((!$_POST["title"]) or (!$_POST["author"]) or (!$_POST["question"]) or (strlen($_POST["points"]) == 0))
00221 {
00222 $result = 1;
00223 }
00224
00225 $this->object->setTitle(ilUtil::stripSlashes($_POST["title"]));
00226 $this->object->setAuthor(ilUtil::stripSlashes($_POST["author"]));
00227 $this->object->setComment(ilUtil::stripSlashes($_POST["comment"]));
00228 include_once "./classes/class.ilObjAdvancedEditing.php";
00229 $questiontext = ilUtil::stripSlashes($_POST["question"], false, ilObjAdvancedEditing::_getUsedHTMLTagsAsString("assessment"));
00230 $this->object->setQuestion($questiontext);
00231 $this->object->setPoints($_POST["points"]);
00232 if ($_POST["points"] < 0)
00233 {
00234 $result = 1;
00235 $this->setErrorMessage($this->lng->txt("negative_points_not_allowed"));
00236 }
00237 $this->object->setSuggestedSolution($_POST["solution_hint"], 0);
00238 $this->object->setMaxNumOfChars($_POST["maxchars"]);
00239 $this->object->setKeywords(ilUtil::stripSlashes($_POST["keywords"], false, ilObjAdvancedEditing::_getUsedHTMLTagsAsString("assessment")));
00240 $this->object->setTextRating($_POST["text_rating"]);
00241
00242 $saved = $this->writeOtherPostData($result);
00243
00244
00245 if ($_POST["text_question_id"] > 0)
00246 {
00247 $this->object->setId($_POST["text_question_id"]);
00248 }
00249
00250 return $result;
00251 }
00252
00253 function outAdditionalOutput()
00254 {
00255 if ($this->object->getMaxNumOfChars() > 0)
00256 {
00257 $this->tpl->addBlockFile("CONTENT_BLOCK", "charcounter", "tpl.charcounter.html", true);
00258 $this->tpl->setCurrentBlock("charcounter");
00259 $this->tpl->setVariable("CHARACTERS", $this->lng->txt("characters"));
00260 $this->tpl->parseCurrentBlock();
00261 }
00262 }
00263
00264 function outQuestionForTest($formaction, $active_id, $pass = NULL, $is_postponed = FALSE, $use_post_solutions = FALSE)
00265 {
00266 $test_output = $this->getTestOutput($active_id, $pass, $is_postponed, $use_post_solutions);
00267 $this->tpl->setVariable("QUESTION_OUTPUT", $test_output);
00268 $this->tpl->setVariable("FORMACTION", $formaction);
00269 $this->outAdditionalOutput();
00270 }
00271
00272 function getSolutionOutput($active_id, $pass = NULL, $graphicalOutput = FALSE, $result_output = FALSE, $show_question_only = TRUE)
00273 {
00274
00275 $user_solution = "";
00276 if ($active_id)
00277 {
00278 $solutions =& $this->object->getSolutionValues($active_id, $pass);
00279 foreach ($solutions as $idx => $solution_value)
00280 {
00281 $user_solution = $solution_value["value1"];
00282 }
00283 }
00284 else
00285 {
00286 $keywords = $this->object->getKeywordList();
00287 if (count($keywords))
00288 {
00289 $user_solution = $this->lng->txt("solution_may_contain_keywords") . ": " . join(",", $keywords);
00290 }
00291 }
00292
00293
00294 include_once "./classes/class.ilTemplate.php";
00295 $template = new ilTemplate("tpl.il_as_qpl_text_question_output_solution.html", TRUE, TRUE, TRUE);
00296 $solutiontemplate = new ilTemplate("tpl.il_as_tst_solution_output.html", TRUE, TRUE, TRUE);
00297 $template->setVariable("ESSAY", ilUtil::prepareFormOutput($user_solution));
00298 $questiontext = $this->object->getQuestion();
00299 if ($active_id)
00300 {
00301 if ($graphicalOutput)
00302 {
00303
00304 $reached_points = $this->object->getReachedPoints($active_id);
00305 if ($reached_points == $this->object->getMaximumPoints())
00306 {
00307 $template->setCurrentBlock("icon_ok");
00308 $template->setVariable("ICON_OK", ilUtil::getImagePath("icon_ok.gif"));
00309 $template->setVariable("TEXT_OK", $this->lng->txt("answer_is_right"));
00310 $template->parseCurrentBlock();
00311 }
00312 else
00313 {
00314 $template->setCurrentBlock("icon_ok");
00315 if ($reached_points > 0)
00316 {
00317 $template->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_mostly_ok.gif"));
00318 $template->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_not_correct_but_positive"));
00319 }
00320 else
00321 {
00322 $template->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_not_ok.gif"));
00323 $template->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_wrong"));
00324 }
00325 $template->parseCurrentBlock();
00326 }
00327 }
00328 }
00329 $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
00330 $questionoutput = $template->get();
00331 $solutiontemplate->setVariable("SOLUTION_OUTPUT", $questionoutput);
00332
00333 $solutionoutput = $solutiontemplate->get();
00334 if (!$show_question_only)
00335 {
00336
00337 $pageoutput = $this->getILIASPage();
00338 $solutionoutput = preg_replace("/(<div( xmlns:xhtml\=\"http:\/\/www.w3.org\/1999\/xhtml\"){0,1} class\=\"ilc_Question\"><\/div>)/ims", $solutionoutput, $pageoutput);
00339 }
00340 return $solutionoutput;
00341 }
00342
00343 function getPreview()
00344 {
00345
00346 include_once "./classes/class.ilTemplate.php";
00347 $template = new ilTemplate("tpl.il_as_qpl_text_question_output.html", TRUE, TRUE, TRUE);
00348 if ($this->object->getMaxNumOfChars())
00349 {
00350 $template->setCurrentBlock("maximum_char_hint");
00351 $template->setVariable("MAXIMUM_CHAR_HINT", sprintf($this->lng->txt("text_maximum_chars_allowed"), $this->object->getMaxNumOfChars()));
00352 $template->parseCurrentBlock();
00353 $template->setCurrentBlock("has_maxchars");
00354 $template->setVariable("MAXCHARS", $this->object->getMaxNumOfChars());
00355 $template->parseCurrentBlock();
00356 $template->setCurrentBlock("maxchars_counter");
00357 $template->setVariable("MAXCHARS", $this->object->getMaxNumOfChars());
00358 $template->parseCurrentBlock();
00359 }
00360 $questiontext = $this->object->getQuestion();
00361 $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
00362 $questionoutput = $template->get();
00363 $questionoutput = preg_replace("/<div[^>]*?>(.*)<\/div>/is", "\\1", $questionoutput);
00364 return $questionoutput;
00365 }
00366
00367 function getTestOutput($active_id, $pass = NULL, $is_postponed = FALSE, $use_post_solutions = FALSE)
00368 {
00369
00370 $pageoutput = $this->outQuestionPage("", $is_postponed, $active_id);
00371
00372
00373 $user_solution = "";
00374 if ($active_id)
00375 {
00376 $solutions = NULL;
00377 include_once "./assessment/classes/class.ilObjTest.php";
00378 if (ilObjTest::_getHidePreviousResults($active_id, true))
00379 {
00380 if (is_null($pass)) $pass = ilObjTest::_getPass($active_id);
00381 }
00382 $solutions =& $this->object->getSolutionValues($active_id, $pass);
00383 foreach ($solutions as $idx => $solution_value)
00384 {
00385 $user_solution = $solution_value["value1"];
00386 }
00387 }
00388
00389
00390 include_once "./classes/class.ilTemplate.php";
00391 $template = new ilTemplate("tpl.il_as_qpl_text_question_output.html", TRUE, TRUE, TRUE);
00392 if ($this->object->getMaxNumOfChars())
00393 {
00394 $template->setCurrentBlock("maximum_char_hint");
00395 $template->setVariable("MAXIMUM_CHAR_HINT", sprintf($this->lng->txt("text_maximum_chars_allowed"), $this->object->getMaxNumOfChars()));
00396 $template->parseCurrentBlock();
00397 $template->setCurrentBlock("has_maxchars");
00398 $template->setVariable("MAXCHARS", $this->object->getMaxNumOfChars());
00399 $template->parseCurrentBlock();
00400 $template->setCurrentBlock("maxchars_counter");
00401 $template->setVariable("MAXCHARS", $this->object->getMaxNumOfChars());
00402 $template->parseCurrentBlock();
00403 }
00404 $template->setVariable("ESSAY", ilUtil::prepareFormOutput($user_solution));
00405 $questiontext = $this->object->getQuestion();
00406 $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
00407 $questionoutput = $template->get();
00408 $questionoutput = preg_replace("/(<div( xmlns:xhtml\=\"http:\/\/www.w3.org\/1999\/xhtml\"){0,1} class\=\"ilc_Question\"><\/div>)/ims", $questionoutput, $pageoutput);
00409 return $questionoutput;
00410 }
00411
00412 function addSuggestedSolution()
00413 {
00414 $_SESSION["subquestion_index"] = 0;
00415 if ($_POST["cmd"]["addSuggestedSolution"])
00416 {
00417 if ($this->writePostData())
00418 {
00419 sendInfo($this->getErrorMessage());
00420 $this->editQuestion();
00421 return;
00422 }
00423 if (!$this->checkInput())
00424 {
00425 sendInfo($this->lng->txt("fill_out_all_required_fields_add_answer"));
00426 $this->editQuestion();
00427 return;
00428 }
00429 }
00430 $this->object->saveToDb();
00431 $_GET["q_id"] = $this->object->getId();
00432 $this->tpl->setVariable("HEADER", $this->object->getTitle());
00433 $this->getQuestionTemplate();
00434 parent::addSuggestedSolution();
00435 }
00436 }
00437 ?>