ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjSurveyGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once "./Services/Object/classes/class.ilObjectGUI.php";
5 
23 {
24  public function __construct()
25  {
26  global $lng, $ilCtrl;
27 
28  $this->type = "svy";
29  $lng->loadLanguageModule("survey");
30  $this->ctrl = $ilCtrl;
31  $this->ctrl->saveParameter($this, "ref_id");
32 
33  parent::__construct("", (int)$_GET["ref_id"], true, false);
34  }
35 
36  public function executeCommand()
37  {
38  global $ilAccess, $ilNavigationHistory, $ilErr, $ilTabs;
39 
40  $this->external_rater_360 = false;
41  if(!$this->creation_mode &&
42  $this->object->get360Mode() &&
43  $_SESSION["anonymous_id"][$this->object->getId()] &&
44  ilObjSurvey::validateExternalRaterCode($this->object->getRefId(),
45  $_SESSION["anonymous_id"][$this->object->getId()]))
46  {
47  $this->external_rater_360 = true;
48  }
49 
50  if(!$this->external_rater_360)
51  {
52  if (!$ilAccess->checkAccess("read", "", $this->ref_id) &&
53  !$ilAccess->checkAccess("visible", "", $this->ref_id))
54  {
55  $ilErr->raiseError($this->lng->txt("permission_denied"), $ilErr->MESSAGE);
56  }
57 
58  // add entry to navigation history
59  if (!$this->getCreationMode() &&
60  $ilAccess->checkAccess("read", "", $this->ref_id))
61  {
62  $this->ctrl->setParameterByClass("ilobjsurveygui", "ref_id", $this->ref_id);
63  $link = $this->ctrl->getLinkTargetByClass("ilobjsurveygui", "");
64  $ilNavigationHistory->addItem($this->ref_id, $link, "svy");
65  }
66  }
67 
68  $cmd = $this->ctrl->getCmd("properties");
69 
70  // workaround for bug #6288, needs better solution
71  if ($cmd == "saveTags")
72  {
73  $this->ctrl->setCmdClass("ilinfoscreengui");
74  }
75 
76  // deep link from repository - "redirect" to page view
77  if(!$this->ctrl->getCmdClass() && $cmd == "questionsrepo")
78  {
79  $_REQUEST["pgov"] = 1;
80  $this->ctrl->setCmd("questions");
81  $this->ctrl->setCmdClass("ilsurveyeditorgui");
82  }
83 
84  $next_class = $this->ctrl->getNextClass($this);
85  $this->ctrl->setReturn($this, "properties");
86  $this->tpl->addCss(ilUtil::getStyleSheetLocation("output", "survey.css", "Modules/Survey"), "screen");
87  $this->prepareOutput();
88 
89  switch($next_class)
90  {
91  case "ilinfoscreengui":
92  if(!in_array($this->ctrl->getCmdClass(),
93  array('ilpublicuserprofilegui', 'ilobjportfoliogui')))
94  {
95  $this->addHeaderAction();
96  $this->infoScreen(); // forwards command
97  }
98  else
99  {
100  // #16891
101  $ilTabs->clearTargets();
102  include_once("./Services/InfoScreen/classes/class.ilInfoScreenGUI.php");
103  $info = new ilInfoScreenGUI($this);
104  $this->ctrl->forwardCommand($info);
105  }
106  break;
107 
108  case 'ilmdeditorgui':
109  $this->handleWriteAccess();
110  $ilTabs->activateTab("meta_data");
111  $this->addHeaderAction();
112  include_once 'Services/MetaData/classes/class.ilMDEditorGUI.php';
113  $md_gui =& new ilMDEditorGUI($this->object->getId(), 0, $this->object->getType());
114  $md_gui->addObserver($this->object,'MDUpdateListener','General');
115 
116  $this->ctrl->forwardCommand($md_gui);
117  break;
118 
119  case "ilsurveyevaluationgui":
120  $ilTabs->activateTab("svy_results");
121  $this->addHeaderAction();
122  include_once("./Modules/Survey/classes/class.ilSurveyEvaluationGUI.php");
123  $eval_gui = new ilSurveyEvaluationGUI($this->object);
124  $this->ctrl->forwardCommand($eval_gui);
125  break;
126 
127  case "ilsurveyexecutiongui":
128  $ilTabs->clearTargets();
129  include_once("./Modules/Survey/classes/class.ilSurveyExecutionGUI.php");
130  $exec_gui = new ilSurveyExecutionGUI($this->object);
131  $this->ctrl->forwardCommand($exec_gui);
132  break;
133 
134  case 'ilpermissiongui':
135  $ilTabs->activateTab("perm_settings");
136  $this->addHeaderAction();
137  include_once("Services/AccessControl/classes/class.ilPermissionGUI.php");
138  $perm_gui =& new ilPermissionGUI($this);
139  $this->ctrl->forwardCommand($perm_gui);
140  break;
141 
142  case 'ilobjectcopygui':
143  include_once './Services/Object/classes/class.ilObjectCopyGUI.php';
144  $cp = new ilObjectCopyGUI($this);
145  $cp->setType('svy');
146  $this->ctrl->forwardCommand($cp);
147  break;
148 
149  case "ilcommonactiondispatchergui":
150  include_once("Services/Object/classes/class.ilCommonActionDispatcherGUI.php");
152  $this->ctrl->forwardCommand($gui);
153  break;
154 
155  // 360, skill service
156  case 'ilsurveyskillgui':
157  $ilTabs->activateTab("survey_competences");
158  include_once("./Modules/Survey/classes/class.ilSurveySkillGUI.php");
159  $gui = new ilSurveySkillGUI($this->object);
160  $this->ctrl->forwardCommand($gui);
161  break;
162 
163  case 'ilsurveyskilldeterminationgui':
164  $ilTabs->activateTab("maintenance");
165  include_once("./Modules/Survey/classes/class.ilSurveySkillDeterminationGUI.php");
166  $gui = new ilSurveySkillDeterminationGUI($this->object);
167  $this->ctrl->forwardCommand($gui);
168  break;
169 
170  case 'ilsurveyeditorgui':
171  $this->handleWriteAccess();
172  $ilTabs->activateTab("survey_questions");
173  include_once("./Modules/Survey/classes/class.ilSurveyEditorGUI.php");
174  $gui = new ilSurveyEditorGUI($this);
175  $this->ctrl->forwardCommand($gui);
176  break;
177 
178  case 'ilsurveyconstraintsgui':
179  $this->handleWriteAccess();
180  $ilTabs->activateTab("constraints");
181  include_once("./Modules/Survey/classes/class.ilSurveyConstraintsGUI.php");
182  $gui = new ilSurveyConstraintsGUI($this);
183  $this->ctrl->forwardCommand($gui);
184  break;
185 
186  case 'ilsurveyparticipantsgui':
187  if(!$this->object->get360Mode())
188  {
189  $ilTabs->activateTab("maintenance");
190  }
191  else
192  {
193  $ilTabs->activateTab("survey_360_appraisees");
194  }
195  include_once("./Modules/Survey/classes/class.ilSurveyParticipantsGUI.php");
196  $gui = new ilSurveyParticipantsGUI($this);
197  $this->ctrl->forwardCommand($gui);
198  break;
199 
200  default:
201  $this->addHeaderAction();
202  $cmd.= "Object";
203  $this->$cmd();
204  break;
205  }
206 
207  if (strtolower($_GET["baseClass"]) != "iladministrationgui" &&
208  $this->getCreationMode() != true)
209  {
210  $this->tpl->show();
211  }
212  }
213 
221  public function evaluationObject()
222  {
223  include_once("./Modules/Survey/classes/class.ilSurveyEvaluationGUI.php");
224  $eval_gui = new ilSurveyEvaluationGUI($this->object);
225  $this->ctrl->setCmdClass(get_class($eval_gui));
226  $this->ctrl->redirect($eval_gui, "evaluation");
227  }
228 
229  protected function addDidacticTemplateOptions(array &$a_options)
230  {
231  include_once "Services/Administration/classes/class.ilSettingsTemplate.php";
233  if($templates)
234  {
235  foreach($templates as $item)
236  {
237  $a_options["svytpl_".$item["id"]] = array($item["title"],
238  nl2br(trim($item["description"])));
239  }
240  }
241 
242  // JF, 2013-06-10
243  $a_options["svy360_1"] = array($this->lng->txt("survey_360_mode"),
244  $this->lng->txt("survey_360_mode_info"));
245  }
246 
251  function afterSave(ilObject $a_new_object)
252  {
253  $tpl = $this->getDidacticTemplateVar("svytpl");
254  if($tpl)
255  {
256  $a_new_object->applySettingsTemplate($tpl);
257  }
258 
259  $a_new_object->set360Mode((bool)$this->getDidacticTemplateVar("svy360"));
260  if($a_new_object->get360Mode())
261  {
262  // this should rather be ilObjSurvey::ANONYMIZE_ON - see ilObjSurvey::getUserDataFromActiveId()
263  $a_new_object->setAnonymize(ilObjSurvey::ANONYMIZE_CODE_ALL);
264  $a_new_object->setEvaluationAccess(ilObjSurvey::EVALUATION_ACCESS_PARTICIPANTS);
265  }
266  $a_new_object->saveToDB();
267 
268  // always send a message
269  ilUtil::sendSuccess($this->lng->txt("object_added"),true);
270  ilUtil::redirect("ilias.php?baseClass=ilObjSurveyGUI&ref_id=".
271  $a_new_object->getRefId()."&cmd=properties");
272  }
273 
279  function getTabs(&$tabs_gui)
280  {
281  global $ilAccess, $ilUser, $ilHelp;
282 
283  if($this->object instanceof ilObjSurveyQuestionPool)
284  {
285  return true;
286  }
287 
288  $ilHelp->setScreenIdComponent("svy");
289 
290  $hidden_tabs = array();
291  $template = $this->object->getTemplate();
292  if($template)
293  {
294  include_once "Services/Administration/classes/class.ilSettingsTemplate.php";
295  $template = new ilSettingsTemplate($template);
296  $hidden_tabs = $template->getHiddenTabs();
297  }
298 
299  if ($ilAccess->checkAccess("write", "", $this->ref_id))
300  {
301  $tabs_gui->addTab("survey_questions",
302  $this->lng->txt("survey_questions"),
303  $this->ctrl->getLinkTargetByClass(array("ilsurveyeditorgui", "ilsurveypagegui"), "renderPage"));
304  }
305 
306  if ($ilAccess->checkAccess("visible", "", $this->ref_id))
307  {
308  $tabs_gui->addTab("info_short",
309  $this->lng->txt("info_short"),
310  $this->ctrl->getLinkTarget($this,'infoScreen'));
311  }
312 
313  // properties
314  if ($ilAccess->checkAccess("write", "", $this->ref_id))
315  {
316  $tabs_gui->addTab("settings",
317  $this->lng->txt("settings"),
318  $this->ctrl->getLinkTarget($this,'properties'));
319  }
320  else if ($ilAccess->checkAccess("read", "", $this->ref_id))
321  {
322  if($this->object->get360Mode() &&
323  $this->object->get360SelfRaters() &&
324  $this->object->isAppraisee($ilUser->getId()) &&
325  !$this->object->isAppraiseeClosed($ilUser->getId()))
326  {
327  $tabs_gui->addTab("survey_360_edit_raters",
328  $this->lng->txt("survey_360_edit_raters"),
329  $this->ctrl->getLinkTargetByClass('ilsurveyparticipantsgui','editRaters'));
330 
331  // :TODO: mail to raters
332  }
333  }
334 
335  // questions
336  if ($ilAccess->checkAccess("write", "", $this->ref_id) &&
337  !in_array("constraints", $hidden_tabs) &&
338  !$this->object->get360Mode())
339  {
340  // constraints
341  $tabs_gui->addTab("constraints",
342  $this->lng->txt("constraints"),
343  $this->ctrl->getLinkTargetByClass("ilsurveyconstraintsgui", "constraints"));
344  }
345 
346  if ($ilAccess->checkAccess("write", "", $this->ref_id))
347  {
348  // 360°
349  if($this->object->get360Mode())
350  {
351  // 360 mode + competence service
352  include_once("./Services/Skill/classes/class.ilSkillManagementSettings.php");
353  $skmg_set = new ilSkillManagementSettings();
354  if ($this->object->get360SkillService() && $skmg_set->isActivated())
355  {
356  $tabs_gui->addTab("survey_competences",
357  $this->lng->txt("survey_competences"),
358  $this->ctrl->getLinkTargetByClass("ilsurveyskillgui", "listQuestionAssignment"));
359  }
360 
361  $tabs_gui->addTab("survey_360_appraisees",
362  $this->lng->txt("survey_360_appraisees"),
363  $this->ctrl->getLinkTargetByClass('ilsurveyparticipantsgui', 'listAppraisees'));
364  }
365  else
366  {
367  // maintenance
368  $tabs_gui->addTab("maintenance",
369  $this->lng->txt("maintenance"),
370  $this->ctrl->getLinkTargetByClass('ilsurveyparticipantsgui', 'maintenance'));
371  }
372  }
373 
374  include_once "./Modules/Survey/classes/class.ilObjSurveyAccess.php";
375  if ($ilAccess->checkAccess("write", "", $this->ref_id) ||
376  ilObjSurveyAccess::_hasEvaluationAccess($this->object->getId(), $ilUser->getId()))
377  {
378  // evaluation
379  $tabs_gui->addTab("svy_results",
380  $this->lng->txt("svy_results"),
381  $this->ctrl->getLinkTargetByClass("ilsurveyevaluationgui", "evaluation"));
382  }
383 
384  if ($ilAccess->checkAccess("write", "", $this->ref_id))
385  {
386  if(!in_array("meta_data", $hidden_tabs))
387  {
388  // meta data
389  $tabs_gui->addTab("meta_data",
390  $this->lng->txt("meta_data"),
391  $this->ctrl->getLinkTargetByClass('ilmdeditorgui','listSection'));
392  }
393 
394  if(!in_array("export", $hidden_tabs))
395  {
396  // export
397  $tabs_gui->addTab("export",
398  $this->lng->txt("export"),
399  $this->ctrl->getLinkTarget($this,'export'));
400  }
401  }
402 
403  if ($ilAccess->checkAccess("edit_permission", "", $this->ref_id))
404  {
405  // permissions
406  $tabs_gui->addTab("perm_settings",
407  $this->lng->txt("perm_settings"),
408  $this->ctrl->getLinkTargetByClass(array(get_class($this),'ilpermissiongui'), "perm"));
409  }
410  }
411 
419  public function handleWriteAccess()
420  {
421  global $ilAccess;
422  if (!$ilAccess->checkAccess("write", "", $this->ref_id))
423  {
424  // allow only write access
425  ilUtil::sendInfo($this->lng->txt("cannot_edit_survey"), TRUE);
426  $this->ctrl->redirect($this, "infoScreen");
427  }
428  }
429 
430 
431  //
432  // SETTINGS
433  //
434 
443  {
444  global $rbacsystem;
445 
446  $form = $this->initPropertiesForm();
447  if ($form->checkInput())
448  {
449  $valid = true;
450 
451  if(!$this->object->get360Mode())
452  {
453  if($form->getInput("tut"))
454  {
455  // check if given "tutors" have write permission
456  $tut_ids =array();
457  $tut_logins = $form->getInput("tut_ids");
458  foreach($tut_logins as $tut_login)
459  {
460  $tut_id = ilObjUser::_lookupId($tut_login);
461  if($tut_id && $rbacsystem->checkAccessOfUser($tut_id, "write", $this->object->getRefId()))
462  {
463  $tut_ids[] = $tut_id;
464  }
465  }
466  if(!$tut_ids)
467  {
468  $tut_ids = $form->getItemByPostVar("tut_ids");
469  $tut_ids->setAlert($this->lng->txt("survey_notification_tutor_recipients_invalid"));
470  $valid = false;
471  }
472  }
473  }
474 
475  if($valid)
476  {
477  if(!$this->object->get360Mode())
478  {
479  if($form->getInput("rmd"))
480  {
481  $rmd_start = $form->getInput("rmd_start");
482  $rmd_start = $rmd_start["date"];
483  $rmd_end = null;
484  if($form->getInput("rmd_end_tgl"))
485  {
486  $rmd_end = $form->getInput("rmd_end");
487  $rmd_end = $rmd_end["date"];
488  if($rmd_start > $rmd_end)
489  {
490  $tmp = $rmd_start;
491  $rmd_start = $rmd_end;
492  $rmd_end = $tmp;
493  }
494  $rmd_end = new ilDate($rmd_end, IL_CAL_DATE);
495  }
496  $rmd_start = new ilDate($rmd_start, IL_CAL_DATE);
497 
498  $this->object->setReminderStatus(true);
499  $this->object->setReminderStart($rmd_start);
500  $this->object->setReminderEnd($rmd_end);
501  $this->object->setReminderFrequency($form->getInput("rmd_freq"));
502  $this->object->setReminderTarget($form->getInput("rmd_grp"));
503  }
504  else
505  {
506  $this->object->setReminderStatus(false);
507  }
508 
509  if($form->getInput("tut"))
510  {
511  $this->object->setTutorNotificationStatus(true);
512  $this->object->setTutorNotificationRecipients($tut_ids); // see above
513  $this->object->setTutorNotificationTarget($form->getInput("tut_grp"));
514  }
515  else
516  {
517  $this->object->setTutorNotificationStatus(false);
518  }
519  }
520 
521  // #10055
522  if ($_POST['online'] && count($this->object->questions) == 0)
523  {
524  $_POST['online'] = null;
525  ilUtil::sendFailure($this->lng->txt("cannot_switch_to_online_no_questions"), true);
526  }
527 
528  $template_settings = null;
529  $template = $this->object->getTemplate();
530  if($template)
531  {
532  include_once "Services/Administration/classes/class.ilSettingsTemplate.php";
533  $template = new ilSettingsTemplate($template);
534  $template_settings = $template->getSettings();
535  }
536 
537  include_once 'Services/MetaData/classes/class.ilMD.php';
538  $md_obj =& new ilMD($this->object->getId(), 0, "svy");
539  $md_section = $md_obj->getGeneral();
540 
541  // title
542  $md_section->setTitle(ilUtil::stripSlashes($_POST['title']));
543  $md_section->update();
544 
545  // Description
546  $md_desc_ids = $md_section->getDescriptionIds();
547  if($md_desc_ids)
548  {
549  $md_desc = $md_section->getDescription(array_pop($md_desc_ids));
550  $md_desc->setDescription(ilUtil::stripSlashes($_POST['description']));
551  $md_desc->update();
552  }
553 
554  $this->object->setViewOwnResults($_POST["view_own"]);
555  $this->object->setMailOwnResults($_POST["mail_own"]);
556 
557  // both are saved in object, too
558  $this->object->setTitle(ilUtil::stripSlashes($_POST['title']));
559  $this->object->setDescription(ilUtil::stripSlashes($_POST['description']));
560  $this->object->update();
561 
562  $this->object->setStatus($_POST['online']);
563 
564  // activation
565  if($_POST["access_type"])
566  {
567  $this->object->setActivationLimited(true);
568  $this->object->setActivationVisibility($_POST["access_visiblity"]);
569 
570  $period = $form->getItemByPostVar("access_period");
571  $this->object->setActivationStartDate($period->getStart()->get(IL_CAL_UNIX));
572  $this->object->setActivationEndDate($period->getEnd()->get(IL_CAL_UNIX));
573  }
574  else
575  {
576  $this->object->setActivationLimited(false);
577  }
578 
579 
580  if(!$template_settings["enabled_start_date"]["hide"])
581  {
582  if ($_POST["enabled_start_date"])
583  {
584  $this->object->setStartDateAndTime($_POST["start_date"]['date'], $_POST["start_date"]['time']);
585  }
586  else
587  {
588  $this->object->setStartDate(null);
589  }
590  }
591 
592  if(!$template_settings["enabled_end_date"]["hide"])
593  {
594  if ($_POST["enabled_end_date"])
595  {
596  $this->object->setEndDateAndTime($_POST["end_date"]['date'], $_POST["end_date"]['time']);
597  }
598  else
599  {
600  $this->object->setEndDate(null);
601  }
602  }
603 
604 
605  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
606  $introduction = $_POST["introduction"];
607  $this->object->setIntroduction($introduction);
608  $outro = $_POST["outro"];
609  $this->object->setOutro($outro);
610 
611  if(!$template_settings["show_question_titles"]["hide"])
612  {
613  $this->object->setShowQuestionTitles($_POST["show_question_titles"]);
614  }
615 
616  if(!$template_settings["use_pool"]["hide"])
617  {
618  $this->object->setPoolUsage($_POST["use_pool"]);
619  }
620 
621  $this->object->setMailNotification($_POST['mailnotification']);
622  $this->object->setMailAddresses($_POST['mailaddresses']);
623  $this->object->setMailParticipantData($_POST['mailparticipantdata']);
624 
625  // 360°
626  if($this->object->get360Mode())
627  {
628  $this->object->set360SelfEvaluation((bool)$_POST["self_eval"]);
629  $this->object->set360SelfAppraisee((bool)$_POST["self_appr"]);
630  $this->object->set360SelfRaters((bool)$_POST["self_rate"]);
631  $this->object->set360Results((int)$_POST["ts_res"]);;
632  $this->object->set360SkillService((int)$_POST["skill_service"]);
633  }
634  else
635  {
636  $this->object->setEvaluationAccess($_POST["evaluation_access"]);
637 
638  $hasDatasets = $this->object->_hasDatasets($this->object->getSurveyId());
639  if (!$hasDatasets)
640  {
641  $codes = (bool)$_POST["acc_codes"];
642  $anon = ((string)$_POST["anonymization_options"] == "statanon");
643  if (!$anon)
644  {
645  if (!$codes)
646  {
647  $this->object->setAnonymize(ilObjSurvey::ANONYMIZE_OFF);
648  }
649  else
650  {
651  $this->object->setAnonymize(ilObjSurvey::ANONYMIZE_CODE_ALL);
652  }
653  }
654  else
655  {
656  if ($codes)
657  {
658  $this->object->setAnonymize(ilObjSurvey::ANONYMIZE_ON);
659  }
660  else
661  {
662  $this->object->setAnonymize(ilObjSurvey::ANONYMIZE_FREEACCESS);
663  }
664  }
665 
666  // if settings were changed get rid of existing code
667  unset($_SESSION["anonymous_id"][$this->object->getId()]);
668  }
669  }
670 
671  $this->object->saveToDb();
672 
673  if (strcmp($_SESSION["info"], "") != 0)
674  {
675  ilUtil::sendSuccess($_SESSION["info"] . "<br />" . $this->lng->txt("settings_saved"), true);
676  }
677  else
678  {
679  ilUtil::sendSuccess($this->lng->txt("settings_saved"), true);
680  }
681  $this->ctrl->redirect($this, "properties");
682  }
683  }
684 
685  $form->setValuesByPost();
686  $this->propertiesObject($form);
687  }
688 
695  {
696  $template_settings = $hide_rte_switch = null;
697  $template = $this->object->getTemplate();
698  if($template)
699  {
700  include_once "Services/Administration/classes/class.ilSettingsTemplate.php";
701  $template = new ilSettingsTemplate($template);
702 
703  $template_settings = $template->getSettings();
704  $hide_rte_switch = $template_settings["rte_switch"]["hide"];
705  }
706 
707  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
708  $form = new ilPropertyFormGUI();
709  $form->setFormAction($this->ctrl->getFormAction($this));
710  $form->setTableWidth("100%");
711  $form->setId("survey_properties");
712 
713  // general properties
714  $header = new ilFormSectionHeaderGUI();
715  $header->setTitle($this->lng->txt("settings"));
716  $form->addItem($header);
717 
718 
719  // title & description (meta data)
720 
721  include_once 'Services/MetaData/classes/class.ilMD.php';
722  $md_obj = new ilMD($this->object->getId(), 0, "svy");
723  $md_section = $md_obj->getGeneral();
724 
725  $title = new ilTextInputGUI($this->lng->txt("title"), "title");
726  $title->setRequired(true);
727  $title->setValue($md_section->getTitle());
728  $form->addItem($title);
729 
730  $ids = $md_section->getDescriptionIds();
731  if($ids)
732  {
733  $desc_obj = $md_section->getDescription(array_pop($ids));
734 
735  $desc = new ilTextAreaInputGUI($this->lng->txt("description"), "description");
736  $desc->setCols(50);
737  $desc->setRows(4);
738  $desc->setValue($desc_obj->getDescription());
739  $form->addItem($desc);
740  }
741 
742  // pool usage
743  $pool_usage = new ilRadioGroupInputGUI($this->lng->txt("survey_question_pool_usage"), "use_pool");
744  $opt = new ilRadioOption($this->lng->txt("survey_question_pool_usage_active"), 1);
745  $opt->setInfo($this->lng->txt("survey_question_pool_usage_active_info"));
746  $pool_usage->addOption($opt);
747  $opt = new ilRadioOption($this->lng->txt("survey_question_pool_usage_inactive"), 0);
748  $opt->setInfo($this->lng->txt("survey_question_pool_usage_inactive_info"));
749  $pool_usage->addOption($opt);
750  $pool_usage->setValue($this->object->getPoolUsage());
751  $form->addItem($pool_usage);
752 
753  // 360°: appraisees
754  if($this->object->get360Mode())
755  {
756  $self_eval = new ilCheckboxInputGUI($this->lng->txt("survey_360_self_evaluation"), "self_eval");
757  $self_eval->setInfo($this->lng->txt("survey_360_self_evaluation_info"));
758  $self_eval->setChecked($this->object->get360SelfEvaluation());
759  $form->addItem($self_eval);
760 
761  $self_rate = new ilCheckboxInputGUI($this->lng->txt("survey_360_self_raters"), "self_rate");
762  $self_rate->setInfo($this->lng->txt("survey_360_self_raters_info"));
763  $self_rate->setChecked($this->object->get360SelfRaters());
764  $form->addItem($self_rate);
765 
766  $self_appr = new ilCheckboxInputGUI($this->lng->txt("survey_360_self_appraisee"), "self_appr");
767  $self_appr->setInfo($this->lng->txt("survey_360_self_appraisee_info"));
768  $self_appr->setChecked($this->object->get360SelfAppraisee());
769  $form->addItem($self_appr);
770  }
771 
772 
773  // activation
774 
775  include_once "Services/Object/classes/class.ilObjectActivation.php";
776  $this->lng->loadLanguageModule('rep');
777 
779  $section->setTitle($this->lng->txt('rep_activation_availability'));
780  $form->addItem($section);
781 
782  // additional info only with multiple references
783  $act_obj_info = $act_ref_info = "";
784  if(sizeof(ilObject::_getAllReferences($this->object->getId())) > 1)
785  {
786  $act_obj_info = ' '.$this->lng->txt('rep_activation_online_object_info');
787  $act_ref_info = $this->lng->txt('rep_activation_access_ref_info');
788  }
789 
790  $online = new ilCheckboxInputGUI($this->lng->txt('rep_activation_online'),'online');
791  $online->setInfo($this->lng->txt('svy_activation_online_info').$act_obj_info);
792  $online->setChecked($this->object->isOnline());
793  $form->addItem($online);
794 
795  $act_type = new ilCheckboxInputGUI($this->lng->txt('rep_visibility_until'),'access_type');
796  // $act_type->setInfo($this->lng->txt('svy_availability_until_info'));
797  $act_type->setChecked($this->object->isActivationLimited());
798 
799  $this->tpl->addJavaScript('./Services/Form/js/date_duration.js');
800  include_once "Services/Form/classes/class.ilDateDurationInputGUI.php";
801  $dur = new ilDateDurationInputGUI($this->lng->txt('rep_time_period'), "access_period");
802  $dur->setShowTime(true);
803  $date = $this->object->getActivationStartDate();
804  $dur->setStart(new ilDateTime($date ? $date : time(), IL_CAL_UNIX));
805  $dur->setStartText($this->lng->txt('rep_activation_limited_start'));
806  $date = $this->object->getActivationEndDate();
807  $dur->setEnd(new ilDateTime($date ? $date : time(), IL_CAL_UNIX));
808  $dur->setEndText($this->lng->txt('rep_activation_limited_end'));
809  $act_type->addSubItem($dur);
810 
811  $visible = new ilCheckboxInputGUI($this->lng->txt('rep_activation_limited_visibility'), 'access_visiblity');
812  $visible->setInfo($this->lng->txt('svy_activation_limited_visibility_info'));
813  $visible->setChecked($this->object->getActivationVisibility());
814  $act_type->addSubItem($visible);
815 
816  $form->addItem($act_type);
817 
818 
819  // before start
820 
822  $section->setTitle($this->lng->txt('svy_settings_section_before_start'));
823  $form->addItem($section);
824 
825  // introduction
826  $intro = new ilTextAreaInputGUI($this->lng->txt("introduction"), "introduction");
827  $intro->setValue($this->object->prepareTextareaOutput($this->object->getIntroduction()));
828  $intro->setRows(10);
829  $intro->setCols(80);
830  $intro->setUseRte(TRUE);
831  $intro->setInfo($this->lng->txt("survey_introduction_info"));
832  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
833  $intro->setRteTags(ilObjAdvancedEditing::_getUsedHTMLTags("survey"));
834  $intro->addPlugin("latex");
835  $intro->addButton("latex");
836  $intro->addButton("pastelatex");
837  $intro->setRTESupport($this->object->getId(), "svy", "survey", null, $hide_rte_switch);
838  $form->addItem($intro);
839 
840 
841  // access
842 
844  $section->setTitle($this->lng->txt('svy_settings_section_access'));
845  $form->addItem($section);
846 
847  // enable start date
848  $start = $this->object->getStartDate();
849  $enablestartingtime = new ilCheckboxInputGUI($this->lng->txt("start_date"), "enabled_start_date");
850  $enablestartingtime->setValue(1);
851  // $enablestartingtime->setOptionTitle($this->lng->txt("enabled"));
852  $enablestartingtime->setChecked($start);
853  // start date
854  $startingtime = new ilDateTimeInputGUI('', 'start_date');
855  $startingtime->setShowTime(true);
856  if ($start)
857  {
858  $startingtime->setDate(new ilDate($start, IL_CAL_TIMESTAMP));
859  }
860  $enablestartingtime->addSubItem($startingtime);
861  $form->addItem($enablestartingtime);
862 
863  // enable end date
864  $end = $this->object->getEndDate();
865  $enableendingtime = new ilCheckboxInputGUI($this->lng->txt("end_date"), "enabled_end_date");
866  $enableendingtime->setValue(1);
867  // $enableendingtime->setOptionTitle($this->lng->txt("enabled"));
868  $enableendingtime->setChecked($end);
869  // end date
870  $endingtime = new ilDateTimeInputGUI('', 'end_date');
871  $endingtime->setShowTime(true);
872  if ($end)
873  {
874  $endingtime->setDate(new ilDate($end, IL_CAL_TIMESTAMP));
875  }
876  $enableendingtime->addSubItem($endingtime);
877  $form->addItem($enableendingtime);
878 
879  // anonymization
880  if(!$this->object->get360Mode())
881  {
882  $codes = new ilCheckboxInputGUI($this->lng->txt("survey_access_codes"), "acc_codes");
883  $codes->setInfo($this->lng->txt("survey_access_codes_info"));
884  $codes->setChecked(!$this->object->isAccessibleWithoutCode());
885  $form->addItem($codes);
886 
887  if ($this->object->_hasDatasets($this->object->getSurveyId()))
888  {
889  $codes->setDisabled(true);
890  }
891  }
892 
893 
894  // question behaviour
895 
897  $section->setTitle($this->lng->txt('svy_settings_section_question_behaviour'));
898  $form->addItem($section);
899 
900  // show question titles
901  $show_question_titles = new ilCheckboxInputGUI($this->lng->txt("svy_show_questiontitles"), "show_question_titles");
902  $show_question_titles->setValue(1);
903  $show_question_titles->setChecked($this->object->getShowQuestionTitles());
904  $form->addItem($show_question_titles);
905 
906 
907  // finishing
908 
909  $info = new ilFormSectionHeaderGUI();
910  $info->setTitle($this->lng->txt("svy_settings_section_finishing"));
911  $form->addItem($info);
912 
913  $view_own = new ilCheckboxInputGUI($this->lng->txt("svy_results_view_own"), "view_own");
914  $view_own->setInfo($this->lng->txt("svy_results_view_own_info"));
915  $view_own->setChecked($this->object->hasViewOwnResults());
916  $form->addItem($view_own);
917 
918  $mail_own = new ilCheckboxInputGUI($this->lng->txt("svy_results_mail_own"), "mail_own");
919  $mail_own->setInfo($this->lng->txt("svy_results_mail_own_info"));
920  $mail_own->setChecked($this->object->hasMailOwnResults());
921  $form->addItem($mail_own);
922 
923  // final statement
924  $finalstatement = new ilTextAreaInputGUI($this->lng->txt("outro"), "outro");
925  $finalstatement->setValue($this->object->prepareTextareaOutput($this->object->getOutro()));
926  $finalstatement->setRows(10);
927  $finalstatement->setCols(80);
928  $finalstatement->setUseRte(TRUE);
929  $finalstatement->setRteTags(ilObjAdvancedEditing::_getUsedHTMLTags("survey"));
930  $finalstatement->addPlugin("latex");
931  $finalstatement->addButton("latex");
932  $finalstatement->addButton("pastelatex");
933  $finalstatement->setRTESupport($this->object->getId(), "svy", "survey", null, $hide_rte_switch);
934  $form->addItem($finalstatement);
935 
936  // mail notification
937  $mailnotification = new ilCheckboxInputGUI($this->lng->txt("mailnotification"), "mailnotification");
938  // $mailnotification->setOptionTitle($this->lng->txt("activate"));
939  $mailnotification->setInfo($this->lng->txt("svy_result_mail_notification_info")); // #11762
940  $mailnotification->setValue(1);
941  $mailnotification->setChecked($this->object->getMailNotification());
942 
943  // addresses
944  $mailaddresses = new ilTextInputGUI($this->lng->txt("mailaddresses"), "mailaddresses");
945  $mailaddresses->setValue($this->object->getMailAddresses());
946  $mailaddresses->setSize(80);
947  $mailaddresses->setInfo($this->lng->txt('mailaddresses_info'));
948  $mailaddresses->setRequired(true);
949 
950  // participant data
951  $participantdata = new ilTextAreaInputGUI($this->lng->txt("mailparticipantdata"), "mailparticipantdata");
952  $participantdata->setValue($this->object->getMailParticipantData());
953  $participantdata->setRows(6);
954  $participantdata->setCols(80);
955  $participantdata->setUseRte(false);
956  $participantdata->setInfo($this->lng->txt("mailparticipantdata_info"));
957 
958  // #12755 - because of privacy concerns we restrict user data to a minimum
959  $placeholders = array(
960  "FIRST_NAME" => "firstname",
961  "LAST_NAME" => "lastname",
962  "LOGIN" => "login"
963  );
964  $txt = array();
965  foreach($placeholders as $placeholder => $caption)
966  {
967  $txt[] = "[".strtoupper($placeholder)."]: ".$this->lng->txt($caption);
968  }
969  $txt = implode("<br />", $txt);
970  $participantdatainfo = new ilNonEditableValueGUI($this->lng->txt("mailparticipantdata_placeholder"), "", true);
971  $participantdatainfo->setValue($txt);
972 
973  $mailnotification->addSubItem($mailaddresses);
974  $mailnotification->addSubItem($participantdata);
975  $mailnotification->addSubItem($participantdatainfo);
976  $form->addItem($mailnotification);
977 
978  // tutor notification - currently not available for 360°
979  if(!$this->object->get360Mode())
980  {
981  // parent course?
982  global $tree;
983  $has_parent = $tree->checkForParentType($this->object->getRefId(), "grp");
984  if(!$has_parent)
985  {
986  $has_parent = $tree->checkForParentType($this->object->getRefId(), "crs");
987  }
988  $num_inv = sizeof($this->object->getInvitedUsers());
989 
990  // notification
991  $tut = new ilCheckboxInputGUI($this->lng->txt("survey_notification_tutor_setting"), "tut");
992  $tut->setChecked($this->object->getTutorNotificationStatus());
993  $form->addItem($tut);
994 
995  $tut_logins = array();
996  $tuts = $this->object->getTutorNotificationRecipients();
997  if($tuts)
998  {
999  foreach($tuts as $tut_id)
1000  {
1001  $tmp = ilObjUser::_lookupName($tut_id);
1002  if($tmp["login"])
1003  {
1004  $tut_logins[] = $tmp["login"];
1005  }
1006  }
1007  }
1008  $tut_ids = new ilTextInputGUI($this->lng->txt("survey_notification_tutor_recipients"), "tut_ids");
1009  $tut_ids->setDataSource($this->ctrl->getLinkTarget($this, "doAutoComplete", "", true));
1010  $tut_ids->setRequired(true);
1011  $tut_ids->setMulti(true);
1012  $tut_ids->setMultiValues($tut_logins);
1013  $tut_ids->setValue(array_shift($tut_logins));
1014  $tut->addSubItem($tut_ids);
1015 
1016  $tut_grp = new ilRadioGroupInputGUI($this->lng->txt("survey_notification_target_group"), "tut_grp");
1017  $tut_grp->setRequired(true);
1018  $tut_grp->setValue($this->object->getTutorNotificationTarget());
1019  $tut->addSubItem($tut_grp);
1020 
1021  $tut_grp_crs = new ilRadioOption($this->lng->txt("survey_notification_target_group_parent_course"),
1023  if(!$has_parent)
1024  {
1025  $tut_grp_crs->setInfo($this->lng->txt("survey_notification_target_group_parent_course_inactive"));
1026  }
1027  $tut_grp->addOption($tut_grp_crs);
1028 
1029  $tut_grp_inv = new ilRadioOption($this->lng->txt("survey_notification_target_group_invited"),
1031  $tut_grp_inv->setInfo(sprintf($this->lng->txt("survey_notification_target_group_invited_info"), $num_inv));
1032  $tut_grp->addOption($tut_grp_inv);
1033  }
1034 
1035 
1036  // reminders
1037 
1038  // reminder - currently not available for 360°
1039  if(!$this->object->get360Mode())
1040  {
1041  $info = new ilFormSectionHeaderGUI();
1042  $info->setTitle($this->lng->txt("svy_settings_section_reminders"));
1043  $form->addItem($info);
1044 
1045  $rmd = new ilCheckboxInputGUI($this->lng->txt("survey_reminder_setting"), "rmd");
1046  $rmd->setChecked($this->object->getReminderStatus());
1047  $form->addItem($rmd);
1048 
1049  $rmd_start = new ilDateTimeInputGUI($this->lng->txt("survey_reminder_start"), "rmd_start");
1050  $rmd_start->setRequired(true);
1051  $start = $this->object->getReminderStart();
1052  if($start)
1053  {
1054  $rmd_start->setDate($start);
1055  }
1056  $rmd->addSubItem($rmd_start);
1057 
1058  $end = $this->object->getReminderEnd();
1059  $rmd_end = new ilDateTimeInputGUI($this->lng->txt("survey_reminder_end"), "rmd_end");
1060  $rmd_end->enableDateActivation("", "rmd_end_tgl", (bool)$end);
1061  if($end)
1062  {
1063  $rmd_end->setDate($end);
1064  }
1065  $rmd->addSubItem($rmd_end);
1066 
1067  $rmd_freq = new ilNumberInputGUI($this->lng->txt("survey_reminder_frequency"), "rmd_freq");
1068  $rmd_freq->setRequired(true);
1069  $rmd_freq->setSize(3);
1070  $rmd_freq->setSuffix($this->lng->txt("survey_reminder_frequency_days"));
1071  $rmd_freq->setValue($this->object->getReminderFrequency());
1072  $rmd_freq->setMinValue(1);
1073  $rmd->addSubItem($rmd_freq);
1074 
1075  $rmd_grp = new ilRadioGroupInputGUI($this->lng->txt("survey_notification_target_group"), "rmd_grp");
1076  $rmd_grp->setRequired(true);
1077  $rmd_grp->setValue($this->object->getReminderTarget());
1078  $rmd->addSubItem($rmd_grp);
1079 
1080  $rmd_grp_crs = new ilRadioOption($this->lng->txt("survey_notification_target_group_parent_course"),
1082  if(!$has_parent)
1083  {
1084  $rmd_grp_crs->setInfo($this->lng->txt("survey_notification_target_group_parent_course_inactive"));
1085  }
1086  $rmd_grp->addOption($rmd_grp_crs);
1087 
1088  $rmd_grp_inv = new ilRadioOption($this->lng->txt("survey_notification_target_group_invited"),
1090  $rmd_grp_inv->setInfo(sprintf($this->lng->txt("survey_notification_target_group_invited_info"), $num_inv));
1091  $rmd_grp->addOption($rmd_grp_inv);
1092  }
1093 
1094 
1095  // results
1096 
1098  $results->setTitle($this->lng->txt("results"));
1099  $form->addItem($results);
1100 
1101  // evaluation access
1102  if(!$this->object->get360Mode())
1103  {
1104  $evaluation_access = new ilRadioGroupInputGUI($this->lng->txt('evaluation_access'), "evaluation_access");
1105 
1106  $option = new ilCheckboxOption($this->lng->txt("evaluation_access_off"), ilObjSurvey::EVALUATION_ACCESS_OFF, '');
1107  $option->setInfo($this->lng->txt("svy_evaluation_access_off_info"));
1108  $evaluation_access->addOption($option);
1109 
1110  $option = new ilCheckboxOption($this->lng->txt("evaluation_access_all"), ilObjSurvey::EVALUATION_ACCESS_ALL, '');
1111  $option->setInfo($this->lng->txt("svy_evaluation_access_all_info"));
1112  $evaluation_access->addOption($option);
1113 
1114  $option = new ilCheckboxOption($this->lng->txt("evaluation_access_participants"), ilObjSurvey::EVALUATION_ACCESS_PARTICIPANTS, '');
1115  $option->setInfo($this->lng->txt("svy_evaluation_access_participants_info"));
1116  $evaluation_access->addOption($option);
1117 
1118  $evaluation_access->setValue($this->object->getEvaluationAccess());
1119  $form->addItem($evaluation_access);
1120 
1121 
1122  $anonymization_options = new ilRadioGroupInputGUI($this->lng->txt("survey_results_anonymization"), "anonymization_options");
1123 
1124  $option = new ilCheckboxOption($this->lng->txt("survey_results_personalized"), "statpers");
1125  $option->setInfo($this->lng->txt("survey_results_personalized_info"));
1126  $anonymization_options->addOption($option);
1127 
1128  $option = new ilCheckboxOption($this->lng->txt("survey_results_anonymized"), "statanon");
1129  $option->setInfo($this->lng->txt("survey_results_anonymized_info"));
1130  $anonymization_options->addOption($option);
1131  $anonymization_options->setValue($this->object->hasAnonymizedResults()
1132  ? "statanon"
1133  : "statpers");
1134  $form->addItem($anonymization_options);
1135 
1136  if ($this->object->_hasDatasets($this->object->getSurveyId()))
1137  {
1138  $anonymization_options->setDisabled(true);
1139  }
1140  }
1141  // 360°
1142  else
1143  {
1144  $ts_results = new ilRadioGroupInputGUI($this->lng->txt("survey_360_results"), "ts_res");
1145  $ts_results->setValue($this->object->get360Results());
1146 
1147  $option = new ilRadioOption($this->lng->txt("survey_360_results_none"), ilObjSurvey::RESULTS_360_NONE);
1148  $option->setInfo($this->lng->txt("survey_360_results_none_info"));
1149  $ts_results->addOption($option);
1150 
1151  $option = new ilRadioOption($this->lng->txt("survey_360_results_own"), ilObjSurvey::RESULTS_360_OWN);
1152  $option->setInfo($this->lng->txt("survey_360_results_own_info"));
1153  $ts_results->addOption($option);
1154 
1155  $option = new ilRadioOption($this->lng->txt("survey_360_results_all"), ilObjSurvey::RESULTS_360_ALL);
1156  $option->setInfo($this->lng->txt("survey_360_results_all_info"));
1157  $ts_results->addOption($option);
1158  $form->addItem($ts_results);
1159  }
1160 
1161 
1162  // competence service activation for 360 mode
1163 
1164  include_once("./Services/Skill/classes/class.ilSkillManagementSettings.php");
1165  $skmg_set = new ilSkillManagementSettings();
1166  if($this->object->get360Mode() && $skmg_set->isActivated())
1167  {
1168  $other = new ilFormSectionHeaderGUI();
1169  $other->setTitle($this->lng->txt("other"));
1170  $form->addItem($other);
1171 
1172  $skill_service = new ilCheckboxInputGUI($this->lng->txt("survey_activate_skill_service"), "skill_service");
1173  $skill_service->setInfo($this->lng->txt("survey_activate_skill_service_info"));
1174  $skill_service->setChecked($this->object->get360SkillService());
1175  $form->addItem($skill_service);
1176  }
1177 
1178 
1179  $form->addCommandButton("saveProperties", $this->lng->txt("save"));
1180 
1181  // remove items when using template
1182  if($template_settings)
1183  {
1184  foreach($template_settings as $id => $item)
1185  {
1186  if($item["hide"])
1187  {
1188  $form->removeItemByPostVar($id);
1189  }
1190  }
1191  }
1192 
1193  return $form;
1194  }
1195 
1201  function propertiesObject(ilPropertyFormGUI $a_form = null)
1202  {
1203  global $ilTabs, $ilHelp;
1204 
1205  $this->handleWriteAccess();
1206 
1207  $ilTabs->activateTab("settings");
1208 
1209 
1210  if ($this->object->get360Mode())
1211  {
1212  $ilHelp->setScreenId("settings_360");
1213  }
1214 
1215  if(!$a_form)
1216  {
1217  $a_form = $this->initPropertiesForm();
1218  }
1219 
1220  // using template?
1221  $message = "";
1222  if($this->object->getTemplate())
1223  {
1224  $link = $this->ctrl->getLinkTarget($this, "confirmResetTemplate");
1225  $link = "<a href=\"".$link."\">".$this->lng->txt("survey_using_template_link")."</a>";
1226  $message = "<div style=\"margin-top:10px\">".
1227  $this->tpl->getMessageHTML(sprintf($this->lng->txt("survey_using_template"),
1228  ilSettingsTemplate::lookupTitle($this->object->getTemplate()), $link), "info"). // #10651
1229  "</div>";
1230  }
1231 
1232  $this->tpl->setContent($a_form->getHTML().$message);
1233  }
1234 
1236  {
1237  $fields = array('login','firstname','lastname','email');
1238 
1239  include_once './Services/User/classes/class.ilUserAutoComplete.php';
1240  $auto = new ilUserAutoComplete();
1241  $auto->setSearchFields($fields);
1242  $auto->setResultField('login');
1243  $auto->enableFieldSearchableCheck(true);
1244  $auto->setMoreLinkAvailable(true);
1245 
1246  if(($_REQUEST['fetchall']))
1247  {
1248  $auto->setLimit(ilUserAutoComplete::MAX_ENTRIES);
1249  }
1250 
1251  echo $auto->getList(ilUtil::stripSlashes($_REQUEST['term']));
1252  exit();
1253  }
1254 
1259  {
1260  ilUtil::sendQuestion($this->lng->txt("survey_confirm_template_reset"));
1261  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_svy_confirm_resettemplate.html", "Modules/Survey");
1262  $this->tpl->setCurrentBlock("adm_content");
1263  $this->tpl->setVariable("BTN_CONFIRM_REMOVE", $this->lng->txt("confirm"));
1264  $this->tpl->setVariable("BTN_CANCEL_REMOVE", $this->lng->txt("cancel"));
1265  $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this, "resetTemplateObject"));
1266  $this->tpl->parseCurrentBlock();
1267  }
1268 
1273  {
1274  $this->object->setTemplate(null);
1275  $this->object->saveToDB();
1276 
1277  ilUtil::sendSuccess($this->lng->txt("survey_template_reset"), true);
1278  $this->ctrl->redirect($this, "properties");
1279  }
1280 
1281 
1282 
1283  //
1284  // IMPORT/EXPORT
1285  //
1286 
1287  protected function initImportForm($a_new_type)
1288  {
1289  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
1290  $form = new ilPropertyFormGUI();
1291  $form->setTarget("_top");
1292  $form->setFormAction($this->ctrl->getFormAction($this));
1293  $form->setTitle($this->lng->txt("import_svy"));
1294 
1295  include_once("./Services/Form/classes/class.ilFileInputGUI.php");
1296  $fi = new ilFileInputGUI($this->lng->txt("import_file"), "importfile");
1297  $fi->setSuffixes(array("zip"));
1298  $fi->setRequired(true);
1299  $form->addItem($fi);
1300 
1301  include_once("./Modules/Survey/classes/class.ilObjSurvey.php");
1302  $svy = new ilObjSurvey();
1303  $questionspools = $svy->getAvailableQuestionpools(true, true, true);
1304 
1305  $pools = new ilSelectInputGUI($this->lng->txt("select_questionpool_short"), "spl");
1306  $pools->setOptions(array(""=>$this->lng->txt("dont_use_questionpool")) + $questionspools);
1307  $pools->setRequired(false);
1308  $form->addItem($pools);
1309 
1310  $form->addCommandButton("importFile", $this->lng->txt("import"));
1311  $form->addCommandButton("cancel", $this->lng->txt("cancel"));
1312 
1313  return $form;
1314  }
1315 
1319  function importFileObject()
1320  {
1321  global $tpl, $ilErr;
1322 
1323  $parent_id = $_GET["ref_id"];
1324  $new_type = $_REQUEST["new_type"];
1325 
1326  // create permission is already checked in createObject. This check here is done to prevent hacking attempts
1327  if (!$this->checkPermissionBool("create", "", $new_type))
1328  {
1329  $ilErr->raiseError($this->lng->txt("no_create_permission"));
1330  }
1331 
1332  $this->lng->loadLanguageModule($new_type);
1333  $this->ctrl->setParameter($this, "new_type", $new_type);
1334 
1335  $form = $this->initImportForm($new_type);
1336  if ($form->checkInput())
1337  {
1338  include_once("./Modules/Survey/classes/class.ilObjSurvey.php");
1339  $newObj = new ilObjSurvey();
1340  $newObj->setType($new_type);
1341  $newObj->setTitle("dummy");
1342  $newObj->setDescription("dummy");
1343  $newObj->create(true);
1344  $this->putObjectInTree($newObj);
1345 
1346  // copy uploaded file to import directory
1347  $error = $newObj->importObject($_FILES["importfile"], $form->getInput("spl"));
1348  if (strlen($error))
1349  {
1350  $newObj->delete();
1351  $this->ilias->raiseError($error, $this->ilias->error_obj->MESSAGE);
1352  return;
1353  }
1354 
1355  ilUtil::sendSuccess($this->lng->txt("object_imported"),true);
1356  ilUtil::redirect("ilias.php?ref_id=".$newObj->getRefId().
1357  "&baseClass=ilObjSurveyGUI");
1358 
1359  // using template?
1360  include_once "Services/Administration/classes/class.ilSettingsTemplate.php";
1361  $templates = ilSettingsTemplate::getAllSettingsTemplates("svy");
1362  if($templates)
1363  {
1364  global $tpl;
1365  $tpl->addJavaScript("./Modules/Scorm2004/scripts/questions/jquery.js");
1366  // $tpl->addJavaScript("./Modules/Scorm2004/scripts/questions/jquery-ui-min.js");
1367 
1368  $this->tpl->setCurrentBlock("template_option");
1369  $this->tpl->setVariable("VAL_TEMPLATE_OPTION", "");
1370  $this->tpl->setVariable("TXT_TEMPLATE_OPTION", $this->lng->txt("none"));
1371  $this->tpl->parseCurrentBlock();
1372 
1373  foreach($templates as $item)
1374  {
1375  $this->tpl->setCurrentBlock("template_option");
1376  $this->tpl->setVariable("VAL_TEMPLATE_OPTION", $item["id"]);
1377  $this->tpl->setVariable("TXT_TEMPLATE_OPTION", $item["title"]);
1378  $this->tpl->parseCurrentBlock();
1379 
1380  $desc = str_replace("\n", "", nl2br($item["description"]));
1381  $desc = str_replace("\r", "", $desc);
1382 
1383  $this->tpl->setCurrentBlock("js_data");
1384  $this->tpl->setVariable("JS_DATA_ID", $item["id"]);
1385  $this->tpl->setVariable("JS_DATA_TEXT", $desc);
1386  $this->tpl->parseCurrentBlock();
1387  }
1388 
1389  $this->tpl->setCurrentBlock("templates");
1390  $this->tpl->setVariable("TXT_TEMPLATE", $this->lng->txt("svy_settings_template"));
1391  $this->tpl->parseCurrentBlock();
1392  }
1393  }
1394 
1395  // display form to correct errors
1396  $form->setValuesByPost();
1397  $tpl->setContent($form->getHtml());
1398  }
1399 
1400  /*
1401  * list all export files
1402  */
1403  public function exportObject()
1404  {
1405  global $ilTabs, $ilToolbar;
1406 
1407  $this->handleWriteAccess();
1408  $ilTabs->activateTab("export");
1409 
1410  include_once "Services/UIComponent/Button/classes/class.ilLinkButton.php";
1411  $button = ilLinkButton::getInstance();
1412  $button->setCaption("svy_create_export_file");
1413  $button->setUrl($this->ctrl->getLinkTarget($this, "createExportFile"));
1414  $ilToolbar->addButtonInstance($button);
1415 
1416  $export_dir = $this->object->getExportDirectory();
1417  $export_files = $this->object->getExportFiles($export_dir);
1418  $data = array();
1419  if(count($export_files) > 0)
1420  {
1421  foreach($export_files as $exp_file)
1422  {
1423  $file_arr = explode("__", $exp_file);
1424  $date = new ilDateTime($file_arr[0], IL_CAL_UNIX);
1425  array_push($data, array(
1426  'file' => $exp_file,
1427  'size' => filesize($export_dir."/".$exp_file),
1428  'date' => $date->get(IL_CAL_DATETIME)
1429  ));
1430  }
1431  }
1432 
1433  include_once "./Modules/Survey/classes/tables/class.ilSurveyExportTableGUI.php";
1434  $table_gui = new ilSurveyExportTableGUI($this, 'export');
1435  $table_gui->setData($data);
1436  $this->tpl->setVariable('ADM_CONTENT', $table_gui->getHTML());
1437  }
1438 
1442  public function createExportFileObject()
1443  {
1444  $this->handleWriteAccess();
1445  include_once("./Modules/Survey/classes/class.ilSurveyExport.php");
1446  $survey_exp = new ilSurveyExport($this->object);
1447  $survey_exp->buildExportFile();
1448  $this->ctrl->redirect($this, "export");
1449  }
1450 
1454  public function downloadExportFileObject()
1455  {
1456  if(!isset($_POST["file"]))
1457  {
1458  ilUtil::sendFailure($this->lng->txt("no_checkbox"), true);
1459  $this->ctrl->redirect($this, "export");
1460  }
1461 
1462  if (count($_POST["file"]) > 1)
1463  {
1464  ilUtil::sendFailure($this->lng->txt("select_max_one_item"), true);
1465  $this->ctrl->redirect($this, "export");
1466  }
1467 
1468  $file = basename($_POST["file"][0]);
1469 
1470  $export_dir = $this->object->getExportDirectory();
1471  include_once "./Services/Utilities/classes/class.ilUtil.php";
1472  ilUtil::deliverFile($export_dir."/".$file, $file);
1473  }
1474 
1479  {
1480  global $ilTabs;
1481 
1482  $this->handleWriteAccess();
1483  $ilTabs->activateTab("export");
1484 
1485  if (!isset($_POST["file"]))
1486  {
1487  ilUtil::sendFailure($this->lng->txt("no_checkbox"), true);
1488  $this->ctrl->redirect($this, "export");
1489  }
1490 
1491  ilUtil::sendQuestion($this->lng->txt("info_delete_sure"));
1492 
1493  $export_dir = $this->object->getExportDirectory();
1494  $export_files = $this->object->getExportFiles($export_dir);
1495  $data = array();
1496  if (count($_POST["file"]) > 0)
1497  {
1498  foreach ($_POST["file"] as $exp_file)
1499  {
1500  $file_arr = explode("__", $exp_file);
1501  $date = new ilDateTime($file_arr[0], IL_CAL_UNIX);
1502  array_push($data, array(
1503  'file' => $exp_file,
1504  'size' => filesize($export_dir."/".$exp_file),
1505  'date' => $date->get(IL_CAL_DATETIME)
1506  ));
1507  }
1508  }
1509 
1510  include_once "./Modules/Survey/classes/tables/class.ilSurveyExportTableGUI.php";
1511  $table_gui = new ilSurveyExportTableGUI($this, 'export', true);
1512  $table_gui->setData($data);
1513  $this->tpl->setVariable('ADM_CONTENT', $table_gui->getHTML());
1514  }
1515 
1516 
1521  {
1522  ilUtil::sendInfo($this->lng->txt('msg_cancel'), true);
1523  $this->ctrl->redirect($this, "export");
1524  }
1525 
1526 
1530  public function deleteExportFileObject()
1531  {
1532  $export_dir = $this->object->getExportDirectory();
1533  foreach ($_POST["file"] as $file)
1534  {
1535  $file = basename($file);
1536 
1537  $exp_file = $export_dir."/".$file;
1538  $exp_dir = $export_dir."/".substr($file, 0, strlen($file) - 4);
1539  if (@is_file($exp_file))
1540  {
1541  unlink($exp_file);
1542  }
1543  if (@is_dir($exp_dir))
1544  {
1545  include_once "./Services/Utilities/classes/class.ilUtil.php";
1546  ilUtil::delDir($exp_dir);
1547  }
1548  }
1549  ilUtil::sendSuccess($this->lng->txt('msg_deleted_export_files'), true);
1550  $this->ctrl->redirect($this, "export");
1551  }
1552 
1553 
1554  //
1555  // INFOSCREEN
1556  //
1557 
1563  function infoScreenObject()
1564  {
1565  $this->ctrl->setCmd("showSummary");
1566  $this->ctrl->setCmdClass("ilinfoscreengui");
1567  $this->infoScreen();
1568  }
1569 
1573  function infoScreen()
1574  {
1575  global $ilAccess, $ilTabs, $ilUser, $ilToolbar;
1576 
1577  if (!$this->external_rater_360 &&
1578  !$ilAccess->checkAccess("visible", "", $this->ref_id))
1579  {
1580  $this->ilias->raiseError($this->lng->txt("msg_no_perm_read"),$this->ilias->error_obj->MESSAGE);
1581  }
1582 
1583  $ilTabs->activateTab("info_short");
1584 
1585  include_once "./Modules/Survey/classes/class.ilSurveyExecutionGUI.php";
1586  $output_gui =& new ilSurveyExecutionGUI($this->object);
1587 
1588  include_once("./Services/InfoScreen/classes/class.ilInfoScreenGUI.php");
1589  $info = new ilInfoScreenGUI($this);
1590  $info->enablePrivateNotes();
1591 
1592  // "active" survey?
1593  $canStart = $this->object->canStartSurvey(null, $this->external_rater_360);
1594 
1595  $showButtons = $canStart["result"];
1596  if (!$showButtons)
1597  {
1598  if($canStart["edit_settings"] &&
1599  $ilAccess->checkAccess("write", "", $this->ref_id))
1600  {
1601  $canStart["messages"][] = "<a href=\"".$this->ctrl->getLinkTarget($this, "properties")."\">&raquo; ".
1602  $this->lng->txt("survey_edit_settings")."</a>";
1603  }
1604  ilUtil::sendInfo(implode("<br />", $canStart["messages"]));
1605  }
1606 
1607  $big_button = false;
1608  if ($showButtons)
1609  {
1610  // closing survey?
1611  $is_appraisee = false;
1612  if($this->object->get360Mode() &&
1613  $this->object->isAppraisee($ilUser->getId()))
1614  {
1615  $info->addSection($this->lng->txt("survey_360_appraisee_info"));
1616 
1617  $appr_data = $this->object->getAppraiseesData();
1618  $appr_data = $appr_data[$ilUser->getId()];
1619  $info->addProperty($this->lng->txt("survey_360_raters_status_info"), $appr_data["finished"]);
1620 
1621  if(!$appr_data["closed"])
1622  {
1623  include_once "Services/UIComponent/Button/classes/class.ilLinkButton.php";
1624  $button = ilLinkButton::getInstance();
1625  $button->setCaption("survey_360_appraisee_close_action");
1626  $button->setUrl($this->ctrl->getLinkTargetByClass("ilsurveyparticipantsgui", "confirmappraiseeclose"));
1627  $close_button_360 = '<div>'.$button->render().'</div>';
1628 
1629  $txt = "survey_360_appraisee_close_action_info";
1630  if($this->object->get360SkillService())
1631  {
1632  $txt .= "_skill";
1633  }
1634  $info->addProperty($this->lng->txt("status"),
1635  $close_button_360.$this->lng->txt($txt));
1636  }
1637  else
1638  {
1640 
1641  $dt = new ilDateTime($appr_data["closed"], IL_CAL_UNIX);
1642  $info->addProperty($this->lng->txt("status"),
1643  sprintf($this->lng->txt("survey_360_appraisee_close_action_status"),
1645  }
1646 
1647  $is_appraisee = true;
1648  }
1649 
1650 
1651  // handle code
1652 
1653  // validate incoming
1654  $code_input = false;
1655  $anonymous_code = $_POST["anonymous_id"];
1656  if ($anonymous_code)
1657  {
1658  $code_input = true;
1659  // if(!$this->object->isUnusedCode($anonymous_code, $ilUser->getId()))
1660  if(!$this->object->checkSurveyCode($anonymous_code)) // #15031 - valid as long survey is not finished
1661  {
1662  $anonymous_code = null;
1663  }
1664  else
1665  {
1666  // #15860
1667  $this->object->bindSurveyCodeToUser($ilUser->getId(), $anonymous_code);
1668  }
1669  }
1670  if ($anonymous_code)
1671  {
1672  $_SESSION["anonymous_id"][$this->object->getId()] = $anonymous_code;
1673  }
1674  else
1675  {
1676  $anonymous_code = $_SESSION["anonymous_id"][$this->object->getId()];
1677  if($anonymous_code)
1678  {
1679  $code_input = true;
1680  }
1681  }
1682 
1683  // try to find code for current (registered) user from existing run
1684  if($this->object->getAnonymize() && !$anonymous_code)
1685  {
1686  $anonymous_code = $this->object->findCodeForUser($ilUser->getId());
1687  }
1688 
1689  // get existing runs for current user, might generate code
1690  $participant_status = $this->object->getUserSurveyExecutionStatus($anonymous_code);
1691  if($participant_status)
1692  {
1693  $anonymous_code = $participant_status["code"];
1694  $participant_status = $participant_status["runs"];
1695  }
1696 
1697  // (final) check for proper anonymous code
1698  if(!$this->object->isAccessibleWithoutCode() &&
1699  !$is_appraisee &&
1700  $code_input && // #11346
1701  (!$anonymous_code || !$this->object->isAnonymousKey($anonymous_code)))
1702  {
1703  $anonymous_code = null;
1704  ilUtil::sendInfo($this->lng->txt("wrong_survey_code_used"));
1705  }
1706 
1707  // :TODO: really save in session?
1708  $_SESSION["anonymous_id"][$this->object->getId()] = $anonymous_code;
1709 
1710  // code is mandatory and not given yet
1711  if(!$is_appraisee &&
1712  !$anonymous_code &&
1713  !$this->object->isAccessibleWithoutCode())
1714  {
1715  $info->setFormAction($this->ctrl->getFormAction($this, "infoScreen"));
1716  $info->addSection($this->lng->txt("anonymization"));
1717  $info->addProperty("", $this->lng->txt("anonymize_anonymous_introduction"));
1718  $info->addPropertyTextinput($this->lng->txt("enter_anonymous_id"), "anonymous_id", "", 8, "infoScreen", $this->lng->txt("submit"), true);
1719  }
1720  else
1721  {
1722  // trunk/default
1723  if(!$this->object->get360Mode())
1724  {
1725  if($anonymous_code)
1726  {
1727  $info->addHiddenElement("anonymous_id", $anonymous_code);
1728  }
1729 
1730  $survey_started = $this->object->isSurveyStarted($ilUser->getId(), $anonymous_code);
1731  if ($survey_started === 1)
1732  {
1733  if($ilUser->getId() != ANONYMOUS_USER_ID)
1734  {
1735  if($this->object->hasViewOwnResults())
1736  {
1737  include_once "Services/UIComponent/Button/classes/class.ilLinkButton.php";
1738  $button = ilLinkButton::getInstance();
1739  $button->setCaption("svy_view_own_results");
1740  $button->setUrl($this->ctrl->getLinkTarget($this, "viewUserResults"));
1741  $ilToolbar->addButtonInstance($button);
1742  }
1743 
1744  if($this->object->hasMailOwnResults())
1745  {
1746  if($this->object->hasViewOwnResults())
1747  {
1748  $ilToolbar->addSeparator();
1749  }
1750 
1751  require_once "Services/Form/classes/class.ilTextInputGUI.php";
1752  $mail = new ilTextInputGUI($this->lng->txt("email"), "mail");
1753  $mail->setSize(25);
1754  $mail->setValue($ilUser->getEmail());
1755  $ilToolbar->addInputItem($mail, true);
1756 
1757  $ilToolbar->setFormAction($this->ctrl->getFormAction($this, "mailUserResults"));
1758 
1759  include_once "Services/UIComponent/Button/classes/class.ilSubmitButton.php";
1760  $button = ilSubmitButton::getInstance();
1761  $button->setCaption("svy_mail_own_results");
1762  $button->setCommand("mailUserResults");
1763  $ilToolbar->addButtonInstance($button);
1764  }
1765  }
1766 
1767  ilUtil::sendInfo($this->lng->txt("already_completed_survey"));
1768  }
1769  elseif ($survey_started === 0)
1770  {
1771  $big_button = array("resume", $this->lng->txt("resume_survey"));
1772  }
1773  elseif ($survey_started === FALSE)
1774  {
1775  $big_button = array("start", $this->lng->txt("start_survey"));
1776  }
1777  }
1778  // 360°
1779  else
1780  {
1781  $appr_ids = array();
1782 
1783  // use given code (if proper external one)
1784  if($anonymous_code)
1785  {
1786  $anonymous_id = $this->object->getAnonymousIdByCode($anonymous_code);
1787  if($anonymous_id)
1788  {
1789  $appr_ids = $this->object->getAppraiseesToRate(0, $anonymous_id);
1790  }
1791  }
1792 
1793  // registered user
1794  // if an auto-code was generated, we still have to check for the original user id
1795  if(!$appr_ids && $ilUser->getId() != ANONYMOUS_USER_ID)
1796  {
1797  $appr_ids = $this->object->getAppraiseesToRate($ilUser->getId());
1798  }
1799 
1800  if(sizeof($appr_ids))
1801  {
1802  // map existing runs to appraisees
1803  $active_appraisees = array();
1804  if($participant_status)
1805  {
1806  foreach($participant_status as $item)
1807  {
1808  $active_appraisees[$item["appr_id"]] = $item["finished"];
1809  }
1810  }
1811 
1812  $list = array();
1813 
1814  foreach($appr_ids as $appr_id)
1815  {
1816  if($this->object->isAppraiseeClosed($appr_id))
1817  {
1818  // closed
1819  $list[$appr_id] = $this->lng->txt("survey_360_appraisee_is_closed");
1820  }
1821  else if(array_key_exists($appr_id, $active_appraisees))
1822  {
1823  // already done
1824  if($active_appraisees[$appr_id])
1825  {
1826  $list[$appr_id] = $this->lng->txt("already_completed_survey");
1827  }
1828  // resume
1829  else
1830  {
1831  $list[$appr_id] = array("resume", $this->lng->txt("resume_survey"));
1832  }
1833  }
1834  else
1835  {
1836  // start
1837  $list[$appr_id] = array("start", $this->lng->txt("start_survey"));
1838  }
1839  }
1840 
1841  $info->addSection($this->lng->txt("survey_360_rate_other_appraisees"));
1842 
1843  include_once "Services/User/classes/class.ilUserUtil.php";
1844  foreach($list as $appr_id => $item)
1845  {
1846  $appr_name = ilUserUtil::getNamePresentation($appr_id, false, false, "", true);
1847 
1848  if(!is_array($item))
1849  {
1850  $info->addProperty($appr_name, $item);
1851  }
1852  else
1853  {
1854  $this->ctrl->setParameter($output_gui, "appr_id", $appr_id);
1855  $href = $this->ctrl->getLinkTarget($output_gui, $item[0]);
1856  $this->ctrl->setParameter($output_gui, "appr_id", "");
1857 
1858  include_once "Services/UIComponent/Button/classes/class.ilLinkButton.php";
1859  $button = ilLinkButton::getInstance();
1860  $button->setCaption($item[1], false);
1861  $button->setUrl($href);
1862  $big_button_360 = '<div>'.$button->render().'</div>';
1863 
1864  $info->addProperty($appr_name, $big_button_360);
1865  }
1866  }
1867  }
1868  else if(!$is_appraisee)
1869  {
1870  ilUtil::sendFailure($this->lng->txt("survey_360_no_appraisees"));
1871  }
1872  }
1873  }
1874 
1875  if($this->object->get360Mode() &&
1876  $this->object->get360SelfAppraisee() &&
1877  !$this->object->isAppraisee($ilUser->getId()) &&
1878  $ilUser->getId() != ANONYMOUS_USER_ID) // #14968
1879  {
1880  $link = $this->ctrl->getLinkTargetByClass("ilsurveyparticipantsgui", "addSelfAppraisee");
1881  $link = '<a href="'.$link.'">'.$this->lng->txt("survey_360_add_self_appraisee").'</a>';
1882  $info->addProperty("&nbsp;", $link);
1883  }
1884  }
1885 
1886  if($big_button)
1887  {
1888  $ilToolbar->setFormAction($this->ctrl->getFormAction($output_gui, "infoScreen"));
1889 
1890  include_once "Services/UIComponent/Button/classes/class.ilSubmitButton.php";
1891  $button = ilSubmitButton::getInstance();
1892  $button->setCaption($big_button[1], false);
1893  $button->setCommand($big_button[0]);
1894  $button->setPrimary(true);
1895  $ilToolbar->addButtonInstance($button);
1896 
1897  $ilToolbar->setCloseFormTag(false);
1898  $info->setOpenFormTag(false);
1899  }
1900  /* #12016
1901  else
1902  {
1903  $info->setFormAction($this->ctrl->getFormAction($output_gui, "infoScreen"));
1904  }
1905  */
1906 
1907  if (strlen($this->object->getIntroduction()))
1908  {
1909  $introduction = $this->object->getIntroduction();
1910  $info->addSection($this->lng->txt("introduction"));
1911  $info->addProperty("", $this->object->prepareTextareaOutput($introduction).
1912  "<br />".$info->getHiddenToggleButton());
1913  }
1914  else
1915  {
1916  $info->addSection("");
1917  $info->addProperty("", $info->getHiddenToggleButton());
1918  }
1919 
1920  $info->hideFurtherSections(false);
1921 
1922  if(!$this->object->get360Mode())
1923  {
1924  $info->addSection($this->lng->txt("svy_general_properties"));
1925 
1926  $info->addProperty($this->lng->txt("survey_results_anonymization"),
1927  !$this->object->hasAnonymizedResults()
1928  ? $this->lng->txt("survey_results_personalized_info")
1929  : $this->lng->txt("survey_results_anonymized_info"));
1930 
1931  include_once "./Modules/Survey/classes/class.ilObjSurveyAccess.php";
1932  if ($ilAccess->checkAccess("write", "", $this->ref_id) ||
1933  ilObjSurveyAccess::_hasEvaluationAccess($this->object->getId(), $ilUser->getId()))
1934  {
1935  $info->addProperty($this->lng->txt("evaluation_access"), $this->lng->txt("evaluation_access_info"));
1936  }
1937  }
1938 
1939  $info->addMetaDataSections($this->object->getId(),0, $this->object->getType());
1940 
1941  $this->ctrl->forwardCommand($info);
1942  }
1943 
1944  function addLocatorItems()
1945  {
1946  global $ilLocator;
1947  switch ($this->ctrl->getCmd())
1948  {
1949  case "next":
1950  case "previous":
1951  case "start":
1952  case "resume":
1953  case "redirectQuestion":
1954  $ilLocator->addItem($this->object->getTitle(), $this->ctrl->getLinkTarget($this, "infoScreen"), "", $_GET["ref_id"]);
1955  break;
1956  case "evaluation":
1957  case "checkEvaluationAccess":
1958  case "evaluationdetails":
1959  case "evaluationuser":
1960  $ilLocator->addItem($this->object->getTitle(), $this->ctrl->getLinkTargetByClass("ilsurveyevaluationgui", "evaluation"), "", $_GET["ref_id"]);
1961  break;
1962  case "create":
1963  case "save":
1964  case "cancel":
1965  case "importFile":
1966  case "cloneAll":
1967  break;
1968  case "infoScreen":
1969  $ilLocator->addItem($this->object->getTitle(), $this->ctrl->getLinkTarget($this, "infoScreen"), "", $_GET["ref_id"]);
1970  break;
1971  default:
1972  $ilLocator->addItem($this->object->getTitle(), $this->ctrl->getLinkTarget($this, ""), "", $_GET["ref_id"]);
1973 
1974  // this has to be done here because ilSurveyEditorGUI is called after finalizing the locator
1975  if ((int)$_GET["q_id"] && !(int)$_REQUEST["new_for_survey"])
1976  {
1977  // not on create
1978  // see ilObjSurveyQuestionPool::addLocatorItems
1979  $q_id = (int)$_GET["q_id"];
1980  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
1981  $q_type = SurveyQuestion::_getQuestionType($q_id)."GUI";
1982  $this->ctrl->setParameterByClass($q_type, "q_id", $q_id);
1983  $ilLocator->addItem(SurveyQuestion::_getTitle($q_id),
1984  $this->ctrl->getLinkTargetByClass(array("ilSurveyEditorGUI", $q_type), "editQuestion"));
1985  }
1986  break;
1987  }
1988  }
1989 
1990 
1991 
1997  public static function _goto($a_target, $a_access_code = "")
1998  {
1999  global $ilAccess, $ilErr, $lng;
2000 
2001  // see ilObjSurveyAccess::_checkGoto()
2002  include_once "./Services/Utilities/classes/class.ilUtil.php";
2003  if (strlen($a_access_code))
2004  {
2005  $_SESSION["anonymous_id"][ilObject::_lookupObjId($a_target)] = $a_access_code;
2006  $_GET["baseClass"] = "ilObjSurveyGUI";
2007  $_GET["cmd"] = "infoScreen";
2008  $_GET["ref_id"] = $a_target;
2009  include("ilias.php");
2010  exit;
2011  }
2012 
2013  if ($ilAccess->checkAccess("read", "", $a_target))
2014  {
2015  $_GET["baseClass"] = "ilObjSurveyGUI";
2016  $_GET["cmd"] = "infoScreen";
2017  $_GET["ref_id"] = $a_target;
2018  include("ilias.php");
2019  exit;
2020  }
2021  else if ($ilAccess->checkAccess("read", "", ROOT_FOLDER_ID))
2022  {
2023  ilUtil::sendFailure(sprintf($lng->txt("msg_no_perm_read_item"),
2024  ilObject::_lookupTitle(ilObject::_lookupObjId($a_target))), true);
2026  }
2027 
2028  $ilErr->raiseError($lng->txt("msg_no_perm_read_lm"), $ilErr->FATAL);
2029  }
2030 
2031  public function getUserResultsTable($a_active_id)
2032  {
2033  $rtpl = new ilTemplate("tpl.svy_view_user_results.html", true, true, "Modules/Survey");
2034 
2035  $show_titles = (bool)$this->object->getShowQuestionTitles();
2036 
2037  foreach($this->object->getSurveyPages() as $page)
2038  {
2039  if(count($page) > 0)
2040  {
2041  // question block
2042  if(count($page) > 1)
2043  {
2044  if((bool)$page[0]["questionblock_show_blocktitle"])
2045  {
2046  $rtpl->setVariable("BLOCK_TITLE", trim($page[0]["questionblock_title"]));
2047  }
2048  }
2049 
2050  // questions
2051  foreach($page as $question)
2052  {
2053  $question_gui = $this->object->getQuestionGUI($question["type_tag"], $question["question_id"]);
2054  if(is_object($question_gui))
2055  {
2056  $rtpl->setCurrentBlock("question_bl");
2057 
2058  // heading
2059  if(strlen($question["heading"]))
2060  {
2061  $rtpl->setVariable("HEADING", trim($question["heading"]));
2062  }
2063 
2064  $rtpl->setVariable("QUESTION_DATA",
2065  $question_gui->getPrintView(
2066  $show_titles,
2067  (bool)$question["questionblock_show_questiontext"],
2068  $this->object->getId(),
2069  $this->object->loadWorkingData($question["question_id"], $a_active_id)
2070  )
2071  );
2072 
2073  $rtpl->parseCurrentBlock();
2074  }
2075  }
2076 
2077  $rtpl->setCurrentBlock("block_bl");
2078  $rtpl->parseCurrentBlock();
2079  }
2080  }
2081 
2082  return $rtpl->get();
2083  }
2084 
2085  protected function viewUserResultsObject()
2086  {
2087  global $ilUser, $tpl, $ilTabs;
2088 
2089  $anonymous_code = $_SESSION["anonymous_id"][$this->object->getId()];
2090  $active_id = $this->object->getActiveID($ilUser->getId(), $anonymous_code, 0);
2091  if($this->object->isSurveyStarted($ilUser->getId(), $anonymous_code) !== 1 ||
2092  !$active_id)
2093  {
2094  $this->ctrl->redirect($this, "infoScreen");
2095  }
2096 
2097  $ilTabs->clearTargets();
2098  $ilTabs->setBackTarget($this->lng->txt("btn_back"),
2099  $this->ctrl->getLinkTarget($this, "infoScreen"));
2100 
2101  $html = $this->getUserResultsTable($active_id);
2102  $tpl->setContent($html);
2103  }
2104 
2105  protected function getUserResultsPlain($a_active_id)
2106  {
2107  $res = array();
2108 
2109  $show_titles = (bool)$this->object->getShowQuestionTitles();
2110 
2111  foreach($this->object->getSurveyPages() as $page)
2112  {
2113  if(count($page) > 0)
2114  {
2115  $res[] = "\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
2116 
2117  // question block
2118  if(count($page) > 1)
2119  {
2120  if((bool)$page[0]["questionblock_show_blocktitle"])
2121  {
2122  $res[$this->lng->txt("questionblock")] = trim($page[0]["questionblock_title"])."\n";
2123  }
2124  }
2125 
2126  // questions
2127 
2128  $page_res = array();
2129 
2130  foreach($page as $question)
2131  {
2132  $question_gui = $this->object->getQuestionGUI($question["type_tag"], $question["question_id"]);
2133  if(is_object($question_gui))
2134  {
2135  $question_parts = array();
2136 
2137  // heading
2138  if(strlen($question["heading"]))
2139  {
2140  $question_parts[$this->lng->txt("heading")] = trim($question["heading"]);
2141  }
2142 
2143  if($show_titles)
2144  {
2145  $question_parts[$this->lng->txt("title")] = trim($question["title"]);
2146  }
2147 
2148  if((bool)$question["questionblock_show_questiontext"])
2149  {
2150  $question_parts[$this->lng->txt("question")] = trim(strip_tags($question_gui->object->getQuestionText()));
2151  }
2152 
2153  $answers = $question_gui->getParsedAnswers(
2154  $this->object->loadWorkingData($question["question_id"], $a_active_id),
2155  true
2156  );
2157 
2158  if(sizeof($answers))
2159  {
2160  $multiline = false;
2161  if(sizeof($answers) > 1 ||
2162  get_class($question_gui) == "SurveyTextQuestionGUI")
2163  {
2164  $multiline = true;
2165  }
2166 
2167  $parts = array();
2168  foreach($answers as $answer)
2169  {
2170  $text = null;
2171  if($answer["textanswer"])
2172  {
2173  $text = ' ("'.$answer["textanswer"].'")';
2174  }
2175  if(!isset($answer["cols"]))
2176  {
2177  if(isset($answer["title"]))
2178  {
2179  $parts[] = $answer["title"].$text;
2180  }
2181  else if(isset($answer["value"]))
2182  {
2183  $parts[] = $answer["value"];
2184  }
2185  else if($text)
2186  {
2187  $parts[] = substr($text, 2, -1);
2188  }
2189  }
2190  // matrix
2191  else
2192  {
2193  $tmp = array();
2194  foreach($answer["cols"] as $col)
2195  {
2196  $tmp[] = $col["title"];
2197  }
2198  $parts[] = $answer["title"].": ".implode(", ", $tmp).$text;
2199  }
2200 
2201  }
2202  $question_parts[$this->lng->txt("answer")] =
2203  ($multiline ? "\n" : "").implode("\n", $parts);
2204  }
2205 
2206  $tmp = array();
2207  foreach($question_parts as $type => $value)
2208  {
2209  $tmp[] = $type.": ".$value;
2210  }
2211  $page_res[] = implode("\n", $tmp);
2212  }
2213  }
2214 
2215  $res[] = implode("\n\n-------------------------------\n\n", $page_res);
2216  }
2217  }
2218 
2219  $res[] = "\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
2220 
2221  return implode("\n", $res);
2222  }
2223 
2224  public function sendUserResultsMail($a_active_id, $a_recipient)
2225  {
2226  global $ilUser;
2227 
2228  $finished = $this->object->getSurveyParticipants(array($a_active_id));
2229  $finished = array_pop($finished);
2230  $finished = ilDatePresentation::formatDate(new ilDateTime($finished["finished_tstamp"], IL_CAL_UNIX));
2231 
2232  require_once "Services/Mail/classes/class.ilMail.php";
2233  require_once "Services/Link/classes/class.ilLink.php";
2234 
2235  $body = ilMail::getSalutation($ilUser->getId())."\n\n";
2236  $body .= $this->lng->txt("svy_mail_own_results_body")."\n";
2237  $body .= "\n".$this->lng->txt("obj_svy").": ".$this->object->getTitle()."\n";
2238  $body .= ilLink::_getLink($this->object->getRefId(), "svy")."\n";
2239  $body .= "\n".$this->lng->txt("survey_results_finished").": ".$finished."\n\n";
2240 
2241  $body .= $this->getUserResultsPlain($a_active_id);
2242 
2243  // $body .= ilMail::_getAutoGeneratedMessageString($this->lng);
2245 
2246  require_once "Services/Mail/classes/class.ilMail.php";
2247  $mail = new ilMail(ANONYMOUS_USER_ID);
2248  $mail->sendMimeMail(
2249  $a_recipient,
2250  null,
2251  null,
2252  sprintf($this->lng->txt("svy_mail_own_results_subject"), $this->object->getTitle()),
2253  $body,
2254  null,
2255  true
2256  );
2257  }
2258 
2260  {
2261  global $ilUser;
2262 
2263  $anonymous_code = $_SESSION["anonymous_id"][$this->object->getId()];
2264  $active_id = $this->object->getActiveID($ilUser->getId(), $anonymous_code, 0);
2265  if($this->object->isSurveyStarted($ilUser->getId(), $anonymous_code) !== 1 ||
2266  !$active_id)
2267  {
2268  $this->ctrl->redirect($this, "infoScreen");
2269  }
2270 
2271  $recipient = $_POST["mail"];
2272  if(!ilUtil::is_email($recipient))
2273  {
2274  $this->ctrl->redirect($this, "infoScreen");
2275  }
2276 
2277  $this->sendUserResultsMail($active_id, $recipient);
2278 
2279  ilUtil::sendSuccess($this->lng->txt("mail_sent"), true);
2280  $this->ctrl->redirect($this, "infoScreen");
2281  }
2282 }
2283 
2284 ?>