ILIAS  eassessment Revision 61809
 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  // user image
271  $this->tpl->setCurrentBlock("usr_image");
272  $this->tpl->setVariable("USR_IMAGE",
273  ilObjUser::_getPersonalPicturePath($a_set["id"],"xxsmall"));
274  $this->tpl->setVariable("USR_ALT", $lng->txt("personal_picture"));
275  $this->tpl->parseCurrentBlock();
276 
277  $pd_set = new ilSetting("pd");
278  $osi_server = $pd_set->get("osi_host");
279 
280 // if (trim($osi_server) != "")
281 // {
282  // instant messengers
283  // 1 indicates to use online status check
284  $im_arr = array("icq" => 0,
285  "yahoo" => 1,
286  "msn" => 0,
287  "aim" => 0,
288  "skype" => 1,
289  "jabber" => 0,
290  "voip" => 0);
291 
292  // use onlinestatus.org
293  // when enabled all instant messengers are checked online and ignores settings above
294  if (trim($osi_server) != "")
295  {
296  $osi_enable = true;
297  }
298 
299  foreach ($im_arr as $im_name => $im_check)
300  {
301  if ($im_id = ilObjUser::_lookupIm($a_set["id"], $im_name))
302  {
303  $im_url = "#";
304  switch ($im_name)
305  {
306  case "icq":
307  //$im_url = "http://people.icq.com/people/webmsg.php?to=".$im_id;
308  $im_url = "http://people.icq.com/people/about_me.php?uin=".$im_id;
309  //$im_img = "http://status.icq.com/online.gif?icq=".$im_id."&img=5";
310  $im_img = "http://wwp.icq.com/scripts/online.dll?icq=".$im_id."&img=5";
311  break;
312 
313  case "yahoo":
314  $im_url = "http://edit.yahoo.com/config/send_webmesg?.target=".$im_id."&.src=pg";
315  $im_img = "http://opi.yahoo.com/online?u=".$im_id."&m=g&t=5";
316  break;
317 
318  case "msn":
319  $im_url = "http://messenger.live.com";
320  $im_img = ilUtil::getImagePath($im_name.'offline.gif'); // online check not possible
321  break;
322 
323  case "aim":
324  //$im_url = "aim:GoIM?screenname=".$im_id;
325  $im_url = "http://aimexpress.aim.com";
326  //$im_img = "http://api.oscar.aol.com/SOA/key=<put_your_key_here>/presence/".$im_id; // doesn't work. you need a key
327  $im_img = ilUtil::getImagePath($im_name.'offline.gif'); // online check not possible
328  break;
329 
330  case "skype":
331  $im_url = "skype:".$im_id."?call";
332  /* the link above needs this piece of js to work
333  <script type="text/javascript"
334  src="http://download.skype.com/share/skypebuttons/js/skypeCheck.js">
335  </script>
336  */
337  //$im_url = "http://www.skype.com/go/download";
338  $im_img = "http://mystatus.skype.com/smallicon/".$im_id;
339  break;
340  }
341 
342  $this->tpl->setCurrentBlock("instant_messengers");
343 
344  if ($osi_enable)
345  {
346  $this->tpl->setVariable("URL_IM",$osi_server."/message/".$im_name."/".$im_id);
347  $this->tpl->setVariable("IMG_IM_ICON",$osi_server."/".$im_name."/".$im_id);
348  }
349  else
350  {
351  $this->tpl->setVariable("URL_IM",$im_url);
352  $this->tpl->setVariable("IMG_IM_ICON", $im_check ? $im_img : ilUtil::getImagePath($im_name.'offline.gif'));
353  }
354 
355  $this->tpl->setVariable("TXT_IM_ICON", $lng->txt("im_".$im_name));
356  $this->tpl->parseCurrentBlock();
357  }
358  }
359 // }
360  }
361 
362  // username
363  if ($this->getCurrentDetailLevel() > 2)
364  {
365  $this->tpl->setVariable("USR_LOGIN", "<br />".$a_set["login"]);
366  }
367  else
368  {
369  $this->tpl->setVariable("USR_LOGIN", " [".$a_set["login"]."]");
370  }
371 
372  // profile link
373  if ($a_set["profile"])
374  {
375  $this->tpl->setCurrentBlock("profile_link");
376  $this->tpl->setVariable("TXT_VIEW", $lng->txt("profile"));
377  $ilCtrl->setParameter($this, "user", $a_set["id"]);
378  $this->tpl->setVariable("LINK_PROFILE",
379  $ilCtrl->getLinkTarget($this, "showUserProfile"));
380  $this->tpl->setVariable("USR_ID", $a_set["id"]);
381  $this->tpl->setVariable("LINK_FULLNAME", ilObjUser::_lookupFullName($a_set["id"]));
382  $this->tpl->parseCurrentBlock();
383  }
384  else
385  {
386  $this->tpl->setVariable("USR_FULLNAME", ilObjUser::_lookupFullName($a_set["id"]));
387  }
388  }
389 
393  function getOverview()
394  {
395  global $ilUser, $lng, $ilCtrl;
396 
397  // parse visitors text
398  if (empty($this->visitors) || $this->users_online_pref == "associated")
399  {
400  $visitor_text = "";
401  }
402  elseif ($this->visitors == "1")
403  {
404  $visitor_text = "1 ".$lng->txt("visitor");
405  }
406  else
407  {
408  $visitor_text = $visitors." ".$lng->txt("visitors");
409  }
410 
411  // parse registered users text
412  if ($this->num_users > 0)
413  {
414  $user_kind = ($this->users_online_pref == "associated") ? "associated_user" : "registered_user";
415  if ($this->num_users == 1)
416  {
417  $user_list = $this->num_users." ".$lng->txt($user_kind);
418  }
419 
420  else
421  {
422  $user_list = $this->num_users." ".$lng->txt($user_kind."s");
423  }
424 
425  if (!empty($visitor_text))
426  {
427  $user_list .= " ".$lng->txt("and")." ".$visitor_text;
428  }
429  }
430  else
431  {
432  $user_list = $visitor_text;
433  }
434 
435  return '<div class="small">'.$user_list."</div>";
436  }
437 
441  function showUserProfile()
442  {
443  global $lng, $ilCtrl;
444 
445 // include_once("./Services/PersonalDesktop/classes/class.ilPDContentBlockGUI.php");
446 // $content_block = new ilPDContentBlockGUI("ilpersonaldesktopgui", "show");
447  include_once('./Services/User/classes/class.ilPublicUserProfileGUI.php');
448  $profile_gui = new ilPublicUserProfileGUI($_GET["user"]);
449  //$profile_gui->setAsRows(true);
450  $profile_gui->setBackUrl($ilCtrl->getParentReturn($this));
451 // $content_block->setContent($ilCtrl->getHTML($profile_gui));
452 
453 // $content_block->setTitle($lng->txt("profile_of")." ".
454 // ilObjUser::_lookupLogin($_GET["user"]));
455 // $content_block->setColSpan(2);
456 // $content_block->setImage(ilUtil::getImagePath("icon_usr.gif"));
457 // $content_block->addHeaderCommand($ilCtrl->getParentReturn($this),
458 // $lng->txt("selected_items_back"));
459 
460 // return $content_block->getHTML();
461  return $ilCtrl->getHTML($profile_gui);
462  }
463 
464 }
465 
466 ?>