ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 {
26  protected $tabs;
27 
31  protected $settings;
32 
33  public $obj;
34 
41  public function __construct(&$a_content_obj)
42  {
43  global $DIC;
44 
45  $this->tpl = $DIC["tpl"];
46  $this->ctrl = $DIC->ctrl();
47  $this->tabs = $DIC->tabs();
48  $this->settings = $DIC->settings();
49  $this->lng = $DIC->language();
50  parent::__construct($a_content_obj);
51  }
52 
53 
57  public function setLMPageObject($a_pg_obj)
58  {
59  $this->obj = $a_pg_obj;
60  $this->obj->setLMId($this->content_object->getId());
61  }
62 
66  public function executeCommand()
67  {
68  $tpl = $this->tpl;
70  $ilTabs = $this->tabs;
72 
73  $next_class = $this->ctrl->getNextClass($this);
74  $cmd = $this->ctrl->getCmd();
75 
76  //echo "<br>:cmd:".$this->ctrl->getCmd().":cmdClass:".$this->ctrl->getCmdClass().":".
77  // ":nextClass:".$next_class.":"; flush();
78 
79  switch ($next_class) {
80  case "illmpagegui":
81 
82  // Determine whether the view of a learning resource should
83  // be shown in the frameset of ilias, or in a separate window.
84  $showViewInFrameset = true;
85  $lm_set = new ilSetting("lm");
86 
87  $this->ctrl->setReturn($this, "edit");
88  if (!ilPageObject::_exists("lm", $this->obj->getId(), $_GET["transl"]) &&
89  ilPageObject::_exists("lm", $this->obj->getId(), "-")) {
90  if ($_GET["totransl"] == "") {
91  $_GET["totransl"] = $_GET["transl"];
92  $ilCtrl->setCmd("switchToLanguage");
93  }
94  $ilCtrl->setCmdClass("illmpagegui");
95  $page_gui = new ilLMPageGUI($this->obj->getId(), 0, false, "-");
96  } else {
97  $page_gui = new ilLMPageGUI($this->obj->getId());
98  }
99  $page_gui->setEditPreview(true);
100  $page_gui->activateMetaDataEditor(
101  $this->content_object,
102  $this->obj->getType(),
103  $this->obj->getId(),
104  $this->obj,
105  "MDUpdateListener"
106  );
107  if ($ilSetting->get("block_activated_news")) {
108  $page_gui->setEnabledNews(
109  true,
110  $this->obj->content_object->getId(),
111  $this->obj->content_object->getType()
112  );
113  }
114 
115  // set page view link
116  if ($showViewInFrameset) {
117  $view_frame = ilFrameTargetInfo::_getFrame("MainContent");
118  } else {
119  $view_frame = "ilContObj" . $this->content_object->getID();
120  }
121  $page_gui->setViewPageLink(
122  ILIAS_HTTP_PATH . "/goto.php?target=pg_" . $this->obj->getId() .
123  "_" . $_GET["ref_id"],
124  $view_frame
125  );
126 
127  include_once("./Services/Style/Content/classes/class.ilObjStyleSheet.php");
128  $page_gui->setStyleId(ilObjStyleSheet::getEffectiveContentStyleId(
129  $this->content_object->getStyleSheetId(),
130  "lm"
131  ));
132  $page_gui->setTemplateTargetVar("ADM_CONTENT");
133  $page_gui->getPageObject()->buildDom();
134  $int_links = $page_gui->getPageObject()->getInternalLinks();
135  $link_xml = $this->getLinkXML($int_links);
136  $page_gui->setLinkXML($link_xml);
137 
138  $page_gui->enableChangeComments($this->content_object->isActiveHistoryUserComments());
139  $page_gui->setFileDownloadLink("ilias.php?cmd=downloadFile&ref_id=" . $_GET["ref_id"] . "&baseClass=ilLMPresentationGUI");
140  $page_gui->setFullscreenLink("ilias.php?cmd=fullscreen&ref_id=" . $_GET["ref_id"] . "&baseClass=ilLMPresentationGUI");
141  $page_gui->setLinkParams("ref_id=" . $this->content_object->getRefId());
142  $page_gui->setSourcecodeDownloadScript("ilias.php?ref_id=" . $_GET["ref_id"] . "&baseClass=ilLMPresentationGUI");
143  $page_gui->setPresentationTitle(
145  $this->obj->getId(),
146  $this->content_object->getPageHeader(),
147  $this->content_object->isActiveNumbering()
148  )
149  );
150  $page_gui->setLocator($contObjLocator);
151  $page_gui->setHeader($this->lng->txt("page") . ": " . $this->obj->getTitle());
152  $page_gui->setActivationListener($this, "activatePage");
153 
154  $up_gui = "ilobjlearningmodulegui";
155  $ilCtrl->setParameterByClass($up_gui, "active_node", $this->obj->getId());
156 
157  $tpl->setTitleIcon(ilUtil::getImagePath("icon_pg.svg"));
158  $tpl->setTitle($this->lng->txt("page") . ": " . $this->obj->getTitle());
159  if ($this->content_object->getLayoutPerPage()) {
160  $page_gui->setTabHook($this, "addPageTabs");
161  }
162  $ret = $this->ctrl->forwardCommand($page_gui);
163  $tpl->setContent($ret);
164  break;
165 
166  default:
167  $ret = $this->$cmd();
168  break;
169  }
170  }
171 
172 
173  /*
174  * display content of page (edit view)
175  */
176  public function edit()
177  {
178  //echo "<br>umschuss";
179  $this->ctrl->setCmdClass("ilLMPageGUI");
180  $this->ctrl->setCmd("edit");
181  $this->executeCommand();
182  //$this->setTabs();
183  }
184 
185  /*
186  * display content of page (edit view)
187  */
188  public function preview()
189  {
190  $this->ctrl->setCmdClass("ilLMPageGUI");
191  $this->ctrl->setCmd("preview");
192  $this->executeCommand();
193  // $this->setTabs();
194  }
195 
199  public function save()
200  {
201  $this->obj = new ilLMPageObject($this->content_object);
202  $this->obj->setType("pg");
203  $this->obj->setTitle(ilUtil::stripSlashes($_POST["Fobject"]["title"]));
204  $this->obj->setDescription(ilUtil::stripSlashes($_POST["Fobject"]["desc"]));
205  $this->obj->setLMId($this->content_object->getId());
206  $this->obj->create();
207 
208  // obj_id is empty, if page is created from "all pages" screen
209  // -> a free page is created (not in the tree)
210  //echo "<br>savePage:".$_GET["obj_id"].":";
211  if ($_GET["obj_id"] != 0) {
212  $this->putInTree();
213 
214  // check the tree
215  $this->checkTree();
216 
217  ilUtil::redirect($this->ctrl->getLinkTargetByClass(
218  "ilStructureObjectGUI",
219  "edit",
220  "",
221  true
222  ));
223  }
224  $up_gui = "ilobjlearningmodulegui";
225  $this->ctrl->redirectByClass($up_gui, "pages");
226  }
227 
231  public function cancel()
232  {
233  if ($_GET["obj_id"] != 0) {
234  ilUtil::redirect($this->ctrl->getLinkTargetByClass(
235  "ilStructureObjectGUI",
236  "view",
237  "",
238  true
239  ));
240  }
241  $up_gui = "ilobjlearningmodulegui";
242  $this->ctrl->redirectByClass($up_gui, "pages");
243  }
244 
248  public function getLinkXML($a_int_links)
249  {
250  if ($a_layoutframes == "") {
251  $a_layoutframes = array();
252  }
253  $link_info = "<IntLinkInfos>";
254  foreach ($a_int_links as $int_link) {
255  $target = $int_link["Target"];
256  if (substr($target, 0, 4) == "il__") {
257  $target_arr = explode("_", $target);
258  $target_id = $target_arr[count($target_arr) - 1];
259  $type = $int_link["Type"];
260  $targetframe = ($int_link["TargetFrame"] != "")
261  ? $int_link["TargetFrame"]
262  : "None";
263 
264  // anchor
265  $anc = $anc_add = "";
266  if ($int_link["Anchor"] != "") {
267  $anc = $int_link["Anchor"];
268  $anc_add = "_" . rawurlencode($int_link["Anchor"]);
269  }
270 
271  switch ($type) {
272  case "PageObject":
273  case "StructureObject":
275  $cont_obj = $this->content_object;
276  if ($lm_id == $cont_obj->getId()) {
277  $ltarget = "";
278  if ($type == "PageObject") {
279  $this->ctrl->setParameter($this, "obj_id", $target_id);
280  $href = $this->ctrl->getLinkTargetByClass(get_class($this), "edit");
281  } else {
282  $this->ctrl->setParameterByClass("ilstructureobjectgui", "obj_id", $target_id);
283  $href = $this->ctrl->getLinkTargetByClass("ilstructureobjectgui", "view");
284  }
285  $href = str_replace("&", "&amp;", $href);
286  $this->ctrl->setParameter($this, "obj_id", $_GET["obj_id"]);
287  } else {
288  if ($type == "PageObject") {
289  $href = "goto.php?target=pg_" . $target_id . $anc_add;
290  } else {
291  $href = "goto.php?target=st_" . $target_id;
292  }
293  $ltarget = "ilContObj" . $lm_id;
294  }
295  if ($lm_id == "") {
296  $href = "";
297  }
298  break;
299 
300  case "GlossaryItem":
301  $ltarget = $nframe = "_blank";
302  $href = "ilias.php?cmdClass=illmpresentationgui&amp;baseClass=ilLMPresentationGUI&amp;" .
303  "obj_type=$type&amp;cmd=glossary&amp;ref_id=" . $_GET["ref_id"] .
304  "&amp;obj_id=" . $target_id . "&amp;frame=$nframe";
305  break;
306 
307  case "MediaObject":
308  $ltarget = $nframe = "_blank";
309  $href = "ilias.php?cmdClass=illmpresentationgui&amp;baseClass=ilLMPresentationGUI&amp;obj_type=$type&amp;cmd=media&amp;ref_id=" . $_GET["ref_id"] .
310  "&amp;mob_id=" . $target_id . "&amp;frame=$nframe";
311  break;
312 
313  case "RepositoryItem":
314  $obj_type = ilObject::_lookupType($target_id, true);
316  $href = "./goto.php?target=" . $obj_type . "_" . $target_id;
317  $t_frame = ilFrameTargetInfo::_getFrame("MainContent", $obj_type);
318  $ltarget = $t_frame;
319  break;
320 
321  case "File":
322  $this->ctrl->setParameter($this, "file_id", "il__file_" . $target_id);
323  $href = $this->ctrl->getLinkTarget($this, "downloadFile");
324  $this->ctrl->setParameter($this, "file_id", "");
325  break;
326 
327  case "User":
328  $obj_type = ilObject::_lookupType($target_id);
329  if ($obj_type == "usr") {
330  include_once("./Services/User/classes/class.ilUserUtil.php");
331  $back = $this->ctrl->getLinkTarget($this, "edit");
332  //var_dump($back); exit;
333  $this->ctrl->setParameterByClass("ilpublicuserprofilegui", "user_id", $target_id);
334  $this->ctrl->setParameterByClass(
335  "ilpublicuserprofilegui",
336  "back_url",
337  rawurlencode($back)
338  );
339  $href = "";
340  include_once("./Services/User/classes/class.ilUserUtil.php");
342  $href = $this->ctrl->getLinkTargetByClass("ilpublicuserprofilegui", "getHTML");
343  }
344  $this->ctrl->setParameterByClass("ilpublicuserprofilegui", "user_id", "");
345  $lcontent = ilUserUtil::getNamePresentation($target_id, false, false);
346  }
347  break;
348 
349  }
350 
351  if ($href != "") {
352  $anc_par = 'Anchor="' . $anc . '"';
353  $link_info .= "<IntLinkInfo Target=\"$target\" Type=\"$type\" " .
354  "TargetFrame=\"$targetframe\" LinkHref=\"$href\" LinkTarget=\"$ltarget\" LinkContent=\"$lcontent\" $anc_par/>";
355  }
356  }
357  }
358  $link_info .= "</IntLinkInfos>";
359  //echo ":".htmlentities($link_info).":";
360  return $link_info;
361  }
362 
366  public function updateHistory()
367  {
368  require_once("./Services/History/classes/class.ilHistory.php");
370  $this->obj->getId(),
371  "update",
372  "",
373  $this->content_object->getType() . ":pg",
374  "",
375  true
376  );
377  }
378 
384  public static function _goto($a_target)
385  {
386  global $DIC;
387 
388  $rbacsystem = $DIC->rbac()->system();
389  $ilErr = $DIC["ilErr"];
390  $lng = $DIC->language();
391  $ilAccess = $DIC->access();
392 
393  $first = strpos($a_target, "_");
394  $second = strpos($a_target, "_", $first + 1);
395  $page_id = substr($a_target, 0, $first);
396  if ($first > 0) {
397  $page_id = substr($a_target, 0, $first);
398  if ($second > 0) {
399  $ref_id = substr($a_target, $first + 1, $second - ($first + 1));
400  $anchor = substr($a_target, $second + 1);
401  } else {
402  $ref_id = substr($a_target, $first + 1);
403  }
404  } else {
405  $page_id = $a_target;
406  }
407 
408  // determine learning object
409  $lm_id = ilLMObject::_lookupContObjID($page_id);
410 
411  // get all references
412  $ref_ids = ilObject::_getAllReferences($lm_id);
413 
414  // always try passed ref id first
415  if (in_array($ref_id, $ref_ids)) {
416  $ref_ids = array_merge(array($ref_id), $ref_ids);
417  }
418 
419  // check read permissions
420  foreach ($ref_ids as $ref_id) {
421  // check read permissions
422  if ($ilAccess->checkAccess("read", "", $ref_id)) {
423  // don't redirect anymore, just set parameters
424  // (goto.php includes "ilias.php")
425  $_GET["baseClass"] = "ilLMPresentationGUI";
426  $_GET["obj_id"] = $page_id;
427  $_GET["ref_id"] = $ref_id;
428  $_GET["anchor"] = $anchor;
429  include_once("ilias.php");
430  exit;
431  }
432  }
433 
434  if ($ilAccess->checkAccess("read", "", ROOT_FOLDER_ID)) {
435  if ($lm_id > 0) {
436  ilUtil::sendFailure(sprintf(
437  $lng->txt("msg_no_perm_read_item"),
438  ilObject::_lookupTitle($lm_id)
439  ), true);
440  } else {
441  $lng->loadLanguageModule("content");
442  ilUtil::sendFailure($lng->txt("page_does_not_exist"), true);
443  }
444  include_once("./Services/Object/classes/class.ilObjectGUI.php");
446  }
447 
448  $ilErr->raiseError($lng->txt("msg_no_perm_read_lm"), $ilErr->FATAL);
449  }
450 
454  public function editLayout()
455  {
456  $tpl = $this->tpl;
458  $ilTabs = $this->tabs;
459 
460  $page_gui = new ilLMPageGUI($this->obj->getId());
461  $page_gui->setEditPreview(true);
462  $page_gui->activateMetaDataEditor(
463  $this->content_object,
464  $this->obj->getType(),
465  $this->obj->getId(),
466  $this->obj,
467  "MDUpdateListener"
468  );
469  $page_gui->setActivationListener($this, "activatePage");
470  $page_gui->setTabHook($this, "addPageTabs");
471  $lm_set = new ilSetting("lm");
472  $tpl->setTitleIcon(ilUtil::getImagePath("icon_pg.svg"));
473  $tpl->setTitle($this->lng->txt("page") . ": " . $this->obj->getTitle());
474  $ilCtrl->getHTML($page_gui);
475  $ilTabs->setTabActive("cont_layout");
476  $this->initEditLayoutForm();
477  $tpl->setContent($this->form->getHTML());
478  }
479 
485  public function initEditLayoutForm()
486  {
487  $lng = $this->lng;
489 
490  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
491  $this->form = new ilPropertyFormGUI();
492 
493  // default layout
494  $layout = new ilRadioGroupInputGUI($lng->txt("cont_layout"), "layout");
495 
496  if (is_file($im = ilUtil::getImagePath("layout_" . $this->content_object->getLayout() . ".png"))) {
497  $im_tag = ilUtil::img($im, $this->content_object->getLayout());
498  }
499  $layout->addOption(new ilRadioOption("<table><tr><td>" . $im_tag . "</td><td><b>" .
500  $lng->txt("cont_lm_default_layout") .
501  "</b>: " . $lng->txt("cont_layout_" . $this->content_object->getLayout()) .
502  "</td></tr></table>", ""));
503 
505  $im_tag = "";
506  if (is_file($im = ilUtil::getImagePath("layout_" . $l . ".png"))) {
507  $im_tag = ilUtil::img($im, $l);
508  }
509  $layout->addOption(new ilRadioOption("<table><tr><td>" . $im_tag . "</td><td><b>" .
510  $lng->txt("cont_layout_" . $l) . "</b>: " . $lng->txt("cont_layout_" . $l . "_desc") .
511  "</td></tr></table>", $l));
512  }
513 
514  $layout->setValue($this->obj->getLayout());
515  $this->form->addItem($layout);
516 
517  $this->form->addCommandButton("saveLayout", $lng->txt("save"));
518 
519  $this->form->setTitle($lng->txt("cont_page_layout"));
520  $this->form->setFormAction($ilCtrl->getFormAction($this));
521  }
522 
527  public function saveLayout()
528  {
529  $tpl = $this->tpl;
530  $lng = $this->lng;
532 
533  $this->initEditLayoutForm();
534  if ($this->form->checkInput()) {
535  ilLMObject::writeLayout($this->obj->getId(), $this->form->getInput("layout"));
536  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
537  $ilCtrl->redirect($this, "editLayout");
538  }
539  $this->form->setValuesByPost();
540  $tpl->setContent($this->form->getHtml());
541  }
542 
546  public function addPageTabs()
547  {
548  $ilTabs = $this->tabs;
550 
551  $ilTabs->addTarget(
552  "cont_layout",
553  $ilCtrl->getLinkTarget($this, 'editLayout'),
554  "editLayout"
555  );
556  }
557 
561  public function downloadFile()
562  {
563  $pg_obj = $this->obj->getPageObject();
564  $pg_obj->buildDom();
565  $int_links = $pg_obj->getInternalLinks();
566  foreach ($int_links as $il) {
567  if ($il["Target"] == str_replace("_file_", "_dfile_", $_GET["file_id"])) {
568  $file = explode("_", $_GET["file_id"]);
569  $file_id = (int) $file[count($file) - 1];
570  require_once("./Modules/File/classes/class.ilObjFile.php");
571  $fileObj = new ilObjFile($file_id, false);
572  $fileObj->sendFile();
573  exit;
574  }
575  }
576  }
577 }
static _exists($a_parent_type, $a_id, $a_lang="", $a_no_cache=false)
Checks whether page exists.
This class represents an option in a radio group.
$target_arr
Definition: goto.php:47
settings()
Definition: settings.php:2
setEditPreview($a_editpreview)
Set Display first Edit tab, then Preview tab, instead of Page and Edit.
This class represents a property form user interface.
$type
global $DIC
Definition: saml.php:7
$_GET["client_id"]
checkTree()
check the content object tree
static getAvailableLayouts()
get all available lm layouts
static _gotoRepositoryRoot($a_raise_error=false)
Goto repository root.
$target_id
Definition: goto.php:49
static _lookupTitle($a_id)
lookup object title
static writeLayout($a_obj_id, $a_layout, $a_lm=null)
Write layout setting.
static _lookupContObjID($a_id)
get learning module / digibook id for lm object
static _createEntry( $a_obj_id, $a_action, $a_info_params="", $a_obj_type="", $a_user_comment="", $a_update_last=false)
Creates a new history entry for an object.
__construct(&$a_content_obj)
Constructor.
static _getAllReferences($a_id)
get all reference ids of object
Class ilLMObject.
$ilErr
Definition: raiseError.php:18
global $ilCtrl
Definition: ilias.php:18
static _goto($a_target)
redirect script
This class represents a property in a property form.
Class ilLMPageObject.
setLMPageObject($a_pg_obj)
Set content object dependent page object (co page)
save()
save co page object
static hasPublicProfile($a_user_id)
Has public profile.
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
static _lookupObjId($a_id)
Extension of ilPageObjectGUI for learning modules.
static getEffectiveContentStyleId($a_style_id, $a_type="")
Get effective Style Id.
addPageTabs()
Add page tabs.
editLayout()
Edit layout of page.
putInTree()
put this object into content object tree
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
static getNamePresentation( $a_user_id, $a_user_image=false, $a_profile_link=false, $a_profile_back_link="", $a_force_first_lastname=false, $a_omit_login=false, $a_sortable=true, $a_return_data_array=false, $a_ctrl_path="ilpublicuserprofilegui")
Default behaviour is:
static img($a_src, $a_alt=null, $a_width="", $a_height="", $a_border=0, $a_id="", $a_class="")
Build img tag.
static _lookupType($a_id, $a_reference=false)
lookup object type
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
Class ilLMPageObjectGUI.
exit
Definition: backend.php:16
static _getPresentationTitle( $a_pg_id, $a_mode=IL_CHAPTER_TITLE, $a_include_numbers=false, $a_time_scheduled_activation=false, $a_force_content=false, $a_lm_id=0, $a_lang="-", $a_include_short=false)
presentation title doesn&#39;t have to be page title, it may be chapter title + page title or chapter tit...
static _getFrame($a_class, $a_type='')
Get content frame name.
$lm_set
global $l
Definition: afr.php:30
global $ilSetting
Definition: privfeed.php:17
executeCommand()
execute command
initEditLayoutForm()
Init edit layout form.
getLinkXML($a_int_links)
get link targets
$ret
Definition: parser.php:6
downloadFile()
download file of file lists
updateHistory()
update history
static redirect($a_script)
$target
Definition: test.php:19
$_POST["username"]