ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilSurveyEditorGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3
17{
21 protected $ctrl;
22
26 protected $lng;
27
31 protected $tpl;
32
36 protected $tabs;
37
41 protected $help;
42
46 protected $toolbar;
47
51 protected $user;
52
56 protected $tree;
57
58 protected $parent_gui; // [ilObjSurveyGUI]
59 protected $object; // [ilObjSurvey]
60
64 protected $print_options;
65
66 public function __construct(ilObjSurveyGUI $a_parent_gui)
67 {
68 global $DIC;
69
70 $this->tabs = $DIC->tabs();
71 $this->help = $DIC["ilHelp"];
72 $this->toolbar = $DIC->toolbar();
73 $this->user = $DIC->user();
74 $this->tree = $DIC->repositoryTree();
75 $ilCtrl = $DIC->ctrl();
76 $lng = $DIC->language();
77 $tpl = $DIC["tpl"];
78
79 $this->parent_gui = $a_parent_gui;
80 $this->object = $this->parent_gui->object;
81
82 $this->ctrl = $ilCtrl;
83 $this->lng = $lng;
84 $this->tpl = $tpl;
85
86 $this->ctrl->saveParameter($this, array("pgov", "pgov_pos"));
87
88 $this->print_options = array(
89 //0 => $this->lng->txt('none'),
90 ilObjSurvey::PRINT_HIDE_LABELS => $this->lng->txt('svy_print_hide_labels'),
91 //2 => $this->lng->txt('svy_print_label_only'),
92 ilObjSurvey::PRINT_SHOW_LABELS => $this->lng->txt('svy_print_show_labels')
93 );
94 }
95
96 public function executeCommand()
97 {
98 $ilTabs = $this->tabs;
99
100 $cmd = $this->ctrl->getCmd("questions");
101
102 if ($_REQUEST["pgov"]) {
103 if ($cmd == "questions") {
104 $this->ctrl->setCmdClass("ilsurveypagegui");
105 $this->ctrl->setCmd("renderpage");
106 } elseif ($cmd == "confirmRemoveQuestions") {
107 // #14324
108 $this->ctrl->setCmdClass("ilsurveypagegui");
109 $this->ctrl->setCmd("confirmRemoveQuestions");
110 }
111 }
112
113 $next_class = $this->ctrl->getNextClass($this);
114 switch ($next_class) {
115 case 'ilsurveypagegui':
116 $this->questionsSubtabs("page");
117 $pg = new ilSurveyPageGUI($this->object, $this);
118 $this->ctrl->forwardCommand($pg);
119 break;
120
121 default:
122 // question gui
123 if (stristr($next_class, "questiongui")) {
124 $ilTabs->clearTargets();
125 $this->ctrl->saveParameter($this, array("new_for_survey"));
126
127 $q_gui = SurveyQuestionGUI::_getQuestionGUI(null, $_REQUEST["q_id"]);
128 if (is_object($q_gui->object)) {
129 $ilHelp = $this->help;
130 $ilHelp->setScreenIdComponent("spl_qt" . $q_gui->object->getQuestionTypeId());
131 }
132 // $q_gui->object->setObjId($this->object->getId());
133 $q_gui->setBackUrl($this->ctrl->getLinkTarget($this, "questions"));
134 $q_gui->setQuestionTabs();
135 $this->ctrl->forwardCommand($q_gui);
136
137 if (!(int) $_REQUEST["new_for_survey"]) {
138 // not on create
139 $this->tpl->setTitle($this->lng->txt("question") . ": " . $q_gui->object->getTitle());
140 }
141 } else {
142 $cmd .= "Object";
143 $this->$cmd();
144 }
145 break;
146 }
147 }
148
149 protected function questionsSubtabs($a_cmd)
150 {
151 $ilTabs = $this->tabs;
152
153 if ($a_cmd == "questions" && $_REQUEST["pgov"]) {
154 $a_cmd = "page";
155 }
156
157 $hidden_tabs = array();
158 $template = $this->object->getTemplate();
159 if ($template) {
160 $template = new ilSettingsTemplate($template);
161 $hidden_tabs = $template->getHiddenTabs();
162 }
163
164 $ilTabs->addSubTab(
165 "page",
166 $this->lng->txt("survey_per_page_view"),
167 $this->ctrl->getLinkTargetByClass("ilsurveypagegui", "renderPage")
168 );
169
170 if (!in_array("survey_question_editor", $hidden_tabs)) {
171 $this->ctrl->setParameter($this, "pgov", "");
172 $ilTabs->addSubTab(
173 "questions",
174 $this->lng->txt("survey_question_editor"),
175 $this->ctrl->getLinkTarget($this, "questions")
176 );
177 $this->ctrl->setParameter($this, "pgov", $_REQUEST["pgov"]);
178 }
179
180 $ilTabs->addSubTab(
181 "print",
182 $this->lng->txt("print_view"),
183 $this->ctrl->getLinkTarget($this, "printView")
184 );
185
186 if ($this->object->getSurveyPages()) {
187 if ($a_cmd == "page") {
188 $this->ctrl->setParameterByClass("ilsurveyexecutiongui", "pgov", max(1, $_REQUEST["pg"]));
189 }
190 $this->ctrl->setParameterByClass("ilsurveyexecutiongui", "prvw", 1);
191 $ilTabs->addSubTab(
192 "preview",
193 $this->lng->txt("preview"),
194 $this->ctrl->getLinkTargetByClass(array("ilobjsurveygui", "ilsurveyexecutiongui"), "preview")
195 );
196 }
197
198 $ilTabs->activateSubTab($a_cmd);
199 }
200
201
202 //
203 // QUESTIONS BROWSER INCL. MULTI-ACTIONS
204 //
205
206 public function questionsObject()
207 {
208 $ilToolbar = $this->toolbar;
210
211 // insert new questions?
212 if ($_GET["new_id"] > 0) {
213 // add a question to the survey previous created in a questionpool
214 $existing = $this->object->getExistingQuestions();
215 if (!in_array($_GET["new_id"], $existing)) {
216 $inserted = $this->object->insertQuestion($_GET["new_id"]);
217 if (!$inserted) {
218 ilUtil::sendFailure($this->lng->txt("survey_error_insert_incomplete_question"));
219 }
220 }
221 }
222
223 $this->questionsSubtabs("questions");
224
225 $hasDatasets = ilObjSurvey::_hasDatasets($this->object->getSurveyId());
226 $read_only = $hasDatasets;
227
228 // toolbar
229 if (!$read_only) {
230 $qtypes = array();
231 foreach (ilObjSurveyQuestionPool::_getQuestiontypes() as $translation => $data) {
232 $qtypes[$data["type_tag"]] = $translation;
233 }
234
235 $ilToolbar->setFormAction($this->ctrl->getFormAction($this));
236 $types = new ilSelectInputGUI($this->lng->txt("create_new"), "sel_question_types");
237 $types->setOptions($qtypes);
238 $ilToolbar->addStickyItem($types, "");
239
240 $button = ilSubmitButton::getInstance();
241 $button->setCaption("svy_create_question");
242 $button->setCommand("createQuestion");
243 $ilToolbar->addStickyItem($button);
244
245 if ($this->object->isPoolActive()) {
246 $ilToolbar->addSeparator();
247
248 $cmd = ($ilUser->getPref('svy_insert_type') == 1 ||
249 strlen($ilUser->getPref('svy_insert_type')) == 0)
250 ? 'browseForQuestions'
251 : 'browseForQuestionblocks';
252
253 $button = ilLinkButton::getInstance();
254 $button->setCaption("browse_for_questions");
255 $button->setUrl($this->ctrl->getLinkTarget($this, $cmd));
256 $ilToolbar->addStickyItem($button);
257 }
258
259 $ilToolbar->addSeparator();
260
261 $button = ilLinkButton::getInstance();
262 $button->setCaption("add_heading");
263 $button->setUrl($this->ctrl->getLinkTarget($this, "addHeading"));
264 $ilToolbar->addInputItem($button);
265 }
266 $mess = "";
267 if ($hasDatasets) {
269 $mess = $mbox->getHTML();
270 }
271
272 // table gui
273 $table = new ilSurveyQuestionTableGUI(
274 $this,
275 "questions",
276 $this->object,
277 $read_only
278 );
279 $this->tpl->setContent($mess . $table->getHTML());
280 }
281
291 protected function gatherSelectedTableItems($allow_blocks = true, $allow_questions = true, $allow_headings = false, $allow_questions_in_blocks = false)
292 {
293 $block_map = array();
294 foreach ($this->object->getSurveyQuestions() as $item) {
295 $block_map[$item["question_id"]] = $item["questionblock_id"];
296 }
297
298 $questions = $blocks = $headings = array();
299 if ($_POST["id"]) {
300 foreach ($_POST["id"] as $key) {
301 // questions
302 if ($allow_questions && preg_match("/cb_(\d+)/", $key, $matches)) {
303 if (($allow_questions_in_blocks || !$block_map[$matches[1]]) &&
304 !in_array($block_map[$matches[1]], $blocks)) {
305 array_push($questions, $matches[1]);
306 }
307 }
308 // blocks
309 if ($allow_blocks && preg_match("/cb_qb_(\d+)/", $key, $matches)) {
310 array_push($blocks, $matches[1]);
311 }
312 // headings
313 if ($allow_headings && preg_match("/cb_tb_(\d+)/", $key, $matches)) {
314 array_push($headings, $matches[1]);
315 }
316 }
317 }
318
319 return array("questions" => $questions,
320 "blocks" => $blocks,
321 "headings" => $headings);
322 }
323
324 public function saveObligatoryObject()
325 {
326 if (isset($_POST["order"])) {
327 $position = -1;
328 $order = array();
329 asort($_POST["order"]);
330 foreach (array_keys($_POST["order"]) as $id) {
331 // block items
332 if (substr($id, 0, 3) == "qb_") {
333 $block_id = substr($id, 3);
334 $block = $_POST["block_order"][$block_id];
335 asort($block);
336 foreach (array_keys($block) as $question_id) {
337 $position++;
338 $order[$question_id] = $position;
339 }
340 } else {
341 $question_id = substr($id, 2);
342 $position++;
343 $order[$question_id] = $position;
344 }
345 }
346 $this->object->updateOrder($order);
347 }
348
349 $obligatory = array();
350 foreach ($_POST as $key => $value) {
351 if (preg_match("/obligatory_(\d+)/", $key, $matches)) {
352 $obligatory[$matches[1]] = 1;
353 }
354 }
355 $this->object->setObligatoryStates($obligatory);
356 ilUtil::sendSuccess($this->lng->txt('msg_obj_modified'), true);
357 $this->ctrl->redirect($this, "questions");
358 }
359
361 {
362 $items = $this->gatherSelectedTableItems(true, false, false, false);
363 if (count($items["blocks"])) {
364 ilUtil::sendSuccess($this->lng->txt('msg_obj_modified'), true);
365 $this->object->unfoldQuestionblocks($items["blocks"]);
366 } else {
367 ilUtil::sendInfo($this->lng->txt("qpl_unfold_select_none"), true);
368 }
369 $this->ctrl->redirect($this, "questions");
370 }
371
372 public function moveQuestionsObject()
373 {
374 $items = $this->gatherSelectedTableItems(true, true, false, false);
375
376 $move_questions = $items["questions"];
377 foreach ($items["blocks"] as $block_id) {
378 foreach ($this->object->getQuestionblockQuestionIds($block_id) as $qid) {
379 array_push($move_questions, $qid);
380 }
381 }
382 if (count($move_questions) == 0) {
383 ilUtil::sendInfo($this->lng->txt("no_question_selected_for_move"), true);
384 $this->ctrl->redirect($this, "questions");
385 } else {
386 $_SESSION["move_questions"] = $move_questions;
387 $_SESSION["move_questions_survey_id"] = $this->object->getId();
388 ilUtil::sendInfo($this->lng->txt("select_target_position_for_move_question"));
389 $this->questionsObject();
390 }
391 }
392
394 {
395 $this->insertQuestions(0);
396 }
397
399 {
400 $this->insertQuestions(1);
401 }
402
403 protected function insertQuestions($insert_mode)
404 {
405 $insert_id = null;
406 if ($_POST["id"]) {
407 $items = $this->gatherSelectedTableItems(true, true, false, false);
408
409 // we are using POST id for original order
410 while (!$insert_id && sizeof($_POST["id"])) {
411 $target = array_shift($_POST["id"]);
412 if (preg_match("/^cb_(\d+)$/", $target, $matches)) {
413 // questions in blocks are not allowed
414 if (in_array($matches[1], $items["questions"])) {
415 $insert_id = $matches[1];
416 }
417 }
418 if (!$insert_id && preg_match("/^cb_qb_(\d+)$/", $target, $matches)) {
419 $ids = $this->object->getQuestionblockQuestionIds($matches[1]);
420 if (count($ids)) {
421 if ($insert_mode == 0) {
422 $insert_id = $ids[0];
423 } elseif ($insert_mode == 1) {
424 $insert_id = $ids[count($ids) - 1];
425 }
426 }
427 }
428 }
429 }
430
431 if (!$insert_id) {
432 ilUtil::sendInfo($this->lng->txt("no_target_selected_for_move"), true);
433 } else {
434 ilUtil::sendSuccess($this->lng->txt('msg_obj_modified'), true);
435 $this->object->moveQuestions($_SESSION["move_questions"], $insert_id, $insert_mode);
436 unset($_SESSION["move_questions"]);
437 unset($_SESSION["move_questions_survey_id"]);
438 }
439
440 $this->ctrl->redirect($this, "questions");
441 }
442
443 public function removeQuestionsObject()
444 {
445 $items = $this->gatherSelectedTableItems(true, true, true, true);
446 if (count($items["blocks"]) + count($items["questions"]) + count($items["headings"]) > 0) {
447 ilUtil::sendQuestion($this->lng->txt("remove_questions"));
448 $this->removeQuestionsForm($items["blocks"], $items["questions"], $items["headings"]);
449 return;
450 } else {
451 ilUtil::sendInfo($this->lng->txt("no_question_selected_for_removal"), true);
452 $this->ctrl->redirect($this, "questions");
453 }
454 }
455
456 public function removeQuestionsForm($checked_questionblocks, $checked_questions, $checked_headings)
457 {
458 $cgui = new ilConfirmationGUI();
459 $cgui->setHeaderText($this->lng->txt("survey_sure_delete_questions"));
460
461 $cgui->setFormAction($this->ctrl->getFormAction($this, "confirmRemoveQuestions"));
462 $cgui->setCancel($this->lng->txt("cancel"), "questions");
463 $cgui->setConfirm($this->lng->txt("confirm"), "confirmRemoveQuestions");
464
465 $counter = 0;
466 $surveyquestions = &$this->object->getSurveyQuestions();
467 foreach ($surveyquestions as $question_id => $data) {
468 if (in_array($data["question_id"], $checked_questions)) {
470
471 $cgui->addItem(
472 "id_" . $data["question_id"],
473 $data["question_id"],
474 $type . ": " . $data["title"]
475 );
476 } elseif ((in_array($data["questionblock_id"], $checked_questionblocks))) {
478
479 $cgui->addItem(
480 "id_qb_" . $data["questionblock_id"],
481 $data["questionblock_id"],
482 $data["questionblock_title"] . " - " . $type . ": " . $data["title"]
483 );
484 } elseif (in_array($data["question_id"], $checked_headings)) {
485 $cgui->addItem(
486 "id_tb_" . $data["question_id"],
487 $data["question_id"],
488 $data["heading"]
489 );
490 }
491 }
492
493 $this->tpl->setContent($cgui->getHTML());
494 }
495
497 {
498 $checked_questions = array();
499 $checked_questionblocks = array();
500 $checked_headings = array();
501 foreach ($_POST as $key => $value) {
502 if (preg_match("/id_(\d+)/", $key, $matches)) {
503 array_push($checked_questions, $matches[1]);
504 }
505 if (preg_match("/id_qb_(\d+)/", $key, $matches)) {
506 array_push($checked_questionblocks, $matches[1]);
507 }
508 if (preg_match("/id_tb_(\d+)/", $key, $matches)) {
509 array_push($checked_headings, $matches[1]);
510 }
511 }
512
513 if (sizeof($checked_questions) || sizeof($checked_questionblocks)) {
514 $this->object->removeQuestions($checked_questions, $checked_questionblocks);
515 }
516 if ($checked_headings) {
517 foreach ($checked_headings as $q_id) {
518 $this->object->saveHeading("", $q_id);
519 }
520 }
521 $this->object->saveCompletionStatus();
522 ilUtil::sendSuccess($this->lng->txt("questions_removed"), true);
523 $this->ctrl->redirect($this, "questions");
524 }
525
527 {
528 $items = $this->gatherSelectedTableItems(true, true, false, true);
529
530 // gather questions from blocks
531 $copy_questions = $items["questions"];
532 foreach ($items["blocks"] as $block_id) {
533 foreach ($this->object->getQuestionblockQuestionIds($block_id) as $qid) {
534 array_push($copy_questions, $qid);
535 }
536 }
537 $copy_questions = array_unique($copy_questions);
538
539 // only if not already in pool
540 if (count($copy_questions)) {
541 foreach ($copy_questions as $idx => $question_id) {
542 $question = ilObjSurvey::_instanciateQuestion($question_id);
543 if ($question->getOriginalId()) {
544 unset($copy_questions[$idx]);
545 }
546 }
547 }
548 if (count($copy_questions) == 0) {
549 ilUtil::sendInfo($this->lng->txt("no_question_selected_for_copy_to_pool"), true);
550 $this->ctrl->redirect($this, "questions");
551 } else {
552 $this->questionsSubtabs("questions");
553
554 $form = new ilPropertyFormGUI();
555
556 $form->setFormAction($this->ctrl->getFormAction($this, "executeCreateQuestion"));
557
558 $ids = new ilHiddenInputGUI("question_ids");
559 $ids->setValue(implode(";", $copy_questions));
560 $form->addItem($ids);
561
562 $questionpools = &$this->object->getAvailableQuestionpools(false, false, true, "write");
563 $pools = new ilSelectInputGUI($this->lng->txt("survey_copy_select_questionpool"), "sel_spl");
564 $pools->setOptions($questionpools);
565 $form->addItem($pools);
566
567 $form->addCommandButton("executeCopyQuestionsToPool", $this->lng->txt("submit"));
568 $form->addCommandButton("questions", $this->lng->txt("cancel"));
569
570 return $this->tpl->setContent($form->getHTML());
571 }
572 }
573
575 {
576 $question_ids = explode(";", $_POST["question_ids"]);
577 $pool_id = ilObject::_lookupObjId($_POST["sel_spl"]);
578
579 foreach ($question_ids as $qid) {
580 // create copy (== pool "original")
581 $new_question = ilObjSurvey::_instanciateQuestion($qid);
582 $new_question->setId();
583 $new_question->setObjId($pool_id);
584 $new_question->saveToDb();
585
586 // link "source" (survey) to copy (pool)
587 SurveyQuestion::_changeOriginalId($qid, $new_question->getId(), $pool_id);
588 }
589
590 ilUtil::sendSuccess($this->lng->txt("survey_copy_to_questionpool_success"), true);
591 $this->ctrl->redirect($this, "questions");
592 }
593
594
595 //
596 // QUESTION CREATION
597 //
598
599 public function createQuestionObject(ilPropertyFormGUI $a_form = null)
600 {
601 if (!$this->object->isPoolActive()) {
602 $_POST["usage"] = 1;
603 $_GET["sel_question_types"] = $_POST["sel_question_types"];
604 return $this->executeCreateQuestionObject();
605 }
606
607 if (!$a_form) {
608 $this->questionsSubtabs("questions");
609
610 $form = new ilPropertyFormGUI();
611
612 $sel_question_types = (strlen($_POST["sel_question_types"])) ? $_POST["sel_question_types"] : $_GET["sel_question_types"];
613 $this->ctrl->setParameter($this, "sel_question_types", $sel_question_types);
614 $form->setFormAction($this->ctrl->getFormAction($this, "executeCreateQuestion"));
615 } else {
616 $form = $a_form;
617 }
618
619 $usage = new ilRadioGroupInputGUI($this->lng->txt("survey_pool_selection"), "usage");
620 $usage->setRequired(true);
621 $no_pool = new ilRadioOption($this->lng->txt("survey_no_pool"), 1);
622 $usage->addOption($no_pool);
623 $existing_pool = new ilRadioOption($this->lng->txt("survey_existing_pool"), 3);
624 $usage->addOption($existing_pool);
625 $new_pool = new ilRadioOption($this->lng->txt("survey_new_pool"), 2);
626 $usage->addOption($new_pool);
627 $form->addItem($usage);
628
629 if (isset($_SESSION["svy_qpool_choice"])) {
630 $usage->setValue($_SESSION["svy_qpool_choice"]);
631 } else {
632 // default: no pool
633 $usage->setValue(1);
634 }
635
636 $questionpools = &$this->object->getAvailableQuestionpools(false, true, true, "write");
637 $pools = new ilSelectInputGUI($this->lng->txt("select_questionpool"), "sel_spl");
638 $pools->setOptions($questionpools);
639 $existing_pool->addSubItem($pools);
640
641 $name = new ilTextInputGUI($this->lng->txt("spl_new"), "name_spl"); // #11740
642 $name->setSize(50);
643 $name->setMaxLength(50);
644 $new_pool->addSubItem($name);
645
646 if ($a_form) {
647 return $a_form;
648 }
649
650 $form->addCommandButton("executeCreateQuestion", $this->lng->txt("submit"));
651 $form->addCommandButton("questions", $this->lng->txt("cancel"));
652
653 return $this->tpl->setContent($form->getHTML());
654 }
655
657 {
658 $_SESSION["svy_qpool_choice"] = $_POST["usage"];
659
660 $q_type = $_GET["sel_question_types"];
661
662 // no pool
663 if ($_POST["usage"] == 1) {
664 $obj_id = $this->object->getId();
665 }
666 // existing pool
667 elseif ($_POST["usage"] == 3 && strlen($_POST["sel_spl"])) {
668 $obj_id = ilObject::_lookupObjId($_POST["sel_spl"]);
669 }
670 // new pool
671 elseif ($_POST["usage"] == 2 && strlen($_POST["name_spl"])) {
672 $obj_id = $this->createQuestionPool($_POST["name_spl"]);
673 } else {
674 if (!$_POST["usage"]) {
675 ilUtil::sendFailure($this->lng->txt("select_one"), true);
676 } else {
677 ilUtil::sendFailure($this->lng->txt("err_no_pool_name"), true);
678 }
679 $this->ctrl->setParameter($this, "sel_question_types", $q_type);
680 $this->ctrl->redirect($this, "createQuestion");
681 }
682
683
684 // create question and redirect to question form
685
686 $q_gui = SurveyQuestionGUI::_getQuestionGUI($q_type);
687 $q_gui->object->setObjId($obj_id); // survey/pool!
688 $q_gui->object->createNewQuestion();
689 $q_gui_class = get_class($q_gui);
690
691 if ($_REQUEST["pgov"]) {
692 $this->ctrl->setParameterByClass($q_gui_class, "pgov", $_REQUEST["pgov"]);
693 $this->ctrl->setParameterByClass($q_gui_class, "pgov_pos", $_REQUEST["pgov_pos"]);
694 }
695
696 $this->ctrl->setParameterByClass($q_gui_class, "ref_id", $this->object->getRefId());
697 $this->ctrl->setParameterByClass($q_gui_class, "new_for_survey", $this->object->getRefId());
698 $this->ctrl->setParameterByClass($q_gui_class, "q_id", $q_gui->object->getId());
699 $this->ctrl->setParameterByClass($q_gui_class, "sel_question_types", $q_gui->getQuestionType());
700 $this->ctrl->redirectByClass($q_gui_class, "editQuestion");
701 }
702
703 protected function createQuestionPool($name = "dummy")
704 {
706
707 $parent_ref = $tree->getParentId($this->object->getRefId());
708
709 $qpl = new ilObjSurveyQuestionPool();
710 $qpl->setType("spl");
711 $qpl->setTitle($name);
712 $qpl->setDescription("");
713 $qpl->create();
714 $qpl->createReference();
715 $qpl->putInTree($parent_ref);
716 $qpl->setPermissions($parent_ref);
717 $qpl->setOnline(1); // must be online to be available
718 $qpl->saveToDb();
719
720 return $qpl->getId();
721 }
722
723
724 //
725 // ADD FROM POOL
726 //
727
728 protected function setBrowseForQuestionsSubtabs()
729 {
730 $ilTabs = $this->tabs;
731 $ilToolbar = $this->toolbar;
733
734 if (!isset($_REQUEST["pgov"])) {
735 $link = $this->ctrl->getLinkTarget($this, "questions");
736 } else {
737 $link = $this->ctrl->getLinkTargetByClass("ilsurveypagegui", "renderpage");
738 }
739 $ilTabs->setBackTarget($this->lng->txt("menubacktosurvey"), $link);
740
741 // type selector
742 $types = new ilSelectInputGUI($this->lng->txt("display_all_available"), "datatype");
743 $types->setOptions(array(
744 1 => $this->lng->txt("questions"),
745 2 => $this->lng->txt("questionblocks")
746 ));
747 $types->setValue($ilUser->getPref('svy_insert_type'));
748 $ilToolbar->addInputItem($types, true);
749 $ilToolbar->addFormButton($this->lng->txt("change"), "changeDatatype");
750 $ilToolbar->setFormAction($this->ctrl->getFormAction($this, "changeDatatype"));
751 }
752
753 public function changeDatatypeObject()
754 {
756
757 $ilUser->writePref('svy_insert_type', $_POST['datatype']);
758
759 switch ($_POST["datatype"]) {
760 case 2:
761 $this->ctrl->redirect($this, 'browseForQuestionblocks');
762 break;
763
764 case 1:
765 default:
766 $this->ctrl->redirect($this, 'browseForQuestions');
767 break;
768 }
769 }
770
771 public function browseForQuestionsObject()
772 {
774
775 $table_gui = new ilSurveyQuestionbrowserTableGUI($this, 'browseForQuestions', $this->object, true);
776 $table_gui->setEditable(true);
777 $this->tpl->setContent($table_gui->getHTML());
778 }
779
781 {
782 $table_gui = new ilSurveyQuestionbrowserTableGUI($this, 'browseForQuestions', $this->object);
783 $table_gui->writeFilterToSession();
784 $this->ctrl->redirect($this, 'browseForQuestions');
785 }
786
788 {
789 $table_gui = new ilSurveyQuestionbrowserTableGUI($this, 'browseForQuestions', $this->object);
790 $table_gui->resetFilter();
791 $this->ctrl->redirect($this, 'browseForQuestions');
792 }
793
794 public function insertQuestionsObject()
795 {
796 $inserted_objects = 0;
797 if (is_array($_POST['q_id'])) {
798 if ($_REQUEST["pgov"]) {
799 $page_gui = new ilSurveyPageGUI($this->object, $this);
800 $page_gui->determineCurrentPage();
801
802 // as target position is predefined, insert in reverse order
803 $_POST['q_id'] = array_reverse($_POST['q_id']);
804 }
805 foreach ($_POST['q_id'] as $question_id) {
806 if (!$_REQUEST["pgov"]) {
807 $this->object->insertQuestion($question_id);
808 } else {
809 // target position (pgov pos) is processed there
810 $page_gui->insertNewQuestion($question_id);
811 }
812 $inserted_objects++;
813 }
814 }
815 if ($inserted_objects) {
816 $this->object->saveCompletionStatus();
817 ilUtil::sendSuccess($this->lng->txt("questions_inserted"), true);
818 if (!$_REQUEST["pgov"]) {
819 $this->ctrl->redirect($this, "questions");
820 } else {
821 $target_page = $_REQUEST["pgov"];
822 if (substr($_REQUEST["pgov_pos"], -1) == "c") {
823 // see ilSurveyPageGUI::insertNewQuestion()
824 if ((int) $_REQUEST["pgov_pos"]) {
825 $target_page++;
826 } else {
827 $target_page = 1;
828 }
829 }
830 $this->ctrl->setParameterByClass("ilsurveypagegui", "pgov", $target_page);
831 $this->ctrl->redirectByClass("ilsurveypagegui", "renderpage");
832 }
833 } else {
834 ilUtil::sendInfo($this->lng->txt("insert_missing_question"), true);
835 $this->ctrl->redirect($this, 'browseForQuestions');
836 }
837 }
838
840 {
842
843 $table_gui = new ilSurveyQuestionblockbrowserTableGUI($this, 'browseForQuestionblocks', $this->object, true);
844 $table_gui->setEditable(true);
845 $this->tpl->setContent($table_gui->getHTML());
846 }
847
849 {
850 $table_gui = new ilSurveyQuestionblockbrowserTableGUI($this, 'browseForQuestionblocks', $this->object);
851 $table_gui->writeFilterToSession();
852 $this->ctrl->redirect($this, 'browseForQuestionblocks');
853 }
854
856 {
857 $table_gui = new ilSurveyQuestionblockbrowserTableGUI($this, 'browseForQuestionblocks', $this->object);
858 $table_gui->resetFilter();
859 $this->ctrl->redirect($this, 'browseForQuestionblocks');
860 }
861
863 {
864 $inserted_objects = 0;
865 if (is_array($_POST['cb'])) {
866 if ($_REQUEST["pgov"]) {
867 $page_gui = new ilSurveyPageGUI($this->object, $this);
868 $page_gui->determineCurrentPage();
869
870 // as target position is predefined, insert in reverse order
871 $_POST['cb'] = array_reverse($_POST['cb']);
872 }
873 foreach ($_POST['cb'] as $questionblock_id) {
874 if (!$_REQUEST["pgov"]) {
875 $this->object->insertQuestionblock($questionblock_id);
876 } else {
877 $page_gui->insertQuestionblock($questionblock_id);
878 }
879 $inserted_objects++;
880 }
881 }
882 if ($inserted_objects) {
883 $this->object->saveCompletionStatus();
884 ilUtil::sendSuccess(($inserted_objects == 1) ? $this->lng->txt("questionblock_inserted") : $this->lng->txt("questionblocks_inserted"), true);
885 if (!$_REQUEST["pgov"]) {
886 $this->ctrl->redirect($this, "questions");
887 } else {
888 $target_page = $_REQUEST["pgov"];
889 if (substr($_REQUEST["pgov_pos"], -1) == "c") {
890 $target_page++;
891 }
892 $this->ctrl->setParameterByClass("ilsurveypagegui", "pgov", $target_page);
893 $this->ctrl->redirectByClass("ilsurveypagegui", "renderpage");
894 }
895 } else {
896 ilUtil::sendInfo($this->lng->txt("insert_missing_questionblock"), true);
897 $this->ctrl->redirect($this, 'browseForQuestionblocks');
898 }
899 }
900
901
902 //
903 // BLOCKS
904 //
905
906 public function editQuestionblockObject(ilPropertyFormGUI $a_form = null)
907 {
908 $block_id = (int) $_REQUEST["bl_id"];
909 $this->ctrl->setParameter($this, "bl_id", $block_id);
910
911 if (!$a_form) {
912 $a_form = $this->initQuestionblockForm($block_id);
913 }
914
915 $this->questionsSubtabs("questions");
916 $this->tpl->setContent($a_form->getHTML());
917 }
918
919 public function createQuestionblockObject(ilPropertyFormGUI $a_form = null)
920 {
921 if (!$a_form) {
922 // gather questions from table selected
923 $items = $this->gatherSelectedTableItems(false, true, false, false);
924
925 if (is_array($_POST["qids"]) && sizeof($_POST["qids"])) {
926 $items["questions"] = $_POST["qids"];
927 }
928 if (count($items["questions"]) < 2) {
929 ilUtil::sendInfo($this->lng->txt("qpl_define_questionblock_select_missing"), true);
930 $this->ctrl->redirect($this, "questions");
931 }
932
933 $a_form = $this->initQuestionblockForm(null, $items["questions"]);
934 }
935
936 $this->questionsSubtabs("questions");
937 $this->tpl->setContent($a_form->getHTML());
938 }
939
940 protected function initQuestionblockForm($a_block_id = null, $a_question_ids = null)
941 {
942 $form = new ilPropertyFormGUI();
943 $form->setFormAction($this->ctrl->getFormAction($this, "saveDefineQuestionblock"));
944 $form->setTitle($this->lng->txt("define_questionblock"));
945
946 $title = new ilTextInputGUI($this->lng->txt("title"), "title");
947 $title->setRequired(true);
948 $form->addItem($title);
949
950 $toggle_blocktitle = new ilCheckboxInputGUI($this->lng->txt("survey_show_blocktitle"), "show_blocktitle");
951 $toggle_blocktitle->setInfo($this->lng->txt("survey_show_blocktitle_description"));
952 $form->addItem($toggle_blocktitle);
953
954 $toggle_questiontitle = new ilCheckboxInputGUI($this->lng->txt("show_questiontext"), "show_questiontext");
955 $toggle_questiontitle->setInfo($this->lng->txt("show_questiontext_description"));
956 $form->addItem($toggle_questiontitle);
957
958 if ($a_block_id) {
959 $questionblock = ilObjSurvey::_getQuestionblock($a_block_id);
960 $title->setValue($questionblock["title"]);
961 $toggle_blocktitle->setChecked($questionblock["show_blocktitle"]);
962 $toggle_questiontitle->setChecked($questionblock["show_questiontext"]);
963 } else {
964 $toggle_blocktitle->setChecked(true);
965 $toggle_questiontitle->setChecked(true);
966 }
967
968 $compress_view = new ilCheckboxInputGUI($this->lng->txt("svy_compress_view"), "compress_view");
969 $compress_view->setInfo($this->lng->txt("svy_compress_view_info"));
970 $compress_view->setChecked($questionblock["compress_view"]);
971 $form->addItem($compress_view);
972
973 $form->addCommandButton("saveDefineQuestionblock", $this->lng->txt("save"));
974 $form->addCommandButton("questions", $this->lng->txt("cancel"));
975
976 // reload?
977 if (!$a_question_ids && $_POST["qids"]) {
978 $a_question_ids = $_POST["qids"];
979 }
980
981 if ($a_question_ids) {
982 foreach ($a_question_ids as $q_id) {
983 $hidden = new ilHiddenInputGUI("qids[]");
984 $hidden->setValue($q_id);
985 $form->addItem($hidden);
986 }
987 }
988
989 return $form;
990 }
991
993 {
994 $block_id = (int) $_REQUEST["bl_id"];
995 $q_ids = $_POST["qids"];
996
997 $this->ctrl->setParameter($this, "bl_id", $block_id);
998
999 if (!$block_id && !is_array($q_ids)) {
1000 $this->ctrl->redirect($this, "questions");
1001 }
1002
1003 $form = $this->initQuestionblockForm($block_id);
1004 if ($form->checkInput()) {
1005 $title = $form->getInput("title");
1006 $show_questiontext = $form->getInput("show_questiontext");
1007 $show_blocktitle = $form->getInput("show_blocktitle") ;
1008 $compress_view = $form->getInput("compress_view") ;
1009 if ($block_id) {
1010 $this->object->modifyQuestionblock(
1011 $block_id,
1012 $title,
1013 $show_questiontext,
1014 $show_blocktitle,
1015 $compress_view
1016 );
1017 } elseif ($q_ids) {
1018 $this->object->createQuestionblock(
1019 $title,
1020 $show_questiontext,
1021 $show_blocktitle,
1022 $q_ids,
1023 $compress_view
1024 );
1025 }
1026
1027 ilUtil::sendSuccess($this->lng->txt('msg_obj_modified'), true);
1028 $this->ctrl->redirect($this, "questions");
1029 }
1030
1031 $form->setValuesByPost();
1032 $this->editQuestionblockObject($form);
1033 }
1034
1035
1036 //
1037 // HEADING
1038 //
1039
1040 protected function initHeadingForm($a_question_id = null)
1041 {
1042 $survey_questions = $this->object->getSurveyQuestions();
1043
1044 $form = new ilPropertyFormGUI();
1045 $form->setFormAction($this->ctrl->getFormAction($this, ""));
1046
1047 // heading
1048 $heading = new ilTextAreaInputGUI($this->lng->txt("heading"), "heading");
1049 $heading->setRows(10);
1050 $heading->setCols(80);
1051 if (ilObjAdvancedEditing::_getRichTextEditor() === "tinymce") {
1052 $heading->setUseRte(true);
1053 $heading->setRteTags(ilObjAdvancedEditing::_getUsedHTMLTags("survey"));
1054 $heading->removePlugin(ilRTE::ILIAS_IMG_MANAGER_PLUGIN);
1055 $heading->setRTESupport($this->object->getId(), "svy", "survey");
1056 }
1057 $heading->setRequired(true);
1058 $form->addItem($heading);
1059
1060 $insertbefore = new ilSelectInputGUI($this->lng->txt("insert"), "insertbefore");
1061 $options = array();
1062 foreach ($survey_questions as $key => $value) {
1063 $options[$key] = $this->lng->txt("before") . ": \"" . $value["title"] . "\"";
1064 }
1065 $insertbefore->setOptions($options);
1066 $insertbefore->setRequired(true);
1067 $form->addItem($insertbefore);
1068
1069 $form->addCommandButton("saveHeading", $this->lng->txt("save"));
1070 $form->addCommandButton("questions", $this->lng->txt("cancel"));
1071
1072 if ($a_question_id) {
1073 $form->setTitle($this->lng->txt("edit_heading"));
1074
1075 $heading->setValue($this->object->prepareTextareaOutput($survey_questions[$a_question_id]["heading"]));
1076 $insertbefore->setValue($a_question_id);
1077 $insertbefore->setDisabled(true);
1078 } else {
1079 $form->setTitle($this->lng->txt("add_heading"));
1080 }
1081
1082 return $form;
1083 }
1084
1085 public function addHeadingObject(ilPropertyFormGUI $a_form = null)
1086 {
1087 $q_id = $_REQUEST["q_id"];
1088 $this->ctrl->setParameter($this, "q_id", $q_id);
1089
1090 $this->questionsSubtabs("questions");
1091
1092 if (!$a_form) {
1093 $a_form = $this->initHeadingForm($q_id);
1094 }
1095
1096 $this->tpl->setContent($a_form->getHTML());
1097 }
1098
1099 public function editHeadingObject(ilPropertyFormGUI $a_form = null)
1100 {
1101 $q_id = $_REQUEST["q_id"];
1102 $this->ctrl->setParameter($this, "q_id", $q_id);
1103
1104 $this->questionsSubtabs("questions");
1105
1106 if (!$a_form) {
1107 $a_form = $this->initHeadingForm($q_id);
1108 }
1109
1110 $this->tpl->setContent($a_form->getHTML());
1111 }
1112
1113 public function saveHeadingObject()
1114 {
1115 // #15474
1116 $q_id = (int) $_REQUEST["q_id"];
1117 $this->ctrl->setParameter($this, "q_id", $q_id);
1118
1119 $form = $this->initHeadingForm($q_id);
1120 if ($form->checkInput()) {
1121 $this->object->saveHeading(
1123 $form->getInput("heading"),
1124 true,
1126 ),
1127 $form->getInput("insertbefore")
1128 );
1129 $this->ctrl->redirect($this, "questions");
1130 }
1131
1132 $form->setValuesByPost();
1133 $this->addHeadingObject($form);
1134 }
1135
1136 public function removeHeadingObject()
1137 {
1138 $q_id = (int) $_REQUEST["q_id"];
1139 $this->ctrl->setParameter($this, "q_id", $q_id);
1140
1141 if (!$q_id) {
1142 $this->ctrl->redirect($this, "questions");
1143 }
1144
1145 $this->questionsSubtabs("questions");
1146
1147 $cgui = new ilConfirmationGUI();
1148 $cgui->setHeaderText($this->lng->txt("confirm_remove_heading"));
1149
1150 $cgui->setFormAction($this->ctrl->getFormAction($this, "confirmedRemoveHeading"));
1151 $cgui->setCancel($this->lng->txt("cancel"), "questions");
1152 $cgui->setConfirm($this->lng->txt("confirm"), "confirmedRemoveHeading");
1153
1154 $this->tpl->setContent($cgui->getHTML());
1155 }
1156
1158 {
1159 $q_id = (int) $_REQUEST["q_id"];
1160 if (!$q_id) {
1161 $this->ctrl->redirect($this, "questions");
1162 }
1163
1164 $this->object->saveHeading("", $q_id);
1165 $this->ctrl->redirect($this, "questions");
1166 }
1167
1173 public function printViewObject()
1174 {
1175 $ilToolbar = $this->toolbar;
1176
1177 $this->questionsSubtabs("print");
1178
1179 #21023 and #19448
1180 if (!$current_title = (int) $_REQUEST['export_label']) {
1181 $current_title = $this->object->getShowQuestionTitles();
1182 }
1183
1184 $label = new ilSelectInputGUI($this->lng->txt("title") . "/" . $this->lng->txt("label"), "export_label");
1185
1186 #19448 comment none and label only options.
1187 $label->setOptions($this->print_options);
1188 $label->setValue($current_title);
1189
1190 $ilToolbar->addStickyItem($label, true);
1191
1192 $ilToolbar->setFormAction($this->ctrl->getFormAction($this, "printView"));
1193
1194 $button = ilSubmitButton::getInstance();
1195 $button->setCaption("show");
1196 $button->setCommand("printView");
1197 $ilToolbar->addStickyItem($button);
1198
1199 $ilToolbar->addSeparator();
1200
1201 $button = ilLinkButton::getInstance();
1202 $button->setCaption("print");
1203 $button->setOnClick("window.print(); return false;");
1204 $button->setOmitPreventDoubleSubmission(true);
1205 $ilToolbar->addButtonInstance($button);
1206
1207 if (ilRPCServerSettings::getInstance()->isEnabled()) {
1208 $this->ctrl->setParameter($this, "export_label", $current_title);
1209 $this->ctrl->setParameter($this, "pdf", "1");
1210 $pdf_url = $this->ctrl->getLinkTarget($this, "printView");
1211 $this->ctrl->setParameter($this, "pdf", "");
1212 $this->ctrl->setParameter($this, "export_label", "");
1213
1214 $button = ilLinkButton::getInstance();
1215 $button->setCaption("pdf_export");
1216 $button->setUrl($pdf_url);
1217 $button->setOmitPreventDoubleSubmission(true);
1218 $ilToolbar->addButtonInstance($button);
1219 }
1220
1221 // defer rendering of tex to fo processing
1222 if (array_key_exists("pdf", $_GET) && ($_GET["pdf"] == 1)) {
1223 require_once('Services/MathJax/classes/class.ilMathJax.php');
1225 }
1226
1227 $template = new ilTemplate("tpl.il_svy_svy_printview.html", true, true, "Modules/Survey");
1228
1229 $pages = &$this->object->getSurveyPages();
1230 $required = false;
1231 foreach ($pages as $page) {
1232 if (count($page) > 0) {
1233 foreach ($page as $question) {
1234 $questionGUI = $this->object->getQuestionGUI($question["type_tag"], $question["question_id"]);
1235 if (is_object($questionGUI)) {
1236 if (strlen($question["heading"])) {
1237 $template->setCurrentBlock("textblock");
1238 $template->setVariable("TEXTBLOCK", $question["heading"]);
1239 $template->parseCurrentBlock();
1240 }
1241 $template->setCurrentBlock("question");
1242 $template->setVariable("QUESTION_DATA", $questionGUI->getPrintView($current_title, $question["questionblock_show_questiontext"], $this->object->getSurveyId()));
1243 $template->parseCurrentBlock();
1244
1245 if ($question["obligatory"]) {
1246 $required = true;
1247 }
1248 }
1249 }
1250 if (count($page) > 1 && $page[0]["questionblock_show_blocktitle"]) {
1251 $template->setCurrentBlock("page");
1252 $template->setVariable("BLOCKTITLE", $page[0]["questionblock_title"]);
1253 $template->parseCurrentBlock();
1254 } else {
1255 $template->setCurrentBlock("page");
1256 $template->parseCurrentBlock();
1257 }
1258 }
1259 }
1260
1261 // #6412
1262 if ($required) {
1263 $template->setVariable("TEXT_REQUIRED", $this->lng->txt("required_field"));
1264 }
1265
1266 // $this->tpl->addCss("./Modules/Survey/templates/default/survey_print.css", "print");
1267 if (array_key_exists("pdf", $_GET) && ($_GET["pdf"] == 1)) {
1268 $printbody = new ilTemplate("tpl.il_as_tst_print_body.html", true, true, "Modules/Test");
1269 $printbody->setVariable("TITLE", sprintf($this->lng->txt("tst_result_user_name"), $uname));
1270 $printbody->setVariable("ADM_CONTENT", $template->get());
1271 $printoutput = $printbody->get();
1272 $printoutput = preg_replace("/href=\".*?\"/", "", $printoutput);
1273 $fo = $this->object->processPrintoutput2FO($printoutput);
1274
1275 // render tex as fo graphics
1276 require_once('Services/MathJax/classes/class.ilMathJax.php');
1279 ->setRendering(ilMathJax::RENDER_PNG_AS_FO_FILE)
1280 ->insertLatexImages($fo);
1281
1282 // #11436
1283 if (!$fo || !$this->object->deliverPDFfromFO($fo)) {
1284 ilUtil::sendFailure($this->lng->txt("msg_failed"), true);
1285 $this->ctrl->redirect($this, "printView");
1286 }
1287 } else {
1288 $this->tpl->setVariable("ADM_CONTENT", $template->get());
1289 }
1290 }
1291}
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 _getQuestionTypeName($type_tag)
Return the translation for a given question type tag.
static _changeOriginalId($a_question_id, $a_original_id, $a_object_id)
Change original id of existing question in db.
This class represents a checkbox property in a property form.
Confirmation screen class.
This class represents a hidden form property in a property form.
static getInstance()
Factory.
static getInstance()
Singleton: get instance.
const PURPOSE_PDF
const PURPOSE_DEFERRED_PDF
const RENDER_PNG_AS_FO_FILE
static _getUsedHTMLTagsAsString($a_module="")
Returns a string of all allowed HTML tags for text editing.
static _getRichTextEditor()
Returns the identifier for the Rich Text Editor.
static _getUsedHTMLTags($a_module="")
Returns an array of all allowed HTML tags for text editing.
Class ilObjSurveyGUI.
Class ilObjSurveyQuestionPool.
static _getQuestiontypes()
Creates a list of all available question types.
static _instanciateQuestion($question_id)
Creates an instance of a question with a given question id.
static _hasDatasets($survey_id)
static _getQuestionblock($questionblock_id)
Returns the database row for a given question block.
static _lookupObjId($a_id)
This class represents a property form user interface.
static getInstance()
Get singelton instance.
const ILIAS_IMG_MANAGER_PLUGIN
Definition: class.ilRTE.php:14
This class represents a property in a property form.
This class represents an option in a radio group.
This class represents a selection list property in a property form.
Settings template application class.
static getInstance()
Factory.
Message box for survey, when data is alrady available.
Class ilSurveyEditorGUI.
editHeadingObject(ilPropertyFormGUI $a_form=null)
initHeadingForm($a_question_id=null)
removeQuestionsForm($checked_questionblocks, $checked_questions, $checked_headings)
addHeadingObject(ilPropertyFormGUI $a_form=null)
createQuestionblockObject(ilPropertyFormGUI $a_form=null)
__construct(ilObjSurveyGUI $a_parent_gui)
gatherSelectedTableItems($allow_blocks=true, $allow_questions=true, $allow_headings=false, $allow_questions_in_blocks=false)
Gather (and filter) selected items from table gui.
createQuestionPool($name="dummy")
initQuestionblockForm($a_block_id=null, $a_question_ids=null)
editQuestionblockObject(ilPropertyFormGUI $a_form=null)
createQuestionObject(ilPropertyFormGUI $a_form=null)
printViewObject()
Creates a print view of the survey questions.
Survey per page view.
Survey question table GUI class.
special template class to simplify handling of ITX/PEAR
This class represents a text area property in a property form.
This class represents a text property in a property form.
static sendQuestion($a_info="", $a_keep=false)
Send Question to Screen.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
global $DIC
Definition: goto.php:24
help()
Definition: help.php:2
$ilUser
Definition: imgupload.php:18
if($format !==null) $name
Definition: metadata.php:230
$type
$data
Definition: storeScorm.php:23