33                 $this->survey_gui = $a_survey_gui;
 
   34                 $this->ref_id = $this->survey_gui->ref_id;
 
   35                 $this->
object = $this->survey_gui->object;
 
   45                 $cmd = $ilCtrl->getCmd(
"renderPage");
 
   46                 $next_class = $ilCtrl->getNextClass($this);
 
   55                                 if($rbacsystem->checkAccess(
"write", $this->ref_id))
 
   69                                                 $ilCtrl->setParameter($this->survey_gui, 
"pgov", $this->current_page);
 
   72                                                 $id = explode(
"_", 
$_REQUEST[
"il_hform_node"]);
 
   76                                                 if(substr(
$_REQUEST[
"il_hform_subcmd"], 0, 5) == 
"multi")
 
   82                                                                 foreach(explode(
";", 
$_REQUEST[
"il_hform_multi"]) as $item)
 
   84                                                                         $id[] = (int)array_pop(explode(
"_", $item));
 
   87                                                                 if($subcmd == 
"multiDelete")
 
   89                                                                         $subcmd = 
"deleteQuestion";
 
   95                                                                 if($subcmd == 
"multiDelete")
 
   98                                                                         $ilCtrl->redirect($this, 
"renderPage");
 
  107                                                 if(substr($subcmd, 0, 11) == 
"addQuestion")
 
  109                                                         $type = explode(
"_", $subcmd);
 
  110                                                         $type = (int)$type[1];
 
  111                                                         $has_content = $this->
addQuestion($type, $this->object->isPoolActive(), $id, 
$_REQUEST[
"il_hform_node"]);
 
  115                                                         $has_content = $this->$subcmd($id, 
$_REQUEST[
"il_hform_node"]);
 
  160                 $result = $ilDB->queryF(
"SELECT survey_question_id FROM svy_svy_qst WHERE survey_fi = %s",
 
  162                         array($this->object->getSurveyId())
 
  164                 $sequence = 
$result->numRows();
 
  169                         $survey_question_id = $this->
object->duplicateQuestionForSurvey($a_new_id, $a_force_duplicate);
 
  174                         $survey_question_id = $a_new_id;
 
  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())
 
  185                 return $survey_question_id;
 
  195                 global $rbacsystem, $ilDB, 
$lng;
 
  197                 include_once 
"./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
 
  205                         $this->
object->loadQuestionsFromDb();
 
  210                         if(substr($pos, -1) != 
"c")
 
  213                                 $current = $this->
object->getSurveyPages();
 
  214                                 $current = $current[$this->current_page-1];
 
  215                                 if(
sizeof($current) == 1)
 
  221                                                                         array((
int)$pos, $a_new_id));
 
  225                                         $block_id = array_pop($current);
 
  226                                         $block_id = $block_id[
"questionblock_id"];
 
  228                                         $this->
object->addQuestionToBlock($a_new_id, $block_id);
 
  237                                         $pos = (int)$pos.
"a";
 
  238                                         $this->current_page++;
 
  243                                         $first = $this->
object->getSurveyPages();
 
  245                                         $first = array_shift($first);
 
  246                                         $pos = $first[
"question_id"].
"b";
 
  247                                         $this->current_page = 1;
 
  252                         $this->
object->moveQuestions(array($a_new_id), (
int)$pos,
 
  253                                 ((substr($pos, -1) == 
"a") ? 1 : 0));
 
  265                 $question_ids = $this->
object->getQuestionblockQuestionIds($a_block_id);
 
  266                 foreach($question_ids as $qid)
 
  273                         $this->
object->loadQuestionsFromDb();
 
  278                         if(substr($pos, -1) != 
"c")
 
  281                                 $current = $this->
object->getSurveyPages();
 
  282                                 $current = $current[$this->current_page-1];
 
  283                                 if(
sizeof($current) == 1)
 
  289                                                                         array((
int)$pos)+$new_ids);
 
  293                                         $block_id = array_pop($current);
 
  294                                         $block_id = $block_id[
"questionblock_id"];
 
  296                                         foreach($new_ids as $qid)
 
  298                                                 $this->
object->addQuestionToBlock($qid, $block_id);
 
  312                                         $pos = (int)$pos.
"a";
 
  317                                         $first = $this->
object->getSurveyPages();
 
  319                                         $first = array_shift($first);
 
  320                                         $pos = $first[
"question_id"].
"b";
 
  325                         $this->
