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 "./Modules/TestQuestionPool/classes/class.assQuestionGUI.php";
00025 include_once "./Modules/Test/classes/inc.AssessmentConstants.php";
00026
00038 class assNumericGUI extends assQuestionGUI
00039 {
00048 function assNumericGUI(
00049 $id = -1
00050 )
00051 {
00052 $this->assQuestionGUI();
00053 include_once "./Modules/TestQuestionPool/classes/class.assNumeric.php";
00054 $this->object = new assNumeric();
00055 if ($id >= 0)
00056 {
00057 $this->object->loadFromDb($id);
00058 }
00059 }
00060
00061 function getCommand($cmd)
00062 {
00063 if (substr($cmd, 0, 6) == "delete")
00064 {
00065 $cmd = "delete";
00066 }
00067
00068 return $cmd;
00069 }
00070
00071
00079 function editQuestion()
00080 {
00081 $this->tpl->addJavascript("./Services/JavaScript/js/Basic.js");
00082 $javascript = "<script type=\"text/javascript\">ilAddOnLoad(initialSelect);\n".
00083 "function initialSelect() {\n%s\n}</script>";
00084 $this->getQuestionTemplate();
00085 $this->tpl->addBlockFile("QUESTION_DATA", "question_data", "tpl.il_as_qpl_numeric.html", "Modules/TestQuestionPool");
00086
00087 $this->outOtherQuestionData();
00088
00089 $internallinks = array(
00090 "lm" => $this->lng->txt("obj_lm"),
00091 "st" => $this->lng->txt("obj_st"),
00092 "pg" => $this->lng->txt("obj_pg"),
00093 "glo" => $this->lng->txt("glossary_term")
00094 );
00095 foreach ($internallinks as $key => $value)
00096 {
00097 $this->tpl->setCurrentBlock("internallink");
00098 $this->tpl->setVariable("TYPE_INTERNAL_LINK", $key);
00099 $this->tpl->setVariable("TEXT_INTERNAL_LINK", $value);
00100 $this->tpl->parseCurrentBlock();
00101 }
00102
00103 if ($this->object->getRangeCount() == 0)
00104 {
00105 $this->object->addRange(0.0, 0.0, 0);
00106 }
00107
00108 $counter = 0;
00109 foreach ($this->object->ranges as $range)
00110 {
00111 $this->tpl->setCurrentBlock("ranges");
00112 $this->tpl->setVariable("COUNTER", $counter);
00113 $this->tpl->setVariable("TEXT_RANGE", $this->lng->txt("range"));
00114 if (strlen($range->getPoints())) $this->tpl->setVariable("VALUE_POINTS", " value=\"" . $range->getPoints() . "\"");
00115 if (strlen($range->getLowerLimit())) $this->tpl->setVariable("VALUE_LOWER_LIMIT", " value=\"" . $range->getLowerLimit() . "\"");
00116 if (strlen($range->getUpperLimit())) $this->tpl->setVariable("VALUE_UPPER_LIMIT", " value=\"" . $range->getUpperLimit() . "\"");
00117 $this->tpl->setVariable("TEXT_RANGE_LOWER_LIMIT", $this->lng->txt("range_lower_limit"));
00118 $this->tpl->setVariable("TEXT_RANGE_UPPER_LIMIT", $this->lng->txt("range_upper_limit"));
00119 $this->tpl->setVariable("TEXT_POINTS", $this->lng->txt("points"));
00120 $this->tpl->parseCurrentBlock();
00121 $counter++;
00122 }
00123
00124 $this->tpl->setCurrentBlock("question_data");
00125 $this->tpl->setVariable("NUMERIC_ID", $this->object->getId());
00126 $this->tpl->setVariable("VALUE_NUMERIC_TITLE", ilUtil::prepareFormOutput($this->object->getTitle()));
00127 $this->tpl->setVariable("VALUE_NUMERIC_COMMENT", ilUtil::prepareFormOutput($this->object->getComment()));
00128 $this->tpl->setVariable("VALUE_NUMERIC_AUTHOR", ilUtil::prepareFormOutput($this->object->getAuthor()));
00129 $questiontext = $this->object->getQuestion();
00130 $this->tpl->setVariable("VALUE_QUESTION", ilUtil::prepareFormOutput($this->object->prepareTextareaOutput($questiontext)));
00131 $this->tpl->setVariable("TEXT_TITLE", $this->lng->txt("title"));
00132 $this->tpl->setVariable("TEXT_AUTHOR", $this->lng->txt("author"));
00133 $this->tpl->setVariable("TEXT_COMMENT", $this->lng->txt("description"));
00134 $this->tpl->setVariable("TEXT_QUESTION", $this->lng->txt("question"));
00135 $this->tpl->setVariable("TEXT_SOLUTION_HINT", $this->lng->txt("solution_hint"));
00136 $this->tpl->setVariable("TEXT_MAXCHARS", $this->lng->txt("maxchars"));
00137 $this->tpl->setVariable("VALUE_MAXCHARS", $this->object->getMaxChars());
00138 if (count($this->object->suggested_solutions))
00139 {
00140 $solution_array = $this->object->getSuggestedSolution(0);
00141 include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
00142 $href = assQuestion::_getInternalLinkHref($solution_array["internal_link"]);
00143 $this->tpl->setVariable("TEXT_VALUE_SOLUTION_HINT", " <a href=\"$href\" target=\"content\">" . $this->lng->txt("solution_hint"). "</a> ");
00144 $this->tpl->setVariable("BUTTON_REMOVE_SOLUTION", $this->lng->txt("remove"));
00145 $this->tpl->setVariable("BUTTON_ADD_SOLUTION", $this->lng->txt("change"));
00146 $this->tpl->setVariable("VALUE_SOLUTION_HINT", $solution_array["internal_link"]);
00147 }
00148 else
00149 {
00150 $this->tpl->setVariable("BUTTON_ADD_SOLUTION", $this->lng->txt("add"));
00151 }
00152 $this->tpl->setVariable("SAVE",$this->lng->txt("save"));
00153 $this->tpl->setVariable("SAVE_EDIT", $this->lng->txt("save_edit"));
00154 $this->tpl->setVariable("CANCEL",$this->lng->txt("cancel"));
00155 $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
00156 $this->ctrl->setParameter($this, "sel_question_types", "assNumeric");
00157 $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
00158 $this->tpl->setVariable("TEXT_QUESTION_TYPE", $this->lng->txt("assNumeric"));
00159 include_once "./Services/RTE/classes/class.ilRTE.php";
00160 $rtestring = ilRTE::_getRTEClassname();
00161 include_once "./Services/RTE/classes/class.$rtestring.php";
00162 $rte = new $rtestring();
00163 $rte->addPlugin("latex");
00164 $rte->addButton("latex"); $rte->addButton("pastelatex");
00165 include_once "./classes/class.ilObject.php";
00166 $obj_id = $_GET["q_id"];
00167 $obj_type = ilObject::_lookupType($_GET["ref_id"], TRUE);
00168 $rte->addRTESupport($obj_id, $obj_type, "assessment");
00169
00170 $this->tpl->parseCurrentBlock();
00171 $this->tpl->setCurrentBlock("adm_content");
00172
00173 $this->tpl->parseCurrentBlock();
00174 }
00175
00179 function checkInput()
00180 {
00181 $cmd = $this->ctrl->getCmd();
00182
00183 if ((!$_POST["title"]) or (!$_POST["author"]) or (!$_POST["question"]))
00184 {
00185
00186 return false;
00187 }
00188 foreach ($_POST as $key => $value)
00189 {
00190 if (preg_match("/range_(\d+)/", $key, $matches))
00191 {
00192 if (!$value)
00193 {
00194
00195 return false;
00196 }
00197 }
00198 }
00199
00200 return true;
00201 }
00202
00212 function checkRange()
00213 {
00214 include_once "./Services/Math/classes/class.EvalMath.php";
00215 $eval = new EvalMath();
00216 $eval->suppress_errors = TRUE;
00217 if (($eval->e($_POST["rang_lower_limit"]) !== FALSE) AND ($eval->e($_POST ["range_upper_limit"]) !== FALSE))
00218 {
00219 if ($eval->e($_POST["rang_lower_limit"]) < $eval->e($_POST["range_upper_limit"]))
00220 {
00221 return TRUE;
00222 }
00223 else
00224 {
00225 return FALSE;
00226 }
00227 }
00228 else
00229 {
00230 return FALSE;
00231 }
00232 }
00233
00242 function writePostData()
00243 {
00244 include_once "./Services/Math/classes/class.EvalMath.php";
00245 $eval = new EvalMath();
00246 $eval->suppress_errors = TRUE;
00247
00248 $saved = false;
00249 $result = 0;
00250 if ((!$_POST["title"]) or (!$_POST["author"]) or (!$_POST["question"]) or (!$_POST["maxchars"]))
00251 {
00252 $result = 1;
00253 }
00254
00255 $this->object->setTitle(ilUtil::stripSlashes($_POST["title"]));
00256 $this->object->setAuthor(ilUtil::stripSlashes($_POST["author"]));
00257 $this->object->setComment(ilUtil::stripSlashes($_POST["comment"]));
00258 include_once "./classes/class.ilObjAdvancedEditing.php";
00259 $questiontext = ilUtil::stripSlashes($_POST["question"], false, ilObjAdvancedEditing::_getUsedHTMLTagsAsString("assessment"));
00260 $questiontext = preg_replace("/[\n\r]+/", "<br />", $questiontext);
00261 $this->object->setQuestion($questiontext);
00262 $this->object->setSuggestedSolution($_POST["solution_hint"], 0);
00263 $this->object->setShuffle($_POST["shuffle"]);
00264 $this->object->setMaxChars($_POST["maxchars"]);
00265
00266
00267 $saved = $saved | $this->writeOtherPostData($result);
00268
00269
00270 $this->object->flushRanges();
00271
00272
00273
00274
00275 foreach ($_POST as $key => $value)
00276 {
00277 if (preg_match("/lowerlimit_(\d+)/", $key, $matches))
00278 {
00279 $points = $_POST["points_$matches[1]"];
00280 if ($points < 0)
00281 {
00282 $result = 1;
00283 $this->setErrorMessage($this->lng->txt("negative_points_not_allowed"));
00284 }
00285 $lowerlimit = str_replace(",", ".", $_POST["lowerlimit_".$matches[1]]);
00286 if (strlen($lowerlimit) == 0) $lowerlimit = 0.0;
00287 if ($eval->e($lowerlimit) === FALSE)
00288 {
00289 $this->setErrorMessage($this->lng->txt("value_is_not_a_numeric_value"));
00290 $result = 1;
00291 }
00292 $upperlimit = str_replace(",", ".", $_POST["upperlimit_".$matches[1]]);
00293 if (strlen($upperlimit) == 0) $upperlimit = 0.0;
00294 if ($eval->e($upperlimit) === FALSE)
00295 {
00296 $this->setErrorMessage($this->lng->txt("value_is_not_a_numeric_value"));
00297 $result = 1;
00298 }
00299 $this->object->addRange(
00300 $lowerlimit,
00301 $upperlimit,
00302 $points,
00303 $matches[1]
00304 );
00305 }
00306 }
00307
00308 if ($saved)
00309 {
00310
00311
00312
00313
00314 $this->object->saveToDb();
00315 $this->ctrl->setParameter($this, "q_id", $this->object->getId());
00316 }
00317
00318 return $result;
00319 }
00320
00321 function outQuestionForTest($formaction, $active_id, $pass = NULL, $is_postponed = FALSE, $use_post_solutions = FALSE)
00322 {
00323 $test_output = $this->getTestOutput($active_id, $pass, $is_postponed, $use_post_solutions);
00324 $this->tpl->setVariable("QUESTION_OUTPUT", $test_output);
00325 $this->tpl->setVariable("FORMACTION", $formaction);
00326 }
00327
00328 function getSolutionOutput($active_id, $pass = NULL, $graphicalOutput = FALSE, $result_output = FALSE, $show_question_only = TRUE, $show_feedback = FALSE)
00329 {
00330
00331 $solutions = array();
00332 if ($active_id)
00333 {
00334 $solutions =& $this->object->getSolutionValues($active_id, $pass);
00335 }
00336 else
00337 {
00338 foreach ($this->object->ranges as $key => $range)
00339 {
00340 array_push($solutions, array("value1" => sprintf($this->lng->txt("value_between_x_and_y"), $range->getLowerLimit(), $range->getUpperLimit())));
00341 }
00342 }
00343
00344
00345 include_once "./classes/class.ilTemplate.php";
00346 $template = new ilTemplate("tpl.il_as_qpl_numeric_output_solution.html", TRUE, TRUE, "Modules/TestQuestionPool");
00347 $solutiontemplate = new ilTemplate("tpl.il_as_tst_solution_output.html",TRUE, TRUE, "Modules/TestQuestionPool");
00348 if (is_array($solutions))
00349 {
00350 if ($active_id)
00351 {
00352 if ($graphicalOutput)
00353 {
00354
00355 if ($this->object->getReachedPoints($active_id, $pass) == $this->object->getMaximumPoints())
00356 {
00357 $template->setCurrentBlock("icon_ok");
00358 $template->setVariable("ICON_OK", ilUtil::getImagePath("icon_ok.gif"));
00359 $template->setVariable("TEXT_OK", $this->lng->txt("answer_is_right"));
00360 $template->parseCurrentBlock();
00361 }
00362 else
00363 {
00364 $template->setCurrentBlock("icon_ok");
00365 $template->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_not_ok.gif"));
00366 $template->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_wrong"));
00367 $template->parseCurrentBlock();
00368 }
00369 }
00370 }
00371 foreach ($solutions as $solution)
00372 {
00373 $template->setVariable("NUMERIC_VALUE", $solution["value1"]);
00374 }
00375 if (count($solutions) == 0)
00376 {
00377 $template->setVariable("NUMERIC_VALUE", " ");
00378 }
00379 }
00380 $template->setVariable("NUMERIC_SIZE", $this->object->getMaxChars());
00381 $questiontext = $this->object->getQuestion();
00382 $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
00383 $questionoutput = $template->get();
00384 $feedback = ($show_feedback) ? $this->getAnswerFeedbackOutput($active_id, $pass) : "";
00385 if (strlen($feedback)) $solutiontemplate->setVariable("FEEDBACK", $feedback);
00386 $solutiontemplate->setVariable("SOLUTION_OUTPUT", $questionoutput);
00387
00388 $solutionoutput = $solutiontemplate->get();
00389 if (!$show_question_only)
00390 {
00391
00392 $pageoutput = $this->getILIASPage();
00393 $solutionoutput = "<div class=\"ilias_content\">" . preg_replace("/(<div( xmlns:xhtml\=\"http:\/\/www.w3.org\/1999\/xhtml\"){0,1} class\=\"ilc_Question\"><\/div>)/ims", "</div><div class=\"ilc_Question\">" . $solutionoutput . "</div><div class=\"ilias_content\">", $pageoutput) . "</div>";
00394 }
00395 return $solutionoutput;
00396 }
00397
00398 function getPreview($show_question_only = FALSE)
00399 {
00400
00401 include_once "./classes/class.ilTemplate.php";
00402 $template = new ilTemplate("tpl.il_as_qpl_numeric_output.html", TRUE, TRUE, "Modules/TestQuestionPool");
00403 $template->setVariable("NUMERIC_SIZE", $this->object->getMaxChars());
00404 $questiontext = $this->object->getQuestion();
00405 $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
00406 $questionoutput = $template->get();
00407 if (!$show_question_only)
00408 {
00409
00410 $pageoutput = $this->getILIASPage();
00411 $questionoutput = preg_replace("/(<div( xmlns:xhtml\=\"http:\/\/www.w3.org\/1999\/xhtml\"){0,1} class\=\"ilc_Question\"><\/div>)/ims", $questionoutput, $pageoutput);
00412 }
00413 else
00414 {
00415 $questionoutput = preg_replace("/<div[^>]*?>(.*)<\/div>/is", "\\1", $questionoutput);
00416 }
00417
00418 return $questionoutput;
00419 }
00420
00421 function getTestOutput($active_id, $pass = NULL, $is_postponed = FALSE, $use_post_solutions = FALSE)
00422 {
00423
00424 $pageoutput = $this->outQuestionPage("", $is_postponed, $active_id);
00425
00426
00427 if ($active_id)
00428 {
00429 $solutions = NULL;
00430 include_once "./Modules/Test/classes/class.ilObjTest.php";
00431 if (!ilObjTest::_getUsePreviousAnswers($active_id, true))
00432 {
00433 if (is_null($pass)) $pass = ilObjTest::_getPass($active_id);
00434 }
00435 $solutions =& $this->object->getSolutionValues($active_id, $pass);
00436 }
00437
00438
00439 include_once "./classes/class.ilTemplate.php";
00440 $template = new ilTemplate("tpl.il_as_qpl_numeric_output.html", TRUE, TRUE, "Modules/TestQuestionPool");
00441 if (is_array($solutions))
00442 {
00443 foreach ($solutions as $solution)
00444 {
00445 $template->setVariable("NUMERIC_VALUE", " value=\"".$solution["value1"]."\"");
00446 }
00447 }
00448 $template->setVariable("NUMERIC_SIZE", $this->object->getMaxChars());
00449 $questiontext = $this->object->getQuestion();
00450 $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
00451 $questionoutput = $template->get();
00452 $questionoutput = preg_replace("/(<div( xmlns:xhtml\=\"http:\/\/www.w3.org\/1999\/xhtml\"){0,1} class\=\"ilc_Question\"><\/div>)/ims", $questionoutput, $pageoutput);
00453 return $questionoutput;
00454 }
00455
00456 function addSuggestedSolution()
00457 {
00458 $_SESSION["subquestion_index"] = 0;
00459 if ($_POST["cmd"]["addSuggestedSolution"])
00460 {
00461 if ($this->writePostData())
00462 {
00463 ilUtil::sendInfo($this->getErrorMessage());
00464 $this->editQuestion();
00465 return;
00466 }
00467 if (!$this->checkInput())
00468 {
00469 ilUtil::sendInfo($this->lng->txt("fill_out_all_required_fields_add_answer"));
00470 $this->editQuestion();
00471 return;
00472 }
00473 }
00474 $this->object->saveToDb();
00475 $this->ctrl->setParameter($this, "q_id", $this->object->getId());
00476 $this->tpl->setVariable("HEADER", $this->object->getTitle());
00477 $this->getQuestionTemplate();
00478 parent::addSuggestedSolution();
00479 }
00480
00488 function saveFeedback()
00489 {
00490 include_once "./classes/class.ilObjAdvancedEditing.php";
00491 $this->object->saveFeedbackGeneric(0, ilUtil::stripSlashes($_POST["feedback_incomplete"], false, ilObjAdvancedEditing::_getUsedHTMLTagsAsString("assessment")));
00492 $this->object->saveFeedbackGeneric(1, ilUtil::stripSlashes($_POST["feedback_complete"], false, ilObjAdvancedEditing::_getUsedHTMLTagsAsString("assessment")));
00493 $this->object->cleanupMediaObjectUsage();
00494 parent::saveFeedback();
00495 }
00496
00504 function feedback()
00505 {
00506 $this->tpl->addBlockFile("ADM_CONTENT", "feedback", "tpl.il_as_qpl_numeric_feedback.html", "Modules/TestQuestionPool");
00507 $this->tpl->setVariable("FEEDBACK_TEXT", $this->lng->txt("feedback"));
00508 $this->tpl->setVariable("FEEDBACK_COMPLETE", $this->lng->txt("feedback_complete_solution"));
00509 $this->tpl->setVariable("VALUE_FEEDBACK_COMPLETE", ilUtil::prepareFormOutput($this->object->prepareTextareaOutput($this->object->getFeedbackGeneric(1)), FALSE));
00510 $this->tpl->setVariable("FEEDBACK_INCOMPLETE", $this->lng->txt("feedback_incomplete_solution"));
00511 $this->tpl->setVariable("VALUE_FEEDBACK_INCOMPLETE", ilUtil::prepareFormOutput($this->object->prepareTextareaOutput($this->object->getFeedbackGeneric(0)), FALSE));
00512 $this->tpl->setVariable("SAVE", $this->lng->txt("save"));
00513 $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
00514
00515 include_once "./Services/RTE/classes/class.ilRTE.php";
00516 $rtestring = ilRTE::_getRTEClassname();
00517 include_once "./Services/RTE/classes/class.$rtestring.php";
00518 $rte = new $rtestring();
00519 $rte->addPlugin("latex");
00520 $rte->addButton("latex"); $rte->addButton("pastelatex");
00521 include_once "./classes/class.ilObject.php";
00522 $obj_id = $_GET["q_id"];
00523 $obj_type = ilObject::_lookupType($_GET["ref_id"], TRUE);
00524 $rte->addRTESupport($obj_id, $obj_type, "assessment");
00525 }
00526
00534 function setQuestionTabs()
00535 {
00536 global $rbacsystem, $ilTabs;
00537
00538 $this->ctrl->setParameterByClass("ilpageobjectgui", "q_id", $_GET["q_id"]);
00539 include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
00540 $q_type = $this->object->getQuestionType();
00541
00542 if (strlen($q_type))
00543 {
00544 $classname = $q_type . "GUI";
00545 $this->ctrl->setParameterByClass(strtolower($classname), "sel_question_types", $q_type);
00546 $this->ctrl->setParameterByClass(strtolower($classname), "q_id", $_GET["q_id"]);
00547 }
00548
00549 if ($_GET["q_id"])
00550 {
00551 if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
00552 {
00553
00554 $ilTabs->addTarget("edit_content",
00555 $this->ctrl->getLinkTargetByClass("ilPageObjectGUI", "view"),
00556 array("view", "insert", "exec_pg"),
00557 "", "", $force_active);
00558 }
00559
00560
00561 $ilTabs->addTarget("preview",
00562 $this->ctrl->getLinkTargetByClass("ilPageObjectGUI", "preview"),
00563 array("preview"),
00564 "ilPageObjectGUI", "", $force_active);
00565 }
00566
00567 $force_active = false;
00568 if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
00569 {
00570 $url = "";
00571 if ($classname) $url = $this->ctrl->getLinkTargetByClass($classname, "editQuestion");
00572
00573 $ilTabs->addTarget("edit_properties",
00574 $url,
00575 array("editQuestion", "save", "cancel", "addSuggestedSolution",
00576 "cancelExplorer", "linkChilds", "removeSuggestedSolution",
00577 "saveEdit"),
00578 $classname, "", $force_active);
00579 }
00580
00581 if ($_GET["q_id"])
00582 {
00583 $ilTabs->addTarget("feedback",
00584 $this->ctrl->getLinkTargetByClass($classname, "feedback"),
00585 array("feedback", "saveFeedback"),
00586 $classname, "");
00587 }
00588
00589
00590 if ($_GET["q_id"])
00591 {
00592 $ilTabs->addTarget("statistics",
00593 $this->ctrl->getLinkTargetByClass($classname, "assessment"),
00594 array("assessment"),
00595 $classname, "");
00596 }
00597
00598 if (($_GET["calling_test"] > 0) || ($_GET["test_ref_id"] > 0))
00599 {
00600 $ref_id = $_GET["calling_test"];
00601 if (strlen($ref_id) == 0) $ref_id = $_GET["test_ref_id"];
00602 $ilTabs->setBackTarget($this->lng->txt("backtocallingtest"), "ilias.php?baseClass=ilObjTestGUI&cmd=questions&ref_id=$ref_id");
00603 }
00604 else
00605 {
00606 $ilTabs->setBackTarget($this->lng->txt("qpl"), $this->ctrl->getLinkTargetByClass("ilobjquestionpoolgui", "questions"));
00607 }
00608 }
00609 }
00610 ?>