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