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