ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5
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,
90  $this->obj->getType(), $this->obj->getId(),
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  case "File":
312  $this->ctrl->setParameter($this, "file_id", "il__file_".$target_id);
313  $href = $this->ctrl->getLinkTarget($this, "downloadFile");
314  $this->ctrl->setParameter($this, "file_id", "");
315  break;
316 
317  }
318 
319  $anc_par = 'Anchor="'.$anc.'"';
320 
321  $link_info.="<IntLinkInfo Target=\"$target\" Type=\"$type\" ".
322  "TargetFrame=\"$targetframe\" LinkHref=\"$href\" LinkTarget=\"$ltarget\" $anc_par/>";
323  }
324  }
325  $link_info.= "</IntLinkInfos>";
326 //echo ":".htmlentities($link_info).":";
327  return $link_info;
328  }
329 
333  function updateHistory()
334  {
335  require_once("./Services/History/classes/class.ilHistory.php");
336  ilHistory::_createEntry($this->obj->getId(), "update",
337  "", $this->content_object->getType().":pg",
338  "", true);
339  }
340 
346  public static function _goto($a_target)
347  {
348  global $rbacsystem, $ilErr, $lng, $ilAccess;
349 
350  $first = strpos($a_target, "_");
351  $second = strpos($a_target, "_", $first + 1);
352  $page_id = substr($a_target, 0, $first);
353  if ($first > 0)
354  {
355  $page_id = substr($a_target, 0, $first);
356  if ($second > 0)
357  {
358  $ref_id = substr($a_target, $first + 1, $second - ($first + 1));
359  $anchor = substr($a_target, $second + 1);
360  }
361  else
362  {
363  $ref_id = substr($a_target, $first + 1);
364  }
365  }
366  else
367  {
368  $page_id = $a_target;
369  }
370 
371  // determine learning object
372  $lm_id = ilLMObject::_lookupContObjID($page_id);
373 
374  // get all references
375  $ref_ids = ilObject::_getAllReferences($lm_id);
376 
377  // always try passed ref id first
378  if (in_array($ref_id, $ref_ids))
379  {
380  $ref_ids = array_merge(array($ref_id), $ref_ids);
381  }
382 
383  // check read permissions
384  foreach ($ref_ids as $ref_id)
385  {
386  // check read permissions
387  if ($ilAccess->checkAccess("read", "", $ref_id))
388  {
389  // don't redirect anymore, just set parameters
390  // (goto.php includes "ilias.php")
391  $_GET["baseClass"] = "ilLMPresentationGUI";
392  $_GET["obj_id"] = $page_id;
393  $_GET["ref_id"] = $ref_id;
394  $_GET["anchor"] = $anchor;
395  include_once("ilias.php");
396  exit;
397  }
398  }
399 
400  if ($ilAccess->checkAccess("read", "", ROOT_FOLDER_ID))
401  {
402  if ($lm_id > 0)
403  {
404  ilUtil::sendFailure(sprintf($lng->txt("msg_no_perm_read_item"),
405  ilObject::_lookupTitle($lm_id)), true);
406  }
407  else
408  {
409  $lng->loadLanguageModule("content");
410  ilUtil::sendFailure($lng->txt("page_does_not_exist"), true);
411  }
412  include_once("./Services/Object/classes/class.ilObjectGUI.php");
414  }
415 
416  $ilErr->raiseError($lng->txt("msg_no_perm_read_lm"), $ilErr->FATAL);
417  }
418 
422  function editLayout()
423  {
424  global $tpl, $ilCtrl, $ilTabs;
425 
426  $page_gui = new ilLMPageGUI($this->obj->getId());
427  $page_gui->setEditPreview(true);
428  $page_gui->activateMetaDataEditor($this->content_object,
429  $this->obj->getType(), $this->obj->getId(),
430  $this->obj, "MDUpdateListener");
431  $page_gui->setActivationListener($this, "activatePage");
432  $page_gui->setTabHook($this, "addPageTabs");
433  $lm_set = new ilSetting("lm");
434  $tpl->setTitleIcon(ilUtil::getImagePath("icon_pg.svg"));
435  $tpl->setTitle($this->lng->txt("page").": ".$this->obj->getTitle());
436  $ilCtrl->getHTML($page_gui);
437  $ilTabs->setTabActive("cont_layout");
438  $this->initEditLayoutForm();
439  $tpl->setContent($this->form->getHTML());
440  }
441 
447  public function initEditLayoutForm()
448  {
449  global $lng, $ilCtrl;
450 
451  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
452  $this->form = new ilPropertyFormGUI();
453 
454  // default layout
455  $layout = new ilRadioGroupInputGUI($lng->txt("cont_layout"), "layout");
456 
457  if (is_file($im = ilUtil::getImagePath("layout_".$this->content_object->getLayout().".png")))
458  {
459  $im_tag = ilUtil::img($im, $this->content_object->getLayout());
460  }
461  $layout->addOption(new ilRadioOption("<table><tr><td>".$im_tag."</td><td><b>".
462  $lng->txt("cont_lm_default_layout").
463  "</b>: ".$lng->txt("cont_layout_".$this->content_object->getLayout()).
464  "</td></tr></table>", ""));
465 
467  {
468  $im_tag = "";
469  if (is_file($im = ilUtil::getImagePath("layout_".$l.".png")))
470  {
471  $im_tag = ilUtil::img($im, $l);
472  }
473  $layout->addOption(new ilRadioOption("<table><tr><td>".$im_tag."</td><td><b>".
474  $lng->txt("cont_layout_".$l)."</b>: ".$lng->txt("cont_layout_".$l."_desc").
475  "</td></tr></table>", $l));
476  }
477 
478  $layout->setValue($this->obj->getLayout());
479  $this->form->addItem($layout);
480 
481  $this->form->addCommandButton("saveLayout", $lng->txt("save"));
482 
483  $this->form->setTitle($lng->txt("cont_page_layout"));
484  $this->form->setFormAction($ilCtrl->getFormAction($this));
485 
486  }
487 
492  public function saveLayout()
493  {
494  global $tpl, $lng, $ilCtrl;
495 
496  $this->initEditLayoutForm();
497  if ($this->form->checkInput())
498  {
499  ilLMObject::writeLayout($this->obj->getId(), $this->form->getInput("layout"));
500  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
501  $ilCtrl->redirect($this, "editLayout");
502  }
503  $this->form->setValuesByPost();
504  $tpl->setContent($this->form->getHtml());
505  }
506 
510  function addPageTabs()
511  {
512  global $ilTabs, $ilCtrl;
513 
514  $ilTabs->addTarget("cont_layout",
515  $ilCtrl->getLinkTarget($this, 'editLayout'), "editLayout");
516  }
517 
521  function downloadFile()
522  {
523  $pg_obj = $this->obj->getPageObject();
524  $pg_obj->buildDom();
525  $int_links = $pg_obj->getInternalLinks();
526  foreach ($int_links as $il)
527  {
528  if ($il["Target"] == str_replace("_file_", "_dfile_", $_GET["file_id"]))
529  {
530  $file = explode("_", $_GET["file_id"]);
531  $file_id = (int) $file[count($file) - 1];
532  require_once("./Modules/File/classes/class.ilObjFile.php");
533  $fileObj = new ilObjFile($file_id, false);
534  $fileObj->sendFile();
535  exit;
536  }
537  }
538  }
539 
540 }
541 ?>
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
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:86
ILIAS Setting Class.
print $file
exit
Definition: login.php:54
setEditPreview($a_editpreview)
Set Display first Edit tab, then Preview tab, instead of Page and Edit.
$_POST['username']
Definition: cron.php:12
This class represents a property form user interface.
$_GET["client_id"]
checkTree()
check the content object tree
$cmd
Definition: sahs_server.php:35
static _gotoRepositoryRoot($a_raise_error=false)
Goto repository root.
$target_id
Definition: goto.php:88
static _lookupTitle($a_id)
lookup object title
static writeLayout($a_obj_id, $a_layout, $a_lm=null)
Write layout setting.
getAvailableLayouts()
get all available lm layouts
static _getAllReferences($a_id)
get all reference ids of object
Class ilLMObject.
global $ilCtrl
Definition: ilias.php:18
static _goto($a_target)
redirect script
This class represents a property in a property form.
_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.
Class ilLMPageObject.
setLMPageObject($a_pg_obj)
Set content object dependent page object (co page)
save()
save co page object
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.
& executeCommand()
execute command
addPageTabs()
Add page tabs.
editLayout()
Edit layout of page.
Class ilObjFile.
_lookupContObjID($a_id)
get learning module / digibook id for lm object
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
ilLMPageObjectGUI(&$a_content_obj)
Constructor.
static _lookupType($a_id, $a_reference=false)
lookup object type
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
Class ilLMPageObjectGUI.
static img($a_src, $a_alt="", $a_width="", $a_height="", $a_border=0, $a_id="", $a_class="")
Build img tag.
static _getFrame($a_class, $a_type='')
Get content frame name.
$lm_set
global $l
Definition: afr.php:30
$ref_id
Definition: sahs_server.php:39
global $ilSetting
Definition: privfeed.php:40
initEditLayoutForm()
Init edit layout form.
getLinkXML($a_int_links)
get link targets
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="-")
presentation title doesn&#39;t have to be page title, it may be chapter title + page title or chapter tit...
downloadFile()
download file of file lists
updateHistory()
update history
static redirect($a_script)
http redirect to other script