ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilGlossaryTermGUI.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2009 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 require_once("./Modules/Glossary/classes/class.ilGlossaryTerm.php");
25 
37 {
38  var $ilias;
39  var $lng;
40  var $tpl;
41  var $glossary;
42  var $term;
43  var $link_xml;
44 
49  function ilGlossaryTermGUI($a_id = 0)
50  {
51  global $lng, $ilias, $tpl, $ilCtrl;
52 
53  $this->lng =& $lng;
54  $this->ilias =& $ilias;
55  $this->tpl =& $tpl;
56  $this->ctrl =& $ilCtrl;
57  $this->ctrl->saveParameter($this, array("term_id"));
58 
59  if($a_id != 0)
60  {
61  $this->term =& new ilGlossaryTerm($a_id);
62  }
63  }
64 
68  function executeCommand()
69  {
70  $next_class = $this->ctrl->getNextClass($this);
71  $cmd = $this->ctrl->getCmd();
72 
73  switch ($next_class)
74  {
75 
76  case "iltermdefinitioneditorgui":
77  //$this->ctrl->setReturn($this, "listDefinitions");
78  $def_edit =& new ilTermDefinitionEditorGUI();
79  //$ret =& $def_edit->executeCommand();
80  $ret =& $this->ctrl->forwardCommand($def_edit);
81  break;
82 
83  default:
84  $ret =& $this->$cmd();
85  break;
86  }
87  }
88 
94  function setOfflineDirectory ($offdir) {
95  $this->offline_directory = $offdir;
96  }
97 
98 
103  function getOfflineDirectory () {
104  return $this->offline_directory;
105  }
106 
107 
108  function setGlossary(&$a_glossary)
109  {
110  $this->glossary =& $a_glossary;
111  }
112 
113  function setLinkXML($a_link_xml)
114  {
115  $this->link_xml = $a_link_xml;
116  }
117 
118  function getLinkXML()
119  {
120  return $this->link_xml;
121  }
122 
126  function create()
127  {
128  global $ilUser;
129 
130  $this->getTemplate();
131  $this->displayLocator();
132  $this->tpl->setVariable("HEADER", $this->lng->txt("cont_new_term"));
133  $this->tpl->setTitleIcon(ilUtil::getImagePath("icon_term_b.gif"));
134  $this->setTabs();
135 
136  // load template for table
137  $this->tpl->addBlockfile("ADM_CONTENT", "adm_content", "tpl.glossary_term_new.html", true);
138  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
139  $this->tpl->setVariable("TXT_ACTION", $this->lng->txt("cont_new_term"));
140  $this->tpl->setVariable("TXT_TERM", $this->lng->txt("cont_term"));
141  $this->tpl->setVariable("INPUT_TERM", "term");
142  $this->tpl->setVariable("TXT_LANGUAGE", $this->lng->txt("language"));
144 
145  if ($_SESSION["il_text_lang_".$_GET["ref_id"]] != "")
146  {
147  $s_lang = $_SESSION["il_text_lang_".$_GET["ref_id"]];
148  }
149  else
150  {
151  $s_lang = $ilUser->getLanguage();
152  }
153 
154  $select_language = ilUtil::formSelect ($s_lang, "term_language",$lang,false,true);
155  $this->tpl->setVariable("SELECT_LANGUAGE", $select_language);
156  $this->tpl->setVariable("BTN_NAME", "saveTerm");
157  $this->tpl->setVariable("BTN_TEXT", $this->lng->txt("save"));
158  }
159 
163  function saveTerm()
164  {
165  $term =& new ilGlossaryTerm();
166  $term->setGlossary($this->glossary);
167  $term->setTerm(ilUtil::stripSlashes($_POST["term"]));
168  $term->setLanguage($_POST["term_language"]);
169  $_SESSION["il_text_lang_".$_GET["ref_id"]] = $_POST["term_language"];
170  $term->create();
171 
172  ilUtil::sendSuccess($this->lng->txt("cont_added_term"),true);
173  $this->ctrl->returnToParent($this);
174  }
175 
176 
180  function editTerm()
181  {
182  //$this->displayLocator();
183  $this->getTemplate();
184  $this->displayLocator();
185  $this->setTabs();
186  //$this->displayLocator();
187  $this->tpl->setVariable("HEADER", $this->lng->txt("cont_term").": ".$this->term->getTerm());
188  $this->tpl->setTitleIcon(ilUtil::getImagePath("icon_term_b.gif"));
189 
190  // load template for table
191  $this->tpl->addBlockfile("ADM_CONTENT", "adm_content", "tpl.glossary_term_edit.html", true);
192  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this, "updateTerm"));
193  $this->tpl->setVariable("TXT_ACTION", $this->lng->txt("cont_edit_term"));
194  $this->tpl->setVariable("TXT_TERM", $this->lng->txt("cont_term"));
195  $this->tpl->setVariable("INPUT_TERM", "term");
196  $this->tpl->setVariable("VALUE_TERM", htmlspecialchars($this->term->getTerm()));
197  $this->tpl->setVariable("TXT_LANGUAGE", $this->lng->txt("language"));
199  $select_language = ilUtil::formSelect ($this->term->getLanguage(),"term_language",$lang,false,true);
200  $this->tpl->setVariable("SELECT_LANGUAGE", $select_language);
201  $this->tpl->setVariable("BTN_NAME", "updateTerm");
202  $this->tpl->setVariable("BTN_TEXT", $this->lng->txt("save"));
203  }
204 
205 
209  function updateTerm()
210  {
211  $this->term->setTerm(ilUtil::stripSlashes($_POST["term"]));
212  $this->term->setLanguage($_POST["term_language"]);
213  $this->term->update();
214  ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"),true);
215  $this->ctrl->redirect($this, "editTerm");
216  }
217 
223  function output($a_offline = false)
224  {
225  require_once("./Modules/Glossary/classes/class.ilGlossaryDefinition.php");
226  require_once("./Services/COPage/classes/class.ilPageObjectGUI.php");
227 
228  $defs = ilGlossaryDefinition::getDefinitionList($this->term->getId());
229 
230  $this->tpl->setVariable("TXT_TERM", $this->term->getTerm());
231 
232  for($j=0; $j<count($defs); $j++)
233  {
234  $def = $defs[$j];
235  $page_gui = new ilPageObjectGUI("gdf", $def["id"]);
236  $page_gui->setSourcecodeDownloadScript("ilias.php?baseClass=ilGlossaryPresentationGUI&amp;ref_id=".$_GET["ref_id"]);
237  if (!$a_offline)
238  {
239  $page_gui->setFullscreenLink("ilias.php?baseClass=ilGlossaryPresentationGUI&amp;cmd=fullscreen&amp;ref_id=".$_GET["ref_id"]);
240  }
241  else
242  {
243  $page_gui->setFullscreenLink("fullscreen.html"); // id is set by xslt
244  }
245  $page_gui->setFileDownloadLink("ilias.php?baseClass=ilGlossaryPresentationGUI&amp;cmd=downloadFile&amp;ref_id=".$_GET["ref_id"]);
246 
247  if (!$a_offline)
248  {
249  $page_gui->setOutputMode("presentation");
250  }
251  else
252  {
253  $page_gui->setOutputMode("offline");
254  $page_gui->setOfflineDirectory($this->getOfflineDirectory());
255  }
256 
257  //$page_gui->setOutputMode("edit");
258  //$page_gui->setPresentationTitle($this->term->getTerm());
259  $page_gui->setLinkXML($this->getLinkXML());
260  $page_gui->setTemplateOutput(false);
261  $output = $page_gui->presentation($page_gui->getOutputMode());
262 
263  if (count($defs) > 1)
264  {
265  $this->tpl->setCurrentBlock("definition_header");
266  $this->tpl->setVariable("TXT_DEFINITION",
267  $this->lng->txt("cont_definition")." ".($j+1));
268  $this->tpl->parseCurrentBlock();
269  }
270 
271  $this->tpl->setCurrentBlock("definition");
272  $this->tpl->setVariable("PAGE_CONTENT", $output);
273  $this->tpl->parseCurrentBlock();
274  }
275  }
276 
280  function getInternalLinks()
281  {
282  require_once("./Modules/Glossary/classes/class.ilGlossaryDefinition.php");
283  require_once("./Services/COPage/classes/class.ilPageObjectGUI.php");
284 
285  $defs = ilGlossaryDefinition::getDefinitionList($this->term->getId());
286 
287  $term_links = array();
288  for($j=0; $j<count($defs); $j++)
289  {
290  $def = $defs[$j];
291  $page = new ilPageObject("gdf", $def["id"]);
292  $page->buildDom();
293  $page_links = $page->getInternalLinks();
294  foreach($page_links as $key => $page_link)
295  {
296  $term_links[$key] = $page_link;
297  }
298  }
299 
300  return $term_links;
301  }
302 
306  function listDefinitions()
307  {
308  $this->getTemplate();
309  $this->displayLocator();
310  $this->setTabs();
311 
312  require_once("./Services/COPage/classes/class.ilPageObjectGUI.php");
313 
314  // content style
315  $this->tpl->setCurrentBlock("ContentStyle");
316  $this->tpl->setVariable("LOCATION_CONTENT_STYLESHEET",
318  $this->tpl->parseCurrentBlock();
319 
320  // syntax style
321  $this->tpl->setCurrentBlock("SyntaxStyle");
322  $this->tpl->setVariable("LOCATION_SYNTAX_STYLESHEET",
324  $this->tpl->parseCurrentBlock();
325 
326  // load template for table
327  $this->tpl->addBlockfile("ADM_CONTENT", "def_list", "tpl.glossary_definition_list.html", true);
328  //$this->tpl->addBlockfile("CONTENT", "def_list", "tpl.glossary_definition_list.html", true);
329  //ilUtil::sendInfo();
330  $this->tpl->addBlockfile("STATUSLINE", "statusline", "tpl.statusline.html");
331  $this->tpl->setVariable("HEADER",
332  $this->lng->txt("cont_term").": ".$this->term->getTerm());
333  $this->tpl->setTitleIcon(ilUtil::getImagePath("icon_term_b.gif"));
334 
335  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
336 
337  $this->tpl->setCurrentBlock("add_def");
338  $this->tpl->setVariable("TXT_ADD_DEFINITION",
339  $this->lng->txt("cont_add_definition"));
340  $this->tpl->setVariable("BTN_ADD", "addDefinition");
341  $this->tpl->parseCurrentBlock();
342  $this->tpl->setCurrentBlock("def_list");
343 
345 
346  $this->tpl->setVariable("TXT_TERM", $this->term->getTerm());
347 
348  for($j=0; $j<count($defs); $j++)
349  {
350  $def = $defs[$j];
351  $page_gui = new ilPageObjectGUI("gdf", $def["id"]);
352  $page_gui->setSourcecodeDownloadScript("ilias.php?baseClass=ilGlossaryPresentationGUI&amp;ref_id=".$_GET["ref_id"]);
353  $page_gui->setTemplateOutput(false);
354  $output = $page_gui->preview();
355 
356  if (count($defs) > 1)
357  {
358  $this->tpl->setCurrentBlock("definition_header");
359  $this->tpl->setVariable("TXT_DEFINITION",
360  $this->lng->txt("cont_definition")." ".($j+1));
361  $this->tpl->parseCurrentBlock();
362  }
363 
364  if ($j > 0)
365  {
366  $this->tpl->setCurrentBlock("up");
367  $this->tpl->setVariable("TXT_UP", $this->lng->txt("up"));
368  $this->ctrl->setParameter($this, "def", $def["id"]);
369  $this->tpl->setVariable("LINK_UP",
370  $this->ctrl->getLinkTarget($this, "moveUp"));
371  $this->tpl->parseCurrentBlock();
372  }
373 
374  if ($j+1 < count($defs))
375  {
376  $this->tpl->setCurrentBlock("down");
377  $this->tpl->setVariable("TXT_DOWN", $this->lng->txt("down"));
378  $this->ctrl->setParameter($this, "def", $def["id"]);
379  $this->tpl->setVariable("LINK_DOWN",
380  $this->ctrl->getLinkTarget($this, "moveDown"));
381  $this->tpl->parseCurrentBlock();
382  }
383  $this->tpl->setCurrentBlock("submit_btns");
384  $this->tpl->setVariable("TXT_EDIT", $this->lng->txt("edit"));
385  $this->ctrl->setParameter($this, "def", $def["id"]);
386  $this->ctrl->setParameterByClass("ilTermDefinitionEditorGUI", "def", $def["id"]);
387  $this->tpl->setVariable("LINK_EDIT",
388  $this->ctrl->getLinkTargetByClass(array("ilTermDefinitionEditorGUI", "ilPageObjectGUI"), "edit"));
389  $this->tpl->setVariable("TXT_DELETE", $this->lng->txt("delete"));
390  $this->tpl->setVariable("LINK_DELETE",
391  $this->ctrl->getLinkTarget($this, "confirmDefinitionDeletion"));
392  $this->tpl->parseCurrentBlock();
393 
394  $this->tpl->setCurrentBlock("definition");
395  $this->tpl->setVariable("PAGE_CONTENT", $output);
396  $this->tpl->parseCurrentBlock();
397  }
398  //$this->tpl->setCurrentBlock("def_list");
399  //$this->tpl->parseCurrentBlock();
400 
401  }
402 
403 
408  {
409  $this->getTemplate();
410  $this->displayLocator();
411  $this->setTabs();
412 
413  // content style
414  $this->tpl->setCurrentBlock("ContentStyle");
415  $this->tpl->setVariable("LOCATION_CONTENT_STYLESHEET",
417  $this->tpl->parseCurrentBlock();
418 
419  // syntax style
420  $this->tpl->setCurrentBlock("SyntaxStyle");
421  $this->tpl->setVariable("LOCATION_SYNTAX_STYLESHEET",
423  $this->tpl->parseCurrentBlock();
424 
425  $this->tpl->setVariable("HEADER",
426  $this->lng->txt("cont_term").": ".$this->term->getTerm());
427  $this->tpl->setTitleIcon(ilUtil::getImagePath("icon_term_b.gif"));
428 
429  $this->tpl->addBlockfile("ADM_CONTENT", "def_list", "tpl.glossary_definition_delete.html", true);
430  ilUtil::sendQuestion($this->lng->txt("info_delete_sure"));
431 
432  $this->tpl->setVariable("TXT_TERM", $this->term->getTerm());
433 
434  $definition =& new ilGlossaryDefinition($_GET["def"]);
435  //$page =& new ilPageObject("gdf", $definition->getId());
436  $page_gui =& new ilPageObjectGUI("gdf", $definition->getId());
437  $page_gui->setTemplateOutput(false);
438  $page_gui->setSourcecodeDownloadScript("ilias.php?baseClass=ilGlossaryPresentationGUI&amp;ref_id=".$_GET["ref_id"]);
439  $page_gui->setFileDownloadLink("ilias.php?baseClass=ilGlossaryPresentationGUI&amp;ref_id=".$_GET["ref_id"]);
440  $page_gui->setFullscreenLink("ilias.php?baseClass=ilGlossaryPresentationGUI&amp;ref_id=".$_GET["ref_id"]);
441  $output = $page_gui->preview();
442 
443  $this->tpl->setCurrentBlock("definition");
444  $this->tpl->setVariable("PAGE_CONTENT", $output);
445  $this->tpl->setVariable("TXT_CANCEL", $this->lng->txt("cancel"));
446  $this->tpl->setVariable("LINK_CANCEL",
447  $this->ctrl->getLinkTarget($this, "cancelDefinitionDeletion"));
448  $this->tpl->setVariable("TXT_CONFIRM", $this->lng->txt("confirm"));
449  $this->ctrl->setParameter($this, "def", $definition->getId());
450  $this->tpl->setVariable("LINK_CONFIRM",
451  $this->ctrl->getLinkTarget($this, "deleteDefinition"));
452  $this->tpl->parseCurrentBlock();
453  }
454 
456  {
457  $this->ctrl->redirect($this, "listDefinitions");
458  }
459 
460 
461  function deleteDefinition()
462  {
463  $definition =& new ilGlossaryDefinition($_GET["def"]);
464  $definition->delete();
465  $this->ctrl->redirect($this, "listDefinitions");
466  }
467 
468 
472  function moveUp()
473  {
474  $definition =& new ilGlossaryDefinition($_GET["def"]);
475  $definition->moveUp();
476  $this->ctrl->redirect($this, "listDefinitions");
477  }
478 
479 
483  function moveDown()
484  {
485  $definition =& new ilGlossaryDefinition($_GET["def"]);
486  $definition->moveDown();
487  $this->ctrl->redirect($this, "listDefinitions");
488  }
489 
490 
494  function addDefinition()
495  {
496 
497  $this->getTemplate();
498  $this->displayLocator();
499  $this->setTabs();
500  $this->tpl->setVariable("HEADER", $this->lng->txt("cont_term").": ".$this->term->getTerm());
501  $this->tpl->setTitleIcon(ilUtil::getImagePath("icon_term_b.gif"));
502 
503  $term_id = $_GET["term_id"];
504 
505  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.obj_edit.html");
506  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this, "saveDefinition"));
507  $this->tpl->setVariable("TXT_HEADER", $this->lng->txt("gdf_new"));
508  $this->tpl->setVariable("TXT_CANCEL", $this->lng->txt("cancel"));
509  $this->tpl->setVariable("TXT_SUBMIT", $this->lng->txt("gdf_add"));
510  $this->tpl->setVariable("TXT_TITLE", $this->lng->txt("title"));
511  $this->tpl->setVariable("TXT_DESC", $this->lng->txt("description"));
512  $this->tpl->setVariable("CMD_SUBMIT", "saveDefinition");
513  //$this->tpl->setVariable("TARGET", $this->getTargetFrame("save"));
514  $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
515  $this->tpl->parseCurrentBlock();
516 
517  }
518 
522  function cancel()
523  {
524  $this->ctrl->redirect($this, "listDefinitions");
525  }
526 
530  function saveDefinition()
531  {
532  $def =& new ilGlossaryDefinition();
533  $def->setTermId($_GET["term_id"]);
534  $def->setTitle(ilUtil::stripSlashes($_POST["Fobject"]["title"]));#"content object ".$newObj->getId()); // set by meta_gui->save
535  $def->setDescription(ilUtil::stripSlashes($_POST["Fobject"]["desc"])); // set by meta_gui->save
536  $def->create();
537 
538  $this->ctrl->redirect($this, "listDefinitions");
539  }
540 
541 
545  function getTemplate()
546  {
547  $this->tpl->addBlockFile("CONTENT", "content", "tpl.adm_content.html");
548  $this->tpl->addBlockFile("STATUSLINE", "statusline", "tpl.statusline.html");
549  }
550 
554  function setTabs()
555  {
556  global $ilTabs;
557 
558  // catch feedback message
559  #include_once("classes/class.ilTabsGUI.php");
560  #$tabs_gui =& new ilTabsGUI();
561  $this->getTabs($ilTabs);
562 
563  #$this->tpl->setVariable("TABS", $tabs_gui->getHTML());
564 
565  }
566 
570  function displayLocator()
571  {
572  require_once ("./Modules/Glossary/classes/class.ilGlossaryLocatorGUI.php");
573  $gloss_loc =& new ilGlossaryLocatorGUI();
574  $gloss_loc->setTerm($this->term);
575  $gloss_loc->setGlossary($this->glossary);
576  //$gloss_loc->setDefinition($this->definition);
577  $gloss_loc->display();
578  }
579 
580 
584  function getTabs(&$tabs_gui)
585  {
586 //echo ":".$_GET["term_id"].":";
587  if ($_GET["term_id"] != "")
588  {
589  $tabs_gui->addTarget("properties",
590  $this->ctrl->getLinkTarget($this, "editTerm"), array("editTerm"),
591  get_class($this));
592 
593  $tabs_gui->addTarget("cont_definitions",
594  $this->ctrl->getLinkTarget($this, "listDefinitions"),
595  "listDefinitions",
596  get_class($this));
597  }
598 
599  // back to glossary
600  $tabs_gui->setBackTarget($this->lng->txt("glossary"),
601  $this->ctrl->getLinkTargetByClass("ilobjglossarygui", "listTerms"));
602  }
603 
609  function _goto($a_target, $a_ref_id = "")
610  {
611  global $rbacsystem, $ilErr, $lng, $ilAccess;
612 
613  $glo_id = ilGlossaryTerm::_lookGlossaryID($a_target);//::_lookupContObjID($a_target);
614 
615  // get all references
616  if ($a_ref_id > 0)
617  {
618  $ref_ids = array($a_ref_id);
619  }
620  else
621  {
622  $ref_ids = ilObject::_getAllReferences($glo_id);
623  }
624 
625  // check read permissions
626  foreach ($ref_ids as $ref_id)
627  {
628  // Permission check
629  if ($ilAccess->checkAccess("read", "", $ref_id))
630  {
631  $_GET["baseClass"] = "ilGlossaryPresentationGUI";
632  $_GET["term_id"] = $a_target;
633  $_GET["ref_id"] = $ref_id;
634  $_GET["cmd"] = "listDefinitions";
635  include_once("ilias.php");
636  exit;
637  }
638  }
639  if ($ilAccess->checkAccess("read", "", ROOT_FOLDER_ID))
640  {
641  $_GET["cmd"] = "frameset";
642  $_GET["target"] = "";
643  $_GET["ref_id"] = ROOT_FOLDER_ID;
644  ilUtil::sendFailure(sprintf($lng->txt("msg_no_perm_read_item"),
645  ilObject::_lookupTitle($glo_id)), true);
646  include("repository.php");
647  exit;
648  }
649 
650 
651  $ilErr->raiseError($lng->txt("msg_no_perm_read_lm"), $ilErr->FATAL);
652  }
653 
654 }
655 
656 ?>