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