object->moveQuestions($new_ids, (
int)$pos,
 
  326                                 ((substr($pos, -1) == 
"a") ? 1 : 0));                   
 
  338         protected function addQuestion($a_type, $a_use_pool, $a_pos, $a_special_position)
 
  343                 include_once 
"./Modules/SurveyQuestionPool/classes/class.ilObjSurveyQuestionPool.php";
 
  345                 foreach($questiontypes as $item)
 
  347                         if($item[
"questiontype_id"] == $a_type)
 
  349                                 $type_trans = $item[
"type_tag"];
 
  356                 if($a_special_position == 
"toolbar")
 
  358                         $id = $this->
object->getSurveyPages();
 
  359                         if($a_pos && $a_pos != 
"fst")
 
  362                                 $id = array_pop($id);
 
  363                                 $id = $id[
"question_id"].
"c";
 
  371                 else if($a_special_position == 
"page_end")
 
  373                         $id = $this->
object->getSurveyPages();
 
  374                         $id = $id[$this->current_page-1];
 
  375                         $id = array_pop($id);
 
  376                         $id = $id[
"question_id"].
"a";
 
  385                         $_GET[
"sel_question_types"] = $type_trans;
 
  387                         $ilCtrl->setParameter($this->survey_gui, 
"pgov_pos", $id);
 
  390                                 $this->survey_gui->createQuestionObject();
 
  394                                 $this->survey_gui->executeCreateQuestionObject();
 
  401                                 $this->ref_id.
"&cmd=createQuestionForSurvey&new_for_survey=".
 
  402                                 $this->ref_id.
"&sel_question_types=".$type_trans.
"&pgov=".$this->current_page.
 
  417                 $this->suppress_clipboard_msg = 
true;
 
  420                                                 "source" => $this->current_page,
 
  421                                                 "nodes" => array($a_id),
 
  435                 $this->suppress_clipboard_msg = 
true;
 
  438                                                 "source" => $this->current_page,
 
  439                                                 "nodes" => array($a_id),
 
  453                 $this->suppress_clipboard_msg = 
true;
 
  456                                                 "source" => $this->current_page,
 
  471                 $this->suppress_clipboard_msg = 
true;
 
  474                                                 "source" => $this->current_page,
 
  495                 $pages = $this->
object->getSurveyPages();
 
  496                 $source = $pages[
$data[
"source"]-1];
 
  497                 $target = $pages[$this->current_page-1];
 
  501                 foreach($source as $src_qst)
 
  503                         if(in_array($src_qst[
"question_id"], $data[
"nodes"]))
 
  505                                 $nodes[] = $src_qst[
"question_id"];
 
  511                 if(
$_REQUEST[
"il_hform_node"] == 
"page_end")
 
  514                         $a_id = array_pop($a_id);
 
  515                         $a_id = $a_id[
"question_id"];
 
  520                 if($data[
"mode"] == 
"cut")
 
  523                         if($data[
"source"] == $this->current_page)
 
  526                                 if(
sizeof($nodes) <= 
sizeof($source))
 
  528                                         $this->
object->moveQuestions($nodes, $a_id, $pos);                                                                      
 
  536                                 $source_block_id = 
false;
 
  537                                 if(
sizeof($source) > 1)
 
  539                                         $source_block_id = $source;
 
  540                                         $source_block_id = array_shift($source_block_id);
 
  541                                         $source_block_id = $source_block_id[
"questionblock_id"];
 
  544                                         if(
sizeof($source) > 
sizeof($nodes))
 
  546                                                 foreach($nodes as $qid)
 
  548                                                         $this->
object->removeQuestionFromBlock($qid, $source_block_id);
 
  554                                                 $this->
object->unfoldQuestionblocks(array($source_block_id));
 
  559                                 if(
sizeof($source) == 
sizeof($nodes) && $data[
"source"] < $this->current_page)
 
  561                                         $this->current_page--;
 
  567                 else if($data[
"mode"] == 
"copy")
 
  570                         foreach($this->object->getSurveyPages() as $page)
 
  572                                 foreach($page as $question)
 
  574                                         $titles[] = $question[
"title"];
 
  579                         $question_pointer = array();
 
  580                         foreach($nodes as $qid)
 
  586                                 $title = $question->getTitle();
 
  588                                 foreach($titles as $existing_title)
 
  590                                         if(preg_match(
"/".preg_quote(
$title).
" \(([0-9]+)\)$/", $existing_title, $match))
 
  592                                                 $max = max($match[1], $max);                                            
 
  597                                         $title .= 
