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