ILIAS  eassessment Revision 61809
 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;
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("Media");
44  $ret = $ilCtrl->forwardCommand($link_gui);
45  break;
46 
47  default:
48  if (isset($_POST["editImagemapForward"]) ||
49  isset($_POST["editImagemapForward_x"]) ||
50  isset($_POST["editImagemapForward_y"]))
51  {
52  $cmd = "editImagemapForward";
53  }
54  $ret = $this->$cmd();
55  break;
56  }
57 
58  return $ret;
59  }
60 
64  function editMapAreas()
65  {
66  global $ilCtrl, $lng;
67 
68  $_SESSION["il_map_edit_target_script"] = $ilCtrl->getLinkTarget($this, "addArea",
69  "", false, false);
70  $this->handleMapParameters();
71 
72  $this->tpl = new ilTemplate("tpl.map_edit.html", true, true, "Services/MediaObjects");
73  $this->tpl->setVariable("FORMACTION", $ilCtrl->getFormAction($this));
74 
75  $this->tpl->setVariable("TXT_IMAGEMAP", $lng->txt("cont_imagemap"));
76 
77  // create/update imagemap work copy
78  $this->makeMapWorkCopy();
79 
80  $output = $this->getImageMapOutput();
81  $this->tpl->setVariable("IMAGE_MAP", $output);
82 
83  $this->tpl->setVariable("MAP_AREA_TABLE", $this->getImageMapTableHTML());
84 
85  return $this->tpl->get();
86  }
87 
92  {
93  include_once("./Services/MediaObjects/classes/class.ilImageMapTableGUI.php");
94  $image_map_table = new ilImageMapTableGUI($this, "editMapAreas", $this->media_object);
95  return $image_map_table->getHTML();
96  }
97 
102  {
103  if($_GET["ref_id"] != "")
104  {
105  $_SESSION["il_map_edit_ref_id"] = $_GET["ref_id"];
106  }
107 
108  if($_GET["obj_id"] != "")
109  {
110  $_SESSION["il_map_edit_obj_id"] = $_GET["obj_id"];
111  }
112 
113  if($_GET["hier_id"] != "")
114  {
115  $_SESSION["il_map_edit_hier_id"] = $_GET["hier_id"];
116  }
117 
118  if($_GET["pc_id"] != "")
119  {
120  $_SESSION["il_map_edit_pc_id"] = $_GET["pc_id"];
121  }
122  }
123 
127  function showImageMap()
128  {
129  $item =& new ilMediaItem($_GET["item_id"]);
130  $item->outputMapWorkCopy();
131  }
132 
136  function updateAreas()
137  {
138  global $lng, $ilCtrl;
139 
140  $st_item =& $this->media_object->getMediaItem("Standard");
141  $max = ilMapArea::_getMaxNr($st_item->getId());
142  for ($i=1; $i<=$max; $i++)
143  {
144  $area =& new ilMapArea($st_item->getId(), $i);
145  $area->setTitle(ilUtil::stripSlashes($_POST["name_".$i]));
146  $area->update();
147  }
148 
149  ilUtil::sendSuccess($lng->txt("cont_saved_map_data"), true);
150  $ilCtrl->redirect($this, "editMapAreas");
151  }
152 
156  function linkWholePicture()
157  {
158  $this->clearSessionVars();
159  $_SESSION["il_map_edit_area_type"] = "WholePicture";
160 
161  return $this->editMapArea(false, false, true);
162  }
163 
167  function addRectangle()
168  {
169  $this->clearSessionVars();
170  $_SESSION["il_map_edit_area_type"] = "Rect";
171  return $this->addArea(false);
172  }
173 
177  function addCircle()
178  {
179  $this->clearSessionVars();
180  $_SESSION["il_map_edit_area_type"] = "Circle";
181  return $this->addArea(false);
182  }
183 
187  function addPolygon()
188  {
189  $this->clearSessionVars();
190  $_SESSION["il_map_edit_area_type"] = "Poly";
191  return $this->addArea(false);
192  }
193 
197  function clearSessionVars()
198  {
199  $_SESSION["il_map_area_nr"] = "";
200  $_SESSION["il_map_edit_coords"] = "";
201  $_SESSION["il_map_edit_mode"] = "";
202  $_SESSION["il_map_el_href"] = "";
203  $_SESSION["il_map_il_type"] = "";
204  $_SESSION["il_map_il_ltype"] = "";
205  $_SESSION["il_map_il_target"] = "";
206  $_SESSION["il_map_il_targetframe"] = "";
207  $_SESSION["il_map_edit_area_type"] = "";
208  }
209 
213  function addArea($a_handle = true)
214  {
215 
216  // handle map parameters
217  if($a_handle)
218  {
219  $this->handleMapParameters();
220  }
221 
222  $area_type = $_SESSION["il_map_edit_area_type"];
223  $coords = $_SESSION["il_map_edit_coords"];
224  include_once("./Services/MediaObjects/classes/class.ilMapArea.php");
225  $cnt_coords = ilMapArea::countCoords($coords);
226 
227  // decide what to do next
228  switch ($area_type)
229  {
230  // Rectangle
231  case "Rect" :
232  if ($cnt_coords < 2)
233  {
234  $html = $this->editMapArea(true, false, false);
235  return $html;
236  }
237  else if ($cnt_coords == 2)
238  {
239  return $this->editMapArea(false, true, true);
240  }
241  break;
242 
243  // Circle
244  case "Circle":
245  if ($cnt_coords <= 1)
246  {
247  return $this->editMapArea(true, false, false);
248  }
249  else
250  {
251  if ($cnt_coords == 2)
252  {
253  $c = explode(",",$coords);
254  $coords = $c[0].",".$c[1].","; // determine radius
255  $coords .= round(sqrt(pow(abs($c[3]-$c[1]),2)+pow(abs($c[2]-$c[0]),2)));
256  }
257  $_SESSION["il_map_edit_coords"] = $coords;
258 
259  return $this->editMapArea(false, true, true);
260  }
261  break;
262 
263  // Polygon
264  case "Poly":
265  if ($cnt_coords < 1)
266  {
267  return $this->editMapArea(true, false, false);
268  }
269  else if ($cnt_coords < 3)
270  {
271  return $this->editMapArea(true, true, false);
272  }
273  else
274  {
275  return $this->editMapArea(true, true, true);
276  }
277  break;
278 
279  // Whole picture
280  case "WholePicture":
281  return $this->editMapArea(false, false, true);
282  break;
283  }
284  }
285 
294  function editMapArea($a_get_next_coordinate = false, $a_output_new_area = false,
295  $a_save_form = false, $a_edit_property = "", $a_area_nr = 0)
296  {
297  global $ilCtrl, $lng;
298 
299  $area_type = $_SESSION["il_map_edit_area_type"];
300  $coords = $_SESSION["il_map_edit_coords"];
301  include_once("./Services/MediaObjects/classes/class.ilMapArea.php");
302  $cnt_coords = ilMapArea::countCoords($coords);
303 
304  $this->tpl = new ilTemplate("tpl.map_edit.html", true, true, "Services/MediaObjects");
305 
306  $this->tpl->setVariable("FORMACTION", $ilCtrl->getFormAction($this));
307 
308  $this->tpl->setVariable("TXT_IMAGEMAP", $lng->txt("cont_imagemap"));
309 
310  $this->tpl->setCurrentBlock("instruction");
311  if ($a_edit_property != "link")
312  {
313  switch ($area_type)
314  {
315  // rectangle
316  case "Rect" :
317  if ($cnt_coords == 0)
318  {
319  $this->tpl->setVariable("INSTRUCTION", $lng->txt("cont_click_tl_corner"));
320  }
321  if ($cnt_coords == 1)
322  {
323  $this->tpl->setVariable("INSTRUCTION", $lng->txt("cont_click_br_corner"));
324  }
325  break;
326 
327  // circle
328  case "Circle" :
329  if ($cnt_coords == 0)
330  {
331  $this->tpl->setVariable("INSTRUCTION", $lng->txt("cont_click_center"));
332  }
333  if ($cnt_coords == 1)
334  {
335  $this->tpl->setVariable("INSTRUCTION", $lng->txt("cont_click_circle"));
336  }
337  break;
338 
339  // polygon
340  case "Poly" :
341  if ($cnt_coords == 0)
342  {
343  $this->tpl->setVariable("INSTRUCTION", $lng->txt("cont_click_starting_point"));
344  }
345  else if ($cnt_coords < 3)
346  {
347  $this->tpl->setVariable("INSTRUCTION", $lng->txt("cont_click_next_point"));
348  }
349  else
350  {
351  $this->tpl->setVariable("INSTRUCTION", $lng->txt("cont_click_next_or_save"));
352  }
353  break;
354  }
355  }
356  $this->tpl->parseCurrentBlock();
357 
358 // $this->tpl->setCurrentBlock("adm_content");
359 
360 
361  // map properties input fields (name and link)
362  if ($a_save_form)
363  {
364  if ($a_edit_property != "link" && $a_edit_property != "shape")
365  {
366  $this->tpl->setCurrentBlock("edit_name");
367  $this->tpl->setVariable("VAR_NAME2", "area_name");
368  $this->tpl->setVariable("TXT_NAME2", $lng->txt("cont_name"));
369  $this->tpl->parseCurrentBlock();
370  }
371 
372  if ($a_edit_property != "shape")
373  {
374  $this->tpl->setCurrentBlock("edit_link");
375  $this->tpl->setVariable("TXT_LINK_EXT", $lng->txt("cont_link_ext"));
376  $this->tpl->setVariable("TXT_LINK_INT", $lng->txt("cont_link_int"));
377  if ($_SESSION["il_map_el_href"] != "")
378  {
379  $this->tpl->setVariable("VAL_LINK_EXT", $_SESSION["il_map_el_href"]);
380  }
381  else
382  {
383  $this->tpl->setVariable("VAL_LINK_EXT", "http://");
384  }
385  $this->tpl->setVariable("VAR_LINK_EXT", "area_link_ext");
386  $this->tpl->setVariable("VAR_LINK_TYPE", "area_link_type");
387  if ($_SESSION["il_map_il_ltype"] != "int")
388  {
389  $this->tpl->setVariable("EXT_CHECKED", "checked=\"1\"");
390  }
391  else
392  {
393  $this->tpl->setVariable("INT_CHECKED", "checked=\"1\"");
394  }
395 
396  // internal link
397  $link_str = "";
398  if($_SESSION["il_map_il_target"] != "")
399  {
400  $link_str = $this->getMapAreaLinkString($_SESSION["il_map_il_target"],
401  $_SESSION["il_map_il_type"], $_SESSION["il_map_il_targetframe"]);
402  $this->tpl->setVariable("VAL_LINK_INT", $link_str);
403  }
404 
405  // internal link list
406  $ilCtrl->setParameter($this, "linkmode", "map");
407  $this->tpl->setVariable("LINK_ILINK",
408  $ilCtrl->getLinkTargetByClass("ilInternalLinkGUI", "showLinkHelp",
409  array("ilObjMediaObjectGUI"), true));
410  $this->tpl->setVariable("TXT_ILINK", "[".$lng->txt("cont_get_link")."]");
411 
412  $this->tpl->parseCurrentBlock();
413  }
414 
415  $this->tpl->setCurrentBlock("new_area");
416  $this->tpl->setVariable("TXT_SAVE", $lng->txt("save"));
417  $this->tpl->setVariable("BTN_SAVE", "saveArea");
418  if ($a_edit_property == "")
419  {
420  $this->tpl->setVariable("TXT_NEW_AREA", $lng->txt("cont_new_area"));
421  }
422  else
423  {
424  $this->tpl->setVariable("TXT_NEW_AREA", $lng->txt("cont_edit_area"));
425  }
426  $this->tpl->parseCurrentBlock();
427  }
428 
429  $this->makeMapWorkCopy($a_edit_property, $a_area_nr,
430  $a_output_new_area, $area_type, $coords);
431 
432  $edit_mode = ($a_get_next_coordinate)
433  ? "get_coords"
434  : "";
435  $output = $this->getImageMapOutput($edit_mode);
436  $this->tpl->setVariable("IMAGE_MAP", $output);
437 
438  return $this->tpl->get();
439  }
440 
444  function makeMapWorkCopy($a_edit_property = "", $a_area_nr = 0,
445  $a_output_new_area = false, $a_area_type = "", $a_coords = "")
446  {
447  // create/update imagemap work copy
448  $st_item = $this->media_object->getMediaItem("Standard");
449 
450  if ($a_edit_property == "shape")
451  {
452  $st_item->makeMapWorkCopy($a_area_nr, true); // exclude area currently being edited
453  }
454  else
455  {
456  $st_item->makeMapWorkCopy($a_area_nr, false);
457  }
458 
459  if ($a_output_new_area)
460  {
461  $st_item->addAreaToMapWorkCopy($a_area_type, $a_coords);
462  }
463  }
464 
468  function getImageMapOutput($a_map_edit_mode = "")
469  {
470  global $ilCtrl;
471 
472  $st_item = $this->media_object->getMediaItem("Standard");
473 
474  // output image map
475  $xml = "<dummy>";
476  $xml.= $this->getAliasXML();
477  $xml.= $this->media_object->getXML(IL_MODE_OUTPUT);
478  $xml.="</dummy>";
479  $xsl = file_get_contents("./Services/COPage/xsl/page.xsl");
480  $args = array( '/_xml' => $xml, '/_xsl' => $xsl );
481  $xh = xslt_create();
482  $wb_path = ilUtil::getWebspaceDir("output")."/";
483  $mode = "media";
484 //echo htmlentities($ilCtrl->getLinkTarget($this, "showImageMap"));
485  $params = array ('map_edit_mode' => $a_map_edit_mode,
486  'map_item' => $st_item->getId(),
487  'mode' => $mode,
488  'image_map_link' => $ilCtrl->getLinkTarget($this, "showImageMap", "", false, false),
489  'link_params' => "ref_id=".$_GET["ref_id"]."&rand=".rand(1,999999),
490  'ref_id' => $_GET["ref_id"],
491  'pg_frame' => "",
492  'webspace_path' => $wb_path);
493  $output = xslt_process($xh,"arg:/_xml","arg:/_xsl",NULL,$args, $params);
494  echo xslt_error($xh);
495  xslt_free($xh);
496 
497  return $output;
498  }
499 
500  function getAliasXML()
501  {
502  return $this->media_object->getXML(IL_MODE_ALIAS);
503  }
504 
514  function getMapAreaLinkString($a_target, $a_type, $a_frame)
515  {
516  global $lng;
517 
518  $t_arr = explode("_", $a_target);
519  if ($a_frame != "")
520  {
521  $frame_str = " (".$a_frame." Frame)";
522  }
523  switch($a_type)
524  {
525  case "StructureObject":
526  require_once("./Modules/LearningModule/classes/class.ilLMObject.php");
527  $title = ilLMObject::_lookupTitle($t_arr[count($t_arr) - 1]);
528  $link_str = $lng->txt("chapter").
529  ": ".$title." [".$t_arr[count($t_arr) - 1]."]".$frame_str;
530  break;
531 
532  case "PageObject":
533  require_once("./Modules/LearningModule/classes/class.ilLMObject.php");
534  $title = ilLMObject::_lookupTitle($t_arr[count($t_arr) - 1]);
535  $link_str = $lng->txt("page").
536  ": ".$title." [".$t_arr[count($t_arr) - 1]."]".$frame_str;
537  break;
538 
539  case "GlossaryItem":
540  require_once("./Modules/Glossary/classes/class.ilGlossaryTerm.php");
541  $term =& new ilGlossaryTerm($t_arr[count($t_arr) - 1]);
542  $link_str = $lng->txt("term").
543  ": ".$term->getTerm()." [".$t_arr[count($t_arr) - 1]."]".$frame_str;
544  break;
545 
546  case "MediaObject":
547  require_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
548  $mob =& new ilObjMediaObject($t_arr[count($t_arr) - 1]);
549  $link_str = $lng->txt("mob").
550  ": ".$mob->getTitle()." [".$t_arr[count($t_arr) - 1]."]".$frame_str;
551  break;
552 
553  case "RepositoryItem":
555  ilObject::_lookupObjId($t_arr[count($t_arr) - 1]));
556  $link_str = $lng->txt("obj_".$t_arr[count($t_arr) - 2]).
557  ": ".$title." [".$t_arr[count($t_arr) - 1]."]".$frame_str;
558  break;
559  }
560 
561  return $link_str;
562  }
563 
568  {
570 
571  if ($_SESSION["il_map_edit_coords"] != "")
572  {
573  $_SESSION["il_map_edit_coords"] .= ",";
574  }
575 
576  $_SESSION["il_map_edit_coords"] .= $_POST["editImagemapForward_x"].",".
577  $_POST["editImagemapForward_y"];
578 
579  // call editing script
580  ilUtil::redirect($_SESSION["il_map_edit_target_script"]);
581  }
582 
587  {
588  $_GET["ref_id"] = $_SESSION["il_map_edit_ref_id"];
589  $_GET["obj_id"] = $_SESSION["il_map_edit_obj_id"];
590  $_GET["hier_id"] = $_SESSION["il_map_edit_hier_id"];
591  $_GET["pc_id"] = $_SESSION["il_map_edit_pc_id"];
592  }
593 
597  function saveArea()
598  {
599  global $lng, $ilCtrl;
600 
601  switch ($_SESSION["il_map_edit_mode"])
602  {
603  // save edited link
604  case "edit_link":
605  $st_item = $this->media_object->getMediaItem("Standard");
606  $max = ilMapArea::_getMaxNr($st_item->getId());
607  $area = new ilMapArea($st_item->getId(), $_SESSION["il_map_area_nr"]);
608 
609  if ($_POST["area_link_type"] == IL_INT_LINK)
610  {
611  $area->setLinkType(IL_INT_LINK);
612  $area->setType($_SESSION["il_map_il_type"]);
613  $area->setTarget($_SESSION["il_map_il_target"]);
614  $area->setTargetFrame($_SESSION["il_map_il_targetframe"]);
615  }
616  else
617  {
618  $area->setLinkType(IL_EXT_LINK);
619  $area->setHref(ilUtil::stripSlashes($_POST["area_link_ext"]));
620  }
621  $area->update();
622  break;
623 
624  // save edited shape
625  case "edit_shape":
626  $st_item = $this->media_object->getMediaItem("Standard");
627  $max = ilMapArea::_getMaxNr($st_item->getId());
628  $area =& new ilMapArea($st_item->getId(), $_SESSION["il_map_area_nr"]);
629 
630  $area->setShape($_SESSION["il_map_edit_area_type"]);
631  $area->setCoords($_SESSION["il_map_edit_coords"]);
632  $area->update();
633  break;
634 
635  // save new area
636  default:
637  $area_type = $_SESSION["il_map_edit_area_type"];
638  $coords = $_SESSION["il_map_edit_coords"];
639 
640  $st_item = $this->media_object->getMediaItem("Standard");
641  $max = ilMapArea::_getMaxNr($st_item->getId());
642 
643  // make new area object
644  $area = new ilMapArea();
645  $area->setItemId($st_item->getId());
646  $area->setShape($area_type);
647  $area->setCoords($coords);
648  $area->setNr($max + 1);
649  $area->setTitle(ilUtil::stripSlashes($_POST["area_name"]));
650  switch($_POST["area_link_type"])
651  {
652  case "ext":
653  $area->setLinkType(IL_EXT_LINK);
654  $area->setHref($_POST["area_link_ext"]);
655  break;
656 
657  case "int":
658  $area->setLinkType(IL_INT_LINK);
659  $area->setType($_SESSION["il_map_il_type"]);
660  $area->setTarget($_SESSION["il_map_il_target"]);
661  $area->setTargetFrame($_SESSION["il_map_il_targetframe"]);
662  break;
663  }
664 
665  // put area into item and update media object
666  $st_item->addMapArea($area);
667  $this->media_object->update();
668  break;
669  }
670 
671  //$this->initMapParameters();
672  ilUtil::sendSuccess($lng->txt("cont_saved_map_area"), true);
673  $ilCtrl->redirect($this, "editMapAreas");
674  }
675 
679  function setInternalLink()
680  {
681  $_SESSION["il_map_il_type"] = $_GET["linktype"];
682  $_SESSION["il_map_il_ltype"] = "int";
683 
684  $_SESSION["il_map_il_target"] = $_GET["linktarget"];
685  $_SESSION["il_map_il_targetframe"] = $_GET["linktargetframe"];
686  switch ($_SESSION["il_map_edit_mode"])
687  {
688  case "edit_link":
689  return $this->setLink();
690  break;
691 
692  default:
693  return $this->addArea();
694  break;
695  }
696  }
697 
701  function setLink($a_handle = true)
702  {
703  global $lng, $ilCtrl;
704 
705  if($a_handle)
706  {
707  $this->handleMapParameters();
708  }
709  if ($_SESSION["il_map_area_nr"] != "")
710  {
711  $_POST["area"][0] = $_SESSION["il_map_area_nr"];
712  }
713  if (!isset($_POST["area"]))
714  {
715  ilUtil::sendFailure($lng->txt("no_checkbox"), true);
716  $ilCtrl->redirect($this, "editMapAreas");
717  }
718 
719  if (count($_POST["area"]) > 1)
720  {
721  //$this->ilias->raiseError($this->lng->txt("cont_select_max_one_item"),$this->ilias->error_obj->MESSAGE);
722  ilUtil::sendFailure($lng->txt("cont_select_max_one_item"), true);
723  $ilCtrl->redirect($this, "editMapAreas");
724  }
725 
726 
727  if ($_SESSION["il_map_edit_mode"] != "edit_link")
728  {
729  $_SESSION["il_map_area_nr"] = $_POST["area"][0];
730  $_SESSION["il_map_il_ltype"] = $this->getLinkTypeOfArea($_POST["area"][0]);
731  $_SESSION["il_map_edit_mode"] = "edit_link";
732  $_SESSION["il_map_edit_target_script"] = $ilCtrl->getLinkTarget($this, "setLink");
733  if ($_SESSION["il_map_il_ltype"] == IL_INT_LINK)
734  {
735  $_SESSION["il_map_il_type"] = $this->getTypeOfArea($_POST["area"][0]);
736  $_SESSION["il_map_il_target"] = $this->getTargetOfArea($_POST["area"][0]);
737  $_SESSION["il_map_il_targetframe"] = $this->getTargetFrameOfArea($_POST["area"][0]);
738  }
739  else
740  {
741  $_SESSION["il_map_el_href"] = $this->getHrefOfArea($_POST["area"][0]);
742  }
743  }
744 
745  return $this->editMapArea(false, false, true, "link", $_POST["area"][0]);
746  }
747 
751  function getLinkTypeOfArea($a_nr)
752  {
753  $st_item = $this->media_object->getMediaItem("Standard");
754  $area = $st_item->getMapArea($a_nr);
755  return $area->getLinkType();
756  }
757 
761  function getTypeOfArea($a_nr)
762  {
763  $st_item = $this->media_object->getMediaItem("Standard");
764  $area = $st_item->getMapArea($a_nr);
765  return $area->getType();
766  }
767 
771  function getTargetOfArea($a_nr)
772  {
773  $st_item = $this->media_object->getMediaItem("Standard");
774  $area = $st_item->getMapArea($a_nr);
775  return $area->getTarget();
776  }
777 
781  function getTargetFrameOfArea($a_nr)
782  {
783  $st_item = $this->media_object->getMediaItem("Standard");
784  $area = $st_item->getMapArea($a_nr);
785  return $area->getTargetFrame();
786  }
787 
791  function getHrefOfArea($a_nr)
792  {
793  $st_item = $this->media_object->getMediaItem("Standard");
794  $area = $st_item->getMapArea($a_nr);
795  return $area->getHref();
796  }
797 
801  function deleteAreas()
802  {
803  global $ilCtrl, $lng;
804 
805  if (!isset($_POST["area"]))
806  {
807  ilUtil::sendFailure($lng->txt("no_checkbox"), true);
808  $ilCtrl->redirect($this, "editMapAreas");
809  }
810 
811  $st_item = $this->media_object->getMediaItem("Standard");
812  $max = ilMapArea::_getMaxNr($st_item->getId());
813 
814  if (count($_POST["area"]) > 0)
815  {
816  $i = 0;
817 
818  foreach ($_POST["area"] as $area_nr)
819  {
820  $st_item->deleteMapArea($area_nr - $i);
821  $i++;
822  }
823 
824  $this->media_object->update();
825  ilUtil::sendSuccess($lng->txt("cont_areas_deleted"), true);
826  }
827 
828  $ilCtrl->redirect($this, "editMapAreas");
829  }
830 
834  function editLink()
835  {
836  $_SESSION["il_map_edit_coords"] = "";
837  $_SESSION["il_map_edit_mode"] = "";
838  $_SESSION["il_map_el_href"] = "";
839  $_SESSION["il_map_il_type"] = "";
840  $_SESSION["il_map_il_ltype"] = "";
841  $_SESSION["il_map_il_target"] = "";
842  $_SESSION["il_map_il_targetframe"] = "";
843  $_SESSION["il_map_area_nr"] = "";
844  return $this->setLink(false);
845  }
846 
851  {
852  $this->clearSessionVars();
853  $_SESSION["il_map_edit_area_type"] = "WholePicture";
854  return $this->setShape(false);
855  }
856 
861  {
862  $this->clearSessionVars();
863  $_SESSION["il_map_edit_area_type"] = "Rect";
864  return $this->setShape(false);
865  }
866 
870  function editShapeCircle()
871  {
872  $this->clearSessionVars();
873  $_SESSION["il_map_edit_area_type"] = "Circle";
874  return $this->setShape(false);
875  }
876 
880  function editShapePolygon()
881  {
882  $this->clearSessionVars();
883  $_SESSION["il_map_edit_area_type"] = "Poly";
884  return $this->setShape(false);
885  }
886 
890  function setShape($a_handle = true)
891  {
892  global $lng, $ilCtrl;
893 
894  if($a_handle)
895  {
896  $this->handleMapParameters();
897  }
898  if($_POST["areatype2"] != "")
899  {
900  $_SESSION["il_map_edit_area_type"] = $_POST["areatype2"];
901  }
902  if ($_SESSION["il_map_area_nr"] != "")
903  {
904  $_POST["area"][0] = $_SESSION["il_map_area_nr"];
905  }
906  if (!isset($_POST["area"]))
907  {
908  ilUtil::sendFailure($lng->txt("no_checkbox"), true);
909  $ilCtrl->redirect($this, "editMapAreas");
910  }
911 
912  if (count($_POST["area"]) > 1)
913  {
914  ilUtil::sendFailure($lng->txt("cont_select_max_one_item"), true);
915  $ilCtrl->redirect($this, "editMapAreas");
916  }
917 
918  if ($_SESSION["il_map_edit_mode"] != "edit_shape")
919  {
920  $_SESSION["il_map_area_nr"] = $_POST["area"][0];
921  $_SESSION["il_map_edit_mode"] = "edit_shape";
922  $_SESSION["il_map_edit_target_script"] = $ilCtrl->getLinkTarget($this, "setShape", "", false, false);
923  }
924 
925 
926  $area_type = $_SESSION["il_map_edit_area_type"];
927  $coords = $_SESSION["il_map_edit_coords"];
928  $cnt_coords = ilMapArea::countCoords($coords);
929 
930  // decide what to do next
931  switch ($area_type)
932  {
933  // Rectangle
934  case "Rect" :
935  if ($cnt_coords < 2)
936  {
937  return $this->editMapArea(true, false, false, "shape", $_POST["area"][0]);
938  }
939  else if ($cnt_coords == 2)
940  {
941  return $this->saveArea();
942  }
943  break;
944 
945  // Circle
946  case "Circle":
947  if ($cnt_coords <= 1)
948  {
949  return $this->editMapArea(true, false, false, "shape", $_POST["area"][0]);
950  }
951  else
952  {
953  if ($cnt_coords == 2)
954  {
955  $c = explode(",",$coords);
956  $coords = $c[0].",".$c[1].","; // determine radius
957  $coords .= round(sqrt(pow(abs($c[3]-$c[1]),2)+pow(abs($c[2]-$c[0]),2)));
958  }
959  $_SESSION["il_map_edit_coords"] = $coords;
960 
961  return $this->saveArea();
962  }
963  break;
964 
965  // Polygon
966  case "Poly":
967  if ($cnt_coords < 1)
968  {
969  return $this->editMapArea(true, false, false, "shape", $_POST["area"][0]);
970  }
971  else if ($cnt_coords < 3)
972  {
973  return $this->editMapArea(true, true, false, "shape", $_POST["area"][0]);
974  }
975  else
976  {
977  return $this->editMapArea(true, true, true, "shape", $_POST["area"][0]);
978  }
979  break;
980 
981  // Whole Picture
982  case "WholePicture":
983  return $this->saveArea();
984  }
985 
986  }
987 
988 }
989 ?>