" (".($max+1).
")";
 
  604                                 $question->setTitle(
$title);                                    
 
  607                                 $question->saveToDb();
 
  609                                 $question_pointer[$qid] = $question->getId();
 
  614                         $this->
object->cloneTextblocks($question_pointer);
 
  616                         $this->
object->loadQuestionsFromDb();
 
  618                         $nodes = array_values($question_pointer);
 
  625                 if(
sizeof($target) == 1)
 
  627                         $nodes = array_merge(array($a_id), $nodes);
 
  636                         $target_block_id = $target;
 
  637                         $target_block_id = array_shift($target_block_id);
 
  638                         $target_block_id = $target_block_id[
"questionblock_id"];
 
  640                         foreach($nodes as $qid)
 
  642                                 $this->
object->addQuestionToBlock($qid, $target_block_id);
 
  646                         $this->
object->moveQuestions($nodes, $a_id, $pos);
 
  657                 $source_id = (int)array_pop(explode(
"_", 
$_REQUEST[
"il_hform_source"]));
 
  658                 if(
$_REQUEST[
"il_hform_target"] != 
"page_end")
 
  665                         $page = $this->
object->getSurveyPages();
 
  666                         $page = $page[$this->current_page-1];
 
  667                         $last = array_pop($page);
 
  673                         $this->
object->moveQuestions(array($source_id), 
$target_id, $pos);
 
  685                 $this->survey_gui->questionsSubtabs(
'questions_per_page');
 
  687                 $ilCtrl->setParameter($this->survey_gui, 
"pgov", $this->current_page);
 
  690                 $page = $this->
object->getSurveyPages();
 
  691                 $page = $page[$this->current_page-1];
 
  694                 if(
$_REQUEST[
"csum"] != md5(print_r($page, 
true)))
 
  696                         $ilCtrl->redirect($this, 
"renderPage");
 
  699                 $page = array_shift($page);
 
  700                 $block_id = $page[
"questionblock_id"];
 
  703                         $this->survey_gui->removeQuestionsForm(array($block_id), array(), array());
 
  707                         $this->survey_gui->removeQuestionsForm(array(), array($page[
"question_id"]), array());
 
  720                         $a_id = array($a_id);
 
  722                 $this->survey_gui->removeQuestionsForm(array(), $a_id, array());
 
  735                 foreach (
$_POST as $key => $value)
 
  737                         if (preg_match(
"/id_(\d+)/", $key, $matches))
 
  739                                 array_push($ids, $matches[1]);
 
  744                 $pages = $this->
object->getSurveyPages();
 
  745                 $source = $pages[$this->current_page-1];
 
  748                 $block_id = array_shift($block_id);
 
  749                 $block_id = $block_id[
"questionblock_id"];
 
  751                 if(
sizeof($ids) && 
sizeof($source) > 
sizeof($ids))
 
  754                         if(
sizeof($source)-
sizeof($ids) == 1)
 
  756                                 $this->
object->unfoldQuestionblocks(array($block_id));
 
  761                                 foreach($ids as $qid)
 
  763                                         $this->
object->removeQuestionFromBlock($qid, $block_id);
 
  767                         $this->
object->removeQuestions($ids, array());
 
  775                                 $this->
object->removeQuestions(array(), array($block_id));
 
  780                                 $this->
object->removeQuestions($ids, array());
 
  784                         if($this->current_page > 1)
 
  786                                 $this->current_page--;
 
  790                 $this->
object->saveCompletionStatus();
 
  793                 $ilCtrl->setParameter($this, 
"pgov", $this->current_page);
 
  794                 $ilCtrl->redirect($this, 
"renderPage");
 
  804                 $this->survey_gui->defineQuestionblock($a_id);
 
  815                 $this->survey_gui->addHeadingObject(
false, $a_id);
 
  826                 $this->survey_gui->addHeadingObject(
false, $a_id);
 
  837                 $_GET[
"removeheading"] = $a_id;
 
  838                 $this->survey_gui->confirmRemoveHeadingForm();
 
  849                 $pages = $this->
object->getSurveyPages();
 
  850                 $source = $pages[$this->current_page-1];
 
  852                 $block_questions = array();
 
  853                 $add = $block_id = 
