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 "./Modules/TestQuestionPool/classes/class.assQuestionGUI.php";
00025 include_once "./Modules/Test/classes/inc.AssessmentConstants.php";
00026
00037 class assImagemapQuestionGUI extends assQuestionGUI
00038 {
00039 private $linecolor;
00040
00049 function assImagemapQuestionGUI(
00050 $id = -1
00051 )
00052 {
00053 include_once "./Modules/TestQuestionPool/classes/class.assImagemapQuestion.php";
00054 $this->assQuestionGUI();
00055 $this->object = new assImagemapQuestion();
00056 if ($id >= 0)
00057 {
00058 $this->object->loadFromDb($id);
00059 }
00060 $assessmentSetting = new ilSetting("assessment");
00061 $this->linecolor = (strlen($assessmentSetting->get("imap_line_color"))) ? "#" . $assessmentSetting->get("imap_line_color") : "#FF0000";
00062
00063 }
00064
00065 function getCommand($cmd)
00066 {
00067 if (isset($_POST["imagemap"]) ||
00068 isset($_POST["imagemap_x"]) ||
00069 isset($_POST["imagemap_y"]))
00070 {
00071 $this->ctrl->setCmd("getCoords");
00072 $cmd = "getCoords";
00073 }
00074
00075 return $cmd;
00076 }
00077
00078
00086 function editQuestion()
00087 {
00088 include_once "./Modules/TestQuestionPool/classes/class.ilImagemapPreview.php";
00089
00090 $this->getQuestionTemplate();
00091 $this->tpl->addBlockFile("QUESTION_DATA", "question_data", "tpl.il_as_qpl_imagemap_question.html", "Modules/TestQuestionPool");
00092 if (($this->ctrl->getCmd() == "addArea" or $this->ctrl->getCmd() == "getCoords") and ($this->ctrl->getCmd() != "saveShape"))
00093 {
00094 foreach ($this->object->coords as $key => $value)
00095 {
00096 $this->tpl->setCurrentBlock("hidden");
00097 $this->tpl->setVariable("HIDDEN_NAME", "coords_$key");
00098 $this->tpl->setVariable("HIDDEN_VALUE", $value);
00099 $this->tpl->parseCurrentBlock();
00100 }
00101 $this->tpl->setCurrentBlock("hidden");
00102 $this->tpl->setVariable("HIDDEN_NAME", "newarea");
00103 $this->tpl->setVariable("HIDDEN_VALUE", $_POST["newarea"]);
00104 $this->tpl->parseCurrentBlock();
00105
00106 $preview = new ilImagemapPreview($this->object->getImagePath().$this->object->get_image_filename());
00107 foreach ($this->object->answers as $index => $answer)
00108 {
00109 $preview->addArea($index, $answer->getArea(), $answer->getCoords(), $answer->getAnswertext(), "", "", true, $this->linecolor);
00110 }
00111 $hidearea = false;
00112 $disabled_save = " disabled=\"disabled\"";
00113 $coords = "";
00114 switch ($_POST["newarea"])
00115 {
00116 case "rect":
00117 if (count($this->object->coords) == 0)
00118 {
00119 ilUtil::sendInfo($this->lng->txt("rectangle_click_tl_corner"));
00120 }
00121 else if (count($this->object->coords) == 1)
00122 {
00123 ilUtil::sendInfo($this->lng->txt("rectangle_click_br_corner"));
00124 $preview->addPoint($preview->getAreaCount(), join($this->object->coords, ","), TRUE, "blue");
00125 }
00126 else if (count($this->object->coords) == 2)
00127 {
00128 $coords = join($this->object->coords, ",");
00129 $hidearea = true;
00130 $disabled_save = "";
00131 }
00132 break;
00133 case "circle":
00134 if (count($this->object->coords) == 0)
00135 {
00136 ilUtil::sendInfo($this->lng->txt("circle_click_center"));
00137 }
00138 else if (count($this->object->coords) == 1)
00139 {
00140 ilUtil::sendInfo($this->lng->txt("circle_click_circle"));
00141 $preview->addPoint($preview->getAreaCount(), join($this->object->coords, ","), TRUE, "blue");
00142 }
00143 else if (count($this->object->coords) == 2)
00144 {
00145 if (preg_match("/(\d+)\s*,\s*(\d+)\s+(\d+)\s*,\s*(\d+)/", $this->object->coords[0] . " " . $this->object->coords[1], $matches))
00146 {
00147 $coords = "$matches[1],$matches[2]," . (int)sqrt((($matches[3]-$matches[1])*($matches[3]-$matches[1]))+(($matches[4]-$matches[2])*($matches[4]-$matches[2])));
00148 }
00149 $hidearea = true;
00150 $disabled_save = "";
00151 }
00152 break;
00153 case "poly":
00154 if (count($this->object->coords) == 0)
00155 {
00156 ilUtil::sendInfo($this->lng->txt("polygon_click_starting_point"));
00157 }
00158 else if (count($this->object->coords) == 1)
00159 {
00160 ilUtil::sendInfo($this->lng->txt("polygon_click_next_point"));
00161 $preview->addPoint($preview->getAreaCount(), join($this->object->coords, ","), TRUE, "blue");
00162 }
00163 else if (count($this->object->coords) > 1)
00164 {
00165 ilUtil::sendInfo($this->lng->txt("polygon_click_next_or_save"));
00166 $disabled_save = "";
00167 $coords = join($this->object->coords, ",");
00168 }
00169 break;
00170 }
00171 if ($coords)
00172 {
00173 $preview->addArea($preview->getAreaCount(), $_POST["newarea"], $coords, $_POST["shapetitle"], "", "", true, "blue");
00174 }
00175 $preview->createPreview();
00176 $imagepath = $this->object->getImagePathWeb() . $preview->getPreviewFilename($this->object->getImagePath(), $this->object->get_image_filename());
00177 if (!$hidearea)
00178 {
00179 $this->tpl->setCurrentBlock("maparea");
00180 $this->tpl->setVariable("IMAGE_SOURCE", "$imagepath");
00181 $this->tpl->parseCurrentBlock();
00182 }
00183 else
00184 {
00185 $this->tpl->setCurrentBlock("imagearea");
00186 $this->tpl->setVariable("IMAGE_SOURCE", "$imagepath");
00187 $this->tpl->setVariable("ALT_IMAGE", $this->lng->txt("imagemap"));
00188 $this->tpl->parseCurrentBlock();
00189 }
00190 $this->tpl->setCurrentBlock("imagemapeditor");
00191 $this->tpl->setVariable("TEXT_IMAGEMAP", $this->lng->txt("imagemap"));
00192 $this->tpl->setVariable("VALUE_SHAPETITLE", $_POST["shapetitle"]);
00193 $this->tpl->setVariable("TEXT_SHAPETITLE", $this->lng->txt("name"));
00194 $this->tpl->setVariable("CANCEL", $this->lng->txt("cancel"));
00195 $this->tpl->setVariable("SAVE", $this->lng->txt("save"));
00196 $this->tpl->setVariable("DISABLED_SAVE", $disabled_save);
00197 $this->tpl->parseCurrentBlock();
00198 $this->tpl->setCurrentBlock("adm_content");
00199 $this->tpl->setVariable("IMAGEMAP_ID", $this->object->getId());
00200 $this->ctrl->setParameter($this, "sel_question_types", "assImagemapQuestion");
00201 $this->ctrl->setParameter($this, "editmap", "1");
00202 $this->tpl->setVariable("ACTION_IMAGEMAP_QUESTION", $this->ctrl->getFormaction($this));
00203 $this->tpl->parseCurrentBlock();
00204 }
00205 else
00206 {
00207 $tblrow = array("tblrow1top", "tblrow2top");
00208 for ($i = 0; $i < $this->object->getAnswerCount(); $i++)
00209 {
00210 $this->tpl->setCurrentBlock("answers");
00211 $answer = $this->object->getAnswer($i);
00212 $this->tpl->setVariable("ANSWER_ORDER", $answer->getOrder());
00213 $this->tpl->setVariable("VALUE_ANSWER", ilUtil::prepareFormOutput($answer->getAnswertext()));
00214 $this->tpl->setVariable("TEXT_POINTS", $this->lng->txt("points"));
00215 if ((strcmp($_GET["markarea"], "") != 0) && ($_GET["markarea"] == $i))
00216 {
00217 $this->tpl->setVariable("CLASS_FULLWIDTH", "fullwidth_marked");
00218 }
00219 else
00220 {
00221 $this->tpl->setVariable("CLASS_FULLWIDTH", "fullwidth");
00222 }
00223 $this->tpl->setVariable("VALUE_IMAGEMAP_POINTS", $answer->getPoints());
00224 $this->tpl->setVariable("COLOR_CLASS", $tblrow[$i % 2]);
00225 $coords = "";
00226 switch ($answer->getArea())
00227 {
00228 case "poly":
00229 case "rect":
00230 $coords = preg_replace("/(\d+,\d+,)/", "\$1 ", $answer->getCoords());
00231 break;
00232 case "circle":
00233 $coords = preg_replace("/(\d+,\d+,)/", "\$1 ", $answer->getCoords());
00234 break;
00235 }
00236 $this->tpl->setVariable("COORDINATES", $coords);
00237 $this->tpl->setVariable("AREA", $answer->getArea());
00238 $this->tpl->setVariable("TEXT_SHAPE", strtoupper($answer->getArea()));
00239 $this->tpl->parseCurrentBlock();
00240 }
00241 if ($this->object->getAnswerCount())
00242 {
00243 $this->tpl->setCurrentBlock("selectall");
00244 $this->tpl->setVariable("SELECT_ALL", $this->lng->txt("select_all"));
00245 $i++;
00246 $this->tpl->setVariable("COLOR_CLASS", $tblrow[$i % 2]);
00247 $this->tpl->parseCurrentBlock();
00248 $this->tpl->setCurrentBlock("QFooter");
00249 $this->tpl->setVariable("DELETE_AREA", $this->lng->txt("delete_area"));
00250 $this->tpl->setVariable("ARROW", "<img src=\"" . ilUtil::getImagePath("arrow_downright.gif") . "\" alt=\"".$this->lng->txt("arrow_downright")."\"/>");
00251 $this->tpl->parseCurrentBlock();
00252 $this->tpl->setCurrentBlock("answerheader");
00253 $this->tpl->setVariable("TEXT_NAME", $this->lng->txt("name"));
00254 $this->tpl->setVariable("TEXT_TRUE", $this->lng->txt("true"));
00255 $this->tpl->setVariable("TEXT_POINTS", $this->lng->txt("points"));
00256 $this->tpl->setVariable("TEXT_SHAPE", $this->lng->txt("shape"));
00257 $this->tpl->setVariable("TEXT_COORDINATES", $this->lng->txt("coordinates"));
00258 $this->tpl->parseCurrentBlock();
00259 }
00260
00261 $this->outOtherQuestionData();
00262
00263
00264 $internallinks = array(
00265 "lm" => $this->lng->txt("obj_lm"),
00266 "st" => $this->lng->txt("obj_st"),
00267 "pg" => $this->lng->txt("obj_pg"),
00268 "glo" => $this->lng->txt("glossary_term")
00269 );
00270 foreach ($internallinks as $key => $value)
00271 {
00272 $this->tpl->setCurrentBlock("internallink");
00273 $this->tpl->setVariable("TYPE_INTERNAL_LINK", $key);
00274 $this->tpl->setVariable("TEXT_INTERNAL_LINK", $value);
00275 $this->tpl->parseCurrentBlock();
00276 }
00277
00278 if (strcmp($this->object->get_image_filename(), "") != 0)
00279 {
00280 $this->tpl->setCurrentBlock("addarea");
00281 $this->tpl->setVariable("ADD_AREA", $this->lng->txt("add_area"));
00282 $this->tpl->setVariable("TEXT_RECT", $this->lng->txt("rectangle"));
00283 $this->tpl->setVariable("TEXT_CIRCLE", $this->lng->txt("circle"));
00284 $this->tpl->setVariable("TEXT_POLY", $this->lng->txt("polygon"));
00285 if (array_key_exists("newarea", $_POST))
00286 {
00287 switch ($_POST["newarea"])
00288 {
00289 case "circle":
00290 $this->tpl->setVariable("SELECTED_CIRCLE", " selected=\"selected\"");
00291 break;
00292 case "poly":
00293 $this->tpl->setVariable("SELECTED_POLY", " selected=\"selected\"");
00294 break;
00295 case "rect":
00296 $this->tpl->setVariable("SELECTED_RECT", " selected=\"selected\"");
00297 break;
00298 }
00299 }
00300 $this->tpl->parseCurrentBlock();
00301 }
00302 $this->tpl->setCurrentBlock("HeadContent");
00303 $this->tpl->addJavascript("./Services/JavaScript/js/Basic.js");
00304 $javascript = "<script type=\"text/javascript\">ilAddOnLoad(initialSelect);\n".
00305 "function initialSelect() {\n%s\n}</script>";
00306 if (strcmp($_GET["markarea"], "") != 0)
00307 {
00308 $this->tpl->setVariable("CONTENT_BLOCK", sprintf($javascript, "document.frm_imagemap.answer_".$_GET["markarea"].".focus(); document.frm_imagemap.answer_".$_GET["markarea"].".scrollIntoView(\"true\");"));
00309 }
00310 else
00311 {
00312 switch ($this->ctrl->getCmd())
00313 {
00314 case "saveShape":
00315 case "deletearea":
00316 if ($this->object->getAnswerCount() > 0)
00317 {
00318 $this->tpl->setVariable("CONTENT_BLOCK", sprintf($javascript, "document.frm_imagemap.answer_".($this->object->getAnswerCount() - 1).".focus(); document.frm_imagemap.answer_".($this->object->getAnswerCount() - 1).".scrollIntoView(\"true\");"));
00319 }
00320 else
00321 {
00322 $this->tpl->setVariable("CONTENT_BLOCK", sprintf($javascript, "document.frm_imagemap.title.focus();"));
00323 }
00324 break;
00325 default:
00326 $this->tpl->setVariable("CONTENT_BLOCK", sprintf($javascript, "document.frm_imagemap.title.focus();"));
00327 break;
00328 }
00329 }
00330 $this->tpl->parseCurrentBlock();
00331 $this->tpl->setCurrentBlock("question_data");
00332 $img = $this->object->get_image_filename();
00333 $this->tpl->setVariable("TEXT_IMAGE", $this->lng->txt("image"));
00334 if (!empty($img))
00335 {
00336 $this->tpl->setVariable("IMAGE_FILENAME", $img);
00337 $this->tpl->setVariable("VALUE_IMAGE_UPLOAD", $this->lng->txt("change"));
00338 $this->tpl->setCurrentBlock("imageupload");
00339
00340 $this->tpl->parse("imageupload");
00341 $map = "";
00342 if (count($this->object->answers))
00343 {
00344 $preview = new ilImagemapPreview($this->object->getImagePath() . $this->object->get_image_filename());
00345 foreach ($this->object->answers as $index => $answer)
00346 {
00347 $preview->addArea($index, $answer->getArea(), $answer->getCoords(), $answer->getAnswertext(), $this->ctrl->getLinkTarget($this, "editQuestion") . "&markarea=$index", "", true, $this->linecolor);
00348 }
00349 $preview->createPreview();
00350 $imagepath = $this->object->getImagePathWeb() . $preview->getPreviewFilename($this->object->getImagePath(), $this->object->get_image_filename());
00351 $map = $preview->getImagemap("imagemap_" . $this->object->getId());
00352 }
00353 else
00354 {
00355 $imagepath = $this->object->getImagePathWeb() . $img;
00356 }
00357 $size = GetImageSize ($this->object->getImagePath() . $this->object->get_image_filename());
00358 if ($map)
00359 {
00360 $this->tpl->setVariable("UPLOADED_IMAGE", "<img src=\"$imagepath\" alt=\"$img\" border=\"0\" " . $size[3] . " usemap=\"" . "#imagemap_" . $this->object->getId(). "\" />\n$map\n");
00361 }
00362 else
00363 {
00364 $this->tpl->setVariable("UPLOADED_IMAGE", "<img src=\"$imagepath\" alt=\"$img\" border=\"0\" " . $size[3] . " />");
00365 }
00366 }
00367 else
00368 {
00369 $this->tpl->setVariable("VALUE_IMAGE_UPLOAD", $this->lng->txt("upload"));
00370 }
00371
00372
00373 $imgmap = $this->object->get_imagemap_filename();
00374 $this->tpl->setVariable("TEXT_IMAGEMAP", $this->lng->txt("imagemap_file"));
00375 $this->tpl->setVariable("VALUE_IMAGEMAP_UPLOAD", $this->lng->txt("add_imagemap"));
00376 $this->tpl->setCurrentBlock("questioneditor");
00377 $this->tpl->setVariable("VALUE_IMAGEMAP_TITLE", ilUtil::prepareFormOutput($this->object->getTitle()));
00378 $this->tpl->setVariable("VALUE_IMAGEMAP_COMMENT", ilUtil::prepareFormOutput($this->object->getComment()));
00379 $this->tpl->setVariable("VALUE_IMAGEMAP_AUTHOR", ilUtil::prepareFormOutput($this->object->getAuthor()));
00380 $questiontext = $this->object->getQuestion();
00381 $this->tpl->setVariable("VALUE_QUESTION", ilUtil::prepareFormOutput($this->object->prepareTextareaOutput($questiontext)));
00382 $this->tpl->setVariable("TEXT_TITLE", $this->lng->txt("title"));
00383 $this->tpl->setVariable("TEXT_AUTHOR", $this->lng->txt("author"));
00384 $this->tpl->setVariable("TEXT_COMMENT", $this->lng->txt("description"));
00385 $this->tpl->setVariable("TEXT_QUESTION", $this->lng->txt("question"));
00386 $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
00387
00388 $this->tpl->setVariable("TEXT_SOLUTION_HINT", $this->lng->txt("solution_hint"));
00389 if (count($this->object->suggested_solutions))
00390 {
00391 $solution_array = $this->object->getSuggestedSolution(0);
00392 include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
00393 $href = assQuestion::_getInternalLinkHref($solution_array["internal_link"]);
00394 $this->tpl->setVariable("TEXT_VALUE_SOLUTION_HINT", " <a href=\"$href\" target=\"content\">" . $this->lng->txt("solution_hint"). "</a> ");
00395 $this->tpl->setVariable("BUTTON_REMOVE_SOLUTION", $this->lng->txt("remove"));
00396 $this->tpl->setVariable("BUTTON_ADD_SOLUTION", $this->lng->txt("change"));
00397 $this->tpl->setVariable("VALUE_SOLUTION_HINT", $solution_array["internal_link"]);
00398 }
00399 else
00400 {
00401 $this->tpl->setVariable("BUTTON_ADD_SOLUTION", $this->lng->txt("add"));
00402 }
00403
00404 $this->tpl->setVariable("SAVE",$this->lng->txt("save"));
00405 $this->tpl->setVariable("SAVE_EDIT", $this->lng->txt("save_edit"));
00406 $this->tpl->setVariable("CANCEL",$this->lng->txt("cancel"));
00407 $this->tpl->setVariable("TEXT_QUESTION_TYPE", $this->lng->txt("assImagemapQuestion"));
00408 $this->tpl->parseCurrentBlock();
00409 $this->tpl->setCurrentBlock("adm_content");
00410 $this->ctrl->setParameter($this, "sel_question_types", "assImagemapQuestion");
00411 $this->tpl->setVariable("ACTION_IMAGEMAP_QUESTION", $this->ctrl->getFormaction($this));
00412 $this->tpl->setVariable("IMAGEMAP_ID", $this->object->getId());
00413 $this->tpl->parseCurrentBlock();
00414 include_once "./Services/RTE/classes/class.ilRTE.php";
00415 $rtestring = ilRTE::_getRTEClassname();
00416 include_once "./Services/RTE/classes/class.$rtestring.php";
00417 $rte = new $rtestring();
00418 $rte->addPlugin("latex");
00419 $rte->addButton("latex"); $rte->addButton("pastelatex");
00420 include_once "./classes/class.ilObject.php";
00421 $obj_id = $_GET["q_id"];
00422 $obj_type = ilObject::_lookupType($_GET["ref_id"], TRUE);
00423 $rte->addRTESupport($obj_id, $obj_type, "assessment");
00424 $this->tpl->setCurrentBlock("adm_content");
00425
00426 $this->tpl->parseCurrentBlock();
00427 }
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->save();
00444 }
00445
00446 function addArea()
00447 {
00448 $_SESSION["last_area"] = $_POST["newarea"];
00449 if ($this->writePostData())
00450 {
00451 ilUtil::sendInfo($this->getErrorMessage());
00452 $this->ctrl->setCmd("");
00453 }
00454 $this->editQuestion();
00455 }
00456
00457 function uploadingImage()
00458 {
00459 if ($_GET["q_id"] < 1)
00460 {
00461 $this->save();
00462 }
00463 else
00464 {
00465 $this->writePostData();
00466 $this->editQuestion();
00467 }
00468 }
00469
00470 function uploadingImagemap()
00471 {
00472 if ($_GET["q_id"] < 1)
00473 {
00474 $this->save();
00475 }
00476 else
00477 {
00478 $this->writePostData();
00479 $this->editQuestion();
00480 }
00481 }
00482
00483 function deleteArea()
00484 {
00485 $this->writePostData();
00486 $checked_areas = array();
00487 foreach ($_POST as $key => $value)
00488 {
00489 if (preg_match("/cb_(\d+)/", $key, $matches))
00490 {
00491 array_push($checked_areas, $matches[1]);
00492 }
00493 }
00494 rsort($checked_areas, SORT_NUMERIC);
00495 foreach ($checked_areas as $index)
00496 {
00497 $this->object->deleteArea($index);
00498 }
00499 $this->editQuestion();
00500 }
00501
00510 function writePostData()
00511 {
00512 $result = 0;
00513 $saved = false;
00514
00515 if ($_GET["editmap"])
00516 {
00517 $this->object->coords = array();
00518 foreach ($_POST as $key => $value)
00519 {
00520 if (preg_match("/coords_(\d+)/", $key, $matches))
00521 {
00522 $this->object->coords[$matches[1]] = $value;
00523 }
00524 }
00525 if (isset($_POST["imagemap_x"]))
00526 {
00527 array_push($this->object->coords, $_POST["imagemap_x"] . "," . $_POST["imagemap_y"]);
00528 }
00529 if ($this->ctrl->getCmd() == "saveShape")
00530 {
00531 $coords = "";
00532 switch ($_POST["newarea"])
00533 {
00534 case "rect":
00535 $coords = join($this->object->coords, ",");
00536 break;
00537 case "circle":
00538 if (preg_match("/(\d+)\s*,\s*(\d+)\s+(\d+)\s*,\s*(\d+)/", $this->object->coords[0] . " " . $this->object->coords[1], $matches))
00539 {
00540 $coords = "$matches[1],$matches[2]," . (int)sqrt((($matches[3]-$matches[1])*($matches[3]-$matches[1]))+(($matches[4]-$matches[2])*($matches[4]-$matches[2])));
00541 }
00542 break;
00543 case "poly":
00544 $coords = join($this->object->coords, ",");
00545 break;
00546 }
00547 $this->object->addAnswer($_POST["shapetitle"], 0, count($this->object->answers), $coords, $_POST["newarea"]);
00548 }
00549 }
00550 else
00551 {
00552 if (!$this->checkInput())
00553 {
00554 $result = 1;
00555 }
00556 $this->object->setTitle(ilUtil::stripSlashes($_POST["title"]));
00557 $this->object->setAuthor(ilUtil::stripSlashes($_POST["author"]));
00558 $this->object->setComment(ilUtil::stripSlashes($_POST["comment"]));
00559 include_once "./classes/class.ilObjAdvancedEditing.php";
00560 $questiontext = ilUtil::stripSlashes($_POST["question"], false, ilObjAdvancedEditing::_getUsedHTMLTagsAsString("assessment"));
00561 $this->object->setQuestion($questiontext);
00562 $this->object->setSuggestedSolution($_POST["solution_hint"], 0);
00563 $this->object->setShuffle($_POST["shuffle"]);
00564
00565
00566 $saved = $this->writeOtherPostData($result);
00567
00568 if (($_POST["id"] > 0) or ($result != 1))
00569 {
00570
00571
00572
00573 if (strlen($_FILES['imageName']['tmp_name']) == 0)
00574 {
00575 $this->object->setImageFilename(ilUtil::stripSlashes($_POST["uploaded_image"]));
00576 }
00577 else
00578 {
00579 if ($this->object->getId() <= 0)
00580 {
00581 $this->object->saveToDb();
00582 $this->ctrl->setParameter($this, "q_id", $this->object->getId());
00583 $saved = true;
00584 ilUtil::sendInfo($this->lng->txt("question_saved_for_upload"));
00585 }
00586 $this->object->setImageFilename($_FILES['imageName']['name'], $_FILES['imageName']['tmp_name']);
00587 }
00588
00589
00590 if (empty($_FILES['imagemapName']['tmp_name']))
00591 {
00592 $this->object->setImagemapFilename(ilUtil::stripSlashes($_POST['uploaded_imagemap']));
00593
00594 $this->object->flushAnswers();
00595 foreach ($_POST as $key => $value)
00596 {
00597 if (preg_match("/answer_(\d+)/", $key, $matches))
00598 {
00599 $points = $_POST["points_$matches[1]"];
00600
00601 $this->object->addAnswer(
00602 ilUtil::stripSlashes($_POST["$key"]),
00603 ilUtil::stripSlashes($points),
00604 $matches[1],
00605 ilUtil::stripSlashes($_POST["coords_$matches[1]"]),
00606 ilUtil::stripSlashes($_POST["area_$matches[1]"])
00607 );
00608 }
00609 }
00610 }
00611 else
00612 {
00613 if ($this->object->getId() <= 0)
00614 {
00615 $this->object->saveToDb();
00616 $this->ctrl->setParameter($this, "q_id", $this->object->getId());
00617 $saved = TRUE;
00618 ilUtil::sendInfo($this->lng->txt("question_saved_for_upload"), TRUE);
00619 }
00620 $this->object->setImagemapFilename($_FILES['imagemapName']['name'], $_FILES['imagemapName']['tmp_name']);
00621 }
00622 }
00623 else
00624 {
00625 if (($this->ctrl->getCmd() == "uploadingImage") and (!empty($_FILES['imageName']['tmp_name'])))
00626 {
00627 ilUtil::sendInfo($this->lng->txt("fill_out_all_required_fields_upload_image"));
00628 }
00629 else if (($_POST["cmd"]["uploadingImagemap"]) and (!empty($_FILES['imagemapName']['tmp_name'])))
00630 {
00631 ilUtil::sendInfo($this->lng->txt("fill_out_all_required_fields_upload_imagemap"));
00632 }
00633 }
00634 }
00635 if ($this->ctrl->getCmd() == "addArea")
00636 {
00637 $this->object->saveToDb();
00638 $saved = true;
00639 }
00640 if ($saved)
00641 {
00642 $this->ctrl->setParameter($this, "q_id", $this->object->getId());
00643 }
00644 return $result;
00645 }
00646
00647 function outQuestionForTest($formaction, $active_id, $pass = NULL, $is_postponed = FALSE, $use_post_solutions = FALSE, $show_feedback = FALSE)
00648 {
00649 $test_output = $this->getTestOutput($active_id, $pass, $is_postponed, $use_post_solutions, $show_feedback);
00650 $this->tpl->setVariable("QUESTION_OUTPUT", $test_output);
00651
00652 $this->ctrl->setParameterByClass("ilTestOutputGUI", "formtimestamp", time());
00653 $formaction = $this->ctrl->getLinkTargetByClass("ilTestOutputGUI", "selectImagemapRegion");
00654 include_once "./Modules/Test/classes/class.ilObjTest.php";
00655 if (!ilObjTest::_getUsePreviousAnswers($active_id, true))
00656 {
00657 $pass = ilObjTest::_getPass($active_id);
00658 $info =& $this->object->getSolutionValues($active_id, $pass);
00659 }
00660 else
00661 {
00662 $info =& $this->object->getSolutionValues($active_id, NULL);
00663 }
00664 if (count($info))
00665 {
00666 if (strcmp($info[0]["value1"], "") != 0)
00667 {
00668 $formaction .= "&selImage=" . $info[0]["value1"];
00669 }
00670 }
00671 $this->tpl->setVariable("FORMACTION", $formaction);
00672 }
00673
00674 function getSolutionOutput($active_id, $pass = NULL, $graphicalOutput = FALSE, $result_output = FALSE, $show_question_only = TRUE, $show_feedback = FALSE)
00675 {
00676 $imagepath = $this->object->getImagePathWeb() . $this->object->get_image_filename();
00677 $solutions = array();
00678 if ($active_id)
00679 {
00680 include_once "./Modules/Test/classes/class.ilObjTest.php";
00681 if ((!$showsolution) && !ilObjTest::_getUsePreviousAnswers($active_id, true))
00682 {
00683 if (is_null($pass)) $pass = ilObjTest::_getPass($active_id);
00684 }
00685 $solutions =& $this->object->getSolutionValues($active_id, $pass);
00686 }
00687 else
00688 {
00689 $found_index = -1;
00690 $max_points = 0;
00691 foreach ($this->object->answers as $index => $answer)
00692 {
00693 if ($answer->getPoints() > $max_points)
00694 {
00695 $max_points = $answer->getPoints();
00696 $found_index = $index;
00697 }
00698 }
00699 array_push($solutions, array("value1" => $found_index));
00700 }
00701 $solution_id = -1;
00702 if (is_array($solutions))
00703 {
00704 include_once "./Modules/TestQuestionPool/classes/class.ilImagemapPreview.php";
00705 $preview = new ilImagemapPreview($this->object->getImagePath().$this->object->get_image_filename());
00706 foreach ($solutions as $idx => $solution_value)
00707 {
00708 if (strcmp($solution_value["value1"], "") != 0)
00709 {
00710 $preview->addArea($solution_value["value1"], $this->object->answers[$solution_value["value1"]]->getArea(), $this->object->answers[$solution_value["value1"]]->getCoords(), $this->object->answers[$solution_value["value1"]]->getAnswertext(), "", "", true, $this->linecolor);
00711 $solution_id = $solution_value["value1"];
00712 }
00713 }
00714 $preview->createPreview();
00715 $imagepath = $this->object->getImagePathWeb() . $preview->getPreviewFilename($this->object->getImagePath(), $this->object->get_image_filename());
00716 }
00717
00718
00719 include_once "./classes/class.ilTemplate.php";
00720 $template = new ilTemplate("tpl.il_as_qpl_imagemap_question_output_solution.html", TRUE, TRUE, "Modules/TestQuestionPool");
00721 $solutiontemplate = new ilTemplate("tpl.il_as_tst_solution_output.html",TRUE, TRUE, "Modules/TestQuestionPool");
00722 $questiontext = $this->object->getQuestion();
00723 $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
00724 $template->setVariable("IMG_SRC", "$imagepath");
00725 $template->setVariable("IMG_ALT", $this->lng->txt("imagemap"));
00726 $template->setVariable("IMG_TITLE", $this->lng->txt("imagemap"));
00727 if ($active_id)
00728 {
00729 if ($graphicalOutput)
00730 {
00731
00732 $reached_points = $this->object->getReachedPoints($active_id, $pass);
00733 if ($reached_points == $this->object->getMaximumPoints())
00734 {
00735 $template->setCurrentBlock("icon_ok");
00736 $template->setVariable("ICON_OK", ilUtil::getImagePath("icon_ok.gif"));
00737 $template->setVariable("TEXT_OK", $this->lng->txt("answer_is_right"));
00738 $template->parseCurrentBlock();
00739 }
00740 else
00741 {
00742 $template->setCurrentBlock("icon_ok");
00743 if ($reached_points > 0)
00744 {
00745 $template->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_mostly_ok.gif"));
00746 $template->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_not_correct_but_positive"));
00747 }
00748 else
00749 {
00750 $template->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_not_ok.gif"));
00751 $template->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_wrong"));
00752 }
00753 $template->parseCurrentBlock();
00754 }
00755 }
00756 }
00757
00758 if ($show_feedback)
00759 {
00760 $fb = $this->object->getFeedbackSingleAnswer($solution_id);
00761 if (strlen($fb))
00762 {
00763 $template->setCurrentBlock("feedback");
00764 $template->setVariable("FEEDBACK", $fb);
00765 $template->parseCurrentBlock();
00766 }
00767 }
00768
00769 $questionoutput = $template->get();
00770 $feedback = ($show_feedback) ? $this->getAnswerFeedbackOutput($active_id, $pass) : "";
00771 if (strlen($feedback)) $solutiontemplate->setVariable("FEEDBACK", $feedback);
00772 $solutiontemplate->setVariable("SOLUTION_OUTPUT", $questionoutput);
00773
00774 $solutionoutput = $solutiontemplate->get();
00775 if (!$show_question_only)
00776 {
00777
00778 $pageoutput = $this->getILIASPage();
00779 $solutionoutput = "<div class=\"ilias_content\">" . preg_replace("/(<div( xmlns:xhtml\=\"http:\/\/www.w3.org\/1999\/xhtml\"){0,1} class\=\"ilc_Question\"><\/div>)/ims", "</div><div class=\"ilc_Question\">" . $solutionoutput . "</div><div class=\"ilias_content\">", $pageoutput) . "</div>";
00780 }
00781 return $solutionoutput;
00782 }
00783
00784 function getPreview($show_question_only = FALSE)
00785 {
00786 $imagepath = $this->object->getImagePathWeb() . $this->object->get_image_filename();
00787
00788 include_once "./classes/class.ilTemplate.php";
00789 $template = new ilTemplate("tpl.il_as_qpl_imagemap_question_output.html", TRUE, TRUE, "Modules/TestQuestionPool");
00790 $formaction = "#";
00791 foreach ($this->object->answers as $answer_id => $answer)
00792 {
00793 $template->setCurrentBlock("imagemap_area");
00794 $template->setVariable("HREF_AREA", $formaction);
00795 $template->setVariable("SHAPE", $answer->getArea());
00796 $template->setVariable("COORDS", $answer->getCoords());
00797 $template->setVariable("ALT", ilUtil::prepareFormOutput($answer->getAnswertext()));
00798 $template->setVariable("TITLE", ilUtil::prepareFormOutput($answer->getAnswertext()));
00799 $template->parseCurrentBlock();
00800 }
00801 $questiontext = $this->object->getQuestion();
00802 $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
00803 $template->setVariable("IMG_SRC", "$imagepath");
00804 $template->setVariable("IMG_ALT", $this->lng->txt("imagemap"));
00805 $template->setVariable("IMG_TITLE", $this->lng->txt("imagemap"));
00806 $questionoutput = $template->get();
00807 if (!$show_question_only)
00808 {
00809
00810 $pageoutput = $this->getILIASPage();
00811 $questionoutput = preg_replace("/(<div( xmlns:xhtml\=\"http:\/\/www.w3.org\/1999\/xhtml\"){0,1} class\=\"ilc_Question\"><\/div>)/ims", $questionoutput, $pageoutput);
00812 }
00813 else
00814 {
00815 $questionoutput = preg_replace("/<div[^>]*?>(.*)<\/div>/is", "\\1", $questionoutput);
00816 }
00817
00818 return $questionoutput;
00819 }
00820
00821 function getTestOutput($active_id, $pass = NULL, $is_postponed = FALSE, $use_post_solutions = FALSE, $show_feedback = FALSE)
00822 {
00823
00824 $pageoutput = $this->outQuestionPage("", $is_postponed, $active_id);
00825
00826
00827 $user_solution = "";
00828 if ($active_id)
00829 {
00830 $solutions = NULL;
00831 include_once "./Modules/Test/classes/class.ilObjTest.php";
00832 if (!ilObjTest::_getUsePreviousAnswers($active_id, true))
00833 {
00834 if (is_null($pass)) $pass = ilObjTest::_getPass($active_id);
00835 }
00836 $solutions =& $this->object->getSolutionValues($active_id, $pass);
00837 foreach ($solutions as $idx => $solution_value)
00838 {
00839 $user_solution = $solution_value["value1"];
00840 }
00841 }
00842
00843 $imagepath = $this->object->getImagePathWeb() . $this->object->get_image_filename();
00844 if ($active_id)
00845 {
00846 $solutions = NULL;
00847 include_once "./Modules/Test/classes/class.ilObjTest.php";
00848 if ((!$showsolution) && !ilObjTest::_getUsePreviousAnswers($active_id, true))
00849 {
00850 if (is_null($pass)) $pass = ilObjTest::_getPass($active_id);
00851 }
00852 $solutions =& $this->object->getSolutionValues($active_id, $pass);
00853 include_once "./Modules/TestQuestionPool/classes/class.ilImagemapPreview.php";
00854 $preview = new ilImagemapPreview($this->object->getImagePath().$this->object->get_image_filename());
00855 foreach ($solutions as $idx => $solution_value)
00856 {
00857 if (strcmp($solution_value["value1"], "") != 0)
00858 {
00859 $preview->addArea($solution_value["value1"], $this->object->answers[$solution_value["value1"]]->getArea(), $this->object->answers[$solution_value["value1"]]->getCoords(), $this->object->answers[$solution_value["value1"]]->getAnswertext(), "", "", true, $this->linecolor);
00860 }
00861 }
00862 $preview->createPreview();
00863 $imagepath = $this->object->getImagePathWeb() . $preview->getPreviewFilename($this->object->getImagePath(), $this->object->get_image_filename());
00864 }
00865
00866
00867 include_once "./classes/class.ilTemplate.php";
00868 $template = new ilTemplate("tpl.il_as_qpl_imagemap_question_output.html", TRUE, TRUE, "Modules/TestQuestionPool");
00869 $this->ctrl->setParameterByClass("ilTestOutputGUI", "formtimestamp", time());
00870 $formaction = $this->ctrl->getLinkTargetByClass("ilTestOutputGUI", "selectImagemapRegion");
00871 foreach ($this->object->answers as $answer_id => $answer)
00872 {
00873 $template->setCurrentBlock("imagemap_area");
00874 $template->setVariable("HREF_AREA", $formaction . "&selImage=$answer_id");
00875 $template->setVariable("SHAPE", $answer->getArea());
00876 $template->setVariable("COORDS", $answer->getCoords());
00877 $template->setVariable("ALT", ilUtil::prepareFormOutput($answer->getAnswertext()));
00878 $template->setVariable("TITLE", ilUtil::prepareFormOutput($answer->getAnswertext()));
00879 $template->parseCurrentBlock();
00880 if ($show_feedback)
00881 {
00882 if (strlen($user_solution) && $user_solution == $answer_id)
00883 {
00884 $feedback = $this->object->getFeedbackSingleAnswer($user_solution);
00885 if (strlen($feedback))
00886 {
00887 $template->setCurrentBlock("feedback");
00888 $template->setVariable("FEEDBACK", $feedback);
00889 $template->parseCurrentBlock();
00890 }
00891 }
00892 }
00893 }
00894 $questiontext = $this->object->getQuestion();
00895 $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
00896 $template->setVariable("IMG_SRC", "$imagepath");
00897 $template->setVariable("IMG_ALT", $this->lng->txt("imagemap"));
00898 $template->setVariable("IMG_TITLE", $this->lng->txt("imagemap"));
00899 $questionoutput = $template->get();
00900 $questionoutput = preg_replace("/(<div( xmlns:xhtml\=\"http:\/\/www.w3.org\/1999\/xhtml\"){0,1} class\=\"ilc_Question\"><\/div>)/ims", $questionoutput, $pageoutput);
00901 return $questionoutput;
00902 }
00903
00907 function checkInput()
00908 {
00909 if ((!$_POST["title"]) or (!$_POST["author"]) or (!$_POST["question"]))
00910 {
00911 return false;
00912 }
00913 return true;
00914 }
00915
00916 function addSuggestedSolution()
00917 {
00918 $_SESSION["subquestion_index"] = 0;
00919 if ($_POST["cmd"]["addSuggestedSolution"])
00920 {
00921 if ($this->writePostData())
00922 {
00923 ilUtil::sendInfo($this->getErrorMessage());
00924 $this->editQuestion();
00925 return;
00926 }
00927 if (!$this->checkInput())
00928 {
00929 ilUtil::sendInfo($this->lng->txt("fill_out_all_required_fields_add_answer"));
00930 $this->editQuestion();
00931 return;
00932 }
00933 }
00934 $this->object->saveToDb();
00935 $this->ctrl->setParameter($this, "q_id", $this->object->getId());
00936 $this->tpl->setVariable("HEADER", $this->object->getTitle());
00937 $this->getQuestionTemplate();
00938 parent::addSuggestedSolution();
00939 }
00940
00948 function saveFeedback()
00949 {
00950 include_once "./classes/class.ilObjAdvancedEditing.php";
00951 $this->object->saveFeedbackGeneric(0, ilUtil::stripSlashes($_POST["feedback_incomplete"], false, ilObjAdvancedEditing::_getUsedHTMLTagsAsString("assessment")));
00952 $this->object->saveFeedbackGeneric(1, ilUtil::stripSlashes($_POST["feedback_complete"], false, ilObjAdvancedEditing::_getUsedHTMLTagsAsString("assessment")));
00953 foreach ($this->object->answers as $index => $answer)
00954 {
00955 $this->object->saveFeedbackSingleAnswer($index, ilUtil::stripSlashes($_POST["feedback_answer_$index"], false, ilObjAdvancedEditing::_getUsedHTMLTagsAsString("assessment")));
00956 }
00957 $this->object->cleanupMediaObjectUsage();
00958 parent::saveFeedback();
00959 }
00960
00968 function feedback()
00969 {
00970 $this->tpl->addBlockFile("ADM_CONTENT", "feedback", "tpl.il_as_qpl_imagemap_feedback.html", "Modules/TestQuestionPool");
00971 foreach ($this->object->answers as $index => $answer)
00972 {
00973 $this->tpl->setCurrentBlock("feedback_answer");
00974 $this->tpl->setVariable("FEEDBACK_TEXT_ANSWER", $this->lng->txt("feedback"));
00975 $text = strtoupper($answer->getArea() . " (" . $answer->getCoords() . ")");
00976 if (strlen($answer->getAnswertext()))
00977 {
00978 $text = $answer->getAnswertext() . ": " . $text;
00979 }
00980 $this->tpl->setVariable("ANSWER_TEXT", $this->object->prepareTextareaOutput($text, TRUE));
00981 $this->tpl->setVariable("ANSWER_ID", $index);
00982 $this->tpl->setVariable("VALUE_FEEDBACK_ANSWER", ilUtil::prepareFormOutput($this->object->prepareTextareaOutput($this->object->getFeedbackSingleAnswer($index)), FALSE));
00983 $this->tpl->parseCurrentBlock();
00984 }
00985 $this->tpl->setVariable("FEEDBACK_TEXT", $this->lng->txt("feedback"));
00986 $this->tpl->setVariable("FEEDBACK_COMPLETE", $this->lng->txt("feedback_complete_solution"));
00987 $this->tpl->setVariable("VALUE_FEEDBACK_COMPLETE", ilUtil::prepareFormOutput($this->object->prepareTextareaOutput($this->object->getFeedbackGeneric(1)), FALSE));
00988 $this->tpl->setVariable("FEEDBACK_INCOMPLETE", $this->lng->txt("feedback_incomplete_solution"));
00989 $this->tpl->setVariable("VALUE_FEEDBACK_INCOMPLETE", ilUtil::prepareFormOutput($this->object->prepareTextareaOutput($this->object->getFeedbackGeneric(0)), FALSE));
00990 $this->tpl->setVariable("FEEDBACK_ANSWERS", $this->lng->txt("feedback_answers"));
00991 $this->tpl->setVariable("SAVE", $this->lng->txt("save"));
00992 $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
00993
00994 include_once "./Services/RTE/classes/class.ilRTE.php";
00995 $rtestring = ilRTE::_getRTEClassname();
00996 include_once "./Services/RTE/classes/class.$rtestring.php";
00997 $rte = new $rtestring();
00998 $rte->addPlugin("latex");
00999 $rte->addButton("latex"); $rte->addButton("pastelatex");
01000 include_once "./classes/class.ilObject.php";
01001 $obj_id = $_GET["q_id"];
01002 $obj_type = ilObject::_lookupType($_GET["ref_id"], TRUE);
01003 $rte->addRTESupport($obj_id, $obj_type, "assessment");
01004 }
01005
01013 function setQuestionTabs()
01014 {
01015 global $rbacsystem, $ilTabs;
01016
01017 $this->ctrl->setParameterByClass("ilpageobjectgui", "q_id", $_GET["q_id"]);
01018 include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
01019 $q_type = $this->object->getQuestionType();
01020
01021 if (strlen($q_type))
01022 {
01023 $classname = $q_type . "GUI";
01024 $this->ctrl->setParameterByClass(strtolower($classname), "sel_question_types", $q_type);
01025 $this->ctrl->setParameterByClass(strtolower($classname), "q_id", $_GET["q_id"]);
01026 }
01027
01028 if ($_GET["q_id"])
01029 {
01030 if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
01031 {
01032
01033 $ilTabs->addTarget("edit_content",
01034 $this->ctrl->getLinkTargetByClass("ilPageObjectGUI", "view"),
01035 array("view", "insert", "exec_pg"),
01036 "", "", $force_active);
01037 }
01038
01039
01040 $ilTabs->addTarget("preview",
01041 $this->ctrl->getLinkTargetByClass("ilPageObjectGUI", "preview"),
01042 array("preview"),
01043 "ilPageObjectGUI", "", $force_active);
01044 }
01045
01046 $force_active = false;
01047 if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
01048 {
01049 $url = "";
01050 if ($classname) $url = $this->ctrl->getLinkTargetByClass($classname, "editQuestion");
01051 if (array_key_exists("imagemap_x", $_POST))
01052 {
01053 $force_active = true;
01054 }
01055
01056 $ilTabs->addTarget("edit_properties",
01057 $url,
01058 array("editQuestion", "save", "cancel", "addSuggestedSolution",
01059 "cancelExplorer", "linkChilds", "removeSuggestedSolution",
01060 "uploadingImage", "uploadingImagemap", "addArea",
01061 "deletearea", "saveShape", "back", "saveEdit"),
01062 $classname, "", $force_active);
01063 }
01064
01065 if ($_GET["q_id"])
01066 {
01067 $ilTabs->addTarget("feedback",
01068 $this->ctrl->getLinkTargetByClass($classname, "feedback"),
01069 array("feedback", "saveFeedback"),
01070 $classname, "");
01071 }
01072
01073
01074 if ($_GET["q_id"])
01075 {
01076 $ilTabs->addTarget("statistics",
01077 $this->ctrl->getLinkTargetByClass($classname, "assessment"),
01078 array("assessment"),
01079 $classname, "");
01080 }
01081
01082 if (($_GET["calling_test"] > 0) || ($_GET["test_ref_id"] > 0))
01083 {
01084 $ref_id = $_GET["calling_test"];
01085 if (strlen($ref_id) == 0) $ref_id = $_GET["test_ref_id"];
01086 $ilTabs->setBackTarget($this->lng->txt("backtocallingtest"), "ilias.php?baseClass=ilObjTestGUI&cmd=questions&ref_id=$ref_id");
01087 }
01088 else
01089 {
01090 $ilTabs->setBackTarget($this->lng->txt("qpl"), $this->ctrl->getLinkTargetByClass("ilobjquestionpoolgui", "questions"));
01091 }
01092 }
01093 }
01094 ?>