ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilPersonalProfileGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
13 {
14  var $tpl;
15  var $lng;
16  var $ilias;
17  var $ctrl;
18 
20 
21 
26  {
27  global $ilias, $tpl, $lng, $rbacsystem, $ilCtrl;
28 
29  include_once './Services/User/classes/class.ilUserDefinedFields.php';
30  $this->user_defined_fields =& ilUserDefinedFields::_getInstance();
31 
32  $this->tpl =& $tpl;
33  $this->lng =& $lng;
34  $this->ilias =& $ilias;
35  $this->ctrl =& $ilCtrl;
36  $this->settings = $ilias->getAllSettings();
37  $lng->loadLanguageModule("jsmath");
38  $lng->loadLanguageModule("pd");
39  $this->upload_error = "";
40  $this->password_error = "";
41  $lng->loadLanguageModule("user");
42  // $ilCtrl->saveParameter($this, "user_page");
43  }
44 
48  function &executeCommand()
49  {
50  global $ilUser, $ilCtrl, $tpl, $ilTabs, $lng;
51 
52  $next_class = $this->ctrl->getNextClass();
53 
54  switch($next_class)
55  {
56  case "ilpublicuserprofilegui":
57  include_once("./Services/User/classes/class.ilPublicUserProfileGUI.php");
58  $_GET["user_id"] = $ilUser->getId();
59  $pub_profile_gui = new ilPublicUserProfileGUI($_GET["user_id"]);
60  $pub_profile_gui->setBackUrl($ilCtrl->getLinkTarget($this, "showPersonalData"));
61  $ilCtrl->forwardCommand($pub_profile_gui);
62  $tpl->show();
63  break;
64 
65  default:
66  $this->setTabs();
67  $cmd = $this->ctrl->getCmd("showPersonalData");
68  $this->$cmd();
69  break;
70  }
71  return true;
72  }
73 
74 
79  function workWithUserSetting($setting)
80  {
81  $result = TRUE;
82  if ($this->settings["usr_settings_hide_".$setting] == 1)
83  {
84  $result = FALSE;
85  }
86  if ($this->settings["usr_settings_disable_".$setting] == 1)
87  {
88  $result = FALSE;
89  }
90  return $result;
91  }
92 
97  function userSettingVisible($setting)
98  {
99  $result = TRUE;
100  if (isset($this->settings["usr_settings_hide_".$setting]) &&
101  $this->settings["usr_settings_hide_".$setting] == 1)
102  {
103  $result = FALSE;
104  }
105  return $result;
106  }
107 
112  function userSettingEnabled($setting)
113  {
114  $result = TRUE;
115  if ($this->settings["usr_settings_disable_".$setting] == 1)
116  {
117  $result = FALSE;
118  }
119  return $result;
120  }
121 
125  function uploadUserPicture()
126  {
127  global $ilUser;
128 
129  if ($this->workWithUserSetting("upload"))
130  {
131  if (!$this->form->hasFileUpload("userfile"))
132  {
133  if ($this->form->getItemByPostVar("userfile")->getDeletionFlag())
134  {
135  $ilUser->removeUserPicture();
136  }
137  return;
138  }
139  else
140  {
141  $webspace_dir = ilUtil::getWebspaceDir();
142  $image_dir = $webspace_dir."/usr_images";
143  $store_file = "usr_".$ilUser->getID()."."."jpg";
144 
145  // store filename
146  $ilUser->setPref("profile_image", $store_file);
147  $ilUser->update();
148 
149  // move uploaded file
150  $uploaded_file = $this->form->moveFileUpload($image_dir,
151  "userfile", "upload_".$ilUser->getId()."pic");
152 
153  if (!$uploaded_file)
154  {
155  ilUtil::sendFailure($this->lng->txt("upload_error", true));
156  $this->ctrl->redirect($this, "showProfile");
157  }
158  chmod($uploaded_file, 0770);
159 
160  // take quality 100 to avoid jpeg artefacts when uploading jpeg files
161  // taking only frame [0] to avoid problems with animated gifs
162  $show_file = "$image_dir/usr_".$ilUser->getId().".jpg";
163  $thumb_file = "$image_dir/usr_".$ilUser->getId()."_small.jpg";
164  $xthumb_file = "$image_dir/usr_".$ilUser->getId()."_xsmall.jpg";
165  $xxthumb_file = "$image_dir/usr_".$ilUser->getId()."_xxsmall.jpg";
166  $uploaded_file = ilUtil::escapeShellArg($uploaded_file);
167  $show_file = ilUtil::escapeShellArg($show_file);
168  $thumb_file = ilUtil::escapeShellArg($thumb_file);
169  $xthumb_file = ilUtil::escapeShellArg($xthumb_file);
170  $xxthumb_file = ilUtil::escapeShellArg($xxthumb_file);
171 
172  if(ilUtil::isConvertVersionAtLeast("6.3.8-3"))
173  {
174  ilUtil::execConvert($uploaded_file . "[0] -geometry 200x200^ -gravity center -extent 200x200 -quality 100 JPEG:".$show_file);
175  ilUtil::execConvert($uploaded_file . "[0] -geometry 100x100^ -gravity center -extent 100x100 -quality 100 JPEG:".$thumb_file);
176  ilUtil::execConvert($uploaded_file . "[0] -geometry 75x75^ -gravity center -extent 75x75 -quality 100 JPEG:".$xthumb_file);
177  ilUtil::execConvert($uploaded_file . "[0] -geometry 30x30^ -gravity center -extent 30x30 -quality 100 JPEG:".$xxthumb_file);
178  }
179  else
180  {
181  ilUtil::execConvert($uploaded_file . "[0] -geometry 200x200 -quality 100 JPEG:".$show_file);
182  ilUtil::execConvert($uploaded_file . "[0] -geometry 100x100 -quality 100 JPEG:".$thumb_file);
183  ilUtil::execConvert($uploaded_file . "[0] -geometry 75x75 -quality 100 JPEG:".$xthumb_file);
184  ilUtil::execConvert($uploaded_file . "[0] -geometry 30x30 -quality 100 JPEG:".$xxthumb_file);
185  }
186  }
187  }
188 
189 // $this->saveProfile();
190  }
191 
195  function removeUserPicture()
196  {
197  global $ilUser;
198 
199  $ilUser->removeUserPicture();
200 
201  $this->saveProfile();
202  }
203 
204 
205 
209  function saveProfile()
210  {
211  global $ilUser ,$ilSetting, $ilAuth;
212 
213  //init checking var
214  $form_valid = true;
215 
216  // testing by ratana ty:
217  // if people check on check box it will
218  // write some datata to table usr_pref
219  // if check on Public Profile
220  if (($_POST["chk_pub"])=="on")
221  {
222  $ilUser->setPref("public_profile","y");
223  }
224  else
225  {
226  $ilUser->setPref("public_profile","n");
227  }
228 
229  // if check on Institute
230  $val_array = array("institution", "department", "upload", "street",
231  "zip", "city", "country", "phone_office", "phone_home", "phone_mobile",
232  "fax", "email", "hobby", "matriculation");
233 
234  // set public profile preferences
235  foreach($val_array as $key => $value)
236  {
237  if (($_POST["chk_".$value]) == "on")
238  {
239  $ilUser->setPref("public_".$value,"y");
240  }
241  else
242  {
243  $ilUser->setPref("public_".$value,"n");
244  }
245  }
246 
247  $d_set = new ilSetting("delicious");
248  if ($d_set->get("user_profile"))
249  {
250  if (($_POST["chk_delicious"]) == "on")
251  {
252  $ilUser->setPref("public_delicious","y");
253  }
254  else
255  {
256  $ilUser->setPref("public_delicious","n");
257  }
258  }
259 
260 
261  // check dynamically required fields
262  foreach($this->settings as $key => $val)
263  {
264  if (substr($key,0,8) == "require_")
265  {
266  $require_keys[] = substr($key,8);
267  }
268  }
269 
270  foreach($require_keys as $key => $val)
271  {
272  // exclude required system and registration-only fields
273  $system_fields = array("login", "default_role", "passwd", "passwd2");
274  if (!in_array($val, $system_fields))
275  {
276  if ($this->workWithUserSetting($val))
277  {
278  if (isset($this->settings["require_" . $val]) && $this->settings["require_" . $val])
279  {
280  if (empty($_POST["usr_" . $val]))
281  {
282  ilUtil::sendFailure($this->lng->txt("fill_out_all_required_fields") . ": " . $this->lng->txt($val));
283  $form_valid = false;
284  }
285  }
286  }
287  }
288  }
289 
290  // Check user defined required fields
291  if($form_valid and !$this->__checkUserDefinedRequiredFields())
292  {
293  ilUtil::sendFailure($this->lng->txt("fill_out_all_required_fields"));
294  $form_valid = false;
295  }
296 
297  // check email
298  if ($this->workWithUserSetting("email"))
299  {
300  if (!ilUtil::is_email($_POST["usr_email"]) and !empty($_POST["usr_email"]) and $form_valid)
301  {
302  ilUtil::sendFailure($this->lng->txt("email_not_valid"));
303  $form_valid = false;
304  }
305  }
306 
307  //update user data (not saving!)
308  if ($this->workWithUserSetting("firstname"))
309  {
310  $ilUser->setFirstName(ilUtil::stripSlashes($_POST["usr_firstname"]));
311  }
312  if ($this->workWithUserSetting("lastname"))
313  {
314  $ilUser->setLastName(ilUtil::stripSlashes($_POST["usr_lastname"]));
315  }
316  if ($this->workWithUserSetting("gender"))
317  {
318  $ilUser->setGender($_POST["usr_gender"]);
319  }
320  if ($this->workWithUserSetting("title"))
321  {
322  $ilUser->setUTitle(ilUtil::stripSlashes($_POST["usr_title"]));
323  }
324  $ilUser->setFullname();
325  if ($this->workWithUserSetting("institution"))
326  {
327  $ilUser->setInstitution(ilUtil::stripSlashes($_POST["usr_institution"]));
328  }
329  if ($this->workWithUserSetting("department"))
330  {
331  $ilUser->setDepartment(ilUtil::stripSlashes($_POST["usr_department"]));
332  }
333  if ($this->workWithUserSetting("street"))
334  {
335  $ilUser->setStreet(ilUtil::stripSlashes($_POST["usr_street"]));
336  }
337  if ($this->workWithUserSetting("zipcode"))
338  {
339  $ilUser->setZipcode(ilUtil::stripSlashes($_POST["usr_zipcode"]));
340  }
341  if ($this->workWithUserSetting("city"))
342  {
343  $ilUser->setCity(ilUtil::stripSlashes($_POST["usr_city"]));
344  }
345  if ($this->workWithUserSetting("country"))
346  {
347  $ilUser->setCountry(ilUtil::stripSlashes($_POST["usr_country"]));
348  }
349  if ($this->workWithUserSetting("phone_office"))
350  {
351  $ilUser->setPhoneOffice(ilUtil::stripSlashes($_POST["usr_phone_office"]));
352  }
353  if ($this->workWithUserSetting("phone_home"))
354  {
355  $ilUser->setPhoneHome(ilUtil::stripSlashes($_POST["usr_phone_home"]));
356  }
357  if ($this->workWithUserSetting("phone_mobile"))
358  {
359  $ilUser->setPhoneMobile(ilUtil::stripSlashes($_POST["usr_phone_mobile"]));
360  }
361  if ($this->workWithUserSetting("fax"))
362  {
363  $ilUser->setFax(ilUtil::stripSlashes($_POST["usr_fax"]));
364  }
365  if ($this->workWithUserSetting("email"))
366  {
367  $ilUser->setEmail(ilUtil::stripSlashes($_POST["usr_email"]));
368  }
369  if ($this->workWithUserSetting("hobby"))
370  {
371  $ilUser->setHobby(ilUtil::stripSlashes($_POST["usr_hobby"]));
372  }
373  if ($this->workWithUserSetting("referral_comment"))
374  {
375  $ilUser->setComment(ilUtil::stripSlashes($_POST["usr_referral_comment"]));
376  }
377  if ($this->workWithUserSetting("matriculation"))
378  {
379  $ilUser->setMatriculation(ilUtil::stripSlashes($_POST["usr_matriculation"]));
380  }
381 
382  // delicious
383  $d_set = new ilSetting("delicious");
384  if ($d_set->get("user_profile"))
385  {
386  $ilUser->setDelicious(ilUtil::stripSlashes($_POST["usr_delicious"]));
387  }
388 
389  // set instant messengers
390  if ($this->workWithUserSetting("instant_messengers"))
391  {
392  $ilUser->setInstantMessengerId('icq',ilUtil::stripSlashes($_POST["usr_im_icq"]));
393  $ilUser->setInstantMessengerId('yahoo',ilUtil::stripSlashes($_POST["usr_im_yahoo"]));
394  $ilUser->setInstantMessengerId('msn',ilUtil::stripSlashes($_POST["usr_im_msn"]));
395  $ilUser->setInstantMessengerId('aim',ilUtil::stripSlashes($_POST["usr_im_aim"]));
396  $ilUser->setInstantMessengerId('skype',ilUtil::stripSlashes($_POST["usr_im_skype"]));
397  $ilUser->setInstantMessengerId('jabber',ilUtil::stripSlashes($_POST["usr_im_jabber"]));
398  $ilUser->setInstantMessengerId('voip',ilUtil::stripSlashes($_POST["usr_im_voip"]));
399  }
400 
401  // Set user defined data
402  $ilUser->setUserDefinedData($_POST['udf']);
403 
404  // everthing's ok. save form data
405  if ($form_valid)
406  {
407  // init reload var. page should only be reloaded if skin or style were changed
408  $reload = false;
409 
410  if ($this->workWithUserSetting("skin_style"))
411  {
412  //set user skin and style
413  if ($_POST["usr_skin_style"] != "")
414  {
415  $sknst = explode(":", $_POST["usr_skin_style"]);
416 
417  if ($ilUser->getPref("style") != $sknst[1] ||
418  $ilUser->getPref("skin") != $sknst[0])
419  {
420  $ilUser->setPref("skin", $sknst[0]);
421  $ilUser->setPref("style", $sknst[1]);
422  $reload = true;
423  }
424  }
425  }
426 
427  if ($this->workWithUserSetting("language"))
428  {
429  // reload page if language was changed
430  //if ($_POST["usr_language"] != "" and $_POST["usr_language"] != $_SESSION['lang'])
431  // (this didn't work as expected, alex)
432  if ($_POST["usr_language"] != $ilUser->getLanguage())
433  {
434  $reload = true;
435  }
436 
437  // set user language
438  $ilUser->setLanguage($_POST["usr_language"]);
439 
440  }
441  if ($this->workWithUserSetting("hits_per_page"))
442  {
443  // set user hits per page
444  if ($_POST["hits_per_page"] != "")
445  {
446  $ilUser->setPref("hits_per_page",$_POST["hits_per_page"]);
447  }
448  }
449 
450  // set show users online
451  if ($this->workWithUserSetting("show_users_online"))
452  {
453  $ilUser->setPref("show_users_online", $_POST["show_users_online"]);
454  }
455 
456  // set hide own online_status
457  if ($this->workWithUserSetting("hide_own_online_status"))
458  {
459  if ($_POST["chk_hide_own_online_status"] != "")
460  {
461  $ilUser->setPref("hide_own_online_status","y");
462  }
463  else
464  {
465  $ilUser->setPref("hide_own_online_status","n");
466  }
467  }
468 
469  // personal desktop items in news block
470 /* Subscription Concept is abandonded for now, we show all news of pd items (Alex)
471  if ($_POST["pd_items_news"] != "")
472  {
473  $ilUser->setPref("pd_items_news","y");
474  }
475  else
476  {
477  $ilUser->setPref("pd_items_news","n");
478  }
479 */
480 
481  // profile ok
482  $ilUser->setProfileIncomplete(false);
483 
484  // save user data & object_data
485  $ilUser->setTitle($ilUser->getFullname());
486  $ilUser->setDescription($ilUser->getEmail());
487 
488  $ilUser->update();
489 
490  // update lucene index
491  include_once './Services/Search/classes/Lucene/class.ilLuceneIndexer.php';
492  ilLuceneIndexer::updateLuceneIndex(array($GLOBALS['ilUser']->getId()));
493 
494 
495  // reload page only if skin or style were changed
496  // feedback
497  if (!empty($this->password_error))
498  {
499  ilUtil::sendFailure($this->password_error,true);
500  }
501  elseif (!empty($this->upload_error))
502  {
503  ilUtil::sendFailure($this->upload_error,true);
504  }
505  else if ($reload)
506  {
507  // feedback
508  ilUtil::sendSuccess($this->lng->txt("saved_successfully"),true);
509  $this->ctrl->redirect($this, "");
510  //$this->tpl->setVariable("RELOAD","<script language=\"Javascript\">\ntop.location.href = \"./start.php\";\n</script>\n");
511  }
512  else
513  {
514  ilUtil::sendSuccess($this->lng->txt("saved_successfully"),true);
515  }
516  }
517 
518  $this->showProfile();
519  }
520 
526  function showProfile()
527  {
528  $this->showPersonalData();
529  }
530 
537  function addLocationToForm(ilPropertyFormGUI $a_form, ilObjUser $a_user)
538  {
539  global $ilCtrl;
540 
541  // check map activation
542  include_once("./Services/Maps/classes/class.ilMapUtil.php");
543  if (!ilMapUtil::isActivated())
544  {
545  return;
546  }
547 
548  // Don't really know if this is still necessary...
549  $this->lng->loadLanguageModule("maps");
550 
551  // Get user settings
552  $latitude = $a_user->getLatitude();
553  $longitude = $a_user->getLongitude();
554  $zoom = $a_user->getLocationZoom();
555 
556  // Get Default settings, when nothing is set
557  if ($latitude == 0 && $longitude == 0 && $zoom == 0)
558  {
560  $latitude = $def["latitude"];
561  $longitude = $def["longitude"];
562  $zoom = $def["zoom"];
563  }
564 
565  $street = $a_user->getStreet();
566  if (!$street)
567  {
568  $street = $this->lng->txt("street");
569  }
570  $city = $a_user->getCity();
571  if (!$city)
572  {
573  $city = $this->lng->txt("city");
574  }
575  $country = $a_user->getCountry();
576  if (!$country)
577  {
578  $country = $this->lng->txt("country");
579  }
580 
581  // location property
582  $loc_prop = new ilLocationInputGUI($this->lng->txt("location"),
583  "location");
584  $loc_prop->setLatitude($latitude);
585  $loc_prop->setLongitude($longitude);
586  $loc_prop->setZoom($zoom);
587  $loc_prop->setAddress($street.",".$city.",".$country);
588 
589  $a_form->addItem($loc_prop);
590  }
591 
592  // init sub tabs
593  function setTabs()
594  {
595  global $ilTabs, $ilUser, $ilHelp;
596 
597  $ilHelp->setScreenIdComponent("user");
598 
599  // personal data
600  $ilTabs->addTab("personal_data",
601  $this->lng->txt("personal_data"),
602  $this->ctrl->getLinkTarget($this, "showPersonalData"));
603 
604  // public profile
605  $ilTabs->addTab("public_profile",
606  $this->lng->txt("public_profile"),
607  $this->ctrl->getLinkTarget($this, "showPublicProfile"));
608 
609  // export
610  $ilTabs->addTab("export",
611  $this->lng->txt("export")."/".$this->lng->txt("import"),
612  $this->ctrl->getLinkTarget($this, "showExportImport"));
613 
614  if($ilUser->getPref("public_profile") != "n" || $this->getProfilePortfolio())
615  {
616  // profile preview
617  $ilTabs->addNonTabbedLink("profile_preview",
618  $this->lng->txt("user_profile_preview"),
619  $this->ctrl->getLinkTargetByClass("ilpublicuserprofilegui", "view"));
620  }
621  }
622 
623 
625  {
626  $d_set = new ilSetting("delicous");
627  if($this->userSettingVisible("matriculation") or count($this->user_defined_fields->getVisibleDefinitions())
628  or $d_set->get("user_profile") == "1")
629  {
630  return true;
631  }
632  return false;
633  }
634 
636  {
637  global $ilUser;
638 
639  $user_defined_data = $ilUser->getUserDefinedData();
640  foreach($this->user_defined_fields->getVisibleDefinitions() as $field_id => $definition)
641  {
642  if($definition['field_type'] == UDF_TYPE_TEXT)
643  {
644  $this->tpl->setCurrentBlock("field_text");
645  $this->tpl->setVariable("FIELD_VALUE",ilUtil::prepareFormOutput($user_defined_data[$field_id]));
646  if(!$definition['changeable'])
647  {
648  $this->tpl->setVariable("DISABLED_FIELD",'disabled=\"disabled\"');
649  $this->tpl->setVariable("FIELD_NAME",'udf['.$definition['field_id'].']');
650  }
651  else
652  {
653  $this->tpl->setVariable("FIELD_NAME",'udf['.$definition['field_id'].']');
654  }
655  $this->tpl->parseCurrentBlock();
656  }
657  else
658  {
659  if($definition['changeable'])
660  {
661  $name = 'udf['.$definition['field_id'].']';
662  $disabled = false;
663  }
664  else
665  {
666  $name = '';
667  $disabled = true;
668  }
669  $this->tpl->setCurrentBlock("field_select");
670  $this->tpl->setVariable("SELECT_BOX",ilUtil::formSelect($user_defined_data[$field_id],
671  $name,
672  $this->user_defined_fields->fieldValuesToSelectArray(
673  $definition['field_values']),
674  false,
675  true,0,'','',$disabled));
676  $this->tpl->parseCurrentBlock();
677  }
678  $this->tpl->setCurrentBlock("user_defined");
679 
680  if($definition['required'])
681  {
682  $name = $definition['field_name']."<span class=\"asterisk\">*</span>";
683  }
684  else
685  {
686  $name = $definition['field_name'];
687  }
688  $this->tpl->setVariable("TXT_FIELD_NAME",$name);
689  $this->tpl->parseCurrentBlock();
690  }
691  return true;
692  }
693 
695  {
696  foreach($this->user_defined_fields->getVisibleDefinitions() as $definition)
697  {
698  $field_id = $definition['field_id'];
699  if($definition['required'] and !strlen($_POST['udf'][$field_id]))
700  {
701  return false;
702  }
703  }
704  return true;
705  }
706 
710  function setHeader()
711  {
712  $this->tpl->setTitle($this->lng->txt('personal_profile'));
713  }
714 
715  //
716  //
717  // PERSONAL DATA FORM
718  //
719  //
720 
724  function showPersonalData($a_no_init = false)
725  {
726  global $ilUser, $styleDefinition, $rbacreview, $ilias, $lng, $ilSetting, $ilTabs;
727 
728  $ilTabs->activateTab("personal_data");
729 
730  $settings = $ilias->getAllSettings();
731 
732  $this->setHeader();
733 
734  if (!$a_no_init)
735  {
736  $this->initPersonalDataForm();
737  // catch feedback message
738  if ($ilUser->getProfileIncomplete())
739  {
740  ilUtil::sendInfo($lng->txt("profile_incomplete"));
741  }
742  }
743  $this->tpl->setContent($this->form->getHTML());
744 
745  $this->tpl->show();
746  }
747 
752  {
753  global $ilSetting, $lng, $ilUser, $styleDefinition, $rbacreview;
754 
755  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
756  $this->form = new ilPropertyFormGUI();
757  $this->form->setFormAction($this->ctrl->getFormAction($this));
758 
759  // user defined fields
760  $user_defined_data = $ilUser->getUserDefinedData();
761 
762  foreach($this->user_defined_fields->getVisibleDefinitions() as $field_id => $definition)
763  {
764  if($definition['field_type'] == UDF_TYPE_TEXT)
765  {
766  $this->input["udf_".$definition['field_id']] =
767  new ilTextInputGUI($definition['field_name'], "udf_".$definition['field_id']);
768  $this->input["udf_".$definition['field_id']]->setMaxLength(255);
769  $this->input["udf_".$definition['field_id']]->setSize(40);
770  }
771  else if($definition['field_type'] == UDF_TYPE_WYSIWYG)
772  {
773  $this->input["udf_".$definition['field_id']] =
774  new ilTextAreaInputGUI($definition['field_name'], "udf_".$definition['field_id']);
775  $this->input["udf_".$definition['field_id']]->setUseRte(true);
776  }
777  else
778  {
779  $options = $this->user_defined_fields->fieldValuesToSelectArray($definition['field_values']);
780  $this->input["udf_".$definition['field_id']] =
781  new ilSelectInputGUI($definition['field_name'], "udf_".$definition['field_id']);
782  $this->input["udf_".$definition['field_id']]->setOptions($options);
783  }
784 
785  $value = $user_defined_data["f_".$field_id];
786  $this->input["udf_".$definition['field_id']]->setValue($value);
787 
788  if($definition['required'])
789  {
790  $this->input["udf_".$definition['field_id']]->setRequired(true);
791  }
792  if(!$definition['changeable'] && (!$definition['required'] || $value))
793  {
794  $this->input["udf_".$definition['field_id']]->setDisabled(true);
795  }
796 
797  // add "please select" if no current value
798  if($definition['field_type'] == UDF_TYPE_SELECT && !$value)
799  {
800  $options = array(""=>$lng->txt("please_select")) + $options;
801  $this->input["udf_".$definition['field_id']]->setOptions($options);
802  }
803  }
804 
805  // standard fields
806  include_once("./Services/User/classes/class.ilUserProfile.php");
807  $up = new ilUserProfile();
808  $up->skipField("password");
809  $up->skipGroup("settings");
810  $up->skipGroup("preferences");
811 
812  $up->setAjaxCallback(
813  $this->ctrl->getLinkTargetByClass('ilPublicUserProfileGUI', 'doProfileAutoComplete', '', true)
814  );
815 
816  // standard fields
817  $up->addStandardFieldsToForm($this->form, $ilUser, $this->input);
818 
819  $this->addLocationToForm($this->form, $ilUser);
820 
821  $this->form->addCommandButton("savePersonalData", $lng->txt("save"));
822 
823  }
824 
829  public function savePersonalData()
830  {
831  global $tpl, $lng, $ilCtrl, $ilUser, $ilSetting, $ilAuth;
832 
833  $this->initPersonalDataForm();
834  if ($this->form->checkInput())
835  {
836  $form_valid = true;
837 
838  // if form field name differs from setter
839  $map = array(
840  "firstname" => "FirstName",
841  "lastname" => "LastName",
842  "title" => "UTitle",
843  "sel_country" => "SelectedCountry",
844  "phone_office" => "PhoneOffice",
845  "phone_home" => "PhoneHome",
846  "phone_mobile" => "PhoneMobile",
847  "referral_comment" => "Comment",
848  "interests_general" => "GeneralInterests",
849  "interests_help_offered" => "OfferingHelp",
850  "interests_help_looking" => "LookingForHelp"
851  );
852  include_once("./Services/User/classes/class.ilUserProfile.php");
853  $up = new ilUserProfile();
854  foreach($up->getStandardFields() as $f => $p)
855  {
856  // if item is part of form, it is currently valid (if not disabled)
857  $item = $this->form->getItemByPostVar("usr_".$f);
858  if($item && !$item->getDisabled())
859  {
860  $value = $this->form->getInput("usr_".$f);
861  switch($f)
862  {
863  case "birthday":
864  if (is_array($value))
865  {
866  if (is_array($value['date']))
867  {
868  if (($value['d'] > 0) && ($value['m'] > 0) && ($value['y'] > 0))
869  {
870  $ilUser->setBirthday(sprintf("%04d-%02d-%02d", $value['y'], $value['m'], $value['d']));
871  }
872  else
873  {
874  $ilUser->setBirthday("");
875  }
876  }
877  else
878  {
879  $ilUser->setBirthday($value['date']);
880  }
881  }
882  break;
883 
884  default:
885  $m = ucfirst($f);
886  if(isset($map[$f]))
887  {
888  $m = $map[$f];
889  }
890  $ilUser->{"set".$m}($value);
891  break;
892  }
893  }
894  }
895  $ilUser->setFullname();
896 
897  // set instant messengers
898  if ($this->workWithUserSetting("instant_messengers"))
899  {
900  $ilUser->setInstantMessengerId('icq', $this->form->getInput("usr_im_icq"));
901  $ilUser->setInstantMessengerId('yahoo', $this->form->getInput("usr_im_yahoo"));
902  $ilUser->setInstantMessengerId('msn', $this->form->getInput("usr_im_msn"));
903  $ilUser->setInstantMessengerId('aim', $this->form->getInput("usr_im_aim"));
904  $ilUser->setInstantMessengerId('skype', $this->form->getInput("usr_im_skype"));
905  $ilUser->setInstantMessengerId('jabber', $this->form->getInput("usr_im_jabber"));
906  $ilUser->setInstantMessengerId('voip', $this->form->getInput("usr_im_voip"));
907  }
908 
909  // check map activation
910  include_once("./Services/Maps/classes/class.ilMapUtil.php");
912  {
913  // #17619 - proper escaping
914  $location = $this->form->getInput("location");
915  $lat = ilUtil::stripSlashes($location["latitude"]);
916  $long = ilUtil::stripSlashes($location["longitude"]);
917  $zoom = ilUtil::stripSlashes($location["zoom"]);
918  $ilUser->setLatitude(is_numeric($lat) ? $lat : null);
919  $ilUser->setLongitude(is_numeric($long) ? $long : null);
920  $ilUser->setLocationZoom(is_numeric($zoom) ? $zoom : null);
921  }
922 
923  // Set user defined data
924  $defs = $this->user_defined_fields->getVisibleDefinitions();
925  $udf = array();
926  foreach ($defs as $definition)
927  {
928  $f = "udf_".$definition['field_id'];
929  $item = $this->form->getItemByPostVar($f);
930  if ($item && !$item->getDisabled())
931  {
932  $udf[$definition['field_id']] = $this->form->getInput($f);
933  }
934  }
935  $ilUser->setUserDefinedData($udf);
936 
937  // if loginname is changeable -> validate
938  $un = $this->form->getInput('username');
939  if((int)$ilSetting->get('allow_change_loginname') &&
940  $un != $ilUser->getLogin())
941  {
942  if(!strlen($un) || !ilUtil::isLogin($un))
943  {
944  ilUtil::sendFailure($lng->txt('form_input_not_valid'));
945  $this->form->getItemByPostVar('username')->setAlert($this->lng->txt('login_invalid'));
946  $form_valid = false;
947  }
948  else if(ilObjUser::_loginExists($un, $ilUser->getId()))
949  {
950  ilUtil::sendFailure($lng->txt('form_input_not_valid'));
951  $this->form->getItemByPostVar('username')->setAlert($this->lng->txt('loginname_already_exists'));
952  $form_valid = false;
953  }
954  else
955  {
956  $ilUser->setLogin($un);
957 
958  try
959  {
960  $ilUser->updateLogin($ilUser->getLogin());
961  $ilAuth->setAuth($ilUser->getLogin());
962  $ilAuth->start();
963  }
964  catch (ilUserException $e)
965  {
966  ilUtil::sendFailure($lng->txt('form_input_not_valid'));
967  $this->form->getItemByPostVar('username')->setAlert($e->getMessage());
968  $form_valid = false;
969  }
970  }
971  }
972 
973  // everthing's ok. save form data
974  if ($form_valid)
975  {
976  $this->uploadUserPicture();
977 
978  // profile ok
979  $ilUser->setProfileIncomplete(false);
980 
981  // save user data & object_data
982  $ilUser->setTitle($ilUser->getFullname());
983  $ilUser->setDescription($ilUser->getEmail());
984 
985  $ilUser->update();
986 
987  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
988 
989  if(ilSession::get('orig_request_target'))
990  {
991  $target = ilSession::get('orig_request_target');
992  ilSession::set('orig_request_target', '');
993  ilUtil::redirect($target);
994  }
995  else if($redirect = $_SESSION['profile_complete_redirect'])
996  {
997  unset($_SESSION['profile_complete_redirect']);
999  }
1000  else
1001  {
1002  $ilCtrl->redirect($this, "showPersonalData");
1003  }
1004  }
1005  }
1006 
1007  $this->form->setValuesByPost();
1008  $this->showPersonalData(true);
1009  }
1010 
1011  //
1012  //
1013  // PUBLIC PROFILE FORM
1014  //
1015  //
1016 
1020  function showPublicProfile($a_no_init = false)
1021  {
1022  global $ilUser, $lng, $ilSetting, $ilTabs;
1023 
1024  $ilTabs->activateTab("public_profile");
1025 
1026  $this->setHeader();
1027 
1028  if (!$a_no_init)
1029  {
1030  $this->initPublicProfileForm();
1031  }
1032 
1033  $ptpl = new ilTemplate("tpl.edit_personal_profile.html", true, true, "Services/User");
1034  $ptpl->setVariable("FORM", $this->form->getHTML());
1035  include_once("./Services/User/classes/class.ilPublicUserProfileGUI.php");
1036  $pub_profile = new ilPublicUserProfileGUI($ilUser->getId());
1037  $ptpl->setVariable("PREVIEW", $pub_profile->getEmbeddable());
1038  $this->tpl->setContent($ptpl->get());
1039  $this->tpl->show();
1040  }
1041 
1047  protected function getProfilePortfolio()
1048  {
1049  global $ilUser, $ilSetting;
1050 
1051  if ($ilSetting->get('user_portfolios'))
1052  {
1053  include_once "Modules/Portfolio/classes/class.ilObjPortfolio.php";
1054  return ilObjPortfolio::getDefaultPortfolio($ilUser->getId());
1055  }
1056  }
1057 
1063  public function initPublicProfileForm()
1064  {
1065  global $lng, $ilUser, $ilSetting;
1066 
1067  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
1068  $this->form = new ilPropertyFormGUI();
1069 
1070  $this->form->setTitle($lng->txt("public_profile"));
1071  $this->form->setDescription($lng->txt("user_public_profile_info"));
1072  $this->form->setFormAction($this->ctrl->getFormAction($this));
1073 
1074  $portfolio_id = $this->getProfilePortfolio();
1075 
1076  if(!$portfolio_id)
1077  {
1078  // Activate public profile
1079  $radg = new ilRadioGroupInputGUI($lng->txt("user_activate_public_profile"), "public_profile");
1080  $info = $this->lng->txt("user_activate_public_profile_info");
1081  $pub_prof = in_array($ilUser->prefs["public_profile"], array("y", "n", "g"))
1082  ? $ilUser->prefs["public_profile"]
1083  : "n";
1084  if (!$ilSetting->get('enable_global_profiles') && $pub_prof == "g")
1085  {
1086  $pub_prof = "y";
1087  }
1088  $radg->setValue($pub_prof);
1089  $op1 = new ilRadioOption($lng->txt("usr_public_profile_disabled"), "n",$lng->txt("usr_public_profile_disabled_info"));
1090  $radg->addOption($op1);
1091  $op2 = new ilRadioOption($lng->txt("usr_public_profile_logged_in"), "y");
1092  $radg->addOption($op2);
1093  if ($ilSetting->get('enable_global_profiles'))
1094  {
1095  $op3 = new ilRadioOption($lng->txt("usr_public_profile_global"), "g");
1096  $radg->addOption($op3);
1097  }
1098  $this->form->addItem($radg);
1099 
1100  // #11773
1101  if ($ilSetting->get('user_portfolios'))
1102  {
1103  // #10826
1104  $prtf = "<br />".$lng->txt("user_profile_portfolio");
1105  $prtf .= "<br /><a href=\"ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToPortfolio\">&raquo; ".
1106  $lng->txt("user_portfolios")."</a>";
1107  $info .= $prtf;
1108  }
1109 
1110  $radg->setInfo($info);
1111  }
1112  else
1113  {
1114  $prtf = $lng->txt("user_profile_portfolio_selected");
1115  $prtf .= "<br /><a href=\"ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToPortfolio&prt_id=".$portfolio_id."\">&raquo; ".
1116  $lng->txt("portfolio")."</a>";
1117 
1118  $info = new ilCustomInputGUI($lng->txt("user_activate_public_profile"));
1119  $info->setHTML($prtf);
1120  $this->form->addItem($info);
1121  }
1122 
1123  $this->showPublicProfileFields($this->form, $ilUser->prefs);
1124 
1125  $this->form->addCommandButton("savePublicProfile", $lng->txt("save"));
1126  }
1127 
1136  public function showPublicProfileFields(ilPropertyformGUI $form, array $prefs, $parent = null, $anonymized = false)
1137  {
1138  global $ilUser;
1139 
1140  $birthday = $ilUser->getBirthday();
1141  if($birthday)
1142  {
1143  $birthday = ilDatePresentation::formatDate(new ilDate($birthday, IL_CAL_DATE));
1144  }
1145  $gender = $ilUser->getGender();
1146  if($gender)
1147  {
1148  $gender = $this->lng->txt("gender_".$gender);
1149  }
1150 
1151  if ($ilUser->getSelectedCountry() != "")
1152  {
1153  $this->lng->loadLanguageModule("meta");
1154  $txt_sel_country = $this->lng->txt("meta_c_".$ilUser->getSelectedCountry());
1155  }
1156 
1157  // profile picture
1158  $pic = ilObjUser::_getPersonalPicturePath($ilUser->getId(), "xsmall", true, true);
1159  if($pic)
1160  {
1161  $pic = "<img src=\"".$pic."\" />";
1162  }
1163 
1164  // personal data
1165  $val_array = array(
1166  "title" => $ilUser->getUTitle(),
1167  "birthday" => $birthday,
1168  "gender" => $gender,
1169  "upload" => $pic,
1170  "interests_general" => $ilUser->getGeneralInterestsAsText(),
1171  "interests_help_offered" => $ilUser->getOfferingHelpAsText(),
1172  "interests_help_looking" => $ilUser->getLookingForHelpAsText(),
1173  "institution" => $ilUser->getInstitution(),
1174  "department" => $ilUser->getDepartment(),
1175  "street" => $ilUser->getStreet(),
1176  "zipcode" => $ilUser->getZipcode(),
1177  "city" => $ilUser->getCity(),
1178  "country" => $ilUser->getCountry(),
1179  "sel_country" => $txt_sel_country,
1180  "phone_office" => $ilUser->getPhoneOffice(),
1181  "phone_home" => $ilUser->getPhoneHome(),
1182  "phone_mobile" => $ilUser->getPhoneMobile(),
1183  "fax" => $ilUser->getFax(),
1184  "email" => $ilUser->getEmail(),
1185  "hobby" => $ilUser->getHobby(),
1186  "matriculation" => $ilUser->getMatriculation(),
1187  "delicious" => $ilUser->getDelicious()
1188  );
1189 
1190  // location
1191  include_once("./Services/Maps/classes/class.ilMapUtil.php");
1192  if (ilMapUtil::isActivated())
1193  {
1194  $val_array["location"] = "";
1195  }
1196 
1197  foreach($val_array as $key => $value)
1198  {
1199  if($anonymized)
1200  {
1201  $value = null;
1202  }
1203 
1204  if ($this->userSettingVisible($key))
1205  {
1206  // public setting
1207  if ($key == "upload")
1208  {
1209  $cb = new ilCheckboxInputGUI($this->lng->txt("personal_picture"), "chk_".$key);
1210  }
1211  else
1212  {
1213  $cb = new ilCheckboxInputGUI($this->lng->txt($key), "chk_".$key);
1214  }
1215  if ($prefs["public_".$key] == "y")
1216  {
1217  $cb->setChecked(true);
1218  }
1219  //$cb->setInfo($value);
1220  $cb->setOptionTitle($value);
1221 
1222  if(!$parent)
1223  {
1224  $form->addItem($cb);
1225  }
1226  else
1227  {
1228  $parent->addSubItem($cb);
1229  }
1230  }
1231  }
1232 
1233  $im_arr = array("icq","yahoo","msn","aim","skype","jabber","voip");
1234  if ($this->userSettingVisible("instant_messengers"))
1235  {
1236  foreach ($im_arr as $im)
1237  {
1238  // public setting
1239  $cb = new ilCheckboxInputGUI($this->lng->txt("im_".$im), "chk_im_".$im);
1240  //$cb->setInfo($ilUser->getInstantMessengerId($im));
1241  $cb->setOptionTitle($ilUser->getInstantMessengerId($im));
1242  if ($prefs["public_im_".$im] != "n")
1243  {
1244  $cb->setChecked(true);
1245  }
1246 
1247  if(!$parent)
1248  {
1249  $form->addItem($cb);
1250  }
1251  else
1252  {
1253  $parent->addSubItem($cb);
1254  }
1255  }
1256  }
1257 
1258  // additional defined user data fields
1259  $user_defined_data = array();
1260  if(!$anonymized)
1261  {
1262  $user_defined_data = $ilUser->getUserDefinedData();
1263  }
1264  foreach($this->user_defined_fields->getVisibleDefinitions() as $field_id => $definition)
1265  {
1266  // public setting
1267  $cb = new ilCheckboxInputGUI($definition["field_name"], "chk_udf_".$definition["field_id"]);
1268  $cb->setOptionTitle($user_defined_data["f_".$definition["field_id"]]);
1269  if ($prefs["public_udf_".$definition["field_id"]] == "y")
1270  {
1271  $cb->setChecked(true);
1272  }
1273 
1274  if(!$parent)
1275  {
1276  $form->addItem($cb);
1277  }
1278  else
1279  {
1280  $parent->addSubItem($cb);
1281  }
1282  }
1283  }
1284 
1289  public function savePublicProfile()
1290  {
1291  global $tpl, $lng, $ilCtrl, $ilUser;
1292 
1293  $this->initPublicProfileForm();
1294  if ($this->form->checkInput())
1295  {
1296  // with active portfolio no options are presented
1297  if(isset($_POST["public_profile"]))
1298  {
1299  $ilUser->setPref("public_profile", $_POST["public_profile"]);
1300  }
1301 
1302  // if check on Institute
1303  $val_array = array("title", "birthday", "gender", "institution", "department", "upload", "street",
1304  "zipcode", "city", "country", "sel_country", "phone_office", "phone_home", "phone_mobile",
1305  "fax", "email", "hobby", "matriculation", "location",
1306  "interests_general", "interests_help_offered", "interests_help_looking");
1307 
1308  // set public profile preferences
1309  foreach($val_array as $key => $value)
1310  {
1311  if (($_POST["chk_".$value]))
1312  {
1313  $ilUser->setPref("public_".$value,"y");
1314  }
1315  else
1316  {
1317  $ilUser->setPref("public_".$value,"n");
1318  }
1319  }
1320 
1321  $im_arr = array("icq","yahoo","msn","aim","skype","jabber","voip");
1322  if ($this->userSettingVisible("instant_messengers"))
1323  {
1324  foreach ($im_arr as $im)
1325  {
1326  if (($_POST["chk_im_".$im]))
1327  {
1328  $ilUser->setPref("public_im_".$im,"y");
1329  }
1330  else
1331  {
1332  $ilUser->setPref("public_im_".$im,"n");
1333  }
1334  }
1335  }
1336 
1337 // $d_set = new ilSetting("delicious");
1338 // if ($d_set->get("user_profile"))
1339 // {
1340  if (($_POST["chk_delicious"]))
1341  {
1342  $ilUser->setPref("public_delicious","y");
1343  }
1344  else
1345  {
1346  $ilUser->setPref("public_delicious","n");
1347  }
1348 // }
1349 
1350  // additional defined user data fields
1351  foreach($this->user_defined_fields->getVisibleDefinitions() as $field_id => $definition)
1352  {
1353  if (($_POST["chk_udf_".$definition["field_id"]]))
1354  {
1355  $ilUser->setPref("public_udf_".$definition["field_id"], "y");
1356  }
1357  else
1358  {
1359  $ilUser->setPref("public_udf_".$definition["field_id"], "n");
1360  }
1361  }
1362 
1363  $ilUser->update();
1364 
1365  // update lucene index
1366  include_once './Services/Search/classes/Lucene/class.ilLuceneIndexer.php';
1367  ilLuceneIndexer::updateLuceneIndex(array((int) $GLOBALS['ilUser']->getId()));
1368 
1369  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
1370  $ilCtrl->redirect($this, "showPublicProfile");
1371  }
1372  $this->form->setValuesByPost();
1373  $tpl->showPublicProfile(true);
1374  }
1375 
1382  function showExportImport()
1383  {
1384  global $ilToolbar, $ilCtrl, $tpl, $ilTabs, $ilUser;
1385 
1386  $ilTabs->activateTab("export");
1387  $this->setHeader();
1388 
1389  $ilToolbar->addButton($this->lng->txt("pd_export_profile"),
1390  $ilCtrl->getLinkTarget($this, "exportPersonalData"));
1391 
1392  $exp_file = $ilUser->getPersonalDataExportFile();
1393  if ($exp_file != "")
1394  {
1395  $ilToolbar->addSeparator();
1396  $ilToolbar->addButton($this->lng->txt("pd_download_last_export_file"),
1397  $ilCtrl->getLinkTarget($this, "downloadPersonalData"));
1398  }
1399 
1400  $ilToolbar->addSeparator();
1401  $ilToolbar->addButton($this->lng->txt("pd_import_personal_data"),
1402  $ilCtrl->getLinkTarget($this, "importPersonalDataSelection"));
1403 
1404  $tpl->show();
1405  }
1406 
1407 
1411  function exportPersonalData()
1412  {
1413  global $ilCtrl, $ilUser;
1414 
1415  $ilUser->exportPersonalData();
1416  $ilUser->sendPersonalDataFile();
1417  $ilCtrl->redirect($this, "showExportImport");
1418  }
1419 
1426  function downloadPersonalData()
1427  {
1428  global $ilUser;
1429 
1430  $ilUser->sendPersonalDataFile();
1431  }
1432 
1439  function importPersonalDataSelection()
1440  {
1441  global $lng, $ilCtrl, $tpl, $ilTabs;
1442 
1443  $ilTabs->activateTab("export");
1444  $this->setHeader();
1445 
1446  $this->initPersonalDataImportForm();
1447 
1448  $tpl->setContent($this->form->getHTML());
1449  $tpl->show();
1450  }
1451 
1458  function initPersonalDataImportForm()
1459  {
1460  global $lng, $ilCtrl;
1461 
1462  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
1463  $this->form = new ilPropertyFormGUI();
1464 
1465  // input file
1466  $fi = new ilFileInputGUI($lng->txt("file"), "file");
1467  $fi->setRequired(true);
1468  $fi->setSuffixes(array("zip"));
1469  $this->form->addItem($fi);
1470 
1471  // profile data
1472  $cb = new ilCheckboxInputGUI($this->lng->txt("pd_profile_data"), "profile_data");
1473  $this->form->addItem($cb);
1474 
1475  // settings
1476  $cb = new ilCheckboxInputGUI($this->lng->txt("settings"), "settings");
1477  $this->form->addItem($cb);
1478 
1479  // bookmarks
1480  $cb = new ilCheckboxInputGUI($this->lng->txt("pd_bookmarks"), "bookmarks");
1481  $this->form->addItem($cb);
1482 
1483  // personal notes
1484  $cb = new ilCheckboxInputGUI($this->lng->txt("pd_notes"), "notes");
1485  $this->form->addItem($cb);
1486 
1487  // calendar entries
1488  $cb = new ilCheckboxInputGUI($this->lng->txt("pd_private_calendars"), "calendar");
1489  $this->form->addItem($cb);
1490 
1491  $this->form->addCommandButton("importPersonalData", $lng->txt("import"));
1492  $this->form->addCommandButton("showExportImport", $lng->txt("cancel"));
1493 
1494  $this->form->setTitle($lng->txt("pd_import_personal_data"));
1495  $this->form->setFormAction($ilCtrl->getFormAction($this));
1496 
1497  }
1498 
1499 
1506  function importPersonalData()
1507  {
1508  global $ilUser, $ilCtrl, $tpl, $ilTabs;
1509 
1510  $this->initPersonalDataImportForm();
1511  if ($this->form->checkInput())
1512  {
1513  $ilUser->importPersonalData($_FILES["file"],
1514  (int) $_POST["profile_data"],
1515  (int) $_POST["settings"],
1516  (int) $_POST["bookmarks"],
1517  (int) $_POST["notes"],
1518  (int) $_POST["calendar"]
1519  );
1520  ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
1521  $ilCtrl->redirect($this, "");
1522  }
1523  else
1524  {
1525  $ilTabs->activateTab("export");
1526  $this->setHeader();
1527  $this->form->setValuesByPost();
1528  $tpl->setContent($this->form->getHtml());
1529  $tpl->show();
1530  }
1531  }
1532 
1533 }
1534 
1535 ?>