ILIAS  Release_4_2_x_branch Revision 61807
 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();
245  }
246  }
247 
253  function getEmbeddable()
254  {
255  global $ilSetting, $lng, $ilCtrl, $lng, $ilSetting, $ilTabs, $ilUser;
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  $tpl->setCurrentBlock("mail");
273  $tpl->setVariable("TXT_MAIL", $lng->txt("send_mail"));
274  require_once 'Services/Mail/classes/class.ilMailFormCall.php';
275  $tpl->setVariable('HREF_MAIL', ilMailFormCall::_getLinkTarget(basename($_SERVER['REQUEST_URI']), '', array(), array('type' => 'new', 'rcp_to' => urlencode($user->getLogin()))));
276  $tpl->parseCurrentBlock();
277  }
278 
279  $first_name = "";
280  if($this->getPublicPref($user, "public_title") == "y")
281  {
282  $first_name .= $user->getUTitle()." ";
283  }
284  $first_name .= $user->getFirstName();
285 
286  $tpl->setVariable("TXT_NAME", $lng->txt("name"));
287  $tpl->setVariable("FIRSTNAME", $first_name);
288  $tpl->setVariable("LASTNAME", $user->getLastName());
289 
290  if(!$this->offline)
291  {
292  // vcard
293  $tpl->setCurrentBlock("vcard");
294  $tpl->setVariable("TXT_VCARD", $lng->txt("vcard"));
295  $tpl->setVariable("TXT_DOWNLOAD_VCARD", $lng->txt("vcard_download"));
296  $ilCtrl->setParameter($this, "user", $this->getUserId());
297  $tpl->setVariable("HREF_VCARD", $ilCtrl->getLinkTarget($this, "deliverVCard"));
298  //$tpl->setVariable("IMG_VCARD", ilUtil::getImagePath("vcard.png"));
299 
300  /*
301  // link to global profile
302  if ($user->prefs["public_profile"] == "g" && $ilSetting->get('enable_global_profiles'))
303  {
304  $tpl->setCurrentBlock("link");
305  $tpl->setVariable("TXT_LINK", $lng->txt("usr_link_to_profile"));
306  include_once("./classes/class.ilLink.php");
307  $tpl->setVariable("HREF_LINK",
308  ilLink::_getStaticLink($user->getId(), "usr"));
309  $tpl->parseCurrentBlock();
310  }
311  */
312  }
313 
314  $webspace_dir = ilUtil::getWebspaceDir("user");
315  $check_dir = ilUtil::getWebspaceDir();
316  $imagefile = $webspace_dir."/usr_images/".$user->getPref("profile_image")."?dummy=".rand(1,999999);
317  $check_file = $check_dir."/usr_images/".$user->getPref("profile_image");
318 
319  if (!@is_file($check_file))
320  {
321  $imagefile = $check_file =
322  ilObjUser::_getPersonalPicturePath($user->getId(), "small", false, true);
323  }
324 
325  if ($this->getPublicPref($user, "public_upload")=="y" && $imagefile != "")
326  {
327  //Getting the flexible path of image form ini file
328  //$webspace_dir = ilUtil::getWebspaceDir("output");
329  $tpl->setCurrentBlock("image");
330  $tpl->setVariable("TXT_IMAGE",$lng->txt("image"));
331  $tpl->setVariable("IMAGE_PATH", $imagefile);
332  $tpl->setVariable("IMAGE_ALT", $lng->txt("personal_picture"));
333  $tpl->parseCurrentBlock();
334  }
335 
336  // address
337  if ($this->getPublicPref($user, "public_street") == "y" ||
338  $this->getPublicPref($user, "public_zipcode") == "y" ||
339  $this->getPublicPref($user, "public_city") == "y" ||
340  $this->getPublicPref($user, "public_countr") == "y")
341  {
342  $tpl->setCurrentBlock("address");
343  $tpl->setVariable("TXT_ADDRESS", $lng->txt("address"));
344  $val_arr = array ("getStreet" => "street",
345  "getZipcode" => "zipcode", "getCity" => "city", "getCountry" => "country", "getSelectedCountry" => "sel_country");
346  foreach ($val_arr as $key => $value)
347  {
348  // if value "y" show information
349  if ($this->getPublicPref($user, "public_".$value) == "y")
350  {
351  if ($user->$key() != "")
352  {
353  if ($value == "sel_country")
354  {
355  $lng->loadLanguageModule("meta");
356  $tpl->setVariable("COUNTRY",
357  $lng->txt("meta_c_".$user->$key()));
358  }
359  else
360  {
361  $tpl->setVariable(strtoupper($value), $user->$key());
362  }
363  }
364  }
365  }
366  $tpl->parseCurrentBlock();
367  }
368 
369  // institution / department
370  if ($this->getPublicPref($user, "public_institution") == "y" ||
371  $this->getPublicPref($user, "public_department") == "y")
372  {
373  $tpl->setCurrentBlock("inst_dep");
374  $sep = "";
375  if ($this->getPublicPref($user, "public_institution") == "y")
376  {
377  $h = $lng->txt("institution");
378  $v = $user->getInstitution();
379  $sep = " / ";
380  }
381  if ($this->getPublicPref($user, "public_department") == "y")
382  {
383  $h.= $sep.$lng->txt("department");
384  $v.= $sep.$user->getDepartment();
385  }
386  $tpl->setVariable("TXT_INST_DEP", $h);
387  $tpl->setVariable("INST_DEP", $v);
388  $tpl->parseCurrentBlock();
389  }
390 
391  // contact
392  $val_arr = array(
393  "getPhoneOffice" => "phone_office", "getPhoneHome" => "phone_home",
394  "getPhoneMobile" => "phone_mobile", "getFax" => "fax", "getEmail" => "email");
395  $v = $sep = "";
396  foreach ($val_arr as $key => $value)
397  {
398  // if value "y" show information
399  if ($this->getPublicPref($user, "public_".$value) == "y")
400  {
401  $v.= $sep.$lng->txt($value).": ".$user->$key();
402  $sep = "<br />";
403  }
404  }
405  if ($ilSetting->get("usr_settings_hide_instant_messengers") != 1)
406  {
407  $im_arr = array("icq","yahoo","msn","aim","skype","jabber","voip");
408 
409  foreach ($im_arr as $im_name)
410  {
411  if ($im_id = $user->getInstantMessengerId($im_name))
412  {
413  if ($this->getPublicPref($user, "public_im_".$im_name) != "n")
414  {
415  $v.= $sep.$lng->txt('im_'.$im_name).": ".$im_id;
416  $sep = "<br />";
417  }
418  }
419  }
420  }
421  if ($v != "")
422  {
423  $tpl->parseCurrentBlock("contact");
424  $tpl->setVariable("TXT_CONTACT", $lng->txt("contact"));
425  $tpl->setVariable("CONTACT", $v);
426  $tpl->parseCurrentBlock();
427  }
428 
429 
430  $val_arr = array(
431  "getHobby" => "hobby", "getMatriculation" => "matriculation", "getClientIP" => "client_ip");
432 
433  foreach ($val_arr as $key => $value)
434  {
435  // if value "y" show information
436  if ($this->getPublicPref($user, "public_".$value) == "y")
437  {
438  $tpl->setCurrentBlock("profile_data");
439  $tpl->setVariable("TXT_DATA", $lng->txt($value));
440  $tpl->setVariable("DATA", $user->$key());
441  $tpl->parseCurrentBlock();
442  }
443  }
444 
445  // delicious row
446  //$d_set = new ilSetting("delicious");
447  if ($this->getPublicPref($user, "public_delicious") == "y")
448  {
449  $tpl->setCurrentBlock("delicious_row");
450  $tpl->setVariable("TXT_DELICIOUS", $lng->txt("delicious"));
451  $tpl->setVariable("TXT_DEL_ICON", $lng->txt("delicious"));
452  $tpl->setVariable("SRC_DEL_ICON", ilUtil::getImagePath("icon_delicious.gif"));
453  $tpl->setVariable("DEL_ACCOUNT", $user->getDelicious());
454  $tpl->parseCurrentBlock();
455  }
456 
457  // map
458  include_once("./Services/GoogleMaps/classes/class.ilGoogleMapUtil.php");
460  $this->getPublicPref($user, "public_location") == "y" &&
461  $user->getLatitude() != "")
462  {
463  $tpl->setVariable("TXT_LOCATION", $lng->txt("location"));
464 
465  include_once("./Services/GoogleMaps/classes/class.ilGoogleMapGUI.php");
466  $map_gui = new ilGoogleMapGUI();
467 
468  $map_gui->setMapId("user_map");
469  $map_gui->setWidth("350px");
470  $map_gui->setHeight("230px");
471  $map_gui->setLatitude($user->getLatitude());
472  $map_gui->setLongitude($user->getLongitude());
473  $map_gui->setZoom($user->getLocationZoom());
474  $map_gui->setEnableNavigationControl(true);
475  $map_gui->addUserMarker($user->getId());
476 
477  $tpl->setVariable("MAP_CONTENT", $map_gui->getHTML());
478  }
479 
480  // additional defined user data fields
481  include_once './Services/User/classes/class.ilUserDefinedFields.php';
482  $this->user_defined_fields =& ilUserDefinedFields::_getInstance();
483  $user_defined_data = $user->getUserDefinedData();
484  foreach($this->user_defined_fields->getVisibleDefinitions() as $field_id => $definition)
485  {
486  // public setting
487  if ($this->getPublicPref($user, "public_udf_".$definition["field_id"]) == "y")
488  {
489  if ($user_defined_data["f_".$definition["field_id"]] != "")
490  {
491  $tpl->setCurrentBlock("udf_data");
492  $tpl->setVariable("TXT_UDF_DATA", $definition["field_name"]);
493  $tpl->setVariable("UDF_DATA", $user_defined_data["f_".$definition["field_id"]]);
494  $tpl->parseCurrentBlock();
495  }
496  }
497  }
498 
499  // additional information
500  $additional = $this->getAdditional();
501  if (is_array($additional))
502  {
503  foreach($additional as $key => $val)
504  {
505  $tpl->setCurrentBlock("profile_data");
506  $tpl->setVariable("TXT_DATA", $key);
507  $tpl->setVariable("DATA", $val);
508  $tpl->parseCurrentBlock();
509  }
510  }
511 
512  return $tpl->get();
513  }
514 
518  function deliverVCard()
519  {
520  // get user object
521  if (!ilObject::_exists($this->getUserId()))
522  {
523  return "";
524  }
525  $user = new ilObjUser($this->getUserId());
526 
527  require_once "./Services/User/classes/class.ilvCard.php";
528  $vcard = new ilvCard();
529 
530  // ilsharedresourceGUI: embedded in shared portfolio
531  if ($user->getPref("public_profile") != "y" &&
532  $user->getPref("public_profile") != "g" &&
533  $_GET["baseClass"] != "ilsharedresourceGUI")
534  {
535  return;
536  }
537 
538  $vcard->setName($user->getLastName(), $user->getFirstName(), "", $user->getUTitle());
539  $vcard->setNickname($user->getLogin());
540 
541  $webspace_dir = ilUtil::getWebspaceDir("output");
542  $imagefile = $webspace_dir."/usr_images/".$user->getPref("profile_image");
543  if ($user->getPref("public_upload")=="y" && @is_file($imagefile))
544  {
545  $fh = fopen($imagefile, "r");
546  if ($fh)
547  {
548  $image = fread($fh, filesize($imagefile));
549  fclose($fh);
550  require_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
551  $mimetype = ilObjMediaObject::getMimeType($imagefile);
552  if (preg_match("/^image/", $mimetype))
553  {
554  $type = $mimetype;
555  }
556  $vcard->setPhoto($image, $type);
557  }
558  }
559 
560  $val_arr = array("getInstitution" => "institution", "getDepartment" => "department",
561  "getStreet" => "street",
562  "getZipcode" => "zipcode", "getCity" => "city", "getCountry" => "country",
563  "getPhoneOffice" => "phone_office", "getPhoneHome" => "phone_home",
564  "getPhoneMobile" => "phone_mobile", "getFax" => "fax", "getEmail" => "email",
565  "getHobby" => "hobby", "getMatriculation" => "matriculation", "getClientIP" => "client_ip");
566 
567  $org = array();
568  $adr = array();
569  foreach ($val_arr as $key => $value)
570  {
571  // if value "y" show information
572  if ($user->getPref("public_".$value) == "y")
573  {
574  switch ($value)
575  {
576  case "institution":
577  $org[0] = $user->$key();
578  break;
579  case "department":
580  $org[1] = $user->$key();
581  break;
582  case "street":
583  $adr[2] = $user->$key();
584  break;
585  case "zipcode":
586  $adr[5] = $user->$key();
587  break;
588  case "city":
589  $adr[3] = $user->$key();
590  break;
591  case "country":
592  $adr[6] = $user->$key();
593  break;
594  case "phone_office":
595  $vcard->setPhone($user->$key(), TEL_TYPE_WORK);
596  break;
597  case "phone_home":
598  $vcard->setPhone($user->$key(), TEL_TYPE_HOME);
599  break;
600  case "phone_mobile":
601  $vcard->setPhone($user->$key(), TEL_TYPE_CELL);
602  break;
603  case "fax":
604  $vcard->setPhone($user->$key(), TEL_TYPE_FAX);
605  break;
606  case "email":
607  $vcard->setEmail($user->$key());
608  break;
609  case "hobby":
610  $vcard->setNote($user->$key());
611  break;
612  }
613  }
614  }
615 
616  if (count($org))
617  {
618  $vcard->setOrganization(join(";", $org));
619  }
620  if (count($adr))
621  {
622  $vcard->setAddress($adr[0], $adr[1], $adr[2], $adr[3], $adr[4], $adr[5], $adr[6]);
623  }
624 
625  ilUtil::deliverData(utf8_decode($vcard->buildVCard()), $vcard->getFilename(), $vcard->getMimetype());
626  }
627 
633  protected static function validateUser($a_user_id)
634  {
635  global $ilUser;
636 
637  if (ilObject::_lookupType($a_user_id) != "usr")
638  {
639  return false;
640  }
641  $user = new ilObjUser($a_user_id);
642  if ($ilUser->getId() == ANONYMOUS_USER_ID && $user->getPref("public_profile") != "g")
643  {
644  return false;
645  }
646  return true;
647  }
648 
649  function renderTitle()
650  {
651  global $tpl, $ilTabs, $lng;
652 
653  $tpl->resetHeaderBlock();
654 
655  include_once("./Services/User/classes/class.ilUserUtil.php");
656  $tpl->setTitle(ilUserUtil::getNamePresentation($this->getUserId()));
657  $tpl->setTitleIcon(ilObjUser::_getPersonalPicturePath($this->getUserId(), "xxsmall"));
658 
659  $back = ($this->getBackUrl() != "")
660  ? $this->getBackUrl()
661  : $_GET["back_url"];
662 
663  if ($back != "")
664  {
665  $ilTabs->clearTargets();
666  $ilTabs->setBackTarget($lng->txt("back"),
667  $back);
668  }
669  }
670 
676  protected function getProfilePortfolio()
677  {
678  include_once "Services/Portfolio/classes/class.ilObjPortfolio.php";
679  $portfolio_id = ilObjPortfolio::getDefaultPortfolio($this->getUserId());
680  if($portfolio_id)
681  {
682  include_once('./Services/Portfolio/classes/class.ilPortfolioAccessHandler.php');
683  $access_handler = new ilPortfolioAccessHandler();
684  if($access_handler->checkAccess("read", "", $portfolio_id))
685  {
686  return $portfolio_id;
687  }
688  }
689  }
690 }
691 
692 ?>