ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjSurveyGUI.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 
40 include_once "./classes/class.ilObjectGUI.php";
41 include_once "./Modules/Survey/classes/inc.SurveyConstants.php";
42 
44 {
49  function ilObjSurveyGUI()
50  {
51  global $lng, $ilCtrl;
52 
53  $this->type = "svy";
54  $lng->loadLanguageModule("survey");
55  $this->ctrl =& $ilCtrl;
56  $this->ctrl->saveParameter($this, "ref_id");
57 
58  $this->ilObjectGUI("",$_GET["ref_id"], true, false);
59  }
60 
62  {
63  include_once "./Services/Utilities/classes/class.ilUtil.php";
64  $path = $this->tree->getPathFull($this->object->getRefID());
65  ilUtil::redirect($this->getReturnLocation("cancel","./repository.php?cmd=frameset&ref_id=" . $path[count($path) - 2]["child"]));
66  }
67 
71  function &executeCommand()
72  {
73  global $ilAccess, $ilNavigationHistory,$ilCtrl;
74 
75  if ((!$ilAccess->checkAccess("read", "", $_GET["ref_id"])) && (!$ilAccess->checkAccess("visible", "", $_GET["ref_id"])))
76  {
77  global $ilias;
78  $ilias->raiseError($this->lng->txt("permission_denied"), $ilias->error_obj->MESSAGE);
79  }
80  // add entry to navigation history
81  if (!$this->getCreationMode() &&
82  $ilAccess->checkAccess("read", "", $_GET["ref_id"]))
83  {
84  $ilNavigationHistory->addItem($_GET["ref_id"],
85  "ilias.php?baseClass=ilObjSurveyGUI&cmd=infoScreen&ref_id=".$_GET["ref_id"], "svy");
86  }
87 
88  $cmd = $this->ctrl->getCmd("properties");
89 
90  // workaround for bug #6288, needs better solution
91  if ($cmd == "saveTags")
92  {
93  $ilCtrl->setCmdClass("ilinfoscreengui");
94  }
95 
96  $next_class = $this->ctrl->getNextClass($this);
97  $this->ctrl->setReturn($this, "properties");
98  $this->tpl->addCss(ilUtil::getStyleSheetLocation("output", "survey.css", "Modules/Survey"), "screen");
99  $this->prepareOutput();
100  //echo "<br>nextclass:$next_class:cmd:$cmd:qtype=$q_type";
101  switch($next_class)
102  {
103  case "ilinfoscreengui":
104  $this->infoScreen(); // forwards command
105  break;
106  case 'ilmdeditorgui':
107  include_once 'Services/MetaData/classes/class.ilMDEditorGUI.php';
108  $md_gui =& new ilMDEditorGUI($this->object->getId(), 0, $this->object->getType());
109  $md_gui->addObserver($this->object,'MDUpdateListener','General');
110 
111  $this->ctrl->forwardCommand($md_gui);
112  break;
113 
114  case "ilsurveyevaluationgui":
115  include_once("./Modules/Survey/classes/class.ilSurveyEvaluationGUI.php");
116  $eval_gui = new ilSurveyEvaluationGUI($this->object);
117  $ret =& $this->ctrl->forwardCommand($eval_gui);
118  break;
119 
120  case "ilsurveyexecutiongui":
121  include_once("./Modules/Survey/classes/class.ilSurveyExecutionGUI.php");
122  $exec_gui = new ilSurveyExecutionGUI($this->object);
123  $ret =& $this->ctrl->forwardCommand($exec_gui);
124  break;
125 
126  case 'ilpermissiongui':
127  include_once("Services/AccessControl/classes/class.ilPermissionGUI.php");
128  $perm_gui =& new ilPermissionGUI($this);
129  $ret =& $this->ctrl->forwardCommand($perm_gui);
130  break;
131 
132  case 'ilobjectcopygui':
133  include_once './Services/Object/classes/class.ilObjectCopyGUI.php';
134  $cp = new ilObjectCopyGUI($this);
135  $cp->setType('svy');
136  $this->ctrl->forwardCommand($cp);
137  break;
138 
139 
140  default:
141  $cmd.= "Object";
142  $ret =& $this->$cmd();
143  break;
144  }
145  if (strtolower($_GET["baseClass"]) != "iladministrationgui" &&
146  $this->getCreationMode() != true)
147  {
148  $this->tpl->show();
149  }
150  }
151 
156  function saveObject()
157  {
158  global $rbacadmin;
159 
160  if (!strlen($_POST['Fobject']['title']))
161  {
162  ilUtil::sendFailure($this->lng->txt('title_required'), true);
163  $this->ctrl->setParameter($this, 'new_type', $_GET['new_type']);
164  $this->ctrl->redirect($this, 'create');
165  }
166 
167  // create and insert forum in objecttree
168  $newObj = parent::saveObject();
169  // always send a message
170  ilUtil::sendSuccess($this->lng->txt("object_added"),true);
171  ilUtil::redirect("ilias.php?baseClass=ilObjSurveyGUI&ref_id=".$newObj->getRefId()."&cmd=properties");
172  }
173 
179  function cancelObject($in_rep = false)
180  {
181  ilUtil::redirect("repository.php?cmd=frameset&ref_id=".$_GET["ref_id"]);
182  }
183 
192  {
193  $this->ctrl->redirect($this, "properties");
194  }
195 
203  function handleWriteAccess()
204  {
205  global $ilAccess;
206  if (!$ilAccess->checkAccess("write", "", $this->ref_id))
207  {
208  // allow only write access
209  ilUtil::sendInfo($this->lng->txt("cannot_edit_survey"), TRUE);
210  $this->ctrl->redirect($this, "infoScreen");
211  }
212  }
213 
222  {
223  $hasErrors = $this->propertiesObject(true);
224  if (!$hasErrors)
225  {
226  $result = $this->object->setStatus($_POST['online']);
227  $this->object->setEvaluationAccess($_POST["evaluation_access"]);
228  $this->object->setStartDateEnabled($_POST["enabled_start_date"]);
229  if ($this->object->getStartDateEnabled())
230  {
231  $this->object->setStartDate($_POST['start_date']['date']);
232  }
233  else
234  {
235  $this->object->setStartDate(null);
236  }
237  $this->object->setEndDateEnabled($_POST["enabled_end_date"]);
238  if ($this->object->getEndDateEnabled())
239  {
240  $this->object->setEndDate($_POST['end_date']['date']);
241  }
242  else
243  {
244  $this->object->setEndDate(null);
245  }
246 
247  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
248  $introduction = $_POST["introduction"];
249  $this->object->setIntroduction($introduction);
250  $outro = $_POST["outro"];
251  $this->object->setOutro($outro);
252 
253  $hasDatasets = $this->object->_hasDatasets($this->object->getSurveyId());
254  if (!$hasDatasets)
255  {
256  $anonymize = $_POST["anonymization"];
257  if ($anonymize)
258  {
259  if (strcmp($_POST['anonymization_options'], 'anonymize_without_code') == 0) $anonymize = ANONYMIZE_FREEACCESS;
260  }
261  $this->object->setAnonymize($anonymize);
262  }
263  $this->object->setShowQuestionTitles($_POST["show_question_titles"]);
264  $this->object->saveToDb();
265  if (strcmp($_SESSION["info"], "") != 0)
266  {
267  ilUtil::sendSuccess($_SESSION["info"] . "<br />" . $this->lng->txt("settings_saved"), true);
268  }
269  else
270  {
271  ilUtil::sendSuccess($this->lng->txt("settings_saved"), true);
272  }
273  $this->ctrl->redirect($this, "properties");
274  }
275  }
276 
282  function propertiesObject($checkonly = FALSE)
283  {
284  global $ilAccess;
285 
286  $save = (strcmp($this->ctrl->getCmd(), "saveProperties") == 0) ? TRUE : FALSE;
287 
288  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
289  $form = new ilPropertyFormGUI();
290  $form->setFormAction($this->ctrl->getFormAction($this));
291  $form->setTableWidth("100%");
292  $form->setId("survey_properties");
293 
294  // general properties
295  $header = new ilFormSectionHeaderGUI();
296  $header->setTitle($this->lng->txt("properties"));
297  $form->addItem($header);
298 
299  // online
300  $online = new ilCheckboxInputGUI($this->lng->txt("online"), "online");
301  $online->setValue(1);
302  $online->setChecked($this->object->isOnline());
303  $form->addItem($online);
304 
305  // introduction
306  $intro = new ilTextAreaInputGUI($this->lng->txt("introduction"), "introduction");
307  $intro->setValue($this->object->prepareTextareaOutput($this->object->getIntroduction()));
308  $intro->setRows(10);
309  $intro->setCols(80);
310  $intro->setUseRte(TRUE);
311  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
312  $intro->setRteTags(ilObjAdvancedEditing::_getUsedHTMLTags("survey"));
313  $intro->addPlugin("latex");
314  $intro->addButton("latex");
315  $intro->addPlugin("pastelatex");
316  $intro->setRTESupport($this->object->getId(), "svy", "survey");
317  $form->addItem($intro);
318 
319  // enable start date
320  $enablestartingtime = new ilCheckboxInputGUI($this->lng->txt("start_date"), "enabled_start_date");
321  $enablestartingtime->setValue(1);
322  $enablestartingtime->setOptionTitle($this->lng->txt("enabled"));
323  $enablestartingtime->setChecked($this->object->getStartDateEnabled());
324  // start date
325  $startingtime = new ilDateTimeInputGUI('', 'start_date');
326  $startingtime->setShowDate(true);
327  $startingtime->setShowTime(false);
328  if ($this->object->getStartDateEnabled())
329  {
330  $startingtime->setDate(new ilDate($this->object->getStartDate(), IL_CAL_DATE));
331  }
332  else
333  {
334  $startingtime->setDate(new ilDate(time(), IL_CAL_UNIX));
335  }
336  $enablestartingtime->addSubItem($startingtime);
337  $form->addItem($enablestartingtime);
338 
339  // enable end date
340  $enableendingtime = new ilCheckboxInputGUI($this->lng->txt("end_date"), "enabled_end_date");
341  $enableendingtime->setValue(1);
342  $enableendingtime->setOptionTitle($this->lng->txt("enabled"));
343  $enableendingtime->setChecked($this->object->getEndDateEnabled());
344  // end date
345  $endingtime = new ilDateTimeInputGUI('', 'end_date');
346  $endingtime->setShowDate(true);
347  $endingtime->setShowTime(false);
348  if ($this->object->getEndDateEnabled())
349  {
350  $endingtime->setDate(new ilDate($this->object->getEndDate(), IL_CAL_DATE));
351  }
352  else
353  {
354  $endingtime->setDate(new ilDate(time(), IL_CAL_UNIX));
355  }
356  $enableendingtime->addSubItem($endingtime);
357  $form->addItem($enableendingtime);
358 
359  // anonymization
360  $anonymization = new ilCheckboxInputGUI($this->lng->txt("anonymization"), "anonymization");
361  $hasDatasets = $this->object->_hasDatasets($this->object->getSurveyId());
362  if ($hasDatasets)
363  {
364  $anonymization->setDisabled(true);
365  }
366  $anonymization->setOptionTitle($this->lng->txt("on"));
367  $anonymization->setValue(1);
368  $anonymization->setChecked($this->object->getAnonymize());
369  $anonymization->setInfo($this->lng->txt("anonymize_survey_description"));
370 
371  $anonymization_options = new ilRadioGroupInputGUI('', "anonymization_options");
372  if ($hasDatasets)
373  {
374  $anonymization_options->setDisabled(true);
375  }
376  $anonymization_options->addOption(new ilCheckboxOption($this->lng->txt("anonymize_without_code"), 'anonymize_without_code', ''));
377  $anonymization_options->addOption(new ilCheckboxOption($this->lng->txt("anonymize_with_code"), 'anonymize_with_code', ''));
378  $anonymization_options->setValue(($this->object->isAccessibleWithoutCode()) ? 'anonymize_without_code' : 'anonymize_with_code');
379 
380  $anonymization->addSubItem($anonymization_options);
381  $form->addItem($anonymization);
382 
383  // evaluation access
384  $evaluation_access = new ilRadioGroupInputGUI($this->lng->txt('evaluation_access'), "evaluation_access");
385  $evaluation_access->setInfo($this->lng->txt('evaluation_access_description'));
386  $evaluation_access->addOption(new ilCheckboxOption($this->lng->txt("evaluation_access_off"), EVALUATION_ACCESS_OFF, ''));
387  $evaluation_access->addOption(new ilCheckboxOption($this->lng->txt("evaluation_access_all"), EVALUATION_ACCESS_ALL, ''));
388  $evaluation_access->addOption(new ilCheckboxOption($this->lng->txt("evaluation_access_participants"), EVALUATION_ACCESS_PARTICIPANTS, ''));
389  $evaluation_access->setValue($this->object->getEvaluationAccess());
390  $form->addItem($evaluation_access);
391 
392  // show question titles
393  $show_question_titles = new ilCheckboxInputGUI('', "show_question_titles");
394  $show_question_titles->setOptionTitle($this->lng->txt("svy_show_questiontitles"));
395  $show_question_titles->setValue(1);
396  $show_question_titles->setChecked($this->object->getShowQuestionTitles());
397  $form->addItem($show_question_titles);
398 
399  // final statement
400  $finalstatement = new ilTextAreaInputGUI($this->lng->txt("outro"), "outro");
401  $finalstatement->setValue($this->object->prepareTextareaOutput($this->object->getOutro()));
402  $finalstatement->setRows(10);
403  $finalstatement->setCols(80);
404  $finalstatement->setUseRte(TRUE);
405  $finalstatement->setRteTags(ilObjAdvancedEditing::_getUsedHTMLTags("survey"));
406  $finalstatement->addPlugin("latex");
407  $finalstatement->addButton("latex");
408  $finalstatement->addPlugin("pastelatex");
409  $finalstatement->setRTESupport($this->object->getId(), "svy", "survey");
410  $form->addItem($finalstatement);
411 
412  if ($ilAccess->checkAccess("write", "", $_GET["ref_id"])) $form->addCommandButton("saveProperties", $this->lng->txt("save"));
413  $errors = false;
414 
415  if ($save)
416  {
417  $errors = !$form->checkInput();
418  $form->setValuesByPost();
419  if (!$errors)
420  {
421  if (($online->getChecked()) && (count($this->object->questions) == 0))
422  {
423  $online->setAlert($this->lng->txt("cannot_switch_to_online_no_questions"));
424  ilUtil::sendFailure($this->lng->txt('form_input_not_valid'));
425  $errors = true;
426  }
427  }
428  if ($errors) $checkonly = false;
429  }
430  if (!$checkonly) $this->tpl->setVariable("ADM_CONTENT", $form->getHTML());
431  return $errors;
432  }
433 
442  {
443  $checked_questions = array();
444  $checked_questionblocks = array();
445  foreach ($_POST as $key => $value)
446  {
447  if (preg_match("/cb_(\d+)/", $key, $matches))
448  {
449  array_push($checked_questions, $matches[1]);
450  }
451  if (preg_match("/cb_qb_(\d+)/", $key, $matches))
452  {
453  array_push($checked_questionblocks, $matches[1]);
454  }
455  }
456  if (count($checked_questions) + count($checked_questionblocks) > 0)
457  {
458  ilUtil::sendQuestion($this->lng->txt("remove_questions"));
459  $this->removeQuestionsForm($checked_questions, $checked_questionblocks);
460  return;
461  }
462  else
463  {
464  ilUtil::sendInfo($this->lng->txt("no_question_selected_for_removal"), true);
465  $this->ctrl->redirect($this, "questions");
466  }
467  }
468 
472  public function insertQuestionsObject()
473  {
474  $inserted_objects = 0;
475  if (is_array($_POST['q_id']))
476  {
477  foreach ($_POST['q_id'] as $question_id)
478  {
479  $this->object->insertQuestion($question_id);
480  $inserted_objects++;
481  }
482  }
483  if ($inserted_objects)
484  {
485  $this->object->saveCompletionStatus();
486  ilUtil::sendSuccess($this->lng->txt("questions_inserted"), true);
487  $this->ctrl->redirect($this, "questions");
488  }
489  else
490  {
491  ilUtil::sendInfo($this->lng->txt("insert_missing_question"), true);
492  $this->ctrl->redirect($this, 'browseForQuestions');
493  }
494  }
495 
499  public function insertQuestionblocksObject()
500  {
501  $inserted_objects = 0;
502  if (is_array($_POST['cb']))
503  {
504  foreach ($_POST['cb'] as $questionblock_id)
505  {
506  $this->object->insertQuestionblock($questionblock_id);
507  $inserted_objects++;
508  }
509  }
510  if ($inserted_objects)
511  {
512  $this->object->saveCompletionStatus();
513  ilUtil::sendSuccess(($inserted_objects == 1) ? $this->lng->txt("questionblock_inserted") : $this->lng->txt("questionblocks_inserted"), true);
514  $this->ctrl->redirect($this, "questions");
515  }
516  else
517  {
518  ilUtil::sendInfo($this->lng->txt("insert_missing_questionblock"), true);
519  $this->ctrl->redirect($this, 'browseForQuestionblocks');
520  }
521  }
522 
526  public function changeDatatypeObject()
527  {
528  global $ilUser;
529  $ilUser->writePref('svy_insert_type', $_POST['datatype']);
530  switch ($_POST["datatype"])
531  {
532  case 0:
533  $this->ctrl->redirect($this, 'browseForQuestionblocks');
534  break;
535  case 1:
536  default:
537  $this->ctrl->redirect($this, 'browseForQuestions');
538  break;
539  }
540  }
541 
546  {
547  include_once "./Modules/Survey/classes/tables/class.ilSurveyQuestionblockbrowserTableGUI.php";
548  $table_gui = new ilSurveyQuestionblockbrowserTableGUI($this, 'browseForQuestionblocks');
549  $table_gui->writeFilterToSession();
550  $this->ctrl->redirect($this, 'browseForQuestionblocks');
551  }
552 
557  {
558  include_once "./Modules/Survey/classes/tables/class.ilSurveyQuestionblockbrowserTableGUI.php";
559  $table_gui = new ilSurveyQuestionblockbrowserTableGUI($this, 'browseForQuestionblocks');
560  $table_gui->resetFilter();
561  $this->ctrl->redirect($this, 'browseForQuestionblocks');
562  }
563 
567  public function browseForQuestionblocksObject($arrFilter = null)
568  {
569  global $rbacsystem;
570  global $ilUser;
571 
573  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_svy_questionbrowser.html", "Modules/Survey");
574  include_once "./Modules/Survey/classes/tables/class.ilSurveyQuestionblockbrowserTableGUI.php";
575  $table_gui = new ilSurveyQuestionblockbrowserTableGUI($this, 'browseForQuestionblocks', (($rbacsystem->checkAccess('write', $_GET['ref_id']) ? true : false)));
576  $table_gui->setEditable($rbacsystem->checkAccess('write', $_GET['ref_id']));
577  $arrFilter = array();
578  foreach ($table_gui->getFilterItems() as $item)
579  {
580  if ($item->getValue() !== false)
581  {
582  $arrFilter[$item->getPostVar()] = $item->getValue();
583  }
584  }
585  $data = $this->object->getQuestionblocksTable($arrFilter);
586  $table_gui->setData($data);
587  $this->tpl->setVariable('TABLE', $table_gui->getHTML());
588 
589  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this, 'changeDatatype'));
590  $this->tpl->setVariable("OPTION_QUESTIONS", $this->lng->txt("questions"));
591  $this->tpl->setVariable("OPTION_QUESTIONBLOCKS", $this->lng->txt("questionblocks"));
592  $this->tpl->setVariable("SELECTED_QUESTIONBLOCKS", " selected=\"selected\"");
593  $this->tpl->setVariable("TEXT_DATATYPE", $this->lng->txt("display_all_available"));
594  $this->tpl->setVariable("BTN_CHANGE", $this->lng->txt("change"));
595  }
596 
600  public function filterQuestionBrowserObject()
601  {
602  include_once "./Modules/Survey/classes/tables/class.ilSurveyQuestionbrowserTableGUI.php";
603  $table_gui = new ilSurveyQuestionbrowserTableGUI($this, 'browseForQuestions');
604  $table_gui->writeFilterToSession();
605  $this->ctrl->redirect($this, 'browseForQuestions');
606  }
607 
612  {
613  include_once "./Modules/Survey/classes/tables/class.ilSurveyQuestionbrowserTableGUI.php";
614  $table_gui = new ilSurveyQuestionbrowserTableGUI($this, 'browseForQuestions');
615  $table_gui->resetFilter();
616  $this->ctrl->redirect($this, 'browseForQuestions');
617  }
618 
622  public function browseForQuestionsObject($arrFilter = null)
623  {
624  global $rbacsystem;
625  global $ilUser;
626 
628  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_svy_questionbrowser.html", "Modules/Survey");
629  include_once "./Modules/Survey/classes/tables/class.ilSurveyQuestionbrowserTableGUI.php";
630  $table_gui = new ilSurveyQuestionbrowserTableGUI($this, 'browseForQuestions', (($rbacsystem->checkAccess('write', $_GET['ref_id']) ? true : false)));
631  $table_gui->setEditable($rbacsystem->checkAccess('write', $_GET['ref_id']));
632  $arrFilter = array();
633  foreach ($table_gui->getFilterItems() as $item)
634  {
635  if ($item->getValue() !== false)
636  {
637  $arrFilter[$item->getPostVar()] = $item->getValue();
638  }
639  }
640  $data = $this->object->getQuestionsTable($arrFilter);
641  $table_gui->setData($data);
642  $this->tpl->setVariable('TABLE', $table_gui->getHTML());
643 
644  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this, 'changeDatatype'));
645  $this->tpl->setVariable("OPTION_QUESTIONS", $this->lng->txt("questions"));
646  $this->tpl->setVariable("OPTION_QUESTIONBLOCKS", $this->lng->txt("questionblocks"));
647  $this->tpl->setVariable("SELECTED_QUESTIONS", " selected=\"selected\"");
648  $this->tpl->setVariable("TEXT_DATATYPE", $this->lng->txt("display_all_available"));
649  $this->tpl->setVariable("BTN_CHANGE", $this->lng->txt("change"));
650  }
651 
661  function removeQuestionsForm($checked_questions, $checked_questionblocks)
662  {
664  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_svy_remove_questions.html", "Modules/Survey");
665  $colors = array("tblrow1", "tblrow2");
666  $counter = 0;
667  $surveyquestions =& $this->object->getSurveyQuestions();
668  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
669  foreach ($surveyquestions as $question_id => $data)
670  {
671  if (in_array($data["question_id"], $checked_questions) or (in_array($data["questionblock_id"], $checked_questionblocks)))
672  {
673  $this->tpl->setCurrentBlock("row");
674  $this->tpl->setVariable("COLOR_CLASS", $colors[$counter % 2]);
675  $this->tpl->setVariable("TEXT_TITLE", $data["title"]);
676  $this->tpl->setVariable("TEXT_DESCRIPTION", $data["description"]);
677  $this->tpl->setVariable("TEXT_TYPE", SurveyQuestion::_getQuestionTypeName($data["type_tag"]));
678  $this->tpl->setVariable("TEXT_QUESTIONBLOCK", $data["questionblock_title"]);
679  $this->tpl->parseCurrentBlock();
680  $counter++;
681  }
682  }
683  foreach ($checked_questions as $id)
684  {
685  $this->tpl->setCurrentBlock("hidden");
686  $this->tpl->setVariable("HIDDEN_NAME", "id_$id");
687  $this->tpl->setVariable("HIDDEN_VALUE", "$id");
688  $this->tpl->parseCurrentBlock();
689  }
690  foreach ($checked_questionblocks as $id)
691  {
692  $this->tpl->setCurrentBlock("hidden");
693  $this->tpl->setVariable("HIDDEN_NAME", "id_qb_$id");
694  $this->tpl->setVariable("HIDDEN_VALUE", "$id");
695  $this->tpl->parseCurrentBlock();
696  }
697  $this->tpl->setCurrentBlock("adm_content");
698  $this->tpl->setVariable("TEXT_TITLE", $this->lng->txt("title"));
699  $this->tpl->setVariable("TEXT_DESCRIPTION", $this->lng->txt("description"));
700  $this->tpl->setVariable("TEXT_TYPE", $this->lng->txt("question_type"));
701  $this->tpl->setVariable("TEXT_QUESTIONBLOCK", $this->lng->txt("questionblock"));
702  $this->tpl->setVariable("BTN_CONFIRM", $this->lng->txt("confirm"));
703  $this->tpl->setVariable("BTN_CANCEL", $this->lng->txt("cancel"));
704  $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this, "confirmRemoveQuestions"));
705  $this->tpl->parseCurrentBlock();
706  }
707 
708 
717  function defineQuestionblock($questionblock_id = "")
718  {
719  $this->questionsSubtabs("questions");
721  if ($questionblock_id)
722  {
723  $questionblock = $this->object->getQuestionblock($questionblock_id);
724  }
725  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_define_questionblock.html", "Modules/Survey");
726  foreach ($_POST as $key => $value)
727  {
728  if (preg_match("/cb_(\d+)/", $key, $matches))
729  {
730  $this->tpl->setCurrentBlock("hidden");
731  $this->tpl->setVariable("HIDDEN_NAME", "cb_$matches[1]");
732  $this->tpl->setVariable("HIDDEN_VALUE", $matches[1]);
733  $this->tpl->parseCurrentBlock();
734  }
735  }
736  if ($questionblock_id)
737  {
738  $this->tpl->setCurrentBlock("hidden");
739  $this->tpl->setVariable("HIDDEN_NAME", "questionblock_id");
740  $this->tpl->setVariable("HIDDEN_VALUE", $questionblock_id);
741  $this->tpl->parseCurrentBlock();
742  }
743  $this->tpl->setCurrentBlock("adm_content");
744  $this->tpl->setVariable("TEXT_TITLE", $this->lng->txt("title"));
745  if ($questionblock_id)
746  {
747  $this->tpl->setVariable("VALUE_TITLE", $questionblock["title"]);
748  }
749  $this->tpl->setVariable("TXT_QUESTIONTEXT_DESCRIPTION", $this->lng->txt("show_questiontext_description"));
750  $this->tpl->setVariable("TXT_QUESTIONTEXT", $this->lng->txt("show_questiontext"));
751  if (($questionblock["show_questiontext"]) || (strlen($questionblock_id) == 0))
752  {
753  $this->tpl->setVariable("CHECKED_QUESTIONTEXT", " checked=\"checked\"");
754  }
755  $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
756  $this->tpl->setVariable("HEADING_QUESTIONBLOCK", $this->lng->txt("define_questionblock"));
757  $this->tpl->setVariable("SAVE", $this->lng->txt("save"));
758  $this->tpl->setVariable("CANCEL", $this->lng->txt("cancel"));
759  $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this, "saveDefineQuestionblock"));
760  $this->tpl->parseCurrentBlock();
761  }
762 
771  {
772  global $ilUser;
773  $this->questionsSubtabs("questions");
774  $tpl = new ilTemplate("tpl.il_svy_svy_qpl_select.html", TRUE, TRUE, "Modules/Survey");
775  $questionpools =& $this->object->getAvailableQuestionpools(FALSE, TRUE, TRUE, "write");
776  if (count($questionpools))
777  {
778  foreach ($questionpools as $key => $value)
779  {
780  $tpl->setCurrentBlock("option");
781  $tpl->setVariable("VALUE_OPTION", $key);
782  $tpl->setVariable("TEXT_OPTION", $value);
783  $tpl->parseCurrentBlock();
784  }
785  $tpl->setCurrentBlock("selection");
786  $tpl->setVariable("TXT_QPL_SELECT", $this->lng->txt("select_questionpool"));
787  $tpl->parseCurrentBlock();
788  }
789  else
790  {
791  $tpl->setCurrentBlock("selection");
792  $tpl->setVariable("TXT_QPL_ENTER", $this->lng->txt("cat_create_spl"));
793  $tpl->parseCurrentBlock();
794  }
795  $tpl->setVariable("BTN_SUBMIT", $this->lng->txt("submit"));
796  $sel_question_types = (strlen($_POST["sel_question_types"])) ? $_POST["sel_question_types"] : $_GET["sel_question_types"];
797  $this->ctrl->setParameter($this, "sel_question_types", $sel_question_types);
798  $tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this, "executeCreateQuestion"));
799  $tpl->setVariable("BTN_CANCEL", $this->lng->txt("cancel"));
800  $this->tpl->setVariable("ADM_CONTENT", $tpl->get());
801  }
802 
811  {
812  $this->ctrl->redirect($this, "questions");
813  }
814 
823  {
824  if (strlen($_POST["sel_spl"]))
825  {
826  include_once "./Services/Utilities/classes/class.ilUtil.php";
827  ilUtil::redirect("ilias.php?baseClass=ilObjSurveyQuestionPoolGUI&ref_id=" . $_POST["sel_spl"] . "&cmd=createQuestionForSurvey&new_for_survey=".$_GET["ref_id"]."&sel_question_types=".$_GET["sel_question_types"]);
828  }
829  elseif (strlen($_POST["name_spl"]))
830  {
831  $ref_id = $this->createQuestionPool($_POST["name_spl"]);
832  ilUtil::redirect("ilias.php?baseClass=ilObjSurveyQuestionPoolGUI&ref_id=" . $ref_id . "&cmd=createQuestionForSurvey&new_for_survey=".$_GET["ref_id"]."&sel_question_types=".$_GET["sel_question_types"]);
833  }
834  else
835  {
836  ilUtil::sendFailure($this->lng->txt("err_no_pool_name"), true);
837  $this->ctrl->setParameter($this, "sel_question_types", $_GET["sel_question_types"]);
838  $this->ctrl->redirect($this, "createQuestion");
839  }
840  }
841 
848  private function createQuestionPool($name = "dummy")
849  {
850  global $tree;
851  $parent_ref = $tree->getParentId($this->object->getRefId());
852  include_once "./Modules/SurveyQuestionPool/classes/class.ilObjSurveyQuestionPool.php";
853  $qpl = new ilObjSurveyQuestionPool();
854  $qpl->setType("spl");
855  $qpl->setTitle($name);
856  $qpl->setDescription("");
857  $qpl->create();
858  $qpl->createReference();
859  $qpl->putInTree($parent_ref);
860  $qpl->setPermissions($parent_ref);
861  $qpl->setOnline(1); // must be online to be available
862  $qpl->saveToDb();
863  return $qpl->getRefId();
864  }
865 
874  function addHeadingObject($question_id = "")
875  {
876  $this->questionsSubtabs("questions");
877  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_svy_heading.html", "Modules/Survey");
878  $survey_questions =& $this->object->getSurveyQuestions();
879  if ($question_id)
880  {
881  $_POST["insertbefore"] = $question_id;
882  $_POST["heading"] = $survey_questions[$question_id]["heading"];
883  }
884  foreach ($survey_questions as $key => $value)
885  {
886  $this->tpl->setCurrentBlock("insertbefore_row");
887  $this->tpl->setVariable("VALUE_OPTION", $key);
888  $option = $this->lng->txt("before") . ": \"" . $value["title"] . "\"";
889  if (strlen($option) > 80)
890  {
891  $option = preg_replace("/^(.{40}).*(.{40})$/", "\\1 [...] \\2", $option);
892  }
893  include_once "./Services/Utilities/classes/class.ilUtil.php";
894  $this->tpl->setVariable("TEXT_OPTION", ilUtil::prepareFormOutput($option));
895  if ($key == $_POST["insertbefore"])
896  {
897  $this->tpl->setVariable("SELECTED_OPTION", " selected=\"selected\"");
898  }
899  $this->tpl->parseCurrentBlock();
900  }
901  if ($question_id)
902  {
903  $this->tpl->setCurrentBlock("hidden");
904  $this->tpl->setVariable("INSERTBEFORE_ORIGINAL", $question_id);
905  $this->tpl->parseCurrentBlock();
906  }
907  $this->tpl->setCurrentBlock("adm_content");
908  $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this, "saveHeading"));
909  $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
910  if ($question_id)
911  {
912  $this->tpl->setVariable("TEXT_ADD_HEADING", $this->lng->txt("edit_heading"));
913  $this->tpl->setVariable("SELECT_DISABLED", " disabled=\"disabled\"");
914  }
915  else
916  {
917  $this->tpl->setVariable("TEXT_ADD_HEADING", $this->lng->txt("add_heading"));
918  }
919  $this->tpl->setVariable("TEXT_HEADING", $this->lng->txt("heading"));
920  $this->tpl->setVariable("VALUE_HEADING", $_POST["heading"]);
921  $this->tpl->setVariable("TEXT_INSERT", $this->lng->txt("insert"));
922  $this->tpl->setVariable("CANCEL", $this->lng->txt("cancel"));
923  $this->tpl->setVariable("SAVE", $this->lng->txt("save"));
924  $this->tpl->parseCurrentBlock();
925  include_once "./Services/RTE/classes/class.ilRTE.php";
926  $rtestring = ilRTE::_getRTEClassname();
927  include_once "./Services/RTE/classes/class.$rtestring.php";
928  $rte = new $rtestring();
929  $rte->removePlugin("ibrowser");
930  include_once "./classes/class.ilObject.php";
932  $obj_type = ilObject::_lookupType($_GET["ref_id"], TRUE);
933  $rte->addRTESupport($obj_id, $obj_type, "survey");
934  }
935 
944  {
945  // insert questions from test after confirmation
946  foreach ($_POST as $key => $value) {
947  if (preg_match("/id_(\d+)/", $key, $matches)) {
948  if ($_GET["browsetype"] == 1)
949  {
950  $this->object->insertQuestion($matches[1]);
951  }
952  else
953  {
954  $this->object->insertQuestionBlock($matches[1]);
955  }
956  }
957  }
958  $this->object->saveCompletionStatus();
959  ilUtil::sendSuccess($this->lng->txt("questions_inserted"), true);
960  $this->ctrl->redirect($this, "questions");
961  }
962 
971  {
972  $this->ctrl->redirect($this, "questions");
973  }
974 
982  function saveHeadingObject()
983  {
984  if ($_POST["heading"])
985  {
986  $insertbefore = $_POST["insertbefore"];
987  if (!$insertbefore)
988  {
989  $insertbefore = $_POST["insertbefore_original"];
990  }
991  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
992  $this->object->saveHeading(ilUtil::stripSlashes($_POST["heading"], TRUE, ilObjAdvancedEditing::_getUsedHTMLTagsAsString("survey")), $insertbefore);
993  $this->ctrl->redirect($this, "questions");
994  }
995  else
996  {
997  ilUtil::sendFailure($this->lng->txt("error_add_heading"));
998  $this->addHeadingObject();
999  return;
1000  }
1001  }
1002 
1011  {
1012  $this->ctrl->redirect($this, "questions");
1013  }
1014 
1023  {
1024  $this->object->saveHeading("", $_POST["removeheading"]);
1025  $this->ctrl->redirect($this, "questions");
1026  }
1027 
1036  {
1037  $this->ctrl->redirect($this, "questions");
1038  }
1039 
1048  {
1049  ilUtil::sendQuestion($this->lng->txt("confirm_remove_heading"));
1050  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_svy_confirm_removeheading.html", "Modules/Survey");
1051  $this->tpl->setCurrentBlock("adm_content");
1052  $this->tpl->setVariable("BTN_CONFIRM_REMOVE", $this->lng->txt("confirm"));
1053  $this->tpl->setVariable("BTN_CANCEL_REMOVE", $this->lng->txt("cancel"));
1054  $this->tpl->setVariable("REMOVE_HEADING", $_GET["removeheading"]);
1055  $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this, "confirmRemoveHeading"));
1056  $this->tpl->parseCurrentBlock();
1057  }
1058 
1067  {
1068  $checked_questions = array();
1069  $checked_questionblocks = array();
1070  foreach ($_POST as $key => $value)
1071  {
1072  if (preg_match("/id_(\d+)/", $key, $matches))
1073  {
1074  array_push($checked_questions, $matches[1]);
1075  }
1076  if (preg_match("/id_qb_(\d+)/", $key, $matches))
1077  {
1078  array_push($checked_questionblocks, $matches[1]);
1079  }
1080  }
1081  $this->object->removeQuestions($checked_questions, $checked_questionblocks);
1082  $this->object->saveCompletionStatus();
1083  ilUtil::sendSuccess($this->lng->txt("questions_removed"), true);
1084  $this->ctrl->redirect($this, "questions");
1085  }
1086 
1095  {
1096  $this->ctrl->redirect($this, "questions");
1097  }
1098 
1107  {
1108  $questionblock = array();
1109  foreach ($_POST as $key => $value)
1110  {
1111  if (preg_match("/cb_(\d+)/", $key, $matches))
1112  {
1113  array_push($questionblock, $value);
1114  }
1115  }
1116  if (count($questionblock) < 2)
1117  {
1118  ilUtil::sendInfo($this->lng->txt("qpl_define_questionblock_select_missing"), true);
1119  $this->ctrl->redirect($this, "questions");
1120  }
1121  else
1122  {
1123  $this->defineQuestionblock();
1124  return;
1125  }
1126  }
1127 
1132  {
1133  if ($_POST["title"])
1134  {
1135  $show_questiontext = ($_POST["show_questiontext"]) ? 1 : 0;
1136  if ($_POST["questionblock_id"])
1137  {
1138  include_once "./Services/Utilities/classes/class.ilUtil.php";
1139  $this->object->modifyQuestionblock($_POST["questionblock_id"], ilUtil::stripSlashes($_POST["title"]), $show_questiontext);
1140  }
1141  else
1142  {
1143  $questionblock = array();
1144  foreach ($_POST as $key => $value)
1145  {
1146  if (preg_match("/cb_(\d+)/", $key, $matches))
1147  {
1148  array_push($questionblock, $value);
1149  }
1150  }
1151  include_once "./Services/Utilities/classes/class.ilUtil.php";
1152  $this->object->createQuestionblock(ilUtil::stripSlashes($_POST["title"]), $show_questiontext, $questionblock);
1153  }
1154  ilUtil::sendSuccess($this->lng->txt('msg_obj_modified'), true);
1155  $this->ctrl->redirect($this, "questions");
1156  }
1157  else
1158  {
1159  ilUtil::sendInfo($this->lng->txt("enter_questionblock_title"));
1160  $this->defineQuestionblockObject();
1161  return;
1162  }
1163  }
1164 
1168  public function unfoldQuestionblockObject()
1169  {
1170  $unfoldblocks = array();
1171  foreach ($_POST as $key => $value)
1172  {
1173  if (preg_match("/cb_qb_(\d+)/", $key, $matches))
1174  {
1175  array_push($unfoldblocks, $matches[1]);
1176  }
1177  }
1178  if (count($unfoldblocks))
1179  {
1180  ilUtil::sendSuccess($this->lng->txt('msg_obj_modified'), true);
1181  $this->object->unfoldQuestionblocks($unfoldblocks);
1182  }
1183  else
1184  {
1185  ilUtil::sendInfo($this->lng->txt("qpl_unfold_select_none"), true);
1186  }
1187  $this->ctrl->redirect($this, "questions");
1188  }
1189 
1194  {
1195  ilUtil::sendInfo($this->lng->txt('msg_cancel'), true);
1196  $this->ctrl->redirect($this, "questions");
1197  }
1198 
1202  public function moveQuestionsObject()
1203  {
1204  $move_questions = array();
1205  foreach ($_POST as $key => $value)
1206  {
1207  if (preg_match("/cb_(\d+)/", $key, $matches))
1208  {
1209  array_push($move_questions, $matches[1]);
1210  }
1211  if (preg_match("/cb_qb_(\d+)/", $key, $matches))
1212  {
1213  $ids = $this->object->getQuestionblockQuestionIds($matches[1]);
1214  foreach ($ids as $qkey => $qid)
1215  {
1216  array_push($move_questions, $qid);
1217  }
1218  }
1219  }
1220  if (count($move_questions) == 0)
1221  {
1222  ilUtil::sendInfo($this->lng->txt("no_question_selected_for_move"), true);
1223  $this->ctrl->redirect($this, "questions");
1224  }
1225  else
1226  {
1227  $_SESSION["move_questions"] = $move_questions;
1228  ilUtil::sendInfo($this->lng->txt("select_target_position_for_move_question"));
1229  $this->questionsObject();
1230  }
1231  }
1232 
1236  public function insertQuestions($insert_mode)
1237  {
1238  // get all questions to move
1239  $move_questions = $_SESSION["move_questions"];
1240  // get insert point
1241  $insert_id = -1;
1242  foreach ($_POST as $key => $value)
1243  {
1244  if (preg_match("/^cb_(\d+)$/", $key, $matches))
1245  {
1246  if ($insert_id < 0)
1247  {
1248  $insert_id = $matches[1];
1249  }
1250  }
1251  if (preg_match("/^cb_qb_(\d+)$/", $key, $matches))
1252  {
1253  if ($insert_id < 0)
1254  {
1255  $ids =& $this->object->getQuestionblockQuestionIds($matches[1]);
1256  if (count($ids))
1257  {
1258  if ($insert_mode == 0)
1259  {
1260  $insert_id = $ids[0];
1261  }
1262  else if ($insert_mode == 1)
1263  {
1264  $insert_id = $ids[count($ids)-1];
1265  }
1266  }
1267  }
1268  }
1269  }
1270  if ($insert_id <= 0)
1271  {
1272  ilUtil::sendInfo($this->lng->txt("no_target_selected_for_move"), true);
1273  }
1274  else
1275  {
1276  ilUtil::sendSuccess($this->lng->txt('msg_obj_modified'), true);
1277  $this->object->moveQuestions($move_questions, $insert_id, $insert_mode);
1278  }
1279  unset($_SESSION["move_questions"]);
1280  $this->ctrl->redirect($this, "questions");
1281  }
1282 
1287  {
1288  $this->insertQuestions(0);
1289  }
1290 
1294  public function insertQuestionsAfterObject()
1295  {
1296  $this->insertQuestions(1);
1297  }
1298 
1302  public function saveObligatoryObject()
1303  {
1304  $obligatory = array();
1305  foreach ($_POST as $key => $value)
1306  {
1307  if (preg_match("/obligatory_(\d+)/", $key, $matches))
1308  {
1309  $obligatory[$matches[1]] = 1;
1310  }
1311  }
1312  $this->object->setObligatoryStates($obligatory);
1313  ilUtil::sendSuccess($this->lng->txt('msg_obj_modified'), true);
1314  $this->ctrl->redirect($this, "questions");
1315  }
1316 
1320  public function questionsObject()
1321  {
1322  $this->handleWriteAccess();
1323  global $rbacsystem;
1324 
1325  $hasDatasets = $this->object->_hasDatasets($this->object->getSurveyId());
1326  include_once "./Services/Utilities/classes/class.ilUtil.php";
1327  if ((!$rbacsystem->checkAccess("read", $this->ref_id)) && (!$rbacsystem->checkAccess("write", $this->ref_id)))
1328  {
1329  // allow only read and write access
1330  ilUtil::sendInfo($this->lng->txt("cannot_edit_survey"), true);
1331  $path = $this->tree->getPathFull($this->object->getRefID());
1332  ilUtil::redirect($this->getReturnLocation("cancel","./repository.php?cmd=frameset&ref_id=" . $path[count($path) - 2]["child"]));
1333  return;
1334  }
1335 
1336  if ($_GET["new_id"] > 0)
1337  {
1338  // add a question to the survey previous created in a questionpool
1339  $existing = $this->object->getExistingQuestions();
1340  if (!in_array($_GET["new_id"], $existing))
1341  {
1342  $inserted = $this->object->insertQuestion($_GET["new_id"]);
1343  if (!$inserted)
1344  {
1345  ilUtil::sendFailure($this->lng->txt("survey_error_insert_incomplete_question"));
1346  }
1347  }
1348  }
1349 
1350  if ($_GET["eqid"] and $_GET["eqpl"])
1351  {
1352  ilUtil::redirect("ilias.php?baseClass=ilObjSurveyQuestionPoolGUI&ref_id=" . $_GET["eqpl"] . "&cmd=editQuestionForSurvey&calling_survey=".$_GET["ref_id"]."&q_id=" . $_GET["eqid"]);
1353  }
1354 
1355 
1356  $_SESSION["calling_survey"] = $this->object->getRefId();
1357  unset($_SESSION["survey_id"]);
1358 
1359  if ($_GET["editheading"])
1360  {
1361  $this->addHeadingObject($_GET["editheading"]);
1362  return;
1363  }
1364 
1365  if ($_GET["up"] > 0)
1366  {
1367  $this->object->moveUpQuestion($_GET["up"]);
1368  ilUtil::sendSuccess($this->lng->txt('msg_obj_modified'));
1369  }
1370  if ($_GET["down"] > 0)
1371  {
1372  $this->object->moveDownQuestion($_GET["down"]);
1373  ilUtil::sendSuccess($this->lng->txt('msg_obj_modified'));
1374  }
1375  if ($_GET["qbup"] > 0)
1376  {
1377  $this->object->moveUpQuestionblock($_GET["qbup"]);
1378  ilUtil::sendSuccess($this->lng->txt('msg_obj_modified'));
1379  }
1380  if ($_GET["qbdown"] > 0)
1381  {
1382  $this->object->moveDownQuestionblock($_GET["qbdown"]);
1383  ilUtil::sendSuccess($this->lng->txt('msg_obj_modified'));
1384  }
1385 
1386  if ($_GET["removeheading"])
1387  {
1388  $this->confirmRemoveHeadingForm();
1389  return;
1390  }
1391 
1392  if ($_GET["editblock"])
1393  {
1394  $this->defineQuestionblock($_GET["editblock"]);
1395  return;
1396  }
1397 
1398  if ($_GET["add"])
1399  {
1400  // called after a new question was created from a questionpool
1401  $selected_array = array();
1402  array_push($selected_array, $_GET["add"]);
1403  ilUtil::sendQuestion($this->lng->txt("ask_insert_questions"));
1404  $this->insertQuestionsForm($selected_array);
1405  return;
1406  }
1407 
1408  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_svy_questions.html", "Modules/Survey");
1409  $survey_questions =& $this->object->getSurveyQuestions();
1410  $questionpools =& $this->object->getQuestionpoolTitles();
1411  $colors = array("tblrow1", "tblrow2");
1412  $counter = 0;
1413  $title_counter = 0;
1414  $last_color_class = "";
1415  $obligatory = "<img src=\"" . ilUtil::getImagePath("obligatory.gif", "Modules/Survey") . "\" alt=\"" . $this->lng->txt("question_obligatory") . "\" title=\"" . $this->lng->txt("question_obligatory") . "\" />";
1416  include_once "./Modules/SurveyQuestionPool/classes/class.ilObjSurveyQuestionPool.php";
1417  $questiontypes =& ilObjSurveyQuestionPool::_getQuestiontypes();
1418  if (count($survey_questions) > 0)
1419  {
1420  foreach ($survey_questions as $question_id => $data)
1421  {
1422  $title_counter++;
1423  if (($last_questionblock_id > 0) && ($data["questionblock_id"] == 0))
1424  {
1425  $counter++;
1426  }
1427  if (($last_questionblock_id > 0) && ($data["questionblock_id"] > 0) && ($data["questionblock_id"] != $last_questionblock_id))
1428  {
1429  $counter++;
1430  }
1431  if (($data["questionblock_id"] > 0) and ($data["questionblock_id"] != $last_questionblock_id))
1432  {
1433  // add a separator line for the beginning of a question block
1434  $this->tpl->setCurrentBlock("separator");
1435  $this->tpl->setVariable("COLOR_CLASS", $colors[$counter % 2]);
1436  $this->tpl->parseCurrentBlock();
1437  $this->tpl->setCurrentBlock("QTab");
1438  $this->tpl->setVariable("COLOR_CLASS", $colors[$counter % 2]);
1439  $this->tpl->parseCurrentBlock();
1440 
1441  $this->tpl->setCurrentBlock("block");
1442  $this->tpl->setVariable("TYPE_ICON", "<img src=\"" . ilUtil::getImagePath("questionblock.gif", "Modules/Survey") . "\" alt=\"".$this->lng->txt("questionblock_icon")."\" />");
1443  $this->tpl->setVariable("TEXT_QUESTIONBLOCK", $this->lng->txt("questionblock") . ": " . $data["questionblock_title"]);
1444  $this->tpl->setVariable("COLOR_CLASS", $colors[$counter % 2]);
1445  if ($rbacsystem->checkAccess("write", $this->ref_id) and !$hasDatasets)
1446  {
1447  if ($data["question_id"] != $this->object->questions[0])
1448  {
1449  $this->tpl->setVariable("BUTTON_UP", "<a href=\"" . $this->ctrl->getLinkTarget($this, "questions") . "&qbup=" . $data["questionblock_id"] . "\"><img src=\"" . ilUtil::getImagePath("a_up.gif") . "\" alt=\"" . $this->lng->txt("up") . "\" title=\"" . $this->lng->txt("up") . "\" border=\"0\" /></a>");
1450  }
1451  $akeys = array_keys($survey_questions);
1452  if ($data["questionblock_id"] != $survey_questions[$akeys[count($akeys)-1]]["questionblock_id"])
1453  {
1454  $this->tpl->setVariable("BUTTON_DOWN", "<a href=\"" . $this->ctrl->getLinkTarget($this, "questions") . "&qbdown=" . $data["questionblock_id"] . "\"><img src=\"" . ilUtil::getImagePath("a_down.gif") . "\" alt=\"" . $this->lng->txt("down") . "\" title=\"" . $this->lng->txt("down") . "\" border=\"0\" /></a>");
1455  }
1456  $this->tpl->setVariable("TEXT_EDIT", $this->lng->txt("edit"));
1457  $this->tpl->setVariable("HREF_EDIT", $this->ctrl->getLinkTarget($this, "questions") . "&editblock=" . $data["questionblock_id"]);
1458  }
1459  $this->tpl->parseCurrentBlock();
1460  $this->tpl->setCurrentBlock("QTab");
1461  $this->tpl->setVariable("QUESTION_ID", "qb_" . $data["questionblock_id"]);
1462  $this->tpl->setVariable("COLOR_CLASS", $colors[$counter % 2]);
1463  $this->tpl->parseCurrentBlock();
1464  }
1465  if (($last_questionblock_id > 0) && ($data["questionblock_id"] == 0))
1466  {
1467  // add a separator line for the end of a question block
1468  $this->tpl->setCurrentBlock("separator");
1469  $this->tpl->setVariable("COLOR_CLASS", $colors[$counter % 2]);
1470  $this->tpl->parseCurrentBlock();
1471  $this->tpl->setCurrentBlock("QTab");
1472  $this->tpl->setVariable("COLOR_CLASS", $colors[$counter % 2]);
1473  $this->tpl->parseCurrentBlock();
1474  }
1475  if ($data["heading"])
1476  {
1477  $this->tpl->setCurrentBlock("heading");
1478  $this->tpl->setVariable("TEXT_HEADING", $data["heading"]);
1479  $this->tpl->setVariable("COLOR_CLASS", $colors[$counter % 2]);
1480  if ($rbacsystem->checkAccess("write", $this->ref_id) and !$hasDatasets)
1481  {
1482  $this->tpl->setVariable("TEXT_EDIT", $this->lng->txt("edit"));
1483  $this->tpl->setVariable("HREF_EDIT", $this->ctrl->getLinkTarget($this, "questions") . "&editheading=" . $data["question_id"]);
1484  $this->tpl->setVariable("TEXT_DELETE", $this->lng->txt("remove"));
1485  $this->tpl->setVariable("HREF_DELETE", $this->ctrl->getLinkTarget($this, "questions") . "&removeheading=" . $data["question_id"]);
1486  }
1487  $this->tpl->parseCurrentBlock();
1488  $this->tpl->setCurrentBlock("QTab");
1489  $this->tpl->setVariable("COLOR_CLASS", $colors[$counter % 2]);
1490  $this->tpl->parseCurrentBlock();
1491  }
1492  if (!$data["questionblock_id"])
1493  {
1494  $this->tpl->setCurrentBlock("checkable");
1495  $this->tpl->setVariable("QUESTION_ID", $data["question_id"]);
1496  $this->tpl->parseCurrentBlock();
1497  }
1498  $this->tpl->setCurrentBlock("QTab");
1499  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
1500  if ($rbacsystem->checkAccess("write", $this->ref_id) and !$hasDatasets)
1501  {
1502  $q_id = $data["question_id"];
1503  $qpl_ref_id = current(ilObject::_getAllReferences($data["obj_fi"]));
1504  $this->tpl->setVariable("QUESTION_TITLE", "$title_counter. <a href=\"" . $this->ctrl->getLinkTarget($this, "questions") . "&eqid=$q_id&eqpl=$qpl_ref_id" . "\">" . $data["title"] . "</a>");
1505  }
1506  else
1507  {
1508  $this->tpl->setVariable("QUESTION_TITLE", "$title_counter. ". $data["title"]);
1509  }
1510  $this->tpl->setVariable("TYPE_ICON", "<img src=\"" . ilUtil::getImagePath("question.gif", "Modules/Survey") . "\" alt=\"".$this->lng->txt("question_icon")."\" />");
1511  if ($rbacsystem->checkAccess("write", $this->ref_id) and !$hasDatasets)
1512  {
1513  $obligatory_checked = "";
1514  if ($data["obligatory"] == 1)
1515  {
1516  $obligatory_checked = " checked=\"checked\"";
1517  }
1518  $this->tpl->setVariable("QUESTION_OBLIGATORY", "<input type=\"checkbox\" name=\"obligatory_" . $data["question_id"] . "\" value=\"1\"$obligatory_checked />");
1519  }
1520  else
1521  {
1522  if ($data["obligatory"] == 1)
1523  {
1524  $this->tpl->setVariable("QUESTION_OBLIGATORY", $obligatory);
1525  }
1526  }
1527  $this->tpl->setVariable("QUESTION_COMMENT", $data["description"]);
1528  if ($rbacsystem->checkAccess("write", $this->ref_id) and !$hasDatasets)
1529  {
1530  if (!$data["questionblock_id"])
1531  {
1532  // up/down buttons for non-questionblock questions
1533  if ($data["question_id"] != $this->object->questions[0])
1534  {
1535  $this->tpl->setVariable("BUTTON_UP", "<a href=\"" . $this->ctrl->getLinkTarget($this, "questions") . "&up=" . $data["question_id"] . "\"><img src=\"" . ilUtil::getImagePath("a_up.gif") . "\" alt=\"".$this->lng->txt("up")."\" border=\"0\" /></a>");
1536  }
1537  if ($data["question_id"] != $this->object->questions[count($this->object->questions)-1])
1538  {
1539  $this->tpl->setVariable("BUTTON_DOWN", "<a href=\"" . $this->ctrl->getLinkTarget($this, "questions") . "&down=" . $data["question_id"] . "\"><img src=\"" . ilUtil::getImagePath("a_down.gif") . "\" alt=\"".$this->lng->txt("down")."\" border=\"0\" /></a>");
1540  }
1541  }
1542  else
1543  {
1544  // up/down buttons for questionblock questions
1545  if ($data["questionblock_id"] == $last_questionblock_id)
1546  {
1547  $this->tpl->setVariable("BUTTON_UP", "<a href=\"" . $this->ctrl->getLinkTarget($this, "questions") . "&up=" . $data["question_id"] . "\"><img src=\"" . ilUtil::getImagePath("a_up.gif") . "\" alt=\"".$this->lng->txt("up")."\" border=\"0\" /></a>");
1548  }
1549  $tmp_questions = array_keys($survey_questions);
1550  $blockkey = array_search($question_id, $tmp_questions);
1551  if (($blockkey !== FALSE) && ($blockkey < count($tmp_questions)-1))
1552  {
1553  if ($data["questionblock_id"] == $survey_questions[$tmp_questions[$blockkey+1]]["questionblock_id"])
1554  {
1555  $this->tpl->setVariable("BUTTON_DOWN", "<a href=\"" . $this->ctrl->getLinkTarget($this, "questions") . "&down=" . $data["question_id"] . "\"><img src=\"" . ilUtil::getImagePath("a_down.gif") . "\" alt=\"".$this->lng->txt("down")."\" border=\"0\" /></a>");
1556  }
1557  }
1558  }
1559  }
1560  foreach ($questiontypes as $trans => $typedata)
1561  {
1562  if (strcmp($typedata["type_tag"], $data["type_tag"]) == 0)
1563  {
1564  $this->tpl->setVariable("QUESTION_TYPE", $trans);
1565  }
1566  }
1567  $this->tpl->setVariable("QUESTION_AUTHOR", $data["author"]);
1568  $this->tpl->setVariable("COLOR_CLASS", $colors[$counter % 2]);
1569  $last_color_class = $colors[$counter % 2];
1570  if (!$data["questionblock_id"])
1571  {
1572  $counter++;
1573  }
1574  $this->tpl->parseCurrentBlock();
1575  $last_questionblock_id = $data["questionblock_id"];
1576  }
1577 
1578  if ($rbacsystem->checkAccess("write", $this->ref_id) and !$hasDatasets)
1579  {
1580  $this->tpl->setCurrentBlock("selectall");
1581  $this->tpl->setVariable("SELECT_ALL", $this->lng->txt("select_all"));
1582  $this->tpl->setVariable("COLOR_CLASS", $last_color_class);
1583  $this->tpl->parseCurrentBlock();
1584  if (array_key_exists("move_questions", $_SESSION))
1585  {
1586  $this->tpl->setCurrentBlock("move_buttons");
1587  $this->tpl->setVariable("INSERT_BEFORE", $this->lng->txt("insert_before"));
1588  $this->tpl->setVariable("INSERT_AFTER", $this->lng->txt("insert_after"));
1589  $this->tpl->parseCurrentBlock();
1590  }
1591  $this->tpl->setCurrentBlock("QFooter");
1592  $this->tpl->setVariable("ARROW", "<img src=\"" . ilUtil::getImagePath("arrow_downright.gif") . "\" alt=\"".$this->lng->txt("arrow_downright")."\">");
1593  $this->tpl->setVariable("REMOVE", $this->lng->txt("remove_question"));
1594  $this->tpl->setVariable("MOVE", $this->lng->txt("move"));
1595  $this->tpl->setVariable("QUESTIONBLOCK", $this->lng->txt("define_questionblock"));
1596  $this->tpl->setVariable("UNFOLD", $this->lng->txt("unfold"));
1597  $this->tpl->setVariable("SAVE", $this->lng->txt("save_obligatory_state"));
1598  $this->tpl->parseCurrentBlock();
1599  }
1600  }
1601  else
1602  {
1603  $this->tpl->setCurrentBlock("Emptytable");
1604  $this->tpl->setVariable("TEXT_EMPTYTABLE", $this->lng->txt("no_questions_available"));
1605  $this->tpl->parseCurrentBlock();
1606  }
1607  if (($last_questionblock_id > 0))
1608  {
1609  // add a separator line for the end of a question block (if the last question is a questionblock question)
1610  $this->tpl->setCurrentBlock("separator");
1611  $this->tpl->setVariable("COLOR_CLASS", $colors[$counter % 2]);
1612  $this->tpl->parseCurrentBlock();
1613  $this->tpl->setCurrentBlock("QTab");
1614  $this->tpl->setVariable("COLOR_CLASS", $colors[$counter % 2]);
1615  $this->tpl->parseCurrentBlock();
1616  }
1617 
1618  if ($rbacsystem->checkAccess("write", $this->ref_id) and !$hasDatasets)
1619  {
1620  $this->tpl->setCurrentBlock("QTypes");
1621  include_once "./Modules/SurveyQuestionPool/classes/class.ilObjSurveyQuestionPool.php";
1623  foreach ($qtypes as $translation => $data)
1624  {
1625  $this->tpl->setVariable("QUESTION_TYPE_ID", $data["type_tag"]);
1626  $this->tpl->setVariable("QUESTION_TYPE", $translation);
1627  $this->tpl->parseCurrentBlock();
1628  }
1629  $this->tpl->parseCurrentBlock();
1630  }
1631  $this->tpl->setCurrentBlock("adm_content");
1632  $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this, "questions"));
1633  $this->tpl->setVariable("QUESTION_TITLE", $this->lng->txt("title"));
1634  $this->tpl->setVariable("QUESTION_COMMENT", $this->lng->txt("description"));
1635  $this->tpl->setVariable("QUESTION_OBLIGATORY", $this->lng->txt("obligatory"));
1636  $this->tpl->setVariable("QUESTION_SEQUENCE", $this->lng->txt("sequence"));
1637  $this->tpl->setVariable("QUESTION_TYPE", $this->lng->txt("question_type"));
1638  $this->tpl->setVariable("QUESTION_AUTHOR", $this->lng->txt("author"));
1639 
1640  if ($rbacsystem->checkAccess("write", $this->ref_id) and !$hasDatasets)
1641  {
1642  $this->tpl->setVariable("BUTTON_INSERT_QUESTION", $this->lng->txt("browse_for_questions"));
1643  global $ilUser;
1644  $this->tpl->setVariable('BROWSE_COMMAND', ($ilUser->getPref('svy_insert_type') == 1 || strlen($ilUser->getPref('svy_insert_type')) == 0) ? 'browseForQuestions' : 'browseForQuestionblocks');
1645  $this->tpl->setVariable("TEXT_CREATE_NEW", " " . strtolower($this->lng->txt("or")) . " " . $this->lng->txt("create_new"));
1646  $this->tpl->setVariable("BUTTON_CREATE_QUESTION", $this->lng->txt("create"));
1647  $this->tpl->setVariable("HEADING", $this->lng->txt("add_heading"));
1648  }
1649  if ($hasDatasets)
1650  {
1651  ilUtil::sendInfo($this->lng->txt("survey_has_datasets_warning"));
1652  }
1653 
1654  $this->tpl->parseCurrentBlock();
1655  $this->questionsSubtabs("questions");
1656  }
1657 
1665  function evaluationObject()
1666  {
1667  include_once("./Modules/Survey/classes/class.ilSurveyEvaluationGUI.php");
1668  $eval_gui = new ilSurveyEvaluationGUI($this->object);
1669  $this->ctrl->setCmdClass(get_class($eval_gui));
1670  $this->ctrl->redirect($eval_gui, "evaluation");
1671  }
1672 
1676  public function searchInvitationObject()
1677  {
1678  $this->inviteObject();
1679  }
1680 
1684  public function disinviteUserGroupObject()
1685  {
1686  // disinvite users
1687  if (is_array($_POST["user_select"]))
1688  {
1689  foreach ($_POST["user_select"] as $user_id)
1690  {
1691  $this->object->disinviteUser($user_id);
1692  }
1693  }
1694  ilUtil::sendSuccess($this->lng->txt('msg_users_disinvited'), true);
1695  $this->ctrl->redirect($this, "invite");
1696  }
1697 
1701  public function inviteUserGroupObject()
1702  {
1703  $invited = 0;
1704  // add users to invitation
1705  if (is_array($_POST["user_select"]))
1706  {
1707  foreach ($_POST["user_select"] as $user_id)
1708  {
1709  $this->object->inviteUser($user_id);
1710  $invited++;
1711  }
1712  }
1713  // add groups to invitation
1714  if (is_array($_POST["group_select"]))
1715  {
1716  foreach ($_POST["group_select"] as $group_id)
1717  {
1718  $invited += $this->object->inviteGroup($group_id);
1719  }
1720  }
1721  // add roles to invitation
1722  if (is_array($_POST["role_select"]))
1723  {
1724  foreach ($_POST["role_select"] as $role_id)
1725  {
1726  $invited += $this->object->inviteRole($role_id);
1727  }
1728  }
1729  if ($invited == 0)
1730  {
1731  ilUtil::sendFailure($this->lng->txt('no_user_invited'), TRUE);
1732  }
1733  else
1734  {
1735  ilUtil::sendSuccess(sprintf($this->lng->txt('users_invited'), $invited), TRUE);
1736  }
1737  $this->ctrl->redirect($this, "invite");
1738  }
1739 
1743  public function saveInvitationStatusObject()
1744  {
1745  $mode = $_POST['invitation'];
1746  switch ($mode)
1747  {
1748  case 0:
1749  $this->object->setInvitation(0);
1750  break;
1751  case 1:
1752  $this->object->setInvitation(1);
1753  $this->object->setInvitationMode(0);
1754  break;
1755  case 2:
1756  $this->object->setInvitation(1);
1757  $this->object->setInvitationMode(1);
1758  break;
1759  }
1760  $this->object->saveToDb();
1761  ilUtil::sendSuccess($this->lng->txt('msg_obj_modified'), true);
1762  $this->ctrl->redirect($this, "invite");
1763  }
1764 
1765 
1769  public function inviteObject()
1770  {
1771  global $ilAccess;
1772  global $rbacsystem;
1773 
1774  if ((!$rbacsystem->checkAccess("visible,invite", $this->ref_id)) && (!$rbacsystem->checkAccess("write", $this->ref_id)))
1775  {
1776  // allow only read and write access
1777  ilUtil::sendInfo($this->lng->txt("cannot_edit_survey"), true);
1778  $path = $this->tree->getPathFull($this->object->getRefID());
1779  include_once "./Services/Utilities/classes/class.ilUtil.php";
1780  ilUtil::redirect($this->getReturnLocation("cancel","./repository.php?cmd=frameset&ref_id=" . $path[count($path) - 2]["child"]));
1781  return;
1782  }
1783 
1784  if ($this->object->getStatus() == STATUS_OFFLINE)
1785  {
1786  ilUtil::sendInfo($this->lng->txt("survey_offline_message"));
1787  return;
1788  }
1789 
1790  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
1791  $form = new ilPropertyFormGUI();
1792  $form->setFormAction($this->ctrl->getFormAction($this));
1793  $form->setTableWidth("500");
1794  $form->setId("invite");
1795 
1796  // invitation
1797  $header = new ilFormSectionHeaderGUI();
1798  $header->setTitle($this->lng->txt("invitation"));
1799  $form->addItem($header);
1800 
1801  // invitation mode
1802  $invitation = new ilRadioGroupInputGUI($this->lng->txt('invitation_mode'), "invitation");
1803  $invitation->setInfo($this->lng->txt('invitation_mode_desc'));
1804  $invitation->addOption(new ilRadioOption($this->lng->txt("invitation_off"), 0, ''));
1805  $surveySetting = new ilSetting("survey");
1806  if ($surveySetting->get("unlimited_invitation"))
1807  {
1808  $invitation->addOption(new ilRadioOption($this->lng->txt("unlimited_users"), 1, ''));
1809  }
1810  $invitation->addOption(new ilRadioOption($this->lng->txt("predefined_users"), 2, ''));
1811  $inv = 0;
1812  if ($this->object->getInvitation())
1813  {
1814  $inv = $this->object->getInvitationMode() + 1;
1815  }
1816  $invitation->setValue($inv);
1817  $form->addItem($invitation);
1818 
1819  $form->addCommandButton("saveInvitationStatus", $this->lng->txt("save"));
1820 
1821  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_svy_invite.html", "Modules/Survey");
1822  $this->tpl->setVariable("INVITATION_TABLE", $form->getHTML());
1823 
1824  if ($this->object->getInvitation() && $this->object->getInvitationMode() == 1)
1825  {
1826  $searchform = new ilPropertyFormGUI();
1827  $searchform->setFormAction($this->ctrl->getFormAction($this));
1828  $searchform->setTableWidth("500");
1829  $searchform->setId("search");
1830 
1831  // search form
1832  $header = new ilFormSectionHeaderGUI();
1833  $header->setTitle($this->lng->txt("search_invitation"));
1834  $searchform->addItem($header);
1835 
1836  $param_search_term = (strlen($_POST['search_term'])) ? $_POST['search_term'] : $_GET['search_term'];
1837  $param_concatenation = (strlen($_POST['concatenation'])) ? $_POST['concatenation'] : $_GET['concatenation'];
1838  if (is_array($_POST['search_for']))
1839  {
1840  $param_search_for = $_POST['search_for'];
1841  }
1842  else
1843  {
1844  $param_search_for = array();
1845  foreach ($_GET as $key => $value)
1846  {
1847  if (preg_match("/search_for_(\d+)/is", $key, $matches))
1848  {
1849  array_push($param_search_for, $value);
1850  }
1851  }
1852  }
1853 
1854  // search term
1855  $search_term = new ilTextInputGUI($this->lng->txt('search_term'), "search_term");
1856  if (strlen($param_search_term)) $search_term->setValue($param_search_term);
1857  $searchform->addItem($search_term);
1858 
1859  // concatenation
1860  $concatenation = new ilRadioGroupInputGUI($this->lng->txt('concatenation'), "concatenation");
1861  $concatenation->addOption(new ilRadioOption($this->lng->txt("or"), 'or', ''));
1862  $concatenation->addOption(new ilRadioOption($this->lng->txt("and"), 'and', ''));
1863  $concatenation->setValue((strlen($param_concatenation)) ? $param_concatenation : 'or');
1864  $searchform->addItem($concatenation);
1865 
1866  // search for
1867  $search_for = new ilCheckboxGroupInputGUI($this->lng->txt('search_for'), "search_for");
1868  $search_for->addOption(new ilCheckboxOption($this->lng->txt("objs_usr"), 'usr', ''));
1869  $search_for->addOption(new ilCheckboxOption($this->lng->txt("objs_grp"), 'grp', ''));
1870  $search_for->addOption(new ilCheckboxOption($this->lng->txt("objs_role"), 'role', ''));
1871  $search_for->setValue((is_array($param_search_for)) ? $param_search_for : array('usr'));
1872  $searchform->addItem($search_for);
1873 
1874  $searchform->addCommandButton("searchInvitation", $this->lng->txt("search"));
1875  $this->tpl->setVariable("ADM_CONTENT", $form->getHTML());
1876 
1877  $this->tpl->setVariable("SEARCH_TABLE", $searchform->getHTML());
1878 
1879  $invited_users = $this->object->getUserData($this->object->getInvitedUsers());
1880  include_once "./Modules/Survey/classes/tables/class.ilSurveyInvitedUsersTableGUI.php";
1881  $table_gui = new ilSurveyInvitedUsersTableGUI($this, 'invite');
1882  $table_gui->setData($invited_users);
1883  $this->tpl->setVariable('TBL_INVITED_USERS', $table_gui->getHTML());
1884 
1885  }
1886 
1887  $concat = ($param_concatenation) ? $param_concatenation : "or";
1888  $searchfor = ($param_search_for) ? $param_search_for : array("usr");
1889  if (strcmp($this->ctrl->getCmd(), "searchInvitation") == 0 || strlen($_GET['searchInvitation']))
1890  {
1891  $this->ctrl->setParameter($this, 'search_term', $param_search_term);
1892  $this->ctrl->setParameter($this, 'concatenation', $param_concatenation);
1893  $c = 0;
1894  foreach ($searchfor as $param)
1895  {
1896  $this->ctrl->setParameter($this, 'search_for_' . $c, $param);
1897  $c++;
1898  }
1899  $this->ctrl->setParameter($this, 'searchInvitation', 1);
1900 
1901  if (is_array($param_search_for))
1902  {
1903  if (in_array("usr", $searchfor) or in_array("grp", $searchfor) or in_array("role", $searchfor))
1904  {
1905  include_once "./classes/class.ilSearch.php";
1906  $search =& new ilSearch($ilUser->id);
1907  $search->setSearchString($param_search_term);
1908  $search->setCombination($concat);
1909  $search->setSearchFor($searchfor);
1910  $search->setSearchType("new");
1911  if($search->validate($message))
1912  {
1913  $search->performSearch();
1914  }
1915  if ($message)
1916  {
1917  ilUtil::sendInfo($message);
1918  }
1919  if(!$search->getNumberOfResults() && $search->getSearchFor())
1920  {
1921  ilUtil::sendFailure($this->lng->txt("search_no_match"));
1922  }
1923 
1924  if ($searchresult = $search->getResultByType("usr"))
1925  {
1926  $found = array();
1927  foreach ($searchresult as $res)
1928  {
1929  array_push($found, $res['id']);
1930  }
1931  $users = $this->object->getUserData($found);
1932  include_once "./Modules/Survey/classes/tables/class.ilSurveyInviteUsersTableGUI.php";
1933  $table_gui = new ilSurveyInviteUsersTableGUI($this, 'invite');
1934  $table_gui->setData($users);
1935  $this->tpl->setVariable('TBL_USER_RESULT', $table_gui->getHTML());
1936  }
1937  $searchresult = array();
1938  if ($searchresult = $search->getResultByType("grp"))
1939  {
1940  $found = array();
1941  foreach ($searchresult as $res)
1942  {
1943  array_push($found, $res['id']);
1944  }
1945  $groups = $this->object->getGroupData($found);
1946  include_once "./Modules/Survey/classes/tables/class.ilSurveyInviteGroupsTableGUI.php";
1947  $table_gui = new ilSurveyInviteGroupsTableGUI($this, 'invite');
1948  $table_gui->setData($groups);
1949  $this->tpl->setVariable('TBL_GROUP_RESULT', $table_gui->getHTML());
1950  }
1951  $searchresult = array();
1952  if ($searchresult = $search->getResultByType("role"))
1953  {
1954  $found = array();
1955  foreach ($searchresult as $res)
1956  {
1957  array_push($found, $res['id']);
1958  }
1959  $roles = $this->object->getRoleData($found);
1960  if (count($roles))
1961  {
1962  include_once "./Modules/Survey/classes/tables/class.ilSurveyInviteRolesTableGUI.php";
1963  $table_gui = new ilSurveyInviteRolesTableGUI($this, 'invite');
1964  $table_gui->setData($roles);
1965  $this->tpl->setVariable('TBL_ROLE_RESULT', $table_gui->getHTML());
1966  }
1967  }
1968  }
1969  }
1970  else
1971  {
1972  ilUtil::sendInfo($this->lng->txt("no_user_or_group_selected"));
1973  }
1974  }
1975  }
1976 
1980  public function deleteAllUserDataObject()
1981  {
1982  ilUtil::sendQuestion($this->lng->txt("confirm_delete_all_user_data"));
1983  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_svy_maintenance.html", "Modules/Survey");
1984  $this->tpl->setCurrentBlock("adm_content");
1985  $this->tpl->setVariable("BTN_CONFIRM_DELETE_ALL", $this->lng->txt("confirm"));
1986  $this->tpl->setVariable("BTN_CANCEL_DELETE_ALL", $this->lng->txt("cancel"));
1987  $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this, "deleteAllUserData"));
1988  $this->tpl->parseCurrentBlock();
1989  }
1990 
1995  {
1996  $this->object->deleteAllUserData();
1997  ilUtil::sendSuccess($this->lng->txt("svy_all_user_data_deleted"), true);
1998  $this->ctrl->redirect($this, "maintenance");
1999  }
2000 
2005  {
2006  $this->ctrl->redirect($this, "maintenance");
2007  }
2008 
2013  {
2014  $this->object->removeSelectedSurveyResults($_POST["chbUser"]);
2015  ilUtil::sendSuccess($this->lng->txt("svy_selected_user_data_deleted"), true);
2016  $this->ctrl->redirect($this, "maintenance");
2017  }
2018 
2023  {
2024  ilUtil::sendInfo($this->lng->txt('msg_cancel'), true);
2025  $this->ctrl->redirect($this, "maintenance");
2026  }
2027 
2032  {
2033  $this->handleWriteAccess();
2034 
2035  if (count($_POST["chbUser"]) == 0)
2036  {
2037  ilUtil::sendInfo($this->lng->txt('no_checkbox'), true);
2038  $this->ctrl->redirect($this, "maintenance");
2039  }
2040 
2041  ilUtil::sendQuestion($this->lng->txt("confirm_delete_single_user_data"));
2042  include_once "./Modules/Survey/classes/tables/class.ilSurveyMaintenanceTableGUI.php";
2043  $table_gui = new ilSurveyMaintenanceTableGUI($this, 'maintenance', true);
2044  $total =& $this->object->getSurveyParticipants();
2045  $data = array();
2046  foreach ($total as $user_data)
2047  {
2048  if (in_array($user_data['active_id'], $_POST['chbUser']))
2049  {
2050  $last_access = $this->object->_getLastAccess($user_data["active_id"]);
2051  array_push($data, array(
2052  'id' => $user_data["active_id"],
2053  'name' => $user_data["sortname"],
2054  'login' => $user_data["login"],
2055  'last_access' => ilDatePresentation::formatDate(new ilDateTime($last_access,IL_CAL_UNIX))
2056  ));
2057  }
2058  }
2059  $table_gui->setData($data);
2060  $this->tpl->setVariable('ADM_CONTENT', $table_gui->getHTML());
2061  }
2062 
2066  public function maintenanceObject()
2067  {
2068  $this->handleWriteAccess();
2069 
2070  if ($_GET["fill"] > 0)
2071  {
2072  for ($i = 0; $i < $_GET["fill"]; $i++) $this->object->fillSurveyForUser();
2073  }
2074  include_once "./Modules/Survey/classes/tables/class.ilSurveyMaintenanceTableGUI.php";
2075  $table_gui = new ilSurveyMaintenanceTableGUI($this, 'maintenance');
2076  $total =& $this->object->getSurveyParticipants();
2077  $data = array();
2078  foreach ($total as $user_data)
2079  {
2080  $last_access = $this->object->_getLastAccess($user_data["active_id"]);
2081  array_push($data, array(
2082  'id' => $user_data["active_id"],
2083  'name' => $user_data["sortname"],
2084  'login' => $user_data["login"],
2085  'last_access' => ilDatePresentation::formatDate(new ilDateTime($last_access,IL_CAL_UNIX))
2086  ));
2087  }
2088  $table_gui->setData($data);
2089  $this->tpl->setVariable('ADM_CONTENT', $table_gui->getHTML());
2090  }
2091 
2097  function importObject()
2098  {
2099  $this->getTemplateFile("import", "svy");
2100  $this->tpl->setCurrentBlock("option_qpl");
2101  include_once("./Modules/Survey/classes/class.ilObjSurvey.php");
2102  $svy = new ilObjSurvey();
2103  $questionpools =& $svy->getAvailableQuestionpools(TRUE, FALSE, TRUE);
2104  if (count($questionpools) == 0)
2105  {
2106  }
2107  else
2108  {
2109  foreach ($questionpools as $key => $value)
2110  {
2111  $this->tpl->setCurrentBlock("option_spl");
2112  $this->tpl->setVariable("OPTION_VALUE", $key);
2113  $this->tpl->setVariable("TXT_OPTION", $value);
2114  $this->tpl->parseCurrentBlock();
2115  }
2116  }
2117  $this->tpl->setVariable("TXT_SELECT_QUESTIONPOOL", $this->lng->txt("select_questionpool"));
2118  $this->tpl->setVariable("OPTION_SELECT_QUESTIONPOOL", $this->lng->txt("select_questionpool_option"));
2119  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this, "import"));
2120  $this->tpl->setVariable("BTN_NAME", "upload");
2121  $this->tpl->setVariable("TXT_UPLOAD", $this->lng->txt("upload"));
2122  $this->tpl->setVariable("TXT_IMPORT_TST", $this->lng->txt("import_tst"));
2123  $this->tpl->setVariable("TXT_SELECT_MODE", $this->lng->txt("select_mode"));
2124  $this->tpl->setVariable("TXT_SELECT_FILE", $this->lng->txt("select_file"));
2125 
2126  }
2127 
2134  function uploadObject($redirect = true)
2135  {
2136  if ($_POST["spl"] < 1)
2137  {
2138  ilUtil::sendInfo($this->lng->txt("svy_select_questionpools"));
2139  $this->importObject();
2140  return;
2141  }
2142  if (strcmp($_FILES["xmldoc"]["tmp_name"], "") == 0)
2143  {
2144  ilUtil::sendInfo($this->lng->txt("svy_select_file_for_import"));
2145  $this->importObject();
2146  return;
2147  }
2148 
2149  include_once("./Modules/Survey/classes/class.ilObjSurvey.php");
2150  $newObj = new ilObjSurvey();
2151  $newObj->setType($_GET["new_type"]);
2152  $newObj->setTitle("dummy");
2153  $newObj->setDescription("dummy");
2154  $newObj->create(true);
2155  $newObj->createReference();
2156  $newObj->putInTree($_GET["ref_id"]);
2157  $newObj->setPermissions($_GET["ref_id"]);
2158  $newObj->notify("new",$_GET["ref_id"],$_GET["parent_non_rbac_id"],$_GET["ref_id"],$newObj->getRefId());
2159  // copy uploaded file to import directory
2160  $error = $newObj->importObject($_FILES["xmldoc"], $_POST["spl"]);
2161  if (strlen($error))
2162  {
2163  $newObj->delete();
2164  $this->ilias->raiseError($error, $this->ilias->error_obj->MESSAGE);
2165  return;
2166  }
2167  else
2168  {
2169  $ref_id = $newObj->getRefId();
2170  }
2171  if ($redirect)
2172  {
2173  include_once "./Services/Utilities/classes/class.ilUtil.php";
2174  ilUtil::redirect($this->getReturnLocation("upload",$this->ctrl->getTargetScript()."?".$this->link_params));
2175  }
2176  return $ref_id;
2177  }
2178 
2182  function createObject()
2183  {
2184  global $rbacsystem;
2185  $new_type = $_POST["new_type"] ? $_POST["new_type"] : $_GET["new_type"];
2186  if (!$rbacsystem->checkAccess("create", $_GET["ref_id"], $new_type))
2187  {
2188  $this->ilias->raiseError($this->lng->txt("permission_denied"),$this->ilias->error_obj->MESSAGE);
2189  }
2190  else
2191  {
2192  $this->getTemplateFile("create", $new_type);
2193 
2194  include_once("./Modules/Survey/classes/class.ilObjSurvey.php");
2195  $svy = new ilObjSurvey();
2196 
2197  $this->fillCloneTemplate('DUPLICATE','svy');
2198  $questionpools =& $svy->getAvailableQuestionpools($use_obj_id = TRUE, $could_be_offline = TRUE, $showPath = TRUE);
2199  if (count($questionpools) > 0)
2200  {
2201  foreach ($questionpools as $key => $value)
2202  {
2203  $this->tpl->setCurrentBlock("option_spl");
2204  $this->tpl->setVariable("OPTION_VALUE", $key);
2205  $this->tpl->setVariable("TXT_OPTION", $value);
2206  if ($_POST["spl"] == $key)
2207  {
2208  $this->tpl->setVariable("OPTION_SELECTED", " selected=\"selected\"");
2209  }
2210  $this->tpl->parseCurrentBlock();
2211  }
2212  }
2213  // fill in saved values in case of error
2214  $data = array();
2215  $data["fields"] = array();
2216  include_once "./Services/Utilities/classes/class.ilUtil.php";
2217  $data["fields"]["title"] = ilUtil::prepareFormOutput($_SESSION["error_post_vars"]["Fobject"]["title"],true);
2218  $data["fields"]["desc"] = ilUtil::prepareFormOutput($_SESSION["error_post_vars"]["Fobject"]["desc"]);
2219 
2220  foreach ($data["fields"] as $key => $val)
2221  {
2222  $this->tpl->setVariable("TXT_".strtoupper($key), $this->lng->txt($key));
2223  $this->tpl->setVariable(strtoupper($key), $val);
2224 
2225  if ($this->prepare_output)
2226  {
2227  $this->tpl->parseCurrentBlock();
2228  }
2229  }
2230 
2231  $this->ctrl->setParameter($this, "new_type", $this->type);
2232  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this, "create"));
2233  $this->tpl->setVariable("TXT_HEADER", $this->lng->txt($new_type."_new"));
2234  $this->tpl->setVariable("TXT_SELECT_QUESTIONPOOL", $this->lng->txt("select_questionpool_short"));
2235  $this->tpl->setVariable("OPTION_SELECT_QUESTIONPOOL", $this->lng->txt("select_questionpool_option"));
2236  $this->tpl->setVariable("TXT_CANCEL", $this->lng->txt("cancel"));
2237  $this->tpl->setVariable("TXT_SUBMIT", $this->lng->txt($new_type."_add"));
2238  $this->tpl->setVariable("CMD_SUBMIT", "save");
2239  $this->tpl->setVariable("TARGET", ' target="'.
2240  ilFrameTargetInfo::_getFrame("MainContent").'" ');
2241  $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
2242 
2243  $this->tpl->setVariable("TXT_IMPORT_SVY", $this->lng->txt("import_svy"));
2244  $this->tpl->setVariable("TXT_SVY_FILE", $this->lng->txt("svy_upload_file"));
2245  $this->tpl->setVariable("TXT_IMPORT", $this->lng->txt("import"));
2246 
2247  $this->tpl->setVariable("TYPE_IMG", ilUtil::getImagePath('icon_svy.gif'));
2248  $this->tpl->setVariable("ALT_IMG",$this->lng->txt("obj_svy"));
2249  $this->tpl->setVariable("TYPE_IMG2", ilUtil::getImagePath('icon_svy.gif'));
2250  $this->tpl->setVariable("ALT_IMG2",$this->lng->txt("obj_svy"));
2251  }
2252  }
2253 
2257  function importFileObject()
2258  {
2259  if ($_POST["spl"] < 1)
2260  {
2261  ilUtil::sendInfo($this->lng->txt("svy_select_questionpools"));
2262  $this->createObject();
2263  return;
2264  }
2265  if (strcmp($_FILES["xmldoc"]["tmp_name"], "") == 0)
2266  {
2267  ilUtil::sendInfo($this->lng->txt("svy_select_file_for_import"));
2268  $this->createObject();
2269  return;
2270  }
2271  $this->ctrl->setParameter($this, "new_type", $this->type);
2272  $ref_id = $this->uploadObject(false);
2273  // always send a message
2274  ilUtil::sendSuccess($this->lng->txt("object_imported"),true);
2275 
2276  ilUtil::redirect("ilias.php?ref_id=".$ref_id.
2277  "&baseClass=ilObjSurveyGUI");
2278 // $this->ctrl->redirect($this, "importFile");
2279  }
2280 
2281  /*
2282  * list all export files
2283  */
2284  public function exportObject()
2285  {
2286  $this->handleWriteAccess();
2287 
2288  $export_dir = $this->object->getExportDirectory();
2289  $export_files = $this->object->getExportFiles($export_dir);
2290  $data = array();
2291  if(count($export_files) > 0)
2292  {
2293  foreach($export_files as $exp_file)
2294  {
2295  $file_arr = explode("__", $exp_file);
2296  $date = new ilDateTime($file_arr[0], IL_CAL_UNIX);
2297  array_push($data, array(
2298  'file' => $exp_file,
2299  'size' => filesize($export_dir."/".$exp_file),
2300  'date' => $date->get(IL_CAL_DATETIME)
2301  ));
2302  }
2303  }
2304 
2305  include_once "./Modules/Survey/classes/tables/class.ilSurveyExportTableGUI.php";
2306  $table_gui = new ilSurveyExportTableGUI($this, 'export');
2307  $table_gui->setData($data);
2308  $this->tpl->setVariable('ADM_CONTENT', $table_gui->getHTML());
2309  }
2310 
2314  public function createExportFileObject()
2315  {
2316  $this->handleWriteAccess();
2317  include_once("./Modules/Survey/classes/class.ilSurveyExport.php");
2318  $survey_exp = new ilSurveyExport($this->object);
2319  $survey_exp->buildExportFile();
2320  $this->ctrl->redirect($this, "export");
2321  }
2322 
2326  public function downloadExportFileObject()
2327  {
2328  if(!isset($_POST["file"]))
2329  {
2330  ilUtil::sendFailure($this->lng->txt("no_checkbox"), true);
2331  $this->ctrl->redirect($this, "export");
2332  }
2333 
2334  if (count($_POST["file"]) > 1)
2335  {
2336  ilUtil::sendFailure($this->lng->txt("select_max_one_item"), true);
2337  $this->ctrl->redirect($this, "export");
2338  }
2339 
2340 
2341  $export_dir = $this->object->getExportDirectory();
2342  include_once "./Services/Utilities/classes/class.ilUtil.php";
2343  ilUtil::deliverFile($export_dir."/".$_POST["file"][0],
2344  $_POST["file"][0]);
2345  }
2346 
2351  {
2352  $this->handleWriteAccess();
2353 
2354  if (!isset($_POST["file"]))
2355  {
2356  ilUtil::sendFailure($this->lng->txt("no_checkbox"), true);
2357  $this->ctrl->redirect($this, "export");
2358  }
2359 
2360  ilUtil::sendQuestion($this->lng->txt("info_delete_sure"));
2361 
2362  $export_dir = $this->object->getExportDirectory();
2363  $export_files = $this->object->getExportFiles($export_dir);
2364  $data = array();
2365  if (count($_POST["file"]) > 0)
2366  {
2367  foreach ($_POST["file"] as $exp_file)
2368  {
2369  $file_arr = explode("__", $exp_file);
2370  $date = new ilDateTime($file_arr[0], IL_CAL_UNIX);
2371  array_push($data, array(
2372  'file' => $exp_file,
2373  'size' => filesize($export_dir."/".$exp_file),
2374  'date' => $date->get(IL_CAL_DATETIME)
2375  ));
2376  }
2377  }
2378 
2379  include_once "./Modules/Survey/classes/tables/class.ilSurveyExportTableGUI.php";
2380  $table_gui = new ilSurveyExportTableGUI($this, 'export', true);
2381  $table_gui->setData($data);
2382  $this->tpl->setVariable('ADM_CONTENT', $table_gui->getHTML());
2383  }
2384 
2385 
2390  {
2391  ilUtil::sendInfo($this->lng->txt('msg_cancel'), true);
2392  $this->ctrl->redirect($this, "export");
2393  }
2394 
2395 
2399  public function deleteExportFileObject()
2400  {
2401  $export_dir = $this->object->getExportDirectory();
2402  foreach ($_POST["file"] as $file)
2403  {
2404  $exp_file = $export_dir."/".$file;
2405  $exp_dir = $export_dir."/".substr($file, 0, strlen($file) - 4);
2406  if (@is_file($exp_file))
2407  {
2408  unlink($exp_file);
2409  }
2410  if (@is_dir($exp_dir))
2411  {
2412  include_once "./Services/Utilities/classes/class.ilUtil.php";
2413  ilUtil::delDir($exp_dir);
2414  }
2415  }
2416  ilUtil::sendSuccess($this->lng->txt('msg_deleted_export_files'), true);
2417  $this->ctrl->redirect($this, "export");
2418  }
2419 
2423  public function setCodeLanguageObject()
2424  {
2425  if (strcmp($_POST["lang"], "-1") != 0)
2426  {
2427  global $ilUser;
2428  $ilUser->writePref("survey_code_language", $_POST["lang"]);
2429  }
2430  ilUtil::sendSuccess($this->lng->txt('language_changed'), true);
2431  $this->ctrl->redirect($this, 'codes');
2432  }
2433 
2437  public function codesObject()
2438  {
2439  $this->handleWriteAccess();
2440 
2441  global $ilUser;
2442  if ($this->object->getAnonymize() != 1)
2443  {
2444  return ilUtil::sendInfo($this->lng->txt("survey_codes_no_anonymization"));
2445  }
2446 
2447  include_once "./Modules/Survey/classes/tables/class.ilSurveyCodesTableGUI.php";
2448  $table_gui = new ilSurveyCodesTableGUI($this, 'codes');
2449  $default_lang = $ilUser->getPref("survey_code_language");
2450  $survey_codes =& $this->object->getSurveyCodesTableData($default_lang);
2451  $table_gui->setData($survey_codes);
2452  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_svy_codes.html", true);
2453  $this->tpl->setCurrentBlock("adm_content");
2454  $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this, "codes"));
2455  $this->tpl->setVariable("TEXT_CREATE", $this->lng->txt("create"));
2456  $this->tpl->setVariable("TEXT_SURVEY_CODES", $this->lng->txt("new_survey_codes"));
2457  $this->tpl->setVariable('TABLE', $table_gui->getHTML());
2458  }
2459 
2463  public function deleteCodesObject()
2464  {
2465  if (is_array($_POST["chb_code"]) && (count($_POST["chb_code"]) > 0))
2466  {
2467  foreach ($_POST["chb_code"] as $survey_code)
2468  {
2469  $this->object->deleteSurveyCode($survey_code);
2470  }
2471  ilUtil::sendSuccess($this->lng->txt('codes_deleted'), true);
2472  }
2473  else
2474  {
2475  ilUtil::sendInfo($this->lng->txt('no_checkbox'), true);
2476  }
2477  $this->ctrl->redirect($this, 'codes');
2478  }
2479 
2483  public function exportCodesObject()
2484  {
2485  if (is_array($_POST["chb_code"]) && (count($_POST["chb_code"]) > 0))
2486  {
2487  $export = $this->object->getSurveyCodesForExport($_POST["chb_code"]);
2488  ilUtil::deliverData($export, ilUtil::getASCIIFilename($this->object->getTitle() . ".txt"));
2489  }
2490  else
2491  {
2492  ilUtil::sendFailure($this->lng->txt("no_checkbox"), true);
2493  $this->ctrl->redirect($this, 'codes');
2494  }
2495  }
2496 
2500  public function exportAllCodesObject()
2501  {
2502  $export = $this->object->getSurveyCodesForExport(array());
2503  ilUtil::deliverData($export, ilUtil::getASCIIFilename($this->object->getTitle() . ".txt"));
2504  }
2505 
2509  public function createSurveyCodesObject()
2510  {
2511  if (preg_match("/\d+/", $_POST["nrOfCodes"]))
2512  {
2513  $this->object->createSurveyCodes($_POST["nrOfCodes"]);
2514  ilUtil::sendSuccess($this->lng->txt('codes_created'), true);
2515  }
2516  else
2517  {
2518  ilUtil::sendFailure($this->lng->txt("enter_valid_number_of_codes"), true);
2519  }
2520  $this->ctrl->redirect($this, 'codes');
2521  }
2522 
2526  public function addConstraintForm($step, $postvalues, &$survey_questions, $questions = FALSE)
2527  {
2528  $this->ctrl->saveParameter($this, "preid");
2529  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_svy_add_constraint.html", "Modules/Survey");
2530  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
2531  if (is_array($questions))
2532  {
2533  foreach ($questions as $question)
2534  {
2535  $this->tpl->setCurrentBlock("option_q");
2536  $this->tpl->setVariable("OPTION_VALUE", $question["question_id"]);
2537  $this->tpl->setVariable("OPTION_TEXT", $question["title"] . " (" . SurveyQuestion::_getQuestionTypeName($question["type_tag"]) . ")");
2538  if ($question["question_id"] == $postvalues["q"])
2539  {
2540  $this->tpl->setVariable("OPTION_CHECKED", " selected=\"selected\"");
2541  }
2542  $this->tpl->parseCurrentBlock();
2543  }
2544  }
2545  if ($step > 1)
2546  {
2547  $relations = $this->object->getAllRelations();
2548  foreach ($relations as $rel_id => $relation)
2549  {
2550  if (in_array($relation["short"], $survey_questions[$postvalues["q"]]["availableRelations"]))
2551  {
2552  $this->tpl->setCurrentBlock("option_r");
2553  $this->tpl->setVariable("OPTION_VALUE", $rel_id);
2554  $this->tpl->setVariable("OPTION_TEXT", $relation["short"]);
2555  if ($rel_id == $postvalues["r"])
2556  {
2557  $this->tpl->setVariable("OPTION_CHECKED", " selected=\"selected\"");
2558  }
2559  $this->tpl->parseCurrentBlock();
2560  }
2561  }
2562  $this->tpl->setCurrentBlock("select_relation");
2563  $this->tpl->setVariable("SELECT_RELATION", $this->lng->txt("step") . " 2: " . $this->lng->txt("select_relation"));
2564  $this->tpl->parseCurrentBlock();
2565  }
2566 
2567  if ($step > 2)
2568  {
2569  $variables =& $this->object->getVariables($postvalues["q"]);
2570  $question_type = $survey_questions[$postvalues["q"]]["type_tag"];
2571  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
2572  SurveyQuestion::_includeClass($question_type);
2573  $question = new $question_type();
2574  $question->loadFromDb($postvalues["q"]);
2575  $select_value = $question->getPreconditionSelectValue($postvalues["v"]);
2576  $this->tpl->setCurrentBlock("select_value");
2577  $this->tpl->setVariable("SELECT_VALUE", $select_value);
2578  $this->tpl->parseCurrentBlock();
2579  }
2580 
2581  $this->tpl->setCurrentBlock("buttons");
2582  $this->tpl->setVariable("BTN_CONTINUE", $this->lng->txt("continue"));
2583  switch ($step)
2584  {
2585  case 1:
2586  $this->tpl->setVariable("COMMAND", "constraintStep2");
2587  $this->tpl->setVariable("COMMAND_BACK", "constraints");
2588  break;
2589  case 2:
2590  $this->tpl->setVariable("COMMAND", "constraintStep3");
2591  $this->tpl->setVariable("COMMAND_BACK", "constraintStep1");
2592  break;
2593  case 3:
2594  $this->tpl->setVariable("COMMAND", "constraintsAdd");
2595  $this->tpl->setVariable("COMMAND_BACK", "constraintStep2");
2596  break;
2597  }
2598  $this->tpl->setVariable("BTN_BACK", $this->lng->txt("back"));
2599  $this->tpl->parseCurrentBlock();
2600  $this->tpl->setCurrentBlock("adm_content");
2601  $title = "";
2602  if ($survey_questions[$_SESSION["constraintstructure"][$_GET["start"]][0]]["questionblock_id"] > 0)
2603  {
2604  $title = $this->lng->txt("questionblock") . ": " . $survey_questions[$_SESSION["constraintstructure"][$_GET["start"]][0]]["questionblock_title"];
2605  }
2606  else
2607  {
2608  $title = $this->lng->txt($survey_questions[$_SESSION["constraintstructure"][$_GET["start"]][0]]["type_tag"]) . ": " . $survey_questions[$_SESSION["constraintstructure"][$_GET["start"]][0]]["title"];
2609  }
2610  $this->tpl->setVariable("CONSTRAINT_QUESTION_TEXT", $title);
2611  $this->tpl->setVariable("SELECT_PRIOR_QUESTION", $this->lng->txt("step") . " 1: " . $this->lng->txt("select_prior_question"));
2612  if (strlen($_GET["start"])) $this->ctrl->setParameter($this, "start", $_GET["start"]);
2613  $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this, "constraintsAdd"));
2614  $this->tpl->parseCurrentBlock();
2615  }
2616 
2625  {
2626  if (strlen($_POST["v"]) == 0)
2627  {
2628  ilUtil::sendFailure($this->lng->txt("msg_enter_value_for_valid_constraint"));
2629  return $this->constraintStep3Object();
2630  }
2631  $survey_questions =& $this->object->getSurveyQuestions();
2632  $structure =& $_SESSION["constraintstructure"];
2633  $include_elements = $_SESSION["includeElements"];
2634  foreach ($include_elements as $elementCounter)
2635  {
2636  if (is_array($structure[$elementCounter]))
2637  {
2638  foreach ($structure[$elementCounter] as $key => $question_id)
2639  {
2640  if (strlen($_GET["preid"]))
2641  {
2642  $this->object->updateConstraint($question_id, $_POST["q"], $_POST["r"], $_POST["v"]);
2643  }
2644  else
2645  {
2646  $this->object->addConstraint($question_id, $_POST["q"], $_POST["r"], $_POST["v"]);
2647  }
2648  }
2649  }
2650  }
2651  unset($_SESSION["includeElements"]);
2652  unset($_SESSION["constraintstructure"]);
2653  $this->ctrl->redirect($this, "constraints");
2654  }
2655 
2664  {
2665  $survey_questions =& $this->object->getSurveyQuestions();
2666  $option_questions = array();
2667  if (strlen($_GET["precondition"]))
2668  {
2669  $pc = $this->object->getPrecondition($_GET["precondition"]);
2670  $postvalues = array(
2671  "q" => $pc["question_fi"],
2672  "r" => $pc["relation_id"],
2673  "v" => $pc["value"]
2674  );
2675  $this->ctrl->setParameter($this, "preid", $_GET["precondition"]);
2676  array_push($option_questions, array("question_id" => $pc["question_fi"], "title" => $survey_questions[$pc["question_fi"]]["title"], "type_tag" => $survey_questions[$pc["question_fi"]]["type_tag"]));
2677  $this->addConstraintForm(3, $postvalues, $survey_questions, $option_questions);
2678  }
2679  else
2680  {
2681  array_push($option_questions, array("question_id" => $_POST["q"], "title" => $survey_questions[$_POST["q"]]["title"], "type_tag" => $survey_questions[$_POST["q"]]["type_tag"]));
2682  $this->addConstraintForm(3, $_POST, $survey_questions, $option_questions);
2683  }
2684  }
2685 
2694  {
2695  $survey_questions =& $this->object->getSurveyQuestions();
2696  $option_questions = array();
2697  array_push($option_questions, array("question_id" => $_POST["q"], "title" => $survey_questions[$_POST["q"]]["title"], "type_tag" => $survey_questions[$_POST["q"]]["type_tag"]));
2698  $this->addConstraintForm(2, $_POST, $survey_questions, $option_questions);
2699  }
2700 
2709  {
2710  $survey_questions =& $this->object->getSurveyQuestions();
2711  $structure =& $_SESSION["constraintstructure"];
2712  $start = $_GET["start"];
2713  $option_questions = array();
2714  for ($i = 1; $i < $start; $i++)
2715  {
2716  if (is_array($structure[$i]))
2717  {
2718  foreach ($structure[$i] as $key => $question_id)
2719  {
2720  if ($survey_questions[$question_id]["usableForPrecondition"])
2721  {
2722  array_push($option_questions, array("question_id" => $survey_questions[$question_id]["question_id"], "title" => $survey_questions[$question_id]["title"], "type_tag" => $survey_questions[$question_id]["type_tag"]));
2723  }
2724  }
2725  }
2726  }
2727  if (count($option_questions) == 0)
2728  {
2729  unset($_SESSION["includeElements"]);
2730  unset($_SESSION["constraintstructure"]);
2731  ilUtil::sendInfo($this->lng->txt("constraints_no_nonessay_available"), true);
2732  $this->ctrl->redirect($this, "constraints");
2733  }
2734  $this->addConstraintForm(1, $_POST, $survey_questions, $option_questions);
2735  }
2736 
2745  {
2746  $survey_questions =& $this->object->getSurveyQuestions();
2747  $structure =& $_SESSION["constraintstructure"];
2748  foreach ($_POST as $key => $value)
2749  {
2750  if (preg_match("/^constraint_(\d+)_(\d+)/", $key, $matches))
2751  {
2752  foreach ($structure[$matches[1]] as $key => $question_id)
2753  {
2754  $this->object->deleteConstraint($matches[2], $question_id);
2755  }
2756  }
2757  }
2758 
2759  $this->ctrl->redirect($this, "constraints");
2760  }
2761 
2763  {
2764  $include_elements = $_POST["includeElements"];
2765  if ((!is_array($include_elements)) || (count($include_elements) == 0))
2766  {
2767  ilUtil::sendInfo($this->lng->txt("constraints_no_questions_or_questionblocks_selected"), true);
2768  $this->ctrl->redirect($this, "constraints");
2769  }
2770  else if (count($include_elements) >= 1)
2771  {
2772  $_SESSION["includeElements"] = $include_elements;
2773  sort($include_elements, SORT_NUMERIC);
2774  $_GET["start"] = $include_elements[0];
2775  $this->constraintStep1Object();
2776  }
2777  }
2778 
2780  {
2781  $_SESSION["includeElements"] = array($_GET["start"]);
2782  $this->ctrl->setParameter($this, "precondition", $_GET["precondition"]);
2783  $this->ctrl->setParameter($this, "start", $_GET["start"]);
2784  $this->ctrl->redirect($this, "constraintStep3");
2785  }
2786 
2795  {
2796  $this->handleWriteAccess();
2797 
2798  global $rbacsystem;
2799 
2800  $hasDatasets = $this->object->_hasDatasets($this->object->getSurveyId());
2801  $step = 0;
2802  if (array_key_exists("step", $_GET)) $step = $_GET["step"];
2803  switch ($step)
2804  {
2805  case 1:
2806  $this->constraintStep1Object();
2807  return;
2808  break;
2809  case 2:
2810  return;
2811  break;
2812  case 3:
2813  return;
2814  break;
2815  }
2816 
2817  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_svy_constraints_list.html", "Modules/Survey");
2818  $survey_questions =& $this->object->getSurveyQuestions();
2819  $last_questionblock_title = "";
2820  $counter = 1;
2821  $hasPreconditions = FALSE;
2822  $structure = array();
2823  $colors = array("tblrow1", "tblrow2");
2824  foreach ($survey_questions as $question_id => $data)
2825  {
2826  $title = $data["title"];
2827  $show = true;
2828  if ($data["questionblock_id"] > 0)
2829  {
2830  $title = $data["questionblock_title"];
2831  $type = $this->lng->txt("questionblock");
2832  if (strcmp($title, $last_questionblock_title) != 0)
2833  {
2834  $last_questionblock_title = $title;
2835  $structure[$counter] = array();
2836  array_push($structure[$counter], $data["question_id"]);
2837  }
2838  else
2839  {
2840  array_push($structure[$counter-1], $data["question_id"]);
2841  $show = false;
2842  }
2843  }
2844  else
2845  {
2846  $structure[$counter] = array($data["question_id"]);
2847  $type = $this->lng->txt("question");
2848  }
2849  if ($show)
2850  {
2851  if ($counter == 1)
2852  {
2853  $this->tpl->setCurrentBlock("description");
2854  $this->tpl->setVariable("DESCRIPTION", $this->lng->txt("constraints_first_question_description"));
2855  $this->tpl->parseCurrentBlock();
2856  }
2857  else
2858  {
2859  $constraints =& $this->object->getConstraints($data["question_id"]);
2860  $rowcount = 0;
2861  if (count($constraints))
2862  {
2863  $hasPreconditions = TRUE;
2864  foreach ($constraints as $constraint)
2865  {
2866  $this->tpl->setCurrentBlock("constraint");
2867  $this->tpl->setVariable("SEQUENCE_ID", $counter);
2868  $this->tpl->setVariable("CONSTRAINT_ID", $constraint["id"]);
2869  $this->tpl->setVariable("CONSTRAINT_TEXT", $survey_questions[$constraint["question"]]["title"] . " " . $constraint["short"] . " " . $constraint["valueoutput"]);
2870  $this->tpl->setVariable("TEXT_EDIT_PRECONDITION", $this->lng->txt("edit"));
2871  $this->ctrl->setParameter($this, "precondition", $constraint["id"]);
2872  $this->ctrl->setParameter($this, "start", $counter);
2873  $this->tpl->setVariable("EDIT_PRECONDITION", $this->ctrl->getLinkTarget($this, "editPrecondition"));
2874  $this->ctrl->setParameter($this, "precondition", "");
2875  $this->ctrl->setParameter($this, "start", "");
2876  $this->tpl->parseCurrentBlock();
2877  }
2878  }
2879  }
2880  if ($counter != 1)
2881  {
2882  $this->tpl->setCurrentBlock("include_elements");
2883  $this->tpl->setVariable("QUESTION_NR", "$counter");
2884  $this->tpl->parseCurrentBlock();
2885  }
2886  $this->tpl->setCurrentBlock("constraint_section");
2887  $this->tpl->setVariable("COLOR_CLASS", $colors[$counter % 2]);
2888  $this->tpl->setVariable("QUESTION_NR", "$counter");
2889  $this->tpl->setVariable("TITLE", "$title");
2890  $icontype = "question.gif";
2891  if ($data["questionblock_id"] > 0)
2892  {
2893  $icontype = "questionblock.gif";
2894  }
2895  $this->tpl->setVariable("TYPE", "$type: ");
2896  include_once "./Services/Utilities/classes/class.ilUtil.php";
2897  $this->tpl->setVariable("ICON_HREF", ilUtil::getImagePath($icontype, "Modules/Survey"));
2898  $this->tpl->setVariable("ICON_ALT", $type);
2899  $this->tpl->parseCurrentBlock();
2900  $counter++;
2901  }
2902  }
2903  if ($rbacsystem->checkAccess("write", $this->ref_id) and !$hasDatasets)
2904  {
2905  if ($hasPreconditions)
2906  {
2907  $this->tpl->setCurrentBlock("selectall_preconditions");
2908  $this->tpl->setVariable("SELECT_ALL_PRECONDITIONS", $this->lng->txt("select_all"));
2909  $this->tpl->parseCurrentBlock();
2910  }
2911  $this->tpl->setCurrentBlock("selectall");
2912  $counter++;
2913  $this->tpl->setVariable("SELECT_ALL", $this->lng->txt("select_all"));
2914  $this->tpl->setVariable("COLOR_CLASS", $colors[$counter % 2]);
2915  $this->tpl->parseCurrentBlock();
2916 
2917  if ($hasPreconditions)
2918  {
2919  $this->tpl->setCurrentBlock("delete_button");
2920  $this->tpl->setVariable("BTN_DELETE", $this->lng->txt("delete"));
2921  include_once "./Services/Utilities/classes/class.ilUtil.php";
2922  $this->tpl->setVariable("ARROW", "<img src=\"" . ilUtil::getImagePath("arrow_downright.gif") . "\" alt=\"".$this->lng->txt("arrow_downright")."\">");
2923  $this->tpl->parseCurrentBlock();
2924  }
2925 
2926  $this->tpl->setCurrentBlock("buttons");
2927  $this->tpl->setVariable("ARROW", "<img src=\"" . ilUtil::getImagePath("arrow_downright.gif") . "\" alt=\"".$this->lng->txt("arrow_downright")."\">");
2928  $this->tpl->setVariable("BTN_CREATE_CONSTRAINTS", $this->lng->txt("constraint_add"));
2929  $this->tpl->parseCurrentBlock();
2930  }
2931  $this->tpl->setCurrentBlock("adm_content");
2932  $this->tpl->setVariable("CONSTRAINTS_INTRODUCTION", $this->lng->txt("constraints_introduction"));
2933  $this->tpl->setVariable("DEFINED_PRECONDITIONS", $this->lng->txt("existing_constraints"));
2934  $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this, "constraints"));
2935  $this->tpl->setVariable("CONSTRAINTS_HEADER", $this->lng->txt("constraints_list_of_entities"));
2936  $this->tpl->parseCurrentBlock();
2937  $_SESSION["constraintstructure"] = $structure;
2938  if ($hasDatasets)
2939  {
2940  ilUtil::sendInfo($this->lng->txt("survey_has_datasets_warning"));
2941  }
2942  }
2943 
2949  function infoScreenObject()
2950  {
2951  $this->ctrl->setCmd("showSummary");
2952  $this->ctrl->setCmdClass("ilinfoscreengui");
2953  $this->infoScreen();
2954  }
2955 
2956  function setNewTemplate()
2957  {
2958  global $tpl;
2959  $tpl = new ilTemplate("tpl.il_svy_svy_main.html", TRUE, TRUE, "Modules/Survey");
2960  // load style sheet depending on user's settings
2961  $location_stylesheet = ilUtil::getStyleSheetLocation();
2962  $tpl->setVariable("LOCATION_STYLESHEET",$location_stylesheet);
2963  $tpl->setVariable("LOCATION_JAVASCRIPT",dirname($location_stylesheet));
2964  }
2965 
2969  function infoScreen()
2970  {
2971  global $ilAccess;
2972  global $ilUser;
2973 
2974  if (!$ilAccess->checkAccess("visible", "", $this->ref_id))
2975  {
2976  $this->ilias->raiseError($this->lng->txt("msg_no_perm_read"),$this->ilias->error_obj->MESSAGE);
2977  }
2978 
2979  include_once("./Services/InfoScreen/classes/class.ilInfoScreenGUI.php");
2980  $info = new ilInfoScreenGUI($this);
2981  include_once "./Modules/Survey/classes/class.ilSurveyExecutionGUI.php";
2982  $output_gui =& new ilSurveyExecutionGUI($this->object);
2983  $info->setFormAction($this->ctrl->getFormAction($output_gui, "infoScreen"));
2984  $info->enablePrivateNotes();
2985  $anonymize_key = NULL;
2986  if ($this->object->getAnonymize() == 1)
2987  {
2988  if ($_SESSION["anonymous_id"])
2989  {
2990  $anonymize_key = $_SESSION["anonymous_id"];
2991  }
2992  else if ($_POST["anonymous_id"])
2993  {
2994  $anonymize_key = $_POST["anonymous_id"];
2995  }
2996  }
2997  $canStart = $this->object->canStartSurvey($anonymize_key);
2998  $showButtons = $canStart["result"];
2999  if (!$showButtons) ilUtil::sendInfo(implode("<br />", $canStart["messages"]));
3000 
3001  if ($showButtons)
3002  {
3003  // output of start/resume buttons for personalized surveys
3004  if (!$this->object->getAnonymize())
3005  {
3006  $survey_started = $this->object->isSurveyStarted($ilUser->getId(), "");
3007  // Anonymous User tries to start a personalized survey
3008  if ($_SESSION["AccountId"] == ANONYMOUS_USER_ID)
3009  {
3010  ilUtil::sendInfo($this->lng->txt("anonymous_with_personalized_survey"));
3011  }
3012  else
3013  {
3014  if ($survey_started === 1)
3015  {
3016  ilUtil::sendInfo($this->lng->txt("already_completed_survey"));
3017  }
3018  elseif ($survey_started === 0)
3019  {
3020  $info->addFormButton("resume", $this->lng->txt("resume_survey"));
3021  }
3022  elseif ($survey_started === FALSE)
3023  {
3024  $info->addFormButton("start", $this->lng->txt("start_survey"));
3025  }
3026  }
3027  }
3028  // output of start/resume buttons for anonymized surveys
3029  else if ($this->object->getAnonymize() && !$this->object->isAccessibleWithoutCode())
3030  {
3031  if (($_SESSION["AccountId"] == ANONYMOUS_USER_ID) && (strlen($_POST["anonymous_id"]) == 0) && (strlen($_SESSION["anonymous_id"]) == 0))
3032  {
3033  $info->setFormAction($this->ctrl->getFormAction($this, "infoScreen"));
3034  $info->addSection($this->lng->txt("anonymization"));
3035  $info->addProperty("", $this->lng->txt("anonymize_anonymous_introduction"));
3036  $info->addPropertyTextinput($this->lng->txt("enter_anonymous_id"), "anonymous_id", "", 8, "infoScreen", $this->lng->txt("submit"));
3037  }
3038  else
3039  {
3040  if (strlen($_POST["anonymous_id"]) > 0)
3041  {
3042  if (!$this->object->checkSurveyCode($_POST["anonymous_id"]))
3043  {
3044  ilUtil::sendInfo($this->lng->txt("wrong_survey_code_used"));
3045  }
3046  else
3047  {
3048  $anonymize_key = $_POST["anonymous_id"];
3049  }
3050  }
3051  else if (strlen($_SESSION["anonymous_id"]) > 0)
3052  {
3053  if (!$this->object->checkSurveyCode($_SESSION["anonymous_id"]))
3054  {
3055  ilUtil::sendInfo($this->lng->txt("wrong_survey_code_used"));
3056  }
3057  else
3058  {
3059  $anonymize_key = $_SESSION["anonymous_id"];
3060  }
3061  }
3062  else
3063  {
3064  // registered users do not need to know that there is an anonymous key. The data is anonymized automatically
3065  $anonymize_key = $this->object->getUserAccessCode($ilUser->getId());
3066  if (!strlen($anonymize_key))
3067  {
3068  $anonymize_key = $this->object->createNewAccessCode();
3069  $this->object->saveUserAccessCode($ilUser->getId(), $anonymize_key);
3070  }
3071  }
3072  $info->addHiddenElement("anonymous_id", $anonymize_key);
3073  $survey_started = $this->object->isSurveyStarted($ilUser->getId(), $anonymize_key);
3074  if ($survey_started === 1)
3075  {
3076  ilUtil::sendInfo($this->lng->txt("already_completed_survey"));
3077  }
3078  elseif ($survey_started === 0)
3079  {
3080  $info->addFormButton("resume", $this->lng->txt("resume_survey"));
3081  }
3082  elseif ($survey_started === FALSE)
3083  {
3084  $info->addFormButton("start", $this->lng->txt("start_survey"));
3085  }
3086  }
3087  }
3088  else
3089  {
3090  // free access
3091  $survey_started = $this->object->isSurveyStarted($ilUser->getId(), "");
3092  if ($survey_started === 1)
3093  {
3094  ilUtil::sendInfo($this->lng->txt("already_completed_survey"));
3095  }
3096  elseif ($survey_started === 0)
3097  {
3098  $info->addFormButton("resume", $this->lng->txt("resume_survey"));
3099  }
3100  elseif ($survey_started === FALSE)
3101  {
3102  $info->addFormButton("start", $this->lng->txt("start_survey"));
3103  }
3104  }
3105  }
3106 
3107  if (strlen($this->object->getIntroduction()))
3108  {
3109  $introduction = $this->object->getIntroduction();
3110  $info->addSection($this->lng->txt("introduction"));
3111  $info->addProperty("", $this->object->prepareTextareaOutput($introduction));
3112  }
3113 
3114  $info->addSection($this->lng->txt("svy_general_properties"));
3115  if (strlen($this->object->getAuthor()))
3116  {
3117  $info->addProperty($this->lng->txt("author"), $this->object->getAuthor());
3118  }
3119  $info->addProperty($this->lng->txt("title"), $this->object->getTitle());
3120  switch ($this->object->getAnonymize())
3121  {
3122  case ANONYMIZE_OFF:
3123  $info->addProperty($this->lng->txt("anonymization"), $this->lng->txt("anonymize_personalized"));
3124  break;
3125  case ANONYMIZE_ON:
3126  if ($_SESSION["AccountId"] == ANONYMOUS_USER_ID)
3127  {
3128  $info->addProperty($this->lng->txt("anonymization"), $this->lng->txt("info_anonymize_with_code"));
3129  }
3130  else
3131  {
3132  $info->addProperty($this->lng->txt("anonymization"), $this->lng->txt("info_anonymize_registered_user"));
3133  }
3134  break;
3135  case ANONYMIZE_FREEACCESS:
3136  $info->addProperty($this->lng->txt("anonymization"), $this->lng->txt("info_anonymize_without_code"));
3137  break;
3138  }
3139  include_once "./Modules/Survey/classes/class.ilObjSurveyAccess.php";
3140  if ($ilAccess->checkAccess("write", "", $this->ref_id) || ilObjSurveyAccess::_hasEvaluationAccess($this->object->getId(), $ilUser->getId()))
3141  {
3142  $info->addProperty($this->lng->txt("evaluation_access"), $this->lng->txt("evaluation_access_info"));
3143  }
3144  $info->addMetaDataSections($this->object->getId(),0, $this->object->getType());
3145  $this->ctrl->forwardCommand($info);
3146  }
3147 
3153  function printViewObject()
3154  {
3155  global $ilias;
3156 
3157  $this->questionsSubtabs("printview");
3158  $template = new ilTemplate("tpl.il_svy_svy_printview.html", TRUE, TRUE, "Modules/Survey");
3159 
3160  include_once './Services/WebServices/RPC/classes/class.ilRPCServerSettings.php';
3161  if(ilRPCServerSettings::getInstance()->isEnabled())
3162  {
3163  $this->ctrl->setParameter($this, "pdf", "1");
3164  $template->setCurrentBlock("pdf_export");
3165  $template->setVariable("PDF_URL", $this->ctrl->getLinkTarget($this, "printView"));
3166  $this->ctrl->setParameter($this, "pdf", "");
3167  $template->setVariable("PDF_TEXT", $this->lng->txt("pdf_export"));
3168  $template->setVariable("PDF_IMG_ALT", $this->lng->txt("pdf_export"));
3169  $template->setVariable("PDF_IMG_URL", ilUtil::getHtmlPath(ilUtil::getImagePath("application-pdf.png")));
3170  $template->parseCurrentBlock();
3171  }
3172  $template->setVariable("PRINT_TEXT", $this->lng->txt("print"));
3173  $template->setVariable("PRINT_URL", "javascript:window.print();");
3174 
3175  $pages =& $this->object->getSurveyPages();
3176  foreach ($pages as $page)
3177  {
3178  if (count($page) > 0)
3179  {
3180  foreach ($page as $question)
3181  {
3182  $questionGUI = $this->object->getQuestionGUI($question["type_tag"], $question["question_id"]);
3183  if (is_object($questionGUI))
3184  {
3185  if (strlen($question["heading"]))
3186  {
3187  $template->setCurrentBlock("textblock");
3188  $template->setVariable("TEXTBLOCK", $question["heading"]);
3189  $template->parseCurrentBlock();
3190  }
3191  $template->setCurrentBlock("question");
3192  $template->setVariable("QUESTION_DATA", $questionGUI->getPrintView($this->object->getShowQuestionTitles(), $question["questionblock_show_questiontext"], $this->object->getSurveyId()));
3193  $template->parseCurrentBlock();
3194  }
3195  }
3196  if (count($page) > 1)
3197  {
3198  $template->setCurrentBlock("page");
3199  $template->setVariable("BLOCKTITLE", $page[0]["questionblock_title"]);
3200  $template->parseCurrentBlock();
3201  }
3202  else
3203  {
3204  $template->setCurrentBlock("page");
3205  $template->parseCurrentBlock();
3206  }
3207  }
3208  }
3209  $this->tpl->addCss("./Modules/Survey/templates/default/survey_print.css", "print");
3210  if (array_key_exists("pdf", $_GET) && ($_GET["pdf"] == 1))
3211  {
3212  $printbody = new ilTemplate("tpl.il_as_tst_print_body.html", TRUE, TRUE, "Modules/Test");
3213  $printbody->setVariable("TITLE", sprintf($this->lng->txt("tst_result_user_name"), $uname));
3214  $printbody->setVariable("ADM_CONTENT", $template->get());
3215  $printoutput = $printbody->get();
3216  $printoutput = preg_replace("/href=\".*?\"/", "", $printoutput);
3217  $fo = $this->object->processPrintoutput2FO($printoutput);
3218  $this->object->deliverPDFfromFO($fo);
3219  }
3220  else
3221  {
3222  $this->tpl->setVariable("ADM_CONTENT", $template->get());
3223  }
3224  }
3225 
3226  function addLocatorItems()
3227  {
3228  global $ilLocator;
3229  switch ($this->ctrl->getCmd())
3230  {
3231  case "next":
3232  case "previous":
3233  case "start":
3234  case "resume":
3235  case "redirectQuestion":
3236  $ilLocator->addItem($this->object->getTitle(), $this->ctrl->getLinkTarget($this, "infoScreen"), "", $_GET["ref_id"]);
3237  break;
3238  case "evaluation":
3239  case "checkEvaluationAccess":
3240  case "evaluationdetails":
3241  case "evaluationuser":
3242  $ilLocator->addItem($this->object->getTitle(), $this->ctrl->getLinkTargetByClass("ilsurveyevaluationgui", "evaluation"), "", $_GET["ref_id"]);
3243  break;
3244  case "create":
3245  case "save":
3246  case "cancel":
3247  case "importFile":
3248  case "cloneAll":
3249  break;
3250  case "infoScreen":
3251  $ilLocator->addItem($this->object->getTitle(), $this->ctrl->getLinkTarget($this, "infoScreen"), "", $_GET["ref_id"]);
3252  break;
3253  default:
3254  $ilLocator->addItem($this->object->getTitle(), $this->ctrl->getLinkTarget($this, ""), "", $_GET["ref_id"]);
3255  break;
3256  }
3257  }
3258 
3266  function questionsSubtabs($a_cmd)
3267  {
3268  $questions = ($a_cmd == 'questions') ? true : false;
3269  $printview = ($a_cmd == 'printview') ? true : false;
3270 
3271  $this->tabs_gui->addSubTabTarget("survey_question_editor", $this->ctrl->getLinkTarget($this, "questions"),
3272  "", "", "", $questions);
3273  $this->tabs_gui->addSubTabTarget("print_view", $this->ctrl->getLinkTarget($this, "printView"),
3274  "", "", "", $printview);
3275  }
3283  function setEvalSubtabs()
3284  {
3285  global $ilTabs;
3286  global $ilAccess;
3287 
3288  $ilTabs->addSubTabTarget(
3289  "svy_eval_cumulated",
3290  $this->ctrl->getLinkTargetByClass("ilsurveyevaluationgui", "evaluation"),
3291  array("evaluation", "checkEvaluationAccess"),
3292  ""
3293  );
3294 
3295  $ilTabs->addSubTabTarget(
3296  "svy_eval_detail",
3297  $this->ctrl->getLinkTargetByClass("ilsurveyevaluationgui", "evaluationdetails"),
3298  array("evaluationdetails"),
3299  ""
3300  );
3301 
3302  if ($ilAccess->checkAccess("write", "", $this->object->getRefId()))
3303  {
3304  $ilTabs->addSubTabTarget(
3305  "svy_eval_user",
3306  $this->ctrl->getLinkTargetByClass("ilsurveyevaluationgui", "evaluationuser"),
3307  array("evaluationuser"),
3308  ""
3309  );
3310  }
3311  }
3312 
3314  {
3315  global $ilAccess;
3316  global $ilTabs;
3317 
3318  if ($ilAccess->checkAccess("write", "", $this->ref_id))
3319  {
3320  $ilTabs->setBackTarget($this->lng->txt("menubacktosurvey"), $this->ctrl->getLinkTarget($this, "questions"));
3321  $ilTabs->addTarget("browse_for_questions",
3322  $this->ctrl->getLinkTarget($this, "browseForQuestions"),
3323  array("browseForQuestions", "browseForQuestionblocks"),
3324  "", ""
3325  );
3326  }
3327  }
3328 
3334  function getTabs(&$tabs_gui)
3335  {
3336  global $ilAccess, $ilUser;
3337 
3338  switch ($this->ctrl->getCmd())
3339  {
3340  case "browseForQuestions":
3341  case "browseForQuestionblocks":
3342  case "insertQuestions":
3343  case "filterQuestions":
3344  case "resetFilterQuestions":
3345  case "changeDatatype":
3346 
3347  case "start":
3348  case "resume":
3349  case "next":
3350  case "previous":
3351  case "redirectQuestion":
3352  return;
3353  break;
3354  case "evaluation":
3355  case "checkEvaluationAccess":
3356  case "evaluationdetails":
3357  case "evaluationuser":
3358  $this->setEvalSubtabs();
3359  break;
3360  }
3361 
3362  // questions
3363  if ($ilAccess->checkAccess("write", "", $this->ref_id))
3364  {
3365  $force_active = ($_GET["up"] != "" || $_GET["down"] != "")
3366  ? true
3367  : false;
3368 
3369  $tabs_gui->addTarget("survey_questions",
3370  $this->ctrl->getLinkTarget($this,'questions'),
3371  array("questions", "browseForQuestions", "createQuestion",
3372  "filterQuestions", "resetFilterQuestions", "changeDatatype", "insertQuestions",
3373  "removeQuestions", "cancelRemoveQuestions", "confirmRemoveQuestions",
3374  "defineQuestionblock", "saveDefineQuestionblock", "cancelDefineQuestionblock",
3375  "unfoldQuestionblock", "moveQuestions",
3376  "insertQuestionsBefore", "insertQuestionsAfter", "saveObligatory",
3377  "addHeading", "saveHeading", "cancelHeading", "editHeading",
3378  "confirmRemoveHeading", "cancelRemoveHeading", "printView"),
3379  "", "", $force_active);
3380  }
3381 
3382  if ($ilAccess->checkAccess("visible", "", $this->ref_id))
3383  {
3384  $tabs_gui->addTarget("info_short",
3385  $this->ctrl->getLinkTarget($this,'infoScreen'),
3386  array("infoScreen", "showSummary"));
3387  }
3388 
3389  // properties
3390  if ($ilAccess->checkAccess("write", "", $this->ref_id))
3391  {
3392  $force_active = ($this->ctrl->getCmd() == "")
3393  ? true
3394  : false;
3395  $tabs_gui->addTarget("properties",
3396  $this->ctrl->getLinkTarget($this,'properties'),
3397  array("properties", "save", "cancel"), "",
3398  "", $force_active);
3399  }
3400 
3401  // questions
3402  if ($ilAccess->checkAccess("write", "", $this->ref_id))
3403  {
3404  // meta data
3405  $tabs_gui->addTarget("meta_data",
3406  $this->ctrl->getLinkTargetByClass('ilmdeditorgui','listSection'),
3407  "", "ilmdeditorgui");
3408 
3409  // constraints
3410  $tabs_gui->addTarget("constraints",
3411  $this->ctrl->getLinkTarget($this, "constraints"),
3412  array("constraints", "constraintStep1", "constraintStep2",
3413  "constraintStep3", "constraintsAdd", "createConstraints",
3414  "editPrecondition"),
3415  "");
3416  }
3417  if (($ilAccess->checkAccess("write", "", $this->ref_id)) || ($ilAccess->checkAccess("invite", "", $this->ref_id)))
3418  {
3419  // invite
3420  $tabs_gui->addTarget("invitation",
3421  $this->ctrl->getLinkTarget($this, "invite"),
3422  array("invite", "saveInvitationStatus",
3423  "searchInvitation", "inviteUserGroup",
3424  "disinviteUserGroup"),
3425  "");
3426  }
3427  if ($ilAccess->checkAccess("write", "", $this->ref_id))
3428  {
3429  // export
3430  $tabs_gui->addTarget("export",
3431  $this->ctrl->getLinkTarget($this,'export'),
3432  array("export", "createExportFile", "confirmDeleteExportFile",
3433  "downloadExportFile"),
3434  ""
3435  );
3436 
3437  // maintenance
3438  $tabs_gui->addTarget("maintenance",
3439  $this->ctrl->getLinkTarget($this,'maintenance'),
3440  array("maintenance", "deleteAllUserData"),
3441  "");
3442 
3443  if ($this->object->getAnonymize() == 1)
3444  {
3445  // code
3446  $tabs_gui->addTarget("codes",
3447  $this->ctrl->getLinkTarget($this,'codes'),
3448  array("codes", "createSurveyCodes", "setCodeLanguage", "deleteCodes", "exportCodes"),
3449  "");
3450  }
3451  }
3452 
3453  include_once "./Modules/Survey/classes/class.ilObjSurveyAccess.php";
3454  if ($ilAccess->checkAccess("write", "", $this->ref_id) || ilObjSurveyAccess::_hasEvaluationAccess($this->object->getId(), $ilUser->getId()))
3455  {
3456  // evaluation
3457  $tabs_gui->addTarget("svy_evaluation",
3458  $this->ctrl->getLinkTargetByClass("ilsurveyevaluationgui", "evaluation"),
3459  array("evaluation", "checkEvaluationAccess", "evaluationdetails",
3460  "evaluationuser"),
3461  "");
3462  }
3463 
3464  if ($ilAccess->checkAccess("edit_permission", "", $this->ref_id))
3465  {
3466  // permissions
3467  $tabs_gui->addTarget("perm_settings",
3468  $this->ctrl->getLinkTargetByClass(array(get_class($this),'ilpermissiongui'), "perm"), array("perm","info","owner"), 'ilpermissiongui');
3469  }
3470  }
3471 
3477  function _goto($a_target, $a_access_code = "")
3478  {
3479  global $ilAccess, $ilErr, $lng;
3480  if ($ilAccess->checkAccess("read", "", $a_target))
3481  {
3482  include_once "./Services/Utilities/classes/class.ilUtil.php";
3483  if (strlen($a_access_code))
3484  {
3485  $_SESSION["anonymous_id"] = $a_access_code;
3486  $_GET["baseClass"] = "ilObjSurveyGUI";
3487  $_GET["cmd"] = "infoScreen";
3488  $_GET["ref_id"] = $a_target;
3489  include("ilias.php");
3490  exit;
3491  }
3492  else
3493  {
3494  $_GET["baseClass"] = "ilObjSurveyGUI";
3495  $_GET["cmd"] = "infoScreen";
3496  $_GET["ref_id"] = $a_target;
3497  include("ilias.php");
3498  exit;
3499  }
3500  }
3501  else if ($ilAccess->checkAccess("read", "", ROOT_FOLDER_ID))
3502  {
3503  $_GET["cmd"] = "frameset";
3504  $_GET["target"] = "";
3505  $_GET["ref_id"] = ROOT_FOLDER_ID;
3506  ilUtil::sendFailure(sprintf($lng->txt("msg_no_perm_read_item"),
3507  ilObject::_lookupTitle(ilObject::_lookupObjId($a_target))), true);
3508  include("repository.php");
3509  exit;
3510  }
3511 
3512  $ilErr->raiseError($lng->txt("msg_no_perm_read_lm"), $ilErr->FATAL);
3513  }
3514 
3515 } // END class.ilObjSurveyGUI
3516 ?>