ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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{
16 protected $ref_id; // [int]
17 protected $lng; // [object]
18 protected $object; // [ilObjSurvey]
19 protected $editor_gui; // [ilSurveyEditorGUI]
20 protected $current_page; // [int]
21 protected $has_previous_page; // [bool]
22 protected $has_next_page; // [bool]
23 protected $has_datasets; // [bool]
24 protected $use_pool; // [bool]
25
29 protected $log;
30
37 function __construct(ilObjSurvey $a_survey, ilSurveyEditorGUI $a_survey_editor_gui)
38 {
39 $this->editor_gui = $a_survey_editor_gui;
40 $this->ref_id = $a_survey->getRefId();
41 $this->object = $a_survey;
42 $this->log = ilLoggerFactory::getLogger("svy");
43 }
44
48 function executeCommand()
49 {
50 global $lng, $ilCtrl, $rbacsystem;
51
52 $cmd = $ilCtrl->getCmd("renderPage");
53 $next_class = $ilCtrl->getNextClass($this);
54
55 switch($next_class)
56 {
57 default:
58 $this->determineCurrentPage();
59
60 $has_content = false;
61
62 if($rbacsystem->checkAccess("write", $this->ref_id))
63 {
64 // add page?
65 if($_REQUEST["new_id"])
66 {
67 $this->insertNewQuestion($_REQUEST["new_id"]);
68 }
69
70 // subcommands
71 if($_REQUEST["il_hform_subcmd"])
72 {
73 $subcmd = $_REQUEST["il_hform_subcmd"];
74
75 // make sure that it is set for current and next requests
76 $ilCtrl->setParameter($this->editor_gui, "pgov", $this->current_page);
77 $_REQUEST["pgov"] = $this->current_page;
78
79 $id = explode("_", $_REQUEST["il_hform_node"]);
80 $id = (int)$id[1];
81
82 // multi operation
83 if(substr($_REQUEST["il_hform_subcmd"], 0, 5) == "multi")
84 {
85 if($_REQUEST["il_hform_multi"])
86 {
87 // removing types as we only allow questions anyway
88 $id = array();
89 foreach(explode(";", $_REQUEST["il_hform_multi"]) as $item)
90 {
91 $id[] = (int)array_pop(explode("_", $item));
92 }
93
94 if($subcmd == "multiDelete")
95 {
96 $subcmd = "deleteQuestion";
97 }
98 }
99 else
100 {
101 // #9525
102 if($subcmd == "multiDelete")
103 {
104 ilUtil::sendFailure($lng->txt("no_checkbox"), true);
105 $ilCtrl->redirect($this, "renderPage");
106 }
107 else
108 {
109 ilUtil::sendFailure($lng->txt("no_checkbox"));
110 }
111 }
112 }
113
114 if(substr($subcmd, 0, 11) == "addQuestion")
115 {
116 $type = explode("_", $subcmd);
117 $type = (int)$type[1];
118 $has_content = $this->addQuestion($type, $this->object->isPoolActive(), $id, $_REQUEST["il_hform_node"]);
119 }
120 else
121 {
122 $has_content = $this->$subcmd($id, $_REQUEST["il_hform_node"]);
123 }
124 }
125 }
126
127 if(!$has_content)
128 {
129 $this->$cmd();
130 }
131 break;
132 }
133 }
134
138 public function determineCurrentPage()
139 {
140 $current_page = (int)$_REQUEST["jump"];
141 if(!$current_page)
142 {
143 $current_page = (int)$_REQUEST["pgov"];
144 }
145 if(!$current_page)
146 {
147 $current_page = (int)$_REQUEST["pg"];
148 }
149 if(!$current_page)
150 {
151 $current_page = 1;
152 }
153 $this->current_page = $current_page;
154 }
155
163 protected function appendNewQuestionToSurvey($a_new_id, $a_duplicate = true, $a_force_duplicate = false)
164 {
165 global $ilDB;
166
167 $this->log->debug("append question, id: ".$a_new_id.", duplicate: ".$a_duplicate.", force: ".$a_force_duplicate);
168
169 // get maximum sequence index in test
170 $result = $ilDB->queryF("SELECT survey_question_id FROM svy_svy_qst WHERE survey_fi = %s",
171 array('integer'),
172 array($this->object->getSurveyId())
173 );
174 $sequence = $result->numRows();
175
176 // create duplicate if pool question (or forced for question blocks copy)
177 if($a_duplicate)
178 {
179 // this does nothing if this is not a pool question and $a_force_duplicate is false
180 $survey_question_id = $this->object->duplicateQuestionForSurvey($a_new_id, $a_force_duplicate);
181 }
182 // used by copy & paste
183 else
184 {
185 $survey_question_id = $a_new_id;
186 }
187
188 // check if question is not already in the survey, see #22018
189 if ($this->object->isQuestionInSurvey($survey_question_id))
190 {
191 return $survey_question_id;
192 }
193
194 // append to survey
195 $next_id = $ilDB->nextId('svy_svy_qst');
196 $affectedRows = $ilDB->manipulateF("INSERT INTO svy_svy_qst (survey_question_id, survey_fi,".
197 "question_fi, sequence, tstamp) VALUES (%s, %s, %s, %s, %s)",
198 array('integer', 'integer', 'integer', 'integer', 'integer'),
199 array($next_id, $this->object->getSurveyId(), $survey_question_id, $sequence, time())
200 );
201
202 $this->log->debug("insert svy_svy_qst, id: ".$next_id.", qfi: ".$survey_question_id.", seq: ".$sequence);
203
204 return $survey_question_id;
205 }
206
212 public function insertNewQuestion($a_new_id)
213 {
214 global $rbacsystem, $ilDB, $lng;
215
216 include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
217 if (!SurveyQuestion::_isComplete($a_new_id))
218 {
219 ilUtil::sendFailure($lng->txt("survey_error_insert_incomplete_question"));
220 }
221 else
222 {
223 $a_new_id = $this->appendNewQuestionToSurvey($a_new_id);
224 $this->object->loadQuestionsFromDb();
225
226 $pos = $_REQUEST["pgov_pos"];
227
228 // a[fter]/b[efore] on same page
229 if(substr($pos, -1) != "c")
230 {
231 // block handling
232 $current = $this->object->getSurveyPages();
233 $current = $current[$this->current_page-1];
234 if(sizeof($current) == 1)
235 {
236 // as questions are moved to first block question
237 // always use existing as first
238 // the new question is moved later on (see below)
239 $this->object->createQuestionblock($this->getAutoBlockTitle(), true, false,
240 array((int)$pos, $a_new_id));
241 }
242 else
243 {
244 $block_id = array_pop($current);
245 $block_id = $block_id["questionblock_id"];
246
247 $this->object->addQuestionToBlock($a_new_id, $block_id);
248 }
249 }
250 // c: as new page (from toolbar/pool)
251 else
252 {
253 // after given question
254 if((int)$pos)
255 {
256 $pos = (int)$pos."a";
257 $this->current_page++;
258 }
259 // at the beginning
260 else
261 {
262 $first = $this->object->getSurveyPages();
263 $first = $first[0];
264 $first = array_shift($first);
265 $pos = $first["question_id"]."b";
266 $this->current_page = 1;
267 }
268 }
269
270 // move to target position
271 $this->object->moveQuestions(array($a_new_id), (int)$pos,
272 ((substr($pos, -1) == "a") ? 1 : 0));
273
274 $this->object->fixSequenceStructure();
275 }
276 }
277
283 public function insertQuestionBlock($a_block_id)
284 {
285 $new_ids = array();
286 $question_ids = $this->object->getQuestionblockQuestionIds($a_block_id);
287 foreach($question_ids as $qid)
288 {
289 $new_ids[] = $this->appendNewQuestionToSurvey($qid, true, true);
290 }
291
292 if(sizeof($new_ids))
293 {
294 $this->object->loadQuestionsFromDb();
295
296 $pos = $_REQUEST["pgov_pos"];
297
298 // a[fter]/b[efore] on same page
299 if(substr($pos, -1) != "c")
300 {
301 // block handling
302 $current = $this->object->getSurveyPages();
303 $current = $current[$this->current_page-1];
304 if(sizeof($current) == 1)
305 {
306 // as questions are moved to first block question
307 // always use existing as first
308 // the new question is moved later on (see below)
309 $this->object->createQuestionblock($this->getAutoBlockTitle(), true, false,
310 array((int)$pos)+$new_ids);
311 }
312 else
313 {
314 $block_id = array_pop($current);
315 $block_id = $block_id["questionblock_id"];
316
317 foreach($new_ids as $qid)
318 {
319 $this->object->addQuestionToBlock($qid, $block_id);
320 }
321 }
322 }
323 // c: as new page (from toolbar/pool)
324 else
325 {
326 // re-create block
327 $this->object->createQuestionblock($this->getAutoBlockTitle(), true, false,
328 $new_ids);
329
330 // after given question
331 if((int)$pos)
332 {
333 $pos = (int)$pos."a";
334 }
335 // at the beginning
336 else
337 {
338 $first = $this->object->getSurveyPages();
339 $first = $first[0];
340 $first = array_shift($first);
341 $pos = $first["question_id"]."b";
342 }
343 }
344
345 // move to target position
346 $this->object->moveQuestions($new_ids, (int)$pos,
347 ((substr($pos, -1) == "a") ? 1 : 0));
348 }
349 }
350
359 protected function addQuestion($a_type, $a_use_pool, $a_pos, $a_special_position)
360 {
361 global $ilCtrl, $ilTabs;
362
363 // get translated type
364 include_once "./Modules/SurveyQuestionPool/classes/class.ilObjSurveyQuestionPool.php";
366 foreach($questiontypes as $item)
367 {
368 if($item["questiontype_id"] == $a_type)
369 {
370 $type_trans = $item["type_tag"];
371 }
372 }
373
374 $id = $a_pos;
375
376 // new page behind current (from toolbar)
377 if($a_special_position == "toolbar")
378 {
379 $id = $this->object->getSurveyPages();
380 if($a_pos && $a_pos != "fst")
381 {
382 $id = $id[$a_pos-1];
383 $id = array_pop($id);
384 $id = $id["question_id"]."c";
385 }
386 else
387 {
388 $id = "0c";
389 }
390 }
391 // append current page
392 else if($a_special_position == "page_end")
393 {
394 $id = $this->object->getSurveyPages();
395 $id = $id[$this->current_page-1];
396 $id = array_pop($id);
397 $id = $id["question_id"]."a";
398 }
399 else
400 {
401 $id .= "b";
402 }
403
404 if($a_use_pool)
405 {
406 $_GET["sel_question_types"] = $type_trans;
407 $_REQUEST["pgov_pos"] = $id;
408 $ilCtrl->setParameter($this->editor_gui, "pgov_pos", $id);
409 if(!$_POST["usage"])
410 {
411 $ilTabs->clearSubTabs(); // #17193
412 $this->editor_gui->createQuestionObject();
413 }
414 else
415 {
416 $this->editor_gui->executeCreateQuestionObject();
417 }
418 return true;
419 }
420 else
421 {
422 // create question and redirect to question form
423
424 include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestionGUI.php";
425 $q_gui = SurveyQuestionGUI::_getQuestionGUI($type_trans);
426 $q_gui->object->setObjId($this->object->getId());
427 $q_gui->object->createNewQuestion();
428 $q_gui_class = get_class($q_gui);
429
430 // #12531
431 $ilCtrl->setParameterByClass($q_gui_class, "pgov", $this->current_page);
432 $ilCtrl->setParameterByClass($q_gui_class, "pgov_pos",$id);
433 $ilCtrl->setParameterByClass($q_gui_class, "ref_id", $this->ref_id);
434 $ilCtrl->setParameterByClass($q_gui_class, "new_for_survey", $this->ref_id);
435 $ilCtrl->setParameterByClass($q_gui_class, "q_id", $q_gui->object->getId());
436 $ilCtrl->setParameterByClass($q_gui_class, "sel_question_types", $q_gui->getQuestionType());
437 $ilCtrl->redirectByClass($q_gui_class, "editQuestion");
438 }
439 }
440
446 protected function cutQuestion($a_id)
447 {
448 global $lng;
449
450 ilUtil::sendSuccess($lng->txt("survey_questions_to_clipboard_cut"));
451 $this->suppress_clipboard_msg = true;
452
453 $_SESSION["survey_page_view"][$this->ref_id]["clipboard"] = array(
454 "source" => $this->current_page,
455 "nodes" => array($a_id),
456 "mode" => "cut");
457 }
458
464 protected function copyQuestion($a_id)
465 {
466 global $lng;
467
468 ilUtil::sendSuccess($lng->txt("survey_questions_to_clipboard_copy"));
469 $this->suppress_clipboard_msg = true;
470
471 $_SESSION["survey_page_view"][$this->ref_id]["clipboard"] = array(
472 "source" => $this->current_page,
473 "nodes" => array($a_id),
474 "mode" => "copy");
475 }
476
482 protected function multiCut($a_id)
483 {
484 global $lng;
485
486 if (is_array($a_id))
487 {
488 ilUtil::sendSuccess($lng->txt("survey_questions_to_clipboard_cut"));
489 $this->suppress_clipboard_msg = true;
490
491 $_SESSION["survey_page_view"][$this->ref_id]["clipboard"] = array(
492 "source" => $this->current_page,
493 "nodes" => $a_id,
494 "mode" => "cut");
495 }
496 }
497
503 protected function multiCopy($a_id)
504 {
505 global $lng;
506
507 if (is_array($a_id))
508 {
509 ilUtil::sendSuccess($lng->txt("survey_questions_to_clipboard_copy"));
510 $this->suppress_clipboard_msg = true;
511
512 $_SESSION["survey_page_view"][$this->ref_id]["clipboard"] = array(
513 "source" => $this->current_page,
514 "nodes" => $a_id,
515 "mode" => "copy");
516 }
517 }
518
522 protected function clearClipboard()
523 {
524 $_SESSION["survey_page_view"][$this->ref_id]["clipboard"] = null;
525 }
526
532 protected function paste($a_id)
533 {
534 $data = $_SESSION["survey_page_view"][$this->ref_id]["clipboard"];
535 $pages = $this->object->getSurveyPages();
536 $source = $pages[$data["source"]-1];
537 $target = $pages[$this->current_page-1];
538
539 // #12558 - use order of source page
540 $nodes = array();
541 foreach($source as $src_qst)
542 {
543 if(in_array($src_qst["question_id"], $data["nodes"]))
544 {
545 $nodes[] = $src_qst["question_id"];
546 }
547 }
548
549 // append to last position?
550 $pos = 0;
551 if($_REQUEST["il_hform_node"] == "page_end")
552 {
553 $a_id = $target;
554 $a_id = array_pop($a_id);
555 $a_id = $a_id["question_id"];
556 $pos = 1;
557 }
558
559 // cut
560 if($data["mode"] == "cut")
561 {
562 // special case: paste cut on same page (no block handling needed)
563 if($data["source"] == $this->current_page)
564 {
565 // re-order nodes in page
566 if(sizeof($nodes) <= sizeof($source))
567 {
568 $this->object->moveQuestions($nodes, $a_id, $pos);
569 }
570 $this->clearClipboard();
571 return;
572 }
573 else
574 {
575 // only if source has block
576 $source_block_id = false;
577 if(sizeof($source) > 1)
578 {
579 $source_block_id = $source;
580 $source_block_id = array_shift($source_block_id);
581 $source_block_id = $source_block_id["questionblock_id"];
582
583 // remove from block
584 if(sizeof($source) > sizeof($nodes))
585 {
586 foreach($nodes as $qid)
587 {
588 $this->object->removeQuestionFromBlock($qid, $source_block_id);
589 }
590 }
591 // remove complete block
592 else
593 {
594 $this->object->unfoldQuestionblocks(array($source_block_id));
595 }
596 }
597
598 // page will be "deleted" by operation
599 if(sizeof($source) == sizeof($nodes) && $data["source"] < $this->current_page)
600 {
601 $this->current_page--;
602 }
603 }
604 }
605
606 // copy
607 else if($data["mode"] == "copy")
608 {
609 $titles = array();
610 foreach($this->object->getSurveyPages() as $page)
611 {
612 foreach($page as $question)
613 {
614 $titles[] = $question["title"];
615 }
616 }
617
618 // copy questions
619 $question_pointer = array();
620 foreach($nodes as $qid)
621 {
622 // create new questions
623 $question = ilObjSurvey::_instanciateQuestion($qid);
624
625 // handle exisiting copies
626 $title = $question->getTitle();
627 $max = 0;
628 foreach($titles as $existing_title)
629 {
630 #21278 preg_quote with delimiter
631 if(preg_match("/".preg_quote($title, "/")." \‍(([0-9]+)\‍)$/", $existing_title, $match))
632 {
633 $max = max($match[1], $max);
634 }
635 }
636 if($max)
637 {
638 $title .= " (".($max+1).")";
639 }
640 else
641 {
642 $title .= " (2)";
643 }
644 $titles[] = $title;
645 $question->setTitle($title);
646
647 $question->id = -1;
648 $question->saveToDb();
649
650 $question_pointer[$qid] = $question->getId();
651 $this->appendNewQuestionToSurvey($question->getId(), false);
652 }
653
654 // copy textblocks
655 $this->object->cloneTextblocks($question_pointer);
656
657 $this->object->loadQuestionsFromDb();
658
659 $nodes = array_values($question_pointer);
660 }
661
662
663 // paste
664
665 // create new block
666 if(sizeof($target) == 1)
667 {
668 $nodes = array_merge(array($a_id), $nodes);
669
670 // moveQuestions() is called within
671 $this->object->createQuestionblock($this->getAutoBlockTitle(), true, false,
672 $nodes);
673 }
674 // add to existing block
675 else
676 {
677 $target_block_id = $target;
678 $target_block_id = array_shift($target_block_id);
679 $target_block_id = $target_block_id["questionblock_id"];
680
681 foreach($nodes as $qid)
682 {
683 $this->object->addQuestionToBlock($qid, $target_block_id);
684 }
685
686 // move to new position
687 $this->object->moveQuestions($nodes, $a_id, $pos);
688 }
689
690 $this->clearClipboard();
691 }
692
696 protected function dnd()
697 {
698 $source_id = (int)array_pop(explode("_", $_REQUEST["il_hform_source"]));
699 if($_REQUEST["il_hform_target"] != "droparea_end")
700 {
701 $target_id = (int)array_pop(explode("_", $_REQUEST["il_hform_target"]));
702 $pos = 0;
703 }
704 else
705 {
706 $page = $this->object->getSurveyPages();
707 $page = $page[$this->current_page-1];
708 $last = array_pop($page);
709 $target_id = (int)$last["question_id"];
710 $pos = 1;
711 }
712 if($source_id != $target_id)
713 {
714 $this->object->moveQuestions(array($source_id), $target_id, $pos);
715 }
716 }
717
722 protected function deleteBlock()
723 {
724 global $lng, $ilCtrl;
725
726 $ilCtrl->setParameter($this->editor_gui, "pgov", $this->current_page);
727 ilUtil::sendQuestion($lng->txt("remove_questions"));
728
729 $page = $this->object->getSurveyPages();
730 $page = $page[$this->current_page-1];
731
732 // #10567
733 if($_REQUEST["csum"] != md5(print_r($page, true)))
734 {
735 $ilCtrl->redirect($this, "renderPage");
736 }
737
738 $page = array_shift($page);
739 $block_id = $page["questionblock_id"];
740 if($block_id)
741 {
742 $this->editor_gui->removeQuestionsForm(array($block_id), array(), array());
743 }
744 else
745 {
746 $this->editor_gui->removeQuestionsForm(array(), array($page["question_id"]), array());
747 }
748 }
749
755 protected function deleteQuestion($a_id)
756 {
757 global $ilCtrl;
758
759 if(!is_array($a_id))
760 {
761 $a_id = array($a_id);
762 }
763
764 $ilCtrl->setParameter($this->editor_gui, "pgov", $this->current_page);
765 $this->editor_gui->removeQuestionsForm(array(), $a_id, array());
766 return true;
767 }
768
772 protected function confirmRemoveQuestions()
773 {
774 global $ilCtrl;
775
776 // gather ids
777 $ids = array();
778 foreach ($_POST as $key => $value)
779 {
780 if (preg_match("/id_(\d+)/", $key, $matches))
781 {
782 array_push($ids, $matches[1]);
783 }
784 }
785
786
787 $pages = $this->object->getSurveyPages();
788 $source = $pages[$this->current_page-1];
789
790 $block_id = $source;
791 $block_id = array_shift($block_id);
792 $block_id = $block_id["questionblock_id"];
793
794 if(sizeof($ids) && sizeof($source) > sizeof($ids))
795 {
796 // block is obsolete
797 if(sizeof($source)-sizeof($ids) == 1)
798 {
799 $this->object->unfoldQuestionblocks(array($block_id));
800 }
801 // block will remain, remove question(s) from block
802 else
803 {
804 foreach($ids as $qid)
805 {
806 $this->object->removeQuestionFromBlock($qid, $block_id);
807 }
808 }
809
810 $this->object->removeQuestions($ids, array());
811 }
812 // all items on page
813 else
814 {
815 // remove complete block
816 if($block_id)
817 {
818 $this->object->removeQuestions(array(), array($block_id));
819 }
820 // remove single question
821 else
822 {
823 $this->object->removeQuestions($ids, array());
824 }
825
826 // render previous page
827 if($this->current_page > 1)
828 {
829 $this->current_page--;
830 }
831 }
832
833 $this->object->saveCompletionStatus();
834
835 // #10567
836 $ilCtrl->setParameter($this, "pgov", $this->current_page);
837 $ilCtrl->redirect($this, "renderPage");
838 }
839
845 protected function editBlock($a_id)
846 {
847 $this->callEditor("editQuestionblockObject", "bl_id", $a_id);
848 return true;
849 }
850
856 protected function addHeading($a_id)
857 {
858 $this->callEditor("addHeadingObject", "q_id", $a_id);
859 return true;
860 }
861
867 protected function editHeading($a_id)
868 {
869 $this->callEditor("editHeadingObject", "q_id", $a_id);
870 return true;
871 }
872
878 protected function deleteHeading($a_id)
879 {
880 $this->callEditor("removeHeadingObject", "q_id", $a_id);
881 return true;
882 }
883
884 protected function callEditor($a_cmd, $a_param, $a_value)
885 {
886 global $ilTabs;
887
888 $ilTabs->clearSubTabs();
889 $_REQUEST[$a_param] = $a_value;
890
891 call_user_func(array($this->editor_gui, $a_cmd));
892 }
893
899 protected function splitPage($a_id)
900 {
901 $pages = $this->object->getSurveyPages();
902 $source = $pages[$this->current_page-1];
903
904 $block_questions = array();
905 $add = $block_id = false;
906 foreach($source as $idx => $item)
907 {
908 if($item["question_id"] == $a_id)
909 {
910 $block_id = $item["questionblock_id"];
911 $add = $idx;
912 }
913 if($add)
914 {
915 $block_questions[] = $item["question_id"];
916 }
917 }
918
919 // just 1 question left: block is obsolete
920 if($add == 1)
921 {
922 $this->object->unfoldQuestionblocks(array($block_id));
923 }
924 // remove questions from block
925 else
926 {
927 foreach($block_questions as $qid)
928 {
929 $this->object->removeQuestionFromBlock($qid, $block_id);
930 }
931 }
932
933 // more than 1 moved?
934 if(sizeof($block_questions) > 1)
935 {
936 // create new block and move target questions
937 $this->object->createQuestionblock($this->getAutoBlockTitle(), true, false,
938 $block_questions);
939 }
940
941 $this->current_page++;
942 }
943
949 protected function moveNext($a_id)
950 {
951 $pages = $this->object->getSurveyPages();
952 $source = $pages[$this->current_page-1];
954 if(sizeof($target))
955 {
957 $target_id = array_shift($target_id);
958 $target_block_id = $target_id["questionblock_id"];
959 $target_id = $target_id["question_id"];
960
961 // nothing to do if no block
962 if(sizeof($source) > 1)
963 {
964 $block_id = $source;
965 $block_id = array_shift($block_id);
966 $block_id = $block_id["questionblock_id"];
967
968 // source pages block is obsolete
969 if(sizeof($source) == 2)
970 {
971 // delete block
972 $this->object->unfoldQuestionblocks(array($block_id));
973 }
974 else
975 {
976 // remove question from block
977 $this->object->removeQuestionFromBlock($a_id, $block_id);
978 }
979 }
980
981 // move source question to target
982 $this->object->moveQuestions(array($a_id), $target_id, 0);
983
984 // new page has no block yet
985 if(sizeof($target) < 2)
986 {
987 // create block and move target question and source into block
988 $this->object->createQuestionblock($this->getAutoBlockTitle(), true, false,
989 array($a_id, $target_id));
990 }
991 else
992 {
993 // add source question to block
994 $this->object->addQuestionToBlock($a_id, $target_block_id);
995 }
996
997 // only if current page is not "deleted"
998 if(sizeof($source) > 1)
999 {
1000 $this->current_page++;
1001 }
1002 }
1003 }
1004
1010 protected function movePrevious($a_id)
1011 {
1012 $pages = $this->object->getSurveyPages();
1013 $source = $pages[$this->current_page-1];
1014 $target = $pages[$this->current_page-2];
1015 if(sizeof($target))
1016 {
1018 $target_id = array_pop($target_id);
1019 $target_block_id = $target_id["questionblock_id"];
1020 $target_id = $target_id["question_id"];
1021
1022 // nothing to do if no block
1023 if(sizeof($source) > 1)
1024 {
1025 $block_id = $source;
1026 $block_id = array_shift($block_id);
1027 $block_id = $block_id["questionblock_id"];
1028
1029 // source pages block is obsolete
1030 if(sizeof($source) == 2)
1031 {
1032 // delete block
1033 $this->object->unfoldQuestionblocks(array($block_id));
1034 }
1035 else
1036 {
1037 // remove question from block
1038 $this->object->removeQuestionFromBlock($a_id, $block_id);
1039 }
1040 }
1041
1042 // move source question to target
1043 $this->object->moveQuestions(array($a_id), $target_id, 1);
1044
1045 // new page has no block yet
1046 if(sizeof($target) < 2)
1047 {
1048 // create block and move target question and source into block
1049 $this->object->createQuestionblock($this->getAutoBlockTitle(), true, false,
1050 array($target_id, $a_id));
1051 }
1052 else
1053 {
1054 // add source question to block
1055 $this->object->addQuestionToBlock($a_id, $target_block_id);
1056 }
1057
1058 $this->current_page--;
1059 }
1060 }
1061
1067 protected function editQuestion($a_id)
1068 {
1069 global $ilCtrl;
1070
1071 $data = $this->object->getSurveyQuestions();
1072 $data = $data[$a_id];
1073
1074 $q_gui = $data["type_tag"]."GUI";
1075 $ilCtrl->setParameterByClass($q_gui, "pgov", $this->current_page);
1076 $ilCtrl->setParameterByClass($q_gui, "q_id", $a_id);
1077
1078 $ilCtrl->redirectByClass($q_gui, "editQuestion");
1079 }
1080
1084 protected function addQuestionToolbarForm()
1085 {
1086 global $lng, $ilCtrl, $tpl;
1087
1088 include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
1089 $form = new ilPropertyFormGUI();
1090 $form->setFormAction($ilCtrl->getFormAction($this, "addQuestionToolbar"));
1091 $form->setTitle($lng->txt("survey_add_new_question"));
1092
1093 // question types
1094 include_once "./Modules/SurveyQuestionPool/classes/class.ilObjSurveyQuestionPool.php";
1096 $type_map = array();
1097 foreach($questiontypes as $trans => $item)
1098 {
1099 $type_map[$item["questiontype_id"]] = $trans;
1100 }
1101 include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
1102 $si = new ilSelectInputGUI($lng->txt("question_type"), "qtype");
1103 $si->setOptions($type_map);
1104 $form->addItem($si);
1105
1106 $pages = $this->object->getSurveyPages();
1107 if($pages)
1108 {
1109 $pages_drop = array("fst"=>$lng->txt("survey_at_beginning"));
1110 foreach($pages as $idx => $questions)
1111 {
1112 $question = array_shift($questions);
1113 if($question["questionblock_id"])
1114 {
1115 $pages_drop[$idx+1] = $lng->txt("survey_behind_page")." ".$question["questionblock_title"];
1116 }
1117 else
1118 {
1119 $pages_drop[$idx+1] = $lng->txt("survey_behind_page")." ".strip_tags($question["title"]);
1120 }
1121 }
1122 $pos = new ilSelectInputGUI($lng->txt("position"), "pgov");
1123 $pos->setOptions($pages_drop);
1124 $form->addItem($pos);
1125
1126 $pos->setValue($this->current_page);
1127 }
1128 else
1129 {
1130 // #9089: 1st page
1131 $pos = new ilHiddenInputGUI("pgov");
1132 $pos->setValue("fst");
1133 $form->addItem($pos);
1134 }
1135
1136 if($this->object->isPoolActive())
1137 {
1138 $this->editor_gui->createQuestionObject($form);
1139 }
1140
1141 $form->addCommandButton("addQuestionToolbar", $lng->txt("create"));
1142 $form->addCommandButton("renderPage", $lng->txt("cancel"));
1143
1144 return $tpl->setContent($form->getHTML());
1145 }
1146
1150 protected function addQuestionToolbar()
1151 {
1152 global $ilCtrl, $lng;
1153
1154 $pool_active = $this->object->isPoolActive();
1155
1156 if(!$_POST["usage"] && $pool_active)
1157 {
1158 ilUtil::sendFailure($lng->txt("select_one"), true);
1159 return $this->addQuestionToolbarForm();
1160 }
1161
1162 // make sure that it is set for current and next requests
1163 $ilCtrl->setParameter($this->editor_gui, "pgov", $this->current_page);
1164
1165 if(!$this->addQuestion($_POST["qtype"], $pool_active, $_POST["pgov"], "toolbar"))
1166 {
1167 $this->renderPage();
1168 }
1169 }
1170
1174 protected function movePageForm()
1175 {
1176 global $lng, $ilCtrl, $tpl;
1177
1178 include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
1179 $form = new ilPropertyFormGUI();
1180 $form->setFormAction($ilCtrl->getFormAction($this, "movePage"));
1181 $form->setTitle($lng->txt("survey_move_page"));
1182
1183 $old_pos = new ilHiddenInputGUI("old_pos");
1184 $old_pos->setValue($this->current_page);
1185 $form->addItem($old_pos);
1186
1187 $pages = $this->object->getSurveyPages();
1188 if($pages)
1189 {
1190 $pages_drop = array();
1191 if($this->current_page != 1)
1192 {
1193 $pages_drop["fst"] = $lng->txt("survey_at_beginning");
1194 }
1195 foreach($pages as $idx => $questions)
1196 {
1197 if(($idx+1) != $this->current_page && ($idx+2) != $this->current_page)
1198 {
1199 $question = array_shift($questions);
1200 if($question["questionblock_id"])
1201 {
1202 $pages_drop[$idx+1] = $lng->txt("survey_behind_page")." ".$question["questionblock_title"];
1203 }
1204 else
1205 {
1206 $pages_drop[$idx+1] = $lng->txt("survey_behind_page")." ".strip_tags($question["title"]);
1207 }
1208 }
1209 }
1210 $pos = new ilSelectInputGUI($lng->txt("position"), "pgov");
1211 $pos->setOptions($pages_drop);
1212 $form->addItem($pos);
1213 }
1214
1215 $form->addCommandButton("movePage", $lng->txt("submit"));
1216 $form->addCommandButton("renderPage", $lng->txt("cancel"));
1217
1218 return $tpl->setContent($form->getHTML());
1219 }
1220
1225 protected function movePage()
1226 {
1227 global $lng, $ilCtrl;
1228
1229 // current_page is already set to new position
1230 $target_page = $this->current_page-1;
1231 $source_page = $_REQUEST["old_pos"]-1;
1232
1233 $pages = $this->object->getSurveyPages();
1234 foreach($pages[$source_page] as $question)
1235 {
1236 $questions[] = $question["question_id"];
1237 }
1238
1239 // move to first position
1240 $position = 0;
1241 if($_REQUEST["pgov"] != "fst")
1242 {
1243 $position = 1;
1244 }
1245
1246 $target = $pages[$target_page];
1247 if ($position == 0) // before
1248 {
1249 $target = array_shift($target); // ... use always the first question of the page
1250 }
1251 else // after
1252 {
1253 $target = array_pop($target); // ... use always the last question of the page
1254 }
1255 $this->object->moveQuestions($questions, $target["question_id"], $position);
1256
1257 if($target_page < $source_page && $position)
1258 {
1259 $this->current_page++;
1260 }
1261
1262 ilUtil::sendSuccess($lng->txt("survey_page_moved"), true);
1263 $ilCtrl->setParameter($this, "pgov", $this->current_page);
1264 $ilCtrl->redirect($this, "renderPage");
1265 }
1266
1272 protected function renderToolbar($a_pages)
1273 {
1274 global $ilToolbar, $ilCtrl, $lng, $ilUser;
1275
1276 include_once "Services/UIComponent/Button/classes/class.ilLinkButton.php";
1277
1278 if(!$this->has_datasets)
1279 {
1280 $button = ilLinkButton::getInstance();
1281 $button->setCaption("survey_add_new_question");
1282 $button->setUrl($ilCtrl->getLinkTarget($this, "addQuestionToolbarForm"));
1283 $ilToolbar->addStickyItem($button);
1284
1285 if($this->object->isPoolActive())
1286 {
1287 //$ilToolbar->addSeparator();
1288
1289 $last_on_page = 0;
1290 if($a_pages &&
1291 is_array($a_pages[$this->current_page-1]))
1292 {
1293 $last_on_page = $a_pages[$this->current_page-1];
1294 $last_on_page = array_pop($last_on_page);
1295 $last_on_page = $last_on_page["question_id"];
1296 }
1297
1298 $ilCtrl->setParameter($this->editor_gui, "pgov", $this->current_page);
1299 $ilCtrl->setParameter($this->editor_gui, "pgov_pos", $last_on_page."c");
1300
1301 $cmd = ($ilUser->getPref('svy_insert_type') == 1 ||
1302 strlen($ilUser->getPref('svy_insert_type')) == 0)
1303 ? 'browseForQuestions'
1304 : 'browseForQuestionblocks';
1305
1306 $button = ilLinkButton::getInstance();
1307 $button->setCaption("browse_for_questions");
1308 $button->setUrl($ilCtrl->getLinkTarget($this->editor_gui, $cmd));
1309 $ilToolbar->addStickyItem($button);
1310
1311 $ilCtrl->setParameter($this->editor_gui, "pgov", "");
1312 $ilCtrl->setParameter($this->editor_gui, "pgov_pos", "");
1313 }
1314
1315 if($a_pages)
1316 {
1317 $ilToolbar->addSeparator();
1318 }
1319 }
1320
1321 // parse data for pages drop-down
1322 if($a_pages)
1323 {
1324 // previous/next
1325
1326 $ilCtrl->setParameter($this, "pg", $this->current_page-1);
1327 $button = ilLinkButton::getInstance();
1328 $button->setCaption("survey_prev_question");
1329 $button->setUrl($ilCtrl->getLinkTarget($this, "renderPage"));
1330 $button->setDisabled(!$this->has_previous_page);
1331 $ilToolbar->addStickyItem($button);
1332
1333 $ilCtrl->setParameter($this, "pg", $this->current_page+1);
1334 $button = ilLinkButton::getInstance();
1335 $button->setCaption("survey_next_question");
1336 $button->setUrl($ilCtrl->getLinkTarget($this, "renderPage"));
1337 $button->setDisabled(!$this->has_next_page);
1338 $ilToolbar->addStickyItem($button);
1339
1340 $ilCtrl->setParameter($this, "pg", $this->current_page); // #14615
1341
1342 foreach($a_pages as $idx => $questions)
1343 {
1344 $page = $questions;
1345 $page = array_shift($page);
1346 if($page["questionblock_id"])
1347 {
1348 $pages_drop[$idx+1] = $page["questionblock_title"];
1349
1350 if(sizeof($questions) > 1)
1351 {
1352 foreach($questions as $question)
1353 {
1354 $pages_drop[($idx+1)."__".$question["question_id"]] = "- ".$question["title"];
1355 }
1356 }
1357 }
1358 else
1359 {
1360 $pages_drop[$idx+1] = strip_tags($page["title"]);
1361 }
1362 }
1363 }
1364
1365 // jump to page
1366 if(sizeof($pages_drop) > 1)
1367 {
1368 //$ilToolbar->addSeparator();
1369
1370 $ilToolbar->setFormAction($ilCtrl->getFormAction($this));
1371
1372 include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
1373 $si = new ilSelectInputGUI($lng->txt("survey_jump_to"), "jump");
1374 $si->addCustomAttribute("onChange=\"forms['ilToolbar'].submit();\"");
1375 $si->setOptions($pages_drop);
1376 $si->setValue($this->current_page);
1377 $ilToolbar->addInputItem($si, true);
1378
1379 // we need this to have to right cmd
1380 $cmd = new ilHiddenInputGUI("cmd[renderPage]");
1381 $cmd->setValue("1");
1382 $ilToolbar->addInputItem($cmd);
1383
1384 if(!$this->has_datasets)
1385 {
1386 $ilToolbar->addSeparator();
1387
1388 $ilCtrl->setParameter($this, "csum", md5(print_r($a_pages[$this->current_page-1], true)));
1389 $url = $ilCtrl->getLinkTarget($this, "deleteBlock");
1390 $ilCtrl->setParameter($this, "csum", "");
1391
1392 $button = ilLinkButton::getInstance();
1393 $button->setCaption("survey_delete_page");
1394 $button->setUrl($url);
1395 $ilToolbar->addButtonInstance($button);
1396
1397 $ilToolbar->addSeparator();
1398
1399 $button = ilLinkButton::getInstance();
1400 $button->setCaption("survey_move_page");
1401 $button->setUrl($ilCtrl->getLinkTarget($this, "movePageForm"));
1402 $ilToolbar->addButtonInstance($button);
1403 }
1404 }
1405 }
1406
1410 protected function renderPage()
1411 {
1412 global $ilCtrl, $lng, $tpl, $rbacsystem;
1413
1414 $pages = $this->object->getSurveyPages();
1415 $this->has_next_page = ($this->current_page < sizeof($pages));
1416 $this->has_previous_page = ($this->current_page > 1);
1417 $this->has_datasets = ilObjSurvey::_hasDatasets($this->object->getSurveyId());
1418
1419 if($this->has_datasets)
1420 {
1421 $link = $ilCtrl->getLinkTargetByClass(array("ilobjsurveygui", "ilsurveyparticipantsgui"), "maintenance");
1422 $link = "<a href=\"".$link."\">".$lng->txt("survey_has_datasets_warning_page_view_link")."</a>";
1423 ilUtil::sendInfo($lng->txt("survey_has_datasets_warning_page_view")." ".$link);
1424 }
1425
1426 $ilCtrl->setParameter($this, "pg", $this->current_page);
1427 $ilCtrl->setParameter($this, "pgov", "");
1428
1429 $this->renderToolbar($pages);
1430
1431 if($pages)
1432 {
1433 $ttpl = new ilTemplate("tpl.il_svy_svy_page_view.html", true, true, "Modules/Survey");
1434 $ttpl->setVariable("FORM_ACTION", $ilCtrl->getFormAction($this));
1435 $lng->loadLanguageModule("form");
1436
1437 $read_only = ($this->has_datasets || !$rbacsystem->checkAccess("write", $this->ref_id));
1438
1439 $commands = $multi_commands = array();
1440
1441 if(!$read_only)
1442 {
1443 // clipboard is empty
1444 if(!$_SESSION["survey_page_view"][$this->ref_id]["clipboard"])
1445 {
1446 $multi_commands[] = array("cmd"=>"multiDelete", "text"=>$lng->txt("delete"));
1447 $multi_commands[] = array("cmd"=>"multiCut", "text"=>$lng->txt("cut"));
1448 $multi_commands[] = array("cmd"=>"multiCopy", "text"=>$lng->txt("copy"));
1449 $multi_commands[] = array("cmd"=>"selectAll", "text"=>$lng->txt("select_all"));
1450 }
1451 else
1452 {
1453 if(!$this->suppress_clipboard_msg)
1454 {
1455 ilUtil::sendInfo($lng->txt("survey_clipboard_notice"));
1456 }
1457 $multi_commands[] = array("cmd"=>"clearClipboard", "text"=>$lng->txt("survey_dnd_clear_clipboard"));
1458 }
1459
1460 // help - see ilPageObjectGUI::insertHelp()
1461 $lng->loadLanguageModule("content");
1462 $ttpl->setCurrentBlock("help_section");
1463 $ttpl->setVariable("TXT_ADD_EL", $lng->txt("cont_add_elements"));
1464 include_once("./Services/UIComponent/Glyph/classes/class.ilGlyphGUI.php");
1465 $ttpl->setVariable("PLUS", ilGlyphGUI::get(ilGlyphGUI::ADD));
1466 $ttpl->setVariable("DRAG_ARROW", ilGlyphGUI::get(ilGlyphGUI::DRAG));
1467 $ttpl->setVariable("TXT_DRAG", $lng->txt("cont_drag_and_drop_elements"));
1468 $ttpl->setVariable("TXT_SEL", $lng->txt("cont_double_click_to_delete"));
1469 $ttpl->parseCurrentBlock();
1470
1471 $ttpl->setVariable("DND_INIT_JS", "initDragElements();");
1472
1473
1474 // tiny mce
1475
1476 include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
1478
1479 include_once "./Services/RTE/classes/class.ilTinyMCE.php";
1480 $tiny = new ilTinyMCE();
1481 $ttpl->setVariable("WYSIWYG_BLOCKFORMATS", $tiny->_buildAdvancedBlockformatsFromHTMLTags($tags));
1482 $ttpl->setVariable("WYSIWYG_VALID_ELEMENTS", $tiny->_getValidElementsFromHTMLTags($tags));
1483
1484 $buttons_1 = $tiny->_buildAdvancedButtonsFromHTMLTags(1, $tags);
1485 $buttons_2 = $tiny->_buildAdvancedButtonsFromHTMLTags(2, $tags).','.
1486 $tiny->_buildAdvancedTableButtonsFromHTMLTags($tags).
1487 ($tiny->getStyleSelect() ? ',styleselect' : '');
1488 $buttons_3 = $tiny->_buildAdvancedButtonsFromHTMLTags(3, $tags);
1489 $ttpl->setVariable('WYSIWYG_BUTTONS_1', ilTinyMCE::removeRedundantSeparators($buttons_1));
1490 $ttpl->setVariable('WYSIWYG_BUTTONS_2', ilTinyMCE::removeRedundantSeparators($buttons_2));
1491 $ttpl->setVariable('WYSIWYG_BUTTONS_3', ilTinyMCE::removeRedundantSeparators($buttons_3));
1492 }
1493
1494 // commands
1495 if (count($multi_commands) > 0)
1496 {
1497 foreach($multi_commands as $cmd)
1498 {
1499 $ttpl->setCurrentBlock("multi_cmd");
1500 $ttpl->setVariable("ORG_CMD_MULTI", "renderPage");
1501 $ttpl->setVariable("MULTI_CMD", $cmd["cmd"]);
1502 $ttpl->setVariable("MULTI_CMD_TXT", $cmd["text"]);
1503 $ttpl->parseCurrentBlock();
1504 }
1505
1506 $ttpl->setCurrentBlock("multi_cmds");
1507 $ttpl->setVariable("MCMD_ALT", $lng->txt("commands"));
1508 $ttpl->setVariable("MCMD_IMG", ilUtil::getImagePath("arrow_downright.svg"));
1509 $ttpl->parseCurrentBlock();
1510 }
1511
1512 // nodes
1513 $ttpl->setVariable("NODES", $this->getPageNodes($pages[$this->current_page-1],
1514 $this->has_previous_page, $this->has_next_page, $read_only));
1515
1516 $tpl->setContent($ttpl->get());
1517
1518 // add js to template
1519 include_once("./Services/YUI/classes/class.ilYuiUtil.php");
1521 $tpl->addJavascript("./Modules/Survey/js/SurveyPageView.js");
1522 $tpl->addJavascript("./Services/RTE/tiny_mce_3_5_11/tiny_mce_src.js");
1523 }
1524 }
1525
1535 function getPageNodes(array $a_questions, $a_has_previous_page = false, $a_has_next_page = false, $a_readonly = false)
1536 {
1537 global $ilCtrl, $lng;
1538
1539 $ttpl = new ilTemplate("tpl.il_svy_svy_page_view_nodes.html", true, true, "Modules/Survey");
1540
1541 $has_clipboard = (bool)$_SESSION["survey_page_view"][$this->ref_id]["clipboard"];
1542
1543 // question block ?
1544
1545 $first_question = $a_questions;
1546 $first_question = array_shift($first_question);
1547
1548 if($first_question["questionblock_id"])
1549 {
1550 $menu = array();
1551
1552 if(!$a_readonly && !$has_clipboard)
1553 {
1554 $menu[] = array("cmd" => "editBlock", "text" => $lng->txt("edit"));
1555 }
1556
1557 if($first_question["questionblock_show_blocktitle"])
1558 {
1559 $block_status = $lng->txt("survey_block_visible");
1560 }
1561 else
1562 {
1563 $block_status = $lng->txt("survey_block_hidden");
1564 }
1565
1566 $this->renderPageNode($ttpl, "block", $first_question["questionblock_id"],
1567 $first_question["questionblock_title"]." (".$block_status.")", $menu, false, false, $block_status);
1568 }
1569
1570
1571 // questions/headings
1572
1573 include_once "./Modules/SurveyQuestionPool/classes/class.ilObjSurveyQuestionPool.php";
1575 $questionpools = array_keys($this->object->getQuestionpoolTitles(true));
1576
1577 $counter = $question_count;
1578 $block_done = null;
1579 foreach($a_questions as $idx => $question)
1580 {
1581 // drop area
1582
1583 $menu = array();
1584
1585 if(!$a_readonly)
1586 {
1587 if(!$has_clipboard)
1588 {
1589 foreach($questiontypes as $trans => $item)
1590 {
1591 $menu[] = array("cmd"=> "addQuestion_".$item["questiontype_id"],
1592 "text"=> sprintf($lng->txt("svy_page_add_question"), $trans));
1593 }
1594
1595 if($this->object->isPoolActive())
1596 {
1597 $menu[] = array("cmd"=> "addPoolQuestion",
1598 "text"=> $lng->txt("browse_for_questions"));
1599 }
1600 }
1601 else
1602 {
1603 $menu[] = array("cmd" => "paste", "text" => $lng->txt("survey_dnd_paste"));
1604 }
1605 }
1606
1607 $this->renderPageNode($ttpl, "droparea", $question["question_id"], null, $menu, true);
1608
1609 // question
1610 $question_gui = $this->object->getQuestionGUI($question["type_tag"], $question["question_id"]);
1611 $question_form = $question_gui->getWorkingForm(array(), $this->object->getShowQuestionTitles(),
1612 $question["questionblock_show_questiontext"], null, $this->object->getSurveyId());
1613
1614 $menu = array();
1615
1616 if(!$a_readonly && !$has_clipboard)
1617 {
1618 $menu[] = array("cmd" => "editQuestion", "text" => $lng->txt("edit"));
1619 $menu[] = array("cmd" => "cutQuestion", "text" => $lng->txt("cut"));
1620 $menu[] = array("cmd" => "copyQuestion", "text" => $lng->txt("copy"));
1621
1622 if(sizeof($a_questions) > 1 && $idx > 0)
1623 {
1624 $menu[] = array("cmd" => "splitPage", "text" => $lng->txt("survey_dnd_split_page"));
1625 }
1626 if($a_has_next_page)
1627 {
1628 $menu[] = array("cmd" => "moveNext", "text" => $lng->txt("survey_dnd_move_next"));
1629 }
1630 if($a_has_previous_page)
1631 {
1632 $menu[] = array("cmd" => "movePrevious", "text" => $lng->txt("survey_dnd_move_previous"));
1633 }
1634
1635 $menu[] = array("cmd" => "deleteQuestion", "text" => $lng->txt("delete"));
1636
1637 // heading
1638 if($question["heading"])
1639 {
1640 $menu[] = array("cmd" => "editHeading", "text" => $lng->txt("survey_edit_heading"));
1641 $menu[] = array("cmd" => "deleteHeading", "text" => $lng->txt("survey_delete_heading"));
1642 }
1643 else
1644 {
1645 $menu[] = array("cmd" => "addHeading", "text" => $lng->txt("add_heading"));
1646 }
1647 }
1648
1649 if($first_question["questionblock_show_questiontext"])
1650 {
1651 $question_title_status = $lng->txt("survey_question_text_visible");
1652 }
1653 else
1654 {
1655 $question_title_status = $lng->txt("survey_question_text_hidden");
1656 }
1657
1658 $this->renderPageNode($ttpl, "question", $question["question_id"], $question_form, $menu,
1659 false, $question["title"], $question_title_status, $question["heading"]);
1660
1661 $ilCtrl->setParameter($this, "eqid", "");
1662 }
1663
1664
1665 // last position (no question id)
1666
1667 $menu = array();
1668
1669 if(!$a_readonly)
1670 {
1671 if(!$has_clipboard)
1672 {
1673 foreach($questiontypes as $trans => $item)
1674 {
1675 $menu[] = array("cmd"=> "addQuestion_".$item["questiontype_id"],
1676 "text"=> sprintf($lng->txt("svy_page_add_question"), $trans));
1677 }
1678
1679 if($this->object->isPoolActive())
1680 {
1681 $menu[] = array("cmd"=> "addPoolQuestion",
1682 "text"=> $lng->txt("browse_for_questions"));
1683 }
1684 }
1685 else
1686 {
1687 $menu[] = array("cmd" => "paste", "text" => $lng->txt("survey_dnd_paste"));
1688 }
1689 }
1690
1691 $this->renderPageNode($ttpl, "page", "end", null, $menu, true);
1692
1693 return $ttpl->get();
1694 }
1695
1708 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)
1709 {
1710 global $ilCtrl, $lng;
1711
1712 $node_id = $a_type."_".$a_id;
1713
1714 if($a_spacer)
1715 {
1716 if($a_menu)
1717 {
1718 // drop area menu
1719 foreach($a_menu as $mcnt => $menu_item)
1720 {
1721 $ilCtrl->setParameter($this, "il_hform_node", $node_id);
1722 $ilCtrl->setParameter($this, "il_hform_subcmd", $menu_item["cmd"]);
1723 $url = $ilCtrl->getLinkTarget($this, "renderPage");
1724 $ilCtrl->setParameter($this, "il_hform_subcmd", "");
1725 $ilCtrl->setParameter($this, "il_hform_node", "");
1726
1727 $a_tpl->setCurrentBlock("menu_cmd");
1728 $a_tpl->setVariable("TXT_MENU_CMD", $menu_item["text"]);
1729 $a_tpl->setVariable("URL_MENU_CMD", $url);
1730 $a_tpl->parseCurrentBlock();
1731 }
1732 }
1733
1734 $a_tpl->setCurrentBlock("drop_area");
1735 include_once "Services/UIComponent/Glyph/classes/class.ilGlyphGUI.php";
1736 $a_tpl->setVariable("ICON_ADD", ilGlyphGUI::get(ilGlyphGUI::ADD));
1737 $a_tpl->setVariable("DROP_ID", $a_id);
1738 $a_tpl->parseCurrentBlock();
1739 }
1740 else if($a_menu)
1741 {
1742 // question action menu
1743 foreach($a_menu as $mcnt => $menu_item)
1744 {
1745 $ilCtrl->setParameter($this, "il_hform_node", $node_id);
1746 $ilCtrl->setParameter($this, "il_hform_subcmd", $menu_item["cmd"]);
1747 $url = $ilCtrl->getLinkTarget($this, "renderPage");
1748 $ilCtrl->setParameter($this, "il_hform_subcmd", "");
1749 $ilCtrl->setParameter($this, "il_hform_node", "");
1750
1751 $a_tpl->setCurrentBlock("action_cmd");
1752 $a_tpl->setVariable("TXT_ACTION_CMD", $menu_item["text"]);
1753 $a_tpl->setVariable("URL_ACTION_CMD", $url);
1754 $a_tpl->parseCurrentBlock();
1755 }
1756 }
1757
1758 // add heading to content
1759 if($a_content !== null &&
1760 $a_type == "question" &&
1761 $a_heading)
1762 {
1763 $a_content = "<div class=\"questionheading\">".$a_heading."</div>".
1764 $a_content;
1765 }
1766
1767 if($a_menu)
1768 {
1769 $a_tpl->setVariable("TXT_NODE_CONTENT_ACTIONS", $a_content);
1770 }
1771 else
1772 {
1773 $a_tpl->setVariable("TXT_NODE_CONTENT_NO_ACTIONS", $a_content);
1774 }
1775
1776 if($a_content !== null)
1777 {
1778 $drag = "";
1779 $selectable = false;
1780 switch($a_type)
1781 {
1782 case "block":
1783 $caption = $lng->txt("questionblock");
1784 break;
1785
1786 case "question":
1787 $caption = $lng->txt("question").": ".$a_subtitle;
1788 $drag = "_drag";
1789 $selectable = true;
1790 break;
1791
1792 case "heading":
1793 $caption = $lng->txt("heading");
1794 break;
1795
1796 default:
1797 return;
1798 }
1799
1800 if($a_status)
1801 {
1802 $caption .= " (".$a_status.")";
1803 }
1804
1805 $a_tpl->setCurrentBlock("list_item");
1806 $a_tpl->setVariable("NODE_ID", $node_id);
1807 $a_tpl->setVariable("NODE_DRAG", $drag);
1808 $a_tpl->setVariable("TXT_NODE_TYPE", $caption);
1809 if($selectable)
1810 {
1811 $a_tpl->setVariable("SELECTABLE", " selectable");
1812 }
1813 $a_tpl->parseCurrentBlock();
1814 }
1815
1816 $a_tpl->touchBlock("element");
1817 }
1818
1824 public function getAutoBlockTitle()
1825 {
1826 global $lng;
1827
1828 return $lng->txt("survey_auto_block_title");
1829 }
1830
1831 public function addPoolQuestion($pos, $node)
1832 {
1833 global $ilCtrl, $ilUser;
1834
1835 if($node == "page_end")
1836 {
1837 $pos = $this->object->getSurveyPages();
1838 $pos = array_pop($pos[$this->current_page-1]);
1839 $pos = $pos["question_id"]."a";
1840 }
1841 else
1842 {
1843 $pos = $pos."b";
1844 }
1845
1846 $ilCtrl->setParameter($this->editor_gui, "pgov", $this->current_page);
1847 $ilCtrl->setParameter($this->editor_gui, "pgov_pos", $pos);
1848
1849 $cmd = ($ilUser->getPref('svy_insert_type') == 1 || strlen($ilUser->getPref('svy_insert_type')) == 0) ? 'browseForQuestions' : 'browseForQuestionblocks';
1850 $ilCtrl->redirect($this->editor_gui, $cmd);
1851 }
1852}
1853
1854?>
sprintf('%.4f', $callTime)
$result
global $tpl
Definition: ilias.php:8
$_GET["client_id"]
$_POST["username"]
$_SESSION["AccountId"]
An exception for terminatinating execution or to throw for unit testing.
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:613
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.
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.
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 sendSuccess($a_info="", $a_keep=false)
Send Success Message 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()
Init YUI Drag and Drop.
$counter
$target_id
Definition: goto.php:51
global $ilCtrl
Definition: ilias.php:18
$cmd
Definition: sahs_server.php:35
$url
Definition: shib_logout.php:72
global $ilDB
$ilUser
Definition: imgupload.php:18
$a_content
Definition: workflow.php:94
$a_type
Definition: workflow.php:93