ILIAS  Release_4_1_x_branch Revision 61804
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilGlossaryTermGUI.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 
5 require_once("./Modules/Glossary/classes/class.ilGlossaryTerm.php");
6 
18 {
19  var $ilias;
20  var $lng;
21  var $tpl;
22  var $glossary;
23  var $term;
24  var $link_xml;
25 
30  function ilGlossaryTermGUI($a_id = 0)
31  {
32  global $lng, $ilias, $tpl, $ilCtrl;
33 
34  $this->lng =& $lng;
35  $this->ilias =& $ilias;
36  $this->tpl =& $tpl;
37  $this->ctrl =& $ilCtrl;
38  $this->ctrl->saveParameter($this, array("term_id"));
39 
40  if($a_id != 0)
41  {
42  $this->term =& new ilGlossaryTerm($a_id);
43  }
44  }
45 
49  function executeCommand()
50  {
51  $next_class = $this->ctrl->getNextClass($this);
52  $cmd = $this->ctrl->getCmd();
53 
54  switch ($next_class)
55  {
56 
57  case "iltermdefinitioneditorgui":
58  //$this->ctrl->setReturn($this, "listDefinitions");
59  $def_edit =& new ilTermDefinitionEditorGUI();
60  //$ret =& $def_edit->executeCommand();
61  $ret =& $this->ctrl->forwardCommand($def_edit);
62  break;
63 
64  default:
65  $ret =& $this->$cmd();
66  break;
67  }
68  }
69 
75  function setOfflineDirectory ($offdir) {
76  $this->offline_directory = $offdir;
77  }
78 
79 
84  function getOfflineDirectory () {
85  return $this->offline_directory;
86  }
87 
88 
89  function setGlossary(&$a_glossary)
90  {
91  $this->glossary =& $a_glossary;
92  }
93 
94  function setLinkXML($a_link_xml)
95  {
96  $this->link_xml = $a_link_xml;
97  }
98 
99  function getLinkXML()
100  {
101  return $this->link_xml;
102  }
103 
107  function create()
108  {
109  global $ilUser;
110 
111  $this->getTemplate();
112  $this->displayLocator();
113  $this->tpl->setVariable("HEADER", $this->lng->txt("cont_new_term"));
114  $this->tpl->setTitleIcon(ilUtil::getImagePath("icon_term_b.gif"));
115  $this->setTabs();
116 
117  // load template for table
118  $this->tpl->addBlockfile("ADM_CONTENT", "adm_content", "tpl.glossary_term_new.html", true);
119  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
120  $this->tpl->setVariable("TXT_ACTION", $this->lng->txt("cont_new_term"));
121  $this->tpl->setVariable("TXT_TERM", $this->lng->txt("cont_term"));
122  $this->tpl->setVariable("INPUT_TERM", "term");
123  $this->tpl->setVariable("TXT_LANGUAGE", $this->lng->txt("language"));
125 
126  if ($_SESSION["il_text_lang_".$_GET["ref_id"]] != "")
127  {
128  $s_lang = $_SESSION["il_text_lang_".$_GET["ref_id"]];
129  }
130  else
131  {
132  $s_lang = $ilUser->getLanguage();
133  }
134 
135  $select_language = ilUtil::formSelect ($s_lang, "term_language",$lang,false,true);
136  $this->tpl->setVariable("SELECT_LANGUAGE", $select_language);
137  $this->tpl->setVariable("BTN_NAME", "saveTerm");
138  $this->tpl->setVariable("BTN_TEXT", $this->lng->txt("save"));
139  }
140 
144  function saveTerm()
145  {
146  $term =& new ilGlossaryTerm();
147  $term->setGlossary($this->glossary);
148  $term->setTerm(ilUtil::stripSlashes($_POST["term"]));
149  $term->setLanguage($_POST["term_language"]);
150  $_SESSION["il_text_lang_".$_GET["ref_id"]] = $_POST["term_language"];
151  $term->create();
152 
153  ilUtil::sendSuccess($this->lng->txt("cont_added_term"),true);
154  $this->ctrl->returnToParent($this);
155  }
156 
157 
161  function editTerm()
162  {
163  global $ilTabs;
164 
165  //$this->displayLocator();
166  $this->getTemplate();
167  $this->displayLocator();
168  $this->setTabs();
169  $ilTabs->activateTab("properties");
170 
171  //$this->displayLocator();
172  $this->tpl->setVariable("HEADER", $this->lng->txt("cont_term").": ".$this->term->getTerm());
173  $this->tpl->setTitleIcon(ilUtil::getImagePath("icon_term_b.gif"));
174 
175  // load template for table
176  $this->tpl->addBlockfile("ADM_CONTENT", "adm_content", "tpl.glossary_term_edit.html", true);
177  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this, "updateTerm"));
178  $this->tpl->setVariable("TXT_ACTION", $this->lng->txt("cont_edit_term"));
179  $this->tpl->setVariable("TXT_TERM", $this->lng->txt("cont_term"));
180  $this->tpl->setVariable("INPUT_TERM", "term");
181  $this->tpl->setVariable("VALUE_TERM", htmlspecialchars($this->term->getTerm()));
182  $this->tpl->setVariable("TXT_LANGUAGE", $this->lng->txt("language"));
184  $select_language = ilUtil::formSelect ($this->term->getLanguage(),"term_language",$lang,false,true);
185  $this->tpl->setVariable("SELECT_LANGUAGE", $select_language);
186  $this->tpl->setVariable("BTN_NAME", "updateTerm");
187  $this->tpl->setVariable("BTN_TEXT", $this->lng->txt("save"));
188  }
189 
190 
194  function updateTerm()
195  {
196  $this->term->setTerm(ilUtil::stripSlashes($_POST["term"]));
197  $this->term->setLanguage($_POST["term_language"]);
198  $this->term->update();
199  ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"),true);
200  $this->ctrl->redirect($this, "editTerm");
201  }
202 
209  function getOverlayHTML($a_close_el_id, $a_glo_ov_id = "")
210  {
211  global $lng;
212 
213  $tpl = new ilTemplate("tpl.glossary_overlay.html", true, true, "Modules/Glossary");
214  $this->output(true, $tpl);
215  if ($a_glo_ov_id != "")
216  {
217  $tpl->setCurrentBlock("glovlink");
218  $tpl->setVariable("TXT_LINK", $lng->txt("cont_sco_glossary"));
219  $tpl->setVariable("ID_LINK", $a_glo_ov_id);
220  $tpl->parseCurrentBlock();
221  }
222  $tpl->setVariable("TXT_CLOSE", $lng->txt("close"));
223  $tpl->setVariable("ID_CLOSE", $a_close_el_id);
224  return $tpl->get();
225  }
226 
232  function output($a_offline = false, $a_tpl = "")
233  {
234  if ($a_tpl != "")
235  {
236  $tpl = $a_tpl;
237  }
238  else
239  {
240  $tpl = $this->tpl;
241  }
242 
243  require_once("./Modules/Glossary/classes/class.ilGlossaryDefinition.php");
244  require_once("./Services/COPage/classes/class.ilPageObjectGUI.php");
245 
246  $defs = ilGlossaryDefinition::getDefinitionList($this->term->getId());
247 
248  $tpl->setVariable("TXT_TERM", $this->term->getTerm());
249 
250  for($j=0; $j<count($defs); $j++)
251  {
252  $def = $defs[$j];
253  $page_gui = new ilPageObjectGUI("gdf", $def["id"]);
254  $page_gui->setSourcecodeDownloadScript("ilias.php?baseClass=ilGlossaryPresentationGUI&amp;ref_id=".$_GET["ref_id"]);
255  if (!$a_offline)
256  {
257  //$page_gui->setFullscreenLink(
258  // "ilias.php?baseClass=ilGlossaryPresentationGUI&cmd=fullscreen&ref_id=".$_GET["ref_id"]);
259  }
260  else
261  {
262  $page_gui->setFullscreenLink("fullscreen.html"); // id is set by xslt
263  }
264  $page_gui->setFileDownloadLink("ilias.php?baseClass=ilGlossaryPresentationGUI&amp;cmd=downloadFile&amp;ref_id=".$_GET["ref_id"]);
265 
266  if (!$a_offline)
267  {
268  $page_gui->setOutputMode("presentation");
269  }
270  else
271  {
272  $page_gui->setOutputMode("offline");
273  $page_gui->setOfflineDirectory($this->getOfflineDirectory());
274  }
275 
276  //$page_gui->setOutputMode("edit");
277  //$page_gui->setPresentationTitle($this->term->getTerm());
278  $page_gui->setLinkXML($this->getLinkXML());
279  $page_gui->setTemplateOutput(false);
280  $output = $page_gui->presentation($page_gui->getOutputMode());
281 
282  if (count($defs) > 1)
283  {
284  $tpl->setCurrentBlock("definition_header");
285  $tpl->setVariable("TXT_DEFINITION",
286  $this->lng->txt("cont_definition")." ".($j+1));
287  $tpl->parseCurrentBlock();
288  }
289 
290  $tpl->setCurrentBlock("definition");
291  $tpl->setVariable("PAGE_CONTENT", $output);
292  $tpl->parseCurrentBlock();
293  }
294  }
295 
299  function getInternalLinks()
300  {
301  require_once("./Modules/Glossary/classes/class.ilGlossaryDefinition.php");
302  require_once("./Services/COPage/classes/class.ilPageObjectGUI.php");
303 
304  $defs = ilGlossaryDefinition::getDefinitionList($this->term->getId());
305 
306  $term_links = array();
307  for($j=0; $j<count($defs); $j++)
308  {
309  $def = $defs[$j];
310  $page = new ilPageObject("gdf", $def["id"]);
311  $page->buildDom();
312  $page_links = $page->getInternalLinks();
313  foreach($page_links as $key => $page_link)
314  {
315  $term_links[$key] = $page_link;
316  }
317  }
318 
319  return $term_links;
320  }
321 
325  function listDefinitions()
326  {
327  global $ilTabs;
328 
329  $this->getTemplate();
330  $this->displayLocator();
331  $this->setTabs();
332  $ilTabs->activateTab("definitions");
333 
334  require_once("./Services/COPage/classes/class.ilPageObjectGUI.php");
335 
336  // content style
337  $this->tpl->setCurrentBlock("ContentStyle");
338  $this->tpl->setVariable("LOCATION_CONTENT_STYLESHEET",
340  $this->tpl->parseCurrentBlock();
341 
342  // syntax style
343  $this->tpl->setCurrentBlock("SyntaxStyle");
344  $this->tpl->setVariable("LOCATION_SYNTAX_STYLESHEET",
346  $this->tpl->parseCurrentBlock();
347 
348  // load template for table
349  $this->tpl->addBlockfile("ADM_CONTENT", "def_list", "tpl.glossary_definition_list.html", true);
350  //$this->tpl->addBlockfile("CONTENT", "def_list", "tpl.glossary_definition_list.html", true);
351  //ilUtil::sendInfo();
352  $this->tpl->addBlockfile("STATUSLINE", "statusline", "tpl.statusline.html");
353  $this->tpl->setVariable("HEADER",
354  $this->lng->txt("cont_term").": ".$this->term->getTerm());
355  $this->tpl->setTitleIcon(ilUtil::getImagePath("icon_term_b.gif"));
356 
357  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
358 
359  $this->tpl->setCurrentBlock("add_def");
360  $this->tpl->setVariable("TXT_ADD_DEFINITION",
361  $this->lng->txt("cont_add_definition"));
362  $this->tpl->setVariable("BTN_ADD", "addDefinition");
363  $this->tpl->parseCurrentBlock();
364  $this->tpl->setCurrentBlock("def_list");
365 
367 
368  $this->tpl->setVariable("TXT_TERM", $this->term->getTerm());
369 
370  for($j=0; $j<count($defs); $j++)
371  {
372  $def = $defs[$j];
373  $page_gui = new ilPageObjectGUI("gdf", $def["id"]);
374  $page_gui->setSourcecodeDownloadScript("ilias.php?baseClass=ilGlossaryPresentationGUI&amp;ref_id=".$_GET["ref_id"]);
375  $page_gui->setTemplateOutput(false);
376  $output = $page_gui->preview();
377 
378  if (count($defs) > 1)
379  {
380  $this->tpl->setCurrentBlock("definition_header");
381  $this->tpl->setVariable("TXT_DEFINITION",
382  $this->lng->txt("cont_definition")." ".($j+1));
383  $this->tpl->parseCurrentBlock();
384  }
385 
386  if ($j > 0)
387  {
388  $this->tpl->setCurrentBlock("up");
389  $this->tpl->setVariable("TXT_UP", $this->lng->txt("up"));
390  $this->ctrl->setParameter($this, "def", $def["id"]);
391  $this->tpl->setVariable("LINK_UP",
392  $this->ctrl->getLinkTarget($this, "moveUp"));
393  $this->tpl->parseCurrentBlock();
394  }
395 
396  if ($j+1 < count($defs))
397  {
398  $this->tpl->setCurrentBlock("down");
399  $this->tpl->setVariable("TXT_DOWN", $this->lng->txt("down"));
400  $this->ctrl->setParameter($this, "def", $def["id"]);
401  $this->tpl->setVariable("LINK_DOWN",
402  $this->ctrl->getLinkTarget($this, "moveDown"));
403  $this->tpl->parseCurrentBlock();
404  }
405  $this->tpl->setCurrentBlock("submit_btns");
406  $this->tpl->setVariable("TXT_EDIT", $this->lng->txt("edit"));
407  $this->ctrl->setParameter($this, "def", $def["id"]);
408  $this->ctrl->setParameterByClass("ilTermDefinitionEditorGUI", "def", $def["id"]);
409  $this->tpl->setVariable("LINK_EDIT",
410  $this->ctrl->getLinkTargetByClass(array("ilTermDefinitionEditorGUI", "ilPageObjectGUI"), "edit"));
411  $this->tpl->setVariable("TXT_DELETE", $this->lng->txt("delete"));
412  $this->tpl->setVariable("LINK_DELETE",
413  $this->ctrl->getLinkTarget($this, "confirmDefinitionDeletion"));
414  $this->tpl->parseCurrentBlock();
415 
416  $this->tpl->setCurrentBlock("definition");
417  $this->tpl->setVariable("PAGE_CONTENT", $output);
418  $this->tpl->parseCurrentBlock();
419  }
420  //$this->tpl->setCurrentBlock("def_list");
421  //$this->tpl->parseCurrentBlock();
422 
423  }
424 
425 
430  {
431  $this->getTemplate();
432  $this->displayLocator();
433  $this->setTabs();
434 
435  // content style
436  $this->tpl->setCurrentBlock("ContentStyle");
437  $this->tpl->setVariable("LOCATION_CONTENT_STYLESHEET",
439  $this->tpl->parseCurrentBlock();
440 
441  // syntax style
442  $this->tpl->setCurrentBlock("SyntaxStyle");
443  $this->tpl->setVariable("LOCATION_SYNTAX_STYLESHEET",
445  $this->tpl->parseCurrentBlock();
446 
447  $this->tpl->setVariable("HEADER",
448  $this->lng->txt("cont_term").": ".$this->term->getTerm());
449  $this->tpl->setTitleIcon(ilUtil::getImagePath("icon_term_b.gif"));
450 
451  $this->tpl->addBlockfile("ADM_CONTENT", "def_list", "tpl.glossary_definition_delete.html", true);
452  ilUtil::sendQuestion($this->lng->txt("info_delete_sure"));
453 
454  $this->tpl->setVariable("TXT_TERM", $this->term->getTerm());
455 
456  $definition =& new ilGlossaryDefinition($_GET["def"]);
457  //$page =& new ilPageObject("gdf", $definition->getId());
458  $page_gui =& new ilPageObjectGUI("gdf", $definition->getId());
459  $page_gui->setTemplateOutput(false);
460  $page_gui->setSourcecodeDownloadScript("ilias.php?baseClass=ilGlossaryPresentationGUI&amp;ref_id=".$_GET["ref_id"]);
461  $page_gui->setFileDownloadLink("ilias.php?baseClass=ilGlossaryPresentationGUI&amp;ref_id=".$_GET["ref_id"]);
462  $page_gui->setFullscreenLink("ilias.php?baseClass=ilGlossaryPresentationGUI&amp;ref_id=".$_GET["ref_id"]);
463  $output = $page_gui->preview();
464 
465  $this->tpl->setCurrentBlock("definition");
466  $this->tpl->setVariable("PAGE_CONTENT", $output);
467  $this->tpl->setVariable("TXT_CANCEL", $this->lng->txt("cancel"));
468  $this->tpl->setVariable("LINK_CANCEL",
469  $this->ctrl->getLinkTarget($this, "cancelDefinitionDeletion"));
470  $this->tpl->setVariable("TXT_CONFIRM", $this->lng->txt("confirm"));
471  $this->ctrl->setParameter($this, "def", $definition->getId());
472  $this->tpl->setVariable("LINK_CONFIRM",
473  $this->ctrl->getLinkTarget($this, "deleteDefinition"));
474  $this->tpl->parseCurrentBlock();
475  }
476 
478  {
479  $this->ctrl->redirect($this, "listDefinitions");
480  }
481 
482 
483  function deleteDefinition()
484  {
485  $definition =& new ilGlossaryDefinition($_GET["def"]);
486  $definition->delete();
487  $this->ctrl->redirect($this, "listDefinitions");
488  }
489 
490 
494  function moveUp()
495  {
496  $definition =& new ilGlossaryDefinition($_GET["def"]);
497  $definition->moveUp();
498  $this->ctrl->redirect($this, "listDefinitions");
499  }
500 
501 
505  function moveDown()
506  {
507  $definition =& new ilGlossaryDefinition($_GET["def"]);
508  $definition->moveDown();
509  $this->ctrl->redirect($this, "listDefinitions");
510  }
511 
512 
516  function addDefinition()
517  {
518 
519  $this->getTemplate();
520  $this->displayLocator();
521  $this->setTabs();
522  $this->tpl->setVariable("HEADER", $this->lng->txt("cont_term").": ".$this->term->getTerm());
523  $this->tpl->setTitleIcon(ilUtil::getImagePath("icon_term_b.gif"));
524 
525  $term_id = $_GET["term_id"];
526 
527  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.obj_edit.html");
528  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this, "saveDefinition"));
529  $this->tpl->setVariable("TXT_HEADER", $this->lng->txt("gdf_new"));
530  $this->tpl->setVariable("TXT_CANCEL", $this->lng->txt("cancel"));
531  $this->tpl->setVariable("TXT_SUBMIT", $this->lng->txt("gdf_add"));
532  $this->tpl->setVariable("TXT_TITLE", $this->lng->txt("title"));
533  $this->tpl->setVariable("TXT_DESC", $this->lng->txt("description"));
534  $this->tpl->setVariable("CMD_SUBMIT", "saveDefinition");
535  //$this->tpl->setVariable("TARGET", $this->getTargetFrame("save"));
536  $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
537  $this->tpl->parseCurrentBlock();
538 
539  }
540 
544  function cancel()
545  {
546  $this->ctrl->redirect($this, "listDefinitions");
547  }
548 
552  function saveDefinition()
553  {
554  $def =& new ilGlossaryDefinition();
555  $def->setTermId($_GET["term_id"]);
556  $def->setTitle(ilUtil::stripSlashes($_POST["Fobject"]["title"]));#"content object ".$newObj->getId()); // set by meta_gui->save
557  $def->setDescription(ilUtil::stripSlashes($_POST["Fobject"]["desc"])); // set by meta_gui->save
558  $def->create();
559 
560  $this->ctrl->redirect($this, "listDefinitions");
561  }
562 
563 
567  function getTemplate()
568  {
569  $this->tpl->addBlockFile("CONTENT", "content", "tpl.adm_content.html");
570  $this->tpl->addBlockFile("STATUSLINE", "statusline", "tpl.statusline.html");
571  }
572 
576  function setTabs()
577  {
578  global $ilTabs;
579 
580  // catch feedback message
581  #include_once("classes/class.ilTabsGUI.php");
582  #$tabs_gui =& new ilTabsGUI();
583  $this->getTabs($ilTabs);
584 
585  #$this->tpl->setVariable("TABS", $tabs_gui->getHTML());
586 
587  }
588 
592  function displayLocator()
593  {
594  require_once ("./Modules/Glossary/classes/class.ilGlossaryLocatorGUI.php");
595  $gloss_loc =& new ilGlossaryLocatorGUI();
596  $gloss_loc->setTerm($this->term);
597  $gloss_loc->setGlossary($this->glossary);
598  //$gloss_loc->setDefinition($this->definition);
599  $gloss_loc->display();
600  }
601 
602 
606  function getTabs(&$tabs_gui)
607  {
608  global $lng;
609 
610 //echo ":".$_GET["term_id"].":";
611  if ($_GET["term_id"] != "")
612  {
613  $tabs_gui->addTab("properties",
614  $lng->txt("properties"),
615  $this->ctrl->getLinkTarget($this, "editTerm"));
616 
617  $tabs_gui->addTab("definitions",
618  $lng->txt("cont_definitions"),
619  $this->ctrl->getLinkTarget($this, "listDefinitions"));
620 
621  $tabs_gui->addTab("usage",
622  $lng->txt("cont_usage")." (".ilGlossaryTerm::getNumberOfUsages($_GET["term_id"]).")",
623  $this->ctrl->getLinkTarget($this, "listUsages"));
624  }
625 
626  // back to glossary
627  $tabs_gui->setBackTarget($this->lng->txt("glossary"),
628  $this->ctrl->getLinkTargetByClass("ilobjglossarygui", "listTerms"));
629 
630  }
631 
637  function _goto($a_target, $a_ref_id = "")
638  {
639  global $rbacsystem, $ilErr, $lng, $ilAccess;
640 
641  $glo_id = ilGlossaryTerm::_lookGlossaryID($a_target);//::_lookupContObjID($a_target);
642 
643  // get all references
644  if ($a_ref_id > 0)
645  {
646  $ref_ids = array($a_ref_id);
647  }
648  else
649  {
650  $ref_ids = ilObject::_getAllReferences($glo_id);
651  }
652 
653  // check read permissions
654  foreach ($ref_ids as $ref_id)
655  {
656  // Permission check
657  if ($ilAccess->checkAccess("read", "", $ref_id))
658  {
659  $_GET["baseClass"] = "ilGlossaryPresentationGUI";
660  $_GET["term_id"] = $a_target;
661  $_GET["ref_id"] = $ref_id;
662  $_GET["cmd"] = "listDefinitions";
663  include_once("ilias.php");
664  exit;
665  }
666  }
667  if ($ilAccess->checkAccess("read", "", ROOT_FOLDER_ID))
668  {
669  $_GET["cmd"] = "frameset";
670  $_GET["target"] = "";
671  $_GET["ref_id"] = ROOT_FOLDER_ID;
672  ilUtil::sendFailure(sprintf($lng->txt("msg_no_perm_read_item"),
673  ilObject::_lookupTitle($glo_id)), true);
674  include("repository.php");
675  exit;
676  }
677 
678 
679  $ilErr->raiseError($lng->txt("msg_no_perm_read_lm"), $ilErr->FATAL);
680  }
681 
685  function listUsages()
686  {
687  global $ilTabs, $tpl;
688 
689  //$this->displayLocator();
690  $this->getTemplate();
691  $this->displayLocator();
692  $this->setTabs();
693  $ilTabs->activateTab("usage");
694  $this->tpl->setVariable("HEADER", $this->lng->txt("cont_term").": ".$this->term->getTerm());
695  $this->tpl->setTitleIcon(ilUtil::getImagePath("icon_term_b.gif"));
696 
697  include_once("./Modules/Glossary/classes/class.ilTermUsagesTableGUI.php");
698  $tab = new ilTermUsagesTableGUI($this, "listUsages", $_GET["term_id"]);
699 
700  $tpl->setContent($tab->getHTML());
701  }
702 }
703 
704 ?>