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.assImagemapQuestion.php";
00026 require_once "./assessment/classes/class.ilImagemapPreview.php";
00027
00039 class ASS_ImagemapQuestionGUI extends ASS_QuestionGUI
00040 {
00049 function ASS_ImagemapQuestionGUI(
00050 $id = -1
00051 )
00052 {
00053 $this->ASS_QuestionGUI();
00054 $this->object = new ASS_ImagemapQuestion();
00055 if ($id >= 0)
00056 {
00057 $this->object->loadFromDb($id);
00058 }
00059 }
00060
00069 function getQuestionType()
00070 {
00071 return "qt_imagemap";
00072 }
00073
00074 function getCommand($cmd)
00075 {
00076 if (isset($_POST["imagemap"]) ||
00077 isset($_POST["imagemap_x"]) ||
00078 isset($_POST["imagemap_y"]))
00079 {
00080 $this->ctrl->setCmd("getCoords");
00081 $cmd = "getCoords";
00082 }
00083
00084 return $cmd;
00085 }
00086
00087
00095 function editQuestion()
00096 {
00097 $this->tpl->setVariable("HEADER", $this->object->getTitle());
00098 $this->getQuestionTemplate("qt_imagemap");
00099 $this->tpl->addBlockFile("QUESTION_DATA", "question_data", "tpl.il_as_qpl_imagemap_question.html", true);
00100 if (($this->ctrl->getCmd() == "addArea" or $this->ctrl->getCmd() == "getCoords") and ($this->ctrl->getCmd() != "saveShape"))
00101 {
00102 foreach ($this->object->coords as $key => $value)
00103 {
00104 $this->tpl->setCurrentBlock("hidden");
00105 $this->tpl->setVariable("HIDDEN_NAME", "coords_$key");
00106 $this->tpl->setVariable("HIDDEN_VALUE", $value);
00107 $this->tpl->parseCurrentBlock();
00108 }
00109 $this->tpl->setCurrentBlock("hidden");
00110 $this->tpl->setVariable("HIDDEN_NAME", "newarea");
00111 $this->tpl->setVariable("HIDDEN_VALUE", $_POST["newarea"]);
00112 $this->tpl->parseCurrentBlock();
00113
00114 $preview = new ilImagemapPreview($this->object->getImagePath().$this->object->get_image_filename());
00115 foreach ($this->object->answers as $index => $answer)
00116 {
00117 $preview->addArea($answer->get_area(), $answer->get_coords(), $answer->get_answertext(), "", "", true);
00118 }
00119 $hidearea = false;
00120 $disabled_save = " disabled=\"disabled\"";
00121 $coords = "";
00122 switch ($_POST["newarea"])
00123 {
00124 case "rect":
00125 if (count($this->object->coords) == 0)
00126 {
00127 sendInfo($this->lng->txt("rectangle_click_tl_corner"));
00128 }
00129 else if (count($this->object->coords) == 1)
00130 {
00131 sendInfo($this->lng->txt("rectangle_click_br_corner"));
00132 }
00133 else if (count($this->object->coords) == 2)
00134 {
00135 $coords = join($this->object->coords, ",");
00136 $hidearea = true;
00137 $disabled_save = "";
00138 }
00139 break;
00140 case "circle":
00141 if (count($this->object->coords) == 0)
00142 {
00143 sendInfo($this->lng->txt("circle_click_center"));
00144 }
00145 else if (count($this->object->coords) == 1)
00146 {
00147 sendInfo($this->lng->txt("circle_click_circle"));
00148 }
00149 else if (count($this->object->coords) == 2)
00150 {
00151 if (preg_match("/(\d+)\s*,\s*(\d+)\s+(\d+)\s*,\s*(\d+)/", $this->object->coords[0] . " " . $this->object->coords[1], $matches))
00152 {
00153 $coords = "$matches[1],$matches[2]," . (int)sqrt((($matches[3]-$matches[1])*($matches[3]-$matches[1]))+(($matches[4]-$matches[2])*($matches[4]-$matches[2])));
00154 }
00155 $hidearea = true;
00156 $disabled_save = "";
00157 }
00158 break;
00159 case "poly":
00160 if (count($this->object->coords) == 0)
00161 {
00162 sendInfo($this->lng->txt("polygon_click_starting_point"));
00163 }
00164 else if (count($this->object->coords) == 1)
00165 {
00166 sendInfo($this->lng->txt("polygon_click_next_point"));
00167 }
00168 else if (count($this->object->coords) > 1)
00169 {
00170 sendInfo($this->lng->txt("polygon_click_next_or_save"));
00171 $disabled_save = "";
00172 $coords = join($this->object->coords, ",");
00173 }
00174 break;
00175 }
00176 if ($coords)
00177 {
00178 $preview->addArea($_POST["newarea"], $coords, $_POST["shapetitle"], "", "", true, "blue");
00179 }
00180 $preview->createPreview();
00181
00182 if (count($preview->areas))
00183 {
00184 $imagepath = "displaytempimage.php?gfx=" . $preview->getPreviewFilename();
00185 }
00186 else
00187 {
00188 $imagepath = $this->object->getImagePathWeb() . $this->object->get_image_filename();
00189 }
00190 if (!$hidearea)
00191 {
00192 $this->tpl->setCurrentBlock("maparea");
00193 $this->tpl->setVariable("IMAGE_SOURCE", "$imagepath");
00194 $this->tpl->parseCurrentBlock();
00195 }
00196 else
00197 {
00198 $this->tpl->setCurrentBlock("imagearea");
00199 $this->tpl->setVariable("IMAGE_SOURCE", "$imagepath");
00200 $this->tpl->setVariable("ALT_IMAGE", $this->lng->txt("imagemap"));
00201 $this->tpl->parseCurrentBlock();
00202 }
00203 $this->tpl->setCurrentBlock("imagemapeditor");
00204 $this->tpl->setVariable("TEXT_IMAGEMAP", $this->lng->txt("imagemap"));
00205 $this->tpl->setVariable("VALUE_SHAPETITLE", $_POST["shapetitle"]);
00206 $this->tpl->setVariable("TEXT_SHAPETITLE", $this->lng->txt("name"));
00207 $this->tpl->setVariable("CANCEL", $this->lng->txt("cancel"));
00208 $this->tpl->setVariable("SAVE", $this->lng->txt("save"));
00209 $this->tpl->setVariable("DISABLED_SAVE", $disabled_save);
00210 $this->tpl->parseCurrentBlock();
00211 $this->tpl->setCurrentBlock("adm_content");
00212 $this->tpl->setVariable("IMAGEMAP_ID", $this->object->getId());
00213 $this->ctrl->setParameter($this, "sel_question_types", "qt_imagemap");
00214 $this->ctrl->setParameter($this, "editmap", "1");
00215 $this->tpl->setVariable("ACTION_IMAGEMAP_QUESTION", $this->ctrl->getFormaction($this));
00216 $this->tpl->parseCurrentBlock();
00217 }
00218 else
00219 {
00220 if ($this->object->get_answer_count())
00221 {
00222 $this->tpl->setCurrentBlock("QFooter");
00223 $this->tpl->setVariable("DELETE_AREA", $this->lng->txt("delete_area"));
00224 $this->tpl->setVariable("ARROW", "<img src=\"" . ilUtil::getImagePath("arrow_downright.gif") . "\" />");
00225 $this->tpl->parseCurrentBlock();
00226 $this->tpl->setCurrentBlock("answerheader");
00227 $this->tpl->setVariable("TEXT_NAME", $this->lng->txt("name"));
00228 $this->tpl->setVariable("TEXT_TRUE", $this->lng->txt("true"));
00229 $this->tpl->setVariable("TEXT_POINTS", $this->lng->txt("points"));
00230 $this->tpl->setVariable("TEXT_SHAPE", $this->lng->txt("shape"));
00231 $this->tpl->setVariable("TEXT_COORDINATES", $this->lng->txt("coordinates"));
00232 $this->tpl->parseCurrentBlock();
00233 }
00234 $tblrow = array("tblrow1", "tblrow2");
00235 for ($i = 0; $i < $this->object->get_answer_count(); $i++)
00236 {
00237 $this->tpl->setCurrentBlock("answers");
00238 $answer = $this->object->get_answer($i);
00239 $this->tpl->setVariable("ANSWER_ORDER", $answer->get_order());
00240 $this->tpl->setVariable("VALUE_ANSWER", htmlspecialchars($answer->get_answertext()));
00241 $this->tpl->setVariable("TEXT_POINTS", $this->lng->txt("points"));
00242 if ((strcmp($_GET["markarea"], "") != 0) && ($_GET["markarea"] == $i))
00243 {
00244 $this->tpl->setVariable("CLASS_FULLWIDTH", "fullwidth_marked");
00245 }
00246 else
00247 {
00248 $this->tpl->setVariable("CLASS_FULLWIDTH", "fullwidth");
00249 }
00250 $this->tpl->setVariable("VALUE_IMAGEMAP_POINTS", $answer->get_points());
00251 $this->tpl->setVariable("COLOR_CLASS", $tblrow[$i % 2]);
00252 $coords = "";
00253 switch ($answer->get_area())
00254 {
00255 case "poly":
00256 case "rect":
00257 $coords = preg_replace("/(\d+,\d+,)/", "\$1 ", $answer->get_coords());
00258 break;
00259 case "circle":
00260 $coords = preg_replace("/(\d+,\d+,)/", "\$1 ", $answer->get_coords());
00261 break;
00262 }
00263 $this->tpl->setVariable("COORDINATES", $coords);
00264 $this->tpl->setVariable("AREA", $answer->get_area());
00265 $this->tpl->setVariable("TEXT_SHAPE", strtoupper($answer->get_area()));
00266 $this->tpl->parseCurrentBlock();
00267 }
00268
00269 $this->outOtherQuestionData();
00270
00271
00272 $internallinks = array(
00273 "lm" => $this->lng->txt("obj_lm"),
00274 "st" => $this->lng->txt("obj_st"),
00275 "pg" => $this->lng->txt("obj_pg"),
00276 "glo" => $this->lng->txt("glossary_term")
00277 );
00278 foreach ($internallinks as $key => $value)
00279 {
00280 $this->tpl->setCurrentBlock("internallink");
00281 $this->tpl->setVariable("TYPE_INTERNAL_LINK", $key);
00282 $this->tpl->setVariable("TEXT_INTERNAL_LINK", $value);
00283 $this->tpl->parseCurrentBlock();
00284 }
00285
00286 if (strcmp($this->object->get_image_filename(), "") != 0)
00287 {
00288 $this->tpl->setCurrentBlock("addarea");
00289 $this->tpl->setVariable("ADD_AREA", $this->lng->txt("add_area"));
00290 $this->tpl->setVariable("TEXT_RECT", $this->lng->txt("rectangle"));
00291 $this->tpl->setVariable("TEXT_CIRCLE", $this->lng->txt("circle"));
00292 $this->tpl->setVariable("TEXT_POLY", $this->lng->txt("polygon"));
00293 $this->tpl->parseCurrentBlock();
00294 }
00295 $this->tpl->setCurrentBlock("HeadContent");
00296 $javascript = "<script type=\"text/javascript\">function initialSelect() {\n%s\n}</script>";
00297 if (strcmp($_GET["markarea"], "") != 0)
00298 {
00299 $this->tpl->setVariable("CONTENT_BLOCK", sprintf($javascript, "document.frm_imagemap.answer_".$_GET["markarea"].".focus(); document.frm_imagemap.answer_".$_GET["markarea"].".scrollIntoView(\"true\");"));
00300 }
00301 else
00302 {
00303 switch ($this->ctrl->getCmd())
00304 {
00305 case "saveShape":
00306 case "deletearea":
00307 if ($this->object->get_answer_count() > 0)
00308 {
00309 $this->tpl->setVariable("CONTENT_BLOCK", sprintf($javascript, "document.frm_imagemap.answer_".($this->object->get_answer_count() - 1).".focus(); document.frm_imagemap.answer_".($this->object->get_answer_count() - 1).".scrollIntoView(\"true\");"));
00310 }
00311 else
00312 {
00313 $this->tpl->setVariable("CONTENT_BLOCK", sprintf($javascript, "document.frm_imagemap.title.focus();"));
00314 }
00315 break;
00316 default:
00317 $this->tpl->setVariable("CONTENT_BLOCK", sprintf($javascript, "document.frm_imagemap.title.focus();"));
00318 break;
00319 }
00320 }
00321 $this->tpl->parseCurrentBlock();
00322 $this->tpl->setCurrentBlock("question_data");
00323 $img = $this->object->get_image_filename();
00324 $this->tpl->setVariable("TEXT_IMAGE", $this->lng->txt("image"));
00325 if (!empty($img))
00326 {
00327 $this->tpl->setVariable("IMAGE_FILENAME", $img);
00328 $this->tpl->setVariable("VALUE_IMAGE_UPLOAD", $this->lng->txt("change"));
00329 $this->tpl->setCurrentBlock("imageupload");
00330
00331 $this->tpl->parse("imageupload");
00332 $map = "";
00333 if (count($this->object->answers))
00334 {
00335 $preview = new ilImagemapPreview($this->object->getImagePath() . $this->object->get_image_filename());
00336 foreach ($this->object->answers as $index => $answer)
00337 {
00338 $preview->addArea($answer->get_area(), $answer->get_coords(), $answer->get_answertext(), $this->ctrl->getLinkTarget($this, "editQuestion") . "&markarea=$index", "", true);
00339 }
00340 $preview->createPreview();
00341 $imagepath = "displaytempimage.php?gfx=" . $preview->getPreviewFilename();
00342 $map = $preview->getImagemap("imagemap_" . $this->object->getId());
00343 }
00344 else
00345 {
00346 $imagepath = $this->object->getImagePathWeb() . $img;
00347 }
00348 $size = GetImageSize ($this->object->getImagePath() . $this->object->get_image_filename());
00349 if ($map)
00350 {
00351 $this->tpl->setVariable("UPLOADED_IMAGE", "<img src=\"$imagepath\" alt=\"$img\" border=\"0\" " . $size[3] . " usemap=\"" . "#imagemap_" . $this->object->getId(). "\" />\n$map\n");
00352 }
00353 else
00354 {
00355 $this->tpl->setVariable("UPLOADED_IMAGE", "<img src=\"$imagepath\" alt=\"$img\" border=\"0\" " . $size[3] . " />");
00356 }
00357 }
00358 else
00359 {
00360 $this->tpl->setVariable("VALUE_IMAGE_UPLOAD", $this->lng->txt("upload"));
00361 }
00362
00363
00364 $imgmap = $this->object->get_imagemap_filename();
00365 $this->tpl->setVariable("TEXT_IMAGEMAP", $this->lng->txt("imagemap_file"));
00366 $this->tpl->setVariable("VALUE_IMAGEMAP_UPLOAD", $this->lng->txt("add_imagemap"));
00367 $this->tpl->setCurrentBlock("questioneditor");
00368 $this->tpl->setVariable("VALUE_IMAGEMAP_TITLE", htmlspecialchars($this->object->getTitle()));
00369 $this->tpl->setVariable("VALUE_IMAGEMAP_COMMENT", htmlspecialchars($this->object->getComment()));
00370 $this->tpl->setVariable("VALUE_IMAGEMAP_AUTHOR", htmlspecialchars($this->object->getAuthor()));
00371 $questiontext = $this->object->get_question();
00372 $questiontext = preg_replace("/<br \/>/", "\n", $questiontext);
00373 $this->tpl->setVariable("VALUE_QUESTION", htmlspecialchars($questiontext));
00374 $this->tpl->setVariable("TEXT_TITLE", $this->lng->txt("title"));
00375 $this->tpl->setVariable("TEXT_AUTHOR", $this->lng->txt("author"));
00376 $this->tpl->setVariable("TEXT_COMMENT", $this->lng->txt("description"));
00377 $this->tpl->setVariable("TEXT_QUESTION", $this->lng->txt("question"));
00378 $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
00379
00380 $this->tpl->setVariable("TEXT_SOLUTION_HINT", $this->lng->txt("solution_hint"));
00381 if (count($this->object->suggested_solutions))
00382 {
00383 $solution_array = $this->object->getSuggestedSolution(0);
00384 $href = ASS_Question::_getInternalLinkHref($solution_array["internal_link"]);
00385 $this->tpl->setVariable("TEXT_VALUE_SOLUTION_HINT", " <a href=\"$href\" target=\"content\">" . $this->lng->txt("solution_hint"). "</a> ");
00386 $this->tpl->setVariable("BUTTON_REMOVE_SOLUTION", $this->lng->txt("remove"));
00387 $this->tpl->setVariable("BUTTON_ADD_SOLUTION", $this->lng->txt("change"));
00388 $this->tpl->setVariable("VALUE_SOLUTION_HINT", $solution_array["internal_link"]);
00389 }
00390 else
00391 {
00392 $this->tpl->setVariable("BUTTON_ADD_SOLUTION", $this->lng->txt("add"));
00393 }
00394
00395 $this->tpl->setVariable("SAVE",$this->lng->txt("save"));
00396 $this->tpl->setVariable("SAVE_EDIT", $this->lng->txt("save_edit"));
00397 $this->tpl->setVariable("CANCEL",$this->lng->txt("cancel"));
00398 $this->tpl->parseCurrentBlock();
00399 $this->tpl->setCurrentBlock("adm_content");
00400 $this->ctrl->setParameter($this, "sel_question_types", "qt_imagemap");
00401 $this->tpl->setVariable("ACTION_IMAGEMAP_QUESTION", $this->ctrl->getFormaction($this));
00402 $this->tpl->setVariable("IMAGEMAP_ID", $this->object->getId());
00403 $this->tpl->parseCurrentBlock();
00404 }
00405
00406 $this->tpl->setCurrentBlock("adm_content");
00407 $this->tpl->setVariable("BODY_ATTRIBUTES", " onload=\"initialSelect();\"");
00408 $this->tpl->parseCurrentBlock();
00409 }
00410
00418 function outOtherQuestionData()
00419 {
00420 $colspan = " colspan=\"3\"";
00421
00422 $this->tpl->setCurrentBlock("other_question_data");
00423 $est_working_time = $this->object->getEstimatedWorkingTime();
00424 $this->tpl->setVariable("TEXT_WORKING_TIME", $this->lng->txt("working_time"));
00425 $this->tpl->setVariable("TIME_FORMAT", $this->lng->txt("time_format"));
00426 $this->tpl->setVariable("VALUE_WORKING_TIME", ilUtil::makeTimeSelect("Estimated", false, $est_working_time[h], $est_working_time[m], $est_working_time[s]));
00427 $this->tpl->parseCurrentBlock();
00428 }
00429
00430 function getCoords()
00431 {
00432 $this->writePostData();
00433 $this->editQuestion();
00434 }
00435
00436 function back()
00437 {
00438 $this->editQuestion();
00439 }
00440
00441 function saveShape()
00442 {
00443 $this->writePostData();
00444 $this->editQuestion();
00445 }
00446
00447 function addArea()
00448 {
00449 $this->writePostData();
00450 $this->editQuestion();
00451 }
00452
00453 function uploadingImage()
00454 {
00455 $this->writePostData();
00456 $this->editQuestion();
00457 }
00458
00459 function uploadingImagemap()
00460 {
00461 $this->writePostData();
00462 $this->editQuestion();
00463 }
00464
00465 function deleteArea()
00466 {
00467 $this->writePostData();
00468 $checked_areas = array();
00469 foreach ($_POST as $key => $value)
00470 {
00471 if (preg_match("/cb_(\d+)/", $key, $matches))
00472 {
00473 array_push($checked_areas, $matches[1]);
00474 }
00475 }
00476 rsort($checked_areas, SORT_NUMERIC);
00477 foreach ($checked_areas as $index)
00478 {
00479 $this->object->deleteArea($index);
00480 }
00481 $this->editQuestion();
00482 }
00483
00492 function writePostData()
00493 {
00494 $result = 0;
00495 $saved = false;
00496
00497 if ($_GET["editmap"])
00498 {
00499 $this->object->coords = array();
00500 foreach ($_POST as $key => $value)
00501 {
00502 if (preg_match("/coords_(\d+)/", $key, $matches))
00503 {
00504 $this->object->coords[$matches[1]] = $value;
00505 }
00506 }
00507 if (isset($_POST["imagemap_x"]))
00508 {
00509 array_push($this->object->coords, $_POST["imagemap_x"] . "," . $_POST["imagemap_y"]);
00510 }
00511 if ($this->ctrl->getCmd() == "saveShape")
00512 {
00513 $coords = "";
00514 switch ($_POST["newarea"])
00515 {
00516 case "rect":
00517 $coords = join($this->object->coords, ",");
00518 break;
00519 case "circle":
00520 if (preg_match("/(\d+)\s*,\s*(\d+)\s+(\d+)\s*,\s*(\d+)/", $this->object->coords[0] . " " . $this->object->coords[1], $matches))
00521 {
00522 $coords = "$matches[1],$matches[2]," . (int)sqrt((($matches[3]-$matches[1])*($matches[3]-$matches[1]))+(($matches[4]-$matches[2])*($matches[4]-$matches[2])));
00523 }
00524 break;
00525 case "poly":
00526 $coords = join($this->object->coords, ",");
00527 break;
00528 }
00529 $this->object->add_answer($_POST["shapetitle"], 0, false, count($this->object->answers), $coords, $_POST["newarea"]);
00530 }
00531 }
00532 else
00533 {
00534 if (!$this->checkInput())
00535 {
00536 $result = 1;
00537 }
00538 $this->object->setTitle(ilUtil::stripSlashes($_POST["title"]));
00539 $this->object->setAuthor(ilUtil::stripSlashes($_POST["author"]));
00540 $this->object->setComment(ilUtil::stripSlashes($_POST["comment"]));
00541 $questiontext = ilUtil::stripSlashes($_POST["question"], true, "<strong><em><code><cite>");
00542 $questiontext = preg_replace("/\n/", "<br />", $questiontext);
00543 $this->object->set_question($questiontext);
00544 $this->object->setSuggestedSolution($_POST["solution_hint"], 0);
00545 $this->object->setShuffle($_POST["shuffle"]);
00546
00547
00548 $saved = $this->writeOtherPostData($result);
00549
00550 if (($_POST["id"] > 0) or ($result != 1))
00551 {
00552
00553
00554 if (empty($_FILES['imageName']['tmp_name']))
00555 {
00556 $this->object->set_image_filename(ilUtil::stripSlashes($_POST["uploaded_image"]));
00557 }
00558 else
00559 {
00560 if ($this->object->getId() <= 0)
00561 {
00562 $this->object->saveToDb();
00563 $_GET["q_id"] = $this->object->getId();
00564 $saved = true;
00565 sendInfo($this->lng->txt("question_saved_for_upload"));
00566 }
00567 $this->object->set_image_filename($_FILES['imageName']['name'], $_FILES['imageName']['tmp_name']);
00568 }
00569
00570
00571 if (empty($_FILES['imagemapName']['tmp_name']))
00572 {
00573 $this->object->set_imagemap_filename(ilUtil::stripSlashes($_POST['uploaded_imagemap']));
00574
00575 $this->object->flush_answers();
00576 foreach ($_POST as $key => $value)
00577 {
00578 if (preg_match("/answer_(\d+)/", $key, $matches))
00579 {
00580 $points = $_POST["points_$matches[1]"];
00581 if (preg_match("/\d+/", $points))
00582 {
00583 if ($points < 0)
00584 {
00585 $points = 0.0;
00586 sendInfo($this->lng->txt("negative_points_not_allowed"), true);
00587 }
00588 }
00589 else
00590 {
00591 $points = 0.0;
00592 }
00593
00594
00595 $this->object->add_answer(
00596 ilUtil::stripSlashes($_POST["$key"]),
00597 ilUtil::stripSlashes($points),
00598 1,
00599 $matches[1],
00600 ilUtil::stripSlashes($_POST["coords_$matches[1]"]),
00601 ilUtil::stripSlashes($_POST["area_$matches[1]"])
00602 );
00603 }
00604 }
00605 }
00606 else
00607 {
00608 if ($this->object->getId() <= 0)
00609 {
00610 $this->object->saveToDb();
00611 $_GET["q_id"] = $this->object->getId();
00612 $saved = true;
00613 sendInfo($this->lng->txt("question_saved_for_upload"));
00614 }
00615 $this->object->set_imagemap_filename($_FILES['imagemapName']['name'], $_FILES['imagemapName']['tmp_name']);
00616 }
00617 }
00618 else
00619 {
00620 if (($this->ctrl->getCmd() == "uploadingImage") and (!empty($_FILES['imageName']['tmp_name'])))
00621 {
00622 sendInfo($this->lng->txt("fill_out_all_required_fields_upload_image"));
00623 }
00624 else if (($_POST["cmd"]["uploadingImagemap"]) and (!empty($_FILES['imagemapName']['tmp_name'])))
00625 {
00626 sendInfo($this->lng->txt("fill_out_all_required_fields_upload_imagemap"));
00627 }
00628 }
00629 }
00630 if ($this->ctrl->getCmd() == "addArea")
00631 {
00632 $this->object->saveToDb();
00633 $saved = true;
00634 }
00635 if ($saved)
00636 {
00637 $_GET["q_id"] = $this->object->getId();
00638 }
00639 return $result;
00640 }
00641
00649 function outWorkingForm($test_id = "", $is_postponed = false, $showsolution = 0, &$formaction)
00650 {
00651 global $ilUser;
00652 $output = $this->outQuestionPage("IMAGEMAP_QUESTION", $is_postponed);
00653
00654
00655 $solutionoutput = preg_replace("/.*?(<div[^<]*?ilc_Question.*?<\/div>).*/", "\\1", $output);
00656 $solutionoutput = preg_replace("/\"map/", "\"solution_map", $solutionoutput);
00657 $solutionoutput = preg_replace("/qmap/", "solution_qmap", $solutionoutput);
00658
00659 if ($test_id)
00660 {
00661 $solutions =& $this->object->getSolutionValues($test_id);
00662 $preview = new ilImagemapPreview($this->object->getImagePath().$this->object->get_image_filename());
00663 foreach ($solutions as $idx => $solution_value)
00664 {
00665 if (strcmp($solution_value->value1, "") != 0)
00666 {
00667 $preview->addArea($this->object->answers[$solution_value->value1]->get_area(), $this->object->answers[$solution_value->value1]->get_coords(), $this->object->answers[$solution_value->value1]->get_answertext(), "", "", true);
00668 }
00669 }
00670 $preview->createPreview();
00671 if (count($preview->areas))
00672 {
00673 $imagepath = "displaytempimage.php?gfx=" . $preview->getPreviewFilename();
00674 $output = preg_replace("/usemap\=\"#qmap\" src\=\"([^\"]*?)\"/", "usemap=\"#qmap\" src=\"$imagepath\"", $output);
00675 }
00676 }
00677
00678 $maxpoints = 0;
00679 $maxindex = -1;
00680 foreach ($this->object->answers as $idx => $answer)
00681 {
00682 if ($answer->get_points() > $maxpoints)
00683 {
00684 $maxpoints = $answer->get_points();
00685 $maxindex = $idx;
00686 }
00687 $output = preg_replace("/nohref id\=\"map$idx\"/", "href=\"$formaction&selImage=$idx\"", $output);
00688 }
00689 if ($maxindex > -1)
00690 {
00691 $answer = $this->object->answers[$maxindex];
00692 $preview = new ilImagemapPreview($this->object->getImagePath().$this->object->get_image_filename());
00693 $preview->addArea($answer->get_area(), $answer->get_coords(), $answer->get_answertext(), "", "", true);
00694 $preview->createPreview();
00695 if (count($preview->areas))
00696 {
00697 $imagepath = "displaytempimage.php?gfx=" . $preview->getPreviewFilename();
00698 $solutionoutput = preg_replace("/usemap\=\"#solution_qmap\" src\=\"([^\"]*?)\"/", "usemap=\"#solution_qmap\" src=\"$imagepath\"", $solutionoutput);
00699 }
00700 }
00701
00702 $solutionoutput = "<p>" . $this->lng->txt("correct_solution_is") . ":</p><p>$solutionoutput</p>";
00703 if ($test_id)
00704 {
00705 $received_points = "<p>" . sprintf($this->lng->txt("you_received_a_of_b_points"), $this->object->getReachedPoints($ilUser->id, $test_id), $this->object->getMaximumPoints()) . "</p>";
00706 }
00707 if (!$showsolution)
00708 {
00709 $solutionoutput = "";
00710 $received_points = "";
00711 }
00712 $this->tpl->setVariable("IMAGEMAP_QUESTION", $output.$solutionoutput.$received_points);
00713 }
00714
00722 function outUserSolution($user_id, $test_id)
00723 {
00724 }
00725
00729 function checkInput()
00730 {
00731 if ((!$_POST["title"]) or (!$_POST["author"]) or (!$_POST["question"]))
00732 {
00733 return false;
00734 }
00735 return true;
00736 }
00737
00738 function addSuggestedSolution()
00739 {
00740 $_SESSION["subquestion_index"] = 0;
00741 if ($_POST["cmd"]["addSuggestedSolution"])
00742 {
00743 $this->writePostData();
00744 if (!$this->checkInput())
00745 {
00746 sendInfo($this->lng->txt("fill_out_all_required_fields_add_answer"));
00747 $this->editQuestion();
00748 return;
00749 }
00750 }
00751 $this->object->saveToDb();
00752 $_GET["q_id"] = $this->object->getId();
00753 $this->tpl->setVariable("HEADER", $this->object->getTitle());
00754 $this->getQuestionTemplate("qt_imagemap");
00755 parent::addSuggestedSolution();
00756 }
00757 }
00758 ?>