/**
  * @see Page::readParameters()
  */
 public function readParameters()
 {
     AbstractForm::readParameters();
     // get user
     if (isset($_REQUEST['userID'])) {
         $this->userID = intval($_REQUEST['userID']);
         require_once WBB_DIR . 'lib/data/user/AbstractWBBUserSession.class.php';
         $this->user = new AbstractWBBUserSession($this->userID);
         if (!$this->user->userID) {
             throw new IllegalLinkException();
         }
         require_once WCF_DIR . 'lib/data/user/group/Group.class.php';
         if (!Group::isAccessibleGroup($this->user->getGroupIDs())) {
             throw new PermissionDeniedException();
         }
     }
     // active permission
     if (isset($_REQUEST['permissionName'])) {
         $this->permissionName = $_REQUEST['permissionName'];
     }
     $this->readPermissionSettings();
 }
 /**
  * Updates the amount of activity points of a user.
  * 
  * @param	integer		$points
  * @param	integer		$userID
  * @param	integer		$packageID
  */
 public static function updateActivityPoints($points, $userID = null, $packageID = PACKAGE_ID)
 {
     // get user object
     if ($userID === null) {
         $user = WCF::getUser();
     } else {
         $user = new User($userID);
         if (!$user->userID) {
             return false;
         }
     }
     if ($points != 0) {
         // update activity points for the package
         $sql = "UPDATE\twcf" . WCF_N . "_user_activity_point\n\t\t\t\tSET\tactivityPoints = IF(" . $points . " > 0 OR activityPoints > ABS(" . $points . "), activityPoints + " . $points . ", 0)\n\t\t\t\tWHERE\tuserID = " . $user->userID . "\n\t\t\t\t\tAND packageID = " . $packageID;
         WCF::getDB()->sendQuery($sql);
         if (WCF::getDB()->getAffectedRows() == 0) {
             $sql = "INSERT IGNORE INTO\twcf" . WCF_N . "_user_activity_point\n\t\t\t\t\t\t\t\t(userID, packageID, activityPoints)\n\t\t\t\t\tVALUES\t\t\t(" . $user->userID . ", " . $packageID . ", " . ($points > 0 ? $points : 0) . ")";
             WCF::getDB()->sendQuery($sql);
         }
     }
     // update user new rank
     $newRankID = 0;
     $neededPoints = intval($user->activityPoints + $points);
     if ($neededPoints < 0) {
         $neededPoints = 0;
     }
     $sql = "SELECT\t\trankID\n\t\t\tFROM\t\twcf" . WCF_N . "_user_rank\n\t\t\tWHERE\t\tgroupID IN (" . ($user->rankID ? "(SELECT groupID FROM wcf" . WCF_N . "_user_rank WHERE rankID = " . $user->rankID . ")" : implode(',', $user->getGroupIDs())) . ") \n\t\t\t\t\tAND neededPoints <= " . $neededPoints . "\n\t\t\t\t\tAND gender IN (0," . intval($user->gender) . ")\n\t\t\tORDER BY\tneededPoints DESC, gender DESC";
     $row = WCF::getDB()->getFirstRow($sql);
     if (isset($row['rankID'])) {
         $newRankID = $row['rankID'];
     }
     // update user rank and global activity points
     $sql = "UPDATE\twcf" . WCF_N . "_user\n\t\t\tSET\tactivityPoints = IF(" . $points . " > 0 OR activityPoints > ABS(" . $points . "), activityPoints + " . $points . ", 0)\n\t\t\t\t" . ($newRankID ? ", rankID = " . $newRankID : "") . "\n\t\t\tWHERE\tuserID = " . $user->userID;
     WCF::getDB()->sendQuery($sql);
     // update user session
     Session::resetSessions($user->userID, true, false);
     return true;
 }
 /**
  * Checks the permissions of the given user to edit applications.
  * 
  * @return	boolean 
  */
 public static function isGroupLeader(User $user, $groupID)
 {
     $sql = "SELECT\tCOUNT(*) AS count\n\t\t\tFROM\twcf" . WCF_N . "_group_leader\n\t\t\tWHERE\tgroupID = " . $groupID . "\n\t\t\t\tAND (\n\t\t\t\t\tleaderUserID = " . $user->userID . "\n\t\t\t\t\tOR leaderGroupID IN (" . implode(',', $user->getGroupIDs()) . ")\n\t\t\t\t)";
     $row = WCF::getDB()->getFirstRow($sql);
     return intval($row['count'] != 0);
 }
 /**
  * Checks whether the given user can receive newsletters or not.
  *
  * @param 	User $user
  * @return 	True, if the user can receive newsletters, false if not.
  */
 public static function canReceiveNewsletters(User $user)
 {
     $nonReceivingGroups = explode(',', MESSAGE_NEWSLETTERSYSTEM_GENERAL_NONRECEIVING_GROUPS);
     $groupIDs = $user->getGroupIDs();
     foreach ($groupIDs as $groupID) {
         if (in_array($groupID, $nonReceivingGroups)) {
             return false;
         }
     }
     return true;
 }