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
00037 class assSingleChoiceGUI extends assQuestionGUI
00038 {
00039 var $choiceKeys;
00040
00049 function assSingleChoiceGUI(
00050 $id = -1
00051 )
00052 {
00053 $this->assQuestionGUI();
00054 include_once "./Modules/TestQuestionPool/classes/class.assSingleChoice.php";
00055 $this->object = new assSingleChoice();
00056 if ($id >= 0)
00057 {
00058 $this->object->loadFromDb($id);
00059 }
00060 }
00061
00062 function getCommand($cmd)
00063 {
00064 if (substr($cmd, 0, 6) == "upload")
00065 {
00066 $cmd = "upload";
00067 }
00068 if (substr($cmd, 0, 11) == "deleteImage")
00069 {
00070 $cmd = "deleteImage";
00071 }
00072 return $cmd;
00073 }
00074
00082 function editQuestion()
00083 {
00084 $this->tpl->addJavascript("./Services/JavaScript/js/Basic.js");
00085 $javascript = "<script type=\"text/javascript\">ilAddOnLoad(initialSelect);\n".
00086 "function initialSelect() {\n%s\n}</script>";
00087 $graphical_answer_setting = $this->object->getGraphicalAnswerSetting();
00088 $multiline_answers = $this->object->getMultilineAnswerSetting();
00089 if ($graphical_answer_setting == 0)
00090 {
00091 for ($i = 0; $i < $this->object->getAnswerCount(); $i++)
00092 {
00093 $answer = $this->object->getAnswer($i);
00094 if (strlen($answer->getImage())) $graphical_answer_setting = 1;
00095 }
00096 }
00097 $this->object->setGraphicalAnswerSetting($graphical_answer_setting);
00098 $this->getQuestionTemplate();
00099 $this->tpl->addBlockFile("QUESTION_DATA", "question_data", "tpl.il_as_qpl_mc_sr.html", "Modules/TestQuestionPool");
00100
00101 if ($this->object->getAnswerCount() > 0)
00102 {
00103 $this->tpl->setCurrentBlock("answersheading");
00104 $this->tpl->setVariable("TEXT_POINTS", $this->lng->txt("points"));
00105 $this->tpl->setVariable("TEXT_ANSWER_TEXT", $this->lng->txt("answer_text"));
00106 $this->tpl->parseCurrentBlock();
00107 $this->tpl->setCurrentBlock("selectall");
00108 $this->tpl->setVariable("SELECT_ALL", $this->lng->txt("select_all"));
00109 $this->tpl->parseCurrentBlock();
00110 $this->tpl->setCurrentBlock("existinganswers");
00111 $this->tpl->setVariable("DELETE", $this->lng->txt("delete"));
00112 $this->tpl->setVariable("MOVE", $this->lng->txt("move"));
00113 $this->tpl->setVariable("ARROW", "<img src=\"" . ilUtil::getImagePath("arrow_downright.gif") . "\" alt=\"".$this->lng->txt("arrow_downright")."\">");
00114 $this->tpl->parseCurrentBlock();
00115 }
00116 for ($i = 0; $i < $this->object->getAnswerCount(); $i++)
00117 {
00118 $answer = $this->object->getAnswer($i);
00119 if ($graphical_answer_setting == 1)
00120 {
00121 $imagefilename = $this->object->getImagePath() . $answer->getImage();
00122 if (!@file_exists($imagefilename))
00123 {
00124 $answer->setImage("");
00125 }
00126 if (strlen($answer->getImage()))
00127 {
00128 $imagepath = $this->object->getImagePathWeb() . $answer->getImage();
00129 $this->tpl->setCurrentBlock("graphical_answer_image");
00130 $this->tpl->setVariable("IMAGE_FILE", $imagepath);
00131 if (strlen($answer->getAnswertext()))
00132 {
00133 $this->tpl->setVariable("IMAGE_ALT", ilUtil::prepareFormOutput($answer->getAnswertext()));
00134 }
00135 else
00136 {
00137 $this->tpl->setVariable("IMAGE_ALT", $this->lng->txt("image"));
00138 }
00139 $this->tpl->setVariable("ANSWER_ORDER", $answer->getOrder());
00140 $this->tpl->setVariable("DELETE_IMAGE", $this->lng->txt("delete_image"));
00141 $this->tpl->parseCurrentBlock();
00142 }
00143 $this->tpl->setCurrentBlock("graphical_answer");
00144 $this->tpl->setVariable("ANSWER_ORDER", $answer->getOrder());
00145 $this->tpl->setVariable("UPLOAD_IMAGE", $this->lng->txt("upload_image"));
00146 $this->tpl->setVariable("VALUE_IMAGE", $answer->getImage());
00147 $this->tpl->parseCurrentBlock();
00148 }
00149 if ($multiline_answers)
00150 {
00151 $this->tpl->setCurrentBlock("show_textarea");
00152 $this->tpl->setVariable("ANSWER_ANSWER_ORDER", $answer->getOrder());
00153 $this->tpl->setVariable("VALUE_ANSWER", ilUtil::prepareFormOutput($answer->getAnswertext()));
00154 $this->tpl->parseCurrentBlock();
00155 }
00156 else
00157 {
00158 $this->tpl->setCurrentBlock("show_textinput");
00159 $this->tpl->setVariable("ANSWER_ANSWER_ORDER", $answer->getOrder());
00160 $this->tpl->setVariable("VALUE_ANSWER", ilUtil::prepareFormOutput($answer->getAnswertext()));
00161 $this->tpl->parseCurrentBlock();
00162 }
00163 $this->tpl->setCurrentBlock("answers");
00164 $this->tpl->setVariable("ANSWER_ORDER", $answer->getOrder());
00165 $this->tpl->setVariable("VALUE_MULTIPLE_CHOICE_POINTS", $answer->getPoints());
00166 $this->tpl->setVariable("VALUE_TRUE", $this->lng->txt("true"));
00167 $this->tpl->parseCurrentBlock();
00168 }
00169
00170 $this->outOtherQuestionData();
00171
00172 $internallinks = array(
00173 "lm" => $this->lng->txt("obj_lm"),
00174 "st" => $this->lng->txt("obj_st"),
00175 "pg" => $this->lng->txt("obj_pg"),
00176 "glo" => $this->lng->txt("glossary_term")
00177 );
00178 foreach ($internallinks as $key => $value)
00179 {
00180 $this->tpl->setCurrentBlock("internallink");
00181 $this->tpl->setVariable("TYPE_INTERNAL_LINK", $key);
00182 $this->tpl->setVariable("TEXT_INTERNAL_LINK", $value);
00183 $this->tpl->parseCurrentBlock();
00184 }
00185
00186 $this->tpl->setCurrentBlock("HeadContent");
00187 if ($this->object->getAnswerCount() == 0)
00188 {
00189 $this->tpl->setVariable("CONTENT_BLOCK", sprintf($javascript, "document.frm_multiple_choice.title.focus();"));
00190 }
00191 else
00192 {
00193 switch ($this->ctrl->getCmd())
00194 {
00195 case "add":
00196 $nrOfAnswers = $_POST["nrOfAnswers"];
00197 if ((strcmp($nrOfAnswers, "yn") == 0) || (strcmp($nrOfAnswers, "tf") == 0)) $nrOfAnswers = 2;
00198 $this->tpl->setVariable("CONTENT_BLOCK", sprintf($javascript, "document.frm_multiple_choice.answer_".($this->object->getAnswerCount() - $nrOfAnswers).".focus(); document.getElementById('answer_".($this->object->getAnswerCount() - $nrOfAnswers)."').scrollIntoView(\"true\");"));
00199 break;
00200 case "deleteAnswer":
00201 if ($this->object->getAnswerCount() == 0)
00202 {
00203 $this->tpl->setVariable("CONTENT_BLOCK", sprintf($javascript, "document.frm_multiple_choice.title.focus();"));
00204 }
00205 else
00206 {
00207 $this->tpl->setVariable("CONTENT_BLOCK", sprintf($javascript, "document.frm_multiple_choice.answer_".($this->object->getAnswerCount() - 1).".focus(); document.getElementById('answer_".($this->object->getAnswerCount() - 1)."').scrollIntoView(\"true\");"));
00208 }
00209 break;
00210 default:
00211 $this->tpl->setVariable("CONTENT_BLOCK", sprintf($javascript, "document.frm_multiple_choice.title.focus();"));
00212 break;
00213 }
00214 }
00215 $this->tpl->parseCurrentBlock();
00216
00217 for ($i = 1; $i < 10; $i++)
00218 {
00219 $this->tpl->setCurrentBlock("numbers");
00220 $this->tpl->setVariable("VALUE_NUMBER", $i);
00221 if ($i == 1)
00222 {
00223 $this->tpl->setVariable("TEXT_NUMBER", $i . " " . $this->lng->txt("answer"));
00224 }
00225 else
00226 {
00227 $this->tpl->setVariable("TEXT_NUMBER", $i . " " . $this->lng->txt("answers"));
00228 }
00229 $this->tpl->parseCurrentBlock();
00230 }
00231
00232 $this->tpl->setCurrentBlock("numbers");
00233 $this->tpl->setVariable("VALUE_NUMBER", "yn");
00234 $this->tpl->setVariable("TEXT_NUMBER", $this->lng->txt("add_answer_yn"));
00235 $this->tpl->parseCurrentBlock();
00236
00237 $this->tpl->setCurrentBlock("numbers");
00238 $this->tpl->setVariable("VALUE_NUMBER", "tf");
00239 $this->tpl->setVariable("TEXT_NUMBER", $this->lng->txt("add_answer_tf"));
00240 $this->tpl->parseCurrentBlock();
00241
00242 $this->tpl->setCurrentBlock("question_data");
00243 $this->tpl->setVariable("MULTIPLE_CHOICE_ID", $this->object->getId());
00244 $this->tpl->setVariable("VALUE_MULTIPLE_CHOICE_TITLE", ilUtil::prepareFormOutput($this->object->getTitle()));
00245 $this->tpl->setVariable("VALUE_MULTIPLE_CHOICE_COMMENT", ilUtil::prepareFormOutput($this->object->getComment()));
00246 $this->tpl->setVariable("VALUE_MULTIPLE_CHOICE_AUTHOR", ilUtil::prepareFormOutput($this->object->getAuthor()));
00247 $questiontext = $this->object->getQuestion();
00248 $this->tpl->setVariable("VALUE_QUESTION", ilUtil::prepareFormOutput($this->object->prepareTextareaOutput($questiontext)));
00249 $this->tpl->setVariable("VALUE_ADD_ANSWER", $this->lng->txt("add"));
00250 $this->tpl->setVariable("TEXT_GRAPHICAL_ANSWERS", $this->lng->txt("graphical_answers"));
00251 $this->tpl->setVariable("TEXT_HIDE_GRAPHICAL_ANSWER_SUPPORT", $this->lng->txt("graphical_answers_hide"));
00252 $this->tpl->setVariable("TEXT_SHOW_GRAPHICAL_ANSWER_SUPPORT", $this->lng->txt("graphical_answers_show"));
00253 if ($this->object->getGraphicalAnswerSetting() == 1)
00254 {
00255 $this->tpl->setVariable("SELECTED_SHOW_GRAPHICAL_ANSWER_SUPPORT", " selected=\"selected\"");
00256 }
00257 if ($multiline_answers)
00258 {
00259 $this->tpl->setVariable("SELECTED_SHOW_MULTILINE_ANSWERS", " selected=\"selected\"");
00260 }
00261 $this->tpl->setVariable("TEXT_HIDE_MULTILINE_ANSWERS", $this->lng->txt("multiline_answers_hide"));
00262 $this->tpl->setVariable("TEXT_SHOW_MULTILINE_ANSWERS", $this->lng->txt("multiline_answers_show"));
00263 $this->tpl->setVariable("SET_EDIT_MODE", $this->lng->txt("set_edit_mode"));
00264 $this->tpl->setVariable("TEXT_TITLE", $this->lng->txt("title"));
00265 $this->tpl->setVariable("TEXT_AUTHOR", $this->lng->txt("author"));
00266 $this->tpl->setVariable("TEXT_COMMENT", $this->lng->txt("description"));
00267 $this->tpl->setVariable("TEXT_QUESTION", $this->lng->txt("question"));
00268 $this->tpl->setVariable("TEXT_SHUFFLE_ANSWERS", $this->lng->txt("shuffle_answers"));
00269 $this->tpl->setVariable("TXT_YES", $this->lng->txt("yes"));
00270 $this->tpl->setVariable("TXT_NO", $this->lng->txt("no"));
00271 if ($this->object->getShuffle())
00272 {
00273 $this->tpl->setVariable("SELECTED_YES", " selected=\"selected\"");
00274 }
00275 else
00276 {
00277 $this->tpl->setVariable("SELECTED_NO", " selected=\"selected\"");
00278 }
00279 $this->tpl->setVariable("TEXT_SOLUTION_HINT", $this->lng->txt("solution_hint"));
00280 if (count($this->object->suggested_solutions))
00281 {
00282 $solution_array = $this->object->getSuggestedSolution(0);
00283 include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
00284 $href = assQuestion::_getInternalLinkHref($solution_array["internal_link"]);
00285 $this->tpl->setVariable("TEXT_VALUE_SOLUTION_HINT", " <a href=\"$href\" target=\"content\">" . $this->lng->txt("solution_hint"). "</a> ");
00286 $this->tpl->setVariable("BUTTON_REMOVE_SOLUTION", $this->lng->txt("remove"));
00287 $this->tpl->setVariable("BUTTON_ADD_SOLUTION", $this->lng->txt("change"));
00288 $this->tpl->setVariable("VALUE_SOLUTION_HINT", $solution_array["internal_link"]);
00289 }
00290 else
00291 {
00292 $this->tpl->setVariable("BUTTON_ADD_SOLUTION", $this->lng->txt("add"));
00293 }
00294 $this->tpl->setVariable("SAVE",$this->lng->txt("save"));
00295 $this->tpl->setVariable("SAVE_EDIT", $this->lng->txt("save_edit"));
00296 $this->tpl->setVariable("CANCEL",$this->lng->txt("cancel"));
00297 $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
00298 $this->ctrl->setParameter($this, "sel_question_types", "assSingleChoice");
00299 $this->tpl->setVariable("ACTION_MULTIPLE_CHOICE_TEST", $this->ctrl->getFormAction($this));
00300 $this->tpl->setVariable("TEXT_QUESTION_TYPE", $this->lng->txt("assSingleChoice"));
00301
00302 $this->tpl->parseCurrentBlock();
00303 include_once "./Services/RTE/classes/class.ilRTE.php";
00304 $rtestring = ilRTE::_getRTEClassname();
00305 include_once "./Services/RTE/classes/class.$rtestring.php";
00306 $rte = new $rtestring();
00307 $rte->addPlugin("latex");
00308 $rte->addButton("latex");
00309 $rte->addButton("pastelatex");
00310 include_once "./classes/class.ilObject.php";
00311 $obj_id = $_GET["q_id"];
00312 $obj_type = ilObject::_lookupType($_GET["ref_id"], TRUE);
00313 $rte->addRTESupport($obj_id, $obj_type, "assessment");
00314
00315 $this->tpl->setCurrentBlock("adm_content");
00316
00317 $this->tpl->parseCurrentBlock();
00318 }
00319
00323 function add()
00324 {
00325
00326 $this->writePostData();
00327
00328 if (!$this->checkInput())
00329 {
00330 ilUtil::sendInfo($this->lng->txt("fill_out_all_required_fields_add_answer"));
00331 }
00332 else
00333 {
00334
00335 $nrOfAnswers = $_POST["nrOfAnswers"];
00336 switch ($nrOfAnswers)
00337 {
00338 case "tf":
00339
00340 $this->object->addAnswer(
00341 $this->lng->txt("true"),
00342 0,
00343 0,
00344 count($this->object->answers),
00345 ""
00346 );
00347 $this->object->addAnswer(
00348 $this->lng->txt("false"),
00349 0,
00350 0,
00351 count($this->object->answers),
00352 ""
00353 );
00354 break;
00355 case "yn":
00356
00357 $this->object->addAnswer(
00358 $this->lng->txt("yes"),
00359 0,
00360 0,
00361 count($this->object->answers),
00362 ""
00363 );
00364 $this->object->addAnswer(
00365 $this->lng->txt("no"),
00366 0,
00367 0,
00368 count($this->object->answers),
00369 ""
00370 );
00371 break;
00372 default:
00373 for ($i = 0; $i < $nrOfAnswers; $i++)
00374 {
00375 $this->object->addAnswer(
00376 $this->lng->txt(""),
00377 0,
00378 0,
00379 count($this->object->answers),
00380 ""
00381 );
00382 }
00383 break;
00384 }
00385 }
00386
00387 $this->editQuestion();
00388 }
00389
00393 function deleteAnswer()
00394 {
00395 $this->writePostData();
00396 $answers = $_POST["chb_answers"];
00397 if (is_array($answers))
00398 {
00399 arsort($answers);
00400 foreach ($answers as $answer)
00401 {
00402 $this->object->deleteAnswer($answer);
00403 }
00404 }
00405 $this->editQuestion();
00406 }
00407
00411 function checkInput()
00412 {
00413 $cmd = $this->ctrl->getCmd();
00414
00415 if ((!$_POST["title"]) or (!$_POST["author"]) or (!$_POST["question"]))
00416 {
00417
00418 return false;
00419 }
00420 foreach ($_POST as $key => $value)
00421 {
00422 if (preg_match("/answer_(\d+)/", $key, $matches))
00423 {
00424 if (strlen($value) == 0)
00425 {
00426 if (strlen($_POST["uploaded_image_".$matches[1]]) == 0)
00427 {
00428 return false;
00429 }
00430 }
00431 }
00432 }
00433
00434 return true;
00435 }
00436
00445 function writePostData()
00446 {
00447 $result = 0;
00448 if ((!$_POST["title"]) or (!$_POST["author"]) or (!$_POST["question"]))
00449 {
00450 $result = 1;
00451 }
00452
00453 if (($result) and (($_POST["cmd"]["add"]) or ($_POST["cmd"]["add_tf"]) or ($_POST["cmd"]["add_yn"])))
00454 {
00455
00456 ilUtil::sendInfo($this->lng->txt("fill_out_all_required_fields_add_answer"));
00457 $_POST["cmd"]["add"] = "";
00458 $_POST["cmd"]["add_yn"] = "";
00459 $_POST["cmd"]["add_tf"] = "";
00460 }
00461
00462
00463 if ($_POST["cmd"]["add"] or $_POST["cmd"]["add_yn"] or $_POST["cmd"]["add_tf"])
00464 {
00465 foreach ($_POST as $key => $value)
00466 {
00467 if (preg_match("/answer_(\d+)/", $key, $matches))
00468 {
00469 if (!$value)
00470 {
00471 $_POST["cmd"]["add"] = "";
00472 $_POST["cmd"]["add_yn"] = "";
00473 $_POST["cmd"]["add_tf"] = "";
00474 ilUtil::sendInfo($this->lng->txt("fill_out_all_answer_fields"));
00475 }
00476 }
00477 }
00478 }
00479
00480 $this->object->setTitle(ilUtil::stripSlashes($_POST["title"]));
00481 $this->object->setAuthor(ilUtil::stripSlashes($_POST["author"]));
00482 $this->object->setComment(ilUtil::stripSlashes($_POST["comment"]));
00483 include_once "./classes/class.ilObjAdvancedEditing.php";
00484 $questiontext = ilUtil::stripSlashes($_POST["question"], false, ilObjAdvancedEditing::_getUsedHTMLTagsAsString("assessment"));
00485 $this->object->setQuestion($questiontext);
00486 $this->object->setSuggestedSolution($_POST["solution_hint"], 0);
00487 $this->object->setShuffle($_POST["shuffle"]);
00488 $this->object->setMultilineAnswerSetting($_POST["multilineAnswers"]);
00489 $this->object->setGraphicalAnswerSetting($_POST["graphicalAnswerSupport"]);
00490
00491 $saved = $this->writeOtherPostData($result);
00492
00493
00494 $this->object->flushAnswers();
00495 $graphical_answer_setting = $this->object->getGraphicalAnswerSetting();
00496
00497 foreach ($_POST as $key => $value)
00498 {
00499 if (preg_match("/answer_(\d+)/", $key, $matches))
00500 {
00501 $answer_image = $_POST["uploaded_image_".$matches[1]];
00502 if ($graphical_answer_setting == 1)
00503 {
00504 foreach ($_FILES as $key2 => $value2)
00505 {
00506 if (preg_match("/image_(\d+)/", $key2, $matches2))
00507 {
00508 if ($matches[1] == $matches2[1])
00509 {
00510 if ($value2["tmp_name"])
00511 {
00512
00513 if ($this->object->getId() <= 0)
00514 {
00515 $this->object->saveToDb();
00516 $saved = true;
00517 ilUtil::sendInfo($this->lng->txt("question_saved_for_upload"));
00518 }
00519 $value2['name'] = $this->object->createNewImageFileName($value2['name']);
00520 $upload_result = $this->object->setImageFile($value2['name'], $value2['tmp_name']);
00521 switch ($upload_result)
00522 {
00523 case 0:
00524 $_POST["image_".$matches2[1]] = $value2['name'];
00525 $answer_image = $value2['name'];
00526 break;
00527 case 1:
00528 $this->setErrorMessage($this->getErrorMessage() . $this->lng->txt("error_image_upload_wrong_format") . "<br />");
00529 break;
00530 case 2:
00531 $this->setErrorMessage($this->getErrorMessage() . $this->lng->txt("error_image_upload_copy_file") . "<br />");
00532 break;
00533 }
00534 }
00535 }
00536 }
00537 }
00538 }
00539 $points = $_POST["points_$matches[1]"];
00540 $answertext = ilUtil::stripSlashes($_POST["$key"], false, ilObjAdvancedEditing::_getUsedHTMLTagsAsString("assessment"));
00541 $this->object->addAnswer(
00542 $answertext,
00543 ilUtil::stripSlashes($points),
00544 0,
00545 ilUtil::stripSlashes($matches[1]),
00546 $answer_image
00547 );
00548 }
00549 }
00550 if ($this->object->getMaximumPoints() < 0)
00551 {
00552 $result = 1;
00553 $this->setErrorMessage($this->lng->txt("enter_enough_positive_points"));
00554 }
00555
00556
00557 if ($_POST["multiple_choice_id"] > 0)
00558 {
00559 $this->object->setId($_POST["multiple_choice_id"]);
00560 }
00561
00562 if ($saved)
00563 {
00564
00565
00566
00567
00568 $this->object->saveToDb();
00569 $this->ctrl->setParameter($this, "q_id", $this->object->getId());
00570 }
00571
00572 return $result;
00573 }
00574
00575 function outQuestionForTest($formaction, $active_id, $pass = NULL, $is_postponed = FALSE, $use_post_solutions = FALSE, $show_feedback = FALSE)
00576 {
00577 $test_output = $this->getTestOutput($active_id, $pass, $is_postponed, $use_post_solutions, $show_feedback);
00578 $this->tpl->setVariable("QUESTION_OUTPUT", $test_output);
00579 $this->tpl->setVariable("FORMACTION", $formaction);
00580 }
00581
00582 function getSolutionOutput($active_id, $pass = NULL, $graphicalOutput = FALSE, $result_output = FALSE, $show_question_only = TRUE, $show_feedback = FALSE)
00583 {
00584 $keys = $this->getChoiceKeys();
00585
00586
00587 $user_solution = "";
00588 if ($active_id)
00589 {
00590 $solutions =& $this->object->getSolutionValues($active_id, $pass);
00591 foreach ($solutions as $idx => $solution_value)
00592 {
00593 $user_solution = $solution_value["value1"];
00594 }
00595 }
00596 else
00597 {
00598 $found_index = -1;
00599 $max_points = 0;
00600 foreach ($this->object->answers as $index => $answer)
00601 {
00602 if ($answer->getPoints() > $max_points)
00603 {
00604 $max_points = $answer->getPoints();
00605 $found_index = $index;
00606 }
00607 }
00608 $user_solution = $found_index;
00609 }
00610
00611 include_once "./classes/class.ilTemplate.php";
00612 $template = new ilTemplate("tpl.il_as_qpl_mc_sr_output_solution.html", TRUE, TRUE, "Modules/TestQuestionPool");
00613 $solutiontemplate = new ilTemplate("tpl.il_as_tst_solution_output.html",TRUE, TRUE, "Modules/TestQuestionPool");
00614 foreach ($keys as $answer_id)
00615 {
00616 $answer = $this->object->answers[$answer_id];
00617 if ($active_id)
00618 {
00619 if ($graphicalOutput)
00620 {
00621
00622 $ok = FALSE;
00623 if (strcmp($user_solution, $answer_id) == 0)
00624 {
00625 if ($answer->getPoints() == $this->object->getMaximumPoints())
00626 {
00627 $ok = TRUE;
00628 }
00629 else
00630 {
00631 $ok = FALSE;
00632 }
00633 if ($ok)
00634 {
00635 $template->setCurrentBlock("icon_ok");
00636 $template->setVariable("ICON_OK", ilUtil::getImagePath("icon_ok.gif"));
00637 $template->setVariable("TEXT_OK", $this->lng->txt("answer_is_right"));
00638 $template->parseCurrentBlock();
00639 }
00640 else
00641 {
00642 $template->setCurrentBlock("icon_not_ok");
00643 if ($answer->getPoints() > 0)
00644 {
00645 $template->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_mostly_ok.gif"));
00646 $template->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_not_correct_but_positive"));
00647 }
00648 else
00649 {
00650 $template->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_not_ok.gif"));
00651 $template->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_wrong"));
00652 }
00653 $template->parseCurrentBlock();
00654 }
00655 }
00656 if (strlen($user_solution) == 0)
00657 {
00658 $template->setCurrentBlock("icon_not_ok");
00659 $template->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_not_ok.gif"));
00660 $template->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_wrong"));
00661 $template->parseCurrentBlock();
00662 }
00663 }
00664 }
00665 if (strlen($answer->getImage()))
00666 {
00667 $template->setCurrentBlock("answer_image");
00668 $template->setVariable("ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $answer->getImage());
00669 $alt = $answer->getImage();
00670 if (strlen($answer->getAnswertext()))
00671 {
00672 $alt = $answer->getAnswertext();
00673 }
00674 $alt = preg_replace("/<[^>]*?>/", "", $alt);
00675 $template->setVariable("ANSWER_IMAGE_ALT", ilUtil::prepareFormOutput($alt));
00676 $template->setVariable("ANSWER_IMAGE_TITLE", ilUtil::prepareFormOutput($alt));
00677 $template->parseCurrentBlock();
00678 }
00679 if ($show_feedback)
00680 {
00681 if (strcmp($user_solution, $answer_id) == 0)
00682 {
00683 $fb = $this->object->getFeedbackSingleAnswer($answer_id);
00684 if (strlen($fb))
00685 {
00686 $template->setCurrentBlock("feedback");
00687 $template->setVariable("FEEDBACK", $fb);
00688 $template->parseCurrentBlock();
00689 }
00690 }
00691 }
00692 $template->setCurrentBlock("answer_row");
00693 $template->setVariable("ANSWER_TEXT", $this->object->prepareTextareaOutput($answer->getAnswertext(), TRUE));
00694 if (strcmp($user_solution, $answer_id) == 0)
00695 {
00696 $template->setVariable("SOLUTION_IMAGE", ilUtil::getHtmlPath(ilUtil::getImagePath("radiobutton_checked.gif")));
00697 $template->setVariable("SOLUTION_ALT", $this->lng->txt("checked"));
00698 }
00699 else
00700 {
00701 $template->setVariable("SOLUTION_IMAGE", ilUtil::getHtmlPath(ilUtil::getImagePath("radiobutton_unchecked.gif")));
00702 $template->setVariable("SOLUTION_ALT", $this->lng->txt("unchecked"));
00703 }
00704 if ($result_output)
00705 {
00706 $points = $this->object->answers[$answer_id]->getPoints();
00707 $resulttext = ($points == 1) ? "(%s " . $this->lng->txt("point") . ")" : "(%s " . $this->lng->txt("points") . ")";
00708 $template->setVariable("RESULT_OUTPUT", sprintf($resulttext, $points));
00709 }
00710 $template->parseCurrentBlock();
00711 }
00712 $questiontext = $this->object->getQuestion();
00713 $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
00714 $questionoutput = $template->get();
00715 $feedback = ($show_feedback) ? $this->getAnswerFeedbackOutput($active_id, $pass) : "";
00716 if (strlen($feedback)) $solutiontemplate->setVariable("FEEDBACK", $feedback);
00717 $solutiontemplate->setVariable("SOLUTION_OUTPUT", $questionoutput);
00718
00719 $solutionoutput = $solutiontemplate->get();
00720 if (!$show_question_only)
00721 {
00722
00723 $pageoutput = $this->getILIASPage();
00724 $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>";
00725 }
00726 return $solutionoutput;
00727 }
00728
00729 function getPreview($show_question_only = FALSE)
00730 {
00731 $keys = $this->getChoiceKeys();
00732
00733
00734 include_once "./classes/class.ilTemplate.php";
00735 $template = new ilTemplate("tpl.il_as_qpl_mc_sr_output.html", TRUE, TRUE, "Modules/TestQuestionPool");
00736 foreach ($keys as $answer_id)
00737 {
00738 $answer = $this->object->answers[$answer_id];
00739 if (strlen($answer->getImage()))
00740 {
00741 $template->setCurrentBlock("answer_image");
00742 $template->setVariable("ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $answer->getImage());
00743 $alt = $answer->getImage();
00744 if (strlen($answer->getAnswertext()))
00745 {
00746 $alt = $answer->getAnswertext();
00747 }
00748 $alt = preg_replace("/<[^>]*?>/", "", $alt);
00749 $template->setVariable("ANSWER_IMAGE_ALT", ilUtil::prepareFormOutput($alt));
00750 $template->setVariable("ANSWER_IMAGE_TITLE", ilUtil::prepareFormOutput($alt));
00751 $template->parseCurrentBlock();
00752 }
00753 $template->setCurrentBlock("answer_row");
00754 $template->setVariable("ANSWER_ID", $answer_id);
00755 $template->setVariable("ANSWER_TEXT", $this->object->prepareTextareaOutput($answer->getAnswertext(), TRUE));
00756 $template->parseCurrentBlock();
00757 }
00758 $questiontext = $this->object->getQuestion();
00759 $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
00760 $questionoutput = $template->get();
00761 if (!$show_question_only)
00762 {
00763
00764 $pageoutput = $this->getILIASPage();
00765 $questionoutput = preg_replace("/(<div( xmlns:xhtml\=\"http:\/\/www.w3.org\/1999\/xhtml\"){0,1} class\=\"ilc_Question\"><\/div>)/ims", $questionoutput, $pageoutput);
00766 }
00767 else
00768 {
00769 $questionoutput = preg_replace("/<div[^>]*?>(.*)<\/div>/is", "\\1", $questionoutput);
00770 }
00771
00772 return $questionoutput;
00773 }
00774
00775 function getTestOutput($active_id, $pass = NULL, $is_postponed = FALSE, $use_post_solutions = FALSE, $show_feedback = FALSE)
00776 {
00777
00778 $pageoutput = $this->outQuestionPage("", $is_postponed, $active_id);
00779
00780 $keys = $this->getChoiceKeys();
00781
00782
00783 $user_solution = "";
00784 if ($active_id)
00785 {
00786 $solutions = NULL;
00787 include_once "./Modules/Test/classes/class.ilObjTest.php";
00788 if (!ilObjTest::_getUsePreviousAnswers($active_id, true))
00789 {
00790 if (is_null($pass)) $pass = ilObjTest::_getPass($active_id);
00791 }
00792 $solutions =& $this->object->getSolutionValues($active_id, $pass);
00793 foreach ($solutions as $idx => $solution_value)
00794 {
00795 $user_solution = $solution_value["value1"];
00796 }
00797 }
00798
00799
00800 include_once "./classes/class.ilTemplate.php";
00801 $template = new ilTemplate("tpl.il_as_qpl_mc_sr_output.html", TRUE, TRUE, "Modules/TestQuestionPool");
00802 foreach ($keys as $answer_id)
00803 {
00804 $answer = $this->object->answers[$answer_id];
00805 if (strlen($answer->getImage()))
00806 {
00807 $template->setCurrentBlock("answer_image");
00808 $template->setVariable("ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $answer->getImage());
00809 $alt = $answer->getImage();
00810 if (strlen($answer->getAnswertext()))
00811 {
00812 $alt = $answer->getAnswertext();
00813 }
00814 $alt = preg_replace("/<[^>]*?>/", "", $alt);
00815 $template->setVariable("ANSWER_IMAGE_ALT", ilUtil::prepareFormOutput($alt));
00816 $template->setVariable("ANSWER_IMAGE_TITLE", ilUtil::prepareFormOutput($alt));
00817 $template->parseCurrentBlock();
00818 }
00819 if ($show_feedback)
00820 {
00821 if (strcmp($user_solution, $answer_id) == 0)
00822 {
00823 $feedback = $this->object->getFeedbackSingleAnswer($answer_id);
00824 if (strlen($feedback))
00825 {
00826 $template->setCurrentBlock("feedback");
00827 $template->setVariable("FEEDBACK", $this->object->prepareTextareaOutput($feedback, TRUE));
00828 $template->parseCurrentBlock();
00829 }
00830 }
00831 }
00832 $template->setCurrentBlock("answer_row");
00833 $template->setVariable("ANSWER_ID", $answer_id);
00834 $template->setVariable("ANSWER_TEXT", $this->object->prepareTextareaOutput($answer->getAnswertext(), TRUE));
00835 if (strcmp($user_solution, $answer_id) == 0)
00836 {
00837 $template->setVariable("CHECKED_ANSWER", " checked=\"checked\"");
00838 }
00839 $template->parseCurrentBlock();
00840 }
00841 $questiontext = $this->object->getQuestion();
00842 $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
00843 $questionoutput = $template->get();
00844 $questionoutput = preg_replace("/(<div( xmlns:xhtml\=\"http:\/\/www.w3.org\/1999\/xhtml\"){0,1} class\=\"ilc_Question\"><\/div>)/ims", $questionoutput, $pageoutput);
00845 return $questionoutput;
00846 }
00847
00848 function addSuggestedSolution()
00849 {
00850 $_SESSION["subquestion_index"] = 0;
00851 if ($_POST["cmd"]["addSuggestedSolution"])
00852 {
00853 if ($this->writePostData())
00854 {
00855 ilUtil::sendInfo($this->getErrorMessage());
00856 $this->editQuestion();
00857 return;
00858 }
00859 if (!$this->checkInput())
00860 {
00861 ilUtil::sendInfo($this->lng->txt("fill_out_all_required_fields_add_answer"));
00862 $this->editQuestion();
00863 return;
00864 }
00865 }
00866 $this->object->saveToDb();
00867 $this->ctrl->setParameter($this, "q_id", $this->object->getId());
00868 $this->tpl->setVariable("HEADER", $this->object->getTitle());
00869 $this->getQuestionTemplate();
00870 parent::addSuggestedSolution();
00871 }
00872
00876 function upload()
00877 {
00878 $this->writePostData();
00879 $this->editQuestion();
00880 }
00881
00882 function deleteImage()
00883 {
00884 if ($this->writePostData())
00885 {
00886 ilUtil::sendInfo($this->getErrorMessage());
00887 $this->editQuestion();
00888 return;
00889 }
00890 $imageorder = "";
00891 foreach ($_POST["cmd"] as $key => $value)
00892 {
00893 if (preg_match("/deleteImage_(\d+)/", $key, $matches))
00894 {
00895 $imageorder = $matches[1];
00896 }
00897 }
00898 for ($i = 0; $i < $this->object->getAnswerCount(); $i++)
00899 {
00900 $answer = $this->object->getAnswer($i);
00901 if ($answer->getOrder() == $imageorder)
00902 {
00903 $this->object->deleteImage($answer->getImage());
00904 $this->object->answers[$i]->setImage("");
00905 }
00906 }
00907 $this->editQuestion();
00908 }
00909
00910 function editMode()
00911 {
00912 global $ilUser;
00913
00914 $this->object->setMultilineAnswerSetting($_POST["multilineAnswers"]);
00915 $this->object->setGraphicalAnswerSetting($_POST["graphicalAnswerSupport"]);
00916 $this->writePostData();
00917 $this->editQuestion();
00918 }
00919
00927 function saveFeedback()
00928 {
00929 include_once "./classes/class.ilObjAdvancedEditing.php";
00930 $this->object->saveFeedbackGeneric(0, ilUtil::stripSlashes($_POST["feedback_incomplete"], false, ilObjAdvancedEditing::_getUsedHTMLTagsAsString("assessment")));
00931 $this->object->saveFeedbackGeneric(1, ilUtil::stripSlashes($_POST["feedback_complete"], false, ilObjAdvancedEditing::_getUsedHTMLTagsAsString("assessment")));
00932 foreach ($this->object->answers as $index => $answer)
00933 {
00934 $this->object->saveFeedbackSingleAnswer($index, ilUtil::stripSlashes($_POST["feedback_answer_$index"], false, ilObjAdvancedEditing::_getUsedHTMLTagsAsString("assessment")));
00935 }
00936 $this->object->cleanupMediaObjectUsage();
00937 parent::saveFeedback();
00938 }
00939
00947 function feedback()
00948 {
00949 $this->tpl->addBlockFile("ADM_CONTENT", "feedback", "tpl.il_as_qpl_mc_sr_feedback.html", "Modules/TestQuestionPool");
00950 foreach ($this->object->answers as $index => $answer)
00951 {
00952 $this->tpl->setCurrentBlock("feedback_answer");
00953 $this->tpl->setVariable("FEEDBACK_TEXT_ANSWER", $this->lng->txt("feedback"));
00954 $this->tpl->setVariable("ANSWER_TEXT", $this->object->prepareTextareaOutput($answer->getAnswertext(), TRUE));
00955 $this->tpl->setVariable("ANSWER_ID", $index);
00956 $this->tpl->setVariable("VALUE_FEEDBACK_ANSWER", ilUtil::prepareFormOutput($this->object->prepareTextareaOutput($this->object->getFeedbackSingleAnswer($index)), FALSE));
00957 $this->tpl->parseCurrentBlock();
00958 }
00959 $this->tpl->setVariable("FEEDBACK_TEXT", $this->lng->txt("feedback"));
00960 $this->tpl->setVariable("FEEDBACK_COMPLETE", $this->lng->txt("feedback_complete_solution"));
00961 $this->tpl->setVariable("VALUE_FEEDBACK_COMPLETE", ilUtil::prepareFormOutput($this->object->prepareTextareaOutput($this->object->getFeedbackGeneric(1)), FALSE));
00962 $this->tpl->setVariable("FEEDBACK_INCOMPLETE", $this->lng->txt("feedback_incomplete_solution"));
00963 $this->tpl->setVariable("VALUE_FEEDBACK_INCOMPLETE", ilUtil::prepareFormOutput($this->object->prepareTextareaOutput($this->object->getFeedbackGeneric(0)), FALSE));
00964 $this->tpl->setVariable("FEEDBACK_ANSWERS", $this->lng->txt("feedback_answers"));
00965 $this->tpl->setVariable("SAVE", $this->lng->txt("save"));
00966 $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
00967
00968 include_once "./Services/RTE/classes/class.ilRTE.php";
00969 $rtestring = ilRTE::_getRTEClassname();
00970 include_once "./Services/RTE/classes/class.$rtestring.php";
00971 $rte = new $rtestring();
00972 $rte->addPlugin("latex");
00973 $rte->addButton("latex"); $rte->addButton("pastelatex");
00974 include_once "./classes/class.ilObject.php";
00975 $obj_id = $_GET["q_id"];
00976 $obj_type = ilObject::_lookupType($_GET["ref_id"], TRUE);
00977 $rte->addRTESupport($obj_id, $obj_type, "assessment");
00978 }
00979
00987 function setQuestionTabs()
00988 {
00989 global $rbacsystem, $ilTabs;
00990
00991 $this->ctrl->setParameterByClass("ilpageobjectgui", "q_id", $_GET["q_id"]);
00992 include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
00993 $q_type = $this->object->getQuestionType();
00994
00995 if (strlen($q_type))
00996 {
00997 $classname = $q_type . "GUI";
00998 $this->ctrl->setParameterByClass(strtolower($classname), "sel_question_types", $q_type);
00999 $this->ctrl->setParameterByClass(strtolower($classname), "q_id", $_GET["q_id"]);
01000 }
01001
01002 if ($_GET["q_id"])
01003 {
01004 if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
01005 {
01006
01007 $ilTabs->addTarget("edit_content",
01008 $this->ctrl->getLinkTargetByClass("ilPageObjectGUI", "view"),
01009 array("view", "insert", "exec_pg"),
01010 "", "", $force_active);
01011 }
01012
01013
01014 $ilTabs->addTarget("preview",
01015 $this->ctrl->getLinkTargetByClass("ilPageObjectGUI", "preview"),
01016 array("preview"),
01017 "ilPageObjectGUI", "", $force_active);
01018 }
01019
01020 $force_active = false;
01021 if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
01022 {
01023 $url = "";
01024 if ($classname) $url = $this->ctrl->getLinkTargetByClass($classname, "editQuestion");
01025 $commands = $_POST["cmd"];
01026 if (is_array($commands))
01027 {
01028 foreach ($commands as $key => $value)
01029 {
01030 if (preg_match("/^deleteImage_.*/", $key, $matches) ||
01031 preg_match("/^upload_.*/", $key, $matches)
01032 )
01033 {
01034 $force_active = true;
01035 }
01036 }
01037 }
01038
01039 $ilTabs->addTarget("edit_properties",
01040 $url,
01041 array("editQuestion", "save", "cancel", "addSuggestedSolution",
01042 "cancelExplorer", "linkChilds", "removeSuggestedSolution",
01043 "toggleGraphicalAnswers", "setMediaMode", "uploadingImage", "add", "editMode", "deleteAnswer", "addYesNo", "addTrueFalse",
01044 "saveEdit"),
01045 $classname, "", $force_active);
01046 }
01047
01048 if ($_GET["q_id"])
01049 {
01050 $ilTabs->addTarget("feedback",
01051 $this->ctrl->getLinkTargetByClass($classname, "feedback"),
01052 array("feedback", "saveFeedback"),
01053 $classname, "");
01054 }
01055
01056
01057 if ($_GET["q_id"])
01058 {
01059 $ilTabs->addTarget("statistics",
01060 $this->ctrl->getLinkTargetByClass($classname, "assessment"),
01061 array("assessment"),
01062 $classname, "");
01063 }
01064
01065 if (($_GET["calling_test"] > 0) || ($_GET["test_ref_id"] > 0))
01066 {
01067 $ref_id = $_GET["calling_test"];
01068 if (strlen($ref_id) == 0) $ref_id = $_GET["test_ref_id"];
01069 $ilTabs->setBackTarget($this->lng->txt("backtocallingtest"), "ilias.php?baseClass=ilObjTestGUI&cmd=questions&ref_id=$ref_id");
01070 }
01071 else
01072 {
01073 $ilTabs->setBackTarget($this->lng->txt("qpl"), $this->ctrl->getLinkTargetByClass("ilobjquestionpoolgui", "questions"));
01074 }
01075 }
01076
01077
01078
01079
01080
01081
01082 function getChoiceKeys()
01083 {
01084 if (strcmp($_GET["activecommand"], "directfeedback") == 0)
01085 {
01086 if (is_array($_SESSION["choicekeys"])) $this->choiceKeys = $_SESSION["choicekeys"];
01087 }
01088 if (!is_array($this->choiceKeys))
01089 {
01090 $this->choiceKeys = array_keys($this->object->answers);
01091 if ($this->object->getShuffle())
01092 {
01093 $this->choiceKeys = $this->object->pcArrayShuffle($this->choiceKeys);
01094 }
01095 }
01096 $_SESSION["choicekeys"] = $this->choiceKeys;
01097 return $this->choiceKeys;
01098 }
01099 }
01100 ?>