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