ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilSurveyParticipantsGUI.php
Go to the documentation of this file.
1 <?php
2 
20 
27 {
28  protected \ILIAS\Survey\Mode\FeatureConfig $feature_config;
29  protected \ILIAS\Survey\Editing\EditingGUIRequest $edit_request;
30  protected \ILIAS\Survey\Editing\EditManager $edit_manager;
31  protected ilCtrl $ctrl;
32  protected ilLanguage $lng;
34  protected ilTabsGUI $tabs;
38  protected ilObjUser $user;
39  protected ilLogger $log;
41  protected ilObjSurvey $object;
42  protected int $ref_id;
43  protected bool $has_write;
44  protected Participants\InvitationsManager $invitation_manager;
45  protected \ILIAS\Survey\InternalService $survey_service;
46  protected \ILIAS\Survey\Code\CodeManager $code_manager;
47  protected \ILIAS\Survey\InternalDataService $data_manager;
48 
49  public function __construct(
50  ilObjSurveyGUI $a_parent_gui,
51  bool $a_has_write_access
52  ) {
53  global $DIC;
54 
55  $this->survey_service = $DIC->survey()->internal();
56 
57  $this->tabs = $DIC->tabs();
58  $this->toolbar = $DIC->toolbar();
59  $this->access = $DIC->access();
60  $this->rbacsystem = $DIC->rbac()->system();
61  $this->user = $DIC->user();
62  $this->log = $DIC["ilLog"];
63  $ilCtrl = $DIC->ctrl();
64  $lng = $DIC->language();
65  $tpl = $DIC["tpl"];
66 
67  $this->parent_gui = $a_parent_gui;
69  $survey = $this->parent_gui->getObject();
70  $this->object = $survey;
71  $this->ref_id = $this->object->getRefId();
72  $this->has_write = $a_has_write_access;
73 
74  $this->ctrl = $ilCtrl;
75  $this->lng = $lng;
76  $this->tpl = $tpl;
77  $this->invitation_manager = $this
78  ->survey_service
79  ->domain()
80  ->participants()
81  ->invitations();
82  $this->code_manager = $this
83  ->survey_service
84  ->domain()
85  ->code($this->object, $this->user->getId());
86  $this->data_manager = $this
87  ->survey_service
88  ->data();
89  $this->feature_config = $this
90  ->survey_service
91  ->domain()->modeFeatureConfig($this->object->getMode());
92  $this->edit_manager = $this->survey_service
93  ->domain()
94  ->edit();
95  $this->edit_request = $this->survey_service
96  ->gui()
97  ->editing()
98  ->request();
99  }
100 
101  public function getObject(): ilObjSurvey
102  {
103  return $this->object;
104  }
105 
106  protected function handleWriteAccess(): void
107  {
108  if (!$this->has_write) {
109  throw new ilSurveyException("Permission denied");
110  }
111  }
112 
113  public function executeCommand(): void
114  {
115  $ilCtrl = $this->ctrl;
116  $ilTabs = $this->tabs;
117  $lng = $this->lng;
118 
119  $cmd = $ilCtrl->getCmd("maintenance");
120  $next_class = $this->ctrl->getNextClass($this);
121 
122  switch ($next_class) {
123  case 'ilrepositorysearchgui':
124  $rep_search = new ilRepositorySearchGUI();
125 
126  if (!$this->edit_request->getAppr360() && !$this->edit_request->getRate360()) {
127  $ilTabs->clearTargets();
128  $ilTabs->setBackTarget(
129  $this->lng->txt("btn_back"),
130  $this->ctrl->getLinkTarget($this, "maintenance")
131  );
132 
133  $rep_search->setCallback(
134  $this,
135  'inviteUsers',
136  array(
137  )
138  );
139  $rep_search->setTitle($lng->txt("svy_invite_participants"));
140  // Set tabs
141  $this->ctrl->setReturn($this, 'maintenance');
142  $this->ctrl->forwardCommand($rep_search);
143  $ilTabs->setTabActive('maintenance');
144  } elseif ($this->edit_request->getRate360()) {
145  $ilTabs->clearTargets();
146  $ilTabs->setBackTarget(
147  $this->lng->txt("btn_back"),
148  $this->ctrl->getLinkTarget($this, "listAppraisees")
149  );
150 
151  $this->ctrl->setParameter($this, "rate360", 1);
152  $this->ctrl->saveParameter($this, "appr_id");
153 
154  $rep_search->setCallback(
155  $this,
156  'addRater',
157  array(
158  )
159  );
160 
161  // Set tabs
162  $this->ctrl->setReturn($this, 'editRaters');
163  $this->ctrl->forwardCommand($rep_search);
164  } else {
165  $ilTabs->activateTab("survey_360_appraisees");
166  $this->ctrl->setParameter($this, "appr360", 1);
167 
168  $rep_search->setCallback(
169  $this,
170  'addAppraisee',
171  array(
172  )
173  );
174 
175  // Set tabs
176  $this->ctrl->setReturn($this, 'listAppraisees');
177  $this->ctrl->forwardCommand($rep_search);
178  }
179  break;
180 
181  case 'ilsurveyratergui':
182  $ilTabs->activateTab("survey_360_edit_raters");
183  $rater_gui = new ilSurveyRaterGUI($this, $this->object);
184  $this->ctrl->forwardCommand($rater_gui);
185  break;
186 
187  default:
188  $cmd .= "Object";
189  $this->$cmd();
190  break;
191  }
192  }
193 
195  array $a_finished_ids = null
196  ): array {
197  $all_participants = $this->object->getSurveyParticipants($a_finished_ids, false, true);
198  $participant_ids = [];
199  foreach ($all_participants as $participant) {
200  if (isset($participant['usr_id'])) {
201  $participant_ids[] = $participant['usr_id'];
202  }
203  }
204 
205  $filtered_participant_ids = $this->access->filterUserIdsByRbacOrPositionOfCurrentUser(
206  'read_results',
207  'access_results',
208  $this->object->getRefId(),
209  $participant_ids
210  );
211 
212  $participants = [];
213  foreach ($all_participants as $username => $user_data) {
214  if (!($user_data['usr_id'] ?? false)) {
215  $participants[$username] = $user_data;
216  }
217  if (in_array(($user_data['usr_id'] ?? -1), $filtered_participant_ids)) {
218  $participants[$username] = $user_data;
219  }
220  }
221 
222  return $participants;
223  }
224 
225 
229  public function maintenanceObject(): void
230  {
231  $ilToolbar = $this->toolbar;
232 
233  if ($this->object->get360Mode()) {
234  $this->listAppraiseesObject();
235  return;
236  }
237 
238  //Btn Determine Competence Levels
239  if ($this->object->getMode() === ilObjSurvey::MODE_SELF_EVAL) {
240  $skmg_set = new ilSkillManagementSettings();
241  if ($this->object->getSkillService() && $skmg_set->isActivated()) {
242  $ilToolbar->addButton(
243  $this->lng->txt("survey_calc_skills"),
244  $this->ctrl->getLinkTargetByClass("ilsurveyskilldeterminationgui"),
245  ""
246  );
247  }
248  }
249 
250  $this->handleWriteAccess();
251  $this->setParticipantSubTabs("overview");
252 
253  $ilToolbar->addButton(
254  $this->lng->txt('svy_remove_all_participants'),
255  $this->ctrl->getLinkTarget($this, 'deleteAllUserData')
256  );
257 
258  $ilToolbar->addSeparator();
259 
260  if ($this->object->isAccessibleWithoutCode()) {
261  $ilToolbar->addButton(
262  $this->lng->txt("svy_invite_participants"),
263  $this->ctrl->getLinkTargetByClass('ilRepositorySearchGUI', '')
264  );
265  }
266 
267  $table_gui = new ilSurveyMaintenanceTableGUI($this, 'maintenance');
268 
269  $total = $this->filterSurveyParticipantsByAccess();
270  $data = array();
271  foreach ($total as $user_data) {
272  $finished = false;
273  if ($user_data["finished"]) {
274  $finished = $user_data["finished_tstamp"];
275  }
276  if (isset($user_data["active_id"])) {
277  $wt = $this->object->getWorkingtimeForParticipant($user_data["active_id"]);
278  $last_access = $this->object->getLastAccess($user_data["active_id"]);
279  $active_id = $user_data["active_id"];
280  } else {
281  $wt = 0;
282  $last_access = null;
283  $active_id = 0;
284  }
285  $data[] = array(
286  'id' => $active_id,
287  'name' => $user_data["sortname"],
288  'usr_id' => $user_data["usr_id"] ?? null,
289  'login' => $user_data["login"],
290  'last_access' => $last_access,
291  'workingtime' => $wt,
292  'finished' => $finished,
293  'invited' => $user_data["invited"] ?? false
294  );
295  }
296  $table_gui->setData($data);
297  $this->tpl->setVariable('ADM_CONTENT', $table_gui->getHTML());
298  }
299 
300  protected function isAnonymousListActive(): bool
301  {
302  $surveySetting = new ilSetting("survey");
303 
304  if ($surveySetting->get("anonymous_participants", false) && $this->object->hasAnonymizedResults() &&
305  $this->object->hasAnonymousUserList()) {
306  $end = $this->object->getEndDate();
307  if ($end && $end < date("YmdHis")) {
308  $min = (int) $surveySetting->get("anonymous_participants_min", '0');
309  $total = $this->object->getSurveyParticipants();
310  if (!$min || count($total) >= $min) {
311  return true;
312  }
313  }
314  }
315  return false;
316  }
317 
318  protected function setParticipantSubTabs(
319  string $active
320  ): void {
321  $ilTabs = $this->tabs;
322 
323  // not used in 360° mode
324 
325  // overview
326  $ilTabs->addSubTab(
327  "overview",
328  $this->lng->txt("svy_part_overview"),
329  $this->ctrl->getLinkTarget($this, 'maintenance')
330  );
331 
332  if ($this->isAnonymousListActive()) {
333  $ilTabs->addSubTab(
334  "anon_participants",
335  $this->lng->txt("svy_anonymous_participants_svy"),
336  $this->ctrl->getLinkTarget($this, 'listParticipants')
337  );
338  }
339 
340  if (!$this->object->isAccessibleWithoutCode()) {
341  $ilTabs->addSubTab(
342  "codes",
343  $this->lng->txt("svy_codes"),
344  $this->ctrl->getLinkTarget($this, 'codes')
345  );
346  }
347 
348 
349  $data = $this->object->getExternalCodeRecipients();
350  if (count($data)) {
351  $ilTabs->addSubTab(
352  "mail_survey_codes",
353  $this->lng->txt("mail_survey_codes"),
354  $this->ctrl->getLinkTarget($this, "mailCodes")
355  );
356  }
357 
358  $ilTabs->activateSubTab($active);
359  }
360 
361 
365  public function deleteAllUserDataObject(): void
366  {
367  $cgui = new ilConfirmationGUI();
368  $cgui->setHeaderText($this->lng->txt("confirm_delete_all_user_data"));
369  $cgui->setFormAction($this->ctrl->getFormAction($this, "deleteAllUserData"));
370  $cgui->setCancel($this->lng->txt("cancel"), "cancelDeleteAllUserData");
371  $cgui->setConfirm($this->lng->txt("confirm"), "confirmDeleteAllUserData");
372  $this->tpl->setContent($cgui->getHTML());
373  }
374 
378  public function confirmDeleteAllUserDataObject(): void
379  {
380  if ($this->access->checkAccess('write', '', $this->object->getRefId())) {
381  $this->object->deleteAllUserData();
382  } else {
383  $participants = $this->filterSurveyParticipantsByAccess();
384  foreach ($participants as $something => $participant_data) {
385  $this->object->removeSelectedSurveyResults([$participant_data['active_id']]);
386  }
387  }
388 
389  // #11558 - re-open closed appraisees
390  if ($this->object->get360Mode()) {
391  $this->object->openAllAppraisees();
392  }
393 
394  $this->tpl->setOnScreenMessage('success', $this->lng->txt("svy_all_user_data_deleted"), true);
395  $this->ctrl->redirect($this, "maintenance");
396  }
397 
401  public function cancelDeleteAllUserDataObject(): void
402  {
403  $this->ctrl->redirect($this, "maintenance");
404  }
405 
409  public function confirmDeleteSelectedUserDataObject(): void
410  {
411  $user_ids = $this->edit_request->getUserIds();
412  if (count($user_ids) > 0) {
413  $this->object->removeSelectedSurveyResults(array_filter($user_ids, static function ($i): bool {
414  return is_numeric($i);
415  }));
416 
417  $invitations = array_filter($user_ids, static function ($i): bool {
418  return strpos($i, "inv") === 0;
419  });
420  foreach ($invitations as $i) {
421  $this->invitation_manager->remove($this->object->getSurveyId(), (int) substr($i, 3));
422  }
423 
424  $this->tpl->setOnScreenMessage('success', $this->lng->txt("svy_selected_user_data_deleted"), true);
425  }
426  $this->ctrl->redirect($this, "maintenance");
427  }
428 
432  public function cancelDeleteSelectedUserDataObject(): void
433  {
434  $this->tpl->setOnScreenMessage('info', $this->lng->txt('msg_cancel'), true);
435  $this->ctrl->redirect($this, "maintenance");
436  }
437 
441  public function deleteSingleUserResultsObject(): void
442  {
443  $this->handleWriteAccess();
444 
445  $user_ids = $this->edit_request->getUserIds();
446  if (count($user_ids) === 0) {
447  $this->tpl->setOnScreenMessage('info', $this->lng->txt('no_checkbox'), true);
448  $this->ctrl->redirect($this, "maintenance");
449  }
450 
451  $this->tpl->setOnScreenMessage('question', $this->lng->txt("confirm_delete_single_user_data"));
452  $table_gui = new ilSurveyMaintenanceTableGUI($this, 'maintenance', true);
453  $total = $this->object->getSurveyParticipants(null, false, true);
454  $data = array();
455  foreach ($total as $user_data) {
456  if (in_array(($user_data['active_id'] ?? null), $user_ids)
457  || (($user_data['invited'] ?? false) && in_array("inv" . $user_data['usr_id'], $user_ids))) {
458  $last_access = $this->object->getLastAccess($user_data["active_id"] ?? 0);
459  $data[] = array(
460  'id' => $user_data["active_id"] ?? null,
461  'name' => $user_data["sortname"],
462  'login' => $user_data["login"] ?? null,
463  'last_access' => $last_access,
464  'finished' => $user_data["finished_tstamp"] ?? 0,
465  'usr_id' => $user_data["usr_id"] ?? null,
466  'invited' => $user_data["invited"] ?? null
467  );
468  }
469  }
470  $table_gui->setData($data);
471  $this->tpl->setVariable('ADM_CONTENT', $table_gui->getHTML());
472  }
473 
477  public function setCodeLanguageObject(): void
478  {
479  if (strcmp($this->edit_request->getLang(), "-1") !== 0) {
481  $ilUser->writePref("survey_code_language", $this->edit_request->getLang());
482  }
483  $this->tpl->setOnScreenMessage('success', $this->lng->txt('language_changed'), true);
484  $this->ctrl->redirect($this, 'codes');
485  }
486 
490  public function codesObject(): void
491  {
493  $ilToolbar = $this->toolbar;
494 
495  $this->handleWriteAccess();
496  $this->setParticipantSubTabs("codes");
497 
498  if ($this->object->isAccessibleWithoutCode()) {
499  $this->tpl->setOnScreenMessage('info', $this->lng->txt("survey_codes_no_anonymization"));
500  return;
501  }
502 
503  $default_lang = $ilUser->getPref("survey_code_language");
504 
505  // creation buttons
506  $ilToolbar->setFormAction($this->ctrl->getFormAction($this));
507 
508  $si = new ilTextInputGUI($this->lng->txt("new_survey_codes"), "nrOfCodes");
509  $si->setValue(1);
510  $si->setSize(3);
511  $ilToolbar->addInputItem($si, true);
512 
513  $button = ilSubmitButton::getInstance();
514  $button->setCaption("create");
515  $button->setCommand("createSurveyCodes");
516  $ilToolbar->addButtonInstance($button);
517 
518  $ilToolbar->addSeparator();
519 
520  $button = ilSubmitButton::getInstance();
521  $button->setCaption("import_from_file");
522  $button->setCommand("importExternalMailRecipientsFromFileForm");
523  $ilToolbar->addButtonInstance($button);
524 
525  $button = ilSubmitButton::getInstance();
526  $button->setCaption("import_from_text");
527  $button->setCommand("importExternalMailRecipientsFromTextForm");
528  $ilToolbar->addButtonInstance($button);
529 
530  $ilToolbar->addSeparator();
531 
532  $button = ilSubmitButton::getInstance();
533  $button->setCaption("svy_import_codes");
534  $button->setCommand("importAccessCodes");
535  $ilToolbar->addButtonInstance($button);
536 
537  $ilToolbar->addSeparator();
538 
539  $languages = $this->lng->getInstalledLanguages();
540  $options = array();
541  $this->lng->loadLanguageModule("meta");
542  foreach ($languages as $lang) {
543  $options[$lang] = $this->lng->txt("meta_l_" . $lang);
544  }
545  $si = new ilSelectInputGUI($this->lng->txt("survey_codes_lang"), "lang");
546  $si->setOptions($options);
547  $si->setValue($default_lang);
548  $ilToolbar->addInputItem($si, true);
549 
550  $button = ilSubmitButton::getInstance();
551  $button->setCaption("set");
552  $button->setCommand("setCodeLanguage");
553  $ilToolbar->addButtonInstance($button);
554 
555  $table_gui = new ilSurveyCodesTableGUI($this, 'codes');
556  $survey_codes = $this->object->getSurveyCodesTableData(null, $default_lang);
557  $table_gui->setData($survey_codes);
558  $this->tpl->setContent($table_gui->getHTML());
559  }
560 
561  public function editCodesObject(): void
562  {
563  $ids = $this->edit_request->getCodeIds();
564  if (count($ids) === 0) {
565  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('no_checkbox'), true);
566  $this->ctrl->redirect($this, 'codes');
567  }
568 
569  $this->handleWriteAccess();
570  $this->setParticipantSubTabs("codes");
571 
572  $table_gui = new ilSurveyCodesEditTableGUI($this, 'editCodes');
573  $table_gui->setData($this->object->getSurveyCodesTableData($ids));
574  $this->tpl->setContent($table_gui->getHTML());
575  }
576 
577  public function updateCodesObject(): void
578  {
579  $codes = $this->edit_request->getCodes();
580  $mails = $this->edit_request->getCodesPar("mail");
581  $lnames = $this->edit_request->getCodesPar("lname");
582  $fnames = $this->edit_request->getCodesPar("fname");
583  $sents = $this->edit_request->getCodesPar("sent");
584  if (count($codes) === 0) {
585  $this->ctrl->redirect($this, 'codes');
586  }
587 
588  $errors = array();
589  $error_message = "";
590  foreach ($codes as $id) {
591  if (!$this->object->updateCode(
592  $id,
593  $mails[$id] ?? "",
594  $lnames[$id] ?? "",
595  $fnames[$id] ?? "",
596  $sents[$id] ?? 0
597  )) {
598  $errors[] = array($mails[$id], $lnames[$id], $fnames[$id]);
599  }
600  }
601  if (empty($errors)) {
602  $this->tpl->setOnScreenMessage('success', $this->lng->txt('settings_saved'), true);
603  } else {
604  foreach ($errors as $error) {
605  $error_message .= sprintf($this->lng->txt("error_save_code"), $error[0], $error[1], $error[2]);
606  }
607  $this->tpl->setOnScreenMessage('failure', $error_message, true);
608  }
609 
610  $this->ctrl->redirect($this, 'codes');
611  }
612 
613  public function deleteCodesConfirmObject(): void
614  {
615  $codes = $this->edit_request->getCodes();
616 
617  $data = $this->object->getSurveyCodesTableData($codes);
618  $data = array_filter($data, static function ($item): bool {
619  return !$item["used"];
620  });
621  if (count($data) > 0) {
622  $cgui = new ilConfirmationGUI();
623  $cgui->setHeaderText($this->lng->txt("survey_code_delete_sure"));
624 
625  $cgui->setFormAction($this->ctrl->getFormAction($this));
626  $cgui->setCancel($this->lng->txt("cancel"), "codes");
627  $cgui->setConfirm($this->lng->txt("confirm"), "deleteCodes");
628 
629  foreach ($data as $item) {
630  $title = array($item["code"]);
631  $title[] = $item["email"] ?? "";
632  $title[] = $item["last_name"] ?? "";
633  $title[] = $item["first_name"] ?? "";
634  $title = implode(", ", $title);
635 
636  $cgui->addItem("chb_code[]", $item["code"], $title);
637  }
638 
639  $this->tpl->setContent($cgui->getHTML());
640  } else {
641  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('svy_please_select_unused_codes'), true);
642  $this->ctrl->redirect($this, 'codes');
643  }
644  }
645 
649  public function deleteCodesObject(): void
650  {
651  $codes = $this->edit_request->getCodes();
652  if (count($codes) > 0) {
653  foreach ($codes as $survey_code) {
654  $this->object->deleteSurveyCode($survey_code);
655  }
656  $this->tpl->setOnScreenMessage('success', $this->lng->txt('codes_deleted'), true);
657  } else {
658  $this->tpl->setOnScreenMessage('info', $this->lng->txt('no_checkbox'), true);
659  }
660  $this->ctrl->redirect($this, 'codes');
661  }
662 
666  public function exportCodesObject(): void
667  {
668  $codes = $this->edit_request->getCodes();
669  if (count($codes) > 0) {
670  $export = $this->object->getSurveyCodesForExport(null, $codes);
671  ilUtil::deliverData($export, ilFileUtils::getASCIIFilename($this->object->getTitle() . ".csv"));
672  } else {
673  $this->tpl->setOnScreenMessage('failure', $this->lng->txt("no_checkbox"), true);
674  $this->ctrl->redirect($this, 'codes');
675  }
676  }
677 
681  public function exportAllCodesObject(): void
682  {
683  $export = $this->object->getSurveyCodesForExport();
684  ilUtil::deliverData($export, ilFileUtils::getASCIIFilename($this->object->getTitle() . ".csv"));
685  }
686 
690  protected function importAccessCodesObject(): void
691  {
692  $this->handleWriteAccess();
693  $this->setParticipantSubTabs("codes");
694 
695  $form_import_file = new ilPropertyFormGUI();
696  $form_import_file->setFormAction($this->ctrl->getFormAction($this));
697  $form_import_file->setTableWidth("100%");
698  $form_import_file->setId("codes_import_file");
699 
700  $headerfile = new ilFormSectionHeaderGUI();
701  $headerfile->setTitle($this->lng->txt("svy_import_codes"));
702  $form_import_file->addItem($headerfile);
703 
704  $export_file = new ilFileInputGUI($this->lng->txt("codes"), "codes");
705  $export_file->setInfo(sprintf(
706  $this->lng->txt('svy_import_codes_info'),
707  $this->lng->txt("export_all_survey_codes")
708  ));
709  $export_file->setSuffixes(array("csv"));
710  $export_file->setRequired(true);
711  $form_import_file->addItem($export_file);
712 
713  $form_import_file->addCommandButton("importAccessCodesAction", $this->lng->txt("import"));
714  $form_import_file->addCommandButton("codes", $this->lng->txt("cancel"));
715 
716  $this->tpl->setContent($form_import_file->getHTML());
717  }
718 
722  protected function importAccessCodesActionObject(): void
723  {
724  if (trim($_FILES['codes']['tmp_name'])) {
725  $existing = array();
726  foreach ($this->object->getSurveyCodesTableData() as $item) {
727  $existing[$item["code"]] = $item["id"];
728  }
729 
730  $reader = new ilCSVReader();
731  $reader->open($_FILES['codes']['tmp_name']);
732  foreach ($reader->getCsvAsArray() as $row) {
733  // numeric check of used column due to #26176
734  $code = $row[0] ?? "";
735  if ($code === "") {
736  continue;
737  }
738  $email = $row[1] ?? "";
739  if (!is_int(strpos($email, "@")) && $email !== "") {
740  continue;
741  }
742  $last_name = $row[2] ?? "";
743  $first_name = $row[3] ?? "";
744  $created = time();
745 
746  // unique code?
747  if (!array_key_exists($code, $existing)) {
748  // could be date or datetime
749  /*try {
750  if (strlen($created) === 10) {
751  $created = new ilDate($created, IL_CAL_DATE);
752  } else {
753  $created = new ilDateTime($created, IL_CAL_DATETIME);
754  }
755  $created = $created->get(IL_CAL_UNIX);
756  } catch (Exception $e) {
757  $this->tpl->setOnScreenMessage('failure', $e->getMessage(), true);
758  $this->ctrl->redirect($this, 'codes');
759  }*/
760 
761  $user_data = array(
762  "email" => $email
763  ,"lastname" => $last_name
764  ,"firstname" => $first_name
765  );
766  $this->object->importSurveyCode($code, $created, $user_data);
767  }
768  }
769 
770  $this->tpl->setOnScreenMessage('success', $this->lng->txt('codes_created'), true);
771  }
772 
773  $this->ctrl->redirect($this, 'codes');
774  }
775 
779  public function createSurveyCodesObject(): void
780  {
781  if ($this->edit_request->getNrOfCodes() > 0) {
782  $ids = $this->code_manager->addCodes($this->edit_request->getNrOfCodes());
783  $this->tpl->setOnScreenMessage('success', $this->lng->txt('codes_created'), true);
784  $this->ctrl->setParameter($this, "new_ids", implode(";", $ids));
785  $this->ctrl->redirect($this, 'editCodes');
786  } else {
787  $this->tpl->setOnScreenMessage('failure', $this->lng->txt("enter_valid_number_of_codes"), true);
788  $this->ctrl->redirect($this, 'codes');
789  }
790  }
791 
792  public function insertSavedMessageObject(): void
793  {
794  $this->handleWriteAccess();
795  $this->setParticipantSubTabs("codes");
796 
797  $form_gui = new FormMailCodesGUI($this);
798  $form_gui->setValuesByPost();
799  try {
800  if ($form_gui->getSavedMessages()->getValue() > 0) {
802  $settings = $this->object->getUserSettings($ilUser->getId(), 'savemessage');
803  $form_gui->getMailMessage()->setValue($settings[$form_gui->getSavedMessages()->getValue()]['value']);
804  $this->tpl->setOnScreenMessage('success', $this->lng->txt('msg_message_inserted'));
805  } else {
806  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('msg_no_message_inserted'));
807  }
808  } catch (Exception $e) {
809  $ilLog = $this->log;
810  $ilLog->write('Error: ' . $e->getMessage());
811  }
812  $this->tpl->setVariable("ADM_CONTENT", $form_gui->getHTML());
813  }
814 
815  public function deleteSavedMessageObject(): void
816  {
817  $this->handleWriteAccess();
818  $this->setParticipantSubTabs("codes");
819 
820  $form_gui = new FormMailCodesGUI($this);
821  $form_gui->setValuesByPost();
822  try {
823  if ($form_gui->getSavedMessages()->getValue() > 0) {
824  $this->object->deleteUserSettings($form_gui->getSavedMessages()->getValue());
825  $form_gui = new FormMailCodesGUI($this);
826  $form_gui->setValuesByPost();
827  $this->tpl->setOnScreenMessage('success', $this->lng->txt('msg_message_deleted'));
828  } else {
829  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('msg_no_message_deleted'));
830  }
831  } catch (Exception $e) {
832  $ilLog = $this->log;
833  $ilLog->write('Error: ' . $e->getMessage());
834  }
835  $this->tpl->setVariable("ADM_CONTENT", $form_gui->getHTML());
836  }
837 
838  public function mailCodesObject(): void
839  {
840  $this->handleWriteAccess();
841  $this->setParticipantSubTabs("mail_survey_codes");
842 
843  $mailData['m_subject'] =
844  $this->edit_request->getCodeMailPart("subject")
845  ?: sprintf($this->lng->txt('default_codes_mail_subject'), $this->object->getTitle());
846  $mailData['m_message'] =
847  $this->edit_request->getCodeMailPart("message")
848  ?: $this->lng->txt('default_codes_mail_message');
849  $mailData['m_notsent'] =
850  $this->edit_request->getCodeMailPart("notsent")
851  ?: '1';
852 
853  $form_gui = new FormMailCodesGUI($this);
854  $form_gui->setValuesByArray($mailData);
855  $this->tpl->setVariable("ADM_CONTENT", $form_gui->getHTML());
856  }
857 
858  public function sendCodesMailObject(): void
859  {
861 
862  $this->handleWriteAccess();
863  $this->setParticipantSubTabs("mail_survey_codes");
864 
865  $form_gui = new FormMailCodesGUI($this);
866  if ($form_gui->checkInput()) {
867  $url_exists = strpos($this->edit_request->getCodeMailPart("message"), '[url]') !== false;
868  if (!$url_exists) {
869  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('please_enter_mail_url'));
870  $form_gui->setValuesByPost();
871  } else {
872  if ($this->edit_request->getSaveMessage() === 1) {
874  $title = ($this->edit_request->getSaveMessageTitle())
875  ?: ilStr::subStr($this->edit_request->getCodeMailPart("message"), 0, 40) . '...';
876  $this->object->saveUserSettings($ilUser->getId(), 'savemessage', $title, $this->edit_request->getCodeMailPart("message"));
877  }
878 
879  $lang = $ilUser->getPref("survey_code_language");
880  if (!$lang) {
881  $lang = $this->lng->getDefaultLanguage();
882  }
883  $this->object->sendCodes(
884  $this->edit_request->getCodeMailPart("notsent"),
885  $this->edit_request->getCodeMailPart("subject"),
886  nl2br($this->edit_request->getCodeMailPart("message")),
887  $lang
888  );
889  $this->tpl->setOnScreenMessage('success', $this->lng->txt('mail_sent'), true);
890  $this->ctrl->redirect($this, 'mailCodes');
891  }
892  } else {
893  $form_gui->setValuesByPost();
894  }
895  $this->tpl->setVariable("ADM_CONTENT", $form_gui->getHTML());
896  }
897 
899  {
900  if (trim($this->edit_request->getExternalText())) {
901  $data = preg_split("/[\n\r]/", $this->edit_request->getExternalText());
902  $fields = explode(";", array_shift($data));
903  if (!in_array('email', $fields, true)) {
904  $this->edit_manager->setExternalText($this->edit_request->getExternalText());
905  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('err_external_rcp_no_email_column'), true);
906  $this->ctrl->redirect($this, 'importExternalMailRecipientsFromTextForm');
907  }
908  $existingdata = $this->object->getExternalCodeRecipients();
909  $existingcolumns = array();
910  if (count($existingdata)) {
911  $first = array_shift($existingdata);
912  foreach ($first as $key => $value) {
913  $existingcolumns[] = $key;
914  }
915  }
916  $founddata = array();
917  foreach ($data as $datarow) {
918  $row = explode(";", $datarow);
919  if (count($row) === count($fields)) {
920  $dataset = array();
921  foreach ($fields as $idx => $fieldname) {
922  if (count($existingcolumns)) {
923  if (array_key_exists($idx, $existingcolumns)) {
924  $dataset[$fieldname] = $row[$idx];
925  }
926  } else {
927  $dataset[$fieldname] = $row[$idx];
928  }
929  }
930  if ($dataset['email'] !== '') {
931  $this->addCodeForExternal(
932  $dataset['email'],
933  $dataset['lastname'] ?? "",
934  $dataset['firstname'] ?? ""
935  );
936  }
937  }
938  }
939  $this->tpl->setOnScreenMessage('success', $this->lng->txt('external_recipients_imported'), true);
940  $this->ctrl->redirect($this, 'codes');
941  }
942 
943  $this->ctrl->redirect($this, 'importExternalMailRecipientsFromTextForm');
944  }
945 
949  public function addCodeForExternal(
950  string $email,
951  string $lastname,
952  string $firstname
953  ): int {
954  $code = $this->data_manager->code("")
955  ->withEmail($email)
956  ->withLastName($lastname)
957  ->withFirstName($firstname);
958  $code_id = $this->code_manager->add($code);
959  return $code_id;
960  }
961 
962  // used for importing external participants
963  // @todo move to manager/transformation class
964  protected function _convertCharset(
965  string $a_string,
966  string $a_from_charset = "",
967  string $a_to_charset = "UTF-8"
968  ): string {
969  if (extension_loaded("mbstring")) {
970  if (!$a_from_charset) {
971  mb_detect_order("UTF-8, ISO-8859-1, Windows-1252, ASCII");
972  $a_from_charset = mb_detect_encoding($a_string);
973  }
974  if (strtoupper($a_from_charset) !== $a_to_charset) {
975  return mb_convert_encoding($a_string, $a_to_charset, $a_from_charset);
976  }
977  }
978  return $a_string;
979  }
980 
981  // @todo move to manager/transformation class
982  protected function removeUTF8Bom(string $a_text): string
983  {
984  $bom = pack('H*', 'EFBBBF');
985  return preg_replace('/^' . $bom . '/', '', $a_text);
986  }
987 
989  {
990  if (trim($_FILES['externalmails']['tmp_name'])) {
991  $reader = new ilCSVReader();
992  $reader->open($_FILES['externalmails']['tmp_name']);
993  $data = $reader->getCsvAsArray();
994  $fields = array_shift($data);
995  foreach ($fields as $idx => $field) {
996  $fields[$idx] = $this->removeUTF8Bom($field);
997  }
998  if (!in_array('email', $fields, true)) {
999  $reader->close();
1000  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('err_external_rcp_no_email'), true);
1001  $this->ctrl->redirect($this, 'codes');
1002  }
1003  $existingdata = $this->object->getExternalCodeRecipients();
1004  $existingcolumns = array();
1005  if (count($existingdata)) {
1006  $first = array_shift($existingdata);
1007  foreach ($first as $key => $value) {
1008  $existingcolumns[] = $key;
1009  }
1010  }
1011 
1012  $founddata = array();
1013  foreach ($data as $row) {
1014  if (count($row) === count($fields)) {
1015  $dataset = array();
1016  foreach ($fields as $idx => $fieldname) {
1017  // #14811
1018  $row[$idx] = $this->_convertCharset($row[$idx]);
1019 
1020  if (count($existingcolumns)) {
1021  if (array_key_exists($idx, $existingcolumns)) {
1022  $dataset[$fieldname] = $row[$idx];
1023  }
1024  } else {
1025  $dataset[$fieldname] = $row[$idx];
1026  }
1027  }
1028  if ($dataset['email'] !== '') {
1029  $founddata[] = $dataset;
1030  $this->addCodeForExternal(
1031  $dataset['email'],
1032  $dataset['lastname'] ?? "",
1033  $dataset['firstname'] ?? ""
1034  );
1035  }
1036  }
1037  }
1038  $reader->close();
1039 
1040  if (count($founddata)) {
1041  $this->tpl->setOnScreenMessage('success', $this->lng->txt('external_recipients_imported'), true);
1042  }
1043  }
1044 
1045  $this->ctrl->redirect($this, 'codes');
1046  }
1047 
1049  {
1050  $ilAccess = $this->access;
1051 
1052  $this->handleWriteAccess();
1053  $this->setParticipantSubTabs("mail_survey_codes");
1054 
1055  $form_import_file = new ilPropertyFormGUI();
1056  $form_import_file->setFormAction($this->ctrl->getFormAction($this));
1057  $form_import_file->setTableWidth("100%");
1058  $form_import_file->setId("codes_import_file");
1059 
1060  $headerfile = new ilFormSectionHeaderGUI();
1061  $headerfile->setTitle($this->lng->txt("import_from_file"));
1062  $form_import_file->addItem($headerfile);
1063 
1064  $externalmails = new ilFileInputGUI($this->lng->txt("externalmails"), "externalmails");
1065  $externalmails->setInfo($this->lng->txt('externalmails_info'));
1066  $externalmails->setRequired(true);
1067  $form_import_file->addItem($externalmails);
1068  if ($ilAccess->checkAccess("write", "", $this->edit_request->getRefId())) {
1069  $form_import_file->addCommandButton("importExternalRecipientsFromFile", $this->lng->txt("import"));
1070  }
1071  if ($ilAccess->checkAccess("write", "", $this->edit_request->getRefId())) {
1072  $form_import_file->addCommandButton("codes", $this->lng->txt("cancel"));
1073  }
1074 
1075  $this->tpl->setContent($form_import_file->getHTML());
1076  }
1077 
1079  {
1080  $ilAccess = $this->access;
1081 
1082  $this->handleWriteAccess();
1083  $this->setParticipantSubTabs("mail_survey_codes");
1084 
1085  $form_import_text = new ilPropertyFormGUI();
1086  $form_import_text->setFormAction($this->ctrl->getFormAction($this));
1087  $form_import_text->setTableWidth("100%");
1088  $form_import_text->setId("codes_import_text");
1089 
1090  $headertext = new ilFormSectionHeaderGUI();
1091  $headertext->setTitle($this->lng->txt("import_from_text"));
1092  $form_import_text->addItem($headertext);
1093 
1094  $inp = new ilTextAreaInputGUI($this->lng->txt('externaltext'), 'externaltext');
1095  $external_text = $this->edit_manager->getExternalText();
1096  if ($external_text !== "") {
1097  $inp->setValue($external_text);
1098  } else {
1099  // $this->lng->txt('mail_import_example1') #14897
1100  $inp->setValue("email;firstname;lastname\n" . $this->lng->txt('mail_import_example2') . "\n" . $this->lng->txt('mail_import_example3') . "\n");
1101  }
1102  $inp->setRequired(true);
1103  $inp->setCols(80);
1104  $inp->setRows(10);
1105  $inp->setInfo($this->lng->txt('externaltext_info'));
1106  $form_import_text->addItem($inp);
1107  $this->edit_manager->setExternalText("");
1108 
1109  if ($ilAccess->checkAccess("write", "", $this->edit_request->getRefId())) {
1110  $form_import_text->addCommandButton("importExternalRecipientsFromText", $this->lng->txt("import"));
1111  }
1112  if ($ilAccess->checkAccess("write", "", $this->edit_request->getRefId())) {
1113  $form_import_text->addCommandButton("codes", $this->lng->txt("cancel"));
1114  }
1115 
1116  $this->tpl->setContent($form_import_text->getHTML());
1117  }
1118 
1119  //
1120  // 360°
1121  //
1122 
1123  public function listAppraiseesObject(): void
1124  {
1125  $ilToolbar = $this->toolbar;
1126  $lng = $this->lng;
1127  $ilCtrl = $this->ctrl;
1128 
1129  $this->handleWriteAccess();
1130 
1131  $this->ctrl->setParameter($this, "appr360", 1);
1132 
1134  $this,
1135  $ilToolbar,
1136  array(
1137  'auto_complete_name' => $this->lng->txt('user'),
1138  'submit_name' => $this->lng->txt('add'),
1139  'add_search' => true,
1140  'add_from_container' => $this->ref_id
1141  )
1142  );
1143 
1144  // competence calculations
1145  $skmg_set = new ilSkillManagementSettings();
1146  if ($this->object->getSkillService() && $skmg_set->isActivated()) {
1147  $ilToolbar->addSeparator();
1148  $ilToolbar->addButton(
1149  $lng->txt("survey_calc_skills"),
1150  $ilCtrl->getLinkTargetByClass("ilsurveyskilldeterminationgui"),
1151  ""
1152  );
1153  }
1154 
1155  $ilToolbar->addSeparator();
1156  $ilToolbar->addButton(
1157  $this->lng->txt('svy_delete_all_user_data'),
1158  $this->ctrl->getLinkTarget($this, 'deleteAllUserData')
1159  );
1160 
1161  $this->ctrl->setParameter($this, "appr360", "");
1162 
1163  $tbl = new ilSurveyAppraiseesTableGUI($this, "listAppraisees");
1164  $tbl->setData($this->object->getAppraiseesData());
1165  $this->tpl->setContent($tbl->getHTML());
1166  }
1167 
1168  public function addAppraisee(
1169  array $a_user_ids
1170  ): void {
1171  if (count($a_user_ids)) {
1172  // #13319
1173  foreach (array_unique($a_user_ids) as $user_id) {
1174  $this->object->addAppraisee($user_id);
1175  }
1176 
1177  $this->tpl->setOnScreenMessage('success', $this->lng->txt("settings_saved"), true);
1178  }
1179  $this->ctrl->redirect($this, "listAppraisees");
1180  }
1181 
1182  public function confirmDeleteAppraiseesObject(): void
1183  {
1184  $ilTabs = $this->tabs;
1185 
1186  $appr_ids = $this->edit_request->getAppraiseeIds();
1187  if (count($appr_ids) === 0) {
1188  $this->tpl->setOnScreenMessage('failure', $this->lng->txt("select_one"), true);
1189  $this->ctrl->redirect($this, "listAppraisees");
1190  }
1191 
1192  $ilTabs->clearTargets();
1193  $ilTabs->setBackTarget(
1194  $this->lng->txt("btn_back"),
1195  $this->ctrl->getLinkTarget($this, "listAppraisees")
1196  );
1197 
1198  $cgui = new ilConfirmationGUI();
1199  $cgui->setHeaderText($this->lng->txt("survey_360_sure_delete_appraises"));
1200 
1201  $cgui->setFormAction($this->ctrl->getFormAction($this, "deleteAppraisees"));
1202  $cgui->setCancel($this->lng->txt("cancel"), "listAppraisees");
1203  $cgui->setConfirm($this->lng->txt("confirm"), "deleteAppraisees");
1204 
1205  $data = $this->object->getAppraiseesData();
1206 
1207  $count = 0;
1208  foreach ($appr_ids as $id) {
1209  if (isset($data[$id]) && !$data[$id]["closed"]) {
1210  $cgui->addItem("appr_id[]", $id, ilUserUtil::getNamePresentation($id));
1211  $count++;
1212  }
1213  }
1214 
1215  if (!$count) {
1216  $this->tpl->setOnScreenMessage('failure', $this->lng->txt("select_one"), true);
1217  $this->ctrl->redirect($this, "listAppraisees");
1218  }
1219 
1220  $this->tpl->setContent($cgui->getHTML());
1221  }
1222 
1223  public function deleteAppraiseesObject(): void
1224  {
1225  $appr_ids = $this->edit_request->getAppraiseeIds();
1226  if (count($appr_ids) > 0) {
1227  $data = $this->object->getAppraiseesData();
1228 
1229  foreach ($appr_ids as $id) {
1230  // #11285
1231  if (isset($data[$id]) && !$data[$id]["closed"]) {
1232  $this->object->deleteAppraisee($id);
1233  }
1234  }
1235 
1236  $this->tpl->setOnScreenMessage('success', $this->lng->txt("settings_saved"), true);
1237  }
1238 
1239  $this->ctrl->redirect($this, "listAppraisees");
1240  }
1241 
1242  public function handleRatersAccess(): ?int
1243  {
1244  $ilAccess = $this->access;
1245  $ilUser = $this->user;
1246 
1247  if ($ilAccess->checkAccess("write", "", $this->ref_id)) {
1248  $appr_id = $this->edit_request->getAppraiseeId();
1249  if (!$appr_id) {
1250  $this->ctrl->redirect($this, "listAppraisees");
1251  }
1252  return $appr_id;
1253  } elseif ($this->feature_config->usesAppraisees() &&
1254  $this->object->get360SelfRaters() &&
1255  $this->object->isAppraisee($ilUser->getId()) &&
1256  !$this->object->isAppraiseeClosed($ilUser->getId())) {
1257  return $ilUser->getId();
1258  }
1259  $this->ctrl->redirect($this->parent_gui, "infoScreen");
1260  return null;
1261  }
1262 
1263  protected function storeMailSent(): void
1264  {
1265  $appr_id = $this->handleRatersAccess();
1266  $all_data = $this->object->getRatersData($appr_id);
1267 
1268  $recs = json_decode(base64_decode($this->edit_request->getRecipients()));
1269  foreach ($all_data as $rec_id => $rater) {
1270  $sent = false;
1271  if (($rater["login"] != "" && in_array($rater["login"], $recs, true)) ||
1272  ($rater["email"] != "" && in_array($rater["email"], $recs, true))) {
1273  $sent = true;
1274  }
1275  if ($sent) {
1276  $this->object->set360RaterSent(
1277  $appr_id,
1278  strpos($rec_id, "a") === 0 ? 0 : (int) substr($rec_id, 1),
1279  strpos($rec_id, "u") === 0 ? 0 : (int) substr($rec_id, 1)
1280  );
1281  }
1282  }
1283  $this->ctrl->setParameter($this, "appr_id", $appr_id);
1284  $this->ctrl->redirect($this, "editRaters");
1285  }
1286 
1287  public function editRatersObject(): void
1288  {
1289  if ($this->edit_request->getReturnedFromMail() === 1) {
1290  $this->storeMailSent();
1291  }
1292 
1293  $ilTabs = $this->tabs;
1294  $ilToolbar = $this->toolbar;
1295  $ilAccess = $this->access;
1296  $ilTabs->activateTab("survey_360_edit_raters");
1297  $appr_id = $this->handleRatersAccess();
1298 
1299  $has_write = $ilAccess->checkAccess("write", "", $this->ref_id);
1300  if ($has_write) {
1301  $ilTabs->clearTargets();
1302  $ilTabs->setBackTarget(
1303  $this->lng->txt("btn_back"),
1304  $this->ctrl->getLinkTarget($this, "listAppraisees")
1305  );
1306  }
1307 
1308  $this->ctrl->setParameter($this, "appr_id", $appr_id);
1309  $this->ctrl->setParameter($this, "rate360", 1);
1310 
1311  $ilToolbar->addButton(
1312  $this->lng->txt("svy_add_rater"),
1313  $this->ctrl->getLinkTargetByClass("ilSurveyRaterGUI", "add")
1314  );
1315 
1316  // #13320
1317  $url = ilLink::_getStaticLink($this->object->getRefId());
1318 
1319  $tbl = new ilSurveyAppraiseesTableGUI($this, "editRaters", true, !$this->object->isAppraiseeClosed($appr_id), $url); // #11285
1320  $tbl->setData($this->object->getRatersData($appr_id));
1321  $this->tpl->setContent($tbl->getHTML());
1322  }
1323 
1325  ilPropertyFormGUI $a_form = null
1326  ): void {
1327  $ilTabs = $this->tabs;
1328  $ilAccess = $this->access;
1329 
1330  $appr_id = $this->handleRatersAccess();
1331  $this->ctrl->setParameter($this, "appr_id", $appr_id);
1332 
1333  $has_write = $ilAccess->checkAccess("write", "", $this->ref_id);
1334  if ($has_write) {
1335  $ilTabs->clearTargets();
1336  $ilTabs->setBackTarget(
1337  $this->lng->txt("btn_back"),
1338  $this->ctrl->getLinkTarget($this, "editRaters")
1339  );
1340  }
1341 
1342  if (!$a_form) {
1343  $a_form = $this->initExternalRaterForm($appr_id);
1344  }
1345 
1346  $this->tpl->setContent($a_form->getHTML());
1347  }
1348 
1349  protected function initExternalRaterForm(
1350  int $appr_id
1351  ): ilPropertyFormGUI {
1352  $form = new ilPropertyFormGUI();
1353  $form->setFormAction($this->ctrl->getFormAction($this, "addExternalRater"));
1354  $form->setTitle($this->lng->txt("survey_360_add_external_rater") .
1355  ": " . ilUserUtil::getNamePresentation($appr_id));
1356 
1357  $email = new ilEmailInputGUI($this->lng->txt("email"), "email");
1358  $email->setRequired(true);
1359  $form->addItem($email);
1360 
1361  $lname = new ilTextInputGUI($this->lng->txt("lastname"), "lname");
1362  $lname->setSize(30);
1363  $form->addItem($lname);
1364 
1365  $fname = new ilTextInputGUI($this->lng->txt("firstname"), "fname");
1366  $fname->setSize(30);
1367  $form->addItem($fname);
1368 
1369  $form->addCommandButton("addExternalRater", $this->lng->txt("save"));
1370  $form->addCommandButton("editRaters", $this->lng->txt("cancel"));
1371 
1372  return $form;
1373  }
1374 
1375  public function addExternalRaterObject(): void
1376  {
1377  $appr_id = $this->edit_request->getAppraiseeId();
1378  if (!$appr_id) {
1379  $this->ctrl->redirect($this, "listAppraisees");
1380  }
1381 
1382  $this->ctrl->setParameter($this, "appr_id", $appr_id);
1383 
1384  $form = $this->initExternalRaterForm($appr_id);
1385  if ($form->checkInput()) {
1386  $code_id = $this->addCodeForExternal(
1387  $form->getInput("email"),
1388  $form->getInput("lname"),
1389  $form->getInput("fname")
1390  );
1391 
1392  $this->object->addRater($appr_id, 0, $code_id);
1393 
1394  $this->tpl->setOnScreenMessage('success', $this->lng->txt("settings_saved"), true);
1395  $this->ctrl->setParameter($this, "appr_id", $appr_id);
1396  $this->ctrl->redirect($this, "editRaters");
1397  }
1398 
1399  $form->setValuesByPost();
1400  $this->addExternalRaterFormObject($form);
1401  }
1402 
1403  public function addRater(
1404  array $a_user_ids
1405  ): void {
1406  $ilAccess = $this->access;
1407  $ilUser = $this->user;
1408 
1409  $appr_id = $this->handleRatersAccess();
1410 
1411  if (count($a_user_ids)) {
1412  // #13319
1413  foreach (array_unique($a_user_ids) as $user_id) {
1414  if ($ilAccess->checkAccess("write", "", $this->ref_id) ||
1415  $this->object->get360SelfEvaluation() ||
1416  $user_id != $ilUser->getId()) {
1417  if ($appr_id != $user_id) {
1418  $this->object->addRater($appr_id, $user_id);
1419  $this->tpl->setOnScreenMessage('success', $this->lng->txt("settings_saved"), true);
1420  } else {
1421  $this->tpl->setOnScreenMessage('failure', $this->lng->txt("svy_appraisses_cannot_be_raters"), true);
1422  }
1423  }
1424  }
1425  }
1426 
1427  $this->ctrl->setParameter($this, "appr_id", $appr_id);
1428  $this->ctrl->redirect($this, "editRaters");
1429  }
1430 
1431  public function confirmDeleteRatersObject(): void
1432  {
1433  $ilTabs = $this->tabs;
1434 
1435  $rater_ids = $this->edit_request->getRaterIds();
1436  $appr_id = $this->handleRatersAccess();
1437  $this->ctrl->setParameter($this, "appr_id", $appr_id);
1438  if (count($rater_ids) === 0) {
1439  $this->tpl->setOnScreenMessage('failure', $this->lng->txt("select_one"), true);
1440  $this->ctrl->redirect($this, "editRaters");
1441  }
1442 
1443  $ilTabs->clearTargets();
1444  $ilTabs->setBackTarget(
1445  $this->lng->txt("btn_back"),
1446  $this->ctrl->getLinkTarget($this, "editRaters")
1447  );
1448 
1449  $cgui = new ilConfirmationGUI();
1450  $cgui->setHeaderText(sprintf(
1451  $this->lng->txt("survey_360_sure_delete_raters"),
1453  ));
1454 
1455  $cgui->setFormAction($this->ctrl->getFormAction($this, "deleteRaters"));
1456  $cgui->setCancel($this->lng->txt("cancel"), "editRaters");
1457  $cgui->setConfirm($this->lng->txt("confirm"), "deleteRaters");
1458 
1459  $data = $this->object->getRatersData($appr_id);
1460 
1461  foreach ($rater_ids as $id) {
1462  if (isset($data[$id])) {
1463  $cgui->addItem("rtr_id[]", $id, $data[$id]["lastname"] . ", " .
1464  $data[$id]["firstname"] . " (" . $data[$id]["email"] . ")");
1465  }
1466  }
1467 
1468  $this->tpl->setContent($cgui->getHTML());
1469  }
1470 
1471  public function deleteRatersObject(): void
1472  {
1473  $appr_id = $this->handleRatersAccess();
1474  $this->ctrl->setParameter($this, "appr_id", $appr_id);
1475 
1476  $rater_ids = $this->edit_request->getRaterIds();
1477  if (count($rater_ids) > 0) {
1478  $data = $this->object->getRatersData($appr_id);
1479 
1480  foreach ($rater_ids as $id) {
1481  if (isset($data[$id])) {
1482  if (strpos($id, "u") === 0) {
1483  $this->object->deleteRater($appr_id, substr($id, 1));
1484  } else {
1485  $this->object->deleteRater($appr_id, 0, substr($id, 1));
1486  }
1487  }
1488  }
1489 
1490  $this->tpl->setOnScreenMessage('success', $this->lng->txt("settings_saved"), true);
1491  }
1492 
1493  $this->ctrl->redirect($this, "editRaters");
1494  }
1495 
1496  public function addSelfAppraiseeObject(): void
1497  {
1498  $ilUser = $this->user;
1499 
1500  if ($this->object->get360SelfAppraisee() &&
1501  !$this->object->isAppraisee($ilUser->getId())) {
1502  $this->object->addAppraisee($ilUser->getId());
1503  }
1504 
1505  $this->ctrl->redirect($this->parent_gui, "infoScreen");
1506  }
1507 
1508  public function initMailRatersForm(
1509  int $appr_id,
1510  array $rec_ids
1511  ): ilPropertyFormGUI {
1512  $form = new ilPropertyFormGUI();
1513  $form->setFormAction($this->ctrl->getFormAction($this, "mailRatersAction"));
1514  $form->setTitle($this->lng->txt('compose'));
1515 
1516  $all_data = $this->object->getRatersData($appr_id);
1517  $rec_data = array();
1518  foreach ($rec_ids as $rec_id) {
1519  if (isset($all_data[$rec_id])) {
1520  $rec_data[] = $all_data[$rec_id]["lastname"] . ", " .
1521  $all_data[$rec_id]["firstname"] .
1522  " (" . $all_data[$rec_id]["email"] . ")";
1523  }
1524  }
1525  sort($rec_data);
1526  $rec = new ilCustomInputGUI($this->lng->txt('recipients'));
1527  $rec->setHtml(implode("<br />", $rec_data));
1528  $form->addItem($rec);
1529 
1530  $subject = new ilTextInputGUI($this->lng->txt('subject'), 'subject');
1531  $subject->setSize(50);
1532  $subject->setRequired(true);
1533  $form->addItem($subject);
1534 
1535  $existingdata = $this->object->getExternalCodeRecipients();
1536  $existingcolumns = array();
1537  if (count($existingdata)) {
1538  $first = array_shift($existingdata);
1539  foreach ($first as $key => $value) {
1540  if (strcmp($key, 'code') !== 0 && strcmp($key, 'email') !== 0 && strcmp($key, 'sent') !== 0) {
1541  $existingcolumns[] = '[' . $key . ']';
1542  }
1543  }
1544  }
1545 
1546  $mailmessage_u = new ilTextAreaInputGUI($this->lng->txt('survey_360_rater_message_content_registered'), 'message_u');
1547  $mailmessage_u->setRequired(true);
1548  $mailmessage_u->setCols(80);
1549  $mailmessage_u->setRows(10);
1550  $form->addItem($mailmessage_u);
1551 
1552  $mailmessage_a = new ilTextAreaInputGUI($this->lng->txt('survey_360_rater_message_content_anonymous'), 'message_a');
1553  $mailmessage_a->setRequired(true);
1554  $mailmessage_a->setCols(80);
1555  $mailmessage_a->setRows(10);
1556  $mailmessage_a->setInfo(sprintf($this->lng->txt('message_content_info'), implode(', ', $existingcolumns)));
1557  $form->addItem($mailmessage_a);
1558 
1559  $recf = new ilHiddenInputGUI("rater_id");
1560  $recf->setValue(implode(";", $rec_ids));
1561  $form->addItem($recf);
1562 
1563  $form->addCommandButton("mailRatersAction", $this->lng->txt("send"));
1564  $form->addCommandButton("editRaters", $this->lng->txt("cancel"));
1565 
1566  $subject->setValue(sprintf($this->lng->txt('survey_360_rater_subject_default'), $this->object->getTitle()));
1567  $mailmessage_u->setValue($this->lng->txt('survey_360_rater_message_content_registered_default'));
1568  $mailmessage_a->setValue($this->lng->txt('survey_360_rater_message_content_anonymous_default'));
1569 
1570  return $form;
1571  }
1572 
1573  public function mailRatersObject(): void
1574  {
1575  $appr_id = $this->handleRatersAccess();
1576  $all_data = $this->object->getRatersData($appr_id);
1577  $this->ctrl->setParameter($this, "appr_id", $appr_id);
1578 
1579  $raters = $this->edit_request->getRaterIds();
1580 
1581  $rec = [];
1582  $external_rater = false;
1583  $rater_id = "";
1584  foreach ($raters as $id) {
1585  if (isset($all_data[$id])) {
1586  if ($all_data[$id]["login"] != "") {
1587  $rec[] = $all_data[$id]["login"];
1588  } elseif ($all_data[$id]["email"] != "") {
1589  $rec[] = $all_data[$id]["email"];
1590  $external_rater = true;
1591  $rater_id = $all_data[$id]["user_id"];
1592  }
1593  }
1594  }
1595  if ($external_rater && count($rec) > 1) {
1596  $this->tpl->setOnScreenMessage('failure', $this->lng->txt("svy_only_max_one_external_rater"), true);
1597  $this->ctrl->redirect($this, "editRaters");
1598  }
1599 
1600  // $_POST["rtr_id"]
1602 
1603  $contextParameters = [
1604  'ref_id' => $this->object->getRefId(),
1605  'ts' => time(),
1606  'appr_id' => $appr_id,
1607  'rater_id' => $rater_id,
1608  ilMailFormCall::CONTEXT_KEY => "svy_rater_inv"
1609  ];
1610 
1611  $this->ctrl->redirectToURL(ilMailFormCall::getRedirectTarget(
1612  $this,
1613  'editRaters',
1614  [
1615  'recipients' => base64_encode(json_encode($rec, JSON_THROW_ON_ERROR)),
1616  ],
1617  [
1618  'type' => 'new',
1619  'sig' => rawurlencode(base64_encode("\n\n" . $this->lng->txt("svy_link_to_svy") . ": [SURVEY_LINK]"))
1620  ],
1621  $contextParameters
1622  ));
1623  }
1624 
1625  public function mailRatersObjectOld(
1626  ilPropertyFormGUI $a_form = null
1627  ): void {
1628  $ilTabs = $this->tabs;
1629  $rater_ids = $this->edit_request->getRaterIds();
1630  if (!$a_form) {
1631  $appr_id = $this->handleRatersAccess();
1632  $this->ctrl->setParameter($this, "appr_id", $appr_id);
1633 
1634  if (count($rater_ids) === 0) {
1635  $this->tpl->setOnScreenMessage('failure', $this->lng->txt("select_one"), true);
1636  $this->ctrl->redirect($this, "editRaters");
1637  }
1638 
1639  $a_form = $this->initMailRatersForm($appr_id, $rater_ids);
1640  }
1641 
1642  $ilTabs->clearTargets();
1643  $ilTabs->setBackTarget(
1644  $this->lng->txt("btn_back"),
1645  $this->ctrl->getLinkTarget($this, "editRaters")
1646  );
1647 
1648  $this->tpl->setContent($a_form->getHTML());
1649  }
1650 
1651  public function mailRatersActionObject(): void
1652  {
1653  $ilUser = $this->user;
1654  $appr_id = $this->handleRatersAccess();
1655  $this->ctrl->setParameter($this, "appr_id", $appr_id);
1656 
1657  $rec_ids = $this->edit_request->getRaterIds();
1658  if (count($rec_ids) === 0) {
1659  $this->ctrl->redirect($this, "editRaters");
1660  }
1661 
1662  $form = $this->initMailRatersForm($appr_id, $rec_ids);
1663  if ($form->checkInput()) {
1664  $txt_u = $form->getInput("message_u");
1665  $txt_a = $form->getInput("message_a");
1666  $subj = $form->getInput("subject");
1667 
1668  // #12743
1669  $sender_id = (trim($ilUser->getEmail()))
1670  ? $ilUser->getId()
1672 
1673  $all_data = $this->object->getRatersData($appr_id);
1674  foreach ($rec_ids as $rec_id) {
1675  if (isset($all_data[$rec_id])) {
1676  $user = $all_data[$rec_id];
1677 
1678  // anonymous
1679  if (strpos($rec_id, "a") === 0) {
1680  $mytxt = $txt_a;
1681  $url = $user["href"];
1682  $rcp = $user["email"];
1683  }
1684  // reg
1685  else {
1686  $mytxt = $txt_u;
1687  $user["code"] = $this->lng->txt("survey_code_mail_on_demand");
1688  $url = ilLink::_getStaticLink($this->object->getRefId());
1689  $rcp = $user["login"]; // #15141
1690  }
1691 
1692  $mytxt = str_replace(
1693  ["[lastname]", "[firstname]", "[url]", "[code]"],
1694  [$user["lastname"], $user["firstname"], $url, $user["code"]],
1695  $mytxt
1696  );
1697 
1698  $mail = new ilMail($sender_id);
1699  $mail->enqueue(
1700  $rcp, // to
1701  "", // cc
1702  "", // bcc
1703  $subj, // subject
1704  $mytxt, // message
1705  array() // attachments
1706  );
1707 
1708  $this->object->set360RaterSent(
1709  $appr_id,
1710  (strpos($rec_id, "a") === 0) ? 0 : (int) substr($rec_id, 1),
1711  (strpos($rec_id, "u") === 0) ? 0 : (int) substr($rec_id, 1)
1712  );
1713  }
1714  }
1715 
1716  $this->tpl->setOnScreenMessage('success', $this->lng->txt("mail_sent"), true);
1717  $this->ctrl->redirect($this, "editRaters");
1718  }
1719 
1720  $form->setValuesByPost();
1721  $this->mailRatersObject();
1722  }
1723 
1724  public function confirmAppraiseeCloseObject(): void
1725  {
1726  $ilUser = $this->user;
1727  $tpl = $this->tpl;
1728  $ilTabs = $this->tabs;
1729 
1730  $ilTabs->clearTargets();
1731  $ilTabs->setBackTarget(
1732  $this->lng->txt("menuback"),
1733  $this->ctrl->getLinkTarget($this->parent_gui, "infoScreen")
1734  );
1735 
1736  if (!$this->object->isAppraisee($ilUser->getId())) {
1737  $this->ctrl->redirect($this->parent_gui, "infoScreen");
1738  }
1739 
1740  $cgui = new ilConfirmationGUI();
1741  $cgui->setHeaderText($this->lng->txt("survey_360_sure_appraisee_close"));
1742 
1743  $cgui->setFormAction($this->ctrl->getFormAction($this, "appraiseeClose"));
1744  $cgui->setCancel($this->lng->txt("cancel"), "confirmAppraiseeCloseCancel");
1745  $cgui->setConfirm($this->lng->txt("confirm"), "appraiseeClose");
1746 
1747  $tpl->setContent($cgui->getHTML());
1748  }
1749 
1750  public function confirmAppraiseeCloseCancelObject(): void
1751  {
1752  $this->ctrl->redirect($this->parent_gui, "infoScreen");
1753  }
1754 
1755  public function appraiseeCloseObject(): void
1756  {
1757  $ilUser = $this->user;
1758 
1759  if (!$this->object->isAppraisee($ilUser->getId())) {
1760  $this->ctrl->redirect($this->parent_gui, "infoScreen");
1761  }
1762 
1763  $this->object->closeAppraisee($ilUser->getId());
1764  $this->tpl->setOnScreenMessage('success', $this->lng->txt("survey_360_appraisee_close_action_success"), true);
1765  $this->ctrl->redirect($this->parent_gui, "infoScreen");
1766  }
1767 
1768  public function confirmAdminAppraiseesCloseObject(): void
1769  {
1770  $tpl = $this->tpl;
1771 
1772  $this->handleWriteAccess();
1773 
1774  $appr_ids = $this->edit_request->getAppraiseeIds();
1775 
1776  if (count($appr_ids) === 0) {
1777  $this->tpl->setOnScreenMessage('failure', $this->lng->txt("select_one"), true);
1778  $this->ctrl->redirect($this, "listAppraisees");
1779  }
1780 
1781  $cgui = new ilConfirmationGUI();
1782  $cgui->setHeaderText($this->lng->txt("survey_360_sure_appraisee_close_admin"));
1783 
1784  $cgui->setFormAction($this->ctrl->getFormAction($this, "adminAppraiseesClose"));
1785  $cgui->setCancel($this->lng->txt("cancel"), "listAppraisees");
1786  $cgui->setConfirm($this->lng->txt("confirm"), "adminAppraiseesClose");
1787 
1788  foreach ($appr_ids as $appr_id) {
1789  $cgui->addItem("appr_id[]", $appr_id, ilUserUtil::getNamePresentation($appr_id));
1790  }
1791 
1792  $tpl->setContent($cgui->getHTML());
1793  }
1794 
1795  public function adminAppraiseesCloseObject(): void
1796  {
1797  $this->handleWriteAccess();
1798 
1799  $appr_ids = $this->edit_request->getAppraiseeIds();
1800 
1801  if (count($appr_ids) === 0) {
1802  $this->tpl->setOnScreenMessage('failure', $this->lng->txt("select_one"), true);
1803  $this->ctrl->redirect($this, "listAppraisees");
1804  }
1805 
1806  $appr_data = $this->object->getAppraiseesData();
1807  foreach ($appr_ids as $appr_id) {
1808  if (isset($appr_data[$appr_id]) && !$appr_data[$appr_id]["closed"]) {
1809  $this->object->closeAppraisee($appr_id);
1810  }
1811  }
1812 
1813  $this->tpl->setOnScreenMessage('success', $this->lng->txt("survey_360_appraisee_close_action_success_admin"), true);
1814  $this->ctrl->redirect($this, "listAppraisees");
1815  }
1816 
1817  protected function listParticipantsObject(): void
1818  {
1819  $ilToolbar = $this->toolbar;
1820 
1821  if (!$this->isAnonymousListActive()) {
1822  $this->ctrl->redirect($this, "maintenance");
1823  }
1824 
1825  $this->handleWriteAccess();
1826  $this->setParticipantSubTabs("anon_participants");
1827 
1828  $button = ilLinkButton::getInstance();
1829  $button->setCaption("print");
1830  $button->setOnClick("window.print(); return false;");
1831  $button->setOmitPreventDoubleSubmission(true);
1832  $ilToolbar->addButtonInstance($button);
1833 
1834  $tbl = new ilSurveyParticipantsTableGUI($this, "listParticipants", $this->object);
1835  $this->tpl->setContent($tbl->getHTML());
1836  }
1837 
1842  public function inviteUsers(array $user_ids): void
1843  {
1844  $lng = $this->lng;
1845  $ctrl = $this->ctrl;
1846 
1847  foreach ($user_ids as $user_id) {
1848  $this->invitation_manager->add($this->object->getSurveyId(), $user_id);
1849  }
1850  $this->tpl->setOnScreenMessage('success', $lng->txt("svy_users_invited"), true);
1851  $ctrl->redirect($this, "maintenance");
1852  }
1853 }
importAccessCodesObject()
Import codes from export codes file (upload form)
Class ilSurveyParticipantsGUI.
setData(array $a_data)
array $settings
Setting values (LTI parameters, custom parameters and local parameters).
Definition: System.php:200
codesObject()
Display the survey access codes tab.
const ANONYMOUS_USER_ID
Definition: constants.php:27
static getNamePresentation( $a_user_id, bool $a_user_image=false, bool $a_profile_link=false, string $a_profile_back_link="", bool $a_force_first_lastname=false, bool $a_omit_login=false, bool $a_sortable=true, bool $a_return_data_array=false, $a_ctrl_path="ilpublicuserprofilegui")
Default behaviour is:
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
$errors
Definition: imgupload.php:65
exportAllCodesObject()
Exports all survey codes.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
redirect(object $a_gui_obj, string $a_cmd=null, string $a_anchor=null, bool $is_async=false)
addExternalRaterFormObject(ilPropertyFormGUI $a_form=null)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This class represents a file property in a property form.
write(string $a_message, $a_level=ilLogLevel::INFO)
write log message
maintenanceObject()
Participants maintenance.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
addCodeForExternal(string $email, string $lastname, string $firstname)
Add code for an external rater.
setCodeLanguageObject()
Change survey language for direct access URL&#39;s.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static subStr(string $a_str, int $a_start, ?int $a_length=null)
Definition: class.ilStr.php:24
Participants InvitationsManager $invitation_manager
static deliverData(string $a_data, string $a_filename, string $mime="application/octet-stream")
cancelDeleteSelectedUserDataObject()
Cancels the deletion of all user data.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getASCIIFilename(string $a_filename)
global $DIC
Definition: feed.php:28
Class ilObjSurveyGUI.
filterSurveyParticipantsByAccess(array $a_finished_ids=null)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
cancelDeleteAllUserDataObject()
Cancels delete of all user data in maintenance.
addSubTab(string $a_id, string $a_text, string $a_link, string $a_frame="")
setContent(string $a_html)
Sets content for standard template.
deleteCodesObject()
Delete a list of survey codes.
ILIAS Survey Editing EditManager $edit_manager
string $key
Consumer key/client ID value.
Definition: System.php:193
ILIAS Survey InternalService $survey_service
static fillAutoCompleteToolbar(object $parent_object, ilToolbarGUI $toolbar=null, array $a_options=[], bool $a_sticky=false)
array( auto_complete_name = $lng->txt(&#39;user&#39;), auto_complete_size = 15, user_type = array(ilCoursePar...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
clearTargets()
clear all targets
initMailRatersForm(int $appr_id, array $rec_ids)
setRequired(bool $a_required)
if($orgName !==null) if($spconfig->hasValue('contacts')) $email
Definition: metadata.php:302
ILIAS Survey InternalDataService $data_manager
$lang
Definition: xapiexit.php:26
createSurveyCodesObject()
Create access codes for the survey.
confirmDeleteSelectedUserDataObject()
Deletes all user data for the test object.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static setRecipients(array $recipients, string $type='to')
__construct(Container $dic, ilPlugin $plugin)
importAccessCodesActionObject()
Import codes from export codes file.
This class represents a text area property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$ilUser
Definition: imgupload.php:34
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
static getRedirectTarget( $gui, string $cmd, array $gui_params=[], array $mail_params=[], array $context_params=[])
$url
confirmDeleteAllUserDataObject()
Deletes all user data of the survey after confirmation.
_convertCharset(string $a_string, string $a_from_charset="", string $a_to_charset="UTF-8")
ILIAS Survey Mode FeatureConfig $feature_config
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
exportCodesObject()
Exports a list of survey codes.
deleteSingleUserResultsObject()
Asks for a confirmation to delete selected user data.
deleteAllUserDataObject()
Creates a confirmation form for delete all user data.
mailRatersObjectOld(ilPropertyFormGUI $a_form=null)
int $created
Timestamp for when the object was created.
Definition: System.php:151
ILIAS Survey Code CodeManager $code_manager
$i
Definition: metadata.php:41
ILIAS Survey Editing EditingGUIRequest $edit_request
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...