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