Esempio n. 1
0
 public function instantGIDchange($gid, $removegid = array(), $sessionextra = null)
 {
     if (empty($this->cmsUser)) {
         return null;
     }
     // Always protect last administrator
     if ($this->isAdmin()) {
         if (xJACLhandler::countAdmins() < 2) {
             return false;
         }
     }
     $shandler = new xJSessionHandler();
     return $shandler->instantGIDchange($this->userid, $gid, $removegid, $sessionextra);
 }
Esempio n. 2
0
 /**
  * @param integer $userid
  */
 public function instantGIDchange($userid, $gid, $removegid = array(), $sessionextra = null)
 {
     $user = JFactory::getUser();
     if (!is_array($gid) && !empty($gid)) {
         $gid = array($gid);
     } elseif (empty($gid)) {
         $gid = array();
     }
     if (!is_array($removegid) && !empty($removegid)) {
         $removegid = array($removegid);
     }
     if (!empty($removegid)) {
         xJACLhandler::removeGIDs((int) $userid, $removegid);
     }
     // Set GID and usertype
     if (!empty($gid)) {
         $info = xJACLhandler::setGIDs((int) $userid, $gid);
     }
     $session = $this->getSession($userid);
     if (empty($session)) {
         return true;
     }
     if (!empty($sessionextra)) {
         if (is_array($sessionextra)) {
             foreach ($sessionextra as $sk => $sv) {
                 $session['user']->{$sk} = $sv;
                 if ($userid == $user->id) {
                     $user->{$sk} = $sv;
                 }
             }
         }
     }
     if (isset($session['user'])) {
         $user = JFactory::getUser();
         $sgsids = JAccess::getGroupsByUser($userid);
         if (!empty($gid)) {
             foreach ($gid as $g) {
                 if (!in_array($g, $sgsids)) {
                     $sgsids[] = $g;
                 }
             }
         }
         if (!empty($removegid)) {
             foreach ($sgsids as $k => $g) {
                 if (in_array($g, $removegid)) {
                     unset($sgsids[$k]);
                 }
             }
         }
         $db = JFactory::getDBO();
         $query = 'SELECT `title`, `id`' . ' FROM #__usergroups' . ' WHERE `id` IN (' . implode(',', $sgsids) . ')';
         $db->setQuery($query);
         $sgslist = $db->loadObjectList();
         $sgs = array();
         foreach ($sgslist as $gidgroup) {
             if (!in_array($gidgroup->id, $removegid)) {
                 $sgs[$gidgroup->title] = $gidgroup->id;
             }
         }
         if ($userid == $user->id) {
             $user->set('groups', $sgs);
             $user->set('_authLevels', xJSessionHandler::getAuthorisedViewLevels($userid));
             $user->set('_authGroups', xJSessionHandler::getGroupsByUser($userid));
         }
         $session['user']->set('groups', $sgs);
         $session['user']->set('_authLevels', xJSessionHandler::getAuthorisedViewLevels($userid));
         $session['user']->set('_authGroups', xJSessionHandler::getGroupsByUser($userid));
     }
     $this->putSession($userid, $session, $gid[0], $info[$gid[0]]);
 }