ILIAS  release_4-3 Revision
 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  // reload page only if skin or style were changed
491  // feedback
492  if (!empty($this->password_error))
493  {
494  ilUtil::sendFailure($this->password_error,true);
495  }
496  elseif (!empty($this->upload_error))
497  {
498  ilUtil::sendFailure($this->upload_error,true);
499  }
500  else if ($reload)
501  {
502  // feedback
503  ilUtil::sendSuccess($this->lng->txt("saved_successfully"),true);
504  $this->ctrl->redirect($this, "");
505  //$this->tpl->setVariable("RELOAD","<script language=\"Javascript\">\ntop.location.href = \"./start.php\";\n</script>\n");
506  }
507  else
508  {
509  ilUtil::sendSuccess($this->lng->txt("saved_successfully"),true);
510  }
511  }
512 
513  $this->showProfile();
514  }
515 
521  function showProfile()
522  {
523  $this->showPersonalData();
524  }
525 
532  function addLocationToForm(ilPropertyFormGUI $a_form, ilObjUser $a_user)
533  {
534  global $ilCtrl;
535 
536  // check google map activation
537  include_once("./Services/GoogleMaps/classes/class.ilGoogleMapUtil.php");
539  {
540  return;
541  }
542 
543  $this->lng->loadLanguageModule("gmaps");
544 
545  // Get user settings
546  $latitude = $a_user->getLatitude();
547  $longitude = $a_user->getLongitude();
548  $zoom = $a_user->getLocationZoom();
549 
550  // Get Default settings, when nothing is set
551  if ($latitude == 0 && $longitude == 0 && $zoom == 0)
552  {
554  $latitude = $def["latitude"];
555  $longitude = $def["longitude"];
556  $zoom = $def["zoom"];
557  }
558 
559  $street = $a_user->getStreet();
560  if (!$street)
561  {
562  $street = $this->lng->txt("street");
563  }
564  $city = $a_user->getCity();
565  if (!$city)
566  {
567  $city = $this->lng->txt("city");
568  }
569  $country = $a_user->getCountry();
570  if (!$country)
571  {
572  $country = $this->lng->txt("country");
573  }
574 
575  // location property
576  $loc_prop = new ilLocationInputGUI($this->lng->txt("location"),
577  "location");
578  $loc_prop->setLatitude($latitude);
579  $loc_prop->setLongitude($longitude);
580  $loc_prop->setZoom($zoom);
581  $loc_prop->setAddress($street.",".$city.",".$country);
582 
583  $a_form->addItem($loc_prop);
584  }
585 
586  // init sub tabs
587  function setTabs()
588  {
589  global $ilTabs, $ilUser, $ilHelp;
590 
591  $ilHelp->setScreenIdComponent("user");
592 
593  // personal data
594  $ilTabs->addTab("personal_data",
595  $this->lng->txt("personal_data"),
596  $this->ctrl->getLinkTarget($this, "showPersonalData"));
597 
598  // public profile
599  $ilTabs->addTab("public_profile",
600  $this->lng->txt("public_profile"),
601  $this->ctrl->getLinkTarget($this, "showPublicProfile"));
602 
603  // export
604  $ilTabs->addTab("export",
605  $this->lng->txt("export")."/".$this->lng->txt("import"),
606  $this->ctrl->getLinkTarget($this, "showExportImport"));
607 
608  if($ilUser->getPref("public_profile") != "n" || $this->getProfilePortfolio())
609  {
610  // profile preview
611  $ilTabs->addNonTabbedLink("profile_preview",
612  $this->lng->txt("user_profile_preview"),
613  $this->ctrl->getLinkTargetByClass("ilpublicuserprofilegui", "view"));
614  }
615  }
616 
617 
619  {
620  $d_set = new ilSetting("delicous");
621  if($this->userSettingVisible("matriculation") or count($this->user_defined_fields->getVisibleDefinitions())
622  or $d_set->get("user_profile") == "1")
623  {
624  return true;
625  }
626  return false;
627  }
628 
630  {
631  global $ilUser;
632 
633  $user_defined_data = $ilUser->getUserDefinedData();
634  foreach($this->user_defined_fields->getVisibleDefinitions() as $field_id => $definition)
635  {
636  if($definition['field_type'] == UDF_TYPE_TEXT)
637  {
638  $this->tpl->setCurrentBlock("field_text");
639  $this->tpl->setVariable("FIELD_VALUE",ilUtil::prepareFormOutput($user_defined_data[$field_id]));
640  if(!$definition['changeable'])
641  {
642  $this->tpl->setVariable("DISABLED_FIELD",'disabled=\"disabled\"');
643  $this->tpl->setVariable("FIELD_NAME",'udf['.$definition['field_id'].']');
644  }
645  else
646  {
647  $this->tpl->setVariable("FIELD_NAME",'udf['.$definition['field_id'].']');
648  }
649  $this->tpl->parseCurrentBlock();
650  }
651  else
652  {
653  if($definition['changeable'])
654  {
655  $name = 'udf['.$definition['field_id'].']';
656  $disabled = false;
657  }
658  else
659  {
660  $name = '';
661  $disabled = true;
662  }
663  $this->tpl->setCurrentBlock("field_select");
664  $this->tpl->setVariable("SELECT_BOX",ilUtil::formSelect($user_defined_data[$field_id],
665  $name,
666  $this->user_defined_fields->fieldValuesToSelectArray(
667  $definition['field_values']),
668  false,
669  true,0,'','',$disabled));
670  $this->tpl->parseCurrentBlock();
671  }
672  $this->tpl->setCurrentBlock("user_defined");
673 
674  if($definition['required'])
675  {
676  $name = $definition['field_name']."<span class=\"asterisk\">*</span>";
677  }
678  else
679  {
680  $name = $definition['field_name'];
681  }
682  $this->tpl->setVariable("TXT_FIELD_NAME",$name);
683  $this->tpl->parseCurrentBlock();
684  }
685  return true;
686  }
687 
689  {
690  foreach($this->user_defined_fields->getVisibleDefinitions() as $definition)
691  {
692  $field_id = $definition['field_id'];
693  if($definition['required'] and !strlen($_POST['udf'][$field_id]))
694  {
695  return false;
696  }
697  }
698  return true;
699  }
700 
704  function setHeader()
705  {
706 // $this->tpl->setTitleIcon(ilUtil::getImagePath("icon_pd_b.png"), "");
707  $this->tpl->setTitle($this->lng->txt('personal_profile'));
708  }
709 
710  //
711  //
712  // PERSONAL DATA FORM
713  //
714  //
715 
719  function showPersonalData($a_no_init = false)
720  {
721  global $ilUser, $styleDefinition, $rbacreview, $ilias, $lng, $ilSetting, $ilTabs;
722 
723  $ilTabs->activateTab("personal_data");
724 
725  $settings = $ilias->getAllSettings();
726 
727  $this->setHeader();
728 
729  if (!$a_no_init)
730  {
731  $this->initPersonalDataForm();
732  // catch feedback message
733  if ($ilUser->getProfileIncomplete())
734  {
735  ilUtil::sendInfo($lng->txt("profile_incomplete"));
736  }
737  }
738  $this->tpl->setContent($this->form->getHTML());
739 
740  $this->tpl->show();
741  }
742 
747  {
748  global $ilSetting, $lng, $ilUser, $styleDefinition, $rbacreview;
749 
750  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
751  $this->form = new ilPropertyFormGUI();
752  $this->form->setFormAction($this->ctrl->getFormAction($this));
753 
754  // user defined fields
755  $user_defined_data = $ilUser->getUserDefinedData();
756 
757  foreach($this->user_defined_fields->getVisibleDefinitions() as $field_id => $definition)
758  {
759  if($definition['field_type'] == UDF_TYPE_TEXT)
760  {
761  $this->input["udf_".$definition['field_id']] =
762  new ilTextInputGUI($definition['field_name'], "udf_".$definition['field_id']);
763  $this->input["udf_".$definition['field_id']]->setMaxLength(255);
764  $this->input["udf_".$definition['field_id']]->setSize(40);
765  }
766  else if($definition['field_type'] == UDF_TYPE_WYSIWYG)
767  {
768  $this->input["udf_".$definition['field_id']] =
769  new ilTextAreaInputGUI($definition['field_name'], "udf_".$definition['field_id']);
770  $this->input["udf_".$definition['field_id']]->setUseRte(true);
771  }
772  else
773  {
774  $options = $this->user_defined_fields->fieldValuesToSelectArray($definition['field_values']);
775  $this->input["udf_".$definition['field_id']] =
776  new ilSelectInputGUI($definition['field_name'], "udf_".$definition['field_id']);
777  $this->input["udf_".$definition['field_id']]->setOptions($options);
778  }
779 
780  $value = $user_defined_data["f_".$field_id];
781  $this->input["udf_".$definition['field_id']]->setValue($value);
782 
783  if($definition['required'])
784  {
785  $this->input["udf_".$definition['field_id']]->setRequired(true);
786  }
787  if(!$definition['changeable'] && (!$definition['required'] || $value))
788  {
789  $this->input["udf_".$definition['field_id']]->setDisabled(true);
790  }
791 
792  // add "please select" if no current value
793  if($definition['field_type'] == UDF_TYPE_SELECT && !$value)
794  {
795  $options = array(""=>$lng->txt("please_select")) + $options;
796  $this->input["udf_".$definition['field_id']]->setOptions($options);
797  }
798  }
799 
800  // standard fields
801  include_once("./Services/User/classes/class.ilUserProfile.php");
802  $up = new ilUserProfile();
803  $up->skipField("password");
804  $up->skipGroup("settings");
805  $up->skipGroup("preferences");
806 
807  // standard fields
808  $up->addStandardFieldsToForm($this->form, $ilUser, $this->input);
809 
810  $this->addLocationToForm($this->form, $ilUser);
811 
812  $this->form->addCommandButton("savePersonalData", $lng->txt("save"));
813 
814  }
815 
820  public function savePersonalData()
821  {
822  global $tpl, $lng, $ilCtrl, $ilUser, $ilSetting, $ilAuth;
823 
824  $this->initPersonalDataForm();
825  if ($this->form->checkInput())
826  {
827  $form_valid = true;
828 
829  // if form field name differs from setter
830  $map = array(
831  "firstname" => "FirstName",
832  "lastname" => "LastName",
833  "title" => "UTitle",
834  "sel_country" => "SelectedCountry",
835  "phone_office" => "PhoneOffice",
836  "phone_home" => "PhoneHome",
837  "phone_mobile" => "PhoneMobile",
838  "referral_comment" => "Comment"
839  );
840  include_once("./Services/User/classes/class.ilUserProfile.php");
841  $up = new ilUserProfile();
842  foreach($up->getStandardFields() as $f => $p)
843  {
844  // if item is part of form, it is currently valid (if not disabled)
845  $item = $this->form->getItemByPostVar("usr_".$f);
846  if($item && !$item->getDisabled())
847  {
848  $value = $this->form->getInput("usr_".$f);
849  switch($f)
850  {
851  case "birthday":
852  if (is_array($value))
853  {
854  if (is_array($value['date']))
855  {
856  if (($value['d'] > 0) && ($value['m'] > 0) && ($value['y'] > 0))
857  {
858  $ilUser->setBirthday(sprintf("%04d-%02d-%02d", $value['y'], $value['m'], $value['d']));
859  }
860  else
861  {
862  $ilUser->setBirthday("");
863  }
864  }
865  else
866  {
867  $ilUser->setBirthday($value['date']);
868  }
869  }
870  break;
871 
872  default:
873  $m = ucfirst($f);
874  if(isset($map[$f]))
875  {
876  $m = $map[$f];
877  }
878  $ilUser->{"set".$m}($value);
879  break;
880  }
881  }
882  }
883  $ilUser->setFullname();
884 
885  // set instant messengers
886  if ($this->workWithUserSetting("instant_messengers"))
887  {
888  $ilUser->setInstantMessengerId('icq', $this->form->getInput("usr_im_icq"));
889  $ilUser->setInstantMessengerId('yahoo', $this->form->getInput("usr_im_yahoo"));
890  $ilUser->setInstantMessengerId('msn', $this->form->getInput("usr_im_msn"));
891  $ilUser->setInstantMessengerId('aim', $this->form->getInput("usr_im_aim"));
892  $ilUser->setInstantMessengerId('skype', $this->form->getInput("usr_im_skype"));
893  $ilUser->setInstantMessengerId('jabber', $this->form->getInput("usr_im_jabber"));
894  $ilUser->setInstantMessengerId('voip', $this->form->getInput("usr_im_voip"));
895  }
896 
897  // check google map activation
898  include_once("./Services/GoogleMaps/classes/class.ilGoogleMapUtil.php");
900  {
901  $location = $this->form->getInput("location");
902  $ilUser->setLatitude(ilUtil::stripSlashes($location["latitude"]));
903  $ilUser->setLongitude(ilUtil::stripSlashes($location["longitude"]));
904  $ilUser->setLocationZoom(ilUtil::stripSlashes($location["zoom"]));
905  }
906 
907  // Set user defined data
908  $defs = $this->user_defined_fields->getVisibleDefinitions();
909  $udf = array();
910  foreach ($defs as $definition)
911  {
912  $f = "udf_".$definition['field_id'];
913  $item = $this->form->getItemByPostVar($f);
914  if ($item && !$item->getDisabled())
915  {
916  $udf[$definition['field_id']] = $this->form->getInput($f);
917  }
918  }
919  $ilUser->setUserDefinedData($udf);
920 
921  // if loginname is changeable -> validate
922  $un = $this->form->getInput('username');
923  if((int)$ilSetting->get('allow_change_loginname') &&
924  $un != $ilUser->getLogin())
925  {
926  if(!strlen($un) || !ilUtil::isLogin($un))
927  {
928  ilUtil::sendFailure($lng->txt('form_input_not_valid'));
929  $this->form->getItemByPostVar('username')->setAlert($this->lng->txt('login_invalid'));
930  $form_valid = false;
931  }
932  else if(ilObjUser::_loginExists($un, $ilUser->getId()))
933  {
934  ilUtil::sendFailure($lng->txt('form_input_not_valid'));
935  $this->form->getItemByPostVar('username')->setAlert($this->lng->txt('loginname_already_exists'));
936  $form_valid = false;
937  }
938  else
939  {
940  $ilUser->setLogin($un);
941 
942  try
943  {
944  $ilUser->updateLogin($ilUser->getLogin());
945  $ilAuth->setAuth($ilUser->getLogin());
946  $ilAuth->start();
947  }
948  catch (ilUserException $e)
949  {
950  ilUtil::sendFailure($lng->txt('form_input_not_valid'));
951  $this->form->getItemByPostVar('username')->setAlert($e->getMessage());
952  $form_valid = false;
953  }
954  }
955  }
956 
957  // everthing's ok. save form data
958  if ($form_valid)
959  {
960  $this->uploadUserPicture();
961 
962  // profile ok
963  $ilUser->setProfileIncomplete(false);
964 
965  // save user data & object_data
966  $ilUser->setTitle($ilUser->getFullname());
967  $ilUser->setDescription($ilUser->getEmail());
968 
969  $ilUser->update();
970 
971  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
972  if ($redirect = $_SESSION['profile_complete_redirect']) {
973  unset($_SESSION['profile_complete_redirect']);
975  }
976  else
977  $ilCtrl->redirect($this, "showPersonalData");
978  }
979  }
980 
981  $this->form->setValuesByPost();
982  $this->showPersonalData(true);
983  }
984 
985  //
986  //
987  // PUBLIC PROFILE FORM
988  //
989  //
990 
994  function showPublicProfile($a_no_init = false)
995  {
996  global $ilUser, $lng, $ilSetting, $ilTabs;
997 
998  $ilTabs->activateTab("public_profile");
999 
1000  $this->setHeader();
1001 
1002  if (!$a_no_init)
1003  {
1004  $this->initPublicProfileForm();
1005  }
1006 
1007  $ptpl = new ilTemplate("tpl.edit_personal_profile.html", true, true, "Services/User");
1008  $ptpl->setVariable("FORM", $this->form->getHTML());
1009  include_once("./Services/User/classes/class.ilPublicUserProfileGUI.php");
1010  $pub_profile = new ilPublicUserProfileGUI($ilUser->getId());
1011  $ptpl->setVariable("PREVIEW", $pub_profile->getEmbeddable());
1012  $this->tpl->setContent($ptpl->get());
1013  $this->tpl->show();
1014  }
1015 
1021  protected function getProfilePortfolio()
1022  {
1023  global $ilUser, $ilSetting;
1024 
1025  if ($ilSetting->get('user_portfolios'))
1026  {
1027  include_once "Services/Portfolio/classes/class.ilObjPortfolio.php";
1028  return ilObjPortfolio::getDefaultPortfolio($ilUser->getId());
1029  }
1030  }
1031 
1037  public function initPublicProfileForm()
1038  {
1039  global $lng, $ilUser, $ilSetting;
1040 
1041  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
1042  $this->form = new ilPropertyFormGUI();
1043 
1044  $this->form->setTitle($lng->txt("public_profile"));
1045  $this->form->setDescription($lng->txt("user_public_profile_info"));
1046  $this->form->setFormAction($this->ctrl->getFormAction($this));
1047 
1048  $portfolio_id = $this->getProfilePortfolio();
1049 
1050  if(!$portfolio_id)
1051  {
1052  // Activate public profile
1053  $radg = new ilRadioGroupInputGUI($lng->txt("user_activate_public_profile"), "public_profile");
1054  $info = $this->lng->txt("user_activate_public_profile_info");
1055  $pub_prof = in_array($ilUser->prefs["public_profile"], array("y", "n", "g"))
1056  ? $ilUser->prefs["public_profile"]
1057  : "n";
1058  if (!$ilSetting->get('enable_global_profiles') && $pub_prof == "g")
1059  {
1060  $pub_prof = "y";
1061  }
1062  $radg->setValue($pub_prof);
1063  $op1 = new ilRadioOption($lng->txt("usr_public_profile_disabled"), "n",$lng->txt("usr_public_profile_disabled_info"));
1064  $radg->addOption($op1);
1065  $op2 = new ilRadioOption($lng->txt("usr_public_profile_logged_in"), "y");
1066  $radg->addOption($op2);
1067  if ($ilSetting->get('enable_global_profiles'))
1068  {
1069  $op3 = new ilRadioOption($lng->txt("usr_public_profile_global"), "g");
1070  $radg->addOption($op3);
1071  }
1072  $this->form->addItem($radg);
1073 
1074  // #11773
1075  if ($ilSetting->get('user_portfolios'))
1076  {
1077  // #10826
1078  $prtf = "<br />".$lng->txt("user_profile_portfolio");
1079  $prtf .= "<br /><a href=\"ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToPortfolio\">&raquo; ".
1080  $lng->txt("user_portfolios")."</a>";
1081  $info .= $prtf;
1082  }
1083 
1084  $radg->setInfo($info);
1085  }
1086  else
1087  {
1088  $prtf = $lng->txt("user_profile_portfolio_selected");
1089  $prtf .= "<br /><a href=\"ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToPortfolio&prt_id=".$portfolio_id."\">&raquo; ".
1090  $lng->txt("portfolio")."</a>";
1091 
1092  $info = new ilCustomInputGUI($lng->txt("user_activate_public_profile"));
1093  $info->setHTML($prtf);
1094  $this->form->addItem($info);
1095  }
1096 
1097  $this->showPublicProfileFields($this->form, $ilUser->prefs);
1098 
1099  $this->form->addCommandButton("savePublicProfile", $lng->txt("save"));
1100  }
1101 
1109  public function showPublicProfileFields(ilPropertyformGUI $form, array $prefs, $parent = null)
1110  {
1111  global $ilUser;
1112 
1113  $birthday = $ilUser->getBirthday();
1114  if($birthday)
1115  {
1116  $birthday = ilDatePresentation::formatDate(new ilDate($birthday, IL_CAL_DATE));
1117  }
1118  $gender = $ilUser->getGender();
1119  if($gender)
1120  {
1121  $gender = $this->lng->txt("gender_".$gender);
1122  }
1123 
1124  if ($ilUser->getSelectedCountry() != "")
1125  {
1126  $this->lng->loadLanguageModule("meta");
1127  $txt_sel_country = $this->lng->txt("meta_c_".$ilUser->getSelectedCountry());
1128  }
1129 
1130  // profile picture
1131  $pic = ilObjUser::_getPersonalPicturePath($ilUser->getId(), "xsmall", true, true);
1132  if($pic)
1133  {
1134  $pic = "<img src=\"".$pic."\" />";
1135  }
1136 
1137  // personal data
1138  $val_array = array(
1139  "title" => $ilUser->getUTitle(),
1140  "birthday" => $birthday,
1141  "gender" => $gender,
1142  "institution" => $ilUser->getInstitution(),
1143  "department" => $ilUser->getDepartment(),
1144  "upload" => $pic,
1145  "street" => $ilUser->getStreet(),
1146  "zipcode" => $ilUser->getZipcode(),
1147  "city" => $ilUser->getCity(),
1148  "country" => $ilUser->getCountry(),
1149  "sel_country" => $txt_sel_country,
1150  "phone_office" => $ilUser->getPhoneOffice(),
1151  "phone_home" => $ilUser->getPhoneHome(),
1152  "phone_mobile" => $ilUser->getPhoneMobile(),
1153  "fax" => $ilUser->getFax(),
1154  "email" => $ilUser->getEmail(),
1155  "hobby" => $ilUser->getHobby(),
1156  "matriculation" => $ilUser->getMatriculation(),
1157  "delicious" => $ilUser->getDelicious()
1158  );
1159 
1160  // location
1161  include_once("./Services/GoogleMaps/classes/class.ilGoogleMapUtil.php");
1163  {
1164  $val_array["location"] = "";
1165  }
1166 
1167  foreach($val_array as $key => $value)
1168  {
1169  if ($this->userSettingVisible($key))
1170  {
1171  // public setting
1172  if ($key == "upload")
1173  {
1174  $cb = new ilCheckboxInputGUI($this->lng->txt("personal_picture"), "chk_".$key);
1175  }
1176  else
1177  {
1178  $cb = new ilCheckboxInputGUI($this->lng->txt($key), "chk_".$key);
1179  }
1180  if ($prefs["public_".$key] == "y")
1181  {
1182  $cb->setChecked(true);
1183  }
1184  //$cb->setInfo($value);
1185  $cb->setOptionTitle($value);
1186 
1187  if(!$parent)
1188  {
1189  $form->addItem($cb);
1190  }
1191  else
1192  {
1193  $parent->addSubItem($cb);
1194  }
1195  }
1196  }
1197 
1198  $im_arr = array("icq","yahoo","msn","aim","skype","jabber","voip");
1199  if ($this->userSettingVisible("instant_messengers"))
1200  {
1201  foreach ($im_arr as $im)
1202  {
1203  // public setting
1204  $cb = new ilCheckboxInputGUI($this->lng->txt("im_".$im), "chk_im_".$im);
1205  //$cb->setInfo($ilUser->getInstantMessengerId($im));
1206  $cb->setOptionTitle($ilUser->getInstantMessengerId($im));
1207  if ($prefs["public_im_".$im] != "n")
1208  {
1209  $cb->setChecked(true);
1210  }
1211 
1212  if(!$parent)
1213  {
1214  $form->addItem($cb);
1215  }
1216  else
1217  {
1218  $parent->addSubItem($cb);
1219  }
1220  }
1221  }
1222 
1223  // additional defined user data fields
1224  $user_defined_data = $ilUser->getUserDefinedData();
1225  foreach($this->user_defined_fields->getVisibleDefinitions() as $field_id => $definition)
1226  {
1227  // public setting
1228  $cb = new ilCheckboxInputGUI($definition["field_name"], "chk_udf_".$definition["field_id"]);
1229  $cb->setOptionTitle($user_defined_data["f_".$definition["field_id"]]);
1230  if ($prefs["public_udf_".$definition["field_id"]] == "y")
1231  {
1232  $cb->setChecked(true);
1233  }
1234 
1235  if(!$parent)
1236  {
1237  $form->addItem($cb);
1238  }
1239  else
1240  {
1241  $parent->addSubItem($cb);
1242  }
1243  }
1244  }
1245 
1250  public function savePublicProfile()
1251  {
1252  global $tpl, $lng, $ilCtrl, $ilUser;
1253 
1254  $this->initPublicProfileForm();
1255  if ($this->form->checkInput())
1256  {
1257  // with active portfolio no options are presented
1258  if(isset($_POST["public_profile"]))
1259  {
1260  $ilUser->setPref("public_profile", $_POST["public_profile"]);
1261  }
1262 
1263  // if check on Institute
1264  $val_array = array("title", "birthday", "gender", "institution", "department", "upload", "street",
1265  "zipcode", "city", "country", "sel_country", "phone_office", "phone_home", "phone_mobile",
1266  "fax", "email", "hobby", "matriculation", "location");
1267 
1268  // set public profile preferences
1269  foreach($val_array as $key => $value)
1270  {
1271  if (($_POST["chk_".$value]))
1272  {
1273  $ilUser->setPref("public_".$value,"y");
1274  }
1275  else
1276  {
1277  $ilUser->setPref("public_".$value,"n");
1278  }
1279  }
1280 
1281  $im_arr = array("icq","yahoo","msn","aim","skype","jabber","voip");
1282  if ($this->userSettingVisible("instant_messengers"))
1283  {
1284  foreach ($im_arr as $im)
1285  {
1286  if (($_POST["chk_im_".$im]))
1287  {
1288  $ilUser->setPref("public_im_".$im,"y");
1289  }
1290  else
1291  {
1292  $ilUser->setPref("public_im_".$im,"n");
1293  }
1294  }
1295  }
1296 
1297 // $d_set = new ilSetting("delicious");
1298 // if ($d_set->get("user_profile"))
1299 // {
1300  if (($_POST["chk_delicious"]))
1301  {
1302  $ilUser->setPref("public_delicious","y");
1303  }
1304  else
1305  {
1306  $ilUser->setPref("public_delicious","n");
1307  }
1308 // }
1309 
1310  // additional defined user data fields
1311  foreach($this->user_defined_fields->getVisibleDefinitions() as $field_id => $definition)
1312  {
1313  if (($_POST["chk_udf_".$definition["field_id"]]))
1314  {
1315  $ilUser->setPref("public_udf_".$definition["field_id"], "y");
1316  }
1317  else
1318  {
1319  $ilUser->setPref("public_udf_".$definition["field_id"], "n");
1320  }
1321  }
1322 
1323  $ilUser->update();
1324  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
1325  $ilCtrl->redirect($this, "showPublicProfile");
1326  }
1327  $this->form->setValuesByPost();
1328  $tpl->showPublicProfile(true);
1329  }
1330 
1337  function showExportImport()
1338  {
1339  global $ilToolbar, $ilCtrl, $tpl, $ilTabs, $ilUser;
1340 
1341  $ilTabs->activateTab("export");
1342  $this->setHeader();
1343 
1344  $ilToolbar->addButton($this->lng->txt("pd_export_profile"),
1345  $ilCtrl->getLinkTarget($this, "exportPersonalData"));
1346 
1347  $exp_file = $ilUser->getPersonalDataExportFile();
1348  if ($exp_file != "")
1349  {
1350  $ilToolbar->addSeparator();
1351  $ilToolbar->addButton($this->lng->txt("pd_download_last_export_file"),
1352  $ilCtrl->getLinkTarget($this, "downloadPersonalData"));
1353  }
1354 
1355  $ilToolbar->addSeparator();
1356  $ilToolbar->addButton($this->lng->txt("pd_import_personal_data"),
1357  $ilCtrl->getLinkTarget($this, "importPersonalDataSelection"));
1358 
1359  $tpl->show();
1360  }
1361 
1362 
1366  function exportPersonalData()
1367  {
1368  global $ilCtrl, $ilUser;
1369 
1370  $ilUser->exportPersonalData();
1371  $ilUser->sendPersonalDataFile();
1372  $ilCtrl->redirect($this, "showExportImport");
1373  }
1374 
1381  function downloadPersonalData()
1382  {
1383  global $ilUser;
1384 
1385  $ilUser->sendPersonalDataFile();
1386  }
1387 
1394  function importPersonalDataSelection()
1395  {
1396  global $lng, $ilCtrl, $tpl, $ilTabs;
1397 
1398  $ilTabs->activateTab("export");
1399  $this->setHeader();
1400 
1401  $this->initPersonalDataImportForm();
1402 
1403  $tpl->setContent($this->form->getHTML());
1404  $tpl->show();
1405  }
1406 
1413  function initPersonalDataImportForm()
1414  {
1415  global $lng, $ilCtrl;
1416 
1417  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
1418  $this->form = new ilPropertyFormGUI();
1419 
1420  // input file
1421  $fi = new ilFileInputGUI($lng->txt("file"), "file");
1422  $fi->setRequired(true);
1423  $fi->setSuffixes(array("zip"));
1424  $this->form->addItem($fi);
1425 
1426  // profile data
1427  $cb = new ilCheckboxInputGUI($this->lng->txt("pd_profile_data"), "profile_data");
1428  $this->form->addItem($cb);
1429 
1430  // settings
1431  $cb = new ilCheckboxInputGUI($this->lng->txt("settings"), "settings");
1432  $this->form->addItem($cb);
1433 
1434  // bookmarks
1435  $cb = new ilCheckboxInputGUI($this->lng->txt("pd_bookmarks"), "bookmarks");
1436  $this->form->addItem($cb);
1437 
1438  // personal notes
1439  $cb = new ilCheckboxInputGUI($this->lng->txt("pd_notes"), "notes");
1440  $this->form->addItem($cb);
1441 
1442  // calendar entries
1443  $cb = new ilCheckboxInputGUI($this->lng->txt("pd_private_calendars"), "calendar");
1444  $this->form->addItem($cb);
1445 
1446  $this->form->addCommandButton("importPersonalData", $lng->txt("import"));
1447  $this->form->addCommandButton("showExportImport", $lng->txt("cancel"));
1448 
1449  $this->form->setTitle($lng->txt("pd_import_personal_data"));
1450  $this->form->setFormAction($ilCtrl->getFormAction($this));
1451 
1452  }
1453 
1454 
1461  function importPersonalData()
1462  {
1463  global $ilUser, $ilCtrl, $tpl, $ilTabs;
1464 
1465  $this->initPersonalDataImportForm();
1466  if ($this->form->checkInput())
1467  {
1468  $ilUser->importPersonalData($_FILES["file"],
1469  (int) $_POST["profile_data"],
1470  (int) $_POST["settings"],
1471  (int) $_POST["bookmarks"],
1472  (int) $_POST["notes"],
1473  (int) $_POST["calendar"]
1474  );
1475  ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
1476  $ilCtrl->redirect($this, "");
1477  }
1478  else
1479  {
1480  $ilTabs->activateTab("export");
1481  $this->setHeader();
1482  $this->form->setValuesByPost();
1483  $tpl->setContent($this->form->getHtml());
1484  $tpl->show();
1485  }
1486  }
1487 
1488 }
1489 
1490 ?>