ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilLMPageObjectGUI.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 require_once("./Modules/LearningModule/classes/class.ilLMObjectGUI.php");
25 require_once("./Modules/LearningModule/classes/class.ilLMPageObject.php");
26 require_once("./Services/COPage/classes/class.ilPageObjectGUI.php");
27 require_once ("./Modules/LearningModule/classes/class.ilInternalLinkGUI.php");
28 
42 {
43  var $obj;
44 
51  function ilLMPageObjectGUI(&$a_content_obj)
52  {
53  global $ilias, $tpl, $lng;
54 
55  parent::ilLMObjectGUI($a_content_obj);
56 
57  }
58 
59 
63  function setLMPageObject(&$a_pg_obj)
64  {
65  $this->obj =& $a_pg_obj;
66  $this->obj->setLMId($this->content_object->getId());
67  }
68 
72  function &executeCommand()
73  {
74  global $tpl, $ilCtrl;
75 
76  $next_class = $this->ctrl->getNextClass($this);
77  $cmd = $this->ctrl->getCmd();
78 
79 //echo "<br>:cmd:".$this->ctrl->getCmd().":cmdClass:".$this->ctrl->getCmdClass().":".
80 // ":nextClass:".$next_class.":"; flush();
81 
82  switch($next_class)
83  {
84  /*case 'ilmdeditorgui':
85 
86  $this->setTabs();
87  include_once 'Services/MetaData/classes/class.ilMDEditorGUI.php';
88 
89  $md_gui =& new ilMDEditorGUI($this->content_object->getID(),
90  $this->obj->getId(), $this->obj->getType());
91  $md_gui->addObserver($this->obj,'MDUpdateListener','General');
92 
93  $this->ctrl->forwardCommand($md_gui);
94  break;*/
95 
96  case "ilpageobjectgui":
97 
98  // Determine whether the view of a learning resource should
99  // be shown in the frameset of ilias, or in a separate window.
100  //$showViewInFrameset = $this->ilias->ini->readVariable("layout","view_target") == "frame";
101  $showViewInFrameset = true;
102 
103  $this->ctrl->setReturn($this, "edit");
104 /* $page_object =& $this->obj->getPageObject();
105  $page_object->buildDom();
106  $page_object->addUpdateListener($this, "updateHistory");
107  $int_links = $page_object->getInternalLinks();
108  $link_xml = $this->getLinkXML($int_links);
109 */
110 // $page_gui =& new ilPageObjectGUI($page_object);
111  $page_gui =& new ilPageObjectGUI($this->obj->content_object->getType(),
112  $this->obj->getId());
113  $page_gui->setEditPreview(true);
114  $page_gui->activateMetaDataEditor($this->content_object->getID(),
115  $this->obj->getId(), $this->obj->getType(),
116  $this->obj, "MDUpdateListener");
117 
118  // set page view link
119  if ($showViewInFrameset)
120  {
121  $view_frame = ilFrameTargetInfo::_getFrame("MainContent");
122  }
123  else
124  {
125  $view_frame = "ilContObj".$this->content_object->getID();
126  }
127  $page_gui->setViewPageLink(ILIAS_HTTP_PATH."/goto.php?target=pg_".$this->obj->getId().
128  "_".$_GET["ref_id"],
129  $view_frame);
130 
131  $page_gui->setIntLinkHelpDefault("StructureObject", $_GET["ref_id"]);
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(
144  ilLMPageObject::_getPresentationTitle($this->obj->getId(),
145  $this->content_object->getPageHeader(), $this->content_object->isActiveNumbering()));
146  $page_gui->setLocator($contObjLocator);
147  $page_gui->setHeader($this->lng->txt("page").": ".$this->obj->getTitle());
148  $page_gui->setEnabledActivation(true);
149  $page_gui->setActivationListener($this, "activatePage");
150  $page_gui->setActivated($this->obj->getActive());
151 
152  $up_gui = ($this->content_object->getType() == "dbk")
153  ? "ilobjdlbookgui"
154  : "ilobjlearningmodulegui";
155  $ilCtrl->setParameterByClass($up_gui, "active_node", $this->obj->getId());
156  $page_gui->setExplorerUpdater("tree", "tree_div",
157  $ilCtrl->getLinkTargetByClass($up_gui, "explorer", "", true));
158 
159  $tpl->setTitleIcon(ilUtil::getImagePath("icon_pg_b.gif"));
160  $tpl->setTitle($this->lng->txt("page").": ".$this->obj->getTitle());
161 
162  $ret = $this->ctrl->forwardCommand($page_gui);
163  //$ret =& $page_gui->executeCommand();
164  $tpl->setContent($ret);
165  break;
166 
167  default:
168  $ret =& $this->$cmd();
169  break;
170  }
171  }
172 
173 
174  /*
175  * display content of page (edit view)
176  */
177  function edit()
178  {
179 //echo "<br>umschuss";
180  $this->ctrl->setCmdClass("ilpageobjectgui");
181  $this->ctrl->setCmd("edit");
182  $this->executeCommand();
183  //$this->setTabs();
184  }
185 
186  /*
187  * display content of page (edit view)
188  */
189  function preview()
190  {
191  $this->ctrl->setCmdClass("ilpageobjectgui");
192  $this->ctrl->setCmd("preview");
193  $this->executeCommand();
194  $this->setTabs();
195  }
196 
200  function save()
201  {
202  $this->obj =& new ilLMPageObject($this->content_object);
203  $this->obj->setType("pg");
204  $this->obj->setTitle(ilUtil::stripSlashes($_POST["Fobject"]["title"]));
205  $this->obj->setDescription(ilUtil::stripSlashes($_POST["Fobject"]["desc"]));
206  $this->obj->setLMId($this->content_object->getId());
207  $this->obj->create();
208 
209  // obj_id is empty, if page is created from "all pages" screen
210  // -> a free page is created (not in the tree)
211 //echo "<br>savePage:".$_GET["obj_id"].":";
212  if ($_GET["obj_id"] != 0)
213  {
214  $this->putInTree();
215 
216  // check the tree
217  $this->checkTree();
218 
219  ilUtil::redirect($this->ctrl->getLinkTargetByClass("ilStructureObjectGUI",
220  "edit", "", true));
221  }
222  }
223 
227  function cancel()
228  {
229  ilUtil::sendInfo($this->lng->txt("msg_cancel"), true);
230  if ($_GET["obj_id"] != 0)
231  {
232  ilUtil::redirect($this->ctrl->getLinkTargetByClass("ilStructureObjectGUI",
233  "view", "", true));
234  }
235  //$this->ctrl->returnToParent($this);
236  }
237 
241  function getLinkXML($a_int_links)
242  {
243  if ($a_layoutframes == "")
244  {
245  $a_layoutframes = array();
246  }
247  $link_info = "<IntLinkInfos>";
248  foreach ($a_int_links as $int_link)
249  {
250  $target = $int_link["Target"];
251  if (substr($target, 0, 4) == "il__")
252  {
253  $target_arr = explode("_", $target);
254  $target_id = $target_arr[count($target_arr) - 1];
255  $type = $int_link["Type"];
256  $targetframe = ($int_link["TargetFrame"] != "")
257  ? $int_link["TargetFrame"]
258  : "None";
259 
260  switch($type)
261  {
262  case "PageObject":
263  case "StructureObject":
265  $cont_obj =& $this->content_object;
266  if ($lm_id == $cont_obj->getId())
267  {
268  $ltarget = "";
269  if ($type == "PageObject")
270  {
271  $this->ctrl->setParameter($this, "obj_id", $target_id);
272  $href = $this->ctrl->getLinkTargetByClass(get_class($this), "edit");
273  }
274  else
275  {
276  $this->ctrl->setParameterByClass("ilstructureobjectgui", "obj_id", $target_id);
277  $href = $this->ctrl->getLinkTargetByClass("ilstructureobjectgui", "view");
278  }
279  $href = str_replace("&", "&amp;", $href);
280  $this->ctrl->setParameter($this, "obj_id", $_GET["obj_id"]);
281  }
282  else
283  {
284  if ($type == "PageObject")
285  {
286  $href = "../goto.php?target=pg_".$target_id;
287  }
288  else
289  {
290  $href = "../goto.php?target=st_".$target_id;
291  }
292  $ltarget = "ilContObj".$lm_id;
293  }
294  break;
295 
296  case "GlossaryItem":
297  $ltarget = $nframe = "_blank";
298  $href = "ilias.php?cmdClass=illmpresentationgui&amp;baseClass=ilLMPresentationGUI&amp;".
299  "obj_type=$type&amp;cmd=glossary&amp;ref_id=".$_GET["ref_id"].
300  "&amp;obj_id=".$target_id."&amp;frame=$nframe";
301  break;
302 
303  case "MediaObject":
304  $ltarget = $nframe = "_blank";
305  $href = "ilias.php?cmdClass=illmpresentationgui&amp;baseClass=ilLMPresentationGUI&amp;obj_type=$type&amp;cmd=media&amp;ref_id=".$_GET["ref_id"].
306  "&amp;mob_id=".$target_id."&amp;frame=$nframe";
307  break;
308 
309  case "RepositoryItem":
310  $obj_type = ilObject::_lookupType($target_id, true);
312  $href = "./goto.php?target=".$obj_type."_".$target_id;
313  $t_frame = ilFrameTargetInfo::_getFrame("MainContent", $obj_type);
314  $ltarget = $t_frame;
315  break;
316  }
317  $link_info.="<IntLinkInfo Target=\"$target\" Type=\"$type\" ".
318  "TargetFrame=\"$targetframe\" LinkHref=\"$href\" LinkTarget=\"$ltarget\" />";
319  }
320  }
321  $link_info.= "</IntLinkInfos>";
322 //echo ":".htmlentities($link_info).":";
323  return $link_info;
324  }
325 
326 
332  function history()
333  {
334  $this->setTabs();
335 
336  require_once("classes/class.ilHistoryGUI.php");
337  $hist_gui =& new ilHistoryGUI($this->obj->getId() ,
338  $this->content_object->getType().":pg");
339  $hist_html = $hist_gui->getHistoryTable(
340  $this->ctrl->getParameterArray($this, "history"),
341  $this->content_object->isActiveHistoryUserComments()
342  );
343 
344  $this->tpl->setVariable("ADM_CONTENT", $hist_html);
345  }
346 
350  function updateHistory()
351  {
352  require_once("classes/class.ilHistory.php");
353  ilHistory::_createEntry($this->obj->getId(), "update",
354  "", $this->content_object->getType().":pg",
355  "", true);
356  }
357 
358 
362  function setTabs()
363  {
364  global $ilTabs;
365 //echo "setTabs";
366  // catch feedback message
367  #include_once("classes/class.ilTabsGUI.php");
368  #$tabs_gui =& new ilTabsGUI();
369  $this->getTabs($ilTabs);
370 
371  $this->tpl->setCurrentBlock("header_image");
372  $this->tpl->setVariable("IMG_HEADER", ilUtil::getImagePath("icon_pg_b.gif"));
373  $this->tpl->parseCurrentBlock();
374  $this->tpl->setCurrentBlock("content");
375 
376  #$this->tpl->setVariable("TABS", $tabs_gui->getHTML());
377  $this->tpl->setVariable("HEADER",
378  $this->lng->txt($this->obj->getType()).": ".$this->obj->getTitle());
379  }
380 
386  function getTabs(&$tabs_gui)
387  {
388  // back to upper context
389  $tabs_gui->addTarget("edit", $this->ctrl->getLinkTarget($this, "view")
390  , array("", "view"), "ilpageobjectgui");
391 
392  $tabs_gui->addTarget("cont_preview", $this->ctrl->getLinkTarget($this, "preview")
393  , "preview", "ilpageobjectgui");
394 
395  //$tabs_gui->addTarget("properties", $this->ctrl->getLinkTarget($this, "properties")
396  // , "properties", get_class($this));
397 
398  $tabs_gui->addTarget("meta_data",
399  $this->ctrl->getLinkTargetByClass('ilmdeditorgui',''),
400  "", "ilmdeditorgui");
401 
402  $tabs_gui->addTarget("history", $this->ctrl->getLinkTarget($this, "history")
403  , "history", get_class($this));
404 
405  $tabs = $this->ctrl->getTabs();
406  foreach ($tabs as $tab)
407  {
408  $tabs_gui->addTarget($tab["lang_var"], $tab["link"]
409  , $tab["cmd"], $tab["class"]);
410  }
411 
412  //$tabs_gui->addTarget("clipboard", $this->ctrl->getLinkTargetByClass("ilEditClipboardGUI", "view")
413  // , "view", "ilEditClipboardGUI");
414 
415  }
416 
422  function _goto($a_target, $a_target_ref_id = "")
423  {
424  global $rbacsystem, $ilErr, $lng, $ilAccess;
425 
426  // determine learning object
427  $lm_id = ilLMObject::_lookupContObjID($a_target);
428 
429  // get all references
430  $ref_ids = ilObject::_getAllReferences($lm_id);
431 
432  // always try passed ref id first
433  if (in_array($a_target_ref_id, $ref_ids))
434  {
435  $ref_ids = array_merge(array($a_target_ref_id), $ref_ids);
436  }
437 
438  // check read permissions
439  foreach ($ref_ids as $ref_id)
440  {
441  // check read permissions
442  if ($ilAccess->checkAccess("read", "", $ref_id))
443  {
444  // don't redirect anymore, just set parameters
445  // (goto.php includes "ilias.php")
446  $_GET["baseClass"] = "ilLMPresentationGUI";
447  $_GET["obj_id"] = $a_target;
448  $_GET["ref_id"] = $ref_id;
449  include_once("ilias.php");
450  exit;
451  }
452  }
453 
454  if ($ilAccess->checkAccess("read", "", ROOT_FOLDER_ID))
455  {
456  $_GET["cmd"] = "frameset";
457  $_GET["target"] = "";
458  $_GET["ref_id"] = ROOT_FOLDER_ID;
459  ilUtil::sendInfo(sprintf($lng->txt("msg_no_perm_read_item"),
460  ilObject::_lookupTitle($lm_id)), true);
461  include("repository.php");
462  exit;
463  }
464 
465  $ilErr->raiseError($lng->txt("msg_no_perm_read_lm"), $ilErr->FATAL);
466  }
467 
468 }
469 ?>