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_ImagemapQuestionGUI extends ASS_QuestionGUI
00039 {
00048 function ASS_ImagemapQuestionGUI(
00049 $id = -1
00050 )
00051 {
00052 include_once "./assessment/classes/class.assImagemapQuestion.php";
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 include_once "./assessment/classes/class.ilImagemapPreview.php";
00098
00099 $this->getQuestionTemplate("qt_imagemap");
00100 $this->tpl->addBlockFile("QUESTION_DATA", "question_data", "tpl.il_as_qpl_imagemap_question.html", true);
00101 if (($this->ctrl->getCmd() == "addArea" or $this->ctrl->getCmd() == "getCoords") and ($this->ctrl->getCmd() != "saveShape"))
00102 {
00103 foreach ($this->object->coords as $key => $value)
00104 {
00105 $this->tpl->setCurrentBlock("hidden");
00106 $this->tpl->setVariable("HIDDEN_NAME", "coords_$key");
00107 $this->tpl->setVariable("HIDDEN_VALUE", $value);
00108 $this->tpl->parseCurrentBlock();
00109 }
00110 $this->tpl->setCurrentBlock("hidden");
00111 $this->tpl->setVariable("HIDDEN_NAME", "newarea");
00112 $this->tpl->setVariable("HIDDEN_VALUE", $_POST["newarea"]);
00113 $this->tpl->parseCurrentBlock();
00114
00115 $preview = new ilImagemapPreview($this->object->getImagePath().$this->object->get_image_filename());
00116 foreach ($this->object->answers as $index => $answer)
00117 {
00118 $preview->addArea($answer->get_area(), $answer->get_coords(), $answer->get_answertext(), "", "", true);
00119 }
00120 $hidearea = false;
00121 $disabled_save = " disabled=\"disabled\"";
00122 $coords = "";
00123 switch ($_POST["newarea"])
00124 {
00125 case "rect":
00126 if (count($this->object->coords) == 0)
00127 {
00128 sendInfo($this->lng->txt("rectangle_click_tl_corner"));
00129 }
00130 else if (count($this->object->coords) == 1)
00131 {
00132 sendInfo($this->lng->txt("rectangle_click_br_corner"));
00133 }
00134 else if (count($this->object->coords) == 2)
00135 {
00136 $coords = join($this->object->coords, ",");
00137 $hidearea = true;
00138 $disabled_save = "";
00139 }
00140 break;
00141 case "circle":
00142 if (count($this->object->coords) == 0)
00143 {
00144 sendInfo($this->lng->txt("circle_click_center"));
00145 }
00146 else if (count($this->object->coords) == 1)
00147 {
00148 sendInfo($this->lng->txt("circle_click_circle"));
00149 }
00150 else if (count($this->object->coords) == 2)
00151 {
00152 if (preg_match("/(\d+)\s*,\s*(\d+)\s+(\d+)\s*,\s*(\d+)/", $this->object->coords[0] . " " . $this->object->coords[1], $matches))
00153 {
00154 $coords = "$matches[1],$matches[2]," . (int)sqrt((($matches[3]-$matches[1])*($matches[3]-$matches[1]))+(($matches[4]-$matches[2])*($matches[4]-$matches[2])));
00155 }
00156 $hidearea = true;
00157 $disabled_save = "";
00158 }
00159 break;
00160 case "poly":
00161 if (count($this->object->coords) == 0)
00162 {
00163 sendInfo($this->lng->txt("polygon_click_starting_point"));
00164 }
00165 else if (count($this->object->coords) == 1)
00166 {
00167 sendInfo($this->lng->txt("polygon_click_next_point"));
00168 }
00169 else if (count($this->object->coords) > 1)
00170 {
00171 sendInfo($this->lng->txt("polygon_click_next_or_save"));
00172 $disabled_save = "";
00173 $coords = join($this->object->coords, ",");
00174 }
00175 break;
00176 }
00177 if ($coords)
00178 {
00179 $preview->addArea($_POST["newarea"], $coords, $_POST["shapetitle"], "", "", true, "blue");
00180 }
00181 $preview->createPreview();
00182
00183 if (count($preview->areas))
00184 {
00185 $pfile = $preview->getPreviewFilename();
00186 if (strlen($pfile) == 0)
00187 {
00188 sendInfo($this->lng->txt("qpl_imagemap_preview_missing"));
00189 $imagepath = $this->object->getImagePathWeb() . $this->object->get_image_filename();
00190 }
00191 else
00192 {
00193 $imagepath = "./assessment/displaytempimage.php?gfx=" . $pfile;
00194 }
00195 }
00196 else
00197 {
00198 $imagepath = $this->object->getImagePathWeb() . $this->object->get_image_filename();
00199 }
00200 if (!$hidearea)
00201 {
00202 $this->tpl->setCurrentBlock("maparea");
00203 $this->tpl->setVariable("IMAGE_SOURCE", "$imagepath");
00204 $this->tpl->parseCurrentBlock();
00205 }
00206 else
00207 {
00208 $this->tpl->setCurrentBlock("imagearea");
00209 $this->tpl->setVariable("IMAGE_SOURCE", "$imagepath");
00210 $this->tpl->setVariable("ALT_IMAGE", $this->lng->txt("imagemap"));
00211 $this->tpl->parseCurrentBlock();
00212 }
00213 $this->tpl->setCurrentBlock("imagemapeditor");
00214 $this->tpl->setVariable("TEXT_IMAGEMAP", $this->lng->txt("imagemap"));
00215 $this->tpl->setVariable("VALUE_SHAPETITLE", $_POST["shapetitle"]);
00216 $this->tpl->setVariable("TEXT_SHAPETITLE", $this->lng->txt("name"));
00217 $this->tpl->setVariable("CANCEL", $this->lng->txt("cancel"));
00218 $this->tpl->setVariable("SAVE", $this->lng->txt("save"));
00219 $this->tpl->setVariable("DISABLED_SAVE", $disabled_save);
00220 $this->tpl->parseCurrentBlock();
00221 $this->tpl->setCurrentBlock("adm_content");
00222 $this->tpl->setVariable("IMAGEMAP_ID", $this->object->getId());
00223 $this->ctrl->setParameter($this, "sel_question_types", "qt_imagemap");
00224 $this->ctrl->setParameter($this, "editmap", "1");
00225 $this->tpl->setVariable("ACTION_IMAGEMAP_QUESTION", $this->ctrl->getFormaction($this));
00226 $this->tpl->parseCurrentBlock();
00227 }
00228 else
00229 {
00230 $tblrow = array("tblrow1top", "tblrow2top");
00231 for ($i = 0; $i < $this->object->get_answer_count(); $i++)
00232 {
00233 $this->tpl->setCurrentBlock("answers");
00234 $answer = $this->object->get_answer($i);
00235 $this->tpl->setVariable("ANSWER_ORDER", $answer->get_order());
00236 $this->tpl->setVariable("VALUE_ANSWER", htmlspecialchars($answer->get_answertext()));
00237 $this->tpl->setVariable("TEXT_POINTS", $this->lng->txt("points"));
00238 if ((strcmp($_GET["markarea"], "") != 0) && ($_GET["markarea"] == $i))
00239 {
00240 $this->tpl->setVariable("CLASS_FULLWIDTH", "fullwidth_marked");
00241 }
00242 else
00243 {
00244 $this->tpl->setVariable("CLASS_FULLWIDTH", "fullwidth");
00245 }
00246 $this->tpl->setVariable("VALUE_IMAGEMAP_POINTS", $answer->get_points());
00247 $this->tpl->setVariable("COLOR_CLASS", $tblrow[$i % 2]);
00248 $coords = "";
00249 switch ($answer->get_area())
00250 {
00251 case "poly":
00252 case "rect":
00253 $coords = preg_replace("/(\d+,\d+,)/", "\$1 ", $answer->get_coords());
00254 break;
00255 case "circle":
00256 $coords = preg_replace("/(\d+,\d+,)/", "\$1 ", $answer->get_coords());
00257 break;
00258 }
00259 $this->tpl->setVariable("COORDINATES", $coords);
00260 $this->tpl->setVariable("AREA", $answer->get_area());
00261 $this->tpl->setVariable("TEXT_SHAPE", strtoupper($answer->get_area()));
00262 $this->tpl->parseCurrentBlock();
00263 }
00264 if ($this->object->get_answer_count())
00265 {
00266 $this->tpl->setCurrentBlock("selectall");
00267 $this->tpl->setVariable("SELECT_ALL", $this->lng->txt("select_all"));
00268 $i++;
00269 $this->tpl->setVariable("COLOR_CLASS", $tblrow[$i % 2]);
00270 $this->tpl->parseCurrentBlock();
00271 $this->tpl->setCurrentBlock("QFooter");
00272 $this->tpl->setVariable("DELETE_AREA", $this->lng->txt("delete_area"));
00273 $this->tpl->setVariable("ARROW", "<img src=\"" . ilUtil::getImagePath("arrow_downright.gif") . "\" alt=\"".$this->lng->txt("arrow_downright")."\"/>");
00274 $this->tpl->parseCurrentBlock();
00275 $this->tpl->setCurrentBlock("answerheader");
00276 $this->tpl->setVariable("TEXT_NAME", $this->lng->txt("name"));
00277 $this->tpl->setVariable("TEXT_TRUE", $this->lng->txt("true"));
00278 $this->tpl->setVariable("TEXT_POINTS", $this->lng->txt("points"));
00279 $this->tpl->setVariable("TEXT_SHAPE", $this->lng->txt("shape"));
00280 $this->tpl->setVariable("TEXT_COORDINATES", $this->lng->txt("coordinates"));
00281 $this->tpl->parseCurrentBlock();
00282 }
00283
00284 $this->outOtherQuestionData();
00285
00286
00287 $internallinks = array(
00288 "lm" => $this->lng->txt("obj_lm"),
00289 "st" => $this->lng->txt("obj_st"),
00290 "pg" => $this->lng->txt("obj_pg"),
00291 "glo" => $this->lng->txt("glossary_term")
00292 );
00293 foreach ($internallinks as $key => $value)
00294 {
00295 $this->tpl->setCurrentBlock("internallink");
00296 $this->tpl->setVariable("TYPE_INTERNAL_LINK", $key);
00297 $this->tpl->setVariable("TEXT_INTERNAL_LINK", $value);
00298 $this->tpl->parseCurrentBlock();
00299 }
00300
00301 if (strcmp($this->object->get_image_filename(), "") != 0)
00302 {
00303 $this->tpl->setCurrentBlock("addarea");
00304 $this->tpl->setVariable("ADD_AREA", $this->lng->txt("add_area"));
00305 $this->tpl->setVariable("TEXT_RECT", $this->lng->txt("rectangle"));
00306 $this->tpl->setVariable("TEXT_CIRCLE", $this->lng->txt("circle"));
00307 $this->tpl->setVariable("TEXT_POLY", $this->lng->txt("polygon"));
00308 if (array_key_exists("newarea", $_POST))
00309 {
00310 switch ($_POST["newarea"])
00311 {
00312 case "circle":
00313 $this->tpl->setVariable("SELECTED_CIRCLE", " selected=\"selected\"");
00314 break;
00315 case "poly":
00316 $this->tpl->setVariable("SELECTED_POLY", " selected=\"selected\"");
00317 break;
00318 case "rect":
00319 $this->tpl->setVariable("SELECTED_RECT", " selected=\"selected\"");
00320 break;
00321 }
00322 }
00323 $this->tpl->parseCurrentBlock();
00324 }
00325 $this->tpl->setCurrentBlock("HeadContent");
00326 $javascript = "<script type=\"text/javascript\">function initialSelect() {\n%s\n}</script>";
00327 if (strcmp($_GET["markarea"], "") != 0)
00328 {
00329 $this->tpl->setVariable("CONTENT_BLOCK", sprintf($javascript, "document.frm_imagemap.answer_".$_GET["markarea"].".focus(); document.frm_imagemap.answer_".$_GET["markarea"].".scrollIntoView(\"true\");"));
00330 }
00331 else
00332 {
00333 switch ($this->ctrl->getCmd())
00334 {
00335 case "saveShape":
00336 case "deletearea":
00337 if ($this->object->get_answer_count() > 0)
00338 {
00339 $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\");"));
00340 }
00341 else
00342 {
00343 $this->tpl->setVariable("CONTENT_BLOCK", sprintf($javascript, "document.frm_imagemap.title.focus();"));
00344 }
00345 break;
00346 default:
00347 $this->tpl->setVariable("CONTENT_BLOCK", sprintf($javascript, "document.frm_imagemap.title.focus();"));
00348 break;
00349 }
00350 }
00351 $this->tpl->parseCurrentBlock();
00352 $this->tpl->setCurrentBlock("question_data");
00353 $img = $this->object->get_image_filename();
00354 $this->tpl->setVariable("TEXT_IMAGE", $this->lng->txt("image"));
00355 if (!empty($img))
00356 {
00357 $this->tpl->setVariable("IMAGE_FILENAME", $img);
00358 $this->tpl->setVariable("VALUE_IMAGE_UPLOAD", $this->lng->txt("change"));
00359 $this->tpl->setCurrentBlock("imageupload");
00360
00361 $this->tpl->parse("imageupload");
00362 $map = "";
00363 if (count($this->object->answers))
00364 {
00365 $preview = new ilImagemapPreview($this->object->getImagePath() . $this->object->get_image_filename());
00366 foreach ($this->object->answers as $index => $answer)
00367 {
00368 $preview->addArea($answer->get_area(), $answer->get_coords(), $answer->get_answertext(), $this->ctrl->getLinkTarget($this, "editQuestion") . "&markarea=$index", "", true);
00369 }
00370 $preview->createPreview();
00371 $pfile = $preview->getPreviewFilename();
00372 if (strlen($pfile) == 0)
00373 {
00374 sendInfo($this->lng->txt("qpl_imagemap_preview_missing"));
00375 $imagepath = $this->object->getImagePathWeb() . $this->object->get_image_filename();
00376 }
00377 else
00378 {
00379 $imagepath = "./assessment/displaytempimage.php?gfx=" . $pfile;
00380 }
00381 $map = $preview->getImagemap("imagemap_" . $this->object->getId());
00382 }
00383 else
00384 {
00385 $imagepath = $this->object->getImagePathWeb() . $img;
00386 }
00387 $size = GetImageSize ($this->object->getImagePath() . $this->object->get_image_filename());
00388 if ($map)
00389 {
00390 $this->tpl->setVariable("UPLOADED_IMAGE", "<img src=\"$imagepath\" alt=\"$img\" border=\"0\" " . $size[3] . " usemap=\"" . "#imagemap_" . $this->object->getId(). "\" />\n$map\n");
00391 }
00392 else
00393 {
00394 $this->tpl->setVariable("UPLOADED_IMAGE", "<img src=\"$imagepath\" alt=\"$img\" border=\"0\" " . $size[3] . " />");
00395 }
00396 }
00397 else
00398 {
00399 $this->tpl->setVariable("VALUE_IMAGE_UPLOAD", $this->lng->txt("upload"));
00400 }
00401
00402
00403 $imgmap = $this->object->get_imagemap_filename();
00404 $this->tpl->setVariable("TEXT_IMAGEMAP", $this->lng->txt("imagemap_file"));
00405 $this->tpl->setVariable("VALUE_IMAGEMAP_UPLOAD", $this->lng->txt("add_imagemap"));
00406 $this->tpl->setCurrentBlock("questioneditor");
00407 $this->tpl->setVariable("VALUE_IMAGEMAP_TITLE", htmlspecialchars($this->object->getTitle()));
00408 $this->tpl->setVariable("VALUE_IMAGEMAP_COMMENT", htmlspecialchars($this->object->getComment()));
00409 $this->tpl->setVariable("VALUE_IMAGEMAP_AUTHOR", htmlspecialchars($this->object->getAuthor()));
00410 $questiontext = $this->object->get_question();
00411 $questiontext = preg_replace("/<br \/>/", "\n", $questiontext);
00412 $this->tpl->setVariable("VALUE_QUESTION", htmlspecialchars($questiontext));
00413 $this->tpl->setVariable("TEXT_TITLE", $this->lng->txt("title"));
00414 $this->tpl->setVariable("TEXT_AUTHOR", $this->lng->txt("author"));
00415 $this->tpl->setVariable("TEXT_COMMENT", $this->lng->txt("description"));
00416 $this->tpl->setVariable("TEXT_QUESTION", $this->lng->txt("question"));
00417 $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
00418
00419 $this->tpl->setVariable("TEXT_SOLUTION_HINT", $this->lng->txt("solution_hint"));
00420 if (count($this->object->suggested_solutions))
00421 {
00422 $solution_array = $this->object->getSuggestedSolution(0);
00423 include_once "./assessment/classes/class.assQuestion.php";
00424 $href = ASS_Question::_getInternalLinkHref($solution_array["internal_link"]);
00425 $this->tpl->setVariable("TEXT_VALUE_SOLUTION_HINT", " <a href=\"$href\" target=\"content\">" . $this->lng->txt("solution_hint"). "</a> ");
00426 $this->tpl->setVariable("BUTTON_REMOVE_SOLUTION", $this->lng->txt("remove"));
00427 $this->tpl->setVariable("BUTTON_ADD_SOLUTION", $this->lng->txt("change"));
00428 $this->tpl->setVariable("VALUE_SOLUTION_HINT", $solution_array["internal_link"]);
00429 }
00430 else
00431 {
00432 $this->tpl->setVariable("BUTTON_ADD_SOLUTION", $this->lng->txt("add"));
00433 }
00434
00435 $this->tpl->setVariable("SAVE",$this->lng->txt("save"));
00436 $this->tpl->setVariable("SAVE_EDIT", $this->lng->txt("save_edit"));
00437 $this->tpl->setVariable("CANCEL",$this->lng->txt("cancel"));
00438 $this->tpl->setVariable("TEXT_QUESTION_TYPE", $this->lng->txt("qt_imagemap"));
00439 $this->tpl->parseCurrentBlock();
00440 $this->tpl->setCurrentBlock("adm_content");
00441 $this->ctrl->setParameter($this, "sel_question_types", "qt_imagemap");
00442 $this->tpl->setVariable("ACTION_IMAGEMAP_QUESTION", $this->ctrl->getFormaction($this));
00443 $this->tpl->setVariable("IMAGEMAP_ID", $this->object->getId());
00444 $this->tpl->parseCurrentBlock();
00445
00446 $this->tpl->setCurrentBlock("adm_content");
00447 $this->tpl->setVariable("BODY_ATTRIBUTES", " onload=\"initialSelect();\"");
00448 $this->tpl->parseCurrentBlock();
00449 }
00450 }
00451
00459 function outOtherQuestionData()
00460 {
00461 $this->tpl->setCurrentBlock("other_question_data");
00462 $est_working_time = $this->object->getEstimatedWorkingTime();
00463 $this->tpl->setVariable("TEXT_WORKING_TIME", $this->lng->txt("working_time"));
00464 $this->tpl->setVariable("TIME_FORMAT", $this->lng->txt("time_format"));
00465 $this->tpl->setVariable("VALUE_WORKING_TIME", ilUtil::makeTimeSelect("Estimated", false, $est_working_time[h], $est_working_time[m], $est_working_time[s]));
00466 $this->tpl->parseCurrentBlock();
00467 }
00468
00469 function getCoords()
00470 {
00471 $this->writePostData();
00472 $this->editQuestion();
00473 }
00474
00475 function back()
00476 {
00477 $this->editQuestion();
00478 }
00479
00480 function saveShape()
00481 {
00482 $this->save();
00483 }
00484
00485 function addArea()
00486 {
00487 $_SESSION["last_area"] = $_POST["newarea"];
00488 $this->writePostData();
00489 $this->editQuestion();
00490 }
00491
00492 function uploadingImage()
00493 {
00494 $this->writePostData();
00495 $this->editQuestion();
00496 }
00497
00498 function uploadingImagemap()
00499 {
00500 $this->writePostData();
00501 $this->editQuestion();
00502 }
00503
00504 function deleteArea()
00505 {
00506 $this->writePostData();
00507 $checked_areas = array();
00508 foreach ($_POST as $key => $value)
00509 {
00510 if (preg_match("/cb_(\d+)/", $key, $matches))
00511 {
00512 array_push($checked_areas, $matches[1]);
00513 }
00514 }
00515 rsort($checked_areas, SORT_NUMERIC);
00516 foreach ($checked_areas as $index)
00517 {
00518 $this->object->deleteArea($index);
00519 }
00520 $this->editQuestion();
00521 }
00522
00531 function writePostData()
00532 {
00533 $result = 0;
00534 $saved = false;
00535
00536 if ($_GET["editmap"])
00537 {
00538 $this->object->coords = array();
00539 foreach ($_POST as $key => $value)
00540 {
00541 if (preg_match("/coords_(\d+)/", $key, $matches))
00542 {
00543 $this->object->coords[$matches[1]] = $value;
00544 }
00545 }
00546 if (isset($_POST["imagemap_x"]))
00547 {
00548 array_push($this->object->coords, $_POST["imagemap_x"] . "," . $_POST["imagemap_y"]);
00549 }
00550 if ($this->ctrl->getCmd() == "saveShape")
00551 {
00552 $coords = "";
00553 switch ($_POST["newarea"])
00554 {
00555 case "rect":
00556 $coords = join($this->object->coords, ",");
00557 break;
00558 case "circle":
00559 if (preg_match("/(\d+)\s*,\s*(\d+)\s+(\d+)\s*,\s*(\d+)/", $this->object->coords[0] . " " . $this->object->coords[1], $matches))
00560 {
00561 $coords = "$matches[1],$matches[2]," . (int)sqrt((($matches[3]-$matches[1])*($matches[3]-$matches[1]))+(($matches[4]-$matches[2])*($matches[4]-$matches[2])));
00562 }
00563 break;
00564 case "poly":
00565 $coords = join($this->object->coords, ",");
00566 break;
00567 }
00568 $this->object->add_answer($_POST["shapetitle"], 0, false, count($this->object->answers), $coords, $_POST["newarea"]);
00569 }
00570 }
00571 else
00572 {
00573 if (!$this->checkInput())
00574 {
00575 $result = 1;
00576 }
00577 $this->object->setTitle(ilUtil::stripSlashes($_POST["title"]));
00578 $this->object->setAuthor(ilUtil::stripSlashes($_POST["author"]));
00579 $this->object->setComment(ilUtil::stripSlashes($_POST["comment"]));
00580 $questiontext = ilUtil::stripSlashes($_POST["question"], true, "<strong><em><code><cite>");
00581 $questiontext = preg_replace("/\n/", "<br />", $questiontext);
00582 $this->object->set_question($questiontext);
00583 $this->object->setSuggestedSolution($_POST["solution_hint"], 0);
00584 $this->object->setShuffle($_POST["shuffle"]);
00585
00586
00587 $saved = $this->writeOtherPostData($result);
00588
00589 if (($_POST["id"] > 0) or ($result != 1))
00590 {
00591
00592
00593 if (empty($_FILES['imageName']['tmp_name']))
00594 {
00595 $this->object->set_image_filename(ilUtil::stripSlashes($_POST["uploaded_image"]));
00596 }
00597 else
00598 {
00599 if ($this->object->getId() <= 0)
00600 {
00601 $this->object->saveToDb();
00602 $_GET["q_id"] = $this->object->getId();
00603 $saved = true;
00604 sendInfo($this->lng->txt("question_saved_for_upload"));
00605 }
00606 $this->object->set_image_filename($_FILES['imageName']['name'], $_FILES['imageName']['tmp_name']);
00607 }
00608
00609
00610 if (empty($_FILES['imagemapName']['tmp_name']))
00611 {
00612 $this->object->set_imagemap_filename(ilUtil::stripSlashes($_POST['uploaded_imagemap']));
00613
00614 $this->object->flush_answers();
00615 foreach ($_POST as $key => $value)
00616 {
00617 if (preg_match("/answer_(\d+)/", $key, $matches))
00618 {
00619 $points = $_POST["points_$matches[1]"];
00620 if (preg_match("/\d+/", $points))
00621 {
00622 if ($points < 0)
00623 {
00624 $points = 0.0;
00625 sendInfo($this->lng->txt("negative_points_not_allowed"), true);
00626 }
00627 }
00628 else
00629 {
00630 $points = 0.0;
00631 }
00632
00633
00634 $this->object->add_answer(
00635 ilUtil::stripSlashes($_POST["$key"]),
00636 ilUtil::stripSlashes($points),
00637 1,
00638 $matches[1],
00639 ilUtil::stripSlashes($_POST["coords_$matches[1]"]),
00640 ilUtil::stripSlashes($_POST["area_$matches[1]"])
00641 );
00642 }
00643 }
00644 }
00645 else
00646 {
00647 if ($this->object->getId() <= 0)
00648 {
00649 $this->object->saveToDb();
00650 $_GET["q_id"] = $this->object->getId();
00651 $saved = true;
00652 sendInfo($this->lng->txt("question_saved_for_upload"));
00653 }
00654 $this->object->set_imagemap_filename($_FILES['imagemapName']['name'], $_FILES['imagemapName']['tmp_name']);
00655 }
00656 }
00657 else
00658 {
00659 if (($this->ctrl->getCmd() == "uploadingImage") and (!empty($_FILES['imageName']['tmp_name'])))
00660 {
00661 sendInfo($this->lng->txt("fill_out_all_required_fields_upload_image"));
00662 }
00663 else if (($_POST["cmd"]["uploadingImagemap"]) and (!empty($_FILES['imagemapName']['tmp_name'])))
00664 {
00665 sendInfo($this->lng->txt("fill_out_all_required_fields_upload_imagemap"));
00666 }
00667 }
00668 }
00669 if ($this->ctrl->getCmd() == "addArea")
00670 {
00671 $this->object->saveToDb();
00672 $saved = true;
00673 }
00674 if ($saved)
00675 {
00676 $_GET["q_id"] = $this->object->getId();
00677 }
00678 return $result;
00679 }
00680
00697 function outWorkingForm(
00698 $test_id = "",
00699 $is_postponed = false,
00700 $showsolution = 0,
00701 &$formaction,
00702 $show_question_page = true,
00703 $show_solution_only = false,
00704 $ilUser = NULL,
00705 $pass = NULL,
00706 $mixpass = false
00707 )
00708 {
00709 if (!is_object($ilUser))
00710 {
00711 global $ilUser;
00712 }
00713 $output = $this->outQuestionPage(($show_solution_only)?"":"IMAGEMAP_QUESTION", $is_postponed, $test_id);
00714
00715
00716
00717 if ($showsolution && !$show_solution_only)
00718 {
00719 $solutionintroduction = "<p>" . $this->lng->txt("tst_your_answer_was") . "</p>";
00720 $output = preg_replace("/(<div[^<]*?ilc_PageTitle.*?<\/div>)/", "\\1" . $solutionintroduction, $output);
00721 }
00722 $solutionoutput = preg_replace("/.*?(<div[^<]*?ilc_Question.*?<\/div>).*/", "\\1", $output);
00723 $solutionoutput = preg_replace("/\"map/", "\"solution_map", $solutionoutput);
00724 $solutionoutput = preg_replace("/qmap/", "solution_qmap", $solutionoutput);
00725
00726 if (!$show_question_page)
00727 $output = preg_replace("/.*?(<div[^<]*?ilc_Question.*?<\/div>).*/", "\\1", $output);
00728
00729
00730 if ($show_solution_only) {
00731 $output = preg_replace("/(<div[^<]*?ilc_Question[^>]*>.*?<\/div>)/", "", $output);
00732 }
00733
00734
00735
00736 if ($test_id)
00737 {
00738 $solutions = NULL;
00739 include_once "./assessment/classes/class.ilObjTest.php";
00740 if ((!$showsolution) && ilObjTest::_getHidePreviousResults($test_id, true))
00741 {
00742 if ($show_question_page)
00743 {
00744 if (is_null($pass)) $pass = ilObjTest::_getPass($ilUser->id, $test_id);
00745 }
00746 }
00747 if ($mixpass) $pass = NULL;
00748 $solutions =& $this->object->getSolutionValues($test_id, $ilUser, $pass);
00749 include_once "./assessment/classes/class.ilImagemapPreview.php";
00750 $preview = new ilImagemapPreview($this->object->getImagePath().$this->object->get_image_filename());
00751 foreach ($solutions as $idx => $solution_value)
00752 {
00753 if (strcmp($solution_value["value1"], "") != 0)
00754 {
00755 $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);
00756 }
00757 }
00758 $preview->createPreview();
00759 if (count($preview->areas))
00760 {
00761 $pfile = $preview->getPreviewFilename();
00762 if (strlen($pfile) == 0)
00763 {
00764 sendInfo($this->lng->txt("qpl_imagemap_preview_missing"));
00765 $imagepath = $this->object->getImagePathWeb() . $this->object->get_image_filename();
00766 }
00767 else
00768 {
00769 $imagepath = "./assessment/displaytempimage.php?gfx=" . $pfile;
00770 }
00771 $output = preg_replace("/usemap\=\"#qmap\" src\=\"([^\"]*?)\"/", "usemap=\"#qmap\" src=\"$imagepath\"", $output);
00772 }
00773 }
00774
00775 $maxpoints = 0;
00776 $maxindex = -1;
00777 foreach ($this->object->answers as $idx => $answer)
00778 {
00779 if ($answer->get_points() > $maxpoints)
00780 {
00781 $maxpoints = $answer->get_points();
00782 $maxindex = $idx;
00783 }
00784 if (!array_key_exists("evaluation", $_GET))
00785 {
00786 $output = preg_replace("/nohref id\=\"map$idx\"/", "href=\"$formaction&selImage=$idx\"", $output);
00787 }
00788 }
00789 if ($maxindex > -1)
00790 {
00791 $answer = $this->object->answers[$maxindex];
00792 include_once "./assessment/classes/class.ilImagemapPreview.php";
00793 $preview = new ilImagemapPreview($this->object->getImagePath().$this->object->get_image_filename());
00794 $preview->addArea($answer->get_area(), $answer->get_coords(), $answer->get_answertext(), "", "", true);
00795 $preview->createPreview();
00796 if (count($preview->areas))
00797 {
00798 $pfile = $preview->getPreviewFilename();
00799 if (strlen($pfile) == 0)
00800 {
00801 sendInfo($this->lng->txt("qpl_imagemap_preview_missing"));
00802 $imagepath = $this->object->getImagePathWeb() . $this->object->get_image_filename();
00803 }
00804 else
00805 {
00806 $imagepath = "./assessment/displaytempimage.php?gfx=" . $pfile;
00807 }
00808 $solutionoutput = preg_replace("/usemap\=\"#solution_qmap\" src\=\"([^\"]*?)\"/", "usemap=\"#solution_qmap\" src=\"$imagepath\"", $solutionoutput);
00809 }
00810 }
00811
00812 if (!$show_solution_only)
00813 {
00814 $solutionoutput = "<p>" . $this->lng->txt("correct_solution_is") . ":</p><p>$solutionoutput</p>";
00815 }
00816 if ($test_id)
00817 {
00818 $reached_points = $this->object->getReachedPoints($ilUser->id, $test_id);
00819 $received_points = "<p>" . sprintf($this->lng->txt("you_received_a_of_b_points"), $reached_points, $this->object->getMaximumPoints());
00820 $count_comment = "";
00821 if ($reached_points == 0)
00822 {
00823 $count_comment = $this->object->getSolutionCommentCountSystem($test_id);
00824 if (strlen($count_comment))
00825 {
00826 if (strlen($mc_comment) == 0)
00827 {
00828 $count_comment = "<span class=\"asterisk\">*</span><br /><br /><span class=\"asterisk\">*</span>$count_comment";
00829 }
00830 else
00831 {
00832 $count_comment = "<br /><span class=\"asterisk\">*</span>$count_comment";
00833 }
00834 }
00835 }
00836 $received_points .= $count_comment;
00837 $received_points .= "</p>";
00838 }
00839 if (!$showsolution)
00840 {
00841 $solutionoutput = "";
00842 $received_points = "";
00843 }
00844 $this->tpl->setVariable("IMAGEMAP_QUESTION", $output.$solutionoutput.$received_points);
00845 }
00846
00850 function checkInput()
00851 {
00852 if ((!$_POST["title"]) or (!$_POST["author"]) or (!$_POST["question"]))
00853 {
00854 return false;
00855 }
00856 return true;
00857 }
00858
00859 function addSuggestedSolution()
00860 {
00861 $_SESSION["subquestion_index"] = 0;
00862 if ($_POST["cmd"]["addSuggestedSolution"])
00863 {
00864 $this->writePostData();
00865 if (!$this->checkInput())
00866 {
00867 sendInfo($this->lng->txt("fill_out_all_required_fields_add_answer"));
00868 $this->editQuestion();
00869 return;
00870 }
00871 }
00872 $this->object->saveToDb();
00873 $_GET["q_id"] = $this->object->getId();
00874 $this->tpl->setVariable("HEADER", $this->object->getTitle());
00875 $this->getQuestionTemplate("qt_imagemap");
00876 parent::addSuggestedSolution();
00877 }
00878 }
00879 ?>