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