ILIAS  Release_3_10_x_branch Revision 61812
 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-2006 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 require_once("./Modules/LearningModule/classes/class.ilLMObjectGUI.php");
25 require_once("./Modules/LearningModule/classes/class.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  if (!ilLMPageObject::_lookupActive($child["obj_id"]))
183  {
184  $this->tpl->setCurrentBlock("deactivated");
185  $this->tpl->setVariable("TXT_DEACTIVATED",
186  $this->lng->txt("cont_page_deactivated"));
187  $this->tpl->parseCurrentBlock();
188  }
189  else
190  {
192  $this->content_object->getType()))
193  {
194  $this->tpl->setCurrentBlock("deactivated");
195  $this->tpl->setVariable("TXT_DEACTIVATED",
196  $this->lng->txt("cont_page_deactivated_elements"));
197  $this->tpl->parseCurrentBlock();
198  }
199  }
200 
201  $this->tpl->setCurrentBlock("table_row");
202  // color changing
203  $css_row = ilUtil::switchColor($cnt++,"tblrow1","tblrow2");
204 
205  // checkbox
206  $this->tpl->setVariable("CHECKBOX_ID", $child["obj_id"]);
207  $this->tpl->setVariable("CSS_ROW", $css_row);
208  $this->tpl->setVariable("IMG_OBJ", ilUtil::getImagePath("icon_pg.gif"));
209 
210  // link
211  $this->ctrl->setParameterByClass("ilLMPageObjectGUI", "obj_id", $child["obj_id"]);
212  $link = $this->ctrl->getLinkTargetByClass("ilLMPageObjectGUI", "edit", "");
213  $this->tpl->setVariable("LINK_TARGET", $link);
214 
215  // title
216  $this->tpl->setVariable("TEXT_CONTENT", $child["title"]);
217 
218  $this->tpl->parseCurrentBlock();
219  }
220  if($cnt == 0)
221  {
222  $this->tpl->setCurrentBlock("notfound");
223  $this->tpl->setVariable("NUM_COLS", 3);
224  $this->tpl->setVariable("TXT_OBJECT_NOT_FOUND", $this->lng->txt("obj_not_found"));
225  $this->tpl->parseCurrentBlock();
226  }
227  //else
228  //{
229  // SHOW VALID ACTIONS
230  $this->tpl->setVariable("NUM_COLS", 3);
231  //$this->setActions(array("confirmTermDeletion" => "delete", "addDefinition" => "cont_add_definition"));
232  $acts = array("delete" => "delete", "cutPage" => "cutPage",
233  "copyPage" => "copyPage", "activatePages" => "cont_de_activate");
234  //echo ":".$this->checkClipboardContentType().":<br>";
235  if ($ilUser->clipboardHasObjectsOfType("pg"))
236  {
237  $acts["pastePage"] = "pastePage";
238  }
239  $this->setActions($acts);
240  $this->showActions();
241  //}
242 
243  // SHOW POSSIBLE SUB OBJECTS
244  $this->tpl->setVariable("NUM_COLS", 3);
245  //$this->showPossibleSubObjects("st");
246  $subobj = array("pg");
247  $opts = ilUtil::formSelect(12,"new_type",$subobj);
248  //$this->tpl->setVariable("IMG_ARROW", ilUtil::getImagePath("arrow_downright.gif"));
249  $this->tpl->setCurrentBlock("add_object");
250  $this->tpl->setVariable("SELECT_OBJTYPE", $opts);
251  //$this->tpl->setVariable("FORMACTION_OBJ_ADD", "adm_object.php?cmd=create&ref_id=".$_GET["ref_id"]);
252  $this->tpl->setVariable("BTN_NAME", "create");
253  $this->tpl->setVariable("TXT_ADD", $this->lng->txt("insert"));
254  $this->tpl->parseCurrentBlock();
255 
256  $this->tpl->setCurrentBlock("form");
257  $this->tpl->parseCurrentBlock();
258 
259  $ilCtrl->setParameter($this, "obj_id", $_GET["obj_id"]);
260  $this->tpl->setVariable("HREF_JS_EDIT",
261  $ilCtrl->getLinkTarget($this, "activateJSChapterEditing"));
262  $this->tpl->setVariable("TXT_JS_EDIT",
263  $lng->txt("cont_js_chap_editing"));
264  }
265  }
266 
267 
271  function showHierarchy()
272  {
273  global $lng, $ilCtrl;
274 
275  $this->setTabs();
276 
277  $ilCtrl->setParameter($this, "backcmd", "showHierarchy");
278 
279  include_once("./Modules/LearningModule/classes/class.ilChapterHierarchyFormGUI.php");
280  $form_gui = new ilChapterHierarchyFormGUI($this->content_object->getType());
281  $form_gui->setFormAction($ilCtrl->getFormAction($this));
282  $form_gui->setTitle($this->obj->getTitle());
283  $form_gui->setIcon(ilUtil::getImagePath("icon_st.gif"));
284  $form_gui->setTree($this->tree);
285  $form_gui->setCurrentTopNodeId($this->obj->getId());
286  $form_gui->addMultiCommand($lng->txt("delete"), "delete");
287  $form_gui->addMultiCommand($lng->txt("cut"), "cutItems");
288  $form_gui->addMultiCommand($lng->txt("copy"), "copyItems");
289  $form_gui->addMultiCommand($lng->txt("cont_de_activate"), "activatePages");
290  $form_gui->setDragIcon(ilUtil::getImagePath("icon_pg_s.gif"));
291  $form_gui->addCommand($lng->txt("cont_save_all_titles"), "saveAllTitles");
292  $form_gui->addHelpItem($lng->txt("cont_chapters_after_pages"));
293  $up_gui = ($this->content_object->getType() == "dbk")
294  ? "ilobjdlbookgui"
295  : "ilobjlearningmodulegui";
296  $ilCtrl->setParameterByClass($up_gui, "active_node", $this->obj->getId());
297  $form_gui->setExplorerUpdater("tree", "tree_div",
298  $ilCtrl->getLinkTargetByClass($up_gui, "explorer", "", true));
299  $ilCtrl->setParameterByClass($up_gui, "active_node", "");
300 
301  $ctpl = new ilTemplate("tpl.chap_and_pages.html", true, true, "Modules/LearningModule");
302  $ctpl->setVariable("HIERARCHY_FORM", $form_gui->getHTML());
303  $ilCtrl->setParameter($this, "obj_id", $_GET["obj_id"]);
304  $ctpl->setVariable("HREF_NO_JS_EDIT",
305  $ilCtrl->getLinkTarget($this, "deactivateJSChapterEditing"));
306  $ctpl->setVariable("TXT_NO_JS_EDIT",
307  $lng->txt("cont_not_js_chap_editing"));
308 
309  $this->tpl->setContent($ctpl->get());
310  }
311 
316  {
317  global $ilCtrl, $ilUser;
318 
319  $ilUser->writePref("lm_js_chapter_editing", "disable");
320  $ilCtrl->redirect($this, "view");
321  }
322 
327  {
328  global $ilCtrl, $ilUser;
329 
330  $ilUser->writePref("lm_js_chapter_editing", "enable");
331  $ilCtrl->redirect($this, "view");
332  }
333 
337  function cutItems($a_return = "view")
338  {
339  global $ilCtrl, $lng;
340 
341  $items = ilUtil::stripSlashesArray($_POST["id"]);
342  if (!is_array($items))
343  {
344  ilUtil::sendInfo($lng->txt("no_checkbox"), true);
345  $ilCtrl->redirect($this, "showHierarchy");
346  }
347 
348  $todel = array(); // delete IDs < 0 (needed for non-js editing)
349  foreach($items as $k => $item)
350  {
351  if ($item < 0)
352  {
353  $todel[] = $k;
354  }
355  }
356  foreach($todel as $k)
357  {
358  unset($items[$k]);
359  }
360 
361  if (!ilLMObject::uniqueTypesCheck($items))
362  {
363  ilUtil::sendInfo($lng->txt("cont_choose_pages_or_chapters_only"), true);
364  $ilCtrl->redirect($this, "showHierarchy");
365  }
366 
367  ilLMObject::clipboardCut($this->content_object->getId(), $items);
369  //ilUtil::sendInfo($this->lng->txt("msg_cut_clipboard"), true);
370  ilUtil::sendInfo($lng->txt("cont_selected_items_have_been_cut"), true);
371 
372  $ilCtrl->redirect($this, $a_return);
373  }
374 
378  function copyItems($a_return = "view")
379  {
380  global $ilCtrl, $lng;
381 
382  $items = ilUtil::stripSlashesArray($_POST["id"]);
383  if (!is_array($items))
384  {
385  ilUtil::sendInfo($lng->txt("no_checkbox"), true);
386  $ilCtrl->redirect($this, "showHierarchy");
387  }
388 
389  $todel = array(); // delete IDs < 0 (needed for non-js editing)
390  foreach($items as $k => $item)
391  {
392  if ($item < 0)
393  {
394  $todel[] = $k;
395  }
396  }
397  foreach($todel as $k)
398  {
399  unset($items[$k]);
400  }
401 
402  if (!ilLMObject::uniqueTypesCheck($items))
403  {
404  ilUtil::sendInfo($lng->txt("cont_choose_pages_or_chapters_only"), true);
405  $ilCtrl->redirect($this, "showHierarchy");
406  }
407 
408  ilLMObject::clipboardCopy($this->content_object->getId(), $items);
410 
411  ilUtil::sendInfo($lng->txt("cont_selected_items_have_been_copied"), true);
412  $ilCtrl->redirect($this, $a_return);
413  }
414 
418  function saveAllTitles()
419  {
420  global $ilCtrl;
421 
422  ilLMObject::saveTitles($this->content_object, ilUtil::stripSlashesArray($_POST["title"]));
423 
424  $ilCtrl->redirect($this, "showHierarchy");
425  }
426 
427  /*
428  * display subchapters of structure object
429  */
430  function subchap()
431  {
432  global $tree, $ilCtrl, $lng, $ilUser;
433 
434  $this->setTabs();
435 
436  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.structure_edit.html", "Modules/LearningModule");
437  $num = 0;
438 
439  $this->tpl->setCurrentBlock("form");
440  $this->ctrl->setParameter($this, "backcmd", "subchap");
441  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
442  $this->tpl->setVariable("HEADER_TEXT", $this->lng->txt("cont_subchapters"));
443  $this->tpl->setVariable("CHECKBOX_TOP", IL_FIRST_NODE);
444 
445  $cnt = 0;
446  $childs = $this->tree->getChilds($this->obj->getId());
447  foreach ($childs as $child)
448  {
449  if($child["type"] != "st")
450  {
451  continue;
452  }
453  $this->tpl->setCurrentBlock("table_row");
454  // color changing
455  $css_row = ilUtil::switchColor($cnt++,"tblrow1","tblrow2");
456 
457  // checkbox
458  $this->tpl->setVariable("CHECKBOX_ID", $child["obj_id"]);
459  $this->tpl->setVariable("CSS_ROW", $css_row);
460  $this->tpl->setVariable("IMG_OBJ", ilUtil::getImagePath("icon_st.gif"));
461 
462  // type
463  $this->ctrl->setParameterByClass("ilStructureObjectGUI", "obj_id", $child["obj_id"]);
464  $link = $this->ctrl->getLinkTargetByClass("ilStructureObjectGUI", "view");
465  $this->tpl->setVariable("LINK_TARGET", $link);
466 
467  // title
468  $this->tpl->setVariable("TEXT_CONTENT",
470  $this->content_object->isActiveNumbering()));
471 
472  $this->tpl->parseCurrentBlock();
473  }
474  if($cnt == 0)
475  {
476  $this->tpl->setCurrentBlock("notfound");
477  $this->tpl->setVariable("NUM_COLS", 3);
478  $this->tpl->setVariable("TXT_OBJECT_NOT_FOUND", $this->lng->txt("obj_not_found"));
479  $this->tpl->parseCurrentBlock();
480  }
481  //else
482  //{
483  // SHOW VALID ACTIONS
484  $this->tpl->setVariable("NUM_COLS", 3);
485  $acts = array("delete" => "delete", "cutChapter" => "cut",
486  "copyChapter" => "copyChapter");
487  if ($ilUser->clipboardHasObjectsOfType("st"))
488  {
489  $acts["pasteChapter"] = "pasteChapter";
490  }
491  /*if(!empty($_SESSION["ilEditClipboard"]))
492  {
493  $acts["paste"] = "paste";
494  }*/
495  $this->setActions($acts);
496  $this->showActions();
497  //}
498 
499  // SHOW POSSIBLE SUB OBJECTS
500  $this->tpl->setVariable("NUM_COLS", 3);
501  //$this->showPossibleSubObjects("st");
502  $subobj = array("st");
503  $opts = ilUtil::formSelect(12,"new_type",$subobj);
504  //$this->tpl->setVariable("IMG_ARROW", ilUtil::getImagePath("arrow_downright.gif"));
505  $this->tpl->setCurrentBlock("add_object");
506  $this->tpl->setVariable("SELECT_OBJTYPE", $opts);
507  //$this->tpl->setVariable("FORMACTION_OBJ_ADD", "adm_object.php?cmd=create&ref_id=".$_GET["ref_id"]);
508  $this->tpl->setVariable("BTN_NAME", "create");
509  $this->tpl->setVariable("TXT_ADD", $this->lng->txt("insert"));
510  $this->tpl->parseCurrentBlock();
511 
512  //$this->tpl->setVariable("NUM_COLS", 2);
513  //$this->showPossibleSubObjects("st");
514 
515  $this->tpl->setCurrentBlock("form");
516  $this->tpl->parseCurrentBlock();
517 
518  $ilCtrl->setParameter($this, "obj_id", $_GET["obj_id"]);
519  $this->tpl->setVariable("HREF_JS_EDIT",
520  $ilCtrl->getLinkTarget($this, "activateJSChapterEditing"));
521  $this->tpl->setVariable("TXT_JS_EDIT",
522  $lng->txt("cont_js_chap_editing"));
523 
524  }
525 
529  function add_cell($val, $link = "")
530  {
531  if(!empty($link))
532  {
533  $this->tpl->setCurrentBlock("begin_link");
534  $this->tpl->setVariable("LINK_TARGET", $link);
535  $this->tpl->parseCurrentBlock();
536  $this->tpl->touchBlock("end_link");
537  }
538 
539  $this->tpl->setCurrentBlock("text");
540  $this->tpl->setVariable("TEXT_CONTENT", $val);
541  $this->tpl->parseCurrentBlock();
542  $this->tpl->setCurrentBlock("table_cell");
543  $this->tpl->parseCurrentBlock();
544  }
545 
546 
550  function save()
551  {
552 
553  $this->obj =& new ilStructureObject($this->content_object);
554 
555  $this->obj->setType("st");
556  $this->obj->setTitle(ilUtil::stripSlashes($_POST["Fobject"]["title"]));
557  $this->obj->setDescription(ilUtil::stripSlashes($_POST["Fobject"]["desc"]));
558  $this->obj->setLMId($this->content_object->getId());
559  $this->obj->create();
560 
561  $this->putInTree();
562 
563  // check the tree
564  $this->checkTree();
565 
566  if (!empty($_GET["obj_id"]))
567  {
568  $this->ctrl->redirect($this, "subchap");
569  }
570 
571  }
572 
576  function putInTree()
577  {
578 //echo "st:putInTree";
579  // chapters should be behind pages in the tree
580  // so if target is first node, the target is substituted with
581  // the last child of type pg
582  if ($_GET["target"] == IL_FIRST_NODE)
583  {
584  $tree = new ilTree($this->content_object->getId());
585  $tree->setTableNames('lm_tree','lm_data');
586  $tree->setTreeTablePK("lm_id");
587 
588  // determine parent node id
589  $parent_id = (!empty($_GET["obj_id"]))
590  ? $_GET["obj_id"]
591  : $tree->getRootId();
592  // determine last child of type pg
593  $childs =& $tree->getChildsByType($parent_id, "pg");
594  if (count($childs) != 0)
595  {
596  $_GET["target"] = $childs[count($childs) - 1]["obj_id"];
597  }
598  }
599  if (empty($_GET["target"]))
600  {
601  $_GET["target"] = IL_LAST_NODE;
602  }
603 
605  }
606 
610  function cutPage()
611  {
612  $this->cutItems();
613 
614  return;
615  if(!isset($_POST["id"]))
616  {
617  $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
618 
619  }
620  if(count($_POST["id"]) > 1)
621  {
622  $this->ilias->raiseError($this->lng->txt("cont_select_max_one_item"),$this->ilias->error_obj->MESSAGE);
623  }
624 
625  if(count($_POST["id"]) == 1 && $_POST["id"][0] == IL_FIRST_NODE)
626  {
627  $this->ilias->raiseError($this->lng->txt("cont_select_item"), $this->ilias->error_obj->MESSAGE);
628  }
629 
630  // SAVE POST VALUES
631  ilEditClipboard::storeContentObject("pg",$_POST["id"][0]);
632 
633  $tree = new ilTree($this->content_object->getId());
634  $tree->setTableNames('lm_tree','lm_data');
635  $tree->setTreeTablePK("lm_id");
636 
637  // cut selected object
638  $cutted = 0;
639  foreach ($_POST["id"] as $id)
640  {
641  if ($id == -1)
642  {
643  continue;
644  }
645 
646  $obj =& ilLMObjectFactory::getInstance($this->content_object, $id);
647  $obj->setLMId($this->content_object->getId());
648  $node_data = $tree->getNodeData($id);
649  //$obj->delete();
650  if($tree->isInTree($id))
651  {
652  $parent_id = $tree->getParentId($id);
653  $tree->deleteTree($node_data);
654 
655  // write history entry
656  require_once("classes/class.ilHistory.php");
657  ilHistory::_createEntry($id, "cut",
658  array(ilLMObject::_lookupTitle($parent_id), $parent_id),
659  $this->content_object->getType().":pg");
660  ilHistory::_createEntry($parent_id, "cut_page",
661  array(ilLMObject::_lookupTitle($id), $id),
662  $this->content_object->getType().":st");
663  }
664  $cutted++;
665  }
666 
667  // tree check
668  $this->checkTree();
669 
670  if($cutted > 0)
671  {
672  ilUtil::sendInfo($this->lng->txt("msg_cut_clipboard"), true);
673  }
674 
675  $this->ctrl->redirect($this, "view");
676  }
677 
681  function copyPage()
682  {
683  $this->copyItems();
684  return;
685 
686  if(!isset($_POST["id"]))
687  {
688  $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
689  }
690  if(count($_POST["id"]) > 1)
691  {
692  $this->ilias->raiseError($this->lng->txt("cont_select_max_one_item"),$this->ilias->error_obj->MESSAGE);
693  }
694 
695  if(count($_POST["id"]) == 1 && $_POST["id"][0] == IL_FIRST_NODE)
696  {
697  $this->ilias->raiseError($this->lng->txt("cont_select_item"), $this->ilias->error_obj->MESSAGE);
698  }
699 
700  // SAVE POST VALUES
701  ilEditClipboard::storeContentObject("pg",$_POST["id"][0],"copy");
702 
703  ilUtil::sendInfo($this->lng->txt("msg_copy_clipboard"), true);
704 
705  $this->ctrl->redirect($this, "view");
706  }
707 
711  function pastePage()
712  {
713  global $ilUser;
714 
715  if (!$ilUser->clipboardHasObjectsOfType("pg"))
716  {
717  $this->ilias->raiseError($this->lng->txt("no_page_in_clipboard"),$this->ilias->error_obj->MESSAGE);
718  }
719 
720  return $this->insertPageClip();
721  return;
722  $tree = new ilTree($this->content_object->getId());
723  $tree->setTableNames('lm_tree','lm_data');
724  $tree->setTreeTablePK("lm_id");
725 
726  // paste selected object
728 
729  // copy page, if action is copy
730  if (ilEditClipboard::getAction() == "copy")
731  {
732  // check wether page belongs to lm
734  == $this->content_object->getID())
735  {
736  $lm_page = new ilLMPageObject($this->content_object, $id);
737  $new_page =& $lm_page->copy();
738  $id = $new_page->getId();
739  }
740  else
741  {
742  // get page from other content object into current content object
744  $lm_obj =& $this->ilias->obj_factory->getInstanceByObjId($lm_id);
745  $lm_page = new ilLMPageObject($lm_obj, $id);
746  $copied_nodes = array();
747  $new_page =& $lm_page->copyToOtherContObject($this->content_object, $copied_nodes);
748  $id = $new_page->getId();
749  ilLMObject::updateInternalLinks($copied_nodes);
750  }
751  }
752 
753  if (ilEditClipboard::getAction() == "cut")
754  {
755  // check wether page belongs not to lm
757  != $this->content_object->getID())
758  {
760  $lm_obj =& $this->ilias->obj_factory->getInstanceByObjId($lm_id);
761  $lm_page = new ilLMPageObject($lm_obj, $id);
762  $lm_page->setLMId($this->content_object->getID());
763  $lm_page->update();
764  $page =& $lm_page->getPageObject();
765  $page->buildDom();
766  $page->setParentId($this->content_object->getID());
767  $page->update();
768  }
769  }
770 
771  if(!$tree->isInTree($id))
772  {
773  if(!isset($_POST["id"]))
774  {
775  $target = IL_FIRST_NODE;
776  }
777  else
778  {
779  $target = $_POST["id"][0];
780  }
781  $tree->insertNode($id, $this->obj->getId(), $target);
783  }
784 
785  // write history comments
786  include_once("classes/class.ilHistory.php");
787  $parent_id = $tree->getParentId($id);
788  ilHistory::_createEntry($id, "paste",
789  array(ilLMObject::_lookupTitle($this->obj->getId()), $this->obj->getId()),
790  $this->content_object->getType().":pg");
791  ilHistory::_createEntry($parent_id, "paste_page",
792  array(ilLMObject::_lookupTitle($id), $id),
793  $this->content_object->getType().":st");
794 
795  // check the tree
796  $this->checkTree();
797 
798  $this->ctrl->redirect($this, "view");
799  }
800 
801 
805  function cutChapter()
806  {
807  $this->cutItems("subchap");
808 
809  return;
810 
811  $cont_obj_gui =& new ilObjContentObjectGUI("",$this->content_object->getRefId(),
812  true, false);
813  $cont_obj_gui->moveChapter($this->obj->getId());
814 
815  $this->ctrl->redirect($this, "subchap");
816  }
817 
821  function copyChapter()
822  {
823  $this->copyItems("subchap");
824  return;
825 
826  $cont_obj_gui =& new ilObjContentObjectGUI("",$this->content_object->getRefId(),
827  true, false);
828  $cont_obj_gui->copyChapter($this->obj->getId());
829 
830  $this->ctrl->redirect($this, "subchap");
831  }
832 
836  function pasteChapter()
837  {
838  global $ilUser;
839 
840  return $this->insertChapterClip(false, "subchap");
841  return;
842 
844  if($id == $_POST["id"][0])
845  {
847  $this->subchap();
848  return;
849  }
850  $cont_obj_gui =& new ilObjContentObjectGUI("",$this->content_object->getRefId(),
851  true, false);
852  $cont_obj_gui->pasteChapter($this->obj->getId());
853 
854  $this->ctrl->redirect($this, "subchap");
855  }
856 
860  function activatePages()
861  {
862  global $lng;
863 
864  if (is_array($_POST["id"]))
865  {
866  $act_items = array();
867  // get all "top" ids, i.e. remove ids, that have a selected parent
868  foreach($_POST["id"] as $id)
869  {
870  $path = $this->tree->getPathId($id);
871  $take = true;
872  foreach($path as $path_id)
873  {
874  if ($path_id != $id && in_array($path_id, $_POST["id"]))
875  {
876  $take = false;
877  }
878  }
879  if ($take)
880  {
881  $act_items[] = $id;
882  }
883  }
884 
885 
886  foreach($act_items as $id)
887  {
888  $childs = $this->tree->getChilds($id);
889  foreach($childs as $child)
890  {
891  if (ilLMObject::_lookupType($child["child"]) == "pg")
892  {
893  $act = ilLMObject::_lookupActive($child["child"]);
894  ilLMObject::_writeActive($child["child"], !$act);
895  }
896  }
897  if (ilLMObject::_lookupType($id) == "pg")
898  {
899  $act = ilLMObject::_lookupActive($id);
900  ilLMObject::_writeActive($id, !$act);
901  }
902  }
903  }
904  else
905  {
906  ilUtil::sendInfo($lng->txt("no_checkbox"), true);
907  }
908 
909  $this->ctrl->redirect($this, "view");
910  }
911 
912  //
913  // Condition handling stuff
914  //
915 
917  {
918  include_once("classes/class.ilConditionHandlerInterface.php");
919 
920  $this->condHI =& new ilConditionHandlerInterface($this);
921  $this->condHI->setBackButtons(array());
922  $this->condHI->setAutomaticValidation(false);
923  $this->condHI->setTargetType("st");
924  $this->condHI->setTargetRefId($this->content_object->getRefId());
925  $this->condHI->setTargetId($this->obj->getId());
926  $this->condHI->setTargetTitle($this->obj->getTitle());
927  }
928 
929 
933  function cancel()
934  {
935  ilUtil::sendInfo($this->lng->txt("msg_cancel"), true);
936  if ($_GET["obj_id"] != 0)
937  {
938  if ($_GET["new_type"] == "pg")
939  {
940  $this->ctrl->redirect($this, "view");
941  }
942  else
943  {
944  $this->ctrl->redirect($this, "subchap");
945  }
946  }
947  }
948 
949 
953  function setTabs()
954  {
955  global $ilTabs, $ilUser;
956 
957  if ($ilUser->getPref("lm_js_chapter_editing") == "disable")
958  {
959  // pages
960  $ilTabs->addTarget("cont_pages",
961  $this->ctrl->getLinkTarget($this,'view'),
962  "view", get_class($this));
963 
964  // subchapters
965  $ilTabs->addTarget("cont_subchapters",
966  $this->ctrl->getLinkTarget($this,'subchap'),
967  "subchap", get_class($this));
968  }
969  else
970  {
971  // subelements
972  $ilTabs->addTarget("cont_pages_and_subchapters",
973  $this->ctrl->getLinkTarget($this,'showHierarchy'),
974  array("view", "showHierarchy"), get_class($this));
975  }
976 
977  // preconditions
978  $ilTabs->addTarget("preconditions",
979  $this->ctrl->getLinkTarget($this, 'listConditions'),
980  "listConditions", get_class($this));
981 
982  // metadata
983  $ilTabs->addTarget("meta_data",
984  $this->ctrl->getLinkTargetByClass("ilmdeditorgui",''),
985  "", "ilmdeditorgui");
986 
987  $this->tpl->setCurrentBlock("header_image");
988  $this->tpl->setVariable("IMG_HEADER", ilUtil::getImagePath("icon_st_b.gif"));
989  $this->tpl->parseCurrentBlock();
990  $this->tpl->setCurrentBlock("content");
991 
992  #$this->tpl->setVariable("TABS", $tabs_gui->getHTML());
993  $this->tpl->setVariable("HEADER",
994  $this->lng->txt($this->obj->getType()).": ".$this->obj->getTitle());
995  }
996 
1002  function _goto($a_target, $a_target_ref_id = "")
1003  {
1004  global $rbacsystem, $ilErr, $lng, $ilAccess;
1005 
1006  // determine learning object
1007  $lm_id = ilLMObject::_lookupContObjID($a_target);
1008 
1009  // get all references
1010  $ref_ids = ilObject::_getAllReferences($lm_id);
1011 
1012  // always try passed ref id first
1013  if (in_array($a_target_ref_id, $ref_ids))
1014  {
1015  $ref_ids = array_merge(array($a_target_ref_id), $ref_ids);
1016  }
1017 
1018  // check read permissions
1019  foreach ($ref_ids as $ref_id)
1020  {
1021  // Permission check
1022  if ($ilAccess->checkAccess("read", "", $ref_id))
1023  {
1024  // don't redirect anymore, just set parameters
1025  // (goto.php includes "ilias.php")
1026  $_GET["baseClass"] = "ilLMPresentationGUI";
1027  $_GET["obj_id"] = $a_target;
1028  $_GET["ref_id"] = $ref_id;
1029  include_once("ilias.php");
1030  exit;;
1031  }
1032  }
1033 
1034  if ($ilAccess->checkAccess("read", "", ROOT_FOLDER_ID))
1035  {
1036  $_GET["cmd"] = "frameset";
1037  $_GET["target"] = "";
1038  $_GET["ref_id"] = ROOT_FOLDER_ID;
1039  ilUtil::sendInfo(sprintf($lng->txt("msg_no_perm_read_item"),
1040  ilObject::_lookupTitle($lm_id)), true);
1041  include("repository.php");
1042  exit;
1043  }
1044 
1045  $ilErr->raiseError($lng->txt("msg_no_perm_read_lm"), $ilErr->FATAL);
1046  }
1047 
1051  function insertChapter($a_as_sub = false)
1052  {
1053  global $ilCtrl;
1054 
1055  include_once("./Modules/LearningModule/classes/class.ilChapterHierarchyFormGUI.php");
1056 
1059 
1060  if ($a_as_sub) // as subchapter
1061  {
1062  if (!ilChapterHierarchyFormGUI::getPostFirstChild()) // insert under parent
1063  {
1064  $parent_id = $node_id;
1065  $target = "";
1066  }
1067  else // we shouldnt end up here
1068  {
1069  $ilCtrl->redirect($this, "showHierarchy");
1070  return;
1071  }
1072  }
1073  else // as chapter
1074  {
1075  if (!ilChapterHierarchyFormGUI::getPostFirstChild()) // insert after node id
1076  {
1077  $parent_id = $this->tree->getParentId($node_id);
1078  $target = $node_id;
1079  }
1080  else // insert as first child
1081  {
1082  $parent_id = $node_id;
1083  $target = IL_FIRST_NODE;
1084  }
1085  }
1086  for ($i = 1; $i <= $num; $i++)
1087  {
1088  $chap = new ilStructureObject($this->content_object);
1089  $chap->setType("st");
1090  $chap->setTitle("");
1091  $chap->setLMId($this->content_object->getId());
1092  $chap->create();
1093  ilLMObject::putInTree($chap, $parent_id, $target);
1094  }
1095 
1096  $ilCtrl->redirect($this, "view");
1097  }
1098 
1102  function insertSubchapter()
1103  {
1104  global $ilCtrl;
1105 
1106  $this->insertChapter(true);
1107  }
1108 
1112  function insertChapterClip($a_as_sub = false, $a_return = "view")
1113  {
1114  global $ilUser, $ilCtrl, $ilLog;
1115 
1116  $ilLog->write("Insert Chapter From Clipboard");
1117 
1118  include_once("./Modules/LearningModule/classes/class.ilChapterHierarchyFormGUI.php");
1119 
1120  if ($ilUser->getPref("lm_js_chapter_editing") != "disable")
1121  {
1122  //$num = ilChapterHierarchyFormGUI::getPostMulti();
1125  }
1126  else
1127  {
1128  if (!isset($_POST["id"]) || $_POST["id"][0] == -1)
1129  {
1130  $node_id = $this->obj->getId();
1131  $first_child = true;
1132  }
1133  else
1134  {
1135  $node_id = $_POST["id"][0];
1136  $first_child = false;
1137  }
1138  }
1139 
1140  if ($a_as_sub) // as subchapter
1141  {
1142  if (!$first_child) // insert under parent
1143  {
1144  $parent_id = $node_id;
1145  $target = "";
1146  }
1147  else // we shouldnt end up here
1148  {
1149  $ilCtrl->redirect($this, "showHierarchy");
1150  return;
1151  }
1152  }
1153  else // as chapter
1154  {
1155  if (!$first_child) // insert after node id
1156  {
1157  $parent_id = $this->tree->getParentId($node_id);
1158  $target = $node_id;
1159  }
1160  else // insert as first child
1161  {
1162  $parent_id = $node_id;
1163  $target = IL_FIRST_NODE;
1164 
1165  // do not move a chapter in front of a page
1166  $childs = $this->tree->getChildsByType($parent_id, "pg");
1167  if (count($childs) != 0)
1168  {
1169  $target = $childs[count($childs) - 1]["obj_id"];
1170  }
1171  }
1172  }
1173 
1174  // copy and paste
1175  $chapters = $ilUser->getClipboardObjects("st", true);
1176  $copied_nodes = array();
1177 
1178  foreach ($chapters as $chap)
1179  {
1180  $ilLog->write("Call pasteTree, Target LM: ".$this->content_object->getId().", Chapter ID: ".$chap["id"]
1181  .", Parent ID: ".$parent_id.", Target: ".$target);
1182  $cid = ilLMObject::pasteTree($this->content_object, $chap["id"], $parent_id,
1183  $target, $chap["insert_time"], $copied_nodes,
1184  (ilEditClipboard::getAction() == "copy"));
1185  $target = $cid;
1186  }
1187  ilLMObject::updateInternalLinks($copied_nodes);
1188 
1189  if (ilEditClipboard::getAction() == "cut")
1190  {
1191  $ilUser->clipboardDeleteObjectsOfType("pg");
1192  $ilUser->clipboardDeleteObjectsOfType("st");
1194  }
1195 
1196  $this->content_object->checkTree();
1197  $ilCtrl->redirect($this, $a_return);
1198  }
1199 
1204  {
1205  $this->insertChapterClip(true);
1206  }
1207 
1211  function insertPage()
1212  {
1213  global $ilCtrl;
1214 
1215  include_once("./Modules/LearningModule/classes/class.ilChapterHierarchyFormGUI.php");
1216 
1219 
1220  if (!ilChapterHierarchyFormGUI::getPostFirstChild()) // insert after node id
1221  {
1222  $parent_id = $this->tree->getParentId($node_id);
1223  $target = $node_id;
1224  }
1225  else // insert as first child
1226  {
1227  $parent_id = $node_id;
1228  $target = IL_FIRST_NODE;
1229  }
1230 
1231  for ($i = 1; $i <= $num; $i++)
1232  {
1233  $page = new ilLMPageObject($this->content_object);
1234  $page->setType("pg");
1235  $page->setTitle("");
1236  $page->setLMId($this->content_object->getId());
1237  $page->create();
1238  ilLMObject::putInTree($page, $parent_id, $target);
1239  }
1240 
1241  $ilCtrl->redirect($this, "showHierarchy");
1242  }
1243 
1247  function insertPageClip()
1248  {
1249  global $ilCtrl, $ilUser;
1250 
1251  include_once("./Modules/LearningModule/classes/class.ilChapterHierarchyFormGUI.php");
1252 
1253  if ($ilUser->getPref("lm_js_chapter_editing") != "disable")
1254  {
1255  //$num = ilChapterHierarchyFormGUI::getPostMulti();
1258  }
1259  else
1260  {
1261  if(!isset($_POST["id"]) || $_POST["id"][0] == -1)
1262  {
1263  $node_id = $this->obj->getId();
1264  $first_child = true;
1265  }
1266  else
1267  {
1268  $node_id = $_POST["id"][0];
1269  $first_child = false;
1270  }
1271  }
1272 
1273  if (!$first_child) // insert after node id
1274  {
1275  $parent_id = $this->tree->getParentId($node_id);
1276  $target = $node_id;
1277  }
1278  else // insert as first child
1279  {
1280  $parent_id = $node_id;
1281  $target = IL_FIRST_NODE;
1282  }
1283 
1284  // cut and paste
1285  $pages = $ilUser->getClipboardObjects("pg");
1286  $copied_nodes = array();
1287  foreach ($pages as $pg)
1288  {
1289  $cid = ilLMObject::pasteTree($this->content_object, $pg["id"], $parent_id, $target,
1290  $pg["insert_time"], $copied_nodes,
1291  (ilEditClipboard::getAction() == "copy"));
1292  $target = $cid;
1293  }
1294  ilLMObject::updateInternalLinks($copied_nodes);
1295 
1296  if (ilEditClipboard::getAction() == "cut")
1297  {
1298  $ilUser->clipboardDeleteObjectsOfType("pg");
1299  $ilUser->clipboardDeleteObjectsOfType("st");
1301  }
1302 
1303  $ilCtrl->redirect($this, "view");
1304  }
1305 
1306 
1310  function proceedDragDrop()
1311  {
1312  global $ilCtrl;
1313 
1314 //echo "-".$_POST["il_hform_source_id"]."-".$_POST["il_hform_target_id"]."-".$_POST["il_hform_fc"]."-";
1315  $this->content_object->executeDragDrop($_POST["il_hform_source_id"], $_POST["il_hform_target_id"],
1316  $_POST["il_hform_fc"], $_POST["il_hform_as_subitem"]);
1317  $ilCtrl->redirect($this, "showHierarchy");
1318  }
1319 
1320 }
1321 ?>