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