false;
 
  854                 foreach($source as $idx => $item)
 
  856                         if($item[
"question_id"] == $a_id)
 
  858                                 $block_id = $item[
"questionblock_id"];
 
  863                                 $block_questions[] = $item[
"question_id"];
 
  870                         $this->
object->unfoldQuestionblocks(array($block_id));
 
  875                         foreach($block_questions as $qid)
 
  877                                 $this->
object->removeQuestionFromBlock($qid, $block_id);
 
  882                 if(
sizeof($block_questions) > 1)
 
  889                 $this->current_page++;
 
  899                 $pages = $this->
object->getSurveyPages();
 
  900                 $source = $pages[$this->current_page-1];
 
  906                         $target_block_id = 
$target_id[
"questionblock_id"];
 
  910                         if(
sizeof($source) > 1)
 
  913                                 $block_id = array_shift($block_id);
 
  914                                 $block_id = $block_id[
"questionblock_id"];
 
  917                                 if(
sizeof($source) == 2)
 
  920                                         $this->
object->unfoldQuestionblocks(array($block_id));
 
  925                                         $this->
object->removeQuestionFromBlock($a_id, $block_id);
 
  930                         $this->
object->moveQuestions(array($a_id), 
$target_id, 0);
 
  933                         if(
sizeof($target) < 2)
 
  942                                 $this->
object->addQuestionToBlock($a_id, $target_block_id);
 
  946                         if(
sizeof($source) > 1)
 
  948                                 $this->current_page++;
 
  960                 $pages = $this->
object->getSurveyPages();
 
  961                 $source = $pages[$this->current_page-1];
 
  962                 $target = $pages[$this->current_page-2];
 
  967                         $target_block_id = 
$target_id[
"questionblock_id"];
 
  971                         if(
sizeof($source) > 1)
 
  974                                 $block_id = array_shift($block_id);
 
  975                                 $block_id = $block_id[
"questionblock_id"];
 
  978                                 if(
sizeof($source) == 2)
 
  981                                         $this->
object->unfoldQuestionblocks(array($block_id));
 
  986                                         $this->
object->removeQuestionFromBlock($a_id, $block_id);
 
  991                         $this->
object->moveQuestions(array($a_id), 
$target_id, 1);
 
  994                         if(
sizeof($target) < 2)
 
 1003                                 $this->
object->addQuestionToBlock($a_id, $target_block_id);
 
 1006                         $this->current_page--;
 
 1017                 $data = $this->
object->getQuestions(array($a_id));
 
 1021                                 $pool_id.
"&cmd=editQuestionForSurvey&calling_survey=".
 
 1022                                 $this->ref_id.
"&q_id=".$a_id.
"&pgov=".$this->current_page);
 
 1032                 $this->survey_gui->questionsSubtabs(
'questions_per_page');
 
 1034                 include_once 
"Services/Form/classes/class.ilPropertyFormGUI.php";
 
 1036                 $form->setFormAction($ilCtrl->getFormAction($this, 
"addQuestionToolbar"));
 
 1037                 $form->setTitle($lng->txt(
"survey_add_new_question"));
 
 1040                 include_once 
"./Modules/SurveyQuestionPool/classes/class.ilObjSurveyQuestionPool.php";
 
 1042                 $type_map = array();
 
 1043                 foreach($questiontypes as $trans => $item)
 
 1045                         $type_map[$item[
"questiontype_id"]] = $trans;
 
 1047                 include_once(
"./Services/Form/classes/class.ilSelectInputGUI.php");
 
 1049                 $si->setOptions($type_map);
 
 1050                 $form->addItem(
$si);
 
 1052                 $pages = $this->
object->getSurveyPages();
 
 1055                         $pages_drop = array(
"fst"=>$lng->txt(
"survey_at_beginning"));
 
 1056                         foreach($pages as $idx => $questions)
 
 1058                                 $question = array_shift($questions);
 
 1059                                 if($question[
"questionblock_id"])
 
 1061                                         $pages_drop[$idx+1] = $lng->txt(
"survey_behind_page").
" ".$question[
"questionblock_title"];
 
 1065                                         $pages_drop[$idx+1] = $lng->txt(
"survey_behind_page").
" ".strip_tags($question[
"title"]);
 
 1070                         $form->addItem($pos);
 
 1072                         $pos->setValue($this->current_page);
 
 1078                         $pos->setValue(
"fst");
 
 1079                         $form->addItem($pos);
 
 1082                 if($this->object->isPoolActive())
 
 1084                         $this->survey_gui->createQuestionObject($form);
 
 1087                 $form->addCommandButton(
"addQuestionToolbar", $lng->txt(
"create"));
 
 1088                 $form->addCommandButton(
"renderPage", $lng->txt(
"cancel"));
 
 1090                 return $tpl->setContent($form->getHTML());
 
 1100                 $pool_active = $this->
