ILIAS  Release_4_2_x_branch Revision 61807
 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 
343  function updateHistory()
344  {
345  require_once("classes/class.ilHistory.php");
346  ilHistory::_createEntry($this->obj->getId(), "update",
347  "", $this->content_object->getType().":pg",
348  "", true);
349  }
350 
356  function _goto($a_target)
357  {
358  global $rbacsystem, $ilErr, $lng, $ilAccess;
359 
360  $first = strpos($a_target, "_");
361  $second = strpos($a_target, "_", $first + 1);
362  $page_id = substr($a_target, 0, $first);
363  if ($first > 0)
364  {
365  $page_id = substr($a_target, 0, $first);
366  if ($second > 0)
367  {
368  $ref_id = substr($a_target, $first + 1, $second - ($first + 1));
369  $anchor = substr($a_target, $second + 1);
370  }
371  else
372  {
373  $ref_id = substr($a_target, $first + 1);
374  }
375  }
376  else
377  {
378  $page_id = $a_target;
379  }
380 
381  // determine learning object
382  $lm_id = ilLMObject::_lookupContObjID($page_id);
383 
384  // get all references
385  $ref_ids = ilObject::_getAllReferences($lm_id);
386 
387  // always try passed ref id first
388  if (in_array($ref_id, $ref_ids))
389  {
390  $ref_ids = array_merge(array($ref_id), $ref_ids);
391  }
392 
393  // check read permissions
394  foreach ($ref_ids as $ref_id)
395  {
396  // check read permissions
397  if ($ilAccess->checkAccess("read", "", $ref_id))
398  {
399  // don't redirect anymore, just set parameters
400  // (goto.php includes "ilias.php")
401  $_GET["baseClass"] = "ilLMPresentationGUI";
402  $_GET["obj_id"] = $page_id;
403  $_GET["ref_id"] = $ref_id;
404  $_GET["anchor"] = $anchor;
405  include_once("ilias.php");
406  exit;
407  }
408  }
409 
410  if ($ilAccess->checkAccess("read", "", ROOT_FOLDER_ID))
411  {
412  $_GET["cmd"] = "frameset";
413  $_GET["target"] = "";
414  $_GET["ref_id"] = ROOT_FOLDER_ID;
415  if ($lm_id > 0)
416  {
417  ilUtil::sendFailure(sprintf($lng->txt("msg_no_perm_read_item"),
418  ilObject::_lookupTitle($lm_id)), true);
419  }
420  else
421  {
422  $lng->loadLanguageModule("content");
423  ilUtil::sendFailure($lng->txt("page_does_not_exist"), true);
424  }
425  include("repository.php");
426  exit;
427  }
428 
429  $ilErr->raiseError($lng->txt("msg_no_perm_read_lm"), $ilErr->FATAL);
430  }
431 
435  function editLayout()
436  {
437  global $tpl, $ilCtrl, $ilTabs;
438 
439  $page_gui =& new ilPageObjectGUI($this->obj->content_object->getType(),
440  $this->obj->getId());
441  $page_gui->setEditPreview(true);
442  $page_gui->activateMetaDataEditor($this->content_object->getID(),
443  $this->obj->getId(), $this->obj->getType(),
444  $this->obj, "MDUpdateListener");
445  $page_gui->setActivationListener($this, "activatePage");
446  $page_gui->setTabHook($this, "addPageTabs");
447  $page_gui->setEnabledActivation(true);
448  $lm_set = new ilSetting("lm");
449  if ($lm_set->get("time_scheduled_page_activation"))
450  {
451  $page_gui->setEnabledScheduledActivation(true);
452  }
453  $tpl->setTitleIcon(ilUtil::getImagePath("icon_pg_b.gif"));
454  $tpl->setTitle($this->lng->txt("page").": ".$this->obj->getTitle());
455  $ilCtrl->getHTML($page_gui);
456  $ilTabs->setTabActive("cont_layout");
457  $this->initEditLayoutForm();
458  $tpl->setContent($this->form->getHTML());
459  }
460 
466  public function initEditLayoutForm()
467  {
468  global $lng, $ilCtrl;
469 
470  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
471  $this->form = new ilPropertyFormGUI();
472 
473  // default layout
474  $layout = new ilRadioMatrixInputGUI($lng->txt("cont_layout"), "layout");
475  $option = array();
476  if (is_file($im = ilUtil::getImagePath("layout_".$this->content_object->getLayout().".gif")))
477  {
478  $im_tag = ilUtil::img($im, $this->content_object->getLayout());
479  }
480  $option[""] =
481  "<table><tr><td>".$im_tag."</td><td><b>".$lng->txt("cont_lm_default_layout").
482  "</b>: ".$lng->txt("cont_layout_".$this->content_object->getLayout())."</td></tr></table>";
484  {
485  $im_tag = "";
486  if (is_file($im = ilUtil::getImagePath("layout_".$l.".gif")))
487  {
488  $im_tag = ilUtil::img($im, $l);
489  }
490  $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>";
491  }
492  $layout->setOptions($option);
493  $layout->setValue($this->obj->getLayout());
494  $this->form->addItem($layout);
495 
496  $this->form->addCommandButton("saveLayout", $lng->txt("save"));
497 
498  $this->form->setTitle($lng->txt("cont_page_layout"));
499  $this->form->setFormAction($ilCtrl->getFormAction($this));
500 
501  }
502 
507  public function saveLayout()
508  {
509  global $tpl, $lng, $ilCtrl;
510 
511  $this->initEditLayoutForm();
512  if ($this->form->checkInput())
513  {
514  ilLMObject::writeLayout($this->obj->getId(), $this->form->getInput("layout"));
515  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
516  $ilCtrl->redirect($this, "editLayout");
517  }
518  $this->form->setValuesByPost();
519  $tpl->setContent($this->form->getHtml());
520  }
521 
525  function addPageTabs()
526  {
527  global $ilTabs, $ilCtrl;
528 
529  $ilTabs->addTarget("cont_layout",
530  $ilCtrl->getLinkTarget($this, 'editLayout'), "editLayout");
531  }
532 
533 }
534 ?>