ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilPersonalProfileGUI.php
Go to the documentation of this file.
1<?php
2
19use ILIAS\UI\Factory as UIFactory;
20use ILIAS\UI\Renderer as UIRenderer;
24
34{
35 private const PERSONAL_DATA_FORM_ID = 'pd';
36 public const CHANGE_EMAIL_CMD = 'changeEmail';
37
42
43 public $tpl;
44
48 protected $lng;
49
53 protected $ctrl;
54
55 public $user_defined_fields = null;
56
58 protected $tabs;
59
62
65
67 protected $errorHandler;
68
72 protected $checklist;
73
78
83
84 protected $ui_factory;
85 protected $ui_renderer;
86 protected $auth_session;
89
95 public function __construct(
98 ) {
99 global $DIC;
100
101 $this->tabs = $DIC->tabs();
102 $this->user = $DIC->user();
103 $this->lng = $DIC->language();
104 $this->setting = $DIC->settings();
105 $this->tpl = $DIC->ui()->mainTemplate();
106 $this->ctrl = $DIC->ctrl();
107 $this->errorHandler = $DIC['ilErr'];
108 $this->eventHandler = $DIC['ilAppEventHandler'];
109
110 if ($termsOfServiceEvaluation === null) {
111 $termsOfServiceEvaluation = $DIC['tos.document.evaluator'];
112 }
113 $this->termsOfServiceEvaluation = $termsOfServiceEvaluation;
114 if ($termsOfServiceHelper === null) {
116 }
117 $this->termsOfServiceHelper = $termsOfServiceHelper;
118
119 include_once './Services/User/classes/class.ilUserDefinedFields.php';
120 $this->user_defined_fields = &ilUserDefinedFields::_getInstance();
121
122 $this->lng->loadLanguageModule("jsmath");
123 $this->lng->loadLanguageModule("pd");
124 $this->upload_error = "";
125 $this->password_error = "";
126 $this->lng->loadLanguageModule("user");
127 $this->ctrl->saveParameter($this, "prompted");
128
129 $this->checklist = new ilProfileChecklistGUI();
130 $this->checklist_status = new ilProfileChecklistStatus();
131
132 $this->user_settings_config = new ilUserSettingsConfig();
133
134 $this->ui_factory = $DIC['ui.factory'];
135 $this->ui_renderer = $DIC['ui.renderer'];
136 $this->auth_session = $DIC['ilAuthSession'];
137 $this->change_mail_token_repo = new ProfileChangeMailTokenDBRepository($DIC['ilDB']);
138 }
139
143 public function executeCommand()
144 {
145 global $DIC;
146
147 $ilUser = $DIC['ilUser'];
148 $ilCtrl = $DIC['ilCtrl'];
149 $tpl = $DIC['tpl'];
150 $ilTabs = $DIC['ilTabs'];
151
152 $next_class = $this->ctrl->getNextClass();
153
154 switch ($next_class) {
155 case "ilpublicuserprofilegui":
156 include_once("./Services/User/classes/class.ilPublicUserProfileGUI.php");
157 $_GET["user_id"] = $ilUser->getId();
158 $pub_profile_gui = new ilPublicUserProfileGUI($_GET["user_id"]);
159 $pub_profile_gui->setBackUrl($ilCtrl->getLinkTarget($this, "showPersonalData"));
160 $ilCtrl->forwardCommand($pub_profile_gui);
161 $tpl->printToStdout();
162 break;
163
164 case "iluserprivacysettingsgui":
165 $this->setHeader();
166 $this->setTabs();
167 $ilTabs->activateTab("visibility_settings");
169 $gui = new ilUserPrivacySettingsGUI();
170 $ilCtrl->forwardCommand($gui);
171 break;
172
173 default:
174 $this->setTabs();
175 $cmd = $this->ctrl->getCmd("showPersonalData");
176 $this->$cmd();
177 break;
178 }
179 return true;
180 }
181
182
187 public function workWithUserSetting(string $setting) : bool
188 {
189 return $this->user_settings_config->isVisibleAndChangeable($setting);
190 }
191
196 public function userSettingVisible(string $setting) : bool
197 {
198 return $this->user_settings_config->isVisible($setting);
199 }
200
205 public function userSettingEnabled(string $setting) : bool
206 {
207 return $this->user_settings_config->isChangeable($setting);
208 }
209
213 public function uploadUserPicture()
214 {
215 global $DIC;
216
217 $ilUser = $DIC['ilUser'];
218
219 if ($this->workWithUserSetting("upload")) {
220 if (!$this->form->hasFileUpload("userfile")) {
221 if ($this->form->getItemByPostVar("userfile")->getDeletionFlag()) {
222 $ilUser->removeUserPicture();
223 }
224 return;
225 } else {
226 $webspace_dir = ilUtil::getWebspaceDir();
227 $image_dir = $webspace_dir . "/usr_images";
228 $store_file = "usr_" . $ilUser->getID() . "." . "jpg";
229
230 // store filename
231 $ilUser->setPref("profile_image", $store_file);
232 $ilUser->update();
233
234 // move uploaded file
235
236 $pi = pathinfo($_FILES["userfile"]["name"]);
237 $uploaded_file = $this->form->moveFileUpload(
238 $image_dir,
239 "userfile",
240 "upload_" . $ilUser->getId() . "." . $pi["extension"]
241 );
242 if (!$uploaded_file) {
243 ilUtil::sendFailure($this->lng->txt("upload_error", true));
244 $this->ctrl->redirect($this, "showProfile");
245 }
246 chmod($uploaded_file, 0770);
247
248 // take quality 100 to avoid jpeg artefacts when uploading jpeg files
249 // taking only frame [0] to avoid problems with animated gifs
250 $show_file = "$image_dir/usr_" . $ilUser->getId() . ".jpg";
251 $thumb_file = "$image_dir/usr_" . $ilUser->getId() . "_small.jpg";
252 $xthumb_file = "$image_dir/usr_" . $ilUser->getId() . "_xsmall.jpg";
253 $xxthumb_file = "$image_dir/usr_" . $ilUser->getId() . "_xxsmall.jpg";
254 $uploaded_file = ilUtil::escapeShellArg($uploaded_file);
255 $show_file = ilUtil::escapeShellArg($show_file);
256 $thumb_file = ilUtil::escapeShellArg($thumb_file);
257 $xthumb_file = ilUtil::escapeShellArg($xthumb_file);
258 $xxthumb_file = ilUtil::escapeShellArg($xxthumb_file);
259
260 if (ilUtil::isConvertVersionAtLeast("6.3.8-3")) {
261 ilUtil::execConvert($uploaded_file . "[0] -geometry 200x200^ -gravity center -extent 200x200 -quality 100 JPEG:" . $show_file);
262 ilUtil::execConvert($uploaded_file . "[0] -geometry 100x100^ -gravity center -extent 100x100 -quality 100 JPEG:" . $thumb_file);
263 ilUtil::execConvert($uploaded_file . "[0] -geometry 75x75^ -gravity center -extent 75x75 -quality 100 JPEG:" . $xthumb_file);
264 ilUtil::execConvert($uploaded_file . "[0] -geometry 30x30^ -gravity center -extent 30x30 -quality 100 JPEG:" . $xxthumb_file);
265 } else {
266 ilUtil::execConvert($uploaded_file . "[0] -geometry 200x200 -quality 100 JPEG:" . $show_file);
267 ilUtil::execConvert($uploaded_file . "[0] -geometry 100x100 -quality 100 JPEG:" . $thumb_file);
268 ilUtil::execConvert($uploaded_file . "[0] -geometry 75x75 -quality 100 JPEG:" . $xthumb_file);
269 ilUtil::execConvert($uploaded_file . "[0] -geometry 30x30 -quality 100 JPEG:" . $xxthumb_file);
270 }
271 }
272 }
273
274 // $this->saveProfile();
275 }
276
280 public function removeUserPicture()
281 {
282 global $DIC;
283
284 $ilUser = $DIC['ilUser'];
285
286 $ilUser->removeUserPicture();
287
288 $this->saveProfile();
289 }
290
291
292
296 public function saveProfile()
297 {
298 global $DIC;
299
300 $ilUser = $DIC['ilUser'];
301
302 //init checking var
303 $form_valid = true;
304
305 // testing by ratana ty:
306 // if people check on check box it will
307 // write some datata to table usr_pref
308 // if check on Public Profile
309 if (($_POST["chk_pub"]) == "on") {
310 $ilUser->setPref("public_profile", "y");
311 } else {
312 $ilUser->setPref("public_profile", "n");
313 }
314
315 // if check on Institute
316 $val_array = array("institution", "department", "upload", "street",
317 "zip", "city", "country", "phone_office", "phone_home", "phone_mobile",
318 "fax", "email", "second_email", "hobby", "matriculation");
319
320 // set public profile preferences
321 foreach ($val_array as $key => $value) {
322 if (($_POST["chk_" . $value]) == "on") {
323 $ilUser->setPref("public_" . $value, "y");
324 } else {
325 $ilUser->setPref("public_" . $value, "n");
326 }
327 }
328
329 // check dynamically required fields
330 foreach ($this->settings as $key => $val) {
331 if (substr($key, 0, 8) == "require_") {
332 $require_keys[] = substr($key, 8);
333 }
334 }
335
336 foreach ($require_keys as $key => $val) {
337 // exclude required system and registration-only fields
338 $system_fields = array("login", "default_role", "passwd", "passwd2");
339 if (!in_array($val, $system_fields)) {
340 if ($this->workWithUserSetting($val)) {
341 if (isset($this->settings["require_" . $val]) && $this->settings["require_" . $val]) {
342 if (empty($_POST["usr_" . $val])) {
343 ilUtil::sendFailure($this->lng->txt("fill_out_all_required_fields") . ": " . $this->lng->txt($val));
344 $form_valid = false;
345 }
346 }
347 }
348 }
349 }
350
351 // Check user defined required fields
352 if ($form_valid and !$this->__checkUserDefinedRequiredFields()) {
353 ilUtil::sendFailure($this->lng->txt("fill_out_all_required_fields"));
354 $form_valid = false;
355 }
356
357 // check email
358 if ($this->workWithUserSetting("email")) {
359 if (!ilUtil::is_email($_POST["usr_email"]) and !empty($_POST["usr_email"]) and $form_valid) {
360 ilUtil::sendFailure($this->lng->txt("email_not_valid"));
361 $form_valid = false;
362 }
363 }
364 // check second email
365 if ($this->workWithUserSetting("second_email")) {
366 if (!ilUtil::is_email($_POST["usr_second_email"]) and !empty($_POST["usr_second_email"]) and $form_valid) {
367 ilUtil::sendFailure($this->lng->txt("second_email_not_valid"));
368 $form_valid = false;
369 }
370 }
371
372 //update user data (not saving!)
373 if ($this->workWithUserSetting("firstname")) {
374 $ilUser->setFirstName(ilUtil::stripSlashes($_POST["usr_firstname"]));
375 }
376 if ($this->workWithUserSetting("lastname")) {
377 $ilUser->setLastName(ilUtil::stripSlashes($_POST["usr_lastname"]));
378 }
379 if ($this->workWithUserSetting("gender")) {
380 $ilUser->setGender($_POST["usr_gender"]);
381 }
382 if ($this->workWithUserSetting("title")) {
383 $ilUser->setUTitle(ilUtil::stripSlashes($_POST["usr_title"]));
384 }
385 $ilUser->setFullname();
386 if ($this->workWithUserSetting("institution")) {
387 $ilUser->setInstitution(ilUtil::stripSlashes($_POST["usr_institution"]));
388 }
389 if ($this->workWithUserSetting("department")) {
390 $ilUser->setDepartment(ilUtil::stripSlashes($_POST["usr_department"]));
391 }
392 if ($this->workWithUserSetting("street")) {
393 $ilUser->setStreet(ilUtil::stripSlashes($_POST["usr_street"]));
394 }
395 if ($this->workWithUserSetting("zipcode")) {
396 $ilUser->setZipcode(ilUtil::stripSlashes($_POST["usr_zipcode"]));
397 }
398 if ($this->workWithUserSetting("city")) {
399 $ilUser->setCity(ilUtil::stripSlashes($_POST["usr_city"]));
400 }
401 if ($this->workWithUserSetting("country")) {
402 $ilUser->setCountry(ilUtil::stripSlashes($_POST["usr_country"]));
403 }
404 if ($this->workWithUserSetting("phone_office")) {
405 $ilUser->setPhoneOffice(ilUtil::stripSlashes($_POST["usr_phone_office"]));
406 }
407 if ($this->workWithUserSetting("phone_home")) {
408 $ilUser->setPhoneHome(ilUtil::stripSlashes($_POST["usr_phone_home"]));
409 }
410 if ($this->workWithUserSetting("phone_mobile")) {
411 $ilUser->setPhoneMobile(ilUtil::stripSlashes($_POST["usr_phone_mobile"]));
412 }
413 if ($this->workWithUserSetting("fax")) {
414 $ilUser->setFax(ilUtil::stripSlashes($_POST["usr_fax"]));
415 }
416 if ($this->workWithUserSetting("email")) {
417 $ilUser->setEmail(ilUtil::stripSlashes($_POST["usr_email"]));
418 }
419 if ($this->workWithUserSetting("second_email")) {
420 $ilUser->setSecondEmail(ilUtil::stripSlashes($_POST["usr_second_email"]));
421 }
422 if ($this->workWithUserSetting("hobby")) {
423 $ilUser->setHobby(ilUtil::stripSlashes($_POST["usr_hobby"]));
424 }
425 if ($this->workWithUserSetting("referral_comment")) {
426 $ilUser->setComment(ilUtil::stripSlashes($_POST["usr_referral_comment"]));
427 }
428 if ($this->workWithUserSetting("matriculation")) {
429 $ilUser->setMatriculation(ilUtil::stripSlashes($_POST["usr_matriculation"]));
430 }
431
432 // Set user defined data
433 $ilUser->setUserDefinedData($_POST['udf']);
434
435 // everthing's ok. save form data
436 if ($form_valid) {
437 // init reload var. page should only be reloaded if skin or style were changed
438 $reload = false;
439
440 if ($this->workWithUserSetting("skin_style")) {
441 //set user skin and style
442 if ($_POST["usr_skin_style"] != "") {
443 $sknst = explode(":", $_POST["usr_skin_style"]);
444
445 if ($ilUser->getPref("style") != $sknst[1] ||
446 $ilUser->getPref("skin") != $sknst[0]) {
447 $ilUser->setPref("skin", $sknst[0]);
448 $ilUser->setPref("style", $sknst[1]);
449 $reload = true;
450 }
451 }
452 }
453
454 if ($this->workWithUserSetting("language")) {
455 // reload page if language was changed
456 //if ($_POST["usr_language"] != "" and $_POST["usr_language"] != $_SESSION['lang'])
457 // (this didn't work as expected, alex)
458 if ($_POST["usr_language"] != $ilUser->getLanguage()) {
459 $reload = true;
460 }
461
462 // set user language
463 $ilUser->setLanguage($_POST["usr_language"]);
464 }
465 if ($this->workWithUserSetting("hits_per_page")) {
466 // set user hits per page
467 if ($_POST["hits_per_page"] != "") {
468 $ilUser->setPref("hits_per_page", $_POST["hits_per_page"]);
469 }
470 }
471
472 // set show users online
473 /*if ($this->workWithUserSetting("show_users_online"))
474 {
475 $ilUser->setPref("show_users_online", $_POST["show_users_online"]);
476 }*/
477
478 // set hide own online_status
479 if ($this->workWithUserSetting("hide_own_online_status")) {
480 if ($_POST["chk_hide_own_online_status"] != "") {
481 $ilUser->setPref("hide_own_online_status", "y");
482 } else {
483 $ilUser->setPref("hide_own_online_status", "n");
484 }
485 }
486
487 // personal desktop items in news block
488 /* Subscription Concept is abandonded for now, we show all news of pd items (Alex)
489 if ($_POST["pd_items_news"] != "")
490 {
491 $ilUser->setPref("pd_items_news","y");
492 }
493 else
494 {
495 $ilUser->setPref("pd_items_news","n");
496 }
497 */
498
499 // profile ok
500 $ilUser->setProfileIncomplete(false);
501
502 // save user data & object_data
503 $ilUser->setTitle($ilUser->getFullname());
504 $ilUser->setDescription($ilUser->getEmail());
505
506 $ilUser->update();
507
508 // update lucene index
509 include_once './Services/Search/classes/Lucene/class.ilLuceneIndexer.php';
510 ilLuceneIndexer::updateLuceneIndex(array($GLOBALS['DIC']['ilUser']->getId()));
511
512
513 // reload page only if skin or style were changed
514 // feedback
515 if (!empty($this->password_error)) {
516 ilUtil::sendFailure($this->password_error, true);
517 } elseif (!empty($this->upload_error)) {
518 ilUtil::sendFailure($this->upload_error, true);
519 } elseif ($reload) {
520 // feedback
521 ilUtil::sendSuccess($this->lng->txt("saved_successfully"), true);
522 $this->ctrl->redirect($this, "");
523 } else {
524 ilUtil::sendSuccess($this->lng->txt("saved_successfully"), true);
525 }
526 }
527
528 $this->showProfile();
529 }
530
536 public function showProfile()
537 {
538 $this->showPersonalData();
539 }
540
541 protected function showUserAgreement()
542 {
543 $this->tabs->clearTargets();
544 $this->tabs->clearSubTabs();
545
546 $tpl = new \ilTemplate('tpl.view_terms_of_service.html', true, true, 'Services/Init');
547
548 $this->tpl->setTitle($this->lng->txt('usr_agreement'));
549
550 $noAgreement = true;
551 if (!$this->user->isAnonymous() && (int) $this->user->getId() > 0 && $this->user->getAgreeDate()) {
552 $helper = new \ilTermsOfServiceHelper();
553
554 $entity = $helper->getCurrentAcceptanceForUser($this->user);
555 if ($entity->getId()) {
556 $noAgreement = false;
557 $tpl->setVariable('TERMS_OF_SERVICE_CONTENT', $entity->getText());
558 }
559 } else {
560 $handleDocument = \ilTermsOfServiceHelper::isEnabled() && $this->termsOfServiceEvaluation->hasDocument();
561 if ($handleDocument) {
562 $noAgreement = false;
563 $document = $this->termsOfServiceEvaluation->document();
564 $tpl->setVariable('TERMS_OF_SERVICE_CONTENT', $document->content());
565 }
566 }
567
568 if ($noAgreement) {
569 $tpl->setVariable(
570 'TERMS_OF_SERVICE_CONTENT',
571 sprintf(
572 $this->lng->txt('no_agreement_description'),
574 )
575 );
576 }
577
578 $this->tpl->setContent($tpl->get());
579 $this->tpl->setPermanentLink('usr', null, 'agreement');
580 $this->tpl->printToStdout();
581 }
582
583 protected function showConsentWithdrawalConfirmation() : void
584 {
585 if (
586 !$this->user->getPref('consent_withdrawal_requested') ||
587 !$this->termsOfServiceHelper->isIncludedUser($this->user)
588 ) {
589 $this->errorHandler->raiseError($this->lng->txt('permission_denied'), $this->errorHandler->MESSAGE);
590 }
591
592 $this->tabs->clearTargets();
593 $this->tabs->clearSubTabs();
594 $this->tpl->setTitle($this->lng->txt('refuse_tos_acceptance'));
595
596 $tosWithdrawalGui = new ilTermsOfServiceWithdrawalGUIHelper($this->user);
597 $content = $tosWithdrawalGui->getConsentWithdrawalConfirmation($this);
598
599 $this->tpl->setContent($content);
600 $this->tpl->setPermanentLink('usr', null, 'agreement');
601 $this->tpl->printToStdout();
602 }
603
604 protected function cancelWithdrawal() : void
605 {
606 if (!$this->termsOfServiceHelper->isIncludedUser($this->user)) {
607 $this->errorHandler->raiseError($this->lng->txt('permission_denied'), $this->errorHandler->MESSAGE);
608 }
609
610 $this->user->deletePref('consent_withdrawal_requested');
611
612 if (ilSession::get('orig_request_target')) {
613 $target = ilSession::get('orig_request_target');
614 ilSession::set('orig_request_target', '');
615 $this->ctrl->redirectToUrl($target);
616 } else {
617 ilInitialisation::redirectToStartingPage();
618 }
619 }
620
621 protected function withdrawAcceptance() : void
622 {
623 if (
624 !$this->user->getPref('consent_withdrawal_requested') ||
625 !$this->termsOfServiceHelper->isIncludedUser($this->user)
626 ) {
627 $this->errorHandler->raiseError($this->lng->txt('permission_denied'), $this->errorHandler->MESSAGE);
628 }
629 $this->termsOfServiceHelper->resetAcceptance($this->user);
630
631 $defaultAuth = AUTH_LOCAL;
632 if ($this->setting->get('auth_mode')) {
633 $defaultAuth = $this->setting->get('auth_mode');
634 }
635
636 $withdrawalType = 0;
637 if (
638 $this->user->getAuthMode() == AUTH_LDAP ||
639 ($this->user->getAuthMode() === 'default' && $defaultAuth == AUTH_LDAP)
640 ) {
641 $withdrawalType = 2;
642 } elseif ((bool) $this->setting->get('tos_withdrawal_usr_deletion', false)) {
643 $withdrawalType = 1;
644 }
645
646 $domainEvent = new ilTermsOfServiceEventWithdrawn($this->user);
647 $this->eventHandler->raise(
648 'Services/TermsOfService',
649 'ilTermsOfServiceEventWithdrawn',
650 ['event' => $domainEvent]
651 );
652
654 $this->auth_session->logout();
655
656 $this->ctrl->redirectToUrl('login.php?tos_withdrawal_type=' . $withdrawalType . '&cmd=force_login');
657 }
658
665 public function addLocationToForm(ilPropertyFormGUI $a_form, ilObjUser $a_user)
666 {
667 global $DIC;
668
669 $ilCtrl = $DIC['ilCtrl'];
670
671 // check map activation
672 include_once("./Services/Maps/classes/class.ilMapUtil.php");
673 if (!ilMapUtil::isActivated()) {
674 return;
675 }
676
677 // Don't really know if this is still necessary...
678 $this->lng->loadLanguageModule("maps");
679
680 // Get user settings
681 $latitude = $a_user->getLatitude();
682 $longitude = $a_user->getLongitude();
683 $zoom = $a_user->getLocationZoom();
684
685 // Get Default settings, when nothing is set
686 if ($latitude == 0 && $longitude == 0 && $zoom == 0) {
688 $latitude = $def["latitude"];
689 $longitude = $def["longitude"];
690 $zoom = $def["zoom"];
691 }
692
693 $street = $a_user->getStreet();
694 if (!$street) {
695 $street = $this->lng->txt("street");
696 }
697 $city = $a_user->getCity();
698 if (!$city) {
699 $city = $this->lng->txt("city");
700 }
701 $country = $a_user->getCountry();
702 if (!$country) {
703 $country = $this->lng->txt("country");
704 }
705
706 // location property
707 $loc_prop = new ilLocationInputGUI(
708 $this->lng->txt("location"),
709 "location"
710 );
711 $loc_prop->setLatitude($latitude);
712 $loc_prop->setLongitude($longitude);
713 $loc_prop->setZoom($zoom);
714 $loc_prop->setAddress($street . "," . $city . "," . $country);
715
716 $a_form->addItem($loc_prop);
717 }
718
719 // init sub tabs
720 public function setTabs()
721 {
722 global $DIC;
723
724 $ilTabs = $DIC['ilTabs'];
725 $ilHelp = $DIC['ilHelp'];
726
727 $ilHelp->setScreenIdComponent("user");
728
729 // personal data
730 $ilTabs->addTab(
731 "personal_data",
732 $this->lng->txt("user_profile_data"),
733 $this->ctrl->getLinkTarget($this, "showPersonalData")
734 );
735
736 // publishing options
737 $ilTabs->addTab(
738 "public_profile",
739 $this->lng->txt("user_publish_options"),
740 $this->ctrl->getLinkTarget($this, "showPublicProfile")
741 );
742
743 // visibility settings
744 $txt_visibility = $this->checklist_status->anyVisibilitySettings()
745 ? $this->lng->txt("user_visibility_settings")
746 : $this->lng->txt("preview");
747 $ilTabs->addTab(
748 "visibility_settings",
749 $txt_visibility,
750 $this->ctrl->getLinkTargetByClass("ilUserPrivacySettingsGUI", "")
751 );
752
753 // export
754 $ilTabs->addTab(
755 "export",
756 $this->lng->txt("export") . "/" . $this->lng->txt("import"),
757 $this->ctrl->getLinkTarget($this, "showExportImport")
758 );
759 }
760
761
762 public function __showOtherInformations()
763 {
764 $d_set = new ilSetting("delicous");
765 if ($this->userSettingVisible("matriculation") or count($this->user_defined_fields->getVisibleDefinitions())
766 or $d_set->get("user_profile") == "1") {
767 return true;
768 }
769 return false;
770 }
771
772 public function __showUserDefinedFields()
773 {
774 global $DIC;
775
776 $ilUser = $DIC['ilUser'];
777
778 $user_defined_data = $ilUser->getUserDefinedData();
779 foreach ($this->user_defined_fields->getVisibleDefinitions() as $field_id => $definition) {
780 if ($definition['field_type'] == UDF_TYPE_TEXT) {
781 $this->tpl->setCurrentBlock("field_text");
782 $this->tpl->setVariable("FIELD_VALUE", ilUtil::prepareFormOutput($user_defined_data[$field_id]));
783 if (!$definition['changeable']) {
784 $this->tpl->setVariable("DISABLED_FIELD", 'disabled=\"disabled\"');
785 $this->tpl->setVariable("FIELD_NAME", 'udf[' . $definition['field_id'] . ']');
786 } else {
787 $this->tpl->setVariable("FIELD_NAME", 'udf[' . $definition['field_id'] . ']');
788 }
789 $this->tpl->parseCurrentBlock();
790 } else {
791 if ($definition['changeable']) {
792 $name = 'udf[' . $definition['field_id'] . ']';
793 $disabled = false;
794 } else {
795 $name = '';
796 $disabled = true;
797 }
798 $this->tpl->setCurrentBlock("field_select");
799 $this->tpl->setVariable("SELECT_BOX", ilUtil::formSelect(
800 $user_defined_data[$field_id],
801 $name,
802 $this->user_defined_fields->fieldValuesToSelectArray(
803 $definition['field_values']
804 ),
805 false,
806 true,
807 0,
808 '',
809 '',
810 $disabled
811 ));
812 $this->tpl->parseCurrentBlock();
813 }
814 $this->tpl->setCurrentBlock("user_defined");
815
816 if ($definition['required']) {
817 $name = $definition['field_name'] . "<span class=\"asterisk\">*</span>";
818 } else {
819 $name = $definition['field_name'];
820 }
821 $this->tpl->setVariable("TXT_FIELD_NAME", $name);
822 $this->tpl->parseCurrentBlock();
823 }
824 return true;
825 }
826
828 {
829 foreach ($this->user_defined_fields->getVisibleDefinitions() as $definition) {
830 $field_id = $definition['field_id'];
831 if ($definition['required'] and !strlen($_POST['udf'][$field_id])) {
832 return false;
833 }
834 }
835 return true;
836 }
837
841 public function setHeader()
842 {
843 $this->tpl->setTitle($this->lng->txt('personal_profile'));
844 }
845
846 //
847 //
848 // PERSONAL DATA FORM
849 //
850 //
851
855 public function showPersonalData($a_no_init = false, $a_migration_started = false)
856 {
857 global $DIC;
858
859 $ilUser = $DIC['ilUser'];
860 $lng = $DIC['lng'];
861 $ilTabs = $DIC['ilTabs'];
862 $prompt_service = new ilUserProfilePromptService();
863
864 $ilTabs->activateTab("personal_data");
865 $ctrl = $DIC->ctrl();
866
867 $it = "";
868 if ($_GET["prompted"] == 1) {
869 $it = $prompt_service->data()->getSettings()->getPromptText($ilUser->getLanguage());
870 }
871 if ($it === "") {
872 $it = $prompt_service->data()->getSettings()->getInfoText($ilUser->getLanguage());
873 }
874 if (trim($it) !== "") {
875 $pub_prof = in_array($ilUser->prefs["public_profile"], array("y", "n", "g"))
876 ? $ilUser->prefs["public_profile"]
877 : "n";
878 $box = $DIC->ui()->factory()->messageBox()->info($it);
879 if ($pub_prof === "n") {
880 $box = $box->withLinks(
881 [$DIC->ui()->factory()->link()->standard(
882 $lng->txt("user_make_profile_public"),
883 $ctrl->getLinkTarget($this, "showPublicProfile")
884 )]
885 );
886 }
887 $it = $DIC->ui()->renderer()->render($box);
888 }
889 $this->setHeader();
890
892
893 if (!$a_no_init) {
894 $this->initPersonalDataForm();
895 // catch feedback message
896 if ($ilUser->getProfileIncomplete()) {
897 ilUtil::sendInfo($lng->txt("profile_incomplete"));
898 }
899 }
900
901 $modal = '';
902 if ($this->email_change_confirmation_modal !== null) {
903 $modal = $this->ui_renderer->render($this->email_change_confirmation_modal);
904 }
905
906 $this->tpl->setContent($it . $this->form->getHTML() . $modal);
907 $this->tpl->printToStdout();
908 }
909
913 public function initPersonalDataForm()
914 {
915 global $DIC;
916 $lng = $DIC['lng'];
917 $ilUser = $DIC['ilUser'];
918
919 $this->form = new ilPropertyFormGUI();
920 $this->form->setFormAction($this->ctrl->getFormAction($this));
921 $this->form->setId(self::PERSONAL_DATA_FORM_ID);
922
923 // user defined fields
924 $user_defined_data = $ilUser->getUserDefinedData();
925
926
927 foreach ($this->user_defined_fields->getVisibleDefinitions() as $field_id => $definition) {
928 $value = $user_defined_data["f_" . $field_id];
929
930 include_once './Services/User/classes/class.ilCustomUserFieldsHelper.php';
931 $fprop = ilCustomUserFieldsHelper::getInstance()->getFormPropertyForDefinition(
932 $definition,
933 $definition['changeable'],
934 $value
935 );
936 if ($fprop instanceof ilFormPropertyGUI) {
937 $this->input['udf_' . $definition['field_id']] = $fprop;
938 }
939 }
940
941 // standard fields
942 include_once("./Services/User/classes/class.ilUserProfile.php");
943 $up = new ilUserProfile();
944 $up->skipField("password");
945 $up->skipGroup("settings");
946 $up->skipGroup("preferences");
947
948 $up->setAjaxCallback(
949 $this->ctrl->getLinkTargetByClass('ilPublicUserProfileGUI', 'doProfileAutoComplete', '', true)
950 );
951
952 // standard fields
953 $up->addStandardFieldsToForm($this->form, $ilUser, $this->input);
954
955 $this->addLocationToForm($this->form, $ilUser);
956
957 $this->form->addCommandButton("savePersonalData", $lng->txt("user_save_continue"));
958 }
959
964 public function savePersonalData()
965 {
966 $this->initPersonalDataForm();
967
968 if (!$this->form->checkInput()
969 || !$this->emailCompletionForced()
970 && $this->emailChanged()
971 && $this->addEmailChangeModal()
972 || $this->loginChanged() && !$this->updateLoginOrSetErrorMessages()) {
973 $this->form->setValuesByPost();
974 $this->showPersonalData(true);
975 return;
976 }
977 $this->savePersonalDataForm();
978
979 $this->checklist_status->saveStepSucess(ilProfileChecklistStatus::STEP_PROFILE_DATA);
980 $this->tpl->setOnScreenMessage('success', $this->lng->txt("msg_obj_modified"), true);
981
982 $this->ctrl->redirect($this, "showPublicProfile");
983 }
984
985 private function emailChanged() : bool
986 {
987 $email_input = $this->form->getItemByPostVar('usr_email');
988 if ($email_input !== null
989 && $email_input !== false
990 && !$email_input->getDisabled()
991 && $this->form->getInput('usr_email') !== $this->user->getEmail()) {
992 return true;
993 }
994
995 return false;
996 }
997
998 private function emailCompletionForced() : bool
999 {
1000 $current_email = $this->user->getEmail();
1001 if (
1002 $this->user->getProfileIncomplete()
1003 && $this->setting->get('require_email') === '1'
1004 && ($current_email === null || $current_email === '')
1005 ) {
1006 return true;
1007 }
1008
1009 return false;
1010 }
1011
1012 private function addEmailChangeModal() : bool
1013 {
1014 $form_id = 'form_' . self::PERSONAL_DATA_FORM_ID;
1015 $modal = $this->ui_factory->modal()->interruptive(
1016 $this->lng->txt('confirm'),
1017 $this->lng->txt('confirm_logout_for_email_change'),
1018 '#'
1019 )->withActionButtonLabel('change');
1020 $this->email_change_confirmation_modal = $modal->withOnLoad($modal->getShowSignal())
1021 ->withAdditionalOnLoadCode(
1022 static function ($id) use ($form_id) {
1023 return "var button = {$id}.querySelector('input[type=\"submit\"]'); "
1024 . "button.addEventListener('click', (e) => {e.preventDefault();"
1025 . "document.getElementById('{$form_id}').submit();});";
1026 }
1027 );
1028
1029 $this->form->setFormAction($this->ctrl->getFormActionByClass(self::class, 'goToEmailConfirmation'));
1030 return true;
1031 }
1032
1033 private function loginChanged() : bool
1034 {
1035 $login = $this->form->getInput('username');
1036 if ((int) $this->setting->get('allow_change_loginname')
1037 && $login !== $this->user->getLogin()) {
1038 return true;
1039 }
1040
1041 return false;
1042 }
1043
1044 private function updateLoginOrSetErrorMessages() : bool
1045 {
1046 $login = $this->form->getInput('username');
1047 if ($login === '' || !ilUtil::isLogin($login)) {
1048 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('form_input_not_valid'));
1049 $this->form->getItemByPostVar('username')->setAlert($this->lng->txt('login_invalid'));
1050 return false;
1051 }
1052
1053 if (ilObjUser::_loginExists($login, $this->user->getId())) {
1054 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('form_input_not_valid'));
1055 $this->form->getItemByPostVar('username')->setAlert($this->lng->txt('loginname_already_exists'));
1056 return false;
1057 }
1058
1059 $this->user->setLogin($login);
1060
1061 try {
1062 $this->user->updateLogin($this->user->getLogin());
1063 return true;
1064 } catch (ilUserException $e) {
1065 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('form_input_not_valid'));
1066 $this->form->getItemByPostVar('username')->setAlert($e->getMessage());
1067 return false;
1068 }
1069 }
1070
1071 public function goToEmailConfirmation() : void
1072 {
1073 $this->initPersonalDataForm();
1074 if (!$this->form->checkInput()
1075 || $this->loginChanged() && !$this->updateLoginOrSetErrorMessages()) {
1076 $this->form->setValuesByPost();
1077 $this->showPersonalData(true);
1078 return;
1079 }
1080 $this->savePersonalDataForm();
1081
1083 $this->auth_session->logout();
1084 session_unset();
1085 $token = $this->change_mail_token_repo->getNewTokenForUser($this->user, $this->form->getInput('usr_email'));
1086 $this->ctrl->redirectToURL('login.php?cmd=force_login&target=usr_' . self::CHANGE_EMAIL_CMD . $token);
1087 }
1088
1089 private function savePersonalDataForm() : void
1090 {
1091 // if form field name differs from setter
1092 $map = [
1093 "firstname" => "FirstName",
1094 "lastname" => "LastName",
1095 "title" => "UTitle",
1096 "sel_country" => "SelectedCountry",
1097 "phone_office" => "PhoneOffice",
1098 "phone_home" => "PhoneHome",
1099 "phone_mobile" => "PhoneMobile",
1100 "referral_comment" => "Comment",
1101 "interests_general" => "GeneralInterests",
1102 "interests_help_offered" => "OfferingHelp",
1103 "interests_help_looking" => "LookingForHelp"
1104 ];
1105 $up = new ilUserProfile();
1106 foreach (array_keys($up->getStandardFields()) as $f) {
1107 // if item is part of form, it is currently valid (if not disabled)
1108 $item = $this->form->getItemByPostVar("usr_" . $f);
1109 if (!$item || $item->getDisabled()) {
1110 continue;
1111 }
1112
1113 $value = $this->form->getInput("usr_" . $f);
1114 switch ($f) {
1115 case 'email':
1116 if ($this->emailCompletionForced()) {
1117 $this->user->setEmail($value);
1118 }
1119
1120 break;
1121 case "birthday":
1122 $value = $item->getDate();
1123 $this->user->setBirthday($value
1124 ? $value->get(IL_CAL_DATE)
1125 : "");
1126 break;
1127 case "second_email":
1128 $this->user->setSecondEmail($value);
1129 break;
1130 default:
1131 $m = $map[$f] ?? ucfirst($f);
1132 $this->user->{"set" . $m}($value);
1133 break;
1134 }
1135 }
1136 $this->user->setFullname();
1137
1138 // check map activation
1139 if (ilMapUtil::isActivated()) {
1140 // #17619 - proper escaping
1141 $location = $this->form->getInput("location");
1142 $lat = ilUtil::stripSlashes($location["latitude"]);
1143 $long = ilUtil::stripSlashes($location["longitude"]);
1144 $zoom = ilUtil::stripSlashes($location["zoom"]);
1145 $this->user->setLatitude(is_numeric($lat) ? $lat : null);
1146 $this->user->setLongitude(is_numeric($long) ? $long : null);
1147 $this->user->setLocationZoom(is_numeric($zoom) ? $zoom : null);
1148 }
1149
1150 // Set user defined data
1151 $defs = $this->user_defined_fields->getVisibleDefinitions();
1152 $udf = [];
1153 foreach ($defs as $definition) {
1154 $f = "udf_" . $definition['field_id'];
1155 $item = $this->form->getItemByPostVar($f);
1156 if ($item && !$item->getDisabled()) {
1157 $udf[$definition['field_id']] = $this->form->getInput($f);
1158 }
1159 }
1160 $this->user->setUserDefinedData($udf);
1161
1162 $this->uploadUserPicture();
1163
1164 // profile ok
1165 $this->user->setProfileIncomplete(false);
1166
1167 // save user data & object_data
1168 $this->user->setTitle($this->user->getFullname());
1169 $this->user->setDescription($this->user->getEmail());
1170
1171 $this->user->update();
1172 }
1173
1174 public function changeEmail() : void
1175 {
1176 $token = $_GET['token'];
1177 $new_email = $this->change_mail_token_repo->getNewEmailForUser($this->user, $token);
1178
1179 if ($new_email !== '') {
1180 $this->user->setEmail($new_email);
1181 $this->user->update();
1182 $this->change_mail_token_repo->deleteEntryByToken($token);
1183 $this->tpl->setOnScreenMessage(
1184 'success',
1185 $this->lng->txt('saved_successfully')
1186 );
1187 $this->showPublicProfile();
1188 return;
1189 }
1190
1191 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('email_could_not_be_changed'));
1192 $this->showPublicProfile();
1193 }
1194
1195 //
1196 //
1197 // PUBLIC PROFILE FORM
1198 //
1199 //
1200
1204 public function showPublicProfile($a_no_init = false)
1205 {
1206 $ilTabs = $this->tabs;
1207
1208 $ilTabs->activateTab("public_profile");
1210
1211 $this->setHeader();
1212
1213 if (!$a_no_init) {
1214 $this->initPublicProfileForm();
1215 }
1216
1217 $this->tpl->setContent($this->form->getHTML());
1218 $this->tpl->printToStdout();
1219 }
1220
1226 protected function getProfilePortfolio()
1227 {
1228 global $DIC;
1229
1230 $ilUser = $DIC['ilUser'];
1231 $ilSetting = $DIC['ilSetting'];
1232
1233 if ($ilSetting->get('user_portfolios')) {
1234 include_once "Modules/Portfolio/classes/class.ilObjPortfolio.php";
1236 }
1237 }
1238
1244 public function initPublicProfileForm()
1245 {
1246 global $DIC;
1247
1248 $lng = $DIC['lng'];
1249 $ilUser = $DIC['ilUser'];
1250 $ilSetting = $DIC['ilSetting'];
1251
1252 include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
1253 $this->form = new ilPropertyFormGUI();
1254
1255 $this->form->setTitle($lng->txt("user_publish_options"));
1256 $this->form->setDescription($lng->txt("user_public_profile_info"));
1257 $this->form->setFormAction($this->ctrl->getFormAction($this));
1258
1259 $portfolio_id = $this->getProfilePortfolio();
1260
1261 if (!$portfolio_id) {
1262 // Activate public profile
1263 $radg = new ilRadioGroupInputGUI($lng->txt("user_activate_public_profile"), "public_profile");
1264 $info = $this->lng->txt("user_activate_public_profile_info");
1265 $profile_mode = new ilPersonalProfileMode($ilUser, $ilSetting);
1266 $pub_prof = $profile_mode->getMode();
1267 $radg->setValue($pub_prof);
1268 $op1 = new ilRadioOption($lng->txt("usr_public_profile_disabled"), "n", $lng->txt("usr_public_profile_disabled_info"));
1269 $radg->addOption($op1);
1270 $op2 = new ilRadioOption($lng->txt("usr_public_profile_logged_in"), "y");
1271 $radg->addOption($op2);
1272 if ($ilSetting->get('enable_global_profiles')) {
1273 $op3 = new ilRadioOption($lng->txt("usr_public_profile_global"), "g");
1274 $radg->addOption($op3);
1275 }
1276 $this->form->addItem($radg);
1277
1278 // #11773
1279 if ($ilSetting->get('user_portfolios')) {
1280 // #10826
1281 $prtf = "<br />" . $lng->txt("user_profile_portfolio");
1282 $prtf .= "<br /><a href=\"ilias.php?baseClass=ilDashboardGUI&cmd=jumpToPortfolio\">&raquo; " .
1283 $lng->txt("user_portfolios") . "</a>";
1284 $info .= $prtf;
1285 }
1286
1287 $radg->setInfo($info);
1288 } else {
1289 $prtf = $lng->txt("user_profile_portfolio_selected");
1290 $prtf .= "<br /><a href=\"ilias.php?baseClass=ilDashboardGUI&cmd=jumpToPortfolio&prt_id=" . $portfolio_id . "\">&raquo; " .
1291 $lng->txt("portfolio") . "</a>";
1292
1293 $info = new ilCustomInputGUI($lng->txt("user_activate_public_profile"));
1294 $info->setHTML($prtf);
1295 $this->form->addItem($info);
1296 $this->showPublicProfileFields($this->form, $ilUser->prefs);
1297 }
1298
1299 if (is_object($op2)) {
1300 $this->showPublicProfileFields($this->form, $ilUser->prefs, $op2, false, "-1");
1301 }
1302 if (is_object($op3)) {
1303 $this->showPublicProfileFields($this->form, $ilUser->prefs, $op3, false, "-2");
1304 }
1305 $this->form->setForceTopButtons(true);
1306 $this->form->addCommandButton("savePublicProfile", $lng->txt("user_save_continue"));
1307 }
1308
1318 ilPropertyformGUI $form,
1319 array $prefs,
1320 $parent = null,
1321 $anonymized = false,
1322 $key_suffix = ""
1323 ) {
1324 global $DIC;
1325
1326 $ilUser = $DIC['ilUser'];
1327
1328 $birthday = $ilUser->getBirthday();
1329 if ($birthday) {
1330 $birthday = ilDatePresentation::formatDate(new ilDate($birthday, IL_CAL_DATE));
1331 }
1332 $gender = $ilUser->getGender();
1333 if ($gender) {
1334 $gender = $this->lng->txt("gender_" . $gender);
1335 }
1336
1337 if ($ilUser->getSelectedCountry() != "") {
1338 $this->lng->loadLanguageModule("meta");
1339 $txt_sel_country = $this->lng->txt("meta_c_" . $ilUser->getSelectedCountry());
1340 }
1341
1342 // profile picture
1343 $pic = ilObjUser::_getPersonalPicturePath($ilUser->getId(), "xsmall", true, true);
1344 if ($pic) {
1345 $pic = "<img src=\"" . $pic . "\" />";
1346 }
1347
1348 // personal data
1349 $val_array = array(
1350 "title" => $ilUser->getUTitle(),
1351 "birthday" => $birthday,
1352 "gender" => $gender,
1353 "upload" => $pic,
1354 "interests_general" => $ilUser->getGeneralInterestsAsText(),
1355 "interests_help_offered" => $ilUser->getOfferingHelpAsText(),
1356 "interests_help_looking" => $ilUser->getLookingForHelpAsText(),
1357 "org_units" => $ilUser->getOrgUnitsRepresentation(),
1358 "institution" => $ilUser->getInstitution(),
1359 "department" => $ilUser->getDepartment(),
1360 "street" => $ilUser->getStreet(),
1361 "zipcode" => $ilUser->getZipcode(),
1362 "city" => $ilUser->getCity(),
1363 "country" => $ilUser->getCountry(),
1364 "sel_country" => $txt_sel_country,
1365 "phone_office" => $ilUser->getPhoneOffice(),
1366 "phone_home" => $ilUser->getPhoneHome(),
1367 "phone_mobile" => $ilUser->getPhoneMobile(),
1368 "fax" => $ilUser->getFax(),
1369 "email" => $ilUser->getEmail(),
1370 "second_email" => $ilUser->getSecondEmail(),
1371 "hobby" => $ilUser->getHobby(),
1372 "matriculation" => $ilUser->getMatriculation()
1373 );
1374
1375 // location
1376 include_once("./Services/Maps/classes/class.ilMapUtil.php");
1377 if (ilMapUtil::isActivated()) {
1378 $val_array["location"] = ((int) $ilUser->getLatitude() + (int) $ilUser->getLongitude() + (int) $ilUser->getLocationZoom() > 0)
1379 ? " "
1380 : "";
1381 }
1382 foreach ($val_array as $key => $value) {
1383 if (in_array($value, ["", "-"]) && !$anonymized) {
1384 continue;
1385 }
1386 if ($anonymized) {
1387 $value = null;
1388 }
1389
1390 if ($this->userSettingVisible($key)) {
1391 // #18795 - we should use ilUserProfile
1392 switch ($key) {
1393 case "upload":
1394 $caption = "personal_picture";
1395 break;
1396
1397 case "title":
1398 $caption = "person_title";
1399 break;
1400
1401 default:
1402 $caption = $key;
1403 }
1404 $cb = new ilCheckboxInputGUI($this->lng->txt($caption), "chk_" . $key . $key_suffix);
1405 if ($prefs["public_" . $key] == "y") {
1406 $cb->setChecked(true);
1407 }
1408 //$cb->setInfo($value);
1409 $cb->setOptionTitle($value);
1410
1411 if (!$parent) {
1412 $form->addItem($cb);
1413 } else {
1414 $parent->addSubItem($cb);
1415 }
1416 }
1417 }
1418
1419 // additional defined user data fields
1420 $user_defined_data = array();
1421 if (!$anonymized) {
1422 $user_defined_data = $ilUser->getUserDefinedData();
1423 }
1424 foreach ($this->user_defined_fields->getVisibleDefinitions() as $field_id => $definition) {
1425 // public setting
1426 $cb = new ilCheckboxInputGUI($definition["field_name"], "chk_udf_" . $definition["field_id"]);
1427 $cb->setOptionTitle($user_defined_data["f_" . $definition["field_id"]]);
1428 if ($prefs["public_udf_" . $definition["field_id"]] == "y") {
1429 $cb->setChecked(true);
1430 }
1431
1432 if (!$parent) {
1433 $form->addItem($cb);
1434 } else {
1435 $parent->addSubItem($cb);
1436 }
1437 }
1438
1439 if (!$anonymized) {
1440 include_once "Services/Badge/classes/class.ilBadgeHandler.php";
1441 $handler = ilBadgeHandler::getInstance();
1442 if ($handler->isActive()) {
1443 $badge_options = array();
1444
1445 include_once "Services/Badge/classes/class.ilBadgeAssignment.php";
1446 include_once "Services/Badge/classes/class.ilBadge.php";
1447 foreach (ilBadgeAssignment::getInstancesByUserId($ilUser->getId()) as $ass) {
1448 // only active
1449 if ($ass->getPosition()) {
1450 $badge = new ilBadge($ass->getBadgeId());
1451 $badge_options[] = $badge->getTitle();
1452 }
1453 }
1454
1455 if (sizeof($badge_options) > 1) {
1456 $badge_order = new ilNonEditableValueGUI($this->lng->txt("obj_bdga"), "bpos" . $key_suffix);
1457 $badge_order->setMultiValues($badge_options);
1458 $badge_order->setValue(array_shift($badge_options));
1459 $badge_order->setMulti(true, true, false);
1460
1461 if (!$parent) {
1462 $form->addItem($badge_order);
1463 } else {
1464 $parent->addSubItem($badge_order);
1465 }
1466 }
1467 }
1468 }
1469
1470 // permalink
1471 $ne = new ilNonEditableValueGUI($this->lng->txt("perma_link"), "");
1472 $ne->setValue(ilLink::_getLink($this->user->getId(), "usr"));
1473 if (!$parent) {
1474 $form->addItem($ne);
1475 } else {
1476 $parent->addSubItem($ne);
1477 }
1478 }
1479
1484 public function savePublicProfile()
1485 {
1486 global $DIC;
1487
1488 $tpl = $DIC['tpl'];
1489 $lng = $DIC['lng'];
1490 $ilCtrl = $DIC['ilCtrl'];
1491 $ilUser = $DIC['ilUser'];
1492
1493 $this->initPublicProfileForm();
1494 if ($this->form->checkInput()) {
1495 // with active portfolio no options are presented
1496 if (isset($_POST["public_profile"])) {
1497 $ilUser->setPref("public_profile", $_POST["public_profile"]);
1498 }
1499
1500 // if check on Institute
1501 $val_array = array("title", "birthday", "gender", "org_units", "institution", "department", "upload",
1502 "street", "zipcode", "city", "country", "sel_country", "phone_office", "phone_home", "phone_mobile",
1503 "fax", "email", "second_email", "hobby", "matriculation", "location",
1504 "interests_general", "interests_help_offered", "interests_help_looking");
1505
1506 // set public profile preferences
1507 $checked_values = $this->getCheckedValues();
1508 foreach ($val_array as $key => $value) {
1509 if (($checked_values["chk_" . $value])) {
1510 $ilUser->setPref("public_" . $value, "y");
1511 } else {
1512 $ilUser->setPref("public_" . $value, "n");
1513 }
1514 }
1515
1516 // additional defined user data fields
1517 foreach ($this->user_defined_fields->getVisibleDefinitions() as $field_id => $definition) {
1518 if (($checked_values["chk_udf_" . $definition["field_id"]])) {
1519 $ilUser->setPref("public_udf_" . $definition["field_id"], "y");
1520 } else {
1521 $ilUser->setPref("public_udf_" . $definition["field_id"], "n");
1522 }
1523 }
1524
1525 $ilUser->update();
1526
1527 switch ($_POST["public_profile"]) {
1528 case "y":
1529 $key_suffix = "-1";
1530 break;
1531 case "g":
1532 $key_suffix = "-2";
1533 break;
1534 }
1535
1536 include_once "Services/Badge/classes/class.ilBadgeHandler.php";
1537 $handler = ilBadgeHandler::getInstance();
1538 if ($handler->isActive()) {
1539 $badgePositions = [];
1540 if (isset($_POST["bpos" . $key_suffix]) && is_array($_POST["bpos" . $key_suffix])) {
1541 $badgePositions = $_POST["bpos" . $key_suffix];
1542 }
1543
1544 if (count($badgePositions) > 0) {
1545 include_once "Services/Badge/classes/class.ilBadgeAssignment.php";
1546 ilBadgeAssignment::updatePositions($ilUser->getId(), $badgePositions);
1547 }
1548 }
1549
1550 // update lucene index
1551 include_once './Services/Search/classes/Lucene/class.ilLuceneIndexer.php';
1552 ilLuceneIndexer::updateLuceneIndex(array((int) $GLOBALS['DIC']['ilUser']->getId()));
1553
1554 ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
1555
1556 $this->checklist_status->saveStepSucess(ilProfileChecklistStatus::STEP_PUBLISH_OPTIONS);
1557
1558 if (ilSession::get('orig_request_target')) {
1559 $target = ilSession::get('orig_request_target');
1560 ilSession::set('orig_request_target', '');
1561 ilUtil::redirect($target);
1562 } elseif ($redirect = $_SESSION['profile_complete_redirect']) {
1563 unset($_SESSION['profile_complete_redirect']);
1564 ilUtil::redirect($redirect);
1565 } else {
1566 $ilCtrl->redirectByClass("iluserprivacysettingsgui", "");
1567 }
1568 }
1569 $this->form->setValuesByPost();
1570 $tpl->showPublicProfile(true);
1571 }
1572
1578 protected function getCheckedValues()
1579 {
1580 $checked_values = [];
1581 foreach ($_POST as $k => $v) {
1582 if (substr($k, 0, 4) == "chk_") {
1583 $k = str_replace("-1", "", $k);
1584 $k = str_replace("-2", "", $k);
1585 $checked_values[$k] = $v;
1586 }
1587 }
1588 return $checked_values;
1589 }
1590
1591
1598 public function showExportImport()
1599 {
1600 global $DIC;
1601
1602 $ilToolbar = $DIC['ilToolbar'];
1603 $ilCtrl = $DIC['ilCtrl'];
1604 $tpl = $DIC['tpl'];
1605 $ilTabs = $DIC['ilTabs'];
1606 $ilUser = $DIC['ilUser'];
1607
1608 $ilTabs->activateTab("export");
1609 $this->setHeader();
1610
1611 include_once "Services/UIComponent/Button/classes/class.ilLinkButton.php";
1612 $button = ilLinkButton::getInstance();
1613 $button->setCaption("pd_export_profile");
1614 $button->setUrl($ilCtrl->getLinkTarget($this, "exportPersonalData"));
1615 $ilToolbar->addStickyItem($button);
1616
1617 $exp_file = $ilUser->getPersonalDataExportFile();
1618 if ($exp_file != "") {
1619 $ilToolbar->addSeparator();
1620 $ilToolbar->addButton(
1621 $this->lng->txt("pd_download_last_export_file"),
1622 $ilCtrl->getLinkTarget($this, "downloadPersonalData")
1623 );
1624 }
1625
1626 $ilToolbar->addSeparator();
1627 $ilToolbar->addButton(
1628 $this->lng->txt("pd_import_personal_data"),
1629 $ilCtrl->getLinkTarget($this, "importPersonalDataSelection")
1630 );
1631
1632 $tpl->printToStdout();
1633 }
1634
1635
1639 public function exportPersonalData()
1640 {
1641 global $DIC;
1642
1643 $ilCtrl = $DIC['ilCtrl'];
1644 $ilUser = $DIC['ilUser'];
1645
1646 $ilUser->exportPersonalData();
1647 $ilUser->sendPersonalDataFile();
1648 $ilCtrl->redirect($this, "showExportImport");
1649 }
1650
1657 public function downloadPersonalData()
1658 {
1659 global $DIC;
1660
1661 $ilUser = $DIC['ilUser'];
1662
1663 $ilUser->sendPersonalDataFile();
1664 }
1665
1673 {
1674 global $DIC;
1675
1676 $lng = $DIC['lng'];
1677 $ilCtrl = $DIC['ilCtrl'];
1678 $tpl = $DIC['tpl'];
1679 $ilTabs = $DIC['ilTabs'];
1680
1681 $ilTabs->activateTab("export");
1682 $this->setHeader();
1683
1684 $this->initPersonalDataImportForm();
1685
1686 $tpl->setContent($this->form->getHTML());
1687 $tpl->printToStdout();
1688 }
1689
1697 {
1698 global $DIC;
1699
1700 $lng = $DIC['lng'];
1701 $ilCtrl = $DIC['ilCtrl'];
1702
1703 include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
1704 $this->form = new ilPropertyFormGUI();
1705
1706 // input file
1707 $fi = new ilFileInputGUI($lng->txt("file"), "file");
1708 $fi->setRequired(true);
1709 $fi->setSuffixes(array("zip"));
1710 $this->form->addItem($fi);
1711
1712 // profile data
1713 $cb = new ilCheckboxInputGUI($this->lng->txt("pd_profile_data"), "profile_data");
1714 $this->form->addItem($cb);
1715
1716 // settings
1717 $cb = new ilCheckboxInputGUI($this->lng->txt("settings"), "settings");
1718 $this->form->addItem($cb);
1719
1720 // personal notes
1721 $cb = new ilCheckboxInputGUI($this->lng->txt("notes"), "notes");
1722 $this->form->addItem($cb);
1723
1724 // calendar entries
1725 $cb = new ilCheckboxInputGUI($this->lng->txt("pd_private_calendars"), "calendar");
1726 $this->form->addItem($cb);
1727
1728 $this->form->addCommandButton("importPersonalData", $lng->txt("import"));
1729 $this->form->addCommandButton("showExportImport", $lng->txt("cancel"));
1730
1731 $this->form->setTitle($lng->txt("pd_import_personal_data"));
1732 $this->form->setFormAction($ilCtrl->getFormAction($this));
1733 }
1734
1735
1742 public function importPersonalData()
1743 {
1744 global $DIC;
1745
1746 $ilUser = $DIC['ilUser'];
1747 $ilCtrl = $DIC['ilCtrl'];
1748 $tpl = $DIC['tpl'];
1749 $ilTabs = $DIC['ilTabs'];
1750
1751 $this->initPersonalDataImportForm();
1752 if ($this->form->checkInput()) {
1753 $ilUser->importPersonalData(
1754 $_FILES["file"],
1755 (int) $_POST["profile_data"],
1756 (int) $_POST["settings"],
1757 (int) $_POST["notes"],
1758 (int) $_POST["calendar"]
1759 );
1760 ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
1761 $ilCtrl->redirect($this, "");
1762 } else {
1763 $ilTabs->activateTab("export");
1764 $this->setHeader();
1765 $this->form->setValuesByPost();
1766 $tpl->setContent($this->form->getHtml());
1767 $tpl->printToStdout();
1768 }
1769 }
1770
1776 protected function showChecklist($active_step)
1777 {
1778 $main_tpl = $this->tpl;
1779
1780 $main_tpl->setRightContent($this->checklist->render($active_step));
1781 }
1782}
user()
Definition: user.php:4
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
$location
Definition: buildRTE.php:44
$_GET["client_id"]
$_POST["username"]
$_SESSION["AccountId"]
An exception for terminatinating execution or to throw for unit testing.
const AUTH_LDAP
const AUTH_LOCAL
const IL_CAL_DATE
const UDF_TYPE_TEXT
static getInstancesByUserId($a_user_id)
static updatePositions($a_user_id, array $a_positions)
static getInstance()
Constructor.
Class ilBadge.
This class represents a checkbox property in a property form.
This class represents a custom property in a property form.
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false, $include_seconds=false)
Format a date @access public.
Class for single dates.
This class represents a file property in a property form.
This class represents a property in a property form.
static getInstance()
Factory.
This class represents a location property in a property form.
static updateLuceneIndex($a_obj_ids)
Update lucene index.
static isActivated()
Checks whether Map feature is activated.
static getDefaultSettings()
Get default longitude, latitude and zoom.
This class represents a non editable value in a property form.
static getDefaultPortfolio($a_user_id)
Get default portfolio of user.
getLatitude()
Get Latitude.
getCountry()
Get country (free text)
static _getPersonalPicturePath( $a_usr_id, $a_size="small", $a_force_pic=false, $a_prevent_no_photo_image=false, $html_export=false)
Get path to personal picture.
getLongitude()
Get Longitude.
getLocationZoom()
Get Location Zoom.
getStreet()
get street @access public
getCity()
get city @access public
static _loginExists($a_login, $a_user_id=0)
check if a login name already exists You may exclude a user from the check by giving his user id as 2...
GUI class for personal profile.
saveProfile()
save user profile data
initPersonalDataImportForm()
Init personal data import form.
showPersonalData($a_no_init=false, $a_migration_started=false)
Personal data form.
getCheckedValues()
Get checked values.
importPersonalData()
Import personal data.
showPublicProfile($a_no_init=false)
Public profile form.
initPersonalDataForm()
Init personal form.
savePersonalData()
Save personal data form.
savePublicProfile()
Save public profile form.
exportPersonalData()
Export personal data.
removeUserPicture()
remove user image
getProfilePortfolio()
has profile set to a portfolio?
showExportImport()
Show export/import.
uploadUserPicture()
Upload user image.
downloadPersonalData()
Download personal data export file.
showPublicProfileFields(ilPropertyformGUI $form, array $prefs, $parent=null, $anonymized=false, $key_suffix="")
Add fields to form.
importPersonalDataSelection()
Import personal data selection.
initPublicProfileForm()
Init public profile form.
__construct(\ilTermsOfServiceDocumentEvaluation $termsOfServiceEvaluation=null, \ilTermsOfServiceHelper $termsOfServiceHelper=null)
constructor
showChecklist($active_step)
Show checklist.
addLocationToForm(ilPropertyFormGUI $a_form, ilObjUser $a_user)
Add location fields to form if activated.
Personal profile publishing mode of a iser.
This class represents a property form user interface.
addItem($a_item)
Add Item (Property, SectionHeader).
GUI class for public user profile presentation.
This class represents a property in a property form.
This class represents an option in a radio group.
const SESSION_CLOSE_USER
static set($a_var, $a_val)
Set a value.
static setClosingContext($a_context)
set closing context (for statistics)
static get($a_var)
Get a value.
ILIAS Setting Class.
static getMailsToAddress()
Get mailto: emails.
Class ilTermsOfServiceEventWithdrawn.
Class ilTermsOfServiceHelper.
static _getInstance()
Get instance.
Class for user related exception handling in ILIAS.
User privacy settings (currently located under "Profile and Privacy")
Class ilUserProfile.
User settings configuration (what preferences can be visible/changed/...)
static isConvertVersionAtLeast($a_version)
Compare convert version numbers.
static escapeShellArg($a_arg)
static getWebspaceDir($mode="filesystem")
get webspace directory
static execConvert($args)
execute convert command
static redirect($a_script)
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static is_email($a_email, ilMailRfc822AddressParserFactory $mailAddressParserFactory=null)
This preg-based function checks whether an e-mail address is formally valid.
static isLogin($a_login)
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
static formSelect( $selected, $varname, $options, $multiple=false, $direct_text=false, $size="0", $style_class="", $attribs="", $disabled=false)
Builds a select form field with options and shows the selected option first.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms @access public
$login
Definition: cron.php:13
global $DIC
Definition: goto.php:24
$ilUser
Definition: imgupload.php:18
This is how the factory for UI elements looks.
Definition: Factory.php:18
An entity that renders components to a string output.
Definition: Renderer.php:15
Interface ilTermsOfServiceDocumentEvaluation.
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41
if($format !==null) $name
Definition: metadata.php:230
global $ilSetting
Definition: privfeed.php:17
$lng
settings()
Definition: settings.php:2
$token
Definition: xapitoken.php:52