object->isPoolActive();
 
 1102                 if(!
$_POST[
"usage"] && $pool_active)
 
 1109                 $ilCtrl->setParameter($this->survey_gui, 
"pgov", $this->current_page);
 
 1124                 $this->survey_gui->questionsSubtabs(
'questions_per_page');
 
 1126                 include_once 
"Services/Form/classes/class.ilPropertyFormGUI.php";
 
 1128                 $form->setFormAction($ilCtrl->getFormAction($this, 
"movePage"));
 
 1129                 $form->setTitle($lng->txt(
"survey_move_page"));
 
 1132                 $old_pos->setValue($this->current_page);
 
 1133                 $form->addItem($old_pos);
 
 1135                 $pages = $this->
object->getSurveyPages();
 
 1138                         $pages_drop = array();
 
 1139                         if($this->current_page != 1)
 
 1141                                 $pages_drop[
"fst"] = $lng->txt(
"survey_at_beginning");
 
 1143                         foreach($pages as $idx => $questions)
 
 1145                                 if(($idx+1) != $this->current_page && ($idx+2) != $this->current_page)
 
 1147                                         $question = array_shift($questions);
 
 1148                                         if($question[
"questionblock_id"])
 
 1150                                                 $pages_drop[$idx+1] = $lng->txt(
"survey_behind_page").
" ".$question[
"questionblock_title"];
 
 1154                                                 $pages_drop[$idx+1] = $lng->txt(
"survey_behind_page").
" ".strip_tags($question[
"title"]);
 
 1160                         $form->addItem($pos);
 
 1163                 $form->addCommandButton(
"movePage", $lng->txt(
"submit"));
 
 1164                 $form->addCommandButton(
"renderPage", $lng->txt(
"cancel"));
 
 1166                 return $tpl->setContent($form->getHTML());
 
 1177                 $target_page = $this->current_page-1;
 
 1180                 $pages = $this->
object->getSurveyPages();
 
 1181                 foreach($pages[$source_page] as $question)
 
 1183                         $questions[] = $question[
"question_id"];
 
 1193                 $target = $pages[$target_page];
 
 1194                 $target = array_shift($target);
 
 1195                 $this->
