ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilPublicUserProfileGUI.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2008 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
33 {
39  function __construct($a_user_id)
40  {
41  global $ilCtrl;
42 
43  $this->setUserId($a_user_id);
44  $ilCtrl->saveParameter($this, "user_id");
45  if ($_GET["back_url"] != "")
46  {
47  $this->setBackUrl($_GET["back_url"]);
48  }
49  }
50 
56  function setUserId($a_userid)
57  {
58  $this->userid = $a_userid;
59  }
60 
66  function getUserId()
67  {
68  return $this->userid;
69  }
70 
76  function setAsRows($a_asrows)
77  {
78  $this->asrows = $a_asrows;
79  }
80 
86  function getAsRows()
87  {
88  return $this->asrows;
89  }
90 
96  function setAdditional($a_additional)
97  {
98  $this->additional = $a_additional;
99  }
100 
106  function getAdditional()
107  {
108  return $this->additional;
109  }
110 
116  function setBackUrl($a_backurl)
117  {
118  global $ilCtrl;
119  $this->backurl = $a_backurl;
120  $ilCtrl->setParameter($this, "back_url", rawurlencode($a_backurl));
121  }
122 
128  function getBackUrl()
129  {
130  return $this->backurl;
131  }
132 
136  function executeCommand()
137  {
138  global $ilCtrl;
139 
140  $cmd = $ilCtrl->getCmd();
141 
142  return $this->$cmd();
143  }
144 
151  function getHTML()
152  {
153  global $ilSetting, $lng, $ilCtrl, $lng;
154 
155  // get user object
156  if (!ilObject::_exists($this->getUserId()))
157  {
158  return "";
159  }
160  $user = new ilObjUser($this->getUserId());
161 
162  $tpl = new ilTemplate("tpl.usr_public_profile.html", true, true,
163  "Services/User");
164 
165  // Back Link
166  if ($this->getBackUrl() != "")
167  {
168  $tpl->setCurrentBlock("back_url");
169  $tpl->setVariable("TXT_BACK", $lng->txt("back"));
170  $tpl->setVariable("HREF_BACK", $this->getBackUrl());
171  $tpl->parseCurrentBlock();
172  }
173 
174  if (!$this->getAsRows())
175  {
176  $tpl->touchBlock("table_end");
177  $tpl->setCurrentBlock("table_start");
178  $tpl->setVariable("USR_PROFILE", $lng->txt("profile_of")." ".$user->getLogin());
179  $tpl->parseCurrentBlock();
180  }
181 
182  $tpl->setVariable("ROWCOL1", "tblrow1");
183  $tpl->setVariable("ROWCOL2", "tblrow2");
184 
185  // Check from Database if value
186  // of public_profile = "y" show user infomation
187  if ($user->getPref("public_profile") != "y")
188  {
189  return;
190  }
191 
192  $tpl->setVariable("TXT_MAIL", $lng->txt("send_mail"));
193 
194  // Disabled (smeyer), since tags are not allowed for GET parameters
195  /*
196  $mail_to = ilMail::_getUserInternalMailboxAddress(
197  $user->getId(),
198  $user->getLogin(),
199  $user->getFirstname(),
200  $user->getLastname()
201  );
202  $tpl->setVariable("MAIL_USR_LOGIN", urlencode(
203  $mail_to)
204  );
205  */
206  $tpl->setVariable('MAIL_USR_LOGIN',urlencode($user->getLogin()));
207 
208  $tpl->setVariable("TXT_NAME", $lng->txt("name"));
209  $tpl->setVariable("FIRSTNAME", $user->getFirstName());
210  $tpl->setVariable("LASTNAME", $user->getLastName());
211 
212  $tpl->setCurrentBlock("vcard");
213  $tpl->setVariable("TXT_VCARD", $lng->txt("vcard"));
214  $tpl->setVariable("TXT_DOWNLOAD_VCARD", $lng->txt("vcard_download"));
215  $ilCtrl->setParameter($this, "user", $this->getUserId());
216  $tpl->setVariable("HREF_VCARD", $ilCtrl->getLinkTarget($this, "deliverVCard"));
217  $tpl->setVariable("IMG_VCARD", ilUtil::getImagePath("vcard.png"));
218 
219  $webspace_dir = ilUtil::getWebspaceDir("user");
220  $check_dir = ilUtil::getWebspaceDir();
221  $imagefile = $webspace_dir."/usr_images/".$user->getPref("profile_image");
222  $check_file = $check_dir."/usr_images/".$user->getPref("profile_image");
223 
224  if ($user->getPref("public_upload")=="y" && @is_file($check_file))
225  {
226  //Getting the flexible path of image form ini file
227  //$webspace_dir = ilUtil::getWebspaceDir("output");
228  $tpl->setCurrentBlock("image");
229  $tpl->setVariable("TXT_IMAGE",$lng->txt("image"));
230  $tpl->setVariable("IMAGE_PATH", $webspace_dir."/usr_images/".$user->getPref("profile_image")."?dummy=".rand(1,999999));
231  $tpl->parseCurrentBlock();
232  }
233 
234  $val_arr = array("getInstitution" => "institution", "getDepartment" => "department",
235  "getStreet" => "street",
236  "getZipcode" => "zip", "getCity" => "city", "getCountry" => "country",
237  "getPhoneOffice" => "phone_office", "getPhoneHome" => "phone_home",
238  "getPhoneMobile" => "phone_mobile", "getFax" => "fax", "getEmail" => "email",
239  "getHobby" => "hobby", "getMatriculation" => "matriculation", "getClientIP" => "client_ip");
240 
241  foreach ($val_arr as $key => $value)
242  {
243  // if value "y" show information
244  if ($user->getPref("public_".$value) == "y")
245  {
246  $tpl->setCurrentBlock("profile_data");
247  $tpl->setVariable("TXT_DATA", $lng->txt($value));
248  $tpl->setVariable("DATA", $user->$key());
249  $tpl->parseCurrentBlock();
250  }
251  }
252 
253  // delicious row
254  $d_set = new ilSetting("delicious");
255  if ($d_set->get("user_profile") == "1" && $user->getPref("public_delicious") == "y")
256  {
257  $tpl->setCurrentBlock("delicious_row");
258  $tpl->setVariable("TXT_DELICIOUS", $lng->txt("delicious"));
259  $tpl->setVariable("TXT_DEL_ICON", $lng->txt("delicious"));
260  $tpl->setVariable("SRC_DEL_ICON", ilUtil::getImagePath("icon_delicious.gif"));
261  $tpl->setVariable("DEL_ACCOUNT", $user->getDelicious());
262  $tpl->parseCurrentBlock();
263  }
264 
265  // map
266  include_once("./Services/GoogleMaps/classes/class.ilGoogleMapUtil.php");
267  if (ilGoogleMapUtil::isActivated() && $user->getPref("public_location")
268  && $user->getLatitude() != "")
269  {
270  $tpl->setVariable("TXT_LOCATION", $lng->txt("location"));
271 
272  include_once("./Services/GoogleMaps/classes/class.ilGoogleMapGUI.php");
273  $map_gui = new ilGoogleMapGUI();
274 
275  $map_gui->setMapId("user_map");
276  $map_gui->setWidth("350px");
277  $map_gui->setHeight("230px");
278  $map_gui->setLatitude($user->getLatitude());
279  $map_gui->setLongitude($user->getLongitude());
280  $map_gui->setZoom($user->getLocationZoom());
281  $map_gui->setEnableNavigationControl(true);
282  $map_gui->addUserMarker($user->getId());
283 
284  $tpl->setVariable("MAP_CONTENT", $map_gui->getHTML());
285  }
286 
287  // display available IM contacts
288  if ($ilSetting->get("usr_settings_hide_instant_messengers") != 1)
289  {
290  $im_arr = array("icq","yahoo","msn","aim","skype");
291 
292  foreach ($im_arr as $im_name)
293  {
294  if ($im_id = $user->getInstantMessengerId($im_name))
295  {
296  $tpl->setCurrentBlock("profile_data");
297  $tpl->setVariable("TXT_DATA", $lng->txt('im_'.$im_name));
298  $tpl->setVariable("IMG_ICON", ilUtil::getImagePath($im_name.'online.gif'));
299  $tpl->setVariable("TXT_ICON", $lng->txt("im_".$im_name."_icon"));
300  $tpl->setVariable("DATA", $im_id);
301  $tpl->parseCurrentBlock();
302  }
303  }
304  }
305 
306  // additional information
307  $additional = $this->getAdditional();
308  if (is_array($additional))
309  {
310  foreach($additional as $key => $val)
311  {
312  $tpl->setCurrentBlock("profile_data");
313  $tpl->setVariable("TXT_DATA", $key);
314  $tpl->setVariable("DATA", $val);
315  $tpl->parseCurrentBlock();
316  }
317  }
318 
319  return $tpl->get();
320  }
321 
325  function deliverVCard()
326  {
327  // get user object
328  if (!ilObject::_exists($this->getUserId()))
329  {
330  return "";
331  }
332  $user = new ilObjUser($this->getUserId());
333 
334  require_once "./Services/User/classes/class.ilvCard.php";
335  $vcard = new ilvCard();
336 
337  if ($user->getPref("public_profile")!="y")
338  {
339  return;
340  }
341 
342  $vcard->setName($user->getLastName(), $user->getFirstName(), "", $user->getUTitle());
343  $vcard->setNickname($user->getLogin());
344 
345  $webspace_dir = ilUtil::getWebspaceDir("output");
346  $imagefile = $webspace_dir."/usr_images/".$user->getPref("profile_image");
347  if ($user->getPref("public_upload")=="y" && @is_file($imagefile))
348  {
349  $fh = fopen($imagefile, "r");
350  if ($fh)
351  {
352  $image = fread($fh, filesize($imagefile));
353  fclose($fh);
354  require_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
355  $mimetype = ilObjMediaObject::getMimeType($imagefile);
356  if (preg_match("/^image/", $mimetype))
357  {
358  $type = $mimetype;
359  }
360  $vcard->setPhoto($image, $type);
361  }
362  }
363 
364  $val_arr = array("getInstitution" => "institution", "getDepartment" => "department",
365  "getStreet" => "street",
366  "getZipcode" => "zip", "getCity" => "city", "getCountry" => "country",
367  "getPhoneOffice" => "phone_office", "getPhoneHome" => "phone_home",
368  "getPhoneMobile" => "phone_mobile", "getFax" => "fax", "getEmail" => "email",
369  "getHobby" => "hobby", "getMatriculation" => "matriculation", "getClientIP" => "client_ip");
370 
371  $org = array();
372  $adr = array();
373  foreach ($val_arr as $key => $value)
374  {
375  // if value "y" show information
376  if ($user->getPref("public_".$value) == "y")
377  {
378  switch ($value)
379  {
380  case "institution":
381  $org[0] = $user->$key();
382  break;
383  case "department":
384  $org[1] = $user->$key();
385  break;
386  case "street":
387  $adr[2] = $user->$key();
388  break;
389  case "zip":
390  $adr[5] = $user->$key();
391  break;
392  case "city":
393  $adr[3] = $user->$key();
394  break;
395  case "country":
396  $adr[6] = $user->$key();
397  break;
398  case "phone_office":
399  $vcard->setPhone($user->$key(), TEL_TYPE_WORK);
400  break;
401  case "phone_home":
402  $vcard->setPhone($user->$key(), TEL_TYPE_HOME);
403  break;
404  case "phone_mobile":
405  $vcard->setPhone($user->$key(), TEL_TYPE_CELL);
406  break;
407  case "fax":
408  $vcard->setPhone($user->$key(), TEL_TYPE_FAX);
409  break;
410  case "email":
411  $vcard->setEmail($user->$key());
412  break;
413  case "hobby":
414  $vcard->setNote($user->$key());
415  break;
416  }
417  }
418  }
419 
420  if (count($org))
421  {
422  $vcard->setOrganization(join(";", $org));
423  }
424  if (count($adr))
425  {
426  $vcard->setAddress($adr[0], $adr[1], $adr[2], $adr[3], $adr[4], $adr[5], $adr[6]);
427  }
428 
429  ilUtil::deliverData(utf8_decode($vcard->buildVCard()), $vcard->getFilename(), $vcard->getMimetype());
430  }
431 }
432 
433 ?>