ILIAS  Release_4_2_x_branch Revision 61807
 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  $this->upload_error = "";
39  $this->password_error = "";
40  $lng->loadLanguageModule("user");
41  // $ilCtrl->saveParameter($this, "user_page");
42  }
43 
47  function &executeCommand()
48  {
49  global $ilUser, $ilCtrl, $tpl, $ilTabs, $lng;
50 
51  $next_class = $this->ctrl->getNextClass();
52 
53  switch($next_class)
54  {
55  case "ilpublicuserprofilegui":
56  include_once("./Services/User/classes/class.ilPublicUserProfileGUI.php");
57  $_GET["user_id"] = $ilUser->getId();
58  $pub_profile_gui = new ilPublicUserProfileGUI($_GET["user_id"]);
59  $pub_profile_gui->setBackUrl($ilCtrl->getLinkTarget($this, "showPersonalData"));
60  $ilCtrl->forwardCommand($pub_profile_gui);
61  $tpl->show();
62  break;
63 
64  default:
65  $this->setTabs();
66  $cmd = $this->ctrl->getCmd("showPersonalData");
67  $this->$cmd();
68  break;
69  }
70  return true;
71  }
72 
73 
78  function workWithUserSetting($setting)
79  {
80  $result = TRUE;
81  if ($this->settings["usr_settings_hide_".$setting] == 1)
82  {
83  $result = FALSE;
84  }
85  if ($this->settings["usr_settings_disable_".$setting] == 1)
86  {
87  $result = FALSE;
88  }
89  return $result;
90  }
91 
96  function userSettingVisible($setting)
97  {
98  $result = TRUE;
99  if (isset($this->settings["usr_settings_hide_".$setting]) &&
100  $this->settings["usr_settings_hide_".$setting] == 1)
101  {
102  $result = FALSE;
103  }
104  return $result;
105  }
106 
111  function userSettingEnabled($setting)
112  {
113  $result = TRUE;
114  if ($this->settings["usr_settings_disable_".$setting] == 1)
115  {
116  $result = FALSE;
117  }
118  return $result;
119  }
120 
124  function uploadUserPicture()
125  {
126  global $ilUser;
127 
128  if ($this->workWithUserSetting("upload"))
129  {
130  if (!$this->form->hasFileUpload("userfile"))
131  {
132  if ($this->form->getItemByPostVar("userfile")->getDeletionFlag())
133  {
134  $ilUser->removeUserPicture();
135  }
136  return;
137  }
138  else
139  {
140  $webspace_dir = ilUtil::getWebspaceDir();
141  $image_dir = $webspace_dir."/usr_images";
142  $store_file = "usr_".$ilUser->getID()."."."jpg";
143 
144  // store filename
145  $ilUser->setPref("profile_image", $store_file);
146  $ilUser->update();
147 
148  // move uploaded file
149  $uploaded_file = $this->form->moveFileUpload($image_dir,
150  "userfile", "upload_".$ilUser->getId()."pic");
151 
152  if (!$uploaded_file)
153  {
154  ilUtil::sendFailure($this->lng->txt("upload_error", true));
155  $this->ctrl->redirect($this, "showProfile");
156  }
157  chmod($uploaded_file, 0770);
158 
159  // take quality 100 to avoid jpeg artefacts when uploading jpeg files
160  // taking only frame [0] to avoid problems with animated gifs
161  $show_file = "$image_dir/usr_".$ilUser->getId().".jpg";
162  $thumb_file = "$image_dir/usr_".$ilUser->getId()."_small.jpg";
163  $xthumb_file = "$image_dir/usr_".$ilUser->getId()."_xsmall.jpg";
164  $xxthumb_file = "$image_dir/usr_".$ilUser->getId()."_xxsmall.jpg";
165  $uploaded_file = ilUtil::escapeShellArg($uploaded_file);
166  $show_file = ilUtil::escapeShellArg($show_file);
167  $thumb_file = ilUtil::escapeShellArg($thumb_file);
168  $xthumb_file = ilUtil::escapeShellArg($xthumb_file);
169  $xxthumb_file = ilUtil::escapeShellArg($xxthumb_file);
170 
171  if(ilUtil::isConvertVersionAtLeast("6.3.8-3"))
172  {
173  ilUtil::execConvert($uploaded_file . "[0] -geometry 200x200^ -gravity center -extent 200x200 -quality 100 JPEG:".$show_file);
174  ilUtil::execConvert($uploaded_file . "[0] -geometry 100x100^ -gravity center -extent 100x100 -quality 100 JPEG:".$thumb_file);
175  ilUtil::execConvert($uploaded_file . "[0] -geometry 75x75^ -gravity center -extent 75x75 -quality 100 JPEG:".$xthumb_file);
176  ilUtil::execConvert($uploaded_file . "[0] -geometry 30x30^ -gravity center -extent 30x30 -quality 100 JPEG:".$xxthumb_file);
177  }
178  else
179  {
180  ilUtil::execConvert($uploaded_file . "[0] -geometry 200x200 -quality 100 JPEG:".$show_file);
181  ilUtil::execConvert($uploaded_file . "[0] -geometry 100x100 -quality 100 JPEG:".$thumb_file);
182  ilUtil::execConvert($uploaded_file . "[0] -geometry 75x75 -quality 100 JPEG:".$xthumb_file);
183  ilUtil::execConvert($uploaded_file . "[0] -geometry 30x30 -quality 100 JPEG:".$xxthumb_file);
184  }
185  }
186  }
187 
188 // $this->saveProfile();
189  }
190 
194  function removeUserPicture()
195  {
196  global $ilUser;
197 
198  $ilUser->removeUserPicture();
199 
200  $this->saveProfile();
201  }
202 
203 
204 
208  function saveProfile()
209  {
210  global $ilUser ,$ilSetting, $ilAuth;
211 
212  //init checking var
213  $form_valid = true;
214 
215  // testing by ratana ty:
216  // if people check on check box it will
217  // write some datata to table usr_pref
218  // if check on Public Profile
219  if (($_POST["chk_pub"])=="on")
220  {
221  $ilUser->setPref("public_profile","y");
222  }
223  else
224  {
225  $ilUser->setPref("public_profile","n");
226  }
227 
228  // if check on Institute
229  $val_array = array("institution", "department", "upload", "street",
230  "zip", "city", "country", "phone_office", "phone_home", "phone_mobile",
231  "fax", "email", "hobby", "matriculation");
232 
233  // set public profile preferences
234  foreach($val_array as $key => $value)
235  {
236  if (($_POST["chk_".$value]) == "on")
237  {
238  $ilUser->setPref("public_".$value,"y");
239  }
240  else
241  {
242  $ilUser->setPref("public_".$value,"n");
243  }
244  }
245 
246  $d_set = new ilSetting("delicious");
247  if ($d_set->get("user_profile"))
248  {
249  if (($_POST["chk_delicious"]) == "on")
250  {
251  $ilUser->setPref("public_delicious","y");
252  }
253  else
254  {
255  $ilUser->setPref("public_delicious","n");
256  }
257  }
258 
259 
260  // check dynamically required fields
261  foreach($this->settings as $key => $val)
262  {
263  if (substr($key,0,8) == "require_")
264  {
265  $require_keys[] = substr($key,8);
266  }
267  }
268 
269  foreach($require_keys as $key => $val)
270  {
271  // exclude required system and registration-only fields
272  $system_fields = array("login", "default_role", "passwd", "passwd2");
273  if (!in_array($val, $system_fields))
274  {
275  if ($this->workWithUserSetting($val))
276  {
277  if (isset($this->settings["require_" . $val]) && $this->settings["require_" . $val])
278  {
279  if (empty($_POST["usr_" . $val]))
280  {
281  ilUtil::sendFailure($this->lng->txt("fill_out_all_required_fields") . ": " . $this->lng->txt($val));
282  $form_valid = false;
283  }
284  }
285  }
286  }
287  }
288 
289  // Check user defined required fields
290  if($form_valid and !$this->__checkUserDefinedRequiredFields())
291  {
292  ilUtil::sendFailure($this->lng->txt("fill_out_all_required_fields"));
293  $form_valid = false;
294  }
295 
296  // check email
297  if ($this->workWithUserSetting("email"))
298  {
299  if (!ilUtil::is_email($_POST["usr_email"]) and !empty($_POST["usr_email"]) and $form_valid)
300  {
301  ilUtil::sendFailure($this->lng->txt("email_not_valid"));
302  $form_valid = false;
303  }
304  }
305 
306  //update user data (not saving!)
307  if ($this->workWithUserSetting("firstname"))
308  {
309  $ilUser->setFirstName(ilUtil::stripSlashes($_POST["usr_firstname"]));
310  }
311  if ($this->workWithUserSetting("lastname"))
312  {
313  $ilUser->setLastName(ilUtil::stripSlashes($_POST["usr_lastname"]));
314  }
315  if ($this->workWithUserSetting("gender"))
316  {
317  $ilUser->setGender($_POST["usr_gender"]);
318  }
319  if ($this->workWithUserSetting("title"))
320  {
321  $ilUser->setUTitle(ilUtil::stripSlashes($_POST["usr_title"]));
322  }
323  $ilUser->setFullname();
324  if ($this->workWithUserSetting("institution"))
325  {
326  $ilUser->setInstitution(ilUtil::stripSlashes($_POST["usr_institution"]));
327  }
328  if ($this->workWithUserSetting("department"))
329  {
330  $ilUser->setDepartment(ilUtil::stripSlashes($_POST["usr_department"]));
331  }
332  if ($this->workWithUserSetting("street"))
333  {
334  $ilUser->setStreet(ilUtil::stripSlashes($_POST["usr_street"]));
335  }
336  if ($this->workWithUserSetting("zipcode"))
337  {
338  $ilUser->setZipcode(ilUtil::stripSlashes($_POST["usr_zipcode"]));
339  }
340  if ($this->workWithUserSetting("city"))
341  {
342  $ilUser->setCity(ilUtil::stripSlashes($_POST["usr_city"]));
343  }
344  if ($this->workWithUserSetting("country"))
345  {
346  $ilUser->setCountry(ilUtil::stripSlashes($_POST["usr_country"]));
347  }
348  if ($this->workWithUserSetting("phone_office"))
349  {
350  $ilUser->setPhoneOffice(ilUtil::stripSlashes($_POST["usr_phone_office"]));
351  }
352  if ($this->workWithUserSetting("phone_home"))
353  {
354  $ilUser->setPhoneHome(ilUtil::stripSlashes($_POST["usr_phone_home"]));
355  }
356  if ($this->workWithUserSetting("phone_mobile"))
357  {
358  $ilUser->setPhoneMobile(ilUtil::stripSlashes($_POST["usr_phone_mobile"]));
359  }
360  if ($this->workWithUserSetting("fax"))
361  {
362  $ilUser->setFax(ilUtil::stripSlashes($_POST["usr_fax"]));
363  }
364  if ($this->workWithUserSetting("email"))
365  {
366  $ilUser->setEmail(ilUtil::stripSlashes($_POST["usr_email"]));
367  }
368  if ($this->workWithUserSetting("hobby"))
369  {
370  $ilUser->setHobby(ilUtil::stripSlashes($_POST["usr_hobby"]));
371  }
372  if ($this->workWithUserSetting("referral_comment"))
373  {
374  $ilUser->setComment(ilUtil::stripSlashes($_POST["usr_referral_comment"]));
375  }
376  if ($this->workWithUserSetting("matriculation"))
377  {
378  $ilUser->setMatriculation(ilUtil::stripSlashes($_POST["usr_matriculation"]));
379  }
380 
381  // delicious
382  $d_set = new ilSetting("delicious");
383  if ($d_set->get("user_profile"))
384  {
385  $ilUser->setDelicious(ilUtil::stripSlashes($_POST["usr_delicious"]));
386  }
387 
388  // set instant messengers
389  if ($this->workWithUserSetting("instant_messengers"))
390  {
391  $ilUser->setInstantMessengerId('icq',ilUtil::stripSlashes($_POST["usr_im_icq"]));
392  $ilUser->setInstantMessengerId('yahoo',ilUtil::stripSlashes($_POST["usr_im_yahoo"]));
393  $ilUser->setInstantMessengerId('msn',ilUtil::stripSlashes($_POST["usr_im_msn"]));
394  $ilUser->setInstantMessengerId('aim',ilUtil::stripSlashes($_POST["usr_im_aim"]));
395  $ilUser->setInstantMessengerId('skype',ilUtil::stripSlashes($_POST["usr_im_skype"]));
396  $ilUser->setInstantMessengerId('jabber',ilUtil::stripSlashes($_POST["usr_im_jabber"]));
397  $ilUser->setInstantMessengerId('voip',ilUtil::stripSlashes($_POST["usr_im_voip"]));
398  }
399 
400  // Set user defined data
401  $ilUser->setUserDefinedData($_POST['udf']);
402 
403  // everthing's ok. save form data
404  if ($form_valid)
405  {
406  // init reload var. page should only be reloaded if skin or style were changed
407  $reload = false;
408 
409  if ($this->workWithUserSetting("skin_style"))
410  {
411  //set user skin and style
412  if ($_POST["usr_skin_style"] != "")
413  {
414  $sknst = explode(":", $_POST["usr_skin_style"]);
415 
416  if ($ilUser->getPref("style") != $sknst[1] ||
417  $ilUser->getPref("skin") != $sknst[0])
418  {
419  $ilUser->setPref("skin", $sknst[0]);
420  $ilUser->setPref("style", $sknst[1]);
421  $reload = true;
422  }
423  }
424  }
425 
426  if ($this->workWithUserSetting("language"))
427  {
428  // reload page if language was changed
429  //if ($_POST["usr_language"] != "" and $_POST["usr_language"] != $_SESSION['lang'])
430  // (this didn't work as expected, alex)
431  if ($_POST["usr_language"] != $ilUser->getLanguage())
432  {
433  $reload = true;
434  }
435 
436  // set user language
437  $ilUser->setLanguage($_POST["usr_language"]);
438 
439  }
440  if ($this->workWithUserSetting("hits_per_page"))
441  {
442  // set user hits per page
443  if ($_POST["hits_per_page"] != "")
444  {
445  $ilUser->setPref("hits_per_page",$_POST["hits_per_page"]);
446  }
447  }
448 
449  // set show users online
450  if ($this->workWithUserSetting("show_users_online"))
451  {
452  $ilUser->setPref("show_users_online", $_POST["show_users_online"]);
453  }
454 
455  // set hide own online_status
456  if ($this->workWithUserSetting("hide_own_online_status"))
457  {
458  if ($_POST["chk_hide_own_online_status"] != "")
459  {
460  $ilUser->setPref("hide_own_online_status","y");
461  }
462  else
463  {
464  $ilUser->setPref("hide_own_online_status","n");
465  }
466  }
467 
468  // personal desktop items in news block
469 /* Subscription Concept is abandonded for now, we show all news of pd items (Alex)
470  if ($_POST["pd_items_news"] != "")
471  {
472  $ilUser->setPref("pd_items_news","y");
473  }
474  else
475  {
476  $ilUser->setPref("pd_items_news","n");
477  }
478 */
479 
480  // profile ok
481  $ilUser->setProfileIncomplete(false);
482 
483  // save user data & object_data
484  $ilUser->setTitle($ilUser->getFullname());
485  $ilUser->setDescription($ilUser->getEmail());
486 
487  $ilUser->update();
488 
489  // reload page only if skin or style were changed
490  // feedback
491  if (!empty($this->password_error))
492  {
493  ilUtil::sendFailure($this->password_error,true);
494  }
495  elseif (!empty($this->upload_error))
496  {
497  ilUtil::sendFailure($this->upload_error,true);
498  }
499  else if ($reload)
500  {
501  // feedback
502  ilUtil::sendSuccess($this->lng->txt("saved_successfully"),true);
503  $this->ctrl->redirect($this, "");
504  //$this->tpl->setVariable("RELOAD","<script language=\"Javascript\">\ntop.location.href = \"./start.php\";\n</script>\n");
505  }
506  else
507  {
508  ilUtil::sendSuccess($this->lng->txt("saved_successfully"),true);
509  }
510  }
511 
512  $this->showProfile();
513  }
514 
520  function showProfile()
521  {
522  $this->showPersonalData();
523  }
524 
531  function addLocationToForm(ilPropertyFormGUI $a_form, ilObjUser $a_user)
532  {
533  global $ilCtrl;
534 
535  // check google map activation
536  include_once("./Services/GoogleMaps/classes/class.ilGoogleMapUtil.php");
538  {
539  return;
540  }
541 
542  $this->lng->loadLanguageModule("gmaps");
543 
544  // Get user settings
545  $latitude = $a_user->getLatitude();
546  $longitude = $a_user->getLongitude();
547  $zoom = $a_user->getLocationZoom();
548 
549  // Get Default settings, when nothing is set
550  if ($latitude == 0 && $longitude == 0 && $zoom == 0)
551  {
553  $latitude = $def["latitude"];
554  $longitude = $def["longitude"];
555  $zoom = $def["zoom"];
556  }
557 
558  $street = $a_user->getStreet();
559  if (!$street)
560  {
561  $street = $this->lng->txt("street");
562  }
563  $city = $a_user->getCity();
564  if (!$city)
565  {
566  $city = $this->lng->txt("city");
567  }
568  $country = $a_user->getCountry();
569  if (!$country)
570  {
571  $country = $this->lng->txt("country");
572  }
573 
574  // location property
575  $loc_prop = new ilLocationInputGUI($this->lng->txt("location"),
576  "location");
577  $loc_prop->setLatitude($latitude);
578  $loc_prop->setLongitude($longitude);
579  $loc_prop->setZoom($zoom);
580  $loc_prop->setAddress($street.",".$city.",".$country);
581 
582  $a_form->addItem($loc_prop);
583  }
584 
585  // init sub tabs
586  function setTabs()
587  {
588  global $ilTabs, $ilUser;
589 
590  // personal data
591  $ilTabs->addTab("personal_data",
592  $this->lng->txt("personal_data"),
593  $this->ctrl->getLinkTarget($this, "showPersonalData"));
594 
595  // public profile
596  $ilTabs->addTab("public_profile",
597  $this->lng->txt("public_profile"),
598  $this->ctrl->getLinkTarget($this, "showPublicProfile"));
599 
600  if($ilUser->getPref("public_profile") != "n" || $this->getProfilePortfolio())
601  {
602  // profile preview
603  $ilTabs->addNonTabbedLink("profile_preview",
604  $this->lng->txt("user_profile_preview"),
605  $this->ctrl->getLinkTargetByClass("ilpublicuserprofilegui", "view"));
606  }
607  }
608 
609 
611  {
612  $d_set = new ilSetting("delicous");
613  if($this->userSettingVisible("matriculation") or count($this->user_defined_fields->getVisibleDefinitions())
614  or $d_set->get("user_profile") == "1")
615  {
616  return true;
617  }
618  return false;
619  }
620 
622  {
623  global $ilUser;
624 
625  $user_defined_data = $ilUser->getUserDefinedData();
626  foreach($this->user_defined_fields->getVisibleDefinitions() as $field_id => $definition)
627  {
628  if($definition['field_type'] == UDF_TYPE_TEXT)
629  {
630  $this->tpl->setCurrentBlock("field_text");
631  $this->tpl->setVariable("FIELD_VALUE",ilUtil::prepareFormOutput($user_defined_data[$field_id]));
632  if(!$definition['changeable'])
633  {
634  $this->tpl->setVariable("DISABLED_FIELD",'disabled=\"disabled\"');
635  $this->tpl->setVariable("FIELD_NAME",'udf['.$definition['field_id'].']');
636  }
637  else
638  {
639  $this->tpl->setVariable("FIELD_NAME",'udf['.$definition['field_id'].']');
640  }
641  $this->tpl->parseCurrentBlock();
642  }
643  else
644  {
645  if($definition['changeable'])
646  {
647  $name = 'udf['.$definition['field_id'].']';
648  $disabled = false;
649  }
650  else
651  {
652  $name = '';
653  $disabled = true;
654  }
655  $this->tpl->setCurrentBlock("field_select");
656  $this->tpl->setVariable("SELECT_BOX",ilUtil::formSelect($user_defined_data[$field_id],
657  $name,
658  $this->user_defined_fields->fieldValuesToSelectArray(
659  $definition['field_values']),
660  false,
661  true,0,'','',$disabled));
662  $this->tpl->parseCurrentBlock();
663  }
664  $this->tpl->setCurrentBlock("user_defined");
665 
666  if($definition['required'])
667  {
668  $name = $definition['field_name']."<span class=\"asterisk\">*</span>";
669  }
670  else
671  {
672  $name = $definition['field_name'];
673  }
674  $this->tpl->setVariable("TXT_FIELD_NAME",$name);
675  $this->tpl->parseCurrentBlock();
676  }
677  return true;
678  }
679 
681  {
682  foreach($this->user_defined_fields->getVisibleDefinitions() as $definition)
683  {
684  $field_id = $definition['field_id'];
685  if($definition['required'] and !strlen($_POST['udf'][$field_id]))
686  {
687  return false;
688  }
689  }
690  return true;
691  }
692 
696  function setHeader()
697  {
698 // $this->tpl->setTitleIcon(ilUtil::getImagePath("icon_pd_b.gif"), "");
699  $this->tpl->setVariable('HEADER', $this->lng->txt('personal_profile'));
700  }
701 
702  //
703  //
704  // PERSONAL DATA FORM
705  //
706  //
707 
711  function showPersonalData($a_no_init = false)
712  {
713  global $ilUser, $styleDefinition, $rbacreview, $ilias, $lng, $ilSetting, $ilTabs;
714 
715  $ilTabs->activateTab("personal_data");
716 
717  $settings = $ilias->getAllSettings();
718 
719  $this->setHeader();
720 
721  if (!$a_no_init)
722  {
723  $this->initPersonalDataForm();
724  // catch feedback message
725  if ($ilUser->getProfileIncomplete())
726  {
727  ilUtil::sendInfo($lng->txt("profile_incomplete"));
728  }
729  }
730  $this->tpl->setContent($this->form->getHTML());
731 
732  $this->tpl->show();
733  }
734 
739  {
740  global $ilSetting, $lng, $ilUser, $styleDefinition, $rbacreview;
741 
742  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
743  $this->form = new ilPropertyFormGUI();
744  $this->form->setFormAction($this->ctrl->getFormAction($this));
745 
746  // user defined fields
747  $user_defined_data = $ilUser->getUserDefinedData();
748 
749  foreach($this->user_defined_fields->getVisibleDefinitions() as $field_id => $definition)
750  {
751  if($definition['field_type'] == UDF_TYPE_TEXT)
752  {
753  $this->input["udf_".$definition['field_id']] =
754  new ilTextInputGUI($definition['field_name'], "udf_".$definition['field_id']);
755  $this->input["udf_".$definition['field_id']]->setMaxLength(255);
756  $this->input["udf_".$definition['field_id']]->setSize(40);
757  }
758  else if($definition['field_type'] == UDF_TYPE_WYSIWYG)
759  {
760  $this->input["udf_".$definition['field_id']] =
761  new ilTextAreaInputGUI($definition['field_name'], "udf_".$definition['field_id']);
762  $this->input["udf_".$definition['field_id']]->setUseRte(true);
763  }
764  else
765  {
766  $options = $this->user_defined_fields->fieldValuesToSelectArray($definition['field_values']);
767  $this->input["udf_".$definition['field_id']] =
768  new ilSelectInputGUI($definition['field_name'], "udf_".$definition['field_id']);
769  $this->input["udf_".$definition['field_id']]->setOptions($options);
770  }
771 
772  $value = $user_defined_data["f_".$field_id];
773  $this->input["udf_".$definition['field_id']]->setValue($value);
774 
775  if($definition['required'])
776  {
777  $this->input["udf_".$definition['field_id']]->setRequired(true);
778  }
779  if(!$definition['changeable'] && (!$definition['required'] || $value))
780  {
781  $this->input["udf_".$definition['field_id']]->setDisabled(true);
782  }
783 
784  // add "please select" if no current value
785  if($definition['field_type'] == UDF_TYPE_SELECT && !$value)
786  {
787  $options = array(""=>$lng->txt("please_select")) + $options;
788  $this->input["udf_".$definition['field_id']]->setOptions($options);
789  }
790  }
791 
792  // standard fields
793  include_once("./Services/User/classes/class.ilUserProfile.php");
794  $up = new ilUserProfile();
795  $up->skipField("password");
796  $up->skipGroup("settings");
797  $up->skipGroup("preferences");
798 
799  // standard fields
800  $up->addStandardFieldsToForm($this->form, $ilUser, $this->input);
801 
802  $this->addLocationToForm($this->form, $ilUser);
803 
804  $this->form->addCommandButton("savePersonalData", $lng->txt("save"));
805 
806  }
807 
812  public function savePersonalData()
813  {
814  global $tpl, $lng, $ilCtrl, $ilUser, $ilSetting, $ilAuth;
815 
816  $this->initPersonalDataForm();
817  if ($this->form->checkInput())
818  {
819  $form_valid = true;
820 
821  // if form field name differs from setter
822  $map = array(
823  "firstname" => "FirstName",
824  "lastname" => "LastName",
825  "title" => "UTitle",
826  "sel_country" => "SelectedCountry",
827  "phone_office" => "PhoneOffice",
828  "phone_home" => "PhoneHome",
829  "phone_mobile" => "PhoneMobile",
830  "referral_comment" => "Comment"
831  );
832  include_once("./Services/User/classes/class.ilUserProfile.php");
833  $up = new ilUserProfile();
834  foreach($up->getStandardFields() as $f => $p)
835  {
836  // if item is part of form, it is currently valid (if not disabled)
837  $item = $this->form->getItemByPostVar("usr_".$f);
838  if($item && !$item->getDisabled())
839  {
840  $value = $this->form->getInput("usr_".$f);
841  switch($f)
842  {
843  case "birthday":
844  if (is_array($value))
845  {
846  if (is_array($value['date']))
847  {
848  if (($value['d'] > 0) && ($value['m'] > 0) && ($value['y'] > 0))
849  {
850  $ilUser->setBirthday(sprintf("%04d-%02d-%02d", $value['y'], $value['m'], $value['d']));
851  }
852  else
853  {
854  $ilUser->setBirthday("");
855  }
856  }
857  else
858  {
859  $ilUser->setBirthday($value['date']);
860  }
861  }
862  break;
863 
864  default:
865  $m = ucfirst($f);
866  if(isset($map[$f]))
867  {
868  $m = $map[$f];
869  }
870  $ilUser->{"set".$m}($value);
871  break;
872  }
873  }
874  }
875  $ilUser->setFullname();
876 
877  // set instant messengers
878  if ($this->workWithUserSetting("instant_messengers"))
879  {
880  $ilUser->setInstantMessengerId('icq', $this->form->getInput("usr_im_icq"));
881  $ilUser->setInstantMessengerId('yahoo', $this->form->getInput("usr_im_yahoo"));
882  $ilUser->setInstantMessengerId('msn', $this->form->getInput("usr_im_msn"));
883  $ilUser->setInstantMessengerId('aim', $this->form->getInput("usr_im_aim"));
884  $ilUser->setInstantMessengerId('skype', $this->form->getInput("usr_im_skype"));
885  $ilUser->setInstantMessengerId('jabber', $this->form->getInput("usr_im_jabber"));
886  $ilUser->setInstantMessengerId('voip', $this->form->getInput("usr_im_voip"));
887  }
888 
889  // check google map activation
890  include_once("./Services/GoogleMaps/classes/class.ilGoogleMapUtil.php");
892  {
893  $location = $this->form->getInput("location");
894  $ilUser->setLatitude(ilUtil::stripSlashes($location["latitude"]));
895  $ilUser->setLongitude(ilUtil::stripSlashes($location["longitude"]));
896  $ilUser->setLocationZoom(ilUtil::stripSlashes($location["zoom"]));
897  }
898 
899  // Set user defined data
900  $defs = $this->user_defined_fields->getVisibleDefinitions();
901  $udf = array();
902  foreach ($defs as $definition)
903  {
904  $f = "udf_".$definition['field_id'];
905  $item = $this->form->getItemByPostVar($f);
906  if ($item && !$item->getDisabled())
907  {
908  $udf[$definition['field_id']] = $this->form->getInput($f);
909  }
910  }
911  $ilUser->setUserDefinedData($udf);
912 
913  // if loginname is changeable -> validate
914  $un = $this->form->getInput('username');
915  if((int)$ilSetting->get('allow_change_loginname') &&
916  $un != $ilUser->getLogin())
917  {
918  if(!strlen($un) || !ilUtil::isLogin($un))
919  {
920  ilUtil::sendFailure($lng->txt('form_input_not_valid'));
921  $this->form->getItemByPostVar('username')->setAlert($this->lng->txt('login_invalid'));
922  $form_valid = false;
923  }
924  else if(ilObjUser::_loginExists($un, $ilUser->getId()))
925  {
926  ilUtil::sendFailure($lng->txt('form_input_not_valid'));
927  $this->form->getItemByPostVar('username')->setAlert($this->lng->txt('loginname_already_exists'));
928  $form_valid = false;
929  }
930  else
931  {
932  $ilUser->setLogin($un);
933 
934  try
935  {
936  $ilUser->updateLogin($ilUser->getLogin());
937  $ilAuth->setAuth($ilUser->getLogin());
938  $ilAuth->start();
939  }
940  catch (ilUserException $e)
941  {
942  ilUtil::sendFailure($lng->txt('form_input_not_valid'));
943  $this->form->getItemByPostVar('username')->setAlert($e->getMessage());
944  $form_valid = false;
945  }
946  }
947  }
948 
949  // everthing's ok. save form data
950  if ($form_valid)
951  {
952  $this->uploadUserPicture();
953 
954  // profile ok
955  $ilUser->setProfileIncomplete(false);
956 
957  // save user data & object_data
958  $ilUser->setTitle($ilUser->getFullname());
959  $ilUser->setDescription($ilUser->getEmail());
960 
961  $ilUser->update();
962 
963  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
964  if ($redirect = $_SESSION['profile_complete_redirect']) {
965  unset($_SESSION['profile_complete_redirect']);
967  }
968  else
969  $ilCtrl->redirect($this, "showPersonalData");
970  }
971  }
972 
973  $this->form->setValuesByPost();
974  $this->showPersonalData(true);
975  }
976 
977  //
978  //
979  // PUBLIC PROFILE FORM
980  //
981  //
982 
986  function showPublicProfile($a_no_init = false)
987  {
988  global $ilUser, $lng, $ilSetting, $ilTabs;
989 
990  $ilTabs->activateTab("public_profile");
991 
992  $this->setHeader();
993 
994  if (!$a_no_init)
995  {
996  $this->initPublicProfileForm();
997  }
998 
999  $ptpl = new ilTemplate("tpl.edit_personal_profile.html", true, true, "Services/User");
1000  $ptpl->setVariable("FORM", $this->form->getHTML());
1001  include_once("./Services/User/classes/class.ilPublicUserProfileGUI.php");
1002  $pub_profile = new ilPublicUserProfileGUI($ilUser->getId());
1003  $ptpl->setVariable("PREVIEW", $pub_profile->getEmbeddable());
1004  $this->tpl->setContent($ptpl->get());
1005  $this->tpl->show();
1006  }
1007 
1013  protected function getProfilePortfolio()
1014  {
1015  global $ilUser, $ilSetting;
1016 
1017  if ($ilSetting->get('user_portfolios'))
1018  {
1019  include_once "Services/Portfolio/classes/class.ilObjPortfolio.php";
1020  return ilObjPortfolio::getDefaultPortfolio($ilUser->getId());
1021  }
1022  }
1023 
1029  public function initPublicProfileForm()
1030  {
1031  global $lng, $ilUser, $ilSetting;
1032 
1033  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
1034  $this->form = new ilPropertyFormGUI();
1035 
1036  $this->form->setTitle($lng->txt("public_profile"));
1037  $this->form->setDescription($lng->txt("user_public_profile_info").$prtf);
1038  $this->form->setFormAction($this->ctrl->getFormAction($this));
1039 
1040  $portfolio_id = $this->getProfilePortfolio();
1041 
1042  if(!$portfolio_id)
1043  {
1044  // Activate public profile
1045  $radg = new ilRadioGroupInputGUI($lng->txt("user_activate_public_profile"), "public_profile");
1046  $radg->setInfo($this->lng->txt("user_activate_public_profile_info"));
1047  $pub_prof = in_array($ilUser->prefs["public_profile"], array("y", "n", "g"))
1048  ? $ilUser->prefs["public_profile"]
1049  : "n";
1050  if (!$ilSetting->get('enable_global_profiles') && $pub_prof == "g")
1051  {
1052  $pub_prof = "y";
1053  }
1054  $radg->setValue($pub_prof);
1055  $op1 = new ilRadioOption($lng->txt("usr_public_profile_disabled"), "n",$lng->txt("usr_public_profile_disabled_info"));
1056  $radg->addOption($op1);
1057  $op2 = new ilRadioOption($lng->txt("usr_public_profile_logged_in"), "y");
1058  $radg->addOption($op2);
1059  if ($ilSetting->get('enable_global_profiles'))
1060  {
1061  $op3 = new ilRadioOption($lng->txt("usr_public_profile_global"), "g");
1062  $radg->addOption($op3);
1063  }
1064  $this->form->addItem($radg);
1065 
1066  $radg->setInfo($lng->txt("user_profile_portfolio"));
1067  }
1068  else
1069  {
1070  $prtf = $lng->txt("user_profile_portfolio_selected");
1071  $prtf .= "<br /><a href=\"ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToPortfolio&prt_id=".$portfolio_id."\">&raquo; ".
1072  $lng->txt("portfolio")."</a>";
1073 
1074  $info = new ilCustomInputGUI($lng->txt("user_activate_public_profile"));
1075  $info->setHTML($prtf);
1076  $this->form->addItem($info);
1077  }
1078 
1079  $this->showPublicProfileFields($this->form, $ilUser->prefs);
1080 
1081  $this->form->addCommandButton("savePublicProfile", $lng->txt("save"));
1082  }
1083 
1091  public function showPublicProfileFields(ilPropertyformGUI $form, array $prefs, $parent = null)
1092  {
1093  global $ilUser;
1094 
1095  $birthday = $ilUser->getBirthday();
1096  if($birthday)
1097  {
1098  $birthday = ilDatePresentation::formatDate(new ilDate($birthday, IL_CAL_DATE));
1099  }
1100  $gender = $ilUser->getGender();
1101  if($gender)
1102  {
1103  $gender = $this->lng->txt("gender_".$gender);
1104  }
1105 
1106  if ($ilUser->getSelectedCountry() != "")
1107  {
1108  $this->lng->loadLanguageModule("meta");
1109  $txt_sel_country = $this->lng->txt("meta_c_".$ilUser->getSelectedCountry());
1110  }
1111 
1112  // personal data
1113  $val_array = array(
1114  "title" => $ilUser->getUTitle(),
1115  "birthday" => $birthday,
1116  "gender" => $gender,
1117  "institution" => $ilUser->getInstitution(),
1118  "department" => $ilUser->getDepartment(),
1119  "upload" => "",
1120  "street" => $ilUser->getStreet(),
1121  "zipcode" => $ilUser->getZipcode(),
1122  "city" => $ilUser->getCity(),
1123  "country" => $ilUser->getCountry(),
1124  "sel_country" => $txt_sel_country,
1125  "phone_office" => $ilUser->getPhoneOffice(),
1126  "phone_home" => $ilUser->getPhoneHome(),
1127  "phone_mobile" => $ilUser->getPhoneMobile(),
1128  "fax" => $ilUser->getFax(),
1129  "email" => $ilUser->getEmail(),
1130  "hobby" => $ilUser->getHobby(),
1131  "matriculation" => $ilUser->getMatriculation(),
1132  "delicious" => $ilUser->getDelicious()
1133  );
1134 
1135  // location
1136  include_once("./Services/GoogleMaps/classes/class.ilGoogleMapUtil.php");
1138  {
1139  $val_array["location"] = "";
1140  }
1141 
1142  foreach($val_array as $key => $value)
1143  {
1144  if ($this->userSettingVisible($key))
1145  {
1146  // public setting
1147  if ($key == "upload")
1148  {
1149  $cb = new ilCheckboxInputGUI($this->lng->txt("personal_picture"), "chk_".$key);
1150  }
1151  else
1152  {
1153  $cb = new ilCheckboxInputGUI($this->lng->txt($key), "chk_".$key);
1154  }
1155  if ($prefs["public_".$key] == "y")
1156  {
1157  $cb->setChecked(true);
1158  }
1159  //$cb->setInfo($value);
1160  $cb->setOptionTitle($value);
1161 
1162  if(!$parent)
1163  {
1164  $form->addItem($cb);
1165  }
1166  else
1167  {
1168  $parent->addSubItem($cb);
1169  }
1170  }
1171  }
1172 
1173  $im_arr = array("icq","yahoo","msn","aim","skype","jabber","voip");
1174  if ($this->userSettingVisible("instant_messengers"))
1175  {
1176  foreach ($im_arr as $im)
1177  {
1178  // public setting
1179  $cb = new ilCheckboxInputGUI($this->lng->txt("im_".$im), "chk_im_".$im);
1180  //$cb->setInfo($ilUser->getInstantMessengerId($im));
1181  $cb->setOptionTitle($ilUser->getInstantMessengerId($im));
1182  if ($prefs["public_im_".$im] != "n")
1183  {
1184  $cb->setChecked(true);
1185  }
1186 
1187  if(!$parent)
1188  {
1189  $form->addItem($cb);
1190  }
1191  else
1192  {
1193  $parent->addSubItem($cb);
1194  }
1195  }
1196  }
1197 
1198  // additional defined user data fields
1199  $user_defined_data = $ilUser->getUserDefinedData();
1200  foreach($this->user_defined_fields->getVisibleDefinitions() as $field_id => $definition)
1201  {
1202  // public setting
1203  $cb = new ilCheckboxInputGUI($definition["field_name"], "chk_udf_".$definition["field_id"]);
1204  $cb->setOptionTitle($user_defined_data["f_".$definition["field_id"]]);
1205  if ($prefs["public_udf_".$definition["field_id"]] == "y")
1206  {
1207  $cb->setChecked(true);
1208  }
1209 
1210  if(!$parent)
1211  {
1212  $form->addItem($cb);
1213  }
1214  else
1215  {
1216  $parent->addSubItem($cb);
1217  }
1218  }
1219  }
1220 
1225  public function savePublicProfile()
1226  {
1227  global $tpl, $lng, $ilCtrl, $ilUser;
1228 
1229  $this->initPublicProfileForm();
1230  if ($this->form->checkInput())
1231  {
1232  // with active portfolio no options are presented
1233  if(isset($_POST["public_profile"]))
1234  {
1235  $ilUser->setPref("public_profile", $_POST["public_profile"]);
1236  }
1237 
1238  // if check on Institute
1239  $val_array = array("title", "birthday", "gender", "institution", "department", "upload", "street",
1240  "zipcode", "city", "country", "sel_country", "phone_office", "phone_home", "phone_mobile",
1241  "fax", "email", "hobby", "matriculation", "location");
1242 
1243  // set public profile preferences
1244  foreach($val_array as $key => $value)
1245  {
1246  if (($_POST["chk_".$value]))
1247  {
1248  $ilUser->setPref("public_".$value,"y");
1249  }
1250  else
1251  {
1252  $ilUser->setPref("public_".$value,"n");
1253  }
1254  }
1255 
1256  $im_arr = array("icq","yahoo","msn","aim","skype","jabber","voip");
1257  if ($this->userSettingVisible("instant_messengers"))
1258  {
1259  foreach ($im_arr as $im)
1260  {
1261  if (($_POST["chk_im_".$im]))
1262  {
1263  $ilUser->setPref("public_im_".$im,"y");
1264  }
1265  else
1266  {
1267  $ilUser->setPref("public_im_".$im,"n");
1268  }
1269  }
1270  }
1271 
1272 // $d_set = new ilSetting("delicious");
1273 // if ($d_set->get("user_profile"))
1274 // {
1275  if (($_POST["chk_delicious"]))
1276  {
1277  $ilUser->setPref("public_delicious","y");
1278  }
1279  else
1280  {
1281  $ilUser->setPref("public_delicious","n");
1282  }
1283 // }
1284 
1285  // additional defined user data fields
1286  foreach($this->user_defined_fields->getVisibleDefinitions() as $field_id => $definition)
1287  {
1288  if (($_POST["chk_udf_".$definition["field_id"]]))
1289  {
1290  $ilUser->setPref("public_udf_".$definition["field_id"], "y");
1291  }
1292  else
1293  {
1294  $ilUser->setPref("public_udf_".$definition["field_id"], "n");
1295  }
1296  }
1297 
1298  $ilUser->update();
1299  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
1300  $ilCtrl->redirect($this, "showPublicProfile");
1301  }
1302  $this->form->setValuesByPost();
1303  $tpl->showPublicProfile(true);
1304  }
1305 }
1306 
1307 ?>