Esempio n. 1
0
File: j15.php Progetto: Ibrahim1/aec
 /**
  * @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'])) {
         if (!empty($gid[0])) {
             $session['user']->gid = $gid[0];
             $session['user']->usertype = $info[$gid[0]];
             if ($userid == $user->id) {
                 $user->gid = $gid[0];
                 $user->usertype = $info[$gid[0]];
             }
         }
     }
     return $this->putSession($userid, $session, $gid[0], $info[$gid[0]]);
 }
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]]);
 }