ILIAS  release_4-3 Revision
 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  $this->quickList("edit", $def_edit);
63  break;
64 
65  default:
66  $ret =& $this->$cmd();
67  break;
68  }
69  }
70 
76  function setOfflineDirectory ($offdir) {
77  $this->offline_directory = $offdir;
78  }
79 
80 
85  function getOfflineDirectory () {
86  return $this->offline_directory;
87  }
88 
89 
90  function setGlossary($a_glossary)
91  {
92  $this->glossary = $a_glossary;
93  }
94 
95  function setLinkXML($a_link_xml)
96  {
97  $this->link_xml = $a_link_xml;
98  }
99 
100  function getLinkXML()
101  {
102  return $this->link_xml;
103  }
104 
108  function create()
109  {
110  // deprecated
111  }
112 
116  function saveTerm()
117  {
118  // deprecated
119  }
120 
121 
125  function editTerm()
126  {
127  global $ilTabs;
128 
129  $this->getTemplate();
130  $this->displayLocator();
131  $this->setTabs();
132  $ilTabs->activateTab("properties");
133 
134  $this->tpl->setTitle($this->lng->txt("cont_term").": ".$this->term->getTerm());
135  $this->tpl->setTitleIcon(ilUtil::getImagePath("icon_term_b.png"));
136 
137  include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
138  $form = new ilPropertyFormGUI();
139  $form->setFormAction($this->ctrl->getFormAction($this, "updateTerm"));
140  $form->setTitle($this->lng->txt("cont_edit_term"));
141 
142  $term = new ilTextInputGUI($this->lng->txt("cont_term"), "term");
143  $term->setRequired(true);
144  $term->setValue($this->term->getTerm());
145  $form->addItem($term);
146 
147  $lang = new ilSelectInputGUI($this->lng->txt("language"), "term_language");
148  $lang->setRequired(true);
149  $lang->setOptions(ilMDLanguageItem::_getLanguages());
150  $lang->setValue($this->term->getLanguage());
151  $form->addItem($lang);
152 
153  // taxonomy
154  if ($this->glossary->getTaxonomyId() > 0)
155  {
156  include_once("./Services/Taxonomy/classes/class.ilTaxAssignInputGUI.php");
157  $tax_node_assign = new ilTaxAssignInputGUI($this->glossary->getTaxonomyId());
158  $tax_node_assign->setCurrentValues("glo", "term", $this->term->getId());
159  $form->addItem($tax_node_assign);
160  }
161 
162  $form->addCommandButton("updateTerm", $this->lng->txt("save"));
163 
164  $this->tpl->setContent($form->getHTML());
165 
166  $this->quickList();
167  }
168 
169 
173  function updateTerm()
174  {
175  // update term
176  $this->term->setTerm(ilUtil::stripSlashes($_POST["term"]));
177  $this->term->setLanguage($_POST["term_language"]);
178  $this->term->update();
179 
180  // update taxonomy assignment
181  if ($this->glossary->getTaxonomyId() > 0)
182  {
183  include_once("./Services/Taxonomy/classes/class.ilTaxAssignInputGUI.php");
184  $tax_node_assign = new ilTaxAssignInputGUI($this->glossary->getTaxonomyId());
185  $tax_node_assign->saveInput("glo", "term", $this->term->getId());
186  }
187 
188  ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"),true);
189  $this->ctrl->redirect($this, "editTerm");
190  }
191 
198  function getOverlayHTML($a_close_el_id, $a_glo_ov_id = "", $a_lang = "", $a_outputmode = "offline")
199  {
200  global $lng;
201 
202  if ($a_lang == "")
203  {
204  $a_lang = $lng->getLangKey();
205  }
206 
207  $tpl = new ilTemplate("tpl.glossary_overlay.html", true, true, "Modules/Glossary");
208 // $this->output(true, $tpl);
209  if ($a_outputmode == "preview")
210  {
211  $a_outputmode = "presentation";
212  }
213  if ($a_outputmode == "offline")
214  {
215  $this->output(true, $tpl, $a_outputmode);
216  }
217  else
218  {
219  $this->output(false, $tpl, $a_outputmode);
220  }
221  if ($a_glo_ov_id != "")
222  {
223  $tpl->setCurrentBlock("glovlink");
224  $tpl->setVariable("TXT_LINK", $lng->txtlng("content", "cont_sco_glossary", $a_lang));
225  $tpl->setVariable("ID_LINK", $a_glo_ov_id);
226  $tpl->parseCurrentBlock();
227  }
228  $tpl->setVariable("TXT_CLOSE", $lng->txtlng("common", "close", $a_lang));
229  $tpl->setVariable("ID_CLOSE", $a_close_el_id);
230  return $tpl->get();
231  }
232 
238  function output($a_offline = false, $a_tpl = "", $a_outputmode = "presentation")
239  {
240  if ($a_tpl != "")
241  {
242  $tpl = $a_tpl;
243  }
244  else
245  {
246  $tpl = $this->tpl;
247  }
248 
249  require_once("./Modules/Glossary/classes/class.ilGlossaryDefinition.php");
250  require_once("./Services/COPage/classes/class.ilPageObjectGUI.php");
251 
252  $defs = ilGlossaryDefinition::getDefinitionList($this->term->getId());
253 
254  $tpl->setVariable("TXT_TERM", $this->term->getTerm());
255 
256  for($j=0; $j<count($defs); $j++)
257  {
258  $def = $defs[$j];
259  $page_gui = new ilPageObjectGUI("gdf", $def["id"]);
260  $page_gui->setSourcecodeDownloadScript("ilias.php?baseClass=ilGlossaryPresentationGUI&amp;ref_id=".$_GET["ref_id"]);
261  if (!$a_offline)
262  {
263  //$page_gui->setFullscreenLink(
264  // "ilias.php?baseClass=ilGlossaryPresentationGUI&cmd=fullscreen&ref_id=".$_GET["ref_id"]);
265  }
266  else
267  {
268  $page_gui->setFullscreenLink("fullscreen.html"); // id is set by xslt
269  }
270  $page_gui->setFileDownloadLink("ilias.php?baseClass=ilGlossaryPresentationGUI&amp;cmd=downloadFile&amp;ref_id=".$_GET["ref_id"]);
271 
272  if (!$a_offline)
273  {
274  $page_gui->setOutputMode($a_outputmode);
275  }
276  else
277  {
278  $page_gui->setOutputMode("offline");
279  $page_gui->setOfflineDirectory($this->getOfflineDirectory());
280  }
281 
282  //$page_gui->setOutputMode("edit");
283  //$page_gui->setPresentationTitle($this->term->getTerm());
284  $page_gui->setLinkXML($this->getLinkXML());
285  $page_gui->setTemplateOutput(false);
286  $output = $page_gui->presentation($page_gui->getOutputMode());
287 
288  if (count($defs) > 1)
289  {
290  $tpl->setCurrentBlock("definition_header");
291  $tpl->setVariable("TXT_DEFINITION",
292  $this->lng->txt("cont_definition")." ".($j+1));
293  $tpl->parseCurrentBlock();
294  }
295 
296  $tpl->setCurrentBlock("definition");
297  $tpl->setVariable("PAGE_CONTENT", $output);
298  $tpl->parseCurrentBlock();
299  }
300  }
301 
305  function getInternalLinks()
306  {
307  require_once("./Modules/Glossary/classes/class.ilGlossaryDefinition.php");
308  require_once("./Services/COPage/classes/class.ilPageObjectGUI.php");
309 
310  $defs = ilGlossaryDefinition::getDefinitionList($this->term->getId());
311 
312  $term_links = array();
313  for($j=0; $j<count($defs); $j++)
314  {
315  $def = $defs[$j];
316  $page = new ilPageObject("gdf", $def["id"]);
317  $page->buildDom();
318  $page_links = $page->getInternalLinks();
319  foreach($page_links as $key => $page_link)
320  {
321  $term_links[$key] = $page_link;
322  }
323  }
324 
325  return $term_links;
326  }
327 
331  function listDefinitions()
332  {
333  global $ilTabs;
334 
335  $this->getTemplate();
336  $this->displayLocator();
337  $this->setTabs();
338  $ilTabs->activateTab("definitions");
339  require_once("./Services/COPage/classes/class.ilPageObjectGUI.php");
340 
341  // content style
342  $this->tpl->setCurrentBlock("ContentStyle");
343  $this->tpl->setVariable("LOCATION_CONTENT_STYLESHEET",
344  ilObjStyleSheet::getContentStylePath($this->glossary->getStyleSheetId()));
345  $this->tpl->parseCurrentBlock();
346 
347  // syntax style
348  $this->tpl->setCurrentBlock("SyntaxStyle");
349  $this->tpl->setVariable("LOCATION_SYNTAX_STYLESHEET",
351  $this->tpl->parseCurrentBlock();
352 
353  // load template for table
354  $this->tpl->addBlockfile("ADM_CONTENT", "def_list", "tpl.glossary_definition_list.html", true);
355  //$this->tpl->addBlockfile("CONTENT", "def_list", "tpl.glossary_definition_list.html", true);
356  //ilUtil::sendInfo();
357  $this->tpl->addBlockfile("STATUSLINE", "statusline", "tpl.statusline.html");
358  $this->tpl->setTitle(
359  $this->lng->txt("cont_term").": ".$this->term->getTerm());
360  $this->tpl->setTitleIcon(ilUtil::getImagePath("icon_term_b.png"));
361 
362  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
363 
364  $this->tpl->setCurrentBlock("add_def");
365  $this->tpl->setVariable("TXT_ADD_DEFINITION",
366  $this->lng->txt("cont_add_definition"));
367  $this->tpl->setVariable("BTN_ADD", "addDefinition");
368  $this->tpl->parseCurrentBlock();
369  $this->tpl->setCurrentBlock("def_list");
370 
372 
373  $this->tpl->setVariable("TXT_TERM", $this->term->getTerm());
374 
375  for($j=0; $j<count($defs); $j++)
376  {
377  $def = $defs[$j];
378  $page_gui = new ilPageObjectGUI("gdf", $def["id"]);
379  $page_gui->setStyleId($this->glossary->getStyleSheetId());
380  $page_gui->setSourcecodeDownloadScript("ilias.php?baseClass=ilGlossaryPresentationGUI&amp;ref_id=".$_GET["ref_id"]);
381  $page_gui->setTemplateOutput(false);
382  $output = $page_gui->preview();
383 
384  if (count($defs) > 1)
385  {
386  $this->tpl->setCurrentBlock("definition_header");
387  $this->tpl->setVariable("TXT_DEFINITION",
388  $this->lng->txt("cont_definition")." ".($j+1));
389  $this->tpl->parseCurrentBlock();
390  }
391 
392  if ($j > 0)
393  {
394  $this->tpl->setCurrentBlock("up");
395  $this->tpl->setVariable("TXT_UP", $this->lng->txt("up"));
396  $this->ctrl->setParameter($this, "def", $def["id"]);
397  $this->tpl->setVariable("LINK_UP",
398  $this->ctrl->getLinkTarget($this, "moveUp"));
399  $this->tpl->parseCurrentBlock();
400  }
401 
402  if ($j+1 < count($defs))
403  {
404  $this->tpl->setCurrentBlock("down");
405  $this->tpl->setVariable("TXT_DOWN", $this->lng->txt("down"));
406  $this->ctrl->setParameter($this, "def", $def["id"]);
407  $this->tpl->setVariable("LINK_DOWN",
408  $this->ctrl->getLinkTarget($this, "moveDown"));
409  $this->tpl->parseCurrentBlock();
410  }
411  $this->tpl->setCurrentBlock("submit_btns");
412  $this->tpl->setVariable("TXT_EDIT", $this->lng->txt("edit"));
413  $this->ctrl->setParameter($this, "def", $def["id"]);
414  $this->ctrl->setParameterByClass("ilTermDefinitionEditorGUI", "def", $def["id"]);
415  $this->tpl->setVariable("LINK_EDIT",
416  $this->ctrl->getLinkTargetByClass(array("ilTermDefinitionEditorGUI", "ilPageObjectGUI"), "edit"));
417  $this->tpl->setVariable("TXT_DELETE", $this->lng->txt("delete"));
418  $this->tpl->setVariable("LINK_DELETE",
419  $this->ctrl->getLinkTarget($this, "confirmDefinitionDeletion"));
420  $this->tpl->parseCurrentBlock();
421 
422  $this->tpl->setCurrentBlock("definition");
423  $this->tpl->setVariable("PAGE_CONTENT", $output);
424  $this->tpl->parseCurrentBlock();
425  }
426  //$this->tpl->setCurrentBlock("def_list");
427  //$this->tpl->parseCurrentBlock();
428 
429  $this->quickList();
430  }
431 
432 
437  {
438  global $ilTabs;
439 
440  $this->getTemplate();
441  $this->displayLocator();
442  $this->setTabs();
443  $ilTabs->activateTab("definitions");
444 
445  // content style
446  $this->tpl->setCurrentBlock("ContentStyle");
447  $this->tpl->setVariable("LOCATION_CONTENT_STYLESHEET",
448  ilObjStyleSheet::getContentStylePath($this->glossary->getStyleSheetId()));
449  $this->tpl->parseCurrentBlock();
450 
451  // syntax style
452  $this->tpl->setCurrentBlock("SyntaxStyle");
453  $this->tpl->setVariable("LOCATION_SYNTAX_STYLESHEET",
455  $this->tpl->parseCurrentBlock();
456 
457  $this->tpl->setTitle(
458  $this->lng->txt("cont_term").": ".$this->term->getTerm());
459  $this->tpl->setTitleIcon(ilUtil::getImagePath("icon_term_b.png"));
460 
461  $this->tpl->addBlockfile("ADM_CONTENT", "def_list", "tpl.glossary_definition_delete.html", true);
462  ilUtil::sendQuestion($this->lng->txt("info_delete_sure"));
463 
464  $this->tpl->setVariable("TXT_TERM", $this->term->getTerm());
465 
466  $definition =& new ilGlossaryDefinition($_GET["def"]);
467  //$page =& new ilPageObject("gdf", $definition->getId());
468  $page_gui =& new ilPageObjectGUI("gdf", $definition->getId());
469  $page_gui->setTemplateOutput(false);
470  $page_gui->setStyleId($this->glossary->getStyleSheetId());
471  $page_gui->setSourcecodeDownloadScript("ilias.php?baseClass=ilGlossaryPresentationGUI&amp;ref_id=".$_GET["ref_id"]);
472  $page_gui->setFileDownloadLink("ilias.php?baseClass=ilGlossaryPresentationGUI&amp;ref_id=".$_GET["ref_id"]);
473  $page_gui->setFullscreenLink("ilias.php?baseClass=ilGlossaryPresentationGUI&amp;ref_id=".$_GET["ref_id"]);
474  $output = $page_gui->preview();
475 
476  $this->tpl->setCurrentBlock("definition");
477  $this->tpl->setVariable("PAGE_CONTENT", $output);
478  $this->tpl->setVariable("TXT_CANCEL", $this->lng->txt("cancel"));
479  $this->tpl->setVariable("LINK_CANCEL",
480  $this->ctrl->getLinkTarget($this, "cancelDefinitionDeletion"));
481  $this->tpl->setVariable("TXT_CONFIRM", $this->lng->txt("confirm"));
482  $this->ctrl->setParameter($this, "def", $definition->getId());
483  $this->tpl->setVariable("LINK_CONFIRM",
484  $this->ctrl->getLinkTarget($this, "deleteDefinition"));
485  $this->tpl->parseCurrentBlock();
486  }
487 
489  {
490  $this->ctrl->redirect($this, "listDefinitions");
491  }
492 
493 
494  function deleteDefinition()
495  {
496  $definition =& new ilGlossaryDefinition($_GET["def"]);
497  $definition->delete();
498  $this->ctrl->redirect($this, "listDefinitions");
499  }
500 
501 
505  function moveUp()
506  {
507  $definition =& new ilGlossaryDefinition($_GET["def"]);
508  $definition->moveUp();
509  $this->ctrl->redirect($this, "listDefinitions");
510  }
511 
512 
516  function moveDown()
517  {
518  $definition =& new ilGlossaryDefinition($_GET["def"]);
519  $definition->moveDown();
520  $this->ctrl->redirect($this, "listDefinitions");
521  }
522 
523 
527  function addDefinition()
528  {
529  global $ilTabs;
530 
531  $this->getTemplate();
532  $this->displayLocator();
533  $this->setTabs();
534  $ilTabs->activateTab("definitions");
535 
536  $this->tpl->setTitle($this->lng->txt("cont_term").": ".$this->term->getTerm());
537  $this->tpl->setTitleIcon(ilUtil::getImagePath("icon_term_b.png"));
538 
539  include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
540  $form = new ilPropertyFormGUI();
541  $form->setFormAction($this->ctrl->getFormAction($this, "saveDefinition"));
542  $form->setTitle($this->lng->txt("gdf_new"));
543 
544  $title = new ilTextInputGUI($this->lng->txt("title"), "title");
545  $title->setRequired(true);
546  $form->addItem($title);
547 
548  $desc = new ilTextAreaInputGUI($this->lng->txt("description"), "desc");
549  $form->addItem($desc);
550 
551  $form->addCommandButton("saveDefinition", $this->lng->txt("gdf_add"));
552  $form->addCommandButton("cancel", $this->lng->txt("cancel"));
553 
554  $this->tpl->setContent($form->getHTML());
555  }
556 
560  function cancel()
561  {
562  $this->ctrl->redirect($this, "listDefinitions");
563  }
564 
568  function saveDefinition()
569  {
570  $def =& new ilGlossaryDefinition();
571  $def->setTermId($_GET["term_id"]);
572  $def->setTitle(ilUtil::stripSlashes($_POST["title"]));#"content object ".$newObj->getId()); // set by meta_gui->save
573  $def->setDescription(ilUtil::stripSlashes($_POST["desc"])); // set by meta_gui->save
574  $def->create();
575 
576  $this->ctrl->redirect($this, "listDefinitions");
577  }
578 
579 
583  function getTemplate()
584  {
585  $this->tpl->addBlockFile("CONTENT", "content", "tpl.adm_content.html");
586  $this->tpl->addBlockFile("STATUSLINE", "statusline", "tpl.statusline.html");
587  }
588 
592  function setTabs()
593  {
594  global $ilTabs;
595  $this->getTabs($ilTabs);
596  }
597 
601  function displayLocator()
602  {
603  require_once ("./Modules/Glossary/classes/class.ilGlossaryLocatorGUI.php");
604  $gloss_loc =& new ilGlossaryLocatorGUI();
605  $gloss_loc->setTerm($this->term);
606  $gloss_loc->setGlossary($this->glossary);
607  //$gloss_loc->setDefinition($this->definition);
608  $gloss_loc->display();
609  }
610 
611 
615  function getTabs(&$tabs_gui)
616  {
617  global $lng, $ilHelp;
618 
619 
620  $ilHelp->setScreenIdComponent("glo_term");
621 
622 //echo ":".$_GET["term_id"].":";
623  if ($_GET["term_id"] != "")
624  {
625  $tabs_gui->addTab("properties",
626  $lng->txt("properties"),
627  $this->ctrl->getLinkTarget($this, "editTerm"));
628 
629  $tabs_gui->addTab("definitions",
630  $lng->txt("cont_definitions"),
631  $this->ctrl->getLinkTarget($this, "listDefinitions"));
632 
633  $tabs_gui->addTab("usage",
634  $lng->txt("cont_usage")." (".ilGlossaryTerm::getNumberOfUsages($_GET["term_id"]).")",
635  $this->ctrl->getLinkTarget($this, "listUsages"));
636 
637  $tabs_gui->addNonTabbedLink("presentation_view",
638  $this->lng->txt("glo_presentation_view"),
639  ILIAS_HTTP_PATH.
640  "/goto.php?target=".
641  "git".
642  "_".$_GET["term_id"]."_".$_GET["ref_id"]."&client_id=".CLIENT_ID,
643  "_top"
644  );
645 
646  }
647 
648  // back to glossary
649  $tabs_gui->setBackTarget($this->lng->txt("glossary"),
650  $this->ctrl->getLinkTargetByClass("ilobjglossarygui", "listTerms"));
651 
652  }
653 
659  function _goto($a_target, $a_ref_id = "")
660  {
661  global $rbacsystem, $ilErr, $lng, $ilAccess;
662 
663  $glo_id = ilGlossaryTerm::_lookGlossaryID($a_target);//::_lookupContObjID($a_target);
664 
665  // get all references
666  if ($a_ref_id > 0)
667  {
668  $ref_ids = array($a_ref_id);
669  }
670  else
671  {
672  $ref_ids = ilObject::_getAllReferences($glo_id);
673  }
674 
675  // check read permissions
676  foreach ($ref_ids as $ref_id)
677  {
678  // Permission check
679  if ($ilAccess->checkAccess("read", "", $ref_id))
680  {
681  $_GET["baseClass"] = "ilGlossaryPresentationGUI";
682  $_GET["term_id"] = $a_target;
683  $_GET["ref_id"] = $ref_id;
684  $_GET["cmd"] = "listDefinitions";
685  include_once("ilias.php");
686  exit;
687  }
688  }
689  if ($ilAccess->checkAccess("read", "", ROOT_FOLDER_ID))
690  {
691  ilUtil::sendFailure(sprintf($lng->txt("msg_no_perm_read_item"),
692  ilObject::_lookupTitle($glo_id)), true);
694  }
695 
696 
697  $ilErr->raiseError($lng->txt("msg_no_perm_read_lm"), $ilErr->FATAL);
698  }
699 
703  function listUsages()
704  {
705  global $ilTabs, $tpl;
706 
707  //$this->displayLocator();
708  $this->getTemplate();
709  $this->displayLocator();
710  $this->setTabs();
711  $ilTabs->activateTab("usage");
712 
713  $this->tpl->setTitle($this->lng->txt("cont_term").": ".$this->term->getTerm());
714  $this->tpl->setTitleIcon(ilUtil::getImagePath("icon_term_b.png"));
715 
716  include_once("./Modules/Glossary/classes/class.ilTermUsagesTableGUI.php");
717  $tab = new ilTermUsagesTableGUI($this, "listUsages", $_GET["term_id"]);
718 
719  $tpl->setContent($tab->getHTML());
720 
721  $this->quickList();
722  }
723 
727  function quickList()
728  {
729  global $tpl, $ilCtrl;
730 
731  //$tpl->setLeftNavUrl($ilCtrl->getLinkTarget($this, "showQuickList"));
732 
733  include_once("./Modules/Glossary/classes/class.ilTermQuickListTableGUI.php");
734  $tab = new ilTermQuickListTableGUI($this, "editTerm");
735  $tpl->setLeftNavContent($tab->getHTML());
736  }
737 }
738 
739 ?>