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 ASS_MatchingQuestionGUI extends ASS_QuestionGUI
00039 {
00048 function ASS_MatchingQuestionGUI(
00049 $id = -1
00050 )
00051 {
00052 $this->ASS_QuestionGUI();
00053 include_once "./assessment/classes/class.assMatchingQuestion.php";
00054 $this->object = new ASS_MatchingQuestion();
00055 if ($id >= 0)
00056 {
00057 $this->object->loadFromDb($id);
00058 }
00059 }
00060
00069 function getQuestionType()
00070 {
00071 return "qt_matching";
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
00098 $this->getQuestionTemplate("qt_matching");
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", htmlspecialchars($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", htmlspecialchars($thispair->getTerm()));
00136 $this->tpl->setVariable("TEXT_MATCHES", $this->lng->txt("matches"));
00137 $this->tpl->setVariable("VALUE_MATCHINGPAIR_POINTS", sprintf("%d", $thispair->getPoints()));
00138 $this->tpl->setVariable("COLOR_CLASS", $tblrow[$i % 2]);
00139 $this->tpl->parseCurrentBlock();
00140 }
00141 if ($this->object->get_matchingpair_count())
00142 {
00143 $this->tpl->setCurrentBlock("answerhead");
00144 $this->tpl->setVariable("TEXT_POINTS", $this->lng->txt("points"));
00145 $this->tpl->setVariable("TERM", $this->lng->txt("term"));
00146 if ($this->object->get_matching_type() == MT_TERMS_PICTURES)
00147 {
00148 $this->tpl->setVariable("PICTURE_OR_DEFINITION", $this->lng->txt("picture"));
00149 }
00150 else
00151 {
00152 $this->tpl->setVariable("PICTURE_OR_DEFINITION", $this->lng->txt("definition"));
00153 }
00154 $this->tpl->parseCurrentBlock();
00155 $this->tpl->setCurrentBlock("selectall");
00156 $this->tpl->setVariable("SELECT_ALL", $this->lng->txt("select_all"));
00157 $i++;
00158 $this->tpl->setVariable("COLOR_CLASS", $tblrow[$i % 2]);
00159 $this->tpl->parseCurrentBlock();
00160 $this->tpl->setCurrentBlock("QFooter");
00161 $this->tpl->setVariable("ARROW", "<img src=\"" . ilUtil::getImagePath("arrow_downright.gif") . "\" alt=\"".$this->lng->txt("arrow_downright")."\"/>");
00162 $this->tpl->setVariable("DELETE", $this->lng->txt("delete"));
00163 $this->tpl->parseCurrentBlock();
00164 }
00165
00166 $this->outOtherQuestionData();
00167
00168
00169 $allow_add_pair = 1;
00170 foreach ($_POST as $key => $value)
00171 {
00172 if (preg_match("/(term|picture|definition)_(\d+)_(\d+)/", $key, $matches))
00173 {
00174 if (!$value)
00175 {
00176 $allow_add_pair = 0;
00177 }
00178 }
00179 }
00180 $add_random_id = "";
00181 if (($this->ctrl->getCmd() == "addPair") and $allow_add_pair and (!$has_error))
00182 {
00183 $i++;
00184
00185 if ($this->object->get_matching_type() == MT_TERMS_PICTURES)
00186 {
00187 $this->tpl->setCurrentBlock("pictures");
00188 $this->tpl->setVariable("ANSWER_ORDER", $this->object->get_matchingpair_count());
00189 $this->tpl->setVariable("PICTURE_ID", $this->object->get_random_id());
00190 $this->tpl->setVariable("VALUE_PICTURE", "");
00191 $this->tpl->setVariable("UPLOAD", $this->lng->txt("upload"));
00192 }
00193 elseif ($this->object->get_matching_type() == MT_TERMS_DEFINITIONS)
00194 {
00195 $this->tpl->setCurrentBlock("definitions");
00196 $this->tpl->setVariable("ANSWER_ORDER", $this->object->get_matchingpair_count());
00197 $this->tpl->setVariable("DEFINITION_ID", $this->object->get_random_id());
00198 $this->tpl->setVariable("VALUE_DEFINITION", "");
00199 }
00200 $this->tpl->parseCurrentBlock();
00201 $this->tpl->setCurrentBlock("answers");
00202 $this->tpl->setVariable("TEXT_MATCHING_PAIR", $this->lng->txt("matching_pair"));
00203 $this->tpl->setVariable("VALUE_ANSWER_COUNTER", $this->object->get_matchingpair_count() + 1);
00204 $this->tpl->setVariable("TEXT_MATCHES", $this->lng->txt("matches"));
00205 $this->tpl->setVariable("ANSWER_ORDER", $this->object->get_matchingpair_count());
00206 $add_random_id = $this->object->get_random_id();
00207 $this->tpl->setVariable("TERM_ID", $add_random_id);
00208 $this->tpl->setVariable("VALUE_MATCHINGPAIR_POINTS", sprintf("%d", 0));
00209 $this->tpl->setVariable("COLOR_CLASS", $tblrow[$i % 2]);
00210 $this->tpl->parseCurrentBlock();
00211 }
00212 else if ($this->ctrl->getCmd() == "addPair")
00213 {
00214 $this->error .= $this->lng->txt("fill_out_all_matching_pairs") . "<br />";
00215 }
00216
00217 $internallinks = array(
00218 "lm" => $this->lng->txt("obj_lm"),
00219 "st" => $this->lng->txt("obj_st"),
00220 "pg" => $this->lng->txt("obj_pg"),
00221 "glo" => $this->lng->txt("glossary_term")
00222 );
00223 foreach ($internallinks as $key => $value)
00224 {
00225 $this->tpl->setCurrentBlock("internallink");
00226 $this->tpl->setVariable("TYPE_INTERNAL_LINK", $key);
00227 $this->tpl->setVariable("TEXT_INTERNAL_LINK", $value);
00228 $this->tpl->parseCurrentBlock();
00229 }
00230
00231 $this->tpl->setCurrentBlock("HeadContent");
00232 $javascript = "<script type=\"text/javascript\">function initialSelect() {\n%s\n}</script>";
00233 if ($delete)
00234 {
00235 if ($this->object->get_matchingpair_count() > 0)
00236 {
00237 $thispair = $this->object->get_matchingpair($this->object->get_matchingpair_count()-1);
00238 $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\");"));
00239 }
00240 else
00241 {
00242 $this->tpl->setVariable("CONTENT_BLOCK", sprintf($javascript, "document.frm_matching.title.focus();"));
00243 }
00244 }
00245 else
00246 {
00247 switch ($this->ctrl->getCmd())
00248 {
00249 case "addPair":
00250 $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\");"));
00251 break;
00252 default:
00253 $this->tpl->setVariable("CONTENT_BLOCK", sprintf($javascript, "document.frm_matching.title.focus();"));
00254 break;
00255 }
00256 }
00257 $this->tpl->parseCurrentBlock();
00258 $this->tpl->setCurrentBlock("question_data");
00259 $this->tpl->setVariable("TEXT_TITLE", $this->lng->txt("title"));
00260 $this->tpl->setVariable("TEXT_AUTHOR", $this->lng->txt("author"));
00261 $this->tpl->setVariable("TEXT_COMMENT", $this->lng->txt("description"));
00262 $this->tpl->setVariable("TEXT_QUESTION", $this->lng->txt("question"));
00263 $this->tpl->setVariable("TEXT_SHUFFLE_ANSWERS", $this->lng->txt("shuffle_answers"));
00264 $this->tpl->setVariable("TXT_YES", $this->lng->txt("yes"));
00265 $this->tpl->setVariable("TXT_NO", $this->lng->txt("no"));
00266 if ($this->object->getShuffle())
00267 {
00268 $this->tpl->setVariable("SELECTED_YES", " selected=\"selected\"");
00269 }
00270 else
00271 {
00272 $this->tpl->setVariable("SELECTED_NO", " selected=\"selected\"");
00273 }
00274 $this->tpl->setVariable("MATCHING_ID", $this->object->getId());
00275 $this->tpl->setVariable("VALUE_MATCHING_TITLE", htmlspecialchars($this->object->getTitle()));
00276 $this->tpl->setVariable("VALUE_MATCHING_COMMENT", htmlspecialchars($this->object->getComment()));
00277 $this->tpl->setVariable("VALUE_MATCHING_AUTHOR", htmlspecialchars($this->object->getAuthor()));
00278 $questiontext = $this->object->get_question();
00279 $questiontext = preg_replace("/<br \/>/", "\n", $questiontext);
00280 $this->tpl->setVariable("VALUE_QUESTION", htmlspecialchars($questiontext));
00281 $this->tpl->setVariable("VALUE_ADD_ANSWER", $this->lng->txt("add_matching_pair"));
00282 $this->tpl->setVariable("TEXT_TYPE", $this->lng->txt("type"));
00283 $this->tpl->setVariable("TEXT_TYPE_TERMS_PICTURES", $this->lng->txt("match_terms_and_pictures"));
00284 $this->tpl->setVariable("TEXT_TYPE_TERMS_DEFINITIONS", $this->lng->txt("match_terms_and_definitions"));
00285 if ($this->object->get_matching_type() == MT_TERMS_DEFINITIONS)
00286 {
00287 $this->tpl->setVariable("SELECTED_DEFINITIONS", " selected=\"selected\"");
00288 }
00289 elseif ($this->object->get_matching_type() == MT_TERMS_PICTURES)
00290 {
00291 $this->tpl->setVariable("SELECTED_PICTURES", " selected=\"selected\"");
00292 }
00293 $this->tpl->setVariable("TEXT_SOLUTION_HINT", $this->lng->txt("solution_hint"));
00294 if (count($this->object->suggested_solutions))
00295 {
00296 $solution_array = $this->object->getSuggestedSolution(0);
00297 include_once "./assessment/classes/class.assQuestion.php";
00298 $href = ASS_Question::_getInternalLinkHref($solution_array["internal_link"]);
00299 $this->tpl->setVariable("TEXT_VALUE_SOLUTION_HINT", " <a href=\"$href\" target=\"content\">" . $this->lng->txt("solution_hint"). "</a> ");
00300 $this->tpl->setVariable("BUTTON_REMOVE_SOLUTION", $this->lng->txt("remove"));
00301 $this->tpl->setVariable("BUTTON_ADD_SOLUTION", $this->lng->txt("change"));
00302 $this->tpl->setVariable("VALUE_SOLUTION_HINT", $solution_array["internal_link"]);
00303 }
00304 else
00305 {
00306 $this->tpl->setVariable("BUTTON_ADD_SOLUTION", $this->lng->txt("add"));
00307 }
00308 $this->tpl->setVariable("SAVE", $this->lng->txt("save"));
00309 $this->tpl->setVariable("SAVE_EDIT", $this->lng->txt("save_edit"));
00310 $this->tpl->setVariable("CANCEL", $this->lng->txt("cancel"));
00311 $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
00312 $this->ctrl->setParameter($this, "sel_question_types", "qt_matching");
00313 $this->tpl->setVariable("TEXT_QUESTION_TYPE", $this->lng->txt("qt_matching"));
00314 $this->tpl->setVariable("ACTION_MATCHING_QUESTION", $this->ctrl->getFormAction($this));
00315
00316 $this->tpl->parseCurrentBlock();
00317 if ($this->error)
00318 {
00319 sendInfo($this->error);
00320 }
00321 $this->tpl->setCurrentBlock("adm_content");
00322 $this->tpl->setVariable("BODY_ATTRIBUTES", " onload=\"initialSelect();\"");
00323 $this->tpl->parseCurrentBlock();
00324 }
00325
00333 function outOtherQuestionData()
00334 {
00335 $this->tpl->setCurrentBlock("other_question_data");
00336 $est_working_time = $this->object->getEstimatedWorkingTime();
00337 $this->tpl->setVariable("TEXT_WORKING_TIME", $this->lng->txt("working_time"));
00338 $this->tpl->setVariable("TIME_FORMAT", $this->lng->txt("time_format"));
00339 $this->tpl->setVariable("VALUE_WORKING_TIME", ilUtil::makeTimeSelect("Estimated", false, $est_working_time[h], $est_working_time[m], $est_working_time[s]));
00340 $this->tpl->parseCurrentBlock();
00341 }
00342
00343
00347 function addPair()
00348 {
00349 $result = $this->writePostData();
00350 $this->editQuestion($result);
00351 }
00352
00356 function upload()
00357 {
00358 $this->writePostData();
00359 $this->editQuestion();
00360 }
00361
00362
00366 function delete()
00367 {
00368 $this->writePostData();
00369 if (is_array($_POST["chb_answer"]))
00370 {
00371 $deleteanswers = $_POST["chb_answer"];
00372 rsort($deleteanswers);
00373 foreach ($deleteanswers as $value)
00374 {
00375 $this->object->delete_matchingpair($value);
00376 }
00377 }
00378 $this->editQuestion(0, true);
00379 }
00380
00389 function writePostData()
00390 {
00391 $saved = false;
00392 $result = 0;
00393
00394 if (!$this->checkInput())
00395 {
00396 $result = 1;
00397 }
00398
00399 if (($result) and ($_POST["cmd"]["addPair"]))
00400 {
00401
00402 $this->error .= $this->lng->txt("fill_out_all_required_fields_add_matching") . "<br />";
00403 }
00404
00405 $this->object->setTitle(ilUtil::stripSlashes($_POST["title"]));
00406 $this->object->setAuthor(ilUtil::stripSlashes($_POST["author"]));
00407 $this->object->setComment(ilUtil::stripSlashes($_POST["comment"]));
00408 $questiontext = ilUtil::stripSlashes($_POST["question"], true, "<strong><em><code><cite>");
00409 $questiontext = preg_replace("/\n/", "<br />", $questiontext);
00410 $this->object->set_question($questiontext);
00411 $this->object->setSuggestedSolution($_POST["solution_hint"], 0);
00412 $this->object->setShuffle($_POST["shuffle"]);
00413
00414 $saved = $saved | $this->writeOtherPostData($result);
00415 $this->object->set_matching_type($_POST["matching_type"]);
00416
00417
00418 $this->object->flush_matchingpairs();
00419 $saved = false;
00420
00421
00422 $postvalues = $_POST;
00423 foreach ($postvalues as $key => $value)
00424 {
00425 $matching_text = "";
00426 if (preg_match("/term_(\d+)_(\d+)/", $key, $matches))
00427 {
00428
00429 foreach ($_POST as $key2 => $value2)
00430 {
00431 if (preg_match("/(definition|picture)_$matches[1]_(\d+)/", $key2, $matches2))
00432 {
00433 $matchingtext_id = $matches2[2];
00434 if (strcmp($matches2[1], "definition") == 0)
00435 {
00436 $matching_text = $_POST["definition_$matches[1]_$matches2[2]"];
00437 }
00438 else
00439 {
00440 $matching_text = $_POST["picture_$matches[1]_$matches2[2]"];
00441 }
00442 }
00443 }
00444
00445
00446 if ($this->object->get_matching_type() == MT_TERMS_PICTURES)
00447 {
00448 foreach ($_FILES as $key2 => $value2)
00449 {
00450 if (preg_match("/picture_$matches[1]_(\d+)/", $key2, $matches2))
00451 {
00452 if ($value2["tmp_name"])
00453 {
00454
00455 if ($this->object->getId() <= 0)
00456 {
00457 $this->object->saveToDb();
00458 $saved = true;
00459 $this->error .= $this->lng->txt("question_saved_for_upload") . "<br />";
00460 }
00461 $upload_result = $this->object->set_image_file($value2['name'], $value2['tmp_name']);
00462 switch ($upload_result)
00463 {
00464 case 0:
00465 $_POST["picture_$matches[1]_".$matches2[1]] = $value2['name'];
00466 $matching_text = $value2['name'];
00467 break;
00468 case 1:
00469 $this->error .= $this->lng->txt("error_image_upload_wrong_format") . "<br />";
00470 break;
00471 case 2:
00472 $this->error .= $this->lng->txt("error_image_upload_copy_file") . "<br />";
00473 break;
00474 }
00475 }
00476 }
00477 }
00478 }
00479 $points = $_POST["points_$matches[1]"];
00480 if (preg_match("/\d+/", $points))
00481 {
00482 if ($points < 0)
00483 {
00484 $points = 0.0;
00485 $this->error .= $this->lng->txt("negative_points_not_allowed") . "<br />";
00486 }
00487 }
00488 else
00489 {
00490 $points = 0.0;
00491 }
00492 $this->object->add_matchingpair(
00493 ilUtil::stripSlashes($_POST["$key"]),
00494 ilUtil::stripSlashes($matching_text),
00495 ilUtil::stripSlashes($points),
00496 ilUtil::stripSlashes($matches[2]),
00497 ilUtil::stripSlashes($matchingtext_id)
00498 );
00499 }
00500 }
00501
00502 if ($saved)
00503 {
00504
00505
00506
00507
00508 $this->object->saveToDb();
00509 $_GET["q_id"] = $this->object->getId();
00510 }
00511 return $result;
00512 }
00513
00529 function outWorkingForm(
00530 $test_id = "",
00531 $is_postponed = false,
00532 $showsolution = 0,
00533 $show_question_page = true,
00534 $show_solution_only = false,
00535 $ilUser = NULL,
00536 $pass = NULL,
00537 $mixpass = false,
00538 $user_post_solution = false
00539 )
00540 {
00541 if (!is_object($ilUser))
00542 {
00543 global $ilUser;
00544 }
00545 $output = $this->outQuestionPage(($show_solution_only)?"":"MATCHING_QUESTION", $is_postponed, $test_id);
00546 $output = preg_replace("/{/", "{", $output);
00547 $output = preg_replace("/}/", "}", $output);
00548
00549 if ($showsolution && !$show_solution_only)
00550 {
00551 $solutionintroduction = "<p>" . $this->lng->txt("tst_your_answer_was") . "</p>";
00552 $output = preg_replace("/(<div[^<]*?ilc_PageTitle.*?<\/div>)/", "\\1" . $solutionintroduction, $output);
00553 }
00554 if ($this->object->getOutputType() == OUTPUT_HTML)
00555 {
00556 $solutionoutput = preg_replace("/.*?(<div[^<]*?ilc_Question.*?<\/div>).*/", "\\1", $output);
00557 $solutionoutput = preg_replace("/\"match/", "\"solution_match", $solutionoutput);
00558 $solutionoutput = preg_replace("/name\=\"sel_matching/", "name=\"solution_sel_matching", $solutionoutput);
00559 }
00560 else
00561 {
00562 $solutionoutput = "<table border=\"0\">\n";
00563 }
00564
00565 if (!$show_question_page)
00566 $output = preg_replace("/.*?(<div[^<]*?ilc_Question.*?<\/div>).*/", "\\1", $output);
00567
00568
00569 if ($show_solution_only) {
00570 $output = preg_replace("/(<div[^<]*?ilc_Question[^>]*>.*?<\/div>)/", "", $output);
00571 }
00572
00573
00574
00575 $solution_script = "";
00576 if ($test_id)
00577 {
00578 $solutions = NULL;
00579 include_once "./assessment/classes/class.ilObjTest.php";
00580 if ((!$showsolution) && ilObjTest::_getHidePreviousResults($test_id, true))
00581 {
00582 if ($show_question_page)
00583 {
00584 if (is_null($pass)) $pass = ilObjTest::_getPass($ilUser->id, $test_id);
00585 }
00586 }
00587 if ($mixpass) $pass = NULL;
00588 if (is_array($user_post_solution))
00589 {
00590 $solutions = array();
00591 foreach ($user_post_solution as $key => $value)
00592 {
00593 if (preg_match("/sel_matching_(\d+)/", $key, $matches))
00594 {
00595 array_push($solutions, array("value1" => $value, "value2" => $matches[1]));
00596 }
00597 }
00598 }
00599 else
00600 {
00601 $solutions =& $this->object->getSolutionValues($test_id, $ilUser, $pass);
00602 }
00603 $solution_script .= "";
00604 foreach ($solutions as $idx => $solution_value)
00605 {
00606 if ($this->object->getOutputType() == OUTPUT_HTML || !$show_question_page)
00607 {
00608 $repl_str = "dummy=\"match".$solution_value["value2"]."_".$solution_value["value1"]."\"";
00609
00610 if (!$show_question_page) {
00611 $output = $this->replaceSelectElements ("sel_matching_".$solution_value["value2"],$repl_str,$output,"[","]");
00612 }
00613 else
00614 $output = str_replace($repl_str, $repl_str." selected=\"selected\"", $output);
00615
00616 }
00617 else
00618 {
00619 if (($solution_value["value2"] > 1) && ($solution_value["value1"] > 1))
00620 {
00621 $solution_script .= "addSolution(" . $solution_value["value1"] . "," . $solution_value["value2"] . ");\n";
00622 }
00623 }
00624 }
00625 if (!$show_question_page)
00626 {
00627
00628 $output = $this->removeFormElements($output);
00629 }
00630
00631 }
00632 if ($this->object->getOutputType() == OUTPUT_JAVASCRIPT)
00633 {
00634 $output = str_replace("// solution_script", "", $output);
00635 $this->tpl->setVariable("JS_INITIALIZE", "<script type=\"text/javascript\">\nfunction show_solution() {\n$solution_script\n}\n</script>\n");
00636 $this->tpl->setVariable("BODY_ATTRIBUTES", " onload=\"setDragelementPositions();show_solution();\"");
00637 }
00638
00639 if ($this->object->getOutputType() == OUTPUT_HTML)
00640 {
00641 foreach ($this->object->matchingpairs as $idx => $answer)
00642 {
00643 $id = $answer->getDefinitionId()."_".$answer->getTermId();
00644 $repl_str = "dummy=\"solution_match".$id."\"";
00645 $solutionoutput = str_replace($repl_str, $repl_str." selected=\"selected\"", $solutionoutput);
00646 $solutionoutput = preg_replace("/(<tr.*?dummy=\"solution_match$id" . "[^\d].*?)<\/tr>/", "\\1<td>" . "<em>(" . $answer->getPoints() . " " . $this->lng->txt("points") . ")</em>" . "</td></tr>", $solutionoutput);
00647
00648 if ($show_solution_only) {
00649
00650
00651
00652 $solutionoutput = $this->replaceSelectElements("solution_sel_matching_".$answer->getDefinitionId(),$repl_str, $solutionoutput,"[","]" );
00653 }
00654 }
00655
00656
00657 }
00658 else
00659 {
00660 foreach ($this->object->matchingpairs as $idx => $answer)
00661 {
00662 if ($this->object->get_matching_type() == MT_TERMS_PICTURES)
00663 {
00664 $imagepath = $this->object->getImagePathWeb() . $answer->getPicture();
00665 $solutionoutput .= "<tr><td><div class=\"textbox\">" . $answer->getTerm() . "</div></td><td width=\"10\"></td><td><div class=\"imagebox\"><img src=\"" . $imagepath . ".thumb.jpg\" alt=\"".$this->lng->txt("thumbnail")."\"/></div></td></tr>\n";
00666 $size = GetImageSize ($this->object->getImagePath() . $answer->getPicture() . ".thumb.jpg");
00667 $sizeorig = GetImageSize ($this->object->getImagePath() . $answer->getPicture());
00668 if ($size[0] >= $sizeorig[0])
00669 {
00670
00671 $output = preg_replace("/<a[^>]*?id\=\"enlarge_" . $answer->getDefinitionId() . "[^>]*?>.*?<\/a>/", "", $output);
00672 }
00673
00674 $output = preg_replace("/(id\=\"thumb_" . $answer->getDefinitionId() . "\")/", "\\1 " . $size[3], $output);
00675 }
00676 else
00677 {
00678 $solutionoutput .= "<tr><td><div class=\"textbox\">" . $answer->getTerm() . "</div></td><td width=\"10\"></td><td><div class=\"textbox\"><strong>" . $answer->getDefinition() . "</strong></div></td></tr>\n";
00679 }
00680 }
00681 $solutionoutput .= "</table>";
00682 }
00683 if (!$show_solution_only)
00684 {
00685 $solutionoutput = "<p>" . $this->lng->txt("correct_solution_is") . ":</p><p>$solutionoutput</p>";
00686 }
00687 if ($test_id)
00688 {
00689 $reached_points = $this->object->getReachedPoints($ilUser->id, $test_id);
00690 $received_points = "<p>" . sprintf($this->lng->txt("you_received_a_of_b_points"), $reached_points, $this->object->getMaximumPoints());
00691 $count_comment = "";
00692 if ($reached_points == 0)
00693 {
00694 $count_comment = $this->object->getSolutionCommentCountSystem($test_id);
00695 if (strlen($count_comment))
00696 {
00697 if (strlen($mc_comment) == 0)
00698 {
00699 $count_comment = "<span class=\"asterisk\">*</span><br /><br /><span class=\"asterisk\">*</span>$count_comment";
00700 }
00701 else
00702 {
00703 $count_comment = "<br /><span class=\"asterisk\">*</span>$count_comment";
00704 }
00705 }
00706 }
00707 $received_points .= $count_comment;
00708 $received_points .= "</p>";
00709 }
00710 if (!$showsolution)
00711 {
00712 $solutionoutput = "";
00713 $received_points = "";
00714 }
00715 if ($this->object->get_matching_type() == MT_TERMS_PICTURES)
00716 {
00717 $output = str_replace("textbox", "textboximage", $output);
00718 $solutionoutput = str_replace("textbox", "textboximage", $solutionoutput);
00719 }
00720 $this->tpl->setVariable("MATCHING_QUESTION", $output.$solutionoutput.$received_points);
00721 }
00722
00726 function checkInput()
00727 {
00728 if ((!$_POST["title"]) or (!$_POST["author"]) or (!$_POST["question"]))
00729 {
00730 return false;
00731 }
00732 return true;
00733 }
00734
00735
00736 function addSuggestedSolution()
00737 {
00738 $_SESSION["subquestion_index"] = 0;
00739 if ($_POST["cmd"]["addSuggestedSolution"])
00740 {
00741 $this->writePostData();
00742 if (!$this->checkInput())
00743 {
00744 sendInfo($this->lng->txt("fill_out_all_required_fields_add_answer"));
00745 $this->editQuestion();
00746 return;
00747 }
00748 }
00749 $this->object->saveToDb();
00750 $_GET["q_id"] = $this->object->getId();
00751 $this->tpl->setVariable("HEADER", $this->object->getTitle());
00752 $this->getQuestionTemplate("qt_matching");
00753 parent::addSuggestedSolution();
00754 }
00755 }
00756 ?>