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