ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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  function __construct($a_media_object)
20  {
21  $this->media_object = $a_media_object;
22  }
23 
27  function executeCommand()
28  {
29  global $ilCtrl, $tpl;
30 
31  $next_class = $ilCtrl->getNextClass($this);
32  $cmd = $ilCtrl->getCmd();
33 
34  switch($next_class)
35  {
36  case "ilinternallinkgui":
37  require_once("./Services/Link/classes/class.ilInternalLinkGUI.php");
38  $link_gui = new ilInternalLinkGUI("Media_Media", 0);
39  $link_gui->setMode("link");
40  $link_gui->setSetLinkTargetScript(
41  $ilCtrl->getLinkTarget($this,
42  "setInternalLink"));
43  $link_gui->filterLinkType("File");
44  $link_gui->setMode("asynch");
45  $ret = $ilCtrl->forwardCommand($link_gui);
46  break;
47 
48  default:
49  require_once("./Services/MediaObjects/classes/class.ilObjMediaObjectGUI.php");
51  if (isset($_POST["editImagemapForward"]) ||
52  isset($_POST["editImagemapForward_x"]) ||
53  isset($_POST["editImagemapForward_y"]))
54  {
55  $cmd = "editImagemapForward";
56  }
57  $ret = $this->$cmd();
58  break;
59  }
60 
61  return $ret;
62  }
63 
67  function editMapAreas()
68  {
69  global $ilCtrl, $lng, $ilToolbar;
70 
71  $_SESSION["il_map_edit_target_script"] = $ilCtrl->getLinkTarget($this, "addArea",
72  "", false, false);
73  $this->handleMapParameters();
74 
75  $this->tpl = new ilTemplate("tpl.map_edit.html", true, true, "Services/MediaObjects");
76  $this->tpl->setVariable("FORMACTION", $ilCtrl->getFormAction($this));
77 
78  // create/update imagemap work copy
79  $this->makeMapWorkCopy();
80 
81  $output = $this->getImageMapOutput();
82  $this->tpl->setVariable("IMAGE_MAP", $output);
83 
84  $this->tpl->setVariable("TOOLBAR", $this->getToolbar()->getHTML());
85 
86  // table
87  $this->tpl->setVariable("MAP_AREA_TABLE", $this->getImageMapTableHTML());
88 
89  return $this->tpl->get();
90  }
91 
97  function getToolbar()
98  {
99  global $ilCtrl, $lng, $tpl;
100 
101  // toolbar
102  $tb = new ilToolbarGUI();
103  $tb->setFormAction($ilCtrl->getFormAction($this));
104  include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
105  $options = array(
106  "WholePicture" => $lng->txt("cont_WholePicture"),
107  "Rect" => $lng->txt("cont_Rect"),
108  "Circle" => $lng->txt("cont_Circle"),
109  "Poly" => $lng->txt("cont_Poly"),
110  );
111  $si = new ilSelectInputGUI($lng->txt("cont_shape"), "shape");
112  $si->setOptions($options);
113  $tb->addInputItem($si, true);
114  $tb->addFormButton($lng->txt("cont_add_area"), "addNewArea");
115 
116 
117  // highlight mode
118 /* if (strtolower(get_class($this)) == "ilimagemapeditorgui")
119  {
120  $st_item = $this->media_object->getMediaItem("Standard");
121  $tb->addSeparator();
122  $options = ilMapArea::getAllHighlightModes();
123  $hl = new ilSelectInputGUI($lng->txt("cont_highlight_mode"), "highlight_mode");
124  $hl->setOptions($options);
125 // $hl->setValue($st_item->getHighlightMode());
126  $tb->addInputItem($hl, true);
127  $options = ilMapArea::getAllHighlightClasses();
128  $hc = new ilSelectInputGUI($lng->txt("cont_highlight_class"), "highlight_class");
129  $hc->setOptions($options);
130 // $hc->setValue($st_item->getHighlightClass());
131  $tb->addInputItem($hc, false);
132  $tb->addFormButton($lng->txt("cont_set"), "setHighlight");
133  }*/
134 
135  return $tb;
136  }
137 
138 
144  function getEditorTitle()
145  {
146  global $lng;
147 
148  return $lng->txt("cont_imagemap");
149  }
150 
151 
156  {
157  include_once("./Services/MediaObjects/classes/class.ilImageMapTableGUI.php");
158  $image_map_table = new ilImageMapTableGUI($this, "editMapAreas", $this->media_object);
159  return $image_map_table->getHTML();
160  }
161 
166  {
167  if($_GET["ref_id"] != "")
168  {
169  $_SESSION["il_map_edit_ref_id"] = $_GET["ref_id"];
170  }
171 
172  if($_GET["obj_id"] != "")
173  {
174  $_SESSION["il_map_edit_obj_id"] = $_GET["obj_id"];
175  }
176 
177  if($_GET["hier_id"] != "")
178  {
179  $_SESSION["il_map_edit_hier_id"] = $_GET["hier_id"];
180  }
181 
182  if($_GET["pc_id"] != "")
183  {
184  $_SESSION["il_map_edit_pc_id"] = $_GET["pc_id"];
185  }
186  }
187 
191  function showImageMap()
192  {
193  $item = new ilMediaItem($_GET["item_id"]);
194  $item->outputMapWorkCopy();
195  }
196 
200  function updateAreas()
201  {
202  global $lng, $ilCtrl;
203 
204  $st_item = $this->media_object->getMediaItem("Standard");
205  $max = ilMapArea::_getMaxNr($st_item->getId());
206  for ($i=1; $i<=$max; $i++)
207  {
208  $area = new ilMapArea($st_item->getId(), $i);
209  $area->setTitle(ilUtil::stripSlashes($_POST["name_".$i]));
210  $area->setHighlightMode(ilUtil::stripSlashes($_POST["hl_mode_".$i]));
211  $area->setHighlightClass(ilUtil::stripSlashes($_POST["hl_class_".$i]));
212  $area->update();
213  }
214 
215  ilUtil::sendSuccess($lng->txt("cont_saved_map_data"), true);
216  $ilCtrl->redirect($this, "editMapAreas");
217  }
218 
222  function addNewArea()
223  {
224  switch ($_POST["shape"])
225  {
226  case "WholePicture": return $this->linkWholePicture();
227  case "Rect": return $this->addRectangle();
228  case "Circle": return $this->addCircle();
229  case "Poly": return $this->addPolygon();
230  }
231  }
232 
233 
237  function linkWholePicture()
238  {
239  $this->clearSessionVars();
240  $_SESSION["il_map_edit_area_type"] = "WholePicture";
241 
242  return $this->editMapArea(false, false, true);
243  }
244 
248  function addRectangle()
249  {
250  $this->clearSessionVars();
251  $_SESSION["il_map_edit_area_type"] = "Rect";
252  return $this->addArea(false);
253  }
254 
258  function addCircle()
259  {
260  $this->clearSessionVars();
261  $_SESSION["il_map_edit_area_type"] = "Circle";
262  return $this->addArea(false);
263  }
264 
268  function addPolygon()
269  {
270  $this->clearSessionVars();
271  $_SESSION["il_map_edit_area_type"] = "Poly";
272  return $this->addArea(false);
273  }
274 
278  function clearSessionVars()
279  {
280  $_SESSION["il_map_area_nr"] = "";
281  $_SESSION["il_map_edit_coords"] = "";
282  $_SESSION["il_map_edit_mode"] = "";
283  $_SESSION["il_map_el_href"] = "";
284  $_SESSION["il_map_il_type"] = "";
285  $_SESSION["il_map_il_ltype"] = "";
286  $_SESSION["il_map_il_target"] = "";
287  $_SESSION["il_map_il_targetframe"] = "";
288  $_SESSION["il_map_edit_area_type"] = "";
289  }
290 
294  function addArea($a_handle = true)
295  {
296 
297  // handle map parameters
298  if($a_handle)
299  {
300  $this->handleMapParameters();
301  }
302 
303  $area_type = $_SESSION["il_map_edit_area_type"];
304  $coords = $_SESSION["il_map_edit_coords"];
305  include_once("./Services/MediaObjects/classes/class.ilMapArea.php");
306  $cnt_coords = ilMapArea::countCoords($coords);
307 
308  // decide what to do next
309  switch ($area_type)
310  {
311  // Rectangle
312  case "Rect" :
313  if ($cnt_coords < 2)
314  {
315  $html = $this->editMapArea(true, false, false);
316  return $html;
317  }
318  else if ($cnt_coords == 2)
319  {
320  return $this->editMapArea(false, true, true);
321  }
322  break;
323 
324  // Circle
325  case "Circle":
326  if ($cnt_coords <= 1)
327  {
328  return $this->editMapArea(true, false, false);
329  }
330  else
331  {
332  if ($cnt_coords == 2)
333  {
334  $c = explode(",",$coords);
335  $coords = $c[0].",".$c[1].","; // determine radius
336  $coords .= round(sqrt(pow(abs($c[3]-$c[1]),2)+pow(abs($c[2]-$c[0]),2)));
337  }
338  $_SESSION["il_map_edit_coords"] = $coords;
339 
340  return $this->editMapArea(false, true, true);
341  }
342  break;
343 
344  // Polygon
345  case "Poly":
346  if ($cnt_coords < 1)
347  {
348  return $this->editMapArea(true, false, false);
349  }
350  else if ($cnt_coords < 3)
351  {
352  return $this->editMapArea(true, true, false);
353  }
354  else
355  {
356  return $this->editMapArea(true, true, true);
357  }
358  break;
359 
360  // Whole picture
361  case "WholePicture":
362  return $this->editMapArea(false, false, true);
363  break;
364  }
365  }
366 
375  function editMapArea($a_get_next_coordinate = false, $a_output_new_area = false,
376  $a_save_form = false, $a_edit_property = "", $a_area_nr = 0)
377  {
378  global $ilCtrl, $lng, $tpl;
379 
380  $area_type = $_SESSION["il_map_edit_area_type"];
381  $coords = $_SESSION["il_map_edit_coords"];
382  include_once("./Services/MediaObjects/classes/class.ilMapArea.php");
383  $cnt_coords = ilMapArea::countCoords($coords);
384 
385  $this->tpl = new ilTemplate("tpl.map_edit.html", true, true, "Services/MediaObjects");
386 
387  $this->tpl->setVariable("FORMACTION", $ilCtrl->getFormAction($this));
388 
389  if ($a_edit_property != "link")
390  {
391  switch ($area_type)
392  {
393  // rectangle
394  case "Rect" :
395  if ($cnt_coords == 0)
396  {
397  ilUtil::sendInfo($lng->txt("cont_click_tl_corner"));
398  }
399  if ($cnt_coords == 1)
400  {
401  ilUtil::sendInfo($lng->txt("cont_click_br_corner"));
402  }
403  break;
404 
405  // circle
406  case "Circle" :
407  if ($cnt_coords == 0)
408  {
409  ilUtil::sendInfo($lng->txt("cont_click_center"));
410  }
411  if ($cnt_coords == 1)
412  {
413  ilUtil::sendInfo($lng->txt("cont_click_circle"));
414  }
415  break;
416 
417  // polygon
418  case "Poly" :
419  if ($cnt_coords == 0)
420  {
421  ilUtil::sendInfo($lng->txt("cont_click_starting_point"));
422  }
423  else if ($cnt_coords < 3)
424  {
425  ilUtil::sendInfo($lng->txt("cont_click_next_point"));
426  }
427  else
428  {
429  ilUtil::sendInfo($lng->txt("cont_click_next_or_save"));
430  }
431  break;
432  }
433  }
434 
435 
436  // map properties input fields (name and link)
437  if ($a_save_form)
438  {
439  if ($a_edit_property != "shape")
440  {
441  // prepare link gui
442  $ilCtrl->setParameter($this, "linkmode", "map");
443  include_once("./Services/Link/classes/class.ilInternalLinkGUI.php");
444  $this->tpl->setCurrentBlock("int_link_prep");
445  $this->tpl->setVariable("INT_LINK_PREP", ilInternalLinkGUI::getInitHTML(
446  $ilCtrl->getLinkTargetByClass("ilinternallinkgui",
447  "", false, true, false)));
448  $this->tpl->parseCurrentBlock();
449  }
450  $form = $this->initAreaEditingForm($a_edit_property);
451  $this->tpl->setVariable("FORM", $form->getHTML());
452  }
453 
454  $this->makeMapWorkCopy($a_edit_property, $a_area_nr,
455  $a_output_new_area, $area_type, $coords);
456 
457  $edit_mode = ($a_get_next_coordinate)
458  ? "get_coords"
459  : (($a_output_new_area)
460  ? "new_area"
461  :"");
462  $output = $this->getImageMapOutput($edit_mode);
463  $this->tpl->setVariable("IMAGE_MAP", $output);
464 
465  return $this->tpl->get();
466  }
467 
473  public function initAreaEditingForm($a_edit_property)
474  {
475  global $lng, $ilCtrl;
476 
477  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
478  $form = new ilPropertyFormGUI();
479  $form->setOpenTag(false);
480  $form->setCloseTag(false);
481 
482  // link
483  if ($a_edit_property != "shape")
484  {
485  //
486  $radg = new ilRadioGroupInputGUI($lng->txt("cont_link"), "area_link_type");
487  if ($_SESSION["il_map_il_ltype"] != "int")
488  {
489  if ($_SESSION["il_map_el_href"] == "")
490  {
491  $radg->setValue("no");
492  }
493  else
494  {
495  $radg->setValue("ext");
496  }
497  }
498  else
499  {
500  $radg->setValue("int");
501  }
502 
503  // external link
504  $ext = new ilRadioOption($lng->txt("cont_link_ext"), "ext");
505  $radg->addOption($ext);
506 
507  $ti = new ilTextInputGUI("", "area_link_ext");
508  $ti->setMaxLength(200);
509  $ti->setSize(50);
510  if ($_SESSION["il_map_el_href"] != "")
511  {
512  $ti->setValue($_SESSION["il_map_el_href"]);
513  }
514  else
515  {
516  $ti->setValue("http://");
517  }
518  $ext->addSubItem($ti);
519 
520  // internal link
521  $int = new ilRadioOption($lng->txt("cont_link_int"), "int");
522  $radg->addOption($int);
523 
524  $ne = new ilNonEditableValueGUI("", "", true);
525  $link_str = "";
526  if($_SESSION["il_map_il_target"] != "")
527  {
528  $link_str = $this->getMapAreaLinkString($_SESSION["il_map_il_target"],
529  $_SESSION["il_map_il_type"], $_SESSION["il_map_il_targetframe"]);
530  }
531  $ne->setValue($link_str.
532  '&nbsp;<a id="iosEditInternalLinkTrigger" href="#">'.
533  "[".$lng->txt("cont_get_link")."]".
534  '</a>'
535  );
536  $int->addSubItem($ne);
537 
538  // no link
539  $no = new ilRadioOption($lng->txt("cont_link_no"), "no");
540  $radg->addOption($no);
541 
542  $form->addItem($radg);
543  }
544 
545 
546  // name
547  if ($a_edit_property != "link" && $a_edit_property != "shape")
548  {
549  $ti = new ilTextInputGUI($lng->txt("cont_name"), "area_name");
550  $ti->setMaxLength(200);
551  $ti->setSize(20);
552  $form->addItem($ti);
553  }
554 
555  // save and cancel commands
556  if ($a_edit_property == "")
557  {
558  $form->setTitle($lng->txt("cont_new_area"));
559  $form->addCommandButton("saveArea", $lng->txt("save"));
560  }
561  else
562  {
563  $form->setTitle($lng->txt("cont_new_area"));
564  $form->addCommandButton("saveArea", $lng->txt("save"));
565  }
566 
567 // $form->setFormAction($ilCtrl->getFormAction($this));
568 
569  return $form;
570  }
571 
575  function makeMapWorkCopy($a_edit_property = "", $a_area_nr = 0,
576  $a_output_new_area = false, $a_area_type = "", $a_coords = "")
577  {
578  // create/update imagemap work copy
579  $st_item = $this->media_object->getMediaItem("Standard");
580 
581  if ($a_edit_property == "shape")
582  {
583  $st_item->makeMapWorkCopy($a_area_nr, true); // exclude area currently being edited
584  }
585  else
586  {
587  $st_item->makeMapWorkCopy($a_area_nr, false);
588  }
589 
590  if ($a_output_new_area)
591  {
592  $st_item->addAreaToMapWorkCopy($a_area_type, $a_coords);
593  }
594  }
595 
599  function getImageMapOutput($a_map_edit_mode = "")
600  {
601  global $ilCtrl;
602 
603  $st_item = $this->media_object->getMediaItem("Standard");
604 
605  // output image map
606  $xml = "<dummy>";
607  $xml.= $this->getAliasXML();
608  $xml.= $this->media_object->getXML(IL_MODE_OUTPUT);
609  $xml.= $this->getAdditionalPageXML();
610  $xml.="</dummy>";
611  $xsl = file_get_contents("./Services/COPage/xsl/page.xsl");
612 //echo htmlentities($xml); exit;
613  $args = array( '/_xml' => $xml, '/_xsl' => $xsl );
614  $xh = xslt_create();
615  $wb_path = ilUtil::getWebspaceDir("output")."/";
616  $mode = "media";
617 //echo htmlentities($ilCtrl->getLinkTarget($this, "showImageMap"));
618  $params = array ('map_edit_mode' => $a_map_edit_mode,
619  'map_item' => $st_item->getId(),
620  'map_mob_id' => $this->media_object->getId(),
621  'mode' => $mode,
622  'media_mode' => 'enable',
623  'image_map_link' => $ilCtrl->getLinkTarget($this, "showImageMap", "", false, false),
624  'link_params' => "ref_id=".$_GET["ref_id"]."&rand=".rand(1,999999),
625  'ref_id' => $_GET["ref_id"],
626  'pg_frame' => "",
627  'enlarge_path' => ilUtil::getImagePath("enlarge.svg"),
628  'webspace_path' => $wb_path);
629  $output = xslt_process($xh,"arg:/_xml","arg:/_xsl",NULL,$args, $params);
630  echo xslt_error($xh);
631  xslt_free($xh);
632 
633  $output = $this->outputPostProcessing($output);
634 
635  return $output;
636  }
637 
644  {
645  return "";
646  }
647 
654  function outputPostProcessing($a_output)
655  {
656  return $a_output;
657  }
658 
659  function getAliasXML()
660  {
661  return $this->media_object->getXML(IL_MODE_ALIAS);
662  }
663 
673  function getMapAreaLinkString($a_target, $a_type, $a_frame)
674  {
675  global $lng;
676 
677  $t_arr = explode("_", $a_target);
678  if ($a_frame != "")
679  {
680  $frame_str = " (".$a_frame." Frame)";
681  }
682  switch($a_type)
683  {
684  case "StructureObject":
685  require_once("./Modules/LearningModule/classes/class.ilLMObject.php");
686  $title = ilLMObject::_lookupTitle($t_arr[count($t_arr) - 1]);
687  $link_str = $lng->txt("chapter").
688  ": ".$title." [".$t_arr[count($t_arr) - 1]."]".$frame_str;
689  break;
690 
691  case "PageObject":
692  require_once("./Modules/LearningModule/classes/class.ilLMObject.php");
693  $title = ilLMObject::_lookupTitle($t_arr[count($t_arr) - 1]);
694  $link_str = $lng->txt("page").
695  ": ".$title." [".$t_arr[count($t_arr) - 1]."]".$frame_str;
696  break;
697 
698  case "GlossaryItem":
699  require_once("./Modules/Glossary/classes/class.ilGlossaryTerm.php");
700  $term = new ilGlossaryTerm($t_arr[count($t_arr) - 1]);
701  $link_str = $lng->txt("term").
702  ": ".$term->getTerm()." [".$t_arr[count($t_arr) - 1]."]".$frame_str;
703  break;
704 
705  case "MediaObject":
706  require_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
707  $mob = new ilObjMediaObject($t_arr[count($t_arr) - 1]);
708  $link_str = $lng->txt("mob").
709  ": ".$mob->getTitle()." [".$t_arr[count($t_arr) - 1]."]".$frame_str;
710  break;
711 
712  case "RepositoryItem":
714  ilObject::_lookupObjId($t_arr[count($t_arr) - 1]));
715  $link_str = $lng->txt("obj_".$t_arr[count($t_arr) - 2]).
716  ": ".$title." [".$t_arr[count($t_arr) - 1]."]".$frame_str;
717  break;
718  }
719 
720  return $link_str;
721  }
722 
727  {
729 
730  if ($_SESSION["il_map_edit_coords"] != "")
731  {
732  $_SESSION["il_map_edit_coords"] .= ",";
733  }
734 
735  $_SESSION["il_map_edit_coords"] .= $_POST["editImagemapForward_x"].",".
736  $_POST["editImagemapForward_y"];
737 
738  // call editing script
739  ilUtil::redirect($_SESSION["il_map_edit_target_script"]);
740  }
741 
745  static function _recoverParameters()
746  {
747  $_GET["ref_id"] = $_SESSION["il_map_edit_ref_id"];
748  $_GET["obj_id"] = $_SESSION["il_map_edit_obj_id"];
749  $_GET["hier_id"] = $_SESSION["il_map_edit_hier_id"];
750  $_GET["pc_id"] = $_SESSION["il_map_edit_pc_id"];
751  }
752 
756  function saveArea()
757  {
758  global $lng, $ilCtrl;
759 
760  switch ($_SESSION["il_map_edit_mode"])
761  {
762  // save edited link
763  case "edit_link":
764  $st_item = $this->media_object->getMediaItem("Standard");
765  $max = ilMapArea::_getMaxNr($st_item->getId());
766  $area = new ilMapArea($st_item->getId(), $_SESSION["il_map_area_nr"]);
767 
768  if ($_POST["area_link_type"] == IL_INT_LINK)
769  {
770  $area->setLinkType(IL_INT_LINK);
771  $area->setType($_SESSION["il_map_il_type"]);
772  $area->setTarget($_SESSION["il_map_il_target"]);
773  $area->setTargetFrame($_SESSION["il_map_il_targetframe"]);
774  }
775  else
776  {
777  $area->setLinkType(IL_EXT_LINK);
778  if ($_POST["area_link_type"] != IL_NO_LINK)
779  {
780  $area->setHref(ilUtil::stripSlashes($_POST["area_link_ext"]));
781  }
782  else
783  {
784  $area->setHref("");
785  }
786  }
787  $area->update();
788  break;
789 
790  // save edited shape
791  case "edit_shape":
792  $st_item = $this->media_object->getMediaItem("Standard");
793  $max = ilMapArea::_getMaxNr($st_item->getId());
794  $area = new ilMapArea($st_item->getId(), $_SESSION["il_map_area_nr"]);
795 
796  $area->setShape($_SESSION["il_map_edit_area_type"]);
797  $area->setCoords($_SESSION["il_map_edit_coords"]);
798  $area->update();
799  break;
800 
801  // save new area
802  default:
803  $area_type = $_SESSION["il_map_edit_area_type"];
804  $coords = $_SESSION["il_map_edit_coords"];
805 
806  $st_item = $this->media_object->getMediaItem("Standard");
807  $max = ilMapArea::_getMaxNr($st_item->getId());
808 
809  // make new area object
810  $area = new ilMapArea();
811  $area->setItemId($st_item->getId());
812  $area->setShape($area_type);
813  $area->setCoords($coords);
814  $area->setNr($max + 1);
815  $area->setTitle(ilUtil::stripSlashes($_POST["area_name"]));
816  switch($_POST["area_link_type"])
817  {
818  case "ext":
819  $area->setLinkType(IL_EXT_LINK);
820  $area->setHref($_POST["area_link_ext"]);
821  break;
822 
823  case "int":
824  $area->setLinkType(IL_INT_LINK);
825  $area->setType($_SESSION["il_map_il_type"]);
826  $area->setTarget($_SESSION["il_map_il_target"]);
827  $area->setTargetFrame($_SESSION["il_map_il_targetframe"]);
828  break;
829  }
830 
831  // put area into item and update media object
832  $st_item->addMapArea($area);
833  $this->media_object->update();
834  break;
835  }
836 
837  //$this->initMapParameters();
838  ilUtil::sendSuccess($lng->txt("cont_saved_map_area"), true);
839  $ilCtrl->redirect($this, "editMapAreas");
840  }
841 
845  function setInternalLink()
846  {
847  $_SESSION["il_map_il_type"] = $_GET["linktype"];
848  $_SESSION["il_map_il_ltype"] = "int";
849 
850  $_SESSION["il_map_il_target"] = $_GET["linktarget"];
851  $_SESSION["il_map_il_targetframe"] = $_GET["linktargetframe"];
852  switch ($_SESSION["il_map_edit_mode"])
853  {
854  case "edit_link":
855  return $this->setLink();
856  break;
857 
858  default:
859  return $this->addArea();
860  break;
861  }
862  }
863 
867  function setLink($a_handle = true)
868  {
869  global $lng, $ilCtrl;
870 
871  if($a_handle)
872  {
873  $this->handleMapParameters();
874  }
875  if ($_SESSION["il_map_area_nr"] != "")
876  {
877  $_POST["area"][0] = $_SESSION["il_map_area_nr"];
878  }
879  if (!isset($_POST["area"]))
880  {
881  ilUtil::sendFailure($lng->txt("no_checkbox"), true);
882  $ilCtrl->redirect($this, "editMapAreas");
883  }
884 
885  if (count($_POST["area"]) > 1)
886  {
887  //$this->ilias->raiseError($this->lng->txt("cont_select_max_one_item"),$this->ilias->error_obj->MESSAGE);
888  ilUtil::sendFailure($lng->txt("cont_select_max_one_item"), true);
889  $ilCtrl->redirect($this, "editMapAreas");
890  }
891 
892 
893  if ($_SESSION["il_map_edit_mode"] != "edit_link")
894  {
895  $_SESSION["il_map_area_nr"] = $_POST["area"][0];
896  $_SESSION["il_map_il_ltype"] = $this->getLinkTypeOfArea($_POST["area"][0]);
897  $_SESSION["il_map_edit_mode"] = "edit_link";
898  $_SESSION["il_map_edit_target_script"] = $ilCtrl->getLinkTarget($this, "setLink");
899  if ($_SESSION["il_map_il_ltype"] == IL_INT_LINK)
900  {
901  $_SESSION["il_map_il_type"] = $this->getTypeOfArea($_POST["area"][0]);
902  $_SESSION["il_map_il_target"] = $this->getTargetOfArea($_POST["area"][0]);
903  $_SESSION["il_map_il_targetframe"] = $this->getTargetFrameOfArea($_POST["area"][0]);
904  }
905  else
906  {
907  $_SESSION["il_map_el_href"] = $this->getHrefOfArea($_POST["area"][0]);
908  }
909  }
910 
911  return $this->editMapArea(false, false, true, "link", $_POST["area"][0]);
912  }
913 
917  function getLinkTypeOfArea($a_nr)
918  {
919  $st_item = $this->media_object->getMediaItem("Standard");
920  $area = $st_item->getMapArea($a_nr);
921  return $area->getLinkType();
922  }
923 
927  function getTypeOfArea($a_nr)
928  {
929  $st_item = $this->media_object->getMediaItem("Standard");
930  $area = $st_item->getMapArea($a_nr);
931  return $area->getType();
932  }
933 
937  function getTargetOfArea($a_nr)
938  {
939  $st_item = $this->media_object->getMediaItem("Standard");
940  $area = $st_item->getMapArea($a_nr);
941  return $area->getTarget();
942  }
943 
947  function getTargetFrameOfArea($a_nr)
948  {
949  $st_item = $this->media_object->getMediaItem("Standard");
950  $area = $st_item->getMapArea($a_nr);
951  return $area->getTargetFrame();
952  }
953 
957  function getHrefOfArea($a_nr)
958  {
959  $st_item = $this->media_object->getMediaItem("Standard");
960  $area = $st_item->getMapArea($a_nr);
961  return $area->getHref();
962  }
963 
967  function deleteAreas()
968  {
969  global $ilCtrl, $lng;
970 
971  if (!isset($_POST["area"]))
972  {
973  ilUtil::sendFailure($lng->txt("no_checkbox"), true);
974  $ilCtrl->redirect($this, "editMapAreas");
975  }
976 
977  $st_item = $this->media_object->getMediaItem("Standard");
978  $max = ilMapArea::_getMaxNr($st_item->getId());
979 
980  if (count($_POST["area"]) > 0)
981  {
982  $i = 0;
983 
984  foreach ($_POST["area"] as $area_nr)
985  {
986  $st_item->deleteMapArea($area_nr - $i);
987  $i++;
988  }
989 
990  $this->media_object->update();
991  ilUtil::sendSuccess($lng->txt("cont_areas_deleted"), true);
992  }
993 
994  $ilCtrl->redirect($this, "editMapAreas");
995  }
996 
1000  function editLink()
1001  {
1002  $_SESSION["il_map_edit_coords"] = "";
1003  $_SESSION["il_map_edit_mode"] = "";
1004  $_SESSION["il_map_el_href"] = "";
1005  $_SESSION["il_map_il_type"] = "";
1006  $_SESSION["il_map_il_ltype"] = "";
1007  $_SESSION["il_map_il_target"] = "";
1008  $_SESSION["il_map_il_targetframe"] = "";
1009  $_SESSION["il_map_area_nr"] = "";
1010  return $this->setLink(false);
1011  }
1012 
1017  {
1018  $this->clearSessionVars();
1019  $_SESSION["il_map_edit_area_type"] = "WholePicture";
1020  return $this->setShape(false);
1021  }
1022 
1027  {
1028  $this->clearSessionVars();
1029  $_SESSION["il_map_edit_area_type"] = "Rect";
1030  return $this->setShape(false);
1031  }
1032 
1036  function editShapeCircle()
1037  {
1038  $this->clearSessionVars();
1039  $_SESSION["il_map_edit_area_type"] = "Circle";
1040  return $this->setShape(false);
1041  }
1042 
1046  function editShapePolygon()
1047  {
1048  $this->clearSessionVars();
1049  $_SESSION["il_map_edit_area_type"] = "Poly";
1050  return $this->setShape(false);
1051  }
1052 
1056  function setShape($a_handle = true)
1057  {
1058  global $lng, $ilCtrl;
1059 
1060  if($a_handle)
1061  {
1062  $this->handleMapParameters();
1063  }
1064  if($_POST["areatype2"] != "")
1065  {
1066  $_SESSION["il_map_edit_area_type"] = $_POST["areatype2"];
1067  }
1068  if ($_SESSION["il_map_area_nr"] != "")
1069  {
1070  $_POST["area"][0] = $_SESSION["il_map_area_nr"];
1071  }
1072  if (!isset($_POST["area"]))
1073  {
1074  ilUtil::sendFailure($lng->txt("no_checkbox"), true);
1075  $ilCtrl->redirect($this, "editMapAreas");
1076  }
1077 
1078  if (count($_POST["area"]) > 1)
1079  {
1080  ilUtil::sendFailure($lng->txt("cont_select_max_one_item"), true);
1081  $ilCtrl->redirect($this, "editMapAreas");
1082  }
1083 
1084  if ($_SESSION["il_map_edit_mode"] != "edit_shape")
1085  {
1086  $_SESSION["il_map_area_nr"] = $_POST["area"][0];
1087  $_SESSION["il_map_edit_mode"] = "edit_shape";
1088  $_SESSION["il_map_edit_target_script"] = $ilCtrl->getLinkTarget($this, "setShape", "", false, false);
1089  }
1090 
1091 
1092  $area_type = $_SESSION["il_map_edit_area_type"];
1093  $coords = $_SESSION["il_map_edit_coords"];
1094  $cnt_coords = ilMapArea::countCoords($coords);
1095 
1096  // decide what to do next
1097  switch ($area_type)
1098  {
1099  // Rectangle
1100  case "Rect" :
1101  if ($cnt_coords < 2)
1102  {
1103  return $this->editMapArea(true, false, false, "shape", $_POST["area"][0]);
1104  }
1105  else if ($cnt_coords == 2)
1106  {
1107  return $this->saveArea();
1108  }
1109  break;
1110 
1111  // Circle
1112  case "Circle":
1113  if ($cnt_coords <= 1)
1114  {
1115  return $this->editMapArea(true, false, false, "shape", $_POST["area"][0]);
1116  }
1117  else
1118  {
1119  if ($cnt_coords == 2)
1120  {
1121  $c = explode(",",$coords);
1122  $coords = $c[0].",".$c[1].","; // determine radius
1123  $coords .= round(sqrt(pow(abs($c[3]-$c[1]),2)+pow(abs($c[2]-$c[0]),2)));
1124  }
1125  $_SESSION["il_map_edit_coords"] = $coords;
1126 
1127  return $this->saveArea();
1128  }
1129  break;
1130 
1131  // Polygon
1132  case "Poly":
1133  if ($cnt_coords < 1)
1134  {
1135  return $this->editMapArea(true, false, false, "shape", $_POST["area"][0]);
1136  }
1137  else if ($cnt_coords < 3)
1138  {
1139  return $this->editMapArea(true, true, false, "shape", $_POST["area"][0]);
1140  }
1141  else
1142  {
1143  return $this->editMapArea(true, true, true, "shape", $_POST["area"][0]);
1144  }
1145  break;
1146 
1147  // Whole Picture
1148  case "WholePicture":
1149  return $this->saveArea();
1150  }
1151 
1152  }
1153 
1160  function setHighlight()
1161  {
1162  global $ilCtrl, $lng;
1163 
1164  $st_item = $this->media_object->getMediaItem("Standard");
1165  $st_item->setHighlightMode(ilUtil::stripSlashes($_POST["highlight_mode"]));
1166  $st_item->setHighlightClass(ilUtil::stripSlashes($_POST["highlight_class"]));
1167  $st_item->update();
1168 
1169  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
1170  $ilCtrl->redirect($this, "editMapAreas");
1171  }
1172 }
1173 ?>
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
xslt_create()
This class represents an option in a radio group.
static getInitHTML($a_url)
Get initialisation HTML to use interna link editing.
addPolygon()
Add a new polygon.
getImageMapOutput($a_map_edit_mode="")
Render the image map.
$_SESSION["AccountId"]
editShapeWholePicture()
Edit an existing shape (make it a whole picture link)
This class represents a selection list property in a property form.
This class represents a property form user interface.
getEditorTitle()
Get editor title.
saveArea()
Save new or updated map area.
getLinkTypeOfArea($a_nr)
Get Link Type of Area.
$_GET["client_id"]
Class ilGlossaryTerm.
xslt_free(&$proc)
clearSessionVars()
Clear Session Vars.
$cmd
Definition: sahs_server.php:35
getTargetFrameOfArea($a_nr)
Get TargetFrame of Area (only internal link)
static _lookupTitle($a_id)
lookup object title
static includePresentationJS($a_tpl=null)
Include media object presentation JS.
Class ilInternalLinkGUI.
static _lookupTitle($a_obj_id)
Lookup title.
$coords
Definition: example_030.php:88
setInternalLink()
Set internal link.
initAreaEditingForm($a_edit_property)
Init area editing form.
const IL_NO_LINK
global $tpl
Definition: ilias.php:8
getMapAreaLinkString($a_target, $a_type, $a_frame)
Get text name of internal link.
global $ilCtrl
Definition: ilias.php:18
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
$a_type
Definition: workflow.php:93
editShapeCircle()
Edit an existing shape (make it a circle)
xslt_error(&$proc)
if(!is_dir( $entity_dir)) exit("Fatal Error ([A-Za-z0-9]+)\+" &#(? foreach( $entity_files as $file) $output
updateAreas()
Update map areas.
setHighlight()
Set highlight settings.
This class represents a property in a property form.
setLink($a_handle=true)
Set link.
if(!is_array($argv)) $options
const IL_INT_LINK
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
static _lookupObjId($a_id)
special template class to simplify handling of ITX/PEAR
Class ilMediaItem.
This class represents a text property in a property form.
setTitle($a_title)
set (tooltip)title of area
editLink()
Edit existing link.
Class ilObjMediaObject.
setMaxLength($a_maxlength)
Set Max Length.
outputPostProcessing($a_output)
Output post processing.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
deleteAreas()
Delete map areas.
setOptions($a_options)
Set Options.
setShape($a_handle=true)
edit shape of existing map area
const IL_MODE_ALIAS
Create styles array
The data for the language used.
handleMapParameters()
handle parameter during map area editing (storing to session)
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
const IL_EXT_LINK
User interface class for map editor.
getHrefOfArea($a_nr)
Get Href of Area (only external link)
addArea($a_handle=true)
Handle adding new area process.
Class ilMapArea.
static _recoverParameters()
Recover parameters from session variables (static)
editShapePolygon()
Edit an existing shape (make it a polygon)
editImagemapForward()
Get image map coordinates.
setShape($a_shape)
set shape (IL_AREA_RECT, IL_AREA_CIRCLE, IL_AREA_POLY, IL_AREA_WHOLE_PICTURE)
__construct($a_media_object)
Constructor.
This class represents a non editable value in a property form.
linkWholePicture()
Link the whole picture.
static _getMaxNr($a_item_id)
get maximum nr of media item (static)
global $lng
Definition: privfeed.php:17
$ret
Definition: parser.php:6
getAdditionalPageXML()
Get additional page xml (to be overwritten)
getTypeOfArea($a_nr)
Get Type of Area (only internal 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.
TableGUI class for image map editor.
const IL_MODE_OUTPUT
executeCommand()
Execute current command.
addRectangle()
Add a new rectangle.
makeMapWorkCopy($a_edit_property="", $a_area_nr=0, $a_output_new_area=false, $a_area_type="", $a_coords="")
Make work file for editing.
getImageMapTableHTML()
Get table HTML.
setLinkType($a_link_type)
set link type
static redirect($a_script)
http redirect to other script
static getWebspaceDir($mode="filesystem")
get webspace directory
$_POST["username"]
$html
Definition: example_001.php:87
$params
Definition: example_049.php:96
static countCoords($c)
count the number of coordinates (x,y) in a coordinate string (format: "x1,y1,x2,y2,x3,y3,...")
getTargetOfArea($a_nr)
Get Target of Area (only internal link)
editShapeRectangle()
Edit an existing shape (make it a rectangle)