ILIAS  Release_4_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 
16 {
17  static $block_type = "pdusers";
18 
23  {
24  global $ilCtrl, $lng, $ilUser;
25 
26  parent::ilBlockGUI($a_parent_class, $a_parent_cmd);
27 
28  $this->setLimit(10);
29  $this->setImage(ilUtil::getImagePath("icon_grp_s.gif"));
30  $this->setTitle($lng->txt("users_online"));
31  $this->setAvailableDetailLevels(3);
32  }
33 
39  static function getBlockType()
40  {
41  return self::$block_type;
42  }
43 
49  static function isRepositoryObject()
50  {
51  return false;
52  }
53 
57  static function getScreenMode()
58  {
59  global $ilCtrl;
60 
61  switch($ilCtrl->getCmd())
62  {
63  case "showUserProfile":
64  return IL_SCREEN_FULL;
65  break;
66 
67  default:
68  return IL_SCREEN_SIDE;
69  break;
70  }
71  }
72 
76  function &executeCommand()
77  {
78  global $ilCtrl;
79 
80  $next_class = $ilCtrl->getNextClass();
81  $cmd = $ilCtrl->getCmd("getHTML");
82 
83  switch($next_class)
84  {
85  // profile
86  case "ilpublicuserprofilegui":
87  include_once('./Services/User/classes/class.ilPublicUserProfileGUI.php');
88  $profile_gui = new ilPublicUserProfileGUI($_GET["user"]);
89  $return = $ilCtrl->forwardCommand($profile_gui);
90  break;
91 
92  default:
93  return $this->$cmd();
94  }
95  }
96 
97  function getHTML()
98  {
99  global $ilUser;
100 
101  $this->users_online_pref = $ilUser->getPref("show_users_online");
102 
103  if ($this->users_online_pref != "y" && $this->users_online_pref != "associated")
104  {
105  return "";
106  }
107 
108  $this->getUsers();
109 
110  if ($this->getCurrentDetailLevel() == 0)
111  {
112  return "";
113  }
114  else
115  {
116  return parent::getHTML();
117  }
118  }
119 
123  function getUsers()
124  {
125  global $ilUser;
126 
127  if ($this->users_online_pref == "associated")
128  {
129  $this->users = ilUtil::getAssociatedUsersOnline($ilUser->getId(), true);
130  }
131  else
132  {
133  $this->users = ilObjUser::_getUsersOnline(0, true);
134  }
135 
136  $this->num_users = 0;
137 
138  // add current user always to list
139  if ($ilUser->getId() != ANONYMOUS_USER_ID &&
140  ilObjUser::_lookupPref($ilUser->getId(), "hide_own_online_status") != "y")
141  {
142  $this->users[$ilUser->getId()] =
143  array("user_id" => $ilUser->getId(),
144  "firstname" => $ilUser->getFirstname(),
145  "lastname" => $ilUser->getLastname(),
146  "title" => $ilUser->getUTitle(),
147  "login" => $ilUser->getLogin());
148  }
149 
150  foreach ($this->users as $user_id => $user)
151  {
152  if ($user_id != ANONYMOUS_USER_ID)
153  {
154  $this->num_users++;
155  }
156  else
157  {
158  $this->visitors = $user["num"];
159  }
160  }
161  }
162 
166  function fillDataSection()
167  {
168  global $ilUser, $ilSetting, $ilCtrl;
169 
170  $pd_set = new ilSetting("pd");
171 
172  include_once("Services/Notes/classes/class.ilNote.php");
173 
174  if ($this->getCurrentDetailLevel() > 1 && $this->num_users > 0)
175  {
176  $this->setRowTemplate("tpl.users_online_row.html", "Services/PersonalDesktop");
177  $this->getListRowData();
178  if ($this->getCurrentDetailLevel() > 2)
179  {
180  $this->setColSpan(2);
181  }
183  }
184  else
185  {
186  $this->setEnableNumInfo(false);
187  $this->setDataSection($this->getOverview());
188  }
189  }
190 
191 
195  function getListRowData()
196  {
197  global $ilUser, $lng, $ilCtrl, $ilDB, $rbacsystem;
198 
199  $data = array();
200 
201  $mail = new ilMail($ilUser->getId());
202  $this->mail_settings_id = $mail->getMailObjectReferenceId();
203  $this->mail_allowed = ($_SESSION["AccountId"] != ANONYMOUS_USER_ID
204  && $rbacsystem->checkAccess('mail_visible',$this->mail_settings_id));
205 
206  foreach ($this->users as $user_id => $user)
207  {
208  $data[] = array(
209  "id" => $user_id,
210  "login" => $user["login"]
211  );
212  }
213  $this->setData($data);
214 
215  // we do not have at least one (non hidden) active user
216  if (count($data) == 0)
217  {
218  $this->setEnableNumInfo(false);
219  $this->setCurrentDetailLevel(1);
220  $this->enabledetailrow = false;
221  $this->setDataSection($this->getOverview());
222  }
223  }
224 
228  function fillRow($a_set)
229  {
230  global $ilUser, $ilCtrl, $lng, $ilSetting, $rbacsetting, $rbacsystem;
231 
232  // mail link
233  $a_set["mail_to"] = "";
234  if($this->mail_allowed &&
235  $rbacsystem->checkAccessOfUser($a_set["id"],'mail_visible',$this->mail_settings_id))
236  {
237 // $a_set["mail_to"] = ilMail::_getUserInternalMailboxAddress(
238 // $a_set["id"], $a_set['login'], $a_set['firstname'], $a_set['lastname']
239 // );
240 
241  #$mail_to = urlencode($mail_to);
242  $a_set["mail_to"] = $a_set['login'];
243  }
244 
245  // check for profile
246  $a_set["profile"] = in_array(
247  ilObjUser::_lookupPref($a_set["id"], "public_profile"),
248  array("y", "g"));
249 
250  // user image
251  if ($this->getCurrentDetailLevel() > 2)
252  {
253  if ($a_set["mail_to"] != "")
254  {
255  $this->tpl->setCurrentBlock("mailto_link");
256  $this->tpl->setVariable("TXT_MAIL", $lng->txt("mail"));
257  $this->tpl->setVariable("MAIL_USR_LOGIN", urlencode($a_set["mail_to"]));
258  $this->tpl->parseCurrentBlock();
259  }
260 
261  include_once './Modules/Chat/classes/class.ilChatServerConfig.php';
263  {
264  if(!$this->__showActiveChatsOfUser($a_set["id"]))
265  {
266  // Show invite to chat
267  $this->__showChatInvitation($a_set["id"]);
268  }
269 
270  global $rbacsystem;
271 
272  include_once './Modules/Chat/classes/class.ilObjChat.php';
273  if($a_set["id"] == $ilUser->getId() &&
274  $rbacsystem->checkAccess('read', ilObjChat::_getPublicChatRefId()))
275  {
276  $this->tpl->setCurrentBlock('chat_link');
277  $this->tpl->setVariable('TXT_CHAT_INVITE', $lng->txt('chat_enter_public_room'));
278  $this->tpl->setVariable('TXT_CHAT_INVITE_TOOLTIP', $lng->txt('chat_enter_public_room_tooltip'));
279  $this->tpl->setVariable('CHAT_LINK','./ilias.php?baseClass=ilChatPresentationGUI&ref_id='.ilObjChat::_getPublicChatRefId());
280  $this->tpl->parseCurrentBlock();
281  }
282  }
283 
284  // user image
285  $this->tpl->setCurrentBlock("usr_image");
286  $this->tpl->setVariable("USR_IMAGE",
287  ilObjUser::_getPersonalPicturePath($a_set["id"],"xxsmall"));
288  $this->tpl->setVariable("USR_ALT", $lng->txt("personal_picture"));
289  $this->tpl->parseCurrentBlock();
290 
291  $pd_set = new ilSetting("pd");
292  $osi_server = $pd_set->get("osi_host");
293 
294 // if (trim($osi_server) != "")
295 // {
296  // instant messengers
297  // 1 indicates to use online status check
298  $im_arr = array("icq" => 1,
299  "yahoo" => 1,
300  "msn" => 0,
301  "aim" => 0,
302  "skype" => 1,
303  "jabber" => 0,
304  "voip" => 0);
305 
306  // use onlinestatus.org
307  // when enabled all instant messengers are checked online and ignores settings above
308  if (trim($osi_server) != "")
309  {
310  $osi_enable = true;
311  }
312 
313  foreach ($im_arr as $im_name => $im_check)
314  {
315  if ($im_id = ilObjUser::_lookupIm($a_set["id"], $im_name))
316  {
317  switch ($im_name)
318  {
319  case "icq":
320  //$im_url = "http://people.icq.com/people/webmsg.php?to=".$im_id;
321  $im_url = "http://people.icq.com/people/about_me.php?uin=".$im_id;
322  //$im_img = "http://status.icq.com/online.gif?icq=".$im_id."&img=5";
323  $im_img = "http://wwp.icq.com/scripts/online.dll?icq=".$im_id."&img=5";
324  break;
325 
326  case "yahoo":
327  $im_url = "http://edit.yahoo.com/config/send_webmesg?.target=".$im_id."&.src=pg";
328  $im_img = "http://opi.yahoo.com/online?u=".$im_id."&m=g&t=5";
329  break;
330 
331  case "msn":
332  $im_url = "http://messenger.live.com";
333  $im_img = ilUtil::getImagePath($im_name.'offline.gif'); // online check not possible
334 
335  break;
336 
337  case "aim":
338  //$im_url = "aim:GoIM?screenname=".$im_id;
339  $im_url = "http://aimexpress.aim.com";
340  //$im_img = "http://api.oscar.aol.com/SOA/key=<put_your_key_here>/presence/".$im_id; // doesn't work. you need a key
341  $im_img = ilUtil::getImagePath($im_name.'offline.gif'); // online check not possible
342  break;
343 
344  case "skype":
345  $im_url = "skype:".$im_id."?call";
346  /* the link above needs this piece of js to work
347  <script type="text/javascript"
348  src="http://download.skype.com/share/skypebuttons/js/skypeCheck.js">
349  </script>
350  */
351  //$im_url = "http://www.skype.com/go/download";
352  $im_img = "http://mystatus.skype.com/smallicon/".$im_id;
353  break;
354  }
355 
356  $this->tpl->setCurrentBlock("instant_messengers");
357 
358  if ($osi_enable)
359  {
360  $this->tpl->setVariable("URL_IM",$osi_server."/message/".$im_name."/".$im_id);
361  $this->tpl->setVariable("IMG_IM_ICON",$osi_server."/".$im_name."/".$im_id);
362  }
363  else
364  {
365  $this->tpl->setVariable("URL_IM",$im_url);
366  $this->tpl->setVariable("IMG_IM_ICON", $im_check ? $im_img : ilUtil::getImagePath($im_name.'offline.gif'));
367  }
368 
369  $this->tpl->setVariable("TXT_IM_ICON", $lng->txt("im_".$im_name));
370  $this->tpl->parseCurrentBlock();
371  }
372  }
373 // }
374  }
375 
376  // username
377  if ($this->getCurrentDetailLevel() > 2)
378  {
379  $this->tpl->setVariable("USR_LOGIN", "<br />".$a_set["login"]);
380  }
381  else
382  {
383  $this->tpl->setVariable("USR_LOGIN", " [".$a_set["login"]."]");
384  }
385 
386  // profile link
387  if ($a_set["profile"])
388  {
389  $this->tpl->setCurrentBlock("profile_link");
390  $this->tpl->setVariable("TXT_VIEW", $lng->txt("profile"));
391  $ilCtrl->setParameter($this, "user", $a_set["id"]);
392  $this->tpl->setVariable("LINK_PROFILE",
393  $ilCtrl->getLinkTarget($this, "showUserProfile"));
394  $this->tpl->setVariable("USR_ID", $a_set["id"]);
395  $this->tpl->setVariable("LINK_FULLNAME", ilObjUser::_lookupFullName($a_set["id"]));
396  $this->tpl->parseCurrentBlock();
397  }
398  else
399  {
400  $this->tpl->setVariable("USR_FULLNAME", ilObjUser::_lookupFullName($a_set["id"]));
401  }
402  }
403 
407  function getOverview()
408  {
409  global $ilUser, $lng, $ilCtrl;
410 
411  // parse visitors text
412  if (empty($this->visitors) || $this->users_online_pref == "associated")
413  {
414  $visitor_text = "";
415  }
416  elseif ($this->visitors == "1")
417  {
418  $visitor_text = "1 ".$lng->txt("visitor");
419  }
420  else
421  {
422  $visitor_text = $visitors." ".$lng->txt("visitors");
423  }
424 
425  // parse registered users text
426  if ($this->num_users > 0)
427  {
428  $user_kind = ($this->users_online_pref == "associated") ? "associated_user" : "registered_user";
429  if ($this->num_users == 1)
430  {
431  $user_list = $this->num_users." ".$lng->txt($user_kind);
432  }
433 
434  else
435  {
436  $user_list = $this->num_users." ".$lng->txt($user_kind."s");
437  }
438 
439  if (!empty($visitor_text))
440  {
441  $user_list .= " ".$lng->txt("and")." ".$visitor_text;
442  }
443  }
444  else
445  {
446  $user_list = $visitor_text;
447  }
448 
449  return '<div class="small">'.$user_list."</div>";
450  }
451 
452  function __showActiveChatsOfUser($a_usr_id)
453  {
454  global $rbacsystem, $lng;
455 
456  // show chat info
457  include_once './Modules/Chat/classes/class.ilChatRoom.php';
458 
459  $chat_id = ilChatRoom::_isActive($a_usr_id);
460  foreach(ilObject::_getAllReferences($chat_id) as $ref_id)
461  {
462  if($rbacsystem->checkAccess('read',$ref_id))
463  {
464  $this->tpl->setCurrentBlock("chat_info");
465  $this->tpl->setVariable("CHAT_ACTIVE_IN",$lng->txt('chat_active_in'));
466  $this->tpl->setVariable("CHAT_LINK","./ilias.php?baseClass=ilChatPresentationGUI&ref_id=".$ref_id."&room_id=0");
467  $this->tpl->setVariable("CHAT_TITLE",ilObject::_lookupTitle($chat_id));
468  $this->tpl->parseCurrentBlock();
469 
470  return true;
471  }
472  }
473  return false;
474  }
475 
476  function __showChatInvitation($a_usr_id)
477  {
478  global $rbacsystem,$ilUser,$lng;
479 
480  include_once './Modules/Chat/classes/class.ilObjChat.php';
481 
482  if($a_usr_id == $ilUser->getId())
483  {
484  return false;
485  }
486 
487  if($rbacsystem->checkAccess('read',ilObjChat::_getPublicChatRefId())
488  and $rbacsystem->checkAccessOfUser($a_usr_id,'read',ilObjChat::_getPublicChatRefId()))
489  {
490  $this->tpl->setCurrentBlock("chat_link");
491  $this->tpl->setVariable("TXT_CHAT_INVITE",$lng->txt('chat_invite_public_room'));
492  $this->tpl->setVariable("CHAT_LINK",'./ilias.php?baseClass=ilChatPresentationGUI&ref_id='.ilObjChat::_getPublicChatRefId().
493  '&usr_id='.$a_usr_id.'&cmd=invitePD');
494  $this->tpl->setVariable('TXT_CHAT_INVITE_TOOLTIP', $lng->txt('chat_invite_public_room_tooltip'));
495  $this->tpl->parseCurrentBlock();
496 
497  return true;
498  }
499  return false;
500  }
501 
505  function showUserProfile()
506  {
507  global $lng, $ilCtrl;
508 
509 // include_once("./Services/PersonalDesktop/classes/class.ilPDContentBlockGUI.php");
510 // $content_block = new ilPDContentBlockGUI("ilpersonaldesktopgui", "show");
511  include_once('./Services/User/classes/class.ilPublicUserProfileGUI.php');
512  $profile_gui = new ilPublicUserProfileGUI($_GET["user"]);
513  //$profile_gui->setAsRows(true);
514  $profile_gui->setBackUrl($ilCtrl->getParentReturn($this));
515 // $content_block->setContent($ilCtrl->getHTML($profile_gui));
516 
517 // $content_block->setTitle($lng->txt("profile_of")." ".
518 // ilObjUser::_lookupLogin($_GET["user"]));
519 // $content_block->setColSpan(2);
520 // $content_block->setImage(ilUtil::getImagePath("icon_usr.gif"));
521 // $content_block->addHeaderCommand($ilCtrl->getParentReturn($this),
522 // $lng->txt("selected_items_back"));
523 
524 // return $content_block->getHTML();
525  return $ilCtrl->getHTML($profile_gui);
526  }
527 
528 }
529 
530 ?>