ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
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("./Modules/LearningModule/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("./Modules/LearningModule/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);
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  'webspace_path' => $wb_path);
628  $output = xslt_process($xh,"arg:/_xml","arg:/_xsl",NULL,$args, $params);
629  echo xslt_error($xh);
630  xslt_free($xh);
631 
632  $output = $this->outputPostProcessing($output);
633 
634  return $output;
635  }
636 
643  {
644  return "";
645  }
646 
653  function outputPostProcessing($a_output)
654  {
655  return $a_output;
656  }
657 
658  function getAliasXML()
659  {
660  return $this->media_object->getXML(IL_MODE_ALIAS);
661  }
662 
672  function getMapAreaLinkString($a_target, $a_type, $a_frame)
673  {
674  global $lng;
675 
676  $t_arr = explode("_", $a_target);
677  if ($a_frame != "")
678  {
679  $frame_str = " (".$a_frame." Frame)";
680  }
681  switch($a_type)
682  {
683  case "StructureObject":
684  require_once("./Modules/LearningModule/classes/class.ilLMObject.php");
685  $title = ilLMObject::_lookupTitle($t_arr[count($t_arr) - 1]);
686  $link_str = $lng->txt("chapter").
687  ": ".$title." [".$t_arr[count($t_arr) - 1]."]".$frame_str;
688  break;
689 
690  case "PageObject":
691  require_once("./Modules/LearningModule/classes/class.ilLMObject.php");
692  $title = ilLMObject::_lookupTitle($t_arr[count($t_arr) - 1]);
693  $link_str = $lng->txt("page").
694  ": ".$title." [".$t_arr[count($t_arr) - 1]."]".$frame_str;
695  break;
696 
697  case "GlossaryItem":
698  require_once("./Modules/Glossary/classes/class.ilGlossaryTerm.php");
699  $term =& new ilGlossaryTerm($t_arr[count($t_arr) - 1]);
700  $link_str = $lng->txt("term").
701  ": ".$term->getTerm()." [".$t_arr[count($t_arr) - 1]."]".$frame_str;
702  break;
703 
704  case "MediaObject":
705  require_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
706  $mob =& new ilObjMediaObject($t_arr[count($t_arr) - 1]);
707  $link_str = $lng->txt("mob").
708  ": ".$mob->getTitle()." [".$t_arr[count($t_arr) - 1]."]".$frame_str;
709  break;
710 
711  case "RepositoryItem":
713  ilObject::_lookupObjId($t_arr[count($t_arr) - 1]));
714  $link_str = $lng->txt("obj_".$t_arr[count($t_arr) - 2]).
715  ": ".$title." [".$t_arr[count($t_arr) - 1]."]".$frame_str;
716  break;
717  }
718 
719  return $link_str;
720  }
721 
726  {
728 
729  if ($_SESSION["il_map_edit_coords"] != "")
730  {
731  $_SESSION["il_map_edit_coords"] .= ",";
732  }
733 
734  $_SESSION["il_map_edit_coords"] .= $_POST["editImagemapForward_x"].",".
735  $_POST["editImagemapForward_y"];
736 
737  // call editing script
738  ilUtil::redirect($_SESSION["il_map_edit_target_script"]);
739  }
740 
745  {
746  $_GET["ref_id"] = $_SESSION["il_map_edit_ref_id"];
747  $_GET["obj_id"] = $_SESSION["il_map_edit_obj_id"];
748  $_GET["hier_id"] = $_SESSION["il_map_edit_hier_id"];
749  $_GET["pc_id"] = $_SESSION["il_map_edit_pc_id"];
750  }
751 
755  function saveArea()
756  {
757  global $lng, $ilCtrl;
758 
759  switch ($_SESSION["il_map_edit_mode"])
760  {
761  // save edited link
762  case "edit_link":
763  $st_item = $this->media_object->getMediaItem("Standard");
764  $max = ilMapArea::_getMaxNr($st_item->getId());
765  $area = new ilMapArea($st_item->getId(), $_SESSION["il_map_area_nr"]);
766 
767  if ($_POST["area_link_type"] == IL_INT_LINK)
768  {
769  $area->setLinkType(IL_INT_LINK);
770  $area->setType($_SESSION["il_map_il_type"]);
771  $area->setTarget($_SESSION["il_map_il_target"]);
772  $area->setTargetFrame($_SESSION["il_map_il_targetframe"]);
773  }
774  else
775  {
776  $area->setLinkType(IL_EXT_LINK);
777  if ($_POST["area_link_type"] != IL_NO_LINK)
778  {
779  $area->setHref(ilUtil::stripSlashes($_POST["area_link_ext"]));
780  }
781  else
782  {
783  $area->setHref("");
784  }
785  }
786  $area->update();
787  break;
788 
789  // save edited shape
790  case "edit_shape":
791  $st_item = $this->media_object->getMediaItem("Standard");
792  $max = ilMapArea::_getMaxNr($st_item->getId());
793  $area =& new ilMapArea($st_item->getId(), $_SESSION["il_map_area_nr"]);
794 
795  $area->setShape($_SESSION["il_map_edit_area_type"]);
796  $area->setCoords($_SESSION["il_map_edit_coords"]);
797  $area->update();
798  break;
799 
800  // save new area
801  default:
802  $area_type = $_SESSION["il_map_edit_area_type"];
803  $coords = $_SESSION["il_map_edit_coords"];
804 
805  $st_item = $this->media_object->getMediaItem("Standard");
806  $max = ilMapArea::_getMaxNr($st_item->getId());
807 
808  // make new area object
809  $area = new ilMapArea();
810  $area->setItemId($st_item->getId());
811  $area->setShape($area_type);
812  $area->setCoords($coords);
813  $area->setNr($max + 1);
814  $area->setTitle(ilUtil::stripSlashes($_POST["area_name"]));
815  switch($_POST["area_link_type"])
816  {
817  case "ext":
818  $area->setLinkType(IL_EXT_LINK);
819  $area->setHref($_POST["area_link_ext"]);
820  break;
821 
822  case "int":
823  $area->setLinkType(IL_INT_LINK);
824  $area->setType($_SESSION["il_map_il_type"]);
825  $area->setTarget($_SESSION["il_map_il_target"]);
826  $area->setTargetFrame($_SESSION["il_map_il_targetframe"]);
827  break;
828  }
829 
830  // put area into item and update media object
831  $st_item->addMapArea($area);
832  $this->media_object->update();
833  break;
834  }
835 
836  //$this->initMapParameters();
837  ilUtil::sendSuccess($lng->txt("cont_saved_map_area"), true);
838  $ilCtrl->redirect($this, "editMapAreas");
839  }
840 
844  function setInternalLink()
845  {
846  $_SESSION["il_map_il_type"] = $_GET["linktype"];
847  $_SESSION["il_map_il_ltype"] = "int";
848 
849  $_SESSION["il_map_il_target"] = $_GET["linktarget"];
850  $_SESSION["il_map_il_targetframe"] = $_GET["linktargetframe"];
851  switch ($_SESSION["il_map_edit_mode"])
852  {
853  case "edit_link":
854  return $this->setLink();
855  break;
856 
857  default:
858  return $this->addArea();
859  break;
860  }
861  }
862 
866  function setLink($a_handle = true)
867  {
868  global $lng, $ilCtrl;
869 
870  if($a_handle)
871  {
872  $this->handleMapParameters();
873  }
874  if ($_SESSION["il_map_area_nr"] != "")
875  {
876  $_POST["area"][0] = $_SESSION["il_map_area_nr"];
877  }
878  if (!isset($_POST["area"]))
879  {
880  ilUtil::sendFailure($lng->txt("no_checkbox"), true);
881  $ilCtrl->redirect($this, "editMapAreas");
882  }
883 
884  if (count($_POST["area"]) > 1)
885  {
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  {
894  $_SESSION["il_map_area_nr"] = $_POST["area"][0];
895  $_SESSION["il_map_il_ltype"] = $this->getLinkTypeOfArea($_POST["area"][0]);
896  $_SESSION["il_map_edit_mode"] = "edit_link";
897  $_SESSION["il_map_edit_target_script"] = $ilCtrl->getLinkTarget($this, "setLink");
898  if ($_SESSION["il_map_il_ltype"] == IL_INT_LINK)
899  {
900  $_SESSION["il_map_il_type"] = $this->getTypeOfArea($_POST["area"][0]);
901  $_SESSION["il_map_il_target"] = $this->getTargetOfArea($_POST["area"][0]);
902  $_SESSION["il_map_il_targetframe"] = $this->getTargetFrameOfArea($_POST["area"][0]);
903  }
904  else
905  {
906  $_SESSION["il_map_el_href"] = $this->getHrefOfArea($_POST["area"][0]);
907  }
908  }
909 
910  return $this->editMapArea(false, false, true, "link", $_POST["area"][0]);
911  }
912 
916  function getLinkTypeOfArea($a_nr)
917  {
918  $st_item = $this->media_object->getMediaItem("Standard");
919  $area = $st_item->getMapArea($a_nr);
920  return $area->getLinkType();
921  }
922 
926  function getTypeOfArea($a_nr)
927  {
928  $st_item = $this->media_object->getMediaItem("Standard");
929  $area = $st_item->getMapArea($a_nr);
930  return $area->getType();
931  }
932 
936  function getTargetOfArea($a_nr)
937  {
938  $st_item = $this->media_object->getMediaItem("Standard");
939  $area = $st_item->getMapArea($a_nr);
940  return $area->getTarget();
941  }
942 
946  function getTargetFrameOfArea($a_nr)
947  {
948  $st_item = $this->media_object->getMediaItem("Standard");
949  $area = $st_item->getMapArea($a_nr);
950  return $area->getTargetFrame();
951  }
952 
956  function getHrefOfArea($a_nr)
957  {
958  $st_item = $this->media_object->getMediaItem("Standard");
959  $area = $st_item->getMapArea($a_nr);
960  return $area->getHref();
961  }
962 
966  function deleteAreas()
967  {
968  global $ilCtrl, $lng;
969 
970  if (!isset($_POST["area"]))
971  {
972  ilUtil::sendFailure($lng->txt("no_checkbox"), true);
973  $ilCtrl->redirect($this, "editMapAreas");
974  }
975 
976  $st_item = $this->media_object->getMediaItem("Standard");
977  $max = ilMapArea::_getMaxNr($st_item->getId());
978 
979  if (count($_POST["area"]) > 0)
980  {
981  $i = 0;
982 
983  foreach ($_POST["area"] as $area_nr)
984  {
985  $st_item->deleteMapArea($area_nr - $i);
986  $i++;
987  }
988 
989  $this->media_object->update();
990  ilUtil::sendSuccess($lng->txt("cont_areas_deleted"), true);
991  }
992 
993  $ilCtrl->redirect($this, "editMapAreas");
994  }
995 
999  function editLink()
1000  {
1001  $_SESSION["il_map_edit_coords"] = "";
1002  $_SESSION["il_map_edit_mode"] = "";
1003  $_SESSION["il_map_el_href"] = "";
1004  $_SESSION["il_map_il_type"] = "";
1005  $_SESSION["il_map_il_ltype"] = "";
1006  $_SESSION["il_map_il_target"] = "";
1007  $_SESSION["il_map_il_targetframe"] = "";
1008  $_SESSION["il_map_area_nr"] = "";
1009  return $this->setLink(false);
1010  }
1011 
1016  {
1017  $this->clearSessionVars();
1018  $_SESSION["il_map_edit_area_type"] = "WholePicture";
1019  return $this->setShape(false);
1020  }
1021 
1026  {
1027  $this->clearSessionVars();
1028  $_SESSION["il_map_edit_area_type"] = "Rect";
1029  return $this->setShape(false);
1030  }
1031 
1035  function editShapeCircle()
1036  {
1037  $this->clearSessionVars();
1038  $_SESSION["il_map_edit_area_type"] = "Circle";
1039  return $this->setShape(false);
1040  }
1041 
1045  function editShapePolygon()
1046  {
1047  $this->clearSessionVars();
1048  $_SESSION["il_map_edit_area_type"] = "Poly";
1049  return $this->setShape(false);
1050  }
1051 
1055  function setShape($a_handle = true)
1056  {
1057  global $lng, $ilCtrl;
1058 
1059  if($a_handle)
1060  {
1061  $this->handleMapParameters();
1062  }
1063  if($_POST["areatype2"] != "")
1064  {
1065  $_SESSION["il_map_edit_area_type"] = $_POST["areatype2"];
1066  }
1067  if ($_SESSION["il_map_area_nr"] != "")
1068  {
1069  $_POST["area"][0] = $_SESSION["il_map_area_nr"];
1070  }
1071  if (!isset($_POST["area"]))
1072  {
1073  ilUtil::sendFailure($lng->txt("no_checkbox"), true);
1074  $ilCtrl->redirect($this, "editMapAreas");
1075  }
1076 
1077  if (count($_POST["area"]) > 1)
1078  {
1079  ilUtil::sendFailure($lng->txt("cont_select_max_one_item"), true);
1080  $ilCtrl->redirect($this, "editMapAreas");
1081  }
1082 
1083  if ($_SESSION["il_map_edit_mode"] != "edit_shape")
1084  {
1085  $_SESSION["il_map_area_nr"] = $_POST["area"][0];
1086  $_SESSION["il_map_edit_mode"] = "edit_shape";
1087  $_SESSION["il_map_edit_target_script"] = $ilCtrl->getLinkTarget($this, "setShape", "", false, false);
1088  }
1089 
1090 
1091  $area_type = $_SESSION["il_map_edit_area_type"];
1092  $coords = $_SESSION["il_map_edit_coords"];
1093  $cnt_coords = ilMapArea::countCoords($coords);
1094 
1095  // decide what to do next
1096  switch ($area_type)
1097  {
1098  // Rectangle
1099  case "Rect" :
1100  if ($cnt_coords < 2)
1101  {
1102  return $this->editMapArea(true, false, false, "shape", $_POST["area"][0]);
1103  }
1104  else if ($cnt_coords == 2)
1105  {
1106  return $this->saveArea();
1107  }
1108  break;
1109 
1110  // Circle
1111  case "Circle":
1112  if ($cnt_coords <= 1)
1113  {
1114  return $this->editMapArea(true, false, false, "shape", $_POST["area"][0]);
1115  }
1116  else
1117  {
1118  if ($cnt_coords == 2)
1119  {
1120  $c = explode(",",$coords);
1121  $coords = $c[0].",".$c[1].","; // determine radius
1122  $coords .= round(sqrt(pow(abs($c[3]-$c[1]),2)+pow(abs($c[2]-$c[0]),2)));
1123  }
1124  $_SESSION["il_map_edit_coords"] = $coords;
1125 
1126  return $this->saveArea();
1127  }
1128  break;
1129 
1130  // Polygon
1131  case "Poly":
1132  if ($cnt_coords < 1)
1133  {
1134  return $this->editMapArea(true, false, false, "shape", $_POST["area"][0]);
1135  }
1136  else if ($cnt_coords < 3)
1137  {
1138  return $this->editMapArea(true, true, false, "shape", $_POST["area"][0]);
1139  }
1140  else
1141  {
1142  return $this->editMapArea(true, true, true, "shape", $_POST["area"][0]);
1143  }
1144  break;
1145 
1146  // Whole Picture
1147  case "WholePicture":
1148  return $this->saveArea();
1149  }
1150 
1151  }
1152 
1159  function setHighlight()
1160  {
1161  global $ilCtrl, $lng;
1162 
1163  $st_item = $this->media_object->getMediaItem("Standard");
1164  $st_item->setHighlightMode(ilUtil::stripSlashes($_POST["highlight_mode"]));
1165  $st_item->setHighlightClass(ilUtil::stripSlashes($_POST["highlight_class"]));
1166  $st_item->update();
1167 
1168  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
1169  $ilCtrl->redirect($this, "editMapAreas");
1170  }
1171 }
1172 ?>