object->moveQuestions($questions, $target[
"question_id"], $position);
 
 1197                 if($target_page < $source_page && $position)
 
 1199                    $this->current_page++;
 
 1203                 $ilCtrl->setParameter($this, 
"pgov", $this->current_page);
 
 1204                 $ilCtrl->redirect($this, 
"renderPage");
 
 1216                 if(!$this->has_datasets)
 
 1218                         $ilToolbar->addButton($lng->txt(
"survey_add_new_question"),     $ilCtrl->getLinkTarget($this, 
"addQuestionToolbarForm"));
 
 1220                         if($this->object->isPoolActive())
 
 1222                                 $ilToolbar->addSeparator();
 
 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"];
 
 1232                                 $ilCtrl->setParameter($this->survey_gui, 
"pgov", $this->current_page);
 
 1233                                 $ilCtrl->setParameter($this->survey_gui, 
"pgov_pos", $last_on_page.
"c");
 
 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));               
 
 1239                                 $ilCtrl->setParameter($this->survey_gui, 
"pgov", 
"");
 
 1240                                 $ilCtrl->setParameter($this->survey_gui, 
"pgov_pos", 
"");
 
 1245                                 $ilToolbar->addSeparator();
 
 1253                         $ilCtrl->setParameter($this, 
"pg", $this->current_page-1);
 
 1254                         $ilToolbar->addLink($lng->txt(
"survey_prev_question"),
 
 1256                         $ilCtrl->setParameter($this, 
"pg", $this->current_page+1);
 
 1257                         $ilToolbar->addLink($lng->txt(
"survey_next_question"),
 
 1259                         $ilCtrl->setParameter($this, 
"pg", $this->current_page);
 
 1261                         foreach($a_pages as $idx => $questions)
 
 1264                                 $page = array_shift($page);
 
 1265                                 if($page[
"questionblock_id"])
 
 1267                                         $pages_drop[$idx+1] = $page[
"questionblock_title"];
 
 1269                                         if(
sizeof($questions) > 1)
 
 1271                                                 foreach($questions as $question)
 
 1273                                                         $pages_drop[($idx+1).
"__".$question[
"question_id"]] = 
"- ".$question[
"title"];
 
 1279                                         $pages_drop[$idx+1] = strip_tags($page[
"title"]);
 
 1285                 if(
sizeof($pages_drop) > 1)
 
 1287                         $ilToolbar->addSeparator();
 
 1289                         $ilToolbar->setFormAction($ilCtrl->getFormAction($this));
 
 1291                         include_once(
"./Services/Form/classes/class.ilPropertyFormGUI.php");
 
 1293                         $si->addCustomAttribute(
"onChange=\"forms['ilToolbar'].submit();\"");
 
 1294                         $si->setOptions($pages_drop);
 
 1295                         $si->setValue($this->current_page);
 
 1296                         $ilToolbar->addInputItem(
$si, 
true);
 
 1300                         $cmd->setValue(
"1");
 
 1301                         $ilToolbar->addInputItem(
$cmd);
 
 1303                         if(!$this->has_datasets)
 
 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", 
"");               
 
 1310                                 $ilToolbar->addSeparator();
 
 1311                                 $ilToolbar->addButton($lng->txt(
"survey_move_page"), $ilCtrl->getLinkTarget($this, 
"movePageForm"));
 
 1323                 $this->survey_gui->questionsSubtabs(
'questions_per_page');
 
 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());
 
 1330                 if($this->has_datasets)
 
 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);
 
 1337                 $ilCtrl->setParameter($this, 
"pg", $this->current_page);
 
 1338                 $ilCtrl->setParameter($this, 
"pgov", 
"");
 
 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");
 
 1349                         $read_only = ($this->has_datasets || !$rbacsystem->checkAccess(
"write", $this->ref_id));
 
 1351                         $commands = $multi_commands = array();
 
 1356                                 if(!
$_SESSION[
"survey_page_view"][$this->ref_id][
"clipboard"])
 
 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"));
 
 1364                                         if(!$this->suppress_clipboard_msg)
 
 1368                                         $multi_commands[] = array(
"cmd"=>
"clearClipboard", 
"text"=>$lng->txt(
"survey_dnd_clear_clipboard"));
 
 1372                                 $ttpl->setCurrentBlock(
"help_img");
 
 1374                                 $ttpl->parseCurrentBlock();
 
 1375                                 $ttpl->setCurrentBlock(
"help_section");
 
 1376                                 $ttpl->setVariable(
"TXT_HELP",  $lng->txt(
"form_hierarchy_add_elements"));
 
 1377                                 $ttpl->parseCurrentBlock();
 
 1379                                 $ttpl->setCurrentBlock(
"help_img");
 
 1381                                 $ttpl->parseCurrentBlock();
 
 1383                                 $ttpl->parseCurrentBlock();
 
 1384                                 $ttpl->setCurrentBlock(
"help_section");
 
 1385                                 $ttpl->setVariable(
"TXT_HELP",  $lng->txt(
"form_hierarchy_drag_drop_help"));
 
 1386                                 $ttpl->parseCurrentBlock();
 
 1388                                 $ttpl->setCurrentBlock(
"help_img");
 
 1390                                 $ttpl->parseCurrentBlock();
 
 1391                                 $ttpl->setCurrentBlock(
"help_section");
 
 1392                                 $ttpl->setVariable(
"TXT_HELP",  $lng->txt(
"survey_dnd_double_click_to_delete"));
 
 1393                                 $ttpl->parseCurrentBlock();
 
 1395                                 $ttpl->setVariable(
"DND_INIT_JS", 
"initDragElements();");
 
 1400                                 include_once 
"./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
 
 1403                                 include_once 
