ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilImageMapEditorGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3
15{
19 protected $ctrl;
20
24 protected $tpl;
25
29 protected $lng;
30
34 protected $toolbar;
35
39 public function __construct($a_media_object)
40 {
41 global $DIC;
42
43 $this->ctrl = $DIC->ctrl();
44 $this->tpl = $DIC["tpl"];
45 $this->lng = $DIC->language();
46 $this->toolbar = $DIC->toolbar();
47 $this->media_object = $a_media_object;
48 }
49
53 public function executeCommand()
54 {
55 $ilCtrl = $this->ctrl;
57
58 $next_class = $ilCtrl->getNextClass($this);
59 $cmd = $ilCtrl->getCmd();
60
61 switch ($next_class) {
62 case "ilinternallinkgui":
63 require_once("./Services/Link/classes/class.ilInternalLinkGUI.php");
64 $link_gui = new ilInternalLinkGUI("Media_Media", 0);
65 $link_gui->setSetLinkTargetScript(
66 $ilCtrl->getLinkTarget(
67 $this,
68 "setInternalLink"
69 )
70 );
71 $link_gui->filterLinkType("File");
72 $ret = $ilCtrl->forwardCommand($link_gui);
73 break;
74
75 default:
76 require_once("./Services/MediaObjects/classes/class.ilObjMediaObjectGUI.php");
78 if (isset($_POST["editImagemapForward"]) ||
79 isset($_POST["editImagemapForward_x"]) ||
80 isset($_POST["editImagemapForward_y"])) {
81 $cmd = "editImagemapForward";
82 }
83 $ret = $this->$cmd();
84 break;
85 }
86
87 return $ret;
88 }
89
93 public function editMapAreas()
94 {
95 $ilCtrl = $this->ctrl;
97 $ilToolbar = $this->toolbar;
98
99 $_SESSION["il_map_edit_target_script"] = $ilCtrl->getLinkTarget(
100 $this,
101 "addArea",
102 "",
103 false,
104 false
105 );
106 $this->handleMapParameters();
107
108 $this->tpl = new ilTemplate("tpl.map_edit.html", true, true, "Services/MediaObjects");
109 $this->tpl->setVariable("FORMACTION", $ilCtrl->getFormAction($this));
110
111 // create/update imagemap work copy
112 $this->makeMapWorkCopy();
113
114 $output = $this->getImageMapOutput();
115 $this->tpl->setVariable("IMAGE_MAP", $output);
116
117 $this->tpl->setVariable("TOOLBAR", $this->getToolbar()->getHTML());
118
119 // table
120 $this->tpl->setVariable("MAP_AREA_TABLE", $this->getImageMapTableHTML());
121
122 return $this->tpl->get();
123 }
124
130 public function getToolbar()
131 {
132 $ilCtrl = $this->ctrl;
135
136 // toolbar
137 $tb = new ilToolbarGUI();
138 $tb->setFormAction($ilCtrl->getFormAction($this));
139 include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
140 $options = array(
141 "WholePicture" => $lng->txt("cont_WholePicture"),
142 "Rect" => $lng->txt("cont_Rect"),
143 "Circle" => $lng->txt("cont_Circle"),
144 "Poly" => $lng->txt("cont_Poly"),
145 );
146 $si = new ilSelectInputGUI($lng->txt("cont_shape"), "shape");
147 $si->setOptions($options);
148 $tb->addInputItem($si, true);
149 $tb->addFormButton($lng->txt("cont_add_area"), "addNewArea");
150
151
152 // highlight mode
153 /* if (strtolower(get_class($this)) == "ilimagemapeditorgui")
154 {
155 $st_item = $this->media_object->getMediaItem("Standard");
156 $tb->addSeparator();
157 $options = ilMapArea::getAllHighlightModes();
158 $hl = new ilSelectInputGUI($lng->txt("cont_highlight_mode"), "highlight_mode");
159 $hl->setOptions($options);
160 // $hl->setValue($st_item->getHighlightMode());
161 $tb->addInputItem($hl, true);
162 $options = ilMapArea::getAllHighlightClasses();
163 $hc = new ilSelectInputGUI($lng->txt("cont_highlight_class"), "highlight_class");
164 $hc->setOptions($options);
165 // $hc->setValue($st_item->getHighlightClass());
166 $tb->addInputItem($hc, false);
167 $tb->addFormButton($lng->txt("cont_set"), "setHighlight");
168 }*/
169
170 return $tb;
171 }
172
173
179 public function getEditorTitle()
180 {
182
183 return $lng->txt("cont_imagemap");
184 }
185
186
190 public function getImageMapTableHTML()
191 {
192 include_once("./Services/MediaObjects/classes/class.ilImageMapTableGUI.php");
193 $image_map_table = new ilImageMapTableGUI($this, "editMapAreas", $this->media_object);
194 return $image_map_table->getHTML();
195 }
196
200 public function handleMapParameters()
201 {
202 if ($_GET["ref_id"] != "") {
203 $_SESSION["il_map_edit_ref_id"] = $_GET["ref_id"];
204 }
205
206 if ($_GET["obj_id"] != "") {
207 $_SESSION["il_map_edit_obj_id"] = $_GET["obj_id"];
208 }
209
210 if ($_GET["hier_id"] != "") {
211 $_SESSION["il_map_edit_hier_id"] = $_GET["hier_id"];
212 }
213
214 if ($_GET["pc_id"] != "") {
215 $_SESSION["il_map_edit_pc_id"] = $_GET["pc_id"];
216 }
217 }
218
222 public function showImageMap()
223 {
224 $item = new ilMediaItem($_GET["item_id"]);
225 $item->outputMapWorkCopy();
226 }
227
231 public function updateAreas()
232 {
234 $ilCtrl = $this->ctrl;
235
236 $st_item = $this->media_object->getMediaItem("Standard");
237 $max = ilMapArea::_getMaxNr($st_item->getId());
238 for ($i = 1; $i <= $max; $i++) {
239 $area = new ilMapArea($st_item->getId(), $i);
240 $area->setTitle(ilUtil::stripSlashes($_POST["name_" . $i]));
241 $area->setHighlightMode(ilUtil::stripSlashes($_POST["hl_mode_" . $i]));
242 $area->setHighlightClass(ilUtil::stripSlashes($_POST["hl_class_" . $i]));
243 $area->update();
244 }
245
246 ilUtil::sendSuccess($lng->txt("cont_saved_map_data"), true);
247 $ilCtrl->redirect($this, "editMapAreas");
248 }
249
253 public function addNewArea()
254 {
255 switch ($_POST["shape"]) {
256 case "WholePicture": return $this->linkWholePicture();
257 case "Rect": return $this->addRectangle();
258 case "Circle": return $this->addCircle();
259 case "Poly": return $this->addPolygon();
260 }
261 }
262
263
267 public function linkWholePicture()
268 {
269 $this->clearSessionVars();
270 $_SESSION["il_map_edit_area_type"] = "WholePicture";
271
272 return $this->editMapArea(false, false, true);
273 }
274
278 public function addRectangle()
279 {
280 $this->clearSessionVars();
281 $_SESSION["il_map_edit_area_type"] = "Rect";
282 return $this->addArea(false);
283 }
284
288 public function addCircle()
289 {
290 $this->clearSessionVars();
291 $_SESSION["il_map_edit_area_type"] = "Circle";
292 return $this->addArea(false);
293 }
294
298 public function addPolygon()
299 {
300 $this->clearSessionVars();
301 $_SESSION["il_map_edit_area_type"] = "Poly";
302 return $this->addArea(false);
303 }
304
308 public function clearSessionVars()
309 {
310 $_SESSION["il_map_area_nr"] = "";
311 $_SESSION["il_map_edit_coords"] = "";
312 $_SESSION["il_map_edit_mode"] = "";
313 $_SESSION["il_map_el_href"] = "";
314 $_SESSION["il_map_il_type"] = "";
315 $_SESSION["il_map_il_ltype"] = "";
316 $_SESSION["il_map_il_target"] = "";
317 $_SESSION["il_map_il_targetframe"] = "";
318 $_SESSION["il_map_edit_area_type"] = "";
319 }
320
324 public function addArea($a_handle = true)
325 {
326
327 // handle map parameters
328 if ($a_handle) {
329 $this->handleMapParameters();
330 }
331
332 $area_type = $_SESSION["il_map_edit_area_type"];
333 $coords = $_SESSION["il_map_edit_coords"];
334 include_once("./Services/MediaObjects/classes/class.ilMapArea.php");
335 $cnt_coords = ilMapArea::countCoords($coords);
336
337 // decide what to do next
338 switch ($area_type) {
339 // Rectangle
340 case "Rect":
341 if ($cnt_coords < 2) {
342 $html = $this->editMapArea(true, false, false);
343 return $html;
344 } elseif ($cnt_coords == 2) {
345 return $this->editMapArea(false, true, true);
346 }
347 break;
348
349 // Circle
350 case "Circle":
351 if ($cnt_coords <= 1) {
352 return $this->editMapArea(true, false, false);
353 } else {
354 if ($cnt_coords == 2) {
355 $c = explode(",", $coords);
356 $coords = $c[0] . "," . $c[1] . ","; // determine radius
357 $coords .= round(sqrt(pow(abs($c[3] - $c[1]), 2) + pow(abs($c[2] - $c[0]), 2)));
358 }
359 $_SESSION["il_map_edit_coords"] = $coords;
360
361 return $this->editMapArea(false, true, true);
362 }
363 break;
364
365 // Polygon
366 case "Poly":
367 if ($cnt_coords < 1) {
368 return $this->editMapArea(true, false, false);
369 } elseif ($cnt_coords < 3) {
370 return $this->editMapArea(true, true, false);
371 } else {
372 return $this->editMapArea(true, true, true);
373 }
374 break;
375
376 // Whole picture
377 case "WholePicture":
378 return $this->editMapArea(false, false, true);
379 break;
380 }
381 }
382
391 public function editMapArea(
392 $a_get_next_coordinate = false,
393 $a_output_new_area = false,
394 $a_save_form = false,
395 $a_edit_property = "",
396 $a_area_nr = 0
397 ) {
398 $ilCtrl = $this->ctrl;
401
402 $area_type = $_SESSION["il_map_edit_area_type"];
403 $coords = $_SESSION["il_map_edit_coords"];
404 include_once("./Services/MediaObjects/classes/class.ilMapArea.php");
405 $cnt_coords = ilMapArea::countCoords($coords);
406
407 $this->tpl = new ilTemplate("tpl.map_edit.html", true, true, "Services/MediaObjects");
408
409 $this->tpl->setVariable("FORMACTION", $ilCtrl->getFormAction($this));
410
411 if ($a_edit_property != "link") {
412 switch ($area_type) {
413 // rectangle
414 case "Rect":
415 if ($cnt_coords == 0) {
416 ilUtil::sendInfo($lng->txt("cont_click_tl_corner"));
417 }
418 if ($cnt_coords == 1) {
419 ilUtil::sendInfo($lng->txt("cont_click_br_corner"));
420 }
421 break;
422
423 // circle
424 case "Circle":
425 if ($cnt_coords == 0) {
426 ilUtil::sendInfo($lng->txt("cont_click_center"));
427 }
428 if ($cnt_coords == 1) {
429 ilUtil::sendInfo($lng->txt("cont_click_circle"));
430 }
431 break;
432
433 // polygon
434 case "Poly":
435 if ($cnt_coords == 0) {
436 ilUtil::sendInfo($lng->txt("cont_click_starting_point"));
437 } elseif ($cnt_coords < 3) {
438 ilUtil::sendInfo($lng->txt("cont_click_next_point"));
439 } else {
440 ilUtil::sendInfo($lng->txt("cont_click_next_or_save"));
441 }
442 break;
443 }
444 }
445
446
447 // map properties input fields (name and link)
448 if ($a_save_form) {
449 if ($a_edit_property != "shape") {
450 // prepare link gui
451 $ilCtrl->setParameter($this, "linkmode", "map");
452 include_once("./Services/Link/classes/class.ilInternalLinkGUI.php");
453 $this->tpl->setCurrentBlock("int_link_prep");
454 $this->tpl->setVariable("INT_LINK_PREP", ilInternalLinkGUI::getInitHTML(
455 $ilCtrl->getLinkTargetByClass(
456 "ilinternallinkgui",
457 "",
458 false,
459 true,
460 false
461 )
462 ));
463 $this->tpl->parseCurrentBlock();
464 }
465 $form = $this->initAreaEditingForm($a_edit_property);
466 $this->tpl->setVariable("FORM", $form->getHTML());
467 }
468
469 $this->makeMapWorkCopy(
470 $a_edit_property,
471 $a_area_nr,
472 $a_output_new_area,
473 $area_type,
474 $coords
475 );
476
477 $edit_mode = ($a_get_next_coordinate)
478 ? "get_coords"
479 : (($a_output_new_area)
480 ? "new_area"
481 :"");
482 $output = $this->getImageMapOutput($edit_mode);
483 $this->tpl->setVariable("IMAGE_MAP", $output);
484
485 return $this->tpl->get();
486 }
487
493 public function initAreaEditingForm($a_edit_property)
494 {
496 $ilCtrl = $this->ctrl;
497
498 include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
499 $form = new ilPropertyFormGUI();
500 $form->setOpenTag(false);
501 $form->setCloseTag(false);
502
503 // link
504 if ($a_edit_property != "shape") {
505 //
506 $radg = new ilRadioGroupInputGUI($lng->txt("cont_link"), "area_link_type");
507 if ($_SESSION["il_map_il_ltype"] != "int") {
508 if ($_SESSION["il_map_el_href"] == "") {
509 $radg->setValue("no");
510 } else {
511 $radg->setValue("ext");
512 }
513 } else {
514 $radg->setValue("int");
515 }
516
517 // external link
518 $ext = new ilRadioOption($lng->txt("cont_link_ext"), "ext");
519 $radg->addOption($ext);
520
521 $ti = new ilTextInputGUI("", "area_link_ext");
522 $ti->setMaxLength(800);
523 $ti->setSize(50);
524 if ($_SESSION["il_map_el_href"] != "") {
525 $ti->setValue($_SESSION["il_map_el_href"]);
526 } else {
527 $ti->setValue("http://");
528 }
529 $ext->addSubItem($ti);
530
531 // internal link
532 $int = new ilRadioOption($lng->txt("cont_link_int"), "int");
533 $radg->addOption($int);
534
535 $ne = new ilNonEditableValueGUI("", "", true);
536 $link_str = "";
537 if ($_SESSION["il_map_il_target"] != "") {
538 $link_str = $this->getMapAreaLinkString(
539 $_SESSION["il_map_il_target"],
540 $_SESSION["il_map_il_type"],
541 $_SESSION["il_map_il_targetframe"]
542 );
543 }
544 $ne->setValue(
545 $link_str .
546 '&nbsp;<a id="iosEditInternalLinkTrigger" href="#">' .
547 "[" . $lng->txt("cont_get_link") . "]" .
548 '</a>'
549 );
550 $int->addSubItem($ne);
551
552 // no link
553 $no = new ilRadioOption($lng->txt("cont_link_no"), "no");
554 $radg->addOption($no);
555
556 $form->addItem($radg);
557 }
558
559
560 // name
561 if ($a_edit_property != "link" && $a_edit_property != "shape") {
562 $ti = new ilTextInputGUI($lng->txt("cont_name"), "area_name");
563 $ti->setMaxLength(200);
564 $ti->setSize(20);
565 $form->addItem($ti);
566 }
567
568 // save and cancel commands
569 if ($a_edit_property == "") {
570 $form->setTitle($lng->txt("cont_new_area"));
571 $form->addCommandButton("saveArea", $lng->txt("save"));
572 } else {
573 $form->setTitle($lng->txt("cont_new_area"));
574 $form->addCommandButton("saveArea", $lng->txt("save"));
575 }
576
577 // $form->setFormAction($ilCtrl->getFormAction($this));
578
579 return $form;
580 }
581
585 public function makeMapWorkCopy(
586 $a_edit_property = "",
587 $a_area_nr = 0,
588 $a_output_new_area = false,
589 $a_area_type = "",
590 $a_coords = ""
591 ) {
592 // create/update imagemap work copy
593 $st_item = $this->media_object->getMediaItem("Standard");
594
595 if ($a_edit_property == "shape") {
596 $st_item->makeMapWorkCopy($a_area_nr, true); // exclude area currently being edited
597 } else {
598 $st_item->makeMapWorkCopy($a_area_nr, false);
599 }
600
601 if ($a_output_new_area) {
602 $st_item->addAreaToMapWorkCopy($a_area_type, $a_coords);
603 }
604 }
605
609 public function getImageMapOutput($a_map_edit_mode = "")
610 {
611 $ilCtrl = $this->ctrl;
612
613 $st_item = $this->media_object->getMediaItem("Standard");
614
615 // output image map
616 $xml = "<dummy>";
617 $xml .= $this->getAliasXML();
618 $xml .= $this->media_object->getXML(IL_MODE_OUTPUT);
619 $xml .= $this->getAdditionalPageXML();
620 $xml .= "</dummy>";
621 $xsl = file_get_contents("./Services/COPage/xsl/page.xsl");
622 //echo htmlentities($xml); exit;
623 $args = array( '/_xml' => $xml, '/_xsl' => $xsl );
624 $xh = xslt_create();
625 $wb_path = ilUtil::getWebspaceDir("output") . "/";
626 $mode = "media";
627 //echo htmlentities($ilCtrl->getLinkTarget($this, "showImageMap"));
628
629 $random = new \ilRandom();
630 $params = array('map_edit_mode' => $a_map_edit_mode,
631 'map_item' => $st_item->getId(),
632 'map_mob_id' => $this->media_object->getId(),
633 'mode' => $mode,
634 'media_mode' => 'enable',
635 'image_map_link' => $ilCtrl->getLinkTarget($this, "showImageMap", "", false, false),
636 'link_params' => "ref_id=" . $_GET["ref_id"] . "&rand=" . $random->int(1, 999999),
637 'ref_id' => $_GET["ref_id"],
638 'pg_frame' => "",
639 'enlarge_path' => ilUtil::getImagePath("enlarge.svg"),
640 'webspace_path' => $wb_path);
641 $output = xslt_process($xh, "arg:/_xml", "arg:/_xsl", null, $args, $params);
642 echo xslt_error($xh);
643 xslt_free($xh);
644
645 $output = $this->outputPostProcessing($output);
646
647 return $output;
648 }
649
655 public function getAdditionalPageXML()
656 {
657 return "";
658 }
659
666 public function outputPostProcessing($a_output)
667 {
668 return $a_output;
669 }
670
671 public function getAliasXML()
672 {
673 return $this->media_object->getXML(IL_MODE_ALIAS);
674 }
675
685 public function getMapAreaLinkString($a_target, $a_type, $a_frame)
686 {
688
689 $t_arr = explode("_", $a_target);
690 if ($a_frame != "") {
691 $frame_str = " (" . $a_frame . " Frame)";
692 }
693 switch ($a_type) {
694 case "StructureObject":
695 require_once("./Modules/LearningModule/classes/class.ilLMObject.php");
696 $title = ilLMObject::_lookupTitle($t_arr[count($t_arr) - 1]);
697 $link_str = $lng->txt("chapter") .
698 ": " . $title . " [" . $t_arr[count($t_arr) - 1] . "]" . $frame_str;
699 break;
700
701 case "PageObject":
702 require_once("./Modules/LearningModule/classes/class.ilLMObject.php");
703 $title = ilLMObject::_lookupTitle($t_arr[count($t_arr) - 1]);
704 $link_str = $lng->txt("page") .
705 ": " . $title . " [" . $t_arr[count($t_arr) - 1] . "]" . $frame_str;
706 break;
707
708 case "GlossaryItem":
709 $term = new ilGlossaryTerm($t_arr[count($t_arr) - 1]);
710 $link_str = $lng->txt("term") .
711 ": " . $term->getTerm() . " [" . $t_arr[count($t_arr) - 1] . "]" . $frame_str;
712 break;
713
714 case "MediaObject":
715 require_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
716 $mob = new ilObjMediaObject($t_arr[count($t_arr) - 1]);
717 $link_str = $lng->txt("mob") .
718 ": " . $mob->getTitle() . " [" . $t_arr[count($t_arr) - 1] . "]" . $frame_str;
719 break;
720
721 case "RepositoryItem":
722 $title = ilObject::_lookupTitle(
723 ilObject::_lookupObjId($t_arr[count($t_arr) - 1])
724 );
725 $link_str = $lng->txt("obj_" . $t_arr[count($t_arr) - 2]) .
726 ": " . $title . " [" . $t_arr[count($t_arr) - 1] . "]" . $frame_str;
727 break;
728 }
729
730 return $link_str;
731 }
732
736 public function editImagemapForward()
737 {
739
740 if ($_SESSION["il_map_edit_coords"] != "") {
741 $_SESSION["il_map_edit_coords"] .= ",";
742 }
743
744 $_SESSION["il_map_edit_coords"] .= $_POST["editImagemapForward_x"] . "," .
745 $_POST["editImagemapForward_y"];
746
747 // call editing script
748 ilUtil::redirect($_SESSION["il_map_edit_target_script"]);
749 }
750
754 public static function _recoverParameters()
755 {
756 $_GET["ref_id"] = $_SESSION["il_map_edit_ref_id"];
757 $_GET["obj_id"] = $_SESSION["il_map_edit_obj_id"];
758 $_GET["hier_id"] = $_SESSION["il_map_edit_hier_id"];
759 $_GET["pc_id"] = $_SESSION["il_map_edit_pc_id"];
760 }
761
765 public function saveArea()
766 {
768 $ilCtrl = $this->ctrl;
769
770 switch ($_SESSION["il_map_edit_mode"]) {
771 // save edited link
772 case "edit_link":
773 $st_item = $this->media_object->getMediaItem("Standard");
774 $max = ilMapArea::_getMaxNr($st_item->getId());
775 $area = new ilMapArea($st_item->getId(), $_SESSION["il_map_area_nr"]);
776
777 if ($_POST["area_link_type"] == IL_INT_LINK) {
778 $area->setLinkType(IL_INT_LINK);
779 $area->setType($_SESSION["il_map_il_type"]);
780 $area->setTarget($_SESSION["il_map_il_target"]);
781 $area->setTargetFrame($_SESSION["il_map_il_targetframe"]);
782 } else {
783 $area->setLinkType(IL_EXT_LINK);
784 if ($_POST["area_link_type"] != IL_NO_LINK) {
785 $area->setHref(ilUtil::stripSlashes($_POST["area_link_ext"]));
786 } else {
787 $area->setHref("");
788 }
789 }
790 $area->update();
791 break;
792
793 // save edited shape
794 case "edit_shape":
795 $st_item = $this->media_object->getMediaItem("Standard");
796 $max = ilMapArea::_getMaxNr($st_item->getId());
797 $area = new ilMapArea($st_item->getId(), $_SESSION["il_map_area_nr"]);
798
799 $area->setShape($_SESSION["il_map_edit_area_type"]);
800 $area->setCoords($_SESSION["il_map_edit_coords"]);
801 $area->update();
802 break;
803
804 // save new area
805 default:
806 $area_type = $_SESSION["il_map_edit_area_type"];
807 $coords = $_SESSION["il_map_edit_coords"];
808
809 $st_item = $this->media_object->getMediaItem("Standard");
810 $max = ilMapArea::_getMaxNr($st_item->getId());
811
812 // make new area object
813 $area = new ilMapArea();
814 $area->setItemId($st_item->getId());
815 $area->setShape($area_type);
816 $area->setCoords($coords);
817 $area->setNr($max + 1);
818 $area->setTitle(ilUtil::stripSlashes($_POST["area_name"]));
819 switch ($_POST["area_link_type"]) {
820 case "ext":
821 $area->setLinkType(IL_EXT_LINK);
822 $area->setHref($_POST["area_link_ext"]);
823 break;
824
825 case "int":
826 $area->setLinkType(IL_INT_LINK);
827 $area->setType($_SESSION["il_map_il_type"]);
828 $area->setTarget($_SESSION["il_map_il_target"]);
829 $area->setTargetFrame($_SESSION["il_map_il_targetframe"]);
830 break;
831 }
832
833 // put area into item and update media object
834 $st_item->addMapArea($area);
835 $this->media_object->update();
836 break;
837 }
838
839 //$this->initMapParameters();
840 ilUtil::sendSuccess($lng->txt("cont_saved_map_area"), true);
841 $ilCtrl->redirect($this, "editMapAreas");
842 }
843
847 public function setInternalLink()
848 {
849 $_SESSION["il_map_il_type"] = $_GET["linktype"];
850 $_SESSION["il_map_il_ltype"] = "int";
851
852 $_SESSION["il_map_il_target"] = $_GET["linktarget"];
853 $_SESSION["il_map_il_targetframe"] = $_GET["linktargetframe"];
854 $_SESSION["il_map_il_anchor"] = $_GET["linkanchor"];
855 switch ($_SESSION["il_map_edit_mode"]) {
856 case "edit_link":
857 return $this->setLink();
858 break;
859
860 default:
861 return $this->addArea();
862 break;
863 }
864 }
865
869 public function setLink($a_handle = true)
870 {
872 $ilCtrl = $this->ctrl;
873
874 if ($a_handle) {
875 $this->handleMapParameters();
876 }
877 if ($_SESSION["il_map_area_nr"] != "") {
878 $_POST["area"][0] = $_SESSION["il_map_area_nr"];
879 }
880 if (!isset($_POST["area"])) {
881 ilUtil::sendFailure($lng->txt("no_checkbox"), true);
882 $ilCtrl->redirect($this, "editMapAreas");
883 }
884
885 if (count($_POST["area"]) > 1) {
886 //$this->ilias->raiseError($this->lng->txt("cont_select_max_one_item"),$this->ilias->error_obj->MESSAGE);
887 ilUtil::sendFailure($lng->txt("cont_select_max_one_item"), true);
888 $ilCtrl->redirect($this, "editMapAreas");
889 }
890
891
892 if ($_SESSION["il_map_edit_mode"] != "edit_link") {
893 $_SESSION["il_map_area_nr"] = $_POST["area"][0];
894 $_SESSION["il_map_il_ltype"] = $this->getLinkTypeOfArea($_POST["area"][0]);
895 $_SESSION["il_map_edit_mode"] = "edit_link";
896 $_SESSION["il_map_edit_target_script"] = $ilCtrl->getLinkTarget($this, "setLink");
897 if ($_SESSION["il_map_il_ltype"] == IL_INT_LINK) {
898 $_SESSION["il_map_il_type"] = $this->getTypeOfArea($_POST["area"][0]);
899 $_SESSION["il_map_il_target"] = $this->getTargetOfArea($_POST["area"][0]);
900 $_SESSION["il_map_il_targetframe"] = $this->getTargetFrameOfArea($_POST["area"][0]);
901 } else {
902 $_SESSION["il_map_el_href"] = $this->getHrefOfArea($_POST["area"][0]);
903 }
904 }
905
906 return $this->editMapArea(false, false, true, "link", $_POST["area"][0]);
907 }
908
912 public function getLinkTypeOfArea($a_nr)
913 {
914 $st_item = $this->media_object->getMediaItem("Standard");
915 $area = $st_item->getMapArea($a_nr);
916 return $area->getLinkType();
917 }
918
922 public function getTypeOfArea($a_nr)
923 {
924 $st_item = $this->media_object->getMediaItem("Standard");
925 $area = $st_item->getMapArea($a_nr);
926 return $area->getType();
927 }
928
932 public function getTargetOfArea($a_nr)
933 {
934 $st_item = $this->media_object->getMediaItem("Standard");
935 $area = $st_item->getMapArea($a_nr);
936 return $area->getTarget();
937 }
938
942 public function getTargetFrameOfArea($a_nr)
943 {
944 $st_item = $this->media_object->getMediaItem("Standard");
945 $area = $st_item->getMapArea($a_nr);
946 return $area->getTargetFrame();
947 }
948
952 public function getHrefOfArea($a_nr)
953 {
954 $st_item = $this->media_object->getMediaItem("Standard");
955 $area = $st_item->getMapArea($a_nr);
956 return $area->getHref();
957 }
958
962 public function deleteAreas()
963 {
964 $ilCtrl = $this->ctrl;
966
967 if (!isset($_POST["area"])) {
968 ilUtil::sendFailure($lng->txt("no_checkbox"), true);
969 $ilCtrl->redirect($this, "editMapAreas");
970 }
971
972 $st_item = $this->media_object->getMediaItem("Standard");
973 $max = ilMapArea::_getMaxNr($st_item->getId());
974
975 if (count($_POST["area"]) > 0) {
976 $i = 0;
977
978 foreach ($_POST["area"] as $area_nr) {
979 $st_item->deleteMapArea($area_nr - $i);
980 $i++;
981 }
982
983 $this->media_object->update();
984 ilUtil::sendSuccess($lng->txt("cont_areas_deleted"), true);
985 }
986
987 $ilCtrl->redirect($this, "editMapAreas");
988 }
989
993 public function editLink()
994 {
995 $_SESSION["il_map_edit_coords"] = "";
996 $_SESSION["il_map_edit_mode"] = "";
997 $_SESSION["il_map_el_href"] = "";
998 $_SESSION["il_map_il_type"] = "";
999 $_SESSION["il_map_il_ltype"] = "";
1000 $_SESSION["il_map_il_target"] = "";
1001 $_SESSION["il_map_il_targetframe"] = "";
1002 $_SESSION["il_map_area_nr"] = "";
1003 return $this->setLink(false);
1004 }
1005
1009 public function editShapeWholePicture()
1010 {
1011 $this->clearSessionVars();
1012 $_SESSION["il_map_edit_area_type"] = "WholePicture";
1013 return $this->setShape(false);
1014 }
1015
1019 public function editShapeRectangle()
1020 {
1021 $this->clearSessionVars();
1022 $_SESSION["il_map_edit_area_type"] = "Rect";
1023 return $this->setShape(false);
1024 }
1025
1029 public function editShapeCircle()
1030 {
1031 $this->clearSessionVars();
1032 $_SESSION["il_map_edit_area_type"] = "Circle";
1033 return $this->setShape(false);
1034 }
1035
1039 public function editShapePolygon()
1040 {
1041 $this->clearSessionVars();
1042 $_SESSION["il_map_edit_area_type"] = "Poly";
1043 return $this->setShape(false);
1044 }
1045
1049 public function setShape($a_handle = true)
1050 {
1051 $lng = $this->lng;
1052 $ilCtrl = $this->ctrl;
1053
1054 if ($a_handle) {
1055 $this->handleMapParameters();
1056 }
1057 if ($_POST["areatype2"] != "") {
1058 $_SESSION["il_map_edit_area_type"] = $_POST["areatype2"];
1059 }
1060 if ($_SESSION["il_map_area_nr"] != "") {
1061 $_POST["area"][0] = $_SESSION["il_map_area_nr"];
1062 }
1063 if (!isset($_POST["area"])) {
1064 ilUtil::sendFailure($lng->txt("no_checkbox"), true);
1065 $ilCtrl->redirect($this, "editMapAreas");
1066 }
1067
1068 if (count($_POST["area"]) > 1) {
1069 ilUtil::sendFailure($lng->txt("cont_select_max_one_item"), true);
1070 $ilCtrl->redirect($this, "editMapAreas");
1071 }
1072
1073 if ($_SESSION["il_map_edit_mode"] != "edit_shape") {
1074 $_SESSION["il_map_area_nr"] = $_POST["area"][0];
1075 $_SESSION["il_map_edit_mode"] = "edit_shape";
1076 $_SESSION["il_map_edit_target_script"] = $ilCtrl->getLinkTarget($this, "setShape", "", false, false);
1077 }
1078
1079
1080 $area_type = $_SESSION["il_map_edit_area_type"];
1081 $coords = $_SESSION["il_map_edit_coords"];
1082 $cnt_coords = ilMapArea::countCoords($coords);
1083
1084 // decide what to do next
1085 switch ($area_type) {
1086 // Rectangle
1087 case "Rect":
1088 if ($cnt_coords < 2) {
1089 return $this->editMapArea(true, false, false, "shape", $_POST["area"][0]);
1090 } elseif ($cnt_coords == 2) {
1091 return $this->saveArea();
1092 }
1093 break;
1094
1095 // Circle
1096 case "Circle":
1097 if ($cnt_coords <= 1) {
1098 return $this->editMapArea(true, false, false, "shape", $_POST["area"][0]);
1099 } else {
1100 if ($cnt_coords == 2) {
1101 $c = explode(",", $coords);
1102 $coords = $c[0] . "," . $c[1] . ","; // determine radius
1103 $coords .= round(sqrt(pow(abs($c[3] - $c[1]), 2) + pow(abs($c[2] - $c[0]), 2)));
1104 }
1105 $_SESSION["il_map_edit_coords"] = $coords;
1106
1107 return $this->saveArea();
1108 }
1109 break;
1110
1111 // Polygon
1112 case "Poly":
1113 if ($cnt_coords < 1) {
1114 return $this->editMapArea(true, false, false, "shape", $_POST["area"][0]);
1115 } elseif ($cnt_coords < 3) {
1116 return $this->editMapArea(true, true, false, "shape", $_POST["area"][0]);
1117 } else {
1118 return $this->editMapArea(true, true, true, "shape", $_POST["area"][0]);
1119 }
1120 break;
1121
1122 // Whole Picture
1123 case "WholePicture":
1124 return $this->saveArea();
1125 }
1126 }
1127
1134 public function setHighlight()
1135 {
1136 $ilCtrl = $this->ctrl;
1137 $lng = $this->lng;
1138
1139 $st_item = $this->media_object->getMediaItem("Standard");
1140 $st_item->setHighlightMode(ilUtil::stripSlashes($_POST["highlight_mode"]));
1141 $st_item->setHighlightClass(ilUtil::stripSlashes($_POST["highlight_class"]));
1142 $st_item->update();
1143
1144 ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
1145 $ilCtrl->redirect($this, "editMapAreas");
1146 }
1147}
$_GET["client_id"]
$_POST["username"]
$_SESSION["AccountId"]
An exception for terminatinating execution or to throw for unit testing.
const IL_INT_LINK
const IL_EXT_LINK
const IL_NO_LINK
const IL_MODE_ALIAS
const IL_MODE_OUTPUT
User interface class for map editor.
static _recoverParameters()
Recover parameters from session variables (static)
editImagemapForward()
Get image map coordinates.
getEditorTitle()
Get editor title.
linkWholePicture()
Link the whole picture.
setShape($a_handle=true)
edit shape of existing map area
makeMapWorkCopy( $a_edit_property="", $a_area_nr=0, $a_output_new_area=false, $a_area_type="", $a_coords="")
Make work file for editing.
executeCommand()
Execute current command.
setLink($a_handle=true)
Set link.
editMapArea( $a_get_next_coordinate=false, $a_output_new_area=false, $a_save_form=false, $a_edit_property="", $a_area_nr=0)
Edit a single map area.
clearSessionVars()
Clear Session Vars.
getTargetOfArea($a_nr)
Get Target of Area (only internal link)
getMapAreaLinkString($a_target, $a_type, $a_frame)
Get text name of internal link.
__construct($a_media_object)
Constructor.
getTypeOfArea($a_nr)
Get Type of Area (only internal link)
handleMapParameters()
handle parameter during map area editing (storing to session)
setInternalLink()
Set internal link.
editLink()
Edit existing link.
getTargetFrameOfArea($a_nr)
Get TargetFrame of Area (only internal link)
getHrefOfArea($a_nr)
Get Href of Area (only external link)
getImageMapOutput($a_map_edit_mode="")
Render the image map.
addPolygon()
Add a new polygon.
getAdditionalPageXML()
Get additional page xml (to be overwritten)
setHighlight()
Set highlight settings.
getImageMapTableHTML()
Get table HTML.
editShapeWholePicture()
Edit an existing shape (make it a whole picture link)
getLinkTypeOfArea($a_nr)
Get Link Type of Area.
editShapeRectangle()
Edit an existing shape (make it a rectangle)
saveArea()
Save new or updated map area.
initAreaEditingForm($a_edit_property)
Init area editing form.
outputPostProcessing($a_output)
Output post processing.
editShapePolygon()
Edit an existing shape (make it a polygon)
addRectangle()
Add a new rectangle.
editShapeCircle()
Edit an existing shape (make it a circle)
addArea($a_handle=true)
Handle adding new area process.
TableGUI class for image map editor.
Class ilInternalLinkGUI.
static getInitHTML($a_url)
Get initialisation HTML to use interna link editing.
static _lookupTitle($a_obj_id)
Lookup title.
Class ilMapArea.
static _getMaxNr($a_item_id)
get maximum nr of media item (static)
static countCoords($c)
count the number of coordinates (x,y) in a coordinate string (format: "x1,y1,x2,y2,...
Class ilMediaItem Media Item, component of a media object (file or reference)
This class represents a non editable value in a property form.
static includePresentationJS($a_tpl=null)
Include media object presentation JS.
Class ilObjMediaObject.
static _lookupObjId($a_id)
static _lookupTitle($a_id)
lookup object title
This class represents a property form user interface.
This class represents a property in a property form.
This class represents an option in a radio group.
This class represents a selection list property in a property form.
special template class to simplify handling of ITX/PEAR
This class represents a text property in a property form.
static getWebspaceDir($mode="filesystem")
get webspace directory
static redirect($a_script)
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
$c
Definition: cli.php:37
global $DIC
Definition: goto.php:24
xslt_error(&$proc)
xslt_free(&$proc)
xslt_create()
$i
Definition: metadata.php:24
$xml
Definition: metadata.php:332
$ret
Definition: parser.php:6