/**
  * Get Form HTML
  *
  * @param array $questions
  * @param bool $a_has_previous_page
  * @param bool $a_has_next_page
  * @param bool $a_readonly
  * @return string
  */
 function getPageNodes(array $a_questions, $a_has_previous_page = false, $a_has_next_page = false, $a_readonly = false)
 {
     global $ilCtrl, $lng;
     $ttpl = new ilTemplate("tpl.il_svy_svy_page_view_nodes.html", true, true, "Modules/Survey");
     $has_clipboard = (bool) $_SESSION["survey_page_view"][$this->ref_id]["clipboard"];
     // question block ?
     $first_question = $a_questions;
     $first_question = array_shift($first_question);
     if ($first_question["questionblock_id"]) {
         $menu = array();
         if (!$a_readonly && !$has_clipboard) {
             $menu[] = array("cmd" => "editBlock", "text" => $lng->txt("edit"));
         }
         if ($first_question["questionblock_show_blocktitle"]) {
             $block_status = $lng->txt("survey_block_visible");
         } else {
             $block_status = $lng->txt("survey_block_hidden");
         }
         $this->renderPageNode($ttpl, "block", $first_question["questionblock_id"], $first_question["questionblock_title"] . " (" . $block_status . ")", $menu, false, false, $block_status);
     }
     // questions/headings
     include_once "./Modules/SurveyQuestionPool/classes/class.ilObjSurveyQuestionPool.php";
     $questiontypes = ilObjSurveyQuestionPool::_getQuestiontypes();
     $questionpools = array_keys($this->object->getQuestionpoolTitles(true));
     $counter = $question_count;
     $block_done = null;
     foreach ($a_questions as $idx => $question) {
         // drop area
         $menu = array();
         if (!$a_readonly) {
             if (!$has_clipboard) {
                 foreach ($questiontypes as $trans => $item) {
                     $menu[] = array("cmd" => "addQuestion_" . $item["questiontype_id"], "text" => sprintf($lng->txt("svy_page_add_question"), $trans));
                 }
                 if ($this->object->isPoolActive()) {
                     $menu[] = array("cmd" => "addPoolQuestion", "text" => $lng->txt("browse_for_questions"));
                 }
             } else {
                 $menu[] = array("cmd" => "paste", "text" => $lng->txt("survey_dnd_paste"));
             }
         }
         $this->renderPageNode($ttpl, "droparea", $question["question_id"], null, $menu, true);
         // question
         $question_gui = $this->object->getQuestionGUI($question["type_tag"], $question["question_id"]);
         $question_form = $question_gui->getWorkingForm(array(), $this->object->getShowQuestionTitles(), $question["questionblock_show_questiontext"], null, $this->object->getSurveyId());
         $menu = array();
         if (!$a_readonly && !$has_clipboard) {
             $menu[] = array("cmd" => "editQuestion", "text" => $lng->txt("edit"));
             $menu[] = array("cmd" => "cutQuestion", "text" => $lng->txt("cut"));
             $menu[] = array("cmd" => "copyQuestion", "text" => $lng->txt("copy"));
             if (sizeof($a_questions) > 1 && $idx > 0) {
                 $menu[] = array("cmd" => "splitPage", "text" => $lng->txt("survey_dnd_split_page"));
             }
             if ($a_has_next_page) {
                 $menu[] = array("cmd" => "moveNext", "text" => $lng->txt("survey_dnd_move_next"));
             }
             if ($a_has_previous_page) {
                 $menu[] = array("cmd" => "movePrevious", "text" => $lng->txt("survey_dnd_move_previous"));
             }
             $menu[] = array("cmd" => "deleteQuestion", "text" => $lng->txt("delete"));
             // heading
             if ($question["heading"]) {
                 $menu[] = array("cmd" => "editHeading", "text" => $lng->txt("survey_edit_heading"));
                 $menu[] = array("cmd" => "deleteHeading", "text" => $lng->txt("survey_delete_heading"));
             } else {
                 $menu[] = array("cmd" => "addHeading", "text" => $lng->txt("add_heading"));
             }
         }
         if ($first_question["questionblock_show_questiontext"]) {
             $question_title_status = $lng->txt("survey_question_text_visible");
         } else {
             $question_title_status = $lng->txt("survey_question_text_hidden");
         }
         $this->renderPageNode($ttpl, "question", $question["question_id"], $question_form, $menu, false, $question["title"], $question_title_status, $question["heading"]);
         $ilCtrl->setParameter($this, "eqid", "");
     }
     // last position (no question id)
     $menu = array();
     if (!$a_readonly) {
         if (!$has_clipboard) {
             foreach ($questiontypes as $trans => $item) {
                 $menu[] = array("cmd" => "addQuestion_" . $item["questiontype_id"], "text" => sprintf($lng->txt("svy_page_add_question"), $trans));
             }
             if ($this->object->isPoolActive()) {
                 $menu[] = array("cmd" => "addPoolQuestion", "text" => $lng->txt("browse_for_questions"));
             }
         } else {
             $menu[] = array("cmd" => "paste", "text" => $lng->txt("survey_dnd_paste"));
         }
     }
     $this->renderPageNode($ttpl, "page", "end", null, $menu, true);
     return $ttpl->get();
 }
 /**
  * Import data from DB
  */
 protected function importData()
 {
     global $ilCtrl, $lng;
     $survey_questions = $this->object->getSurveyQuestions();
     if (count($survey_questions) > 0) {
         include_once "./Modules/SurveyQuestionPool/classes/class.ilObjSurveyQuestionPool.php";
         $questiontypes = ilObjSurveyQuestionPool::_getQuestiontypes();
         $questionpools = $this->object->getQuestionpoolTitles(true);
         $table_data = array();
         $last_questionblock_id = $position = $block_position = 0;
         foreach ($survey_questions as $question_id => $data) {
             // question block
             if ($data["questionblock_id"] > 0 && $data["questionblock_id"] != $last_questionblock_id) {
                 $id = "qb_" . $data["questionblock_id"];
                 $table_data[$id] = array("id" => $id, "type" => "block", "title" => $data["questionblock_title"]);
                 if (!$this->read_only) {
                     // order
                     if (sizeof($survey_questions) > 1) {
                         $position += 10;
                         $table_data[$id]["position"] = $position;
                     }
                     $table_data[$id]["url"] = $ilCtrl->getLinkTarget($this->parent_obj, $this->parent_cmd) . "&editblock=" . $data["questionblock_id"];
                 }
                 $block_position = 0;
             }
             // question
             $id = $data["question_id"];
             $table_data[$id] = array("id" => $id, "type" => "question", "heading" => $data["heading"], "title" => $data["title"], "description" => $data["description"], "author" => $data["author"], "block_id" => $data["questionblock_id"], "obligatory" => (bool) $data["obligatory"]);
             // question type
             foreach ($questiontypes as $trans => $typedata) {
                 if (strcmp($typedata["type_tag"], $data["type_tag"]) == 0) {
                     $table_data[$id]["question_type"] = $trans;
                 }
             }
             // pool title
             if ($data["original_id"]) {
                 if (isset($questionpools[$data["obj_fi"]])) {
                     $table_data[$id]["pool"] = $questionpools[$data["obj_fi"]];
                 } else {
                     // #11186
                     $table_data[$id]["pool"] = $this->lng->txt("status_no_permission");
                 }
             }
             if (!$this->read_only) {
                 if ($data["obj_fi"] > 0) {
                     // edit url
                     $qpl_ref_id = current(ilObject::_getAllReferences($data["obj_fi"]));
                     $table_data[$id]["url"] = $ilCtrl->getLinkTarget($this->parent_obj, $this->parent_cmd) . "&eqid=" . $id . "&eqpl=" . $qpl_ref_id;
                 }
                 // order
                 if (sizeof($survey_questions) > 1) {
                     if (!$data["questionblock_id"]) {
                         $position += 10;
                         $table_data[$id]["position"] = $position;
                     } else {
                         $block_position += 10;
                         $table_data[$id]["position"] = $block_position;
                     }
                 }
             }
             $last_questionblock_id = $data["questionblock_id"];
         }
     }
     $this->setData($table_data);
 }
 public function questionsObject()
 {
     global $ilToolbar, $ilUser;
     // insert new questions?
     if ($_GET["new_id"] > 0) {
         // add a question to the survey previous created in a questionpool
         $existing = $this->object->getExistingQuestions();
         if (!in_array($_GET["new_id"], $existing)) {
             $inserted = $this->object->insertQuestion($_GET["new_id"]);
             if (!$inserted) {
                 ilUtil::sendFailure($this->lng->txt("survey_error_insert_incomplete_question"));
             }
         }
     }
     $this->questionsSubtabs("questions");
     $hasDatasets = $this->object->_hasDatasets($this->object->getSurveyId());
     $read_only = $hasDatasets;
     // toolbar
     if (!$read_only) {
         $qtypes = array();
         include_once "./Modules/SurveyQuestionPool/classes/class.ilObjSurveyQuestionPool.php";
         foreach (ilObjSurveyQuestionPool::_getQuestiontypes() as $translation => $data) {
             $qtypes[$data["type_tag"]] = $translation;
         }
         $ilToolbar->setFormAction($this->ctrl->getFormAction($this));
         include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
         $types = new ilSelectInputGUI($this->lng->txt("create_new"), "sel_question_types");
         $types->setOptions($qtypes);
         $ilToolbar->addInputItem($types, "");
         $ilToolbar->addFormButton($this->lng->txt("svy_create_question"), "createQuestion");
         if ($this->object->isPoolActive()) {
             $ilToolbar->addSeparator();
             $cmd = $ilUser->getPref('svy_insert_type') == 1 || strlen($ilUser->getPref('svy_insert_type')) == 0 ? 'browseForQuestions' : 'browseForQuestionblocks';
             $ilToolbar->addButton($this->lng->txt("browse_for_questions"), $this->ctrl->getLinkTarget($this, $cmd));
         }
         $ilToolbar->addSeparator();
         $ilToolbar->addButton($this->lng->txt("add_heading"), $this->ctrl->getLinkTarget($this, "addHeading"));
     }
     if ($hasDatasets) {
         $link = $this->ctrl->getLinkTargetByClass("ilsurveyparticipantsgui", "maintenance");
         $link = "<a href=\"" . $link . "\">" . $this->lng->txt("survey_has_datasets_warning_page_view_link") . "</a>";
         ilUtil::sendInfo($this->lng->txt("survey_has_datasets_warning_page_view") . " " . $link);
     }
     // table gui
     include_once "Modules/Survey/classes/class.ilSurveyQuestionTableGUI.php";
     $table = new ilSurveyQuestionTableGUI($this, "questions", $this->object, $read_only);
     $this->tpl->setContent($table->getHTML());
 }
 /**
 * Creates the questions form for the survey object
 */
 public function questionsObject()
 {
     global $rbacsystem, $ilToolbar, $ilUser;
     $this->handleWriteAccess();
     $hasDatasets = $this->object->_hasDatasets($this->object->getSurveyId());
     include_once "./Services/Utilities/classes/class.ilUtil.php";
     if (!$rbacsystem->checkAccess("read", $this->ref_id) && !$rbacsystem->checkAccess("write", $this->ref_id)) {
         // allow only read and write access
         ilUtil::sendInfo($this->lng->txt("cannot_edit_survey"), true);
         $path = $this->tree->getPathFull($this->object->getRefID());
         ilUtil::redirect($this->getReturnLocation("cancel", "./ilias.php?baseClass=ilRepositoryGUI&cmd=frameset&ref_id=" . $path[count($path) - 2]["child"]));
         return;
     }
     if ($_GET["new_id"] > 0) {
         // add a question to the survey previous created in a questionpool
         $existing = $this->object->getExistingQuestions();
         if (!in_array($_GET["new_id"], $existing)) {
             $inserted = $this->object->insertQuestion($_GET["new_id"]);
             if (!$inserted) {
                 ilUtil::sendFailure($this->lng->txt("survey_error_insert_incomplete_question"));
             }
         }
     }
     if ($_GET["eqid"] and $_GET["eqpl"]) {
         ilUtil::redirect("ilias.php?baseClass=ilObjSurveyQuestionPoolGUI&ref_id=" . $_GET["eqpl"] . "&cmd=editQuestionForSurvey&calling_survey=" . $_GET["ref_id"] . "&q_id=" . $_GET["eqid"]);
     }
     $_SESSION["calling_survey"] = $this->object->getRefId();
     unset($_SESSION["survey_id"]);
     if ($_GET["editheading"]) {
         $this->addHeadingObject(false, $_GET["editheading"]);
         return;
     }
     /*
     if ($_GET["up"] > 0)
     {
     	$this->object->moveUpQuestion($_GET["up"]);
     	ilUtil::sendSuccess($this->lng->txt('msg_obj_modified'));
     }
     if ($_GET["down"] > 0)
     {
     	$this->object->moveDownQuestion($_GET["down"]);
     	ilUtil::sendSuccess($this->lng->txt('msg_obj_modified'));
     }
     if ($_GET["qbup"] > 0)
     {
     	$this->object->moveUpQuestionblock($_GET["qbup"]);
     	ilUtil::sendSuccess($this->lng->txt('msg_obj_modified'));
     }
     if ($_GET["qbdown"] > 0)
     {
     	$this->object->moveDownQuestionblock($_GET["qbdown"]);
     	ilUtil::sendSuccess($this->lng->txt('msg_obj_modified'));
     }
     */
     if ($_GET["removeheading"]) {
         $this->confirmRemoveHeadingForm();
         return;
     }
     if ($_GET["editblock"]) {
         $this->defineQuestionblock($_GET["editblock"]);
         return;
     }
     if ($_GET["add"]) {
         // called after a new question was created from a questionpool
         $selected_array = array();
         array_push($selected_array, $_GET["add"]);
         ilUtil::sendQuestion($this->lng->txt("ask_insert_questions"));
         $this->insertQuestionsForm($selected_array);
         return;
     }
     $this->questionsSubtabs("questions");
     $read_only = !$rbacsystem->checkAccess("write", $this->ref_id) || $hasDatasets;
     // toolbar
     if (!$read_only) {
         $qtypes = array();
         include_once "./Modules/SurveyQuestionPool/classes/class.ilObjSurveyQuestionPool.php";
         foreach (ilObjSurveyQuestionPool::_getQuestiontypes() as $translation => $data) {
             $qtypes[$data["type_tag"]] = $translation;
         }
         $ilToolbar->setFormAction($this->ctrl->getFormAction($this));
         include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
         $types = new ilSelectInputGUI($this->lng->txt("create_new"), "sel_question_types");
         $types->setOptions($qtypes);
         $ilToolbar->addInputItem($types, "");
         $ilToolbar->addFormButton($this->lng->txt("svy_create_question"), "createQuestion");
         if ($this->object->isPoolActive()) {
             $ilToolbar->addSeparator();
             $cmd = $ilUser->getPref('svy_insert_type') == 1 || strlen($ilUser->getPref('svy_insert_type')) == 0 ? 'browseForQuestions' : 'browseForQuestionblocks';
             $ilToolbar->addButton($this->lng->txt("browse_for_questions"), $this->ctrl->getLinkTarget($this, $cmd));
         }
         $ilToolbar->addSeparator();
         $ilToolbar->addButton($this->lng->txt("add_heading"), $this->ctrl->getLinkTarget($this, "addHeading"));
     }
     if ($hasDatasets) {
         // ilUtil::sendInfo($this->lng->txt("survey_has_datasets_warning"));
         $link = $this->ctrl->getLinkTarget($this, "maintenance");
         $link = "<a href=\"" . $link . "\">" . $this->lng->txt("survey_has_datasets_warning_page_view_link") . "</a>";
         ilUtil::sendInfo($this->lng->txt("survey_has_datasets_warning_page_view") . " " . $link);
     }
     // table gui
     include_once "Modules/Survey/classes/class.ilSurveyQuestionTableGUI.php";
     $table = new ilSurveyQuestionTableGUI($this, "questions", $this->object, $read_only);
     $this->tpl->setContent($table->getHTML());
 }