ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilUsersOnlineBlockGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once("Services/Block/classes/class.ilBlockGUI.php");
5 require_once 'Services/Mail/classes/class.ilMailFormCall.php';
6 include_once 'Services/Mail/classes/class.ilMailGlobalServices.php';
7 
18 {
19  static $block_type = "pdusers";
20 
25  {
26  global $ilCtrl, $lng, $ilUser;
27 
29 
30  $this->setLimit(10);
31  $this->setImage(ilUtil::getImagePath("icon_grp_s.png"));
32  $this->setTitle($lng->txt("users_online"));
33  $this->setAvailableDetailLevels(3);
34 
35  // mjansen: Used for mail referer link (@see fillRow). I don't want to create a new instance in each fillRow call.
36  $this->topGuiObj = new ilPersonalDesktopGUI();
37  }
38 
44  static function getBlockType()
45  {
46  return self::$block_type;
47  }
48 
54  static function isRepositoryObject()
55  {
56  return false;
57  }
58 
62  static function getScreenMode()
63  {
64  global $ilCtrl;
65 
66  if ($ilCtrl->getCmdClass() == "ilpublicuserprofilegui")
67  {
68  return IL_SCREEN_FULL;
69  }
70 
71  switch($ilCtrl->getCmd())
72  {
73  case "showUserProfile":
74  return IL_SCREEN_FULL;
75  break;
76 
77  default:
78  return IL_SCREEN_SIDE;
79  break;
80  }
81  }
82 
86  function &executeCommand()
87  {
88  global $ilCtrl, $tpl;
89 
90  $next_class = $ilCtrl->getNextClass();
91  $cmd = $ilCtrl->getCmd("getHTML");
92 
93  switch($next_class)
94  {
95  // profile
96  case "ilpublicuserprofilegui":
97  include_once('./Services/User/classes/class.ilPublicUserProfileGUI.php');
98  $profile_gui = new ilPublicUserProfileGUI($_GET["user"]);
99  $profile_gui->setBackUrl($ilCtrl->getParentReturn($this));
100  return $ilCtrl->forwardCommand($profile_gui);
101  break;
102 
103  default:
104  return $this->$cmd();
105  }
106  }
107 
108  function getHTML()
109  {
110  global $ilUser;
111 
112  $this->users_online_pref = $ilUser->getPref("show_users_online");
113 
114  if ($this->users_online_pref != "y" && $this->users_online_pref != "associated")
115  {
116  return "";
117  }
118 
119  $this->getUsers();
120 
121  if ($this->getCurrentDetailLevel() == 0)
122  {
123  return "";
124  }
125  else
126  {
127  return parent::getHTML();
128  }
129  }
130 
134  function getUsers()
135  {
136  global $ilUser;
137 
138  if ($this->users_online_pref == "associated")
139  {
140  $this->users = ilUtil::getAssociatedUsersOnline($ilUser->getId(), true);
141  }
142  else
143  {
144  $this->users = ilObjUser::_getUsersOnline(0, true);
145  }
146 
147  $this->num_users = 0;
148 
149  // add current user always to list
150  if ($ilUser->getId() != ANONYMOUS_USER_ID &&
151  ilObjUser::_lookupPref($ilUser->getId(), "hide_own_online_status") != "y")
152  {
153  $this->users[$ilUser->getId()] =
154  array("user_id" => $ilUser->getId(),
155  "firstname" => $ilUser->getFirstname(),
156  "lastname" => $ilUser->getLastname(),
157  "title" => $ilUser->getUTitle(),
158  "login" => $ilUser->getLogin());
159  }
160 
161  foreach ($this->users as $user_id => $user)
162  {
163  if ($user_id != ANONYMOUS_USER_ID)
164  {
165  $this->num_users++;
166  }
167  else
168  {
169  $this->visitors = $user["num"];
170  }
171  }
172  }
173 
177  function fillDataSection()
178  {
179  global $ilUser, $ilSetting, $ilCtrl;
180 
181  $pd_set = new ilSetting("pd");
182 
183  include_once("Services/Notes/classes/class.ilNote.php");
184 
185  if ($this->getCurrentDetailLevel() > 1 && $this->num_users > 0)
186  {
187  $this->setRowTemplate("tpl.users_online_row.html", "Services/PersonalDesktop");
188  $this->getListRowData();
189  if ($this->getCurrentDetailLevel() > 2)
190  {
191  $this->setColSpan(2);
192  }
194  }
195  else
196  {
197  $this->setEnableNumInfo(false);
198  $this->setDataSection($this->getOverview());
199  }
200  }
201 
202 
206  function getListRowData()
207  {
208  global $ilUser, $lng, $ilCtrl, $ilDB, $rbacsystem;
209 
210  $data = array();
211 
212  $this->mail_allowed = ($ilUser->getId() != ANONYMOUS_USER_ID &&
213  $rbacsystem->checkAccess('internal_mail', ilMailGlobalServices::getMailObjectRefId()));
214 
215  foreach ($this->users as $user_id => $user)
216  {
217  $data[] = array(
218  "id" => $user_id,
219  "login" => $user["login"]
220  );
221  }
222  $this->setData($data);
223 
224  // we do not have at least one (non hidden) active user
225  if (count($data) == 0)
226  {
227  $this->setEnableNumInfo(false);
228  $this->setCurrentDetailLevel(1);
229  $this->enabledetailrow = false;
230  $this->setDataSection($this->getOverview());
231  }
232  }
233 
237  function fillRow($a_set)
238  {
239  global $ilUser, $ilCtrl, $lng, $ilSetting, $rbacsetting, $rbacsystem;
240 
241  // mail link
242  $a_set["mail_to"] = "";
243  if($this->mail_allowed &&
244  $rbacsystem->checkAccessOfUser($a_set['id'],'internal_mail', ilMailGlobalServices::getMailObjectRefId()))
245  {
246  $a_set['mail_url'] = ilMailFormCall::getLinkTarget($this->topGuiObj, '', array(), array('type' => 'new', 'rcp_to' => urlencode($a_set['login'])));
247  }
248 
249  // check for profile
250  $a_set["profile"] = in_array(
251  ilObjUser::_lookupPref($a_set["id"], "public_profile"),
252  array("y", "g"));
253 
254  // user image
255  if ($this->getCurrentDetailLevel() > 2)
256  {
257  if ($a_set["mail_url"] != "")
258  {
259  $this->tpl->setCurrentBlock("mailto_link");
260  $this->tpl->setVariable("TXT_MAIL", $lng->txt("mail"));
261  $this->tpl->setVariable("MAIL_URL", $a_set["mail_url"]);
262  $this->tpl->parseCurrentBlock();
263  }
264 
265  $chatSettings = new ilSetting('chatroom');
266  if(/*ilChatServerConfig::_isActive() && */$chatSettings->get('chat_enabled'))
267  {
268  if(!$this->__showActiveChatsOfUser($a_set["id"]))
269  {
270  // Show invite to chat
271  $this->__showChatInvitation($a_set["id"]);
272  }
273 
274  global $rbacsystem;
275 
276  include_once './Modules/Chatroom/classes/class.ilObjChatroom.php';
277  if($a_set["id"] == $ilUser->getId() &&
278  //$rbacsystem->checkAccess('read', ilObjChat::_getPublicChatRefId()))
279  $rbacsystem->checkAccess('read', ilObjChatroom::_getPublicRefId()))
280  {
281  $this->tpl->setCurrentBlock('chat_link');
282  $this->tpl->setVariable('TXT_CHAT_INVITE', $lng->txt('chat_enter_public_room'));
283  $this->tpl->setVariable('TXT_CHAT_INVITE_TOOLTIP', $lng->txt('chat_enter_public_room_tooltip'));
284 // $this->tpl->setVariable('CHAT_LINK','./ilias.php?baseClass=ilChatPresentationGUI&ref_id='.ilObjChat::_getPublicChatRefId());
285  $this->tpl->setVariable('CHAT_LINK','./ilias.php?baseClass=ilRepositoryGUI&cmd=view&ref_id='.ilObjChatroom::_getPublicRefId());
286  $this->tpl->parseCurrentBlock();
287  }
288  }
289 
290  // user image
291  $this->tpl->setCurrentBlock("usr_image");
292  $this->tpl->setVariable("USR_IMAGE",
293  ilObjUser::_getPersonalPicturePath($a_set["id"],"xxsmall"));
294  $this->tpl->setVariable("USR_ALT", $lng->txt("personal_picture"));
295  $this->tpl->parseCurrentBlock();
296  $this->tpl->touchBlock("usr_image_space");
297 
298  $pd_set = new ilSetting("pd");
299  $osi_server = $pd_set->get("osi_host");
300 
301 // if (trim($osi_server) != "")
302 // {
303  // instant messengers
304  // 1 indicates to use online status check
305  $im_arr = array("icq" => 0,
306  "yahoo" => 1,
307  "msn" => 0,
308  "aim" => 0,
309  "skype" => 1,
310  "jabber" => 0,
311  "voip" => 0);
312 
313  // use onlinestatus.org
314  // when enabled all instant messengers are checked online and ignores settings above
315  if (trim($osi_server) != "")
316  {
317  $osi_enable = true;
318  }
319 
320  // removed calls to external servers due to
321  // bug 10583, alex 8 Mar 2013
322 
323  foreach ($im_arr as $im_name => $im_check)
324  {
325  if ($im_id = ilObjUser::_lookupIm($a_set["id"], $im_name))
326  {
327  $im_url = "";
328 
329  switch ($im_name)
330  {
331  case "icq":
332  $im_url = "http://http://www.icq.com/people/".$im_id;
333  break;
334 
335  case "yahoo":
336  $im_url = "http://edit.yahoo.com/config/send_webmesg?target=".$im_id."&src=pg";
337  break;
338 
339  case "msn":
340  $im_url = "http://messenger.live.com";
341  break;
342 
343  case "aim":
344  //$im_url = "aim:GoIM?screenname=".$im_id;
345  $im_url = "http://aimexpress.aim.com";
346  break;
347 
348  case "skype":
349  $im_url = "skype:".$im_id."?call";
350  break;
351  }
352  $im_img = ilUtil::getImagePath($im_name.'online.png');
353 
354 
355  if ($im_url != "")
356  {
357  $this->tpl->setCurrentBlock("im_link_start");
358  $this->tpl->setVariable("URL_IM",$im_url);
359  $this->tpl->parseCurrentBlock();
360  $this->tpl->touchBlock("im_link_end");
361  }
362 
363  $this->tpl->setCurrentBlock("instant_messengers");
364  $this->tpl->setVariable("IMG_IM_ICON", $im_img);
365  $this->tpl->setVariable("TXT_IM_ICON", $lng->txt("im_".$im_name));
366  $icon_id = "im_".$im_name."_usr_".$a_set["id"];
367  $this->tpl->setVariable("ICON_ID", $icon_id);
368 
369  include_once("./Services/UIComponent/Tooltip/classes/class.ilTooltipGUI.php");
370  ilTooltipGUI::addTooltip($icon_id, $lng->txt("im_".$im_name).": ".$im_id, "",
371  "top center", "bottom center");
372 
373  $this->tpl->parseCurrentBlock();
374  }
375  }
376 // }
377  }
378 
379  // username
380  if(!$a_set["profile"])
381  {
382  $this->tpl->setVariable("USR_LOGIN", $a_set["login"]);
383  }
384  else if ($this->getCurrentDetailLevel() > 2)
385  {
386  $this->tpl->setVariable("USR_LOGIN", "<br />".$a_set["login"]);
387  }
388  else
389  {
390  $this->tpl->setVariable("USR_LOGIN", " [".$a_set["login"]."]");
391  }
392 
393  // profile link
394  if ($a_set["profile"])
395  {
396  include_once "Services/User/classes/class.ilUserUtil.php";
397  $user_name = ilUserUtil::getNamePresentation($a_set["id"], false, false, "", false, true, false);
398 
399  $this->tpl->setCurrentBlock("profile_link");
400  $this->tpl->setVariable("TXT_VIEW", $lng->txt("profile"));
401 
402  $ilCtrl->setParameter($this, "user", $a_set["id"]);
403  $this->tpl->setVariable("LINK_PROFILE",
404  $ilCtrl->getLinkTargetByClass("ilpublicuserprofilegui", "getHTML"));
405 
406  $this->tpl->setVariable("USR_ID", $a_set["id"]);
407  $this->tpl->setVariable("LINK_FULLNAME", $user_name);
408  $this->tpl->parseCurrentBlock();
409  }
410  else
411  {
412  $this->tpl->setVariable("USR_FULLNAME", "");
413  }
414  }
415 
419  function getOverview()
420  {
421  global $ilUser, $lng, $ilCtrl;
422 
423  // parse visitors text
424  if (empty($this->visitors) || $this->users_online_pref == "associated")
425  {
426  $visitor_text = "";
427  }
428  elseif ($this->visitors == "1")
429  {
430  $visitor_text = "1 ".$lng->txt("visitor");
431  }
432  else
433  {
434  $visitor_text = $visitors." ".$lng->txt("visitors");
435  }
436 
437  // parse registered users text
438  if ($this->num_users > 0)
439  {
440  $user_kind = ($this->users_online_pref == "associated") ? "associated_user" : "registered_user";
441  if ($this->num_users == 1)
442  {
443  $user_list = $this->num_users." ".$lng->txt($user_kind);
444  }
445 
446  else
447  {
448  $user_list = $this->num_users." ".$lng->txt($user_kind."s");
449  }
450 
451  if (!empty($visitor_text))
452  {
453  $user_list .= " ".$lng->txt("and")." ".$visitor_text;
454  }
455  }
456  else
457  {
458  $user_list = $visitor_text;
459  }
460 
461  return '<div class="small">'.$user_list."</div>";
462  }
463 
464  function __showActiveChatsOfUser($a_usr_id)
465  {
466  global $rbacsystem, $lng;
467 
468  // show chat info
469  /*
470  $chat_id = ilChatRoom::_isActive($a_usr_id);
471  foreach(ilObject::_getAllReferences($chat_id) as $ref_id)
472  {
473  if($rbacsystem->checkAccess('read',$ref_id))
474  {
475  $this->tpl->setCurrentBlock("chat_info");
476  $this->tpl->setVariable("CHAT_ACTIVE_IN",$lng->txt('chat_active_in'));
477  $this->tpl->setVariable("CHAT_LINK","./ilias.php?baseClass=ilChatPresentationGUI&ref_id=".$ref_id."&room_id=0");
478  $this->tpl->setVariable("CHAT_TITLE",ilObject::_lookupTitle($chat_id));
479  $this->tpl->parseCurrentBlock();
480 
481  return true;
482  }
483  }*/
484  return false;
485  }
486 
487  function __showChatInvitation($a_usr_id)
488  {
489  global $rbacsystem,$ilUser,$lng;
490 
491  include_once './Modules/Chatroom/classes/class.ilObjChatroom.php';
492 
493  if($a_usr_id == $ilUser->getId())
494  {
495  return false;
496  }
497 
498  //if($rbacsystem->checkAccess('read',ilObjChat::_getPublicChatRefId())
499  //and $rbacsystem->checkAccessOfUser($a_usr_id,'read',ilObjChat::_getPublicChatRefId()))
500  if($rbacsystem->checkAccess('read',ilObjChatroom::_getPublicRefId())
501  and $rbacsystem->checkAccessOfUser($a_usr_id,'read',ilObjChatroom::_getPublicRefId()))
502  {
503  $this->tpl->setCurrentBlock("chat_link");
504  $this->tpl->setVariable("TXT_CHAT_INVITE",$lng->txt('chat_invite_public_room'));
505  //$this->tpl->setVariable("CHAT_LINK",'./ilias.php?baseClass=ilChatPresentationGUI&ref_id='.ilObjChat::_getPublicChatRefId().
506  //'&usr_id='.$a_usr_id.'&cmd=invitePD');
507  $this->tpl->setVariable("CHAT_LINK",'./ilias.php?baseClass=ilRepositoryGUI&ref_id='.ilObjChatroom::_getPublicRefId().'&usr_id='.$a_usr_id.'&cmd=view-invitePD');
508  $this->tpl->setVariable('TXT_CHAT_INVITE_TOOLTIP', $lng->txt('chat_invite_public_room_tooltip'));
509  $this->tpl->parseCurrentBlock();
510 
511  return true;
512  }
513  return false;
514  }
515 }
516 
517 ?>