ILIAS  Release_4_1_x_branch Revision 61804
 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 
17 {
18  static $block_type = "pdusers";
19 
24  {
25  global $ilCtrl, $lng, $ilUser;
26 
28 
29  $this->setLimit(10);
30  $this->setImage(ilUtil::getImagePath("icon_grp_s.gif"));
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  return $ilCtrl->forwardCommand($profile_gui);
99  break;
100 
101  default:
102  return $this->$cmd();
103  }
104  }
105 
106  function getHTML()
107  {
108  global $ilUser;
109 
110  $this->users_online_pref = $ilUser->getPref("show_users_online");
111 
112  if ($this->users_online_pref != "y" && $this->users_online_pref != "associated")
113  {
114  return "";
115  }
116 
117  $this->getUsers();
118 
119  if ($this->getCurrentDetailLevel() == 0)
120  {
121  return "";
122  }
123  else
124  {
125  return parent::getHTML();
126  }
127  }
128 
132  function getUsers()
133  {
134  global $ilUser;
135 
136  if ($this->users_online_pref == "associated")
137  {
138  $this->users = ilUtil::getAssociatedUsersOnline($ilUser->getId(), true);
139  }
140  else
141  {
142  $this->users = ilObjUser::_getUsersOnline(0, true);
143  }
144 
145  $this->num_users = 0;
146 
147  // add current user always to list
148  if ($ilUser->getId() != ANONYMOUS_USER_ID &&
149  ilObjUser::_lookupPref($ilUser->getId(), "hide_own_online_status") != "y")
150  {
151  $this->users[$ilUser->getId()] =
152  array("user_id" => $ilUser->getId(),
153  "firstname" => $ilUser->getFirstname(),
154  "lastname" => $ilUser->getLastname(),
155  "title" => $ilUser->getUTitle(),
156  "login" => $ilUser->getLogin());
157  }
158 
159  foreach ($this->users as $user_id => $user)
160  {
161  if ($user_id != ANONYMOUS_USER_ID)
162  {
163  $this->num_users++;
164  }
165  else
166  {
167  $this->visitors = $user["num"];
168  }
169  }
170  }
171 
175  function fillDataSection()
176  {
177  global $ilUser, $ilSetting, $ilCtrl;
178 
179  $pd_set = new ilSetting("pd");
180 
181  include_once("Services/Notes/classes/class.ilNote.php");
182 
183  if ($this->getCurrentDetailLevel() > 1 && $this->num_users > 0)
184  {
185  $this->setRowTemplate("tpl.users_online_row.html", "Services/PersonalDesktop");
186  $this->getListRowData();
187  if ($this->getCurrentDetailLevel() > 2)
188  {
189  $this->setColSpan(2);
190  }
192  }
193  else
194  {
195  $this->setEnableNumInfo(false);
196  $this->setDataSection($this->getOverview());
197  }
198  }
199 
200 
204  function getListRowData()
205  {
206  global $ilUser, $lng, $ilCtrl, $ilDB, $rbacsystem;
207 
208  $data = array();
209 
210  $mail = new ilMail($ilUser->getId());
211  $this->mail_settings_id = $mail->getMailObjectReferenceId();
212  $this->mail_allowed = ($_SESSION["AccountId"] != ANONYMOUS_USER_ID
213  && $rbacsystem->checkAccess('mail_visible',$this->mail_settings_id));
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"],'mail_visible',$this->mail_settings_id))
245  {
246 // $a_set["mail_to"] = ilMail::_getUserInternalMailboxAddress(
247 // $a_set["id"], $a_set['login'], $a_set['firstname'], $a_set['lastname']
248 // );
249 
250  #$mail_to = urlencode($mail_to);
251  $a_set['mail_url'] = ilMailFormCall::_getLinkTarget($this->topGuiObj, '', array(), array('type' => 'new', 'rcp_to' => urlencode($a_set['login'])));
252  }
253 
254  // check for profile
255  $a_set["profile"] = in_array(
256  ilObjUser::_lookupPref($a_set["id"], "public_profile"),
257  array("y", "g"));
258 
259  // user image
260  if ($this->getCurrentDetailLevel() > 2)
261  {
262  if ($a_set["mail_url"] != "")
263  {
264  $this->tpl->setCurrentBlock("mailto_link");
265  $this->tpl->setVariable("TXT_MAIL", $lng->txt("mail"));
266  $this->tpl->setVariable("MAIL_URL", $a_set["mail_url"]);
267  $this->tpl->parseCurrentBlock();
268  }
269 
270  include_once './Modules/Chat/classes/class.ilChatServerConfig.php';
272  {
273  if(!$this->__showActiveChatsOfUser($a_set["id"]))
274  {
275  // Show invite to chat
276  $this->__showChatInvitation($a_set["id"]);
277  }
278 
279  global $rbacsystem;
280 
281  include_once './Modules/Chat/classes/class.ilObjChat.php';
282  if($a_set["id"] == $ilUser->getId() &&
283  $rbacsystem->checkAccess('read', ilObjChat::_getPublicChatRefId()))
284  {
285  $this->tpl->setCurrentBlock('chat_link');
286  $this->tpl->setVariable('TXT_CHAT_INVITE', $lng->txt('chat_enter_public_room'));
287  $this->tpl->setVariable('TXT_CHAT_INVITE_TOOLTIP', $lng->txt('chat_enter_public_room_tooltip'));
288  $this->tpl->setVariable('CHAT_LINK','./ilias.php?baseClass=ilChatPresentationGUI&ref_id='.ilObjChat::_getPublicChatRefId());
289  $this->tpl->parseCurrentBlock();
290  }
291  }
292 
293  // user image
294  $this->tpl->setCurrentBlock("usr_image");
295  $this->tpl->setVariable("USR_IMAGE",
296  ilObjUser::_getPersonalPicturePath($a_set["id"],"xxsmall"));
297  $this->tpl->setVariable("USR_ALT", $lng->txt("personal_picture"));
298  $this->tpl->parseCurrentBlock();
299 
300  $pd_set = new ilSetting("pd");
301  $osi_server = $pd_set->get("osi_host");
302 
303 // if (trim($osi_server) != "")
304 // {
305  // instant messengers
306  // 1 indicates to use online status check
307  $im_arr = array("icq" => 0,
308  "yahoo" => 1,
309  "msn" => 0,
310  "aim" => 0,
311  "skype" => 1,
312  "jabber" => 0,
313  "voip" => 0);
314 
315  // use onlinestatus.org
316  // when enabled all instant messengers are checked online and ignores settings above
317  if (trim($osi_server) != "")
318  {
319  $osi_enable = true;
320  }
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  switch ($im_name)
328  {
329  case "icq":
330  //$im_url = "http://people.icq.com/people/webmsg.php?to=".$im_id;
331  $im_url = "http://people.icq.com/people/about_me.php?uin=".$im_id;
332  //$im_img = "http://status.icq.com/online.gif?icq=".$im_id."&img=5";
333  $im_img = "http://wwp.icq.com/scripts/online.dll?icq=".$im_id."&img=5";
334  break;
335 
336  case "yahoo":
337  $im_url = "http://edit.yahoo.com/config/send_webmesg?.target=".$im_id."&.src=pg";
338  $im_img = "http://opi.yahoo.com/online?u=".$im_id."&m=g&t=5";
339  break;
340 
341  case "msn":
342  $im_url = "http://messenger.live.com";
343  $im_img = ilUtil::getImagePath($im_name.'offline.gif'); // online check not possible
344  break;
345 
346  case "aim":
347  //$im_url = "aim:GoIM?screenname=".$im_id;
348  $im_url = "http://aimexpress.aim.com";
349  //$im_img = "http://api.oscar.aol.com/SOA/key=<put_your_key_here>/presence/".$im_id; // doesn't work. you need a key
350  $im_img = ilUtil::getImagePath($im_name.'offline.gif'); // online check not possible
351  break;
352 
353  case "skype":
354  $im_url = "skype:".$im_id."?call";
355  /* the link above needs this piece of js to work
356  <script type="text/javascript"
357  src="http://download.skype.com/share/skypebuttons/js/skypeCheck.js">
358  </script>
359  */
360  //$im_url = "http://www.skype.com/go/download";
361  $im_img = "http://mystatus.skype.com/smallicon/".$im_id;
362  break;
363  }
364 
365  $this->tpl->setCurrentBlock("instant_messengers");
366 
367  if ($osi_enable)
368  {
369  $this->tpl->setVariable("URL_IM",$osi_server."/message/".$im_name."/".$im_id);
370  $this->tpl->setVariable("IMG_IM_ICON",$osi_server."/".$im_name."/".$im_id);
371  }
372  else
373  {
374  $this->tpl->setVariable("URL_IM",$im_url);
375  $this->tpl->setVariable("IMG_IM_ICON", $im_check ? $im_img : ilUtil::getImagePath($im_name.'offline.gif'));
376  }
377 
378  $this->tpl->setVariable("TXT_IM_ICON", $lng->txt("im_".$im_name));
379  $this->tpl->parseCurrentBlock();
380  }
381  }
382 // }
383  }
384 
385  // username
386  if ($this->getCurrentDetailLevel() > 2)
387  {
388  $this->tpl->setVariable("USR_LOGIN", "<br />".$a_set["login"]);
389  }
390  else
391  {
392  $this->tpl->setVariable("USR_LOGIN", " [".$a_set["login"]."]");
393  }
394 
395  // profile link
396  if ($a_set["profile"])
397  {
398  $this->tpl->setCurrentBlock("profile_link");
399  $this->tpl->setVariable("TXT_VIEW", $lng->txt("profile"));
400  $ilCtrl->setParameter($this, "user", $a_set["id"]);
401  $this->tpl->setVariable("LINK_PROFILE",
402  $ilCtrl->getLinkTarget($this, "showUserProfile"));
403  $this->tpl->setVariable("USR_ID", $a_set["id"]);
404  $this->tpl->setVariable("LINK_FULLNAME", ilObjUser::_lookupFullName($a_set["id"]));
405  $this->tpl->parseCurrentBlock();
406  }
407  else
408  {
409  $this->tpl->setVariable("USR_FULLNAME", ilObjUser::_lookupFullName($a_set["id"]));
410  }
411  }
412 
416  function getOverview()
417  {
418  global $ilUser, $lng, $ilCtrl;
419 
420  // parse visitors text
421  if (empty($this->visitors) || $this->users_online_pref == "associated")
422  {
423  $visitor_text = "";
424  }
425  elseif ($this->visitors == "1")
426  {
427  $visitor_text = "1 ".$lng->txt("visitor");
428  }
429  else
430  {
431  $visitor_text = $visitors." ".$lng->txt("visitors");
432  }
433 
434  // parse registered users text
435  if ($this->num_users > 0)
436  {
437  $user_kind = ($this->users_online_pref == "associated") ? "associated_user" : "registered_user";
438  if ($this->num_users == 1)
439  {
440  $user_list = $this->num_users." ".$lng->txt($user_kind);
441  }
442 
443  else
444  {
445  $user_list = $this->num_users." ".$lng->txt($user_kind."s");
446  }
447 
448  if (!empty($visitor_text))
449  {
450  $user_list .= " ".$lng->txt("and")." ".$visitor_text;
451  }
452  }
453  else
454  {
455  $user_list = $visitor_text;
456  }
457 
458  return '<div class="small">'.$user_list."</div>";
459  }
460 
461  function __showActiveChatsOfUser($a_usr_id)
462  {
463  global $rbacsystem, $lng;
464 
465  // show chat info
466  include_once './Modules/Chat/classes/class.ilChatRoom.php';
467 
468  $chat_id = ilChatRoom::_isActive($a_usr_id);
469  foreach(ilObject::_getAllReferences($chat_id) as $ref_id)
470  {
471  if($rbacsystem->checkAccess('read',$ref_id))
472  {
473  $this->tpl->setCurrentBlock("chat_info");
474  $this->tpl->setVariable("CHAT_ACTIVE_IN",$lng->txt('chat_active_in'));
475  $this->tpl->setVariable("CHAT_LINK","./ilias.php?baseClass=ilChatPresentationGUI&ref_id=".$ref_id."&room_id=0");
476  $this->tpl->setVariable("CHAT_TITLE",ilObject::_lookupTitle($chat_id));
477  $this->tpl->parseCurrentBlock();
478 
479  return true;
480  }
481  }
482  return false;
483  }
484 
485  function __showChatInvitation($a_usr_id)
486  {
487  global $rbacsystem,$ilUser,$lng;
488 
489  include_once './Modules/Chat/classes/class.ilObjChat.php';
490 
491  if($a_usr_id == $ilUser->getId())
492  {
493  return false;
494  }
495 
496  if($rbacsystem->checkAccess('read',ilObjChat::_getPublicChatRefId())
497  and $rbacsystem->checkAccessOfUser($a_usr_id,'read',ilObjChat::_getPublicChatRefId()))
498  {
499  $this->tpl->setCurrentBlock("chat_link");
500  $this->tpl->setVariable("TXT_CHAT_INVITE",$lng->txt('chat_invite_public_room'));
501  $this->tpl->setVariable("CHAT_LINK",'./ilias.php?baseClass=ilChatPresentationGUI&ref_id='.ilObjChat::_getPublicChatRefId().
502  '&usr_id='.$a_usr_id.'&cmd=invitePD');
503  $this->tpl->setVariable('TXT_CHAT_INVITE_TOOLTIP', $lng->txt('chat_invite_public_room_tooltip'));
504  $this->tpl->parseCurrentBlock();
505 
506  return true;
507  }
508  return false;
509  }
510 
514  function showUserProfile()
515  {
516  global $lng, $ilCtrl;
517 
518 // include_once("./Services/PersonalDesktop/classes/class.ilPDContentBlockGUI.php");
519 // $content_block = new ilPDContentBlockGUI("ilpersonaldesktopgui", "show");
520  include_once('./Services/User/classes/class.ilPublicUserProfileGUI.php');
521  $profile_gui = new ilPublicUserProfileGUI($_GET["user"]);
522  //$profile_gui->setAsRows(true);
523  $profile_gui->setBackUrl($ilCtrl->getParentReturn($this));
524 // $content_block->setContent($ilCtrl->getHTML($profile_gui));
525 
526 // $content_block->setTitle($lng->txt("profile_of")." ".
527 // ilObjUser::_lookupLogin($_GET["user"]));
528 // $content_block->setColSpan(2);
529 // $content_block->setImage(ilUtil::getImagePath("icon_usr.gif"));
530 // $content_block->addHeaderCommand($ilCtrl->getParentReturn($this),
531 // $lng->txt("selected_items_back"));
532 
533 // return $content_block->getHTML();
534  return $ilCtrl->getHTML($profile_gui);
535  }
536 
537 }
538 
539 ?>