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