ILIAS  release_4-3 Revision
 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 
115  function getBackUrl()
116  {
117  return $this->backurl;
118  }
119 
125  function setCustomPrefs(array $a_prefs)
126  {
127  $this->custom_prefs = $a_prefs;
128  }
129 
139  protected function getPublicPref(ilObjUser $a_user, $a_id)
140  {
141  if(!$this->custom_prefs)
142  {
143  return $a_user->getPref($a_id);
144  }
145  else
146  {
147  return $this->custom_prefs[$a_id];
148  }
149  }
150 
151  function setEmbedded($a_value, $a_offline = false)
152  {
153  $this->embedded = (bool)$a_value;
154  $this->offline = (bool)$a_offline;
155  }
156 
160  function executeCommand()
161  {
162  global $ilCtrl, $tpl;
163 
164  if(!self::validateUser($this->getUserId()))
165  {
166  return;
167  }
168 
169  $next_class = $ilCtrl->getNextClass($this);
170  $cmd = $ilCtrl->getCmd();
171 
172  $tpl->getStandardTemplate();
173 
174  switch($next_class)
175  {
176  case "ilobjportfoliogui":
177  $portfolio_id = $this->getProfilePortfolio();
178  if($portfolio_id)
179  {
180  include_once('Services/PermanentLink/classes/class.ilPermanentLinkGUI.php');
181  $plink = new ilPermanentLinkGUI("usr", $this->getUserId());
182  $plink = $plink->getHTML();
183 
184  include_once "Services/Portfolio/classes/class.ilObjPortfolioGUI.php";
185  $gui = new ilObjPortfolioGUI();
186  $gui->initPortfolioObject($portfolio_id);
187  $gui->setAdditional($this->getAdditional());
188  $gui->setPermaLink($plink);
189  $ilCtrl->forwardCommand($gui);
190  break;
191  }
192 
193  default:
194  $ret = $this->$cmd();
195  $tpl->setContent($ret);
196 
197  // only for direct links
198  if ($_GET["baseClass"] == "ilPublicUserProfileGUI")
199  {
200  $tpl->show();
201  }
202  break;
203  }
204  }
205 
209  function view()
210  {
211  return $this->getHTML();
212  }
213 
217  function getHTML()
218  {
219  global $ilCtrl, $ilSetting;
220 
221  if($this->embedded)
222  {
223  return $this->getEmbeddable();
224  }
225 
226  if($this->getProfilePortfolio())
227  {
228  $ilCtrl->redirectByClass("ilobjportfoliogui", "preview");
229  }
230  else
231  {
232  $this->renderTitle();
233 
234  // Check from Database if value
235  // of public_profile = "y" show user infomation
236  $user = new ilObjUser($this->getUserId());
237  if ($user->getPref("public_profile") != "y" &&
238  ($user->getPref("public_profile") != "g" || !$ilSetting->get('enable_global_profiles')) &&
239  !$this->custom_prefs)
240  {
241  return;
242  }
243 
244  return $this->getEmbeddable(true);
245  }
246  }
247 
253  function getEmbeddable($a_add_goto = false)
254  {
256 
257  // get user object
258  if (!ilObject::_exists($this->getUserId()))
259  {
260  return "";
261  }
262  $user = new ilObjUser($this->getUserId());
263 
264  $tpl = new ilTemplate("tpl.usr_public_profile.html", true, true,
265  "Services/User");
266 
267  $tpl->setVariable("ROWCOL1", "tblrow1");
268  $tpl->setVariable("ROWCOL2", "tblrow2");
269 
270  if(!$this->offline && $ilUser->getId() != ANONYMOUS_USER_ID)
271  {
272  $ref_url = str_replace("&amp;", "&", $this->getBackUrl());
273  if(!$ref_url)
274  {
275  $ref_url = basename($_SERVER['REQUEST_URI']);
276  }
277 
278  $tpl->setCurrentBlock("mail");
279  $tpl->setVariable("TXT_MAIL", $lng->txt("send_mail"));
280  require_once 'Services/Mail/classes/class.ilMailFormCall.php';
281  $tpl->setVariable('HREF_MAIL', ilMailFormCall::getLinkTarget($ref_url, '', array(), array('type' => 'new', 'rcp_to' => urlencode($user->getLogin()))));
282  $tpl->parseCurrentBlock();
283  }
284 
285  $first_name = "";
286  if($this->getPublicPref($user, "public_title") == "y")
287  {
288  $first_name .= $user->getUTitle()." ";
289  }
290  $first_name .= $user->getFirstName();
291 
292  $tpl->setVariable("TXT_NAME", $lng->txt("name"));
293  $tpl->setVariable("FIRSTNAME", $first_name);
294  $tpl->setVariable("LASTNAME", $user->getLastName());
295 
296  if(!$this->offline)
297  {
298  // vcard
299  $tpl->setCurrentBlock("vcard");
300  $tpl->setVariable("TXT_VCARD", $lng->txt("vcard"));
301  $tpl->setVariable("TXT_DOWNLOAD_VCARD", $lng->txt("vcard_download"));
302  $ilCtrl->setParameter($this, "user", $this->getUserId());
303  $tpl->setVariable("HREF_VCARD", $ilCtrl->getLinkTarget($this, "deliverVCard"));
304  //$tpl->setVariable("IMG_VCARD", ilUtil::getImagePath("vcard.png"));
305  }
306 
307  $webspace_dir = ilUtil::getWebspaceDir("user");
308  $check_dir = ilUtil::getWebspaceDir();
309  $imagefile = $webspace_dir."/usr_images/".$user->getPref("profile_image")."?dummy=".rand(1,999999);
310  $check_file = $check_dir."/usr_images/".$user->getPref("profile_image");
311 
312  if (!@is_file($check_file))
313  {
314  $imagefile = $check_file =
315  ilObjUser::_getPersonalPicturePath($user->getId(), "small", false, true);
316  }
317 
318  if ($this->getPublicPref($user, "public_upload")=="y" && $imagefile != "")
319  {
320  //Getting the flexible path of image form ini file
321  //$webspace_dir = ilUtil::getWebspaceDir("output");
322  $tpl->setCurrentBlock("image");
323  $tpl->setVariable("TXT_IMAGE",$lng->txt("image"));
324  $tpl->setVariable("IMAGE_PATH", $imagefile);
325  $tpl->setVariable("IMAGE_ALT", $lng->txt("personal_picture"));
326  $tpl->parseCurrentBlock();
327  }
328 
329  // address
330  if ($this->getPublicPref($user, "public_street") == "y" ||
331  $this->getPublicPref($user, "public_zipcode") == "y" ||
332  $this->getPublicPref($user, "public_city") == "y" ||
333  $this->getPublicPref($user, "public_country") == "y")
334  {
335  $address = array();
336  $val_arr = array ("getStreet" => "street",
337  "getZipcode" => "zipcode",
338  "getCity" => "city",
339  "getCountry" => "country",
340  "getSelectedCountry" => "sel_country");
341  foreach ($val_arr as $key => $value)
342  {
343  // if value "y" show information
344  if ($this->getPublicPref($user, "public_".$value) == "y")
345  {
346  $address_value = $user->$key();
347 
348  // only if set
349  if (trim($address_value) != "")
350  {
351  switch($value)
352  {
353  case "street":
354  $address[0] = $address_value;
355  break;
356 
357  case "zipcode":
358  case "city":
359  $address[1] .= " ".$address_value;
360  break;
361 
362  case "sel_country":
363  $lng->loadLanguageModule("meta");
364  $address[2] = $lng->txt("meta_c_".$address_value);
365  break;
366 
367  case "country":
368  $address[2] = $address_value;
369  break;
370  }
371  }
372  }
373  }
374  if(sizeof($address))
375  {
376  $tpl->setCurrentBlock("address_line");
377  foreach($address as $line)
378  {
379  if(trim($line))
380  {
381  $tpl->setVariable("TXT_ADDRESS_LINE", trim($line));
382  $tpl->parseCurrentBlock();
383  }
384  }
385  $tpl->setCurrentBlock("address");
386  $tpl->setVariable("TXT_ADDRESS", $lng->txt("address"));
387  $tpl->parseCurrentBlock();
388  }
389  }
390 
391  // institution / department
392  if ($this->getPublicPref($user, "public_institution") == "y" ||
393  $this->getPublicPref($user, "public_department") == "y")
394  {
395  $tpl->setCurrentBlock("inst_dep");
396  $sep = "";
397  if ($this->getPublicPref($user, "public_institution") == "y")
398  {
399  $h = $lng->txt("institution");
400  $v = $user->getInstitution();
401  $sep = " / ";
402  }
403  if ($this->getPublicPref($user, "public_department") == "y")
404  {
405  $h.= $sep.$lng->txt("department");
406  $v.= $sep.$user->getDepartment();
407  }
408  $tpl->setVariable("TXT_INST_DEP", $h);
409  $tpl->setVariable("INST_DEP", $v);
410  $tpl->parseCurrentBlock();
411  }
412 
413  // contact
414  $val_arr = array(
415  "getPhoneOffice" => "phone_office", "getPhoneHome" => "phone_home",
416  "getPhoneMobile" => "phone_mobile", "getFax" => "fax", "getEmail" => "email");
417  $v = $sep = "";
418  foreach ($val_arr as $key => $value)
419  {
420  // if value "y" show information
421  if ($this->getPublicPref($user, "public_".$value) == "y")
422  {
423  $v.= $sep.$lng->txt($value).": ".$user->$key();
424  $sep = "<br />";
425  }
426  }
427  if ($ilSetting->get("usr_settings_hide_instant_messengers") != 1)
428  {
429  $im_arr = array("icq","yahoo","msn","aim","skype","jabber","voip");
430 
431  foreach ($im_arr as $im_name)
432  {
433  if ($im_id = $user->getInstantMessengerId($im_name))
434  {
435  if ($this->getPublicPref($user, "public_im_".$im_name) != "n")
436  {
437  $v.= $sep.$lng->txt('im_'.$im_name).": ".$im_id;
438  $sep = "<br />";
439  }
440  }
441  }
442  }
443  if ($v != "")
444  {
445  $tpl->parseCurrentBlock("contact");
446  $tpl->setVariable("TXT_CONTACT", $lng->txt("contact"));
447  $tpl->setVariable("CONTACT", $v);
448  $tpl->parseCurrentBlock();
449  }
450 
451 
452  $val_arr = array(
453  "getHobby" => "hobby", "getMatriculation" => "matriculation", "getClientIP" => "client_ip");
454 
455  foreach ($val_arr as $key => $value)
456  {
457  // if value "y" show information
458  if ($this->getPublicPref($user, "public_".$value) == "y")
459  {
460  $tpl->setCurrentBlock("profile_data");
461  $tpl->setVariable("TXT_DATA", $lng->txt($value));
462  $tpl->setVariable("DATA", $user->$key());
463  $tpl->parseCurrentBlock();
464  }
465  }
466 
467  // delicious row
468  //$d_set = new ilSetting("delicious");
469  if ($this->getPublicPref($user, "public_delicious") == "y")
470  {
471  $tpl->setCurrentBlock("delicious_row");
472  $tpl->setVariable("TXT_DELICIOUS", $lng->txt("delicious"));
473  $tpl->setVariable("TXT_DEL_ICON", $lng->txt("delicious"));
474  $tpl->setVariable("SRC_DEL_ICON", ilUtil::getImagePath("icon_delicious.png"));
475  $tpl->setVariable("DEL_ACCOUNT", $user->getDelicious());
476  $tpl->parseCurrentBlock();
477  }
478 
479  // map
480  include_once("./Services/GoogleMaps/classes/class.ilGoogleMapUtil.php");
482  $this->getPublicPref($user, "public_location") == "y" &&
483  $user->getLatitude() != "")
484  {
485  $tpl->setVariable("TXT_LOCATION", $lng->txt("location"));
486 
487  include_once("./Services/GoogleMaps/classes/class.ilGoogleMapGUI.php");
488  $map_gui = new ilGoogleMapGUI();
489 
490  $map_gui->setMapId("user_map");
491  $map_gui->setWidth("350px");
492  $map_gui->setHeight("230px");
493  $map_gui->setLatitude($user->getLatitude());
494  $map_gui->setLongitude($user->getLongitude());
495  $map_gui->setZoom($user->getLocationZoom());
496  $map_gui->setEnableNavigationControl(true);
497  $map_gui->addUserMarker($user->getId());
498 
499  $tpl->setVariable("MAP_CONTENT", $map_gui->getHTML());
500  }
501 
502  // additional defined user data fields
503  include_once './Services/User/classes/class.ilUserDefinedFields.php';
504  $this->user_defined_fields =& ilUserDefinedFields::_getInstance();
505  $user_defined_data = $user->getUserDefinedData();
506  foreach($this->user_defined_fields->getVisibleDefinitions() as $field_id => $definition)
507  {
508  // public setting
509  if ($this->getPublicPref($user, "public_udf_".$definition["field_id"]) == "y")
510  {
511  if ($user_defined_data["f_".$definition["field_id"]] != "")
512  {
513  $tpl->setCurrentBlock("udf_data");
514  $tpl->setVariable("TXT_UDF_DATA", $definition["field_name"]);
515  $tpl->setVariable("UDF_DATA", $user_defined_data["f_".$definition["field_id"]]);
516  $tpl->parseCurrentBlock();
517  }
518  }
519  }
520 
521  // additional information
522  $additional = $this->getAdditional();
523  if (is_array($additional))
524  {
525  foreach($additional as $key => $val)
526  {
527  $tpl->setCurrentBlock("profile_data");
528  $tpl->setVariable("TXT_DATA", $key);
529  $tpl->setVariable("DATA", $val);
530  $tpl->parseCurrentBlock();
531  }
532  }
533 
534  $goto = "";
535  if($a_add_goto)
536  {
537  include_once('Services/PermanentLink/classes/class.ilPermanentLinkGUI.php');
538  $goto = new ilPermanentLinkGUI("usr", $user->getId());
539  $goto = $goto->getHTML();
540  }
541 
542  return $tpl->get().$goto;
543  }
544 
548  function deliverVCard()
549  {
550  // get user object
551  if (!ilObject::_exists($this->getUserId()))
552  {
553  return "";
554  }
555  $user = new ilObjUser($this->getUserId());
556 
557  require_once "./Services/User/classes/class.ilvCard.php";
558  $vcard = new ilvCard();
559 
560  // ilsharedresourceGUI: embedded in shared portfolio
561  if ($user->getPref("public_profile") != "y" &&
562  $user->getPref("public_profile") != "g" &&
563  $_GET["baseClass"] != "ilsharedresourceGUI")
564  {
565  return;
566  }
567 
568  $vcard->setName($user->getLastName(), $user->getFirstName(), "", $user->getUTitle());
569  $vcard->setNickname($user->getLogin());
570 
571  $webspace_dir = ilUtil::getWebspaceDir("output");
572  $imagefile = $webspace_dir."/usr_images/".$user->getPref("profile_image");
573  if ($user->getPref("public_upload")=="y" && @is_file($imagefile))
574  {
575  $fh = fopen($imagefile, "r");
576  if ($fh)
577  {
578  $image = fread($fh, filesize($imagefile));
579  fclose($fh);
580  require_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
581  $mimetype = ilObjMediaObject::getMimeType($imagefile);
582  if (preg_match("/^image/", $mimetype))
583  {
584  $type = $mimetype;
585  }
586  $vcard->setPhoto($image, $type);
587  }
588  }
589 
590  $val_arr = array("getInstitution" => "institution", "getDepartment" => "department",
591  "getStreet" => "street",
592  "getZipcode" => "zipcode", "getCity" => "city", "getCountry" => "country",
593  "getPhoneOffice" => "phone_office", "getPhoneHome" => "phone_home",
594  "getPhoneMobile" => "phone_mobile", "getFax" => "fax", "getEmail" => "email",
595  "getHobby" => "hobby", "getMatriculation" => "matriculation", "getClientIP" => "client_ip");
596 
597  $org = array();
598  $adr = array();
599  foreach ($val_arr as $key => $value)
600  {
601  // if value "y" show information
602  if ($user->getPref("public_".$value) == "y")
603  {
604  switch ($value)
605  {
606  case "institution":
607  $org[0] = $user->$key();
608  break;
609  case "department":
610  $org[1] = $user->$key();
611  break;
612  case "street":
613  $adr[2] = $user->$key();
614  break;
615  case "zipcode":
616  $adr[5] = $user->$key();
617  break;
618  case "city":
619  $adr[3] = $user->$key();
620  break;
621  case "country":
622  $adr[6] = $user->$key();
623  break;
624  case "phone_office":
625  $vcard->setPhone($user->$key(), TEL_TYPE_WORK);
626  break;
627  case "phone_home":
628  $vcard->setPhone($user->$key(), TEL_TYPE_HOME);
629  break;
630  case "phone_mobile":
631  $vcard->setPhone($user->$key(), TEL_TYPE_CELL);
632  break;
633  case "fax":
634  $vcard->setPhone($user->$key(), TEL_TYPE_FAX);
635  break;
636  case "email":
637  $vcard->setEmail($user->$key());
638  break;
639  case "hobby":
640  $vcard->setNote($user->$key());
641  break;
642  }
643  }
644  }
645 
646  if (count($org))
647  {
648  $vcard->setOrganization(join(";", $org));
649  }
650  if (count($adr))
651  {
652  $vcard->setAddress($adr[0], $adr[1], $adr[2], $adr[3], $adr[4], $adr[5], $adr[6]);
653  }
654 
655  ilUtil::deliverData(utf8_decode($vcard->buildVCard()), $vcard->getFilename(), $vcard->getMimetype());
656  }
657 
663  protected static function validateUser($a_user_id)
664  {
665  global $ilUser;
666 
667  if (ilObject::_lookupType($a_user_id) != "usr")
668  {
669  return false;
670  }
671  $user = new ilObjUser($a_user_id);
672  if ($ilUser->getId() == ANONYMOUS_USER_ID && $user->getPref("public_profile") != "g")
673  {
674  // #12151
675  if($user->getPref("public_profile") == "y")
676  {
677  ilUtil::redirect("login.php?cmd=force_login&target=usr_".$a_user_id);
678  }
679  return false;
680  }
681  return true;
682  }
683 
684  function renderTitle()
685  {
686  global $tpl, $ilTabs, $lng;
687 
688  $tpl->resetHeaderBlock();
689 
690  include_once("./Services/User/classes/class.ilUserUtil.php");
691  $tpl->setTitle(ilUserUtil::getNamePresentation($this->getUserId()));
692  $tpl->setTitleIcon(ilObjUser::_getPersonalPicturePath($this->getUserId(), "xxsmall"));
693 
694  $back = ($this->getBackUrl() != "")
695  ? $this->getBackUrl()
696  : $_GET["back_url"];
697 
698  if ($back != "")
699  {
700  $ilTabs->clearTargets();
701  $ilTabs->setBackTarget($lng->txt("back"),
702  $back);
703  }
704  }
705 
711  protected function getProfilePortfolio()
712  {
713  include_once "Services/Portfolio/classes/class.ilObjPortfolio.php";
714  $portfolio_id = ilObjPortfolio::getDefaultPortfolio($this->getUserId());
715  if($portfolio_id)
716  {
717  include_once('./Services/Portfolio/classes/class.ilPortfolioAccessHandler.php');
718  $access_handler = new ilPortfolioAccessHandler();
719  if($access_handler->checkAccess("read", "", $portfolio_id))
720  {
721  return $portfolio_id;
722  }
723  }
724  }
725 }
726 
727 ?>