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 $acts["pastePage"] = "pastePage";
00205 }
00206 $this->setActions($acts);
00207 $this->showActions();
00208
00209
00210
00211 $this->tpl->setVariable("NUM_COLS", 3);
00212
00213 $subobj = array("pg");
00214 $opts = ilUtil::formSelect(12,"new_type",$subobj);
00215
00216 $this->tpl->setCurrentBlock("add_object");
00217 $this->tpl->setVariable("SELECT_OBJTYPE", $opts);
00218
00219 $this->tpl->setVariable("BTN_NAME", "create");
00220 $this->tpl->setVariable("TXT_ADD", $this->lng->txt("insert"));
00221 $this->tpl->parseCurrentBlock();
00222
00223
00224 $this->tpl->setCurrentBlock("form");
00225 $this->tpl->parseCurrentBlock();
00226
00227 }
00228
00229
00230
00231
00232
00233 function subchap()
00234 {
00235 global $tree;
00236
00237 $this->setTabs();
00238
00239 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.structure_edit.html", true);
00240 $num = 0;
00241
00242 $this->tpl->setCurrentBlock("form");
00243 $this->ctrl->setParameter($this, "backcmd", "subchap");
00244 $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
00245 $this->tpl->setVariable("HEADER_TEXT", $this->lng->txt("cont_subchapters"));
00246 $this->tpl->setVariable("CHECKBOX_TOP", IL_FIRST_NODE);
00247
00248 $cnt = 0;
00249 $childs = $this->tree->getChilds($this->obj->getId());
00250 foreach ($childs as $child)
00251 {
00252 if($child["type"] != "st")
00253 {
00254 continue;
00255 }
00256 $this->tpl->setCurrentBlock("table_row");
00257
00258 $css_row = ilUtil::switchColor($cnt++,"tblrow1","tblrow2");
00259
00260
00261 $this->tpl->setVariable("CHECKBOX_ID", $child["obj_id"]);
00262 $this->tpl->setVariable("CSS_ROW", $css_row);
00263 $this->tpl->setVariable("IMG_OBJ", ilUtil::getImagePath("icon_st.gif"));
00264
00265
00266 $this->ctrl->setParameterByClass("ilStructureObjectGUI", "obj_id", $child["obj_id"]);
00267 $link = $this->ctrl->getLinkTargetByClass("ilStructureObjectGUI", "view");
00268 $this->tpl->setVariable("LINK_TARGET", $link);
00269
00270
00271 $this->tpl->setVariable("TEXT_CONTENT", $child["title"]);
00272
00273 $this->tpl->parseCurrentBlock();
00274 }
00275 if($cnt == 0)
00276 {
00277 $this->tpl->setCurrentBlock("notfound");
00278 $this->tpl->setVariable("NUM_COLS", 2);
00279 $this->tpl->setVariable("TXT_OBJECT_NOT_FOUND", $this->lng->txt("obj_not_found"));
00280 $this->tpl->parseCurrentBlock();
00281 }
00282
00283
00284
00285 $this->tpl->setVariable("NUM_COLS", 3);
00286 $acts = array("delete" => "delete", "move" => "moveChapter",
00287 "copy" => "copyChapter");
00288 if(ilEditClipboard::getContentObjectType() == "st")
00289 {
00290 if ($this->tree->isInTree(ilEditClipboard::getContentObjectId())
00291 || ilEditClipboard::getAction() == "copy")
00292 {
00293 $acts["pasteChapter"] = "pasteChapter";
00294 }
00295 }
00296
00297
00298
00299
00300 $this->setActions($acts);
00301 $this->showActions();
00302
00303
00304
00305 $this->tpl->setVariable("NUM_COLS", 3);
00306
00307 $subobj = array("st");
00308 $opts = ilUtil::formSelect(12,"new_type",$subobj);
00309
00310 $this->tpl->setCurrentBlock("add_object");
00311 $this->tpl->setVariable("SELECT_OBJTYPE", $opts);
00312
00313 $this->tpl->setVariable("BTN_NAME", "create");
00314 $this->tpl->setVariable("TXT_ADD", $this->lng->txt("insert"));
00315 $this->tpl->parseCurrentBlock();
00316
00317
00318
00319
00320 $this->tpl->setCurrentBlock("form");
00321 $this->tpl->parseCurrentBlock();
00322
00323 }
00324
00328 function add_cell($val, $link = "")
00329 {
00330 if(!empty($link))
00331 {
00332 $this->tpl->setCurrentBlock("begin_link");
00333 $this->tpl->setVariable("LINK_TARGET", $link);
00334 $this->tpl->parseCurrentBlock();
00335 $this->tpl->touchBlock("end_link");
00336 }
00337
00338 $this->tpl->setCurrentBlock("text");
00339 $this->tpl->setVariable("TEXT_CONTENT", $val);
00340 $this->tpl->parseCurrentBlock();
00341 $this->tpl->setCurrentBlock("table_cell");
00342 $this->tpl->parseCurrentBlock();
00343 }
00344
00345
00349 function save()
00350 {
00351
00352 $this->obj =& new ilStructureObject($this->content_object);
00353
00354 $this->obj->setType("st");
00355 $this->obj->setTitle(ilUtil::stripSlashes($_POST["Fobject"]["title"]));
00356 $this->obj->setDescription(ilUtil::stripSlashes($_POST["Fobject"]["desc"]));
00357 $this->obj->setLMId($this->content_object->getId());
00358 $this->obj->create();
00359
00360 $this->putInTree();
00361
00362
00363 $this->checkTree();
00364
00365 if (!empty($_GET["obj_id"]))
00366 {
00367 $this->ctrl->redirect($this, "subchap");
00368 }
00369
00370 }
00371
00375 function putInTree()
00376 {
00377
00378
00379
00380
00381 if ($_GET["target"] == IL_FIRST_NODE)
00382 {
00383 $tree = new ilTree($this->content_object->getId());
00384 $tree->setTableNames('lm_tree','lm_data');
00385 $tree->setTreeTablePK("lm_id");
00386
00387
00388 $parent_id = (!empty($_GET["obj_id"]))
00389 ? $_GET["obj_id"]
00390 : $tree->getRootId();
00391
00392 $childs =& $tree->getChildsByType($parent_id, "pg");
00393 if (count($childs) != 0)
00394 {
00395 $_GET["target"] = $childs[count($childs) - 1]["obj_id"];
00396 }
00397 }
00398 if (empty($_GET["target"]))
00399 {
00400 $_GET["target"] = IL_LAST_NODE;
00401 }
00402
00403 parent::putInTree();
00404 }
00405
00409 function cutPage()
00410 {
00411 if(!isset($_POST["id"]))
00412 {
00413 $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
00414
00415 }
00416 if(count($_POST["id"]) > 1)
00417 {
00418 $this->ilias->raiseError($this->lng->txt("cont_select_max_one_item"),$this->ilias->error_obj->MESSAGE);
00419 }
00420
00421 if(count($_POST["id"]) == 1 && $_POST["id"][0] == IL_FIRST_NODE)
00422 {
00423 $this->ilias->raiseError($this->lng->txt("cont_select_item"), $this->ilias->error_obj->MESSAGE);
00424 }
00425
00426
00427 ilEditClipboard::storeContentObject("pg",$_POST["id"][0]);
00428
00429 $tree = new ilTree($this->content_object->getId());
00430 $tree->setTableNames('lm_tree','lm_data');
00431 $tree->setTreeTablePK("lm_id");
00432
00433
00434 $cutted = 0;
00435 foreach ($_POST["id"] as $id)
00436 {
00437 if ($id == -1)
00438 {
00439 continue;
00440 }
00441
00442 $obj =& ilLMObjectFactory::getInstance($this->content_object, $id);
00443 $obj->setLMId($this->content_object->getId());
00444 $node_data = $tree->getNodeData($id);
00445
00446 if($tree->isInTree($id))
00447 {
00448 $parent_id = $tree->getParentId($id);
00449 $tree->deleteTree($node_data);
00450
00451
00452 require_once("classes/class.ilHistory.php");
00453 ilHistory::_createEntry($id, "cut",
00454 array(ilLMObject::_lookupTitle($parent_id), $parent_id),
00455 $this->content_object->getType().":pg");
00456 ilHistory::_createEntry($parent_id, "cut_page",
00457 array(ilLMObject::_lookupTitle($id), $id),
00458 $this->content_object->getType().":st");
00459 }
00460 $cutted++;
00461 }
00462
00463
00464 $this->checkTree();
00465
00466 if($cutted > 0)
00467 {
00468 sendInfo($this->lng->txt("msg_cut_clipboard"), true);
00469 }
00470
00471 $this->ctrl->redirect($this, "view");
00472 }
00473
00477 function copyPage()
00478 {
00479 if(!isset($_POST["id"]))
00480 {
00481 $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
00482 }
00483 if(count($_POST["id"]) > 1)
00484 {
00485 $this->ilias->raiseError($this->lng->txt("cont_select_max_one_item"),$this->ilias->error_obj->MESSAGE);
00486 }
00487
00488 if(count($_POST["id"]) == 1 && $_POST["id"][0] == IL_FIRST_NODE)
00489 {
00490 $this->ilias->raiseError($this->lng->txt("cont_select_item"), $this->ilias->error_obj->MESSAGE);
00491 }
00492
00493
00494 ilEditClipboard::storeContentObject("pg",$_POST["id"][0],"copy");
00495
00496 sendInfo($this->lng->txt("msg_copy_clipboard"), true);
00497
00498 $this->ctrl->redirect($this, "view");
00499 }
00500
00504 function pastePage()
00505 {
00506 if(ilEditClipboard::getContentObjectType() != "pg")
00507 {
00508 $this->ilias->raiseError($this->lng->txt("no_page_in_clipboard"),$this->ilias->error_obj->MESSAGE);
00509 }
00510
00511 $tree = new ilTree($this->content_object->getId());
00512 $tree->setTableNames('lm_tree','lm_data');
00513 $tree->setTreeTablePK("lm_id");
00514
00515
00516 $id = ilEditClipboard::getContentObjectId();
00517
00518
00519 if (ilEditClipboard::getAction() == "copy")
00520 {
00521
00522 if (ilLMObject::_lookupContObjID(ilEditClipboard::getContentObjectId())
00523 == $this->content_object->getID())
00524 {
00525 $lm_page = new ilLMPageObject($this->content_object, $id);
00526 $new_page =& $lm_page->copy();
00527 $id = $new_page->getId();
00528 }
00529 else
00530 {
00531
00532 $lm_id = ilLMObject::_lookupContObjID(ilEditClipboard::getContentObjectId());
00533 $lm_obj =& $this->ilias->obj_factory->getInstanceByObjId($lm_id);
00534 $lm_page = new ilLMPageObject($lm_obj, $id);
00535 $new_page =& $lm_page->copyToOtherContObject($this->content_object);
00536 $id = $new_page->getId();
00537 }
00538 }
00539
00540 if (ilEditClipboard::getAction() == "cut")
00541 {
00542
00543 if (ilLMObject::_lookupContObjID(ilEditClipboard::getContentObjectId())
00544 != $this->content_object->getID())
00545 {
00546 $lm_id = ilLMObject::_lookupContObjID(ilEditClipboard::getContentObjectId());
00547 $lm_obj =& $this->ilias->obj_factory->getInstanceByObjId($lm_id);
00548 $lm_page = new ilLMPageObject($lm_obj, $id);
00549 $lm_page->setLMId($this->content_object->getID());
00550 $lm_page->update();
00551 $page =& $lm_page->getPageObject();
00552 $page->buildDom();
00553 $page->setParentId($this->content_object->getID());
00554 $page->update();
00555 }
00556 }
00557
00558 if(!$tree->isInTree($id))
00559 {
00560 if(!isset($_POST["id"]))
00561 {
00562 $target = IL_FIRST_NODE;
00563 }
00564 else
00565 {
00566 $target = $_POST["id"][0];
00567 }
00568 $tree->insertNode($id, $this->obj->getId(), $target);
00569 ilEditClipboard::clear();
00570 }
00571
00572
00573 include_once("classes/class.ilHistory.php");
00574 ilHistory::_createEntry($id, "paste",
00575 array(ilLMObject::_lookupTitle($this->obj->getId()), $this->obj->getId()),
00576 $this->content_object->getType().":pg");
00577 ilHistory::_createEntry($parent_id, "paste_page",
00578 array(ilLMObject::_lookupTitle($id), $id),
00579 $this->content_object->getType().":st");
00580
00581
00582 $this->checkTree();
00583
00584 $this->ctrl->redirect($this, "view");
00585 }
00586
00587
00591 function moveChapter()
00592 {
00593 $cont_obj_gui =& new ilObjContentObjectGUI("",$this->content_object->getRefId(),
00594 true, false);
00595 $cont_obj_gui->moveChapter($this->obj->getId());
00596
00597 $this->ctrl->redirect($this, "subchap");
00598 }
00599
00603 function copyChapter()
00604 {
00605 $cont_obj_gui =& new ilObjContentObjectGUI("",$this->content_object->getRefId(),
00606 true, false);
00607 $cont_obj_gui->copyChapter($this->obj->getId());
00608
00609 $this->ctrl->redirect($this, "subchap");
00610 }
00611
00615 function pasteChapter()
00616 {
00617 $id = ilEditClipboard::getContentObjectId();
00618 if($id == $_POST["id"][0])
00619 {
00620 ilEditClipboard::clear();
00621 $this->subchap();
00622 return;
00623 }
00624 $cont_obj_gui =& new ilObjContentObjectGUI("",$this->content_object->getRefId(),
00625 true, false);
00626 $cont_obj_gui->pasteChapter($this->obj->getId());
00627
00628 $this->ctrl->redirect($this, "subchap");
00629 }
00630
00631
00632
00633
00634
00635
00636 function initConditionHandlerInterface()
00637 {
00638 include_once("classes/class.ilConditionHandlerInterface.php");
00639
00640 $this->condHI =& new ilConditionHandlerInterface($this);
00641 $this->condHI->setBackButtons(array());
00642 $this->condHI->setAutomaticValidation(false);
00643 $this->condHI->setTargetType("st");
00644 $this->condHI->setTargetId($this->obj->getId());
00645 $this->condHI->setTargetTitle($this->obj->getTitle());
00646 }
00647
00648
00652 function cancel()
00653 {
00654 sendInfo($this->lng->txt("msg_cancel"), true);
00655 if ($_GET["obj_id"] != 0)
00656 {
00657 if ($_GET["new_type"] == "pg")
00658 {
00659 $this->ctrl->redirect($this, "view");
00660 }
00661 else
00662 {
00663 $this->ctrl->redirect($this, "subchap");
00664 }
00665 }
00666 }
00667
00668
00672 function setTabs()
00673 {
00674
00675 include_once("classes/class.ilTabsGUI.php");
00676 $tabs_gui =& new ilTabsGUI();
00677
00678 $tabs_gui->getTargetsByObjectType($this, "st");
00679
00680 $tabs_gui->addTarget("meta_data",
00681 $this->ctrl->getLinkTargetByClass('ilmdeditorgui',''),
00682 "meta_data", get_class($this));
00683
00684 $this->tpl->setCurrentBlock("header_image");
00685 $this->tpl->setVariable("IMG_HEADER", ilUtil::getImagePath("icon_st.gif"));
00686 $this->tpl->parseCurrentBlock();
00687 $this->tpl->setCurrentBlock("content");
00688
00689 $this->tpl->setVariable("TABS", $tabs_gui->getHTML());
00690 $this->tpl->setVariable("HEADER",
00691 $this->lng->txt($this->obj->getType()).": ".$this->obj->getTitle());
00692 }
00693
00699 function getTabs(&$tabs_gui)
00700 {
00701
00702 $tabs_gui->addTarget("edit", $this->ctrl->getLinkTarget($this, "view")
00703 , "view", get_class($this));
00704
00705 $tabs_gui->addTarget("cont_preview", $this->ctrl->getLinkTarget($this, "preview")
00706 , "preview", get_class($this));
00707
00708 $tabs_gui->addTarget("meta_data",
00709 $this->ctrl->getLinkTargetByClass('ilmdeditorgui',''),
00710 "meta_data", get_class($this));
00711
00712 $tabs_gui->addTarget("clipboard", $this->ctrl->getLinkTargetByClass("ilEditClipboardGUI", "view")
00713 , "view", "ilEditClipboardGUI");
00714
00715 }
00716
00717 }
00718 ?>