ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilInternalLinkGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 require_once("./Modules/LearningModule/classes/class.ilLMPageObject.php");
5 require_once("./Services/MediaObjects/classes/class.ilObjMediaObjectGUI.php");
6 
18 {
23  var $lng;
24  var $mode; // "text" | "link"
26  var $ctrl;
27  var $tree;
28 
29  function ilInternalLinkGUI($a_default_type, $a_default_obj)
30  {
31  global $lng, $ilias, $ilCtrl, $tree;
32 
33  if (($_SESSION["il_link_cont_obj"] != "" && !$tree->isInTree($_SESSION["il_link_cont_obj"])) ||
34  ($_SESSION["il_link_glossary"] != "" && !$tree->isInTree($_SESSION["il_link_glossary"])) ||
35  ($_SESSION["il_link_mep"] != "" && !$tree->isInTree($_SESSION["il_link_mep"])))
36  {
37  $this->resetSessionVars();
38  }
39 
40  $this->lng =& $lng;
41  $this->tree =& $tree;
42  $this->ilias =& $ilias;
43  $this->ctrl =& $ilCtrl;
44  $this->ctrl->saveParameter($this, array("linkmode", "target_type"));
45  $this->default_type = $a_default_type;
46  $this->default_obj = $a_default_obj;
47  $this->filter_link_types = array();
48  $this->mode = "text";
49 
50  // determine link type and target
51  $this->determineLinkType();
52 
53  $def_type = ilObject::_lookupType($this->default_obj, true);
54 
55  // determine content object id
56  switch($this->link_type)
57  {
58  case "PageObject":
59  case "StructureObject":
60  if (empty($_SESSION["il_link_cont_obj"]) &&
61  ($def_type != "mep" && $def_type != "glo"))
62  {
63  $_SESSION["il_link_cont_obj"] = $this->default_obj;
64  }
65  break;
66 
67  case "GlossaryItem":
68  if (empty($_SESSION["il_link_glossary"]) && $def_type == "glo")
69  {
70  $_SESSION["il_link_glossary"] = $this->default_obj;
71  }
72  break;
73 
74  case "Media":
75  if (empty($_SESSION["il_link_mep"]) && $def_type == "mep")
76  {
77  $_SESSION["il_link_mep"] = $this->default_obj;
78  }
79  break;
80  }
81 
82  /*
83  $target_str = ($link_target == "")
84  ? ""
85  : " target=\"".$link_target."\" ";*/
86  }
87 
88  function determineLinkType()
89  {
90  // determine link type and target
91  $ltype = ($_SESSION["il_link_type"] == "")
92  ? $this->default_type
93  : $_SESSION["il_link_type"];
94  $ltype_arr = explode("_", $ltype);
95  $this->link_type = ($ltype_arr[0] == "")
96  ? $this->default_type
97  : $ltype_arr[0];
98  $this->link_target = $ltype_arr[1];
99  }
100 
101  function setMode($a_mode = "text")
102  {
103  $this->mode = $a_mode;
104  }
105 
106  function setSetLinkTargetScript($a_script)
107  {
108  $this->set_link_script = $a_script;
109  }
110 
111  function setReturn($a_return)
112  {
113  $this->return = $a_return;
114  }
115 
117  {
118  return $this->set_link_script;
119  }
120 
121  function filterLinkType($a_link_type)
122  {
123  $this->filter_link_types[] = $a_link_type;
124  }
125 
126  function &executeCommand()
127  {
128  $next_class = $this->ctrl->getNextClass($this);
129 
130  $cmd = $this->ctrl->getCmd("showLinkHelp");
131  switch($next_class)
132  {
133  default:
134  $ret =& $this->$cmd();
135  break;
136  }
137 
138  return $ret;
139  }
140 
141  function resetSessionVars()
142  {
143  $_SESSION["il_link_mep"] = "";
144  $_SESSION["il_link_mep_obj"] = "";
145  $_SESSION["il_link_type"] = "";
146  }
147 
148  function resetLinkList()
149  {
150  $this->resetSessionVars();
151  $this->determineLinkType();
152  $this->showLinkHelp();
153  }
154 
155  function closeLinkHelp()
156  {
157  if ($this->return == "")
158  {
159  $this->ctrl->returnToParent($this);
160  }
161  else
162  {
163  ilUtil::redirect($this->return);
164  }
165  }
166 
167 
168  function prepareJavascriptOutput($str)
169  {
170  global $ilUser;
171 
172  include_once("./Services/COPage/classes/class.ilPageEditorGUI.php");
174  {
175  $str = htmlspecialchars($str, ENT_QUOTES);
176  }
177  return($str);
178  }
179 
180 
184  function showLinkHelp()
185  {
186  global $ilUser;
187 
188  $target_str = ($this->link_target == "")
189  ? ""
190  : " target=\"".$this->link_target."\"";
191 
192  if(($this->link_type == "GlossaryItem") &&
193  empty($_SESSION["il_link_glossary"]))
194  {
195  $this->changeTargetObject("glo");
196  }
197  if(($this->link_type == "PageObject" || $this->link_type == "StructureObject") &&
198  empty($_SESSION["il_link_cont_obj"]))
199  {
200  $this->changeTargetObject("cont_obj");
201  }
202 
203  $tpl =& new ilTemplate("tpl.link_help.html", true, true, "Modules/LearningModule");
204  $tpl->setVariable("LOCATION_STYLESHEET", ilUtil::getStyleSheetLocation());
205 
206  switch($this->link_type)
207  {
208  case "GlossaryItem":
209  $this->ctrl->setParameter($this, "target_type", "glo");
210  break;
211 
212  case "PageObject":
213  case "StructureObject":
214  $this->ctrl->setParameter($this, "target_type", "cont_obj");
215  break;
216 
217  case "Media":
218  $this->ctrl->setParameter($this, "target_type", "mep");
219  break;
220 
221  default:
222  break;
223  }
224 //echo "<br><br>:".$this->ctrl->getFormAction($this).":";
225 //echo "<br>link_type:".$this->link_type;
226 //echo "<br>cont_obj:".$_SESSION["il_link_cont_obj"];
227 //echo "<br>link_mep".$_SESSION["il_link_mep"];
228  $tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
229  $tpl->setVariable("FORMACTION2", $this->ctrl->getFormAction($this));
230  $tpl->setVariable("TXT_HELP_HEADER", $this->lng->txt("cont_link_select"));
231  $tpl->setVariable("TXT_TYPE", $this->lng->txt("cont_link_type"));
232  $ltypes = array("StructureObject" => $this->lng->txt("cont_lk_chapter"),
233  "StructureObject_New" => $this->lng->txt("cont_lk_chapter_new"),
234  "PageObject" => $this->lng->txt("cont_lk_page"),
235  "PageObject_FAQ" => $this->lng->txt("cont_lk_page_faq"),
236  "PageObject_New" => $this->lng->txt("cont_lk_page_new"),
237  "GlossaryItem" => $this->lng->txt("cont_lk_term"),
238  "GlossaryItem_New" => $this->lng->txt("cont_lk_term_new"),
239  "Media" => $this->lng->txt("cont_lk_media_inline"),
240  "Media_Media" => $this->lng->txt("cont_lk_media_media"),
241  "Media_FAQ" => $this->lng->txt("cont_lk_media_faq"),
242  "Media_New" => $this->lng->txt("cont_lk_media_new"),
243  "RepositoryItem" => $this->lng->txt("cont_repository_item")
244  );
245 
246  // filter link types
247  foreach($this->filter_link_types as $link_type)
248  {
249  unset($ltypes[$link_type]);
250  }
251 
252  $ltype = ($this->link_target != "")
253  ? $this->link_type."_".$this->link_target
254  : $this->link_type;
255 
256 //echo "<br><br>".$ltype;
257 
258  $select_ltype = ilUtil::formSelect ($ltype,
259  "ltype", $ltypes, false, true);
260  $tpl->setVariable("SELECT_TYPE", $select_ltype);
261  $tpl->setVariable("CMD_CHANGETYPE", "changeLinkType");
262  $tpl->setVariable("BTN_CHANGETYPE", $this->lng->txt("cont_change_type"));
263 
264 /* if ($this->isEnabledJavaScript())
265  {
266  $tpl->setVariable("BTN_CLOSE_JS", $this->lng->txt("close"));
267  }
268  else
269  {*/
270  $tpl->setVariable("CMD_CLOSE", "closeLinkHelp");
271  $tpl->setVariable("BTN_CLOSE", $this->lng->txt("close"));
272 // }
273 
274  $chapterRowBlock = "chapter_row";
275  $anchor_row_block = "anchor_link";
276  if ($this->isEnabledJavaScript())
277  {
278  $chapterRowBlock .= "_js";
279  $anchor_row_block .= "_js";
280  }
281 
282  $obj_id = ilObject::_lookupObjId($_SESSION["il_link_cont_obj"]);
283  $type = ilObject::_lookupType($obj_id);
284 
285  switch($this->link_type)
286  {
287  // page link
288  case "PageObject":
289  if ($type == "lm")
290  {
291  require_once("./Modules/LearningModule/classes/class.ilObjLearningModule.php");
292  $cont_obj =& new ilObjLearningModule($_SESSION["il_link_cont_obj"], true);
293  }
294  else if ($type == "dbk")
295  {
296  require_once("./Modules/LearningModule/classes/class.ilObjDlBook.php");
297  $cont_obj =& new ilObjDlBook($_SESSION["il_link_cont_obj"], true);
298  }
299 
300  // get all chapters
301  $ctree =& $cont_obj->getLMTree();
302  $nodes = $ctree->getSubtree($ctree->getNodeData($ctree->getRootId()));
303  $tpl->setCurrentBlock("chapter_list");
304  $tpl->setVariable("TXT_CONTENT_OBJECT", $this->lng->txt("cont_content_obj"));
305  $tpl->setVariable("TXT_CONT_TITLE", $cont_obj->getTitle());
306  $tpl->setCurrentBlock("change_cont_obj");
307  $tpl->setVariable("CMD_CHANGE_CONT_OBJ", "changeTargetObject");
308  $tpl->setVariable("BTN_CHANGE_CONT_OBJ", $this->lng->txt("change"));
309  $tpl->parseCurrentBlock();
310 
311  foreach($nodes as $node)
312  {
313  if($node["type"] == "st")
314  {
315  $tpl->setCurrentBlock("chapter_row");
316  $tpl->setVariable("TXT_CHAPTER", $node["title"]);
317  $tpl->setVariable("ROWCLASS", "tblrow1");
318  //$tpl->setVariable("LINK_CHAPTER",
319  // "[iln chap=\"".$node["obj_id"]."\"".$target_str."] [/iln]");
320  $tpl->parseCurrentBlock();
321  }
322 
323  if($node["type"] == "pg")
324  {
325  switch ($this->mode)
326  {
327  case "link":
328  require_once("./Services/MediaObjects/classes/class.ilObjMediaObjectGUI.php");
329  require_once("./Services/MediaObjects/classes/class.ilImageMapEditorGUI.php");
331  $tpl->setCurrentBlock("link_row");
332  $tpl->setVariable("ROWCLASS", "tblrow2");
333  $tpl->setVariable("TXT_CHAPTER", $node["title"]);
334  $tpl->setVariable("LINK_TARGET", "content");
335  $tpl->setVariable("LINK",
337  "linktype=PageObject".
338  "&linktarget=il__pg_".$node["obj_id"].
339  "&linktargetframe=".$this->link_target));
340  $tpl->parseCurrentBlock();
341  break;
342 
343  default:
344  $anchors = ilPageObject::_readAnchors($type, $node["obj_id"]);
345  if (count($anchors) > 0)
346  {
347  foreach ($anchors as $anchor)
348  {
349  $tpl->setCurrentBlock($anchor_row_block);
350  $tpl->setVariable("TXT_LINK", "#".$anchor);
351  $tpl->setVariable("HREF_LINK",
352  $this->prepareJavascriptOutput("[iln page=\"".$node["obj_id"]."\"".$target_str." anchor=\"$anchor\"] [/iln]"));
353  $tpl->parseCurrentBlock();
354  }
355  }
356  $tpl->setCurrentBlock($chapterRowBlock);
357  $tpl->setVariable("TXT_CHAPTER", $node["title"]);
358  if ($this->isEnabledJavaScript())
359  {
360  $tpl->setVariable("TXT_CHAPTER_JS", htmlspecialchars(str_replace("'", "\'", $node["title"])));
361  }
362  $tpl->setVariable("ROWCLASS", "tblrow2");
363  $tpl->setVariable("LINK_CHAPTER",
364  $this->prepareJavascriptOutput("[iln page=\"".$node["obj_id"]."\"".$target_str."] [/iln]"));
365  $tpl->parseCurrentBlock();
366  break;
367  }
368  }
369  $tpl->setCurrentBlock("row");
370  $tpl->parseCurrentBlock();
371  }
372 
373  // get all free pages
374  $pages = ilLMPageObject::getPageList($cont_obj->getId());
375  $free_pages = array();
376  foreach ($pages as $page)
377  {
378  if (!$ctree->isInTree($page["obj_id"]))
379  {
380  $free_pages[] = $page;
381  }
382  }
383  if(count($free_pages) > 0)
384  {
385  $tpl->setCurrentBlock(str_replace("_js","",$chapterRowBlock));
386  $tpl->setVariable("TXT_CHAPTER", $this->lng->txt("cont_free_pages"));
387  $tpl->setVariable("ROWCLASS", "tblrow1");
388  $tpl->parseCurrentBlock();
389 
390  foreach ($free_pages as $node)
391  {
392  switch ($this->mode)
393  {
394  case "link":
395  require_once("./Services/MediaObjects/classes/class.ilObjMediaObjectGUI.php");
396  require_once("./Services/MediaObjects/classes/class.ilImageMapEditorGUI.php");
398  $tpl->setCurrentBlock("link_row");
399  $tpl->setVariable("ROWCLASS", "tblrow2");
400  $tpl->setVariable("TXT_CHAPTER", $node["title"]);
401  $tpl->setVariable("LINK_TARGET", "content");
402  $tpl->setVariable("LINK",
404  "linktype=PageObject".
405  "&linktarget=il__pg_".$node["obj_id"].
406  "&linktargetframe=".$this->link_target));
407  $tpl->parseCurrentBlock();
408  break;
409 
410  default:
411  $tpl->setCurrentBlock($chapterRowBlock);
412  $tpl->setVariable("TXT_CHAPTER", $node["title"]);
413  if ($this->isEnabledJavaScript())
414  {
415  $tpl->setVariable("TXT_CHAPTER_JS", htmlspecialchars(str_replace("'", "\'", $node["title"])));
416  }
417  $tpl->setVariable("ROWCLASS", "tblrow2");
418  $tpl->setVariable("LINK_CHAPTER",
419  $this->prepareJavascriptOutput("[iln page=\"".$node["obj_id"]."\"".$target_str."] [/iln]"));
420  $tpl->parseCurrentBlock();
421  break;
422  }
423  }
424  }
425 
426  $tpl->setCurrentBlock("chapter_list");
427  $tpl->parseCurrentBlock();
428 
429  break;
430 
431  // chapter link
432  case "StructureObject":
433 
434  //echo "-$type-".$_SESSION["il_link_cont_obj"]."-";
435  if ($type == "lm")
436  {
437  require_once("./Modules/LearningModule/classes/class.ilObjLearningModule.php");
438  $cont_obj =& new ilObjLearningModule($_SESSION["il_link_cont_obj"], true);
439  }
440  else if ($type == "dbk")
441  {
442  require_once("./Modules/LearningModule/classes/class.ilObjDlBook.php");
443  $cont_obj =& new ilObjDlBook($_SESSION["il_link_cont_obj"], true);
444  }
445 
446  // get all chapters
447  $ctree =& $cont_obj->getLMTree();
448  $nodes = $ctree->getSubtree($ctree->getNodeData($ctree->getRootId()));
449  $tpl->setCurrentBlock("chapter_list");
450  $tpl->setVariable("TXT_CONTENT_OBJECT", $this->lng->txt("cont_content_obj"));
451  $tpl->setVariable("TXT_CONT_TITLE", $cont_obj->getTitle());
452  $tpl->setCurrentBlock("change_cont_obj");
453  $tpl->setVariable("CMD_CHANGE_CONT_OBJ", "changeTargetObject");
454  $tpl->setVariable("BTN_CHANGE_CONT_OBJ", $this->lng->txt("change"));
455  $tpl->parseCurrentBlock();
456 
457  foreach($nodes as $node)
458  {
459  if($node["type"] == "st")
460  {
461  $css_row = ($css_row == "tblrow1")
462  ? "tblrow2"
463  : "tblrow1";
464 
465  switch ($this->mode)
466  {
467  case "link":
468  require_once("./Services/MediaObjects/classes/class.ilObjMediaObjectGUI.php");
469  require_once("./Services/MediaObjects/classes/class.ilImageMapEditorGUI.php");
471  $tpl->setCurrentBlock("link_row");
472  $tpl->setVariable("ROWCLASS", $css_row);
473  $tpl->setVariable("TXT_CHAPTER", $node["title"]);
474  $tpl->setVariable("LINK_TARGET", "content");
475  $tpl->setVariable("LINK",
477  "linktype=StructureObject".
478  "&linktarget=il__st_".$node["obj_id"].
479  "&linktargetframe=".$this->link_target));
480  $tpl->parseCurrentBlock();
481  break;
482 
483  default:
484  $tpl->setCurrentBlock($chapterRowBlock);
485  $tpl->setVariable("ROWCLASS", $css_row);
486  $tpl->setVariable("TXT_CHAPTER", $node["title"]);
487  if ($this->isEnabledJavaScript())
488  {
489  $tpl->setVariable("TXT_CHAPTER_JS", htmlspecialchars(str_replace("'", "\'", $node["title"])));
490  }
491  $tpl->setVariable("LINK_CHAPTER",
492  $this->prepareJavascriptOutput("[iln chap=\"".$node["obj_id"]."\"".$target_str."] [/iln]"));
493  $tpl->parseCurrentBlock();
494  break;
495  }
496  }
497  $tpl->setCurrentBlock("row");
498  $tpl->parseCurrentBlock();
499  }
500  $tpl->setCurrentBlock("chapter_list");
501  $tpl->parseCurrentBlock();
502  break;
503 
504  // glossary item link
505  case "GlossaryItem":
506  require_once("./Modules/Glossary/classes/class.ilObjGlossary.php");
507  $glossary =& new ilObjGlossary($_SESSION["il_link_glossary"], true);
508 
509  // get all glossary items
510  $terms = $glossary->getTermList();
511  $tpl->setCurrentBlock("chapter_list");
512  $tpl->setVariable("TXT_CONTENT_OBJECT", $this->lng->txt("glossary"));
513  $tpl->setVariable("TXT_CONT_TITLE", $glossary->getTitle());
514  $tpl->setCurrentBlock("change_cont_obj");
515  $tpl->setVariable("CMD_CHANGE_CONT_OBJ", "changeTargetObject");
516  $tpl->setVariable("BTN_CHANGE_CONT_OBJ", $this->lng->txt("change"));
517  $tpl->parseCurrentBlock();
518 
519  foreach($terms as $term)
520  {
521  $css_row = ($css_row =="tblrow1")
522  ? "tblrow2"
523  : "tblrow1";
524 
525  switch ($this->mode)
526  {
527  case "link":
528  require_once("./Services/MediaObjects/classes/class.ilObjMediaObjectGUI.php");
529  require_once("./Services/MediaObjects/classes/class.ilImageMapEditorGUI.php");
531  $tpl->setCurrentBlock("link_row");
532  $tpl->setVariable("ROWCLASS", "tblrow2");
533  $tpl->setVariable("TXT_CHAPTER", $term["term"]);
534  $tpl->setVariable("LINK_TARGET", "content");
535  $tpl->setVariable("LINK",
537  "linktype=GlossaryItem".
538  "&linktarget=il__git_".$term["id"].
539  "&linktargetframe=".$this->link_target));
540  $tpl->parseCurrentBlock();
541  break;
542 
543  default:
544  $tpl->setCurrentBlock($chapterRowBlock);
545  $tpl->setVariable("ROWCLASS", $css_row);
546  $tpl->setVariable("TXT_CHAPTER", $term["term"]);
547  if ($this->isEnabledJavaScript())
548  {
549  $tpl->setVariable("TXT_CHAPTER_JS", htmlspecialchars(str_replace("'", "\'", $term["term"])));
550  }
551 
552  $tpl->setVariable("LINK_CHAPTER",
553  $this->prepareJavascriptOutput("[iln term=\"".$term["id"]."\"".$target_str."]"." "."[/iln]"));
554  $tpl->parseCurrentBlock();
555  $tpl->setCurrentBlock("row");
556  $tpl->parseCurrentBlock();
557  break;
558  }
559  }
560 
561  $tpl->setCurrentBlock("chapter_list");
562  $tpl->parseCurrentBlock();
563  break;
564 
565  // media object
566  case "Media":
567  include_once("./Modules/MediaPool/classes/class.ilMediaPoolItem.php");
568  //$tpl->setVariable("TARGET2", " target=\"content\" ");
569  // content object id = 0 --> get clipboard objects
570  if ($_SESSION["il_link_mep"] == 0)
571  {
572  $tpl->setCurrentBlock("change_cont_obj");
573  $tpl->setVariable("CMD_CHANGE_CONT_OBJ", "changeTargetObject");
574  $tpl->setVariable("BTN_CHANGE_CONT_OBJ", $this->lng->txt("change"));
575  $tpl->parseCurrentBlock();
576  $mobjs = $this->ilias->account->getClipboardObjects("mob");
577  // sort by name
578  $objs = array();
579  foreach ($mobjs as $obj)
580  {
581  $objs[$obj["title"].":".$obj["id"]] = $obj;
582  }
583  ksort($objs);
584  $tpl->setCurrentBlock("chapter_list");
585  $tpl->setVariable("TXT_CONTENT_OBJECT", $this->lng->txt("cont_media_source"));
586  $tpl->setVariable("TXT_CONT_TITLE", $this->lng->txt("cont_personal_clipboard"));
587  $tpl->setVariable("COLSPAN", "2");
588 
589  foreach($objs as $obj)
590  {
591  switch ($this->mode)
592  {
593  case "link":
594  require_once("./Services/MediaObjects/classes/class.ilObjMediaObjectGUI.php");
595  require_once("./Services/MediaObjects/classes/class.ilImageMapEditorGUI.php");
597  $tpl->setCurrentBlock("link_row");
598  $this->outputThumbnail($tpl, $obj["id"], "link");
599  $tpl->setCurrentBlock("link_row");
600 
601  $tpl->setCurrentBlock("link_row");
602  $tpl->setVariable("ROWCLASS", "tblrow2");
603  $tpl->setVariable("TXT_CHAPTER", $obj["title"]);
604  $tpl->setVariable("LINK_TARGET", "content");
605  $tpl->setVariable("LINK",
607  "linktype=MediaObject".
608  "&linktarget=il__mob_".$obj["id"].
609  "&linktargetframe=".$this->link_target));
610  $tpl->parseCurrentBlock();
611  break;
612 
613  default:
614  $tpl->setCurrentBlock($chapterRowBlock);
615  $this->outputThumbnail($tpl, $obj["id"]);
616  $tpl->setCurrentBlock($chapterRowBlock);
617  $tpl->setVariable("TXT_CHAPTER", $obj["title"]);
618  if ($this->isEnabledJavaScript())
619  {
620  $tpl->setVariable("TXT_CHAPTER_JS", htmlspecialchars(str_replace("'", "\'", $obj["title"])));
621  }
622  $tpl->setVariable("ROWCLASS", "tblrow1");
623  if (!empty($target_str))
624  {
625  $tpl->setVariable("LINK_CHAPTER",
626  $this->prepareJavascriptOutput("[iln media=\"".$obj["id"]."\"".$target_str."] [/iln]"));
627  }
628  else
629  {
630  $tpl->setVariable("LINK_CHAPTER",
631  $this->prepareJavascriptOutput("[iln media=\"".$obj["id"]."\"/]"));
632  }
633  $tpl->parseCurrentBlock();
634  $tpl->setCurrentBlock("row");
635  $tpl->parseCurrentBlock();
636  break;
637  }
638  }
639  $tpl->setCurrentBlock("chapter_list");
640  $tpl->parseCurrentBlock();
641  }
642  else
643  {
644  require_once("./Modules/MediaPool/classes/class.ilObjMediaPool.php");
645  $med_pool =& new ilObjMediaPool($_SESSION["il_link_mep"], true);
646  // get current folders
647  $fobjs = $med_pool->getChilds($_SESSION["il_link_mep_obj"], "fold");
648  $f2objs = array();
649  foreach ($fobjs as $obj)
650  {
651  $f2objs[$obj["title"].":".$obj["child"]] = $obj;
652  }
653  ksort($f2objs);
654  // get current media objects
655  $mobjs = $med_pool->getChilds($_SESSION["il_link_mep_obj"], "mob");
656  $m2objs = array();
657  foreach ($mobjs as $obj)
658  {
659  $m2objs[$obj["title"].":".$obj["child"]] = $obj;
660  }
661  ksort($m2objs);
662 
663  // merge everything together
664  $objs = array_merge($f2objs, $m2objs);
665 
666  $tpl->setCurrentBlock("chapter_list");
667  $tpl->setVariable("TXT_CONTENT_OBJECT", $this->lng->txt("mep"));
668  $tpl->setVariable("TXT_CONT_TITLE", $med_pool->getTitle());
669  $tpl->setCurrentBlock("change_cont_obj");
670  $tpl->setVariable("CMD_CHANGE_CONT_OBJ", "changeTargetObject");
671  $tpl->setVariable("BTN_CHANGE_CONT_OBJ", $this->lng->txt("change"));
672  $tpl->setVariable("COLSPAN", "2");
673  $tpl->parseCurrentBlock();
674  if ($parent_id = $med_pool->getParentId($_SESSION["il_link_mep_obj"]))
675  {
676  $css_row = "tblrow1";
677  $tpl->setCurrentBlock("icon");
678  $tpl->setVariable("ICON_SRC", ilUtil::getImagePath("icon_fold.gif"));
679  $tpl->parseCurrentBlock();
680  $tpl->setCurrentBlock("link_row");
681  $tpl->setVariable("ROWCLASS", $css_row);
682  $tpl->setVariable("TXT_CHAPTER", "..");
683  $this->ctrl->setParameter($this, "mep_fold", $parent_id);
684  $tpl->setVariable("LINK",
685  $this->ctrl->getLinkTarget($this, "setMedPoolFolder"));
686  $tpl->parseCurrentBlock();
687  $tpl->setCurrentBlock("row");
688  $tpl->parseCurrentBlock();
689  }
690  foreach($objs as $obj)
691  {
692  if($obj["type"] == "fold")
693  {
694  $css_row = ($css_row == "tblrow2")
695  ? "tblrow1"
696  : "tblrow2";
697  $tpl->setCurrentBlock("icon");
698  $tpl->setVariable("ICON_SRC", ilUtil::getImagePath("icon_fold.gif"));
699  $tpl->parseCurrentBlock();
700  $tpl->setCurrentBlock("link_row");
701  $tpl->setVariable("ROWCLASS", $css_row);
702  $tpl->setVariable("TXT_CHAPTER", $obj["title"]);
703  $this->ctrl->setParameter($this, "mep_fold", $obj["child"]);
704  $tpl->setVariable("LINK",
705  $this->ctrl->getLinkTarget($this, "setMedPoolFolder"));
706  $tpl->parseCurrentBlock();
707  }
708  else
709  {
710  $fid = ilMediaPoolItem::lookupForeignId($obj["child"]);
711  if (ilObject::_lookupType($fid) == "mob")
712  {
713  $css_row = ($css_row == "tblrow2")
714  ? "tblrow1"
715  : "tblrow2";
716  switch ($this->mode)
717  {
718  case "link":
719  require_once("./Services/MediaObjects/classes/class.ilObjMediaObjectGUI.php");
720  require_once("./Services/MediaObjects/classes/class.ilImageMapEditorGUI.php");
722  $tpl->setCurrentBlock("link_row");
723  $this->outputThumbnail($tpl, $fid, "link");
724  $tpl->setCurrentBlock("link_row");
725  $tpl->setVariable("ROWCLASS", $css_row);
726  $tpl->setVariable("TXT_CHAPTER", $obj["title"]);
727  $tpl->setVariable("LINK_TARGET", "content");
728  $tpl->setVariable("LINK",
730  "linktype=MediaObject".
731  "&linktarget=il__mob_".$fid.
732  "&linktargetframe=".$this->link_target));
733  $tpl->parseCurrentBlock();
734  break;
735 
736  default:
737  $tpl->setCurrentBlock($chapterRowBlock);
738  $this->outputThumbnail($tpl, $fid);
739  $tpl->setCurrentBlock($chapterRowBlock);
740  $tpl->setVariable("ROWCLASS", $css_row);
741  $tpl->setVariable("TXT_CHAPTER", $obj["title"]);
742  if ($this->isEnabledJavaScript())
743  {
744  $tpl->setVariable("TXT_CHAPTER_JS", htmlspecialchars(str_replace("'", "\'", $obj["title"])));
745  }
746  if ($target_str != "")
747  {
748  $tpl->setVariable("LINK_CHAPTER",
749  $this->prepareJavascriptOutput("[iln media=\"".$fid."\"".$target_str."] [/iln]"));
750  }
751  else
752  {
753  $tpl->setVariable("LINK_CHAPTER",
754  $this->prepareJavascriptOutput("[iln media=\"".$fid."\"/]"));
755  }
756  $tpl->parseCurrentBlock();
757  break;
758  }
759  }
760  }
761  $tpl->setCurrentBlock("row");
762  $tpl->parseCurrentBlock();
763  }
764  $tpl->setCurrentBlock("chapter_list");
765  $tpl->parseCurrentBlock();
766  }
767  break;
768 
769  // repository item
770  case "RepositoryItem":
771  $tpl->setVariable("LINK_HELP_CONTENT", $this->selectRepositoryItem());
772  break;
773 
774  }
775 
776 
777  $tpl->show();
778  exit;
779  }
780 
781 
785  function outputThumbnail(&$tpl, $a_id, $a_mode = "")
786  {
787  // output thumbnail
788  $mob =& new ilObjMediaObject($a_id);
789  $med =& $mob->getMediaItem("Standard");
790  $target = $med->getThumbnailTarget("small");
791  if ($a_mode == "link")
792  {
793  $tpl->setCurrentBlock("thumbnail_link");
794  }
795  else if ($this->isEnabledJavaScript())
796  {
797  $tpl->setCurrentBlock("thumbnail_js");
798  }
799  else
800  {
801  $tpl->setCurrentBlock("thumbnail");
802  }
803  if ($target != "")
804  {
805  $tpl->setCurrentBlock("thumb");
806  $tpl->setVariable("SRC_THUMB", $target);
807  $tpl->parseCurrentBlock();
808  }
809  else
810  {
811  $tpl->setVariable("NO_THUMB", "&nbsp;");
812  }
813 
814  if ($a_mode == "link")
815  {
816  $tpl->setCurrentBlock("thumbnail_link");
817  }
818  else if ($this->isEnabledJavaScript())
819 
820  {
821  $tpl->setCurrentBlock("thumbnail_js");
822  }
823  else
824  {
825  $tpl->setCurrentBlock("thumbnail");
826  }
827  $tpl->parseCurrentBlock();
828  }
829 
830 
834  function changeLinkType()
835  {
836  $_SESSION["il_link_type"] = $_POST["ltype"];
837  $this->determineLinkType();
838  $this->showLinkHelp();
839  }
840 
844  function setMedPoolFolder()
845  {
846  $_SESSION["il_link_mep_obj"] = $_GET["mep_fold"];
847  $this->showLinkHelp();
848  }
849 
853  function changeTargetObject($a_type = "")
854  {
855  $_SESSION["il_link_mep_obj"] = "";
856 
857  if($_GET["do"] == "set")
858  {
859  switch ($_GET["target_type"])
860  {
861  case "glo":
862  $_SESSION["il_link_glossary"] = $_GET["sel_id"];
863  break;
864 
865  case "mep":
866  $_SESSION["il_link_mep"] = $_GET["sel_id"];
867  break;
868 
869  default:
870  $_SESSION["il_link_cont_obj"] = $_GET["sel_id"];
871  break;
872  }
873  $this->showLinkHelp();
874  return;
875  }
876 
877  if(empty($a_type))
878  {
879  $a_type = $_GET["target_type"];
880  }
881 
882  $tpl =& new ilTemplate("tpl.link_help_explorer.html", true, true, "Modules/LearningModule");
883  $tpl->setVariable("LOCATION_STYLESHEET", ilUtil::getStyleSheetLocation());
884 
885  require_once "classes/class.ilExplorer.php";
886  //$tpl->addBlockFile("CONTENT", "content", "tpl.explorer.html");
887 
888 
889 //echo "<br><br>:".$this->ctrl->getLinkTarget($this).":<br>";
891  $this->ctrl->getTargetScript(), "do=set"));
892  if ($_GET["expand"] == "")
893  {
894  $expanded = $this->tree->readRootId();
895  }
896  else
897  {
898  $expanded = $_GET["expand"];
899  }
900  $exp->setExpand($expanded);
901 //echo "<br><br>exp:$expanded:<br>";
902 
903  $exp->setTargetGet("sel_id");
904  $this->ctrl->setParameter($this, "target_type", $a_type);
905  $exp->setParamsGet($this->ctrl->getParameterArray($this, "changeTargetObject"));
906 //echo "<br>"; var_dump($this->ctrl->getParameterArray($this, "changeTargetObject"));
907  /*$exp->setParamsGet(array("ref_id" => $_GET["ref_id"],
908  "cmd" => "changeTargetObject", "mode" => "page_edit", "obj_id" => $_GET["obj_id"],
909  "target_type" => $a_type, "linkmode" => $_GET["linkmode"]));*/
910 
911  $exp->addFilter("root");
912  $exp->addFilter("cat");
913  $exp->addFilter("grp");
914  $exp->addFilter("fold");
915  $exp->addFilter("crs");
916 
917  switch ($a_type)
918  {
919  case "glo":
920  $exp->addFilter("glo");
921  break;
922 
923  case "mep":
924  $exp->addFilter("mep");
925  break;
926 
927  default:
928  $exp->addFilter("lm");
929  $exp->addFilter("dbk");
930  break;
931  }
932  $exp->setFiltered(true);
933  $exp->setFilterMode(IL_FM_POSITIVE);
934 
935  $exp->setClickable("cat", false);
936  $exp->setClickable("grp", false);
937  $exp->setClickable("fold", false);
938  $exp->setClickable("crs", false);
939 
940  $exp->setFrameTarget("");
941  $exp->setOutput(0);
942 
943  $output = $exp->getOutput();
944 //echo "<br><br><br>out:".$output.":<br>";
945 
946  $tpl->setCurrentBlock("content");
947  if ($a_type == "glo")
948  {
949  $tpl->setVariable("TXT_EXPLORER_HEADER", $this->lng->txt("cont_choose_glossary"));
950  }
951  else if ($a_type == "mep")
952  {
953  $tpl->setVariable("TXT_EXPLORER_HEADER", $this->lng->txt("cont_choose_media_source"));
954  }
955  else
956  {
957  $tpl->setVariable("TXT_EXPLORER_HEADER", $this->lng->txt("cont_choose_cont_obj"));
958  }
959  $tpl->setVariable("EXPLORER",$output);
960  $tpl->setVariable("ACTION", $this->ctrl->getFormAction($this));
961  $tpl->setVariable("BTN_REFRESH", "changeTargetObject");
962  $tpl->setVariable("TXT_REFRESH", $this->lng->txt("refresh"));
963  $tpl->setVariable("BTN_RESET", "resetLinkList");
964  $tpl->setVariable("TXT_RESET", $this->lng->txt("reset"));
965 
966  if ($a_type == "mep")
967  {
968  $tpl->setCurrentBlock("sel_clipboard");
969  $this->ctrl->setParameter($this, "do", "set");
970  //$this->ctrl->setParameter($this, "sel_id", 0);
971  //$this->ctrl->setParameter($this, "target_type", "mep");
972  //$this->ctrl->setParameter($this, "linkmode", "");
973  //$this->ctrl->setParameter($this, "obj_id", "");
974  $tpl->setVariable("LINK_CLIPBOARD", $this->ctrl->getLinkTarget($this, "changeTargetObject"));
975  $tpl->setVariable("TXT_PERS_CLIPBOARD", $this->lng->txt("clipboard"));
976  $tpl->parseCurrentBlock();
977  }
978 
979  /*
980  $tpl->setVariable("BTN_STRUCTURE", "resetLinkList");
981  $tpl->setVariable("TXT_STRUCTURE", $this->lng->txt("reset"));*/
982  $tpl->parseCurrentBlock();
983 
984  $tpl->show();
985  exit;
986  }
987 
992  {
993  $_SESSION["il_link_mep_obj"] = "";
994 
995  if(empty($a_type))
996  {
997  $a_type = $_GET["target_type"];
998  }
999 
1000  $tpl =& new ilTemplate("tpl.link_help_explorer.html", true, true, "Modules/LearningModule");
1001  $tpl->setVariable("LOCATION_STYLESHEET", ilUtil::getStyleSheetLocation());
1002 
1003  include_once "./Modules/LearningModule/classes/class.ilIntLinkRepItemExplorer.php";
1005  $this->ctrl->getTargetScript(), "do=set"));
1006  if ($_GET["expand"] == "")
1007  {
1008  $expanded = $this->tree->readRootId();
1009  }
1010  else
1011  {
1012  $expanded = $_GET["expand"];
1013  }
1014  $exp->setMode($this->mode);
1015  $exp->setSetLinkTargetScript($this->getSetLinkTargetScript());
1016  $exp->setExpand($expanded);
1017 
1018  $exp->setTargetGet("sel_id");
1019  $this->ctrl->setParameter($this, "target_type", $a_type);
1020  $exp->setParamsGet($this->ctrl->getParameterArray($this, "showLinkHelp"));
1021 
1022  // filter
1023  $exp->setFiltered(true);
1024  $exp->setFilterMode(IL_FM_POSITIVE);
1025  $exp->addFilter("root");
1026  $exp->addFilter("cat");
1027  $exp->addFilter("grp");
1028  $exp->addFilter("fold");
1029  $exp->addFilter("crs");
1030  $exp->addFilter("lm");
1031  $exp->addFilter("htlm");
1032  $exp->addFilter("dbk");
1033  $exp->addFilter("glo");
1034  $exp->addFilter("frm");
1035  $exp->addFilter("exc");
1036  $exp->addFilter("tst");
1037  $exp->addFilter("svy");
1038  $exp->addFilter("webr");
1039  $exp->addFilter("file");
1040  $exp->addFilter("chat");
1041  $exp->addFilter("sahs");
1042  $exp->addFilter("mcst");
1043 
1044  $sel_types = array('lm','dbk','htlm','glo','frm','exc','tst','svy','webr','chat',
1045  'cat','crs','grp','file','fold','sahs','mcst');
1046  $exp->setSelectableTypes($sel_types);
1047 
1048  /*
1049  $exp->setClickable("cat", false);
1050  $exp->setClickable("grp", false);
1051  $exp->setClickable("fold", false);
1052  $exp->setClickable("crs", false);*/
1053 
1054  $exp->setFrameTarget("");
1055  $exp->setOutput(0);
1056 
1057  $output = $exp->getOutput();
1058 //echo "<br><br><br>out:".$output.":<br>";
1059 
1060  $tpl->setCurrentBlock("content");
1061  $tpl->setVariable("TXT_EXPLORER_HEADER", $this->lng->txt("cont_repository_item_links"));
1062  $tpl->setVariable("EXPLORER",$output);
1063  $tpl->setVariable("ACTION", $this->ctrl->getFormAction($this));
1064  $tpl->setVariable("BTN_REFRESH", "showLinkHelp");
1065  $tpl->setVariable("TXT_REFRESH", $this->lng->txt("refresh"));
1066  $tpl->setVariable("BTN_RESET", "resetLinkList");
1067  $tpl->setVariable("TXT_RESET", $this->lng->txt("reset"));
1068 
1069  /*
1070  $tpl->setVariable("BTN_STRUCTURE", "resetLinkList");
1071  $tpl->setVariable("TXT_STRUCTURE", $this->lng->txt("reset"));*/
1072  $tpl->parseCurrentBlock();
1073 
1074  return $tpl->get();
1075  //$tpl->show();
1076  //exit;
1077  }
1078 
1079 
1080 
1085  {
1086  global $ilias;
1087 
1088  include_once("./Services/COPage/classes/class.ilPageEditorGUI.php");
1089  if($ilias->getSetting("enable_js_edit"))
1090  {
1092  {
1093  return true;
1094  }
1095  }
1096  return false;
1097  }
1098 
1099 
1100 }
1101 ?>