ILIAS  eassessment Revision 61809
 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 {
21  function __construct($a_user_id = 0)
22  {
23  global $ilCtrl, $lng, $ilTabs;
24 
25  $lng->loadLanguageModule("user");
26  $this->setUserId($a_user_id);
27  $ilCtrl->saveParameter($this, array("user_id","back_url", "user"));
28  if ($_GET["back_url"] != "")
29  {
30  $this->setBackUrl($_GET["back_url"]);
31  }
32  }
33 
39  function setUserId($a_userid)
40  {
41  $this->userid = $a_userid;
42  }
43 
49  function getUserId()
50  {
51  return $this->userid;
52  }
53 
59  function setAsRows($a_asrows)
60  {
61  $this->asrows = $a_asrows;
62  }
63 
69  function getAsRows()
70  {
71  return $this->asrows;
72  }
73 
79  function setAdditional($a_additional)
80  {
81  $this->additional = $a_additional;
82  }
83 
89  function getAdditional()
90  {
91  return $this->additional;
92  }
93 
99  function setBackUrl($a_backurl)
100  {
101  global $ilCtrl;
102  $this->backurl = $a_backurl;
103  $ilCtrl->setParameter($this, "back_url", rawurlencode($a_backurl));
104  }
105 
111  function getBackUrl()
112  {
113  return $this->backurl;
114  }
115 
119  function executeCommand()
120  {
121  global $ilCtrl, $tpl, $ilUser;
122 
123 
124  if ($_GET["baseClass"] != "ilPublicUserProfileGUI")
125  {
126  $cmd = $ilCtrl->getCmd();
127  $ret = $this->$cmd();
128  return $ret;
129  }
130  else
131  {
132  $user_id = (int) $_GET["user_id"];
133  $this->setUserId($user_id);
134  if (ilObject::_lookupType($user_id) != "usr")
135  {
136  return;
137  }
138  $user = new ilObjUser($user_id);
139  if ($ilUser->getId() == ANONYMOUS_USER_ID && $user->getPref("public_profile") != "g")
140  {
141  return;
142  }
143  $cmd = $ilCtrl->getCmd();
144 
145  $ret = $this->$cmd();
146  $tpl->getStandardTemplate();
147  $tpl->setContent($ret);
148  $tpl->show();
149  }
150  }
151 
158  function getHTML($a_preview = false)
159  {
160  global $ilSetting, $lng, $ilCtrl, $lng, $ilSetting, $ilTabs;
161 
162  if (!$a_preview)
163  {
164  $this->setTabs("profile");
165  }
166 
167  // get user object
168  if (!ilObject::_exists($this->getUserId()))
169  {
170  return "";
171  }
172  $user = new ilObjUser($this->getUserId());
173 
174  $tpl = new ilTemplate("tpl.usr_public_profile.html", true, true,
175  "Services/User");
176 
177  // Back Link
178  if ($this->getBackUrl() != "")
179  {
180 // $tpl->setCurrentBlock("back_url");
181 // $tpl->setVariable("TXT_BACK", $lng->txt("back"));
182 // $tpl->setVariable("HREF_BACK", $this->getBackUrl());
183 // $tpl->parseCurrentBlock();
184  }
185 
186  if (!$this->getAsRows())
187  {
188  $tpl->touchBlock("table_end");
189  $tpl->setCurrentBlock("table_start");
190  $tpl->setVariable("USR_PROFILE", $lng->txt("profile_of")." ".$user->getLogin());
191  $tpl->parseCurrentBlock();
192  }
193 
194  $tpl->setVariable("ROWCOL1", "tblrow1");
195  $tpl->setVariable("ROWCOL2", "tblrow2");
196 
197  // Check from Database if value
198  // of public_profile = "y" show user infomation
199  if ($user->getPref("public_profile") != "y" &&
200  ($user->getPref("public_profile") != "g" || !$ilSetting->get('enable_global_profiles')))
201  {
202  return;
203  }
204 
205  $tpl->setVariable("TXT_MAIL", $lng->txt("send_mail"));
206 
207  // Disabled (smeyer), since tags are not allowed for GET parameters
208  /*
209  $mail_to = ilMail::_getUserInternalMailboxAddress(
210  $user->getId(),
211  $user->getLogin(),
212  $user->getFirstname(),
213  $user->getLastname()
214  );
215  $tpl->setVariable("MAIL_USR_LOGIN", urlencode(
216  $mail_to)
217  );
218  */
219  require_once 'Services/Mail/classes/class.ilMailFormCall.php';
220  $tpl->setVariable('HREF_MAIL', ilMailFormCall::_getLinkTarget(basename($_SERVER['REQUEST_URI']), '', array(), array('type' => 'new', 'rcp_to' => urlencode($user->getLogin()))));
221 
222  $first_name = "";
223  if($user->getPref("public_title") == "y")
224  {
225  $first_name .= $user->getUTitle()." ";
226  }
227  $first_name .= $user->getFirstName();
228 
229  $tpl->setVariable("TXT_NAME", $lng->txt("name"));
230  $tpl->setVariable("FIRSTNAME", $first_name);
231  $tpl->setVariable("LASTNAME", $user->getLastName());
232 
233  // vcard
234  $tpl->setCurrentBlock("vcard");
235  $tpl->setVariable("TXT_VCARD", $lng->txt("vcard"));
236  $tpl->setVariable("TXT_DOWNLOAD_VCARD", $lng->txt("vcard_download"));
237  $ilCtrl->setParameter($this, "user", $this->getUserId());
238  $tpl->setVariable("HREF_VCARD", $ilCtrl->getLinkTarget($this, "deliverVCard"));
239  //$tpl->setVariable("IMG_VCARD", ilUtil::getImagePath("vcard.png"));
240 
241  // link to global profile
242  if ($user->prefs["public_profile"] == "g" && $ilSetting->get('enable_global_profiles'))
243  {
244  $tpl->setCurrentBlock("link");
245  $tpl->setVariable("TXT_LINK", $lng->txt("usr_link_to_profile"));
246  include_once("./classes/class.ilLink.php");
247  $tpl->setVariable("HREF_LINK",
248  ilLink::_getStaticLink($user->getId(), "usr"));
249  $tpl->parseCurrentBlock();
250  }
251 
252  $webspace_dir = ilUtil::getWebspaceDir("user");
253  $check_dir = ilUtil::getWebspaceDir();
254  $imagefile = $webspace_dir."/usr_images/".$user->getPref("profile_image")."?dummy=".rand(1,999999);
255  $check_file = $check_dir."/usr_images/".$user->getPref("profile_image");
256 
257  if (!@is_file($check_file))
258  {
259  $imagefile = $check_file =
260  ilObjUser::_getPersonalPicturePath($user->getId(), "small", false, true);
261  }
262 
263  if ($user->getPref("public_upload")=="y" && $imagefile != "")
264  {
265  //Getting the flexible path of image form ini file
266  //$webspace_dir = ilUtil::getWebspaceDir("output");
267  $tpl->setCurrentBlock("image");
268  $tpl->setVariable("TXT_IMAGE",$lng->txt("image"));
269  $tpl->setVariable("IMAGE_PATH", $imagefile);
270  $tpl->setVariable("IMAGE_ALT", $lng->txt("personal_picture"));
271  $tpl->parseCurrentBlock();
272  }
273 
274  // address
275  if ($user->getPref("public_street") == "y" || $user->getPref("public_zipcode") == "y"
276  || $user->getPref("public_city") == "y" || $user->getPref("public_countr") == "y")
277  {
278  $tpl->setCurrentBlock("address");
279  $tpl->setVariable("TXT_ADDRESS", $lng->txt("address"));
280  $val_arr = array ("getStreet" => "street",
281  "getZipcode" => "zipcode", "getCity" => "city", "getCountry" => "country", "getSelectedCountry" => "sel_country");
282  foreach ($val_arr as $key => $value)
283  {
284  // if value "y" show information
285  if ($user->getPref("public_".$value) == "y")
286  {
287  if ($user->$key() != "")
288  {
289  if ($value == "sel_country")
290  {
291  $lng->loadLanguageModule("meta");
292  $tpl->setVariable("COUNTRY",
293  $lng->txt("meta_c_".$user->$key()));
294  }
295  else
296  {
297  $tpl->setVariable(strtoupper($value), $user->$key());
298  }
299  }
300  }
301  }
302  $tpl->parseCurrentBlock();
303  }
304 
305  // institution / department
306  if ($user->getPref("public_institution") == "y" || $user->getPref("public_department") == "y")
307  {
308  $tpl->setCurrentBlock("inst_dep");
309  $sep = "";
310  if ($user->getPref("public_institution") == "y")
311  {
312  $h = $lng->txt("institution");
313  $v = $user->getInstitution();
314  $sep = " / ";
315  }
316  if ($user->getPref("public_department") == "y")
317  {
318  $h.= $sep.$lng->txt("department");
319  $v.= $sep.$user->getDepartment();
320  }
321  $tpl->setVariable("TXT_INST_DEP", $h);
322  $tpl->setVariable("INST_DEP", $v);
323  $tpl->parseCurrentBlock();
324  }
325 
326  // contact
327  $val_arr = array(
328  "getPhoneOffice" => "phone_office", "getPhoneHome" => "phone_home",
329  "getPhoneMobile" => "phone_mobile", "getFax" => "fax", "getEmail" => "email");
330  $v = $sep = "";
331  foreach ($val_arr as $key => $value)
332  {
333  // if value "y" show information
334  if ($user->getPref("public_".$value) == "y")
335  {
336  $v.= $sep.$lng->txt($value).": ".$user->$key();
337  $sep = "<br />";
338  }
339  }
340  if ($ilSetting->get("usr_settings_hide_instant_messengers") != 1)
341  {
342  $im_arr = array("icq","yahoo","msn","aim","skype","jabber","voip");
343 
344  foreach ($im_arr as $im_name)
345  {
346  if ($im_id = $user->getInstantMessengerId($im_name))
347  {
348  if ($user->getPref("public_im_".$im_name) != "n")
349  {
350  $v.= $sep.$lng->txt('im_'.$im_name).": ".$im_id;
351  $sep = "<br />";
352  }
353  }
354  }
355  }
356  if ($v != "")
357  {
358  $tpl->parseCurrentBlock("contact");
359  $tpl->setVariable("TXT_CONTACT", $lng->txt("contact"));
360  $tpl->setVariable("CONTACT", $v);
361  $tpl->parseCurrentBlock();
362  }
363 
364 
365  $val_arr = array(
366  "getHobby" => "hobby", "getMatriculation" => "matriculation", "getClientIP" => "client_ip");
367 
368  foreach ($val_arr as $key => $value)
369  {
370  // if value "y" show information
371  if ($user->getPref("public_".$value) == "y")
372  {
373  $tpl->setCurrentBlock("profile_data");
374  $tpl->setVariable("TXT_DATA", $lng->txt($value));
375  $tpl->setVariable("DATA", $user->$key());
376  $tpl->parseCurrentBlock();
377  }
378  }
379 
380  // delicious row
381  //$d_set = new ilSetting("delicious");
382  if ($user->getPref("public_delicious") == "y")
383  {
384  $tpl->setCurrentBlock("delicious_row");
385  $tpl->setVariable("TXT_DELICIOUS", $lng->txt("delicious"));
386  $tpl->setVariable("TXT_DEL_ICON", $lng->txt("delicious"));
387  $tpl->setVariable("SRC_DEL_ICON", ilUtil::getImagePath("icon_delicious.gif"));
388  $tpl->setVariable("DEL_ACCOUNT", $user->getDelicious());
389  $tpl->parseCurrentBlock();
390  }
391 
392  // map
393  include_once("./Services/GoogleMaps/classes/class.ilGoogleMapUtil.php");
394  if (ilGoogleMapUtil::isActivated() && $user->getPref("public_location")
395  && $user->getLatitude() != "")
396  {
397  $tpl->setVariable("TXT_LOCATION", $lng->txt("location"));
398 
399  include_once("./Services/GoogleMaps/classes/class.ilGoogleMapGUI.php");
400  $map_gui = new ilGoogleMapGUI();
401 
402  $map_gui->setMapId("user_map");
403  $map_gui->setWidth("350px");
404  $map_gui->setHeight("230px");
405  $map_gui->setLatitude($user->getLatitude());
406  $map_gui->setLongitude($user->getLongitude());
407  $map_gui->setZoom($user->getLocationZoom());
408  $map_gui->setEnableNavigationControl(true);
409  $map_gui->addUserMarker($user->getId());
410 
411  $tpl->setVariable("MAP_CONTENT", $map_gui->getHTML());
412  }
413 
414  // additional defined user data fields
415  include_once './Services/User/classes/class.ilUserDefinedFields.php';
416  $this->user_defined_fields =& ilUserDefinedFields::_getInstance();
417  $user_defined_data = $user->getUserDefinedData();
418  foreach($this->user_defined_fields->getVisibleDefinitions() as $field_id => $definition)
419  {
420  // public setting
421  if ($user->prefs["public_udf_".$definition["field_id"]] == "y")
422  {
423  if ($user_defined_data["f_".$definition["field_id"]] != "")
424  {
425  $tpl->setCurrentBlock("udf_data");
426  $tpl->setVariable("TXT_UDF_DATA", $definition["field_name"]);
427  $tpl->setVariable("UDF_DATA", $user_defined_data["f_".$definition["field_id"]]);
428  $tpl->parseCurrentBlock();
429  }
430  }
431  }
432 
433  // additional information
434  $additional = $this->getAdditional();
435  if (is_array($additional))
436  {
437  foreach($additional as $key => $val)
438  {
439  $tpl->setCurrentBlock("profile_data");
440  $tpl->setVariable("TXT_DATA", $key);
441  $tpl->setVariable("DATA", $val);
442  $tpl->parseCurrentBlock();
443  }
444  }
445 
446  return $tpl->get();
447  }
448 
452  function deliverVCard()
453  {
454  // get user object
455  if (!ilObject::_exists($this->getUserId()))
456  {
457  return "";
458  }
459  $user = new ilObjUser($this->getUserId());
460 
461  require_once "./Services/User/classes/class.ilvCard.php";
462  $vcard = new ilvCard();
463 
464  if ($user->getPref("public_profile") != "y" &&
465  $user->getPref("public_profile") != "g")
466  {
467  return;
468  }
469 
470  $vcard->setName($user->getLastName(), $user->getFirstName(), "", $user->getUTitle());
471  $vcard->setNickname($user->getLogin());
472 
473  $webspace_dir = ilUtil::getWebspaceDir("output");
474  $imagefile = $webspace_dir."/usr_images/".$user->getPref("profile_image");
475  if ($user->getPref("public_upload")=="y" && @is_file($imagefile))
476  {
477  $fh = fopen($imagefile, "r");
478  if ($fh)
479  {
480  $image = fread($fh, filesize($imagefile));
481  fclose($fh);
482  require_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
483  $mimetype = ilObjMediaObject::getMimeType($imagefile);
484  if (preg_match("/^image/", $mimetype))
485  {
486  $type = $mimetype;
487  }
488  $vcard->setPhoto($image, $type);
489  }
490  }
491 
492  $val_arr = array("getInstitution" => "institution", "getDepartment" => "department",
493  "getStreet" => "street",
494  "getZipcode" => "zipcode", "getCity" => "city", "getCountry" => "country",
495  "getPhoneOffice" => "phone_office", "getPhoneHome" => "phone_home",
496  "getPhoneMobile" => "phone_mobile", "getFax" => "fax", "getEmail" => "email",
497  "getHobby" => "hobby", "getMatriculation" => "matriculation", "getClientIP" => "client_ip");
498 
499  $org = array();
500  $adr = array();
501  foreach ($val_arr as $key => $value)
502  {
503  // if value "y" show information
504  if ($user->getPref("public_".$value) == "y")
505  {
506  switch ($value)
507  {
508  case "institution":
509  $org[0] = $user->$key();
510  break;
511  case "department":
512  $org[1] = $user->$key();
513  break;
514  case "street":
515  $adr[2] = $user->$key();
516  break;
517  case "zipcode":
518  $adr[5] = $user->$key();
519  break;
520  case "city":
521  $adr[3] = $user->$key();
522  break;
523  case "country":
524  $adr[6] = $user->$key();
525  break;
526  case "phone_office":
527  $vcard->setPhone($user->$key(), TEL_TYPE_WORK);
528  break;
529  case "phone_home":
530  $vcard->setPhone($user->$key(), TEL_TYPE_HOME);
531  break;
532  case "phone_mobile":
533  $vcard->setPhone($user->$key(), TEL_TYPE_CELL);
534  break;
535  case "fax":
536  $vcard->setPhone($user->$key(), TEL_TYPE_FAX);
537  break;
538  case "email":
539  $vcard->setEmail($user->$key());
540  break;
541  case "hobby":
542  $vcard->setNote($user->$key());
543  break;
544  }
545  }
546  }
547 
548  if (count($org))
549  {
550  $vcard->setOrganization(join(";", $org));
551  }
552  if (count($adr))
553  {
554  $vcard->setAddress($adr[0], $adr[1], $adr[2], $adr[3], $adr[4], $adr[5], $adr[6]);
555  }
556 
557  ilUtil::deliverData(utf8_decode($vcard->buildVCard()), $vcard->getFilename(), $vcard->getMimetype());
558  }
559 
563  function view()
564  {
565  global $tpl, $ilUser;
566 
567  $user_id = (int) $_GET["user_id"];
568  $this->setUserId($user_id);
569  if (ilObject::_lookupType($user_id) != "usr")
570  {
571  return;
572  }
573  $user = new ilObjUser($user_id);
574  if ($ilUser->getId() == ANONYMOUS_USER_ID && $user->getPref("public_profile") != "g")
575  {
576  return;
577  }
578  $tpl->getStandardTemplate();
579  $tpl->setContent($this->getHTML());
580 // $tpl->show();
581  }
582 
588  function showUserPage()
589  {
590  global $ilUser, $tpl;
591 
592  $this->setTabs("user_page_".$_GET["user_page"]);
593 
594  include_once("./Services/User/classes/class.ilExtPublicProfilePageGUI.php");
595  $page_gui = new ilExtPublicProfilePageGUI($_GET["user_page"]);
596  if ($page_gui->getPageObject()->getUserId() == $this->getUserId())
597  {
598  $tpl->setCurrentBlock("ContentStyle");
599  $tpl->setVariable("LOCATION_CONTENT_STYLESHEET",
601  $tpl->parseCurrentBlock();
602 
603  return $page_gui->preview();
604  }
605  }
606 
612  function setTabs($a_active)
613  {
614  global $ilTabs, $ilUser, $lng, $ilCtrl, $tpl;
615 
616  include_once("./Services/User/classes/class.ilUserUtil.php");
617  $tpl->setTitle(ilUserUtil::getNamePresentation($this->getUserId()));
618  $tpl->setTitleIcon(ilObjUser::_getPersonalPicturePath($this->getUserId(), "xxsmall"));
619 
620  $back = ($this->getBackUrl() != "")
621  ? $this->getBackUrl()
622  : $_GET["back_url"];
623 
624  if ($back != "")
625  {
626  $ilTabs->clearTargets();
627  $ilTabs->setBackTarget($lng->txt("back"),
628  $back);
629  }
630 
631  include_once("./Services/User/classes/class.ilExtPublicProfilePage.php");
633  if (count($pages) > 0)
634  {
635  $ilTabs->addTab("profile",
636  $lng->txt("profile"),
637  $ilCtrl->getLinkTarget($this, "getHTML"));
638  }
639 
640  foreach ($pages as $p)
641  {
642  $ilCtrl->setParameter($this, "user_page", $p["id"]);
643  $ilTabs->addTab("user_page_".$p["id"],
644  $p["title"],
645  $ilCtrl->getLinkTarget($this, "showUserPage"));
646  }
647 
648  $ilTabs->activateTab($a_active);
649 
650  }
651 
652 }
653 
654 ?>