ILIAS  Release_4_1_x_branch Revision 61804
 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  $page_gui->setPageConfig($pconfig);
85 
86  if ($ilSetting->get("block_activated_news"))
87  {
88  $page_gui->setEnabledNews(true, $this->obj->content_object->getId(),
89  $this->obj->content_object->getType());
90  }
91 
92  // set page view link
93  if ($showViewInFrameset)
94  {
95  $view_frame = ilFrameTargetInfo::_getFrame("MainContent");
96  }
97  else
98  {
99  $view_frame = "ilContObj".$this->content_object->getID();
100  }
101  $page_gui->setViewPageLink(ILIAS_HTTP_PATH."/goto.php?target=pg_".$this->obj->getId().
102  "_".$_GET["ref_id"],
103  $view_frame);
104 
105  include_once("./Services/Style/classes/class.ilObjStyleSheet.php");
106  $page_gui->setStyleId(ilObjStyleSheet::getEffectiveContentStyleId(
107  $this->content_object->getStyleSheetId(), "lm"));
108  $page_gui->setIntLinkHelpDefault("StructureObject", $_GET["ref_id"]);
109  $page_gui->setTemplateTargetVar("ADM_CONTENT");
110  $page_gui->getPageObject()->buildDom();
111  $int_links = $page_gui->getPageObject()->getInternalLinks();
112  $link_xml = $this->getLinkXML($int_links);
113  $page_gui->setLinkXML($link_xml);
114 
115  $page_gui->enableChangeComments($this->content_object->isActiveHistoryUserComments());
116  $page_gui->setFileDownloadLink("ilias.php?cmd=downloadFile&ref_id=".$_GET["ref_id"]."&baseClass=ilLMPresentationGUI");
117  $page_gui->setFullscreenLink("ilias.php?cmd=fullscreen&ref_id=".$_GET["ref_id"]."&baseClass=ilLMPresentationGUI");
118  $page_gui->setLinkParams("ref_id=".$this->content_object->getRefId());
119  $page_gui->setSourcecodeDownloadScript("ilias.php?ref_id=".$_GET["ref_id"]."&baseClass=ilLMPresentationGUI");
120  $page_gui->setPresentationTitle(
121  ilLMPageObject::_getPresentationTitle($this->obj->getId(),
122  $this->content_object->getPageHeader(), $this->content_object->isActiveNumbering()));
123  $page_gui->setLocator($contObjLocator);
124  $page_gui->setHeader($this->lng->txt("page").": ".$this->obj->getTitle());
125  $page_gui->setEnabledActivation(true);
126  $page_gui->setEnabledSelfAssessment(true, false);
127  $page_gui->setEnabledInternalLinks(true);
128  $page_gui->setEnableKeywords(true);
129  $page_gui->setEnabledInternalLinks(true);
130  $page_gui->setEnableAnchors(true);
131  if ($lm_set->get("time_scheduled_page_activation"))
132  {
133  $page_gui->setEnabledScheduledActivation(true);
134  }
135  $page_gui->setActivationListener($this, "activatePage");
136 
137  $mset = new ilSetting("mobs");
138  if ($mset->get("mep_activate_pages"))
139  {
140  $page_gui->enableContentIncludes(true);
141  }
142 
143  //$page_gui->setActivated($this->obj->getActive());
144 
145  $up_gui = ($this->content_object->getType() == "dbk")
146  ? "ilobjdlbookgui"
147  : "ilobjlearningmodulegui";
148  $ilCtrl->setParameterByClass($up_gui, "active_node", $this->obj->getId());
149  $page_gui->setExplorerUpdater("tree", "tree_div",
150  $ilCtrl->getLinkTargetByClass($up_gui, "explorer", "", true));
151 
152  $tpl->setTitleIcon(ilUtil::getImagePath("icon_pg_b.gif"));
153  $tpl->setTitle($this->lng->txt("page").": ".$this->obj->getTitle());
154  if ($this->content_object->getLayoutPerPage())
155  {
156  $page_gui->setTabHook($this, "addPageTabs");
157  }
158  $ret = $this->ctrl->forwardCommand($page_gui);
159 
160  //$ret =& $page_gui->executeCommand();
161  $tpl->setContent($ret);
162  break;
163 
164  default:
165  $ret =& $this->$cmd();
166  break;
167  }
168  }
169 
170 
171  /*
172  * display content of page (edit view)
173  */
174  function edit()
175  {
176 //echo "<br>umschuss";
177  $this->ctrl->setCmdClass("ilpageobjectgui");
178  $this->ctrl->setCmd("edit");
179  $this->executeCommand();
180  //$this->setTabs();
181  }
182 
183  /*
184  * display content of page (edit view)
185  */
186  function preview()
187  {
188  $this->ctrl->setCmdClass("ilpageobjectgui");
189  $this->ctrl->setCmd("preview");
190  $this->executeCommand();
191 // $this->setTabs();
192  }
193 
197  function save()
198  {
199  $this->obj =& new ilLMPageObject($this->content_object);
200  $this->obj->setType("pg");
201  $this->obj->setTitle(ilUtil::stripSlashes($_POST["Fobject"]["title"]));
202  $this->obj->setDescription(ilUtil::stripSlashes($_POST["Fobject"]["desc"]));
203  $this->obj->setLMId($this->content_object->getId());
204  $this->obj->create();
205 
206  // obj_id is empty, if page is created from "all pages" screen
207  // -> a free page is created (not in the tree)
208 //echo "<br>savePage:".$_GET["obj_id"].":";
209  if ($_GET["obj_id"] != 0)
210  {
211  $this->putInTree();
212 
213  // check the tree
214  $this->checkTree();
215 
216  ilUtil::redirect($this->ctrl->getLinkTargetByClass("ilStructureObjectGUI",
217  "edit", "", true));
218  }
219  $up_gui = ($this->content_object->getType() == "dbk")
220  ? "ilobjdlbookgui"
221  : "ilobjlearningmodulegui";
222  $this->ctrl->redirectByClass($up_gui, "pages");
223  }
224 
228  function cancel()
229  {
230  if ($_GET["obj_id"] != 0)
231  {
232  ilUtil::redirect($this->ctrl->getLinkTargetByClass("ilStructureObjectGUI",
233  "view", "", true));
234  }
235  $up_gui = ($this->content_object->getType() == "dbk")
236  ? "ilobjdlbookgui"
237  : "ilobjlearningmodulegui";
238  $this->ctrl->redirectByClass($up_gui, "pages");
239  }
240 
244  function getLinkXML($a_int_links)
245  {
246  if ($a_layoutframes == "")
247  {
248  $a_layoutframes = array();
249  }
250  $link_info = "<IntLinkInfos>";
251  foreach ($a_int_links as $int_link)
252  {
253  $target = $int_link["Target"];
254  if (substr($target, 0, 4) == "il__")
255  {
256  $target_arr = explode("_", $target);
257  $target_id = $target_arr[count($target_arr) - 1];
258  $type = $int_link["Type"];
259  $targetframe = ($int_link["TargetFrame"] != "")
260  ? $int_link["TargetFrame"]
261  : "None";
262 
263  // anchor
264  $anc = $anc_add = "";
265  if ($int_link["Anchor"] != "")
266  {
267  $anc = $int_link["Anchor"];
268  $anc_add = "_".rawurlencode($int_link["Anchor"]);
269  }
270 
271  switch($type)
272  {
273  case "PageObject":
274  case "StructureObject":
276  $cont_obj =& $this->content_object;
277  if ($lm_id == $cont_obj->getId())
278  {
279  $ltarget = "";
280  if ($type == "PageObject")
281  {
282  $this->ctrl->setParameter($this, "obj_id", $target_id);
283  $href = $this->ctrl->getLinkTargetByClass(get_class($this), "edit");
284  }
285  else
286  {
287  $this->ctrl->setParameterByClass("ilstructureobjectgui", "obj_id", $target_id);
288  $href = $this->ctrl->getLinkTargetByClass("ilstructureobjectgui", "view");
289  }
290  $href = str_replace("&", "&amp;", $href);
291  $this->ctrl->setParameter($this, "obj_id", $_GET["obj_id"]);
292  }
293  else
294  {
295  if ($type == "PageObject")
296  {
297  $href = "../goto.php?target=pg_".$target_id.$anc_add;
298  }
299  else
300  {
301  $href = "../goto.php?target=st_".$target_id;
302  }
303  $ltarget = "ilContObj".$lm_id;
304  }
305  break;
306 
307  case "GlossaryItem":
308  $ltarget = $nframe = "_blank";
309  $href = "ilias.php?cmdClass=illmpresentationgui&amp;baseClass=ilLMPresentationGUI&amp;".
310  "obj_type=$type&amp;cmd=glossary&amp;ref_id=".$_GET["ref_id"].
311  "&amp;obj_id=".$target_id."&amp;frame=$nframe";
312  break;
313 
314  case "MediaObject":
315  $ltarget = $nframe = "_blank";
316  $href = "ilias.php?cmdClass=illmpresentationgui&amp;baseClass=ilLMPresentationGUI&amp;obj_type=$type&amp;cmd=media&amp;ref_id=".$_GET["ref_id"].
317  "&amp;mob_id=".$target_id."&amp;frame=$nframe";
318  break;
319 
320  case "RepositoryItem":
321  $obj_type = ilObject::_lookupType($target_id, true);
323  $href = "./goto.php?target=".$obj_type."_".$target_id;
324  $t_frame = ilFrameTargetInfo::_getFrame("MainContent", $obj_type);
325  $ltarget = $t_frame;
326  break;
327  }
328 
329  $anc_par = 'Anchor="'.$anc.'"';
330 
331  $link_info.="<IntLinkInfo Target=\"$target\" Type=\"$type\" ".
332  "TargetFrame=\"$targetframe\" LinkHref=\"$href\" LinkTarget=\"$ltarget\" $anc_par/>";
333  }
334  }
335  $link_info.= "</IntLinkInfos>";
336 //echo ":".htmlentities($link_info).":";
337  return $link_info;
338  }
339 
340 
346 /*
347  function history()
348  {
349  $this->setTabs();
350 
351  require_once("classes/class.ilHistoryGUI.php");
352  $hist_gui =& new ilHistoryGUI($this->obj->getId() ,
353  $this->content_object->getType().":pg");
354  $hist_html = $hist_gui->getHistoryTable(
355  $this->ctrl->getParameterArray($this, "history"),
356  $this->content_object->isActiveHistoryUserComments()
357  );
358 
359  $this->tpl->setVariable("ADM_CONTENT", $hist_html);
360  }*/
361 
365  function updateHistory()
366  {
367  require_once("classes/class.ilHistory.php");
368  ilHistory::_createEntry($this->obj->getId(), "update",
369  "", $this->content_object->getType().":pg",
370  "", true);
371  }
372 
376  function setTabs()
377  {
378  global $ilTabs;
379 return;
380 //echo "setTabs";
381  // catch feedback message
382  #include_once("classes/class.ilTabsGUI.php");
383  #$tabs_gui =& new ilTabsGUI();
384  $this->getTabs($ilTabs);
385 
386  $this->tpl->setCurrentBlock("header_image");
387  $this->tpl->setVariable("IMG_HEADER", ilUtil::getImagePath("icon_pg_b.gif"));
388  $this->tpl->parseCurrentBlock();
389  $this->tpl->setCurrentBlock("content");
390 
391  #$this->tpl->setVariable("TABS", $tabs_gui->getHTML());
392  $this->tpl->setVariable("HEADER",
393  $this->lng->txt($this->obj->getType()).": ".$this->obj->getTitle());
394  }
395 
401 /*
402  function getTabs(&$tabs_gui)
403  {
404  // back to upper context
405  $tabs_gui->addTarget("edit", $this->ctrl->getLinkTarget($this, "view")
406  , array("", "view"), "ilpageobjectgui");
407 
408  $tabs_gui->addTarget("cont_preview", $this->ctrl->getLinkTarget($this, "preview")
409  , "preview", "ilpageobjectgui");
410 
411  //$tabs_gui->addTarget("properties", $this->ctrl->getLinkTarget($this, "properties")
412  // , "properties", get_class($this));
413 
414  $tabs_gui->addTarget("meta_data",
415  $this->ctrl->getLinkTargetByClass('ilmdeditorgui',''),
416  "", "ilmdeditorgui");
417 
418  $tabs_gui->addTarget("history", $this->ctrl->getLinkTarget($this, "history")
419  , "history", get_class($this));
420 
421  $tabs = $this->ctrl->getTabs();
422  foreach ($tabs as $tab)
423  {
424  $tabs_gui->addTarget($tab["lang_var"], $tab["link"]
425  , $tab["cmd"], $tab["class"]);
426  }
427 
428  //$tabs_gui->addTarget("clipboard", $this->ctrl->getLinkTargetByClass("ilEditClipboardGUI", "view")
429  // , "view", "ilEditClipboardGUI");
430 
431  }
432 */
433 
439  function _goto($a_target)
440  {
441  global $rbacsystem, $ilErr, $lng, $ilAccess;
442 
443  $first = strpos($a_target, "_");
444  $second = strpos($a_target, "_", $first + 1);
445  $page_id = substr($a_target, 0, $first);
446  if ($first > 0)
447  {
448  $page_id = substr($a_target, 0, $first);
449  if ($second > 0)
450  {
451  $ref_id = substr($a_target, $first + 1, $second - ($first + 1));
452  $anchor = substr($a_target, $second + 1);
453  }
454  else
455  {
456  $ref_id = substr($a_target, $first + 1);
457  }
458  }
459  else
460  {
461  $page_id = $a_target;
462  }
463 
464  // determine learning object
465  $lm_id = ilLMObject::_lookupContObjID($page_id);
466 
467  // get all references
468  $ref_ids = ilObject::_getAllReferences($lm_id);
469 
470  // always try passed ref id first
471  if (in_array($ref_id, $ref_ids))
472  {
473  $ref_ids = array_merge(array($ref_id), $ref_ids);
474  }
475 
476  // check read permissions
477  foreach ($ref_ids as $ref_id)
478  {
479  // check read permissions
480  if ($ilAccess->checkAccess("read", "", $ref_id))
481  {
482  // don't redirect anymore, just set parameters
483  // (goto.php includes "ilias.php")
484  $_GET["baseClass"] = "ilLMPresentationGUI";
485  $_GET["obj_id"] = $page_id;
486  $_GET["ref_id"] = $ref_id;
487  $_GET["anchor"] = $anchor;
488  include_once("ilias.php");
489  exit;
490  }
491  }
492 
493  if ($ilAccess->checkAccess("read", "", ROOT_FOLDER_ID))
494  {
495  $_GET["cmd"] = "frameset";
496  $_GET["target"] = "";
497  $_GET["ref_id"] = ROOT_FOLDER_ID;
498  if ($lm_id > 0)
499  {
500  ilUtil::sendFailure(sprintf($lng->txt("msg_no_perm_read_item"),
501  ilObject::_lookupTitle($lm_id)), true);
502  }
503  else
504  {
505  $lng->loadLanguageModule("content");
506  ilUtil::sendFailure($lng->txt("page_does_not_exist"), true);
507  }
508  include("repository.php");
509  exit;
510  }
511 
512  $ilErr->raiseError($lng->txt("msg_no_perm_read_lm"), $ilErr->FATAL);
513  }
514 
518  function editLayout()
519  {
520  global $tpl, $ilCtrl, $ilTabs;
521 
522  $page_gui =& new ilPageObjectGUI($this->obj->content_object->getType(),
523  $this->obj->getId());
524  $page_gui->setEditPreview(true);
525  $page_gui->activateMetaDataEditor($this->content_object->getID(),
526  $this->obj->getId(), $this->obj->getType(),
527  $this->obj, "MDUpdateListener");
528  $page_gui->setActivationListener($this, "activatePage");
529  $page_gui->setTabHook($this, "addPageTabs");
530  $page_gui->setEnabledActivation(true);
531  $lm_set = new ilSetting("lm");
532  if ($lm_set->get("time_scheduled_page_activation"))
533  {
534  $page_gui->setEnabledScheduledActivation(true);
535  }
536  $tpl->setTitleIcon(ilUtil::getImagePath("icon_pg_b.gif"));
537  $tpl->setTitle($this->lng->txt("page").": ".$this->obj->getTitle());
538  $ilCtrl->getHTML($page_gui);
539  $ilTabs->setTabActive("cont_layout");
540  $this->initEditLayoutForm();
541  $tpl->setContent($this->form->getHTML());
542  }
543 
549  public function initEditLayoutForm()
550  {
551  global $lng, $ilCtrl;
552 
553  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
554  $this->form = new ilPropertyFormGUI();
555 
556  // default layout
557  $layout = new ilRadioMatrixInputGUI($lng->txt("cont_layout"), "layout");
558  $option = array();
559  if (is_file($im = ilUtil::getImagePath("layout_".$this->content_object->getLayout().".gif")))
560  {
561  $im_tag = ilUtil::img($im, $this->content_object->getLayout());
562  }
563  $option[""] =
564  "<table><tr><td>".$im_tag."</td><td><b>".$lng->txt("cont_lm_default_layout").
565  "</b>: ".$lng->txt("cont_layout_".$this->content_object->getLayout())."</td></tr></table>";
567  {
568  $im_tag = "";
569  if (is_file($im = ilUtil::getImagePath("layout_".$l.".gif")))
570  {
571  $im_tag = ilUtil::img($im, $l);
572  }
573  $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>";
574  }
575  $layout->setOptions($option);
576  $layout->setValue($this->obj->getLayout());
577  $this->form->addItem($layout);
578 
579  $this->form->addCommandButton("saveLayout", $lng->txt("save"));
580 
581  $this->form->setTitle($lng->txt("cont_page_layout"));
582  $this->form->setFormAction($ilCtrl->getFormAction($this));
583 
584  }
585 
590  public function saveLayout()
591  {
592  global $tpl, $lng, $ilCtrl;
593 
594  $this->initEditLayoutForm();
595  if ($this->form->checkInput())
596  {
597  ilLMObject::writeLayout($this->obj->getId(), $this->form->getInput("layout"));
598  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
599  $ilCtrl->redirect($this, "editLayout");
600  }
601  $this->form->setValuesByPost();
602  $tpl->setContent($this->form->getHtml());
603  }
604 
608  function addPageTabs()
609  {
610  global $ilTabs, $ilCtrl;
611 
612  $ilTabs->addTarget("cont_layout",
613  $ilCtrl->getLinkTarget($this, 'editLayout'), "editLayout");
614  }
615 
616 }
617 ?>