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