• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

Services/PersonalDesktop/classes/class.ilUsersOnlineBlockGUI.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2006 ILIAS open source, University of Cologne            |
00007         |                                                                             |
00008         | This program is free software; you can redistribute it and/or               |
00009         | modify it under the terms of the GNU General Public License                 |
00010         | as published by the Free Software Foundation; either version 2              |
00011         | of the License, or (at your option) any later version.                      |
00012         |                                                                             |
00013         | This program is distributed in the hope that it will be useful,             |
00014         | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00015         | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
00016         | GNU General Public License for more details.                                |
00017         |                                                                             |
00018         | You should have received a copy of the GNU General Public License           |
00019         | along with this program; if not, write to the Free Software                 |
00020         | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
00021         +-----------------------------------------------------------------------------+
00022 */
00023 
00024 include_once("Services/Block/classes/class.ilBlockGUI.php");
00025 
00035 class ilUsersOnlineBlockGUI extends ilBlockGUI
00036 {
00037         static $block_type = "pdusers";
00038         
00042         function ilUsersOnlineBlockGUI()
00043         {
00044                 global $ilCtrl, $lng, $ilUser;
00045                 
00046                 parent::ilBlockGUI($a_parent_class, $a_parent_cmd);
00047                 
00048                 $this->setLimit(10);
00049                 $this->setImage(ilUtil::getImagePath("icon_grp_s.gif"));
00050                 $this->setTitle($lng->txt("users_online"));
00051                 $this->setAvailableDetailLevels(3);
00052         }
00053         
00059         static function getBlockType()
00060         {
00061                 return self::$block_type;
00062         }
00063         
00069         static function isRepositoryObject()
00070         {
00071                 return false;
00072         }
00073 
00077         static function getScreenMode()
00078         {
00079                 global $ilCtrl;
00080 
00081                 switch($ilCtrl->getCmd())
00082                 {
00083                         case "showUserProfile":
00084                                 return IL_SCREEN_CENTER;
00085                                 break;
00086                                 
00087                         default:
00088                                 return IL_SCREEN_SIDE;
00089                                 break;
00090                 }
00091         }
00092 
00096         function &executeCommand()
00097         {
00098                 global $ilCtrl;
00099 
00100                 $next_class = $ilCtrl->getNextClass();
00101                 $cmd = $ilCtrl->getCmd("getHTML");
00102                 
00103                 switch($next_class)
00104                 {
00105                         // profile
00106                         case "ilobjusergui":
00107                                 include_once('./Services/User/classes/class.ilObjUserGUI.php');
00108                                 $user_gui = new ilObjUserGUI("",$_GET["user"], false, false);
00109                                 $return = $ilCtrl->forwardCommand($user_gui);
00110                                 break;
00111                                 
00112                         default:
00113                                 return $this->$cmd();
00114                 }
00115         }
00116 
00117         function getHTML()
00118         {
00119                 global $ilUser;
00120                 
00121                 $this->users_online_pref = $ilUser->getPref("show_users_online");
00122                 
00123                 if ($this->users_online_pref != "y" && $this->users_online_pref != "associated")
00124                 {
00125                         return "";
00126                 }
00127                 
00128                 $this->getUsers();
00129                 
00130                 if ($this->getCurrentDetailLevel() == 0)
00131                 {
00132                         return "";
00133                 }
00134                 else
00135                 {
00136                         return parent::getHTML();
00137                 }
00138         }
00139         
00143         function getUsers()
00144         {
00145                 global $ilUser;
00146                 
00147                 if ($this->users_online_pref == "associated")
00148                 {
00149                         $this->users = ilUtil::getAssociatedUsersOnline($ilUser->getId());
00150                 }
00151                 else
00152                 {
00153                         $this->users = ilUtil::getUsersOnline();
00154                 }
00155                 
00156                 $this->num_users = 0;
00157                 
00158                 $this->users[$ilUser->getId()] =
00159                         array("user_id" => $ilUser->getId(),
00160                                 "firstname" => $ilUser->getFirstname(),
00161                                 "lastname" => $ilUser->getLastname(),
00162                                 "title" => $ilUser->getUTitle(),
00163                                 "login" => $ilUser->getLogin());
00164 
00165                 foreach ($this->users as $user_id => $user)
00166                 {
00167                         if ($user_id != ANONYMOUS_USER_ID)
00168                         {
00169                                 $this->num_users++;
00170                         }
00171                         else
00172                         {
00173                                 $this->visitors = $user["num"];
00174                         }
00175                 }
00176         }
00177         
00181         function fillDataSection()
00182         {
00183                 global $ilUser, $ilSetting, $ilCtrl;
00184                 
00185                 $pd_set = new ilSetting("pd");
00186                 
00187                 include_once("Services/Notes/classes/class.ilNote.php");
00188                 
00189                 if ($this->getCurrentDetailLevel() > 1 && $this->num_users > 0)
00190                 {
00191                         $this->setRowTemplate("tpl.users_online_row.html", "Services/PersonalDesktop");
00192                         $this->getListRowData();
00193                         if ($this->getCurrentDetailLevel() > 2)
00194                         {
00195                                 $this->setColSpan(2);
00196                         }
00197                         parent::fillDataSection();
00198                 }
00199                 else
00200                 {
00201                         $this->setEnableNumInfo(false);
00202                         $this->setDataSection($this->getOverview());
00203                 }
00204         }
00205         
00206 
00210         function getListRowData()
00211         {
00212                 global $ilUser, $lng, $ilCtrl, $ilDB, $rbacsystem;
00213 
00214                 $data = array();
00215                 
00216                 $mail = new ilMail($ilUser->getId());
00217                 $mail_settings_id = $mail->getMailObjectReferenceId();
00218                 
00219                 foreach ($this->users as $user_id => $user)
00220                 {
00221                         if ($user_id != ANONYMOUS_USER_ID &&
00222                                 ilObjUser::_lookupPref($user_id, "hide_own_online_status") != "y")
00223                         {
00224                                 // hide mail-to icon for anonymous users
00225                                 // usability: we do show mail-to for the current user, because
00226                                 //            we often got requests by users that their own
00227                                 //            e-mail address doesn't appear 
00228                                 $mail_to = "";
00229                                 if ($_SESSION["AccountId"] != ANONYMOUS_USER_ID)
00230                                 {
00231                                         // No mail for users that do have permissions to use the mail system
00232                                         if($rbacsystem->checkAccess('mail_visible',$mail_settings_id) and
00233                                            $rbacsystem->checkAccessOfUser($user_id,'mail_visible',$mail_settings_id))
00234                                         {
00235                                                 $mail_to = ilMail::_getUserInternalMailboxAddress(
00236                                                         $user_id, $user['login'], $user['firstname'], $user['lastname']
00237                                                 );
00238                                                 
00239                                                 #$mail_to = urlencode($mail_to);
00240                                                 $mail_to = $user['login'];
00241                                         }
00242                                 }
00243                                 
00244                                 // check for profile
00245                                 // todo: use user class!
00246                                 $q = "SELECT value FROM usr_pref WHERE usr_id = ".
00247                                         $ilDB->quote($user_id)." AND keyword='public_profile' AND value='y'";
00248                                 $r = $ilDB->query($q);
00249                                 $profile = false;
00250                                 if ($r->numRows())
00251                                 {
00252                                         $profile = true;
00253                                 }
00254                                                                                         
00255                                 $data[] = array(
00256                                         "mail_to" => $mail_to,
00257                                         "id" => $user_id,
00258                                         "profile" => $profile,
00259                                         "login" => $user["login"]
00260                                         );
00261                         }
00262                 }
00263                 
00264                 $this->setData($data);
00265                 
00266                 // we do not have at least one (non hidden) active user
00267                 if (count($data) == 0)
00268                 {
00269                         $this->setEnableNumInfo(false);
00270                         $this->setCurrentDetailLevel(1);
00271                         $this->enabledetailrow = false;
00272                         $this->setDataSection($this->getOverview());
00273                 }
00274         }
00275         
00279         function fillRow($a_set)
00280         {
00281                 global $ilUser, $ilCtrl, $lng, $ilSetting;
00282                 
00283                 $user_obj = new ilObjUser($a_set["id"]);
00284                 
00285                 // user image
00286                 if ($this->getCurrentDetailLevel() > 2)
00287                 {
00288                         if ($a_set["mail_to"] != "")
00289                         {
00290                                 $this->tpl->setCurrentBlock("mailto_link");
00291                                 $this->tpl->setVariable("TXT_MAIL", $lng->txt("mail"));
00292                                 $this->tpl->setVariable("MAIL_USR_LOGIN", urlencode($a_set["mail_to"]));
00293                                 $this->tpl->parseCurrentBlock();
00294                         }
00295         
00296                         include_once './Modules/Chat/classes/class.ilChatServerConfig.php';
00297                         if(ilChatServerConfig::_isActive())
00298                         {
00299                                 if(!$this->__showActiveChatsOfUser($a_set["id"]))
00300                                 {
00301                                         // Show invite to chat
00302                                         $this->__showChatInvitation($a_set["id"]);
00303                                 }
00304                         }
00305                         
00306                         // user image
00307                         $this->tpl->setCurrentBlock("usr_image");
00308                         $this->tpl->setVariable("USR_IMAGE",
00309                                 $user_obj->getPersonalPicturePath("xxsmall"));
00310                         $this->tpl->setVariable("USR_ALT", $lng->txt("personal_picture"));
00311                         $this->tpl->parseCurrentBlock();
00312                 
00313                         $pd_set = new ilSetting("pd");
00314                         $osi_server = $pd_set->get("osi_host");
00315                         
00316                         if (trim($osi_server) != "")
00317                         {
00318                                 // instant messengers
00319                                 // 1 indicates to use online status check
00320                                 $im_arr = array("icq" => 1,
00321                                                                 "yahoo" => 1,
00322                                                                 "msn" => 0,
00323                                                                 "aim" => 0,
00324                                                                 "skype" => 1);
00325                                                                                         
00326                                 // use onlinestatus.org
00327                                 // when enabled all instant messengers are checked online and ignores settings above
00328                                 $osi_enable = true;
00329                 
00330                                 foreach ($im_arr as $im_name => $im_check)
00331                                 {
00332                                         if ($im_id = $user_obj->getInstantMessengerId($im_name))
00333                                         {
00334                                                 switch ($im_name)
00335                                                 {
00336                                                         case "icq":
00337                                                                 //$im_url = "http://people.icq.com/people/webmsg.php?to=".$im_id;
00338                                                                 $im_url = "http://people.icq.com/people/about_me.php?uin=".$im_id;
00339                                                                 $im_img = "http://status.icq.com/online.gif?icq=".$im_id."&img=5";
00340                                                                 break;
00341                                                         
00342                                                         case "yahoo":
00343                                                                 $im_url = "http://edit.yahoo.com/config/send_webmesg?.target=".$im_id."&.src=pg";
00344                                                                 $im_img = "http://opi.yahoo.com/online?u=".$im_id."&m=g&t=5";
00345                                                                 break;
00346                                                                 
00347                                                         case "msn":
00348                                                                 $im_url = "http://messenger.live.com";
00349                                                                 $im_img = ilUtil::getImagePath($im_name.'offline.gif'); // online check not possible
00350                 
00351                                                                 break;
00352                 
00353                                                         case "aim":
00354                                                                 //$im_url = "aim:GoIM?screenname=".$im_id;
00355                                                                 $im_url = "http://aimexpress.aim.com";
00356                                                                 //$im_img = "http://api.oscar.aol.com/SOA/key=<put_your_key_here>/presence/".$im_id; // doesn't work. you need a key
00357                                                                 $im_img = ilUtil::getImagePath($im_name.'offline.gif'); // online check not possible
00358                                                                 break;
00359                 
00360                                                         case "skype":
00361                                                                 $im_url = "skype:".$im_id."?call";
00362                                                                 /* the link above needs this piece of js to work
00363                                                                 <script type="text/javascript" 
00364                                                                 src="http://download.skype.com/share/skypebuttons/js/skypeCheck.js">
00365                                                                 </script>
00366                                                                 */
00367                                                                 //$im_url = "http://www.skype.com/go/download";
00368                                                                 $im_img = "http://mystatus.skype.com/smallicon/".$im_id;
00369                                                                 break;
00370                                                 }
00371                 
00372                                                 $this->tpl->setCurrentBlock("instant_messengers");
00373                                                 
00374                                                 if ($osi_enable)
00375                                                 {
00376                                                         $this->tpl->setVariable("URL_IM",$osi_server."/message/".$im_name."/".$im_id);
00377                                                         $this->tpl->setVariable("IMG_IM_ICON",$osi_server."/".$im_name."/".$im_id);
00378                                                 }
00379                                                 else
00380                                                 {
00381                                                         $this->tpl->setVariable("URL_IM",$im_url);
00382                                                         $this->tpl->setVariable("IMG_IM_ICON", $im_check ? $im_img : ilUtil::getImagePath($im_name.'offline.gif'));
00383                                                 }
00384                                                 
00385                                                 $this->tpl->setVariable("TXT_IM_ICON", $lng->txt("im_".$im_name));
00386                                                 $this->tpl->parseCurrentBlock();
00387                                         }
00388                                 }
00389                         }
00390                 }
00391                                         
00392                 // username
00393                 if ($this->getCurrentDetailLevel() > 2)
00394                 {
00395                         $this->tpl->setVariable("USR_LOGIN", "<br />".$a_set["login"]);
00396                 }
00397                 else
00398                 {
00399                         $this->tpl->setVariable("USR_LOGIN", " [".$a_set["login"]."]");
00400                 }
00401                 
00402                 // profile link
00403                 if ($a_set["profile"])
00404                 {
00405                         $this->tpl->setCurrentBlock("profile_link");
00406                         $this->tpl->setVariable("TXT_VIEW", $lng->txt("profile"));
00407                         $ilCtrl->setParameter($this, "user", $a_set["id"]);
00408                         $this->tpl->setVariable("LINK_PROFILE",
00409                         $ilCtrl->getLinkTarget($this, "showUserProfile"));
00410                         $this->tpl->setVariable("USR_ID", $a_set["id"]);
00411                         $this->tpl->setVariable("LINK_FULLNAME", $user_obj->getFullname());
00412                         $this->tpl->parseCurrentBlock();
00413                 }
00414                 else
00415                 {
00416                         $this->tpl->setVariable("USR_FULLNAME", $user_obj->getFullname());
00417                 }
00418         }
00419 
00423         function getOverview()
00424         {
00425                 global $ilUser, $lng, $ilCtrl;
00426                 
00427                 // parse visitors text
00428                 if (empty($this->visitors) || $this->users_online_pref == "associated")
00429                 {
00430                         $visitor_text = "";
00431                 }
00432                 elseif ($this->visitors == "1")
00433                 {
00434                         $visitor_text = "1 ".$lng->txt("visitor");
00435                 }
00436                 else
00437                 {
00438                         $visitor_text = $visitors." ".$lng->txt("visitors");
00439                 }
00440                 
00441                 // parse registered users text
00442                 if ($this->num_users > 0)
00443                 {
00444                         $user_kind = ($this->users_online_pref == "associated") ? "associated_user" : "registered_user";
00445                         if ($this->num_users == 1)
00446                         {
00447                                 $user_list = $this->num_users." ".$lng->txt($user_kind);
00448                         }
00449                         
00450                         else
00451                         {
00452                                 $user_list = $this->num_users." ".$lng->txt($user_kind."s");
00453                         }
00454                                                 
00455                         if (!empty($visitor_text))
00456                         {
00457                                 $user_list .= " ".$lng->txt("and")." ".$visitor_text;
00458                         }
00459                 }
00460                 else
00461                 {
00462                         $user_list = $visitor_text;
00463                 }
00464                 
00465                 return '<div class="small">'.$user_list."</div>";
00466         }
00467 
00468         function __showActiveChatsOfUser($a_usr_id)
00469         {
00470                 global $rbacsystem, $lng;
00471                 
00472                 // show chat info
00473                 include_once './Modules/Chat/classes/class.ilChatRoom.php';
00474                 
00475                 $chat_id = ilChatRoom::_isActive($a_usr_id);
00476                 foreach(ilObject::_getAllReferences($chat_id) as $ref_id)
00477                 {
00478                         if($rbacsystem->checkAccess('read',$ref_id))
00479                         {
00480                                 $this->tpl->setCurrentBlock("chat_info");
00481                                 $this->tpl->setVariable("CHAT_ACTIVE_IN",$lng->txt('chat_active_in'));
00482                                 $this->tpl->setVariable("CHAT_LINK","./chat.php?ref_id=".$ref_id."&room_id=0");
00483                                 $this->tpl->setVariable("CHAT_TITLE",ilObject::_lookupTitle($chat_id));
00484                                 $this->tpl->parseCurrentBlock();
00485                                 
00486                                 return true;
00487                         }
00488                 }
00489                 return false;
00490         }
00491         
00492         function __showChatInvitation($a_usr_id)
00493         {
00494                 global $rbacsystem,$ilUser,$lng;
00495                 
00496                 include_once './Modules/Chat/classes/class.ilObjChat.php';
00497                 
00498                 if($a_usr_id == $ilUser->getId())
00499                 {
00500                         return false;
00501                 }
00502                 
00503                 if($rbacsystem->checkAccess('read',ilObjChat::_getPublicChatRefId())
00504                 and $rbacsystem->checkAccessOfUser($a_usr_id,'read',ilObjChat::_getPublicChatRefId()))
00505                 {
00506                         $this->tpl->setCurrentBlock("chat_link");
00507                         $this->tpl->setVariable("TXT_CHAT_INVITE",$lng->txt('chat_invite_public_room'));
00508                         $this->tpl->setVariable("CHAT_LINK",'./chat.php?ref_id='.ilObjChat::_getPublicChatRefId().
00509                         '&usr_id='.$a_usr_id.'&cmd=invitePD');
00510                         $this->tpl->parseCurrentBlock();
00511                         
00512                         return true;
00513                 }
00514                 return false;
00515         }
00516         
00520         function showUserProfile()
00521         {
00522                 global $lng, $ilCtrl;
00523                 include_once('./Services/User/classes/class.ilObjUserGUI.php');
00524                 $user_gui = new ilObjUserGUI("",$_GET["user"], false, false);
00525                 
00526                 include_once("./Services/PersonalDesktop/classes/class.ilPDContentBlockGUI.php");
00527                 $content_block = new ilPDContentBlockGUI("ilpersonaldesktopgui", "show");
00528                 $content_block->setContent($user_gui->getPublicProfile("", false, true));
00529                 $content_block->setTitle($lng->txt("profile_of")." ".
00530                         $user_gui->object->getLogin());
00531                 $content_block->setColSpan(2);
00532                 $content_block->setImage(ilUtil::getImagePath("icon_usr.gif"));
00533                 $content_block->addHeaderCommand($ilCtrl->getParentReturn($this),
00534                         $lng->txt("selected_items_back"));
00535                 
00536                 return $content_block->getHTML();
00537         }
00538 
00539 }
00540 
00541 ?>

Generated on Fri Dec 13 2013 17:57:00 for ILIAS Release_3_9_x_branch .rev 46835 by  doxygen 1.7.1