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 assMultipleChoiceGUI extends assQuestionGUI
00039 {
00048 function assMultipleChoiceGUI(
00049 $id = -1
00050 )
00051 {
00052 $this->assQuestionGUI();
00053 include_once "./assessment/classes/class.assMultipleChoice.php";
00054 $this->object = new assMultipleChoice();
00055 if ($id >= 0)
00056 {
00057 $this->object->loadFromDb($id);
00058 }
00059 }
00060
00061 function getCommand($cmd)
00062 {
00063 if (substr($cmd, 0, 6) == "upload")
00064 {
00065 $cmd = "upload";
00066 }
00067 if (substr($cmd, 0, 11) == "deleteImage")
00068 {
00069 $cmd = "deleteImage";
00070 }
00071 return $cmd;
00072 }
00073
00074
00083 function getQuestionType()
00084 {
00085 return "assMultipleChoice";
00086 }
00087
00095 function editQuestion()
00096 {
00097
00098 $javascript = "<script type=\"text/javascript\">function initialSelect() {\n%s\n}</script>";
00099 $graphical_answer_setting = $this->object->getGraphicalAnswerSetting();
00100 $multiline_answers = $this->object->getMultilineAnswerSetting();
00101 if ($graphical_answer_setting == 0)
00102 {
00103 for ($i = 0; $i < $this->object->getAnswerCount(); $i++)
00104 {
00105 $answer = $this->object->getAnswer($i);
00106 if (strlen($answer->getImage())) $graphical_answer_setting = 1;
00107 }
00108 }
00109 $this->getQuestionTemplate();
00110 $this->tpl->addBlockFile("QUESTION_DATA", "question_data", "tpl.il_as_qpl_mc_mr.html", true);
00111
00112 if ($this->object->getAnswerCount() > 0)
00113 {
00114 $this->tpl->setCurrentBlock("answersheading");
00115 $this->tpl->setVariable("TEXT_POINTS_CHECKED", $this->lng->txt("points_checked"));
00116 $this->tpl->setVariable("TEXT_POINTS_UNCHECKED", $this->lng->txt("points_unchecked"));
00117 $this->tpl->setVariable("TEXT_ANSWER_TEXT", $this->lng->txt("answer_text"));
00118 $this->tpl->parseCurrentBlock();
00119 $this->tpl->setCurrentBlock("selectall");
00120 $this->tpl->setVariable("SELECT_ALL", $this->lng->txt("select_all"));
00121 $this->tpl->parseCurrentBlock();
00122 $this->tpl->setCurrentBlock("existinganswers");
00123 $this->tpl->setVariable("DELETE", $this->lng->txt("delete"));
00124 $this->tpl->setVariable("MOVE", $this->lng->txt("move"));
00125 $this->tpl->setVariable("ARROW", "<img src=\"" . ilUtil::getImagePath("arrow_downright.gif") . "\" alt=\"".$this->lng->txt("arrow_downright")."\">");
00126 $this->tpl->parseCurrentBlock();
00127 }
00128 for ($i = 0; $i < $this->object->getAnswerCount(); $i++)
00129 {
00130 $answer = $this->object->getAnswer($i);
00131 if ($graphical_answer_setting == 1)
00132 {
00133 $imagefilename = $this->object->getImagePath() . $answer->getImage();
00134 if (!@file_exists($imagefilename))
00135 {
00136 $answer->setImage("");
00137 }
00138 if (strlen($answer->getImage()))
00139 {
00140 $imagepath = $this->object->getImagePathWeb() . $answer->getImage();
00141 $this->tpl->setCurrentBlock("graphical_answer_image");
00142 $this->tpl->setVariable("IMAGE_FILE", $imagepath);
00143 if (strlen($answer->getAnswertext()))
00144 {
00145 $this->tpl->setVariable("IMAGE_ALT", ilUtil::prepareFormOutput($answer->getAnswertext()));
00146 }
00147 else
00148 {
00149 $this->tpl->setVariable("IMAGE_ALT", $this->lng->txt("image"));
00150 }
00151 $this->tpl->setVariable("ANSWER_ORDER", $answer->getOrder());
00152 $this->tpl->setVariable("DELETE_IMAGE", $this->lng->txt("delete_image"));
00153 $this->tpl->parseCurrentBlock();
00154 }
00155 $this->tpl->setCurrentBlock("graphical_answer");
00156 $this->tpl->setVariable("ANSWER_ORDER", $answer->getOrder());
00157 $this->tpl->setVariable("UPLOAD_IMAGE", $this->lng->txt("upload_image"));
00158 $this->tpl->setVariable("VALUE_IMAGE", $answer->getImage());
00159 $this->tpl->parseCurrentBlock();
00160 }
00161 if ($multiline_answers)
00162 {
00163 $this->tpl->setCurrentBlock("show_textarea");
00164 $this->tpl->setVariable("ANSWER_ANSWER_ORDER", $answer->getOrder());
00165 $this->tpl->setVariable("VALUE_ANSWER", ilUtil::prepareFormOutput($answer->getAnswertext()));
00166 $this->tpl->parseCurrentBlock();
00167 }
00168 else
00169 {
00170 $this->tpl->setCurrentBlock("show_textinput");
00171 $this->tpl->setVariable("ANSWER_ANSWER_ORDER", $answer->getOrder());
00172 $this->tpl->setVariable("VALUE_ANSWER", ilUtil::prepareFormOutput($answer->getAnswertext()));
00173 $this->tpl->parseCurrentBlock();
00174 }
00175 $this->tpl->setCurrentBlock("answers");
00176 $this->tpl->setVariable("VALUE_MULTIPLE_CHOICE_POINTS_CHECKED", $answer->getPoints());
00177 $this->tpl->setVariable("VALUE_MULTIPLE_CHOICE_POINTS_UNCHECKED", $answer->getPointsUnchecked());
00178 $this->tpl->setVariable("ANSWER_ORDER", $answer->getOrder());
00179 $this->tpl->parseCurrentBlock();
00180 }
00181
00182
00183 $this->outOtherQuestionData();
00184
00185 $internallinks = array(
00186 "lm" => $this->lng->txt("obj_lm"),
00187 "st" => $this->lng->txt("obj_st"),
00188 "pg" => $this->lng->txt("obj_pg"),
00189 "glo" => $this->lng->txt("glossary_term")
00190 );
00191 foreach ($internallinks as $key => $value)
00192 {
00193 $this->tpl->setCurrentBlock("internallink");
00194 $this->tpl->setVariable("TYPE_INTERNAL_LINK", $key);
00195 $this->tpl->setVariable("TEXT_INTERNAL_LINK", $value);
00196 $this->tpl->parseCurrentBlock();
00197 }
00198
00199 $this->tpl->setCurrentBlock("HeadContent");
00200
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 switch ($this->ctrl->getCmd())
00208 {
00209 case "add":
00210 $nrOfAnswers = $_POST["nrOfAnswers"];
00211 if ((strcmp($nrOfAnswers, "yn") == 0) || (strcmp($nrOfAnswers, "tf") == 0)) $nrOfAnswers = 2;
00212 $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\");"));
00213 break;
00214 case "deleteAnswer":
00215 if ($this->object->getAnswerCount() == 0)
00216 {
00217 $this->tpl->setVariable("CONTENT_BLOCK", sprintf($javascript, "document.frm_multiple_choice.title.focus();"));
00218 }
00219 else
00220 {
00221 $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\");"));
00222 }
00223 break;
00224 default:
00225 $this->tpl->setVariable("CONTENT_BLOCK", sprintf($javascript, "document.frm_multiple_choice.title.focus();"));
00226 break;
00227 }
00228 }
00229 $this->tpl->parseCurrentBlock();
00230
00231 for ($i = 1; $i < 10; $i++)
00232 {
00233 $this->tpl->setCurrentBlock("numbers");
00234 $this->tpl->setVariable("VALUE_NUMBER", $i);
00235 if ($i == 1)
00236 {
00237 $this->tpl->setVariable("TEXT_NUMBER", $i . " " . $this->lng->txt("answer"));
00238 }
00239 else
00240 {
00241 $this->tpl->setVariable("TEXT_NUMBER", $i . " " . $this->lng->txt("answers"));
00242 }
00243 $this->tpl->parseCurrentBlock();
00244 }
00245
00246 $this->tpl->setCurrentBlock("question_data");
00247 $this->tpl->setVariable("TEXT_TITLE", $this->lng->txt("title"));
00248 $this->tpl->setVariable("TEXT_AUTHOR", $this->lng->txt("author"));
00249 $this->tpl->setVariable("TEXT_COMMENT", $this->lng->txt("description"));
00250 $this->tpl->setVariable("TEXT_QUESTION", $this->lng->txt("question"));
00251 $this->tpl->setVariable("MULTIPLE_CHOICE_ID", $this->object->getId());
00252 $this->tpl->setVariable("VALUE_MULTIPLE_CHOICE_TITLE", ilUtil::prepareFormOutput($this->object->getTitle()));
00253 $this->tpl->setVariable("VALUE_MULTIPLE_CHOICE_COMMENT", ilUtil::prepareFormOutput($this->object->getComment()));
00254 $this->tpl->setVariable("VALUE_MULTIPLE_CHOICE_AUTHOR", ilUtil::prepareFormOutput($this->object->getAuthor()));
00255 $this->tpl->setVariable("TEXT_GRAPHICAL_ANSWERS", $this->lng->txt("graphical_answers"));
00256 $this->tpl->setVariable("TEXT_HIDE_GRAPHICAL_ANSWER_SUPPORT", $this->lng->txt("graphical_answers_hide"));
00257 $this->tpl->setVariable("TEXT_SHOW_GRAPHICAL_ANSWER_SUPPORT", $this->lng->txt("graphical_answers_show"));
00258 if ($this->object->getGraphicalAnswerSetting() == 1)
00259 {
00260 $this->tpl->setVariable("SELECTED_SHOW_GRAPHICAL_ANSWER_SUPPORT", " selected=\"selected\"");
00261 }
00262 if ($multiline_answers)
00263 {
00264 $this->tpl->setVariable("SELECTED_SHOW_MULTILINE_ANSWERS", " selected=\"selected\"");
00265 }
00266 $this->tpl->setVariable("TEXT_HIDE_MULTILINE_ANSWERS", $this->lng->txt("multiline_answers_hide"));
00267 $this->tpl->setVariable("TEXT_SHOW_MULTILINE_ANSWERS", $this->lng->txt("multiline_answers_show"));
00268 $this->tpl->setVariable("SET_EDIT_MODE", $this->lng->txt("set_edit_mode"));
00269 $questiontext = $this->object->getQuestion();
00270 $this->tpl->setVariable("VALUE_QUESTION", ilUtil::prepareFormOutput($this->object->prepareTextareaOutput($questiontext)));
00271 $this->tpl->setVariable("VALUE_ADD_ANSWER", $this->lng->txt("add"));
00272 $this->tpl->setVariable("TEXT_SHUFFLE_ANSWERS", $this->lng->txt("shuffle_answers"));
00273 $this->tpl->setVariable("TXT_YES", $this->lng->txt("yes"));
00274 $this->tpl->setVariable("TXT_NO", $this->lng->txt("no"));
00275 if ($this->object->getShuffle())
00276 {
00277 $this->tpl->setVariable("SELECTED_YES", " selected=\"selected\"");
00278 }
00279 else
00280 {
00281 $this->tpl->setVariable("SELECTED_NO", " selected=\"selected\"");
00282 }
00283 $this->tpl->setVariable("TEXT_SOLUTION_HINT", $this->lng->txt("solution_hint"));
00284 if (count($this->object->suggested_solutions))
00285 {
00286 $solution_array = $this->object->getSuggestedSolution(0);
00287 include_once "./assessment/classes/class.assQuestion.php";
00288 $href = assQuestion::_getInternalLinkHref($solution_array["internal_link"]);
00289 $this->tpl->setVariable("TEXT_VALUE_SOLUTION_HINT", " <a href=\"$href\" target=\"content\">" . $this->lng->txt("solution_hint"). "</a> ");
00290 $this->tpl->setVariable("BUTTON_REMOVE_SOLUTION", $this->lng->txt("remove"));
00291 $this->tpl->setVariable("BUTTON_ADD_SOLUTION", $this->lng->txt("change"));
00292 $this->tpl->setVariable("VALUE_SOLUTION_HINT", $solution_array["internal_link"]);
00293 }
00294 else
00295 {
00296 $this->tpl->setVariable("BUTTON_ADD_SOLUTION", $this->lng->txt("add"));
00297 }
00298 $this->tpl->setVariable("SAVE",$this->lng->txt("save"));
00299 $this->tpl->setVariable("SAVE_EDIT", $this->lng->txt("save_edit"));
00300 $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
00301 $this->tpl->setVariable("CANCEL", $this->lng->txt("cancel"));
00302 $this->ctrl->setParameter($this, "sel_question_types", "assMultipleChoice");
00303 $this->tpl->setVariable("ACTION_MULTIPLE_CHOICE_TEST", $this->ctrl->getFormAction($this));
00304 $this->tpl->setVariable("TEXT_QUESTION_TYPE", $this->lng->txt("assMultipleChoice"));
00305 $this->tpl->parseCurrentBlock();
00306
00307 include_once "./Services/RTE/classes/class.ilRTE.php";
00308 $rtestring = ilRTE::_getRTEClassname();
00309 include_once "./Services/RTE/classes/class.$rtestring.php";
00310 $rte = new $rtestring();
00311 $rte->addPlugin("latex");
00312 $rte->addButton("latex");
00313 include_once "./classes/class.ilObject.php";
00314 $obj_id = $_GET["q_id"];
00315 $obj_type = ilObject::_lookupType($_GET["ref_id"], TRUE);
00316 $rte->addRTESupport($obj_id, $obj_type, "assessment");
00317 $this->tpl->setCurrentBlock("adm_content");
00318 $this->tpl->setVariable("BODY_ATTRIBUTES", " onload=\"initialSelect();\"");
00319 $this->tpl->parseCurrentBlock();
00320 }
00321
00325 function add()
00326 {
00327
00328 $this->writePostData();
00329
00330 if (!$this->checkInput())
00331 {
00332 sendInfo($this->lng->txt("fill_out_all_required_fields_add_answer"));
00333 }
00334 else
00335 {
00336
00337 $nrOfAnswers = $_POST["nrOfAnswers"];
00338 switch ($nrOfAnswers)
00339 {
00340 case "tf":
00341
00342 $this->object->addAnswer(
00343 $this->lng->txt("true"),
00344 0,
00345 0,
00346 count($this->object->answers),
00347 ""
00348 );
00349 $this->object->addAnswer(
00350 $this->lng->txt("false"),
00351 0,
00352 0,
00353 count($this->object->answers),
00354 ""
00355 );
00356 break;
00357 case "yn":
00358
00359 $this->object->addAnswer(
00360 $this->lng->txt("yes"),
00361 0,
00362 0,
00363 count($this->object->answers),
00364 ""
00365 );
00366 $this->object->addAnswer(
00367 $this->lng->txt("no"),
00368 0,
00369 0,
00370 count($this->object->answers),
00371 ""
00372 );
00373 break;
00374 default:
00375 for ($i = 0; $i < $nrOfAnswers; $i++)
00376 {
00377 $this->object->addAnswer(
00378 $this->lng->txt(""),
00379 0,
00380 0,
00381 count($this->object->answers),
00382 ""
00383 );
00384 }
00385 break;
00386 }
00387 }
00388
00389 $this->editQuestion();
00390 }
00391
00395 function deleteAnswer()
00396 {
00397 $this->writePostData();
00398 $answers = $_POST["chb_answers"];
00399 if (is_array($answers))
00400 {
00401 arsort($answers);
00402 foreach ($answers as $answer)
00403 {
00404 $this->object->deleteAnswer($answer);
00405 }
00406 }
00407 $this->editQuestion();
00408 }
00409
00413 function checkInput()
00414 {
00415 $cmd = $this->ctrl->getCmd();
00416
00417 if ((!$_POST["title"]) or (!$_POST["author"]) or (!$_POST["question"]))
00418 {
00419
00420 return false;
00421 }
00422 foreach ($_POST as $key => $value)
00423 {
00424 if (preg_match("/answer_(\d+)/", $key, $matches))
00425 {
00426 if (strlen($value) == 0)
00427 {
00428 if (strlen($_POST["uploaded_image_".$matches[1]]) == 0)
00429 {
00430 return false;
00431 }
00432 }
00433 }
00434 }
00435
00436 return true;
00437 }
00438
00447 function writePostData()
00448 {
00449
00450
00451 $result = 0;
00452 if ((!$_POST["title"]) or (!$_POST["author"]) or (!$_POST["question"]))
00453 {
00454 $result = 1;
00455 }
00456
00457 if (($result) and (($_POST["cmd"]["add"]) or ($_POST["cmd"]["add_tf"]) or ($_POST["cmd"]["add_yn"])))
00458 {
00459
00460 sendInfo($this->lng->txt("fill_out_all_required_fields_add_answer"));
00461 $_POST["cmd"]["add"] = "";
00462 $_POST["cmd"]["add_yn"] = "";
00463 $_POST["cmd"]["add_tf"] = "";
00464 }
00465
00466
00467 if ($_POST["cmd"]["add"] or $_POST["cmd"]["add_yn"] or $_POST["cmd"]["add_tf"])
00468 {
00469 foreach ($_POST as $key => $value)
00470 {
00471 if (preg_match("/answer_(\d+)/", $key, $matches))
00472 {
00473 if (!$value)
00474 {
00475 $_POST["cmd"]["add"] = "";
00476 $_POST["cmd"]["add_yn"] = "";
00477 $_POST["cmd"]["add_tf"] = "";
00478 sendInfo($this->lng->txt("fill_out_all_answer_fields"));
00479 }
00480 }
00481 }
00482 }
00483
00484 $this->object->setTitle(ilUtil::stripSlashes($_POST["title"]));
00485 $this->object->setAuthor(ilUtil::stripSlashes($_POST["author"]));
00486 $this->object->setComment(ilUtil::stripSlashes($_POST["comment"]));
00487 include_once "./classes/class.ilObjAdvancedEditing.php";
00488 $questiontext = ilUtil::stripSlashes($_POST["question"], false, ilObjAdvancedEditing::_getUsedHTMLTagsAsString("assessment"));
00489 $this->object->setQuestion($questiontext);
00490 $this->object->setSuggestedSolution($_POST["solution_hint"], 0);
00491 $this->object->setShuffle($_POST["shuffle"]);
00492
00493 $saved = $this->writeOtherPostData($result);
00494 $this->object->setMultilineAnswerSetting($_POST["multilineAnswers"]);
00495 $this->object->setGraphicalAnswerSetting($_POST["graphicalAnswerSupport"]);
00496
00497
00498 $this->object->flushAnswers();
00499 $graphical_answer_setting = $this->object->getGraphicalAnswerSetting();
00500
00501 foreach ($_POST as $key => $value)
00502 {
00503 if (preg_match("/answer_(\d+)/", $key, $matches))
00504 {
00505 $answer_image = $_POST["uploaded_image_".$matches[1]];
00506 if ($graphical_answer_setting == 1)
00507 {
00508 foreach ($_FILES as $key2 => $value2)
00509 {
00510 if (preg_match("/image_(\d+)/", $key2, $matches2))
00511 {
00512 if ($matches[1] == $matches2[1])
00513 {
00514 if ($value2["tmp_name"])
00515 {
00516
00517 if ($this->object->getId() <= 0)
00518 {
00519 $this->object->saveToDb();
00520 $saved = true;
00521 $this->error .= $this->lng->txt("question_saved_for_upload") . "<br />";
00522 }
00523 $value2['name'] = $this->object->createNewImageFileName($value2['name']);
00524 $upload_result = $this->object->setImageFile($value2['name'], $value2['tmp_name']);
00525 switch ($upload_result)
00526 {
00527 case 0:
00528 $_POST["image_".$matches2[1]] = $value2['name'];
00529 $answer_image = $value2['name'];
00530 break;
00531 case 1:
00532 $this->error .= $this->lng->txt("error_image_upload_wrong_format") . "<br />";
00533 break;
00534 case 2:
00535 $this->error .= $this->lng->txt("error_image_upload_copy_file") . "<br />";
00536 break;
00537 }
00538 }
00539 }
00540 }
00541 }
00542 }
00543 $points = $_POST["points_checked_$matches[1]"];
00544 $points_unchecked = $_POST["points_unchecked_$matches[1]"];
00545 $answertext = ilUtil::stripSlashes($_POST["$key"], false, ilObjAdvancedEditing::_getUsedHTMLTagsAsString("assessment"));
00546 $this->object->addAnswer(
00547 $answertext,
00548 ilUtil::stripSlashes($points),
00549 ilUtil::stripSlashes($points_unchecked),
00550 ilUtil::stripSlashes($matches[1]),
00551 $answer_image
00552 );
00553 }
00554 }
00555
00556 if ($this->object->getMaximumPoints() < 0)
00557 {
00558 $result = 1;
00559 $this->setErrorMessage($this->lng->txt("enter_enough_positive_points"));
00560 }
00561
00562
00563 if ($_POST["multiple_choice_id"] > 0)
00564 {
00565 $this->object->setId($_POST["multiple_choice_id"]);
00566 }
00567
00568 if ($saved)
00569 {
00570
00571
00572
00573
00574 $this->object->saveToDb();
00575 $_GET["q_id"] = $this->object->getId();
00576 }
00577
00578 return $result;
00579 }
00580
00581 function outQuestionForTest($formaction, $active_id, $pass = NULL, $is_postponed = FALSE, $use_post_solutions = FALSE)
00582 {
00583 $test_output = $this->getTestOutput($active_id, $pass, $is_postponed, $use_post_solutions);
00584 $this->tpl->setVariable("QUESTION_OUTPUT", $test_output);
00585 $this->tpl->setVariable("FORMACTION", $formaction);
00586 }
00587
00588 function getSolutionOutput($active_id, $pass = NULL, $graphicalOutput = FALSE, $result_output = FALSE, $show_question_only = TRUE)
00589 {
00590
00591 $keys = array_keys($this->object->answers);
00592
00593
00594 $user_solution = array();
00595 if ($active_id)
00596 {
00597 $solutions =& $this->object->getSolutionValues($active_id, $pass);
00598 foreach ($solutions as $idx => $solution_value)
00599 {
00600 array_push($user_solution, $solution_value["value1"]);
00601 }
00602 }
00603 else
00604 {
00605
00606 foreach ($this->object->answers as $index => $answer)
00607 {
00608 $points_checked = $answer->getPointsChecked();
00609 $points_unchecked = $answer->getPointsUnchecked();
00610 if ($points_checked > $points_unchecked)
00611 {
00612 if ($points_checked > 0)
00613 {
00614 array_push($user_solution, $index);
00615 }
00616 }
00617 }
00618 }
00619
00620
00621 include_once "./classes/class.ilTemplate.php";
00622 $template = new ilTemplate("tpl.il_as_qpl_mc_mr_output_solution.html", TRUE, TRUE, TRUE);
00623 $solutiontemplate = new ilTemplate("tpl.il_as_tst_solution_output.html", TRUE, TRUE, TRUE);
00624 foreach ($keys as $answer_id)
00625 {
00626 $answer = $this->object->answers[$answer_id];
00627 if ($graphicalOutput)
00628 {
00629
00630 $ok = FALSE;
00631 $checked = FALSE;
00632 foreach ($user_solution as $mc_solution)
00633 {
00634 if (strcmp($mc_solution, $answer_id) == 0)
00635 {
00636 $checked = TRUE;
00637 }
00638 }
00639 if ($checked)
00640 {
00641 if ($answer->getPointsChecked() > $answer->getPointsUnchecked())
00642 {
00643 $ok = TRUE;
00644 }
00645 else
00646 {
00647 $ok = FALSE;
00648 }
00649 }
00650 else
00651 {
00652 if ($answer->getPointsChecked() > $answer->getPointsUnchecked())
00653 {
00654 $ok = FALSE;
00655 }
00656 else
00657 {
00658 $ok = TRUE;
00659 }
00660 }
00661 if ($ok)
00662 {
00663 $template->setCurrentBlock("icon_ok");
00664 $template->setVariable("ICON_OK", ilUtil::getImagePath("icon_ok.gif"));
00665 $template->setVariable("TEXT_OK", $this->lng->txt("answer_is_right"));
00666 $template->parseCurrentBlock();
00667 }
00668 else
00669 {
00670 $template->setCurrentBlock("icon_ok");
00671 $template->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_not_ok.gif"));
00672 $template->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_wrong"));
00673 $template->parseCurrentBlock();
00674 }
00675 }
00676 if (strlen($answer->getImage()))
00677 {
00678 $template->setCurrentBlock("answer_image");
00679 $template->setVariable("ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $answer->getImage());
00680 $alt = $answer->getImage();
00681 if (strlen($answer->getAnswertext()))
00682 {
00683 $alt = $answer->getAnswertext();
00684 }
00685 $alt = preg_replace("/<[^>]*?>/", "", $alt);
00686 $template->setVariable("ANSWER_IMAGE_ALT", ilUtil::prepareFormOutput($alt));
00687 $template->setVariable("ANSWER_IMAGE_TITLE", ilUtil::prepareFormOutput($alt));
00688 $template->parseCurrentBlock();
00689 }
00690 $template->setCurrentBlock("answer_row");
00691 $template->setVariable("ANSWER_TEXT", $this->object->prepareTextareaOutput($answer->getAnswertext(), TRUE));
00692 $checked = FALSE;
00693 foreach ($user_solution as $mc_solution)
00694 {
00695 if (strcmp($mc_solution, $answer_id) == 0)
00696 {
00697 $template->setVariable("SOLUTION_IMAGE", ilUtil::getImagePath("checkbox_checked.gif"));
00698 $template->setVariable("SOLUTION_ALT", $this->lng->txt("checked"));
00699 $checked = TRUE;
00700 }
00701 }
00702 if ($result_output)
00703 {
00704 $pointschecked = $this->object->answers[$answer_id]->getPointsChecked();
00705 $pointsunchecked = $this->object->answers[$answer_id]->getPointsUnchecked();
00706 $resulttextchecked = ($pointschecked == 1) || ($pointschecked == -1) ? "%s " . $this->lng->txt("point") : "%s " . $this->lng->txt("points");
00707 $resulttextunchecked = ($pointsunchecked == 1) || ($pointsunchecked == -1) ? "%s " . $this->lng->txt("point") : "%s " . $this->lng->txt("points");
00708 $template->setVariable("RESULT_OUTPUT", sprintf("(" . $this->lng->txt("checkbox_checked") . " = $resulttextchecked, " . $this->lng->txt("checkbox_unchecked") . " = $resulttextunchecked)", $pointschecked, $pointsunchecked));
00709 }
00710 if (!$checked)
00711 {
00712 $template->setVariable("SOLUTION_IMAGE", ilUtil::getImagePath("checkbox_unchecked.gif"));
00713 $template->setVariable("SOLUTION_ALT", $this->lng->txt("unchecked"));
00714 }
00715 $template->parseCurrentBlock();
00716 }
00717 $questiontext = $this->object->getQuestion();
00718 $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
00719 $questionoutput = $template->get();
00720 $solutiontemplate->setVariable("SOLUTION_OUTPUT", $questionoutput);
00721
00722 $solutionoutput = $solutiontemplate->get();
00723 if (!$show_question_only)
00724 {
00725
00726 $pageoutput = $this->getILIASPage();
00727 $solutionoutput = preg_replace("/(<div( xmlns:xhtml\=\"http:\/\/www.w3.org\/1999\/xhtml\"){0,1} class\=\"ilc_Question\"><\/div>)/ims", $solutionoutput, $pageoutput);
00728 }
00729 return $solutionoutput;
00730 }
00731
00732 function getPreview()
00733 {
00734
00735 $keys = array_keys($this->object->answers);
00736 if ($this->object->getShuffle())
00737 {
00738 $keys = $this->object->pcArrayShuffle($keys);
00739 }
00740
00741
00742 include_once "./classes/class.ilTemplate.php";
00743 $template = new ilTemplate("tpl.il_as_qpl_mc_mr_output.html", TRUE, TRUE, TRUE);
00744 foreach ($keys as $answer_id)
00745 {
00746 $answer = $this->object->answers[$answer_id];
00747 if (strlen($answer->getImage()))
00748 {
00749 $template->setCurrentBlock("answer_image");
00750 $template->setVariable("ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $answer->getImage());
00751 $alt = $answer->getImage();
00752 if (strlen($answer->getAnswertext()))
00753 {
00754 $alt = $answer->getAnswertext();
00755 }
00756 $alt = preg_replace("/<[^>]*?>/", "", $alt);
00757 $template->setVariable("ANSWER_IMAGE_ALT", ilUtil::prepareFormOutput($alt));
00758 $template->setVariable("ANSWER_IMAGE_TITLE", ilUtil::prepareFormOutput($alt));
00759 $template->parseCurrentBlock();
00760 }
00761 $template->setCurrentBlock("answer_row");
00762 $template->setVariable("ANSWER_ID", $answer_id);
00763 $template->setVariable("ANSWER_TEXT", $this->object->prepareTextareaOutput($answer->getAnswertext(), TRUE));
00764 $template->parseCurrentBlock();
00765 }
00766 $questiontext = $this->object->getQuestion();
00767 $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
00768 $questionoutput = $template->get();
00769 $questionoutput = preg_replace("/<div[^>]*?>(.*)<\/div>/is", "\\1", $questionoutput);
00770 return $questionoutput;
00771 }
00772
00773 function getTestOutput($active_id, $pass = NULL, $is_postponed = FALSE, $use_post_solutions = FALSE)
00774 {
00775
00776 $keys = array_keys($this->object->answers);
00777 if ($this->object->getShuffle())
00778 {
00779 $keys = $this->object->pcArrayShuffle($keys);
00780 }
00781
00782
00783 $pageoutput = $this->outQuestionPage("", $is_postponed, $active_id);
00784
00785
00786 $user_solution = array();
00787 if ($active_id)
00788 {
00789 $solutions = NULL;
00790 include_once "./assessment/classes/class.ilObjTest.php";
00791 if (ilObjTest::_getHidePreviousResults($active_id, true))
00792 {
00793 if (is_null($pass)) $pass = ilObjTest::_getPass($active_id);
00794 }
00795 $solutions =& $this->object->getSolutionValues($active_id, $pass);
00796 foreach ($solutions as $idx => $solution_value)
00797 {
00798 array_push($user_solution, $solution_value["value1"]);
00799 }
00800 }
00801
00802
00803 include_once "./classes/class.ilTemplate.php";
00804 $template = new ilTemplate("tpl.il_as_qpl_mc_mr_output.html", TRUE, TRUE, TRUE);
00805 foreach ($keys as $answer_id)
00806 {
00807 $answer = $this->object->answers[$answer_id];
00808 if (strlen($answer->getImage()))
00809 {
00810 $template->setCurrentBlock("answer_image");
00811 $template->setVariable("ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $answer->getImage());
00812 $alt = $answer->getImage();
00813 if (strlen($answer->getAnswertext()))
00814 {
00815 $alt = $answer->getAnswertext();
00816 }
00817 $alt = preg_replace("/<[^>]*?>/", "", $alt);
00818 $template->setVariable("ANSWER_IMAGE_ALT", ilUtil::prepareFormOutput($alt));
00819 $template->setVariable("ANSWER_IMAGE_TITLE", ilUtil::prepareFormOutput($alt));
00820 $template->parseCurrentBlock();
00821 }
00822 $template->setCurrentBlock("answer_row");
00823 $template->setVariable("ANSWER_ID", $answer_id);
00824 $template->setVariable("ANSWER_TEXT", $this->object->prepareTextareaOutput($answer->getAnswertext(), TRUE));
00825 foreach ($user_solution as $mc_solution)
00826 {
00827 if (strcmp($mc_solution, $answer_id) == 0)
00828 {
00829 $template->setVariable("CHECKED_ANSWER", " checked=\"checked\"");
00830 }
00831 }
00832 $template->parseCurrentBlock();
00833 }
00834 $questiontext = $this->object->getQuestion();
00835 $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
00836 $questionoutput = $template->get();
00837 $questionoutput = preg_replace("/(<div( xmlns:xhtml\=\"http:\/\/www.w3.org\/1999\/xhtml\"){0,1} class\=\"ilc_Question\"><\/div>)/ims", $questionoutput, $pageoutput);
00838 return $questionoutput;
00839 }
00840
00841 function addSuggestedSolution()
00842 {
00843 $_SESSION["subquestion_index"] = 0;
00844 if ($_POST["cmd"]["addSuggestedSolution"])
00845 {
00846 if ($this->writePostData())
00847 {
00848 sendInfo($this->getErrorMessage());
00849 $this->editQuestion();
00850 return;
00851 }
00852 if (!$this->checkInput())
00853 {
00854 sendInfo($this->lng->txt("fill_out_all_required_fields_add_answer"));
00855 $this->editQuestion();
00856 return;
00857 }
00858 }
00859 $this->object->saveToDb();
00860 $_GET["q_id"] = $this->object->getId();
00861 $this->tpl->setVariable("HEADER", $this->object->getTitle());
00862 $this->getQuestionTemplate();
00863 parent::addSuggestedSolution();
00864 }
00865
00869 function upload()
00870 {
00871 $this->writePostData();
00872 $this->editQuestion();
00873 }
00874
00875 function deleteImage()
00876 {
00877 if ($this->writePostData())
00878 {
00879 sendInfo($this->getErrorMessage());
00880 $this->editQuestion();
00881 return;
00882 }
00883 $imageorder = "";
00884 foreach ($_POST["cmd"] as $key => $value)
00885 {
00886 if (preg_match("/deleteImage_(\d+)/", $key, $matches))
00887 {
00888 $imageorder = $matches[1];
00889 }
00890 }
00891 for ($i = 0; $i < $this->object->getAnswerCount(); $i++)
00892 {
00893 $answer = $this->object->getAnswer($i);
00894 if ($answer->getOrder() == $imageorder)
00895 {
00896 $this->object->deleteImage($answer->getImage());
00897 $this->object->answers[$i]->setImage("");
00898 }
00899 }
00900 $this->editQuestion();
00901 }
00902
00903 function editMode()
00904 {
00905 global $ilUser;
00906
00907 $this->object->setMultilineAnswerSetting($_POST["multilineAnswers"]);
00908 $this->object->setGraphicalAnswerSetting($_POST["graphicalAnswerSupport"]);
00909 $this->writePostData();
00910 $this->editQuestion();
00911 }
00912
00913 }
00914 ?>