ILIAS  Release_4_2_x_branch Revision 61807
 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.gif"));
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('mail_visible', 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'],'mail_visible', 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/Chat/classes/class.ilObjChat.php';
277  include_once './Modules/Chatroom/classes/class.ilObjChatroom.php';
278  if($a_set["id"] == $ilUser->getId() &&
279  //$rbacsystem->checkAccess('read', ilObjChat::_getPublicChatRefId()))
280  $rbacsystem->checkAccess('read', ilObjChatroom::_getPublicRefId()))
281  {
282  $this->tpl->setCurrentBlock('chat_link');
283  $this->tpl->setVariable('TXT_CHAT_INVITE', $lng->txt('chat_enter_public_room'));
284  $this->tpl->setVariable('TXT_CHAT_INVITE_TOOLTIP', $lng->txt('chat_enter_public_room_tooltip'));
285 // $this->tpl->setVariable('CHAT_LINK','./ilias.php?baseClass=ilChatPresentationGUI&ref_id='.ilObjChat::_getPublicChatRefId());
286  $this->tpl->setVariable('CHAT_LINK','./repository.php?cmd=view&ref_id='.ilObjChatroom::_getPublicRefId());
287  $this->tpl->parseCurrentBlock();
288  }
289  }
290 
291  // user image
292  $this->tpl->setCurrentBlock("usr_image");
293  $this->tpl->setVariable("USR_IMAGE",
294  ilObjUser::_getPersonalPicturePath($a_set["id"],"xxsmall"));
295  $this->tpl->setVariable("USR_ALT", $lng->txt("personal_picture"));
296  $this->tpl->parseCurrentBlock();
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  foreach ($im_arr as $im_name => $im_check)
321  {
322  if ($im_id = ilObjUser::_lookupIm($a_set["id"], $im_name))
323  {
324  $im_url = "#";
325  switch ($im_name)
326  {
327  case "icq":
328  //$im_url = "http://people.icq.com/people/webmsg.php?to=".$im_id;
329  $im_url = "http://people.icq.com/people/about_me.php?uin=".$im_id;
330  //$im_img = "http://status.icq.com/online.gif?icq=".$im_id."&img=5";
331  $im_img = "http://wwp.icq.com/scripts/online.dll?icq=".$im_id."&img=5";
332  break;
333 
334  case "yahoo":
335  $im_url = "http://edit.yahoo.com/config/send_webmesg?.target=".$im_id."&.src=pg";
336  $im_img = "http://opi.yahoo.com/online?u=".$im_id."&m=g&t=5";
337  break;
338 
339  case "msn":
340  $im_url = "http://messenger.live.com";
341  $im_img = ilUtil::getImagePath($im_name.'offline.gif'); // online check not possible
342  break;
343 
344  case "aim":
345  //$im_url = "aim:GoIM?screenname=".$im_id;
346  $im_url = "http://aimexpress.aim.com";
347  //$im_img = "http://api.oscar.aol.com/SOA/key=<put_your_key_here>/presence/".$im_id; // doesn't work. you need a key
348  $im_img = ilUtil::getImagePath($im_name.'offline.gif'); // online check not possible
349  break;
350 
351  case "skype":
352  $im_url = "skype:".$im_id."?call";
353  /* the link above needs this piece of js to work
354  <script type="text/javascript"
355  src="http://download.skype.com/share/skypebuttons/js/skypeCheck.js">
356  </script>
357  */
358  //$im_url = "http://www.skype.com/go/download";
359  $im_img = "http://mystatus.skype.com/smallicon/".$im_id;
360  break;
361  }
362 
363  $this->tpl->setCurrentBlock("instant_messengers");
364 
365  if ($osi_enable)
366  {
367  $this->tpl->setVariable("URL_IM",$osi_server."/message/".$im_name."/".$im_id);
368  $this->tpl->setVariable("IMG_IM_ICON",$osi_server."/".$im_name."/".$im_id);
369  }
370  else
371  {
372  $this->tpl->setVariable("URL_IM",$im_url);
373  $this->tpl->setVariable("IMG_IM_ICON", $im_check ? $im_img : ilUtil::getImagePath($im_name.'offline.gif'));
374  }
375 
376  $this->tpl->setVariable("TXT_IM_ICON", $lng->txt("im_".$im_name));
377  $this->tpl->parseCurrentBlock();
378  }
379  }
380 // }
381  }
382 
383  // username
384  if(!$a_set["profile"])
385  {
386  $this->tpl->setVariable("USR_LOGIN", $a_set["login"]);
387  }
388  else if ($this->getCurrentDetailLevel() > 2)
389  {
390  $this->tpl->setVariable("USR_LOGIN", "<br />".$a_set["login"]);
391  }
392  else
393  {
394  $this->tpl->setVariable("USR_LOGIN", " [".$a_set["login"]."]");
395  }
396 
397  // profile link
398  if ($a_set["profile"])
399  {
400  include_once "Services/User/classes/class.ilUserUtil.php";
401  $user_name = ilUserUtil::getNamePresentation($a_set["id"], false, false, "", false, true, false);
402 
403  $this->tpl->setCurrentBlock("profile_link");
404  $this->tpl->setVariable("TXT_VIEW", $lng->txt("profile"));
405 
406  $ilCtrl->setParameter($this, "user", $a_set["id"]);
407  $this->tpl->setVariable("LINK_PROFILE",
408  $ilCtrl->getLinkTargetByClass("ilpublicuserprofilegui", "getHTML"));
409 
410  $this->tpl->setVariable("USR_ID", $a_set["id"]);
411  $this->tpl->setVariable("LINK_FULLNAME", $user_name);
412  $this->tpl->parseCurrentBlock();
413  }
414  else
415  {
416  $this->tpl->setVariable("USR_FULLNAME", "");
417  }
418  }
419 
423  function getOverview()
424  {
425  global $ilUser, $lng, $ilCtrl;
426 
427  // parse visitors text
428  if (empty($this->visitors) || $this->users_online_pref == "associated")
429  {
430  $visitor_text = "";
431  }
432  elseif ($this->visitors == "1")
433  {
434  $visitor_text = "1 ".$lng->txt("visitor");
435  }
436  else
437  {
438  $visitor_text = $visitors." ".$lng->txt("visitors");
439  }
440 
441  // parse registered users text
442  if ($this->num_users > 0)
443  {
444  $user_kind = ($this->users_online_pref == "associated") ? "associated_user" : "registered_user";
445  if ($this->num_users == 1)
446  {
447  $user_list = $this->num_users." ".$lng->txt($user_kind);
448  }
449 
450  else
451  {
452  $user_list = $this->num_users." ".$lng->txt($user_kind."s");
453  }
454 
455  if (!empty($visitor_text))
456  {
457  $user_list .= " ".$lng->txt("and")." ".$visitor_text;
458  }
459  }
460  else
461  {
462  $user_list = $visitor_text;
463  }
464 
465  return '<div class="small">'.$user_list."</div>";
466  }
467 
468  function __showActiveChatsOfUser($a_usr_id)
469  {
470  global $rbacsystem, $lng;
471 
472  // show chat info
473  /*
474  $chat_id = ilChatRoom::_isActive($a_usr_id);
475  foreach(ilObject::_getAllReferences($chat_id) as $ref_id)
476  {
477  if($rbacsystem->checkAccess('read',$ref_id))
478  {
479  $this->tpl->setCurrentBlock("chat_info");
480  $this->tpl->setVariable("CHAT_ACTIVE_IN",$lng->txt('chat_active_in'));
481  $this->tpl->setVariable("CHAT_LINK","./ilias.php?baseClass=ilChatPresentationGUI&ref_id=".$ref_id."&room_id=0");
482  $this->tpl->setVariable("CHAT_TITLE",ilObject::_lookupTitle($chat_id));
483  $this->tpl->parseCurrentBlock();
484 
485  return true;
486  }
487  }*/
488  return false;
489  }
490 
491  function __showChatInvitation($a_usr_id)
492  {
493  global $rbacsystem,$ilUser,$lng;
494 
495  //include_once './Modules/Chat/classes/class.ilObjChat.php';
496  include_once './Modules/Chatroom/classes/class.ilObjChatroom.php';
497 
498  if($a_usr_id == $ilUser->getId())
499  {
500  return false;
501  }
502 
503  //if($rbacsystem->checkAccess('read',ilObjChat::_getPublicChatRefId())
504  //and $rbacsystem->checkAccessOfUser($a_usr_id,'read',ilObjChat::_getPublicChatRefId()))
505  if($rbacsystem->checkAccess('read',ilObjChatroom::_getPublicRefId())
506  and $rbacsystem->checkAccessOfUser($a_usr_id,'read',ilObjChatroom::_getPublicRefId()))
507  {
508  $this->tpl->setCurrentBlock("chat_link");
509  $this->tpl->setVariable("TXT_CHAT_INVITE",$lng->txt('chat_invite_public_room'));
510  //$this->tpl->setVariable("CHAT_LINK",'./ilias.php?baseClass=ilChatPresentationGUI&ref_id='.ilObjChat::_getPublicChatRefId().
511  //'&usr_id='.$a_usr_id.'&cmd=invitePD');
512  $this->tpl->setVariable("CHAT_LINK",'./repository.php?ref_id='.ilObjChatroom::_getPublicRefId().'&usr_id='.$a_usr_id.'&cmd=view-invitePD');
513  $this->tpl->setVariable('TXT_CHAT_INVITE_TOOLTIP', $lng->txt('chat_invite_public_room_tooltip'));
514  $this->tpl->parseCurrentBlock();
515 
516  return true;
517  }
518  return false;
519  }
520 }
521 
522 ?>