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