ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilSurveyPageGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3
15{
19 protected $ctrl;
20
24 protected $rbacsystem;
25
29 protected $db;
30
34 protected $tabs;
35
39 protected $tpl;
40
44 protected $toolbar;
45
49 protected $user;
50
51 protected $ref_id; // [int]
52 protected $lng; // [object]
53 protected $object; // [ilObjSurvey]
54 protected $editor_gui; // [ilSurveyEditorGUI]
55 protected $current_page; // [int]
56 protected $has_previous_page; // [bool]
57 protected $has_next_page; // [bool]
58 protected $has_datasets; // [bool]
59 protected $use_pool; // [bool]
60
64 protected $log;
65
72 public function __construct(ilObjSurvey $a_survey, ilSurveyEditorGUI $a_survey_editor_gui)
73 {
74 global $DIC;
75
76 $this->lng = $DIC->language();
77 $this->ctrl = $DIC->ctrl();
78 $this->rbacsystem = $DIC->rbac()->system();
79 $this->db = $DIC->database();
80 $this->tabs = $DIC->tabs();
81 $this->tpl = $DIC["tpl"];
82 $this->toolbar = $DIC->toolbar();
83 $this->user = $DIC->user();
84 $this->editor_gui = $a_survey_editor_gui;
85 $this->ref_id = $a_survey->getRefId();
86 $this->object = $a_survey;
87 $this->log = ilLoggerFactory::getLogger("svy");
88 }
89
93 public function executeCommand()
94 {
98
99 $cmd = $ilCtrl->getCmd("renderPage");
100 $next_class = $ilCtrl->getNextClass($this);
101
102 switch ($next_class) {
103 default:
104 $this->determineCurrentPage();
105
106 $has_content = false;
107
108 if ($rbacsystem->checkAccess("write", $this->ref_id)) {
109 // add page?
110 if ($_REQUEST["new_id"]) {
111 $this->insertNewQuestion($_REQUEST["new_id"]);
112 }
113
114 // subcommands
115 if ($_REQUEST["il_hform_subcmd"]) {
116 $subcmd = $_REQUEST["il_hform_subcmd"];
117
118 // make sure that it is set for current and next requests
119 $ilCtrl->setParameter($this->editor_gui, "pgov", $this->current_page);
120 $_REQUEST["pgov"] = $this->current_page;
121
122 $id = explode("_", $_REQUEST["il_hform_node"]);
123 $id = (int) $id[1];
124
125 // multi operation
126 if (substr($_REQUEST["il_hform_subcmd"], 0, 5) == "multi") {
127 if ($_REQUEST["il_hform_multi"]) {
128 // removing types as we only allow questions anyway
129 $id = array();
130 foreach (explode(";", $_REQUEST["il_hform_multi"]) as $item) {
131 $id[] = (int) array_pop(explode("_", $item));
132 }
133
134 if ($subcmd == "multiDelete") {
135 $subcmd = "deleteQuestion";
136 }
137 } else {
138 // #9525
139 if ($subcmd == "multiDelete") {
140 ilUtil::sendFailure($lng->txt("no_checkbox"), true);
141 $ilCtrl->redirect($this, "renderPage");
142 } else {
143 ilUtil::sendFailure($lng->txt("no_checkbox"));
144 }
145 }
146 }
147
148 if (substr($subcmd, 0, 11) == "addQuestion") {
149 $type = explode("_", $subcmd);
150 $type = (int) $type[1];
151 $has_content = $this->addQuestion($type, $this->object->isPoolActive(), $id, $_REQUEST["il_hform_node"]);
152 } else {
153 $has_content = $this->$subcmd($id, $_REQUEST["il_hform_node"]);
154 }
155 }
156 }
157
158 if (!$has_content) {
159 $this->$cmd();
160 }
161 break;
162 }
163 }
164
168 public function determineCurrentPage()
169 {
170 $current_page = (int) $_REQUEST["jump"];
171 if (!$current_page) {
172 $current_page = (int) $_REQUEST["pgov"];
173 }
174 if (!$current_page) {
175 $current_page = (int) $_REQUEST["pg"];
176 }
177 if (!$current_page) {
178 $current_page = 1;
179 }
180 $this->current_page = $current_page;
181 }
182
190 protected function appendNewQuestionToSurvey($a_new_id, $a_duplicate = true, $a_force_duplicate = false)
191 {
193
194 $this->log->debug("append question, id: " . $a_new_id . ", duplicate: " . $a_duplicate . ", force: " . $a_force_duplicate);
195
196 // get maximum sequence index in test
197 $result = $ilDB->queryF(
198 "SELECT survey_question_id FROM svy_svy_qst WHERE survey_fi = %s",
199 array('integer'),
200 array($this->object->getSurveyId())
201 );
202 $sequence = $result->numRows();
203
204 // create duplicate if pool question (or forced for question blocks copy)
205 if ($a_duplicate) {
206 // this does nothing if this is not a pool question and $a_force_duplicate is false
207 $survey_question_id = $this->object->duplicateQuestionForSurvey($a_new_id, $a_force_duplicate);
208 }
209 // used by copy & paste
210 else {
211 $survey_question_id = $a_new_id;
212 }
213
214 // check if question is not already in the survey, see #22018
215 if ($this->object->isQuestionInSurvey($survey_question_id)) {
216 return $survey_question_id;
217 }
218
219 // append to survey
220 $next_id = $ilDB->nextId('svy_svy_qst');
221 $affectedRows = $ilDB->manipulateF(
222 "INSERT INTO svy_svy_qst (survey_question_id, survey_fi," .
223 "question_fi, sequence, tstamp) VALUES (%s, %s, %s, %s, %s)",
224 array('integer', 'integer', 'integer', 'integer', 'integer'),
225 array($next_id, $this->object->getSurveyId(), $survey_question_id, $sequence, time())
226 );
227
228 $this->log->debug("insert svy_svy_qst, id: " . $next_id . ", qfi: " . $survey_question_id . ", seq: " . $sequence);
229
230 return $survey_question_id;
231 }
232
238 public function insertNewQuestion($a_new_id)
239 {
243
244 if (!SurveyQuestion::_isComplete($a_new_id)) {
245 ilUtil::sendFailure($lng->txt("survey_error_insert_incomplete_question"));
246 } else {
247 $a_new_id = $this->appendNewQuestionToSurvey($a_new_id);
248 $this->object->loadQuestionsFromDb();
249
250 $pos = $_REQUEST["pgov_pos"];
251
252 // a[fter]/b[efore] on same page
253 if (substr($pos, -1) != "c") {
254 // block handling
255 $current = $this->object->getSurveyPages();
256 $current = $current[$this->current_page - 1];
257 if (sizeof($current) == 1) {
258 // as questions are moved to first block question
259 // always use existing as first
260 // the new question is moved later on (see below)
261 $this->object->createQuestionblock(
262 $this->getAutoBlockTitle(),
263 true,
264 false,
265 array((int) $pos, $a_new_id)
266 );
267 } else {
268 $block_id = array_pop($current);
269 $block_id = $block_id["questionblock_id"];
270
271 $this->object->addQuestionToBlock($a_new_id, $block_id);
272 }
273 }
274 // c: as new page (from toolbar/pool)
275 else {
276 // after given question
277 if ((int) $pos) {
278 $pos = (int) $pos . "a";
279 $this->current_page++;
280 }
281 // at the beginning
282 else {
283 $first = $this->object->getSurveyPages();
284 $first = $first[0];
285 $first = array_shift($first);
286 $pos = $first["question_id"] . "b";
287 $this->current_page = 1;
288 }
289 }
290
291 // move to target position
292 $this->object->moveQuestions(
293 array($a_new_id),
294 (int) $pos,
295 ((substr($pos, -1) == "a") ? 1 : 0)
296 );
297
298 $this->object->fixSequenceStructure();
299 }
300 }
301
307 public function insertQuestionBlock($a_block_id)
308 {
309 $new_ids = array();
310 $question_ids = $this->object->getQuestionblockQuestionIds($a_block_id);
311 foreach ($question_ids as $qid) {
312 $new_ids[] = $this->appendNewQuestionToSurvey($qid, true, true);
313 }
314
315 if (sizeof($new_ids)) {
316 $this->object->loadQuestionsFromDb();
317
318 $pos = $_REQUEST["pgov_pos"];
319
320 // a[fter]/b[efore] on same page
321 if (substr($pos, -1) != "c") {
322 // block handling
323 $current = $this->object->getSurveyPages();
324 $current = $current[$this->current_page - 1];
325 if (sizeof($current) == 1) {
326 // as questions are moved to first block question
327 // always use existing as first
328 // the new question is moved later on (see below)
329 $this->object->createQuestionblock(
330 $this->getAutoBlockTitle(),
331 true,
332 false,
333 array((int) $pos) + $new_ids
334 );
335 } else {
336 $block_id = array_pop($current);
337 $block_id = $block_id["questionblock_id"];
338
339 foreach ($new_ids as $qid) {
340 $this->object->addQuestionToBlock($qid, $block_id);
341 }
342 }
343 }
344 // c: as new page (from toolbar/pool)
345 else {
346 // re-create block
347 $this->object->createQuestionblock(
348 $this->getAutoBlockTitle(),
349 true,
350 false,
351 $new_ids
352 );
353
354 // after given question
355 if ((int) $pos) {
356 $pos = (int) $pos . "a";
357 }
358 // at the beginning
359 else {
360 $first = $this->object->getSurveyPages();
361 $first = $first[0];
362 $first = array_shift($first);
363 $pos = $first["question_id"] . "b";
364 }
365 }
366
367 // move to target position
368 $this->object->moveQuestions(
369 $new_ids,
370 (int) $pos,
371 ((substr($pos, -1) == "a") ? 1 : 0)
372 );
373 }
374 }
375
384 protected function addQuestion($a_type, $a_use_pool, $a_pos, $a_special_position)
385 {
387 $ilTabs = $this->tabs;
388
389 // get translated type
391 foreach ($questiontypes as $item) {
392 if ($item["questiontype_id"] == $a_type) {
393 $type_trans = $item["type_tag"];
394 }
395 }
396
397 $id = $a_pos;
398
399 // new page behind current (from toolbar)
400 if ($a_special_position == "toolbar") {
401 $id = $this->object->getSurveyPages();
402 if ($a_pos && $a_pos != "fst") {
403 $id = $id[$a_pos - 1];
404 $id = array_pop($id);
405 $id = $id["question_id"] . "c";
406 } else {
407 $id = "0c";
408 }
409 }
410 // append current page
411 elseif ($a_special_position == "page_end") {
412 $id = $this->object->getSurveyPages();
413 $id = $id[$this->current_page - 1];
414 $id = array_pop($id);
415 $id = $id["question_id"] . "a";
416 } else {
417 $id .= "b";
418 }
419
420 if ($a_use_pool) {
421 $_GET["sel_question_types"] = $type_trans;
422 $_REQUEST["pgov_pos"] = $id;
423 $ilCtrl->setParameter($this->editor_gui, "pgov_pos", $id);
424 if (!$_POST["usage"]) {
425 $ilTabs->clearSubTabs(); // #17193
426 $this->editor_gui->createQuestionObject();
427 } else {
428 $this->editor_gui->executeCreateQuestionObject();
429 }
430 return true;
431 } else {
432 // create question and redirect to question form
433
434 $q_gui = SurveyQuestionGUI::_getQuestionGUI($type_trans);
435 $q_gui->object->setObjId($this->object->getId());
436 $q_gui->object->createNewQuestion();
437 $q_gui_class = get_class($q_gui);
438
439 // #12531
440 $ilCtrl->setParameterByClass($q_gui_class, "pgov", $this->current_page);
441 $ilCtrl->setParameterByClass($q_gui_class, "pgov_pos", $id);
442 $ilCtrl->setParameterByClass($q_gui_class, "ref_id", $this->ref_id);
443 $ilCtrl->setParameterByClass($q_gui_class, "new_for_survey", $this->ref_id);
444 $ilCtrl->setParameterByClass($q_gui_class, "q_id", $q_gui->object->getId());
445 $ilCtrl->setParameterByClass($q_gui_class, "sel_question_types", $q_gui->getQuestionType());
446 $ilCtrl->redirectByClass($q_gui_class, "editQuestion");
447 }
448 }
449
455 protected function cutQuestion($a_id)
456 {
458
459 ilUtil::sendSuccess($lng->txt("survey_questions_to_clipboard_cut"));
460 $this->suppress_clipboard_msg = true;
461
462 $_SESSION["survey_page_view"][$this->ref_id]["clipboard"] = array(
463 "source" => $this->current_page,
464 "nodes" => array($a_id),
465 "mode" => "cut");
466 }
467
473 protected function copyQuestion($a_id)
474 {
476
477 ilUtil::sendSuccess($lng->txt("survey_questions_to_clipboard_copy"));
478 $this->suppress_clipboard_msg = true;
479
480 $_SESSION["survey_page_view"][$this->ref_id]["clipboard"] = array(
481 "source" => $this->current_page,
482 "nodes" => array($a_id),
483 "mode" => "copy");
484 }
485
491 protected function multiCut($a_id)
492 {
494
495 if (is_array($a_id)) {
496 ilUtil::sendSuccess($lng->txt("survey_questions_to_clipboard_cut"));
497 $this->suppress_clipboard_msg = true;
498
499 $_SESSION["survey_page_view"][$this->ref_id]["clipboard"] = array(
500 "source" => $this->current_page,
501 "nodes" => $a_id,
502 "mode" => "cut");
503 }
504 }
505
511 protected function multiCopy($a_id)
512 {
514
515 if (is_array($a_id)) {
516 ilUtil::sendSuccess($lng->txt("survey_questions_to_clipboard_copy"));
517 $this->suppress_clipboard_msg = true;
518
519 $_SESSION["survey_page_view"][$this->ref_id]["clipboard"] = array(
520 "source" => $this->current_page,
521 "nodes" => $a_id,
522 "mode" => "copy");
523 }
524 }
525
529 protected function clearClipboard()
530 {
531 $_SESSION["survey_page_view"][$this->ref_id]["clipboard"] = null;
532 }
533
539 protected function paste($a_id)
540 {
541 $data = $_SESSION["survey_page_view"][$this->ref_id]["clipboard"];
542 $pages = $this->object->getSurveyPages();
543 $source = $pages[$data["source"] - 1];
544 $target = $pages[$this->current_page - 1];
545
546 // #12558 - use order of source page
547 $nodes = array();
548 foreach ($source as $src_qst) {
549 if (in_array($src_qst["question_id"], $data["nodes"])) {
550 $nodes[] = $src_qst["question_id"];
551 }
552 }
553
554 // append to last position?
555 $pos = 0;
556 if ($_REQUEST["il_hform_node"] == "page_end") {
557 $a_id = $target;
558 $a_id = array_pop($a_id);
559 $a_id = $a_id["question_id"];
560 $pos = 1;
561 }
562
563 // cut
564 if ($data["mode"] == "cut") {
565 // special case: paste cut on same page (no block handling needed)
566 if ($data["source"] == $this->current_page) {
567 // re-order nodes in page
568 if (sizeof($nodes) <= sizeof($source)) {
569 $this->object->moveQuestions($nodes, $a_id, $pos);
570 }
571 $this->clearClipboard();
572 return;
573 } else {
574 // only if source has block
575 $source_block_id = false;
576 if (sizeof($source) > 1) {
577 $source_block_id = $source;
578 $source_block_id = array_shift($source_block_id);
579 $source_block_id = $source_block_id["questionblock_id"];
580
581 // remove from block
582 if (sizeof($source) > sizeof($nodes)) {
583 foreach ($nodes as $qid) {
584 $this->object->removeQuestionFromBlock($qid, $source_block_id);
585 }
586 }
587 // remove complete block
588 else {
589 $this->object->unfoldQuestionblocks(array($source_block_id));
590 }
591 }
592
593 // page will be "deleted" by operation
594 if (sizeof($source) == sizeof($nodes) && $data["source"] < $this->current_page) {
595 $this->current_page--;
596 }
597 }
598 }
599
600 // copy
601 elseif ($data["mode"] == "copy") {
602 $titles = array();
603 foreach ($this->object->getSurveyPages() as $page) {
604 foreach ($page as $question) {
605 $titles[] = $question["title"];
606 }
607 }
608
609 // copy questions
610 $question_pointer = array();
611 foreach ($nodes as $qid) {
612 // create new questions
613 $question = ilObjSurvey::_instanciateQuestion($qid);
614
615 // handle exisiting copies
616 $title = $question->getTitle();
617 $max = 0;
618 foreach ($titles as $existing_title) {
619 #21278 preg_quote with delimiter
620 if (preg_match("/" . preg_quote($title, "/") . " \‍(([0-9]+)\‍)$/", $existing_title, $match)) {
621 $max = max($match[1], $max);
622 }
623 }
624 if ($max) {
625 $title .= " (" . ($max + 1) . ")";
626 } else {
627 $title .= " (2)";
628 }
629 $titles[] = $title;
630 $question->setTitle($title);
631
632 $question->id = -1;
633 $question->saveToDb();
634
635 $question_pointer[$qid] = $question->getId();
636 $this->appendNewQuestionToSurvey($question->getId(), false);
637 }
638
639 // copy textblocks
640 $this->object->cloneTextblocks($question_pointer);
641
642 $this->object->loadQuestionsFromDb();
643
644 $nodes = array_values($question_pointer);
645 }
646
647
648 // paste
649
650 // create new block
651 if (sizeof($target) == 1) {
652 $nodes = array_merge(array($a_id), $nodes);
653
654 // moveQuestions() is called within
655 $this->object->createQuestionblock(
656 $this->getAutoBlockTitle(),
657 true,
658 false,
659 $nodes
660 );
661 }
662 // add to existing block
663 else {
664 $target_block_id = $target;
665 $target_block_id = array_shift($target_block_id);
666 $target_block_id = $target_block_id["questionblock_id"];
667
668 foreach ($nodes as $qid) {
669 $this->object->addQuestionToBlock($qid, $target_block_id);
670 }
671
672 // move to new position
673 $this->object->moveQuestions($nodes, $a_id, $pos);
674 }
675
676 $this->clearClipboard();
677 }
678
682 protected function dnd()
683 {
684 $source_id = (int) array_pop(explode("_", $_REQUEST["il_hform_source"]));
685 if ($_REQUEST["il_hform_target"] != "droparea_end") {
686 $target_id = (int) array_pop(explode("_", $_REQUEST["il_hform_target"]));
687 $pos = 0;
688 } else {
689 $page = $this->object->getSurveyPages();
690 $page = $page[$this->current_page - 1];
691 $last = array_pop($page);
692 $target_id = (int) $last["question_id"];
693 $pos = 1;
694 }
695 if ($source_id != $target_id) {
696 $this->object->moveQuestions(array($source_id), $target_id, $pos);
697 }
698 }
699
704 protected function deleteBlock()
705 {
708
709 $ilCtrl->setParameter($this->editor_gui, "pgov", $this->current_page);
710 ilUtil::sendQuestion($lng->txt("remove_questions"));
711
712 $page = $this->object->getSurveyPages();
713 $page = $page[$this->current_page - 1];
714
715 // #10567
716 if ($_REQUEST["csum"] != md5(print_r($page, true))) {
717 $ilCtrl->redirect($this, "renderPage");
718 }
719
720 $page = array_shift($page);
721 $block_id = $page["questionblock_id"];
722 if ($block_id) {
723 $this->editor_gui->removeQuestionsForm(array($block_id), array(), array());
724 } else {
725 $this->editor_gui->removeQuestionsForm(array(), array($page["question_id"]), array());
726 }
727 }
728
734 protected function deleteQuestion($a_id)
735 {
737
738 if (!is_array($a_id)) {
739 $a_id = array($a_id);
740 }
741
742 $ilCtrl->setParameter($this->editor_gui, "pgov", $this->current_page);
743 $this->editor_gui->removeQuestionsForm(array(), $a_id, array());
744 return true;
745 }
746
750 protected function confirmRemoveQuestions()
751 {
753
754 // gather ids
755 $ids = array();
756 foreach ($_POST as $key => $value) {
757 if (preg_match("/id_(\d+)/", $key, $matches)) {
758 array_push($ids, $matches[1]);
759 }
760 }
761
762
763 $pages = $this->object->getSurveyPages();
764 $source = $pages[$this->current_page - 1];
765
766 $block_id = $source;
767 $block_id = array_shift($block_id);
768 $block_id = $block_id["questionblock_id"];
769
770 if (sizeof($ids) && sizeof($source) > sizeof($ids)) {
771 // block is obsolete
772 if (sizeof($source) - sizeof($ids) == 1) {
773 $this->object->unfoldQuestionblocks(array($block_id));
774 }
775 // block will remain, remove question(s) from block
776 else {
777 foreach ($ids as $qid) {
778 $this->object->removeQuestionFromBlock($qid, $block_id);
779 }
780 }
781
782 $this->object->removeQuestions($ids, array());
783 }
784 // all items on page
785 else {
786 // remove complete block
787 if ($block_id) {
788 $this->object->removeQuestions(array(), array($block_id));
789 }
790 // remove single question
791 else {
792 $this->object->removeQuestions($ids, array());
793 }
794
795 // render previous page
796 if ($this->current_page > 1) {
797 $this->current_page--;
798 }
799 }
800
801 $this->object->saveCompletionStatus();
802
803 // #10567
804 $ilCtrl->setParameter($this, "pgov", $this->current_page);
805 $ilCtrl->redirect($this, "renderPage");
806 }
807
813 protected function editBlock($a_id)
814 {
815 $this->callEditor("editQuestionblockObject", "bl_id", $a_id);
816 return true;
817 }
818
824 protected function addHeading($a_id)
825 {
826 $this->callEditor("addHeadingObject", "q_id", $a_id);
827 return true;
828 }
829
835 protected function editHeading($a_id)
836 {
837 $this->callEditor("editHeadingObject", "q_id", $a_id);
838 return true;
839 }
840
846 protected function deleteHeading($a_id)
847 {
848 $this->callEditor("removeHeadingObject", "q_id", $a_id);
849 return true;
850 }
851
852 protected function callEditor($a_cmd, $a_param, $a_value)
853 {
854 $ilTabs = $this->tabs;
855
856 $ilTabs->clearSubTabs();
857 $_REQUEST[$a_param] = $a_value;
858
859 call_user_func(array($this->editor_gui, $a_cmd));
860 }
861
867 protected function splitPage($a_id)
868 {
869 $pages = $this->object->getSurveyPages();
870 $source = $pages[$this->current_page - 1];
871
872 $block_questions = array();
873 $add = $block_id = false;
874 foreach ($source as $idx => $item) {
875 if ($item["question_id"] == $a_id) {
876 $block_id = $item["questionblock_id"];
877 $add = $idx;
878 }
879 if ($add) {
880 $block_questions[] = $item["question_id"];
881 }
882 }
883
884 // just 1 question left: block is obsolete
885 if ($add == 1) {
886 $this->object->unfoldQuestionblocks(array($block_id));
887 }
888 // remove questions from block
889 else {
890 foreach ($block_questions as $qid) {
891 $this->object->removeQuestionFromBlock($qid, $block_id);
892 }
893 }
894
895 // more than 1 moved?
896 if (sizeof($block_questions) > 1) {
897 // create new block and move target questions
898 $this->object->createQuestionblock(
899 $this->getAutoBlockTitle(),
900 true,
901 false,
902 $block_questions
903 );
904 }
905
906 $this->current_page++;
907 }
908
914 protected function moveNext($a_id)
915 {
916 $pages = $this->object->getSurveyPages();
917 $source = $pages[$this->current_page - 1];
918 $target = $pages[$this->current_page];
919 if (sizeof($target)) {
920 $target_id = $target;
921 $target_id = array_shift($target_id);
922 $target_block_id = $target_id["questionblock_id"];
923 $target_id = $target_id["question_id"];
924
925 // nothing to do if no block
926 if (sizeof($source) > 1) {
927 $block_id = $source;
928 $block_id = array_shift($block_id);
929 $block_id = $block_id["questionblock_id"];
930
931 // source pages block is obsolete
932 if (sizeof($source) == 2) {
933 // delete block
934 $this->object->unfoldQuestionblocks(array($block_id));
935 } else {
936 // remove question from block
937 $this->object->removeQuestionFromBlock($a_id, $block_id);
938 }
939 }
940
941 // move source question to target
942 $this->object->moveQuestions(array($a_id), $target_id, 0);
943
944 // new page has no block yet
945 if (sizeof($target) < 2) {
946 // create block and move target question and source into block
947 $this->object->createQuestionblock(
948 $this->getAutoBlockTitle(),
949 true,
950 false,
951 array($a_id, $target_id)
952 );
953 } else {
954 // add source question to block
955 $this->object->addQuestionToBlock($a_id, $target_block_id);
956 }
957
958 // only if current page is not "deleted"
959 if (sizeof($source) > 1) {
960 $this->current_page++;
961 }
962 }
963 }
964
970 protected function movePrevious($a_id)
971 {
972 $pages = $this->object->getSurveyPages();
973 $source = $pages[$this->current_page - 1];
974 $target = $pages[$this->current_page - 2];
975 if (sizeof($target)) {
976 $target_id = $target;
977 $target_id = array_pop($target_id);
978 $target_block_id = $target_id["questionblock_id"];
979 $target_id = $target_id["question_id"];
980
981 // nothing to do if no block
982 if (sizeof($source) > 1) {
983 $block_id = $source;
984 $block_id = array_shift($block_id);
985 $block_id = $block_id["questionblock_id"];
986
987 // source pages block is obsolete
988 if (sizeof($source) == 2) {
989 // delete block
990 $this->object->unfoldQuestionblocks(array($block_id));
991 } else {
992 // remove question from block
993 $this->object->removeQuestionFromBlock($a_id, $block_id);
994 }
995 }
996
997 // move source question to target
998 $this->object->moveQuestions(array($a_id), $target_id, 1);
999
1000 // new page has no block yet
1001 if (sizeof($target) < 2) {
1002 // create block and move target question and source into block
1003 $this->object->createQuestionblock(
1004 $this->getAutoBlockTitle(),
1005 true,
1006 false,
1007 array($target_id, $a_id)
1008 );
1009 } else {
1010 // add source question to block
1011 $this->object->addQuestionToBlock($a_id, $target_block_id);
1012 }
1013
1014 $this->current_page--;
1015 }
1016 }
1017
1023 protected function editQuestion($a_id)
1024 {
1026
1027 $data = $this->object->getSurveyQuestions();
1028 $data = $data[$a_id];
1029
1030 $q_gui = $data["type_tag"] . "GUI";
1031 $ilCtrl->setParameterByClass($q_gui, "pgov", $this->current_page);
1032 $ilCtrl->setParameterByClass($q_gui, "q_id", $a_id);
1033
1034 $ilCtrl->redirectByClass($q_gui, "editQuestion");
1035 }
1036
1040 protected function addQuestionToolbarForm()
1041 {
1042 $lng = $this->lng;
1044 $tpl = $this->tpl;
1045
1046 $form = new ilPropertyFormGUI();
1047 $form->setFormAction($ilCtrl->getFormAction($this, "addQuestionToolbar"));
1048 $form->setTitle($lng->txt("survey_add_new_question"));
1049
1050 // question types
1052 $type_map = array();
1053 foreach ($questiontypes as $trans => $item) {
1054 $type_map[$item["questiontype_id"]] = $trans;
1055 }
1056 $si = new ilSelectInputGUI($lng->txt("question_type"), "qtype");
1057 $si->setOptions($type_map);
1058 $form->addItem($si);
1059
1060 $pages = $this->object->getSurveyPages();
1061 if ($pages) {
1062 $pages_drop = array("fst" => $lng->txt("survey_at_beginning"));
1063 foreach ($pages as $idx => $questions) {
1064 $question = array_shift($questions);
1065 if ($question["questionblock_id"]) {
1066 $pages_drop[$idx + 1] = $lng->txt("survey_behind_page") . " " . $question["questionblock_title"];
1067 } else {
1068 $pages_drop[$idx + 1] = $lng->txt("survey_behind_page") . " " . strip_tags($question["title"]);
1069 }
1070 }
1071 $pos = new ilSelectInputGUI($lng->txt("position"), "pgov");
1072 $pos->setOptions($pages_drop);
1073 $form->addItem($pos);
1074
1075 $pos->setValue($this->current_page);
1076 } else {
1077 // #9089: 1st page
1078 $pos = new ilHiddenInputGUI("pgov");
1079 $pos->setValue("fst");
1080 $form->addItem($pos);
1081 }
1082
1083 if ($this->object->isPoolActive()) {
1084 $this->editor_gui->createQuestionObject($form);
1085 }
1086
1087 $form->addCommandButton("addQuestionToolbar", $lng->txt("create"));
1088 $form->addCommandButton("renderPage", $lng->txt("cancel"));
1089
1090 return $tpl->setContent($form->getHTML());
1091 }
1092
1096 protected function addQuestionToolbar()
1097 {
1099 $lng = $this->lng;
1100
1101 $pool_active = $this->object->isPoolActive();
1102
1103 if (!$_POST["usage"] && $pool_active) {
1104 ilUtil::sendFailure($lng->txt("select_one"), true);
1105 return $this->addQuestionToolbarForm();
1106 }
1107
1108 // make sure that it is set for current and next requests
1109 $ilCtrl->setParameter($this->editor_gui, "pgov", $this->current_page);
1110
1111 if (!$this->addQuestion($_POST["qtype"], $pool_active, $_POST["pgov"], "toolbar")) {
1112 $this->renderPage();
1113 }
1114 }
1115
1119 protected function movePageForm()
1120 {
1121 $lng = $this->lng;
1123 $tpl = $this->tpl;
1124
1125 $form = new ilPropertyFormGUI();
1126 $form->setFormAction($ilCtrl->getFormAction($this, "movePage"));
1127 $form->setTitle($lng->txt("survey_move_page"));
1128
1129 $old_pos = new ilHiddenInputGUI("old_pos");
1130 $old_pos->setValue($this->current_page);
1131 $form->addItem($old_pos);
1132
1133 $pages = $this->object->getSurveyPages();
1134 if ($pages) {
1135 $pages_drop = array();
1136 if ($this->current_page != 1) {
1137 $pages_drop["fst"] = $lng->txt("survey_at_beginning");
1138 }
1139 foreach ($pages as $idx => $questions) {
1140 if (($idx + 1) != $this->current_page && ($idx + 2) != $this->current_page) {
1141 $question = array_shift($questions);
1142 if ($question["questionblock_id"]) {
1143 $pages_drop[$idx + 1] = $lng->txt("survey_behind_page") . " " . $question["questionblock_title"];
1144 } else {
1145 $pages_drop[$idx + 1] = $lng->txt("survey_behind_page") . " " . strip_tags($question["title"]);
1146 }
1147 }
1148 }
1149 $pos = new ilSelectInputGUI($lng->txt("position"), "pgov");
1150 $pos->setOptions($pages_drop);
1151 $form->addItem($pos);
1152 }
1153
1154 $form->addCommandButton("movePage", $lng->txt("submit"));
1155 $form->addCommandButton("renderPage", $lng->txt("cancel"));
1156
1157 return $tpl->setContent($form->getHTML());
1158 }
1159
1164 protected function movePage()
1165 {
1166 $lng = $this->lng;
1168
1169 // current_page is already set to new position
1170 $target_page = $this->current_page - 1;
1171 $source_page = $_REQUEST["old_pos"] - 1;
1172
1173 $pages = $this->object->getSurveyPages();
1174 foreach ($pages[$source_page] as $question) {
1175 $questions[] = $question["question_id"];
1176 }
1177
1178 // move to first position
1179 $position = 0;
1180 if ($_REQUEST["pgov"] != "fst") {
1181 $position = 1;
1182 }
1183
1184 $target = $pages[$target_page];
1185 if ($position == 0) { // before
1186 $target = array_shift($target); // ... use always the first question of the page
1187 } else { // after
1188 $target = array_pop($target); // ... use always the last question of the page
1189 }
1190 $this->object->moveQuestions($questions, $target["question_id"], $position);
1191
1192 if ($target_page < $source_page && $position) {
1193 $this->current_page++;
1194 }
1195
1196 ilUtil::sendSuccess($lng->txt("survey_page_moved"), true);
1197 $ilCtrl->setParameter($this, "pgov", $this->current_page);
1198 $ilCtrl->redirect($this, "renderPage");
1199 }
1200
1206 protected function renderToolbar($a_pages)
1207 {
1208 $ilToolbar = $this->toolbar;
1210 $lng = $this->lng;
1212
1213 if (!$this->has_datasets) {
1214 $button = ilLinkButton::getInstance();
1215 $button->setCaption("survey_add_new_question");
1216 $button->setUrl($ilCtrl->getLinkTarget($this, "addQuestionToolbarForm"));
1217 $ilToolbar->addStickyItem($button);
1218
1219 if ($this->object->isPoolActive()) {
1220 //$ilToolbar->addSeparator();
1221
1222 $last_on_page = 0;
1223 if ($a_pages &&
1224 is_array($a_pages[$this->current_page - 1])) {
1225 $last_on_page = $a_pages[$this->current_page - 1];
1226 $last_on_page = array_pop($last_on_page);
1227 $last_on_page = $last_on_page["question_id"];
1228 }
1229
1230 $ilCtrl->setParameter($this->editor_gui, "pgov", $this->current_page);
1231 $ilCtrl->setParameter($this->editor_gui, "pgov_pos", $last_on_page . "c");
1232
1233 $cmd = ($ilUser->getPref('svy_insert_type') == 1 ||
1234 strlen($ilUser->getPref('svy_insert_type')) == 0)
1235 ? 'browseForQuestions'
1236 : 'browseForQuestionblocks';
1237
1238 $button = ilLinkButton::getInstance();
1239 $button->setCaption("browse_for_questions");
1240 $button->setUrl($ilCtrl->getLinkTarget($this->editor_gui, $cmd));
1241 $ilToolbar->addStickyItem($button);
1242
1243 $ilCtrl->setParameter($this->editor_gui, "pgov", "");
1244 $ilCtrl->setParameter($this->editor_gui, "pgov_pos", "");
1245 }
1246
1247 if ($a_pages) {
1248 $ilToolbar->addSeparator();
1249 }
1250 }
1251
1252 // parse data for pages drop-down
1253 if ($a_pages) {
1254 // previous/next
1255
1256 $ilCtrl->setParameter($this, "pg", $this->current_page - 1);
1257 $button = ilLinkButton::getInstance();
1258 $button->setCaption("survey_prev_question");
1259 if ($this->has_previous_page) {
1260 $button->setUrl($ilCtrl->getLinkTarget($this, "renderPage"));
1261 }
1262 $button->setDisabled(!$this->has_previous_page);
1263 $ilToolbar->addStickyItem($button);
1264
1265 $ilCtrl->setParameter($this, "pg", $this->current_page + 1);
1266 $button = ilLinkButton::getInstance();
1267 $button->setCaption("survey_next_question");
1268 if ($this->has_next_page) {
1269 $button->setUrl($ilCtrl->getLinkTarget($this, "renderPage"));
1270 }
1271 $button->setDisabled(!$this->has_next_page);
1272 $ilToolbar->addStickyItem($button);
1273
1274 $ilCtrl->setParameter($this, "pg", $this->current_page); // #14615
1275
1276 foreach ($a_pages as $idx => $questions) {
1277 $page = $questions;
1278 $page = array_shift($page);
1279 if ($page["questionblock_id"]) {
1280 $pages_drop[$idx + 1] = $page["questionblock_title"];
1281
1282 if (sizeof($questions) > 1) {
1283 foreach ($questions as $question) {
1284 $pages_drop[($idx + 1) . "__" . $question["question_id"]] = "- " . $question["title"];
1285 }
1286 }
1287 } else {
1288 $pages_drop[$idx + 1] = strip_tags($page["title"]);
1289 }
1290 }
1291 }
1292
1293 // jump to page
1294 if (is_array($pages_drop) && count($pages_drop) > 1) {
1295 //$ilToolbar->addSeparator();
1296
1297 $ilToolbar->setFormAction($ilCtrl->getFormAction($this));
1298
1299 $si = new ilSelectInputGUI($lng->txt("survey_jump_to"), "jump");
1300 $si->addCustomAttribute("onChange=\"forms['ilToolbar'].submit();\"");
1301 $si->setOptions($pages_drop);
1302 $si->setValue($this->current_page);
1303 $ilToolbar->addInputItem($si, true);
1304
1305 // we need this to have to right cmd
1306 $cmd = new ilHiddenInputGUI("cmd[renderPage]");
1307 $cmd->setValue("1");
1308 $ilToolbar->addInputItem($cmd);
1309
1310 if (!$this->has_datasets) {
1311 $ilToolbar->addSeparator();
1312
1313 $ilCtrl->setParameter($this, "csum", md5(print_r($a_pages[$this->current_page - 1], true)));
1314 $url = $ilCtrl->getLinkTarget($this, "deleteBlock");
1315 $ilCtrl->setParameter($this, "csum", "");
1316
1317 $button = ilLinkButton::getInstance();
1318 $button->setCaption("survey_delete_page");
1319 $button->setUrl($url);
1320 $ilToolbar->addButtonInstance($button);
1321
1322 $ilToolbar->addSeparator();
1323
1324 $button = ilLinkButton::getInstance();
1325 $button->setCaption("survey_move_page");
1326 $button->setUrl($ilCtrl->getLinkTarget($this, "movePageForm"));
1327 $ilToolbar->addButtonInstance($button);
1328 }
1329 }
1330 }
1331
1335 protected function renderPage()
1336 {
1338 $lng = $this->lng;
1339 $tpl = $this->tpl;
1341
1342 $pages = $this->object->getSurveyPages();
1343 $this->has_next_page = ($this->current_page < sizeof($pages));
1344 $this->has_previous_page = ($this->current_page > 1);
1345 $this->has_datasets = ilObjSurvey::_hasDatasets($this->object->getSurveyId());
1346
1347 $mess = "";
1348 if ($this->has_datasets) {
1350 $mess = $mbox->getHTML();
1351 }
1352
1353 $ilCtrl->setParameter($this, "pg", $this->current_page);
1354 $ilCtrl->setParameter($this, "pgov", "");
1355
1356 $this->renderToolbar($pages);
1357
1358 if ($pages) {
1359 $ttpl = new ilTemplate("tpl.il_svy_svy_page_view.html", true, true, "Modules/Survey");
1360 $ttpl->setVariable("FORM_ACTION", $ilCtrl->getFormAction($this));
1361 $lng->loadLanguageModule("form");
1362
1363 $read_only = ($this->has_datasets || !$rbacsystem->checkAccess("write", $this->ref_id));
1364
1365 $commands = $multi_commands = array();
1366
1367 if (!$read_only) {
1368 // clipboard is empty
1369 if (!$_SESSION["survey_page_view"][$this->ref_id]["clipboard"]) {
1370 $multi_commands[] = array("cmd" => "multiDelete", "text" => $lng->txt("delete"));
1371 $multi_commands[] = array("cmd" => "multiCut", "text" => $lng->txt("cut"));
1372 $multi_commands[] = array("cmd" => "multiCopy", "text" => $lng->txt("copy"));
1373 $multi_commands[] = array("cmd" => "selectAll", "text" => $lng->txt("select_all"));
1374 } else {
1375 if (!$this->suppress_clipboard_msg) {
1376 ilUtil::sendInfo($lng->txt("survey_clipboard_notice"));
1377 }
1378 $multi_commands[] = array("cmd" => "clearClipboard", "text" => $lng->txt("survey_dnd_clear_clipboard"));
1379 }
1380
1381 // help - see ilPageObjectGUI::insertHelp()
1382 $lng->loadLanguageModule("content");
1383 $ttpl->setCurrentBlock("help_section");
1384 $ttpl->setVariable("TXT_ADD_EL", $lng->txt("cont_add_elements"));
1385 $ttpl->setVariable("PLUS", ilGlyphGUI::get(ilGlyphGUI::ADD));
1386 $ttpl->setVariable("DRAG_ARROW", ilGlyphGUI::get(ilGlyphGUI::DRAG));
1387 $ttpl->setVariable("TXT_DRAG", $lng->txt("cont_drag_and_drop_elements"));
1388 $ttpl->setVariable("TXT_SEL", $lng->txt("cont_double_click_to_delete"));
1389 $ttpl->parseCurrentBlock();
1390
1391 $ttpl->setVariable("DND_INIT_JS", "initDragElements();");
1392
1393
1394 // tiny mce
1395
1397
1404 $tiny = new ilTinyMCE();
1405 $ttpl->setVariable("WYSIWYG_BLOCKFORMATS", $tiny->_buildAdvancedBlockformatsFromHTMLTags($tags));
1406 $ttpl->setVariable("WYSIWYG_VALID_ELEMENTS", $tiny->_getValidElementsFromHTMLTags($tags));
1407
1408 $buttons_1 = $tiny->_buildAdvancedButtonsFromHTMLTags(1, $tags);
1409 $buttons_2 = $tiny->_buildAdvancedButtonsFromHTMLTags(2, $tags) . ',' .
1410 $tiny->_buildAdvancedTableButtonsFromHTMLTags($tags) .
1411 ($tiny->getStyleSelect() ? ',styleselect' : '');
1412 $buttons_3 = $tiny->_buildAdvancedButtonsFromHTMLTags(3, $tags);
1413 $ttpl->setVariable('WYSIWYG_BUTTONS_1', ilTinyMCE::removeRedundantSeparators($buttons_1));
1414 $ttpl->setVariable('WYSIWYG_BUTTONS_2', ilTinyMCE::removeRedundantSeparators($buttons_2));
1415 $ttpl->setVariable('WYSIWYG_BUTTONS_3', ilTinyMCE::removeRedundantSeparators($buttons_3));
1416 }
1417
1418 // commands
1419 if (count($multi_commands) > 0) {
1420 foreach ($multi_commands as $cmd) {
1421 $ttpl->setCurrentBlock("multi_cmd");
1422 $ttpl->setVariable("ORG_CMD_MULTI", "renderPage");
1423 $ttpl->setVariable("MULTI_CMD", $cmd["cmd"]);
1424 $ttpl->setVariable("MULTI_CMD_TXT", $cmd["text"]);
1425 $ttpl->parseCurrentBlock();
1426 }
1427
1428 $ttpl->setCurrentBlock("multi_cmds");
1429 $ttpl->setVariable("MCMD_ALT", $lng->txt("commands"));
1430 $ttpl->setVariable("MCMD_IMG", ilUtil::getImagePath("arrow_downright.svg"));
1431 $ttpl->parseCurrentBlock();
1432 }
1433
1434 // nodes
1435 $ttpl->setVariable("NODES", $this->getPageNodes(
1436 $pages[$this->current_page - 1],
1437 $this->has_previous_page,
1438 $this->has_next_page,
1439 $read_only
1440 ));
1441
1442 $tpl->setContent($mess . $ttpl->get());
1443
1444 // add js to template
1446 $tpl->addJavascript("./Modules/Survey/js/SurveyPageView.js");
1447 }
1448 }
1449
1459 public function getPageNodes(array $a_questions, $a_has_previous_page = false, $a_has_next_page = false, $a_readonly = false)
1460 {
1462 $lng = $this->lng;
1463
1464 $ttpl = new ilTemplate("tpl.il_svy_svy_page_view_nodes.html", true, true, "Modules/Survey");
1465
1466 $has_clipboard = (bool) $_SESSION["survey_page_view"][$this->ref_id]["clipboard"];
1467
1468 // question block ?
1469
1470 $first_question = $a_questions;
1471 $first_question = array_shift($first_question);
1472
1473 if ($first_question["questionblock_id"]) {
1474 $menu = array();
1475
1476 if (!$a_readonly && !$has_clipboard) {
1477 $menu[] = array("cmd" => "editBlock", "text" => $lng->txt("edit"));
1478 }
1479
1480 if ($first_question["questionblock_show_blocktitle"]) {
1481 $block_status = $lng->txt("survey_block_visible");
1482 } else {
1483 $block_status = $lng->txt("survey_block_hidden");
1484 }
1485
1486 $this->renderPageNode(
1487 $ttpl,
1488 "block",
1489 $first_question["questionblock_id"],
1490 $first_question["questionblock_title"] . " (" . $block_status . ")",
1491 $menu,
1492 false,
1493 false,
1494 $block_status
1495 );
1496 }
1497
1498
1499 // questions/headings
1500
1502 $questionpools = array_keys($this->object->getQuestionpoolTitles(true));
1503
1504 $counter = $question_count;
1505 $block_done = null;
1506 foreach ($a_questions as $idx => $question) {
1507 // drop area
1508
1509 $menu = array();
1510
1511 if (!$a_readonly) {
1512 if (!$has_clipboard) {
1513 foreach ($questiontypes as $trans => $item) {
1514 $menu[] = array("cmd" => "addQuestion_" . $item["questiontype_id"],
1515 "text" => sprintf($lng->txt("svy_page_add_question"), $trans));
1516 }
1517
1518 if ($this->object->isPoolActive()) {
1519 $menu[] = array("cmd" => "addPoolQuestion",
1520 "text" => $lng->txt("browse_for_questions"));
1521 }
1522 } else {
1523 $menu[] = array("cmd" => "paste", "text" => $lng->txt("survey_dnd_paste"));
1524 }
1525 }
1526
1527 $this->renderPageNode($ttpl, "droparea", $question["question_id"], null, $menu, true);
1528
1529 // question
1530 $question_gui = $this->object->getQuestionGUI($question["type_tag"], $question["question_id"]);
1531 $question_form = $question_gui->getWorkingForm(
1532 array(),
1533 $this->object->getShowQuestionTitles(),
1534 $question["questionblock_show_questiontext"],
1535 null,
1536 $this->object->getSurveyId()
1537 );
1538
1539 $menu = array();
1540
1541 if (!$a_readonly && !$has_clipboard) {
1542 $menu[] = array("cmd" => "editQuestion", "text" => $lng->txt("edit"));
1543 $menu[] = array("cmd" => "cutQuestion", "text" => $lng->txt("cut"));
1544 $menu[] = array("cmd" => "copyQuestion", "text" => $lng->txt("copy"));
1545
1546 if (sizeof($a_questions) > 1 && $idx > 0) {
1547 $menu[] = array("cmd" => "splitPage", "text" => $lng->txt("survey_dnd_split_page"));
1548 }
1549 if ($a_has_next_page) {
1550 $menu[] = array("cmd" => "moveNext", "text" => $lng->txt("survey_dnd_move_next"));
1551 }
1552 if ($a_has_previous_page) {
1553 $menu[] = array("cmd" => "movePrevious", "text" => $lng->txt("survey_dnd_move_previous"));
1554 }
1555
1556 $menu[] = array("cmd" => "deleteQuestion", "text" => $lng->txt("delete"));
1557
1558 // heading
1559 if ($question["heading"]) {
1560 $menu[] = array("cmd" => "editHeading", "text" => $lng->txt("survey_edit_heading"));
1561 $menu[] = array("cmd" => "deleteHeading", "text" => $lng->txt("survey_delete_heading"));
1562 } else {
1563 $menu[] = array("cmd" => "addHeading", "text" => $lng->txt("add_heading"));
1564 }
1565 }
1566
1567 if ($first_question["questionblock_show_questiontext"]) {
1568 $question_title_status = $lng->txt("survey_question_text_visible");
1569 } else {
1570 $question_title_status = $lng->txt("survey_question_text_hidden");
1571 }
1572
1573 $this->renderPageNode(
1574 $ttpl,
1575 "question",
1576 $question["question_id"],
1577 $question_form,
1578 $menu,
1579 false,
1580 $question["title"],
1581 $question_title_status,
1582 $question["heading"]
1583 );
1584
1585 $ilCtrl->setParameter($this, "eqid", "");
1586 }
1587
1588
1589 // last position (no question id)
1590
1591 $menu = array();
1592
1593 if (!$a_readonly) {
1594 if (!$has_clipboard) {
1595 foreach ($questiontypes as $trans => $item) {
1596 $menu[] = array("cmd" => "addQuestion_" . $item["questiontype_id"],
1597 "text" => sprintf($lng->txt("svy_page_add_question"), $trans));
1598 }
1599
1600 if ($this->object->isPoolActive()) {
1601 $menu[] = array("cmd" => "addPoolQuestion",
1602 "text" => $lng->txt("browse_for_questions"));
1603 }
1604 } else {
1605 $menu[] = array("cmd" => "paste", "text" => $lng->txt("survey_dnd_paste"));
1606 }
1607 }
1608
1609 $this->renderPageNode($ttpl, "page", "end", null, $menu, true);
1610
1611 return $ttpl->get();
1612 }
1613
1626 public function renderPageNode(ilTemplate $a_tpl, $a_type, $a_id, $a_content = null, array $a_menu = null, $a_spacer = false, $a_subtitle = false, $a_status = false, $a_heading = false)
1627 {
1629 $lng = $this->lng;
1630
1631 $node_id = $a_type . "_" . $a_id;
1632
1633 if ($a_spacer) {
1634 if ($a_menu) {
1635 // drop area menu
1636 foreach ($a_menu as $mcnt => $menu_item) {
1637 $ilCtrl->setParameter($this, "il_hform_node", $node_id);
1638 $ilCtrl->setParameter($this, "il_hform_subcmd", $menu_item["cmd"]);
1639 $url = $ilCtrl->getLinkTarget($this, "renderPage");
1640 $ilCtrl->setParameter($this, "il_hform_subcmd", "");
1641 $ilCtrl->setParameter($this, "il_hform_node", "");
1642
1643 $a_tpl->setCurrentBlock("menu_cmd");
1644 $a_tpl->setVariable("TXT_MENU_CMD", $menu_item["text"]);
1645 $a_tpl->setVariable("URL_MENU_CMD", $url);
1646 $a_tpl->parseCurrentBlock();
1647 }
1648 }
1649
1650 $a_tpl->setCurrentBlock("drop_area");
1651 $a_tpl->setVariable("ICON_ADD", ilGlyphGUI::get(ilGlyphGUI::ADD));
1652 $a_tpl->setVariable("DROP_ID", $a_id);
1653 $a_tpl->parseCurrentBlock();
1654 } elseif ($a_menu) {
1655 // question action menu
1656 foreach ($a_menu as $mcnt => $menu_item) {
1657 $ilCtrl->setParameter($this, "il_hform_node", $node_id);
1658 $ilCtrl->setParameter($this, "il_hform_subcmd", $menu_item["cmd"]);
1659 $url = $ilCtrl->getLinkTarget($this, "renderPage");
1660 $ilCtrl->setParameter($this, "il_hform_subcmd", "");
1661 $ilCtrl->setParameter($this, "il_hform_node", "");
1662
1663 $a_tpl->setCurrentBlock("action_cmd");
1664 $a_tpl->setVariable("TXT_ACTION_CMD", $menu_item["text"]);
1665 $a_tpl->setVariable("URL_ACTION_CMD", $url);
1666 $a_tpl->parseCurrentBlock();
1667 }
1668 }
1669
1670 // add heading to content
1671 if ($a_content !== null &&
1672 $a_type == "question" &&
1673 $a_heading) {
1674 $a_content = "<div class=\"questionheading\">" . $a_heading . "</div>" .
1675 $a_content;
1676 }
1677
1678 if ($a_menu) {
1679 $a_tpl->setVariable("TXT_NODE_CONTENT_ACTIONS", $a_content);
1680 } else {
1681 $a_tpl->setVariable("TXT_NODE_CONTENT_NO_ACTIONS", $a_content);
1682 }
1683
1684 if ($a_content !== null) {
1685 $drag = "";
1686 $selectable = false;
1687 switch ($a_type) {
1688 case "block":
1689 $caption = $lng->txt("questionblock");
1690 break;
1691
1692 case "question":
1693 $caption = $lng->txt("question") . ": " . $a_subtitle;
1694 $drag = "_drag";
1695 $selectable = true;
1696 break;
1697
1698 case "heading":
1699 $caption = $lng->txt("heading");
1700 break;
1701
1702 default:
1703 return;
1704 }
1705
1706 if ($a_status) {
1707 $caption .= " (" . $a_status . ")";
1708 }
1709
1710 $a_tpl->setCurrentBlock("list_item");
1711 $a_tpl->setVariable("NODE_ID", $node_id);
1712 $a_tpl->setVariable("NODE_DRAG", $drag);
1713 $a_tpl->setVariable("TXT_NODE_TYPE", $caption);
1714 if ($selectable) {
1715 $a_tpl->setVariable("SELECTABLE", " selectable");
1716 }
1717 $a_tpl->parseCurrentBlock();
1718 }
1719
1720 $a_tpl->touchBlock("element");
1721 }
1722
1728 public function getAutoBlockTitle()
1729 {
1730 $lng = $this->lng;
1731
1732 return $lng->txt("survey_auto_block_title");
1733 }
1734
1735 public function addPoolQuestion($pos, $node)
1736 {
1739
1740 if ($node == "page_end") {
1741 $pos = $this->object->getSurveyPages();
1742 $pos = array_pop($pos[$this->current_page - 1]);
1743 $pos = $pos["question_id"] . "a";
1744 } else {
1745 $pos = $pos . "b";
1746 }
1747
1748 $ilCtrl->setParameter($this->editor_gui, "pgov", $this->current_page);
1749 $ilCtrl->setParameter($this->editor_gui, "pgov_pos", $pos);
1750
1751 $cmd = ($ilUser->getPref('svy_insert_type') == 1 || strlen($ilUser->getPref('svy_insert_type')) == 0) ? 'browseForQuestions' : 'browseForQuestionblocks';
1752 $ilCtrl->redirect($this->editor_gui, $cmd);
1753 }
1754}
$result
user()
Definition: user.php:4
$_GET["client_id"]
$_POST["username"]
$_SESSION["AccountId"]
An exception for terminatinating execution or to throw for unit testing.
static _getQuestionGUI($questiontype, $question_id=-1)
Creates a question gui representation.
static _isComplete($question_id)
Checks whether the question is complete or not.
static get($a_glyph, $a_text="")
Get glyph html.
This class represents a hidden form property in a property form.
static getInstance()
Factory.
static getLogger($a_component_id)
Get component logger.
static _getUsedHTMLTags($a_module="")
Returns an array of all allowed HTML tags for text editing.
static _getQuestiontypes()
Creates a list of all available question types.
Class ilObjSurvey.
static _instanciateQuestion($question_id)
Creates an instance of a question with a given question id.
static _hasDatasets($survey_id)
getRefId()
get reference id @access public
This class represents a property form user interface.
This class represents a selection list property in a property form.
Message box for survey, when data is alrady available.
Class ilSurveyEditorGUI.
Survey per page view.
cutQuestion($a_id)
Add question to be cut to clipboard.
appendNewQuestionToSurvey($a_new_id, $a_duplicate=true, $a_force_duplicate=false)
Add new question to survey (database part)
determineCurrentPage()
determine current page
insertQuestionBlock($a_block_id)
Copy and insert questions from block.
movePage()
Move current page to new position.
__construct(ilObjSurvey $a_survey, ilSurveyEditorGUI $a_survey_editor_gui)
Constructor.
copyQuestion($a_id)
Add question to be copied to clipboard.
addHeading($a_id)
Add heading to question.
getPageNodes(array $a_questions, $a_has_previous_page=false, $a_has_next_page=false, $a_readonly=false)
Get Form HTML.
renderPageNode(ilTemplate $a_tpl, $a_type, $a_id, $a_content=null, array $a_menu=null, $a_spacer=false, $a_subtitle=false, $a_status=false, $a_heading=false)
Render single of dnd page view.
multiCut($a_id)
Add questions to be cut to clipboard.
deleteBlock()
Confirm removing question block.
editBlock($a_id)
Edit question block.
addQuestionToolbarForm()
Add question to survey form (used in toolbar)
paste($a_id)
Paste from clipboard.
addQuestion($a_type, $a_use_pool, $a_pos, $a_special_position)
Call add question to survey form.
clearClipboard()
Empty clipboard.
dnd()
Move questions in page.
addQuestionToolbar()
Add question to survey action (used in toolbar)
moveNext($a_id)
Move question to next page.
editQuestion($a_id)
Edit question.
splitPage($a_id)
Split current page in 2 pages.
confirmRemoveQuestions()
Remove question(s) from survey.
renderToolbar($a_pages)
Render toolbar form.
movePrevious($a_id)
Move question to previous page.
getAutoBlockTitle()
Get name for newly created blocks.
deleteHeading($a_id)
Delete question heading.
callEditor($a_cmd, $a_param, $a_value)
movePageForm()
Move current page.
renderPage()
render questions per page
editHeading($a_id)
Edit question heading.
deleteQuestion($a_id)
Confirm removing question(s) from survey.
insertNewQuestion($a_new_id)
Add new question to survey.
multiCopy($a_id)
Add questions to be copied to clipboard.
special template class to simplify handling of ITX/PEAR
touchBlock($block)
overwrites ITX::touchBlock.
parseCurrentBlock($part="DEFAULT")
Überladene Funktion, die auf den aktuelle Block vorher noch ein replace ausführt @access public.
setCurrentBlock($part="DEFAULT")
Überladene Funktion, die sich hier lokal noch den aktuellen Block merkt.
Tiny MCE editor class.
static removeRedundantSeparators($a_string)
Removes redundant seperators and removes ,, and , at the first or last position of the string.
static sendQuestion($a_info="", $a_keep=false)
Send Question to Screen.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
static initDragDrop(ilGlobalTemplateInterface $a_main_tpl=null)
Init YUI Drag and Drop.
$target_id
Definition: goto.php:49
global $ilCtrl
Definition: ilias.php:18
setVariable($variable, $value='')
$source
Definition: metadata.php:76
$type
$url
global $ilDB
$data
Definition: storeScorm.php:23
$ilUser
Definition: imgupload.php:18
$a_content
Definition: workflow.php:93
$a_type
Definition: workflow.php:92
$DIC
Definition: xapitoken.php:46