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