ILIAS  Release_4_2_x_branch Revision 61807
 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.gif"));
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.gif"));
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.gif"));
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.gif"));
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.gif"));
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.gif"));
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("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("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.gif"));
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  $_GET["cmd"] = "frameset";
1001  $_GET["target"] = "";
1002  $_GET["ref_id"] = ROOT_FOLDER_ID;
1003  ilUtil::sendFailure(sprintf($lng->txt("msg_no_perm_read_item"),
1004  ilObject::_lookupTitle($lm_id)), true);
1005  include("repository.php");
1006  exit;
1007  }
1008 
1009  $ilErr->raiseError($lng->txt("msg_no_perm_read_lm"), $ilErr->FATAL);
1010  }
1011 
1015  function insertChapter($a_as_sub = false)
1016  {
1017  global $ilCtrl, $lng;
1018 
1019  include_once("./Modules/LearningModule/classes/class.ilChapterHierarchyFormGUI.php");
1020 
1023 
1024  if ($a_as_sub) // as subchapter
1025  {
1026  if (!ilChapterHierarchyFormGUI::getPostFirstChild()) // insert under parent
1027  {
1028  $parent_id = $node_id;
1029  $target = "";
1030  }
1031  else // we shouldnt end up here
1032  {
1033  $ilCtrl->redirect($this, "showHierarchy");
1034  return;
1035  }
1036  }
1037  else // as chapter
1038  {
1039  if (!ilChapterHierarchyFormGUI::getPostFirstChild()) // insert after node id
1040  {
1041  $parent_id = $this->tree->getParentId($node_id);
1042  $target = $node_id;
1043  }
1044  else // insert as first child
1045  {
1046  $parent_id = $node_id;
1047  $target = IL_FIRST_NODE;
1048  }
1049  }
1050  for ($i = 1; $i <= $num; $i++)
1051  {
1052  $chap = new ilStructureObject($this->content_object);
1053  $chap->setType("st");
1054  $chap->setTitle($lng->txt("cont_new_chap"));
1055  $chap->setLMId($this->content_object->getId());
1056  $chap->create();
1057  ilLMObject::putInTree($chap, $parent_id, $target);
1058  }
1059 
1060  $ilCtrl->redirect($this, "view");
1061  }
1062 
1066  function insertSubchapter()
1067  {
1068  global $ilCtrl;
1069 
1070  $this->insertChapter(true);
1071  }
1072 
1076  function insertChapterClip($a_as_sub = false, $a_return = "view")
1077  {
1078  global $ilUser, $ilCtrl, $ilLog;
1079 
1080  $ilLog->write("Insert Chapter From Clipboard");
1081 
1082  include_once("./Modules/LearningModule/classes/class.ilChapterHierarchyFormGUI.php");
1083 
1084  if ($ilUser->getPref("lm_js_chapter_editing") != "disable")
1085  {
1086  //$num = ilChapterHierarchyFormGUI::getPostMulti();
1089  }
1090  else
1091  {
1092  if (!isset($_POST["id"]) || $_POST["id"][0] == -1)
1093  {
1094  $node_id = $this->obj->getId();
1095  $first_child = true;
1096  }
1097  else
1098  {
1099  $node_id = $_POST["id"][0];
1100  $first_child = false;
1101  }
1102  }
1103 
1104  if ($a_as_sub) // as subchapter
1105  {
1106  if (!$first_child) // insert under parent
1107  {
1108  $parent_id = $node_id;
1109  $target = "";
1110  }
1111  else // we shouldnt end up here
1112  {
1113  $ilCtrl->redirect($this, "showHierarchy");
1114  return;
1115  }
1116  }
1117  else // as chapter
1118  {
1119  if (!$first_child) // insert after node id
1120  {
1121  $parent_id = $this->tree->getParentId($node_id);
1122  $target = $node_id;
1123  }
1124  else // insert as first child
1125  {
1126  $parent_id = $node_id;
1127  $target = IL_FIRST_NODE;
1128 
1129  // do not move a chapter in front of a page
1130  $childs = $this->tree->getChildsByType($parent_id, "pg");
1131  if (count($childs) != 0)
1132  {
1133  $target = $childs[count($childs) - 1]["obj_id"];
1134  }
1135  }
1136  }
1137 
1138  // copy and paste
1139  $chapters = $ilUser->getClipboardObjects("st", true);
1140  $copied_nodes = array();
1141 
1142  foreach ($chapters as $chap)
1143  {
1144  $ilLog->write("Call pasteTree, Target LM: ".$this->content_object->getId().", Chapter ID: ".$chap["id"]
1145  .", Parent ID: ".$parent_id.", Target: ".$target);
1146  $cid = ilLMObject::pasteTree($this->content_object, $chap["id"], $parent_id,
1147  $target, $chap["insert_time"], $copied_nodes,
1148  (ilEditClipboard::getAction() == "copy"));
1149  $target = $cid;
1150  }
1151  ilLMObject::updateInternalLinks($copied_nodes);
1152 
1153  if (ilEditClipboard::getAction() == "cut")
1154  {
1155  $ilUser->clipboardDeleteObjectsOfType("pg");
1156  $ilUser->clipboardDeleteObjectsOfType("st");
1158  }
1159 
1160  $this->content_object->checkTree();
1161  $ilCtrl->redirect($this, $a_return);
1162  }
1163 
1168  {
1169  $this->insertChapterClip(true);
1170  }
1171 
1175  function insertPage()
1176  {
1177  global $ilCtrl, $lng;
1178 
1179  include_once("./Modules/LearningModule/classes/class.ilChapterHierarchyFormGUI.php");
1180 
1183 
1184  if (!ilChapterHierarchyFormGUI::getPostFirstChild()) // insert after node id
1185  {
1186  $parent_id = $this->tree->getParentId($node_id);
1187  $target = $node_id;
1188  }
1189  else // insert as first child
1190  {
1191  $parent_id = $node_id;
1192  $target = IL_FIRST_NODE;
1193  }
1194 
1195  for ($i = 1; $i <= $num; $i++)
1196  {
1197  $page = new ilLMPageObject($this->content_object);
1198  $page->setType("pg");
1199  $page->setTitle($lng->txt("cont_new_page"));
1200  $page->setLMId($this->content_object->getId());
1201  $page->create();
1202  ilLMObject::putInTree($page, $parent_id, $target);
1203  }
1204 
1205  $ilCtrl->redirect($this, "showHierarchy");
1206  }
1207 
1211  function insertPageClip()
1212  {
1213  global $ilCtrl, $ilUser;
1214 
1215  include_once("./Modules/LearningModule/classes/class.ilChapterHierarchyFormGUI.php");
1216 
1217  if ($ilUser->getPref("lm_js_chapter_editing") != "disable")
1218  {
1219  //$num = ilChapterHierarchyFormGUI::getPostMulti();
1222  }
1223  else
1224  {
1225  if(!isset($_POST["id"]) || $_POST["id"][0] == -1)
1226  {
1227  $node_id = $this->obj->getId();
1228  $first_child = true;
1229  }
1230  else
1231  {
1232  $node_id = $_POST["id"][0];
1233  $first_child = false;
1234  }
1235  }
1236 
1237  if (!$first_child) // insert after node id
1238  {
1239  $parent_id = $this->tree->getParentId($node_id);
1240  $target = $node_id;
1241  }
1242  else // insert as first child
1243  {
1244  $parent_id = $node_id;
1245  $target = IL_FIRST_NODE;
1246  }
1247 
1248  // cut and paste
1249  $pages = $ilUser->getClipboardObjects("pg");
1250  $copied_nodes = array();
1251  foreach ($pages as $pg)
1252  {
1253  $cid = ilLMObject::pasteTree($this->content_object, $pg["id"], $parent_id, $target,
1254  $pg["insert_time"], $copied_nodes,
1255  (ilEditClipboard::getAction() == "copy"));
1256  $target = $cid;
1257  }
1258  ilLMObject::updateInternalLinks($copied_nodes);
1259 
1260  if (ilEditClipboard::getAction() == "cut")
1261  {
1262  $ilUser->clipboardDeleteObjectsOfType("pg");
1263  $ilUser->clipboardDeleteObjectsOfType("st");
1265  }
1266 
1267  $ilCtrl->redirect($this, "view");
1268  }
1269 
1270 
1274  function proceedDragDrop()
1275  {
1276  global $ilCtrl;
1277 
1278 //echo "-".$_POST["il_hform_source_id"]."-".$_POST["il_hform_target_id"]."-".$_POST["il_hform_fc"]."-";
1279  $this->content_object->executeDragDrop($_POST["il_hform_source_id"], $_POST["il_hform_target_id"],
1280  $_POST["il_hform_fc"], $_POST["il_hform_as_subitem"]);
1281  $ilCtrl->redirect($this, "showHierarchy");
1282  }
1283 
1287 
1291  function setPageLayout()
1292  {
1293  global $tpl, $ilCtrl, $lng;
1294 
1295  if (!is_array($_POST["id"]))
1296  {
1297  ilUtil::sendFailure($lng->txt("no_checkbox"), true);
1298  $ilCtrl->redirect($this, "showHierarchy");
1299  }
1300 
1301  $this->initSetPageLayoutForm();
1302 
1303  $tpl->setContent($this->form->getHTML());
1304  }
1305 
1309  public function initSetPageLayoutForm()
1310  {
1311  global $lng, $ilCtrl;
1312 
1313  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
1314  $this->form = new ilPropertyFormGUI();
1315 
1316  if (is_array($_POST["id"]))
1317  {
1318  foreach ($_POST["id"] as $id)
1319  {
1320  $hi = new ilHiddenInputGUI("id[]");
1321  $hi->setValue($id);
1322  $this->form->addItem($hi);
1323  }
1324  }
1325  $layout = ilObjContentObjectGUI::getLayoutOption($lng->txt("cont_layout"), "layout",
1326  $this->content_object->getLayout());
1327 
1328  $this->form->addItem($layout);
1329 
1330  $this->form->addCommandButton("savePageLayout", $lng->txt("save"));
1331  $this->form->addCommandButton("showHierarchy", $lng->txt("cancel"));
1332 
1333  $this->form->setTitle($lng->txt("cont_set_layout"));
1334  $this->form->setFormAction($ilCtrl->getFormAction($this));
1335 
1336  }
1337 
1341  function savePageLayout()
1342  {
1343  global $lng, $ilCtrl;
1344 
1345  foreach ($_POST["id"] as $id)
1346  {
1347  $id = ilUtil::stripSlashes($id);
1349  ilUtil::stripSlashes($_POST["layout"]),
1350  $this->content_object);
1351  }
1352  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
1353  $ilCtrl->redirect($this, "showHierarchy");
1354  }
1355 
1356 }
1357 ?>