ILIAS  release_4-3 Revision
 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 "./Services/Object/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", "pgov", "pgov_pos");
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","./ilias.php?baseClass=ilRepositoryGUI&amp;cmd=frameset&ref_id=" . $path[count($path) - 2]["child"]));
67  }
68 
72  function executeCommand()
73  {
74  global $ilAccess, $ilNavigationHistory, $ilCtrl, $ilErr;
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  // deep link from repository - "redirect" to page view
98  if(!$this->ctrl->getCmdClass() && $cmd == "questionsrepo")
99  {
100  $_REQUEST["pgov"] = 1;
101  $cmd = "questions";
102  $ilCtrl->setCmd($cmd);
103  }
104 
105  // return to questions in page view mode
106  if(in_array($cmd, array("cancelRemoveQuestions", "questions", "confirmRemoveQuestions",
107  "cancelDeleteAllUserData", "confirmDeleteAllUserData", "cancelCreateQuestion",
108  "cancelHeading", "cancelRemoveHeading", "confirmRemoveHeading", "cancelRemoveQuestions",
109  "cancelDefineQuestionblock"))
110  && $_REQUEST["pgov"])
111  {
112  $ilCtrl->setCmdClass("ilsurveypagegui");
113  if(!in_array($cmd, array("confirmRemoveQuestions", "confirmDeleteAllUserData",
114  "confirmRemoveHeading")))
115  {
116  $ilCtrl->setCmd("renderPage");
117  }
118  }
119 
120  $next_class = $this->ctrl->getNextClass($this);
121  $this->ctrl->setReturn($this, "properties");
122  $this->tpl->addCss(ilUtil::getStyleSheetLocation("output", "survey.css", "Modules/Survey"), "screen");
123  $this->prepareOutput();
124  //echo "<br>nextclass:$next_class:cmd:$cmd:qtype=$q_type";
125  switch($next_class)
126  {
127  case "ilinfoscreengui":
128  $this->addHeaderAction();
129  $this->infoScreen(); // forwards command
130  break;
131 
132  case 'ilmdeditorgui':
133  if(!$ilAccess->checkAccess('write','',$this->object->getRefId()))
134  {
135  $ilErr->raiseError($this->lng->txt('permission_denied'),$ilErr->WARNING);
136  }
137 
138  $this->addHeaderAction();
139  include_once 'Services/MetaData/classes/class.ilMDEditorGUI.php';
140  $md_gui =& new ilMDEditorGUI($this->object->getId(), 0, $this->object->getType());
141  $md_gui->addObserver($this->object,'MDUpdateListener','General');
142 
143  $this->ctrl->forwardCommand($md_gui);
144  break;
145 
146  case "ilsurveyevaluationgui":
147  $this->addHeaderAction();
148  include_once("./Modules/Survey/classes/class.ilSurveyEvaluationGUI.php");
149  $eval_gui = new ilSurveyEvaluationGUI($this->object);
150  $ret =& $this->ctrl->forwardCommand($eval_gui);
151  break;
152 
153  case 'ilrepositorysearchgui':
154  include_once('./Services/Search/classes/class.ilRepositorySearchGUI.php');
155  $rep_search =& new ilRepositorySearchGUI();
156  $rep_search->setCallback($this,
157  'inviteUserGroupObject',
158  array(
159  )
160  );
161 
162  // Set tabs
163  $this->ctrl->setReturn($this, 'invite');
164  $ret =& $this->ctrl->forwardCommand($rep_search);
165  $this->tabs_gui->setTabActive('invitation');
166  break;
167 
168  case "ilsurveyexecutiongui":
169  include_once("./Modules/Survey/classes/class.ilSurveyExecutionGUI.php");
170  $exec_gui = new ilSurveyExecutionGUI($this->object);
171  $ret =& $this->ctrl->forwardCommand($exec_gui);
172  break;
173 
174  case 'ilpermissiongui':
175  $this->addHeaderAction();
176  include_once("Services/AccessControl/classes/class.ilPermissionGUI.php");
177  $perm_gui =& new ilPermissionGUI($this);
178  $ret =& $this->ctrl->forwardCommand($perm_gui);
179  break;
180 
181  case 'ilobjectcopygui':
182  include_once './Services/Object/classes/class.ilObjectCopyGUI.php';
183  $cp = new ilObjectCopyGUI($this);
184  $cp->setType('svy');
185  $this->ctrl->forwardCommand($cp);
186  break;
187 
188  case 'ilsurveypagegui':
189  $this->addHeaderAction();
190  include_once './Modules/Survey/classes/class.ilSurveyPageGUI.php';
191  $pg = new ilSurveyPageGUI($this);
192  $this->ctrl->forwardCommand($pg);
193  break;
194 
195  case "ilcommonactiondispatchergui":
196  include_once("Services/Object/classes/class.ilCommonActionDispatcherGUI.php");
198  $this->ctrl->forwardCommand($gui);
199  break;
200 
201  default:
202  $this->addHeaderAction();
203  $cmd.= "Object";
204  $ret =& $this->$cmd();
205  break;
206  }
207 
208  if (strtolower($_GET["baseClass"]) != "iladministrationgui" &&
209  $this->getCreationMode() != true)
210  {
211  $this->tpl->show();
212  }
213  }
214 
215  protected function addDidacticTemplateOptions(array &$a_options)
216  {
217  include_once "Services/Administration/classes/class.ilSettingsTemplate.php";
219  if($templates)
220  {
221  foreach($templates as $item)
222  {
223  $a_options["svytpl_".$item["id"]] = array($item["title"],
224  nl2br(trim($item["description"])));
225  }
226  }
227  }
228 
233  function afterSave(ilObject $a_new_object)
234  {
235  $tpl = $this->getDidacticTemplateVar("svytpl");
236  if($tpl)
237  {
238  $a_new_object->applySettingsTemplate($tpl);
239  }
240 
241  // always send a message
242  ilUtil::sendSuccess($this->lng->txt("object_added"),true);
243  ilUtil::redirect("ilias.php?baseClass=ilObjSurveyGUI&ref_id=".
244  $a_new_object->getRefId()."&cmd=properties");
245  }
246 
255  {
256  $this->ctrl->redirect($this, "properties");
257  }
258 
266  function handleWriteAccess()
267  {
268  global $ilAccess;
269  if (!$ilAccess->checkAccess("write", "", $this->ref_id))
270  {
271  // allow only write access
272  ilUtil::sendInfo($this->lng->txt("cannot_edit_survey"), TRUE);
273  $this->ctrl->redirect($this, "infoScreen");
274  }
275  }
276 
285  {
286  $form = $this->initPropertiesForm();
287  if ($form->checkInput())
288  {
289  // #10055
290  if ($_POST['online'] && count($this->object->questions) == 0)
291  {
292  $_POST['online'] = null;
293  ilUtil::sendFailure($this->lng->txt("cannot_switch_to_online_no_questions"), true);
294  }
295 
296  $template_settings = null;
297  $template = $this->object->getTemplate();
298  if($template)
299  {
300  include_once "Services/Administration/classes/class.ilSettingsTemplate.php";
301  $template = new ilSettingsTemplate($template);
302  $template_settings = $template->getSettings();
303  }
304 
305  include_once 'Services/MetaData/classes/class.ilMD.php';
306  $md_obj =& new ilMD($this->object->getId(), 0, "svy");
307  $md_section = $md_obj->getGeneral();
308 
309  // title
310  $md_section->setTitle(ilUtil::stripSlashes($_POST['title']));
311  $md_section->update();
312 
313  // Description
314  $md_desc_ids = $md_section->getDescriptionIds();
315  if($md_desc_ids)
316  {
317  $md_desc = $md_section->getDescription(array_pop($md_desc_ids));
318  $md_desc->setDescription(ilUtil::stripSlashes($_POST['description']));
319  $md_desc->update();
320  }
321 
322  // both are saved in object, too
323  $this->object->setTitle(ilUtil::stripSlashes($_POST['title']));
324  $this->object->setDescription(ilUtil::stripSlashes($_POST['description']));
325  $this->object->update();
326 
327  $this->object->setStatus($_POST['online']);
328  $this->object->setEvaluationAccess($_POST["evaluation_access"]);
329 
330  // activation
331  if($_POST["access_type"] == ilObjectActivation::TIMINGS_ACTIVATION)
332  {
333  $this->object->setActivationLimited(true);
334  $this->object->setActivationVisibility($_POST["access_visiblity"]);
335 
336  $date = new ilDateTime($_POST['access_begin']['date'] . ' ' . $_POST['access_begin']['time'], IL_CAL_DATETIME);
337  $this->object->setActivationStartDate($date->get(IL_CAL_UNIX));
338 
339  $date = new ilDateTime($_POST['access_end']['date'] . ' ' . $_POST['access_end']['time'], IL_CAL_DATETIME);
340  $this->object->setActivationEndDate($date->get(IL_CAL_UNIX));
341  }
342  else
343  {
344  $this->object->setActivationLimited(false);
345  }
346 
347 
348  if(!$template_settings["enabled_start_date"]["hide"])
349  {
350  if ($_POST["enabled_start_date"])
351  {
352  $this->object->setStartDateAndTime($_POST["start_date"]['date'], $_POST["start_date"]['time']);
353  }
354  else
355  {
356  $this->object->setStartDate(null);
357  }
358  }
359 
360  if(!$template_settings["enabled_end_date"]["hide"])
361  {
362  if ($_POST["enabled_end_date"])
363  {
364  $this->object->setEndDateAndTime($_POST["end_date"]['date'], $_POST["end_date"]['time']);
365  }
366  else
367  {
368  $this->object->setEndDate(null);
369  }
370  }
371 
372 
373  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
374  $introduction = $_POST["introduction"];
375  $this->object->setIntroduction($introduction);
376  $outro = $_POST["outro"];
377  $this->object->setOutro($outro);
378 
379  $hasDatasets = $this->object->_hasDatasets($this->object->getSurveyId());
380  if (!$hasDatasets)
381  {
382  $anon_map = array('personalized' => ANONYMIZE_OFF,
383  'anonymize_with_code' => ANONYMIZE_ON,
384  'anonymize_without_code' => ANONYMIZE_FREEACCESS);
385  if(array_key_exists($_POST["anonymization_options"], $anon_map))
386  {
387  $this->object->setAnonymize($anon_map[$_POST["anonymization_options"]]);
388  if (strcmp($_POST['anonymization_options'], 'anonymize_with_code') == 0) $anonymize = ANONYMIZE_ON;
389  if (strcmp($_POST['anonymization_options'], 'anonymize_with_code_all') == 0) $anonymize = ANONYMIZE_CODE_ALL;
390  }
391  }
392 
393  if(!$template_settings["show_question_titles"]["hide"])
394  {
395  $this->object->setShowQuestionTitles($_POST["show_question_titles"]);
396  }
397 
398  if(!$template_settings["use_pool"]["hide"])
399  {
400  $this->object->setPoolUsage($_POST["use_pool"]);
401  }
402 
403  $this->object->setMailNotification($_POST['mailnotification']);
404  $this->object->setMailAddresses($_POST['mailaddresses']);
405  $this->object->setMailParticipantData($_POST['mailparticipantdata']);
406  $this->object->saveToDb();
407 
408  if (strcmp($_SESSION["info"], "") != 0)
409  {
410  ilUtil::sendSuccess($_SESSION["info"] . "<br />" . $this->lng->txt("settings_saved"), true);
411  }
412  else
413  {
414  ilUtil::sendSuccess($this->lng->txt("settings_saved"), true);
415  }
416  $this->ctrl->redirect($this, "properties");
417  }
418 
419  $form->setValuesByPost();
420  $this->propertiesObject($form);
421  }
422 
429  {
430  $template_settings = $hide_rte_switch = null;
431  $template = $this->object->getTemplate();
432  if($template)
433  {
434  include_once "Services/Administration/classes/class.ilSettingsTemplate.php";
435  $template = new ilSettingsTemplate($template);
436 
437  $template_settings = $template->getSettings();
438  $hide_rte_switch = $template_settings["rte_switch"]["hide"];
439  }
440 
441  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
442  $form = new ilPropertyFormGUI();
443  $form->setFormAction($this->ctrl->getFormAction($this));
444  $form->setTableWidth("100%");
445  $form->setId("survey_properties");
446 
447  // general properties
448  $header = new ilFormSectionHeaderGUI();
449  $header->setTitle($this->lng->txt("settings"));
450  $form->addItem($header);
451 
452  // title & description (meta data)
453 
454  include_once 'Services/MetaData/classes/class.ilMD.php';
455  $md_obj = new ilMD($this->object->getId(), 0, "svy");
456  $md_section = $md_obj->getGeneral();
457 
458  $title = new ilTextInputGUI($this->lng->txt("title"), "title");
459  $title->setRequired(true);
460  $title->setValue($md_section->getTitle());
461  $form->addItem($title);
462 
463  $ids = $md_section->getDescriptionIds();
464  if($ids)
465  {
466  $desc_obj = $md_section->getDescription(array_pop($ids));
467 
468  $desc = new ilTextAreaInputGUI($this->lng->txt("description"), "description");
469  $desc->setCols(50);
470  $desc->setRows(4);
471  $desc->setValue($desc_obj->getDescription());
472  $form->addItem($desc);
473  }
474 
475  // anonymization
476  $anonymization_options = new ilRadioGroupInputGUI($this->lng->txt("survey_auth_mode"), "anonymization_options");
477  $hasDatasets = $this->object->_hasDatasets($this->object->getSurveyId());
478  if ($hasDatasets)
479  {
480  $anonymization_options->setDisabled(true);
481  }
482  $anonymization_options->addOption(new ilCheckboxOption($this->lng->txt("anonymize_personalized"),
483  'personalized', ''));
484  $anonymization_options->addOption(new ilCheckboxOption(
485  $this->lng->txt("anonymize_without_code"), 'anonymize_without_code', ''));
486  $anonymization_options->addOption(new ilCheckboxOption(
487  $this->lng->txt("anonymize_with_code"), 'anonymize_with_code', ''));
488  if(!$this->object->getAnonymize())
489  {
490  $anonymization_options->setValue('personalized');
491  }
492  else
493  {
494  $anonymization_options->setValue(($this->object->isAccessibleWithoutCode()) ?
495  'anonymize_without_code' : 'anonymize_with_code');
496  }
497  $anonymization_options->setInfo($this->lng->txt("anonymize_survey_description"));
498  $form->addItem($anonymization_options);
499 
500  // pool usage
501  $pool_usage = new ilRadioGroupInputGUI($this->lng->txt("survey_question_pool_usage"), "use_pool");
502  $opt = new ilRadioOption($this->lng->txt("survey_question_pool_usage_active"), 1);
503  $opt->setInfo($this->lng->txt("survey_question_pool_usage_active_info"));
504  $pool_usage->addOption($opt);
505  $opt = new ilRadioOption($this->lng->txt("survey_question_pool_usage_inactive"), 0);
506  $opt->setInfo($this->lng->txt("survey_question_pool_usage_inactive_info"));
507  $pool_usage->addOption($opt);
508  $pool_usage->setValue($this->object->getPoolUsage());
509  $form->addItem($pool_usage);
510 
511 
512  // activation
513 
514  include_once "Services/Object/classes/class.ilObjectActivation.php";
515  $this->lng->loadLanguageModule('rep');
516 
518  $section->setTitle($this->lng->txt('rep_activation_availability'));
519  $form->addItem($section);
520 
521  // additional info only with multiple references
522  $act_obj_info = $act_ref_info = "";
523  if(sizeof(ilObject::_getAllReferences($this->object->getId())) > 1)
524  {
525  $act_obj_info = ' '.$this->lng->txt('rep_activation_online_object_info');
526  $act_ref_info = $this->lng->txt('rep_activation_access_ref_info');
527  }
528 
529  $online = new ilCheckboxInputGUI($this->lng->txt('rep_activation_online'),'online');
530  $online->setInfo($this->lng->txt('svy_activation_online_info').$act_obj_info);
531  $online->setChecked($this->object->isOnline());
532  $form->addItem($online);
533 
534  $act_type = new ilRadioGroupInputGUI($this->lng->txt('rep_activation_access'),'access_type');
535  $act_type->setInfo($act_ref_info);
536  $act_type->setValue($this->object->isActivationLimited() ?
538 
539  $opt = new ilRadioOption($this->lng->txt('rep_visibility_limitless'), ilObjectActivation::TIMINGS_DEACTIVATED);
540  $opt->setInfo($this->lng->txt('svy_availability_limitless_info'));
541  $act_type->addOption($opt);
542 
543  $opt = new ilRadioOption($this->lng->txt('rep_visibility_until'), ilObjectActivation::TIMINGS_ACTIVATION);
544  $opt->setInfo($this->lng->txt('svy_availability_until_info'));
545 
546  $date = $this->object->getActivationStartDate();
547 
548  $start = new ilDateTimeInputGUI($this->lng->txt('rep_activation_limited_start'),'access_begin');
549  $start->setShowTime(true);
550  $start->setDate(new ilDateTime($date ? $date : time(), IL_CAL_UNIX));
551  $opt->addSubItem($start);
552 
553  $date = $this->object->getActivationEndDate();
554 
555  $end = new ilDateTimeInputGUI($this->lng->txt('rep_activation_limited_end'),'access_end');
556  $end->setShowTime(true);
557  $end->setDate(new ilDateTime($date ? $date : time(), IL_CAL_UNIX));
558  $opt->addSubItem($end);
559 
560  $visible = new ilCheckboxInputGUI($this->lng->txt('rep_activation_limited_visibility'), 'access_visiblity');
561  $visible->setInfo($this->lng->txt('svy_activation_limited_visibility_info'));
562  $visible->setChecked($this->object->getActivationVisibility());
563  $opt->addSubItem($visible);
564 
565  $act_type->addOption($opt);
566 
567  $form->addItem($act_type);
568 
569 
570  // enable start date
571  $start = $this->object->getStartDate();
572  $enablestartingtime = new ilCheckboxInputGUI($this->lng->txt("start_date"), "enabled_start_date");
573  $enablestartingtime->setValue(1);
574  // $enablestartingtime->setOptionTitle($this->lng->txt("enabled"));
575  $enablestartingtime->setChecked($start);
576  // start date
577  $startingtime = new ilDateTimeInputGUI('', 'start_date');
578  $startingtime->setShowDate(true);
579  $startingtime->setShowTime(true);
580  if ($start)
581  {
582  $startingtime->setDate(new ilDate($start, IL_CAL_TIMESTAMP));
583  }
584  $enablestartingtime->addSubItem($startingtime);
585  $form->addItem($enablestartingtime);
586 
587  // enable end date
588  $end = $this->object->getEndDate();
589  $enableendingtime = new ilCheckboxInputGUI($this->lng->txt("end_date"), "enabled_end_date");
590  $enableendingtime->setValue(1);
591  // $enableendingtime->setOptionTitle($this->lng->txt("enabled"));
592  $enableendingtime->setChecked($end);
593  // end date
594  $endingtime = new ilDateTimeInputGUI('', 'end_date');
595  $endingtime->setShowDate(true);
596  $endingtime->setShowTime(true);
597  if ($end)
598  {
599  $endingtime->setDate(new ilDate($end, IL_CAL_TIMESTAMP));
600  }
601  $enableendingtime->addSubItem($endingtime);
602  $form->addItem($enableendingtime);
603 
604 
605  // presentation properties
606  $info = new ilFormSectionHeaderGUI();
607  $info->setTitle($this->lng->txt("svy_presentation_properties"));
608  $form->addItem($info);
609 
610  // show question titles
611  $show_question_titles = new ilCheckboxInputGUI($this->lng->txt("svy_show_questiontitles"), "show_question_titles");
612  $show_question_titles->setValue(1);
613  $show_question_titles->setChecked($this->object->getShowQuestionTitles());
614  $form->addItem($show_question_titles);
615 
616  // introduction
617  $intro = new ilTextAreaInputGUI($this->lng->txt("introduction"), "introduction");
618  $intro->setValue($this->object->prepareTextareaOutput($this->object->getIntroduction()));
619  $intro->setRows(10);
620  $intro->setCols(80);
621  $intro->setUseRte(TRUE);
622  $intro->setInfo($this->lng->txt("survey_introduction_info"));
623  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
624  $intro->setRteTags(ilObjAdvancedEditing::_getUsedHTMLTags("survey"));
625  $intro->addPlugin("latex");
626  $intro->addButton("latex");
627  $intro->addButton("pastelatex");
628  $intro->setRTESupport($this->object->getId(), "svy", "survey", null, $hide_rte_switch, "3.4.7");
629  $form->addItem($intro);
630 
631  // final statement
632  $finalstatement = new ilTextAreaInputGUI($this->lng->txt("outro"), "outro");
633  $finalstatement->setValue($this->object->prepareTextareaOutput($this->object->getOutro()));
634  $finalstatement->setRows(10);
635  $finalstatement->setCols(80);
636  $finalstatement->setUseRte(TRUE);
637  $finalstatement->setRteTags(ilObjAdvancedEditing::_getUsedHTMLTags("survey"));
638  $finalstatement->addPlugin("latex");
639  $finalstatement->addButton("latex");
640  $finalstatement->addButton("pastelatex");
641  $finalstatement->setRTESupport($this->object->getId(), "svy", "survey", null, $hide_rte_switch, "3.4.7");
642  $form->addItem($finalstatement);
643 
644 
645  // results properties
647  $results->setTitle($this->lng->txt("results"));
648  $form->addItem($results);
649 
650  // evaluation access
651  $evaluation_access = new ilRadioGroupInputGUI($this->lng->txt('evaluation_access'), "evaluation_access");
652  $evaluation_access->setInfo($this->lng->txt('evaluation_access_description'));
653  $evaluation_access->addOption(new ilCheckboxOption($this->lng->txt("evaluation_access_off"), EVALUATION_ACCESS_OFF, ''));
654  $evaluation_access->addOption(new ilCheckboxOption($this->lng->txt("evaluation_access_all"), EVALUATION_ACCESS_ALL, ''));
655  $evaluation_access->addOption(new ilCheckboxOption($this->lng->txt("evaluation_access_participants"), EVALUATION_ACCESS_PARTICIPANTS, ''));
656  $evaluation_access->setValue($this->object->getEvaluationAccess());
657  $form->addItem($evaluation_access);
658 
659  // mail notification
660  $mailnotification = new ilCheckboxInputGUI($this->lng->txt("mailnotification"), "mailnotification");
661  // $mailnotification->setOptionTitle($this->lng->txt("activate"));
662  $mailnotification->setValue(1);
663  $mailnotification->setChecked($this->object->getMailNotification());
664 
665  // addresses
666  $mailaddresses = new ilTextInputGUI($this->lng->txt("mailaddresses"), "mailaddresses");
667  $mailaddresses->setValue($this->object->getMailAddresses());
668  $mailaddresses->setSize(80);
669  $mailaddresses->setInfo($this->lng->txt('mailaddresses_info'));
670  $mailaddresses->setRequired(true);
671 
672  // participant data
673  $participantdata = new ilTextAreaInputGUI($this->lng->txt("mailparticipantdata"), "mailparticipantdata");
674  $participantdata->setValue($this->object->getMailParticipantData());
675  $participantdata->setRows(6);
676  $participantdata->setCols(80);
677  $participantdata->setUseRte(false);
678  $participantdata->setInfo($this->lng->txt('mailparticipantdata_info'));
679 
680  // #12755 - because of privacy concerns we restrict user data to a minimum
681  $placeholders = array(
682  "FIRST_NAME" => "firstname",
683  "LAST_NAME" => "lastname",
684  "LOGIN" => "login"
685  );
686  $txt = array();
687  foreach($placeholders as $placeholder => $caption)
688  {
689  $txt[] = "[".strtoupper($placeholder)."]: ".$this->lng->txt($caption);
690  }
691  $txt = implode("<br />", $txt);
692  $participantdatainfo = new ilNonEditableValueGUI($this->lng->txt("mailparticipantdata_placeholder"), "", true);
693  $participantdatainfo->setValue($txt);
694 
695  $mailnotification->addSubItem($mailaddresses);
696  $mailnotification->addSubItem($participantdata);
697  $mailnotification->addSubItem($participantdatainfo);
698  $form->addItem($mailnotification);
699 
700  $form->addCommandButton("saveProperties", $this->lng->txt("save"));
701 
702  // remove items when using template
703  if($template_settings)
704  {
705  foreach($template_settings as $id => $item)
706  {
707  if($item["hide"])
708  {
709  $form->removeItemByPostVar($id);
710  }
711  }
712  }
713 
714  return $form;
715  }
716 
722  function propertiesObject(ilPropertyFormGUI $a_form = null)
723  {
724  global $ilAccess;
725 
726  if (!$ilAccess->checkAccess("write", "", $_GET["ref_id"]))
727  {
728  $this->ctrl->redirect($this, "");
729  }
730 
731  if(!$a_form)
732  {
733  $a_form = $this->initPropertiesForm();
734  }
735 
736  // using template?
737  $message = "";
738  if($this->object->getTemplate())
739  {
740  $link = $this->ctrl->getLinkTarget($this, "confirmResetTemplate");
741  $link = "<a href=\"".$link."\">".$this->lng->txt("survey_using_template_link")."</a>";
742  $message = "<div style=\"margin-top:10px\">".
743  $this->tpl->getMessageHTML(sprintf($this->lng->txt("survey_using_template"),
744  ilSettingsTemplate::lookupTitle($this->object->getTemplate()), $link), "info"). // #10651
745  "</div>";
746  }
747 
748  $this->tpl->setContent($a_form->getHTML().$message);
749  }
750 
759  {
760  $items = $this->gatherSelectedTableItems(true, true, true, true);
761  if (count($items["blocks"]) + count($items["questions"]) + count($items["headings"]) > 0)
762  {
763  ilUtil::sendQuestion($this->lng->txt("remove_questions"));
764  $this->removeQuestionsForm($items["blocks"], $items["questions"], $items["headings"]);
765  return;
766  }
767  else
768  {
769  ilUtil::sendInfo($this->lng->txt("no_question_selected_for_removal"), true);
770  $this->ctrl->redirect($this, "questions");
771  }
772  }
773 
777  public function insertQuestionsObject()
778  {
779  $inserted_objects = 0;
780  if (is_array($_POST['q_id']))
781  {
782  if($_REQUEST["pgov"])
783  {
784  include_once "Modules/Survey/classes/class.ilSurveyPageGUI.php";
785  $page_gui = new ilSurveyPageGUI($this);
786  $page_gui->determineCurrentPage();
787 
788  // as target position is predefined, insert in reverse order
789  $_POST['q_id'] = array_reverse($_POST['q_id']);
790  }
791  foreach ($_POST['q_id'] as $question_id)
792  {
793  if(!$_REQUEST["pgov"])
794  {
795  $this->object->insertQuestion($question_id);
796  }
797  else
798  {
799  // target position (pgov pos) is processed there
800  $page_gui->insertNewQuestion($question_id);
801  }
802  $inserted_objects++;
803  }
804  }
805  if ($inserted_objects)
806  {
807  $this->object->saveCompletionStatus();
808  ilUtil::sendSuccess($this->lng->txt("questions_inserted"), true);
809  if(!$_REQUEST["pgov"])
810  {
811  $this->ctrl->redirect($this, "questions");
812  }
813  else
814  {
815  $target_page = $_REQUEST["pgov"];
816  if(substr($_REQUEST["pgov_pos"], -1) == "c")
817  {
818  // see ilSurveyPageGUI::insertNewQuestion()
819  if((int)$_REQUEST["pgov_pos"])
820  {
821  $target_page++;
822  }
823  else
824  {
825  $target_page = 1;
826  }
827  }
828  $this->ctrl->setParameterByClass("ilsurveypagegui", "pgov", $target_page);
829  $this->ctrl->redirectByClass("ilsurveypagegui", "renderpage");
830  }
831  }
832  else
833  {
834  ilUtil::sendInfo($this->lng->txt("insert_missing_question"), true);
835  $this->ctrl->setParameter($this, "pgov", $_REQUEST["pgov"]);
836  $this->ctrl->setParameter($this, "pgov_pos", $_REQUEST["pgov_pos"]);
837  $this->ctrl->redirect($this, 'browseForQuestions');
838  }
839  }
840 
844  public function insertQuestionblocksObject()
845  {
846  $inserted_objects = 0;
847  if (is_array($_POST['cb']))
848  {
849  if($_REQUEST["pgov"])
850  {
851  include_once "Modules/Survey/classes/class.ilSurveyPageGUI.php";
852  $page_gui = new ilSurveyPageGUI($this);
853  $page_gui->determineCurrentPage();
854 
855  // as target position is predefined, insert in reverse order
856  $_POST['cb'] = array_reverse($_POST['cb']);
857  }
858  foreach ($_POST['cb'] as $questionblock_id)
859  {
860  if(!$_REQUEST["pgov"])
861  {
862  $this->object->insertQuestionblock($questionblock_id);
863  }
864  else
865  {
866  $page_gui->insertQuestionblock($questionblock_id);
867  }
868  $inserted_objects++;
869  }
870  }
871  if ($inserted_objects)
872  {
873  $this->object->saveCompletionStatus();
874  ilUtil::sendSuccess(($inserted_objects == 1) ? $this->lng->txt("questionblock_inserted") : $this->lng->txt("questionblocks_inserted"), true);
875  if(!$_REQUEST["pgov"])
876  {
877  $this->ctrl->redirect($this, "questions");
878  }
879  else
880  {
881  $target_page = $_REQUEST["pgov"];
882  if(substr($_REQUEST["pgov_pos"], -1) == "c")
883  {
884  $target_page++;
885  }
886  $this->ctrl->setParameterByClass("ilsurveypagegui", "pgov", $target_page);
887  $this->ctrl->redirectByClass("ilsurveypagegui", "renderpage");
888  }
889  }
890  else
891  {
892  ilUtil::sendInfo($this->lng->txt("insert_missing_questionblock"), true);
893  $this->ctrl->setParameter($this, "pgov", $_REQUEST["pgov"]);
894  $this->ctrl->setParameter($this, "pgov_pos", $_REQUEST["pgov_pos"]);
895  $this->ctrl->redirect($this, 'browseForQuestionblocks');
896  }
897  }
898 
902  public function changeDatatypeObject()
903  {
904  global $ilUser;
905  $ilUser->writePref('svy_insert_type', $_POST['datatype']);
906  $this->ctrl->setParameter($this, "pgov", $_REQUEST["pgov"]);
907  $this->ctrl->setParameter($this, "pgov_pos", $_REQUEST["pgov_pos"]);
908  switch ($_POST["datatype"])
909  {
910  case 0:
911  $this->ctrl->redirect($this, 'browseForQuestionblocks');
912  break;
913  case 1:
914  default:
915  $this->ctrl->redirect($this, 'browseForQuestions');
916  break;
917  }
918  }
919 
924  {
925  include_once "./Modules/Survey/classes/tables/class.ilSurveyQuestionblockbrowserTableGUI.php";
926  $table_gui = new ilSurveyQuestionblockbrowserTableGUI($this, 'browseForQuestionblocks');
927  $table_gui->writeFilterToSession();
928  $this->ctrl->setParameter($this, "pgov", $_REQUEST["pgov"]);
929  $this->ctrl->setParameter($this, "pgov_pos", $_REQUEST["pgov_pos"]);
930  $this->ctrl->redirect($this, 'browseForQuestionblocks');
931  }
932 
937  {
938  include_once "./Modules/Survey/classes/tables/class.ilSurveyQuestionblockbrowserTableGUI.php";
939  $table_gui = new ilSurveyQuestionblockbrowserTableGUI($this, 'browseForQuestionblocks');
940  $table_gui->resetFilter();
941  $this->ctrl->setParameter($this, "pgov", $_REQUEST["pgov"]);
942  $this->ctrl->setParameter($this, "pgov_pos", $_REQUEST["pgov_pos"]);
943  $this->ctrl->redirect($this, 'browseForQuestionblocks');
944  }
945 
949  public function browseForQuestionblocksObject($arrFilter = null)
950  {
951  global $rbacsystem;
952  global $ilUser;
953 
954  $this->ctrl->setParameter($this, "pgov", $_REQUEST["pgov"]);
955  $this->ctrl->setParameter($this, "pgov_pos", $_REQUEST["pgov_pos"]);
956 
958  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_svy_questionbrowser.html", "Modules/Survey");
959  include_once "./Modules/Survey/classes/tables/class.ilSurveyQuestionblockbrowserTableGUI.php";
960  $table_gui = new ilSurveyQuestionblockbrowserTableGUI($this, 'browseForQuestionblocks', (($rbacsystem->checkAccess('write', $_GET['ref_id']) ? true : false)));
961  $table_gui->setEditable($rbacsystem->checkAccess('write', $_GET['ref_id']));
962  $arrFilter = array();
963  foreach ($table_gui->getFilterItems() as $item)
964  {
965  if ($item->getValue() !== false)
966  {
967  $arrFilter[$item->getPostVar()] = $item->getValue();
968  }
969  }
970  $data = $this->object->getQuestionblocksTable($arrFilter);
971  $table_gui->setData($data);
972  $this->tpl->setVariable('TABLE', $table_gui->getHTML());
973 
974  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this, 'changeDatatype'));
975  $this->tpl->setVariable("OPTION_QUESTIONS", $this->lng->txt("questions"));
976  $this->tpl->setVariable("OPTION_QUESTIONBLOCKS", $this->lng->txt("questionblocks"));
977  $this->tpl->setVariable("SELECTED_QUESTIONBLOCKS", " selected=\"selected\"");
978  $this->tpl->setVariable("TEXT_DATATYPE", $this->lng->txt("display_all_available"));
979  $this->tpl->setVariable("BTN_CHANGE", $this->lng->txt("change"));
980  }
981 
985  public function filterQuestionBrowserObject()
986  {
987  include_once "./Modules/Survey/classes/tables/class.ilSurveyQuestionbrowserTableGUI.php";
988  $table_gui = new ilSurveyQuestionbrowserTableGUI($this, 'browseForQuestions');
989  $table_gui->writeFilterToSession();
990  $this->ctrl->setParameter($this, "pgov", $_REQUEST["pgov"]);
991  $this->ctrl->setParameter($this, "pgov_pos", $_REQUEST["pgov_pos"]);
992  $this->ctrl->redirect($this, 'browseForQuestions');
993  }
994 
999  {
1000  include_once "./Modules/Survey/classes/tables/class.ilSurveyQuestionbrowserTableGUI.php";
1001  $table_gui = new ilSurveyQuestionbrowserTableGUI($this, 'browseForQuestions');
1002  $table_gui->resetFilter();
1003  $this->ctrl->setParameter($this, "pgov", $_REQUEST["pgov"]);
1004  $this->ctrl->setParameter($this, "pgov_pos", $_REQUEST["pgov_pos"]);
1005  $this->ctrl->redirect($this, 'browseForQuestions');
1006  }
1007 
1011  public function browseForQuestionsObject($arrFilter = null)
1012  {
1013  global $rbacsystem;
1014  global $ilUser;
1015 
1016  $this->ctrl->setParameter($this, "pgov", $_REQUEST["pgov"]);
1017  $this->ctrl->setParameter($this, "pgov_pos", $_REQUEST["pgov_pos"]);
1018 
1020  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_svy_questionbrowser.html", "Modules/Survey");
1021  include_once "./Modules/Survey/classes/tables/class.ilSurveyQuestionbrowserTableGUI.php";
1022  $table_gui = new ilSurveyQuestionbrowserTableGUI($this, 'browseForQuestions', (($rbacsystem->checkAccess('write', $_GET['ref_id']) ? true : false)));
1023  $table_gui->setEditable($rbacsystem->checkAccess('write', $_GET['ref_id']));
1024  $arrFilter = array();
1025  foreach ($table_gui->getFilterItems() as $item)
1026  {
1027  if ($item->getValue() !== false)
1028  {
1029  $arrFilter[$item->getPostVar()] = $item->getValue();
1030  }
1031  }
1032  $data = $this->object->getQuestionsTable($arrFilter);
1033 
1034  // translate pools for proper sorting
1035  if(sizeof($data))
1036  {
1037  $pools = $table_gui->getQuestionPools();
1038  foreach($data as $idx => $row)
1039  {
1040  $data[$idx]["spl"] = $pools[$row["obj_fi"]];
1041  }
1042  }
1043 
1044  $table_gui->setData($data);
1045  $this->tpl->setVariable('TABLE', $table_gui->getHTML());
1046 
1047  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this, 'changeDatatype'));
1048  $this->tpl->setVariable("OPTION_QUESTIONS", $this->lng->txt("questions"));
1049  $this->tpl->setVariable("OPTION_QUESTIONBLOCKS", $this->lng->txt("questionblocks"));
1050  $this->tpl->setVariable("SELECTED_QUESTIONS", " selected=\"selected\"");
1051  $this->tpl->setVariable("TEXT_DATATYPE", $this->lng->txt("display_all_available"));
1052  $this->tpl->setVariable("BTN_CHANGE", $this->lng->txt("change"));
1053  }
1054 
1062  function removeQuestionsForm($checked_questionblocks, $checked_questions, $checked_headings)
1063  {
1064  include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
1065  $cgui = new ilConfirmationGUI();
1066  $cgui->setHeaderText($this->lng->txt("survey_sure_delete_questions"));
1067 
1068  $cgui->setFormAction($this->ctrl->getFormAction($this, "confirmRemoveQuestions"));
1069  $cgui->setCancel($this->lng->txt("cancel"), "cancelRemoveQuestions");
1070  $cgui->setConfirm($this->lng->txt("confirm"), "confirmRemoveQuestions");
1071 
1072 
1073  $counter = 0;
1074  $surveyquestions =& $this->object->getSurveyQuestions();
1075  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
1076  foreach ($surveyquestions as $question_id => $data)
1077  {
1078  if (in_array($data["question_id"], $checked_questions))
1079  {
1080  $type = SurveyQuestion::_getQuestionTypeName($data["type_tag"]);
1081 
1082  $cgui->addItem("id_".$data["question_id"], $data["question_id"],
1083  $type.": ".$data["title"]);
1084  }
1085  else if((in_array($data["questionblock_id"], $checked_questionblocks)))
1086  {
1087  $type = SurveyQuestion::_getQuestionTypeName($data["type_tag"]);
1088 
1089  $cgui->addItem("id_qb_".$data["questionblock_id"], $data["questionblock_id"],
1090  $data["questionblock_title"]." - ".$type.": ".$data["title"]);
1091 
1092  /*
1093  $data["description"]
1094  ;
1095  */
1096  }
1097  else if (in_array($data["question_id"], $checked_headings))
1098  {
1099  $cgui->addItem("id_tb_".$data["question_id"], $data["question_id"],
1100  $data["heading"]);
1101  }
1102  }
1103 
1104  $this->tpl->setContent($cgui->getHTML());
1105  }
1106 
1107 
1114  function defineQuestionblock($questionblock_id = "", $question_ids = null)
1115  {
1116  $this->questionsSubtabs("questions");
1117  if ($questionblock_id)
1118  {
1119  $questionblock = $this->object->getQuestionblock($questionblock_id);
1120  }
1121 
1122  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
1123  $form = new ilPropertyFormGUI();
1124  $form->setFormAction($this->ctrl->getFormAction($this, "saveDefineQuestionblock"));
1125  $form->setTableWidth("100%");
1126  $form->setId("survey_questionblock");
1127  $form->setTitle($this->lng->txt("define_questionblock"));
1128 
1129  $title = new ilTextInputGUI($this->lng->txt("title"), "title");
1130  $title->setRequired(true);
1131  if ($questionblock_id)
1132  {
1133  $title->setValue($questionblock["title"]);
1134  }
1135  $form->addItem($title);
1136 
1137  $toggle_blocktitle = new ilCheckboxInputGUI($this->lng->txt("survey_show_blocktitle"), "show_blocktitle");
1138  $toggle_blocktitle->setInfo($this->lng->txt("survey_show_blocktitle_description"));
1139  if (($questionblock["show_blocktitle"]) || (strlen($questionblock_id) == 0))
1140  {
1141  $toggle_blocktitle->setChecked(true);
1142  }
1143  $form->addItem($toggle_blocktitle);
1144 
1145  $toggle_questiontitle = new ilCheckboxInputGUI($this->lng->txt("show_questiontext"), "show_questiontext");
1146  $toggle_questiontitle->setInfo($this->lng->txt("show_questiontext_description"));
1147  if (($questionblock["show_questiontext"]) || (strlen($questionblock_id) == 0))
1148  {
1149  $toggle_questiontitle->setChecked(true);
1150  }
1151  $form->addItem($toggle_questiontitle);
1152 
1153  $form->addCommandButton("saveDefineQuestionblock", $this->lng->txt("save"));
1154  $form->addCommandButton("cancelDefineQuestionblock", $this->lng->txt("cancel"));
1155 
1156  if ($question_ids)
1157  {
1158  foreach ($question_ids as $q_id)
1159  {
1160  $hidden = new ilHiddenInputGUI("qids[]");
1161  $hidden->setValue($q_id);
1162  $form->addItem($hidden);
1163  }
1164  }
1165  if ($questionblock_id)
1166  {
1167  $hidden = new ilHiddenInputGUI("questionblock_id");
1168  $hidden->setValue($questionblock_id);
1169  $form->addItem($hidden);
1170  }
1171 
1172  $this->tpl->setContent($form->getHTML());
1173  }
1174 
1180  function createQuestionObject(ilPropertyFormGUI $a_form = null)
1181  {
1182  global $ilUser;
1183 
1184  if(!$this->object->isPoolActive())
1185  {
1186  $_POST["usage"] = 1;
1187  $_GET["sel_question_types"] = $_POST["sel_question_types"];
1188  return $this->executeCreateQuestionObject();
1189  }
1190 
1191  if(!$a_form)
1192  {
1193  if(!$_REQUEST["pgov"])
1194  {
1195  $this->questionsSubtabs("questions");
1196  }
1197  else
1198  {
1199  $this->questionsSubtabs("questions_per_page");
1200  }
1201 
1202  include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
1203  $form = new ilPropertyFormGUI();
1204 
1205  $sel_question_types = (strlen($_POST["sel_question_types"])) ? $_POST["sel_question_types"] : $_GET["sel_question_types"];
1206  $this->ctrl->setParameter($this, "sel_question_types", $sel_question_types);
1207  $form->setFormAction($this->ctrl->getFormAction($this, "executeCreateQuestion"));
1208  }
1209  else
1210  {
1211  $form = $a_form;
1212  }
1213 
1214  $usage = new ilRadioGroupInputGUI($this->lng->txt("survey_pool_selection"), "usage");
1215  $usage->setRequired(true);
1216  $no_pool = new ilRadioOption($this->lng->txt("survey_no_pool"), 1);
1217  $usage->addOption($no_pool);
1218  $existing_pool = new ilRadioOption($this->lng->txt("survey_existing_pool"), 3);
1219  $usage->addOption($existing_pool);
1220  $new_pool = new ilRadioOption($this->lng->txt("survey_new_pool"), 2);
1221  $usage->addOption($new_pool);
1222  $form->addItem($usage);
1223 
1224  if(isset($_SESSION["svy_qpool_choice"]))
1225  {
1226  $usage->setValue($_SESSION["svy_qpool_choice"]);
1227  }
1228  else
1229  {
1230  // default: no pool
1231  $usage->setValue(1);
1232  }
1233 
1234  $questionpools =& $this->object->getAvailableQuestionpools(FALSE, TRUE, TRUE, "write");
1235  $pools = new ilSelectInputGUI($this->lng->txt("select_questionpool"), "sel_spl");
1236  $pools->setOptions($questionpools);
1237  $existing_pool->addSubItem($pools);
1238 
1239  $name = new ilTextInputGUI($this->lng->txt("spl_new"), "name_spl"); // #11740
1240  $name->setSize(50);
1241  $name->setMaxLength(50);
1242  $new_pool->addSubItem($name);
1243 
1244  if($a_form)
1245  {
1246  return $a_form;
1247  }
1248 
1249  $form->addCommandButton("executeCreateQuestion", $this->lng->txt("submit"));
1250  $form->addCommandButton("cancelCreateQuestion", $this->lng->txt("cancel"));
1251 
1252  return $this->tpl->setContent($form->getHTML());
1253  }
1254 
1261  {
1262  $this->ctrl->redirect($this, "questions");
1263  }
1264 
1271  {
1272  $addurl = "";
1273  if($_REQUEST["pgov"])
1274  {
1275  $addurl .= "&pgov=".$_REQUEST["pgov"]."&pgov_pos=".$_REQUEST["pgov_pos"];
1276  }
1277 
1278  include_once "./Services/Utilities/classes/class.ilUtil.php";
1279 
1280  $_SESSION["svy_qpool_choice"] = $_POST["usage"];
1281 
1282  // no pool
1283  if ($_POST["usage"] == 1)
1284  {
1285  ilUtil::redirect("ilias.php?baseClass=ilObjSurveyQuestionPoolGUI&ref_id=".
1286  $_GET["ref_id"]."&cmd=createQuestionForSurvey&new_for_survey=".
1287  $_GET["ref_id"]."&sel_question_types=".$_GET["sel_question_types"].$addurl);
1288  }
1289  // existing pool
1290  else if ($_POST["usage"] == 3 && strlen($_POST["sel_spl"]))
1291  {
1292  ilUtil::redirect("ilias.php?baseClass=ilObjSurveyQuestionPoolGUI&ref_id=".
1293  $_POST["sel_spl"]."&cmd=createQuestionForSurvey&new_for_survey=".$_GET["ref_id"].
1294  "&sel_question_types=".$_GET["sel_question_types"].$addurl);
1295  }
1296  // new pool
1297  elseif ($_POST["usage"] == 2 && strlen($_POST["name_spl"]))
1298  {
1299  $ref_id = $this->createQuestionPool($_POST["name_spl"]);
1300  ilUtil::redirect("ilias.php?baseClass=ilObjSurveyQuestionPoolGUI&ref_id=".$ref_id.
1301  "&cmd=createQuestionForSurvey&new_for_survey=".$_GET["ref_id"].
1302  "&sel_question_types=".$_GET["sel_question_types"].$addurl);
1303  }
1304  else
1305  {
1306  if(!$_POST["usage"])
1307  {
1308  ilUtil::sendFailure($this->lng->txt("select_one"), true);
1309  }
1310  else
1311  {
1312  ilUtil::sendFailure($this->lng->txt("err_no_pool_name"), true);
1313  }
1314  $this->ctrl->setParameter($this, "sel_question_types", $_GET["sel_question_types"]);
1315  $this->ctrl->redirect($this, "createQuestion");
1316  }
1317  }
1318 
1325  private function createQuestionPool($name = "dummy")
1326  {
1327  global $tree;
1328  $parent_ref = $tree->getParentId($this->object->getRefId());
1329  include_once "./Modules/SurveyQuestionPool/classes/class.ilObjSurveyQuestionPool.php";
1330  $qpl = new ilObjSurveyQuestionPool();
1331  $qpl->setType("spl");
1332  $qpl->setTitle($name);
1333  $qpl->setDescription("");
1334  $qpl->create();
1335  $qpl->createReference();
1336  $qpl->putInTree($parent_ref);
1337  $qpl->setPermissions($parent_ref);
1338  $qpl->setOnline(1); // must be online to be available
1339  $qpl->saveToDb();
1340  return $qpl->getRefId();
1341  }
1342 
1349  function addHeadingObject($checkonly = false, $question_id = "")
1350  {
1351  $this->questionsSubtabs("questions");
1352 
1353  global $ilAccess;
1354 
1355  $save = (strcmp($this->ctrl->getCmd(), "saveHeading") == 0) ? TRUE : FALSE;
1356 
1357  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
1358  $form = new ilPropertyFormGUI();
1359  $form->setFormAction($this->ctrl->getFormAction($this));
1360  $form->setTableWidth("100%");
1361  $form->setId("survey_heading");
1362 
1363  // general properties
1364  $header = new ilFormSectionHeaderGUI();
1365  if ($question_id)
1366  {
1367  $header->setTitle($this->lng->txt("edit_heading"));
1368  }
1369  else
1370  {
1371  $header->setTitle($this->lng->txt("add_heading"));
1372  }
1373  $form->addItem($header);
1374 
1375  $survey_questions =& $this->object->getSurveyQuestions();
1376 
1377  // heading
1378  $heading = new ilTextAreaInputGUI($this->lng->txt("heading"), "heading");
1379  $heading->setValue($this->object->prepareTextareaOutput(array_key_exists('heading', $_POST) ? $_POST['heading'] : $survey_questions[$question_id]["heading"]));
1380  $heading->setRows(10);
1381  $heading->setCols(80);
1382  $heading->setUseRte(TRUE);
1383  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
1384  $heading->setRteTags(ilObjAdvancedEditing::_getUsedHTMLTags("survey"));
1385  $heading->removePlugin(ilRTE::ILIAS_IMG_MANAGER_PLUGIN);
1386  $heading->setRTESupport($this->object->getId(), "svy", "survey", null, false, "3.4.7");
1387  $heading->setRequired(true);
1388  $form->addItem($heading);
1389 
1390  $insertbefore = new ilSelectInputGUI($this->lng->txt("insert"), "insertbefore");
1391  $options = array();
1392  foreach ($survey_questions as $key => $value)
1393  {
1394  $options[$key] = $this->lng->txt("before") . ": \"" . $value["title"] . "\"";
1395  }
1396  $insertbefore->setOptions($options);
1397  $insertbefore->setValue((array_key_exists('insertbefore', $_REQUEST)) ? $_REQUEST['insertbefore'] : $question_id);
1398  $insertbefore->setRequired(true);
1399  if ($question_id || array_key_exists('insertbefore', $_REQUEST))
1400  {
1401  $insertbefore->setDisabled(true);
1402  }
1403  $form->addItem($insertbefore);
1404 
1405  if ($ilAccess->checkAccess("write", "", $_GET["ref_id"])) $form->addCommandButton("saveHeading", $this->lng->txt("save"));
1406  if ($ilAccess->checkAccess("write", "", $_GET["ref_id"])) $form->addCommandButton("cancelHeading", $this->lng->txt("cancel"));
1407  $errors = false;
1408 
1409  if ($save)
1410  {
1411  $errors = !$form->checkInput();
1412  $form->setValuesByPost();
1413  if ($errors) $checkonly = false;
1414  }
1415  if (!$checkonly) $this->tpl->setVariable("ADM_CONTENT", $form->getHTML());
1416  return $errors;
1417  }
1418 
1425  {
1426  // insert questions from test after confirmation
1427  foreach ($_POST as $key => $value) {
1428  if (preg_match("/id_(\d+)/", $key, $matches)) {
1429  if ($_GET["browsetype"] == 1)
1430  {
1431  $this->object->insertQuestion($matches[1]);
1432  }
1433  else
1434  {
1435  $this->object->insertQuestionBlock($matches[1]);
1436  }
1437  }
1438  }
1439  $this->object->saveCompletionStatus();
1440  ilUtil::sendSuccess($this->lng->txt("questions_inserted"), true);
1441  $this->ctrl->redirect($this, "questions");
1442  }
1443 
1450  {
1451  $this->ctrl->redirect($this, "questions");
1452  }
1453 
1462  {
1463  $hasErrors = $this->addHeadingObject(true);
1464  if (!$hasErrors)
1465  {
1466  $insertbefore = $_POST["insertbefore"];
1467  if (!$insertbefore)
1468  {
1469  $insertbefore = $_POST["insertbefore_original"];
1470  }
1471  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
1472  $this->object->saveHeading(ilUtil::stripSlashes($_POST["heading"], TRUE, ilObjAdvancedEditing::_getUsedHTMLTagsAsString("survey")), $insertbefore);
1473  $this->ctrl->redirect($this, "questions");
1474  }
1475  }
1476 
1485  {
1486  $this->ctrl->redirect($this, "questions");
1487  }
1488 
1497  {
1498  $this->object->saveHeading("", $_POST["removeheading"]);
1499  $this->ctrl->redirect($this, "questions");
1500  }
1501 
1510  {
1511  $this->ctrl->redirect($this, "questions");
1512  }
1513 
1522  {
1523  ilUtil::sendQuestion($this->lng->txt("confirm_remove_heading"));
1524  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_svy_confirm_removeheading.html", "Modules/Survey");
1525  $this->tpl->setCurrentBlock("adm_content");
1526  $this->tpl->setVariable("BTN_CONFIRM_REMOVE", $this->lng->txt("confirm"));
1527  $this->tpl->setVariable("BTN_CANCEL_REMOVE", $this->lng->txt("cancel"));
1528  $this->tpl->setVariable("REMOVE_HEADING", $_GET["removeheading"]);
1529  $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this, "confirmRemoveHeading"));
1530  $this->tpl->parseCurrentBlock();
1531  }
1532 
1541  {
1542  $checked_questions = array();
1543  $checked_questionblocks = array();
1544  $checked_headings = array();
1545  foreach ($_POST as $key => $value)
1546  {
1547  if (preg_match("/id_(\d+)/", $key, $matches))
1548  {
1549  array_push($checked_questions, $matches[1]);
1550  }
1551  if (preg_match("/id_qb_(\d+)/", $key, $matches))
1552  {
1553  array_push($checked_questionblocks, $matches[1]);
1554  }
1555  if (preg_match("/id_tb_(\d+)/", $key, $matches))
1556  {
1557  array_push($checked_headings, $matches[1]);
1558  }
1559  }
1560 
1561  if(sizeof($checked_questions) || sizeof($checked_questionblocks))
1562  {
1563  $this->object->removeQuestions($checked_questions, $checked_questionblocks);
1564  }
1565  if($checked_headings)
1566  {
1567  foreach($checked_headings as $q_id)
1568  {
1569  $this->object->saveHeading("", $q_id);
1570  }
1571  }
1572  $this->object->saveCompletionStatus();
1573  ilUtil::sendSuccess($this->lng->txt("questions_removed"), true);
1574  $this->ctrl->redirect($this, "questions");
1575  }
1576 
1585  {
1586  $this->ctrl->redirect($this, "questions");
1587  }
1588 
1598  protected function gatherSelectedTableItems($allow_blocks = true, $allow_questions = true, $allow_headings = false, $allow_questions_in_blocks = false)
1599  {
1600  $block_map = array();
1601  foreach($this->object->getSurveyQuestions() as $item)
1602  {
1603  $block_map[$item["question_id"]] = $item["questionblock_id"];
1604  }
1605 
1606  $questions = $blocks = $headings = array();
1607  if($_POST["id"])
1608  {
1609  foreach ($_POST["id"] as $key)
1610  {
1611  // questions
1612  if ($allow_questions && preg_match("/cb_(\d+)/", $key, $matches))
1613  {
1614  if(($allow_questions_in_blocks || !$block_map[$matches[1]]) &&
1615  !in_array($block_map[$matches[1]], $blocks))
1616  {
1617  array_push($questions, $matches[1]);
1618  }
1619  }
1620  // blocks
1621  if ($allow_blocks && preg_match("/cb_qb_(\d+)/", $key, $matches))
1622  {
1623  array_push($blocks, $matches[1]);
1624  }
1625  // headings
1626  if ($allow_headings && preg_match("/cb_tb_(\d+)/", $key, $matches))
1627  {
1628  array_push($headings, $matches[1]);
1629  }
1630  }
1631  }
1632 
1633  return array("questions" => $questions,
1634  "blocks" => $blocks,
1635  "headings" => $headings);
1636  }
1637 
1646  {
1647  $items = $this->gatherSelectedTableItems(false, true, false, false);
1648  if(sizeof($_POST["qids"]))
1649  {
1650  $items["questions"] = $_POST["qids"];
1651  }
1652  if (count($items["questions"]) < 2)
1653  {
1654  ilUtil::sendInfo($this->lng->txt("qpl_define_questionblock_select_missing"), true);
1655  $this->ctrl->redirect($this, "questions");
1656  }
1657  else
1658  {
1659  $this->defineQuestionblock("", $items["questions"]);
1660  return;
1661  }
1662  }
1663 
1668  {
1669  if ($_POST["title"])
1670  {
1671  $show_questiontext = ($_POST["show_questiontext"]) ? 1 : 0;
1672  $show_blocktitle = ($_POST["show_blocktitle"]) ? 1 : 0;
1673  if ($_POST["questionblock_id"])
1674  {
1675  include_once "./Services/Utilities/classes/class.ilUtil.php";
1676  $this->object->modifyQuestionblock($_POST["questionblock_id"], ilUtil::stripSlashes($_POST["title"]), $show_questiontext, $show_blocktitle);
1677  }
1678  else
1679  {
1680  include_once "./Services/Utilities/classes/class.ilUtil.php";
1681  $this->object->createQuestionblock(ilUtil::stripSlashes($_POST["title"]), $show_questiontext, $show_blocktitle, $_POST["qids"]);
1682  }
1683  ilUtil::sendSuccess($this->lng->txt('msg_obj_modified'), true);
1684  $this->ctrl->setParameter($this, "pgov", $_REQUEST["pgov"]);
1685  $this->ctrl->redirect($this, "questions");
1686  }
1687  else
1688  {
1689  ilUtil::sendInfo($this->lng->txt("enter_questionblock_title"));
1690 
1691  // #14433
1692  if(!$_POST["questionblock_id"])
1693  {
1694  $this->defineQuestionblockObject();
1695  }
1696  else
1697  {
1698  $this->defineQuestionblock($_POST["questionblock_id"]);
1699  }
1700  return;
1701  }
1702  }
1703 
1707  public function unfoldQuestionblockObject()
1708  {
1709  $items = $this->gatherSelectedTableItems(true, false, false, false);
1710  if (count($items["blocks"]))
1711  {
1712  ilUtil::sendSuccess($this->lng->txt('msg_obj_modified'), true);
1713  $this->object->unfoldQuestionblocks($items["blocks"]);
1714  }
1715  else
1716  {
1717  ilUtil::sendInfo($this->lng->txt("qpl_unfold_select_none"), true);
1718  }
1719  $this->ctrl->redirect($this, "questions");
1720  }
1721 
1726  {
1727  ilUtil::sendInfo($this->lng->txt('msg_cancel'), true);
1728  $this->ctrl->redirect($this, "questions");
1729  }
1730 
1734  public function moveQuestionsObject()
1735  {
1736  $items = $this->gatherSelectedTableItems(true, true, false, false);
1737 
1738  $move_questions = $items["questions"];
1739  foreach ($items["blocks"] as $block_id)
1740  {
1741  foreach ($this->object->getQuestionblockQuestionIds($block_id) as $qid)
1742  {
1743  array_push($move_questions, $qid);
1744  }
1745  }
1746  if (count($move_questions) == 0)
1747  {
1748  ilUtil::sendInfo($this->lng->txt("no_question_selected_for_move"), true);
1749  $this->ctrl->redirect($this, "questions");
1750  }
1751  else
1752  {
1753  $_SESSION["move_questions"] = $move_questions;
1754  ilUtil::sendInfo($this->lng->txt("select_target_position_for_move_question"));
1755  $this->questionsObject();
1756  }
1757  }
1758 
1762  public function insertQuestions($insert_mode)
1763  {
1764  $insert_id = null;
1765  if($_POST["id"])
1766  {
1767  $items = $this->gatherSelectedTableItems(true, true, false, false);
1768 
1769  // we are using POST id for original order
1770  while(!$insert_id && sizeof($_POST["id"]))
1771  {
1772  $target = array_shift($_POST["id"]);
1773  if (preg_match("/^cb_(\d+)$/", $target, $matches))
1774  {
1775  // questions in blocks are not allowed
1776  if(in_array($matches[1], $items["questions"]))
1777  {
1778  $insert_id = $matches[1];
1779  }
1780  }
1781  if (!$insert_id && preg_match("/^cb_qb_(\d+)$/", $target, $matches))
1782  {
1783  $ids = $this->object->getQuestionblockQuestionIds($matches[1]);
1784  if (count($ids))
1785  {
1786  if ($insert_mode == 0)
1787  {
1788  $insert_id = $ids[0];
1789  }
1790  else if ($insert_mode == 1)
1791  {
1792  $insert_id = $ids[count($ids)-1];
1793  }
1794  }
1795  }
1796  }
1797  }
1798 
1799  if(!$insert_id)
1800  {
1801  ilUtil::sendInfo($this->lng->txt("no_target_selected_for_move"), true);
1802  }
1803  else
1804  {
1805  ilUtil::sendSuccess($this->lng->txt('msg_obj_modified'), true);
1806  $this->object->moveQuestions($_SESSION["move_questions"], $insert_id, $insert_mode);
1807  unset($_SESSION["move_questions"]);
1808  }
1809 
1810  $this->ctrl->redirect($this, "questions");
1811  }
1812 
1817  {
1818  $this->insertQuestions(0);
1819  }
1820 
1824  public function insertQuestionsAfterObject()
1825  {
1826  $this->insertQuestions(1);
1827  }
1828 
1832  public function saveObligatoryObject()
1833  {
1834  if(isset($_POST["order"]))
1835  {
1836  $position = -1;
1837  $order = array();
1838  asort($_POST["order"]);
1839  foreach(array_keys($_POST["order"]) as $id)
1840  {
1841  // block items
1842  if(substr($id, 0, 3) == "qb_")
1843  {
1844  $block_id = substr($id, 3);
1845  $block = $_POST["block_order"][$block_id];
1846  asort($block);
1847  foreach(array_keys($block) as $question_id)
1848  {
1849  $position++;
1850  $order[$question_id] = $position;
1851  }
1852  }
1853  else
1854  {
1855  $question_id = substr($id, 2);
1856  $position++;
1857  $order[$question_id] = $position;
1858  }
1859  }
1860  $this->object->updateOrder($order);
1861  }
1862 
1863  $obligatory = array();
1864  foreach ($_POST as $key => $value)
1865  {
1866  if (preg_match("/obligatory_(\d+)/", $key, $matches))
1867  {
1868  $obligatory[$matches[1]] = 1;
1869  }
1870  }
1871  $this->object->setObligatoryStates($obligatory);
1872  ilUtil::sendSuccess($this->lng->txt('msg_obj_modified'), true);
1873  $this->ctrl->redirect($this, "questions");
1874  }
1875 
1879  public function questionsObject()
1880  {
1881  global $rbacsystem, $ilToolbar, $ilUser;
1882 
1883  $this->handleWriteAccess();
1884 
1885  $hasDatasets = $this->object->_hasDatasets($this->object->getSurveyId());
1886  include_once "./Services/Utilities/classes/class.ilUtil.php";
1887  if ((!$rbacsystem->checkAccess("read", $this->ref_id)) && (!$rbacsystem->checkAccess("write", $this->ref_id)))
1888  {
1889  // allow only read and write access
1890  ilUtil::sendInfo($this->lng->txt("cannot_edit_survey"), true);
1891  $path = $this->tree->getPathFull($this->object->getRefID());
1892  ilUtil::redirect($this->getReturnLocation("cancel","./ilias.php?baseClass=ilRepositoryGUI&cmd=frameset&ref_id=" . $path[count($path) - 2]["child"]));
1893  return;
1894  }
1895 
1896  if ($_GET["new_id"] > 0)
1897  {
1898  // add a question to the survey previous created in a questionpool
1899  $existing = $this->object->getExistingQuestions();
1900  if (!in_array($_GET["new_id"], $existing))
1901  {
1902  $inserted = $this->object->insertQuestion($_GET["new_id"]);
1903  if (!$inserted)
1904  {
1905  ilUtil::sendFailure($this->lng->txt("survey_error_insert_incomplete_question"));
1906  }
1907  }
1908  }
1909 
1910  if ($_GET["eqid"] and $_GET["eqpl"])
1911  {
1912  ilUtil::redirect("ilias.php?baseClass=ilObjSurveyQuestionPoolGUI&ref_id=" . $_GET["eqpl"] . "&cmd=editQuestionForSurvey&calling_survey=".$_GET["ref_id"]."&q_id=" . $_GET["eqid"]);
1913  }
1914 
1915 
1916  $_SESSION["calling_survey"] = $this->object->getRefId();
1917  unset($_SESSION["survey_id"]);
1918 
1919  if ($_GET["editheading"])
1920  {
1921  $this->addHeadingObject(false, $_GET["editheading"]);
1922  return;
1923  }
1924 
1925  /*
1926  if ($_GET["up"] > 0)
1927  {
1928  $this->object->moveUpQuestion($_GET["up"]);
1929  ilUtil::sendSuccess($this->lng->txt('msg_obj_modified'));
1930  }
1931  if ($_GET["down"] > 0)
1932  {
1933  $this->object->moveDownQuestion($_GET["down"]);
1934  ilUtil::sendSuccess($this->lng->txt('msg_obj_modified'));
1935  }
1936  if ($_GET["qbup"] > 0)
1937  {
1938  $this->object->moveUpQuestionblock($_GET["qbup"]);
1939  ilUtil::sendSuccess($this->lng->txt('msg_obj_modified'));
1940  }
1941  if ($_GET["qbdown"] > 0)
1942  {
1943  $this->object->moveDownQuestionblock($_GET["qbdown"]);
1944  ilUtil::sendSuccess($this->lng->txt('msg_obj_modified'));
1945  }
1946  */
1947 
1948  if ($_GET["removeheading"])
1949  {
1950  $this->confirmRemoveHeadingForm();
1951  return;
1952  }
1953 
1954  if ($_GET["editblock"])
1955  {
1956  $this->defineQuestionblock($_GET["editblock"]);
1957  return;
1958  }
1959 
1960  if ($_GET["add"])
1961  {
1962  // called after a new question was created from a questionpool
1963  $selected_array = array();
1964  array_push($selected_array, $_GET["add"]);
1965  ilUtil::sendQuestion($this->lng->txt("ask_insert_questions"));
1966  $this->insertQuestionsForm($selected_array);
1967  return;
1968  }
1969 
1970 
1971  $this->questionsSubtabs("questions");
1972 
1973  $read_only = (!$rbacsystem->checkAccess("write", $this->ref_id) || $hasDatasets);
1974 
1975 
1976  // toolbar
1977 
1978  if (!$read_only)
1979  {
1980  $qtypes = array();
1981  include_once "./Modules/SurveyQuestionPool/classes/class.ilObjSurveyQuestionPool.php";
1982  foreach (ilObjSurveyQuestionPool::_getQuestiontypes() as $translation => $data)
1983  {
1984  $qtypes[$data["type_tag"]] = $translation;
1985  }
1986 
1987  $ilToolbar->setFormAction($this->ctrl->getFormAction($this));
1988  include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
1989  $types = new ilSelectInputGUI($this->lng->txt("create_new"), "sel_question_types");
1990  $types->setOptions($qtypes);
1991  $ilToolbar->addInputItem($types, "");
1992  $ilToolbar->addFormButton($this->lng->txt("svy_create_question"), "createQuestion");
1993 
1994  if($this->object->isPoolActive())
1995  {
1996  $ilToolbar->addSeparator();
1997 
1998  $cmd = ($ilUser->getPref('svy_insert_type') == 1 || strlen($ilUser->getPref('svy_insert_type')) == 0) ? 'browseForQuestions' : 'browseForQuestionblocks';
1999  $ilToolbar->addButton($this->lng->txt("browse_for_questions"),
2000  $this->ctrl->getLinkTarget($this, $cmd));
2001  }
2002 
2003  $ilToolbar->addSeparator();
2004 
2005  $ilToolbar->addButton($this->lng->txt("add_heading"),
2006  $this->ctrl->getLinkTarget($this, "addHeading"));
2007  }
2008  if ($hasDatasets)
2009  {
2010  // ilUtil::sendInfo($this->lng->txt("survey_has_datasets_warning"));
2011  $link = $this->ctrl->getLinkTarget($this, "maintenance");
2012  $link = "<a href=\"".$link."\">".$this->lng->txt("survey_has_datasets_warning_page_view_link")."</a>";
2013  ilUtil::sendInfo($this->lng->txt("survey_has_datasets_warning_page_view")." ".$link);
2014  }
2015 
2016 
2017  // table gui
2018 
2019  include_once "Modules/Survey/classes/class.ilSurveyQuestionTableGUI.php";
2020  $table = new ilSurveyQuestionTableGUI($this, "questions", $this->object,
2021  $read_only);
2022  $this->tpl->setContent($table->getHTML());
2023  }
2024 
2032  function evaluationObject()
2033  {
2034  include_once("./Modules/Survey/classes/class.ilSurveyEvaluationGUI.php");
2035  $eval_gui = new ilSurveyEvaluationGUI($this->object);
2036  $this->ctrl->setCmdClass(get_class($eval_gui));
2037  $this->ctrl->redirect($eval_gui, "evaluation");
2038  }
2039 
2043  public function disinviteUserGroupObject()
2044  {
2045  // disinvite users
2046  if (is_array($_POST["user_select"]))
2047  {
2048  foreach ($_POST["user_select"] as $user_id)
2049  {
2050  $this->object->disinviteUser($user_id);
2051  }
2052  }
2053  ilUtil::sendSuccess($this->lng->txt('msg_users_disinvited'), true);
2054  $this->ctrl->redirect($this, "invite");
2055  }
2056 
2060  public function inviteUserGroupObject($a_user_ids = array())
2061  {
2062  $invited = 0;
2063  // add users to invitation
2064  if (is_array($a_user_ids))
2065  {
2066  foreach ($a_user_ids as $user_id)
2067  {
2068  $this->object->inviteUser($user_id);
2069  $invited++;
2070  }
2071  }
2072  if ($invited == 0)
2073  {
2074  ilUtil::sendFailure($this->lng->txt('no_user_invited'), TRUE);
2075  return false;
2076  }
2077  else
2078  {
2079  ilUtil::sendSuccess(sprintf($this->lng->txt('users_invited'), $invited), TRUE);
2080  return false;
2081  }
2082  $this->ctrl->redirect($this, "invite");
2083  }
2084 
2088  public function saveInvitationStatusObject()
2089  {
2090  $mode = $_POST['invitation'];
2091  switch ($mode)
2092  {
2093  case 0:
2094  $this->object->setInvitation(0);
2095  break;
2096  case 1:
2097  $this->object->setInvitation(1);
2098  $this->object->setInvitationMode(0);
2099  break;
2100  case 2:
2101  $this->object->setInvitation(1);
2102  $this->object->setInvitationMode(1);
2103  break;
2104  }
2105  $this->object->saveToDb();
2106  ilUtil::sendSuccess($this->lng->txt('msg_obj_modified'), true);
2107  $this->ctrl->redirect($this, "invite");
2108  }
2109 
2110 
2114  public function inviteObject()
2115  {
2116  global $ilAccess;
2117  global $rbacsystem;
2118  global $ilToolbar;
2119  global $lng;
2120 
2121  if (!$rbacsystem->checkAccess("visible,invite", $this->ref_id))
2122  {
2123  // allow only read and write access
2124  ilUtil::sendInfo($this->lng->txt("cannot_edit_survey"), true);
2125  $path = $this->tree->getPathFull($this->object->getRefID());
2126  include_once "./Services/Utilities/classes/class.ilUtil.php";
2127  ilUtil::redirect($this->getReturnLocation("cancel","./ilias.php?baseClass=ilRepositoryGUI&cmd=frameset&ref_id=" . $path[count($path) - 2]["child"]));
2128  return;
2129  }
2130 
2131  if ($this->object->getStatus() == STATUS_OFFLINE)
2132  {
2133  ilUtil::sendInfo($this->lng->txt("survey_offline_message"));
2134  return;
2135  }
2136 
2137  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
2138  $form = new ilPropertyFormGUI();
2139  $form->setFormAction($this->ctrl->getFormAction($this));
2140  $form->setTableWidth("500");
2141  $form->setId("invite");
2142 
2143  // invitation
2144  $header = new ilFormSectionHeaderGUI();
2145  $header->setTitle($this->lng->txt("invitation"));
2146  $form->addItem($header);
2147 
2148  // invitation mode
2149  $invitation = new ilRadioGroupInputGUI($this->lng->txt('invitation_mode'), "invitation");
2150  $invitation->setInfo($this->lng->txt('invitation_mode_desc'));
2151  $invitation->addOption(new ilRadioOption($this->lng->txt("invitation_off"), 0, ''));
2152  $surveySetting = new ilSetting("survey");
2153  if ($surveySetting->get("unlimited_invitation"))
2154  {
2155  $invitation->addOption(new ilRadioOption($this->lng->txt("unlimited_users"), 1, ''));
2156  }
2157  $invitation->addOption(new ilRadioOption($this->lng->txt("predefined_users"), 2, ''));
2158  $inv = 0;
2159  if ($this->object->getInvitation())
2160  {
2161  $inv = $this->object->getInvitationMode() + 1;
2162  }
2163  $invitation->setValue($inv);
2164  $form->addItem($invitation);
2165 
2166  $form->addCommandButton("saveInvitationStatus", $this->lng->txt("save"));
2167 
2168  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_svy_invite.html", "Modules/Survey");
2169  $this->tpl->setVariable("INVITATION_TABLE", $form->getHTML());
2170 
2171  if ($this->object->getInvitation() && $this->object->getInvitationMode() == 1)
2172  {
2173  // search button
2174  include_once './Services/Search/classes/class.ilRepositorySearchGUI.php';
2176  $this,
2177  $tb,
2178  array(
2179  'auto_complete_name' => $lng->txt('user'),
2180  'submit_name' => $lng->txt('svy_invite_action')
2181  )
2182  );
2183 
2184  $ilToolbar->addSpacer();
2185 
2186  $ilToolbar->addButton($this->lng->txt("svy_search_users"),
2187  $this->ctrl->getLinkTargetByClass('ilRepositorySearchGUI',''));
2188 
2189  $this->tpl->setVariable("ADM_CONTENT", $form->getHTML());
2190 
2191  $invited_users = $this->object->getUserData($this->object->getInvitedUsers());
2192  include_once "./Modules/Survey/classes/tables/class.ilSurveyInvitedUsersTableGUI.php";
2193  $table_gui = new ilSurveyInvitedUsersTableGUI($this, 'invite');
2194  $table_gui->setData($invited_users);
2195  $this->tpl->setVariable('TBL_INVITED_USERS', $table_gui->getHTML());
2196  }
2197  }
2198 
2202  public function deleteAllUserDataObject()
2203  {
2204  include_once "Services/Utilities/classes/class.ilConfirmationGUI.php";
2205  $cgui = new ilConfirmationGUI();
2206  $cgui->setHeaderText($this->lng->txt("confirm_delete_all_user_data"));
2207  $cgui->setFormAction($this->ctrl->getFormAction($this, "deleteAllUserData"));
2208  $cgui->setCancel($this->lng->txt("cancel"), "cancelDeleteAllUserData");
2209  $cgui->setConfirm($this->lng->txt("confirm"), "confirmDeleteAllUserData");
2210  $this->tpl->setContent($cgui->getHTML());
2211  }
2212 
2217  {
2218  $this->object->deleteAllUserData();
2219  ilUtil::sendSuccess($this->lng->txt("svy_all_user_data_deleted"), true);
2220  $this->ctrl->redirect($this, "maintenance");
2221  }
2222 
2227  {
2228  $this->ctrl->redirect($this, "maintenance");
2229  }
2230 
2235  {
2236  $this->object->removeSelectedSurveyResults($_POST["chbUser"]);
2237  ilUtil::sendSuccess($this->lng->txt("svy_selected_user_data_deleted"), true);
2238  $this->ctrl->redirect($this, "maintenance");
2239  }
2240 
2245  {
2246  ilUtil::sendInfo($this->lng->txt('msg_cancel'), true);
2247  $this->ctrl->redirect($this, "maintenance");
2248  }
2249 
2254  {
2255  $this->handleWriteAccess();
2256 
2257  if (count($_POST["chbUser"]) == 0)
2258  {
2259  ilUtil::sendInfo($this->lng->txt('no_checkbox'), true);
2260  $this->ctrl->redirect($this, "maintenance");
2261  }
2262 
2263  ilUtil::sendQuestion($this->lng->txt("confirm_delete_single_user_data"));
2264  include_once "./Modules/Survey/classes/tables/class.ilSurveyMaintenanceTableGUI.php";
2265  $table_gui = new ilSurveyMaintenanceTableGUI($this, 'maintenance', true);
2266  $total =& $this->object->getSurveyParticipants();
2267  $data = array();
2268  foreach ($total as $user_data)
2269  {
2270  if (in_array($user_data['active_id'], $_POST['chbUser']))
2271  {
2272  $last_access = $this->object->_getLastAccess($user_data["active_id"]);
2273  array_push($data, array(
2274  'id' => $user_data["active_id"],
2275  'name' => $user_data["sortname"],
2276  'login' => $user_data["login"],
2277  'last_access' => $last_access
2278  ));
2279  }
2280  }
2281  $table_gui->setData($data);
2282  $this->tpl->setVariable('ADM_CONTENT', $table_gui->getHTML());
2283  }
2284 
2288  public function maintenanceObject()
2289  {
2290  $this->handleWriteAccess();
2291 
2292  if ($_GET["fill"] > 0)
2293  {
2294  for ($i = 0; $i < $_GET["fill"]; $i++) $this->object->fillSurveyForUser();
2295  }
2296  include_once "./Modules/Survey/classes/tables/class.ilSurveyMaintenanceTableGUI.php";
2297  $table_gui = new ilSurveyMaintenanceTableGUI($this, 'maintenance');
2298  $total =& $this->object->getSurveyParticipants();
2299  $data = array();
2300  foreach ($total as $user_data)
2301  {
2302  $last_access = $this->object->_getLastAccess($user_data["active_id"]);
2303  array_push($data, array(
2304  'id' => $user_data["active_id"],
2305  'name' => $user_data["sortname"],
2306  'login' => $user_data["login"],
2307  'last_access' => $last_access
2308  ));
2309  }
2310  $table_gui->setData($data);
2311  $this->tpl->setVariable('ADM_CONTENT', $table_gui->getHTML());
2312  }
2313 
2314  protected function initImportForm($a_new_type)
2315  {
2316  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
2317  $form = new ilPropertyFormGUI();
2318  $form->setTarget("_top");
2319  $form->setFormAction($this->ctrl->getFormAction($this));
2320  $form->setTitle($this->lng->txt("import_svy"));
2321 
2322  include_once("./Services/Form/classes/class.ilFileInputGUI.php");
2323  $fi = new ilFileInputGUI($this->lng->txt("import_file"), "importfile");
2324  $fi->setSuffixes(array("zip"));
2325  $fi->setRequired(true);
2326  $form->addItem($fi);
2327 
2328  include_once("./Modules/Survey/classes/class.ilObjSurvey.php");
2329  $svy = new ilObjSurvey();
2330  $questionspools = $svy->getAvailableQuestionpools(true, true, true);
2331 
2332  $pools = new ilSelectInputGUI($this->lng->txt("select_questionpool_short"), "spl");
2333  $pools->setOptions(array(""=>$this->lng->txt("dont_use_questionpool")) + $questionspools);
2334  $pools->setRequired(false);
2335  $form->addItem($pools);
2336 
2337  $form->addCommandButton("importFile", $this->lng->txt("import"));
2338  $form->addCommandButton("cancel", $this->lng->txt("cancel"));
2339 
2340  return $form;
2341  }
2342 
2346  function importFileObject()
2347  {
2348  global $tpl, $ilErr;
2349 
2350  $parent_id = $_GET["ref_id"];
2351  $new_type = $_REQUEST["new_type"];
2352 
2353  // create permission is already checked in createObject. This check here is done to prevent hacking attempts
2354  if (!$this->checkPermissionBool("create", "", $new_type))
2355  {
2356  $ilErr->raiseError($this->lng->txt("no_create_permission"));
2357  }
2358 
2359  $this->lng->loadLanguageModule($new_type);
2360  $this->ctrl->setParameter($this, "new_type", $new_type);
2361 
2362  $form = $this->initImportForm($new_type);
2363  if ($form->checkInput())
2364  {
2365  include_once("./Modules/Survey/classes/class.ilObjSurvey.php");
2366  $newObj = new ilObjSurvey();
2367  $newObj->setType($new_type);
2368  $newObj->setTitle("dummy");
2369  $newObj->setDescription("dummy");
2370  $newObj->create(true);
2371  $this->putObjectInTree($newObj);
2372 
2373  // copy uploaded file to import directory
2374  $error = $newObj->importObject($_FILES["importfile"], $form->getInput("spl"));
2375  if (strlen($error))
2376  {
2377  $newObj->delete();
2378  $this->ilias->raiseError($error, $this->ilias->error_obj->MESSAGE);
2379  return;
2380  }
2381 
2382  ilUtil::sendSuccess($this->lng->txt("object_imported"),true);
2383  ilUtil::redirect("ilias.php?ref_id=".$newObj->getRefId().
2384  "&baseClass=ilObjSurveyGUI");
2385 
2386  // using template?
2387  include_once "Services/Administration/classes/class.ilSettingsTemplate.php";
2388  $templates = ilSettingsTemplate::getAllSettingsTemplates("svy");
2389  if($templates)
2390  {
2391  global $tpl;
2392  $tpl->addJavaScript("./Modules/Scorm2004/scripts/questions/jquery.js");
2393  // $tpl->addJavaScript("./Modules/Scorm2004/scripts/questions/jquery-ui-min.js");
2394 
2395  $this->tpl->setCurrentBlock("template_option");
2396  $this->tpl->setVariable("VAL_TEMPLATE_OPTION", "");
2397  $this->tpl->setVariable("TXT_TEMPLATE_OPTION", $this->lng->txt("none"));
2398  $this->tpl->parseCurrentBlock();
2399 
2400  foreach($templates as $item)
2401  {
2402  $this->tpl->setCurrentBlock("template_option");
2403  $this->tpl->setVariable("VAL_TEMPLATE_OPTION", $item["id"]);
2404  $this->tpl->setVariable("TXT_TEMPLATE_OPTION", $item["title"]);
2405  $this->tpl->parseCurrentBlock();
2406 
2407  $desc = str_replace("\n", "", nl2br($item["description"]));
2408  $desc = str_replace("\r", "", $desc);
2409 
2410  $this->tpl->setCurrentBlock("js_data");
2411  $this->tpl->setVariable("JS_DATA_ID", $item["id"]);
2412  $this->tpl->setVariable("JS_DATA_TEXT", $desc);
2413  $this->tpl->parseCurrentBlock();
2414  }
2415 
2416  $this->tpl->setCurrentBlock("templates");
2417  $this->tpl->setVariable("TXT_TEMPLATE", $this->lng->txt("svy_settings_template"));
2418  $this->tpl->parseCurrentBlock();
2419  }
2420  }
2421 
2422  // display form to correct errors
2423  $form->setValuesByPost();
2424  $tpl->setContent($form->getHtml());
2425  }
2426 
2427  /*
2428  * list all export files
2429  */
2430  public function exportObject()
2431  {
2432  $this->handleWriteAccess();
2433 
2434  $export_dir = $this->object->getExportDirectory();
2435  $export_files = $this->object->getExportFiles($export_dir);
2436  $data = array();
2437  if(count($export_files) > 0)
2438  {
2439  foreach($export_files as $exp_file)
2440  {
2441  $file_arr = explode("__", $exp_file);
2442  $date = new ilDateTime($file_arr[0], IL_CAL_UNIX);
2443  array_push($data, array(
2444  'file' => $exp_file,
2445  'size' => filesize($export_dir."/".$exp_file),
2446  'date' => $date->get(IL_CAL_DATETIME)
2447  ));
2448  }
2449  }
2450 
2451  include_once "./Modules/Survey/classes/tables/class.ilSurveyExportTableGUI.php";
2452  $table_gui = new ilSurveyExportTableGUI($this, 'export');
2453  $table_gui->setData($data);
2454  $this->tpl->setVariable('ADM_CONTENT', $table_gui->getHTML());
2455  }
2456 
2460  public function createExportFileObject()
2461  {
2462  $this->handleWriteAccess();
2463  include_once("./Modules/Survey/classes/class.ilSurveyExport.php");
2464  $survey_exp = new ilSurveyExport($this->object);
2465  $survey_exp->buildExportFile();
2466  $this->ctrl->redirect($this, "export");
2467  }
2468 
2472  public function downloadExportFileObject()
2473  {
2474  if(!isset($_POST["file"]))
2475  {
2476  ilUtil::sendFailure($this->lng->txt("no_checkbox"), true);
2477  $this->ctrl->redirect($this, "export");
2478  }
2479 
2480  if (count($_POST["file"]) > 1)
2481  {
2482  ilUtil::sendFailure($this->lng->txt("select_max_one_item"), true);
2483  $this->ctrl->redirect($this, "export");
2484  }
2485 
2486  $file = basename($_POST["file"][0]);
2487 
2488  $export_dir = $this->object->getExportDirectory();
2489  include_once "./Services/Utilities/classes/class.ilUtil.php";
2490  ilUtil::deliverFile($export_dir."/".$file, $file);
2491  }
2492 
2497  {
2498  $this->handleWriteAccess();
2499 
2500  if (!isset($_POST["file"]))
2501  {
2502  ilUtil::sendFailure($this->lng->txt("no_checkbox"), true);
2503  $this->ctrl->redirect($this, "export");
2504  }
2505 
2506  ilUtil::sendQuestion($this->lng->txt("info_delete_sure"));
2507 
2508  $export_dir = $this->object->getExportDirectory();
2509  $export_files = $this->object->getExportFiles($export_dir);
2510  $data = array();
2511  if (count($_POST["file"]) > 0)
2512  {
2513  foreach ($_POST["file"] as $exp_file)
2514  {
2515  $file_arr = explode("__", $exp_file);
2516  $date = new ilDateTime($file_arr[0], IL_CAL_UNIX);
2517  array_push($data, array(
2518  'file' => $exp_file,
2519  'size' => filesize($export_dir."/".$exp_file),
2520  'date' => $date->get(IL_CAL_DATETIME)
2521  ));
2522  }
2523  }
2524 
2525  include_once "./Modules/Survey/classes/tables/class.ilSurveyExportTableGUI.php";
2526  $table_gui = new ilSurveyExportTableGUI($this, 'export', true);
2527  $table_gui->setData($data);
2528  $this->tpl->setVariable('ADM_CONTENT', $table_gui->getHTML());
2529  }
2530 
2531 
2536  {
2537  ilUtil::sendInfo($this->lng->txt('msg_cancel'), true);
2538  $this->ctrl->redirect($this, "export");
2539  }
2540 
2541 
2545  public function deleteExportFileObject()
2546  {
2547  $export_dir = $this->object->getExportDirectory();
2548  foreach ($_POST["file"] as $file)
2549  {
2550  $file = basename($file);
2551 
2552  $exp_file = $export_dir."/".$file;
2553  $exp_dir = $export_dir."/".substr($file, 0, strlen($file) - 4);
2554  if (@is_file($exp_file))
2555  {
2556  unlink($exp_file);
2557  }
2558  if (@is_dir($exp_dir))
2559  {
2560  include_once "./Services/Utilities/classes/class.ilUtil.php";
2561  ilUtil::delDir($exp_dir);
2562  }
2563  }
2564  ilUtil::sendSuccess($this->lng->txt('msg_deleted_export_files'), true);
2565  $this->ctrl->redirect($this, "export");
2566  }
2567 
2571  public function setCodeLanguageObject()
2572  {
2573  if (strcmp($_POST["lang"], "-1") != 0)
2574  {
2575  global $ilUser;
2576  $ilUser->writePref("survey_code_language", $_POST["lang"]);
2577  }
2578  ilUtil::sendSuccess($this->lng->txt('language_changed'), true);
2579  $this->ctrl->redirect($this, 'codes');
2580  }
2581 
2585  public function codesObject()
2586  {
2587  $this->handleWriteAccess();
2588  $this->setCodesSubtabs();
2589  global $ilUser, $ilToolbar;
2590  if ($this->object->getAnonymize() != 1 && !$this->object->isAccessibleWithCodeForAll())
2591  {
2592  return ilUtil::sendInfo($this->lng->txt("survey_codes_no_anonymization"));
2593  }
2594 
2595  $default_lang = $ilUser->getPref("survey_code_language");
2596 
2597  // creation buttons
2598  $ilToolbar->setFormAction($this->ctrl->getFormAction($this));
2599  $languages = $this->lng->getInstalledLanguages();
2600  $options = array();
2601  $this->lng->loadLanguageModule("meta");
2602  foreach ($languages as $lang)
2603  {
2604  $options[$lang] = $this->lng->txt("meta_l_".$lang);
2605  }
2606  include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
2607  $si = new ilSelectInputGUI($this->lng->txt("survey_codes_lang"), "lang");
2608  $si->setOptions($options);
2609  $si->setValue($default_lang);
2610  $ilToolbar->addInputItem($si, true);
2611  $ilToolbar->addFormButton($this->lng->txt("set"), "setCodeLanguage");
2612 
2613  include_once "./Modules/Survey/classes/tables/class.ilSurveyCodesTableGUI.php";
2614  $table_gui = new ilSurveyCodesTableGUI($this, 'codes');
2615  $survey_codes =& $this->object->getSurveyCodesTableData($default_lang);
2616  $table_gui->setData($survey_codes);
2617  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_svy_codes.html", true);
2618  $this->tpl->setCurrentBlock("adm_content");
2619  $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this, "codes"));
2620  $this->tpl->setVariable("TEXT_CREATE", $this->lng->txt("create"));
2621  $this->tpl->setVariable("TEXT_SURVEY_CODES", $this->lng->txt("new_survey_codes"));
2622  $this->tpl->setVariable('TABLE', $table_gui->getHTML());
2623  }
2624 
2628  public function deleteCodesObject()
2629  {
2630  if (is_array($_POST["chb_code"]) && (count($_POST["chb_code"]) > 0))
2631  {
2632  foreach ($_POST["chb_code"] as $survey_code)
2633  {
2634  $this->object->deleteSurveyCode($survey_code);
2635  }
2636  ilUtil::sendSuccess($this->lng->txt('codes_deleted'), true);
2637  }
2638  else
2639  {
2640  ilUtil::sendInfo($this->lng->txt('no_checkbox'), true);
2641  }
2642  $this->ctrl->redirect($this, 'codes');
2643  }
2644 
2648  public function exportCodesObject()
2649  {
2650  if (is_array($_POST["chb_code"]) && (count($_POST["chb_code"]) > 0))
2651  {
2652  $export = $this->object->getSurveyCodesForExport($_POST["chb_code"]);
2653  ilUtil::deliverData($export, ilUtil::getASCIIFilename($this->object->getTitle() . ".txt"));
2654  }
2655  else
2656  {
2657  ilUtil::sendFailure($this->lng->txt("no_checkbox"), true);
2658  $this->ctrl->redirect($this, 'codes');
2659  }
2660  }
2661 
2665  public function exportAllCodesObject()
2666  {
2667  $export = $this->object->getSurveyCodesForExport(array());
2668  ilUtil::deliverData($export, ilUtil::getASCIIFilename($this->object->getTitle() . ".txt"));
2669  }
2670 
2674  public function createSurveyCodesObject()
2675  {
2676  if (preg_match("/\d+/", $_POST["nrOfCodes"]))
2677  {
2678  $this->object->createSurveyCodes($_POST["nrOfCodes"]);
2679  ilUtil::sendSuccess($this->lng->txt('codes_created'), true);
2680  }
2681  else
2682  {
2683  ilUtil::sendFailure($this->lng->txt("enter_valid_number_of_codes"), true);
2684  }
2685  $this->ctrl->redirect($this, 'codes');
2686  }
2687 
2691  public function codesMailObject($checkonly = false)
2692  {
2693  global $ilAccess;
2694 
2695  $this->handleWriteAccess();
2696  $this->setCodesSubtabs();
2697 
2698  $savefields = (strcmp($this->ctrl->getCmd(), "saveMailTableFields") == 0) ? TRUE : FALSE;
2699 
2700  include_once "./Modules/Survey/classes/tables/class.ilSurveyCodesMailTableGUI.php";
2701  $data = $this->object->getExternalCodeRecipients();
2702  $table_gui = new ilSurveyCodesMailTableGUI($this, 'codesMail');
2703  $table_gui->setData($data);
2704  $table_gui->setTitle($this->lng->txt('externalRecipients'));
2705  $table_gui->completeColumns();
2706  $tabledata = $table_gui->getHTML();
2707 
2708  if (!$checkonly)
2709  {
2710  $this->tpl->setVariable('ADM_CONTENT', $tabledata);
2711  }
2712  return $errors;
2713  }
2714 
2715  public function insertSavedMessageObject()
2716  {
2717  $this->handleWriteAccess();
2718  $this->setCodesSubtabs();
2719 
2720  include_once("./Modules/Survey/classes/forms/FormMailCodesGUI.php");
2721  $form_gui = new FormMailCodesGUI($this);
2722  $form_gui->setValuesByPost();
2723  try
2724  {
2725  if ($form_gui->getSavedMessages()->getValue() > 0)
2726  {
2727  global $ilUser;
2728  $settings = $this->object->getUserSettings($ilUser->getId(), 'savemessage');
2729  $form_gui->getMailMessage()->setValue($settings[$form_gui->getSavedMessages()->getValue()]['value']);
2730  ilUtil::sendSuccess($this->lng->txt('msg_message_inserted'));
2731  }
2732  else
2733  {
2734  ilUtil::sendFailure($this->lng->txt('msg_no_message_inserted'));
2735  }
2736  }
2737  catch (Exception $e)
2738  {
2739  global $ilLog;
2740  $ilLog->write('Error: ' + $e->getMessage());
2741  }
2742  $this->tpl->setVariable("ADM_CONTENT", $form_gui->getHTML());
2743  }
2744 
2745  public function deleteSavedMessageObject()
2746  {
2747  $this->handleWriteAccess();
2748  $this->setCodesSubtabs();
2749 
2750  include_once("./Modules/Survey/classes/forms/FormMailCodesGUI.php");
2751  $form_gui = new FormMailCodesGUI($this);
2752  $form_gui->setValuesByPost();
2753  try
2754  {
2755  if ($form_gui->getSavedMessages()->getValue() > 0)
2756  {
2757  $this->object->deleteUserSettings($form_gui->getSavedMessages()->getValue());
2758  $form_gui = new FormMailCodesGUI($this);
2759  $form_gui->setValuesByPost();
2760  ilUtil::sendSuccess($this->lng->txt('msg_message_deleted'));
2761  }
2762  else
2763  {
2764  ilUtil::sendFailure($this->lng->txt('msg_no_message_deleted'));
2765  }
2766  }
2767  catch (Exception $e)
2768  {
2769  global $ilLog;
2770  $ilLog->write('Error: ' + $e->getMessage());
2771  }
2772  $this->tpl->setVariable("ADM_CONTENT", $form_gui->getHTML());
2773  }
2774 
2775  public function mailCodesObject()
2776  {
2777  $this->handleWriteAccess();
2778  $this->setCodesSubtabs();
2779 
2780  $mailData['m_subject'] = (array_key_exists('m_subject', $_POST)) ? $_POST['m_subject'] : sprintf($this->lng->txt('default_codes_mail_subject'), $this->object->getTitle());
2781  $mailData['m_message'] = (array_key_exists('m_message', $_POST)) ? $_POST['m_message'] : $this->lng->txt('default_codes_mail_message');
2782  $mailData['m_notsent'] = (array_key_exists('m_notsent', $_POST)) ? $_POST['m_notsent'] : '1';
2783 
2784  include_once("./Modules/Survey/classes/forms/FormMailCodesGUI.php");
2785  $form_gui = new FormMailCodesGUI($this);
2786  $form_gui->setValuesByArray($mailData);
2787  $this->tpl->setVariable("ADM_CONTENT", $form_gui->getHTML());
2788  }
2789 
2790  public function sendCodesMailObject()
2791  {
2792  global $ilUser;
2793 
2794  $this->handleWriteAccess();
2795  $this->setCodesSubtabs();
2796 
2797  include_once("./Modules/Survey/classes/forms/FormMailCodesGUI.php");
2798  $form_gui = new FormMailCodesGUI($this);
2799  if ($form_gui->checkInput())
2800  {
2801  $code_exists = strpos($_POST['m_message'], '[code]') !== FALSE;
2802  if (!$code_exists)
2803  {
2804  if (!$code_exists) ilUtil::sendFailure($this->lng->txt('please_enter_mail_code'));
2805  $form_gui->setValuesByPost();
2806  }
2807  else
2808  {
2809  if ($_POST['savemessage'] == 1)
2810  {
2811  global $ilUser;
2812  $title = (strlen($_POST['savemessagetitle'])) ? $_POST['savemessagetitle'] : ilStr::substr($_POST['m_message'], 0, 40) . '...';
2813  $this->object->saveUserSettings($ilUser->getId(), 'savemessage', $title, $_POST['m_message']);
2814  }
2815 
2816  $lang = $ilUser->getPref("survey_code_language");
2817  if(!$lang)
2818  {
2819  $lang = "en";
2820  }
2821  $this->object->sendCodes($_POST['m_notsent'], $_POST['m_subject'], $_POST['m_message'],$lang);
2822  ilUtil::sendSuccess($this->lng->txt('mail_sent'), true);
2823  $this->ctrl->redirect($this, 'codesMail');
2824  }
2825  }
2826  else
2827  {
2828  $form_gui->setValuesByPost();
2829  }
2830  $this->tpl->setVariable("ADM_CONTENT", $form_gui->getHTML());
2831  }
2832 
2833  public function cancelCodesMailObject()
2834  {
2835  $this->ctrl->redirect($this, 'codesMail');
2836  }
2837 
2839  {
2840  if (!is_array($_POST['chb_ext']) || count(is_array($_POST['chb_ext'])) == 0)
2841  {
2842  ilUtil::sendInfo($this->lng->txt("err_no_selection"), true);
2843  $this->ctrl->redirect($this, 'codesMail');
2844  }
2845  foreach ($_POST['chb_ext'] as $code)
2846  {
2847  $this->object->deleteSurveyCode($code);
2848  }
2849  ilUtil::sendSuccess($this->lng->txt('external_recipients_deleted'), true);
2850  $this->ctrl->redirect($this, 'codesMail');
2851  }
2852 
2854  {
2855  $hasErrors = $this->importExternalMailRecipientsObject(true, 2);
2856  if (!$hasErrors)
2857  {
2858  $data = array();
2859  $existingdata = $this->object->getExternalCodeRecipients();
2860  $existingcolumns = array('email','firstname','lastname'); // #15337
2861  if (count($existingdata))
2862  {
2863  $existingcolumns = array_unique(array_merge($existingcolumns, array_keys(array_shift($existingdata))));
2864  }
2865  foreach ($existingcolumns as $key)
2866  {
2867  if (strcmp($key, 'code') != 0 && strcmp($key, 'sent') != 0)
2868  {
2869  $data[$key] = trim($_POST[$key]);
2870  }
2871  }
2872  if (count($data))
2873  {
2874  $this->object->createSurveyCodesForExternalData(array($data));
2875  ilUtil::sendSuccess($this->lng->txt('external_recipients_imported'), true);
2876  }
2877  $this->ctrl->redirect($this, 'codesMail');
2878  }
2879  }
2880 
2882  {
2883  $hasErrors = $this->importExternalMailRecipientsObject(true, 1);
2884  if (!$hasErrors)
2885  {
2886  $data = preg_split("/[\n\r]/", $_POST['externaltext']);
2887  $fields = preg_split("/;/", array_shift($data));
2888  if (!in_array('email', $fields))
2889  {
2890  $_SESSION['externaltext'] = $_POST['externaltext'];
2891  ilUtil::sendFailure($this->lng->txt('err_external_rcp_no_email_column'), true);
2892  $this->ctrl->redirect($this, 'importExternalMailRecipients');
2893  }
2894  $existingdata = $this->object->getExternalCodeRecipients();
2895  $existingcolumns = array();
2896  if (count($existingdata))
2897  {
2898  $first = array_shift($existingdata);
2899  foreach ($first as $key => $value)
2900  {
2901  array_push($existingcolumns, $key);
2902  }
2903  }
2904  $founddata = array();
2905  foreach ($data as $datarow)
2906  {
2907  $row = preg_split("/;/", $datarow);
2908  if (count($row) == count($fields))
2909  {
2910  $dataset = array();
2911  foreach ($fields as $idx => $fieldname)
2912  {
2913  if (count($existingcolumns))
2914  {
2915  if (array_key_exists($idx, $existingcolumns))
2916  {
2917  $dataset[$fieldname] = $row[$idx];
2918  }
2919  }
2920  else
2921  {
2922  $dataset[$fieldname] = $row[$idx];
2923  }
2924  }
2925  if (strlen($dataset['email']))
2926  {
2927  array_push($founddata, $dataset);
2928  }
2929  }
2930  }
2931  $this->object->createSurveyCodesForExternalData($founddata);
2932  ilUtil::sendSuccess($this->lng->txt('external_recipients_imported'), true);
2933  $this->ctrl->redirect($this, 'codesMail');
2934  }
2935  }
2936 
2938  {
2939  $hasErrors = $this->importExternalMailRecipientsObject(true, 0);
2940  if (!$hasErrors)
2941  {
2942  include_once "./Services/Utilities/classes/class.ilCSVReader.php";
2943  $reader = new ilCSVReader();
2944  $reader->open($_FILES['externalmails']['tmp_name']);
2945  $data = $reader->getDataArrayFromCSVFile();
2946  $fields = array_shift($data);
2947  if (!in_array('email', $fields))
2948  {
2949  $reader->close();
2950  ilUtil::sendFailure($this->lng->txt('err_external_rcp_no_email'), true);
2951  $this->ctrl->redirect($this, 'codesMail');
2952  }
2953  $existingdata = $this->object->getExternalCodeRecipients();
2954  $existingcolumns = array();
2955  if (count($existingdata))
2956  {
2957  $first = array_shift($existingdata);
2958  foreach ($first as $key => $value)
2959  {
2960  array_push($existingcolumns, $key);
2961  }
2962  }
2963  $founddata = array();
2964  foreach ($data as $row)
2965  {
2966  if (count($row) == count($fields))
2967  {
2968  $dataset = array();
2969  foreach ($fields as $idx => $fieldname)
2970  {
2971  if (count($existingcolumns))
2972  {
2973  if (array_key_exists($idx, $existingcolumns))
2974  {
2975  $dataset[$fieldname] = $row[$idx];
2976  }
2977  }
2978  else
2979  {
2980  $dataset[$fieldname] = $row[$idx];
2981  }
2982  }
2983  if (strlen($dataset['email']))
2984  {
2985  array_push($founddata, $dataset);
2986  }
2987  }
2988  }
2989  $reader->close();
2990  $this->object->createSurveyCodesForExternalData($founddata);
2991  ilUtil::sendSuccess($this->lng->txt('external_recipients_imported'), true);
2992  $this->ctrl->redirect($this, 'codesMail');
2993  }
2994  }
2995 
2996  function importExternalMailRecipientsObject($checkonly = false, $formindex = -1)
2997  {
2998  global $ilAccess;
2999 
3000  $this->handleWriteAccess();
3001  $this->setCodesSubtabs();
3002 
3003  $savefields = (
3004  strcmp($this->ctrl->getCmd(), "importExternalRecipientsFromFile") == 0 ||
3005  strcmp($this->ctrl->getCmd(), "importExternalRecipientsFromText") == 0 ||
3006  strcmp($this->ctrl->getCmd(), "importExternalRecipientsFromDataset") == 0
3007  ) ? TRUE : FALSE;
3008 
3009  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
3010  $form_import_file = new ilPropertyFormGUI();
3011  $form_import_file->setFormAction($this->ctrl->getFormAction($this));
3012  $form_import_file->setTableWidth("100%");
3013  $form_import_file->setId("codes_import_file");
3014 
3015  $headerfile = new ilFormSectionHeaderGUI();
3016  $headerfile->setTitle($this->lng->txt("import_from_file"));
3017  $form_import_file->addItem($headerfile);
3018 
3019  $externalmails = new ilFileInputGUI($this->lng->txt("externalmails"), "externalmails");
3020  $externalmails->setInfo($this->lng->txt('externalmails_info'));
3021  $externalmails->setRequired(true);
3022  $form_import_file->addItem($externalmails);
3023  if ($ilAccess->checkAccess("write", "", $_GET["ref_id"])) $form_import_file->addCommandButton("importExternalRecipientsFromFile", $this->lng->txt("import"));
3024  if ($ilAccess->checkAccess("write", "", $_GET["ref_id"])) $form_import_file->addCommandButton("codesMail", $this->lng->txt("cancel"));
3025 
3026  // import text
3027 
3028  $form_import_text = new ilPropertyFormGUI();
3029  $form_import_text->setFormAction($this->ctrl->getFormAction($this));
3030  $form_import_text->setTableWidth("100%");
3031  $form_import_text->setId("codes_import_text");
3032 
3033  $headertext = new ilFormSectionHeaderGUI();
3034  $headertext->setTitle($this->lng->txt("import_from_text"));
3035  $form_import_text->addItem($headertext);
3036 
3037  $inp = new ilTextAreaInputGUI($this->lng->txt('externaltext'), 'externaltext');
3038  if (array_key_exists('externaltext', $_SESSION) && strlen($_SESSION['externaltext']))
3039  {
3040  $inp->setValue($_SESSION['externaltext']);
3041  }
3042  else
3043  {
3044  $inp->setValue($this->lng->txt('mail_import_example1') . "\n" . $this->lng->txt('mail_import_example2') . "\n" . $this->lng->txt('mail_import_example3') . "\n");
3045  }
3046  $inp->setRequired(true);
3047  $inp->setCols(80);
3048  $inp->setRows(10);
3049  $inp->setInfo($this->lng->txt('externaltext_info'));
3050  $form_import_text->addItem($inp);
3051  unset($_SESSION['externaltext']);
3052 
3053  if ($ilAccess->checkAccess("write", "", $_GET["ref_id"])) $form_import_text->addCommandButton("importExternalRecipientsFromText", $this->lng->txt("import"));
3054  if ($ilAccess->checkAccess("write", "", $_GET["ref_id"])) $form_import_text->addCommandButton("codesMail", $this->lng->txt("cancel"));
3055 
3056  // import dataset
3057 
3058  $form_import_dataset = new ilPropertyFormGUI();
3059  $form_import_dataset->setFormAction($this->ctrl->getFormAction($this));
3060  $form_import_dataset->setTableWidth("100%");
3061  $form_import_dataset->setId("codes_import_dataset");
3062 
3063  $headerfile = new ilFormSectionHeaderGUI();
3064  $headerfile->setTitle($this->lng->txt("import_from_dataset"));
3065  $form_import_dataset->addItem($headerfile);
3066 
3067  $existingdata = $this->object->getExternalCodeRecipients();
3068  $existingcolumns = array('email','firstname','lastname'); // #15337
3069  if (count($existingdata))
3070  {
3071  $first = array_keys(array_shift($existingdata));
3072  foreach ($first as $key)
3073  {
3074  if (strcmp($key, 'code') != 0 && strcmp($key, 'sent') != 0)
3075  {
3076  array_push($existingcolumns, $key);
3077  }
3078  }
3079  $existingcolumns = array_unique($existingcolumns);
3080  }
3081 
3082  foreach ($existingcolumns as $column)
3083  {
3084  $inp = new ilTextInputGUI($column, $column);
3085  $inp->setSize(50);
3086  if (strcmp($column, 'email') == 0)
3087  {
3088  $inp->setRequired(true);
3089  }
3090  else
3091  {
3092  $inp->setRequired(false);
3093  }
3094  $form_import_dataset->addItem($inp);
3095  }
3096  if ($ilAccess->checkAccess("write", "", $_GET["ref_id"])) $form_import_dataset->addCommandButton("importExternalRecipientsFromDataset", $this->lng->txt("import"));
3097  if ($ilAccess->checkAccess("write", "", $_GET["ref_id"])) $form_import_dataset->addCommandButton("codesMail", $this->lng->txt("cancel"));
3098 
3099  $errors = false;
3100 
3101  if ($savefields)
3102  {
3103  switch ($formindex)
3104  {
3105  case 0:
3106  $errors = !$form_import_file->checkInput();
3107  $form_import_file->setValuesByPost();
3108  if ($errors) $checkonly = false;
3109  break;
3110  case 1:
3111  $errors = !$form_import_text->checkInput();
3112  $form_import_text->setValuesByPost();
3113  if ($errors) $checkonly = false;
3114  break;
3115  case 2:
3116  $errors = !$form_import_dataset->checkInput();
3117  $form_import_dataset->setValuesByPost();
3118  if ($errors) $checkonly = false;
3119  break;
3120  }
3121  }
3122 
3123  if (!$checkonly)
3124  {
3125  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_external_mail.html", "Modules/Survey");
3126  $this->tpl->setVariable("HEADLINE", $this->lng->txt("external_mails_import"));
3127  $this->tpl->setVariable("FORM1", $form_import_file->getHTML());
3128  $this->tpl->setVariable("FORM2", $form_import_text->getHTML());
3129  $this->tpl->setVariable("FORM3", $form_import_dataset->getHTML());
3130  }
3131  return $errors;
3132  }
3133 
3137  public function constraintsAddObject()
3138  {
3139  if (strlen($_POST["v"]) == 0)
3140  {
3141  ilUtil::sendFailure($this->lng->txt("msg_enter_value_for_valid_constraint"));
3142  return $this->constraintStep3Object();
3143  }
3144  $survey_questions =& $this->object->getSurveyQuestions();
3145  $structure =& $_SESSION["constraintstructure"];
3146  $include_elements = $_SESSION["includeElements"];
3147  foreach ($include_elements as $elementCounter)
3148  {
3149  if (is_array($structure[$elementCounter]))
3150  {
3151  if (strlen($_GET["precondition"]))
3152  {
3153  $this->object->updateConstraint($_GET['precondition'], $_POST["q"], $_POST["r"], $_POST["v"], $_POST['c']);
3154  }
3155  else
3156  {
3157  $constraint_id = $this->object->addConstraint($_POST["q"], $_POST["r"], $_POST["v"], $_POST['c']);
3158  foreach ($structure[$elementCounter] as $key => $question_id)
3159  {
3160  $this->object->addConstraintToQuestion($question_id, $constraint_id);
3161  }
3162  }
3163  if (count($structure[$elementCounter]) > 1)
3164  {
3165  $this->object->updateConjunctionForQuestions($structure[$elementCounter], $_POST['c']);
3166  }
3167  }
3168  }
3169  unset($_SESSION["includeElements"]);
3170  unset($_SESSION["constraintstructure"]);
3171  $this->ctrl->redirect($this, "constraints");
3172  }
3173 
3177  public function constraintStep1Object()
3178  {
3179  $survey_questions =& $this->object->getSurveyQuestions();
3180  $structure =& $_SESSION["constraintstructure"];
3181  $start = $_GET["start"];
3182  $option_questions = array();
3183  for ($i = 1; $i < $start; $i++)
3184  {
3185  if (is_array($structure[$i]))
3186  {
3187  foreach ($structure[$i] as $key => $question_id)
3188  {
3189  if ($survey_questions[$question_id]["usableForPrecondition"])
3190  {
3191  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"]));
3192  }
3193  }
3194  }
3195  }
3196  if (count($option_questions) == 0)
3197  {
3198  unset($_SESSION["includeElements"]);
3199  unset($_SESSION["constraintstructure"]);
3200  ilUtil::sendInfo($this->lng->txt("constraints_no_nonessay_available"), true);
3201  $this->ctrl->redirect($this, "constraints");
3202  }
3203  $this->constraintForm(1, $_POST, $survey_questions, $option_questions);
3204  }
3205 
3209  public function constraintStep2Object()
3210  {
3211  $survey_questions =& $this->object->getSurveyQuestions();
3212  $option_questions = array();
3213  array_push($option_questions, array("question_id" => $_POST["q"], "title" => $survey_questions[$_POST["q"]]["title"], "type_tag" => $survey_questions[$_POST["q"]]["type_tag"]));
3214  $this->constraintForm(2, $_POST, $survey_questions, $option_questions);
3215  }
3216 
3220  public function constraintStep3Object()
3221  {
3222  $survey_questions =& $this->object->getSurveyQuestions();
3223  $option_questions = array();
3224  if (strlen($_GET["precondition"]))
3225  {
3226  $pc = $this->object->getPrecondition($_GET["precondition"]);
3227  $postvalues = array(
3228  "c" => $pc["conjunction"],
3229  "q" => $pc["question_fi"],
3230  "r" => $pc["relation_id"],
3231  "v" => $pc["value"]
3232  );
3233  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"]));
3234  $this->constraintForm(3, $postvalues, $survey_questions, $option_questions);
3235  }
3236  else
3237  {
3238  array_push($option_questions, array("question_id" => $_POST["q"], "title" => $survey_questions[$_POST["q"]]["title"], "type_tag" => $survey_questions[$_POST["q"]]["type_tag"]));
3239  $this->constraintForm(3, $_POST, $survey_questions, $option_questions);
3240  }
3241  }
3242 
3243  public function constraintForm($step, $postvalues, &$survey_questions, $questions = FALSE)
3244  {
3245  if (strlen($_GET["start"])) $this->ctrl->setParameter($this, "start", $_GET["start"]);
3246  $this->ctrl->saveParameter($this, "precondition");
3247  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
3248  $form = new ilPropertyFormGUI();
3249  $form->setFormAction($this->ctrl->getFormAction($this));
3250  $form->setTableWidth("100%");
3251  $form->setId("constraintsForm");
3252 
3253  // #9366
3254  $title = array();
3255  $title_ids = $_SESSION["includeElements"];
3256  if(!$title_ids)
3257  {
3258  $title_ids = array($_GET["start"]);
3259  }
3260  foreach($title_ids as $title_id)
3261  {
3262  // question block
3263  if ($survey_questions[$_SESSION["constraintstructure"][$title_id][0]]["questionblock_id"] > 0)
3264  {
3265  $title[] = $this->lng->txt("questionblock") . ": " . $survey_questions[$_SESSION["constraintstructure"][$title_id][0]]["questionblock_title"];
3266  }
3267  // question
3268  else
3269  {
3270  $title[] = $this->lng->txt($survey_questions[$_SESSION["constraintstructure"][$title_id][0]]["type_tag"]) . ": " .
3271  $survey_questions[$_SESSION["constraintstructure"][$title_id][0]]["title"];
3272  }
3273  }
3274  $header = new ilFormSectionHeaderGUI();
3275  $header->setTitle(implode("<br/>", $title));
3276  $form->addItem($header);
3277 
3278  $fulfilled = new ilRadioGroupInputGUI($this->lng->txt("constraint_fulfilled"), "c");
3279  $fulfilled->addOption(new ilRadioOption($this->lng->txt("conjunction_and"), '0', ''));
3280  $fulfilled->addOption(new ilRadioOption($this->lng->txt("conjunction_or"), '1', ''));
3281  $fulfilled->setValue((strlen($postvalues['c'])) ? $postvalues['c'] : 0);
3282  $form->addItem($fulfilled);
3283 
3284  $step1 = new ilSelectInputGUI($this->lng->txt("step") . " 1: " . $this->lng->txt("select_prior_question"), "q");
3285  $options = array();
3286  if (is_array($questions))
3287  {
3288  foreach ($questions as $question)
3289  {
3290  $options[$question["question_id"]] = $question["title"] . " (" . SurveyQuestion::_getQuestionTypeName($question["type_tag"]) . ")";
3291  }
3292  }
3293  $step1->setOptions($options);
3294  $step1->setValue($postvalues["q"]);
3295  $form->addItem($step1);
3296 
3297  if ($step > 1)
3298  {
3299  $relations = $this->object->getAllRelations();
3300  $step2 = new ilSelectInputGUI($this->lng->txt("step") . " 2: " . $this->lng->txt("select_relation"), "r");
3301  $options = array();
3302  foreach ($relations as $rel_id => $relation)
3303  {
3304  if (in_array($relation["short"], $survey_questions[$postvalues["q"]]["availableRelations"]))
3305  {
3306  $options[$rel_id] = $relation['short'];
3307  }
3308  }
3309  $step2->setOptions($options);
3310  $step2->setValue($postvalues["r"]);
3311  $form->addItem($step2);
3312  }
3313 
3314  if ($step > 2)
3315  {
3316  $variables =& $this->object->getVariables($postvalues["q"]);
3317  $question_type = $survey_questions[$postvalues["q"]]["type_tag"];
3318  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
3319  SurveyQuestion::_includeClass($question_type);
3320  $question = new $question_type();
3321  $question->loadFromDb($postvalues["q"]);
3322 
3323  $step3 = $question->getPreconditionSelectValue($postvalues["v"], $this->lng->txt("step") . " 3: " . $this->lng->txt("select_value"), "v");
3324  $form->addItem($step3);
3325  }
3326 
3327  switch ($step)
3328  {
3329  case 1:
3330  $cmd_continue = "constraintStep2";
3331  $cmd_back = "constraints";
3332  break;
3333  case 2:
3334  $cmd_continue = "constraintStep3";
3335  $cmd_back = "constraintStep1";
3336  break;
3337  case 3:
3338  $cmd_continue = "constraintsAdd";
3339  $cmd_back = "constraintStep2";
3340  break;
3341  }
3342  $form->addCommandButton($cmd_back, $this->lng->txt("back"));
3343  $form->addCommandButton($cmd_continue, $this->lng->txt("continue"));
3344 
3345  $this->tpl->setVariable("ADM_CONTENT", $form->getHTML());
3346  }
3347 
3351  public function deleteConstraintsObject()
3352  {
3353  $survey_questions =& $this->object->getSurveyQuestions();
3354  $structure =& $_SESSION["constraintstructure"];
3355  foreach ($_POST as $key => $value)
3356  {
3357  if (preg_match("/^constraint_(\d+)_(\d+)/", $key, $matches))
3358  {
3359  $this->object->deleteConstraint($matches[2]);
3360  }
3361  }
3362 
3363  $this->ctrl->redirect($this, "constraints");
3364  }
3365 
3367  {
3368  $include_elements = $_POST["includeElements"];
3369  if ((!is_array($include_elements)) || (count($include_elements) == 0))
3370  {
3371  ilUtil::sendInfo($this->lng->txt("constraints_no_questions_or_questionblocks_selected"), true);
3372  $this->ctrl->redirect($this, "constraints");
3373  }
3374  else if (count($include_elements) >= 1)
3375  {
3376  $_SESSION["includeElements"] = $include_elements;
3377  sort($include_elements, SORT_NUMERIC);
3378  $_GET["start"] = $include_elements[0];
3379  $this->constraintStep1Object();
3380  }
3381  }
3382 
3384  {
3385  $_SESSION["includeElements"] = array($_GET["start"]);
3386  $this->ctrl->setParameter($this, "precondition", $_GET["precondition"]);
3387  $this->ctrl->setParameter($this, "start", $_GET["start"]);
3388  $this->ctrl->redirect($this, "constraintStep3");
3389  }
3390 
3394  public function constraintsObject()
3395  {
3396  $this->handleWriteAccess();
3397 
3398  global $rbacsystem;
3399 
3400  $hasDatasets = $this->object->_hasDatasets($this->object->getSurveyId());
3401  $step = 0;
3402  if (array_key_exists("step", $_GET)) $step = $_GET["step"];
3403  switch ($step)
3404  {
3405  case 1:
3406  $this->constraintStep1Object();
3407  return;
3408  break;
3409  case 2:
3410  return;
3411  break;
3412  case 3:
3413  return;
3414  break;
3415  }
3416 
3417  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_svy_constraints_list.html", "Modules/Survey");
3418  $survey_questions =& $this->object->getSurveyQuestions();
3419  $last_questionblock_id = 0;
3420  $counter = 1;
3421  $hasPreconditions = FALSE;
3422  $structure = array();
3423  $colors = array("tblrow1", "tblrow2");
3424  foreach ($survey_questions as $question_id => $data)
3425  {
3426  $title = $data["title"];
3427  $show = true;
3428  if ($data["questionblock_id"] > 0)
3429  {
3430  $title = $data["questionblock_title"];
3431  $type = $this->lng->txt("questionblock");
3432  if ($data["questionblock_id"] != $last_questionblock_id)
3433  {
3434  $last_questionblock_id = $data["questionblock_id"];
3435  $structure[$counter] = array();
3436  array_push($structure[$counter], $data["question_id"]);
3437  }
3438  else
3439  {
3440  array_push($structure[$counter-1], $data["question_id"]);
3441  $show = false;
3442  }
3443  }
3444  else
3445  {
3446  $structure[$counter] = array($data["question_id"]);
3447  $type = $this->lng->txt("question");
3448  }
3449  if ($show)
3450  {
3451  if ($counter == 1)
3452  {
3453  $this->tpl->setCurrentBlock("description");
3454  $this->tpl->setVariable("DESCRIPTION", $this->lng->txt("constraints_first_question_description"));
3455  $this->tpl->parseCurrentBlock();
3456  }
3457  else
3458  {
3459  $constraints =& $this->object->getConstraints($data["question_id"]);
3460  $rowcount = 0;
3461  if (count($constraints))
3462  {
3463  $hasPreconditions = TRUE;
3464  foreach ($constraints as $constraint)
3465  {
3466  $this->tpl->setCurrentBlock("constraint");
3467  $this->tpl->setVariable("SEQUENCE_ID", $counter);
3468  $this->tpl->setVariable("CONSTRAINT_ID", $constraint["id"]);
3469  $this->tpl->setVariable("CONSTRAINT_TEXT", $survey_questions[$constraint["question"]]["title"] . " " . $constraint["short"] . " " . $constraint["valueoutput"]);
3470  $this->tpl->setVariable("TEXT_EDIT_PRECONDITION", $this->lng->txt("edit"));
3471  $this->ctrl->setParameter($this, "precondition", $constraint["id"]);
3472  $this->ctrl->setParameter($this, "start", $counter);
3473  $this->tpl->setVariable("EDIT_PRECONDITION", $this->ctrl->getLinkTarget($this, "editPrecondition"));
3474  $this->ctrl->setParameter($this, "precondition", "");
3475  $this->ctrl->setParameter($this, "start", "");
3476  $this->tpl->parseCurrentBlock();
3477  }
3478  if (count($constraints) > 1)
3479  {
3480  $this->tpl->setCurrentBlock("conjunction");
3481  $this->tpl->setVariable("TEXT_CONJUNCTION", ($constraints[0]['conjunction']) ? $this->lng->txt('conjunction_or_title') : $this->lng->txt('conjunction_and_title'));
3482  $this->tpl->parseCurrentBlock();
3483  }
3484  }
3485  }
3486  if ($counter != 1)
3487  {
3488  $this->tpl->setCurrentBlock("include_elements");
3489  $this->tpl->setVariable("QUESTION_NR", "$counter");
3490  $this->tpl->parseCurrentBlock();
3491  }
3492  $this->tpl->setCurrentBlock("constraint_section");
3493  $this->tpl->setVariable("COLOR_CLASS", $colors[$counter % 2]);
3494  $this->tpl->setVariable("QUESTION_NR", "$counter");
3495  $this->tpl->setVariable("TITLE", "$title");
3496  $icontype = "question.png";
3497  if ($data["questionblock_id"] > 0)
3498  {
3499  $icontype = "questionblock.png";
3500  }
3501  $this->tpl->setVariable("TYPE", "$type: ");
3502  include_once "./Services/Utilities/classes/class.ilUtil.php";
3503  $this->tpl->setVariable("ICON_HREF", ilUtil::getImagePath($icontype, "Modules/Survey"));
3504  $this->tpl->setVariable("ICON_ALT", $type);
3505  $this->tpl->parseCurrentBlock();
3506  $counter++;
3507  }
3508  }
3509  if ($rbacsystem->checkAccess("write", $this->ref_id) and !$hasDatasets)
3510  {
3511  if ($hasPreconditions)
3512  {
3513  $this->tpl->setCurrentBlock("selectall_preconditions");
3514  $this->tpl->setVariable("SELECT_ALL_PRECONDITIONS", $this->lng->txt("select_all"));
3515  $this->tpl->parseCurrentBlock();
3516  }
3517  $this->tpl->setCurrentBlock("selectall");
3518  $counter++;
3519  $this->tpl->setVariable("SELECT_ALL", $this->lng->txt("select_all"));
3520  $this->tpl->setVariable("COLOR_CLASS", $colors[$counter % 2]);
3521  $this->tpl->parseCurrentBlock();
3522 
3523  if ($hasPreconditions)
3524  {
3525  $this->tpl->setCurrentBlock("delete_button");
3526  $this->tpl->setVariable("BTN_DELETE", $this->lng->txt("delete"));
3527  include_once "./Services/Utilities/classes/class.ilUtil.php";
3528  $this->tpl->setVariable("ARROW", "<img src=\"" . ilUtil::getImagePath("arrow_downright.png") . "\" alt=\"".$this->lng->txt("arrow_downright")."\">");
3529  $this->tpl->parseCurrentBlock();
3530  }
3531 
3532  $this->tpl->setCurrentBlock("buttons");
3533  $this->tpl->setVariable("ARROW", "<img src=\"" . ilUtil::getImagePath("arrow_downright.png") . "\" alt=\"".$this->lng->txt("arrow_downright")."\">");
3534  $this->tpl->setVariable("BTN_CREATE_CONSTRAINTS", $this->lng->txt("constraint_add"));
3535  $this->tpl->parseCurrentBlock();
3536  }
3537  $this->tpl->setCurrentBlock("adm_content");
3538  $this->tpl->setVariable("CONSTRAINTS_INTRODUCTION", $this->lng->txt("constraints_introduction"));
3539  $this->tpl->setVariable("DEFINED_PRECONDITIONS", $this->lng->txt("existing_constraints"));
3540  $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this, "constraints"));
3541  $this->tpl->setVariable("CONSTRAINTS_HEADER", $this->lng->txt("constraints_list_of_entities"));
3542  $this->tpl->parseCurrentBlock();
3543  $_SESSION["constraintstructure"] = $structure;
3544  if ($hasDatasets)
3545  {
3546  // ilUtil::sendInfo($this->lng->txt("survey_has_datasets_warning"));
3547  $link = $this->ctrl->getLinkTarget($this, "maintenance");
3548  $link = "<a href=\"".$link."\">".$this->lng->txt("survey_has_datasets_warning_page_view_link")."</a>";
3549  ilUtil::sendInfo($this->lng->txt("survey_has_datasets_warning_page_view")." ".$link);
3550  }
3551  }
3552 
3558  function infoScreenObject()
3559  {
3560  $this->ctrl->setCmd("showSummary");
3561  $this->ctrl->setCmdClass("ilinfoscreengui");
3562  $this->infoScreen();
3563  }
3564 
3568  function infoScreen()
3569  {
3570  global $ilAccess;
3571  global $ilUser;
3572 
3573  if (!$ilAccess->checkAccess("visible", "", $this->ref_id))
3574  {
3575  $this->ilias->raiseError($this->lng->txt("msg_no_perm_read"),$this->ilias->error_obj->MESSAGE);
3576  }
3577 
3578  include_once("./Services/InfoScreen/classes/class.ilInfoScreenGUI.php");
3579  $info = new ilInfoScreenGUI($this);
3580  include_once "./Modules/Survey/classes/class.ilSurveyExecutionGUI.php";
3581  $output_gui =& new ilSurveyExecutionGUI($this->object);
3582  $info->setFormAction($this->ctrl->getFormAction($output_gui, "infoScreen"));
3583  $info->enablePrivateNotes();
3584  $anonymize_key = NULL;
3585  if ($this->object->getAnonymize() == 1)
3586  {
3587  if ($_SESSION["anonymous_id"][$this->object->getId()])
3588  {
3589  $anonymize_key = $_SESSION["anonymous_id"][$this->object->getId()];
3590  }
3591  else if ($_POST["anonymous_id"])
3592  {
3593  $anonymize_key = $_POST["anonymous_id"];
3594  }
3595  }
3596  $canStart = $this->object->canStartSurvey($anonymize_key);
3597  $showButtons = $canStart["result"];
3598  if (!$showButtons)
3599  {
3600  if($canStart["edit_settings"] &&
3601  $ilAccess->checkAccess("write", "", $this->ref_id))
3602  {
3603  $canStart["messages"][] = "<a href=\"".$this->ctrl->getLinkTarget($this, "properties")."\">&raquo; ".
3604  $this->lng->txt("survey_edit_settings")."</a>";
3605  }
3606  ilUtil::sendInfo(implode("<br />", $canStart["messages"]));
3607  }
3608 
3609  $big_button = false;
3610  if ($showButtons)
3611  {
3612  // output of start/resume buttons for personalized surveys
3613  if (!$this->object->getAnonymize())
3614  {
3615  $survey_started = $this->object->isSurveyStarted($ilUser->getId(), "");
3616  // Anonymous User tries to start a personalized survey
3617  if ($_SESSION["AccountId"] == ANONYMOUS_USER_ID)
3618  {
3619  ilUtil::sendInfo($this->lng->txt("anonymous_with_personalized_survey"));
3620  }
3621  else
3622  {
3623  if ($survey_started === 1)
3624  {
3625  ilUtil::sendInfo($this->lng->txt("already_completed_survey"));
3626  }
3627  elseif ($survey_started === 0)
3628  {
3629  $big_button = array("resume", $this->lng->txt("resume_survey"));
3630  }
3631  elseif ($survey_started === FALSE)
3632  {
3633  $big_button = array("start", $this->lng->txt("start_survey"));
3634  }
3635  }
3636  }
3637  // output of start/resume buttons for anonymized surveys
3638  else if ($this->object->getAnonymize() && !$this->object->isAccessibleWithoutCode())
3639  {
3640  if (($_SESSION["AccountId"] == ANONYMOUS_USER_ID || $this->object->isAccessibleWithCodeForAll()) && (strlen($_POST["anonymous_id"]) == 0) && (strlen($_SESSION["anonymous_id"][$this->object->getId()]) == 0))
3641  {
3642  $info->setFormAction($this->ctrl->getFormAction($this, "infoScreen"));
3643  $info->addSection($this->lng->txt("anonymization"));
3644  $info->addProperty("", $this->lng->txt("anonymize_anonymous_introduction"));
3645  $info->addPropertyTextinput($this->lng->txt("enter_anonymous_id"), "anonymous_id", "", 8, "infoScreen", $this->lng->txt("submit"));
3646  }
3647  else
3648  {
3649  if (strlen($_POST["anonymous_id"]) > 0)
3650  {
3651  if (!$this->object->checkSurveyCode($_POST["anonymous_id"]))
3652  {
3653  ilUtil::sendInfo($this->lng->txt("wrong_survey_code_used"));
3654  }
3655  else
3656  {
3657  $anonymize_key = $_POST["anonymous_id"];
3658  }
3659  }
3660  else if (strlen($_SESSION["anonymous_id"][$this->object->getId()]) > 0)
3661  {
3662  if (!$this->object->checkSurveyCode($_SESSION["anonymous_id"][$this->object->getId()]))
3663  {
3664  ilUtil::sendInfo($this->lng->txt("wrong_survey_code_used"));
3665  }
3666  else
3667  {
3668  $anonymize_key = $_SESSION["anonymous_id"][$this->object->getId()];
3669  }
3670  }
3671  else
3672  {
3673  // registered users do not need to know that there is an anonymous key. The data is anonymized automatically
3674  $anonymize_key = $this->object->getUserAccessCode($ilUser->getId());
3675  if (!strlen($anonymize_key))
3676  {
3677  $anonymize_key = $this->object->createNewAccessCode();
3678  $this->object->saveUserAccessCode($ilUser->getId(), $anonymize_key);
3679  }
3680  }
3681  $info->addHiddenElement("anonymous_id", $anonymize_key);
3682  $survey_started = $this->object->isSurveyStarted($ilUser->getId(), $anonymize_key);
3683  if ($survey_started === 1)
3684  {
3685  ilUtil::sendInfo($this->lng->txt("already_completed_survey"));
3686  }
3687  elseif ($survey_started === 0)
3688  {
3689  $big_button = array("resume", $this->lng->txt("resume_survey"));
3690  }
3691  elseif ($survey_started === FALSE)
3692  {
3693  $big_button = array("start", $this->lng->txt("start_survey"));
3694  }
3695  }
3696  }
3697  else
3698  {
3699  // free access
3700  $survey_started = $this->object->isSurveyStarted($ilUser->getId(), "");
3701  if ($survey_started === 1)
3702  {
3703  ilUtil::sendInfo($this->lng->txt("already_completed_survey"));
3704  }
3705  elseif ($survey_started === 0)
3706  {
3707  $big_button = array("resume", $this->lng->txt("resume_survey"));
3708  }
3709  elseif ($survey_started === FALSE)
3710  {
3711  $big_button = array("start", $this->lng->txt("start_survey"));
3712  }
3713  }
3714  }
3715 
3716  if($big_button)
3717  {
3718  $big_button = '<div class="il_ButtonGroup il_BigButton">'.
3719  '<input type="submit" class="submit il_BigButton" name="cmd['.$big_button[0].']" value="'.
3720  $big_button[1].'" /></div>';
3721  }
3722 
3723  if (strlen($this->object->getIntroduction()))
3724  {
3725  $introduction = $this->object->getIntroduction();
3726  $info->addSection($this->lng->txt("introduction"));
3727  $info->addProperty("", $this->object->prepareTextareaOutput($introduction).
3728  $big_button."<br />".$info->getHiddenToggleButton());
3729  }
3730  else
3731  {
3732  $info->addSection("");
3733  $info->addProperty("", $big_button.$info->getHiddenToggleButton());
3734  }
3735 
3736  $info->hideFurtherSections(false);
3737 
3738  $info->addSection($this->lng->txt("svy_general_properties"));
3739  if (strlen($this->object->getAuthor()))
3740  {
3741  $info->addProperty($this->lng->txt("author"), $this->object->getAuthor());
3742  }
3743  $info->addProperty($this->lng->txt("title"), $this->object->getTitle());
3744  switch ($this->object->getAnonymize())
3745  {
3746  case ANONYMIZE_OFF:
3747  $info->addProperty($this->lng->txt("anonymization"), $this->lng->txt("anonymize_personalized"));
3748  break;
3749  case ANONYMIZE_ON:
3750  if ($_SESSION["AccountId"] == ANONYMOUS_USER_ID)
3751  {
3752  $info->addProperty($this->lng->txt("anonymization"), $this->lng->txt("info_anonymize_with_code"));
3753  }
3754  else
3755  {
3756  $info->addProperty($this->lng->txt("anonymization"), $this->lng->txt("info_anonymize_registered_user"));
3757  }
3758  break;
3759  case ANONYMIZE_FREEACCESS:
3760  $info->addProperty($this->lng->txt("anonymization"), $this->lng->txt("info_anonymize_without_code"));
3761  break;
3762  }
3763  include_once "./Modules/Survey/classes/class.ilObjSurveyAccess.php";
3764  if ($ilAccess->checkAccess("write", "", $this->ref_id) || ilObjSurveyAccess::_hasEvaluationAccess($this->object->getId(), $ilUser->getId()))
3765  {
3766  $info->addProperty($this->lng->txt("evaluation_access"), $this->lng->txt("evaluation_access_info"));
3767  }
3768  $info->addMetaDataSections($this->object->getId(),0, $this->object->getType());
3769  $this->ctrl->forwardCommand($info);
3770  }
3771 
3777  function printViewObject()
3778  {
3779  global $ilias;
3780 
3781  $this->questionsSubtabs("printview");
3782  $template = new ilTemplate("tpl.il_svy_svy_printview.html", TRUE, TRUE, "Modules/Survey");
3783 
3784  include_once './Services/WebServices/RPC/classes/class.ilRPCServerSettings.php';
3785  if(ilRPCServerSettings::getInstance()->isEnabled())
3786  {
3787  $this->ctrl->setParameter($this, "pdf", "1");
3788  $template->setCurrentBlock("pdf_export");
3789  $template->setVariable("PDF_URL", $this->ctrl->getLinkTarget($this, "printView"));
3790  $this->ctrl->setParameter($this, "pdf", "");
3791  $template->setVariable("PDF_TEXT", $this->lng->txt("pdf_export"));
3792  $template->setVariable("PDF_IMG_ALT", $this->lng->txt("pdf_export"));
3793  $template->setVariable("PDF_IMG_URL", ilUtil::getHtmlPath(ilUtil::getImagePath("application-pdf.png")));
3794  $template->parseCurrentBlock();
3795  }
3796  $template->setVariable("PRINT_TEXT", $this->lng->txt("print"));
3797  $template->setVariable("PRINT_URL", "javascript:window.print();");
3798 
3799  $pages =& $this->object->getSurveyPages();
3800  foreach ($pages as $page)
3801  {
3802  if (count($page) > 0)
3803  {
3804  foreach ($page as $question)
3805  {
3806  $questionGUI = $this->object->getQuestionGUI($question["type_tag"], $question["question_id"]);
3807  if (is_object($questionGUI))
3808  {
3809  if (strlen($question["heading"]))
3810  {
3811  $template->setCurrentBlock("textblock");
3812  $template->setVariable("TEXTBLOCK", $question["heading"]);
3813  $template->parseCurrentBlock();
3814  }
3815  $template->setCurrentBlock("question");
3816  $template->setVariable("QUESTION_DATA", $questionGUI->getPrintView($this->object->getShowQuestionTitles(), $question["questionblock_show_questiontext"], $this->object->getSurveyId()));
3817  $template->parseCurrentBlock();
3818  }
3819  }
3820  if (count($page) > 1)
3821  {
3822  $template->setCurrentBlock("page");
3823  $template->setVariable("BLOCKTITLE", $page[0]["questionblock_title"]);
3824  $template->parseCurrentBlock();
3825  }
3826  else
3827  {
3828  $template->setCurrentBlock("page");
3829  $template->parseCurrentBlock();
3830  }
3831  }
3832  }
3833  $this->tpl->addCss("./Modules/Survey/templates/default/survey_print.css", "print");
3834  if (array_key_exists("pdf", $_GET) && ($_GET["pdf"] == 1))
3835  {
3836  $printbody = new ilTemplate("tpl.il_as_tst_print_body.html", TRUE, TRUE, "Modules/Test");
3837  $printbody->setVariable("TITLE", sprintf($this->lng->txt("tst_result_user_name"), $uname));
3838  $printbody->setVariable("ADM_CONTENT", $template->get());
3839  $printoutput = $printbody->get();
3840  $printoutput = preg_replace("/href=\".*?\"/", "", $printoutput);
3841  $fo = $this->object->processPrintoutput2FO($printoutput);
3842  if($fo)
3843  {
3844  $this->object->deliverPDFfromFO($fo);
3845  }
3846  else
3847  {
3848  ilUtil::sendFailure($this->lng->txt("msg_failed"), true);
3849  $this->ctrl->redirect($this, "printView");
3850  }
3851  }
3852  else
3853  {
3854  $this->tpl->setVariable("ADM_CONTENT", $template->get());
3855  }
3856  }
3857 
3858  function addLocatorItems()
3859  {
3860  global $ilLocator;
3861  switch ($this->ctrl->getCmd())
3862  {
3863  case "next":
3864  case "previous":
3865  case "start":
3866  case "resume":
3867  case "redirectQuestion":
3868  $ilLocator->addItem($this->object->getTitle(), $this->ctrl->getLinkTarget($this, "infoScreen"), "", $_GET["ref_id"]);
3869  break;
3870  case "evaluation":
3871  case "checkEvaluationAccess":
3872  case "evaluationdetails":
3873  case "evaluationuser":
3874  $ilLocator->addItem($this->object->getTitle(), $this->ctrl->getLinkTargetByClass("ilsurveyevaluationgui", "evaluation"), "", $_GET["ref_id"]);
3875  break;
3876  case "create":
3877  case "save":
3878  case "cancel":
3879  case "importFile":
3880  case "cloneAll":
3881  break;
3882  case "infoScreen":
3883  $ilLocator->addItem($this->object->getTitle(), $this->ctrl->getLinkTarget($this, "infoScreen"), "", $_GET["ref_id"]);
3884  break;
3885  default:
3886  $ilLocator->addItem($this->object->getTitle(), $this->ctrl->getLinkTarget($this, ""), "", $_GET["ref_id"]);
3887  break;
3888  }
3889  }
3890 
3898  function questionsSubtabs($a_cmd)
3899  {
3900  $questions_per_page = ($a_cmd == 'questions_per_page') ? true : false;
3901  $questions = ($a_cmd == 'questions') ? true : false;
3902  $printview = ($a_cmd == 'printview') ? true : false;
3903 
3904  $hidden_tabs = array();
3905  $template = $this->object->getTemplate();
3906  if($template)
3907  {
3908  include_once "Services/Administration/classes/class.ilSettingsTemplate.php";
3909  $template = new ilSettingsTemplate($template);
3910  $hidden_tabs = $template->getHiddenTabs();
3911  }
3912 
3913  $this->tabs_gui->addSubTabTarget("survey_per_page_view", $this->ctrl->getLinkTargetByClass("ilsurveypagegui", "renderPage"),
3914  "", "", "", $questions_per_page);
3915 
3916  if(!in_array("survey_question_editor", $hidden_tabs))
3917  {
3918  $this->ctrl->setParameter($this, "pgov", "");
3919  $this->tabs_gui->addSubTabTarget("survey_question_editor", $this->ctrl->getLinkTarget($this, "questions"),
3920  "", "", "", $questions);
3921  $this->ctrl->setParameter($this, "pgov", $_REQUEST["pgov"]);
3922  }
3923 
3924  $this->tabs_gui->addSubTabTarget("print_view", $this->ctrl->getLinkTarget($this, "printView"),
3925  "", "", "", $printview);
3926 
3927  if($this->object->getSurveyPages())
3928  {
3929  if($questions_per_page)
3930  {
3931  $this->ctrl->setParameterByClass("ilsurveyexecutiongui", "pgov", max(1, $_REQUEST["pg"]));
3932  }
3933  $this->ctrl->setParameterByClass("ilsurveyexecutiongui", "prvw", 1);
3934  $this->tabs_gui->addSubTabTarget("preview", $this->ctrl->getLinkTargetByClass("ilsurveyexecutiongui", "preview"),
3935  "", "", "", false);
3936  }
3937  }
3938 
3944  function setCodesSubtabs()
3945  {
3946  global $ilTabs;
3947  global $ilAccess;
3948 
3949  $ilTabs->addSubTabTarget
3950  (
3951  "codes",
3952  $this->ctrl->getLinkTarget($this,'codes'),
3953  array("codes", "createSurveyCodes", "setCodeLanguage", "deleteCodes", "exportCodes"),
3954  ""
3955  );
3956 
3957  $ilTabs->addSubTabTarget
3958  (
3959  "participating_users",
3960  $this->ctrl->getLinkTarget($this, "codesMail"),
3961  array("codesMail", "saveMailTableFields", "importExternalMailRecipients",
3962  'importExternalRecipientsFromFile', 'importExternalRecipientsFromText',
3963  'importExternalRecipientsFromDataset'),
3964  ""
3965  );
3966 
3967  $data = $this->object->getExternalCodeRecipients();
3968  if (count($data))
3969  {
3970  $ilTabs->addSubTabTarget
3971  (
3972  "mail_survey_codes",
3973  $this->ctrl->getLinkTarget($this, "mailCodes"),
3974  array("mailCodes", "sendCodesMail", "insertSavedMessage", "deleteSavedMessage"),
3975  ""
3976  );
3977  }
3978  }
3979 
3985  function setEvalSubtabs()
3986  {
3987  global $ilTabs;
3988  global $ilAccess;
3989 
3990  $ilTabs->addSubTabTarget(
3991  "svy_eval_cumulated",
3992  $this->ctrl->getLinkTargetByClass("ilsurveyevaluationgui", "evaluation"),
3993  array("evaluation", "checkEvaluationAccess"),
3994  ""
3995  );
3996 
3997  $ilTabs->addSubTabTarget(
3998  "svy_eval_detail",
3999  $this->ctrl->getLinkTargetByClass("ilsurveyevaluationgui", "evaluationdetails"),
4000  array("evaluationdetails"),
4001  ""
4002  );
4003 
4004  if ($ilAccess->checkAccess("write", "", $this->object->getRefId()))
4005  {
4006  $ilTabs->addSubTabTarget(
4007  "svy_eval_user",
4008  $this->ctrl->getLinkTargetByClass("ilsurveyevaluationgui", "evaluationuser"),
4009  array("evaluationuser"),
4010  ""
4011  );
4012  }
4013  }
4014 
4016  {
4017  global $ilAccess;
4018  global $ilTabs;
4019 
4020  if ($ilAccess->checkAccess("write", "", $this->ref_id))
4021  {
4022  if(!isset($_REQUEST["pgov"]))
4023  {
4024  $link = $this->ctrl->getLinkTarget($this, "questions");
4025  }
4026  else
4027  {
4028  $link = $this->ctrl->getLinkTargetByClass("ilsurveypagegui", "renderpage");
4029  }
4030  $ilTabs->setBackTarget($this->lng->txt("menubacktosurvey"), $link);
4031  $ilTabs->addTarget("browse_for_questions",
4032  $this->ctrl->getLinkTarget($this, "browseForQuestions"),
4033  array("browseForQuestions", "browseForQuestionblocks"),
4034  "", ""
4035  );
4036  }
4037  }
4038 
4044  function getTabs(&$tabs_gui)
4045  {
4046  global $ilAccess, $ilUser, $ilHelp;
4047 
4048  $ilHelp->setScreenIdComponent("svy");
4049 
4050  if (strcmp($this->ctrl->getNextClass(), 'ilrepositorysearchgui') != 0)
4051  {
4052  switch ($this->ctrl->getCmd())
4053  {
4054  case "browseForQuestions":
4055  case "browseForQuestionblocks":
4056  case "insertQuestions":
4057  case "filterQuestions":
4058  case "resetFilterQuestions":
4059  case "changeDatatype":
4060  case "start":
4061  case "resume":
4062  case "next":
4063  case "previous":
4064  case "redirectQuestion":
4065  case "preview":
4066  return;
4067 
4068  case "evaluation":
4069  case "checkEvaluationAccess":
4070  case "evaluationdetails":
4071  case "evaluationuser":
4072  $this->setEvalSubtabs();
4073  break;
4074  }
4075  }
4076 
4077  $hidden_tabs = array();
4078  $template = $this->object->getTemplate();
4079  if($template)
4080  {
4081  include_once "Services/Administration/classes/class.ilSettingsTemplate.php";
4082  $template = new ilSettingsTemplate($template);
4083  $hidden_tabs = $template->getHiddenTabs();
4084  }
4085 
4086  // questions
4087  if ($ilAccess->checkAccess("write", "", $this->ref_id))
4088  {
4089  $force_active = ($_GET["up"] != "" || $_GET["down"] != "")
4090  ? true
4091  : false;
4092 
4093  $cmd = $this->ctrl->getLinkTargetByClass("ilsurveypagegui", "renderPage");
4094  // $cmd = $this->ctrl->getLinkTarget($this, "questions");
4095 
4096  $tabs_gui->addTarget("survey_questions",
4097  $cmd,
4098  array("questions", "browseForQuestions", "createQuestion",
4099  "filterQuestions", "resetFilterQuestions", "changeDatatype", "insertQuestions",
4100  "removeQuestions", "cancelRemoveQuestions", "confirmRemoveQuestions",
4101  "defineQuestionblock", "saveDefineQuestionblock", "cancelDefineQuestionblock",
4102  "unfoldQuestionblock", "moveQuestions",
4103  "insertQuestionsBefore", "insertQuestionsAfter", "saveObligatory",
4104  "addHeading", "saveHeading", "cancelHeading", "editHeading",
4105  "confirmRemoveHeading", "cancelRemoveHeading", "printView", "renderPage",
4106  "addQuestionToolbarForm", "deleteBlock", "movePageForm", "copyQuestionsToPool"),
4107  "", "", $force_active);
4108  }
4109 
4110  if ($ilAccess->checkAccess("visible", "", $this->ref_id))
4111  {
4112  $tabs_gui->addTarget("info_short",
4113  $this->ctrl->getLinkTarget($this,'infoScreen'),
4114  array("infoScreen", "showSummary"));
4115  }
4116 
4117  // properties
4118  if ($ilAccess->checkAccess("write", "", $this->ref_id))
4119  {
4120  $force_active = ($this->ctrl->getCmd() == "")
4121  ? true
4122  : false;
4123  $tabs_gui->addTarget("settings",
4124  $this->ctrl->getLinkTarget($this,'properties'),
4125  array("properties", "save", "cancel", 'saveProperties'), "",
4126  "", $force_active);
4127  }
4128 
4129  // questions
4130  if ($ilAccess->checkAccess("write", "", $this->ref_id) &&
4131  !in_array("constraints", $hidden_tabs))
4132  {
4133  // constraints
4134  $tabs_gui->addTarget("constraints",
4135  $this->ctrl->getLinkTarget($this, "constraints"),
4136  array("constraints", "constraintStep1", "constraintStep2",
4137  "constraintStep3", "constraintsAdd", "createConstraints",
4138  "editPrecondition"),
4139  "");
4140  }
4141 
4142  // #6969
4143  if ($ilAccess->checkAccess("invite", "", $this->ref_id) &&
4144  !in_array("invitation", $hidden_tabs))
4145  {
4146  // invite
4147  $tabs_gui->addTarget("invitation",
4148  $this->ctrl->getLinkTarget($this, 'invite'),
4149  array("invite", "saveInvitationStatus",
4150  "inviteUserGroup", "disinviteUserGroup"),
4151  "");
4152  }
4153 
4154  if ($ilAccess->checkAccess("write", "", $this->ref_id))
4155  {
4156  // maintenance
4157  $tabs_gui->addTarget("maintenance",
4158  $this->ctrl->getLinkTarget($this,'maintenance'),
4159  array("maintenance", "deleteAllUserData"),
4160  "");
4161 
4162  if ($this->object->getAnonymize() == 1 || $this->object->isAccessibleWithCodeForAll())
4163  {
4164  // code
4165  $tabs_gui->addTarget("codes",
4166  $this->ctrl->getLinkTarget($this,'codes'),
4167  array("codes", "exportCodes", 'codesMail', 'saveMailTableFields', 'importExternalMailRecipients',
4168  'mailCodes', 'sendCodesMail', 'importExternalRecipientsFromFile', 'importExternalRecipientsFromText',
4169  'importExternalRecipientsFromDataset', 'insertSavedMessage', 'deleteSavedMessage'),
4170  "");
4171  }
4172  }
4173 
4174  include_once "./Modules/Survey/classes/class.ilObjSurveyAccess.php";
4175  if ($ilAccess->checkAccess("write", "", $this->ref_id) || ilObjSurveyAccess::_hasEvaluationAccess($this->object->getId(), $ilUser->getId()))
4176  {
4177  // evaluation
4178  $tabs_gui->addTarget("svy_evaluation",
4179  $this->ctrl->getLinkTargetByClass("ilsurveyevaluationgui", "evaluation"),
4180  array("evaluation", "checkEvaluationAccess", "evaluationdetails",
4181  "evaluationuser"),
4182  "");
4183  }
4184 
4185  if ($ilAccess->checkAccess("write", "", $this->ref_id))
4186  {
4187  if(!in_array("meta_data", $hidden_tabs))
4188  {
4189  // meta data
4190  $tabs_gui->addTarget("meta_data",
4191  $this->ctrl->getLinkTargetByClass('ilmdeditorgui','listSection'),
4192  "", "ilmdeditorgui");
4193  }
4194 
4195  if(!in_array("export", $hidden_tabs))
4196  {
4197  // export
4198  $tabs_gui->addTarget("export",
4199  $this->ctrl->getLinkTarget($this,'export'),
4200  array("export", "createExportFile", "confirmDeleteExportFile",
4201  "downloadExportFile"),
4202  ""
4203  );
4204  }
4205  }
4206 
4207  if ($ilAccess->checkAccess("edit_permission", "", $this->ref_id))
4208  {
4209  // permissions
4210  $tabs_gui->addTarget("perm_settings",
4211  $this->ctrl->getLinkTargetByClass(array(get_class($this),'ilpermissiongui'), "perm"), array("perm","info","owner"), 'ilpermissiongui');
4212  }
4213  }
4214 
4220  function _goto($a_target, $a_access_code = "")
4221  {
4222  global $ilAccess, $ilErr, $lng;
4223  if ($ilAccess->checkAccess("read", "", $a_target))
4224  {
4225  include_once "./Services/Utilities/classes/class.ilUtil.php";
4226  if (strlen($a_access_code))
4227  {
4228  $_SESSION["anonymous_id"][ilObject::_lookupObjId($a_target)] = $a_access_code;
4229  $_GET["baseClass"] = "ilObjSurveyGUI";
4230  $_GET["cmd"] = "infoScreen";
4231  $_GET["ref_id"] = $a_target;
4232  include("ilias.php");
4233  exit;
4234  }
4235  else
4236  {
4237  $_GET["baseClass"] = "ilObjSurveyGUI";
4238  $_GET["cmd"] = "infoScreen";
4239  $_GET["ref_id"] = $a_target;
4240  include("ilias.php");
4241  exit;
4242  }
4243  }
4244  else if ($ilAccess->checkAccess("read", "", ROOT_FOLDER_ID))
4245  {
4246  ilUtil::sendFailure(sprintf($lng->txt("msg_no_perm_read_item"),
4247  ilObject::_lookupTitle(ilObject::_lookupObjId($a_target))), true);
4249  }
4250 
4251  $ilErr->raiseError($lng->txt("msg_no_perm_read_lm"), $ilErr->FATAL);
4252  }
4253 
4258  {
4259  ilUtil::sendQuestion($this->lng->txt("survey_confirm_template_reset"));
4260  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_svy_confirm_resettemplate.html", "Modules/Survey");
4261  $this->tpl->setCurrentBlock("adm_content");
4262  $this->tpl->setVariable("BTN_CONFIRM_REMOVE", $this->lng->txt("confirm"));
4263  $this->tpl->setVariable("BTN_CANCEL_REMOVE", $this->lng->txt("cancel"));
4264  $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this, "resetTemplateObject"));
4265  $this->tpl->parseCurrentBlock();
4266  }
4267 
4272  {
4273  $this->object->setTemplate(null);
4274  $this->object->saveToDB();
4275 
4276  ilUtil::sendSuccess($this->lng->txt("survey_template_reset"), true);
4277  $this->ctrl->redirect($this, "properties");
4278  }
4279 
4280 
4284  public function copyQuestionsToPoolObject()
4285  {
4286  $items = $this->gatherSelectedTableItems(true, true, false, true);
4287 
4288  // gather questions from blocks
4289  $copy_questions = $items["questions"];
4290  foreach ($items["blocks"] as $block_id)
4291  {
4292  foreach ($this->object->getQuestionblockQuestionIds($block_id) as $qid)
4293  {
4294  array_push($copy_questions, $qid);
4295  }
4296  }
4297  $copy_questions = array_unique($copy_questions);
4298 
4299  // only if not already in pool
4300  if (count($copy_questions))
4301  {
4302  foreach($copy_questions as $idx => $question_id)
4303  {
4304  $question = ilObjSurvey::_instanciateQuestion($question_id);
4305  if($question->getOriginalId())
4306  {
4307  unset($copy_questions[$idx]);
4308  }
4309  }
4310 
4311  }
4312  if (count($copy_questions) == 0)
4313  {
4314  ilUtil::sendInfo($this->lng->txt("no_question_selected_for_copy_to_pool"), true);
4315  $this->ctrl->redirect($this, "questions");
4316  }
4317  else
4318  {
4319  $this->questionsSubtabs("questions");
4320 
4321  include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
4322  $form = new ilPropertyFormGUI();
4323 
4324  $form->setFormAction($this->ctrl->getFormAction($this, "executeCreateQuestion"));
4325 
4326  $ids = new ilHiddenInputGUI("question_ids");
4327  $ids->setValue(implode(";", $copy_questions));
4328  $form->addItem($ids);
4329 
4330  $questionpools =& $this->object->getAvailableQuestionpools(false, false, true, "write");
4331  $pools = new ilSelectInputGUI($this->lng->txt("survey_copy_select_questionpool"), "sel_spl");
4332  $pools->setOptions($questionpools);
4333  $form->addItem($pools);
4334 
4335  $form->addCommandButton("executeCopyQuestionsToPool", $this->lng->txt("submit"));
4336  $form->addCommandButton("questions", $this->lng->txt("cancel"));
4337 
4338  return $this->tpl->setContent($form->getHTML());
4339  }
4340  }
4341 
4346  {
4347  $question_ids = explode(";", $_POST["question_ids"]);
4348  $pool_id = ilObject::_lookupObjId($_POST["sel_spl"]);
4349 
4350  foreach($question_ids as $qid)
4351  {
4352  // create copy (== pool "original")
4353  $new_question = ilObjSurvey::_instanciateQuestion($qid);
4354  $new_question->setId();
4355  $new_question->setObjId($pool_id);
4356  $new_question->saveToDb();
4357 
4358  // link "source" (survey) to copy (pool)
4359  SurveyQuestion::_changeOriginalId($qid, $new_question->getId(), $pool_id);
4360  }
4361 
4362  ilUtil::sendSuccess($this->lng->txt("survey_copy_to_questionpool_success"), true);
4363  $this->ctrl->redirect($this, "questions");
4364  }
4365 
4366 } // END class.ilObjSurveyGUI
4367 ?>