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 assMatchingQuestionGUI extends assQuestionGUI
00039 {
00048 function assMatchingQuestionGUI(
00049 $id = -1
00050 )
00051 {
00052 $this->assQuestionGUI();
00053 include_once "./assessment/classes/class.assMatchingQuestion.php";
00054 $this->object = new assMatchingQuestion();
00055 if ($id >= 0)
00056 {
00057 $this->object->loadFromDb($id);
00058 }
00059 }
00060
00069 function getQuestionType()
00070 {
00071 return "assMatchingQuestion";
00072 }
00073
00074 function getCommand($cmd)
00075 {
00076 if (substr($cmd, 0, 6) == "delete")
00077 {
00078 $cmd = "delete";
00079 }
00080 if (substr($cmd, 0, 6) == "upload")
00081 {
00082 $cmd = "upload";
00083 }
00084
00085 return $cmd;
00086 }
00087
00095 function editQuestion($has_error = 0, $delete = false)
00096 {
00097 $multiline_answers = $this->object->getMultilineAnswerSetting();
00098 $this->getQuestionTemplate();
00099 $this->tpl->addBlockFile("QUESTION_DATA", "question_data", "tpl.il_as_qpl_matching.html", true);
00100
00101 $tblrow = array("tblrow1top", "tblrow2top");
00102
00103 for ($i = 0; $i < $this->object->get_matchingpair_count(); $i++)
00104 {
00105 $thispair = $this->object->get_matchingpair($i);
00106 if ($this->object->get_matching_type() == MT_TERMS_PICTURES)
00107 {
00108 $this->tpl->setCurrentBlock("pictures");
00109 $this->tpl->setVariable("ANSWER_ORDER", $i);
00110 $this->tpl->setVariable("PICTURE_ID", $thispair->getPictureId());
00111 $this->tpl->setVariable("COLOR_CLASS", $tblrow[$i % 2]);
00112 $filename = $thispair->getPicture();
00113 if ($filename)
00114 {
00115 $imagepath = $this->object->getImagePathWeb() . $thispair->getPicture();
00116 $this->tpl->setVariable("UPLOADED_IMAGE", "<img src=\"$imagepath.thumb.jpg\" alt=\"" . $this->lng->txt("qpl_display_fullsize_image") . "\" title=\"" . $this->lng->txt("qpl_display_fullsize_image") . "\" border=\"\" />");
00117 $this->tpl->setVariable("IMAGE_FILENAME", $thispair->getPicture());
00118 $this->tpl->setVariable("VALUE_PICTURE", $thispair->getPicture());
00119 }
00120 $this->tpl->setVariable("UPLOAD", $this->lng->txt("upload"));
00121 }
00122 elseif ($this->object->get_matching_type() == MT_TERMS_DEFINITIONS)
00123 {
00124 $this->tpl->setCurrentBlock("definitions");
00125 $this->tpl->setVariable("ANSWER_ORDER", $i);
00126 $this->tpl->setVariable("DEFINITION_ID", $thispair->getDefinitionId());
00127 $this->tpl->setVariable("VALUE_DEFINITION", ilUtil::prepareFormOutput($thispair->getDefinition()));
00128 $this->tpl->setVariable("COLOR_CLASS", $tblrow[$i % 2]);
00129 }
00130 $this->tpl->parseCurrentBlock();
00131 $this->tpl->setCurrentBlock("answers");
00132 $this->tpl->setVariable("VALUE_ANSWER_COUNTER", $i + 1);
00133 $this->tpl->setVariable("ANSWER_ORDER", $i);
00134 $this->tpl->setVariable("TERM_ID", $thispair->getTermId());
00135 $this->tpl->setVariable("VALUE_TERM", ilUtil::prepareFormOutput($thispair->getTerm()));
00136 $this->tpl->setVariable("TEXT_MATCHES", $this->lng->txt("matches"));
00137 $this->tpl->setVariable("VALUE_MATCHINGPAIR_POINTS", $thispair->getPoints());
00138 $this->tpl->setVariable("COLOR_CLASS", $tblrow[$i % 2]);
00139 $this->tpl->parseCurrentBlock();
00140 }
00141
00142 if ($this->object->get_matching_type() == MT_TERMS_DEFINITIONS)
00143 {
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154 }
00155
00156 if ($this->object->get_matchingpair_count())
00157 {
00158 $this->tpl->setCurrentBlock("answerhead");
00159 $this->tpl->setVariable("TEXT_POINTS", $this->lng->txt("points"));
00160 $this->tpl->setVariable("TERM", $this->lng->txt("term"));
00161 if ($this->object->get_matching_type() == MT_TERMS_PICTURES)
00162 {
00163 $this->tpl->setVariable("PICTURE_OR_DEFINITION", $this->lng->txt("picture"));
00164 }
00165 else
00166 {
00167 $this->tpl->setVariable("PICTURE_OR_DEFINITION", $this->lng->txt("definition"));
00168 }
00169 $this->tpl->parseCurrentBlock();
00170 $this->tpl->setCurrentBlock("selectall");
00171 $this->tpl->setVariable("SELECT_ALL", $this->lng->txt("select_all"));
00172 $i++;
00173 $this->tpl->setVariable("COLOR_CLASS", $tblrow[$i % 2]);
00174 $this->tpl->parseCurrentBlock();
00175 $this->tpl->setCurrentBlock("QFooter");
00176 $this->tpl->setVariable("ARROW", "<img src=\"" . ilUtil::getImagePath("arrow_downright.gif") . "\" alt=\"".$this->lng->txt("arrow_downright")."\"/>");
00177 $this->tpl->setVariable("DELETE", $this->lng->txt("delete"));
00178 $this->tpl->parseCurrentBlock();
00179 }
00180
00181 $this->outOtherQuestionData();
00182
00183
00184 $allow_add_pair = 1;
00185 foreach ($_POST as $key => $value)
00186 {
00187 if (preg_match("/(term|picture|definition)_(\d+)_(\d+)/", $key, $matches))
00188 {
00189 if (!$value)
00190 {
00191 $allow_add_pair = 0;
00192 }
00193 }
00194 }
00195 $add_random_id = "";
00196 if (($this->ctrl->getCmd() == "addPair") and $allow_add_pair and (!$has_error))
00197 {
00198 $i++;
00199
00200 if ($this->object->get_matching_type() == MT_TERMS_PICTURES)
00201 {
00202 $this->tpl->setCurrentBlock("pictures");
00203 $this->tpl->setVariable("ANSWER_ORDER", $this->object->get_matchingpair_count());
00204 $this->tpl->setVariable("PICTURE_ID", $this->object->get_random_id());
00205 $this->tpl->setVariable("VALUE_PICTURE", "");
00206 $this->tpl->setVariable("UPLOAD", $this->lng->txt("upload"));
00207 }
00208 elseif ($this->object->get_matching_type() == MT_TERMS_DEFINITIONS)
00209 {
00210 $this->tpl->setCurrentBlock("definitions");
00211 $this->tpl->setVariable("ANSWER_ORDER", $this->object->get_matchingpair_count());
00212 $this->tpl->setVariable("DEFINITION_ID", $this->object->get_random_id());
00213 $this->tpl->setVariable("VALUE_DEFINITION", "");
00214 }
00215 $this->tpl->parseCurrentBlock();
00216 $this->tpl->setCurrentBlock("answers");
00217 $this->tpl->setVariable("TEXT_MATCHING_PAIR", $this->lng->txt("matching_pair"));
00218 $this->tpl->setVariable("VALUE_ANSWER_COUNTER", $this->object->get_matchingpair_count() + 1);
00219 $this->tpl->setVariable("TEXT_MATCHES", $this->lng->txt("matches"));
00220 $this->tpl->setVariable("ANSWER_ORDER", $this->object->get_matchingpair_count());
00221 $add_random_id = $this->object->get_random_id();
00222 $this->tpl->setVariable("TERM_ID", $add_random_id);
00223 $this->tpl->setVariable("VALUE_MATCHINGPAIR_POINTS", sprintf("%s", 0));
00224 $this->tpl->setVariable("COLOR_CLASS", $tblrow[$i % 2]);
00225 $this->tpl->parseCurrentBlock();
00226 }
00227 else if ($this->ctrl->getCmd() == "addPair")
00228 {
00229 $this->error .= $this->lng->txt("fill_out_all_matching_pairs") . "<br />";
00230 }
00231
00232 $internallinks = array(
00233 "lm" => $this->lng->txt("obj_lm"),
00234 "st" => $this->lng->txt("obj_st"),
00235 "pg" => $this->lng->txt("obj_pg"),
00236 "glo" => $this->lng->txt("glossary_term")
00237 );
00238 foreach ($internallinks as $key => $value)
00239 {
00240 $this->tpl->setCurrentBlock("internallink");
00241 $this->tpl->setVariable("TYPE_INTERNAL_LINK", $key);
00242 $this->tpl->setVariable("TEXT_INTERNAL_LINK", $value);
00243 $this->tpl->parseCurrentBlock();
00244 }
00245
00246 $this->tpl->setCurrentBlock("HeadContent");
00247 $javascript = "<script type=\"text/javascript\">function initialSelect() {\n%s\n}</script>";
00248 if ($delete)
00249 {
00250 if ($this->object->get_matchingpair_count() > 0)
00251 {
00252 $thispair = $this->object->get_matchingpair($this->object->get_matchingpair_count()-1);
00253 $this->tpl->setVariable("CONTENT_BLOCK", sprintf($javascript, "document.frm_matching.term_".($this->object->get_matchingpair_count()-1)."_" . $thispair->getTermId().".focus(); document.frm_matching.term_".($this->object->get_matchingpair_count()-1)."_" . $thispair->getTermId().".scrollIntoView(\"true\");"));
00254 }
00255 else
00256 {
00257 $this->tpl->setVariable("CONTENT_BLOCK", sprintf($javascript, "document.frm_matching.title.focus();"));
00258 }
00259 }
00260 else
00261 {
00262 switch ($this->ctrl->getCmd())
00263 {
00264 case "addPair":
00265 $this->tpl->setVariable("CONTENT_BLOCK", sprintf($javascript, "document.frm_matching.term_".($this->object->get_matchingpair_count())."_" . $add_random_id.".focus(); document.frm_matching.term_".($this->object->get_matchingpair_count())."_" . $add_random_id.".scrollIntoView(\"true\");"));
00266 break;
00267 default:
00268 $this->tpl->setVariable("CONTENT_BLOCK", sprintf($javascript, "document.frm_matching.title.focus();"));
00269 break;
00270 }
00271 }
00272 $this->tpl->parseCurrentBlock();
00273 $this->tpl->setCurrentBlock("question_data");
00274 $this->tpl->setVariable("TEXT_TITLE", $this->lng->txt("title"));
00275 $this->tpl->setVariable("TEXT_AUTHOR", $this->lng->txt("author"));
00276 $this->tpl->setVariable("TEXT_COMMENT", $this->lng->txt("description"));
00277 $this->tpl->setVariable("TEXT_QUESTION", $this->lng->txt("question"));
00278 $this->tpl->setVariable("TEXT_SHUFFLE_ANSWERS", $this->lng->txt("shuffle_answers"));
00279 $this->tpl->setVariable("TXT_YES", $this->lng->txt("yes"));
00280 $this->tpl->setVariable("TXT_NO", $this->lng->txt("no"));
00281 if ($this->object->getShuffle())
00282 {
00283 $this->tpl->setVariable("SELECTED_YES", " selected=\"selected\"");
00284 }
00285 else
00286 {
00287 $this->tpl->setVariable("SELECTED_NO", " selected=\"selected\"");
00288 }
00289 $this->tpl->setVariable("MATCHING_ID", $this->object->getId());
00290 $this->tpl->setVariable("VALUE_MATCHING_TITLE", ilUtil::prepareFormOutput($this->object->getTitle()));
00291 $this->tpl->setVariable("VALUE_MATCHING_COMMENT", ilUtil::prepareFormOutput($this->object->getComment()));
00292 $this->tpl->setVariable("VALUE_MATCHING_AUTHOR", ilUtil::prepareFormOutput($this->object->getAuthor()));
00293 $questiontext = $this->object->getQuestion();
00294 $this->tpl->setVariable("VALUE_QUESTION", ilUtil::prepareFormOutput($this->object->prepareTextareaOutput($questiontext)));
00295 $this->tpl->setVariable("VALUE_ADD_ANSWER", $this->lng->txt("add_matching_pair"));
00296 $this->tpl->setVariable("TEXT_TYPE", $this->lng->txt("type"));
00297 $this->tpl->setVariable("TEXT_TYPE_TERMS_PICTURES", $this->lng->txt("match_terms_and_pictures"));
00298 $this->tpl->setVariable("TEXT_TYPE_TERMS_DEFINITIONS", $this->lng->txt("match_terms_and_definitions"));
00299 if ($this->object->get_matching_type() == MT_TERMS_DEFINITIONS)
00300 {
00301 $this->tpl->setVariable("SELECTED_DEFINITIONS", " selected=\"selected\"");
00302 }
00303 elseif ($this->object->get_matching_type() == MT_TERMS_PICTURES)
00304 {
00305 $this->tpl->setVariable("SELECTED_PICTURES", " selected=\"selected\"");
00306 }
00307 $this->tpl->setVariable("TEXT_SOLUTION_HINT", $this->lng->txt("solution_hint"));
00308 if (count($this->object->suggested_solutions))
00309 {
00310 $solution_array = $this->object->getSuggestedSolution(0);
00311 include_once "./assessment/classes/class.assQuestion.php";
00312 $href = assQuestion::_getInternalLinkHref($solution_array["internal_link"]);
00313 $this->tpl->setVariable("TEXT_VALUE_SOLUTION_HINT", " <a href=\"$href\" target=\"content\">" . $this->lng->txt("solution_hint"). "</a> ");
00314 $this->tpl->setVariable("BUTTON_REMOVE_SOLUTION", $this->lng->txt("remove"));
00315 $this->tpl->setVariable("BUTTON_ADD_SOLUTION", $this->lng->txt("change"));
00316 $this->tpl->setVariable("VALUE_SOLUTION_HINT", $solution_array["internal_link"]);
00317 }
00318 else
00319 {
00320 $this->tpl->setVariable("BUTTON_ADD_SOLUTION", $this->lng->txt("add"));
00321 }
00322 $this->tpl->setVariable("SAVE", $this->lng->txt("save"));
00323 $this->tpl->setVariable("SET_EDIT_MODE", $this->lng->txt("set_edit_mode"));
00324 $this->tpl->setVariable("SAVE_EDIT", $this->lng->txt("save_edit"));
00325 $this->tpl->setVariable("CANCEL", $this->lng->txt("cancel"));
00326 $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
00327 $this->ctrl->setParameter($this, "sel_question_types", "assMatchingQuestion");
00328 $this->tpl->setVariable("TEXT_QUESTION_TYPE", $this->lng->txt("assMatchingQuestion"));
00329 $this->tpl->setVariable("ACTION_MATCHING_QUESTION", $this->ctrl->getFormAction($this));
00330
00331 $this->tpl->parseCurrentBlock();
00332 if ($this->error)
00333 {
00334 sendInfo($this->error);
00335 }
00336 include_once "./Services/RTE/classes/class.ilRTE.php";
00337 $rtestring = ilRTE::_getRTEClassname();
00338 include_once "./Services/RTE/classes/class.$rtestring.php";
00339 $rte = new $rtestring();
00340 $rte->addPlugin("latex");
00341 $rte->addButton("latex");
00342 include_once "./classes/class.ilObject.php";
00343 $obj_id = $_GET["q_id"];
00344 $obj_type = ilObject::_lookupType($_GET["ref_id"], TRUE);
00345 $rte->addRTESupport($obj_id, $obj_type, "assessment");
00346 $this->tpl->setCurrentBlock("adm_content");
00347 $this->tpl->setVariable("BODY_ATTRIBUTES", " onload=\"initialSelect();\"");
00348 $this->tpl->parseCurrentBlock();
00349 }
00350
00354 function addPair()
00355 {
00356 $result = $this->writePostData();
00357 $this->editQuestion($result);
00358 }
00359
00363 function upload()
00364 {
00365 $this->writePostData();
00366 $this->editQuestion();
00367 }
00368
00369
00373 function delete()
00374 {
00375 $this->writePostData();
00376 if (is_array($_POST["chb_answer"]))
00377 {
00378 $deleteanswers = $_POST["chb_answer"];
00379 rsort($deleteanswers);
00380 foreach ($deleteanswers as $value)
00381 {
00382 $this->object->delete_matchingpair($value);
00383 }
00384 }
00385 $this->editQuestion(0, true);
00386 }
00387
00396 function writePostData()
00397 {
00398 $saved = false;
00399 $result = 0;
00400
00401 if (!$this->checkInput())
00402 {
00403 $result = 1;
00404 }
00405
00406 if (($result) and ($_POST["cmd"]["addPair"]))
00407 {
00408
00409 $this->error .= $this->lng->txt("fill_out_all_required_fields_add_matching") . "<br />";
00410 }
00411
00412 $this->object->setTitle(ilUtil::stripSlashes($_POST["title"]));
00413 $this->object->setAuthor(ilUtil::stripSlashes($_POST["author"]));
00414 $this->object->setComment(ilUtil::stripSlashes($_POST["comment"]));
00415 include_once "./classes/class.ilObjAdvancedEditing.php";
00416 $questiontext = ilUtil::stripSlashes($_POST["question"], false, ilObjAdvancedEditing::_getUsedHTMLTagsAsString("assessment"));
00417 $this->object->setQuestion($questiontext);
00418 $this->object->setSuggestedSolution($_POST["solution_hint"], 0);
00419 $this->object->setShuffle($_POST["shuffle"]);
00420
00421 $saved = $saved | $this->writeOtherPostData($result);
00422 $this->object->setMatchingType($_POST["matching_type"]);
00423
00424
00425
00426 $this->object->flush_matchingpairs();
00427 $saved = false;
00428
00429
00430 $postvalues = $_POST;
00431 foreach ($postvalues as $key => $value)
00432 {
00433 $matching_text = "";
00434 if (preg_match("/term_(\d+)_(\d+)/", $key, $matches))
00435 {
00436
00437 foreach ($_POST as $key2 => $value2)
00438 {
00439 if (preg_match("/(definition|picture)_$matches[1]_(\d+)/", $key2, $matches2))
00440 {
00441 $matchingtext_id = $matches2[2];
00442 if (strcmp($matches2[1], "definition") == 0)
00443 {
00444 $matching_text = $_POST["definition_$matches[1]_$matches2[2]"];
00445 }
00446 else
00447 {
00448 $matching_text = $_POST["picture_$matches[1]_$matches2[2]"];
00449 }
00450 }
00451 }
00452
00453
00454 if ($this->object->get_matching_type() == MT_TERMS_PICTURES)
00455 {
00456 foreach ($_FILES as $key2 => $value2)
00457 {
00458 if (preg_match("/picture_$matches[1]_(\d+)/", $key2, $matches2))
00459 {
00460 if ($value2["tmp_name"])
00461 {
00462
00463 if ($this->object->getId() <= 0)
00464 {
00465 $this->object->saveToDb();
00466 $saved = true;
00467 $this->error .= $this->lng->txt("question_saved_for_upload") . "<br />";
00468 }
00469 $value2['name'] = $this->object->createNewImageFileName($value2['name']);
00470 $upload_result = $this->object->setImageFile($value2['name'], $value2['tmp_name']);
00471 switch ($upload_result)
00472 {
00473 case 0:
00474 $_POST["picture_$matches[1]_".$matches2[1]] = $value2['name'];
00475 $matching_text = $value2['name'];
00476 break;
00477 case 1:
00478 $this->error .= $this->lng->txt("error_image_upload_wrong_format") . "<br />";
00479 break;
00480 case 2:
00481 $this->error .= $this->lng->txt("error_image_upload_copy_file") . "<br />";
00482 break;
00483 }
00484 }
00485 }
00486 }
00487 }
00488 $points = $_POST["points_$matches[1]"];
00489 if ($points < 0)
00490 {
00491 $result = 1;
00492 $this->setErrorMessage($this->lng->txt("negative_points_not_allowed"));
00493 }
00494 $this->object->add_matchingpair(
00495 ilUtil::stripSlashes($_POST["$key"]),
00496 ilUtil::stripSlashes($matching_text),
00497 ilUtil::stripSlashes($points),
00498 ilUtil::stripSlashes($matches[2]),
00499 ilUtil::stripSlashes($matchingtext_id)
00500 );
00501 }
00502 }
00503
00504 if ($saved)
00505 {
00506
00507
00508
00509
00510 $this->object->saveToDb();
00511 $_GET["q_id"] = $this->object->getId();
00512 }
00513 return $result;
00514 }
00515
00516 function outQuestionForTest($formaction, $active_id, $pass = NULL, $is_postponed = FALSE, $user_post_solution = FALSE)
00517 {
00518 $test_output = $this->getTestOutput($active_id, $pass, $is_postponed, $user_post_solution);
00519 $this->tpl->setVariable("QUESTION_OUTPUT", $test_output);
00520 if ($this->object->getOutputType() == OUTPUT_JAVASCRIPT)
00521 {
00522 $this->tpl->setVariable("BODY_ATTRIBUTES", " onload=\"setDragelementPositions();show_solution();\"");
00523 }
00524 $this->tpl->setVariable("FORMACTION", $formaction);
00525 }
00526
00527 function getSolutionOutput($active_id, $pass = NULL, $graphicalOutput = FALSE, $result_output = FALSE, $show_question_only = TRUE)
00528 {
00529
00530 include_once "./classes/class.ilTemplate.php";
00531 $template = new ilTemplate("tpl.il_as_qpl_matching_output_solution.html", TRUE, TRUE, TRUE);
00532 $solutiontemplate = new ilTemplate("tpl.il_as_tst_solution_output.html", TRUE, TRUE, TRUE);
00533
00534
00535 $keys = array_keys($this->object->matchingpairs);
00536 $keys2 = $keys;
00537
00538 $solutions = array();
00539 if ($active_id)
00540 {
00541 include_once "./assessment/classes/class.ilObjTest.php";
00542 $solutions =& $this->object->getSolutionValues($active_id, $pass);
00543 $solution_script .= "";
00544 }
00545 else
00546 {
00547 foreach ($this->object->matchingpairs as $pair)
00548 {
00549 array_push($solutions, array("value1" => $pair->getTermId(), "value2" => $pair->getDefinitionId()));
00550 }
00551 }
00552 foreach ($keys as $idx)
00553 {
00554 $answer = $this->object->matchingpairs[$idx];
00555 if ($active_id)
00556 {
00557 if ($graphicalOutput)
00558 {
00559
00560 $ok = FALSE;
00561 foreach ($solutions as $solution)
00562 {
00563 if ($answer->getDefinitionId() == $solution["value2"])
00564 {
00565 if ($answer->getTermId() == $solution["value1"])
00566 {
00567 $ok = TRUE;
00568 }
00569 }
00570 }
00571 if ($ok)
00572 {
00573 $template->setCurrentBlock("icon_ok");
00574 $template->setVariable("ICON_OK", ilUtil::getImagePath("icon_ok.gif"));
00575 $template->setVariable("TEXT_OK", $this->lng->txt("answer_is_right"));
00576 $template->parseCurrentBlock();
00577 }
00578 else
00579 {
00580 $template->setCurrentBlock("icon_ok");
00581 $template->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_not_ok.gif"));
00582 $template->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_wrong"));
00583 $template->parseCurrentBlock();
00584 }
00585 }
00586 }
00587
00588 if ($this->object->get_matching_type() == MT_TERMS_PICTURES)
00589 {
00590 $template->setCurrentBlock("standard_matching_pictures");
00591 $template->setVariable("DEFINITION_ID", $answer->getPictureId());
00592 $template->setVariable("THUMBNAIL_HREF", $this->object->getImagePathWeb() . $answer->getPicture() . ".thumb.jpg");
00593 $template->setVariable("THUMB_ALT", $this->lng->txt("image"));
00594 $template->setVariable("THUMB_TITLE", $this->lng->txt("image"));
00595 $template->parseCurrentBlock();
00596 }
00597 else
00598 {
00599 $template->setCurrentBlock("standard_matching_terms");
00600 $template->setVariable("DEFINITION", $this->object->prepareTextareaOutput($answer->getDefinition(), TRUE));
00601 $template->parseCurrentBlock();
00602 }
00603
00604 $template->setCurrentBlock("standard_matching_row");
00605 $template->setVariable("MATCHES", $this->lng->txt("matches"));
00606 if ($result_output)
00607 {
00608 $points = $answer->getPoints();
00609 $resulttext = ($points == 1) ? "(%s " . $this->lng->txt("point") . ")" : "(%s " . $this->lng->txt("points") . ")";
00610 $template->setVariable("RESULT_OUTPUT", sprintf($resulttext, $points));
00611 }
00612 $hasoutput = FALSE;
00613 foreach ($solutions as $solution)
00614 {
00615 if ($answer->getDefinitionId() == $solution["value2"])
00616 {
00617 foreach ($this->object->matchingpairs as $pair)
00618 {
00619 if ($pair->getTermId() == $solution["value1"])
00620 {
00621 $hasoutput = TRUE;
00622 $template->setVariable("SOLUTION", ilUtil::prepareFormOutput($pair->getTerm()));
00623 }
00624 }
00625 }
00626 }
00627 if (!$hasoutput)
00628 {
00629 $template->setVariable("SOLUTION", " ");
00630 }
00631 $template->parseCurrentBlock();
00632 }
00633
00634 $questiontext = $this->object->getQuestion();
00635 $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
00636 $questionoutput = $template->get();
00637 $solutiontemplate->setVariable("SOLUTION_OUTPUT", $questionoutput);
00638
00639 $solutionoutput = $solutiontemplate->get();
00640 if (!$show_question_only)
00641 {
00642
00643 $pageoutput = $this->getILIASPage();
00644 $solutionoutput = preg_replace("/(<div( xmlns:xhtml\=\"http:\/\/www.w3.org\/1999\/xhtml\"){0,1} class\=\"ilc_Question\"><\/div>)/ims", $solutionoutput, $pageoutput);
00645 }
00646 return $solutionoutput;
00647 }
00648
00649 function getPreview()
00650 {
00651
00652 include_once "./classes/class.ilTemplate.php";
00653 $template = new ilTemplate("tpl.il_as_qpl_matching_output.html", TRUE, TRUE, TRUE);
00654
00655
00656 $keys = array_keys($this->object->matchingpairs);
00657 $keys2 = $keys;
00658 if ($this->object->getShuffle())
00659 {
00660 $keys = $this->object->pcArrayShuffle($keys);
00661 $keys2 = $this->object->pcArrayShuffle($keys);
00662 }
00663
00664 foreach ($keys as $idx)
00665 {
00666 $answer = $this->object->matchingpairs[$idx];
00667 foreach ($keys2 as $comboidx)
00668 {
00669 $comboanswer = $this->object->matchingpairs[$comboidx];
00670 $template->setCurrentBlock("matching_selection");
00671 $template->setVariable("VALUE_SELECTION", $comboanswer->getTermId());
00672 $template->setVariable("TEXT_SELECTION", ilUtil::prepareFormOutput($comboanswer->getTerm()));
00673 $template->parseCurrentBlock();
00674 }
00675 if ($this->object->get_matching_type() == MT_TERMS_PICTURES)
00676 {
00677 $template->setCurrentBlock("standard_matching_pictures");
00678 $template->setVariable("DEFINITION_ID", $answer->getPictureId());
00679 $template->setVariable("IMAGE_HREF", $this->object->getImagePathWeb() . $answer->getPicture());
00680 $template->setVariable("THUMBNAIL_HREF", $this->object->getImagePathWeb() . $answer->getPicture() . ".thumb.jpg");
00681 $template->setVariable("THUMB_ALT", $this->lng->txt("image"));
00682 $template->setVariable("THUMB_TITLE", $this->lng->txt("image"));
00683 $template->parseCurrentBlock();
00684 }
00685 else
00686 {
00687 $template->setCurrentBlock("standard_matching_terms");
00688 $template->setVariable("DEFINITION", $this->object->prepareTextareaOutput($answer->getDefinition(), TRUE));
00689 $template->parseCurrentBlock();
00690 }
00691
00692 $template->setCurrentBlock("standard_matching_row");
00693 $template->setVariable("MATCHES", $this->lng->txt("matches"));
00694 $template->setVariable("DEFINITION_ID", $answer->getDefinitionId());
00695 $template->setVariable("PLEASE_SELECT", $this->lng->txt("please_select"));
00696 $template->parseCurrentBlock();
00697 }
00698
00699 $questiontext = $this->object->getQuestion();
00700 $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
00701 $questionoutput = $template->get();
00702 $questionoutput = preg_replace("/<div[^>]*?>(.*)<\/div>/is", "\\1", $questionoutput);
00703
00704 return $questionoutput;
00705 }
00706
00707 function getTestOutput($active_id, $pass = NULL, $is_postponed = FALSE, $user_post_solution = FALSE)
00708 {
00709
00710 $pageoutput = $this->outQuestionPage("", $is_postponed, $active_id);
00711
00712
00713 include_once "./classes/class.ilTemplate.php";
00714 $template = new ilTemplate("tpl.il_as_qpl_matching_output.html", TRUE, TRUE, TRUE);
00715
00716
00717 $keys = array_keys($this->object->matchingpairs);
00718 $keys2 = $keys;
00719 if ($this->object->getShuffle())
00720 {
00721 $keys = $this->object->pcArrayShuffle($keys);
00722 $keys2 = $this->object->pcArrayShuffle($keys);
00723 }
00724
00725 if ($active_id)
00726 {
00727 $solutions = NULL;
00728 include_once "./assessment/classes/class.ilObjTest.php";
00729 if (ilObjTest::_getHidePreviousResults($active_id, true))
00730 {
00731 if (is_null($pass)) $pass = ilObjTest::_getPass($active_id);
00732 }
00733 if (is_array($user_post_solution))
00734 {
00735 $solutions = array();
00736 foreach ($user_post_solution as $key => $value)
00737 {
00738 if (preg_match("/sel_matching_(\d+)/", $key, $matches))
00739 {
00740 array_push($solutions, array("value1" => $value, "value2" => $matches[1]));
00741 }
00742 }
00743 }
00744 else
00745 {
00746 $solutions =& $this->object->getSolutionValues($active_id, $pass);
00747 }
00748 $solution_script .= "";
00749 foreach ($solutions as $idx => $solution_value)
00750 {
00751 if ($this->object->getOutputType() == OUTPUT_JAVASCRIPT)
00752 {
00753 if (($solution_value["value2"] > 1) && ($solution_value["value1"] > 1))
00754 {
00755 $solution_script .= "addSolution(" . $solution_value["value1"] . "," . $solution_value["value2"] . ");\n";
00756 }
00757 }
00758 }
00759 }
00760 if ($this->object->getOutputType() == OUTPUT_JAVASCRIPT)
00761 {
00762 foreach ($keys as $idx)
00763 {
00764 $answer = $this->object->matchingpairs[$idx];
00765 $template->setCurrentBlock("dragelements");
00766 $template->setVariable("DRAGELEMENT", $answer->getDefinitionId());
00767 $template->parseCurrentBlock();
00768 $template->setCurrentBlock("dropzones");
00769 $template->setVariable("DROPZONE", $answer->getTermId());
00770 $template->parseCurrentBlock();
00771 $template->setCurrentBlock("hidden_values");
00772 $template->setVariable("MATCHING_ID", $answer->getDefinitionId());
00773 $template->parseCurrentBlock();
00774 }
00775
00776 foreach ($keys as $arrayindex => $idx)
00777 {
00778 $answer = $this->object->matchingpairs[$idx];
00779 if ($this->object->get_matching_type() == MT_TERMS_PICTURES)
00780 {
00781 $template->setCurrentBlock("matching_pictures");
00782 $template->setVariable("DEFINITION_ID", $answer->getPictureId());
00783 $template->setVariable("IMAGE_HREF", $this->object->getImagePathWeb() . $answer->getPicture());
00784 $template->setVariable("THUMBNAIL_HREF", $this->object->getImagePathWeb() . $answer->getPicture() . ".thumb.jpg");
00785 $template->setVariable("THUMB_ALT", $this->lng->txt("image"));
00786 $template->setVariable("THUMB_TITLE", $this->lng->txt("image"));
00787 $template->setVariable("ENLARGE_HREF", ilUtil::getImagePath("enlarge.gif", false));
00788 $template->setVariable("ENLARGE_ALT", $this->lng->txt("enlarge"));
00789 $template->setVariable("ENLARGE_TITLE", $this->lng->txt("enlarge"));
00790 $template->parseCurrentBlock();
00791 }
00792 else
00793 {
00794 $template->setCurrentBlock("matching_terms");
00795 $template->setVariable("DEFINITION_ID", $answer->getDefinitionId());
00796 $template->setVariable("DEFINITION_TEXT", $this->object->prepareTextareaOutput($answer->getDefinition(), TRUE));
00797 $template->parseCurrentBlock();
00798 }
00799 $template->setCurrentBlock("javascript_matching_row");
00800 $template->setVariable("MATCHES", $this->lng->txt("matches"));
00801 $shuffledTerm = $this->object->matchingpairs[$keys2[$arrayindex]];
00802 $template->setVariable("DROPZONE_ID", $shuffledTerm->getTermId());
00803 $template->setVariable("TERM_ID", $shuffledTerm->getTermId());
00804 $template->setVariable("TERM_TEXT", $shuffledTerm->getTerm());
00805 $template->parseCurrentBlock();
00806 }
00807
00808 if ($this->object->get_matching_type() == MT_TERMS_PICTURES)
00809 {
00810 $template->setVariable("RESET_TEXT", $this->lng->txt("reset_pictures"));
00811 }
00812 else
00813 {
00814 $template->setVariable("RESET_TEXT", $this->lng->txt("reset_definitions"));
00815 }
00816 $template->setVariable("JAVASCRIPT_HINT", $this->lng->txt("matching_question_javascript_hint"));
00817 $template->setVariable("SHOW_SOLUTIONS", "<script type=\"text/javascript\">\nfunction show_solution() {\n$solution_script\n}\n</script>\n");
00818 }
00819 else
00820 {
00821 foreach ($keys as $idx)
00822 {
00823 $answer = $this->object->matchingpairs[$idx];
00824 foreach ($keys2 as $comboidx)
00825 {
00826 $comboanswer = $this->object->matchingpairs[$comboidx];
00827 $template->setCurrentBlock("matching_selection");
00828 $template->setVariable("VALUE_SELECTION", $comboanswer->getTermId());
00829 $template->setVariable("TEXT_SELECTION", ilUtil::prepareFormOutput($comboanswer->getTerm()));
00830 foreach ($solutions as $solution)
00831 {
00832 if (($comboanswer->getTermId() == $solution["value1"]) && ($answer->getDefinitionId() == $solution["value2"]))
00833 {
00834 $template->setVariable("SELECTED_SELECTION", " selected=\"selected\"");
00835 }
00836 }
00837 $template->parseCurrentBlock();
00838 }
00839 if ($this->object->get_matching_type() == MT_TERMS_PICTURES)
00840 {
00841 $template->setCurrentBlock("standard_matching_pictures");
00842 $template->setVariable("DEFINITION_ID", $answer->getPictureId());
00843 $template->setVariable("IMAGE_HREF", $this->object->getImagePathWeb() . $answer->getPicture());
00844 $template->setVariable("THUMBNAIL_HREF", $this->object->getImagePathWeb() . $answer->getPicture() . ".thumb.jpg");
00845 $template->setVariable("THUMB_ALT", $this->lng->txt("image"));
00846 $template->setVariable("THUMB_TITLE", $this->lng->txt("image"));
00847 $template->parseCurrentBlock();
00848 }
00849 else
00850 {
00851 $template->setCurrentBlock("standard_matching_terms");
00852 $template->setVariable("DEFINITION", $this->object->prepareTextareaOutput($answer->getDefinition(), TRUE));
00853 $template->parseCurrentBlock();
00854 }
00855
00856 $template->setCurrentBlock("standard_matching_row");
00857 $template->setVariable("MATCHES", $this->lng->txt("matches"));
00858 $template->setVariable("DEFINITION_ID", $answer->getDefinitionId());
00859 $template->setVariable("PLEASE_SELECT", $this->lng->txt("please_select"));
00860 $template->parseCurrentBlock();
00861 }
00862 }
00863
00864 $questiontext = $this->object->getQuestion();
00865 $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
00866
00867 $questionoutput = $template->get();
00868 $questionoutput = preg_replace("/(<div( xmlns:xhtml\=\"http:\/\/www.w3.org\/1999\/xhtml\"){0,1} class\=\"ilc_Question\"><\/div>)/ims", $questionoutput, $pageoutput);
00869 return $questionoutput;
00870 }
00871
00875 function checkInput()
00876 {
00877 if ((!$_POST["title"]) or (!$_POST["author"]) or (!$_POST["question"]))
00878 {
00879 return false;
00880 }
00881 return true;
00882 }
00883
00884
00885 function addSuggestedSolution()
00886 {
00887 $_SESSION["subquestion_index"] = 0;
00888 if ($_POST["cmd"]["addSuggestedSolution"])
00889 {
00890 if ($this->writePostData())
00891 {
00892 sendInfo($this->getErrorMessage());
00893 $this->editQuestion();
00894 return;
00895 }
00896 if (!$this->checkInput())
00897 {
00898 sendInfo($this->lng->txt("fill_out_all_required_fields_add_answer"));
00899 $this->editQuestion();
00900 return;
00901 }
00902 }
00903 $this->object->saveToDb();
00904 $_GET["q_id"] = $this->object->getId();
00905 $this->tpl->setVariable("HEADER", $this->object->getTitle());
00906 $this->getQuestionTemplate();
00907 parent::addSuggestedSolution();
00908 }
00909
00910 function editMode()
00911 {
00912 global $ilUser;
00913
00914
00915 $this->object->setMatchingType($_POST["matching_type"]);
00916 $this->writePostData();
00917 $this->editQuestion();
00918 }
00919 }
00920 ?>