ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 
24  function __construct()
25  {
26  global $ilCtrl, $lng, $ilUser;
27 
28  parent::__construct();
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  }
192  parent::fillDataSection();
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 
298  // username
299  if(!$a_set["profile"])
300  {
301  $this->tpl->setVariable("USR_LOGIN", $a_set["login"]);
302  }
303  else if ($this->getCurrentDetailLevel() > 2)
304  {
305  $this->tpl->setVariable("USR_LOGIN", "<br />".$a_set["login"]);
306  }
307  else
308  {
309  $this->tpl->setVariable("USR_LOGIN", " [".$a_set["login"]."]");
310  }
311 
312  // profile link
313  if ($a_set["profile"])
314  {
315  include_once "Services/User/classes/class.ilUserUtil.php";
316  $user_name = ilUserUtil::getNamePresentation($a_set["id"], false, false, "", false, true, false);
317 
318  $this->tpl->setCurrentBlock("profile_link");
319  $this->tpl->setVariable("TXT_VIEW", $lng->txt("profile"));
320 
321  // see ilPersonalProfileGUI::getProfilePortfolio()
322  $has_prtf = false;
323  if ($ilSetting->get('user_portfolios'))
324  {
325  include_once "Modules/Portfolio/classes/class.ilObjPortfolio.php";
326  $has_prtf = ilObjPortfolio::getDefaultPortfolio($a_set["id"]);
327  }
328  if(!$has_prtf)
329  {
330  // (simple) profile: center column
331  $ilCtrl->setParameter($this, "user", $a_set["id"]);
332  $this->tpl->setVariable("LINK_PROFILE",
333  $ilCtrl->getLinkTargetByClass("ilpublicuserprofilegui", "getHTML"));
334  }
335  else
336  {
337  // portfolio: fullscreen
338  include_once "Services/Link/classes/class.ilLink.php";
339  $this->tpl->setVariable("LINK_PROFILE", ilLink::_getLink($a_set["id"], "usr"));
340  $this->tpl->setVariable("LINK_TARGET", "_blank");
341  }
342 
343  $this->tpl->setVariable("USR_ID", $a_set["id"]);
344  $this->tpl->setVariable("LINK_FULLNAME", $user_name);
345  $this->tpl->parseCurrentBlock();
346  }
347  else
348  {
349  $this->tpl->setVariable("USR_FULLNAME", "");
350  }
351  }
352 
356  function getOverview()
357  {
358  global $ilUser, $lng, $ilCtrl;
359 
360  // parse visitors text
361  if (empty($this->visitors) || $this->users_online_pref == "associated")
362  {
363  $visitor_text = "";
364  }
365  elseif ($this->visitors == "1")
366  {
367  $visitor_text = "1 ".$lng->txt("visitor");
368  }
369  else
370  {
371  $visitor_text = $visitors." ".$lng->txt("visitors");
372  }
373 
374  // parse registered users text
375  if ($this->num_users > 0)
376  {
377  $user_kind = ($this->users_online_pref == "associated") ? "associated_user" : "registered_user";
378  if ($this->num_users == 1)
379  {
380  $user_list = $this->num_users." ".$lng->txt($user_kind);
381  }
382 
383  else
384  {
385  $user_list = $this->num_users." ".$lng->txt($user_kind."s");
386  }
387 
388  if (!empty($visitor_text))
389  {
390  $user_list .= " ".$lng->txt("and")." ".$visitor_text;
391  }
392  }
393  else
394  {
395  $user_list = $visitor_text;
396  }
397 
398  return '<div class="small">'.$user_list."</div>";
399  }
400 
401  function __showActiveChatsOfUser($a_usr_id)
402  {
403  global $rbacsystem, $lng;
404 
405  // show chat info
406  /*
407  $chat_id = ilChatRoom::_isActive($a_usr_id);
408  foreach(ilObject::_getAllReferences($chat_id) as $ref_id)
409  {
410  if($rbacsystem->checkAccess('read',$ref_id))
411  {
412  $this->tpl->setCurrentBlock("chat_info");
413  $this->tpl->setVariable("CHAT_ACTIVE_IN",$lng->txt('chat_active_in'));
414  $this->tpl->setVariable("CHAT_LINK","./ilias.php?baseClass=ilChatPresentationGUI&ref_id=".$ref_id."&room_id=0");
415  $this->tpl->setVariable("CHAT_TITLE",ilObject::_lookupTitle($chat_id));
416  $this->tpl->parseCurrentBlock();
417 
418  return true;
419  }
420  }*/
421  return false;
422  }
423 
424  function __showChatInvitation($a_usr_id)
425  {
426  global $rbacsystem,$ilUser,$lng;
427 
428  include_once './Modules/Chatroom/classes/class.ilObjChatroom.php';
429 
430  if($a_usr_id == $ilUser->getId())
431  {
432  return false;
433  }
434 
435  //if($rbacsystem->checkAccess('read',ilObjChat::_getPublicChatRefId())
436  //and $rbacsystem->checkAccessOfUser($a_usr_id,'read',ilObjChat::_getPublicChatRefId()))
437  if($rbacsystem->checkAccess('read',ilObjChatroom::_getPublicRefId())
438  and $rbacsystem->checkAccessOfUser($a_usr_id,'read',ilObjChatroom::_getPublicRefId()))
439  {
440  $this->tpl->setCurrentBlock("chat_link");
441  $this->tpl->setVariable("TXT_CHAT_INVITE",$lng->txt('chat_invite_public_room'));
442  //$this->tpl->setVariable("CHAT_LINK",'./ilias.php?baseClass=ilChatPresentationGUI&ref_id='.ilObjChat::_getPublicChatRefId().
443  //'&usr_id='.$a_usr_id.'&cmd=invitePD');
444  $this->tpl->setVariable("CHAT_LINK",'./ilias.php?baseClass=ilRepositoryGUI&ref_id='.ilObjChatroom::_getPublicRefId().'&usr_id='.$a_usr_id.'&cmd=view-invitePD');
445  $this->tpl->setVariable('TXT_CHAT_INVITE_TOOLTIP', $lng->txt('chat_invite_public_room_tooltip'));
446  $this->tpl->parseCurrentBlock();
447 
448  return true;
449  }
450  return false;
451  }
452 }
453 
454 ?>
static getScreenMode()
Get Screen Mode for current command.
ILIAS Setting Class.
BlockGUI class for Personal Desktop Users Online block.
setDataSection($a_content)
Call this from overwritten fillDataSection(), if standard row based data is not used.
$_GET["client_id"]
$cmd
Definition: sahs_server.php:35
setEnableNumInfo($a_enablenuminfo)
Set Enable Item Number Info.
global $tpl
Definition: ilias.php:8
global $ilCtrl
Definition: ilias.php:18
setColSpan($a_colspan)
Set Columns Span.
GUI class for public user profile presentation.
static getAssociatedUsersOnline($a_user_id)
reads all active sessions from db and returns users that are online and who have a local role in a gr...
static getNamePresentation($a_user_id, $a_user_image=false, $a_profile_link=false, $a_profile_back_link="", $a_force_first_lastname=false, $a_omit_login=false, $a_sortable=true, $a_return_data_array=false)
Default behaviour is:
const IL_SCREEN_FULL
setTitle($a_title)
Set Title.
setData($a_data)
Set Data.
setAvailableDetailLevels($a_max, $a_min=0)
Set Available Detail Levels.
$ilUser
Definition: imgupload.php:18
static isRepositoryObject()
Is block used in repository object?
static getBlockType()
Get block type.
Create styles array
The data for the language used.
fillDataSection()
Fill data section.
static getLinkTarget($gui, $cmd, Array $gui_params=array(), Array $mail_params=array(), $context_params=array())
setLimit($a_limit)
Set Limit.
global $ilSetting
Definition: privfeed.php:17
setCurrentDetailLevel($a_currentdetaillevel)
Set Current Detail Level.
static _lookupPref($a_usr_id, $a_keyword)
global $lng
Definition: privfeed.php:17
static _getPersonalPicturePath($a_usr_id, $a_size="small", $a_force_pic=false, $a_prevent_no_photo_image=false)
Get path to personal picture.
GUI class for personal desktop.
global $ilDB
static getMailObjectRefId()
Determines the reference id of the mail object and stores this information in a local cache variable...
static getDefaultPortfolio($a_user_id)
Get default portfolio of user.
This class represents a block method of a block.
const IL_SCREEN_SIDE
setRowTemplate($a_rowtemplatename, $a_rowtemplatedir="")
Set Row Template Name.
fillRow($a_set)
get flat bookmark list for personal desktop
getCurrentDetailLevel()
Get Current Detail Level.