00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 require_once("./content/classes/class.ilLMObjectGUI.php");
00025
00038 class ilStructureObjectGUI extends ilLMObjectGUI
00039 {
00040 var $obj;
00041 var $tree;
00042
00047 function ilStructureObjectGUI(&$a_content_obj, &$a_tree)
00048 {
00049 global $ilias, $tpl, $lng;
00050
00051 parent::ilLMObjectGUI($a_content_obj);
00052 $this->tree =& $a_tree;
00053 }
00054
00060 function setStructureObject(&$a_st_object)
00061 {
00062 $this->obj =& $a_st_object;
00063 $this->actions = $this->objDefinition->getActions("st");
00064 }
00065
00066
00070 function getType()
00071 {
00072 return "st";
00073 }
00074
00078 function &executeCommand()
00079 {
00080
00081 $next_class = $this->ctrl->getNextClass($this);
00082 $cmd = $this->ctrl->getCmd();
00083
00084 switch($next_class)
00085 {
00086 case 'ilmdeditorgui':
00087
00088 $this->setTabs();
00089 include_once 'Services/MetaData/classes/class.ilMDEditorGUI.php';
00090
00091 $md_gui =& new ilMDEditorGUI($this->content_object->getID(),
00092 $this->obj->getId(), $this->obj->getType());
00093 $md_gui->addObserver($this->obj,'MDUpdateListener','General');
00094
00095 $this->ctrl->forwardCommand($md_gui);
00096 break;
00097
00098 case "ilconditionhandlerinterface":
00099 include_once './classes/class.ilConditionHandlerInterface.php';
00100
00101 $this->setTabs();
00102 $this->initConditionHandlerInterface();
00103 $this->ctrl->forwardCommand($this->condHI);
00104 break;
00105
00106 default:
00107 if($cmd == 'listConditions')
00108 {
00109 $this->setTabs();
00110 $this->initConditionHandlerInterface();
00111 $ret =& $this->condHI->executeCommand();
00112 }
00113 elseif(($cmd == "create") && ($_POST["new_type"] == "pg"))
00114 {
00115 $this->setTabs();
00116 $pg_gui =& new ilLMPageObjectGUI($this->content_object);
00117 $ret =& $pg_gui->executeCommand();
00118 }
00119 else
00120 {
00121 $ret =& $this->$cmd();
00122 }
00123 break;
00124 }
00125 }
00126
00127
00131 function create()
00132 {
00133 if ($_GET["obj_id"] != "")
00134 {
00135 $this->setTabs();
00136 }
00137 parent::create();
00138 }
00139
00140
00141
00142
00143
00144 function view()
00145 {
00146 global $tree;
00147
00148 $this->setTabs();
00149
00150 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.structure_edit.html", true);
00151 $num = 0;
00152
00153 $this->tpl->setCurrentBlock("form");
00154 $this->ctrl->setParameter($this, "backcmd", "view");
00155 $this->tpl->setVariable("FORMACTION",
00156 $this->ctrl->getFormAction($this));
00157 $this->tpl->setVariable("HEADER_TEXT", $this->lng->txt("cont_pages"));
00158 $this->tpl->setVariable("CHECKBOX_TOP", IL_FIRST_NODE);
00159
00160 $cnt = 0;
00161 $childs = $this->tree->getChilds($this->obj->getId());
00162 foreach ($childs as $child)
00163 {
00164 if($child["type"] != "pg")
00165 {
00166 continue;
00167 }
00168 $this->tpl->setCurrentBlock("table_row");
00169
00170 $css_row = ilUtil::switchColor($cnt++,"tblrow1","tblrow2");
00171
00172
00173 $this->tpl->setVariable("CHECKBOX_ID", $child["obj_id"]);
00174 $this->tpl->setVariable("CSS_ROW", $css_row);
00175 $this->tpl->setVariable("IMG_OBJ", ilUtil::getImagePath("icon_le.gif"));
00176
00177
00178 $this->ctrl->setParameterByClass("ilLMPageObjectGUI", "obj_id", $child["obj_id"]);
00179 $link = $this->ctrl->getLinkTargetByClass("ilLMPageObjectGUI", "view", "", true);
00180 $this->tpl->setVariable("LINK_TARGET", $link);
00181
00182
00183 $this->tpl->setVariable("TEXT_CONTENT", $child["title"]);
00184
00185 $this->tpl->parseCurrentBlock();
00186 }
00187 if($cnt == 0)
00188 {
00189 $this->tpl->setCurrentBlock("notfound");
00190 $this->tpl->setVariable("NUM_COLS", 3);
00191 $this->tpl->setVariable("TXT_OBJECT_NOT_FOUND", $this->lng->txt("obj_not_found"));
00192 $this->tpl->parseCurrentBlock();
00193 }
00194
00195
00196
00197 $this->tpl->setVariable("NUM_COLS", 3);
00198
00199 $acts = array("delete" => "delete", "cutPage" => "cutPage",
00200 "copyPage" => "copyPage");
00201
00202 if(ilEditClipboard::getContentObjectType() == "pg")
00203 {
00204 if (ilLMObject::_lookupContObjID(ilEditClipboard::getContentObjectId())
00205 == $this->content_object->getId()
00206 || ilEditClipboard::getAction() == "copy")
00207 {
00208 $acts["pastePage"] = "pastePage";
00209 }
00210 }
00211 $this->setActions($acts);
00212 $this->showActions();
00213
00214
00215
00216 $this->tpl->setVariable("NUM_COLS", 3);
00217
00218 $subobj = array("pg");
00219 $opts = ilUtil::formSelect(12,"new_type",$subobj);
00220
00221 $this->tpl->setCurrentBlock("add_object");
00222 $this->tpl->setVariable("SELECT_OBJTYPE", $opts);
00223
00224 $this->tpl->setVariable("BTN_NAME", "create");
00225 $this->tpl->setVariable("TXT_ADD", $this->lng->txt("insert"));
00226 $this->tpl->parseCurrentBlock();
00227
00228
00229 $this->tpl->setCurrentBlock("form");
00230 $this->tpl->parseCurrentBlock();
00231
00232 }
00233
00234
00235
00236
00237
00238 function subchap()
00239 {
00240 global $tree;
00241
00242 $this->setTabs();
00243
00244 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.structure_edit.html", true);
00245 $num = 0;
00246
00247 $this->tpl->setCurrentBlock("form");
00248 $this->ctrl->setParameter($this, "backcmd", "subchap");
00249 $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
00250 $this->tpl->setVariable("HEADER_TEXT", $this->lng->txt("cont_subchapters"));
00251 $this->tpl->setVariable("CHECKBOX_TOP", IL_FIRST_NODE);
00252
00253 $cnt = 0;
00254 $childs = $this->tree->getChilds($this->obj->getId());
00255 foreach ($childs as $child)
00256 {
00257 if($child["type"] != "st")
00258 {
00259 continue;
00260 }
00261 $this->tpl->setCurrentBlock("table_row");
00262
00263 $css_row = ilUtil::switchColor($cnt++,"tblrow1","tblrow2");
00264
00265
00266 $this->tpl->setVariable("CHECKBOX_ID", $child["obj_id"]);
00267 $this->tpl->setVariable("CSS_ROW", $css_row);
00268 $this->tpl->setVariable("IMG_OBJ", ilUtil::getImagePath("icon_st.gif"));
00269
00270
00271 $this->ctrl->setParameterByClass("ilStructureObjectGUI", "obj_id", $child["obj_id"]);
00272 $link = $this->ctrl->getLinkTargetByClass("ilStructureObjectGUI", "view");
00273 $this->tpl->setVariable("LINK_TARGET", $link);
00274
00275
00276 $this->tpl->setVariable("TEXT_CONTENT",
00277 ilStructureObject::_getPresentationTitle($child["obj_id"],
00278 $this->content_object->isActiveNumbering()));
00279
00280 $this->tpl->parseCurrentBlock();
00281 }
00282 if($cnt == 0)
00283 {
00284 $this->tpl->setCurrentBlock("notfound");
00285 $this->tpl->setVariable("NUM_COLS", 2);
00286 $this->tpl->setVariable("TXT_OBJECT_NOT_FOUND", $this->lng->txt("obj_not_found"));
00287 $this->tpl->parseCurrentBlock();
00288 }
00289
00290
00291
00292 $this->tpl->setVariable("NUM_COLS", 3);
00293 $acts = array("delete" => "delete", "move" => "moveChapter",
00294 "copy" => "copyChapter");
00295 if(ilEditClipboard::getContentObjectType() == "st")
00296 {
00297 if ($this->tree->isInTree(ilEditClipboard::getContentObjectId())
00298 || ilEditClipboard::getAction() == "copy")
00299 {
00300 $acts["pasteChapter"] = "pasteChapter";
00301 }
00302 }
00303
00304
00305
00306
00307 $this->setActions($acts);
00308 $this->showActions();
00309
00310
00311
00312 $this->tpl->setVariable("NUM_COLS", 3);
00313
00314 $subobj = array("st");
00315 $opts = ilUtil::formSelect(12,"new_type",$subobj);
00316
00317 $this->tpl->setCurrentBlock("add_object");
00318 $this->tpl->setVariable("SELECT_OBJTYPE", $opts);
00319
00320 $this->tpl->setVariable("BTN_NAME", "create");
00321 $this->tpl->setVariable("TXT_ADD", $this->lng->txt("insert"));
00322 $this->tpl->parseCurrentBlock();
00323
00324
00325
00326
00327 $this->tpl->setCurrentBlock("form");
00328 $this->tpl->parseCurrentBlock();
00329
00330 }
00331
00335 function add_cell($val, $link = "")
00336 {
00337 if(!empty($link))
00338 {
00339 $this->tpl->setCurrentBlock("begin_link");
00340 $this->tpl->setVariable("LINK_TARGET", $link);
00341 $this->tpl->parseCurrentBlock();
00342 $this->tpl->touchBlock("end_link");
00343 }
00344
00345 $this->tpl->setCurrentBlock("text");
00346 $this->tpl->setVariable("TEXT_CONTENT", $val);
00347 $this->tpl->parseCurrentBlock();
00348 $this->tpl->setCurrentBlock("table_cell");
00349 $this->tpl->parseCurrentBlock();
00350 }
00351
00352
00356 function save()
00357 {
00358
00359 $this->obj =& new ilStructureObject($this->content_object);
00360
00361 $this->obj->setType("st");
00362 $this->obj->setTitle(ilUtil::stripSlashes($_POST["Fobject"]["title"]));
00363 $this->obj->setDescription(ilUtil::stripSlashes($_POST["Fobject"]["desc"]));
00364 $this->obj->setLMId($this->content_object->getId());
00365 $this->obj->create();
00366
00367 $this->putInTree();
00368
00369
00370 $this->checkTree();
00371
00372 if (!empty($_GET["obj_id"]))
00373 {
00374 $this->ctrl->redirect($this, "subchap");
00375 }
00376
00377 }
00378
00382 function putInTree()
00383 {
00384
00385
00386
00387
00388 if ($_GET["target"] == IL_FIRST_NODE)
00389 {
00390 $tree = new ilTree($this->content_object->getId());
00391 $tree->setTableNames('lm_tree','lm_data');
00392 $tree->setTreeTablePK("lm_id");
00393
00394
00395 $parent_id = (!empty($_GET["obj_id"]))
00396 ? $_GET["obj_id"]
00397 : $tree->getRootId();
00398
00399 $childs =& $tree->getChildsByType($parent_id, "pg");
00400 if (count($childs) != 0)
00401 {
00402 $_GET["target"] = $childs[count($childs) - 1]["obj_id"];
00403 }
00404 }
00405 if (empty($_GET["target"]))
00406 {
00407 $_GET["target"] = IL_LAST_NODE;
00408 }
00409
00410 parent::putInTree();
00411 }
00412
00416 function cutPage()
00417 {
00418 if(!isset($_POST["id"]))
00419 {
00420 $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
00421
00422 }
00423 if(count($_POST["id"]) > 1)
00424 {
00425 $this->ilias->raiseError($this->lng->txt("cont_select_max_one_item"),$this->ilias->error_obj->MESSAGE);
00426 }
00427
00428 if(count($_POST["id"]) == 1 && $_POST["id"][0] == IL_FIRST_NODE)
00429 {
00430 $this->ilias->raiseError($this->lng->txt("cont_select_item"), $this->ilias->error_obj->MESSAGE);
00431 }
00432
00433
00434 ilEditClipboard::storeContentObject("pg",$_POST["id"][0]);
00435
00436 $tree = new ilTree($this->content_object->getId());
00437 $tree->setTableNames('lm_tree','lm_data');
00438 $tree->setTreeTablePK("lm_id");
00439
00440
00441 $cutted = 0;
00442 foreach ($_POST["id"] as $id)
00443 {
00444 if ($id == -1)
00445 {
00446 continue;
00447 }
00448
00449 $obj =& ilLMObjectFactory::getInstance($this->content_object, $id);
00450 $obj->setLMId($this->content_object->getId());
00451 $node_data = $tree->getNodeData($id);
00452
00453 if($tree->isInTree($id))
00454 {
00455 $parent_id = $tree->getParentId($id);
00456 $tree->deleteTree($node_data);
00457
00458
00459 require_once("classes/class.ilHistory.php");
00460 ilHistory::_createEntry($id, "cut",
00461 array(ilLMObject::_lookupTitle($parent_id), $parent_id),
00462 $this->content_object->getType().":pg");
00463 ilHistory::_createEntry($parent_id, "cut_page",
00464 array(ilLMObject::_lookupTitle($id), $id),
00465 $this->content_object->getType().":st");
00466 }
00467 $cutted++;
00468 }
00469
00470
00471 $this->checkTree();
00472
00473 if($cutted > 0)
00474 {
00475 sendInfo($this->lng->txt("msg_cut_clipboard"), true);
00476 }
00477
00478 $this->ctrl->redirect($this, "view");
00479 }
00480
00484 function copyPage()
00485 {
00486 if(!isset($_POST["id"]))
00487 {
00488 $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
00489 }
00490 if(count($_POST["id"]) > 1)
00491 {
00492 $this->ilias->raiseError($this->lng->txt("cont_select_max_one_item"),$this->ilias->error_obj->MESSAGE);
00493 }
00494
00495 if(count($_POST["id"]) == 1 && $_POST["id"][0] == IL_FIRST_NODE)
00496 {
00497 $this->ilias->raiseError($this->lng->txt("cont_select_item"), $this->ilias->error_obj->MESSAGE);
00498 }
00499
00500
00501 ilEditClipboard::storeContentObject("pg",$_POST["id"][0],"copy");
00502
00503 sendInfo($this->lng->txt("msg_copy_clipboard"), true);
00504
00505 $this->ctrl->redirect($this, "view");
00506 }
00507
00511 function pastePage()
00512 {
00513 if(ilEditClipboard::getContentObjectType() != "pg")
00514 {
00515 $this->ilias->raiseError($this->lng->txt("no_page_in_clipboard"),$this->ilias->error_obj->MESSAGE);
00516 }
00517
00518 $tree = new ilTree($this->content_object->getId());
00519 $tree->setTableNames('lm_tree','lm_data');
00520 $tree->setTreeTablePK("lm_id");
00521
00522
00523 $id = ilEditClipboard::getContentObjectId();
00524
00525
00526 if (ilEditClipboard::getAction() == "copy")
00527 {
00528
00529 if (ilLMObject::_lookupContObjID(ilEditClipboard::getContentObjectId())
00530 == $this->content_object->getID())
00531 {
00532 $lm_page = new ilLMPageObject($this->content_object, $id);
00533 $new_page =& $lm_page->copy();
00534 $id = $new_page->getId();
00535 }
00536 else
00537 {
00538
00539 $lm_id = ilLMObject::_lookupContObjID(ilEditClipboard::getContentObjectId());
00540 $lm_obj =& $this->ilias->obj_factory->getInstanceByObjId($lm_id);
00541 $lm_page = new ilLMPageObject($lm_obj, $id);
00542 $new_page =& $lm_page->copyToOtherContObject($this->content_object);
00543 $id = $new_page->getId();
00544 }
00545 }
00546
00547 if (ilEditClipboard::getAction() == "cut")
00548 {
00549
00550 if (ilLMObject::_lookupContObjID(ilEditClipboard::getContentObjectId())
00551 != $this->content_object->getID())
00552 {
00553 $lm_id = ilLMObject::_lookupContObjID(ilEditClipboard::getContentObjectId());
00554 $lm_obj =& $this->ilias->obj_factory->getInstanceByObjId($lm_id);
00555 $lm_page = new ilLMPageObject($lm_obj, $id);
00556 $lm_page->setLMId($this->content_object->getID());
00557 $lm_page->update();
00558 $page =& $lm_page->getPageObject();
00559 $page->buildDom();
00560 $page->setParentId($this->content_object->getID());
00561 $page->update();
00562 }
00563 }
00564
00565 if(!$tree->isInTree($id))
00566 {
00567 if(!isset($_POST["id"]))
00568 {
00569 $target = IL_FIRST_NODE;
00570 }
00571 else
00572 {
00573 $target = $_POST["id"][0];
00574 }
00575 $tree->insertNode($id, $this->obj->getId(), $target);
00576 ilEditClipboard::clear();
00577 }
00578
00579
00580 include_once("classes/class.ilHistory.php");
00581 ilHistory::_createEntry($id, "paste",
00582 array(ilLMObject::_lookupTitle($this->obj->getId()), $this->obj->getId()),
00583 $this->content_object->getType().":pg");
00584 ilHistory::_createEntry($parent_id, "paste_page",
00585 array(ilLMObject::_lookupTitle($id), $id),
00586 $this->content_object->getType().":st");
00587
00588
00589 $this->checkTree();
00590
00591 $this->ctrl->redirect($this, "view");
00592 }
00593
00594
00598 function moveChapter()
00599 {
00600 $cont_obj_gui =& new ilObjContentObjectGUI("",$this->content_object->getRefId(),
00601 true, false);
00602 $cont_obj_gui->moveChapter($this->obj->getId());
00603
00604 $this->ctrl->redirect($this, "subchap");
00605 }
00606
00610 function copyChapter()
00611 {
00612 $cont_obj_gui =& new ilObjContentObjectGUI("",$this->content_object->getRefId(),
00613 true, false);
00614 $cont_obj_gui->copyChapter($this->obj->getId());
00615
00616 $this->ctrl->redirect($this, "subchap");
00617 }
00618
00622 function pasteChapter()
00623 {
00624 $id = ilEditClipboard::getContentObjectId();
00625 if($id == $_POST["id"][0])
00626 {
00627 ilEditClipboard::clear();
00628 $this->subchap();
00629 return;
00630 }
00631 $cont_obj_gui =& new ilObjContentObjectGUI("",$this->content_object->getRefId(),
00632 true, false);
00633 $cont_obj_gui->pasteChapter($this->obj->getId());
00634
00635 $this->ctrl->redirect($this, "subchap");
00636 }
00637
00638
00639
00640
00641
00642
00643 function initConditionHandlerInterface()
00644 {
00645 include_once("classes/class.ilConditionHandlerInterface.php");
00646
00647 $this->condHI =& new ilConditionHandlerInterface($this);
00648 $this->condHI->setBackButtons(array());
00649 $this->condHI->setAutomaticValidation(false);
00650 $this->condHI->setTargetType("st");
00651 $this->condHI->setTargetId($this->obj->getId());
00652 $this->condHI->setTargetTitle($this->obj->getTitle());
00653 }
00654
00655
00659 function cancel()
00660 {
00661 sendInfo($this->lng->txt("msg_cancel"), true);
00662 if ($_GET["obj_id"] != 0)
00663 {
00664 if ($_GET["new_type"] == "pg")
00665 {
00666 $this->ctrl->redirect($this, "view");
00667 }
00668 else
00669 {
00670 $this->ctrl->redirect($this, "subchap");
00671 }
00672 }
00673 }
00674
00675
00679 function setTabs()
00680 {
00681 global $ilTabs;
00682
00683
00684 #include_once("classes/class.ilTabsGUI.php");
00685 #$tabs_gui =& new ilTabsGUI();
00686
00687 $ilTabs->getTargetsByObjectType($this, "st");
00688
00689 $ilTabs->addTarget("meta_data",
00690 $this->ctrl->getLinkTargetByClass("ilmdeditorgui",''),
00691 "", "ilmdeditorgui");
00692
00693 $this->tpl->setCurrentBlock("header_image");
00694 $this->tpl->setVariable("IMG_HEADER", ilUtil::getImagePath("icon_st.gif"));
00695 $this->tpl->parseCurrentBlock();
00696 $this->tpl->setCurrentBlock("content");
00697
00698 #$this->tpl->setVariable("TABS", $tabs_gui->getHTML());
00699 $this->tpl->setVariable("HEADER",
00700 $this->lng->txt($this->obj->getType()).": ".$this->obj->getTitle());
00701 }
00702
00708 function getTabs(&$tabs_gui)
00709 {
00710
00711 $tabs_gui->addTarget("edit", $this->ctrl->getLinkTarget($this, "view")
00712 , "view", get_class($this));
00713
00714 $tabs_gui->addTarget("cont_preview", $this->ctrl->getLinkTarget($this, "preview")
00715 , "preview", get_class($this));
00716
00717 $tabs_gui->addTarget("meta_data",
00718 $this->ctrl->getLinkTargetByClass('ilmdeditorgui',''),
00719 "", get_class($this));
00720
00721 $tabs_gui->addTarget("clipboard", $this->ctrl->getLinkTargetByClass("ilEditClipboardGUI", "view")
00722 , "view", "ilEditClipboardGUI");
00723
00724 }
00725
00726 }
00727 ?>