ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilLMPageObjectGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 require_once("./Modules/LearningModule/classes/class.ilLMObjectGUI.php");
5 require_once("./Modules/LearningModule/classes/class.ilLMPageObject.php");
6 require_once("./Services/COPage/classes/class.ilPageObjectGUI.php");
7 require_once ("./Modules/LearningModule/classes/class.ilInternalLinkGUI.php");
8 
22 {
23  var $obj;
24 
31  function ilLMPageObjectGUI(&$a_content_obj)
32  {
33  global $ilias, $tpl, $lng;
34 
35  parent::ilLMObjectGUI($a_content_obj);
36 
37  }
38 
39 
43  function setLMPageObject(&$a_pg_obj)
44  {
45  $this->obj =& $a_pg_obj;
46  $this->obj->setLMId($this->content_object->getId());
47  }
48 
52  function &executeCommand()
53  {
54  global $tpl, $ilCtrl, $ilTabs, $ilSetting;
55 
56  $next_class = $this->ctrl->getNextClass($this);
57  $cmd = $this->ctrl->getCmd();
58 
59 //echo "<br>:cmd:".$this->ctrl->getCmd().":cmdClass:".$this->ctrl->getCmdClass().":".
60 // ":nextClass:".$next_class.":"; flush();
61 
62  switch($next_class)
63  {
64  case "ilpageobjectgui":
65 
66  // Determine whether the view of a learning resource should
67  // be shown in the frameset of ilias, or in a separate window.
68  //$showViewInFrameset = $this->ilias->ini->readVariable("layout","view_target") == "frame";
69  $showViewInFrameset = true;
70  $lm_set = new ilSetting("lm");
71 
72  $this->ctrl->setReturn($this, "edit");
73  $page_gui =& new ilPageObjectGUI($this->obj->content_object->getType(),
74  $this->obj->getId());
75  $page_gui->setEditPreview(true);
76  $page_gui->activateMetaDataEditor($this->content_object->getID(),
77  $this->obj->getId(), $this->obj->getType(),
78  $this->obj, "MDUpdateListener");
79  $page_gui->setEnabledPCTabs(true);
80 
81  include_once("./Services/COPage/classes/class.ilPageConfig.php");
82  $pconfig = new ilPageConfig();
83  $pconfig->setPreventRteUsage(true);
84  $pconfig->setUseAttachedContent(true);
85  $page_gui->setPageConfig($pconfig);
86 
87  if ($ilSetting->get("block_activated_news"))
88  {
89  $page_gui->setEnabledNews(true, $this->obj->content_object->getId(),
90  $this->obj->content_object->getType());
91  }
92 
93  // set page view link
94  if ($showViewInFrameset)
95  {
96  $view_frame = ilFrameTargetInfo::_getFrame("MainContent");
97  }
98  else
99  {
100  $view_frame = "ilContObj".$this->content_object->getID();
101  }
102  $page_gui->setViewPageLink(ILIAS_HTTP_PATH."/goto.php?target=pg_".$this->obj->getId().
103  "_".$_GET["ref_id"],
104  $view_frame);
105 
106  include_once("./Services/Style/classes/class.ilObjStyleSheet.php");
107  $page_gui->setStyleId(ilObjStyleSheet::getEffectiveContentStyleId(
108  $this->content_object->getStyleSheetId(), "lm"));
109  $page_gui->setIntLinkHelpDefault("StructureObject", $_GET["ref_id"]);
110  $page_gui->setTemplateTargetVar("ADM_CONTENT");
111  $page_gui->getPageObject()->buildDom();
112  $int_links = $page_gui->getPageObject()->getInternalLinks();
113  $link_xml = $this->getLinkXML($int_links);
114  $page_gui->setLinkXML($link_xml);
115 
116  $page_gui->enableChangeComments($this->content_object->isActiveHistoryUserComments());
117  $page_gui->setFileDownloadLink("ilias.php?cmd=downloadFile&ref_id=".$_GET["ref_id"]."&baseClass=ilLMPresentationGUI");
118  $page_gui->setFullscreenLink("ilias.php?cmd=fullscreen&ref_id=".$_GET["ref_id"]."&baseClass=ilLMPresentationGUI");
119  $page_gui->setLinkParams("ref_id=".$this->content_object->getRefId());
120  $page_gui->setSourcecodeDownloadScript("ilias.php?ref_id=".$_GET["ref_id"]."&baseClass=ilLMPresentationGUI");
121  $page_gui->setPresentationTitle(
122  ilLMPageObject::_getPresentationTitle($this->obj->getId(),
123  $this->content_object->getPageHeader(), $this->content_object->isActiveNumbering()));
124  $page_gui->setLocator($contObjLocator);
125  $page_gui->setHeader($this->lng->txt("page").": ".$this->obj->getTitle());
126  $page_gui->setEnabledActivation(true);
127  $page_gui->setEnabledSelfAssessment(true, false);
128  $page_gui->setEnabledInternalLinks(true);
129  $page_gui->setEnableKeywords(true);
130  $page_gui->setEnabledInternalLinks(true);
131  $page_gui->setEnableAnchors(true);
132  if ($lm_set->get("time_scheduled_page_activation"))
133  {
134  $page_gui->setEnabledScheduledActivation(true);
135  }
136  $page_gui->setActivationListener($this, "activatePage");
137 
138  $mset = new ilSetting("mobs");
139  if ($mset->get("mep_activate_pages"))
140  {
141  $page_gui->enableContentIncludes(true);
142  }
143 
144  //$page_gui->setActivated($this->obj->getActive());
145 
146  $up_gui = ($this->content_object->getType() == "dbk")
147  ? "ilobjdlbookgui"
148  : "ilobjlearningmodulegui";
149  $ilCtrl->setParameterByClass($up_gui, "active_node", $this->obj->getId());
150  $page_gui->setExplorerUpdater("tree", "tree_div",
151  $ilCtrl->getLinkTargetByClass($up_gui, "explorer", "", true));
152 
153  $tpl->setTitleIcon(ilUtil::getImagePath("icon_pg_b.png"));
154  $tpl->setTitle($this->lng->txt("page").": ".$this->obj->getTitle());
155  if ($this->content_object->getLayoutPerPage())
156  {
157  $page_gui->setTabHook($this, "addPageTabs");
158  }
159  $ret = $this->ctrl->forwardCommand($page_gui);
160 
161  //$ret =& $page_gui->executeCommand();
162  $tpl->setContent($ret);
163  break;
164 
165  default:
166  $ret =& $this->$cmd();
167  break;
168  }
169  }
170 
171 
172  /*
173  * display content of page (edit view)
174  */
175  function edit()
176  {
177 //echo "<br>umschuss";
178  $this->ctrl->setCmdClass("ilpageobjectgui");
179  $this->ctrl->setCmd("edit");
180  $this->executeCommand();
181  //$this->setTabs();
182  }
183 
184  /*
185  * display content of page (edit view)
186  */
187  function preview()
188  {
189  $this->ctrl->setCmdClass("ilpageobjectgui");
190  $this->ctrl->setCmd("preview");
191  $this->executeCommand();
192 // $this->setTabs();
193  }
194 
198  function save()
199  {
200  $this->obj =& new ilLMPageObject($this->content_object);
201  $this->obj->setType("pg");
202  $this->obj->setTitle(ilUtil::stripSlashes($_POST["Fobject"]["title"]));
203  $this->obj->setDescription(ilUtil::stripSlashes($_POST["Fobject"]["desc"]));
204  $this->obj->setLMId($this->content_object->getId());
205  $this->obj->create();
206 
207  // obj_id is empty, if page is created from "all pages" screen
208  // -> a free page is created (not in the tree)
209 //echo "<br>savePage:".$_GET["obj_id"].":";
210  if ($_GET["obj_id"] != 0)
211  {
212  $this->putInTree();
213 
214  // check the tree
215  $this->checkTree();
216 
217  ilUtil::redirect($this->ctrl->getLinkTargetByClass("ilStructureObjectGUI",
218  "edit", "", true));
219  }
220  $up_gui = ($this->content_object->getType() == "dbk")
221  ? "ilobjdlbookgui"
222  : "ilobjlearningmodulegui";
223  $this->ctrl->redirectByClass($up_gui, "pages");
224  }
225 
229  function cancel()
230  {
231  if ($_GET["obj_id"] != 0)
232  {
233  ilUtil::redirect($this->ctrl->getLinkTargetByClass("ilStructureObjectGUI",
234  "view", "", true));
235  }
236  $up_gui = ($this->content_object->getType() == "dbk")
237  ? "ilobjdlbookgui"
238  : "ilobjlearningmodulegui";
239  $this->ctrl->redirectByClass($up_gui, "pages");
240  }
241 
245  function getLinkXML($a_int_links)
246  {
247  if ($a_layoutframes == "")
248  {
249  $a_layoutframes = array();
250  }
251  $link_info = "<IntLinkInfos>";
252  foreach ($a_int_links as $int_link)
253  {
254  $target = $int_link["Target"];
255  if (substr($target, 0, 4) == "il__")
256  {
257  $target_arr = explode("_", $target);
258  $target_id = $target_arr[count($target_arr) - 1];
259  $type = $int_link["Type"];
260  $targetframe = ($int_link["TargetFrame"] != "")
261  ? $int_link["TargetFrame"]
262  : "None";
263 
264  // anchor
265  $anc = $anc_add = "";
266  if ($int_link["Anchor"] != "")
267  {
268  $anc = $int_link["Anchor"];
269  $anc_add = "_".rawurlencode($int_link["Anchor"]);
270  }
271 
272  switch($type)
273  {
274  case "PageObject":
275  case "StructureObject":
277  $cont_obj =& $this->content_object;
278  if ($lm_id == $cont_obj->getId())
279  {
280  $ltarget = "";
281  if ($type == "PageObject")
282  {
283  $this->ctrl->setParameter($this, "obj_id", $target_id);
284  $href = $this->ctrl->getLinkTargetByClass(get_class($this), "edit");
285  }
286  else
287  {
288  $this->ctrl->setParameterByClass("ilstructureobjectgui", "obj_id", $target_id);
289  $href = $this->ctrl->getLinkTargetByClass("ilstructureobjectgui", "view");
290  }
291  $href = str_replace("&", "&amp;", $href);
292  $this->ctrl->setParameter($this, "obj_id", $_GET["obj_id"]);
293  }
294  else
295  {
296  if ($type == "PageObject")
297  {
298  $href = "goto.php?target=pg_".$target_id.$anc_add;
299  }
300  else
301  {
302  $href = "goto.php?target=st_".$target_id;
303  }
304  $ltarget = "ilContObj".$lm_id;
305  }
306  break;
307 
308  case "GlossaryItem":
309  $ltarget = $nframe = "_blank";
310  $href = "ilias.php?cmdClass=illmpresentationgui&amp;baseClass=ilLMPresentationGUI&amp;".
311  "obj_type=$type&amp;cmd=glossary&amp;ref_id=".$_GET["ref_id"].
312  "&amp;obj_id=".$target_id."&amp;frame=$nframe";
313  break;
314 
315  case "MediaObject":
316  $ltarget = $nframe = "_blank";
317  $href = "ilias.php?cmdClass=illmpresentationgui&amp;baseClass=ilLMPresentationGUI&amp;obj_type=$type&amp;cmd=media&amp;ref_id=".$_GET["ref_id"].
318  "&amp;mob_id=".$target_id."&amp;frame=$nframe";
319  break;
320 
321  case "RepositoryItem":
322  $obj_type = ilObject::_lookupType($target_id, true);
324  $href = "./goto.php?target=".$obj_type."_".$target_id;
325  $t_frame = ilFrameTargetInfo::_getFrame("MainContent", $obj_type);
326  $ltarget = $t_frame;
327  break;
328  }
329 
330  $anc_par = 'Anchor="'.$anc.'"';
331 
332  $link_info.="<IntLinkInfo Target=\"$target\" Type=\"$type\" ".
333  "TargetFrame=\"$targetframe\" LinkHref=\"$href\" LinkTarget=\"$ltarget\" $anc_par/>";
334  }
335  }
336  $link_info.= "</IntLinkInfos>";
337 //echo ":".htmlentities($link_info).":";
338  return $link_info;
339  }
340 
344  function updateHistory()
345  {
346  require_once("./Services/History/classes/class.ilHistory.php");
347  ilHistory::_createEntry($this->obj->getId(), "update",
348  "", $this->content_object->getType().":pg",
349  "", true);
350  }
351 
357  function _goto($a_target)
358  {
359  global $rbacsystem, $ilErr, $lng, $ilAccess;
360 
361  $first = strpos($a_target, "_");
362  $second = strpos($a_target, "_", $first + 1);
363  $page_id = substr($a_target, 0, $first);
364  if ($first > 0)
365  {
366  $page_id = substr($a_target, 0, $first);
367  if ($second > 0)
368  {
369  $ref_id = substr($a_target, $first + 1, $second - ($first + 1));
370  $anchor = substr($a_target, $second + 1);
371  }
372  else
373  {
374  $ref_id = substr($a_target, $first + 1);
375  }
376  }
377  else
378  {
379  $page_id = $a_target;
380  }
381 
382  // determine learning object
383  $lm_id = ilLMObject::_lookupContObjID($page_id);
384 
385  // get all references
386  $ref_ids = ilObject::_getAllReferences($lm_id);
387 
388  // always try passed ref id first
389  if (in_array($ref_id, $ref_ids))
390  {
391  $ref_ids = array_merge(array($ref_id), $ref_ids);
392  }
393 
394  // check read permissions
395  foreach ($ref_ids as $ref_id)
396  {
397  // check read permissions
398  if ($ilAccess->checkAccess("read", "", $ref_id))
399  {
400  // don't redirect anymore, just set parameters
401  // (goto.php includes "ilias.php")
402  $_GET["baseClass"] = "ilLMPresentationGUI";
403  $_GET["obj_id"] = $page_id;
404  $_GET["ref_id"] = $ref_id;
405  $_GET["anchor"] = $anchor;
406  include_once("ilias.php");
407  exit;
408  }
409  }
410 
411  if ($ilAccess->checkAccess("read", "", ROOT_FOLDER_ID))
412  {
413  if ($lm_id > 0)
414  {
415  ilUtil::sendFailure(sprintf($lng->txt("msg_no_perm_read_item"),
416  ilObject::_lookupTitle($lm_id)), true);
417  }
418  else
419  {
420  $lng->loadLanguageModule("content");
421  ilUtil::sendFailure($lng->txt("page_does_not_exist"), true);
422  }
423  include_once("./Services/Object/classes/class.ilObjectGUI.php");
425  }
426 
427  $ilErr->raiseError($lng->txt("msg_no_perm_read_lm"), $ilErr->FATAL);
428  }
429 
433  function editLayout()
434  {
435  global $tpl, $ilCtrl, $ilTabs;
436 
437  $page_gui =& new ilPageObjectGUI($this->obj->content_object->getType(),
438  $this->obj->getId());
439  $page_gui->setEditPreview(true);
440  $page_gui->activateMetaDataEditor($this->content_object->getID(),
441  $this->obj->getId(), $this->obj->getType(),
442  $this->obj, "MDUpdateListener");
443  $page_gui->setActivationListener($this, "activatePage");
444  $page_gui->setTabHook($this, "addPageTabs");
445  $page_gui->setEnabledActivation(true);
446  $lm_set = new ilSetting("lm");
447  if ($lm_set->get("time_scheduled_page_activation"))
448  {
449  $page_gui->setEnabledScheduledActivation(true);
450  }
451  $tpl->setTitleIcon(ilUtil::getImagePath("icon_pg_b.png"));
452  $tpl->setTitle($this->lng->txt("page").": ".$this->obj->getTitle());
453  $ilCtrl->getHTML($page_gui);
454  $ilTabs->setTabActive("cont_layout");
455  $this->initEditLayoutForm();
456  $tpl->setContent($this->form->getHTML());
457  }
458 
464  public function initEditLayoutForm()
465  {
466  global $lng, $ilCtrl;
467 
468  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
469  $this->form = new ilPropertyFormGUI();
470 
471  // default layout
472  $layout = new ilRadioMatrixInputGUI($lng->txt("cont_layout"), "layout");
473  $option = array();
474  if (is_file($im = ilUtil::getImagePath("layout_".$this->content_object->getLayout().".png")))
475  {
476  $im_tag = ilUtil::img($im, $this->content_object->getLayout());
477  }
478  $option[""] =
479  "<table><tr><td>".$im_tag."</td><td><b>".$lng->txt("cont_lm_default_layout").
480  "</b>: ".$lng->txt("cont_layout_".$this->content_object->getLayout())."</td></tr></table>";
482  {
483  $im_tag = "";
484  if (is_file($im = ilUtil::getImagePath("layout_".$l.".png")))
485  {
486  $im_tag = ilUtil::img($im, $l);
487  }
488  $option[$l] = "<table><tr><td>".$im_tag."</td><td><b>".$lng->txt("cont_layout_".$l)."</b>: ".$lng->txt("cont_layout_".$l."_desc")."</td></tr></table>";
489  }
490  $layout->setOptions($option);
491  $layout->setValue($this->obj->getLayout());
492  $this->form->addItem($layout);
493 
494  $this->form->addCommandButton("saveLayout", $lng->txt("save"));
495 
496  $this->form->setTitle($lng->txt("cont_page_layout"));
497  $this->form->setFormAction($ilCtrl->getFormAction($this));
498 
499  }
500 
505  public function saveLayout()
506  {
507  global $tpl, $lng, $ilCtrl;
508 
509  $this->initEditLayoutForm();
510  if ($this->form->checkInput())
511  {
512  ilLMObject::writeLayout($this->obj->getId(), $this->form->getInput("layout"));
513  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
514  $ilCtrl->redirect($this, "editLayout");
515  }
516  $this->form->setValuesByPost();
517  $tpl->setContent($this->form->getHtml());
518  }
519 
523  function addPageTabs()
524  {
525  global $ilTabs, $ilCtrl;
526 
527  $ilTabs->addTarget("cont_layout",
528  $ilCtrl->getLinkTarget($this, 'editLayout'), "editLayout");
529  }
530 
531 }
532 ?>