ILIAS  Release_5_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("./Modules/LearningModule/classes/class.ilLMPageGUI.php");
7 require_once("./Services/Link/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 "illmpagegui":
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  if (!ilPageObject::_exists("lm", $this->obj->getId(), $_GET["transl"]) &&
74  ilPageObject::_exists("lm", $this->obj->getId(), "-"))
75  {
76  if ($_GET["totransl"] == "")
77  {
78  $_GET["totransl"] = $_GET["transl"];
79  $ilCtrl->setCmd("switchToLanguage");
80  }
81  $ilCtrl->setCmdClass("illmpagegui");
82  $page_gui = new ilLMPageGUI($this->obj->getId(), 0, false, "-");
83  }
84  else
85  {
86  $page_gui = new ilLMPageGUI($this->obj->getId());
87  }
88  $page_gui->setEditPreview(true);
89  $page_gui->activateMetaDataEditor($this->content_object->getID(),
90  $this->obj->getId(), $this->obj->getType(),
91  $this->obj, "MDUpdateListener");
92  if ($ilSetting->get("block_activated_news"))
93  {
94  $page_gui->setEnabledNews(true, $this->obj->content_object->getId(),
95  $this->obj->content_object->getType());
96  }
97 
98  // set page view link
99  if ($showViewInFrameset)
100  {
101  $view_frame = ilFrameTargetInfo::_getFrame("MainContent");
102  }
103  else
104  {
105  $view_frame = "ilContObj".$this->content_object->getID();
106  }
107  $page_gui->setViewPageLink(ILIAS_HTTP_PATH."/goto.php?target=pg_".$this->obj->getId().
108  "_".$_GET["ref_id"],
109  $view_frame);
110 
111  include_once("./Services/Style/classes/class.ilObjStyleSheet.php");
112  $page_gui->setStyleId(ilObjStyleSheet::getEffectiveContentStyleId(
113  $this->content_object->getStyleSheetId(), "lm"));
114  $page_gui->setTemplateTargetVar("ADM_CONTENT");
115  $page_gui->getPageObject()->buildDom();
116  $int_links = $page_gui->getPageObject()->getInternalLinks();
117  $link_xml = $this->getLinkXML($int_links);
118  $page_gui->setLinkXML($link_xml);
119 
120  $page_gui->enableChangeComments($this->content_object->isActiveHistoryUserComments());
121  $page_gui->setFileDownloadLink("ilias.php?cmd=downloadFile&ref_id=".$_GET["ref_id"]."&baseClass=ilLMPresentationGUI");
122  $page_gui->setFullscreenLink("ilias.php?cmd=fullscreen&ref_id=".$_GET["ref_id"]."&baseClass=ilLMPresentationGUI");
123  $page_gui->setLinkParams("ref_id=".$this->content_object->getRefId());
124  $page_gui->setSourcecodeDownloadScript("ilias.php?ref_id=".$_GET["ref_id"]."&baseClass=ilLMPresentationGUI");
125  $page_gui->setPresentationTitle(
126  ilLMPageObject::_getPresentationTitle($this->obj->getId(),
127  $this->content_object->getPageHeader(), $this->content_object->isActiveNumbering()));
128  $page_gui->setLocator($contObjLocator);
129  $page_gui->setHeader($this->lng->txt("page").": ".$this->obj->getTitle());
130  $page_gui->setActivationListener($this, "activatePage");
131 
132  $up_gui = ($this->content_object->getType() == "dbk")
133  ? "ilobjdlbookgui"
134  : "ilobjlearningmodulegui";
135  $ilCtrl->setParameterByClass($up_gui, "active_node", $this->obj->getId());
136 
137  $tpl->setTitleIcon(ilUtil::getImagePath("icon_pg.svg"));
138  $tpl->setTitle($this->lng->txt("page").": ".$this->obj->getTitle());
139  if ($this->content_object->getLayoutPerPage())
140  {
141  $page_gui->setTabHook($this, "addPageTabs");
142  }
143  $ret = $this->ctrl->forwardCommand($page_gui);
144  $tpl->setContent($ret);
145  break;
146 
147  default:
148  $ret =& $this->$cmd();
149  break;
150  }
151  }
152 
153 
154  /*
155  * display content of page (edit view)
156  */
157  function edit()
158  {
159 //echo "<br>umschuss";
160  $this->ctrl->setCmdClass("ilLMPageGUI");
161  $this->ctrl->setCmd("edit");
162  $this->executeCommand();
163  //$this->setTabs();
164  }
165 
166  /*
167  * display content of page (edit view)
168  */
169  function preview()
170  {
171  $this->ctrl->setCmdClass("ilLMPageGUI");
172  $this->ctrl->setCmd("preview");
173  $this->executeCommand();
174 // $this->setTabs();
175  }
176 
180  function save()
181  {
182  $this->obj =& new ilLMPageObject($this->content_object);
183  $this->obj->setType("pg");
184  $this->obj->setTitle(ilUtil::stripSlashes($_POST["Fobject"]["title"]));
185  $this->obj->setDescription(ilUtil::stripSlashes($_POST["Fobject"]["desc"]));
186  $this->obj->setLMId($this->content_object->getId());
187  $this->obj->create();
188 
189  // obj_id is empty, if page is created from "all pages" screen
190  // -> a free page is created (not in the tree)
191 //echo "<br>savePage:".$_GET["obj_id"].":";
192  if ($_GET["obj_id"] != 0)
193  {
194  $this->putInTree();
195 
196  // check the tree
197  $this->checkTree();
198 
199  ilUtil::redirect($this->ctrl->getLinkTargetByClass("ilStructureObjectGUI",
200  "edit", "", true));
201  }
202  $up_gui = ($this->content_object->getType() == "dbk")
203  ? "ilobjdlbookgui"
204  : "ilobjlearningmodulegui";
205  $this->ctrl->redirectByClass($up_gui, "pages");
206  }
207 
211  function cancel()
212  {
213  if ($_GET["obj_id"] != 0)
214  {
215  ilUtil::redirect($this->ctrl->getLinkTargetByClass("ilStructureObjectGUI",
216  "view", "", true));
217  }
218  $up_gui = ($this->content_object->getType() == "dbk")
219  ? "ilobjdlbookgui"
220  : "ilobjlearningmodulegui";
221  $this->ctrl->redirectByClass($up_gui, "pages");
222  }
223 
227  function getLinkXML($a_int_links)
228  {
229  if ($a_layoutframes == "")
230  {
231  $a_layoutframes = array();
232  }
233  $link_info = "<IntLinkInfos>";
234  foreach ($a_int_links as $int_link)
235  {
236  $target = $int_link["Target"];
237  if (substr($target, 0, 4) == "il__")
238  {
239  $target_arr = explode("_", $target);
240  $target_id = $target_arr[count($target_arr) - 1];
241  $type = $int_link["Type"];
242  $targetframe = ($int_link["TargetFrame"] != "")
243  ? $int_link["TargetFrame"]
244  : "None";
245 
246  // anchor
247  $anc = $anc_add = "";
248  if ($int_link["Anchor"] != "")
249  {
250  $anc = $int_link["Anchor"];
251  $anc_add = "_".rawurlencode($int_link["Anchor"]);
252  }
253 
254  switch($type)
255  {
256  case "PageObject":
257  case "StructureObject":
259  $cont_obj =& $this->content_object;
260  if ($lm_id == $cont_obj->getId())
261  {
262  $ltarget = "";
263  if ($type == "PageObject")
264  {
265  $this->ctrl->setParameter($this, "obj_id", $target_id);
266  $href = $this->ctrl->getLinkTargetByClass(get_class($this), "edit");
267  }
268  else
269  {
270  $this->ctrl->setParameterByClass("ilstructureobjectgui", "obj_id", $target_id);
271  $href = $this->ctrl->getLinkTargetByClass("ilstructureobjectgui", "view");
272  }
273  $href = str_replace("&", "&amp;", $href);
274  $this->ctrl->setParameter($this, "obj_id", $_GET["obj_id"]);
275  }
276  else
277  {
278  if ($type == "PageObject")
279  {
280  $href = "goto.php?target=pg_".$target_id.$anc_add;
281  }
282  else
283  {
284  $href = "goto.php?target=st_".$target_id;
285  }
286  $ltarget = "ilContObj".$lm_id;
287  }
288  break;
289 
290  case "GlossaryItem":
291  $ltarget = $nframe = "_blank";
292  $href = "ilias.php?cmdClass=illmpresentationgui&amp;baseClass=ilLMPresentationGUI&amp;".
293  "obj_type=$type&amp;cmd=glossary&amp;ref_id=".$_GET["ref_id"].
294  "&amp;obj_id=".$target_id."&amp;frame=$nframe";
295  break;
296 
297  case "MediaObject":
298  $ltarget = $nframe = "_blank";
299  $href = "ilias.php?cmdClass=illmpresentationgui&amp;baseClass=ilLMPresentationGUI&amp;obj_type=$type&amp;cmd=media&amp;ref_id=".$_GET["ref_id"].
300  "&amp;mob_id=".$target_id."&amp;frame=$nframe";
301  break;
302 
303  case "RepositoryItem":
304  $obj_type = ilObject::_lookupType($target_id, true);
306  $href = "./goto.php?target=".$obj_type."_".$target_id;
307  $t_frame = ilFrameTargetInfo::_getFrame("MainContent", $obj_type);
308  $ltarget = $t_frame;
309  break;
310  }
311 
312  $anc_par = 'Anchor="'.$anc.'"';
313 
314  $link_info.="<IntLinkInfo Target=\"$target\" Type=\"$type\" ".
315  "TargetFrame=\"$targetframe\" LinkHref=\"$href\" LinkTarget=\"$ltarget\" $anc_par/>";
316  }
317  }
318  $link_info.= "</IntLinkInfos>";
319 //echo ":".htmlentities($link_info).":";
320  return $link_info;
321  }
322 
326  function updateHistory()
327  {
328  require_once("./Services/History/classes/class.ilHistory.php");
329  ilHistory::_createEntry($this->obj->getId(), "update",
330  "", $this->content_object->getType().":pg",
331  "", true);
332  }
333 
339  public static function _goto($a_target)
340  {
341  global $rbacsystem, $ilErr, $lng, $ilAccess;
342 
343  $first = strpos($a_target, "_");
344  $second = strpos($a_target, "_", $first + 1);
345  $page_id = substr($a_target, 0, $first);
346  if ($first > 0)
347  {
348  $page_id = substr($a_target, 0, $first);
349  if ($second > 0)
350  {
351  $ref_id = substr($a_target, $first + 1, $second - ($first + 1));
352  $anchor = substr($a_target, $second + 1);
353  }
354  else
355  {
356  $ref_id = substr($a_target, $first + 1);
357  }
358  }
359  else
360  {
361  $page_id = $a_target;
362  }
363 
364  // determine learning object
365  $lm_id = ilLMObject::_lookupContObjID($page_id);
366 
367  // get all references
368  $ref_ids = ilObject::_getAllReferences($lm_id);
369 
370  // always try passed ref id first
371  if (in_array($ref_id, $ref_ids))
372  {
373  $ref_ids = array_merge(array($ref_id), $ref_ids);
374  }
375 
376  // check read permissions
377  foreach ($ref_ids as $ref_id)
378  {
379  // check read permissions
380  if ($ilAccess->checkAccess("read", "", $ref_id))
381  {
382  // don't redirect anymore, just set parameters
383  // (goto.php includes "ilias.php")
384  $_GET["baseClass"] = "ilLMPresentationGUI";
385  $_GET["obj_id"] = $page_id;
386  $_GET["ref_id"] = $ref_id;
387  $_GET["anchor"] = $anchor;
388  include_once("ilias.php");
389  exit;
390  }
391  }
392 
393  if ($ilAccess->checkAccess("read", "", ROOT_FOLDER_ID))
394  {
395  if ($lm_id > 0)
396  {
397  ilUtil::sendFailure(sprintf($lng->txt("msg_no_perm_read_item"),
398  ilObject::_lookupTitle($lm_id)), true);
399  }
400  else
401  {
402  $lng->loadLanguageModule("content");
403  ilUtil::sendFailure($lng->txt("page_does_not_exist"), true);
404  }
405  include_once("./Services/Object/classes/class.ilObjectGUI.php");
407  }
408 
409  $ilErr->raiseError($lng->txt("msg_no_perm_read_lm"), $ilErr->FATAL);
410  }
411 
415  function editLayout()
416  {
417  global $tpl, $ilCtrl, $ilTabs;
418 
419  $page_gui = new ilLMPageGUI($this->obj->getId());
420  $page_gui->setEditPreview(true);
421  $page_gui->activateMetaDataEditor($this->content_object->getID(),
422  $this->obj->getId(), $this->obj->getType(),
423  $this->obj, "MDUpdateListener");
424  $page_gui->setActivationListener($this, "activatePage");
425  $page_gui->setTabHook($this, "addPageTabs");
426  $lm_set = new ilSetting("lm");
427  $tpl->setTitleIcon(ilUtil::getImagePath("icon_pg.svg"));
428  $tpl->setTitle($this->lng->txt("page").": ".$this->obj->getTitle());
429  $ilCtrl->getHTML($page_gui);
430  $ilTabs->setTabActive("cont_layout");
431  $this->initEditLayoutForm();
432  $tpl->setContent($this->form->getHTML());
433  }
434 
440  public function initEditLayoutForm()
441  {
442  global $lng, $ilCtrl;
443 
444  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
445  $this->form = new ilPropertyFormGUI();
446 
447  // default layout
448  $layout = new ilRadioGroupInputGUI($lng->txt("cont_layout"), "layout");
449 
450  if (is_file($im = ilUtil::getImagePath("layout_".$this->content_object->getLayout().".png")))
451  {
452  $im_tag = ilUtil::img($im, $this->content_object->getLayout());
453  }
454  $layout->addOption(new ilRadioOption("<table><tr><td>".$im_tag."</td><td><b>".
455  $lng->txt("cont_lm_default_layout").
456  "</b>: ".$lng->txt("cont_layout_".$this->content_object->getLayout()).
457  "</td></tr></table>", ""));
458 
460  {
461  $im_tag = "";
462  if (is_file($im = ilUtil::getImagePath("layout_".$l.".png")))
463  {
464  $im_tag = ilUtil::img($im, $l);
465  }
466  $layout->addOption(new ilRadioOption("<table><tr><td>".$im_tag."</td><td><b>".
467  $lng->txt("cont_layout_".$l)."</b>: ".$lng->txt("cont_layout_".$l."_desc").
468  "</td></tr></table>", $l));
469  }
470 
471  $layout->setValue($this->obj->getLayout());
472  $this->form->addItem($layout);
473 
474  $this->form->addCommandButton("saveLayout", $lng->txt("save"));
475 
476  $this->form->setTitle($lng->txt("cont_page_layout"));
477  $this->form->setFormAction($ilCtrl->getFormAction($this));
478 
479  }
480 
485  public function saveLayout()
486  {
487  global $tpl, $lng, $ilCtrl;
488 
489  $this->initEditLayoutForm();
490  if ($this->form->checkInput())
491  {
492  ilLMObject::writeLayout($this->obj->getId(), $this->form->getInput("layout"));
493  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
494  $ilCtrl->redirect($this, "editLayout");
495  }
496  $this->form->setValuesByPost();
497  $tpl->setContent($this->form->getHtml());
498  }
499 
503  function addPageTabs()
504  {
505  global $ilTabs, $ilCtrl;
506 
507  $ilTabs->addTarget("cont_layout",
508  $ilCtrl->getLinkTarget($this, 'editLayout'), "editLayout");
509  }
510 
511 }
512 ?>