ILIAS  Release_4_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 
13 {
19  function __construct($a_user_id = 0)
20  {
21  global $ilCtrl, $lng;
22 
23  $lng->loadLanguageModule("user");
24  $this->setUserId($a_user_id);
25  $ilCtrl->saveParameter($this, "user_id");
26  if ($_GET["back_url"] != "")
27  {
28  $this->setBackUrl($_GET["back_url"]);
29  }
30  }
31 
37  function setUserId($a_userid)
38  {
39  $this->userid = $a_userid;
40  }
41 
47  function getUserId()
48  {
49  return $this->userid;
50  }
51 
57  function setAsRows($a_asrows)
58  {
59  $this->asrows = $a_asrows;
60  }
61 
67  function getAsRows()
68  {
69  return $this->asrows;
70  }
71 
77  function setAdditional($a_additional)
78  {
79  $this->additional = $a_additional;
80  }
81 
87  function getAdditional()
88  {
89  return $this->additional;
90  }
91 
97  function setBackUrl($a_backurl)
98  {
99  global $ilCtrl;
100  $this->backurl = $a_backurl;
101  $ilCtrl->setParameter($this, "back_url", rawurlencode($a_backurl));
102  }
103 
109  function getBackUrl()
110  {
111  return $this->backurl;
112  }
113 
117  function executeCommand()
118  {
119  global $ilCtrl;
120 
121  $cmd = $ilCtrl->getCmd();
122 
123  return $this->$cmd();
124  }
125 
132  function getHTML()
133  {
135 
136  // get user object
137  if (!ilObject::_exists($this->getUserId()))
138  {
139  return "";
140  }
141  $user = new ilObjUser($this->getUserId());
142 
143  $tpl = new ilTemplate("tpl.usr_public_profile.html", true, true,
144  "Services/User");
145 
146  // Back Link
147  if ($this->getBackUrl() != "")
148  {
149  $tpl->setCurrentBlock("back_url");
150  $tpl->setVariable("TXT_BACK", $lng->txt("back"));
151  $tpl->setVariable("HREF_BACK", $this->getBackUrl());
152  $tpl->parseCurrentBlock();
153  }
154 
155  if (!$this->getAsRows())
156  {
157  $tpl->touchBlock("table_end");
158  $tpl->setCurrentBlock("table_start");
159  $tpl->setVariable("USR_PROFILE", $lng->txt("profile_of")." ".$user->getLogin());
160  $tpl->parseCurrentBlock();
161  }
162 
163  $tpl->setVariable("ROWCOL1", "tblrow1");
164  $tpl->setVariable("ROWCOL2", "tblrow2");
165 
166  // Check from Database if value
167  // of public_profile = "y" show user infomation
168  if ($user->getPref("public_profile") != "y" &&
169  ($user->getPref("public_profile") != "g" || !$ilSetting->get('enable_global_profiles')))
170  {
171  return;
172  }
173 
174  $tpl->setVariable("TXT_MAIL", $lng->txt("send_mail"));
175 
176  // Disabled (smeyer), since tags are not allowed for GET parameters
177  /*
178  $mail_to = ilMail::_getUserInternalMailboxAddress(
179  $user->getId(),
180  $user->getLogin(),
181  $user->getFirstname(),
182  $user->getLastname()
183  );
184  $tpl->setVariable("MAIL_USR_LOGIN", urlencode(
185  $mail_to)
186  );
187  */
188  $tpl->setVariable('MAIL_USR_LOGIN',urlencode($user->getLogin()));
189 
190  $tpl->setVariable("TXT_NAME", $lng->txt("name"));
191  $tpl->setVariable("FIRSTNAME", $user->getUTitle()." ".$user->getFirstName());
192  $tpl->setVariable("LASTNAME", $user->getLastName());
193 
194  // vcard
195  $tpl->setCurrentBlock("vcard");
196  $tpl->setVariable("TXT_VCARD", $lng->txt("vcard"));
197  $tpl->setVariable("TXT_DOWNLOAD_VCARD", $lng->txt("vcard_download"));
198  $ilCtrl->setParameter($this, "user", $this->getUserId());
199  $tpl->setVariable("HREF_VCARD", $ilCtrl->getLinkTarget($this, "deliverVCard"));
200  //$tpl->setVariable("IMG_VCARD", ilUtil::getImagePath("vcard.png"));
201 
202  // link to global profile
203  if ($user->prefs["public_profile"] == "g" && $ilSetting->get('enable_global_profiles'))
204  {
205  $tpl->setCurrentBlock("link");
206  $tpl->setVariable("TXT_LINK", $lng->txt("usr_link_to_profile"));
207  $tpl->setVariable("HREF_LINK", ILIAS_HTTP_PATH."/goto.php?client=".CLIENT_ID."&amp;target=usr_".$user->getId());
208  $tpl->parseCurrentBlock();
209  }
210 
211  $webspace_dir = ilUtil::getWebspaceDir("user");
212  $check_dir = ilUtil::getWebspaceDir();
213  $imagefile = $webspace_dir."/usr_images/".$user->getPref("profile_image")."?dummy=".rand(1,999999);
214  $check_file = $check_dir."/usr_images/".$user->getPref("profile_image");
215 
216  if (!@is_file($check_file))
217  {
218  $imagefile = $check_file =
219  ilObjUser::_getPersonalPicturePath($user->getId(), "small", false, true);
220  }
221 
222  if ($user->getPref("public_upload")=="y" && $imagefile != "")
223  {
224  //Getting the flexible path of image form ini file
225  //$webspace_dir = ilUtil::getWebspaceDir("output");
226  $tpl->setCurrentBlock("image");
227  $tpl->setVariable("TXT_IMAGE",$lng->txt("image"));
228  $tpl->setVariable("IMAGE_PATH", $imagefile);
229  $tpl->setVariable("IMAGE_ALT", $lng->txt("personal_picture"));
230  $tpl->parseCurrentBlock();
231  }
232 
233  // address
234  if ($user->getPref("public_street") == "y" || $user->getPref("public_zipcode") == "y"
235  || $user->getPref("public_city") == "y" || $user->getPref("public_countr") == "y")
236  {
237  $tpl->setCurrentBlock("address");
238  $tpl->setVariable("TXT_ADDRESS", $lng->txt("address"));
239  $val_arr = array ("getStreet" => "street",
240  "getZipcode" => "zipcode", "getCity" => "city", "getCountry" => "country");
241  foreach ($val_arr as $key => $value)
242  {
243  // if value "y" show information
244  if ($user->getPref("public_".$value) == "y")
245  {
246  $tpl->setVariable(strtoupper($value), $user->$key());
247  }
248  }
249  $tpl->parseCurrentBlock();
250  }
251 
252  // institution / department
253  if ($user->getPref("public_institution") == "y" || $user->getPref("public_department") == "y")
254  {
255  $tpl->setCurrentBlock("inst_dep");
256  $sep = "";
257  if ($user->getPref("public_institution") == "y")
258  {
259  $h = $lng->txt("institution");
260  $v = $user->getInstitution();
261  $sep = " / ";
262  }
263  if ($user->getPref("public_department") == "y")
264  {
265  $h.= $sep.$lng->txt("department");
266  $v.= $sep.$user->getDepartment();
267  }
268  $tpl->setVariable("TXT_INST_DEP", $h);
269  $tpl->setVariable("INST_DEP", $v);
270  $tpl->parseCurrentBlock();
271  }
272 
273  // contact
274  $val_arr = array(
275  "getPhoneOffice" => "phone_office", "getPhoneHome" => "phone_home",
276  "getPhoneMobile" => "phone_mobile", "getFax" => "fax", "getEmail" => "email");
277  $v = $sep = "";
278  foreach ($val_arr as $key => $value)
279  {
280  // if value "y" show information
281  if ($user->getPref("public_".$value) == "y")
282  {
283  $v.= $sep.$lng->txt($value).": ".$user->$key();
284  $sep = "<br />";
285  }
286  }
287  if ($ilSetting->get("usr_settings_hide_instant_messengers") != 1)
288  {
289  $im_arr = array("icq","yahoo","msn","aim","skype","jabber","voip");
290 
291  foreach ($im_arr as $im_name)
292  {
293  if ($im_id = $user->getInstantMessengerId($im_name))
294  {
295  if ($user->getPref("public_im_".$im_name) != "n")
296  {
297  $v.= $sep.$lng->txt('im_'.$im_name).": ".$im_id;
298  $sep = "<br />";
299  }
300  }
301  }
302  }
303  if ($v != "")
304  {
305  $tpl->parseCurrentBlock("contact");
306  $tpl->setVariable("TXT_CONTACT", $lng->txt("contact"));
307  $tpl->setVariable("CONTACT", $v);
308  $tpl->parseCurrentBlock();
309  }
310 
311 
312  $val_arr = array(
313  "getHobby" => "hobby", "getMatriculation" => "matriculation", "getClientIP" => "client_ip");
314 
315  foreach ($val_arr as $key => $value)
316  {
317  // if value "y" show information
318  if ($user->getPref("public_".$value) == "y")
319  {
320  $tpl->setCurrentBlock("profile_data");
321  $tpl->setVariable("TXT_DATA", $lng->txt($value));
322  $tpl->setVariable("DATA", $user->$key());
323  $tpl->parseCurrentBlock();
324  }
325  }
326 
327  // delicious row
328  //$d_set = new ilSetting("delicious");
329  if ($user->getPref("public_delicious") == "y")
330  {
331  $tpl->setCurrentBlock("delicious_row");
332  $tpl->setVariable("TXT_DELICIOUS", $lng->txt("delicious"));
333  $tpl->setVariable("TXT_DEL_ICON", $lng->txt("delicious"));
334  $tpl->setVariable("SRC_DEL_ICON", ilUtil::getImagePath("icon_delicious.gif"));
335  $tpl->setVariable("DEL_ACCOUNT", $user->getDelicious());
336  $tpl->parseCurrentBlock();
337  }
338 
339  // map
340  include_once("./Services/GoogleMaps/classes/class.ilGoogleMapUtil.php");
341  if (ilGoogleMapUtil::isActivated() && $user->getPref("public_location")
342  && $user->getLatitude() != "")
343  {
344  $tpl->setVariable("TXT_LOCATION", $lng->txt("location"));
345 
346  include_once("./Services/GoogleMaps/classes/class.ilGoogleMapGUI.php");
347  $map_gui = new ilGoogleMapGUI();
348 
349  $map_gui->setMapId("user_map");
350  $map_gui->setWidth("350px");
351  $map_gui->setHeight("230px");
352  $map_gui->setLatitude($user->getLatitude());
353  $map_gui->setLongitude($user->getLongitude());
354  $map_gui->setZoom($user->getLocationZoom());
355  $map_gui->setEnableNavigationControl(true);
356  $map_gui->addUserMarker($user->getId());
357 
358  $tpl->setVariable("MAP_CONTENT", $map_gui->getHTML());
359  }
360 
361  // additional defined user data fields
362  include_once './Services/User/classes/class.ilUserDefinedFields.php';
363  $this->user_defined_fields =& ilUserDefinedFields::_getInstance();
364  $user_defined_data = $user->getUserDefinedData();
365  foreach($this->user_defined_fields->getVisibleDefinitions() as $field_id => $definition)
366  {
367  // public setting
368  if ($user->prefs["public_udf_".$definition["field_id"]] == "y")
369  {
370  if ($user_defined_data["f_".$definition["field_id"]] != "")
371  {
372  $tpl->setCurrentBlock("udf_data");
373  $tpl->setVariable("TXT_UDF_DATA", $definition["field_name"]);
374  $tpl->setVariable("UDF_DATA", $user_defined_data["f_".$definition["field_id"]]);
375  $tpl->parseCurrentBlock();
376  }
377  }
378  }
379 
380  // additional information
381  $additional = $this->getAdditional();
382  if (is_array($additional))
383  {
384  foreach($additional as $key => $val)
385  {
386  $tpl->setCurrentBlock("profile_data");
387  $tpl->setVariable("TXT_DATA", $key);
388  $tpl->setVariable("DATA", $val);
389  $tpl->parseCurrentBlock();
390  }
391  }
392 
393  return $tpl->get();
394  }
395 
399  function deliverVCard()
400  {
401  // get user object
402  if (!ilObject::_exists($this->getUserId()))
403  {
404  return "";
405  }
406  $user = new ilObjUser($this->getUserId());
407 
408  require_once "./Services/User/classes/class.ilvCard.php";
409  $vcard = new ilvCard();
410 
411  if ($user->getPref("public_profile") != "y" &&
412  $user->getPref("public_profile") != "g")
413  {
414  return;
415  }
416 
417  $vcard->setName($user->getLastName(), $user->getFirstName(), "", $user->getUTitle());
418  $vcard->setNickname($user->getLogin());
419 
420  $webspace_dir = ilUtil::getWebspaceDir("output");
421  $imagefile = $webspace_dir."/usr_images/".$user->getPref("profile_image");
422  if ($user->getPref("public_upload")=="y" && @is_file($imagefile))
423  {
424  $fh = fopen($imagefile, "r");
425  if ($fh)
426  {
427  $image = fread($fh, filesize($imagefile));
428  fclose($fh);
429  require_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
430  $mimetype = ilObjMediaObject::getMimeType($imagefile);
431  if (preg_match("/^image/", $mimetype))
432  {
433  $type = $mimetype;
434  }
435  $vcard->setPhoto($image, $type);
436  }
437  }
438 
439  $val_arr = array("getInstitution" => "institution", "getDepartment" => "department",
440  "getStreet" => "street",
441  "getZipcode" => "zipcode", "getCity" => "city", "getCountry" => "country",
442  "getPhoneOffice" => "phone_office", "getPhoneHome" => "phone_home",
443  "getPhoneMobile" => "phone_mobile", "getFax" => "fax", "getEmail" => "email",
444  "getHobby" => "hobby", "getMatriculation" => "matriculation", "getClientIP" => "client_ip");
445 
446  $org = array();
447  $adr = array();
448  foreach ($val_arr as $key => $value)
449  {
450  // if value "y" show information
451  if ($user->getPref("public_".$value) == "y")
452  {
453  switch ($value)
454  {
455  case "institution":
456  $org[0] = $user->$key();
457  break;
458  case "department":
459  $org[1] = $user->$key();
460  break;
461  case "street":
462  $adr[2] = $user->$key();
463  break;
464  case "zipcode":
465  $adr[5] = $user->$key();
466  break;
467  case "city":
468  $adr[3] = $user->$key();
469  break;
470  case "country":
471  $adr[6] = $user->$key();
472  break;
473  case "phone_office":
474  $vcard->setPhone($user->$key(), TEL_TYPE_WORK);
475  break;
476  case "phone_home":
477  $vcard->setPhone($user->$key(), TEL_TYPE_HOME);
478  break;
479  case "phone_mobile":
480  $vcard->setPhone($user->$key(), TEL_TYPE_CELL);
481  break;
482  case "fax":
483  $vcard->setPhone($user->$key(), TEL_TYPE_FAX);
484  break;
485  case "email":
486  $vcard->setEmail($user->$key());
487  break;
488  case "hobby":
489  $vcard->setNote($user->$key());
490  break;
491  }
492  }
493  }
494 
495  if (count($org))
496  {
497  $vcard->setOrganization(join(";", $org));
498  }
499  if (count($adr))
500  {
501  $vcard->setAddress($adr[0], $adr[1], $adr[2], $adr[3], $adr[4], $adr[5], $adr[6]);
502  }
503 
504  ilUtil::deliverData(utf8_decode($vcard->buildVCard()), $vcard->getFilename(), $vcard->getMimetype());
505  }
506 
510  function view()
511  {
512  global $tpl, $ilUser;
513 
514  $user_id = (int) $_GET["user_id"];
515  $this->setUserId($user_id);
516  if (ilObject::_lookupType($user_id) != "usr")
517  {
518  return;
519  }
520  $user = new ilObjUser($user_id);
521  if ($ilUser->getId() == ANONYMOUS_USER_ID && $user->getPref("public_profile") != "g")
522  {
523  return;
524  }
525  $tpl->getStandardTemplate();
526  $tpl->setContent($this->getHTML());
527  $tpl->show();
528  }
529 }
530 
531 ?>