ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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  {
56  $tpl = $this->tpl;
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  {
96  $lng = $this->lng;
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  {
133  $lng = $this->lng;
134  $tpl = $this->tpl;
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  {
181  $lng = $this->lng;
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  {
233  $lng = $this->lng;
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  ) {
399  $lng = $this->lng;
400  $tpl = $this->tpl;
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  {
495  $lng = $this->lng;
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  {
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  {
687  $lng = $this->lng;
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  require_once("./Modules/Glossary/classes/class.ilGlossaryTerm.php");
710  $term = new ilGlossaryTerm($t_arr[count($t_arr) - 1]);
711  $link_str = $lng->txt("term") .
712  ": " . $term->getTerm() . " [" . $t_arr[count($t_arr) - 1] . "]" . $frame_str;
713  break;
714 
715  case "MediaObject":
716  require_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
717  $mob = new ilObjMediaObject($t_arr[count($t_arr) - 1]);
718  $link_str = $lng->txt("mob") .
719  ": " . $mob->getTitle() . " [" . $t_arr[count($t_arr) - 1] . "]" . $frame_str;
720  break;
721 
722  case "RepositoryItem":
724  ilObject::_lookupObjId($t_arr[count($t_arr) - 1])
725  );
726  $link_str = $lng->txt("obj_" . $t_arr[count($t_arr) - 2]) .
727  ": " . $title . " [" . $t_arr[count($t_arr) - 1] . "]" . $frame_str;
728  break;
729  }
730 
731  return $link_str;
732  }
733 
737  public function editImagemapForward()
738  {
740 
741  if ($_SESSION["il_map_edit_coords"] != "") {
742  $_SESSION["il_map_edit_coords"] .= ",";
743  }
744 
745  $_SESSION["il_map_edit_coords"] .= $_POST["editImagemapForward_x"] . "," .
746  $_POST["editImagemapForward_y"];
747 
748  // call editing script
749  ilUtil::redirect($_SESSION["il_map_edit_target_script"]);
750  }
751 
755  public static function _recoverParameters()
756  {
757  $_GET["ref_id"] = $_SESSION["il_map_edit_ref_id"];
758  $_GET["obj_id"] = $_SESSION["il_map_edit_obj_id"];
759  $_GET["hier_id"] = $_SESSION["il_map_edit_hier_id"];
760  $_GET["pc_id"] = $_SESSION["il_map_edit_pc_id"];
761  }
762 
766  public function saveArea()
767  {
768  $lng = $this->lng;
770 
771  switch ($_SESSION["il_map_edit_mode"]) {
772  // save edited link
773  case "edit_link":
774  $st_item = $this->media_object->getMediaItem("Standard");
775  $max = ilMapArea::_getMaxNr($st_item->getId());
776  $area = new ilMapArea($st_item->getId(), $_SESSION["il_map_area_nr"]);
777 
778  if ($_POST["area_link_type"] == IL_INT_LINK) {
779  $area->setLinkType(IL_INT_LINK);
780  $area->setType($_SESSION["il_map_il_type"]);
781  $area->setTarget($_SESSION["il_map_il_target"]);
782  $area->setTargetFrame($_SESSION["il_map_il_targetframe"]);
783  } else {
784  $area->setLinkType(IL_EXT_LINK);
785  if ($_POST["area_link_type"] != IL_NO_LINK) {
786  $area->setHref(ilUtil::stripSlashes($_POST["area_link_ext"]));
787  } else {
788  $area->setHref("");
789  }
790  }
791  $area->update();
792  break;
793 
794  // save edited shape
795  case "edit_shape":
796  $st_item = $this->media_object->getMediaItem("Standard");
797  $max = ilMapArea::_getMaxNr($st_item->getId());
798  $area = new ilMapArea($st_item->getId(), $_SESSION["il_map_area_nr"]);
799 
800  $area->setShape($_SESSION["il_map_edit_area_type"]);
801  $area->setCoords($_SESSION["il_map_edit_coords"]);
802  $area->update();
803  break;
804 
805  // save new area
806  default:
807  $area_type = $_SESSION["il_map_edit_area_type"];
808  $coords = $_SESSION["il_map_edit_coords"];
809 
810  $st_item = $this->media_object->getMediaItem("Standard");
811  $max = ilMapArea::_getMaxNr($st_item->getId());
812 
813  // make new area object
814  $area = new ilMapArea();
815  $area->setItemId($st_item->getId());
816  $area->setShape($area_type);
817  $area->setCoords($coords);
818  $area->setNr($max + 1);
819  $area->setTitle(ilUtil::stripSlashes($_POST["area_name"]));
820  switch ($_POST["area_link_type"]) {
821  case "ext":
822  $area->setLinkType(IL_EXT_LINK);
823  $area->setHref($_POST["area_link_ext"]);
824  break;
825 
826  case "int":
827  $area->setLinkType(IL_INT_LINK);
828  $area->setType($_SESSION["il_map_il_type"]);
829  $area->setTarget($_SESSION["il_map_il_target"]);
830  $area->setTargetFrame($_SESSION["il_map_il_targetframe"]);
831  break;
832  }
833 
834  // put area into item and update media object
835  $st_item->addMapArea($area);
836  $this->media_object->update();
837  break;
838  }
839 
840  //$this->initMapParameters();
841  ilUtil::sendSuccess($lng->txt("cont_saved_map_area"), true);
842  $ilCtrl->redirect($this, "editMapAreas");
843  }
844 
848  public function setInternalLink()
849  {
850  $_SESSION["il_map_il_type"] = $_GET["linktype"];
851  $_SESSION["il_map_il_ltype"] = "int";
852 
853  $_SESSION["il_map_il_target"] = $_GET["linktarget"];
854  $_SESSION["il_map_il_targetframe"] = $_GET["linktargetframe"];
855  $_SESSION["il_map_il_anchor"] = $_GET["linkanchor"];
856  switch ($_SESSION["il_map_edit_mode"]) {
857  case "edit_link":
858  return $this->setLink();
859  break;
860 
861  default:
862  return $this->addArea();
863  break;
864  }
865  }
866 
870  public function setLink($a_handle = true)
871  {
872  $lng = $this->lng;
874 
875  if ($a_handle) {
876  $this->handleMapParameters();
877  }
878  if ($_SESSION["il_map_area_nr"] != "") {
879  $_POST["area"][0] = $_SESSION["il_map_area_nr"];
880  }
881  if (!isset($_POST["area"])) {
882  ilUtil::sendFailure($lng->txt("no_checkbox"), true);
883  $ilCtrl->redirect($this, "editMapAreas");
884  }
885 
886  if (count($_POST["area"]) > 1) {
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  $_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  $_SESSION["il_map_il_type"] = $this->getTypeOfArea($_POST["area"][0]);
900  $_SESSION["il_map_il_target"] = $this->getTargetOfArea($_POST["area"][0]);
901  $_SESSION["il_map_il_targetframe"] = $this->getTargetFrameOfArea($_POST["area"][0]);
902  } else {
903  $_SESSION["il_map_el_href"] = $this->getHrefOfArea($_POST["area"][0]);
904  }
905  }
906 
907  return $this->editMapArea(false, false, true, "link", $_POST["area"][0]);
908  }
909 
913  public function getLinkTypeOfArea($a_nr)
914  {
915  $st_item = $this->media_object->getMediaItem("Standard");
916  $area = $st_item->getMapArea($a_nr);
917  return $area->getLinkType();
918  }
919 
923  public function getTypeOfArea($a_nr)
924  {
925  $st_item = $this->media_object->getMediaItem("Standard");
926  $area = $st_item->getMapArea($a_nr);
927  return $area->getType();
928  }
929 
933  public function getTargetOfArea($a_nr)
934  {
935  $st_item = $this->media_object->getMediaItem("Standard");
936  $area = $st_item->getMapArea($a_nr);
937  return $area->getTarget();
938  }
939 
943  public function getTargetFrameOfArea($a_nr)
944  {
945  $st_item = $this->media_object->getMediaItem("Standard");
946  $area = $st_item->getMapArea($a_nr);
947  return $area->getTargetFrame();
948  }
949 
953  public function getHrefOfArea($a_nr)
954  {
955  $st_item = $this->media_object->getMediaItem("Standard");
956  $area = $st_item->getMapArea($a_nr);
957  return $area->getHref();
958  }
959 
963  public function deleteAreas()
964  {
966  $lng = $this->lng;
967 
968  if (!isset($_POST["area"])) {
969  ilUtil::sendFailure($lng->txt("no_checkbox"), true);
970  $ilCtrl->redirect($this, "editMapAreas");
971  }
972 
973  $st_item = $this->media_object->getMediaItem("Standard");
974  $max = ilMapArea::_getMaxNr($st_item->getId());
975 
976  if (count($_POST["area"]) > 0) {
977  $i = 0;
978 
979  foreach ($_POST["area"] as $area_nr) {
980  $st_item->deleteMapArea($area_nr - $i);
981  $i++;
982  }
983 
984  $this->media_object->update();
985  ilUtil::sendSuccess($lng->txt("cont_areas_deleted"), true);
986  }
987 
988  $ilCtrl->redirect($this, "editMapAreas");
989  }
990 
994  public function editLink()
995  {
996  $_SESSION["il_map_edit_coords"] = "";
997  $_SESSION["il_map_edit_mode"] = "";
998  $_SESSION["il_map_el_href"] = "";
999  $_SESSION["il_map_il_type"] = "";
1000  $_SESSION["il_map_il_ltype"] = "";
1001  $_SESSION["il_map_il_target"] = "";
1002  $_SESSION["il_map_il_targetframe"] = "";
1003  $_SESSION["il_map_area_nr"] = "";
1004  return $this->setLink(false);
1005  }
1006 
1010  public function editShapeWholePicture()
1011  {
1012  $this->clearSessionVars();
1013  $_SESSION["il_map_edit_area_type"] = "WholePicture";
1014  return $this->setShape(false);
1015  }
1016 
1020  public function editShapeRectangle()
1021  {
1022  $this->clearSessionVars();
1023  $_SESSION["il_map_edit_area_type"] = "Rect";
1024  return $this->setShape(false);
1025  }
1026 
1030  public function editShapeCircle()
1031  {
1032  $this->clearSessionVars();
1033  $_SESSION["il_map_edit_area_type"] = "Circle";
1034  return $this->setShape(false);
1035  }
1036 
1040  public function editShapePolygon()
1041  {
1042  $this->clearSessionVars();
1043  $_SESSION["il_map_edit_area_type"] = "Poly";
1044  return $this->setShape(false);
1045  }
1046 
1050  public function setShape($a_handle = true)
1051  {
1052  $lng = $this->lng;
1053  $ilCtrl = $this->ctrl;
1054 
1055  if ($a_handle) {
1056  $this->handleMapParameters();
1057  }
1058  if ($_POST["areatype2"] != "") {
1059  $_SESSION["il_map_edit_area_type"] = $_POST["areatype2"];
1060  }
1061  if ($_SESSION["il_map_area_nr"] != "") {
1062  $_POST["area"][0] = $_SESSION["il_map_area_nr"];
1063  }
1064  if (!isset($_POST["area"])) {
1065  ilUtil::sendFailure($lng->txt("no_checkbox"), true);
1066  $ilCtrl->redirect($this, "editMapAreas");
1067  }
1068 
1069  if (count($_POST["area"]) > 1) {
1070  ilUtil::sendFailure($lng->txt("cont_select_max_one_item"), true);
1071  $ilCtrl->redirect($this, "editMapAreas");
1072  }
1073 
1074  if ($_SESSION["il_map_edit_mode"] != "edit_shape") {
1075  $_SESSION["il_map_area_nr"] = $_POST["area"][0];
1076  $_SESSION["il_map_edit_mode"] = "edit_shape";
1077  $_SESSION["il_map_edit_target_script"] = $ilCtrl->getLinkTarget($this, "setShape", "", false, false);
1078  }
1079 
1080 
1081  $area_type = $_SESSION["il_map_edit_area_type"];
1082  $coords = $_SESSION["il_map_edit_coords"];
1083  $cnt_coords = ilMapArea::countCoords($coords);
1084 
1085  // decide what to do next
1086  switch ($area_type) {
1087  // Rectangle
1088  case "Rect":
1089  if ($cnt_coords < 2) {
1090  return $this->editMapArea(true, false, false, "shape", $_POST["area"][0]);
1091  } elseif ($cnt_coords == 2) {
1092  return $this->saveArea();
1093  }
1094  break;
1095 
1096  // Circle
1097  case "Circle":
1098  if ($cnt_coords <= 1) {
1099  return $this->editMapArea(true, false, false, "shape", $_POST["area"][0]);
1100  } else {
1101  if ($cnt_coords == 2) {
1102  $c = explode(",", $coords);
1103  $coords = $c[0] . "," . $c[1] . ","; // determine radius
1104  $coords .= round(sqrt(pow(abs($c[3]-$c[1]), 2)+pow(abs($c[2]-$c[0]), 2)));
1105  }
1106  $_SESSION["il_map_edit_coords"] = $coords;
1107 
1108  return $this->saveArea();
1109  }
1110  break;
1111 
1112  // Polygon
1113  case "Poly":
1114  if ($cnt_coords < 1) {
1115  return $this->editMapArea(true, false, false, "shape", $_POST["area"][0]);
1116  } elseif ($cnt_coords < 3) {
1117  return $this->editMapArea(true, true, false, "shape", $_POST["area"][0]);
1118  } else {
1119  return $this->editMapArea(true, true, true, "shape", $_POST["area"][0]);
1120  }
1121  break;
1122 
1123  // Whole Picture
1124  case "WholePicture":
1125  return $this->saveArea();
1126  }
1127  }
1128 
1135  public function setHighlight()
1136  {
1137  $ilCtrl = $this->ctrl;
1138  $lng = $this->lng;
1139 
1140  $st_item = $this->media_object->getMediaItem("Standard");
1141  $st_item->setHighlightMode(ilUtil::stripSlashes($_POST["highlight_mode"]));
1142  $st_item->setHighlightClass(ilUtil::stripSlashes($_POST["highlight_class"]));
1143  $st_item->update();
1144 
1145  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
1146  $ilCtrl->redirect($this, "editMapAreas");
1147  }
1148 }
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
$params
Definition: disable.php:11
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.
global $DIC
Definition: saml.php:7
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.
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.
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.
$coords
Definition: example_030.php:88
setInternalLink()
Set internal link.
initAreaEditingForm($a_edit_property)
Init area editing form.
const IL_NO_LINK
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:92
editShapeCircle()
Edit an existing shape (make it a circle)
xslt_error(&$proc)
$xml
Definition: metadata.php:240
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(isset($_POST['submit'])) $form
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)
$ret
Definition: parser.php:6
$i
Definition: disco.tpl.php:19
getAdditionalPageXML()
Get additional page xml (to be overwritten)
getTypeOfArea($a_nr)
Get Type of Area (only internal link)
TableGUI class for image map editor.
const IL_MODE_OUTPUT
executeCommand()
Execute current command.
addRectangle()
Add a new rectangle.
getImageMapTableHTML()
Get table HTML.
setLinkType($a_link_type)
set link type
static redirect($a_script)
makeMapWorkCopy( $a_edit_property="", $a_area_nr=0, $a_output_new_area=false, $a_area_type="", $a_coords="")
Make work file for editing.
static getWebspaceDir($mode="filesystem")
get webspace directory
$_POST["username"]
$html
Definition: example_001.php:87
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)
if(!isset($_REQUEST['ReturnTo'])) if(!isset($_REQUEST['AuthId'])) $options
Definition: as_login.php:20