ILIAS  Release_4_1_x_branch Revision 61804
 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 
41 include_once "./classes/class.ilObjectGUI.php";
42 include_once "./Modules/Survey/classes/inc.SurveyConstants.php";
43 
45 {
50  function ilObjSurveyGUI()
51  {
52  global $lng, $ilCtrl;
53 
54  $this->type = "svy";
55  $lng->loadLanguageModule("survey");
56  $this->ctrl =& $ilCtrl;
57  $this->ctrl->saveParameter($this, "ref_id");
58 
59  $this->ilObjectGUI("",$_GET["ref_id"], true, false);
60  }
61 
63  {
64  include_once "./Services/Utilities/classes/class.ilUtil.php";
65  $path = $this->tree->getPathFull($this->object->getRefID());
66  ilUtil::redirect($this->getReturnLocation("cancel","./repository.php?cmd=frameset&ref_id=" . $path[count($path) - 2]["child"]));
67  }
68 
72  function executeCommand()
73  {
74  global $ilAccess, $ilNavigationHistory,$ilCtrl;
75 
76  if ((!$ilAccess->checkAccess("read", "", $_GET["ref_id"])) && (!$ilAccess->checkAccess("visible", "", $_GET["ref_id"])))
77  {
78  global $ilias;
79  $ilias->raiseError($this->lng->txt("permission_denied"), $ilias->error_obj->MESSAGE);
80  }
81  // add entry to navigation history
82  if (!$this->getCreationMode() &&
83  $ilAccess->checkAccess("read", "", $_GET["ref_id"]))
84  {
85  $ilNavigationHistory->addItem($_GET["ref_id"],
86  "ilias.php?baseClass=ilObjSurveyGUI&cmd=infoScreen&ref_id=".$_GET["ref_id"], "svy");
87  }
88 
89  $cmd = $this->ctrl->getCmd("properties");
90 
91  // workaround for bug #6288, needs better solution
92  if ($cmd == "saveTags")
93  {
94  $ilCtrl->setCmdClass("ilinfoscreengui");
95  }
96 
97  $next_class = $this->ctrl->getNextClass($this);
98  $this->ctrl->setReturn($this, "properties");
99  $this->tpl->addCss(ilUtil::getStyleSheetLocation("output", "survey.css", "Modules/Survey"), "screen");
100  $this->prepareOutput();
101  //echo "<br>nextclass:$next_class:cmd:$cmd:qtype=$q_type";
102  switch($next_class)
103  {
104  case "ilinfoscreengui":
105  $this->infoScreen(); // forwards command
106  break;
107  case 'ilmdeditorgui':
108  include_once 'Services/MetaData/classes/class.ilMDEditorGUI.php';
109  $md_gui =& new ilMDEditorGUI($this->object->getId(), 0, $this->object->getType());
110  $md_gui->addObserver($this->object,'MDUpdateListener','General');
111 
112  $this->ctrl->forwardCommand($md_gui);
113  break;
114 
115  case "ilsurveyevaluationgui":
116  include_once("./Modules/Survey/classes/class.ilSurveyEvaluationGUI.php");
117  $eval_gui = new ilSurveyEvaluationGUI($this->object);
118  $ret =& $this->ctrl->forwardCommand($eval_gui);
119  break;
120 
121  case 'ilrepositorysearchgui':
122  include_once('./Services/Search/classes/class.ilRepositorySearchGUI.php');
123  $rep_search =& new ilRepositorySearchGUI();
124  $rep_search->setCallback($this,
125  'inviteUserGroupObject',
126  array(
127  )
128  );
129 
130  // Set tabs
131  $this->ctrl->setReturn($this, 'invite');
132  $ret =& $this->ctrl->forwardCommand($rep_search);
133  $this->tabs_gui->setTabActive('invitation');
134  break;
135 
136  case "ilsurveyexecutiongui":
137  include_once("./Modules/Survey/classes/class.ilSurveyExecutionGUI.php");
138  $exec_gui = new ilSurveyExecutionGUI($this->object);
139  $ret =& $this->ctrl->forwardCommand($exec_gui);
140  break;
141 
142  case 'ilpermissiongui':
143  include_once("Services/AccessControl/classes/class.ilPermissionGUI.php");
144  $perm_gui =& new ilPermissionGUI($this);
145  $ret =& $this->ctrl->forwardCommand($perm_gui);
146  break;
147 
148  case 'ilobjectcopygui':
149  include_once './Services/Object/classes/class.ilObjectCopyGUI.php';
150  $cp = new ilObjectCopyGUI($this);
151  $cp->setType('svy');
152  $this->ctrl->forwardCommand($cp);
153  break;
154 
155 
156  default:
157  $cmd.= "Object";
158  $ret =& $this->$cmd();
159  break;
160  }
161 
162  if (strtolower($_GET["baseClass"]) != "iladministrationgui" &&
163  $this->getCreationMode() != true)
164  {
165  $this->tpl->show();
166  }
167  }
168 
173  function saveObject()
174  {
175  global $rbacadmin;
176 
177  if (!strlen($_POST['Fobject']['title']))
178  {
179  ilUtil::sendFailure($this->lng->txt('title_required'), true);
180  $this->ctrl->setParameter($this, 'new_type', $_GET['new_type']);
181  $this->ctrl->redirect($this, 'create');
182  }
183 
184  // create and insert forum in objecttree
185  $newObj = parent::saveObject();
186  // always send a message
187  ilUtil::sendSuccess($this->lng->txt("object_added"),true);
188  ilUtil::redirect("ilias.php?baseClass=ilObjSurveyGUI&ref_id=".$newObj->getRefId()."&cmd=properties");
189  }
190 
196  function cancelObject($in_rep = false)
197  {
198  ilUtil::redirect("repository.php?cmd=frameset&ref_id=".$_GET["ref_id"]);
199  }
200 
209  {
210  $this->ctrl->redirect($this, "properties");
211  }
212 
220  function handleWriteAccess()
221  {
222  global $ilAccess;
223  if (!$ilAccess->checkAccess("write", "", $this->ref_id))
224  {
225  // allow only write access
226  ilUtil::sendInfo($this->lng->txt("cannot_edit_survey"), TRUE);
227  $this->ctrl->redirect($this, "infoScreen");
228  }
229  }
230 
239  {
240  $hasErrors = $this->propertiesObject(true);
241  if (!$hasErrors)
242  {
243  $result = $this->object->setStatus($_POST['online']);
244  $this->object->setEvaluationAccess($_POST["evaluation_access"]);
245  $this->object->setStartDateEnabled($_POST["enabled_start_date"]);
246  if ($this->object->getStartDateEnabled())
247  {
248  $this->object->setStartDateAndTime($_POST["start_date"]['date'], $_POST["start_date"]['time']);
249  }
250  else
251  {
252  $this->object->setStartDate(null);
253  }
254  $this->object->setEndDateEnabled($_POST["enabled_end_date"]);
255  if ($this->object->getEndDateEnabled())
256  {
257  $this->object->setEndDateAndTime($_POST["end_date"]['date'], $_POST["end_date"]['time']);
258  }
259  else
260  {
261  $this->object->setEndDate(null);
262  }
263 
264  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
265  $introduction = $_POST["introduction"];
266  $this->object->setIntroduction($introduction);
267  $outro = $_POST["outro"];
268  $this->object->setOutro($outro);
269 
270  $hasDatasets = $this->object->_hasDatasets($this->object->getSurveyId());
271  if (!$hasDatasets)
272  {
273  $anonymize = $_POST["anonymization"];
274  if ($anonymize)
275  {
276  if (strcmp($_POST['anonymization_options'], 'anonymize_without_code') == 0) $anonymize = ANONYMIZE_FREEACCESS;
277  }
278  $this->object->setAnonymize($anonymize);
279  }
280  $this->object->setShowQuestionTitles($_POST["show_question_titles"]);
281  $this->object->setMailNotification($_POST['mailnotification']);
282  $this->object->setMailAddresses($_POST['mailaddresses']);
283  $this->object->setMailParticipantData($_POST['mailparticipantdata']);
284  $this->object->saveToDb();
285  if (strcmp($_SESSION["info"], "") != 0)
286  {
287  ilUtil::sendSuccess($_SESSION["info"] . "<br />" . $this->lng->txt("settings_saved"), true);
288  }
289  else
290  {
291  ilUtil::sendSuccess($this->lng->txt("settings_saved"), true);
292  }
293  $this->ctrl->redirect($this, "properties");
294  }
295  }
296 
302  function propertiesObject($checkonly = FALSE)
303  {
304  global $ilAccess;
305 
306  $save = (strcmp($this->ctrl->getCmd(), "saveProperties") == 0) ? TRUE : FALSE;
307 
308  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
309  $form = new ilPropertyFormGUI();
310  $form->setFormAction($this->ctrl->getFormAction($this));
311  $form->setTableWidth("100%");
312  $form->setId("survey_properties");
313 
314  // general properties
315  $header = new ilFormSectionHeaderGUI();
316  $header->setTitle($this->lng->txt("properties"));
317  $form->addItem($header);
318 
319  // online
320  $online = new ilCheckboxInputGUI($this->lng->txt("online"), "online");
321  $online->setValue(1);
322  $online->setChecked($this->object->isOnline());
323  $form->addItem($online);
324 
325  // introduction
326  $intro = new ilTextAreaInputGUI($this->lng->txt("introduction"), "introduction");
327  $intro->setValue($this->object->prepareTextareaOutput($this->object->getIntroduction()));
328  $intro->setRows(10);
329  $intro->setCols(80);
330  $intro->setUseRte(TRUE);
331  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
332  $intro->setRteTags(ilObjAdvancedEditing::_getUsedHTMLTags("survey"));
333  $intro->addPlugin("latex");
334  $intro->addButton("latex");
335  $intro->addPlugin("pastelatex");
336  $intro->setRTESupport($this->object->getId(), "svy", "survey");
337  $form->addItem($intro);
338 
339  // enable start date
340  $enablestartingtime = new ilCheckboxInputGUI($this->lng->txt("start_date"), "enabled_start_date");
341  $enablestartingtime->setValue(1);
342  $enablestartingtime->setOptionTitle($this->lng->txt("enabled"));
343  $enablestartingtime->setChecked($this->object->getStartDateEnabled());
344  // start date
345  $startingtime = new ilDateTimeInputGUI('', 'start_date');
346  $startingtime->setShowDate(true);
347  $startingtime->setShowTime(true);
348  if ($this->object->getStartDateEnabled())
349  {
350  $startingtime->setDate(new ilDate($this->object->getStartDate(), IL_CAL_DATE));
351  }
352  else
353  {
354  $startingtime->setDate(new ilDate(time(), IL_CAL_UNIX));
355  }
356  $enablestartingtime->addSubItem($startingtime);
357  $form->addItem($enablestartingtime);
358 
359  // enable end date
360  $enableendingtime = new ilCheckboxInputGUI($this->lng->txt("end_date"), "enabled_end_date");
361  $enableendingtime->setValue(1);
362  $enableendingtime->setOptionTitle($this->lng->txt("enabled"));
363  $enableendingtime->setChecked($this->object->getEndDateEnabled());
364  // end date
365  $endingtime = new ilDateTimeInputGUI('', 'end_date');
366  $endingtime->setShowDate(true);
367  $endingtime->setShowTime(true);
368  if ($this->object->getEndDateEnabled())
369  {
370  $endingtime->setDate(new ilDate($this->object->getEndDate(), IL_CAL_DATE));
371  }
372  else
373  {
374  $endingtime->setDate(new ilDate(time(), IL_CAL_UNIX));
375  }
376  $enableendingtime->addSubItem($endingtime);
377  $form->addItem($enableendingtime);
378 
379  // anonymization
380  $anonymization = new ilCheckboxInputGUI($this->lng->txt("anonymization"), "anonymization");
381  $hasDatasets = $this->object->_hasDatasets($this->object->getSurveyId());
382  if ($hasDatasets)
383  {
384  $anonymization->setDisabled(true);
385  }
386  $anonymization->setOptionTitle($this->lng->txt("on"));
387  $anonymization->setValue(1);
388  $anonymization->setChecked($this->object->getAnonymize());
389  $anonymization->setInfo($this->lng->txt("anonymize_survey_description"));
390 
391  $anonymization_options = new ilRadioGroupInputGUI('', "anonymization_options");
392  if ($hasDatasets)
393  {
394  $anonymization_options->setDisabled(true);
395  }
396  $anonymization_options->addOption(new ilCheckboxOption($this->lng->txt("anonymize_without_code"), 'anonymize_without_code', ''));
397  $anonymization_options->addOption(new ilCheckboxOption($this->lng->txt("anonymize_with_code"), 'anonymize_with_code', ''));
398  $anonymization_options->setValue(($this->object->isAccessibleWithoutCode()) ? 'anonymize_without_code' : 'anonymize_with_code');
399 
400  $anonymization->addSubItem($anonymization_options);
401  $form->addItem($anonymization);
402 
403  // show question titles
404  $show_question_titles = new ilCheckboxInputGUI('', "show_question_titles");
405  $show_question_titles->setOptionTitle($this->lng->txt("svy_show_questiontitles"));
406  $show_question_titles->setValue(1);
407  $show_question_titles->setChecked($this->object->getShowQuestionTitles());
408  $form->addItem($show_question_titles);
409 
410  // final statement
411  $finalstatement = new ilTextAreaInputGUI($this->lng->txt("outro"), "outro");
412  $finalstatement->setValue($this->object->prepareTextareaOutput($this->object->getOutro()));
413  $finalstatement->setRows(10);
414  $finalstatement->setCols(80);
415  $finalstatement->setUseRte(TRUE);
416  $finalstatement->setRteTags(ilObjAdvancedEditing::_getUsedHTMLTags("survey"));
417  $finalstatement->addPlugin("latex");
418  $finalstatement->addButton("latex");
419  $finalstatement->addPlugin("pastelatex");
420  $finalstatement->setRTESupport($this->object->getId(), "svy", "survey");
421  $form->addItem($finalstatement);
422 
423  // results properties
425  $results->setTitle($this->lng->txt("results"));
426  $form->addItem($results);
427 
428  // evaluation access
429  $evaluation_access = new ilRadioGroupInputGUI($this->lng->txt('evaluation_access'), "evaluation_access");
430  $evaluation_access->setInfo($this->lng->txt('evaluation_access_description'));
431  $evaluation_access->addOption(new ilCheckboxOption($this->lng->txt("evaluation_access_off"), EVALUATION_ACCESS_OFF, ''));
432  $evaluation_access->addOption(new ilCheckboxOption($this->lng->txt("evaluation_access_all"), EVALUATION_ACCESS_ALL, ''));
433  $evaluation_access->addOption(new ilCheckboxOption($this->lng->txt("evaluation_access_participants"), EVALUATION_ACCESS_PARTICIPANTS, ''));
434  $evaluation_access->setValue($this->object->getEvaluationAccess());
435  $form->addItem($evaluation_access);
436 
437  // mail notification
438  $mailnotification = new ilCheckboxInputGUI($this->lng->txt("mailnotification"), "mailnotification");
439  $mailnotification->setOptionTitle($this->lng->txt("activate"));
440  $mailnotification->setValue(1);
441  $mailnotification->setChecked($this->object->getMailNotification());
442 
443  // addresses
444  $mailaddresses = new ilTextInputGUI($this->lng->txt("mailaddresses"), "mailaddresses");
445  $mailaddresses->setValue($this->object->getMailAddresses());
446  $mailaddresses->setSize(80);
447  $mailaddresses->setInfo($this->lng->txt('mailaddresses_info'));
448  $mailaddresses->setRequired(true);
449  if (($save) && !$_POST['mailnotification'])
450  {
451  $mailaddresses->setRequired(false);
452  }
453 
454  // participant data
455  $participantdata = new ilTextAreaInputGUI($this->lng->txt("mailparticipantdata"), "mailparticipantdata");
456  $participantdata->setValue($this->object->getMailParticipantData());
457  $participantdata->setRows(6);
458  $participantdata->setCols(80);
459  $participantdata->setUseRte(false);
460  $participantdata->setInfo($this->lng->txt('mailparticipantdata_info'));
461 
462  $mailnotification->addSubItem($mailaddresses);
463  $mailnotification->addSubItem($participantdata);
464  $form->addItem($mailnotification);
465 
466  if ($ilAccess->checkAccess("write", "", $_GET["ref_id"])) $form->addCommandButton("saveProperties", $this->lng->txt("save"));
467  $errors = false;
468 
469  if ($save)
470  {
471  $errors = !$form->checkInput();
472  $form->setValuesByPost();
473  if (!$errors)
474  {
475  if (($online->getChecked()) && (count($this->object->questions) == 0))
476  {
477  $online->setAlert($this->lng->txt("cannot_switch_to_online_no_questions"));
478  ilUtil::sendFailure($this->lng->txt('form_input_not_valid'));
479  $errors = true;
480  }
481  }
482  if ($errors) $checkonly = false;
483  }
484  $mailaddresses->setRequired(true);
485  if (!$checkonly) $this->tpl->setVariable("ADM_CONTENT", $form->getHTML());
486  return $errors;
487  }
488 
497  {
498  $checked_questions = array();
499  $checked_questionblocks = array();
500  foreach ($_POST as $key => $value)
501  {
502  if (preg_match("/cb_(\d+)/", $key, $matches))
503  {
504  array_push($checked_questions, $matches[1]);
505  }
506  if (preg_match("/cb_qb_(\d+)/", $key, $matches))
507  {
508  array_push($checked_questionblocks, $matches[1]);
509  }
510  }
511  if (count($checked_questions) + count($checked_questionblocks) > 0)
512  {
513  ilUtil::sendQuestion($this->lng->txt("remove_questions"));
514  $this->removeQuestionsForm($checked_questions, $checked_questionblocks);
515  return;
516  }
517  else
518  {
519  ilUtil::sendInfo($this->lng->txt("no_question_selected_for_removal"), true);
520  $this->ctrl->redirect($this, "questions");
521  }
522  }
523 
527  public function insertQuestionsObject()
528  {
529  $inserted_objects = 0;
530  if (is_array($_POST['q_id']))
531  {
532  foreach ($_POST['q_id'] as $question_id)
533  {
534  $this->object->insertQuestion($question_id);
535  $inserted_objects++;
536  }
537  }
538  if ($inserted_objects)
539  {
540  $this->object->saveCompletionStatus();
541  ilUtil::sendSuccess($this->lng->txt("questions_inserted"), true);
542  $this->ctrl->redirect($this, "questions");
543  }
544  else
545  {
546  ilUtil::sendInfo($this->lng->txt("insert_missing_question"), true);
547  $this->ctrl->redirect($this, 'browseForQuestions');
548  }
549  }
550 
554  public function insertQuestionblocksObject()
555  {
556  $inserted_objects = 0;
557  if (is_array($_POST['cb']))
558  {
559  foreach ($_POST['cb'] as $questionblock_id)
560  {
561  $this->object->insertQuestionblock($questionblock_id);
562  $inserted_objects++;
563  }
564  }
565  if ($inserted_objects)
566  {
567  $this->object->saveCompletionStatus();
568  ilUtil::sendSuccess(($inserted_objects == 1) ? $this->lng->txt("questionblock_inserted") : $this->lng->txt("questionblocks_inserted"), true);
569  $this->ctrl->redirect($this, "questions");
570  }
571  else
572  {
573  ilUtil::sendInfo($this->lng->txt("insert_missing_questionblock"), true);
574  $this->ctrl->redirect($this, 'browseForQuestionblocks');
575  }
576  }
577 
581  public function changeDatatypeObject()
582  {
583  global $ilUser;
584  $ilUser->writePref('svy_insert_type', $_POST['datatype']);
585  switch ($_POST["datatype"])
586  {
587  case 0:
588  $this->ctrl->redirect($this, 'browseForQuestionblocks');
589  break;
590  case 1:
591  default:
592  $this->ctrl->redirect($this, 'browseForQuestions');
593  break;
594  }
595  }
596 
601  {
602  include_once "./Modules/Survey/classes/tables/class.ilSurveyQuestionblockbrowserTableGUI.php";
603  $table_gui = new ilSurveyQuestionblockbrowserTableGUI($this, 'browseForQuestionblocks');
604  $table_gui->writeFilterToSession();
605  $this->ctrl->redirect($this, 'browseForQuestionblocks');
606  }
607 
612  {
613  include_once "./Modules/Survey/classes/tables/class.ilSurveyQuestionblockbrowserTableGUI.php";
614  $table_gui = new ilSurveyQuestionblockbrowserTableGUI($this, 'browseForQuestionblocks');
615  $table_gui->resetFilter();
616  $this->ctrl->redirect($this, 'browseForQuestionblocks');
617  }
618 
622  public function browseForQuestionblocksObject($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.ilSurveyQuestionblockbrowserTableGUI.php";
630  $table_gui = new ilSurveyQuestionblockbrowserTableGUI($this, 'browseForQuestionblocks', (($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->getQuestionblocksTable($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_QUESTIONBLOCKS", " 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 
655  public function filterQuestionBrowserObject()
656  {
657  include_once "./Modules/Survey/classes/tables/class.ilSurveyQuestionbrowserTableGUI.php";
658  $table_gui = new ilSurveyQuestionbrowserTableGUI($this, 'browseForQuestions');
659  $table_gui->writeFilterToSession();
660  $this->ctrl->redirect($this, 'browseForQuestions');
661  }
662 
667  {
668  include_once "./Modules/Survey/classes/tables/class.ilSurveyQuestionbrowserTableGUI.php";
669  $table_gui = new ilSurveyQuestionbrowserTableGUI($this, 'browseForQuestions');
670  $table_gui->resetFilter();
671  $this->ctrl->redirect($this, 'browseForQuestions');
672  }
673 
677  public function browseForQuestionsObject($arrFilter = null)
678  {
679  global $rbacsystem;
680  global $ilUser;
681 
683  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_svy_questionbrowser.html", "Modules/Survey");
684  include_once "./Modules/Survey/classes/tables/class.ilSurveyQuestionbrowserTableGUI.php";
685  $table_gui = new ilSurveyQuestionbrowserTableGUI($this, 'browseForQuestions', (($rbacsystem->checkAccess('write', $_GET['ref_id']) ? true : false)));
686  $table_gui->setEditable($rbacsystem->checkAccess('write', $_GET['ref_id']));
687  $arrFilter = array();
688  foreach ($table_gui->getFilterItems() as $item)
689  {
690  if ($item->getValue() !== false)
691  {
692  $arrFilter[$item->getPostVar()] = $item->getValue();
693  }
694  }
695  $data = $this->object->getQuestionsTable($arrFilter);
696  $table_gui->setData($data);
697  $this->tpl->setVariable('TABLE', $table_gui->getHTML());
698 
699  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this, 'changeDatatype'));
700  $this->tpl->setVariable("OPTION_QUESTIONS", $this->lng->txt("questions"));
701  $this->tpl->setVariable("OPTION_QUESTIONBLOCKS", $this->lng->txt("questionblocks"));
702  $this->tpl->setVariable("SELECTED_QUESTIONS", " selected=\"selected\"");
703  $this->tpl->setVariable("TEXT_DATATYPE", $this->lng->txt("display_all_available"));
704  $this->tpl->setVariable("BTN_CHANGE", $this->lng->txt("change"));
705  }
706 
714  function removeQuestionsForm($checked_questions, $checked_questionblocks)
715  {
717  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_svy_remove_questions.html", "Modules/Survey");
718  $colors = array("tblrow1", "tblrow2");
719  $counter = 0;
720  $surveyquestions =& $this->object->getSurveyQuestions();
721  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
722  foreach ($surveyquestions as $question_id => $data)
723  {
724  if (in_array($data["question_id"], $checked_questions) or (in_array($data["questionblock_id"], $checked_questionblocks)))
725  {
726  $this->tpl->setCurrentBlock("row");
727  $this->tpl->setVariable("COLOR_CLASS", $colors[$counter % 2]);
728  $this->tpl->setVariable("TEXT_TITLE", $data["title"]);
729  $this->tpl->setVariable("TEXT_DESCRIPTION", $data["description"]);
730  $this->tpl->setVariable("TEXT_TYPE", SurveyQuestion::_getQuestionTypeName($data["type_tag"]));
731  $this->tpl->setVariable("TEXT_QUESTIONBLOCK", $data["questionblock_title"]);
732  $this->tpl->parseCurrentBlock();
733  $counter++;
734  }
735  }
736  foreach ($checked_questions as $id)
737  {
738  $this->tpl->setCurrentBlock("hidden");
739  $this->tpl->setVariable("HIDDEN_NAME", "id_$id");
740  $this->tpl->setVariable("HIDDEN_VALUE", "$id");
741  $this->tpl->parseCurrentBlock();
742  }
743  foreach ($checked_questionblocks as $id)
744  {
745  $this->tpl->setCurrentBlock("hidden");
746  $this->tpl->setVariable("HIDDEN_NAME", "id_qb_$id");
747  $this->tpl->setVariable("HIDDEN_VALUE", "$id");
748  $this->tpl->parseCurrentBlock();
749  }
750  $this->tpl->setCurrentBlock("adm_content");
751  $this->tpl->setVariable("TEXT_TITLE", $this->lng->txt("title"));
752  $this->tpl->setVariable("TEXT_DESCRIPTION", $this->lng->txt("description"));
753  $this->tpl->setVariable("TEXT_TYPE", $this->lng->txt("question_type"));
754  $this->tpl->setVariable("TEXT_QUESTIONBLOCK", $this->lng->txt("questionblock"));
755  $this->tpl->setVariable("BTN_CONFIRM", $this->lng->txt("confirm"));
756  $this->tpl->setVariable("BTN_CANCEL", $this->lng->txt("cancel"));
757  $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this, "confirmRemoveQuestions"));
758  $this->tpl->parseCurrentBlock();
759  }
760 
761 
768  function defineQuestionblock($questionblock_id = "")
769  {
770  $this->questionsSubtabs("questions");
772  if ($questionblock_id)
773  {
774  $questionblock = $this->object->getQuestionblock($questionblock_id);
775  }
776  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_define_questionblock.html", "Modules/Survey");
777  foreach ($_POST as $key => $value)
778  {
779  if (preg_match("/cb_(\d+)/", $key, $matches))
780  {
781  $this->tpl->setCurrentBlock("hidden");
782  $this->tpl->setVariable("HIDDEN_NAME", "cb_$matches[1]");
783  $this->tpl->setVariable("HIDDEN_VALUE", $matches[1]);
784  $this->tpl->parseCurrentBlock();
785  }
786  }
787  if ($questionblock_id)
788  {
789  $this->tpl->setCurrentBlock("hidden");
790  $this->tpl->setVariable("HIDDEN_NAME", "questionblock_id");
791  $this->tpl->setVariable("HIDDEN_VALUE", $questionblock_id);
792  $this->tpl->parseCurrentBlock();
793  }
794  $this->tpl->setCurrentBlock("adm_content");
795  $this->tpl->setVariable("TEXT_TITLE", $this->lng->txt("title"));
796  if ($questionblock_id)
797  {
798  $this->tpl->setVariable("VALUE_TITLE", $questionblock["title"]);
799  }
800  $this->tpl->setVariable("TXT_QUESTIONTEXT_DESCRIPTION", $this->lng->txt("show_questiontext_description"));
801  $this->tpl->setVariable("TXT_QUESTIONTEXT", $this->lng->txt("show_questiontext"));
802  if (($questionblock["show_questiontext"]) || (strlen($questionblock_id) == 0))
803  {
804  $this->tpl->setVariable("CHECKED_QUESTIONTEXT", " checked=\"checked\"");
805  }
806  $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
807  $this->tpl->setVariable("HEADING_QUESTIONBLOCK", $this->lng->txt("define_questionblock"));
808  $this->tpl->setVariable("SAVE", $this->lng->txt("save"));
809  $this->tpl->setVariable("CANCEL", $this->lng->txt("cancel"));
810  $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this, "saveDefineQuestionblock"));
811  $this->tpl->parseCurrentBlock();
812  }
813 
820  {
821  global $ilUser;
822  $this->questionsSubtabs("questions");
823  $tpl = new ilTemplate("tpl.il_svy_svy_qpl_select.html", TRUE, TRUE, "Modules/Survey");
824  $questionpools =& $this->object->getAvailableQuestionpools(FALSE, TRUE, TRUE, "write");
825  if (count($questionpools))
826  {
827  foreach ($questionpools as $key => $value)
828  {
829  $tpl->setCurrentBlock("option");
830  $tpl->setVariable("VALUE_OPTION", $key);
831  $tpl->setVariable("TEXT_OPTION", $value);
832  $tpl->parseCurrentBlock();
833  }
834  $tpl->setCurrentBlock("selection");
835  $tpl->setVariable("TXT_QPL_SELECT", $this->lng->txt("select_questionpool"));
836  $tpl->parseCurrentBlock();
837  }
838  else
839  {
840  $tpl->setCurrentBlock("selection");
841  $tpl->setVariable("TXT_QPL_ENTER", $this->lng->txt("cat_create_spl"));
842  $tpl->parseCurrentBlock();
843  }
844  $tpl->setVariable("BTN_SUBMIT", $this->lng->txt("submit"));
845  $sel_question_types = (strlen($_POST["sel_question_types"])) ? $_POST["sel_question_types"] : $_GET["sel_question_types"];
846  $this->ctrl->setParameter($this, "sel_question_types", $sel_question_types);
847  $tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this, "executeCreateQuestion"));
848  $tpl->setVariable("BTN_CANCEL", $this->lng->txt("cancel"));
849  $this->tpl->setVariable("ADM_CONTENT", $tpl->get());
850  }
851 
858  {
859  $this->ctrl->redirect($this, "questions");
860  }
861 
868  {
869  if (strlen($_POST["sel_spl"]))
870  {
871  include_once "./Services/Utilities/classes/class.ilUtil.php";
872  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"]);
873  }
874  elseif (strlen($_POST["name_spl"]))
875  {
876  $ref_id = $this->createQuestionPool($_POST["name_spl"]);
877  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"]);
878  }
879  else
880  {
881  ilUtil::sendFailure($this->lng->txt("err_no_pool_name"), true);
882  $this->ctrl->setParameter($this, "sel_question_types", $_GET["sel_question_types"]);
883  $this->ctrl->redirect($this, "createQuestion");
884  }
885  }
886 
893  private function createQuestionPool($name = "dummy")
894  {
895  global $tree;
896  $parent_ref = $tree->getParentId($this->object->getRefId());
897  include_once "./Modules/SurveyQuestionPool/classes/class.ilObjSurveyQuestionPool.php";
898  $qpl = new ilObjSurveyQuestionPool();
899  $qpl->setType("spl");
900  $qpl->setTitle($name);
901  $qpl->setDescription("");
902  $qpl->create();
903  $qpl->createReference();
904  $qpl->putInTree($parent_ref);
905  $qpl->setPermissions($parent_ref);
906  $qpl->setOnline(1); // must be online to be available
907  $qpl->saveToDb();
908  return $qpl->getRefId();
909  }
910 
917  function addHeadingObject($checkonly = false, $question_id = "")
918  {
919  $this->questionsSubtabs("questions");
920 
921  global $ilAccess;
922 
923  $save = (strcmp($this->ctrl->getCmd(), "saveHeading") == 0) ? TRUE : FALSE;
924 
925  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
926  $form = new ilPropertyFormGUI();
927  $form->setFormAction($this->ctrl->getFormAction($this));
928  $form->setTableWidth("100%");
929  $form->setId("survey_heading");
930 
931  // general properties
932  $header = new ilFormSectionHeaderGUI();
933  if ($question_id)
934  {
935  $header->setTitle($this->lng->txt("edit_heading"));
936  }
937  else
938  {
939  $header->setTitle($this->lng->txt("add_heading"));
940  }
941  $form->addItem($header);
942 
943  $survey_questions =& $this->object->getSurveyQuestions();
944 
945  // heading
946  $heading = new ilTextAreaInputGUI($this->lng->txt("heading"), "heading");
947  $heading->setValue($this->object->prepareTextareaOutput(array_key_exists('heading', $_POST) ? $_POST['heading'] : $survey_questions[$question_id]["heading"]));
948  $heading->setRows(10);
949  $heading->setCols(80);
950  $heading->setUseRte(TRUE);
951  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
952  $heading->setRteTags(ilObjAdvancedEditing::_getUsedHTMLTags("survey"));
953  $heading->removePlugin("ibrowser");
954  $heading->setRTESupport($this->object->getId(), "svy", "survey");
955  $heading->setRequired(true);
956  $form->addItem($heading);
957 
958  $insertbefore = new ilSelectInputGUI($this->lng->txt("insert"), "insertbefore");
959  $options = array();
960  foreach ($survey_questions as $key => $value)
961  {
962  $options[$key] = $this->lng->txt("before") . ": \"" . $value["title"] . "\"";
963  }
964  $insertbefore->setOptions($options);
965  $insertbefore->setValue((array_key_exists('insertbefore', $_POST)) ? $_POST['insertbefore'] : $question_id);
966  $insertbefore->setRequired(true);
967  if ($question_id || array_key_exists('insertbefore', $_POST))
968  {
969  $insertbefore->setDisabled(true);
970  }
971  $form->addItem($insertbefore);
972 
973  if ($ilAccess->checkAccess("write", "", $_GET["ref_id"])) $form->addCommandButton("saveHeading", $this->lng->txt("save"));
974  if ($ilAccess->checkAccess("write", "", $_GET["ref_id"])) $form->addCommandButton("cancelHeading", $this->lng->txt("cancel"));
975  $errors = false;
976 
977  if ($save)
978  {
979  $errors = !$form->checkInput();
980  $form->setValuesByPost();
981  if ($errors) $checkonly = false;
982  }
983  if (!$checkonly) $this->tpl->setVariable("ADM_CONTENT", $form->getHTML());
984  return $errors;
985  }
986 
993  {
994  // insert questions from test after confirmation
995  foreach ($_POST as $key => $value) {
996  if (preg_match("/id_(\d+)/", $key, $matches)) {
997  if ($_GET["browsetype"] == 1)
998  {
999  $this->object->insertQuestion($matches[1]);
1000  }
1001  else
1002  {
1003  $this->object->insertQuestionBlock($matches[1]);
1004  }
1005  }
1006  }
1007  $this->object->saveCompletionStatus();
1008  ilUtil::sendSuccess($this->lng->txt("questions_inserted"), true);
1009  $this->ctrl->redirect($this, "questions");
1010  }
1011 
1018  {
1019  $this->ctrl->redirect($this, "questions");
1020  }
1021 
1030  {
1031  $hasErrors = $this->addHeadingObject(true);
1032  if (!$hasErrors)
1033  {
1034  $insertbefore = $_POST["insertbefore"];
1035  if (!$insertbefore)
1036  {
1037  $insertbefore = $_POST["insertbefore_original"];
1038  }
1039  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
1040  $this->object->saveHeading(ilUtil::stripSlashes($_POST["heading"], TRUE, ilObjAdvancedEditing::_getUsedHTMLTagsAsString("survey")), $insertbefore);
1041  $this->ctrl->redirect($this, "questions");
1042  }
1043  }
1044 
1053  {
1054  $this->ctrl->redirect($this, "questions");
1055  }
1056 
1065  {
1066  $this->object->saveHeading("", $_POST["removeheading"]);
1067  $this->ctrl->redirect($this, "questions");
1068  }
1069 
1078  {
1079  $this->ctrl->redirect($this, "questions");
1080  }
1081 
1090  {
1091  ilUtil::sendQuestion($this->lng->txt("confirm_remove_heading"));
1092  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_svy_confirm_removeheading.html", "Modules/Survey");
1093  $this->tpl->setCurrentBlock("adm_content");
1094  $this->tpl->setVariable("BTN_CONFIRM_REMOVE", $this->lng->txt("confirm"));
1095  $this->tpl->setVariable("BTN_CANCEL_REMOVE", $this->lng->txt("cancel"));
1096  $this->tpl->setVariable("REMOVE_HEADING", $_GET["removeheading"]);
1097  $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this, "confirmRemoveHeading"));
1098  $this->tpl->parseCurrentBlock();
1099  }
1100 
1109  {
1110  $checked_questions = array();
1111  $checked_questionblocks = array();
1112  foreach ($_POST as $key => $value)
1113  {
1114  if (preg_match("/id_(\d+)/", $key, $matches))
1115  {
1116  array_push($checked_questions, $matches[1]);
1117  }
1118  if (preg_match("/id_qb_(\d+)/", $key, $matches))
1119  {
1120  array_push($checked_questionblocks, $matches[1]);
1121  }
1122  }
1123  $this->object->removeQuestions($checked_questions, $checked_questionblocks);
1124  $this->object->saveCompletionStatus();
1125  ilUtil::sendSuccess($this->lng->txt("questions_removed"), true);
1126  $this->ctrl->redirect($this, "questions");
1127  }
1128 
1137  {
1138  $this->ctrl->redirect($this, "questions");
1139  }
1140 
1149  {
1150  $questionblock = array();
1151  foreach ($_POST as $key => $value)
1152  {
1153  if (preg_match("/cb_(\d+)/", $key, $matches))
1154  {
1155  array_push($questionblock, $value);
1156  }
1157  }
1158  if (count($questionblock) < 2)
1159  {
1160  ilUtil::sendInfo($this->lng->txt("qpl_define_questionblock_select_missing"), true);
1161  $this->ctrl->redirect($this, "questions");
1162  }
1163  else
1164  {
1165  $this->defineQuestionblock();
1166  return;
1167  }
1168  }
1169 
1174  {
1175  if ($_POST["title"])
1176  {
1177  $show_questiontext = ($_POST["show_questiontext"]) ? 1 : 0;
1178  if ($_POST["questionblock_id"])
1179  {
1180  include_once "./Services/Utilities/classes/class.ilUtil.php";
1181  $this->object->modifyQuestionblock($_POST["questionblock_id"], ilUtil::stripSlashes($_POST["title"]), $show_questiontext);
1182  }
1183  else
1184  {
1185  $questionblock = array();
1186  foreach ($_POST as $key => $value)
1187  {
1188  if (preg_match("/cb_(\d+)/", $key, $matches))
1189  {
1190  array_push($questionblock, $value);
1191  }
1192  }
1193  include_once "./Services/Utilities/classes/class.ilUtil.php";
1194  $this->object->createQuestionblock(ilUtil::stripSlashes($_POST["title"]), $show_questiontext, $questionblock);
1195  }
1196  ilUtil::sendSuccess($this->lng->txt('msg_obj_modified'), true);
1197  $this->ctrl->redirect($this, "questions");
1198  }
1199  else
1200  {
1201  ilUtil::sendInfo($this->lng->txt("enter_questionblock_title"));
1202  $this->defineQuestionblockObject();
1203  return;
1204  }
1205  }
1206 
1210  public function unfoldQuestionblockObject()
1211  {
1212  $unfoldblocks = array();
1213  foreach ($_POST as $key => $value)
1214  {
1215  if (preg_match("/cb_qb_(\d+)/", $key, $matches))
1216  {
1217  array_push($unfoldblocks, $matches[1]);
1218  }
1219  }
1220  if (count($unfoldblocks))
1221  {
1222  ilUtil::sendSuccess($this->lng->txt('msg_obj_modified'), true);
1223  $this->object->unfoldQuestionblocks($unfoldblocks);
1224  }
1225  else
1226  {
1227  ilUtil::sendInfo($this->lng->txt("qpl_unfold_select_none"), true);
1228  }
1229  $this->ctrl->redirect($this, "questions");
1230  }
1231 
1236  {
1237  ilUtil::sendInfo($this->lng->txt('msg_cancel'), true);
1238  $this->ctrl->redirect($this, "questions");
1239  }
1240 
1244  public function moveQuestionsObject()
1245  {
1246  $move_questions = array();
1247  foreach ($_POST as $key => $value)
1248  {
1249  if (preg_match("/cb_(\d+)/", $key, $matches))
1250  {
1251  array_push($move_questions, $matches[1]);
1252  }
1253  if (preg_match("/cb_qb_(\d+)/", $key, $matches))
1254  {
1255  $ids = $this->object->getQuestionblockQuestionIds($matches[1]);
1256  foreach ($ids as $qkey => $qid)
1257  {
1258  array_push($move_questions, $qid);
1259  }
1260  }
1261  }
1262  if (count($move_questions) == 0)
1263  {
1264  ilUtil::sendInfo($this->lng->txt("no_question_selected_for_move"), true);
1265  $this->ctrl->redirect($this, "questions");
1266  }
1267  else
1268  {
1269  $_SESSION["move_questions"] = $move_questions;
1270  ilUtil::sendInfo($this->lng->txt("select_target_position_for_move_question"));
1271  $this->questionsObject();
1272  }
1273  }
1274 
1278  public function insertQuestions($insert_mode)
1279  {
1280  // get all questions to move
1281  $move_questions = $_SESSION["move_questions"];
1282  // get insert point
1283  $insert_id = -1;
1284  foreach ($_POST as $key => $value)
1285  {
1286  if (preg_match("/^cb_(\d+)$/", $key, $matches))
1287  {
1288  if ($insert_id < 0)
1289  {
1290  $insert_id = $matches[1];
1291  }
1292  }
1293  if (preg_match("/^cb_qb_(\d+)$/", $key, $matches))
1294  {
1295  if ($insert_id < 0)
1296  {
1297  $ids =& $this->object->getQuestionblockQuestionIds($matches[1]);
1298  if (count($ids))
1299  {
1300  if ($insert_mode == 0)
1301  {
1302  $insert_id = $ids[0];
1303  }
1304  else if ($insert_mode == 1)
1305  {
1306  $insert_id = $ids[count($ids)-1];
1307  }
1308  }
1309  }
1310  }
1311  }
1312  if ($insert_id <= 0)
1313  {
1314  ilUtil::sendInfo($this->lng->txt("no_target_selected_for_move"), true);
1315  }
1316  else
1317  {
1318  ilUtil::sendSuccess($this->lng->txt('msg_obj_modified'), true);
1319  $this->object->moveQuestions($move_questions, $insert_id, $insert_mode);
1320  }
1321  unset($_SESSION["move_questions"]);
1322  $this->ctrl->redirect($this, "questions");
1323  }
1324 
1329  {
1330  $this->insertQuestions(0);
1331  }
1332 
1336  public function insertQuestionsAfterObject()
1337  {
1338  $this->insertQuestions(1);
1339  }
1340 
1344  public function saveObligatoryObject()
1345  {
1346  $obligatory = array();
1347  foreach ($_POST as $key => $value)
1348  {
1349  if (preg_match("/obligatory_(\d+)/", $key, $matches))
1350  {
1351  $obligatory[$matches[1]] = 1;
1352  }
1353  }
1354  $this->object->setObligatoryStates($obligatory);
1355  ilUtil::sendSuccess($this->lng->txt('msg_obj_modified'), true);
1356  $this->ctrl->redirect($this, "questions");
1357  }
1358 
1362  public function questionsObject()
1363  {
1364  $this->handleWriteAccess();
1365  global $rbacsystem;
1366 
1367  $hasDatasets = $this->object->_hasDatasets($this->object->getSurveyId());
1368  include_once "./Services/Utilities/classes/class.ilUtil.php";
1369  if ((!$rbacsystem->checkAccess("read", $this->ref_id)) && (!$rbacsystem->checkAccess("write", $this->ref_id)))
1370  {
1371  // allow only read and write access
1372  ilUtil::sendInfo($this->lng->txt("cannot_edit_survey"), true);
1373  $path = $this->tree->getPathFull($this->object->getRefID());
1374  ilUtil::redirect($this->getReturnLocation("cancel","./repository.php?cmd=frameset&ref_id=" . $path[count($path) - 2]["child"]));
1375  return;
1376  }
1377 
1378  if ($_GET["new_id"] > 0)
1379  {
1380  // add a question to the survey previous created in a questionpool
1381  $existing = $this->object->getExistingQuestions();
1382  if (!in_array($_GET["new_id"], $existing))
1383  {
1384  $inserted = $this->object->insertQuestion($_GET["new_id"]);
1385  if (!$inserted)
1386  {
1387  ilUtil::sendFailure($this->lng->txt("survey_error_insert_incomplete_question"));
1388  }
1389  }
1390  }
1391 
1392  if ($_GET["eqid"] and $_GET["eqpl"])
1393  {
1394  ilUtil::redirect("ilias.php?baseClass=ilObjSurveyQuestionPoolGUI&ref_id=" . $_GET["eqpl"] . "&cmd=editQuestionForSurvey&calling_survey=".$_GET["ref_id"]."&q_id=" . $_GET["eqid"]);
1395  }
1396 
1397 
1398  $_SESSION["calling_survey"] = $this->object->getRefId();
1399  unset($_SESSION["survey_id"]);
1400 
1401  if ($_GET["editheading"])
1402  {
1403  $this->addHeadingObject(false, $_GET["editheading"]);
1404  return;
1405  }
1406 
1407  if ($_GET["up"] > 0)
1408  {
1409  $this->object->moveUpQuestion($_GET["up"]);
1410  ilUtil::sendSuccess($this->lng->txt('msg_obj_modified'));
1411  }
1412  if ($_GET["down"] > 0)
1413  {
1414  $this->object->moveDownQuestion($_GET["down"]);
1415  ilUtil::sendSuccess($this->lng->txt('msg_obj_modified'));
1416  }
1417  if ($_GET["qbup"] > 0)
1418  {
1419  $this->object->moveUpQuestionblock($_GET["qbup"]);
1420  ilUtil::sendSuccess($this->lng->txt('msg_obj_modified'));
1421  }
1422  if ($_GET["qbdown"] > 0)
1423  {
1424  $this->object->moveDownQuestionblock($_GET["qbdown"]);
1425  ilUtil::sendSuccess($this->lng->txt('msg_obj_modified'));
1426  }
1427 
1428  if ($_GET["removeheading"])
1429  {
1430  $this->confirmRemoveHeadingForm();
1431  return;
1432  }
1433 
1434  if ($_GET["editblock"])
1435  {
1436  $this->defineQuestionblock($_GET["editblock"]);
1437  return;
1438  }
1439 
1440  if ($_GET["add"])
1441  {
1442  // called after a new question was created from a questionpool
1443  $selected_array = array();
1444  array_push($selected_array, $_GET["add"]);
1445  ilUtil::sendQuestion($this->lng->txt("ask_insert_questions"));
1446  $this->insertQuestionsForm($selected_array);
1447  return;
1448  }
1449 
1450  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_svy_questions.html", "Modules/Survey");
1451  $survey_questions =& $this->object->getSurveyQuestions();
1452  $questionpools =& $this->object->getQuestionpoolTitles();
1453  $colors = array("tblrow1", "tblrow2");
1454  $counter = 0;
1455  $title_counter = 0;
1456  $last_color_class = "";
1457  $obligatory = "<img src=\"" . ilUtil::getImagePath("obligatory.gif", "Modules/Survey") . "\" alt=\"" . $this->lng->txt("question_obligatory") . "\" title=\"" . $this->lng->txt("question_obligatory") . "\" />";
1458  include_once "./Modules/SurveyQuestionPool/classes/class.ilObjSurveyQuestionPool.php";
1459  $questiontypes =& ilObjSurveyQuestionPool::_getQuestiontypes();
1460  if (count($survey_questions) > 0)
1461  {
1462  foreach ($survey_questions as $question_id => $data)
1463  {
1464  $title_counter++;
1465  if (($last_questionblock_id > 0) && ($data["questionblock_id"] == 0))
1466  {
1467  $counter++;
1468  }
1469  if (($last_questionblock_id > 0) && ($data["questionblock_id"] > 0) && ($data["questionblock_id"] != $last_questionblock_id))
1470  {
1471  $counter++;
1472  }
1473  if (($data["questionblock_id"] > 0) and ($data["questionblock_id"] != $last_questionblock_id))
1474  {
1475  // add a separator line for the beginning of a question block
1476  $this->tpl->setCurrentBlock("separator");
1477  $this->tpl->setVariable("COLOR_CLASS", $colors[$counter % 2]);
1478  $this->tpl->parseCurrentBlock();
1479  $this->tpl->setCurrentBlock("QTab");
1480  $this->tpl->setVariable("COLOR_CLASS", $colors[$counter % 2]);
1481  $this->tpl->parseCurrentBlock();
1482 
1483  $this->tpl->setCurrentBlock("block");
1484  $this->tpl->setVariable("TYPE_ICON", "<img src=\"" . ilUtil::getImagePath("questionblock.gif", "Modules/Survey") . "\" alt=\"".$this->lng->txt("questionblock_icon")."\" />");
1485  $this->tpl->setVariable("TEXT_QUESTIONBLOCK", $this->lng->txt("questionblock") . ": " . $data["questionblock_title"]);
1486  $this->tpl->setVariable("COLOR_CLASS", $colors[$counter % 2]);
1487  if ($rbacsystem->checkAccess("write", $this->ref_id) and !$hasDatasets)
1488  {
1489  if ($data["question_id"] != $this->object->questions[0])
1490  {
1491  $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>");
1492  }
1493  $akeys = array_keys($survey_questions);
1494  if ($data["questionblock_id"] != $survey_questions[$akeys[count($akeys)-1]]["questionblock_id"])
1495  {
1496  $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>");
1497  }
1498  $this->tpl->setVariable("TEXT_EDIT", $this->lng->txt("edit"));
1499  $this->tpl->setVariable("HREF_EDIT", $this->ctrl->getLinkTarget($this, "questions") . "&editblock=" . $data["questionblock_id"]);
1500  }
1501  $this->tpl->parseCurrentBlock();
1502  $this->tpl->setCurrentBlock("QTab");
1503  $this->tpl->setVariable("QUESTION_ID", "qb_" . $data["questionblock_id"]);
1504  $this->tpl->setVariable("COLOR_CLASS", $colors[$counter % 2]);
1505  $this->tpl->parseCurrentBlock();
1506  }
1507  if (($last_questionblock_id > 0) && ($data["questionblock_id"] == 0))
1508  {
1509  // add a separator line for the end of a question block
1510  $this->tpl->setCurrentBlock("separator");
1511  $this->tpl->setVariable("COLOR_CLASS", $colors[$counter % 2]);
1512  $this->tpl->parseCurrentBlock();
1513  $this->tpl->setCurrentBlock("QTab");
1514  $this->tpl->setVariable("COLOR_CLASS", $colors[$counter % 2]);
1515  $this->tpl->parseCurrentBlock();
1516  }
1517  if ($data["heading"])
1518  {
1519  $this->tpl->setCurrentBlock("heading");
1520  $this->tpl->setVariable("TEXT_HEADING", $data["heading"]);
1521  $this->tpl->setVariable("COLOR_CLASS", $colors[$counter % 2]);
1522  if ($rbacsystem->checkAccess("write", $this->ref_id) and !$hasDatasets)
1523  {
1524  $this->tpl->setVariable("TEXT_EDIT", $this->lng->txt("edit"));
1525  $this->tpl->setVariable("HREF_EDIT", $this->ctrl->getLinkTarget($this, "questions") . "&editheading=" . $data["question_id"]);
1526  $this->tpl->setVariable("TEXT_DELETE", $this->lng->txt("remove"));
1527  $this->tpl->setVariable("HREF_DELETE", $this->ctrl->getLinkTarget($this, "questions") . "&removeheading=" . $data["question_id"]);
1528  }
1529  $this->tpl->parseCurrentBlock();
1530  $this->tpl->setCurrentBlock("QTab");
1531  $this->tpl->setVariable("COLOR_CLASS", $colors[$counter % 2]);
1532  $this->tpl->parseCurrentBlock();
1533  }
1534  if (!$data["questionblock_id"])
1535  {
1536  $this->tpl->setCurrentBlock("checkable");
1537  $this->tpl->setVariable("QUESTION_ID", $data["question_id"]);
1538  $this->tpl->parseCurrentBlock();
1539  }
1540  $this->tpl->setCurrentBlock("QTab");
1541  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
1542  if ($rbacsystem->checkAccess("write", $this->ref_id) and !$hasDatasets)
1543  {
1544  $q_id = $data["question_id"];
1545  $qpl_ref_id = current(ilObject::_getAllReferences($data["obj_fi"]));
1546  $this->tpl->setVariable("QUESTION_TITLE", "$title_counter. <a href=\"" . $this->ctrl->getLinkTarget($this, "questions") . "&eqid=$q_id&eqpl=$qpl_ref_id" . "\">" . $data["title"] . "</a>");
1547  }
1548  else
1549  {
1550  $this->tpl->setVariable("QUESTION_TITLE", "$title_counter. ". $data["title"]);
1551  }
1552  $this->tpl->setVariable("TYPE_ICON", "<img src=\"" . ilUtil::getImagePath("question.gif", "Modules/Survey") . "\" alt=\"".$this->lng->txt("question_icon")."\" />");
1553  if ($rbacsystem->checkAccess("write", $this->ref_id) and !$hasDatasets)
1554  {
1555  $obligatory_checked = "";
1556  if ($data["obligatory"] == 1)
1557  {
1558  $obligatory_checked = " checked=\"checked\"";
1559  }
1560  $this->tpl->setVariable("QUESTION_OBLIGATORY", "<input type=\"checkbox\" name=\"obligatory_" . $data["question_id"] . "\" value=\"1\"$obligatory_checked />");
1561  }
1562  else
1563  {
1564  if ($data["obligatory"] == 1)
1565  {
1566  $this->tpl->setVariable("QUESTION_OBLIGATORY", $obligatory);
1567  }
1568  }
1569  $this->tpl->setVariable("QUESTION_COMMENT", $data["description"]);
1570  if ($rbacsystem->checkAccess("write", $this->ref_id) and !$hasDatasets)
1571  {
1572  if (!$data["questionblock_id"])
1573  {
1574  // up/down buttons for non-questionblock questions
1575  if ($data["question_id"] != $this->object->questions[0])
1576  {
1577  $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>");
1578  }
1579  if ($data["question_id"] != $this->object->questions[count($this->object->questions)-1])
1580  {
1581  $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>");
1582  }
1583  }
1584  else
1585  {
1586  // up/down buttons for questionblock questions
1587  if ($data["questionblock_id"] == $last_questionblock_id)
1588  {
1589  $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>");
1590  }
1591  $tmp_questions = array_keys($survey_questions);
1592  $blockkey = array_search($question_id, $tmp_questions);
1593  if (($blockkey !== FALSE) && ($blockkey < count($tmp_questions)-1))
1594  {
1595  if ($data["questionblock_id"] == $survey_questions[$tmp_questions[$blockkey+1]]["questionblock_id"])
1596  {
1597  $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>");
1598  }
1599  }
1600  }
1601  }
1602  foreach ($questiontypes as $trans => $typedata)
1603  {
1604  if (strcmp($typedata["type_tag"], $data["type_tag"]) == 0)
1605  {
1606  $this->tpl->setVariable("QUESTION_TYPE", $trans);
1607  }
1608  }
1609  $this->tpl->setVariable("QUESTION_AUTHOR", $data["author"]);
1610  $this->tpl->setVariable("COLOR_CLASS", $colors[$counter % 2]);
1611  $last_color_class = $colors[$counter % 2];
1612  if (!$data["questionblock_id"])
1613  {
1614  $counter++;
1615  }
1616  $this->tpl->parseCurrentBlock();
1617  $last_questionblock_id = $data["questionblock_id"];
1618  }
1619 
1620  if ($rbacsystem->checkAccess("write", $this->ref_id) and !$hasDatasets)
1621  {
1622  $this->tpl->setCurrentBlock("selectall");
1623  $this->tpl->setVariable("SELECT_ALL", $this->lng->txt("select_all"));
1624  $this->tpl->setVariable("COLOR_CLASS", $last_color_class);
1625  $this->tpl->parseCurrentBlock();
1626  if (array_key_exists("move_questions", $_SESSION))
1627  {
1628  $this->tpl->setCurrentBlock("move_buttons");
1629  $this->tpl->setVariable("INSERT_BEFORE", $this->lng->txt("insert_before"));
1630  $this->tpl->setVariable("INSERT_AFTER", $this->lng->txt("insert_after"));
1631  $this->tpl->parseCurrentBlock();
1632  }
1633  $this->tpl->setCurrentBlock("QFooter");
1634  $this->tpl->setVariable("ARROW", "<img src=\"" . ilUtil::getImagePath("arrow_downright.gif") . "\" alt=\"".$this->lng->txt("arrow_downright")."\">");
1635  $this->tpl->setVariable("REMOVE", $this->lng->txt("remove_question"));
1636  $this->tpl->setVariable("MOVE", $this->lng->txt("move"));
1637  $this->tpl->setVariable("QUESTIONBLOCK", $this->lng->txt("define_questionblock"));
1638  $this->tpl->setVariable("UNFOLD", $this->lng->txt("unfold"));
1639  $this->tpl->setVariable("SAVE", $this->lng->txt("save_obligatory_state"));
1640  $this->tpl->parseCurrentBlock();
1641  }
1642  }
1643  else
1644  {
1645  $this->tpl->setCurrentBlock("Emptytable");
1646  $this->tpl->setVariable("TEXT_EMPTYTABLE", $this->lng->txt("no_questions_available"));
1647  $this->tpl->parseCurrentBlock();
1648  }
1649  if (($last_questionblock_id > 0))
1650  {
1651  // add a separator line for the end of a question block (if the last question is a questionblock question)
1652  $this->tpl->setCurrentBlock("separator");
1653  $this->tpl->setVariable("COLOR_CLASS", $colors[$counter % 2]);
1654  $this->tpl->parseCurrentBlock();
1655  $this->tpl->setCurrentBlock("QTab");
1656  $this->tpl->setVariable("COLOR_CLASS", $colors[$counter % 2]);
1657  $this->tpl->parseCurrentBlock();
1658  }
1659 
1660  if ($rbacsystem->checkAccess("write", $this->ref_id) and !$hasDatasets)
1661  {
1662  $this->tpl->setCurrentBlock("QTypes");
1663  include_once "./Modules/SurveyQuestionPool/classes/class.ilObjSurveyQuestionPool.php";
1665  foreach ($qtypes as $translation => $data)
1666  {
1667  $this->tpl->setVariable("QUESTION_TYPE_ID", $data["type_tag"]);
1668  $this->tpl->setVariable("QUESTION_TYPE", $translation);
1669  $this->tpl->parseCurrentBlock();
1670  }
1671  $this->tpl->parseCurrentBlock();
1672  }
1673  $this->tpl->setCurrentBlock("adm_content");
1674  $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this, "questions"));
1675  $this->tpl->setVariable("QUESTION_TITLE", $this->lng->txt("title"));
1676  $this->tpl->setVariable("QUESTION_COMMENT", $this->lng->txt("description"));
1677  $this->tpl->setVariable("QUESTION_OBLIGATORY", $this->lng->txt("obligatory"));
1678  $this->tpl->setVariable("QUESTION_SEQUENCE", $this->lng->txt("sequence"));
1679  $this->tpl->setVariable("QUESTION_TYPE", $this->lng->txt("question_type"));
1680  $this->tpl->setVariable("QUESTION_AUTHOR", $this->lng->txt("author"));
1681 
1682  if ($rbacsystem->checkAccess("write", $this->ref_id) and !$hasDatasets)
1683  {
1684  $this->tpl->setVariable("BUTTON_INSERT_QUESTION", $this->lng->txt("browse_for_questions"));
1685  global $ilUser;
1686  $this->tpl->setVariable('BROWSE_COMMAND', ($ilUser->getPref('svy_insert_type') == 1 || strlen($ilUser->getPref('svy_insert_type')) == 0) ? 'browseForQuestions' : 'browseForQuestionblocks');
1687  $this->tpl->setVariable("TEXT_CREATE_NEW", " " . strtolower($this->lng->txt("or")) . " " . $this->lng->txt("create_new"));
1688  $this->tpl->setVariable("BUTTON_CREATE_QUESTION", $this->lng->txt("create"));
1689  $this->tpl->setVariable("HEADING", $this->lng->txt("add_heading"));
1690  }
1691  if ($hasDatasets)
1692  {
1693  ilUtil::sendInfo($this->lng->txt("survey_has_datasets_warning"));
1694  }
1695 
1696  $this->tpl->parseCurrentBlock();
1697  $this->questionsSubtabs("questions");
1698  }
1699 
1707  function evaluationObject()
1708  {
1709  include_once("./Modules/Survey/classes/class.ilSurveyEvaluationGUI.php");
1710  $eval_gui = new ilSurveyEvaluationGUI($this->object);
1711  $this->ctrl->setCmdClass(get_class($eval_gui));
1712  $this->ctrl->redirect($eval_gui, "evaluation");
1713  }
1714 
1718  public function disinviteUserGroupObject()
1719  {
1720  // disinvite users
1721  if (is_array($_POST["user_select"]))
1722  {
1723  foreach ($_POST["user_select"] as $user_id)
1724  {
1725  $this->object->disinviteUser($user_id);
1726  }
1727  }
1728  ilUtil::sendSuccess($this->lng->txt('msg_users_disinvited'), true);
1729  $this->ctrl->redirect($this, "invite");
1730  }
1731 
1735  public function inviteUserGroupObject()
1736  {
1737  $invited = 0;
1738  // add users to invitation
1739  if (is_array($_POST["user"]))
1740  {
1741  foreach ($_POST["user"] as $user_id)
1742  {
1743  $this->object->inviteUser($user_id);
1744  $invited++;
1745  }
1746  }
1747  if ($invited == 0)
1748  {
1749  ilUtil::sendFailure($this->lng->txt('no_user_invited'), TRUE);
1750  }
1751  else
1752  {
1753  ilUtil::sendSuccess(sprintf($this->lng->txt('users_invited'), $invited), TRUE);
1754  }
1755  $this->ctrl->redirect($this, "invite");
1756  }
1757 
1761  public function saveInvitationStatusObject()
1762  {
1763  $mode = $_POST['invitation'];
1764  switch ($mode)
1765  {
1766  case 0:
1767  $this->object->setInvitation(0);
1768  break;
1769  case 1:
1770  $this->object->setInvitation(1);
1771  $this->object->setInvitationMode(0);
1772  break;
1773  case 2:
1774  $this->object->setInvitation(1);
1775  $this->object->setInvitationMode(1);
1776  break;
1777  }
1778  $this->object->saveToDb();
1779  ilUtil::sendSuccess($this->lng->txt('msg_obj_modified'), true);
1780  $this->ctrl->redirect($this, "invite");
1781  }
1782 
1783 
1787  public function inviteObject()
1788  {
1789  global $ilAccess;
1790  global $rbacsystem;
1791  global $ilToolbar;
1792 
1793  if ((!$rbacsystem->checkAccess("visible,invite", $this->ref_id)) && (!$rbacsystem->checkAccess("write", $this->ref_id)))
1794  {
1795  // allow only read and write access
1796  ilUtil::sendInfo($this->lng->txt("cannot_edit_survey"), true);
1797  $path = $this->tree->getPathFull($this->object->getRefID());
1798  include_once "./Services/Utilities/classes/class.ilUtil.php";
1799  ilUtil::redirect($this->getReturnLocation("cancel","./repository.php?cmd=frameset&ref_id=" . $path[count($path) - 2]["child"]));
1800  return;
1801  }
1802 
1803  if ($this->object->getStatus() == STATUS_OFFLINE)
1804  {
1805  ilUtil::sendInfo($this->lng->txt("survey_offline_message"));
1806  return;
1807  }
1808 
1809  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
1810  $form = new ilPropertyFormGUI();
1811  $form->setFormAction($this->ctrl->getFormAction($this));
1812  $form->setTableWidth("500");
1813  $form->setId("invite");
1814 
1815  // invitation
1816  $header = new ilFormSectionHeaderGUI();
1817  $header->setTitle($this->lng->txt("invitation"));
1818  $form->addItem($header);
1819 
1820  // invitation mode
1821  $invitation = new ilRadioGroupInputGUI($this->lng->txt('invitation_mode'), "invitation");
1822  $invitation->setInfo($this->lng->txt('invitation_mode_desc'));
1823  $invitation->addOption(new ilRadioOption($this->lng->txt("invitation_off"), 0, ''));
1824  $surveySetting = new ilSetting("survey");
1825  if ($surveySetting->get("unlimited_invitation"))
1826  {
1827  $invitation->addOption(new ilRadioOption($this->lng->txt("unlimited_users"), 1, ''));
1828  }
1829  $invitation->addOption(new ilRadioOption($this->lng->txt("predefined_users"), 2, ''));
1830  $inv = 0;
1831  if ($this->object->getInvitation())
1832  {
1833  $inv = $this->object->getInvitationMode() + 1;
1834  }
1835  $invitation->setValue($inv);
1836  $form->addItem($invitation);
1837 
1838  $form->addCommandButton("saveInvitationStatus", $this->lng->txt("save"));
1839 
1840  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_svy_invite.html", "Modules/Survey");
1841  $this->tpl->setVariable("INVITATION_TABLE", $form->getHTML());
1842 
1843  if ($this->object->getInvitation() && $this->object->getInvitationMode() == 1)
1844  {
1845  // search button
1846  $ilToolbar->addButton($this->lng->txt("svy_search_users"),
1847  $this->ctrl->getLinkTargetByClass('ilRepositorySearchGUI','start'));
1848 
1849  $this->tpl->setVariable("ADM_CONTENT", $form->getHTML());
1850 
1851  $invited_users = $this->object->getUserData($this->object->getInvitedUsers());
1852  include_once "./Modules/Survey/classes/tables/class.ilSurveyInvitedUsersTableGUI.php";
1853  $table_gui = new ilSurveyInvitedUsersTableGUI($this, 'invite');
1854  $table_gui->setData($invited_users);
1855  $this->tpl->setVariable('TBL_INVITED_USERS', $table_gui->getHTML());
1856  }
1857  }
1858 
1862  public function deleteAllUserDataObject()
1863  {
1864  ilUtil::sendQuestion($this->lng->txt("confirm_delete_all_user_data"));
1865  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_svy_maintenance.html", "Modules/Survey");
1866  $this->tpl->setCurrentBlock("adm_content");
1867  $this->tpl->setVariable("BTN_CONFIRM_DELETE_ALL", $this->lng->txt("confirm"));
1868  $this->tpl->setVariable("BTN_CANCEL_DELETE_ALL", $this->lng->txt("cancel"));
1869  $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this, "deleteAllUserData"));
1870  $this->tpl->parseCurrentBlock();
1871  }
1872 
1877  {
1878  $this->object->deleteAllUserData();
1879  ilUtil::sendSuccess($this->lng->txt("svy_all_user_data_deleted"), true);
1880  $this->ctrl->redirect($this, "maintenance");
1881  }
1882 
1887  {
1888  $this->ctrl->redirect($this, "maintenance");
1889  }
1890 
1895  {
1896  $this->object->removeSelectedSurveyResults($_POST["chbUser"]);
1897  ilUtil::sendSuccess($this->lng->txt("svy_selected_user_data_deleted"), true);
1898  $this->ctrl->redirect($this, "maintenance");
1899  }
1900 
1905  {
1906  ilUtil::sendInfo($this->lng->txt('msg_cancel'), true);
1907  $this->ctrl->redirect($this, "maintenance");
1908  }
1909 
1914  {
1915  $this->handleWriteAccess();
1916 
1917  if (count($_POST["chbUser"]) == 0)
1918  {
1919  ilUtil::sendInfo($this->lng->txt('no_checkbox'), true);
1920  $this->ctrl->redirect($this, "maintenance");
1921  }
1922 
1923  ilUtil::sendQuestion($this->lng->txt("confirm_delete_single_user_data"));
1924  include_once "./Modules/Survey/classes/tables/class.ilSurveyMaintenanceTableGUI.php";
1925  $table_gui = new ilSurveyMaintenanceTableGUI($this, 'maintenance', true);
1926  $total =& $this->object->getSurveyParticipants();
1927  $data = array();
1928  foreach ($total as $user_data)
1929  {
1930  if (in_array($user_data['active_id'], $_POST['chbUser']))
1931  {
1932  $last_access = $this->object->_getLastAccess($user_data["active_id"]);
1933  array_push($data, array(
1934  'id' => $user_data["active_id"],
1935  'name' => $user_data["sortname"],
1936  'login' => $user_data["login"],
1937  'last_access' => $last_access
1938  ));
1939  }
1940  }
1941  $table_gui->setData($data);
1942  $this->tpl->setVariable('ADM_CONTENT', $table_gui->getHTML());
1943  }
1944 
1948  public function maintenanceObject()
1949  {
1950  $this->handleWriteAccess();
1951 
1952  if ($_GET["fill"] > 0)
1953  {
1954  for ($i = 0; $i < $_GET["fill"]; $i++) $this->object->fillSurveyForUser();
1955  }
1956  include_once "./Modules/Survey/classes/tables/class.ilSurveyMaintenanceTableGUI.php";
1957  $table_gui = new ilSurveyMaintenanceTableGUI($this, 'maintenance');
1958  $total =& $this->object->getSurveyParticipants();
1959  $data = array();
1960  foreach ($total as $user_data)
1961  {
1962  $last_access = $this->object->_getLastAccess($user_data["active_id"]);
1963  array_push($data, array(
1964  'id' => $user_data["active_id"],
1965  'name' => $user_data["sortname"],
1966  'login' => $user_data["login"],
1967  'last_access' => $last_access
1968  ));
1969  }
1970  $table_gui->setData($data);
1971  $this->tpl->setVariable('ADM_CONTENT', $table_gui->getHTML());
1972  }
1973 
1979  function importObject()
1980  {
1981  $this->getTemplateFile("import", "svy");
1982  $this->tpl->setCurrentBlock("option_qpl");
1983  include_once("./Modules/Survey/classes/class.ilObjSurvey.php");
1984  $svy = new ilObjSurvey();
1985  $questionpools =& $svy->getAvailableQuestionpools(TRUE, FALSE, TRUE);
1986  if (count($questionpools) == 0)
1987  {
1988  }
1989  else
1990  {
1991  foreach ($questionpools as $key => $value)
1992  {
1993  $this->tpl->setCurrentBlock("option_spl");
1994  $this->tpl->setVariable("OPTION_VALUE", $key);
1995  $this->tpl->setVariable("TXT_OPTION", $value);
1996  $this->tpl->parseCurrentBlock();
1997  }
1998  }
1999  $this->tpl->setVariable("TXT_SELECT_QUESTIONPOOL", $this->lng->txt("select_questionpool"));
2000  $this->tpl->setVariable("OPTION_SELECT_QUESTIONPOOL", $this->lng->txt("select_questionpool_option"));
2001  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this, "import"));
2002  $this->tpl->setVariable("BTN_NAME", "upload");
2003  $this->tpl->setVariable("TXT_UPLOAD", $this->lng->txt("upload"));
2004  $this->tpl->setVariable("TXT_IMPORT_TST", $this->lng->txt("import_tst"));
2005  $this->tpl->setVariable("TXT_SELECT_MODE", $this->lng->txt("select_mode"));
2006  $this->tpl->setVariable("TXT_SELECT_FILE", $this->lng->txt("select_file"));
2007 
2008  }
2009 
2016  function uploadObject($redirect = true)
2017  {
2018  if ($_POST["spl"] < 1)
2019  {
2020  ilUtil::sendInfo($this->lng->txt("svy_select_questionpools"));
2021  $this->importObject();
2022  return;
2023  }
2024  if (strcmp($_FILES["xmldoc"]["tmp_name"], "") == 0)
2025  {
2026  ilUtil::sendInfo($this->lng->txt("svy_select_file_for_import"));
2027  $this->importObject();
2028  return;
2029  }
2030 
2031  include_once("./Modules/Survey/classes/class.ilObjSurvey.php");
2032  $newObj = new ilObjSurvey();
2033  $newObj->setType($_GET["new_type"]);
2034  $newObj->setTitle("dummy");
2035  $newObj->setDescription("dummy");
2036  $newObj->create(true);
2037  $newObj->createReference();
2038  $newObj->putInTree($_GET["ref_id"]);
2039  $newObj->setPermissions($_GET["ref_id"]);
2040  $newObj->notify("new",$_GET["ref_id"],$_GET["parent_non_rbac_id"],$_GET["ref_id"],$newObj->getRefId());
2041  // copy uploaded file to import directory
2042  $error = $newObj->importObject($_FILES["xmldoc"], $_POST["spl"]);
2043  if (strlen($error))
2044  {
2045  $newObj->delete();
2046  $this->ilias->raiseError($error, $this->ilias->error_obj->MESSAGE);
2047  return;
2048  }
2049  else
2050  {
2051  $ref_id = $newObj->getRefId();
2052  }
2053  if ($redirect)
2054  {
2055  include_once "./Services/Utilities/classes/class.ilUtil.php";
2056  ilUtil::redirect($this->getReturnLocation("upload",$this->ctrl->getTargetScript()."?".$this->link_params));
2057  }
2058  return $ref_id;
2059  }
2060 
2064  function createObject()
2065  {
2066  global $rbacsystem;
2067  $new_type = $_POST["new_type"] ? $_POST["new_type"] : $_GET["new_type"];
2068  if (!$rbacsystem->checkAccess("create", $_GET["ref_id"], $new_type))
2069  {
2070  $this->ilias->raiseError($this->lng->txt("permission_denied"),$this->ilias->error_obj->MESSAGE);
2071  }
2072  else
2073  {
2074  $this->getTemplateFile("create", $new_type);
2075 
2076  include_once("./Modules/Survey/classes/class.ilObjSurvey.php");
2077  $svy = new ilObjSurvey();
2078 
2079  $this->fillCloneTemplate('DUPLICATE','svy');
2080  $questionpools =& $svy->getAvailableQuestionpools($use_obj_id = TRUE, $could_be_offline = TRUE, $showPath = TRUE);
2081  if (count($questionpools) > 0)
2082  {
2083  foreach ($questionpools as $key => $value)
2084  {
2085  $this->tpl->setCurrentBlock("option_spl");
2086  $this->tpl->setVariable("OPTION_VALUE", $key);
2087  $this->tpl->setVariable("TXT_OPTION", $value);
2088  if ($_POST["spl"] == $key)
2089  {
2090  $this->tpl->setVariable("OPTION_SELECTED", " selected=\"selected\"");
2091  }
2092  $this->tpl->parseCurrentBlock();
2093  }
2094  }
2095  // fill in saved values in case of error
2096  $data = array();
2097  $data["fields"] = array();
2098  include_once "./Services/Utilities/classes/class.ilUtil.php";
2099  $data["fields"]["title"] = ilUtil::prepareFormOutput($_SESSION["error_post_vars"]["Fobject"]["title"],true);
2100  $data["fields"]["desc"] = ilUtil::prepareFormOutput($_SESSION["error_post_vars"]["Fobject"]["desc"]);
2101 
2102  foreach ($data["fields"] as $key => $val)
2103  {
2104  $this->tpl->setVariable("TXT_".strtoupper($key), $this->lng->txt($key));
2105  $this->tpl->setVariable(strtoupper($key), $val);
2106 
2107  if ($this->prepare_output)
2108  {
2109  $this->tpl->parseCurrentBlock();
2110  }
2111  }
2112 
2113  $this->ctrl->setParameter($this, "new_type", $this->type);
2114  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this, "create"));
2115  $this->tpl->setVariable("TXT_HEADER", $this->lng->txt($new_type."_new"));
2116  $this->tpl->setVariable("TXT_SELECT_QUESTIONPOOL", $this->lng->txt("select_questionpool_short"));
2117  $this->tpl->setVariable("OPTION_SELECT_QUESTIONPOOL", $this->lng->txt("select_questionpool_option"));
2118  $this->tpl->setVariable("TXT_CANCEL", $this->lng->txt("cancel"));
2119  $this->tpl->setVariable("TXT_SUBMIT", $this->lng->txt($new_type."_add"));
2120  $this->tpl->setVariable("CMD_SUBMIT", "save");
2121  $this->tpl->setVariable("TARGET", ' target="'.
2122  ilFrameTargetInfo::_getFrame("MainContent").'" ');
2123  $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
2124 
2125  $this->tpl->setVariable("TXT_IMPORT_SVY", $this->lng->txt("import_svy"));
2126  $this->tpl->setVariable("TXT_SVY_FILE", $this->lng->txt("svy_upload_file"));
2127  $this->tpl->setVariable("TXT_IMPORT", $this->lng->txt("import"));
2128 
2129  $this->tpl->setVariable("TYPE_IMG", ilUtil::getImagePath('icon_svy.gif'));
2130  $this->tpl->setVariable("ALT_IMG",$this->lng->txt("obj_svy"));
2131  $this->tpl->setVariable("TYPE_IMG2", ilUtil::getImagePath('icon_svy.gif'));
2132  $this->tpl->setVariable("ALT_IMG2",$this->lng->txt("obj_svy"));
2133  }
2134  }
2135 
2139  function importFileObject()
2140  {
2141  if ($_POST["spl"] < 1)
2142  {
2143  ilUtil::sendInfo($this->lng->txt("svy_select_questionpools"));
2144  $this->createObject();
2145  return;
2146  }
2147  if (strcmp($_FILES["xmldoc"]["tmp_name"], "") == 0)
2148  {
2149  ilUtil::sendInfo($this->lng->txt("svy_select_file_for_import"));
2150  $this->createObject();
2151  return;
2152  }
2153  $this->ctrl->setParameter($this, "new_type", $this->type);
2154  $ref_id = $this->uploadObject(false);
2155  // always send a message
2156  ilUtil::sendSuccess($this->lng->txt("object_imported"),true);
2157 
2158  ilUtil::redirect("ilias.php?ref_id=".$ref_id.
2159  "&baseClass=ilObjSurveyGUI");
2160 // $this->ctrl->redirect($this, "importFile");
2161  }
2162 
2163  /*
2164  * list all export files
2165  */
2166  public function exportObject()
2167  {
2168  $this->handleWriteAccess();
2169 
2170  $export_dir = $this->object->getExportDirectory();
2171  $export_files = $this->object->getExportFiles($export_dir);
2172  $data = array();
2173  if(count($export_files) > 0)
2174  {
2175  foreach($export_files as $exp_file)
2176  {
2177  $file_arr = explode("__", $exp_file);
2178  $date = new ilDateTime($file_arr[0], IL_CAL_UNIX);
2179  array_push($data, array(
2180  'file' => $exp_file,
2181  'size' => filesize($export_dir."/".$exp_file),
2182  'date' => $date->get(IL_CAL_DATETIME)
2183  ));
2184  }
2185  }
2186 
2187  include_once "./Modules/Survey/classes/tables/class.ilSurveyExportTableGUI.php";
2188  $table_gui = new ilSurveyExportTableGUI($this, 'export');
2189  $table_gui->setData($data);
2190  $this->tpl->setVariable('ADM_CONTENT', $table_gui->getHTML());
2191  }
2192 
2196  public function createExportFileObject()
2197  {
2198  $this->handleWriteAccess();
2199  include_once("./Modules/Survey/classes/class.ilSurveyExport.php");
2200  $survey_exp = new ilSurveyExport($this->object);
2201  $survey_exp->buildExportFile();
2202  $this->ctrl->redirect($this, "export");
2203  }
2204 
2208  public function downloadExportFileObject()
2209  {
2210  if(!isset($_POST["file"]))
2211  {
2212  ilUtil::sendFailure($this->lng->txt("no_checkbox"), true);
2213  $this->ctrl->redirect($this, "export");
2214  }
2215 
2216  if (count($_POST["file"]) > 1)
2217  {
2218  ilUtil::sendFailure($this->lng->txt("select_max_one_item"), true);
2219  $this->ctrl->redirect($this, "export");
2220  }
2221 
2222 
2223  $export_dir = $this->object->getExportDirectory();
2224  include_once "./Services/Utilities/classes/class.ilUtil.php";
2225  ilUtil::deliverFile($export_dir."/".$_POST["file"][0],
2226  $_POST["file"][0]);
2227  }
2228 
2233  {
2234  $this->handleWriteAccess();
2235 
2236  if (!isset($_POST["file"]))
2237  {
2238  ilUtil::sendFailure($this->lng->txt("no_checkbox"), true);
2239  $this->ctrl->redirect($this, "export");
2240  }
2241 
2242  ilUtil::sendQuestion($this->lng->txt("info_delete_sure"));
2243 
2244  $export_dir = $this->object->getExportDirectory();
2245  $export_files = $this->object->getExportFiles($export_dir);
2246  $data = array();
2247  if (count($_POST["file"]) > 0)
2248  {
2249  foreach ($_POST["file"] as $exp_file)
2250  {
2251  $file_arr = explode("__", $exp_file);
2252  $date = new ilDateTime($file_arr[0], IL_CAL_UNIX);
2253  array_push($data, array(
2254  'file' => $exp_file,
2255  'size' => filesize($export_dir."/".$exp_file),
2256  'date' => $date->get(IL_CAL_DATETIME)
2257  ));
2258  }
2259  }
2260 
2261  include_once "./Modules/Survey/classes/tables/class.ilSurveyExportTableGUI.php";
2262  $table_gui = new ilSurveyExportTableGUI($this, 'export', true);
2263  $table_gui->setData($data);
2264  $this->tpl->setVariable('ADM_CONTENT', $table_gui->getHTML());
2265  }
2266 
2267 
2272  {
2273  ilUtil::sendInfo($this->lng->txt('msg_cancel'), true);
2274  $this->ctrl->redirect($this, "export");
2275  }
2276 
2277 
2281  public function deleteExportFileObject()
2282  {
2283  $export_dir = $this->object->getExportDirectory();
2284  foreach ($_POST["file"] as $file)
2285  {
2286  $exp_file = $export_dir."/".$file;
2287  $exp_dir = $export_dir."/".substr($file, 0, strlen($file) - 4);
2288  if (@is_file($exp_file))
2289  {
2290  unlink($exp_file);
2291  }
2292  if (@is_dir($exp_dir))
2293  {
2294  include_once "./Services/Utilities/classes/class.ilUtil.php";
2295  ilUtil::delDir($exp_dir);
2296  }
2297  }
2298  ilUtil::sendSuccess($this->lng->txt('msg_deleted_export_files'), true);
2299  $this->ctrl->redirect($this, "export");
2300  }
2301 
2305  public function setCodeLanguageObject()
2306  {
2307  if (strcmp($_POST["lang"], "-1") != 0)
2308  {
2309  global $ilUser;
2310  $ilUser->writePref("survey_code_language", $_POST["lang"]);
2311  }
2312  ilUtil::sendSuccess($this->lng->txt('language_changed'), true);
2313  $this->ctrl->redirect($this, 'codes');
2314  }
2315 
2319  public function codesObject()
2320  {
2321  $this->handleWriteAccess();
2322  $this->setCodesSubtabs();
2323  global $ilUser, $ilToolbar;
2324  if ($this->object->getAnonymize() != 1)
2325  {
2326  return ilUtil::sendInfo($this->lng->txt("survey_codes_no_anonymization"));
2327  }
2328 
2329  $default_lang = $ilUser->getPref("survey_code_language");
2330 
2331  // creation buttons
2332  $ilToolbar->setFormAction($this->ctrl->getFormAction($this));
2333  $languages = $this->lng->getInstalledLanguages();
2334  $options = array();
2335  foreach ($languages as $lang)
2336  {
2337  $options[$lang] = $this->lng->txt("lang_$lang");
2338  }
2339  include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
2340  $si = new ilSelectInputGUI($this->lng->txt("survey_codes_lang"), "lang");
2341  $si->setOptions($options);
2342  $si->setValue($default_lang);
2343  $ilToolbar->addInputItem($si, true);
2344  $ilToolbar->addFormButton($this->lng->txt("set"), "setCodeLanguage");
2345 
2346  include_once "./Modules/Survey/classes/tables/class.ilSurveyCodesTableGUI.php";
2347  $table_gui = new ilSurveyCodesTableGUI($this, 'codes');
2348  $survey_codes =& $this->object->getSurveyCodesTableData($default_lang);
2349  $table_gui->setData($survey_codes);
2350  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_svy_codes.html", true);
2351  $this->tpl->setCurrentBlock("adm_content");
2352  $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this, "codes"));
2353  $this->tpl->setVariable("TEXT_CREATE", $this->lng->txt("create"));
2354  $this->tpl->setVariable("TEXT_SURVEY_CODES", $this->lng->txt("new_survey_codes"));
2355  $this->tpl->setVariable('TABLE', $table_gui->getHTML());
2356  }
2357 
2361  public function deleteCodesObject()
2362  {
2363  if (is_array($_POST["chb_code"]) && (count($_POST["chb_code"]) > 0))
2364  {
2365  foreach ($_POST["chb_code"] as $survey_code)
2366  {
2367  $this->object->deleteSurveyCode($survey_code);
2368  }
2369  ilUtil::sendSuccess($this->lng->txt('codes_deleted'), true);
2370  }
2371  else
2372  {
2373  ilUtil::sendInfo($this->lng->txt('no_checkbox'), true);
2374  }
2375  $this->ctrl->redirect($this, 'codes');
2376  }
2377 
2381  public function exportCodesObject()
2382  {
2383  if (is_array($_POST["chb_code"]) && (count($_POST["chb_code"]) > 0))
2384  {
2385  $export = $this->object->getSurveyCodesForExport($_POST["chb_code"]);
2386  ilUtil::deliverData($export, ilUtil::getASCIIFilename($this->object->getTitle() . ".txt"));
2387  }
2388  else
2389  {
2390  ilUtil::sendFailure($this->lng->txt("no_checkbox"), true);
2391  $this->ctrl->redirect($this, 'codes');
2392  }
2393  }
2394 
2398  public function exportAllCodesObject()
2399  {
2400  $export = $this->object->getSurveyCodesForExport(array());
2401  ilUtil::deliverData($export, ilUtil::getASCIIFilename($this->object->getTitle() . ".txt"));
2402  }
2403 
2407  public function createSurveyCodesObject()
2408  {
2409  if (preg_match("/\d+/", $_POST["nrOfCodes"]))
2410  {
2411  $this->object->createSurveyCodes($_POST["nrOfCodes"]);
2412  ilUtil::sendSuccess($this->lng->txt('codes_created'), true);
2413  }
2414  else
2415  {
2416  ilUtil::sendFailure($this->lng->txt("enter_valid_number_of_codes"), true);
2417  }
2418  $this->ctrl->redirect($this, 'codes');
2419  }
2420 
2424  public function codesMailObject($checkonly = false)
2425  {
2426  global $ilAccess;
2427 
2428  $this->handleWriteAccess();
2429  $this->setCodesSubtabs();
2430 
2431  $savefields = (strcmp($this->ctrl->getCmd(), "saveMailTableFields") == 0) ? TRUE : FALSE;
2432 
2433  include_once "./Modules/Survey/classes/tables/class.ilSurveyCodesMailTableGUI.php";
2434  $data = $this->object->getExternalCodeRecipients();
2435  $table_gui = new ilSurveyCodesMailTableGUI($this, 'codesMail');
2436  $table_gui->setData($data);
2437  $table_gui->setTitle($this->lng->txt('externalRecipients'));
2438  $table_gui->completeColumns();
2439  $tabledata = $table_gui->getHTML();
2440 
2441  if (!$checkonly)
2442  {
2443  $this->tpl->setVariable('ADM_CONTENT', $tabledata);
2444  }
2445  return $errors;
2446  }
2447 
2448  public function insertSavedMessageObject()
2449  {
2450  $this->handleWriteAccess();
2451  $this->setCodesSubtabs();
2452 
2453  include_once("./Modules/Survey/classes/forms/FormMailCodesGUI.php");
2454  $form_gui = new FormMailCodesGUI($this);
2455  $form_gui->setValuesByPost();
2456  try
2457  {
2458  if ($form_gui->getSavedMessages()->getValue() > 0)
2459  {
2460  global $ilUser;
2461  $settings = $this->object->getUserSettings($ilUser->getId(), 'savemessage');
2462  $form_gui->getMailMessage()->setValue($settings[$form_gui->getSavedMessages()->getValue()]['value']);
2463  ilUtil::sendSuccess($this->lng->txt('msg_message_inserted'));
2464  }
2465  else
2466  {
2467  ilUtil::sendFailure($this->lng->txt('msg_no_message_inserted'));
2468  }
2469  }
2470  catch (Exception $e)
2471  {
2472  global $ilLog;
2473  $ilLog->write('Error: ' + $e->getMessage());
2474  }
2475  $this->tpl->setVariable("ADM_CONTENT", $form_gui->getHTML());
2476  }
2477 
2478  public function deleteSavedMessageObject()
2479  {
2480  $this->handleWriteAccess();
2481  $this->setCodesSubtabs();
2482 
2483  include_once("./Modules/Survey/classes/forms/FormMailCodesGUI.php");
2484  $form_gui = new FormMailCodesGUI($this);
2485  $form_gui->setValuesByPost();
2486  try
2487  {
2488  if ($form_gui->getSavedMessages()->getValue() > 0)
2489  {
2490  $this->object->deleteUserSettings($form_gui->getSavedMessages()->getValue());
2491  $form_gui = new FormMailCodesGUI($this);
2492  $form_gui->setValuesByPost();
2493  ilUtil::sendSuccess($this->lng->txt('msg_message_deleted'));
2494  }
2495  else
2496  {
2497  ilUtil::sendFailure($this->lng->txt('msg_no_message_deleted'));
2498  }
2499  }
2500  catch (Exception $e)
2501  {
2502  global $ilLog;
2503  $ilLog->write('Error: ' + $e->getMessage());
2504  }
2505  $this->tpl->setVariable("ADM_CONTENT", $form_gui->getHTML());
2506  }
2507 
2508  public function mailCodesObject()
2509  {
2510  $this->handleWriteAccess();
2511  $this->setCodesSubtabs();
2512 
2513  $mailData['m_subject'] = (array_key_exists('m_subject', $_POST)) ? $_POST['m_subject'] : sprintf($this->lng->txt('default_codes_mail_subject'), $this->object->getTitle());
2514  $mailData['m_message'] = (array_key_exists('m_message', $_POST)) ? $_POST['m_message'] : $this->lng->txt('default_codes_mail_message');
2515  $mailData['m_notsent'] = (array_key_exists('m_notsent', $_POST)) ? $_POST['m_notsent'] : '1';
2516 
2517  include_once("./Modules/Survey/classes/forms/FormMailCodesGUI.php");
2518  $form_gui = new FormMailCodesGUI($this);
2519  $form_gui->setValuesByArray($mailData);
2520  $this->tpl->setVariable("ADM_CONTENT", $form_gui->getHTML());
2521  }
2522 
2523  public function sendCodesMailObject()
2524  {
2525  $this->handleWriteAccess();
2526  $this->setCodesSubtabs();
2527 
2528  include_once("./Modules/Survey/classes/forms/FormMailCodesGUI.php");
2529  $form_gui = new FormMailCodesGUI($this);
2530  if ($form_gui->checkInput())
2531  {
2532  $code_exists = strpos($_POST['m_message'], '[code]') !== FALSE;
2533  if (!$code_exists)
2534  {
2535  if (!$code_exists) ilUtil::sendFailure($this->lng->txt('please_enter_mail_code'));
2536  $form_gui->setValuesByPost();
2537  }
2538  else
2539  {
2540  if ($_POST['savemessage'] == 1)
2541  {
2542  global $ilUser;
2543  $title = (strlen($_POST['savemessagetitle'])) ? $_POST['savemessagetitle'] : ilStr::substr($_POST['m_message'], 0, 40) . '...';
2544  $this->object->saveUserSettings($ilUser->getId(), 'savemessage', $title, $_POST['m_message']);
2545  }
2546  $this->object->sendCodes($_POST['m_notsent'], $_POST['m_subject'], $_POST['m_message']);
2547  ilUtil::sendSuccess($this->lng->txt('mail_sent'), true);
2548  $this->ctrl->redirect($this, 'codesMail');
2549  }
2550  }
2551  else
2552  {
2553  $form_gui->setValuesByPost();
2554  }
2555  $this->tpl->setVariable("ADM_CONTENT", $form_gui->getHTML());
2556  }
2557 
2558  public function cancelCodesMailObject()
2559  {
2560  $this->ctrl->redirect($this, 'codesMail');
2561  }
2562 
2564  {
2565  if (!is_array($_POST['chb_ext']) || count(is_array($_POST['chb_ext'])) == 0)
2566  {
2567  ilUtil::sendInfo($this->lng->txt("err_no_selection"), true);
2568  $this->ctrl->redirect($this, 'codesMail');
2569  }
2570  foreach ($_POST['chb_ext'] as $code)
2571  {
2572  $this->object->deleteSurveyCode($code);
2573  }
2574  ilUtil::sendSuccess($this->lng->txt('external_recipients_deleted'), true);
2575  $this->ctrl->redirect($this, 'codesMail');
2576  }
2577 
2579  {
2580  $hasErrors = $this->importExternalMailRecipientsObject(true, 2);
2581  if (!$hasErrors)
2582  {
2583  $data = array();
2584  $existingdata = $this->object->getExternalCodeRecipients();
2585  if (count($existingdata))
2586  {
2587  $first = array_shift($existingdata);
2588  foreach ($first as $key => $value)
2589  {
2590  if (strcmp($key, 'code') != 0 && strcmp($key, 'sent') != 0)
2591  {
2592  $data[$key] = $_POST[$key];
2593  }
2594  }
2595  }
2596  if (count($data))
2597  {
2598  $this->object->createSurveyCodesForExternalData(array($data));
2599  ilUtil::sendSuccess($this->lng->txt('external_recipients_imported'), true);
2600  }
2601  $this->ctrl->redirect($this, 'codesMail');
2602  }
2603  }
2604 
2606  {
2607  $hasErrors = $this->importExternalMailRecipientsObject(true, 1);
2608  if (!$hasErrors)
2609  {
2610  $data = preg_split("/[\n\r]/", $_POST['externaltext']);
2611  $fields = preg_split("/;/", array_shift($data));
2612  if (!in_array('email', $fields))
2613  {
2614  $_SESSION['externaltext'] = $_POST['externaltext'];
2615  ilUtil::sendFailure($this->lng->txt('err_external_rcp_no_email_column'), true);
2616  $this->ctrl->redirect($this, 'importExternalMailRecipients');
2617  }
2618  $existingdata = $this->object->getExternalCodeRecipients();
2619  $existingcolumns = array();
2620  if (count($existingdata))
2621  {
2622  $first = array_shift($existingdata);
2623  foreach ($first as $key => $value)
2624  {
2625  array_push($existingcolumns, $key);
2626  }
2627  }
2628  $founddata = array();
2629  foreach ($data as $datarow)
2630  {
2631  $row = preg_split("/;/", $datarow);
2632  if (count($row) == count($fields))
2633  {
2634  $dataset = array();
2635  foreach ($fields as $idx => $fieldname)
2636  {
2637  if (count($existingcolumns))
2638  {
2639  if (array_key_exists($idx, $existingcolumns))
2640  {
2641  $dataset[$fieldname] = $row[$idx];
2642  }
2643  }
2644  else
2645  {
2646  $dataset[$fieldname] = $row[$idx];
2647  }
2648  }
2649  if (strlen($dataset['email']))
2650  {
2651  array_push($founddata, $dataset);
2652  }
2653  }
2654  }
2655  $this->object->createSurveyCodesForExternalData($founddata);
2656  ilUtil::sendSuccess($this->lng->txt('external_recipients_imported'), true);
2657  $this->ctrl->redirect($this, 'codesMail');
2658  }
2659  }
2660 
2662  {
2663  $hasErrors = $this->importExternalMailRecipientsObject(true, 0);
2664  if (!$hasErrors)
2665  {
2666  include_once "./Services/Utilities/classes/class.ilCSVReader.php";
2667  $reader = new ilCSVReader();
2668  $reader->open($_FILES['externalmails']['tmp_name']);
2669  $data = $reader->getDataArrayFromCSVFile();
2670  $fields = array_shift($data);
2671  if (!in_array('email', $fields))
2672  {
2673  $reader->close();
2674  ilUtil::sendFailure($this->lng->txt('err_external_rcp_no_email'), true);
2675  $this->ctrl->redirect($this, 'codesMail');
2676  }
2677  $existingdata = $this->object->getExternalCodeRecipients();
2678  $existingcolumns = array();
2679  if (count($existingdata))
2680  {
2681  $first = array_shift($existingdata);
2682  foreach ($first as $key => $value)
2683  {
2684  array_push($existingcolumns, $key);
2685  }
2686  }
2687  $founddata = array();
2688  foreach ($data as $row)
2689  {
2690  if (count($row) == count($fields))
2691  {
2692  $dataset = array();
2693  foreach ($fields as $idx => $fieldname)
2694  {
2695  if (count($existingcolumns))
2696  {
2697  if (array_key_exists($idx, $existingcolumns))
2698  {
2699  $dataset[$fieldname] = $row[$idx];
2700  }
2701  }
2702  else
2703  {
2704  $dataset[$fieldname] = $row[$idx];
2705  }
2706  }
2707  if (strlen($dataset['email']))
2708  {
2709  array_push($founddata, $dataset);
2710  }
2711  }
2712  }
2713  $reader->close();
2714  $this->object->createSurveyCodesForExternalData($founddata);
2715  ilUtil::sendSuccess($this->lng->txt('external_recipients_imported'), true);
2716  $this->ctrl->redirect($this, 'codesMail');
2717  }
2718  }
2719 
2720  function importExternalMailRecipientsObject($checkonly = false, $formindex = -1)
2721  {
2722  global $ilAccess;
2723 
2724  $this->handleWriteAccess();
2725  $this->setCodesSubtabs();
2726 
2727  $savefields = (
2728  strcmp($this->ctrl->getCmd(), "importExternalRecipientsFromFile") == 0 ||
2729  strcmp($this->ctrl->getCmd(), "importExternalRecipientsFromText") == 0 ||
2730  strcmp($this->ctrl->getCmd(), "importExternalRecipientsFromDataset") == 0
2731  ) ? TRUE : FALSE;
2732 
2733  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
2734  $form_import_file = new ilPropertyFormGUI();
2735  $form_import_file->setFormAction($this->ctrl->getFormAction($this));
2736  $form_import_file->setTableWidth("100%");
2737  $form_import_file->setId("codes_import_file");
2738 
2739  $headerfile = new ilFormSectionHeaderGUI();
2740  $headerfile->setTitle($this->lng->txt("import_from_file"));
2741  $form_import_file->addItem($headerfile);
2742 
2743  $externalmails = new ilFileInputGUI($this->lng->txt("externalmails"), "externalmails");
2744  $externalmails->setInfo($this->lng->txt('externalmails_info'));
2745  $externalmails->setRequired(true);
2746  $form_import_file->addItem($externalmails);
2747  if ($ilAccess->checkAccess("write", "", $_GET["ref_id"])) $form_import_file->addCommandButton("importExternalRecipientsFromFile", $this->lng->txt("import"));
2748  if ($ilAccess->checkAccess("write", "", $_GET["ref_id"])) $form_import_file->addCommandButton("codesMail", $this->lng->txt("cancel"));
2749 
2750  // import text
2751 
2752  $form_import_text = new ilPropertyFormGUI();
2753  $form_import_text->setFormAction($this->ctrl->getFormAction($this));
2754  $form_import_text->setTableWidth("100%");
2755  $form_import_text->setId("codes_import_text");
2756 
2757  $headertext = new ilFormSectionHeaderGUI();
2758  $headertext->setTitle($this->lng->txt("import_from_text"));
2759  $form_import_text->addItem($headertext);
2760 
2761  $inp = new ilTextAreaInputGUI($this->lng->txt('externaltext'), 'externaltext');
2762  if (array_key_exists('externaltext', $_SESSION) && strlen($_SESSION['externaltext']))
2763  {
2764  $inp->setValue($_SESSION['externaltext']);
2765  }
2766  else
2767  {
2768  $inp->setValue($this->lng->txt('mail_import_example1') . "\n" . $this->lng->txt('mail_import_example2') . "\n" . $this->lng->txt('mail_import_example3') . "\n");
2769  }
2770  $inp->setRequired(true);
2771  $inp->setCols(80);
2772  $inp->setRows(10);
2773  $inp->setInfo($this->lng->txt('externaltext_info'));
2774  $form_import_text->addItem($inp);
2775  unset($_SESSION['externaltext']);
2776 
2777  if ($ilAccess->checkAccess("write", "", $_GET["ref_id"])) $form_import_text->addCommandButton("importExternalRecipientsFromText", $this->lng->txt("import"));
2778  if ($ilAccess->checkAccess("write", "", $_GET["ref_id"])) $form_import_text->addCommandButton("codesMail", $this->lng->txt("cancel"));
2779 
2780  // import dataset
2781 
2782  $form_import_dataset = new ilPropertyFormGUI();
2783  $form_import_dataset->setFormAction($this->ctrl->getFormAction($this));
2784  $form_import_dataset->setTableWidth("100%");
2785  $form_import_dataset->setId("codes_import_dataset");
2786 
2787  $headerfile = new ilFormSectionHeaderGUI();
2788  $headerfile->setTitle($this->lng->txt("import_from_dataset"));
2789  $form_import_dataset->addItem($headerfile);
2790 
2791  $existingdata = $this->object->getExternalCodeRecipients();
2792  $existingcolumns = array('email');
2793  if (count($existingdata))
2794  {
2795  $first = array_shift($existingdata);
2796  foreach ($first as $key => $value)
2797  {
2798  if (strcmp($key, 'email') != 0 && strcmp($key, 'code') != 0 && strcmp($key, 'sent') != 0)
2799  {
2800  array_push($existingcolumns, $key);
2801  }
2802  }
2803  }
2804 
2805  foreach ($existingcolumns as $column)
2806  {
2807  $inp = new ilTextInputGUI($column, $column);
2808  $inp->setSize(50);
2809  if (strcmp($column, 'email') == 0)
2810  {
2811  $inp->setRequired(true);
2812  }
2813  else
2814  {
2815  $inp->setRequired(false);
2816  }
2817  $form_import_dataset->addItem($inp);
2818  }
2819  if ($ilAccess->checkAccess("write", "", $_GET["ref_id"])) $form_import_dataset->addCommandButton("importExternalRecipientsFromDataset", $this->lng->txt("import"));
2820  if ($ilAccess->checkAccess("write", "", $_GET["ref_id"])) $form_import_dataset->addCommandButton("codesMail", $this->lng->txt("cancel"));
2821 
2822  $errors = false;
2823 
2824  if ($savefields)
2825  {
2826  switch ($formindex)
2827  {
2828  case 0:
2829  $errors = !$form_import_file->checkInput();
2830  $form_import_file->setValuesByPost();
2831  if ($errors) $checkonly = false;
2832  break;
2833  case 1:
2834  $errors = !$form_import_text->checkInput();
2835  $form_import_text->setValuesByPost();
2836  if ($errors) $checkonly = false;
2837  break;
2838  case 2:
2839  $errors = !$form_import_dataset->checkInput();
2840  $form_import_dataset->setValuesByPost();
2841  if ($errors) $checkonly = false;
2842  break;
2843  }
2844  }
2845 
2846  if (!$checkonly)
2847  {
2848  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_external_mail.html", "Modules/Survey");
2849  $this->tpl->setVariable("HEADLINE", $this->lng->txt("external_mails_import"));
2850  $this->tpl->setVariable("FORM1", $form_import_file->getHTML());
2851  $this->tpl->setVariable("FORM2", $form_import_text->getHTML());
2852  $this->tpl->setVariable("FORM3", $form_import_dataset->getHTML());
2853  }
2854  return $errors;
2855  }
2856 
2860  public function constraintsAddObject()
2861  {
2862  if (strlen($_POST["v"]) == 0)
2863  {
2864  ilUtil::sendFailure($this->lng->txt("msg_enter_value_for_valid_constraint"));
2865  return $this->constraintStep3Object();
2866  }
2867  $survey_questions =& $this->object->getSurveyQuestions();
2868  $structure =& $_SESSION["constraintstructure"];
2869  $include_elements = $_SESSION["includeElements"];
2870  foreach ($include_elements as $elementCounter)
2871  {
2872  if (is_array($structure[$elementCounter]))
2873  {
2874  if (strlen($_GET["precondition"]))
2875  {
2876  $this->object->updateConstraint($_GET['precondition'], $_POST["q"], $_POST["r"], $_POST["v"], $_POST['c']);
2877  }
2878  else
2879  {
2880  $constraint_id = $this->object->addConstraint($_POST["q"], $_POST["r"], $_POST["v"], $_POST['c']);
2881  foreach ($structure[$elementCounter] as $key => $question_id)
2882  {
2883  $this->object->addConstraintToQuestion($question_id, $constraint_id);
2884  }
2885  }
2886  if (count($structure[$elementCounter]) > 1)
2887  {
2888  $this->object->updateConjunctionForQuestions($structure[$elementCounter], $_POST['c']);
2889  }
2890  }
2891  }
2892  unset($_SESSION["includeElements"]);
2893  unset($_SESSION["constraintstructure"]);
2894  $this->ctrl->redirect($this, "constraints");
2895  }
2896 
2900  public function constraintStep1Object()
2901  {
2902  $survey_questions =& $this->object->getSurveyQuestions();
2903  $structure =& $_SESSION["constraintstructure"];
2904  $start = $_GET["start"];
2905  $option_questions = array();
2906  for ($i = 1; $i < $start; $i++)
2907  {
2908  if (is_array($structure[$i]))
2909  {
2910  foreach ($structure[$i] as $key => $question_id)
2911  {
2912  if ($survey_questions[$question_id]["usableForPrecondition"])
2913  {
2914  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"]));
2915  }
2916  }
2917  }
2918  }
2919  if (count($option_questions) == 0)
2920  {
2921  unset($_SESSION["includeElements"]);
2922  unset($_SESSION["constraintstructure"]);
2923  ilUtil::sendInfo($this->lng->txt("constraints_no_nonessay_available"), true);
2924  $this->ctrl->redirect($this, "constraints");
2925  }
2926  $this->constraintForm(1, $_POST, $survey_questions, $option_questions);
2927  }
2928 
2932  public function constraintStep2Object()
2933  {
2934  $survey_questions =& $this->object->getSurveyQuestions();
2935  $option_questions = array();
2936  array_push($option_questions, array("question_id" => $_POST["q"], "title" => $survey_questions[$_POST["q"]]["title"], "type_tag" => $survey_questions[$_POST["q"]]["type_tag"]));
2937  $this->constraintForm(2, $_POST, $survey_questions, $option_questions);
2938  }
2939 
2943  public function constraintStep3Object()
2944  {
2945  $survey_questions =& $this->object->getSurveyQuestions();
2946  $option_questions = array();
2947  if (strlen($_GET["precondition"]))
2948  {
2949  $pc = $this->object->getPrecondition($_GET["precondition"]);
2950  $postvalues = array(
2951  "c" => $pc["conjunction"],
2952  "q" => $pc["question_fi"],
2953  "r" => $pc["relation_id"],
2954  "v" => $pc["value"]
2955  );
2956  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"]));
2957  $this->constraintForm(3, $postvalues, $survey_questions, $option_questions);
2958  }
2959  else
2960  {
2961  array_push($option_questions, array("question_id" => $_POST["q"], "title" => $survey_questions[$_POST["q"]]["title"], "type_tag" => $survey_questions[$_POST["q"]]["type_tag"]));
2962  $this->constraintForm(3, $_POST, $survey_questions, $option_questions);
2963  }
2964  }
2965 
2966  public function constraintForm($step, $postvalues, &$survey_questions, $questions = FALSE)
2967  {
2968  if (strlen($_GET["start"])) $this->ctrl->setParameter($this, "start", $_GET["start"]);
2969  $this->ctrl->saveParameter($this, "precondition");
2970  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
2971  $form = new ilPropertyFormGUI();
2972  $form->setFormAction($this->ctrl->getFormAction($this));
2973  $form->setTableWidth("100%");
2974  $form->setId("constraintsForm");
2975 
2976  $title = "";
2977  if ($survey_questions[$_SESSION["constraintstructure"][$_GET["start"]][0]]["questionblock_id"] > 0)
2978  {
2979  $title = $this->lng->txt("questionblock") . ": " . $survey_questions[$_SESSION["constraintstructure"][$_GET["start"]][0]]["questionblock_title"];
2980  }
2981  else
2982  {
2983  $title = $this->lng->txt($survey_questions[$_SESSION["constraintstructure"][$_GET["start"]][0]]["type_tag"]) . ": " . $survey_questions[$_SESSION["constraintstructure"][$_GET["start"]][0]]["title"];
2984  }
2985  $header = new ilFormSectionHeaderGUI();
2986  $header->setTitle($title);
2987  $form->addItem($header);
2988 
2989  $fulfilled = new ilRadioGroupInputGUI($this->lng->txt("constraint_fulfilled"), "c");
2990  $fulfilled->addOption(new ilRadioOption($this->lng->txt("conjunction_and"), '0', ''));
2991  $fulfilled->addOption(new ilRadioOption($this->lng->txt("conjunction_or"), '1', ''));
2992  $fulfilled->setValue((strlen($postvalues['c'])) ? $postvalues['c'] : 0);
2993  $form->addItem($fulfilled);
2994 
2995  $step1 = new ilSelectInputGUI($this->lng->txt("step") . " 1: " . $this->lng->txt("select_prior_question"), "q");
2996  $options = array();
2997  if (is_array($questions))
2998  {
2999  foreach ($questions as $question)
3000  {
3001  $options[$question["question_id"]] = $question["title"] . " (" . SurveyQuestion::_getQuestionTypeName($question["type_tag"]) . ")";
3002  }
3003  }
3004  $step1->setOptions($options);
3005  $step1->setValue($postvalues["q"]);
3006  $form->addItem($step1);
3007 
3008  if ($step > 1)
3009  {
3010  $relations = $this->object->getAllRelations();
3011  $step2 = new ilSelectInputGUI($this->lng->txt("step") . " 2: " . $this->lng->txt("select_relation"), "r");
3012  $options = array();
3013  foreach ($relations as $rel_id => $relation)
3014  {
3015  if (in_array($relation["short"], $survey_questions[$postvalues["q"]]["availableRelations"]))
3016  {
3017  $options[$rel_id] = $relation['short'];
3018  }
3019  }
3020  $step2->setOptions($options);
3021  $step2->setValue($postvalues["r"]);
3022  $form->addItem($step2);
3023  }
3024 
3025  if ($step > 2)
3026  {
3027  $variables =& $this->object->getVariables($postvalues["q"]);
3028  $question_type = $survey_questions[$postvalues["q"]]["type_tag"];
3029  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
3030  SurveyQuestion::_includeClass($question_type);
3031  $question = new $question_type();
3032  $question->loadFromDb($postvalues["q"]);
3033 
3034  $step3 = $question->getPreconditionSelectValue($postvalues["v"], $this->lng->txt("step") . " 3: " . $this->lng->txt("select_value"), "v");
3035  $form->addItem($step3);
3036  }
3037 
3038  switch ($step)
3039  {
3040  case 1:
3041  $cmd_continue = "constraintStep2";
3042  $cmd_back = "constraints";
3043  break;
3044  case 2:
3045  $cmd_continue = "constraintStep3";
3046  $cmd_back = "constraintStep1";
3047  break;
3048  case 3:
3049  $cmd_continue = "constraintsAdd";
3050  $cmd_back = "constraintStep2";
3051  break;
3052  }
3053  $form->addCommandButton($cmd_back, $this->lng->txt("back"));
3054  $form->addCommandButton($cmd_continue, $this->lng->txt("continue"));
3055 
3056  $this->tpl->setVariable("ADM_CONTENT", $form->getHTML());
3057  }
3058 
3062  public function deleteConstraintsObject()
3063  {
3064  $survey_questions =& $this->object->getSurveyQuestions();
3065  $structure =& $_SESSION["constraintstructure"];
3066  foreach ($_POST as $key => $value)
3067  {
3068  if (preg_match("/^constraint_(\d+)_(\d+)/", $key, $matches))
3069  {
3070  $this->object->deleteConstraint($matches[2]);
3071  }
3072  }
3073 
3074  $this->ctrl->redirect($this, "constraints");
3075  }
3076 
3078  {
3079  $include_elements = $_POST["includeElements"];
3080  if ((!is_array($include_elements)) || (count($include_elements) == 0))
3081  {
3082  ilUtil::sendInfo($this->lng->txt("constraints_no_questions_or_questionblocks_selected"), true);
3083  $this->ctrl->redirect($this, "constraints");
3084  }
3085  else if (count($include_elements) >= 1)
3086  {
3087  $_SESSION["includeElements"] = $include_elements;
3088  sort($include_elements, SORT_NUMERIC);
3089  $_GET["start"] = $include_elements[0];
3090  $this->constraintStep1Object();
3091  }
3092  }
3093 
3095  {
3096  $_SESSION["includeElements"] = array($_GET["start"]);
3097  $this->ctrl->setParameter($this, "precondition", $_GET["precondition"]);
3098  $this->ctrl->setParameter($this, "start", $_GET["start"]);
3099  $this->ctrl->redirect($this, "constraintStep3");
3100  }
3101 
3105  public function constraintsObject()
3106  {
3107  $this->handleWriteAccess();
3108 
3109  global $rbacsystem;
3110 
3111  $hasDatasets = $this->object->_hasDatasets($this->object->getSurveyId());
3112  $step = 0;
3113  if (array_key_exists("step", $_GET)) $step = $_GET["step"];
3114  switch ($step)
3115  {
3116  case 1:
3117  $this->constraintStep1Object();
3118  return;
3119  break;
3120  case 2:
3121  return;
3122  break;
3123  case 3:
3124  return;
3125  break;
3126  }
3127 
3128  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_svy_constraints_list.html", "Modules/Survey");
3129  $survey_questions =& $this->object->getSurveyQuestions();
3130  $last_questionblock_title = "";
3131  $counter = 1;
3132  $hasPreconditions = FALSE;
3133  $structure = array();
3134  $colors = array("tblrow1", "tblrow2");
3135  foreach ($survey_questions as $question_id => $data)
3136  {
3137  $title = $data["title"];
3138  $show = true;
3139  if ($data["questionblock_id"] > 0)
3140  {
3141  $title = $data["questionblock_title"];
3142  $type = $this->lng->txt("questionblock");
3143  if (strcmp($title, $last_questionblock_title) != 0)
3144  {
3145  $last_questionblock_title = $title;
3146  $structure[$counter] = array();
3147  array_push($structure[$counter], $data["question_id"]);
3148  }
3149  else
3150  {
3151  array_push($structure[$counter-1], $data["question_id"]);
3152  $show = false;
3153  }
3154  }
3155  else
3156  {
3157  $structure[$counter] = array($data["question_id"]);
3158  $type = $this->lng->txt("question");
3159  }
3160  if ($show)
3161  {
3162  if ($counter == 1)
3163  {
3164  $this->tpl->setCurrentBlock("description");
3165  $this->tpl->setVariable("DESCRIPTION", $this->lng->txt("constraints_first_question_description"));
3166  $this->tpl->parseCurrentBlock();
3167  }
3168  else
3169  {
3170  $constraints =& $this->object->getConstraints($data["question_id"]);
3171  $rowcount = 0;
3172  if (count($constraints))
3173  {
3174  $hasPreconditions = TRUE;
3175  foreach ($constraints as $constraint)
3176  {
3177  $this->tpl->setCurrentBlock("constraint");
3178  $this->tpl->setVariable("SEQUENCE_ID", $counter);
3179  $this->tpl->setVariable("CONSTRAINT_ID", $constraint["id"]);
3180  $this->tpl->setVariable("CONSTRAINT_TEXT", $survey_questions[$constraint["question"]]["title"] . " " . $constraint["short"] . " " . $constraint["valueoutput"]);
3181  $this->tpl->setVariable("TEXT_EDIT_PRECONDITION", $this->lng->txt("edit"));
3182  $this->ctrl->setParameter($this, "precondition", $constraint["id"]);
3183  $this->ctrl->setParameter($this, "start", $counter);
3184  $this->tpl->setVariable("EDIT_PRECONDITION", $this->ctrl->getLinkTarget($this, "editPrecondition"));
3185  $this->ctrl->setParameter($this, "precondition", "");
3186  $this->ctrl->setParameter($this, "start", "");
3187  $this->tpl->parseCurrentBlock();
3188  }
3189  if (count($constraints) > 1)
3190  {
3191  $this->tpl->setCurrentBlock("conjunction");
3192  $this->tpl->setVariable("TEXT_CONJUNCTION", ($constraints[0]['conjunction']) ? $this->lng->txt('conjunction_or_title') : $this->lng->txt('conjunction_and_title'));
3193  $this->tpl->parseCurrentBlock();
3194  }
3195  }
3196  }
3197  if ($counter != 1)
3198  {
3199  $this->tpl->setCurrentBlock("include_elements");
3200  $this->tpl->setVariable("QUESTION_NR", "$counter");
3201  $this->tpl->parseCurrentBlock();
3202  }
3203  $this->tpl->setCurrentBlock("constraint_section");
3204  $this->tpl->setVariable("COLOR_CLASS", $colors[$counter % 2]);
3205  $this->tpl->setVariable("QUESTION_NR", "$counter");
3206  $this->tpl->setVariable("TITLE", "$title");
3207  $icontype = "question.gif";
3208  if ($data["questionblock_id"] > 0)
3209  {
3210  $icontype = "questionblock.gif";
3211  }
3212  $this->tpl->setVariable("TYPE", "$type: ");
3213  include_once "./Services/Utilities/classes/class.ilUtil.php";
3214  $this->tpl->setVariable("ICON_HREF", ilUtil::getImagePath($icontype, "Modules/Survey"));
3215  $this->tpl->setVariable("ICON_ALT", $type);
3216  $this->tpl->parseCurrentBlock();
3217  $counter++;
3218  }
3219  }
3220  if ($rbacsystem->checkAccess("write", $this->ref_id) and !$hasDatasets)
3221  {
3222  if ($hasPreconditions)
3223  {
3224  $this->tpl->setCurrentBlock("selectall_preconditions");
3225  $this->tpl->setVariable("SELECT_ALL_PRECONDITIONS", $this->lng->txt("select_all"));
3226  $this->tpl->parseCurrentBlock();
3227  }
3228  $this->tpl->setCurrentBlock("selectall");
3229  $counter++;
3230  $this->tpl->setVariable("SELECT_ALL", $this->lng->txt("select_all"));
3231  $this->tpl->setVariable("COLOR_CLASS", $colors[$counter % 2]);
3232  $this->tpl->parseCurrentBlock();
3233 
3234  if ($hasPreconditions)
3235  {
3236  $this->tpl->setCurrentBlock("delete_button");
3237  $this->tpl->setVariable("BTN_DELETE", $this->lng->txt("delete"));
3238  include_once "./Services/Utilities/classes/class.ilUtil.php";
3239  $this->tpl->setVariable("ARROW", "<img src=\"" . ilUtil::getImagePath("arrow_downright.gif") . "\" alt=\"".$this->lng->txt("arrow_downright")."\">");
3240  $this->tpl->parseCurrentBlock();
3241  }
3242 
3243  $this->tpl->setCurrentBlock("buttons");
3244  $this->tpl->setVariable("ARROW", "<img src=\"" . ilUtil::getImagePath("arrow_downright.gif") . "\" alt=\"".$this->lng->txt("arrow_downright")."\">");
3245  $this->tpl->setVariable("BTN_CREATE_CONSTRAINTS", $this->lng->txt("constraint_add"));
3246  $this->tpl->parseCurrentBlock();
3247  }
3248  $this->tpl->setCurrentBlock("adm_content");
3249  $this->tpl->setVariable("CONSTRAINTS_INTRODUCTION", $this->lng->txt("constraints_introduction"));
3250  $this->tpl->setVariable("DEFINED_PRECONDITIONS", $this->lng->txt("existing_constraints"));
3251  $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this, "constraints"));
3252  $this->tpl->setVariable("CONSTRAINTS_HEADER", $this->lng->txt("constraints_list_of_entities"));
3253  $this->tpl->parseCurrentBlock();
3254  $_SESSION["constraintstructure"] = $structure;
3255  if ($hasDatasets)
3256  {
3257  ilUtil::sendInfo($this->lng->txt("survey_has_datasets_warning"));
3258  }
3259  }
3260 
3266  function infoScreenObject()
3267  {
3268  $this->ctrl->setCmd("showSummary");
3269  $this->ctrl->setCmdClass("ilinfoscreengui");
3270  $this->infoScreen();
3271  }
3272 
3273  function setNewTemplate()
3274  {
3275  global $tpl;
3276  $tpl = new ilTemplate("tpl.il_svy_svy_main.html", TRUE, TRUE, "Modules/Survey");
3277  // load style sheet depending on user's settings
3278  $location_stylesheet = ilUtil::getStyleSheetLocation();
3279  $tpl->setVariable("LOCATION_STYLESHEET",$location_stylesheet);
3280  $tpl->setVariable("LOCATION_JAVASCRIPT",dirname($location_stylesheet));
3281  }
3282 
3286  function infoScreen()
3287  {
3288  global $ilAccess;
3289  global $ilUser;
3290 
3291  if (!$ilAccess->checkAccess("visible", "", $this->ref_id))
3292  {
3293  $this->ilias->raiseError($this->lng->txt("msg_no_perm_read"),$this->ilias->error_obj->MESSAGE);
3294  }
3295 
3296  include_once("./Services/InfoScreen/classes/class.ilInfoScreenGUI.php");
3297  $info = new ilInfoScreenGUI($this);
3298  include_once "./Modules/Survey/classes/class.ilSurveyExecutionGUI.php";
3299  $output_gui =& new ilSurveyExecutionGUI($this->object);
3300  $info->setFormAction($this->ctrl->getFormAction($output_gui, "infoScreen"));
3301  $info->enablePrivateNotes();
3302  $anonymize_key = NULL;
3303  if ($this->object->getAnonymize() == 1)
3304  {
3305  if ($_SESSION["anonymous_id"][$this->object->getId()])
3306  {
3307  $anonymize_key = $_SESSION["anonymous_id"][$this->object->getId()];
3308  }
3309  else if ($_POST["anonymous_id"])
3310  {
3311  $anonymize_key = $_POST["anonymous_id"];
3312  }
3313  }
3314  $canStart = $this->object->canStartSurvey($anonymize_key);
3315  $showButtons = $canStart["result"];
3316  if (!$showButtons) ilUtil::sendInfo(implode("<br />", $canStart["messages"]));
3317 
3318  if ($showButtons)
3319  {
3320  // output of start/resume buttons for personalized surveys
3321  if (!$this->object->getAnonymize())
3322  {
3323  $survey_started = $this->object->isSurveyStarted($ilUser->getId(), "");
3324  // Anonymous User tries to start a personalized survey
3325  if ($_SESSION["AccountId"] == ANONYMOUS_USER_ID)
3326  {
3327  ilUtil::sendInfo($this->lng->txt("anonymous_with_personalized_survey"));
3328  }
3329  else
3330  {
3331  if ($survey_started === 1)
3332  {
3333  ilUtil::sendInfo($this->lng->txt("already_completed_survey"));
3334  }
3335  elseif ($survey_started === 0)
3336  {
3337  $info->addFormButton("resume", $this->lng->txt("resume_survey"));
3338  }
3339  elseif ($survey_started === FALSE)
3340  {
3341  $info->addFormButton("start", $this->lng->txt("start_survey"));
3342  }
3343  }
3344  }
3345  // output of start/resume buttons for anonymized surveys
3346  else if ($this->object->getAnonymize() && !$this->object->isAccessibleWithoutCode())
3347  {
3348  if (($_SESSION["AccountId"] == ANONYMOUS_USER_ID) && (strlen($_POST["anonymous_id"]) == 0) && (strlen($_SESSION["anonymous_id"][$this->object->getId()]) == 0))
3349  {
3350  $info->setFormAction($this->ctrl->getFormAction($this, "infoScreen"));
3351  $info->addSection($this->lng->txt("anonymization"));
3352  $info->addProperty("", $this->lng->txt("anonymize_anonymous_introduction"));
3353  $info->addPropertyTextinput($this->lng->txt("enter_anonymous_id"), "anonymous_id", "", 8, "infoScreen", $this->lng->txt("submit"));
3354  }
3355  else
3356  {
3357  if (strlen($_POST["anonymous_id"]) > 0)
3358  {
3359  if (!$this->object->checkSurveyCode($_POST["anonymous_id"]))
3360  {
3361  ilUtil::sendInfo($this->lng->txt("wrong_survey_code_used"));
3362  }
3363  else
3364  {
3365  $anonymize_key = $_POST["anonymous_id"];
3366  }
3367  }
3368  else if (strlen($_SESSION["anonymous_id"][$this->object->getId()]) > 0)
3369  {
3370  if (!$this->object->checkSurveyCode($_SESSION["anonymous_id"][$this->object->getId()]))
3371  {
3372  ilUtil::sendInfo($this->lng->txt("wrong_survey_code_used"));
3373  }
3374  else
3375  {
3376  $anonymize_key = $_SESSION["anonymous_id"][$this->object->getId()];
3377  }
3378  }
3379  else
3380  {
3381  // registered users do not need to know that there is an anonymous key. The data is anonymized automatically
3382  $anonymize_key = $this->object->getUserAccessCode($ilUser->getId());
3383  if (!strlen($anonymize_key))
3384  {
3385  $anonymize_key = $this->object->createNewAccessCode();
3386  $this->object->saveUserAccessCode($ilUser->getId(), $anonymize_key);
3387  }
3388  }
3389  $info->addHiddenElement("anonymous_id", $anonymize_key);
3390  $survey_started = $this->object->isSurveyStarted($ilUser->getId(), $anonymize_key);
3391  if ($survey_started === 1)
3392  {
3393  ilUtil::sendInfo($this->lng->txt("already_completed_survey"));
3394  }
3395  elseif ($survey_started === 0)
3396  {
3397  $info->addFormButton("resume", $this->lng->txt("resume_survey"));
3398  }
3399  elseif ($survey_started === FALSE)
3400  {
3401  $info->addFormButton("start", $this->lng->txt("start_survey"));
3402  }
3403  }
3404  }
3405  else
3406  {
3407  // free access
3408  $survey_started = $this->object->isSurveyStarted($ilUser->getId(), "");
3409  if ($survey_started === 1)
3410  {
3411  ilUtil::sendInfo($this->lng->txt("already_completed_survey"));
3412  }
3413  elseif ($survey_started === 0)
3414  {
3415  $info->addFormButton("resume", $this->lng->txt("resume_survey"));
3416  }
3417  elseif ($survey_started === FALSE)
3418  {
3419  $info->addFormButton("start", $this->lng->txt("start_survey"));
3420  }
3421  }
3422  }
3423 
3424  if (strlen($this->object->getIntroduction()))
3425  {
3426  $introduction = $this->object->getIntroduction();
3427  $info->addSection($this->lng->txt("introduction"));
3428  $info->addProperty("", $this->object->prepareTextareaOutput($introduction));
3429  }
3430 
3431  $info->addSection($this->lng->txt("svy_general_properties"));
3432  if (strlen($this->object->getAuthor()))
3433  {
3434  $info->addProperty($this->lng->txt("author"), $this->object->getAuthor());
3435  }
3436  $info->addProperty($this->lng->txt("title"), $this->object->getTitle());
3437  switch ($this->object->getAnonymize())
3438  {
3439  case ANONYMIZE_OFF:
3440  $info->addProperty($this->lng->txt("anonymization"), $this->lng->txt("anonymize_personalized"));
3441  break;
3442  case ANONYMIZE_ON:
3443  if ($_SESSION["AccountId"] == ANONYMOUS_USER_ID)
3444  {
3445  $info->addProperty($this->lng->txt("anonymization"), $this->lng->txt("info_anonymize_with_code"));
3446  }
3447  else
3448  {
3449  $info->addProperty($this->lng->txt("anonymization"), $this->lng->txt("info_anonymize_registered_user"));
3450  }
3451  break;
3452  case ANONYMIZE_FREEACCESS:
3453  $info->addProperty($this->lng->txt("anonymization"), $this->lng->txt("info_anonymize_without_code"));
3454  break;
3455  }
3456  include_once "./Modules/Survey/classes/class.ilObjSurveyAccess.php";
3457  if ($ilAccess->checkAccess("write", "", $this->ref_id) || ilObjSurveyAccess::_hasEvaluationAccess($this->object->getId(), $ilUser->getId()))
3458  {
3459  $info->addProperty($this->lng->txt("evaluation_access"), $this->lng->txt("evaluation_access_info"));
3460  }
3461  $info->addMetaDataSections($this->object->getId(),0, $this->object->getType());
3462  $this->ctrl->forwardCommand($info);
3463  }
3464 
3470  function printViewObject()
3471  {
3472  global $ilias;
3473 
3474  $this->questionsSubtabs("printview");
3475  $template = new ilTemplate("tpl.il_svy_svy_printview.html", TRUE, TRUE, "Modules/Survey");
3476 
3477  include_once './Services/WebServices/RPC/classes/class.ilRPCServerSettings.php';
3478  if(ilRPCServerSettings::getInstance()->isEnabled())
3479  {
3480  $this->ctrl->setParameter($this, "pdf", "1");
3481  $template->setCurrentBlock("pdf_export");
3482  $template->setVariable("PDF_URL", $this->ctrl->getLinkTarget($this, "printView"));
3483  $this->ctrl->setParameter($this, "pdf", "");
3484  $template->setVariable("PDF_TEXT", $this->lng->txt("pdf_export"));
3485  $template->setVariable("PDF_IMG_ALT", $this->lng->txt("pdf_export"));
3486  $template->setVariable("PDF_IMG_URL", ilUtil::getHtmlPath(ilUtil::getImagePath("application-pdf.png")));
3487  $template->parseCurrentBlock();
3488  }
3489  $template->setVariable("PRINT_TEXT", $this->lng->txt("print"));
3490  $template->setVariable("PRINT_URL", "javascript:window.print();");
3491 
3492  $pages =& $this->object->getSurveyPages();
3493  foreach ($pages as $page)
3494  {
3495  if (count($page) > 0)
3496  {
3497  foreach ($page as $question)
3498  {
3499  $questionGUI = $this->object->getQuestionGUI($question["type_tag"], $question["question_id"]);
3500  if (is_object($questionGUI))
3501  {
3502  if (strlen($question["heading"]))
3503  {
3504  $template->setCurrentBlock("textblock");
3505  $template->setVariable("TEXTBLOCK", $question["heading"]);
3506  $template->parseCurrentBlock();
3507  }
3508  $template->setCurrentBlock("question");
3509  $template->setVariable("QUESTION_DATA", $questionGUI->getPrintView($this->object->getShowQuestionTitles(), $question["questionblock_show_questiontext"], $this->object->getSurveyId()));
3510  $template->parseCurrentBlock();
3511  }
3512  }
3513  if (count($page) > 1)
3514  {
3515  $template->setCurrentBlock("page");
3516  $template->setVariable("BLOCKTITLE", $page[0]["questionblock_title"]);
3517  $template->parseCurrentBlock();
3518  }
3519  else
3520  {
3521  $template->setCurrentBlock("page");
3522  $template->parseCurrentBlock();
3523  }
3524  }
3525  }
3526  $this->tpl->addCss("./Modules/Survey/templates/default/survey_print.css", "print");
3527  if (array_key_exists("pdf", $_GET) && ($_GET["pdf"] == 1))
3528  {
3529  $printbody = new ilTemplate("tpl.il_as_tst_print_body.html", TRUE, TRUE, "Modules/Test");
3530  $printbody->setVariable("TITLE", sprintf($this->lng->txt("tst_result_user_name"), $uname));
3531  $printbody->setVariable("ADM_CONTENT", $template->get());
3532  $printoutput = $printbody->get();
3533  $printoutput = preg_replace("/href=\".*?\"/", "", $printoutput);
3534  $fo = $this->object->processPrintoutput2FO($printoutput);
3535  $this->object->deliverPDFfromFO($fo);
3536  }
3537  else
3538  {
3539  $this->tpl->setVariable("ADM_CONTENT", $template->get());
3540  }
3541  }
3542 
3543  function addLocatorItems()
3544  {
3545  global $ilLocator;
3546  switch ($this->ctrl->getCmd())
3547  {
3548  case "next":
3549  case "previous":
3550  case "start":
3551  case "resume":
3552  case "redirectQuestion":
3553  $ilLocator->addItem($this->object->getTitle(), $this->ctrl->getLinkTarget($this, "infoScreen"), "", $_GET["ref_id"]);
3554  break;
3555  case "evaluation":
3556  case "checkEvaluationAccess":
3557  case "evaluationdetails":
3558  case "evaluationuser":
3559  $ilLocator->addItem($this->object->getTitle(), $this->ctrl->getLinkTargetByClass("ilsurveyevaluationgui", "evaluation"), "", $_GET["ref_id"]);
3560  break;
3561  case "create":
3562  case "save":
3563  case "cancel":
3564  case "importFile":
3565  case "cloneAll":
3566  break;
3567  case "infoScreen":
3568  $ilLocator->addItem($this->object->getTitle(), $this->ctrl->getLinkTarget($this, "infoScreen"), "", $_GET["ref_id"]);
3569  break;
3570  default:
3571  $ilLocator->addItem($this->object->getTitle(), $this->ctrl->getLinkTarget($this, ""), "", $_GET["ref_id"]);
3572  break;
3573  }
3574  }
3575 
3583  function questionsSubtabs($a_cmd)
3584  {
3585  $questions = ($a_cmd == 'questions') ? true : false;
3586  $printview = ($a_cmd == 'printview') ? true : false;
3587 
3588  $this->tabs_gui->addSubTabTarget("survey_question_editor", $this->ctrl->getLinkTarget($this, "questions"),
3589  "", "", "", $questions);
3590  $this->tabs_gui->addSubTabTarget("print_view", $this->ctrl->getLinkTarget($this, "printView"),
3591  "", "", "", $printview);
3592  }
3593 
3599  function setCodesSubtabs()
3600  {
3601  global $ilTabs;
3602  global $ilAccess;
3603 
3604  $ilTabs->addSubTabTarget
3605  (
3606  "codes",
3607  $this->ctrl->getLinkTarget($this,'codes'),
3608  array("codes", "createSurveyCodes", "setCodeLanguage", "deleteCodes", "exportCodes"),
3609  ""
3610  );
3611 
3612  $ilTabs->addSubTabTarget
3613  (
3614  "participating_users",
3615  $this->ctrl->getLinkTarget($this, "codesMail"),
3616  array("codesMail", "saveMailTableFields", "importExternalMailRecipients",
3617  'importExternalRecipientsFromFile', 'importExternalRecipientsFromText',
3618  'importExternalRecipientsFromDataset'),
3619  ""
3620  );
3621 
3622  $data = $this->object->getExternalCodeRecipients();
3623  if (count($data))
3624  {
3625  $ilTabs->addSubTabTarget
3626  (
3627  "mail_survey_codes",
3628  $this->ctrl->getLinkTarget($this, "mailCodes"),
3629  array("mailCodes", "sendCodesMail", "insertSavedMessage", "deleteSavedMessage"),
3630  ""
3631  );
3632  }
3633  }
3634 
3640  function setEvalSubtabs()
3641  {
3642  global $ilTabs;
3643  global $ilAccess;
3644 
3645  $ilTabs->addSubTabTarget(
3646  "svy_eval_cumulated",
3647  $this->ctrl->getLinkTargetByClass("ilsurveyevaluationgui", "evaluation"),
3648  array("evaluation", "checkEvaluationAccess"),
3649  ""
3650  );
3651 
3652  $ilTabs->addSubTabTarget(
3653  "svy_eval_detail",
3654  $this->ctrl->getLinkTargetByClass("ilsurveyevaluationgui", "evaluationdetails"),
3655  array("evaluationdetails"),
3656  ""
3657  );
3658 
3659  if ($ilAccess->checkAccess("write", "", $this->object->getRefId()))
3660  {
3661  $ilTabs->addSubTabTarget(
3662  "svy_eval_user",
3663  $this->ctrl->getLinkTargetByClass("ilsurveyevaluationgui", "evaluationuser"),
3664  array("evaluationuser"),
3665  ""
3666  );
3667  }
3668  }
3669 
3671  {
3672  global $ilAccess;
3673  global $ilTabs;
3674 
3675  if ($ilAccess->checkAccess("write", "", $this->ref_id))
3676  {
3677  $ilTabs->setBackTarget($this->lng->txt("menubacktosurvey"), $this->ctrl->getLinkTarget($this, "questions"));
3678  $ilTabs->addTarget("browse_for_questions",
3679  $this->ctrl->getLinkTarget($this, "browseForQuestions"),
3680  array("browseForQuestions", "browseForQuestionblocks"),
3681  "", ""
3682  );
3683  }
3684  }
3685 
3691  function getTabs(&$tabs_gui)
3692  {
3693  global $ilAccess, $ilUser;
3694 
3695  if (strcmp($this->ctrl->getNextClass(), 'ilrepositorysearchgui') != 0)
3696  {
3697  switch ($this->ctrl->getCmd())
3698  {
3699  case "browseForQuestions":
3700  case "browseForQuestionblocks":
3701  case "insertQuestions":
3702  case "filterQuestions":
3703  case "resetFilterQuestions":
3704  case "changeDatatype":
3705 
3706  case "start":
3707  case "resume":
3708  case "next":
3709  case "previous":
3710  case "redirectQuestion":
3711  return;
3712  break;
3713  case "evaluation":
3714  case "checkEvaluationAccess":
3715  case "evaluationdetails":
3716  case "evaluationuser":
3717  $this->setEvalSubtabs();
3718  break;
3719  }
3720  }
3721 
3722  // questions
3723  if ($ilAccess->checkAccess("write", "", $this->ref_id))
3724  {
3725  $force_active = ($_GET["up"] != "" || $_GET["down"] != "")
3726  ? true
3727  : false;
3728 
3729  $tabs_gui->addTarget("survey_questions",
3730  $this->ctrl->getLinkTarget($this,'questions'),
3731  array("questions", "browseForQuestions", "createQuestion",
3732  "filterQuestions", "resetFilterQuestions", "changeDatatype", "insertQuestions",
3733  "removeQuestions", "cancelRemoveQuestions", "confirmRemoveQuestions",
3734  "defineQuestionblock", "saveDefineQuestionblock", "cancelDefineQuestionblock",
3735  "unfoldQuestionblock", "moveQuestions",
3736  "insertQuestionsBefore", "insertQuestionsAfter", "saveObligatory",
3737  "addHeading", "saveHeading", "cancelHeading", "editHeading",
3738  "confirmRemoveHeading", "cancelRemoveHeading", "printView"),
3739  "", "", $force_active);
3740  }
3741 
3742  if ($ilAccess->checkAccess("visible", "", $this->ref_id))
3743  {
3744  $tabs_gui->addTarget("info_short",
3745  $this->ctrl->getLinkTarget($this,'infoScreen'),
3746  array("infoScreen", "showSummary"));
3747  }
3748 
3749  // properties
3750  if ($ilAccess->checkAccess("write", "", $this->ref_id))
3751  {
3752  $force_active = ($this->ctrl->getCmd() == "")
3753  ? true
3754  : false;
3755  $tabs_gui->addTarget("settings",
3756  $this->ctrl->getLinkTarget($this,'properties'),
3757  array("properties", "save", "cancel", 'saveProperties'), "",
3758  "", $force_active);
3759  }
3760 
3761  // questions
3762  if ($ilAccess->checkAccess("write", "", $this->ref_id))
3763  {
3764  // constraints
3765  $tabs_gui->addTarget("constraints",
3766  $this->ctrl->getLinkTarget($this, "constraints"),
3767  array("constraints", "constraintStep1", "constraintStep2",
3768  "constraintStep3", "constraintsAdd", "createConstraints",
3769  "editPrecondition"),
3770  "");
3771  }
3772 
3773  if (($ilAccess->checkAccess("write", "", $this->ref_id)) || ($ilAccess->checkAccess("invite", "", $this->ref_id)))
3774  {
3775  // invite
3776  $tabs_gui->addTarget("invitation",
3777  $this->ctrl->getLinkTarget($this, 'invite'),
3778  array("invite", "saveInvitationStatus",
3779  "inviteUserGroup", "disinviteUserGroup"),
3780  "");
3781  }
3782 
3783  if ($ilAccess->checkAccess("write", "", $this->ref_id))
3784  {
3785  // maintenance
3786  $tabs_gui->addTarget("maintenance",
3787  $this->ctrl->getLinkTarget($this,'maintenance'),
3788  array("maintenance", "deleteAllUserData"),
3789  "");
3790 
3791  if ($this->object->getAnonymize() == 1)
3792  {
3793  // code
3794  $tabs_gui->addTarget("codes",
3795  $this->ctrl->getLinkTarget($this,'codes'),
3796  array("codes", "exportCodes", 'codesMail', 'saveMailTableFields', 'importExternalMailRecipients',
3797  'mailCodes', 'sendCodesMail', 'importExternalRecipientsFromFile', 'importExternalRecipientsFromText',
3798  'importExternalRecipientsFromDataset', 'insertSavedMessage', 'deleteSavedMessage'),
3799  "");
3800  }
3801  }
3802 
3803  include_once "./Modules/Survey/classes/class.ilObjSurveyAccess.php";
3804  if ($ilAccess->checkAccess("write", "", $this->ref_id) || ilObjSurveyAccess::_hasEvaluationAccess($this->object->getId(), $ilUser->getId()))
3805  {
3806  // evaluation
3807  $tabs_gui->addTarget("svy_evaluation",
3808  $this->ctrl->getLinkTargetByClass("ilsurveyevaluationgui", "evaluation"),
3809  array("evaluation", "checkEvaluationAccess", "evaluationdetails",
3810  "evaluationuser"),
3811  "");
3812  }
3813 
3814  if ($ilAccess->checkAccess("write", "", $this->ref_id))
3815  {
3816  // meta data
3817  $tabs_gui->addTarget("meta_data",
3818  $this->ctrl->getLinkTargetByClass('ilmdeditorgui','listSection'),
3819  "", "ilmdeditorgui");
3820 
3821  // export
3822  $tabs_gui->addTarget("export",
3823  $this->ctrl->getLinkTarget($this,'export'),
3824  array("export", "createExportFile", "confirmDeleteExportFile",
3825  "downloadExportFile"),
3826  ""
3827  );
3828  }
3829 
3830  if ($ilAccess->checkAccess("edit_permission", "", $this->ref_id))
3831  {
3832  // permissions
3833  $tabs_gui->addTarget("perm_settings",
3834  $this->ctrl->getLinkTargetByClass(array(get_class($this),'ilpermissiongui'), "perm"), array("perm","info","owner"), 'ilpermissiongui');
3835  }
3836  }
3837 
3843  function _goto($a_target, $a_access_code = "")
3844  {
3845  global $ilAccess, $ilErr, $lng;
3846  if ($ilAccess->checkAccess("read", "", $a_target))
3847  {
3848  include_once "./Services/Utilities/classes/class.ilUtil.php";
3849  if (strlen($a_access_code))
3850  {
3851  $_SESSION["anonymous_id"][ilObject::_lookupObjId($a_target)] = $a_access_code;
3852  $_GET["baseClass"] = "ilObjSurveyGUI";
3853  $_GET["cmd"] = "infoScreen";
3854  $_GET["ref_id"] = $a_target;
3855  include("ilias.php");
3856  exit;
3857  }
3858  else
3859  {
3860  $_GET["baseClass"] = "ilObjSurveyGUI";
3861  $_GET["cmd"] = "infoScreen";
3862  $_GET["ref_id"] = $a_target;
3863  include("ilias.php");
3864  exit;
3865  }
3866  }
3867  else if ($ilAccess->checkAccess("read", "", ROOT_FOLDER_ID))
3868  {
3869  $_GET["cmd"] = "frameset";
3870  $_GET["target"] = "";
3871  $_GET["ref_id"] = ROOT_FOLDER_ID;
3872  ilUtil::sendFailure(sprintf($lng->txt("msg_no_perm_read_item"),
3873  ilObject::_lookupTitle(ilObject::_lookupObjId($a_target))), true);
3874  include("repository.php");
3875  exit;
3876  }
3877 
3878  $ilErr->raiseError($lng->txt("msg_no_perm_read_lm"), $ilErr->FATAL);
3879  }
3880 
3881 } // END class.ilObjSurveyGUI
3882 ?>