ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilPublicUserProfileGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
15 {
16  protected $userid; // [int]
17  protected $portfolioid; // [int]
18  protected $backurl; // [string]
19  protected $additional; // [string] used in forum
20  protected $embedded; // [bool] used in portfolio
21  protected $custom_prefs; // [array] used in portfolio
22 
28  function __construct($a_user_id = 0)
29  {
30  global $ilCtrl, $lng;
31 
32  if($a_user_id)
33  {
34  $this->setUserId($a_user_id);
35  }
36  else
37  {
38  $this->setUserId((int)$_GET["user_id"]);
39  }
40 
41  $ilCtrl->saveParameter($this, array("user_id","back_url", "user"));
42  if ($_GET["back_url"] != "")
43  {
44  $this->setBackUrl($_GET["back_url"]);
45  }
46 
47  $lng->loadLanguageModule("user");
48  }
49 
55  function setUserId($a_userid)
56  {
57  $this->userid = $a_userid;
58  }
59 
65  function getUserId()
66  {
67  return $this->userid;
68  }
69 
75  function setAdditional($a_additional)
76  {
77  $this->additional = $a_additional;
78  }
79 
85  function getAdditional()
86  {
87  return $this->additional;
88  }
89 
95  function setBackUrl($a_backurl)
96  {
97  global $ilCtrl;
98 
99  // we only allow relative links
100  $parts = parse_url($a_backurl);
101  if($parts["host"])
102  {
103  $a_backurl = "#";
104  }
105 
106  $this->backurl = $a_backurl;
107  $ilCtrl->setParameter($this, "back_url", rawurlencode($a_backurl));
108  }
109 
110  protected function handleBackUrl($a_is_portfolio = false)
111  {
112  global $ilMainMenu, $ilTabs, $lng;
113 
114  $back = ($this->getBackUrl() != "")
115  ? $this->getBackUrl()
116  : $_GET["back_url"];
117 
118  if(!$back)
119  {
120  // #15984
121  $back = 'ilias.php?baseClass=ilPersonalDesktopGUI';
122  }
123 
124  if((bool)$a_is_portfolio)
125  {
126  $ilMainMenu->setTopBarBack($back);
127  }
128  else
129  {
130  // #17838
131  $ilTabs->clearTargets();
132  $ilTabs->setBackTarget($lng->txt("back"),
133  $back);
134  }
135  }
136 
142  function getBackUrl()
143  {
144  return $this->backurl;
145  }
146 
152  function setCustomPrefs(array $a_prefs)
153  {
154  $this->custom_prefs = $a_prefs;
155  }
156 
166  protected function getPublicPref(ilObjUser $a_user, $a_id)
167  {
168  if(!$this->custom_prefs)
169  {
170  return $a_user->getPref($a_id);
171  }
172  else
173  {
174  return $this->custom_prefs[$a_id];
175  }
176  }
177 
178  function setEmbedded($a_value, $a_offline = false)
179  {
180  $this->embedded = (bool)$a_value;
181  $this->offline = (bool)$a_offline;
182  }
183 
187  function executeCommand()
188  {
189  global $ilCtrl, $tpl;
190 
191  if(!self::validateUser($this->getUserId()))
192  {
193  return;
194  }
195 
196  $next_class = $ilCtrl->getNextClass($this);
197  $cmd = $ilCtrl->getCmd();
198 
199  $tpl->getStandardTemplate();
200 
201  switch($next_class)
202  {
203  case "ilobjportfoliogui":
204  $portfolio_id = $this->getProfilePortfolio();
205  if($portfolio_id)
206  {
207  $this->handleBackUrl(true);
208 
209  include_once "Modules/Portfolio/classes/class.ilObjPortfolioGUI.php";
210  $gui = new ilObjPortfolioGUI($portfolio_id); // #11876
211  $gui->setAdditional($this->getAdditional());
212  $gui->setPermaLink($this->getUserId(), "usr");
213  $ilCtrl->forwardCommand($gui);
214  break;
215  }
216 
217  default:
218  $ret = $this->$cmd();
219  $tpl->setContent($ret);
220  break;
221  }
222 
223  // only for direct links
224  if (strtolower($_GET["baseClass"]) == "ilpublicuserprofilegui")
225  {
226  $tpl->show();
227  }
228  }
229 
233  function view()
234  {
235  return $this->getHTML();
236  }
237 
241  function getHTML()
242  {
243  global $ilCtrl, $ilSetting;
244 
245  if($this->embedded)
246  {
247  return $this->getEmbeddable();
248  }
249 
250  // #15438 - (currently) inactive user?
251  $is_active = true;
252  $user = new ilObjUser($this->getUserId());
253  if(!$user->getActive() ||
254  !$user->checkTimeLimit())
255  {
256  $is_active = false;
257  }
258 
259  if($is_active && $this->getProfilePortfolio())
260  {
261  $ilCtrl->redirectByClass("ilobjportfoliogui", "preview");
262  }
263  else
264  {
265  if(!$is_active)
266  {
267  return;
268  }
269 
270  // Check from Database if value
271  // of public_profile = "y" show user infomation
272  $user = new ilObjUser($this->getUserId());
273  if ($user->getPref("public_profile") != "y" &&
274  ($user->getPref("public_profile") != "g" || !$ilSetting->get('enable_global_profiles')) &&
275  !$this->custom_prefs)
276  {
277  return;
278  }
279 
280  $this->renderTitle();
281 
282  return $this->getEmbeddable(true);
283  }
284  }
285 
291  function getEmbeddable($a_add_goto = false)
292  {
294 
295  // get user object
296  if (!ilObject::_exists($this->getUserId()))
297  {
298  return "";
299  }
300  $user = new ilObjUser($this->getUserId());
301 
302  $tpl = new ilTemplate("tpl.usr_public_profile.html", true, true,
303  "Services/User");
304 
305  $tpl->setVariable("ROWCOL1", "tblrow1");
306  $tpl->setVariable("ROWCOL2", "tblrow2");
307 
308  if(!$this->offline && $ilUser->getId() != ANONYMOUS_USER_ID)
309  {
310  $ref_url = str_replace("&amp;", "&", $this->getBackUrl());
311  if(!$ref_url)
312  {
313  $ref_url = basename($_SERVER['REQUEST_URI']);
314  }
315 
316  $tpl->setCurrentBlock("mail");
317  $tpl->setVariable("TXT_MAIL", $lng->txt("send_mail"));
318  require_once 'Services/Mail/classes/class.ilMailFormCall.php';
319  $tpl->setVariable('HREF_MAIL', ilMailFormCall::getLinkTarget($ref_url, '', array(), array('type' => 'new', 'rcp_to' => urlencode($user->getLogin()))));
320  $tpl->parseCurrentBlock();
321  }
322 
323  $first_name = "";
324  if($this->getPublicPref($user, "public_title") == "y")
325  {
326  $first_name .= $user->getUTitle()." ";
327  }
328  $first_name .= $user->getFirstName();
329 
330  $tpl->setVariable("TXT_NAME", $lng->txt("name"));
331  $tpl->setVariable("FIRSTNAME", $first_name);
332  $tpl->setVariable("LASTNAME", $user->getLastName());
333 
334  if(!$this->offline)
335  {
336  // vcard
337  $tpl->setCurrentBlock("vcard");
338  $tpl->setVariable("TXT_VCARD", $lng->txt("vcard"));
339  $tpl->setVariable("TXT_DOWNLOAD_VCARD", $lng->txt("vcard_download"));
340  $ilCtrl->setParameter($this, "user", $this->getUserId());
341  $tpl->setVariable("HREF_VCARD", $ilCtrl->getLinkTarget($this, "deliverVCard"));
342  }
343 
344  $webspace_dir = ilUtil::getWebspaceDir("user");
345  $check_dir = ilUtil::getWebspaceDir();
346  $imagefile = $webspace_dir."/usr_images/".$user->getPref("profile_image")."?dummy=".rand(1,999999);
347  $check_file = $check_dir."/usr_images/".$user->getPref("profile_image");
348 
349  if (!@is_file($check_file))
350  {
351  $imagefile = $check_file =
352  ilObjUser::_getPersonalPicturePath($user->getId(), "small", false, true);
353  }
354 
355  if($this->offline)
356  {
357  $imagefile = basename($imagefile);
358  }
359 
360  if ($this->getPublicPref($user, "public_upload")=="y" && $imagefile != "")
361  {
362  //Getting the flexible path of image form ini file
363  //$webspace_dir = ilUtil::getWebspaceDir("output");
364  $tpl->setCurrentBlock("image");
365  $tpl->setVariable("TXT_IMAGE",$lng->txt("image"));
366  $tpl->setVariable("IMAGE_PATH", $imagefile);
367  $tpl->setVariable("IMAGE_ALT", $lng->txt("personal_picture"));
368  $tpl->parseCurrentBlock();
369  }
370 
371  // address
372  if ($this->getPublicPref($user, "public_street") == "y" ||
373  $this->getPublicPref($user, "public_zipcode") == "y" ||
374  $this->getPublicPref($user, "public_city") == "y" ||
375  $this->getPublicPref($user, "public_country") == "y")
376  {
377  $address = array();
378  $val_arr = array ("getStreet" => "street",
379  "getZipcode" => "zipcode",
380  "getCity" => "city",
381  "getCountry" => "country",
382  "getSelectedCountry" => "sel_country");
383  foreach ($val_arr as $key => $value)
384  {
385  // if value "y" show information
386  if ($this->getPublicPref($user, "public_".$value) == "y")
387  {
388  $address_value = $user->$key();
389 
390  // only if set
391  if (trim($address_value) != "")
392  {
393  switch($value)
394  {
395  case "street":
396  $address[0] = $address_value;
397  break;
398 
399  case "zipcode":
400  case "city":
401  $address[1] .= " ".$address_value;
402  break;
403 
404  case "sel_country":
405  $lng->loadLanguageModule("meta");
406  $address[2] = $lng->txt("meta_c_".$address_value);
407  break;
408 
409  case "country":
410  $address[2] = $address_value;
411  break;
412  }
413  }
414  }
415  }
416  if(sizeof($address))
417  {
418  $tpl->setCurrentBlock("address_line");
419  foreach($address as $line)
420  {
421  if(trim($line))
422  {
423  $tpl->setVariable("TXT_ADDRESS_LINE", trim($line));
424  $tpl->parseCurrentBlock();
425  }
426  }
427  $tpl->setCurrentBlock("address");
428  $tpl->setVariable("TXT_ADDRESS", $lng->txt("address"));
429  $tpl->parseCurrentBlock();
430  }
431  }
432 
433  // institution / department
434  if ($this->getPublicPref($user, "public_institution") == "y" ||
435  $this->getPublicPref($user, "public_department") == "y")
436  {
437  $tpl->setCurrentBlock("inst_dep");
438  $sep = "";
439  if ($this->getPublicPref($user, "public_institution") == "y")
440  {
441  $h = $lng->txt("institution");
442  $v = $user->getInstitution();
443  $sep = " / ";
444  }
445  if ($this->getPublicPref($user, "public_department") == "y")
446  {
447  $h.= $sep.$lng->txt("department");
448  $v.= $sep.$user->getDepartment();
449  }
450  $tpl->setVariable("TXT_INST_DEP", $h);
451  $tpl->setVariable("INST_DEP", $v);
452  $tpl->parseCurrentBlock();
453  }
454 
455  // contact
456  $val_arr = array(
457  "getPhoneOffice" => "phone_office", "getPhoneHome" => "phone_home",
458  "getPhoneMobile" => "phone_mobile", "getFax" => "fax", "getEmail" => "email");
459  $v = $sep = "";
460  foreach ($val_arr as $key => $value)
461  {
462  // if value "y" show information
463  if ($this->getPublicPref($user, "public_".$value) == "y")
464  {
465  $v.= $sep.$lng->txt($value).": ".$user->$key();
466  $sep = "<br />";
467  }
468  }
469  if ($ilSetting->get("usr_settings_hide_instant_messengers") != 1)
470  {
471  $im_arr = array("icq","yahoo","msn","aim","skype","jabber","voip");
472 
473  foreach ($im_arr as $im_name)
474  {
475  if ($im_id = $user->getInstantMessengerId($im_name))
476  {
477  if ($this->getPublicPref($user, "public_im_".$im_name) != "n")
478  {
479  $v.= $sep.$lng->txt('im_'.$im_name).": ".$im_id;
480  $sep = "<br />";
481  }
482  }
483  }
484  }
485  if ($v != "")
486  {
487  $tpl->parseCurrentBlock("contact");
488  $tpl->setVariable("TXT_CONTACT", $lng->txt("contact"));
489  $tpl->setVariable("CONTACT", $v);
490  $tpl->parseCurrentBlock();
491  }
492 
493 
494  $val_arr = array(
495  "getHobby" => "hobby",
496  "getGeneralInterestsAsText" => "interests_general",
497  "getOfferingHelpAsText" => "interests_help_offered",
498  "getLookingForHelpAsText" => "interests_help_looking",
499  "getMatriculation" => "matriculation",
500  "getClientIP" => "client_ip");
501 
502  foreach ($val_arr as $key => $value)
503  {
504  // if value "y" show information
505  if ($this->getPublicPref($user, "public_".$value) == "y")
506  {
507  $tpl->setCurrentBlock("profile_data");
508  $tpl->setVariable("TXT_DATA", $lng->txt($value));
509  $tpl->setVariable("DATA", $user->$key());
510  $tpl->parseCurrentBlock();
511  }
512  }
513 
514  // delicious row
515  //$d_set = new ilSetting("delicious");
516  if ($this->getPublicPref($user, "public_delicious") == "y")
517  {
518  $tpl->setCurrentBlock("delicious_row");
519  $tpl->setVariable("TXT_DELICIOUS", $lng->txt("delicious"));
520  $tpl->setVariable("TXT_DEL_ICON", $lng->txt("delicious"));
521  $tpl->setVariable("SRC_DEL_ICON", ilUtil::getImagePath("icon_delicious.png"));
522  $tpl->setVariable("DEL_ACCOUNT", $user->getDelicious());
523  $tpl->parseCurrentBlock();
524  }
525 
526  // map
527  include_once("./Services/Maps/classes/class.ilMapUtil.php");
528  if (ilMapUtil::isActivated() &&
529  $this->getPublicPref($user, "public_location") == "y" &&
530  $user->getLatitude() != "")
531  {
532  $tpl->setVariable("TXT_LOCATION", $lng->txt("location"));
533 
534  $map_gui = ilMapUtil::getMapGUI();
535  $map_gui->setMapId("user_map")
536  ->setWidth("350px")
537  ->setHeight("230px")
538  ->setLatitude($user->getLatitude())
539  ->setLongitude($user->getLongitude())
540  ->setZoom($user->getLocationZoom())
541  ->setEnableNavigationControl(true)
542  ->addUserMarker($user->getId());
543 
544  $tpl->setVariable("MAP_CONTENT", $map_gui->getHTML());
545  }
546 
547  // additional defined user data fields
548  include_once './Services/User/classes/class.ilUserDefinedFields.php';
549  $this->user_defined_fields =& ilUserDefinedFields::_getInstance();
550  $user_defined_data = $user->getUserDefinedData();
551  foreach($this->user_defined_fields->getVisibleDefinitions() as $field_id => $definition)
552  {
553  // public setting
554  if ($this->getPublicPref($user, "public_udf_".$definition["field_id"]) == "y")
555  {
556  if ($user_defined_data["f_".$definition["field_id"]] != "")
557  {
558  $tpl->setCurrentBlock("udf_data");
559  $tpl->setVariable("TXT_UDF_DATA", $definition["field_name"]);
560  $tpl->setVariable("UDF_DATA", $user_defined_data["f_".$definition["field_id"]]);
561  $tpl->parseCurrentBlock();
562  }
563  }
564  }
565 
566  // additional information
567  $additional = $this->getAdditional();
568  if (is_array($additional))
569  {
570  foreach($additional as $key => $val)
571  {
572  $tpl->setCurrentBlock("profile_data");
573  $tpl->setVariable("TXT_DATA", $key);
574  $tpl->setVariable("DATA", $val);
575  $tpl->parseCurrentBlock();
576  }
577  }
578 
579  $goto = "";
580  if($a_add_goto)
581  {
582  include_once('Services/PermanentLink/classes/class.ilPermanentLinkGUI.php');
583  $goto = new ilPermanentLinkGUI("usr", $user->getId());
584  $goto = $goto->getHTML();
585  }
586 
587  return $tpl->get().$goto;
588  }
589 
593  function deliverVCard()
594  {
595  // get user object
596  if (!ilObject::_exists($this->getUserId()))
597  {
598  return "";
599  }
600  $user = new ilObjUser($this->getUserId());
601 
602  require_once "./Services/User/classes/class.ilvCard.php";
603  $vcard = new ilvCard();
604 
605  // ilsharedresourceGUI: embedded in shared portfolio
606  if ($user->getPref("public_profile") != "y" &&
607  $user->getPref("public_profile") != "g" &&
608  $_GET["baseClass"] != "ilsharedresourceGUI")
609  {
610  return;
611  }
612 
613  $vcard->setName($user->getLastName(), $user->getFirstName(), "", $user->getUTitle());
614  $vcard->setNickname($user->getLogin());
615 
616  $webspace_dir = ilUtil::getWebspaceDir("output");
617  $imagefile = $webspace_dir."/usr_images/".$user->getPref("profile_image");
618  if ($user->getPref("public_upload")=="y" && @is_file($imagefile))
619  {
620  $fh = fopen($imagefile, "r");
621  if ($fh)
622  {
623  $image = fread($fh, filesize($imagefile));
624  fclose($fh);
625  require_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
626  $mimetype = ilObjMediaObject::getMimeType($imagefile);
627  if (preg_match("/^image/", $mimetype))
628  {
629  $type = $mimetype;
630  }
631  $vcard->setPhoto($image, $type);
632  }
633  }
634 
635  $val_arr = array("getInstitution" => "institution", "getDepartment" => "department",
636  "getStreet" => "street",
637  "getZipcode" => "zipcode", "getCity" => "city", "getCountry" => "country",
638  "getPhoneOffice" => "phone_office", "getPhoneHome" => "phone_home",
639  "getPhoneMobile" => "phone_mobile", "getFax" => "fax", "getEmail" => "email",
640  "getHobby" => "hobby", "getMatriculation" => "matriculation", "getClientIP" => "client_ip",
641  "dummy" => "location");
642 
643  $org = array();
644  $adr = array();
645  foreach ($val_arr as $key => $value)
646  {
647  // if value "y" show information
648  if ($user->getPref("public_".$value) == "y")
649  {
650  switch ($value)
651  {
652  case "institution":
653  $org[0] = $user->$key();
654  break;
655  case "department":
656  $org[1] = $user->$key();
657  break;
658  case "street":
659  $adr[2] = $user->$key();
660  break;
661  case "zipcode":
662  $adr[5] = $user->$key();
663  break;
664  case "city":
665  $adr[3] = $user->$key();
666  break;
667  case "country":
668  $adr[6] = $user->$key();
669  break;
670  case "phone_office":
671  $vcard->setPhone($user->$key(), TEL_TYPE_WORK);
672  break;
673  case "phone_home":
674  $vcard->setPhone($user->$key(), TEL_TYPE_HOME);
675  break;
676  case "phone_mobile":
677  $vcard->setPhone($user->$key(), TEL_TYPE_CELL);
678  break;
679  case "fax":
680  $vcard->setPhone($user->$key(), TEL_TYPE_FAX);
681  break;
682  case "email":
683  $vcard->setEmail($user->$key());
684  break;
685  case "hobby":
686  $vcard->setNote($user->$key());
687  break;
688  case "location":
689  $vcard->setPosition($user->getLatitude(), $user->getLongitude());
690  break;
691  }
692  }
693  }
694 
695  if (count($org))
696  {
697  $vcard->setOrganization(join(";", $org));
698  }
699  if (count($adr))
700  {
701  $vcard->setAddress($adr[0], $adr[1], $adr[2], $adr[3], $adr[4], $adr[5], $adr[6]);
702  }
703 
704  ilUtil::deliverData($vcard->buildVCard(), $vcard->getFilename(), $vcard->getMimetype());
705  }
706 
712  protected static function validateUser($a_user_id)
713  {
714  global $ilUser;
715 
716  if (ilObject::_lookupType($a_user_id) != "usr")
717  {
718  return false;
719  }
720  $user = new ilObjUser($a_user_id);
721  if ($ilUser->getId() == ANONYMOUS_USER_ID && $user->getPref("public_profile") != "g")
722  {
723  // #12151
724  if($user->getPref("public_profile") == "y")
725  {
726  ilUtil::redirect("login.php?cmd=force_login&target=usr_".$a_user_id);
727  }
728  return false;
729  }
730  return true;
731  }
732 
733  function renderTitle()
734  {
735  global $tpl;
736 
737  $tpl->resetHeaderBlock();
738 
739  include_once("./Services/User/classes/class.ilUserUtil.php");
740  $tpl->setTitle(ilUserUtil::getNamePresentation($this->getUserId()));
741  $tpl->setTitleIcon(ilObjUser::_getPersonalPicturePath($this->getUserId(), "xxsmall"));
742 
743  $this->handleBackUrl();
744  }
745 
751  protected function getProfilePortfolio()
752  {
753  include_once "Modules/Portfolio/classes/class.ilObjPortfolio.php";
754  $portfolio_id = ilObjPortfolio::getDefaultPortfolio($this->getUserId());
755  if($portfolio_id)
756  {
757  include_once('./Modules/Portfolio/classes/class.ilPortfolioAccessHandler.php');
758  $access_handler = new ilPortfolioAccessHandler();
759  if($access_handler->checkAccess("read", "", $portfolio_id))
760  {
761  return $portfolio_id;
762  }
763  }
764  }
765 
766  public static function getAutocompleteResult($a_field_id, $a_term)
767  {
768  global $ilUser;
769 
770  $multi_fields = array("interests_general", "interests_help_offered", "interests_help_looking");
771  if(in_array($a_field_id, $multi_fields) && $a_term)
772  {
773  // registration has no current user
774  $user_id = null;
775  if($ilUser && $ilUser->getId() && $ilUser->getId() != ANONYMOUS_USER_ID)
776  {
777  $user_id = $ilUser->getId();
778  }
779 
780  $result = array();
781  $cnt = 0;
782 
783  // term is searched in ALL interest fields, no distinction
784  foreach(ilObjUser::findInterests($a_term, $ilUser->getId()) as $item)
785  {
786  $result[$cnt] = new stdClass();
787  $result[$cnt]->value = $item;
788  $result[$cnt]->label = $item;
789  $cnt++;
790  }
791 
792  // :TODO: search in skill data
793  include_once("./Services/Skill/classes/class.ilSkillTreeNode.php");
794  foreach (ilSkillTreeNode::findSkills($a_term) as $skill)
795  {
796  $result[$cnt] = new stdClass();
797  $result[$cnt]->value = $skill;
798  $result[$cnt]->label = $skill;
799  $cnt++;
800  }
801 
802  }
803 
804  return $result;
805  }
806 
807  protected function doProfileAutoComplete()
808  {
809  $field_id = (string)$_REQUEST["f"];
810  $term = (string)$_REQUEST["term"];
811 
812  $result = self::getAutocompleteResult($field_id, $term);
813 
814  include_once 'Services/JSON/classes/class.ilJsonUtil.php';
816 
817  exit();
818  }
819 }
820 
821 ?>