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