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