"./Services/RTE/classes/class.ilTinyMCE.php";
 
 1405                                 $ttpl->setVariable(
"WYSIWYG_BLOCKFORMATS", $tiny->_buildAdvancedBlockformatsFromHTMLTags($tags));
 
 1406                                 $ttpl->setVariable(
"WYSIWYG_VALID_ELEMENTS", $tiny->_getValidElementsFromHTMLTags($tags));
 
 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));
 
 1419                         if (count($multi_commands) > 0 || count($commands) > 0)
 
 1422                                 foreach($commands as 
$cmd)
 
 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();
 
 1433                                 foreach($multi_commands as $cmd)
 
 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();
 
 1444                                         $ttpl->setCurrentBlock(
"multi_cmds");
 
 1445                                         $ttpl->setVariable(
"MCMD_ALT", $lng->txt(
"commands"));
 
 1447                                         $ttpl->parseCurrentBlock();
 
 1450                                 if ($single || $multi)
 
 1452                                         $ttpl->setCurrentBlock(
"commands");
 
 1453                                         $ttpl->parseCurrentBlock();
 
 1458                         $ttpl->setVariable(
"NODES", $this->
getPageNodes($pages[$this->current_page-1],
 
 1459                                 $this->has_previous_page, $this->has_next_page, $read_only));
 
 1461                         $tpl->setContent($ttpl->get());
 
 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");
 
 1480         function getPageNodes(array $a_questions, $a_has_previous_page = 
false, $a_has_next_page = 
false, $a_readonly = 
false)
 
 1484                 $ttpl = 
new ilTemplate(
"tpl.il_svy_svy_page_view_nodes.html", 
true, 
true, 
"Modules/Survey");
 
 1486                 $has_clipboard = (bool)
$_SESSION[
"survey_page_view"][$this->ref_id][
"clipboard"];
 
 1490                 $first_question = $a_questions;
 
 1491                 $first_question = array_shift($first_question);
 
 1493                 if($first_question[
"questionblock_id"])
 
 1497                         if(!$a_readonly && !$has_clipboard)
 
 1499                                 $menu[] = array(
"cmd" => 
"editBlock", 
"text" => $lng->txt(
"edit"));
 
 1502                         if($first_question[
"questionblock_show_blocktitle"])
 
 1504                                 $block_status = $lng->txt(
"survey_block_visible");
 
 1508                                 $block_status = $lng->txt(
"survey_block_hidden");
 
 1511                         $this->
renderPageNode($ttpl, 
"block", $first_question[
"questionblock_id"],
 
 1512                                 $first_question[
"questionblock_title"].
" (".$block_status.
")", $menu, 
false, 
false, $block_status);
 
 1518                 include_once 
"./Modules/SurveyQuestionPool/classes/class.ilObjSurveyQuestionPool.php";
 
 1520                 $questionpools = array_keys($this->object->getQuestionpoolTitles(
true));
 
 1522                 $counter = $question_count;
 
 1524                 foreach($a_questions as $idx => $question)
 
 1534                                         foreach($questiontypes as $trans => $item)
 
 1536                                                 $menu[] = array(
"cmd"=> 
"addQuestion_".$item[
"questiontype_id"],
 
 1537                                                         "text"=> sprintf($lng->txt(
"svy_page_add_question"), $trans));
 
 1540                                         if($this->object->isPoolActive())
 
 1542                                                 $menu[] = array(
"cmd"=> 
"addPoolQuestion",
 
 1543                                                         "text"=> $lng->txt(
"browse_for_questions"));
 
 1548                                         $menu[] = array(
"cmd" => 
"paste", 
"text" => $lng->txt(
"survey_dnd_paste"));
 
 1552                         $this->
renderPageNode($ttpl, 
"droparea", $question[
"question_id"], null, $menu, 
true);
 
 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());
 
 1561                         if(!$a_readonly && !$has_clipboard)
 
 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"));
 
 1567                                 if(
sizeof($a_questions) > 1 && $idx > 0)
 
 1569                                         $menu[] = array(
"cmd" => 
"splitPage", 
"text" => $lng->txt(
"survey_dnd_split_page"));
 
 1571                                 if($a_has_next_page)
 
 1573                                         $menu[] = array(
"cmd" => 
"moveNext", 
"text" => $lng->txt(
"survey_dnd_move_next"));
 
 1575                                 if($a_has_previous_page)
 
 1577                                         $menu[] = array(
"cmd" => 
"movePrevious", 
"text" => $lng->txt(
"survey_dnd_move_previous"));
 
 1580                                 $menu[] = array(
"cmd" => 
"deleteQuestion", 
"text" => $lng->txt(
"delete"));
 
 1583                                 if($question[
"heading"])
 
 1585                                         $menu[] = array(
"cmd" => 
"editHeading", 
"text" => $lng->txt(
"survey_edit_heading"));
 
 1586                                         $menu[] = array(
"cmd" => 
"deleteHeading", 
"text" => $lng->txt(
"survey_delete_heading"));
 
 1590                                         $menu[] = array(
"cmd" => 
"addHeading", 
"text" => $lng->txt(
"add_heading"));
 
 1594                         if($first_question[
"questionblock_show_questiontext"])
 
 1596                                 $question_title_status = $lng->txt(
"survey_question_text_visible");
 
 1600                                 $question_title_status = $lng->txt(
"survey_question_text_hidden");
 
 1603                         $this->
