/**
  * Insert Chapter from clipboard
  */
 function insertChapterClip($a_slm_obj, $a_as_sub = false)
 {
     global $ilUser, $ilCtrl, $ilLog;
     // @todo: move this to a service since it can be used here, too
     include_once "./Modules/LearningModule/classes/class.ilEditClipboard.php";
     include_once "./Modules/Scorm2004/classes/class.ilSCORM2004OrganizationHFormGUI.php";
     $node_id = ilSCORM2004OrganizationHFormGUI::getPostNodeId();
     $first_child = ilSCORM2004OrganizationHFormGUI::getPostFirstChild();
     $tree = ilSCORM2004Node::getTree($a_slm_obj->getId());
     if ($a_as_sub) {
         if (!$first_child) {
             $parent_id = $node_id;
             $target = "";
         } else {
             return;
         }
     } else {
         if (!$first_child) {
             $parent_id = $tree->getParentId($node_id);
             $target = $node_id;
         } else {
             $parent_id = $node_id;
             $target = IL_FIRST_NODE;
             // do not move a chapter in front of a sco (maybe never needed)
             $childs = $tree->getChildsByType($parent_id, "sco");
             if (count($childs) != 0) {
                 $target = $childs[count($childs) - 1]["obj_id"];
             }
         }
     }
     // copy and paste
     $chapters = $ilUser->getClipboardObjects("chap", true);
     $copied_nodes = array();
     foreach ($chapters as $chap) {
         $cid = ilSCORM2004Node::pasteTree($a_slm_obj, $chap["id"], $parent_id, $target, $chap["insert_time"], $copied_nodes, ilEditClipboard::getAction() == "copy");
         $target = $cid;
     }
     //ilLMObject::updateInternalLinks($copied_nodes);
     if (ilEditClipboard::getAction() == "cut") {
         $ilUser->clipboardDeleteObjectsOfType("page");
         $ilUser->clipboardDeleteObjectsOfType("chap");
         $ilUser->clipboardDeleteObjectsOfType("sco");
         $ilUser->clipboardDeleteObjectsOfType("ass");
         ilEditClipboard::clear();
     }
 }
 /**
  * Displays GUI to select template for page
  */
 function insertTemplateGUI($a_redirect = true, $a_special_page = false)
 {
     global $ilCtrl, $lng, $tpl;
     include_once "./Modules/Scorm2004/classes/class.ilSCORM2004OrganizationHFormGUI.php";
     $arr_templates = ilPageLayout::activeLayouts($a_special_page, ilPageLayout::MODULE_SCORM);
     $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.scormeditor_page_layout_chooser.html", "Modules/Scorm2004");
     $this->tpl->setCurrentBlock("option_item");
     $count = 0;
     foreach ($arr_templates as $templ) {
         $count++;
         $sel = "";
         $templ->readObject();
         $this->tpl->setVariable("VAL_LAYOUT_TITLE", $templ->getTitle());
         $this->tpl->setVariable("VAL_LAYOUT_IMAGE", $templ->getPreview());
         $this->tpl->setVariable("VAL_LAYOUT_ID", $templ->getId());
         $this->tpl->setVariable("VAL_DISPLAY", "inline");
         if ($count == 1) {
             $this->tpl->setVariable("VAL_CHECKED", "checked");
         }
         if ($count % 4 == 0) {
             $this->tpl->setVariable("END_ROW", "</tr>");
         }
         if ($count == 1 || ($count - 1) % 4 == 0) {
             $this->tpl->setVariable("BEGIN_ROW", "<tr>");
         }
         $this->tpl->parseCurrentBlock();
     }
     //matrix table
     if ($count % 4 != 0) {
         $rest = 4 - $count % 4;
     } else {
         $rest = 0;
     }
     for ($i = 1; $i <= $rest; $i++) {
         $this->tpl->setVariable("VAL_DISPLAY", "none");
         $this->tpl->setVariable("VAL_LAYOUT_ID", $templ->getId());
         if ($i == $rest) {
             $this->tpl->setVariable("END_ROW", "</tr>");
         }
         $this->tpl->parseCurrentBlock();
     }
     //empty cells and closing <tr>
     $this->tpl->setVariable("VAL_NODE_ID", ilSCORM2004OrganizationHFormGUI::getPostNodeId());
     $this->tpl->setVariable("VAL_MULTI", ilSCORM2004OrganizationHFormGUI::getPostMulti());
     $this->tpl->setVariable("VAL_FIRST_CHILD", ilSCORM2004OrganizationHFormGUI::getPostFirstChild());
     $this->tpl->setVariable("VAL_OBJ_ID", ilSCORM2004OrganizationHFormGUI::getPostFirstChild());
     $ilCtrl->saveParameter($this, "obj_id");
     $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
     $this->tpl->setVariable("BTN_NAME", "insertTemplate");
     $this->tpl->setVariable("TXT_CANCEL", $this->lng->txt("cancel"));
     $this->tpl->setVariable("TXT_INSERT", $this->lng->txt("create"));
     $this->tpl->setVariable("CMD_CANCEL", "showOrganization");
     $this->tpl->setVariable("TXT_CANCEL", $this->lng->txt("cancel"));
     $this->tpl->setVariable("TXT_INSERT", $this->lng->txt("insert"));
     $this->tpl->setVariable("TXT_CHANGE", $this->lng->txt("change"));
     if ($a_special_page) {
         $this->tpl->setVariable("TXT_TITLE", $this->lng->txt("sahs_choose_special_page"));
     } else {
         $this->tpl->setVariable("TXT_TITLE", $this->lng->txt("sahs_choose_page_template"));
     }
 }