ILIAS  Release_4_4_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 ("./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 "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  $page_gui->setExplorerUpdater("tree", "tree_div",
137  $ilCtrl->getLinkTargetByClass($up_gui, "explorer", "", true));
138 
139  $tpl->setTitleIcon(ilUtil::getImagePath("icon_pg_b.png"));
140  $tpl->setTitle($this->lng->txt("page").": ".$this->obj->getTitle());
141  if ($this->content_object->getLayoutPerPage())
142  {
143  $page_gui->setTabHook($this, "addPageTabs");
144  }
145  $ret = $this->ctrl->forwardCommand($page_gui);
146  $tpl->setContent($ret);
147  break;
148 
149  default:
150  $ret =& $this->$cmd();
151  break;
152  }
153  }
154 
155 
156  /*
157  * display content of page (edit view)
158  */
159  function edit()
160  {
161 //echo "<br>umschuss";
162  $this->ctrl->setCmdClass("ilLMPageGUI");
163  $this->ctrl->setCmd("edit");
164  $this->executeCommand();
165  //$this->setTabs();
166  }
167 
168  /*
169  * display content of page (edit view)
170  */
171  function preview()
172  {
173  $this->ctrl->setCmdClass("ilLMPageGUI");
174  $this->ctrl->setCmd("preview");
175  $this->executeCommand();
176 // $this->setTabs();
177  }
178 
182  function save()
183  {
184  $this->obj =& new ilLMPageObject($this->content_object);
185  $this->obj->setType("pg");
186  $this->obj->setTitle(ilUtil::stripSlashes($_POST["Fobject"]["title"]));
187  $this->obj->setDescription(ilUtil::stripSlashes($_POST["Fobject"]["desc"]));
188  $this->obj->setLMId($this->content_object->getId());
189  $this->obj->create();
190 
191  // obj_id is empty, if page is created from "all pages" screen
192  // -> a free page is created (not in the tree)
193 //echo "<br>savePage:".$_GET["obj_id"].":";
194  if ($_GET["obj_id"] != 0)
195  {
196  $this->putInTree();
197 
198  // check the tree
199  $this->checkTree();
200 
201  ilUtil::redirect($this->ctrl->getLinkTargetByClass("ilStructureObjectGUI",
202  "edit", "", true));
203  }
204  $up_gui = ($this->content_object->getType() == "dbk")
205  ? "ilobjdlbookgui"
206  : "ilobjlearningmodulegui";
207  $this->ctrl->redirectByClass($up_gui, "pages");
208  }
209 
213  function cancel()
214  {
215  if ($_GET["obj_id"] != 0)
216  {
217  ilUtil::redirect($this->ctrl->getLinkTargetByClass("ilStructureObjectGUI",
218  "view", "", 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 getLinkXML($a_int_links)
230  {
231  if ($a_layoutframes == "")
232  {
233  $a_layoutframes = array();
234  }
235  $link_info = "<IntLinkInfos>";
236  foreach ($a_int_links as $int_link)
237  {
238  $target = $int_link["Target"];
239  if (substr($target, 0, 4) == "il__")
240  {
241  $target_arr = explode("_", $target);
242  $target_id = $target_arr[count($target_arr) - 1];
243  $type = $int_link["Type"];
244  $targetframe = ($int_link["TargetFrame"] != "")
245  ? $int_link["TargetFrame"]
246  : "None";
247 
248  // anchor
249  $anc = $anc_add = "";
250  if ($int_link["Anchor"] != "")
251  {
252  $anc = $int_link["Anchor"];
253  $anc_add = "_".rawurlencode($int_link["Anchor"]);
254  }
255 
256  switch($type)
257  {
258  case "PageObject":
259  case "StructureObject":
261  $cont_obj =& $this->content_object;
262  if ($lm_id == $cont_obj->getId())
263  {
264  $ltarget = "";
265  if ($type == "PageObject")
266  {
267  $this->ctrl->setParameter($this, "obj_id", $target_id);
268  $href = $this->ctrl->getLinkTargetByClass(get_class($this), "edit");
269  }
270  else
271  {
272  $this->ctrl->setParameterByClass("ilstructureobjectgui", "obj_id", $target_id);
273  $href = $this->ctrl->getLinkTargetByClass("ilstructureobjectgui", "view");
274  }
275  $href = str_replace("&", "&amp;", $href);
276  $this->ctrl->setParameter($this, "obj_id", $_GET["obj_id"]);
277  }
278  else
279  {
280  if ($type == "PageObject")
281  {
282  $href = "goto.php?target=pg_".$target_id.$anc_add;
283  }
284  else
285  {
286  $href = "goto.php?target=st_".$target_id;
287  }
288  $ltarget = "ilContObj".$lm_id;
289  }
290  break;
291 
292  case "GlossaryItem":
293  $ltarget = $nframe = "_blank";
294  $href = "ilias.php?cmdClass=illmpresentationgui&amp;baseClass=ilLMPresentationGUI&amp;".
295  "obj_type=$type&amp;cmd=glossary&amp;ref_id=".$_GET["ref_id"].
296  "&amp;obj_id=".$target_id."&amp;frame=$nframe";
297  break;
298 
299  case "MediaObject":
300  $ltarget = $nframe = "_blank";
301  $href = "ilias.php?cmdClass=illmpresentationgui&amp;baseClass=ilLMPresentationGUI&amp;obj_type=$type&amp;cmd=media&amp;ref_id=".$_GET["ref_id"].
302  "&amp;mob_id=".$target_id."&amp;frame=$nframe";
303  break;
304 
305  case "RepositoryItem":
306  $obj_type = ilObject::_lookupType($target_id, true);
308  $href = "./goto.php?target=".$obj_type."_".$target_id;
309  $t_frame = ilFrameTargetInfo::_getFrame("MainContent", $obj_type);
310  $ltarget = $t_frame;
311  break;
312  }
313 
314  $anc_par = 'Anchor="'.$anc.'"';
315 
316  $link_info.="<IntLinkInfo Target=\"$target\" Type=\"$type\" ".
317  "TargetFrame=\"$targetframe\" LinkHref=\"$href\" LinkTarget=\"$ltarget\" $anc_par/>";
318  }
319  }
320  $link_info.= "</IntLinkInfos>";
321 //echo ":".htmlentities($link_info).":";
322  return $link_info;
323  }
324 
328  function updateHistory()
329  {
330  require_once("./Services/History/classes/class.ilHistory.php");
331  ilHistory::_createEntry($this->obj->getId(), "update",
332  "", $this->content_object->getType().":pg",
333  "", true);
334  }
335 
341  function _goto($a_target)
342  {
343  global $rbacsystem, $ilErr, $lng, $ilAccess;
344 
345  $first = strpos($a_target, "_");
346  $second = strpos($a_target, "_", $first + 1);
347  $page_id = substr($a_target, 0, $first);
348  if ($first > 0)
349  {
350  $page_id = substr($a_target, 0, $first);
351  if ($second > 0)
352  {
353  $ref_id = substr($a_target, $first + 1, $second - ($first + 1));
354  $anchor = substr($a_target, $second + 1);
355  }
356  else
357  {
358  $ref_id = substr($a_target, $first + 1);
359  }
360  }
361  else
362  {
363  $page_id = $a_target;
364  }
365 
366  // determine learning object
367  $lm_id = ilLMObject::_lookupContObjID($page_id);
368 
369  // get all references
370  $ref_ids = ilObject::_getAllReferences($lm_id);
371 
372  // always try passed ref id first
373  if (in_array($ref_id, $ref_ids))
374  {
375  $ref_ids = array_merge(array($ref_id), $ref_ids);
376  }
377 
378  // check read permissions
379  foreach ($ref_ids as $ref_id)
380  {
381  // check read permissions
382  if ($ilAccess->checkAccess("read", "", $ref_id))
383  {
384  // don't redirect anymore, just set parameters
385  // (goto.php includes "ilias.php")
386  $_GET["baseClass"] = "ilLMPresentationGUI";
387  $_GET["obj_id"] = $page_id;
388  $_GET["ref_id"] = $ref_id;
389  $_GET["anchor"] = $anchor;
390  include_once("ilias.php");
391  exit;
392  }
393  }
394 
395  if ($ilAccess->checkAccess("read", "", ROOT_FOLDER_ID))
396  {
397  if ($lm_id > 0)
398  {
399  ilUtil::sendFailure(sprintf($lng->txt("msg_no_perm_read_item"),
400  ilObject::_lookupTitle($lm_id)), true);
401  }
402  else
403  {
404  $lng->loadLanguageModule("content");
405  ilUtil::sendFailure($lng->txt("page_does_not_exist"), true);
406  }
407  include_once("./Services/Object/classes/class.ilObjectGUI.php");
409  }
410 
411  $ilErr->raiseError($lng->txt("msg_no_perm_read_lm"), $ilErr->FATAL);
412  }
413 
417  function editLayout()
418  {
419  global $tpl, $ilCtrl, $ilTabs;
420 
421  $page_gui = new ilLMPageGUI($this->obj->getId());
422  $page_gui->setEditPreview(true);
423  $page_gui->activateMetaDataEditor($this->content_object->getID(),
424  $this->obj->getId(), $this->obj->getType(),
425  $this->obj, "MDUpdateListener");
426  $page_gui->setActivationListener($this, "activatePage");
427  $page_gui->setTabHook($this, "addPageTabs");
428  $lm_set = new ilSetting("lm");
429  $tpl->setTitleIcon(ilUtil::getImagePath("icon_pg_b.png"));
430  $tpl->setTitle($this->lng->txt("page").": ".$this->obj->getTitle());
431  $ilCtrl->getHTML($page_gui);
432  $ilTabs->setTabActive("cont_layout");
433  $this->initEditLayoutForm();
434  $tpl->setContent($this->form->getHTML());
435  }
436 
442  public function initEditLayoutForm()
443  {
444  global $lng, $ilCtrl;
445 
446  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
447  $this->form = new ilPropertyFormGUI();
448 
449  // default layout
450  $layout = new ilRadioGroupInputGUI($lng->txt("cont_layout"), "layout");
451 
452  if (is_file($im = ilUtil::getImagePath("layout_".$this->content_object->getLayout().".png")))
453  {
454  $im_tag = ilUtil::img($im, $this->content_object->getLayout());
455  }
456  $layout->addOption(new ilRadioOption("<table><tr><td>".$im_tag."</td><td><b>".
457  $lng->txt("cont_lm_default_layout").
458  "</b>: ".$lng->txt("cont_layout_".$this->content_object->getLayout()).
459  "</td></tr></table>", ""));
460 
462  {
463  $im_tag = "";
464  if (is_file($im = ilUtil::getImagePath("layout_".$l.".png")))
465  {
466  $im_tag = ilUtil::img($im, $l);
467  }
468  $layout->addOption(new ilRadioOption("<table><tr><td>".$im_tag."</td><td><b>".
469  $lng->txt("cont_layout_".$l)."</b>: ".$lng->txt("cont_layout_".$l."_desc").
470  "</td></tr></table>", $l));
471  }
472 
473  $layout->setValue($this->obj->getLayout());
474  $this->form->addItem($layout);
475 
476  $this->form->addCommandButton("saveLayout", $lng->txt("save"));
477 
478  $this->form->setTitle($lng->txt("cont_page_layout"));
479  $this->form->setFormAction($ilCtrl->getFormAction($this));
480 
481  }
482 
487  public function saveLayout()
488  {
489  global $tpl, $lng, $ilCtrl;
490 
491  $this->initEditLayoutForm();
492  if ($this->form->checkInput())
493  {
494  ilLMObject::writeLayout($this->obj->getId(), $this->form->getInput("layout"));
495  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
496  $ilCtrl->redirect($this, "editLayout");
497  }
498  $this->form->setValuesByPost();
499  $tpl->setContent($this->form->getHtml());
500  }
501 
505  function addPageTabs()
506  {
507  global $ilTabs, $ilCtrl;
508 
509  $ilTabs->addTarget("cont_layout",
510  $ilCtrl->getLinkTarget($this, 'editLayout'), "editLayout");
511  }
512 
513 }
514 ?>