renderPageNode($ttpl, 
"question", $question[
"question_id"], $question_form, $menu,
 
 1604                                 false, $question[
"title"], $question_title_status, $question[
"heading"]);
 
 1606                         $ilCtrl->setParameter($this, 
"eqid", 
"");
 
 1618                                 foreach($questiontypes as $trans => $item)
 
 1620                                         $menu[] = array(
"cmd"=> 
"addQuestion_".$item[
"questiontype_id"],
 
 1621                                                 "text"=> sprintf($lng->txt(
"svy_page_add_question"), $trans));
 
 1624                                 if($this->object->isPoolActive())
 
 1626                                         $menu[] = array(
"cmd"=> 
"addPoolQuestion",
 
 1627                                                 "text"=> $lng->txt(
"browse_for_questions"));
 
 1632                                 $menu[] = array(
"cmd" => 
"paste", 
"text" => $lng->txt(
"survey_dnd_paste"));
 
 1638                 return $ttpl->get();
 
 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)
 
 1657                 $node_id = $a_type.
"_".$a_id;
 
 1659                 if($a_content !== null)
 
 1666                                         $caption = $lng->txt(
"questionblock");
 
 1672                                                 $a_content = 
"<div class=\"questionheading\">".$a_heading.
"</div>".
 
 1675                                         $caption = $lng->txt(
"question").
": ".$a_subtitle;
 
 1681                                         $caption = $lng->txt(
"heading");
 
 1690                                 $caption .= 
" (".$a_status.
")";
 
 1697                         $a_tpl->
setVariable(
"TXT_NODE_CONTENT", $a_content);
 
 1700                                 $a_tpl->
setVariable(
"VAL_DBLCLICK", 
" onDblClick=\"doMouseDblClick(event,this.id);\"");
 
 1708                         foreach($a_menu as $mcnt => $menu_item)
 
 1711                                 $a_tpl->
setVariable(
"TXT_MENU_CMD", $menu_item[
"text"]);
 
 1745                 $this->
object->deleteAllUserData();
 
 1758                 $this->
object->saveHeading(
"", 
$_POST[
"removeheading"]);
 
 1769                 $node = 
$_POST[
"ajaxform_node"];
 
 1772                         $node = explode(
"_", $node);
 
 1773                         if($node[0] == 
"heading")
 
 1775                                 $id = (int)$node[1];
 
 1777                                 include_once 
"Modules/Survey/classes/class.ilObjSurvey.php";
 
 1789                 $node = 
$_POST[
"ajaxform_node"];
 
 1792                         $node = explode(
"_", $node);
 
 1793                         if($node[0] == 
"heading")
 
 1795                                 $id = (int)$node[1];
 
 1796                                 $content = trim(
$_POST[
"ajaxform_content"]);
 
 1798                                 $this->
object->saveHeading($content, $id);
 
 1813                 return $lng->txt(
"survey_auto_block_title");
 
 1820                 if($node == 
"page_end")
 
 1822                         $pos = $this->
object->getSurveyPages();
 
 1823                         $pos = array_pop($pos[$this->current_page-1]);
 
 1824                         $pos = $pos[
"question_id"].
"a";
 
 1831                 $ilCtrl->setParameter($this->survey_gui, 
"pgov", $this->current_page);
 
 1832                 $ilCtrl->setParameter($this->survey_gui, 
"pgov_pos", $pos);
 
 1834                 $cmd = ($ilUser->getPref(
'svy_insert_type') == 1 || strlen($ilUser->getPref(
'svy_insert_type')) == 0) ? 
'browseForQuestions' : 
'browseForQuestionblocks';
 
 1835                 $ilCtrl->redirect($this->survey_gui, 
$cmd);