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