ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilStructureObjectGUI.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2011 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
5 
6 require_once("./Modules/LearningModule/classes/class.ilLMObjectGUI.php");
7 require_once("./Modules/LearningModule/classes/class.ilLMObject.php");
8 
22 {
23  var $obj; // structure object
24  var $tree;
25 
30  function ilStructureObjectGUI(&$a_content_obj, &$a_tree)
31  {
32  global $ilias, $tpl, $lng;
33 
34  parent::ilLMObjectGUI($a_content_obj);
35  $this->tree =& $a_tree;
36  }
37 
43  function setStructureObject(&$a_st_object)
44  {
45  $this->obj =& $a_st_object;
46  }
47 
48 
52  function getType()
53  {
54  return "st";
55  }
56 
60  function &executeCommand()
61  {
62 //echo "<br>:cmd:".$this->ctrl->getCmd().":cmdClass:".$this->ctrl->getCmdClass().":";
63  $next_class = $this->ctrl->getNextClass($this);
64  $cmd = $this->ctrl->getCmd();
65 
66  switch($next_class)
67  {
68  case 'ilmdeditorgui':
69 
70  $this->setTabs();
71  include_once 'Services/MetaData/classes/class.ilMDEditorGUI.php';
72 
73  $md_gui =& new ilMDEditorGUI($this->content_object->getID(),
74  $this->obj->getId(), $this->obj->getType());
75  $md_gui->addObserver($this->obj,'MDUpdateListener','General');
76 
77  $this->ctrl->forwardCommand($md_gui);
78  break;
79 
80  case "ilconditionhandlerinterface":
81  global $ilTabs;
82  include_once './Services/AccessControl/classes/class.ilConditionHandlerInterface.php';
83 
84  $this->setTabs();
86  $this->ctrl->forwardCommand($this->condHI);
87  $ilTabs->setTabActive('preconditions');
88  break;
89 
90  default:
91  if($cmd == 'listConditions')
92  {
93  $this->setTabs();
95  $ret =& $this->condHI->executeCommand();
96  }
97  elseif(($cmd == "create") && ($_POST["new_type"] == "pg"))
98  {
99  $this->setTabs();
100  $pg_gui =& new ilLMPageObjectGUI($this->content_object);
101  $ret =& $pg_gui->executeCommand();
102  }
103  else
104  {
105  $ret =& $this->$cmd();
106  }
107  break;
108  }
109  }
110 
111 
115  function create()
116  {
117  if ($_GET["obj_id"] != "")
118  {
119  $this->setTabs();
120  }
121  parent::create();
122  }
123 
124  function edit()
125  {
126  $this->view();
127  }
128 
129  /*
130  * display pages of structure object
131  */
132  function view()
133  {
134  global $tree, $ilUser, $ilCtrl, $lng;
135 
136  if ($ilUser->getPref("lm_js_chapter_editing") != "disable")
137  {
138  $this->showHierarchy();
139  }
140  else
141  {
142  $this->setTabs();
143 
144  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.structure_edit.html", "Modules/LearningModule");
145  $num = 0;
146 
147  $this->tpl->setCurrentBlock("form");
148  $this->ctrl->setParameter($this, "backcmd", "view");
149  $this->tpl->setVariable("FORMACTION",
150  $this->ctrl->getFormAction($this));
151  $this->tpl->setVariable("HEADER_TEXT", $this->lng->txt("cont_pages"));
152  $this->tpl->setVariable("CHECKBOX_TOP", IL_FIRST_NODE);
153 
154  $cnt = 0;
155  $childs = $this->tree->getChilds($this->obj->getId());
156  foreach ($childs as $child)
157  {
158  if($child["type"] != "pg")
159  {
160  continue;
161  }
162 
163  // check activation
164  include_once("./Services/COPage/classes/class.ilPageObject.php");
165  $active = ilPageObject::_lookupActive($child["obj_id"],
166  $this->content_object->getType());
167  if (!$active)
168  {
169  $this->tpl->setCurrentBlock("deactivated");
170  $this->tpl->setVariable("TXT_DEACTIVATED",
171  $this->lng->txt("cont_page_deactivated"));
172  $this->tpl->parseCurrentBlock();
173  }
174  else
175  {
177  $this->content_object->getType()))
178  {
179  $this->tpl->setCurrentBlock("deactivated");
180  $this->tpl->setVariable("TXT_DEACTIVATED",
181  $this->lng->txt("cont_page_deactivated_elements"));
182  $this->tpl->parseCurrentBlock();
183  }
184  }
185 
186  $this->tpl->setCurrentBlock("table_row");
187  // color changing
188  $css_row = ilUtil::switchColor($cnt++,"tblrow1","tblrow2");
189 
190  // checkbox
191  $this->tpl->setVariable("CHECKBOX_ID", $child["obj_id"]);
192  $this->tpl->setVariable("CSS_ROW", $css_row);
193  $this->tpl->setVariable("IMG_OBJ", ilUtil::getImagePath("icon_pg.png"));
194 
195  // link
196  $this->ctrl->setParameterByClass("ilLMPageObjectGUI", "obj_id", $child["obj_id"]);
197  $link = $this->ctrl->getLinkTargetByClass("ilLMPageObjectGUI", "edit", "");
198  $this->tpl->setVariable("LINK_TARGET", $link);
199 
200  // title
201  $this->tpl->setVariable("TEXT_CONTENT", $child["title"]);
202 
203  $this->tpl->parseCurrentBlock();
204  }
205  if($cnt == 0)
206  {
207  $this->tpl->setCurrentBlock("notfound");
208  $this->tpl->setVariable("NUM_COLS", 3);
209  $this->tpl->setVariable("TXT_OBJECT_NOT_FOUND", $this->lng->txt("obj_not_found"));
210  $this->tpl->parseCurrentBlock();
211  }
212  //else
213  //{
214  // SHOW VALID ACTIONS
215  $this->tpl->setVariable("NUM_COLS", 3);
216  //$this->setActions(array("confirmTermDeletion" => "delete", "addDefinition" => "cont_add_definition"));
217  $acts = array("delete" => "delete", "cutPage" => "cutPage",
218  "copyPage" => "copyPage", "activatePages" => "cont_de_activate");
219  //echo ":".$this->checkClipboardContentType().":<br>";
220  if ($ilUser->clipboardHasObjectsOfType("pg"))
221  {
222  $acts["pastePage"] = "pastePage";
223  }
224  $this->showActions($acts);
225  //}
226 
227  // SHOW POSSIBLE SUB OBJECTS
228  $this->tpl->setVariable("NUM_COLS", 3);
229  //$this->showPossibleSubObjects("st");
230  $subobj = array("pg");
231  $opts = ilUtil::formSelect(12,"new_type",$subobj);
232  //$this->tpl->setVariable("IMG_ARROW", ilUtil::getImagePath("arrow_downright.png"));
233  $this->tpl->setCurrentBlock("add_object");
234  $this->tpl->setVariable("SELECT_OBJTYPE", $opts);
235  //$this->tpl->setVariable("FORMACTION_OBJ_ADD", "adm_object.php?cmd=create&ref_id=".$_GET["ref_id"]);
236  $this->tpl->setVariable("BTN_NAME", "create");
237  $this->tpl->setVariable("TXT_ADD", $this->lng->txt("insert"));
238  $this->tpl->parseCurrentBlock();
239 
240  $this->tpl->setCurrentBlock("form");
241  $this->tpl->parseCurrentBlock();
242 
243  $ilCtrl->setParameter($this, "obj_id", $_GET["obj_id"]);
244  $this->tpl->setVariable("HREF_JS_EDIT",
245  $ilCtrl->getLinkTarget($this, "activateJSChapterEditing"));
246  $this->tpl->setVariable("TXT_JS_EDIT",
247  $lng->txt("cont_js_chap_editing"));
248  }
249  }
250 
251 
255  function showHierarchy()
256  {
257  global $lng, $ilCtrl;
258 
259  $this->setTabs();
260 
261  $ilCtrl->setParameter($this, "backcmd", "showHierarchy");
262 
263  include_once("./Modules/LearningModule/classes/class.ilChapterHierarchyFormGUI.php");
264  $form_gui = new ilChapterHierarchyFormGUI($this->content_object->getType());
265  $form_gui->setFormAction($ilCtrl->getFormAction($this));
266  $form_gui->setTitle($this->obj->getTitle());
267  $form_gui->setIcon(ilUtil::getImagePath("icon_st.png"));
268  $form_gui->setTree($this->tree);
269  $form_gui->setCurrentTopNodeId($this->obj->getId());
270  $form_gui->addMultiCommand($lng->txt("delete"), "delete");
271  $form_gui->addMultiCommand($lng->txt("cut"), "cutItems");
272  $form_gui->addMultiCommand($lng->txt("copy"), "copyItems");
273  $form_gui->addMultiCommand($lng->txt("cont_de_activate"), "activatePages");
274  if ($this->content_object->getLayoutPerPage())
275  {
276  $form_gui->addMultiCommand($lng->txt("cont_set_layout"), "setPageLayout");
277  }
278  $form_gui->setDragIcon(ilUtil::getImagePath("icon_pg_s.png"));
279  $form_gui->addCommand($lng->txt("cont_save_all_titles"), "saveAllTitles");
280  $form_gui->addHelpItem($lng->txt("cont_chapters_after_pages"));
281  $up_gui = ($this->content_object->getType() == "dbk")
282  ? "ilobjdlbookgui"
283  : "ilobjlearningmodulegui";
284  $ilCtrl->setParameterByClass($up_gui, "active_node", $this->obj->getId());
285  $form_gui->setExplorerUpdater("tree", "tree_div",
286  $ilCtrl->getLinkTargetByClass($up_gui, "explorer", "", true));
287  $ilCtrl->setParameterByClass($up_gui, "active_node", "");
288 
289  $ctpl = new ilTemplate("tpl.chap_and_pages.html", true, true, "Modules/LearningModule");
290  $ctpl->setVariable("HIERARCHY_FORM", $form_gui->getHTML());
291  $ilCtrl->setParameter($this, "obj_id", $_GET["obj_id"]);
292  $ctpl->setVariable("HREF_NO_JS_EDIT",
293  $ilCtrl->getLinkTarget($this, "deactivateJSChapterEditing"));
294  $ctpl->setVariable("TXT_NO_JS_EDIT",
295  $lng->txt("cont_not_js_chap_editing"));
296 
297  $this->tpl->setContent($ctpl->get());
298  }
299 
304  {
305  global $ilCtrl, $ilUser;
306 
307  $ilUser->writePref("lm_js_chapter_editing", "disable");
308  $ilCtrl->redirect($this, "view");
309  }
310 
315  {
316  global $ilCtrl, $ilUser;
317 
318  $ilUser->writePref("lm_js_chapter_editing", "enable");
319  $ilCtrl->redirect($this, "view");
320  }
321 
325  function cutItems($a_return = "view")
326  {
327  global $ilCtrl, $lng;
328 
329  $items = ilUtil::stripSlashesArray($_POST["id"]);
330  if (!is_array($items))
331  {
332  ilUtil::sendFailure($lng->txt("no_checkbox"), true);
333  $ilCtrl->redirect($this, "showHierarchy");
334  }
335 
336  $todel = array(); // delete IDs < 0 (needed for non-js editing)
337  foreach($items as $k => $item)
338  {
339  if ($item < 0)
340  {
341  $todel[] = $k;
342  }
343  }
344  foreach($todel as $k)
345  {
346  unset($items[$k]);
347  }
348 
349  if (!ilLMObject::uniqueTypesCheck($items))
350  {
351  ilUtil::sendFailure($lng->txt("cont_choose_pages_or_chapters_only"), true);
352  $ilCtrl->redirect($this, "showHierarchy");
353  }
354 
355  ilLMObject::clipboardCut($this->content_object->getId(), $items);
357  //ilUtil::sendInfo($this->lng->txt("msg_cut_clipboard"), true);
358  ilUtil::sendInfo($lng->txt("cont_selected_items_have_been_cut"), true);
359 
360  $ilCtrl->redirect($this, $a_return);
361  }
362 
366  function copyItems($a_return = "view")
367  {
368  global $ilCtrl, $lng;
369 
370  $items = ilUtil::stripSlashesArray($_POST["id"]);
371  if (!is_array($items))
372  {
373  ilUtil::sendFailure($lng->txt("no_checkbox"), true);
374  $ilCtrl->redirect($this, "showHierarchy");
375  }
376 
377  $todel = array(); // delete IDs < 0 (needed for non-js editing)
378  foreach($items as $k => $item)
379  {
380  if ($item < 0)
381  {
382  $todel[] = $k;
383  }
384  }
385  foreach($todel as $k)
386  {
387  unset($items[$k]);
388  }
389 
390  if (!ilLMObject::uniqueTypesCheck($items))
391  {
392  ilUtil::sendFailure($lng->txt("cont_choose_pages_or_chapters_only"), true);
393  $ilCtrl->redirect($this, "showHierarchy");
394  }
395 
396  ilLMObject::clipboardCopy($this->content_object->getId(), $items);
398 
399  ilUtil::sendInfo($lng->txt("cont_selected_items_have_been_copied"), true);
400  $ilCtrl->redirect($this, $a_return);
401  }
402 
406  function saveAllTitles()
407  {
408  global $ilCtrl;
409 
410  ilLMObject::saveTitles($this->content_object, ilUtil::stripSlashesArray($_POST["title"]));
411 
412  $ilCtrl->redirect($this, "showHierarchy");
413  }
414 
415  /*
416  * display subchapters of structure object
417  */
418  function subchap()
419  {
420  global $tree, $ilCtrl, $lng, $ilUser;
421 
422  $this->setTabs();
423 
424  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.structure_edit.html", "Modules/LearningModule");
425  $num = 0;
426 
427  $this->tpl->setCurrentBlock("form");
428  $this->ctrl->setParameter($this, "backcmd", "subchap");
429  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
430  $this->tpl->setVariable("HEADER_TEXT", $this->lng->txt("cont_subchapters"));
431  $this->tpl->setVariable("CHECKBOX_TOP", IL_FIRST_NODE);
432 
433  $cnt = 0;
434  $childs = $this->tree->getChilds($this->obj->getId());
435  foreach ($childs as $child)
436  {
437  if($child["type"] != "st")
438  {
439  continue;
440  }
441  $this->tpl->setCurrentBlock("table_row");
442  // color changing
443  $css_row = ilUtil::switchColor($cnt++,"tblrow1","tblrow2");
444 
445  // checkbox
446  $this->tpl->setVariable("CHECKBOX_ID", $child["obj_id"]);
447  $this->tpl->setVariable("CSS_ROW", $css_row);
448  $this->tpl->setVariable("IMG_OBJ", ilUtil::getImagePath("icon_st.png"));
449 
450  // type
451  $this->ctrl->setParameterByClass("ilStructureObjectGUI", "obj_id", $child["obj_id"]);
452  $link = $this->ctrl->getLinkTargetByClass("ilStructureObjectGUI", "view");
453  $this->tpl->setVariable("LINK_TARGET", $link);
454 
455  // title
456  $this->tpl->setVariable("TEXT_CONTENT",
458  $this->content_object->isActiveNumbering()));
459 
460  $this->tpl->parseCurrentBlock();
461  }
462  if($cnt == 0)
463  {
464  $this->tpl->setCurrentBlock("notfound");
465  $this->tpl->setVariable("NUM_COLS", 3);
466  $this->tpl->setVariable("TXT_OBJECT_NOT_FOUND", $this->lng->txt("obj_not_found"));
467  $this->tpl->parseCurrentBlock();
468  }
469  //else
470  //{
471  // SHOW VALID ACTIONS
472  $this->tpl->setVariable("NUM_COLS", 3);
473  $acts = array("delete" => "delete", "cutChapter" => "cut",
474  "copyChapter" => "copyChapter");
475  if ($ilUser->clipboardHasObjectsOfType("st"))
476  {
477  $acts["pasteChapter"] = "pasteChapter";
478  }
479  $this->showActions($acts);
480  //}
481 
482  // SHOW POSSIBLE SUB OBJECTS
483  $this->tpl->setVariable("NUM_COLS", 3);
484  //$this->showPossibleSubObjects("st");
485  $subobj = array("st");
486  $opts = ilUtil::formSelect(12,"new_type",$subobj);
487  //$this->tpl->setVariable("IMG_ARROW", ilUtil::getImagePath("arrow_downright.png"));
488  $this->tpl->setCurrentBlock("add_object");
489  $this->tpl->setVariable("SELECT_OBJTYPE", $opts);
490  //$this->tpl->setVariable("FORMACTION_OBJ_ADD", "adm_object.php?cmd=create&ref_id=".$_GET["ref_id"]);
491  $this->tpl->setVariable("BTN_NAME", "create");
492  $this->tpl->setVariable("TXT_ADD", $this->lng->txt("insert"));
493  $this->tpl->parseCurrentBlock();
494 
495  //$this->tpl->setVariable("NUM_COLS", 2);
496  //$this->showPossibleSubObjects("st");
497 
498  $this->tpl->setCurrentBlock("form");
499  $this->tpl->parseCurrentBlock();
500 
501  $ilCtrl->setParameter($this, "obj_id", $_GET["obj_id"]);
502  $this->tpl->setVariable("HREF_JS_EDIT",
503  $ilCtrl->getLinkTarget($this, "activateJSChapterEditing"));
504  $this->tpl->setVariable("TXT_JS_EDIT",
505  $lng->txt("cont_js_chap_editing"));
506 
507  }
508 
512  function add_cell($val, $link = "")
513  {
514  if(!empty($link))
515  {
516  $this->tpl->setCurrentBlock("begin_link");
517  $this->tpl->setVariable("LINK_TARGET", $link);
518  $this->tpl->parseCurrentBlock();
519  $this->tpl->touchBlock("end_link");
520  }
521 
522  $this->tpl->setCurrentBlock("text");
523  $this->tpl->setVariable("TEXT_CONTENT", $val);
524  $this->tpl->parseCurrentBlock();
525  $this->tpl->setCurrentBlock("table_cell");
526  $this->tpl->parseCurrentBlock();
527  }
528 
529 
533  function save()
534  {
535 
536  $this->obj =& new ilStructureObject($this->content_object);
537 
538  $this->obj->setType("st");
539  $this->obj->setTitle(ilUtil::stripSlashes($_POST["Fobject"]["title"]));
540  $this->obj->setDescription(ilUtil::stripSlashes($_POST["Fobject"]["desc"]));
541  $this->obj->setLMId($this->content_object->getId());
542  $this->obj->create();
543 
544  $this->putInTree();
545 
546  // check the tree
547  $this->checkTree();
548 
549  if (!empty($_GET["obj_id"]))
550  {
551  $this->ctrl->redirect($this, "subchap");
552  }
553 
554  }
555 
559  function putInTree()
560  {
561 //echo "st:putInTree";
562  // chapters should be behind pages in the tree
563  // so if target is first node, the target is substituted with
564  // the last child of type pg
565  if ($_GET["target"] == IL_FIRST_NODE)
566  {
567  $tree = new ilTree($this->content_object->getId());
568  $tree->setTableNames('lm_tree','lm_data');
569  $tree->setTreeTablePK("lm_id");
570 
571  // determine parent node id
572  $parent_id = (!empty($_GET["obj_id"]))
573  ? $_GET["obj_id"]
574  : $tree->getRootId();
575  // determine last child of type pg
576  $childs =& $tree->getChildsByType($parent_id, "pg");
577  if (count($childs) != 0)
578  {
579  $_GET["target"] = $childs[count($childs) - 1]["obj_id"];
580  }
581  }
582  if (empty($_GET["target"]))
583  {
584  $_GET["target"] = IL_LAST_NODE;
585  }
586 
588  }
589 
593  function cutPage()
594  {
595  $this->cutItems();
596 
597  return;
598  if(!isset($_POST["id"]))
599  {
600  $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
601 
602  }
603  if(count($_POST["id"]) > 1)
604  {
605  $this->ilias->raiseError($this->lng->txt("cont_select_max_one_item"),$this->ilias->error_obj->MESSAGE);
606  }
607 
608  if(count($_POST["id"]) == 1 && $_POST["id"][0] == IL_FIRST_NODE)
609  {
610  $this->ilias->raiseError($this->lng->txt("cont_select_item"), $this->ilias->error_obj->MESSAGE);
611  }
612 
613  // SAVE POST VALUES
615 
616  $tree = new ilTree($this->content_object->getId());
617  $tree->setTableNames('lm_tree','lm_data');
618  $tree->setTreeTablePK("lm_id");
619 
620  // cut selected object
621  $cutted = 0;
622  foreach ($_POST["id"] as $id)
623  {
624  if ($id == -1)
625  {
626  continue;
627  }
628 
629  $obj =& ilLMObjectFactory::getInstance($this->content_object, $id);
630  $obj->setLMId($this->content_object->getId());
631  $node_data = $tree->getNodeData($id);
632  //$obj->delete();
633  if($tree->isInTree($id))
634  {
635  $parent_id = $tree->getParentId($id);
636  $tree->deleteTree($node_data);
637 
638  // write history entry
639  require_once("./Services/History/classes/class.ilHistory.php");
640  ilHistory::_createEntry($id, "cut",
641  array(ilLMObject::_lookupTitle($parent_id), $parent_id),
642  $this->content_object->getType().":pg");
643  ilHistory::_createEntry($parent_id, "cut_page",
644  array(ilLMObject::_lookupTitle($id), $id),
645  $this->content_object->getType().":st");
646  }
647  $cutted++;
648  }
649 
650  // tree check
651  $this->checkTree();
652 
653  if($cutted > 0)
654  {
655  ilUtil::sendInfo($this->lng->txt("msg_cut_clipboard"), true);
656  }
657 
658  $this->ctrl->redirect($this, "view");
659  }
660 
664  function copyPage()
665  {
666  $this->copyItems();
667  }
668 
672  function pastePage()
673  {
674  global $ilUser;
675 
676  if (!$ilUser->clipboardHasObjectsOfType("pg"))
677  {
678  $this->ilias->raiseError($this->lng->txt("no_page_in_clipboard"),$this->ilias->error_obj->MESSAGE);
679  }
680 
681  return $this->insertPageClip();
682  return;
683  $tree = new ilTree($this->content_object->getId());
684  $tree->setTableNames('lm_tree','lm_data');
685  $tree->setTreeTablePK("lm_id");
686 
687  // paste selected object
689 
690  // copy page, if action is copy
691  if (ilEditClipboard::getAction() == "copy")
692  {
693  // check wether page belongs to lm
695  == $this->content_object->getID())
696  {
697  $lm_page = new ilLMPageObject($this->content_object, $id);
698  $new_page =& $lm_page->copy();
699  $id = $new_page->getId();
700  }
701  else
702  {
703  // get page from other content object into current content object
705  $lm_obj =& $this->ilias->obj_factory->getInstanceByObjId($lm_id);
706  $lm_page = new ilLMPageObject($lm_obj, $id);
707  $copied_nodes = array();
708  $new_page =& $lm_page->copyToOtherContObject($this->content_object, $copied_nodes);
709  $id = $new_page->getId();
710  ilLMObject::updateInternalLinks($copied_nodes);
711  }
712  }
713 
714  if (ilEditClipboard::getAction() == "cut")
715  {
716  // check wether page belongs not to lm
718  != $this->content_object->getID())
719  {
721  $lm_obj =& $this->ilias->obj_factory->getInstanceByObjId($lm_id);
722  $lm_page = new ilLMPageObject($lm_obj, $id);
723  $lm_page->setLMId($this->content_object->getID());
724  $lm_page->update();
725  $page =& $lm_page->getPageObject();
726  $page->buildDom();
727  $page->setParentId($this->content_object->getID());
728  $page->update();
729  }
730  }
731 
732  if(!$tree->isInTree($id))
733  {
734  if(!isset($_POST["id"]))
735  {
736  $target = IL_FIRST_NODE;
737  }
738  else
739  {
740  $target = $_POST["id"][0];
741  }
742  $tree->insertNode($id, $this->obj->getId(), $target);
744  }
745 
746  // write history comments
747  include_once("./Services/History/classes/class.ilHistory.php");
748  $parent_id = $tree->getParentId($id);
749  ilHistory::_createEntry($id, "paste",
750  array(ilLMObject::_lookupTitle($this->obj->getId()), $this->obj->getId()),
751  $this->content_object->getType().":pg");
752  ilHistory::_createEntry($parent_id, "paste_page",
753  array(ilLMObject::_lookupTitle($id), $id),
754  $this->content_object->getType().":st");
755 
756  // check the tree
757  $this->checkTree();
758 
759  $this->ctrl->redirect($this, "view");
760  }
761 
762 
766  function cutChapter()
767  {
768  $this->cutItems("subchap");
769 
770  return;
771 
772  $cont_obj_gui =& new ilObjContentObjectGUI("",$this->content_object->getRefId(),
773  true, false);
774  $cont_obj_gui->moveChapter($this->obj->getId());
775 
776  $this->ctrl->redirect($this, "subchap");
777  }
778 
782  function copyChapter()
783  {
784  $this->copyItems("subchap");
785  return;
786 
787  $cont_obj_gui =& new ilObjContentObjectGUI("",$this->content_object->getRefId(),
788  true, false);
789  $cont_obj_gui->copyChapter($this->obj->getId());
790 
791  $this->ctrl->redirect($this, "subchap");
792  }
793 
797  function pasteChapter()
798  {
799  global $ilUser;
800 
801  return $this->insertChapterClip(false, "subchap");
802  return;
803 
805  if($id == $_POST["id"][0])
806  {
808  $this->subchap();
809  return;
810  }
811  $cont_obj_gui =& new ilObjContentObjectGUI("",$this->content_object->getRefId(),
812  true, false);
813  $cont_obj_gui->pasteChapter($this->obj->getId());
814 
815  $this->ctrl->redirect($this, "subchap");
816  }
817 
821  function activatePages()
822  {
823  global $lng;
824 
825  include_once("./Services/COPage/classes/class.ilPageObject.php");
826  if (is_array($_POST["id"]))
827  {
828  $act_items = array();
829  // get all "top" ids, i.e. remove ids, that have a selected parent
830  foreach($_POST["id"] as $id)
831  {
832  $path = $this->tree->getPathId($id);
833  $take = true;
834  foreach($path as $path_id)
835  {
836  if ($path_id != $id && in_array($path_id, $_POST["id"]))
837  {
838  $take = false;
839  }
840  }
841  if ($take)
842  {
843  $act_items[] = $id;
844  }
845  }
846 
847 
848  foreach($act_items as $id)
849  {
850  $childs = $this->tree->getChilds($id);
851  foreach($childs as $child)
852  {
853  if (ilLMObject::_lookupType($child["child"]) == "pg")
854  {
855  $act = ilPageObject::_lookupActive($child["child"],
856  $this->content_object->getType());
857  ilPageObject::_writeActive($child["child"],
858  $this->content_object->getType(), !$act);
859  }
860  }
861  if (ilLMObject::_lookupType($id) == "pg")
862  {
863  $act = ilPageObject::_lookupActive($id,
864  $this->content_object->getType());
866  $this->content_object->getType(), !$act);
867  }
868  }
869  }
870  else
871  {
872  ilUtil::sendFailure($lng->txt("no_checkbox"), true);
873  }
874 
875  $this->ctrl->redirect($this, "view");
876  }
877 
878  //
879  // Condition handling stuff
880  //
881 
883  {
884  include_once("./Services/AccessControl/classes/class.ilConditionHandlerInterface.php");
885 
886  $this->condHI =& new ilConditionHandlerInterface($this);
887  $this->condHI->setBackButtons(array());
888  $this->condHI->setAutomaticValidation(false);
889  $this->condHI->setTargetType("st");
890  $this->condHI->setTargetRefId($this->content_object->getRefId());
891  $this->condHI->setTargetId($this->obj->getId());
892  $this->condHI->setTargetTitle($this->obj->getTitle());
893  }
894 
895 
899  function cancel()
900  {
901  if ($_GET["obj_id"] != 0)
902  {
903  if ($_GET["new_type"] == "pg")
904  {
905  $this->ctrl->redirect($this, "view");
906  }
907  else
908  {
909  $this->ctrl->redirect($this, "subchap");
910  }
911  }
912  }
913 
914 
918  function setTabs()
919  {
920  global $ilTabs, $ilUser, $lng;
921 
922  if ($ilUser->getPref("lm_js_chapter_editing") == "disable")
923  {
924  // pages
925  $ilTabs->addTarget("cont_pages",
926  $this->ctrl->getLinkTarget($this,'view'),
927  "view", get_class($this));
928 
929  // subchapters
930  $ilTabs->addTarget("cont_subchapters",
931  $this->ctrl->getLinkTarget($this,'subchap'),
932  "subchap", get_class($this));
933  }
934  else
935  {
936  // subelements
937  $ilTabs->addTarget("cont_pages_and_subchapters",
938  $this->ctrl->getLinkTarget($this,'showHierarchy'),
939  array("view", "showHierarchy"), get_class($this));
940  }
941 
942  // preconditions
943  $ilTabs->addTarget("preconditions",
944  $this->ctrl->getLinkTarget($this, 'listConditions'),
945  "listConditions", get_class($this));
946 
947  // metadata
948  $ilTabs->addTarget("meta_data",
949  $this->ctrl->getLinkTargetByClass("ilmdeditorgui",''),
950  "", "ilmdeditorgui");
951 
952  $this->tpl->setTitleIcon(ilUtil::getImagePath("icon_st_b.png"));
953  $this->tpl->setTitle(
954  $this->lng->txt($this->obj->getType()).": ".$this->obj->getTitle());
955 
956  // presentation view
957  $ilTabs->addNonTabbedLink("pres_mode", $lng->txt("cont_presentation_view"),
958  ILIAS_HTTP_PATH."/goto.php?target=st_".$this->obj->getId(), "_top");
959  }
960 
966  function _goto($a_target, $a_target_ref_id = "")
967  {
968  global $rbacsystem, $ilErr, $lng, $ilAccess;
969 
970  // determine learning object
971  $lm_id = ilLMObject::_lookupContObjID($a_target);
972 
973  // get all references
974  $ref_ids = ilObject::_getAllReferences($lm_id);
975 
976  // always try passed ref id first
977  if (in_array($a_target_ref_id, $ref_ids))
978  {
979  $ref_ids = array_merge(array($a_target_ref_id), $ref_ids);
980  }
981 
982  // check read permissions
983  foreach ($ref_ids as $ref_id)
984  {
985  // Permission check
986  if ($ilAccess->checkAccess("read", "", $ref_id))
987  {
988  // don't redirect anymore, just set parameters
989  // (goto.php includes "ilias.php")
990  $_GET["baseClass"] = "ilLMPresentationGUI";
991  $_GET["obj_id"] = $a_target;
992  $_GET["ref_id"] = $ref_id;
993  include_once("ilias.php");
994  exit;;
995  }
996  }
997 
998  if ($ilAccess->checkAccess("read", "", ROOT_FOLDER_ID))
999  {
1000  ilUtil::sendFailure(sprintf($lng->txt("msg_no_perm_read_item"),
1001  ilObject::_lookupTitle($lm_id)), true);
1002  include_once("./Services/Object/classes/class.ilObjectGUI.php");
1004  }
1005 
1006  $ilErr->raiseError($lng->txt("msg_no_perm_read_lm"), $ilErr->FATAL);
1007  }
1008 
1012  function insertChapter($a_as_sub = false)
1013  {
1014  global $ilCtrl, $lng;
1015 
1016  include_once("./Modules/LearningModule/classes/class.ilChapterHierarchyFormGUI.php");
1017 
1020 
1021  if ($a_as_sub) // as subchapter
1022  {
1023  if (!ilChapterHierarchyFormGUI::getPostFirstChild()) // insert under parent
1024  {
1025  $parent_id = $node_id;
1026  $target = "";
1027  }
1028  else // we shouldnt end up here
1029  {
1030  $ilCtrl->redirect($this, "showHierarchy");
1031  return;
1032  }
1033  }
1034  else // as chapter
1035  {
1036  if (!ilChapterHierarchyFormGUI::getPostFirstChild()) // insert after node id
1037  {
1038  $parent_id = $this->tree->getParentId($node_id);
1039  $target = $node_id;
1040  }
1041  else // insert as first child
1042  {
1043  $parent_id = $node_id;
1044  $target = IL_FIRST_NODE;
1045  }
1046  }
1047  for ($i = 1; $i <= $num; $i++)
1048  {
1049  $chap = new ilStructureObject($this->content_object);
1050  $chap->setType("st");
1051  $chap->setTitle($lng->txt("cont_new_chap"));
1052  $chap->setLMId($this->content_object->getId());
1053  $chap->create();
1054  ilLMObject::putInTree($chap, $parent_id, $target);
1055  }
1056 
1057  $ilCtrl->redirect($this, "view");
1058  }
1059 
1063  function insertSubchapter()
1064  {
1065  global $ilCtrl;
1066 
1067  $this->insertChapter(true);
1068  }
1069 
1073  function insertChapterClip($a_as_sub = false, $a_return = "view")
1074  {
1075  global $ilUser, $ilCtrl, $ilLog;
1076 
1077  $ilLog->write("Insert Chapter From Clipboard");
1078 
1079  include_once("./Modules/LearningModule/classes/class.ilChapterHierarchyFormGUI.php");
1080 
1081  if ($ilUser->getPref("lm_js_chapter_editing") != "disable")
1082  {
1083  //$num = ilChapterHierarchyFormGUI::getPostMulti();
1086  }
1087  else
1088  {
1089  if (!isset($_POST["id"]) || $_POST["id"][0] == -1)
1090  {
1091  $node_id = $this->obj->getId();
1092  $first_child = true;
1093  }
1094  else
1095  {
1096  $node_id = $_POST["id"][0];
1097  $first_child = false;
1098  }
1099  }
1100 
1101  if ($a_as_sub) // as subchapter
1102  {
1103  if (!$first_child) // insert under parent
1104  {
1105  $parent_id = $node_id;
1106  $target = "";
1107  }
1108  else // we shouldnt end up here
1109  {
1110  $ilCtrl->redirect($this, "showHierarchy");
1111  return;
1112  }
1113  }
1114  else // as chapter
1115  {
1116  if (!$first_child) // insert after node id
1117  {
1118  $parent_id = $this->tree->getParentId($node_id);
1119  $target = $node_id;
1120  }
1121  else // insert as first child
1122  {
1123  $parent_id = $node_id;
1124  $target = IL_FIRST_NODE;
1125 
1126  // do not move a chapter in front of a page
1127  $childs = $this->tree->getChildsByType($parent_id, "pg");
1128  if (count($childs) != 0)
1129  {
1130  $target = $childs[count($childs) - 1]["obj_id"];
1131  }
1132  }
1133  }
1134 
1135  // copy and paste
1136  $chapters = $ilUser->getClipboardObjects("st", true);
1137  $copied_nodes = array();
1138 
1139  foreach ($chapters as $chap)
1140  {
1141  $ilLog->write("Call pasteTree, Target LM: ".$this->content_object->getId().", Chapter ID: ".$chap["id"]
1142  .", Parent ID: ".$parent_id.", Target: ".$target);
1143  $cid = ilLMObject::pasteTree($this->content_object, $chap["id"], $parent_id,
1144  $target, $chap["insert_time"], $copied_nodes,
1145  (ilEditClipboard::getAction() == "copy"));
1146  $target = $cid;
1147  }
1148  ilLMObject::updateInternalLinks($copied_nodes);
1149 
1150  if (ilEditClipboard::getAction() == "cut")
1151  {
1152  $ilUser->clipboardDeleteObjectsOfType("pg");
1153  $ilUser->clipboardDeleteObjectsOfType("st");
1155  }
1156 
1157  $this->content_object->checkTree();
1158  $ilCtrl->redirect($this, $a_return);
1159  }
1160 
1165  {
1166  $this->insertChapterClip(true);
1167  }
1168 
1172  function insertPage()
1173  {
1174  global $ilCtrl, $lng;
1175 
1176  include_once("./Modules/LearningModule/classes/class.ilChapterHierarchyFormGUI.php");
1177 
1180 
1181  if (!ilChapterHierarchyFormGUI::getPostFirstChild()) // insert after node id
1182  {
1183  $parent_id = $this->tree->getParentId($node_id);
1184  $target = $node_id;
1185  }
1186  else // insert as first child
1187  {
1188  $parent_id = $node_id;
1189  $target = IL_FIRST_NODE;
1190  }
1191 
1192  for ($i = 1; $i <= $num; $i++)
1193  {
1194  $page = new ilLMPageObject($this->content_object);
1195  $page->setType("pg");
1196  $page->setTitle($lng->txt("cont_new_page"));
1197  $page->setLMId($this->content_object->getId());
1198  $page->create();
1199  ilLMObject::putInTree($page, $parent_id, $target);
1200  }
1201 
1202  $ilCtrl->redirect($this, "showHierarchy");
1203  }
1204 
1208  function insertPageClip()
1209  {
1210  global $ilCtrl, $ilUser;
1211 
1212  include_once("./Modules/LearningModule/classes/class.ilChapterHierarchyFormGUI.php");
1213 
1214  if ($ilUser->getPref("lm_js_chapter_editing") != "disable")
1215  {
1216  //$num = ilChapterHierarchyFormGUI::getPostMulti();
1219  }
1220  else
1221  {
1222  if(!isset($_POST["id"]) || $_POST["id"][0] == -1)
1223  {
1224  $node_id = $this->obj->getId();
1225  $first_child = true;
1226  }
1227  else
1228  {
1229  $node_id = $_POST["id"][0];
1230  $first_child = false;
1231  }
1232  }
1233 
1234  if (!$first_child) // insert after node id
1235  {
1236  $parent_id = $this->tree->getParentId($node_id);
1237  $target = $node_id;
1238  }
1239  else // insert as first child
1240  {
1241  $parent_id = $node_id;
1242  $target = IL_FIRST_NODE;
1243  }
1244 
1245  // cut and paste
1246  $pages = $ilUser->getClipboardObjects("pg");
1247  $copied_nodes = array();
1248  foreach ($pages as $pg)
1249  {
1250  $cid = ilLMObject::pasteTree($this->content_object, $pg["id"], $parent_id, $target,
1251  $pg["insert_time"], $copied_nodes,
1252  (ilEditClipboard::getAction() == "copy"));
1253  $target = $cid;
1254  }
1255  ilLMObject::updateInternalLinks($copied_nodes);
1256 
1257  if (ilEditClipboard::getAction() == "cut")
1258  {
1259  $ilUser->clipboardDeleteObjectsOfType("pg");
1260  $ilUser->clipboardDeleteObjectsOfType("st");
1262  }
1263 
1264  $ilCtrl->redirect($this, "view");
1265  }
1266 
1267 
1271  function proceedDragDrop()
1272  {
1273  global $ilCtrl;
1274 
1275 //echo "-".$_POST["il_hform_source_id"]."-".$_POST["il_hform_target_id"]."-".$_POST["il_hform_fc"]."-";
1276  $this->content_object->executeDragDrop($_POST["il_hform_source_id"], $_POST["il_hform_target_id"],
1277  $_POST["il_hform_fc"], $_POST["il_hform_as_subitem"]);
1278  $ilCtrl->redirect($this, "showHierarchy");
1279  }
1280 
1284 
1288  function setPageLayout()
1289  {
1290  global $tpl, $ilCtrl, $lng;
1291 
1292  if (!is_array($_POST["id"]))
1293  {
1294  ilUtil::sendFailure($lng->txt("no_checkbox"), true);
1295  $ilCtrl->redirect($this, "showHierarchy");
1296  }
1297 
1298  $this->initSetPageLayoutForm();
1299 
1300  $tpl->setContent($this->form->getHTML());
1301  }
1302 
1306  public function initSetPageLayoutForm()
1307  {
1308  global $lng, $ilCtrl;
1309 
1310  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
1311  $this->form = new ilPropertyFormGUI();
1312 
1313  if (is_array($_POST["id"]))
1314  {
1315  foreach ($_POST["id"] as $id)
1316  {
1317  $hi = new ilHiddenInputGUI("id[]");
1318  $hi->setValue($id);
1319  $this->form->addItem($hi);
1320  }
1321  }
1322  $layout = ilObjContentObjectGUI::getLayoutOption($lng->txt("cont_layout"), "layout",
1323  $this->content_object->getLayout());
1324 
1325  $this->form->addItem($layout);
1326 
1327  $this->form->addCommandButton("savePageLayout", $lng->txt("save"));
1328  $this->form->addCommandButton("showHierarchy", $lng->txt("cancel"));
1329 
1330  $this->form->setTitle($lng->txt("cont_set_layout"));
1331  $this->form->setFormAction($ilCtrl->getFormAction($this));
1332 
1333  }
1334 
1338  function savePageLayout()
1339  {
1340  global $lng, $ilCtrl;
1341 
1342  foreach ($_POST["id"] as $id)
1343  {
1344  $id = ilUtil::stripSlashes($id);
1346  ilUtil::stripSlashes($_POST["layout"]),
1347  $this->content_object);
1348  }
1349  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
1350  $ilCtrl->redirect($this, "showHierarchy");
1351  }
1352 
1353 }
1354 ?>