ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilUsersOnlineBlockGUI.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 include_once("Services/Block/classes/class.ilBlockGUI.php");
25 
36 {
37  static $block_type = "pdusers";
38 
43  {
44  global $ilCtrl, $lng, $ilUser;
45 
46  parent::ilBlockGUI($a_parent_class, $a_parent_cmd);
47 
48  $this->setLimit(10);
49  $this->setImage(ilUtil::getImagePath("icon_grp_s.gif"));
50  $this->setTitle($lng->txt("users_online"));
51  $this->setAvailableDetailLevels(3);
52  }
53 
59  static function getBlockType()
60  {
61  return self::$block_type;
62  }
63 
69  static function isRepositoryObject()
70  {
71  return false;
72  }
73 
77  static function getScreenMode()
78  {
79  global $ilCtrl;
80 
81  switch($ilCtrl->getCmd())
82  {
83  case "showUserProfile":
84  return IL_SCREEN_CENTER;
85  break;
86 
87  default:
88  return IL_SCREEN_SIDE;
89  break;
90  }
91  }
92 
96  function &executeCommand()
97  {
98  global $ilCtrl;
99 
100  $next_class = $ilCtrl->getNextClass();
101  $cmd = $ilCtrl->getCmd("getHTML");
102 
103  switch($next_class)
104  {
105  // profile
106  case "ilpublicuserprofilegui":
107  include_once('./Services/User/classes/class.ilPublicUserProfileGUI.php');
108  $profile_gui = new ilPublicUserProfileGUI($_GET["user"]);
109  $return = $ilCtrl->forwardCommand($profile_gui);
110  break;
111 
112  default:
113  return $this->$cmd();
114  }
115  }
116 
117  function getHTML()
118  {
119  global $ilUser;
120 
121  $this->users_online_pref = $ilUser->getPref("show_users_online");
122 
123  if ($this->users_online_pref != "y" && $this->users_online_pref != "associated")
124  {
125  return "";
126  }
127 
128  $this->getUsers();
129 
130  if ($this->getCurrentDetailLevel() == 0)
131  {
132  return "";
133  }
134  else
135  {
136  return parent::getHTML();
137  }
138  }
139 
143  function getUsers()
144  {
145  global $ilUser;
146 
147  if ($this->users_online_pref == "associated")
148  {
149  $this->users = ilUtil::getAssociatedUsersOnline($ilUser->getId());
150  }
151  else
152  {
153  $this->users = ilUtil::getUsersOnline();
154  }
155 
156  $this->num_users = 0;
157 
158  $this->users[$ilUser->getId()] =
159  array("user_id" => $ilUser->getId(),
160  "firstname" => $ilUser->getFirstname(),
161  "lastname" => $ilUser->getLastname(),
162  "title" => $ilUser->getUTitle(),
163  "login" => $ilUser->getLogin());
164 
165  foreach ($this->users as $user_id => $user)
166  {
167  if ($user_id != ANONYMOUS_USER_ID)
168  {
169  $this->num_users++;
170  }
171  else
172  {
173  $this->visitors = $user["num"];
174  }
175  }
176  }
177 
181  function fillDataSection()
182  {
183  global $ilUser, $ilSetting, $ilCtrl;
184 
185  $pd_set = new ilSetting("pd");
186 
187  include_once("Services/Notes/classes/class.ilNote.php");
188 
189  if ($this->getCurrentDetailLevel() > 1 && $this->num_users > 0)
190  {
191  $this->setRowTemplate("tpl.users_online_row.html", "Services/PersonalDesktop");
192  $this->getListRowData();
193  if ($this->getCurrentDetailLevel() > 2)
194  {
195  $this->setColSpan(2);
196  }
198  }
199  else
200  {
201  $this->setEnableNumInfo(false);
202  $this->setDataSection($this->getOverview());
203  }
204  }
205 
206 
210  function getListRowData()
211  {
212  global $ilUser, $lng, $ilCtrl, $ilDB, $rbacsystem;
213 
214  $data = array();
215 
216  $mail = new ilMail($ilUser->getId());
217  $mail_settings_id = $mail->getMailObjectReferenceId();
218 
219  foreach ($this->users as $user_id => $user)
220  {
221  if ($user_id != ANONYMOUS_USER_ID &&
222  ilObjUser::_lookupPref($user_id, "hide_own_online_status") != "y")
223  {
224  // hide mail-to icon for anonymous users
225  // usability: we do show mail-to for the current user, because
226  // we often got requests by users that their own
227  // e-mail address doesn't appear
228  $mail_to = "";
229  if ($_SESSION["AccountId"] != ANONYMOUS_USER_ID)
230  {
231  // No mail for users that do have permissions to use the mail system
232  if($rbacsystem->checkAccess('mail_visible',$mail_settings_id) and
233  $rbacsystem->checkAccessOfUser($user_id,'mail_visible',$mail_settings_id))
234  {
236  $user_id, $user['login'], $user['firstname'], $user['lastname']
237  );
238 
239  #$mail_to = urlencode($mail_to);
240  $mail_to = $user['login'];
241  }
242  }
243 
244  // check for profile
245  // todo: use user class!
246  $q = "SELECT value FROM usr_pref WHERE usr_id = ".
247  $ilDB->quote($user_id)." AND keyword='public_profile' AND value='y'";
248  $r = $ilDB->query($q);
249  $profile = false;
250  if ($r->numRows())
251  {
252  $profile = true;
253  }
254 
255  $data[] = array(
256  "mail_to" => $mail_to,
257  "id" => $user_id,
258  "profile" => $profile,
259  "login" => $user["login"]
260  );
261  }
262  }
263 
264  $this->setData($data);
265 
266  // we do not have at least one (non hidden) active user
267  if (count($data) == 0)
268  {
269  $this->setEnableNumInfo(false);
270  $this->setCurrentDetailLevel(1);
271  $this->enabledetailrow = false;
272  $this->setDataSection($this->getOverview());
273  }
274  }
275 
279  function fillRow($a_set)
280  {
281  global $ilUser, $ilCtrl, $lng, $ilSetting;
282 
283  $user_obj = new ilObjUser($a_set["id"]);
284 
285  // user image
286  if ($this->getCurrentDetailLevel() > 2)
287  {
288  if ($a_set["mail_to"] != "")
289  {
290  $this->tpl->setCurrentBlock("mailto_link");
291  $this->tpl->setVariable("TXT_MAIL", $lng->txt("mail"));
292  $this->tpl->setVariable("MAIL_USR_LOGIN", urlencode($a_set["mail_to"]));
293  $this->tpl->parseCurrentBlock();
294  }
295 
296  include_once './Modules/Chat/classes/class.ilChatServerConfig.php';
298  {
299  if(!$this->__showActiveChatsOfUser($a_set["id"]))
300  {
301  // Show invite to chat
302  $this->__showChatInvitation($a_set["id"]);
303  }
304 
305  global $rbacsystem;
306 
307  include_once './Modules/Chat/classes/class.ilObjChat.php';
308  if($user_obj->getId() == $ilUser->getId() &&
309  $rbacsystem->checkAccess('read', ilObjChat::_getPublicChatRefId()))
310  {
311  $this->tpl->setCurrentBlock('chat_link');
312  $this->tpl->setVariable('TXT_CHAT_INVITE', $lng->txt('chat_enter_public_room'));
313  $this->tpl->setVariable('TXT_CHAT_INVITE_TOOLTIP', $lng->txt('chat_enter_public_room_tooltip'));
314  $this->tpl->setVariable('CHAT_LINK','./ilias.php?baseClass=ilChatPresentationGUI&ref_id='.ilObjChat::_getPublicChatRefId());
315  $this->tpl->parseCurrentBlock();
316  }
317  }
318 
319  // user image
320  $this->tpl->setCurrentBlock("usr_image");
321  $this->tpl->setVariable("USR_IMAGE",
322  $user_obj->getPersonalPicturePath("xxsmall"));
323  $this->tpl->setVariable("USR_ALT", $lng->txt("personal_picture"));
324  $this->tpl->parseCurrentBlock();
325 
326  $pd_set = new ilSetting("pd");
327  $osi_server = $pd_set->get("osi_host");
328 
329  if (trim($osi_server) != "")
330  {
331  // instant messengers
332  // 1 indicates to use online status check
333  $im_arr = array("icq" => 1,
334  "yahoo" => 1,
335  "msn" => 0,
336  "aim" => 0,
337  "skype" => 1);
338 
339  // use onlinestatus.org
340  // when enabled all instant messengers are checked online and ignores settings above
341  $osi_enable = true;
342 
343  foreach ($im_arr as $im_name => $im_check)
344  {
345  if ($im_id = $user_obj->getInstantMessengerId($im_name))
346  {
347  switch ($im_name)
348  {
349  case "icq":
350  //$im_url = "http://people.icq.com/people/webmsg.php?to=".$im_id;
351  $im_url = "http://people.icq.com/people/about_me.php?uin=".$im_id;
352  $im_img = "http://status.icq.com/online.gif?icq=".$im_id."&img=5";
353  break;
354 
355  case "yahoo":
356  $im_url = "http://edit.yahoo.com/config/send_webmesg?.target=".$im_id."&.src=pg";
357  $im_img = "http://opi.yahoo.com/online?u=".$im_id."&m=g&t=5";
358  break;
359 
360  case "msn":
361  $im_url = "http://messenger.live.com";
362  $im_img = ilUtil::getImagePath($im_name.'offline.gif'); // online check not possible
363 
364  break;
365 
366  case "aim":
367  //$im_url = "aim:GoIM?screenname=".$im_id;
368  $im_url = "http://aimexpress.aim.com";
369  //$im_img = "http://api.oscar.aol.com/SOA/key=<put_your_key_here>/presence/".$im_id; // doesn't work. you need a key
370  $im_img = ilUtil::getImagePath($im_name.'offline.gif'); // online check not possible
371  break;
372 
373  case "skype":
374  $im_url = "skype:".$im_id."?call";
375  /* the link above needs this piece of js to work
376  <script type="text/javascript"
377  src="http://download.skype.com/share/skypebuttons/js/skypeCheck.js">
378  </script>
379  */
380  //$im_url = "http://www.skype.com/go/download";
381  $im_img = "http://mystatus.skype.com/smallicon/".$im_id;
382  break;
383  }
384 
385  $this->tpl->setCurrentBlock("instant_messengers");
386 
387  if ($osi_enable)
388  {
389  $this->tpl->setVariable("URL_IM",$osi_server."/message/".$im_name."/".$im_id);
390  $this->tpl->setVariable("IMG_IM_ICON",$osi_server."/".$im_name."/".$im_id);
391  }
392  else
393  {
394  $this->tpl->setVariable("URL_IM",$im_url);
395  $this->tpl->setVariable("IMG_IM_ICON", $im_check ? $im_img : ilUtil::getImagePath($im_name.'offline.gif'));
396  }
397 
398  $this->tpl->setVariable("TXT_IM_ICON", $lng->txt("im_".$im_name));
399  $this->tpl->parseCurrentBlock();
400  }
401  }
402  }
403  }
404 
405  // username
406  if ($this->getCurrentDetailLevel() > 2)
407  {
408  $this->tpl->setVariable("USR_LOGIN", "<br />".$a_set["login"]);
409  }
410  else
411  {
412  $this->tpl->setVariable("USR_LOGIN", " [".$a_set["login"]."]");
413  }
414 
415  // profile link
416  if ($a_set["profile"])
417  {
418  $this->tpl->setCurrentBlock("profile_link");
419  $this->tpl->setVariable("TXT_VIEW", $lng->txt("profile"));
420  $ilCtrl->setParameter($this, "user", $a_set["id"]);
421  $this->tpl->setVariable("LINK_PROFILE",
422  $ilCtrl->getLinkTarget($this, "showUserProfile"));
423  $this->tpl->setVariable("USR_ID", $a_set["id"]);
424  $this->tpl->setVariable("LINK_FULLNAME", $user_obj->getFullname());
425  $this->tpl->parseCurrentBlock();
426  }
427  else
428  {
429  $this->tpl->setVariable("USR_FULLNAME", $user_obj->getFullname());
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  include_once './Modules/Chat/classes/class.ilChatRoom.php';
487 
488  $chat_id = ilChatRoom::_isActive($a_usr_id);
489  foreach(ilObject::_getAllReferences($chat_id) as $ref_id)
490  {
491  if($rbacsystem->checkAccess('read',$ref_id))
492  {
493  $this->tpl->setCurrentBlock("chat_info");
494  $this->tpl->setVariable("CHAT_ACTIVE_IN",$lng->txt('chat_active_in'));
495  $this->tpl->setVariable("CHAT_LINK","./ilias.php?baseClass=ilChatPresentationGUI&ref_id=".$ref_id."&room_id=0");
496  $this->tpl->setVariable("CHAT_TITLE",ilObject::_lookupTitle($chat_id));
497  $this->tpl->parseCurrentBlock();
498 
499  return true;
500  }
501  }
502  return false;
503  }
504 
505  function __showChatInvitation($a_usr_id)
506  {
507  global $rbacsystem,$ilUser,$lng;
508 
509  include_once './Modules/Chat/classes/class.ilObjChat.php';
510 
511  if($a_usr_id == $ilUser->getId())
512  {
513  return false;
514  }
515 
516  if($rbacsystem->checkAccess('read',ilObjChat::_getPublicChatRefId())
517  and $rbacsystem->checkAccessOfUser($a_usr_id,'read',ilObjChat::_getPublicChatRefId()))
518  {
519  $this->tpl->setCurrentBlock("chat_link");
520  $this->tpl->setVariable("TXT_CHAT_INVITE",$lng->txt('chat_invite_public_room'));
521  $this->tpl->setVariable("CHAT_LINK",'./ilias.php?baseClass=ilChatPresentationGUI&ref_id='.ilObjChat::_getPublicChatRefId().
522  '&usr_id='.$a_usr_id.'&cmd=invitePD');
523  $this->tpl->setVariable('TXT_CHAT_INVITE_TOOLTIP', $lng->txt('chat_invite_public_room_tooltip'));
524  $this->tpl->parseCurrentBlock();
525 
526  return true;
527  }
528  return false;
529  }
530 
534  function showUserProfile()
535  {
536  global $lng, $ilCtrl;
537 
538  include_once("./Services/PersonalDesktop/classes/class.ilPDContentBlockGUI.php");
539  $content_block = new ilPDContentBlockGUI("ilpersonaldesktopgui", "show");
540  include_once('./Services/User/classes/class.ilPublicUserProfileGUI.php');
541  $profile_gui = new ilPublicUserProfileGUI($_GET["user"]);
542  $profile_gui->setAsRows(true);
543  $content_block->setContent($ilCtrl->getHTML($profile_gui));
544 
545  $content_block->setTitle($lng->txt("profile_of")." ".
546  ilObjUser::_lookupLogin($_GET["user"]));
547  $content_block->setColSpan(2);
548  $content_block->setImage(ilUtil::getImagePath("icon_usr.gif"));
549  $content_block->addHeaderCommand($ilCtrl->getParentReturn($this),
550  $lng->txt("selected_items_back"));
551 
552  return $content_block->getHTML();
553  }
554 
555 }
556 
557 ?>