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