ILIAS  Release_4_2_x_branch Revision 61807
 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  $nodes = $data["nodes"];
499 
500  // append to last position?
501  $pos = 0;
502  if($_REQUEST["il_hform_node"] == "page_end")
503  {
504  $a_id = $target;
505  $a_id = array_pop($a_id);
506  $a_id = $a_id["question_id"];
507  $pos = 1;
508  }
509 
510  // cut
511  if($data["mode"] == "cut")
512  {
513  // special case: paste cut on same page (no block handling needed)
514  if($data["source"] == $this->current_page)
515  {
516  // re-order nodes in page
517  if(sizeof($nodes) <= sizeof($source))
518  {
519  $this->object->moveQuestions($nodes, $a_id, $pos);
520  }
521  $this->clearClipboard();
522  return;
523  }
524  else
525  {
526  // only if source has block
527  $source_block_id = false;
528  if(sizeof($source) > 1)
529  {
530  $source_block_id = $source;
531  $source_block_id = array_shift($source_block_id);
532  $source_block_id = $source_block_id["questionblock_id"];
533 
534  // remove from block
535  if(sizeof($source) > sizeof($nodes))
536  {
537  foreach($nodes as $qid)
538  {
539  $this->object->removeQuestionFromBlock($qid, $source_block_id);
540  }
541  }
542  // remove complete block
543  else
544  {
545  $this->object->unfoldQuestionblocks(array($source_block_id));
546  }
547  }
548 
549  // page will be "deleted" by operation
550  if(sizeof($source) == sizeof($nodes) && $data["source"] < $this->current_page)
551  {
552  $this->current_page--;
553  }
554  }
555  }
556 
557  // copy
558  else if($data["mode"] == "copy")
559  {
560  $titles = array();
561  foreach($this->object->getSurveyPages() as $page)
562  {
563  foreach($page as $question)
564  {
565  $titles[] = $question["title"];
566  }
567  }
568 
569  // copy questions
570  $question_pointer = array();
571  foreach($nodes as $qid)
572  {
573  // create new questions
574  $question = ilObjSurvey::_instanciateQuestion($qid);
575 
576  // handle exisiting copies
577  $title = $question->getTitle();
578  $max = 0;
579  foreach($titles as $existing_title)
580  {
581  if(preg_match("/".preg_quote($title)." \(([0-9]+)\)$/", $existing_title, $match))
582  {
583  $max = max($match[1], $max);
584  }
585  }
586  if($max)
587  {
588  $title .= " (".($max+1).")";
589  }
590  else
591  {
592  $title .= " (2)";
593  }
594  $titles[] = $title;
595  $question->setTitle($title);
596 
597  $question->id = -1;
598  $question->saveToDb();
599 
600  $question_pointer[$qid] = $question->getId();
601  $this->appendNewQuestionToSurvey($question->getId(), false);
602  }
603 
604  // copy textblocks
605  $this->object->cloneTextblocks($question_pointer);
606 
607  $this->object->loadQuestionsFromDb();
608 
609  $nodes = array_values($question_pointer);
610  }
611 
612 
613  // paste
614 
615  // create new block
616  if(sizeof($target) == 1)
617  {
618  $nodes = array_merge(array($a_id), $nodes);
619 
620  // moveQuestions() is called within
621  $this->object->createQuestionblock($this->getAutoBlockTitle(), true, false,
622  $nodes);
623  }
624  // add to existing block
625  else
626  {
627  $target_block_id = $target;
628  $target_block_id = array_shift($target_block_id);
629  $target_block_id = $target_block_id["questionblock_id"];
630 
631  foreach($nodes as $qid)
632  {
633  $this->object->addQuestionToBlock($qid, $target_block_id);
634  }
635 
636  // move to new position
637  $this->object->moveQuestions($nodes, $a_id, $pos);
638  }
639 
640  $this->clearClipboard();
641  }
642 
646  protected function dnd()
647  {
648  $source_id = (int)array_pop(explode("_", $_REQUEST["il_hform_source"]));
649  if($_REQUEST["il_hform_target"] != "page_end")
650  {
651  $target_id = (int)array_pop(explode("_", $_REQUEST["il_hform_target"]));
652  $pos = 0;
653  }
654  else
655  {
656  $page = $this->object->getSurveyPages();
657  $page = $page[$this->current_page-1];
658  $last = array_pop($page);
659  $target_id = (int)$last["question_id"];
660  $pos = 1;
661  }
662  if($source_id != $target_id)
663  {
664  $this->object->moveQuestions(array($source_id), $target_id, $pos);
665  }
666  }
667 
672  protected function deleteBlock()
673  {
674  global $lng, $ilCtrl;
675 
676  $this->survey_gui->questionsSubtabs('questions_per_page');
677 
678  $ilCtrl->setParameter($this->survey_gui, "pgov", $this->current_page);
679  ilUtil::sendQuestion($lng->txt("remove_questions"));
680 
681  $page = $this->object->getSurveyPages();
682  $page = $page[$this->current_page-1];
683 
684  // #10567
685  if($_REQUEST["csum"] != md5(print_r($page, true)))
686  {
687  $ilCtrl->redirect($this, "renderPage");
688  }
689 
690  $page = array_shift($page);
691  $block_id = $page["questionblock_id"];
692  if($block_id)
693  {
694  $this->survey_gui->removeQuestionsForm(array($block_id), array(), array());
695  }
696  else
697  {
698  $this->survey_gui->removeQuestionsForm(array(), array($page["question_id"]), array());
699  }
700  }
701 
707  protected function deleteQuestion($a_id)
708  {
709  if(!is_array($a_id))
710  {
711  $a_id = array($a_id);
712  }
713  $this->survey_gui->removeQuestionsForm(array(), $a_id, array());
714  return true;
715  }
716 
720  protected function confirmRemoveQuestions()
721  {
722  global $ilCtrl;
723 
724  // gather ids
725  $ids = array();
726  foreach ($_POST as $key => $value)
727  {
728  if (preg_match("/id_(\d+)/", $key, $matches))
729  {
730  array_push($ids, $matches[1]);
731  }
732  }
733 
734 
735  $pages = $this->object->getSurveyPages();
736  $source = $pages[$this->current_page-1];
737 
738  $block_id = $source;
739  $block_id = array_shift($block_id);
740  $block_id = $block_id["questionblock_id"];
741 
742  if(sizeof($ids) && sizeof($source) > sizeof($ids))
743  {
744  // block is obsolete
745  if(sizeof($source)-sizeof($ids) == 1)
746  {
747  $this->object->unfoldQuestionblocks(array($block_id));
748  }
749  // block will remain, remove question(s) from block
750  else
751  {
752  foreach($ids as $qid)
753  {
754  $this->object->removeQuestionFromBlock($qid, $block_id);
755  }
756  }
757 
758  $this->object->removeQuestions($ids, array());
759  }
760  // all items on page
761  else
762  {
763  // remove complete block
764  if($block_id)
765  {
766  $this->object->removeQuestions(array(), array($block_id));
767  }
768  // remove single question
769  else
770  {
771  $this->object->removeQuestions($ids, array());
772  }
773 
774  // render previous page
775  if($this->current_page > 1)
776  {
777  $this->current_page--;
778  }
779  }
780 
781  $this->object->saveCompletionStatus();
782 
783  // #10567
784  $ilCtrl->setParameter($this, "pgov", $this->current_page);
785  $ilCtrl->redirect($this, "renderPage");
786  }
787 
793  protected function editBlock($a_id)
794  {
795  $this->survey_gui->defineQuestionblock($a_id);
796  return true;
797  }
798 
804  protected function addHeading($a_id)
805  {
806  $this->survey_gui->addHeadingObject(false, $a_id);
807  return true;
808  }
809 
815  protected function editHeading($a_id)
816  {
817  $this->survey_gui->addHeadingObject(false, $a_id);
818  return true;
819  }
820 
826  protected function deleteHeading($a_id)
827  {
828  $_GET["removeheading"] = $a_id;
829  $this->survey_gui->confirmRemoveHeadingForm();
830  return true;
831  }
832 
838  protected function splitPage($a_id)
839  {
840  $pages = $this->object->getSurveyPages();
841  $source = $pages[$this->current_page-1];
842 
843  $block_questions = array();
844  $add = $block_id = false;
845  foreach($source as $idx => $item)
846  {
847  if($item["question_id"] == $a_id)
848  {
849  $block_id = $item["questionblock_id"];
850  $add = $idx;
851  }
852  if($add)
853  {
854  $block_questions[] = $item["question_id"];
855  }
856  }
857 
858  // just 1 question left: block is obsolete
859  if($add == 1)
860  {
861  $this->object->unfoldQuestionblocks(array($block_id));
862  }
863  // remove questions from block
864  else
865  {
866  foreach($block_questions as $qid)
867  {
868  $this->object->removeQuestionFromBlock($qid, $block_id);
869  }
870  }
871 
872  // more than 1 moved?
873  if(sizeof($block_questions) > 1)
874  {
875  // create new block and move target questions
876  $this->object->createQuestionblock($this->getAutoBlockTitle(), true, false,
877  $block_questions);
878  }
879 
880  $this->current_page++;
881  }
882 
888  protected function moveNext($a_id)
889  {
890  $pages = $this->object->getSurveyPages();
891  $source = $pages[$this->current_page-1];
892  $target = $pages[$this->current_page];
893  if(sizeof($target))
894  {
895  $target_id = $target;
896  $target_id = array_shift($target_id);
897  $target_block_id = $target_id["questionblock_id"];
898  $target_id = $target_id["question_id"];
899 
900  // nothing to do if no block
901  if(sizeof($source) > 1)
902  {
903  $block_id = $source;
904  $block_id = array_shift($block_id);
905  $block_id = $block_id["questionblock_id"];
906 
907  // source pages block is obsolete
908  if(sizeof($source) == 2)
909  {
910  // delete block
911  $this->object->unfoldQuestionblocks(array($block_id));
912  }
913  else
914  {
915  // remove question from block
916  $this->object->removeQuestionFromBlock($a_id, $block_id);
917  }
918  }
919 
920  // move source question to target
921  $this->object->moveQuestions(array($a_id), $target_id, 0);
922 
923  // new page has no block yet
924  if(sizeof($target) < 2)
925  {
926  // create block and move target question and source into block
927  $this->object->createQuestionblock($this->getAutoBlockTitle(), true, false,
928  array($a_id, $target_id));
929  }
930  else
931  {
932  // add source question to block
933  $this->object->addQuestionToBlock($a_id, $target_block_id);
934  }
935 
936  // only if current page is not "deleted"
937  if(sizeof($source) > 1)
938  {
939  $this->current_page++;
940  }
941  }
942  }
943 
949  protected function movePrevious($a_id)
950  {
951  $pages = $this->object->getSurveyPages();
952  $source = $pages[$this->current_page-1];
953  $target = $pages[$this->current_page-2];
954  if(sizeof($target))
955  {
956  $target_id = $target;
957  $target_id = array_pop($target_id);
958  $target_block_id = $target_id["questionblock_id"];
959  $target_id = $target_id["question_id"];
960 
961  // nothing to do if no block
962  if(sizeof($source) > 1)
963  {
964  $block_id = $source;
965  $block_id = array_shift($block_id);
966  $block_id = $block_id["questionblock_id"];
967 
968  // source pages block is obsolete
969  if(sizeof($source) == 2)
970  {
971  // delete block
972  $this->object->unfoldQuestionblocks(array($block_id));
973  }
974  else
975  {
976  // remove question from block
977  $this->object->removeQuestionFromBlock($a_id, $block_id);
978  }
979  }
980 
981  // move source question to target
982  $this->object->moveQuestions(array($a_id), $target_id, 1);
983 
984  // new page has no block yet
985  if(sizeof($target) < 2)
986  {
987  // create block and move target question and source into block
988  $this->object->createQuestionblock($this->getAutoBlockTitle(), true, false,
989  array($target_id, $a_id));
990  }
991  else
992  {
993  // add source question to block
994  $this->object->addQuestionToBlock($a_id, $target_block_id);
995  }
996 
997  $this->current_page--;
998  }
999  }
1000 
1006  protected function editQuestion($a_id)
1007  {
1008  $data = $this->object->getQuestions(array($a_id));
1009  $pool_id = current(ilObject::_getAllReferences($data[0]["obj_fi"]));
1010 
1011  ilUtil::redirect("ilias.php?baseClass=ilObjSurveyQuestionPoolGUI&ref_id=".
1012  $pool_id."&cmd=editQuestionForSurvey&calling_survey=".
1013  $this->ref_id."&q_id=".$a_id."&pgov=".$this->current_page);
1014  }
1015 
1019  protected function addQuestionToolbarForm()
1020  {
1021  global $lng, $ilCtrl, $tpl;
1022 
1023  $this->survey_gui->questionsSubtabs('questions_per_page');
1024 
1025  include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
1026  $form = new ilPropertyFormGUI();
1027  $form->setFormAction($ilCtrl->getFormAction($this, "addQuestionToolbar"));
1028  $form->setTitle($lng->txt("survey_add_new_question"));
1029 
1030  // question types
1031  include_once "./Modules/SurveyQuestionPool/classes/class.ilObjSurveyQuestionPool.php";
1032  $questiontypes = ilObjSurveyQuestionPool::_getQuestiontypes();
1033  $type_map = array();
1034  foreach($questiontypes as $trans => $item)
1035  {
1036  $type_map[$item["questiontype_id"]] = $trans;
1037  }
1038  include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
1039  $si = new ilSelectInputGUI($lng->txt("question_type"), "qtype");
1040  $si->setOptions($type_map);
1041  $form->addItem($si);
1042 
1043  $pages = $this->object->getSurveyPages();
1044  if($pages)
1045  {
1046  $pages_drop = array("fst"=>$lng->txt("survey_at_beginning"));
1047  foreach($pages as $idx => $questions)
1048  {
1049  $question = array_shift($questions);
1050  if($question["questionblock_id"])
1051  {
1052  $pages_drop[$idx+1] = $lng->txt("survey_behind_page")." ".$question["questionblock_title"];
1053  }
1054  else
1055  {
1056  $pages_drop[$idx+1] = $lng->txt("survey_behind_page")." ".strip_tags($question["title"]);
1057  }
1058  }
1059  $pos = new ilSelectInputGUI($lng->txt("position"), "pgov");
1060  $pos->setOptions($pages_drop);
1061  $form->addItem($pos);
1062 
1063  $pos->setValue($this->current_page);
1064  }
1065  else
1066  {
1067  // #9089 / #9613: 1st page
1068  $pos = new ilHiddenInputGUI("pgov");
1069  $pos->setValue("fst");
1070  $form->addItem($pos);
1071  }
1072 
1073  if($this->object->isPoolActive())
1074  {
1075  $this->survey_gui->createQuestionObject($form);
1076  }
1077 
1078  $form->addCommandButton("addQuestionToolbar", $lng->txt("submit"));
1079  $form->addCommandButton("renderPage", $lng->txt("cancel"));
1080 
1081  return $tpl->setContent($form->getHTML());
1082  }
1083 
1087  protected function addQuestionToolbar()
1088  {
1089  global $ilCtrl, $lng;
1090 
1091  $pool_active = $this->object->isPoolActive();
1092 
1093  if(!$_POST["usage"] && $pool_active)
1094  {
1095  ilUtil::sendFailure($lng->txt("select_one"), true);
1096  return $this->addQuestionToolbarForm();
1097  }
1098 
1099  // make sure that it is set for current and next requests
1100  $ilCtrl->setParameter($this->survey_gui, "pgov", $this->current_page);
1101 
1102  if(!$this->addQuestion($_POST["qtype"], $pool_active, $_POST["pgov"], "toolbar"))
1103  {
1104  $this->renderPage();
1105  }
1106  }
1107 
1111  protected function movePageForm()
1112  {
1113  global $lng, $ilCtrl, $tpl;
1114 
1115  $this->survey_gui->questionsSubtabs('questions_per_page');
1116 
1117  include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
1118  $form = new ilPropertyFormGUI();
1119  $form->setFormAction($ilCtrl->getFormAction($this, "movePage"));
1120  $form->setTitle($lng->txt("survey_move_page"));
1121 
1122  $old_pos = new ilHiddenInputGUI("old_pos");
1123  $old_pos->setValue($this->current_page);
1124  $form->addItem($old_pos);
1125 
1126  $pages = $this->object->getSurveyPages();
1127  if($pages)
1128  {
1129  $pages_drop = array();
1130  if($this->current_page != 1)
1131  {
1132  $pages_drop["fst"] = $lng->txt("survey_at_beginning");
1133  }
1134  foreach($pages as $idx => $questions)
1135  {
1136  if(($idx+1) != $this->current_page && ($idx+2) != $this->current_page)
1137  {
1138  $question = array_shift($questions);
1139  if($question["questionblock_id"])
1140  {
1141  $pages_drop[$idx+1] = $lng->txt("survey_behind_page")." ".$question["questionblock_title"];
1142  }
1143  else
1144  {
1145  $pages_drop[$idx+1] = $lng->txt("survey_behind_page")." ".strip_tags($question["title"]);
1146  }
1147  }
1148  }
1149  $pos = new ilSelectInputGUI($lng->txt("position"), "pgov");
1150  $pos->setOptions($pages_drop);
1151  $form->addItem($pos);
1152  }
1153 
1154  $form->addCommandButton("movePage", $lng->txt("submit"));
1155  $form->addCommandButton("renderPage", $lng->txt("cancel"));
1156 
1157  return $tpl->setContent($form->getHTML());
1158  }
1159 
1163  protected function movePage()
1164  {
1165  global $lng, $ilCtrl;
1166 
1167  // current_page is already set to new position
1168  $target_page = $this->current_page-1;
1169  $source_page = $_REQUEST["old_pos"]-1;
1170 
1171  $pages = $this->object->getSurveyPages();
1172  foreach($pages[$source_page] as $question)
1173  {
1174  $questions[] = $question["question_id"];
1175  }
1176 
1177  // move to first position
1178  $position = 0;
1179  if($_REQUEST["pgov"] != "fst")
1180  {
1181  $position = 1;
1182  }
1183 
1184  $target = $pages[$target_page];
1185  $target = array_shift($target);
1186  $this->object->moveQuestions($questions, $target["question_id"], $position);
1187 
1188  if($target_page < $source_page && $position)
1189  {
1190  $this->current_page++;
1191  }
1192 
1193  ilUtil::sendSuccess($lng->txt("survey_page_moved"), true);
1194  $ilCtrl->setParameter($this, "pgov", $this->current_page);
1195  $ilCtrl->redirect($this, "renderPage");
1196  }
1197 
1203  protected function renderToolbar($a_pages)
1204  {
1205  global $ilToolbar, $ilCtrl, $lng, $ilUser;
1206 
1207  if(!$this->has_datasets)
1208  {
1209  $ilToolbar->addButton($lng->txt("survey_add_new_question"), $ilCtrl->getLinkTarget($this, "addQuestionToolbarForm"));
1210 
1211  if($this->object->isPoolActive())
1212  {
1213  $ilToolbar->addSeparator();
1214 
1215  $last_on_page = 0;
1216  if($a_pages)
1217  {
1218  $last_on_page = $a_pages[$this->current_page-1];
1219  $last_on_page = array_pop($last_on_page);
1220  $last_on_page = $last_on_page["question_id"];
1221  }
1222 
1223  $ilCtrl->setParameter($this->survey_gui, "pgov", $this->current_page);
1224  $ilCtrl->setParameter($this->survey_gui, "pgov_pos", $last_on_page."c");
1225 
1226  $cmd = ($ilUser->getPref('svy_insert_type') == 1 || strlen($ilUser->getPref('svy_insert_type')) == 0) ? 'browseForQuestions' : 'browseForQuestionblocks';
1227  $ilToolbar->addButton($lng->txt("browse_for_questions"),
1228  $ilCtrl->getLinkTarget($this->survey_gui, $cmd));
1229 
1230  $ilCtrl->setParameter($this->survey_gui, "pgov", "");
1231  $ilCtrl->setParameter($this->survey_gui, "pgov_pos", "");
1232  }
1233 
1234  if($a_pages)
1235  {
1236  $ilToolbar->addSeparator();
1237  }
1238  }
1239 
1240  // parse data for pages drop-down
1241  if($a_pages)
1242  {
1243  // previous/next
1244  $ilCtrl->setParameter($this, "pg", $this->current_page-1);
1245  $ilToolbar->addLink($lng->txt("survey_prev_question"),
1246  $ilCtrl->getLinkTarget($this, "renderPage"), !$this->has_previous_page);
1247  $ilCtrl->setParameter($this, "pg", $this->current_page+1);
1248  $ilToolbar->addLink($lng->txt("survey_next_question"),
1249  $ilCtrl->getLinkTarget($this, "renderPage"), !$this->has_next_page);
1250  $ilCtrl->setParameter($this, "pg", $this->current_page);
1251 
1252  foreach($a_pages as $idx => $questions)
1253  {
1254  $page = $questions;
1255  $page = array_shift($page);
1256  if($page["questionblock_id"])
1257  {
1258  $pages_drop[$idx+1] = $page["questionblock_title"];
1259 
1260  if(sizeof($questions) > 1)
1261  {
1262  foreach($questions as $question)
1263  {
1264  $pages_drop[($idx+1)."__".$question["question_id"]] = "- ".$question["title"];
1265  }
1266  }
1267  }
1268  else
1269  {
1270  $pages_drop[$idx+1] = strip_tags($page["title"]);
1271  }
1272  }
1273  }
1274 
1275  // jump to page
1276  if(sizeof($pages_drop) > 1)
1277  {
1278  $ilToolbar->addSeparator();
1279 
1280  $ilToolbar->setFormAction($ilCtrl->getFormAction($this));
1281 
1282  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
1283  $si = new ilSelectInputGUI($lng->txt("survey_jump_to"), "jump");
1284  $si->addCustomAttribute("onChange=\"forms['ilToolbar'].submit();\"");
1285  $si->setOptions($pages_drop);
1286  $si->setValue($this->current_page);
1287  $ilToolbar->addInputItem($si, true);
1288 
1289  // we need this to have to right cmd
1290  $cmd = new ilHiddenInputGUI("cmd[renderPage]");
1291  $cmd->setValue("1");
1292  $ilToolbar->addInputItem($cmd);
1293 
1294  if(!$this->has_datasets)
1295  {
1296  $ilToolbar->addSeparator();
1297  $ilCtrl->setParameter($this, "csum", md5(print_r($a_pages[$this->current_page-1], true)));
1298  $ilToolbar->addButton($lng->txt("survey_delete_page"), $ilCtrl->getLinkTarget($this, "deleteBlock"));
1299  $ilCtrl->setParameter($this, "csum", "");
1300 
1301  $ilToolbar->addSeparator();
1302  $ilToolbar->addButton($lng->txt("survey_move_page"), $ilCtrl->getLinkTarget($this, "movePageForm"));
1303  }
1304  }
1305  }
1306 
1310  protected function renderPage()
1311  {
1312  global $ilCtrl, $lng, $tpl, $rbacsystem;
1313 
1314  $this->survey_gui->questionsSubtabs('questions_per_page');
1315 
1316  $pages = $this->object->getSurveyPages();
1317  $this->has_next_page = ($this->current_page < sizeof($pages));
1318  $this->has_previous_page = ($this->current_page > 1);
1319  $this->has_datasets = $this->object->_hasDatasets($this->object->getSurveyId());
1320 
1321  if($this->has_datasets)
1322  {
1323  $link = $ilCtrl->getLinkTarget($this->survey_gui, "maintenance");
1324  $link = "<a href=\"".$link."\">".$lng->txt("survey_has_datasets_warning_page_view_link")."</a>";
1325  ilUtil::sendInfo($lng->txt("survey_has_datasets_warning_page_view")." ".$link);
1326  }
1327 
1328  $ilCtrl->setParameter($this, "pg", $this->current_page);
1329  $ilCtrl->setParameter($this, "pgov", "");
1330 
1331  $this->renderToolbar($pages);
1332 
1333  if($pages)
1334  {
1335  $ttpl = new ilTemplate("tpl.il_svy_svy_page_view.html", true, true, "Modules/Survey");
1336  $ttpl->setVariable("FORM_ACTION", $ilCtrl->getFormAction($this));
1337  $ttpl->setVariable("WYSIWYG_ACTION", $ilCtrl->getFormAction($this));
1338  $lng->loadLanguageModule("form");
1339 
1340  $read_only = ($this->has_datasets || !$rbacsystem->checkAccess("write", $this->ref_id));
1341 
1342  $commands = $multi_commands = array();
1343 
1344  if(!$read_only)
1345  {
1346  // clipboard is empty
1347  if(!$_SESSION["survey_page_view"][$this->ref_id]["clipboard"])
1348  {
1349  $multi_commands[] = array("cmd"=>"multiDelete", "text"=>$lng->txt("delete"));
1350  $multi_commands[] = array("cmd"=>"multiCut", "text"=>$lng->txt("cut"));
1351  $multi_commands[] = array("cmd"=>"multiCopy", "text"=>$lng->txt("copy"));
1352  }
1353  else
1354  {
1355  if(!$this->suppress_clipboard_msg)
1356  {
1357  ilUtil::sendInfo($lng->txt("survey_clipboard_notice"));
1358  }
1359  $multi_commands[] = array("cmd"=>"clearClipboard", "text"=>$lng->txt("survey_dnd_clear_clipboard"));
1360  }
1361 
1362  // help
1363  $ttpl->setCurrentBlock("help_img");
1364  $ttpl->setVariable("IMG_HELP", ilUtil::getImagePath("streaked_area.gif"));
1365  $ttpl->parseCurrentBlock();
1366  $ttpl->setCurrentBlock("help_section");
1367  $ttpl->setVariable("TXT_HELP", $lng->txt("form_hierarchy_add_elements"));
1368  $ttpl->parseCurrentBlock();
1369 
1370  $ttpl->setCurrentBlock("help_img");
1371  $ttpl->setVariable("IMG_HELP", ilUtil::getImagePath("icon_cont_el_s.gif"));
1372  $ttpl->parseCurrentBlock();
1373  $ttpl->setVariable("IMG_HELP", ilUtil::getImagePath("drop_streaked_area.gif"));
1374  $ttpl->parseCurrentBlock();
1375  $ttpl->setCurrentBlock("help_section");
1376  $ttpl->setVariable("TXT_HELP", $lng->txt("form_hierarchy_drag_drop_help"));
1377  $ttpl->parseCurrentBlock();
1378 
1379  $ttpl->setCurrentBlock("help_img");
1380  $ttpl->setVariable("IMG_HELP", ilUtil::getImagePath("icon_cont_el_s.gif"));
1381  $ttpl->parseCurrentBlock();
1382  $ttpl->setCurrentBlock("help_section");
1383  $ttpl->setVariable("TXT_HELP", $lng->txt("survey_dnd_double_click_to_delete"));
1384  $ttpl->parseCurrentBlock();
1385 
1386  $ttpl->setVariable("DND_INIT_JS", "initDragElements();");
1387 
1388 
1389  // tiny mce
1390 
1391  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
1392  $tags = ilObjAdvancedEditing::_getUsedHTMLTags("survey");
1393 
1394  include_once "./Services/RTE/classes/class.ilTinyMCE.php";
1395  $tiny = new ilTinyMCE("3.3.9.2");
1396  $ttpl->setVariable("WYSIWYG_BLOCKFORMATS", $tiny->_buildAdvancedBlockformatsFromHTMLTags($tags));
1397  $ttpl->setVariable("WYSIWYG_VALID_ELEMENTS", $tiny->_getValidElementsFromHTMLTags($tags));
1398 
1399  $buttons_1 = $tiny->_buildAdvancedButtonsFromHTMLTags(1, $tags);
1400  $buttons_2 = $tiny->_buildAdvancedButtonsFromHTMLTags(2, $tags).','.
1401  $tiny->_buildAdvancedTableButtonsFromHTMLTags($tags).
1402  ($tiny->getStyleSelect() ? ',styleselect' : '');
1403  $buttons_3 = $tiny->_buildAdvancedButtonsFromHTMLTags(3, $tags);
1404  $ttpl->setVariable('WYSIWYG_BUTTONS_1', $tiny->_removeRedundantSeparators($buttons_1));
1405  $ttpl->setVariable('WYSIWYG_BUTTONS_2', $tiny->_removeRedundantSeparators($buttons_2));
1406  $ttpl->setVariable('WYSIWYG_BUTTONS_3', $tiny->_removeRedundantSeparators($buttons_3));
1407  }
1408 
1409  // commands
1410  if (count($multi_commands) > 0 || count($commands) > 0)
1411  {
1412  $single = false;
1413  foreach($commands as $cmd)
1414  {
1415  $ttpl->setCurrentBlock("cmd");
1416  $ttpl->setVariable("ORG_CMD", "renderPage");
1417  $ttpl->setVariable("CMD", $cmd["cmd"]);
1418  $ttpl->setVariable("CMD_TXT", $cmd["text"]);
1419  $ttpl->parseCurrentBlock();
1420  $single = true;
1421  }
1422 
1423  $multi = false;
1424  foreach($multi_commands as $cmd)
1425  {
1426  $ttpl->setCurrentBlock("multi_cmd");
1427  $ttpl->setVariable("ORG_CMD_MULTI", "renderPage");
1428  $ttpl->setVariable("MULTI_CMD", $cmd["cmd"]);
1429  $ttpl->setVariable("MULTI_CMD_TXT", $cmd["text"]);
1430  $ttpl->parseCurrentBlock();
1431  $multi = true;
1432  }
1433  if ($multi)
1434  {
1435  $ttpl->setCurrentBlock("multi_cmds");
1436  $ttpl->setVariable("MCMD_ALT", $lng->txt("commands"));
1437  $ttpl->setVariable("MCMD_IMG", ilUtil::getImagePath("arrow_downright.gif"));
1438  $ttpl->parseCurrentBlock();
1439  }
1440 
1441  if ($single || $multi)
1442  {
1443  $ttpl->setCurrentBlock("commands");
1444  $ttpl->parseCurrentBlock();
1445  }
1446  }
1447 
1448  // nodes
1449  $ttpl->setVariable("NODES", $this->getPageNodes($pages[$this->current_page-1],
1450  $this->has_previous_page, $this->has_next_page, $read_only));
1451 
1452  $tpl->setContent($ttpl->get());
1453 
1454  // add js to template
1455  include_once("./Services/YUI/classes/class.ilYuiUtil.php");
1457  $tpl->addJavascript("./Modules/Survey/js/SurveyPageView.js");
1458  $tpl->addJavascript("./Services/RTE/tiny_mce_3_3_9_2/tiny_mce_src.js");
1459  }
1460  }
1461 
1471  function getPageNodes(array $a_questions, $a_has_previous_page = false, $a_has_next_page = false, $a_readonly = false)
1472  {
1473  global $ilCtrl, $lng;
1474 
1475  $ttpl = new ilTemplate("tpl.il_svy_svy_page_view_nodes.html", true, true, "Modules/Survey");
1476 
1477  $has_clipboard = (bool)$_SESSION["survey_page_view"][$this->ref_id]["clipboard"];
1478 
1479  // question block ?
1480 
1481  $first_question = $a_questions;
1482  $first_question = array_shift($first_question);
1483 
1484  if($first_question["questionblock_id"])
1485  {
1486  $menu = array();
1487 
1488  if(!$a_readonly && !$has_clipboard)
1489  {
1490  $menu[] = array("cmd" => "editBlock", "text" => $lng->txt("edit"));
1491  }
1492 
1493  if($first_question["questionblock_show_blocktitle"])
1494  {
1495  $block_status = $lng->txt("survey_block_visible");
1496  }
1497  else
1498  {
1499  $block_status = $lng->txt("survey_block_hidden");
1500  }
1501 
1502  $this->renderPageNode($ttpl, "block", $first_question["questionblock_id"],
1503  $first_question["questionblock_title"]." (".$block_status.")", $menu, false, false, $block_status);
1504  }
1505 
1506 
1507  // questions/headings
1508 
1509  include_once "./Modules/SurveyQuestionPool/classes/class.ilObjSurveyQuestionPool.php";
1510  $questiontypes = ilObjSurveyQuestionPool::_getQuestiontypes();
1511 
1512  $counter = $question_count;
1513  $block_done = null;
1514  foreach($a_questions as $idx => $question)
1515  {
1516  // drop area
1517 
1518  $menu = array();
1519 
1520  if(!$a_readonly)
1521  {
1522  if(!$has_clipboard)
1523  {
1524  foreach($questiontypes as $trans => $item)
1525  {
1526  $menu[] = array("cmd"=> "addQuestion_".$item["questiontype_id"],
1527  "text"=> sprintf($lng->txt("svy_page_add_question"), $trans));
1528  }
1529 
1530  if($this->object->isPoolActive())
1531  {
1532  $menu[] = array("cmd"=> "addPoolQuestion",
1533  "text"=> $lng->txt("browse_for_questions"));
1534  }
1535  }
1536  else
1537  {
1538  $menu[] = array("cmd" => "paste", "text" => $lng->txt("survey_dnd_paste"));
1539  }
1540  }
1541 
1542  $this->renderPageNode($ttpl, "droparea", $question["question_id"], null, $menu, true);
1543 
1544  // question
1545  $question_gui = $this->object->getQuestionGUI($question["type_tag"], $question["question_id"]);
1546  $question_gui = $question_gui->getWorkingForm(array(), $this->object->getShowQuestionTitles(),
1547  $question["questionblock_show_questiontext"], null, $this->object->getSurveyId());
1548 
1549  $menu = array();
1550 
1551  if(!$a_readonly && !$has_clipboard)
1552  {
1553  $menu[] = array("cmd" => "editQuestion", "text" => $lng->txt("edit"));
1554  $menu[] = array("cmd" => "cutQuestion", "text" => $lng->txt("cut"));
1555  $menu[] = array("cmd" => "copyQuestion", "text" => $lng->txt("copy"));
1556 
1557  if(sizeof($a_questions) > 1 && $idx > 0)
1558  {
1559  $menu[] = array("cmd" => "splitPage", "text" => $lng->txt("survey_dnd_split_page"));
1560  }
1561  if($a_has_next_page)
1562  {
1563  $menu[] = array("cmd" => "moveNext", "text" => $lng->txt("survey_dnd_move_next"));
1564  }
1565  if($a_has_previous_page)
1566  {
1567  $menu[] = array("cmd" => "movePrevious", "text" => $lng->txt("survey_dnd_move_previous"));
1568  }
1569 
1570  $menu[] = array("cmd" => "deleteQuestion", "text" => $lng->txt("delete"));
1571 
1572  // heading
1573  if($question["heading"])
1574  {
1575  $menu[] = array("cmd" => "editHeading", "text" => $lng->txt("survey_edit_heading"));
1576  $menu[] = array("cmd" => "deleteHeading", "text" => $lng->txt("survey_delete_heading"));
1577  }
1578  else
1579  {
1580  $menu[] = array("cmd" => "addHeading", "text" => $lng->txt("add_heading"));
1581  }
1582  }
1583 
1584  if($first_question["questionblock_show_questiontext"])
1585  {
1586  $question_title_status = $lng->txt("survey_question_text_visible");
1587  }
1588  else
1589  {
1590  $question_title_status = $lng->txt("survey_question_text_hidden");
1591  }
1592 
1593  $this->renderPageNode($ttpl, "question", $question["question_id"], $question_gui, $menu,
1594  false, $question["title"], $question_title_status, $question["heading"]);
1595 
1596  $ilCtrl->setParameter($this, "eqid", "");
1597  }
1598 
1599 
1600  // last position (no question id)
1601 
1602  $menu = array();
1603 
1604  if(!$a_readonly)
1605  {
1606  if(!$has_clipboard)
1607  {
1608  foreach($questiontypes as $trans => $item)
1609  {
1610  $menu[] = array("cmd"=> "addQuestion_".$item["questiontype_id"],
1611  "text"=> sprintf($lng->txt("svy_page_add_question"), $trans));
1612  }
1613 
1614  if($this->object->isPoolActive())
1615  {
1616  $menu[] = array("cmd"=> "addPoolQuestion",
1617  "text"=> $lng->txt("browse_for_questions"));
1618  }
1619  }
1620  else
1621  {
1622  $menu[] = array("cmd" => "paste", "text" => $lng->txt("survey_dnd_paste"));
1623  }
1624  }
1625 
1626  $this->renderPageNode($ttpl, "page", "end", null, $menu, true);
1627 
1628  return $ttpl->get();
1629  }
1630 
1643  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)
1644  {
1645  global $ilCtrl, $lng;
1646 
1647  $node_id = $a_type."_".$a_id;
1648 
1649  if($a_content !== null)
1650  {
1651  $drag = "";
1652  $double = false;
1653  switch($a_type)
1654  {
1655  case "block":
1656  $caption = $lng->txt("questionblock");
1657  break;
1658 
1659  case "question":
1660  if($a_heading)
1661  {
1662  $a_content = "<div class=\"questionheading\">".$a_heading."</div>".
1663  $a_content;
1664  }
1665  $caption = $lng->txt("question").": ".$a_subtitle;
1666  $drag = "_drag";
1667  $double = true;
1668  break;
1669 
1670  case "heading":
1671  $caption = $lng->txt("heading");
1672  break;
1673 
1674  default:
1675  return;
1676  }
1677 
1678  if($a_status)
1679  {
1680  $caption .= " (".$a_status.")";
1681  }
1682 
1683  $a_tpl->setCurrentBlock("list_item");
1684  $a_tpl->setVariable("NODE_ID", $node_id);
1685  $a_tpl->setVariable("NODE_DRAG", $drag);
1686  $a_tpl->setVariable("TXT_NODE_TYPE", $caption);
1687  $a_tpl->setVariable("TXT_NODE_CONTENT", $a_content);
1688  if($double)
1689  {
1690  $a_tpl->setVariable("VAL_DBLCLICK", "onDblClick=\"doMouseDblClick(event,this.id);\"");
1691  }
1692  $a_tpl->parseCurrentBlock();
1693  }
1694 
1695  // drop area menu
1696  if($a_menu)
1697  {
1698  foreach($a_menu as $mcnt => $menu_item)
1699  {
1700  $a_tpl->setCurrentBlock("menu_cmd");
1701  $a_tpl->setVariable("TXT_MENU_CMD", $menu_item["text"]);
1702  $a_tpl->setVariable("MENU_CMD", "renderPage");
1703 
1704  $a_tpl->setVariable("FC", $menu_item["cmd"]);
1705  $a_tpl->setVariable("MCNT", $mcnt);
1706 
1707  $a_tpl->setVariable("CMD_NODE", $node_id);
1708  $a_tpl->parseCurrentBlock();
1709  }
1710 
1711  $a_tpl->setCurrentBlock("drop_area_menu");
1712  $a_tpl->setVariable("MNODE_ID", $node_id);
1713  $a_tpl->parseCurrentBlock();
1714  }
1715 
1716  if($a_spacer)
1717  {
1718  $a_tpl->setCurrentBlock("drop_area");
1719  $a_tpl->setVariable("DNODE_ID", $node_id);
1720  $a_tpl->setVariable("IMG_BLANK", ilUtil::getImagePath("spacer.gif"));
1721  $a_tpl->parseCurrentBlock();
1722  }
1723 
1724  $a_tpl->setCurrentBlock("element");
1725  $a_tpl->parseCurrentBlock();
1726  }
1727 
1731  public function confirmDeleteAllUserData()
1732  {
1733  global $lng, $ilCtrl;
1734 
1735  $this->object->deleteAllUserData();
1736  ilUtil::sendSuccess($lng->txt("svy_all_user_data_deleted"), true);
1737 
1738  $this->renderPage();
1739  }
1740 
1744  public function confirmRemoveHeading()
1745  {
1746  global $ilCtrl;
1747 
1748  $this->object->saveHeading("", $_POST["removeheading"]);
1749  $this->renderPage();
1750  }
1751 
1757  public function editJS()
1758  {
1759  $node = $_POST["ajaxform_node"];
1760  if($node)
1761  {
1762  $node = explode("_", $node);
1763  if($node[0] == "heading")
1764  {
1765  $id = (int)$node[1];
1766 
1767  include_once "Modules/Survey/classes/class.ilObjSurvey.php";
1768  echo ilObjSurvey::getTextblock($id);
1769  exit();
1770  }
1771  }
1772  }
1773 
1777  public function saveJS()
1778  {
1779  $node = $_POST["ajaxform_node"];
1780  if($node)
1781  {
1782  $node = explode("_", $node);
1783  if($node[0] == "heading")
1784  {
1785  $id = (int)$node[1];
1786  $content = trim($_POST["ajaxform_content"]);
1787 
1788  $this->object->saveHeading($content, $id);
1789  exit();
1790  }
1791  }
1792  }
1793 
1799  public function getAutoBlockTitle()
1800  {
1801  global $lng;
1802 
1803  return $lng->txt("survey_auto_block_title");
1804  }
1805 
1806  public function addPoolQuestion($pos, $node)
1807  {
1808  global $ilCtrl, $ilUser;
1809 
1810  if($node == "page_end")
1811  {
1812  $pos = $this->object->getSurveyPages();
1813  $pos = array_pop($pos[$this->current_page-1]);
1814  $pos = $pos["question_id"]."a";
1815  }
1816  else
1817  {
1818  $pos = $pos."b";
1819  }
1820 
1821  $ilCtrl->setParameter($this->survey_gui, "pgov", $this->current_page);
1822  $ilCtrl->setParameter($this->survey_gui, "pgov_pos", $pos);
1823 
1824  $cmd = ($ilUser->getPref('svy_insert_type') == 1 || strlen($ilUser->getPref('svy_insert_type')) == 0) ? 'browseForQuestions' : 'browseForQuestionblocks';
1825  $ilCtrl->redirect($this->survey_gui, $cmd);
1826  }
1827 }
1828 
1829 ?>