public function execute(INotification $note)
 {
     $userProxy = new UserProxy();
     $roleProxy = new RoleProxy();
     $userProxy->addItem(new UserVO("lstooge", "Larry", "Stooge", "*****@*****.**", "ijk456", DeptEnum::ACCT));
     $userProxy->addItem(new UserVO("cstooge", "Curly", "Stooge", "*****@*****.**", "xyz987", DeptEnum::SALES));
     $userProxy->addItem(new UserVO("mstooge", "Moe", "Stooge", "*****@*****.**", "abc123", DeptEnum::PLANT));
     $roleProxy->addItem(new RoleVO("lstooge", array(RoleEnum::PAYROLL, RoleEnum::EMP_BENEFITS)));
     $roleProxy->addItem(new RoleVO("cstooge", array(RoleEnum::ACCT_PAY, RoleEnum::ACCT_RCV, RoleEnum::GEN_LEDGER)));
     $roleProxy->addItem(new RoleVO("mstooge", array(RoleEnum::INVENTORY, RoleEnum::PRODUCTION, RoleEnum::SALES, RoleEnum::SHIPPING)));
     $this->facade->registerProxy($userProxy);
     $this->facade->registerProxy($roleProxy);
 }
示例#2
0
 public static function getInstance($aAllowAutoLogin = false)
 {
     if (self::$Instance == NULL) {
         self::$Instance = new UserProxy($aAllowAutoLogin);
     }
     return self::$Instance;
 }
function msgQueryLocalCredentialsById($aRequest)
{
    $Credentials = UserProxy::getInstance()->getUserCredentialsById($aRequest['UserId'], 'none');
    $Out = Out::getInstance();
    if ($Credentials == null) {
        $Out->pushError(L('NoSuchUser'));
    } else {
        $Out->pushValue('salt', $Credentials['salt']);
        $Out->pushValue('pubkey', $Credentials['key']);
        $Out->pushValue('method', $Credentials['method']);
    }
}
function msgUserCreate($aRequest)
{
    require_once dirname(__FILE__) . '/../config/config.php';
    $Out = Out::getInstance();
    if (ALLOW_REGISTRATION) {
        $Salt = UserProxy::generateKey32();
        $NativeBinding = new NativeBinding();
        $HashedPassword = $NativeBinding->hash($aRequest['pass'], $Salt, 'none');
        $PublicMode = defined('PUBLIC_MODE') && PUBLIC_MODE;
        $DefaultGroup = $PublicMode ? 'member' : 'none';
        $Out->pushValue('publicmode', $PublicMode);
        if (!UserProxy::createUser($DefaultGroup, 0, 'none', $aRequest['name'], $HashedPassword, $Salt)) {
            $Out->pushError(L('NameInUse'));
        }
    } else {
        $Out->pushError(L('AccessDenied'));
    }
}
示例#5
0
function msgQueryUser($aRequest)
{
    $Out = Out::getInstance();
    if (registeredUser()) {
        $CurrentUser = UserProxy::getInstance();
        $CharacterIds = array();
        $CharacterGames = array();
        $CharacterNames = array();
        $CharacterClasses = array();
        $CharacterRoles1 = array();
        $CharacterRoles2 = array();
        $Settings = array();
        foreach ($CurrentUser->Characters as $Character) {
            array_push($CharacterIds, $Character->CharacterId);
            array_push($CharacterGames, $Character->Game);
            array_push($CharacterNames, $Character->Name);
            array_push($CharacterClasses, explode(':', $Character->ClassName));
            array_push($CharacterRoles1, $Character->Role1);
            array_push($CharacterRoles2, $Character->Role2);
        }
        $Out->pushValue('registeredUser', true);
        $Out->pushValue('id', $CurrentUser->UserId);
        $Out->pushValue('name', $CurrentUser->UserName);
        $Out->pushValue('characterIds', $CharacterIds);
        $Out->pushValue('characterGames', $CharacterGames);
        $Out->pushValue('characterNames', $CharacterNames);
        $Out->pushValue('characterClass', $CharacterClasses);
        $Out->pushValue('role1', $CharacterRoles1);
        $Out->pushValue('role2', $CharacterRoles2);
        $Out->pushValue('validUser', validUser());
        $Out->pushValue('isRaidlead', validRaidlead());
        $Out->pushValue('isAdmin', validAdmin());
        $Out->pushValue('settings', $CurrentUser->Settings);
        $Session = Session::get();
        if (isset($Session['Calendar'])) {
            $Out->pushValue('calendar', $Session['Calendar']);
        } else {
            $Out->pushValue('calendar', null);
        }
    } else {
        $Out->pushValue('registeredUser', false);
    }
}
function msgCommentupdate($aRequest)
{
    if (validUser()) {
        $Connector = Connector::getInstance();
        $RaidId = intval($aRequest['raidId']);
        $UserId = UserProxy::getInstance()->UserId;
        $CheckQuery = $Connector->prepare('SELECT UserId FROM `' . RP_TABLE_PREFIX . 'Attendance` WHERE UserId = :UserId AND RaidId = :RaidId LIMIT 1');
        $CheckQuery->bindValue(':UserId', $UserId, PDO::PARAM_INT);
        $CheckQuery->bindValue(':RaidId', $RaidId, PDO::PARAM_INT);
        if ($CheckQuery->execute()) {
            $UpdateQuery = null;
            if ($CheckQuery->getAffectedRows() > 0) {
                $UpdateQuery = $Connector->prepare('UPDATE `' . RP_TABLE_PREFIX . 'Attendance` ' . 'SET comment = :Comment, LastUpdate = FROM_UNIXTIME(:Timestamp) ' . 'WHERE RaidId = :RaidId AND UserId = :UserId LIMIT 1');
                $UpdateQuery->bindValue(':Timestamp', time(), PDO::PARAM_INT);
            } else {
                $UpdateQuery = $Connector->prepare('INSERT INTO `' . RP_TABLE_PREFIX . 'Attendance` ( CharacterId, UserId, RaidId, Status, Role, Comment ) ' . 'VALUES ( :CharacterId, :UserId, :RaidId, :Status, :Role, :Comment )');
                $UpdateQuery->bindValue(':CharacterId', 0, PDO::PARAM_INT);
                $UpdateQuery->bindValue(':Role', '', PDO::PARAM_STR);
                $UpdateQuery->bindValue(':Status', 'undecided', PDO::PARAM_STR);
            }
            $UpdateQuery->bindValue(':RaidId', $RaidId, PDO::PARAM_INT);
            $UpdateQuery->bindValue(':UserId', $UserId, PDO::PARAM_INT);
            $UpdateQuery->bindValue(':Comment', requestToXML($aRequest['comment'], ENT_COMPAT, 'UTF-8'), PDO::PARAM_STR);
            $UpdateQuery->execute();
        }
        // reload calendar
        $RaidQuery = $Connector->prepare('SELECT Start FROM `' . RP_TABLE_PREFIX . 'Raid` WHERE RaidId = :RaidId LIMIT 1');
        $RaidQuery->bindValue(':RaidId', $RaidId, PDO::PARAM_INT);
        $RaidData = $RaidQuery->fetchFirst();
        $Session = Session::get();
        $ShowMonth = isset($Session['Calendar']) && isset($Session['Calendar']['month']) ? $Session['Calendar']['month'] : intval(substr($RaidData['Start'], 5, 2));
        $ShowYear = isset($Session['Calendar']) && isset($Session['Calendar']['year']) ? $Session['Calendar']['year'] : intval(substr($RaidData['Start'], 0, 4));
        msgQueryCalendar(prepareCalRequest($ShowMonth, $ShowYear));
    } else {
        $Out = Out::getInstance();
        $Out->pushError(L('AccessDenied'));
    }
}
示例#7
0
include_once "private/message_query_settings.php";
include_once "private/message_query_credentials.php";
include_once "private/message_query_config.php";
include_once "private/message_query_user.php";
include_once "private/message_profile_update.php";
include_once "private/message_comment_update.php";
include_once "private/message_settings_update.php";
include_once "private/message_user_create.php";
include_once "private/message_user_link.php";
// Init user if required
switch (strtolower($_REQUEST["Action"])) {
    case "try_auto_login":
        UserProxy::getInstance(true);
        break;
    default:
        UserProxy::getInstance();
        break;
}
// Process message
$Out = Out::getInstance();
if (isset($_REQUEST["Action"])) {
    switch (strtolower($_REQUEST["Action"])) {
        case "try_auto_login":
            break;
        case "query_locale":
            msgQueryLocale($_REQUEST);
            break;
        case "query_user":
            msgQueryUser($_REQUEST);
            break;
        case "query_config":
示例#8
0
 /**
  * @dataProvider setExtendedLoginCookieDataProvider
  * @covers User::getRequest
  * @covers User::setCookie
  * @backupGlobals enabled
  */
 public function testSetExtendedLoginCookie($extendedLoginCookieExpiration, $cookieExpiration, $expectedExpiry)
 {
     $this->setMwGlobals(array('wgExtendedLoginCookieExpiration' => $extendedLoginCookieExpiration, 'wgCookieExpiration' => $cookieExpiration));
     $response = $this->getMock('WebResponse');
     $setcookieSpy = $this->any();
     $response->expects($setcookieSpy)->method('setcookie');
     $request = new MockWebRequest($response);
     $user = new UserProxy(User::newFromSession($request));
     $user->setExtendedLoginCookie('name', 'value', true);
     $setcookieInvocations = $setcookieSpy->getInvocations();
     $setcookieInvocation = end($setcookieInvocations);
     $actualExpiry = $setcookieInvocation->parameters[2];
     // TODO: ± 300 seconds compensates for
     // slow-running tests. However, the dependency on the time
     // function should be removed.  This requires some way
     // to mock/isolate User->setExtendedLoginCookie's call to time()
     $this->assertEquals($expectedExpiry, $actualExpiry, '', 300);
 }
function msgQueryProfile($aRequest)
{
    if (validUser()) {
        global $gGame;
        loadGameSettings();
        $Out = Out::getInstance();
        $UserId = UserProxy::getInstance()->UserId;
        if (validAdmin() && isset($aRequest['userId']) && $aRequest['userId'] != 0) {
            $UserId = intval($aRequest['userId']);
        }
        $Connector = Connector::getInstance();
        $Out->pushValue('show', $aRequest['showPanel']);
        // Admintool relevant data
        $Users = $Connector->prepare('SELECT Login, UNIX_TIMESTAMP(Created) AS CreatedUTC, ExternalBinding, BindingActive FROM `' . RP_TABLE_PREFIX . 'User` WHERE UserId = :UserId LIMIT 1');
        $Users->bindValue(':UserId', $UserId, PDO::PARAM_INT);
        $Data = $Users->fetchFirst();
        if ($Data != null) {
            $Out->pushValue('userid', $UserId);
            $Out->pushValue('name', $Data['Login']);
            $Out->pushValue('bindingActive', $Data['BindingActive'] == 'true');
            $Out->pushValue('binding', $Data['ExternalBinding']);
            $CreatedUTC = $Data['CreatedUTC'];
        }
        // Load settings
        $SettingsQuery = $Connector->prepare('SELECT * FROM `' . RP_TABLE_PREFIX . 'UserSetting` WHERE UserId = :UserId');
        $SettingsQuery->bindValue(':UserId', $UserId, PDO::PARAM_INT);
        $UserSettings = array();
        $SettingsQuery->loop(function ($Data) use(&$UserSettings) {
            $UserSettings[$Data['Name']] = array('number' => $Data['IntValue'], 'text' => $Data['TextValue']);
        });
        $Out->pushValue('settings', $UserSettings);
        // Load characters
        $Characters = array();
        if ($UserId == UserProxy::getInstance()->UserId) {
            foreach (UserProxy::getInstance()->Characters as $Data) {
                if ($Data->Game == $gGame['GameId']) {
                    $Character = array('id' => $Data->CharacterId, 'name' => $Data->Name, 'classname' => explode(':', $Data->ClassName), 'mainchar' => $Data->IsMainChar, 'role1' => $Data->Role1, 'role2' => $Data->Role2);
                    array_push($Characters, $Character);
                }
            }
        } else {
            $CharacterQuery = $Connector->prepare('SELECT * FROM `' . RP_TABLE_PREFIX . 'Character` ' . 'WHERE UserId = :UserId AND Game = :Game ' . 'ORDER BY Mainchar, Name');
            $CharacterQuery->bindValue(':UserId', $UserId, PDO::PARAM_INT);
            $CharacterQuery->bindValue(':Game', $gGame['GameId'], PDO::PARAM_STR);
            $CharacterQuery->loop(function ($Row) use(&$Characters) {
                $Character = array('id' => $Row['CharacterId'], 'name' => $Row['Name'], 'classname' => explode(':', $Row['Class']), 'mainchar' => $Row['Mainchar'] == 'true', 'role1' => $Row['Role1'], 'role2' => $Row['Role2']);
                array_push($Characters, $Character);
            });
        }
        $Out->pushValue('character', $Characters);
        // Total raid count
        $NumRaids = 0;
        $RaidsQuery = $Connector->prepare('SELECT COUNT(RaidId) AS `NumberOfRaids` FROM `' . RP_TABLE_PREFIX . 'Raid` ' . 'LEFT JOIN `' . RP_TABLE_PREFIX . 'Location` USING(LocationId) ' . 'WHERE Start > FROM_UNIXTIME(:Created) AND Start < FROM_UNIXTIME(:Now) AND Game = :Game');
        $RaidsQuery->bindValue(':Now', time(), PDO::PARAM_INT);
        $RaidsQuery->bindValue(':Created', $CreatedUTC, PDO::PARAM_STR);
        $RaidsQuery->bindValue(':Game', $gGame['GameId'], PDO::PARAM_STR);
        $Data = $RaidsQuery->fetchFirst();
        if ($Data != null) {
            $NumRaids = $Data['NumberOfRaids'];
        }
        // Load attendance
        $AttendanceQuery = $Connector->prepare('Select `Status`, `Role`, COUNT(RaidId) AS `Count` ' . 'FROM `' . RP_TABLE_PREFIX . 'Attendance` ' . 'LEFT JOIN `' . RP_TABLE_PREFIX . 'Raid` USING(RaidId) ' . 'LEFT JOIN `' . RP_TABLE_PREFIX . 'Location` USING(LocationId) ' . 'WHERE UserId = :UserId AND Start > FROM_UNIXTIME(:Created) AND Start < FROM_UNIXTIME(:Now) AND Game = :Game ' . 'GROUP BY `Status`, `Role` ORDER BY Status');
        $AttendanceQuery->bindValue(':UserId', $UserId, PDO::PARAM_INT);
        $AttendanceQuery->bindValue(':Created', $CreatedUTC, PDO::PARAM_INT);
        $AttendanceQuery->bindValue(':Now', time(), PDO::PARAM_INT);
        $AttendanceQuery->bindValue(':Game', $gGame['GameId'], PDO::PARAM_STR);
        $AttendanceData = array('raids' => $NumRaids, 'available' => 0, 'unavailable' => 0, 'ok' => 0, 'roles' => array());
        // Pull data
        $AttendanceQuery->loop(function ($Data) use(&$AttendanceData) {
            if ($Data['Status'] != 'undecided') {
                $AttendanceData[$Data['Status']] += $Data['Count'];
            }
            if ($Data['Status'] == 'ok') {
                $RoleId = $Data['Role'];
                if (isset($AttendanceData['roles'][$RoleId])) {
                    $AttendanceData['roles'][$RoleId] += $Data['Count'];
                } else {
                    $AttendanceData['roles'][$RoleId] = $Data['Count'];
                }
            }
        });
        $Out->pushValue('attendance', $AttendanceData);
    } else {
        $Out = Out::getInstance();
        $Out->pushError(L('AccessDenied'));
    }
}
function parseRaidQuery($aRequest, $aQueryResult, $aLimit)
{
    $Out = Out::getInstance();
    $RaidData = array();
    $RoleInfo = array();
    $NumAttends = array();
    $aQueryResult->loop(function ($Data) use(&$RaidData, &$RoleInfo, &$NumAttends) {
        array_push($RaidData, $Data);
        $RaidId = $Data['RaidId'];
        // Create used slot counts
        if (!isset($RoleInfo[$RaidId])) {
            $RoleInfo[$RaidId] = array();
        }
        if (!isset($NumAttends[$RaidId])) {
            $NumAttends[$RaidId] = 0;
        }
        // Count used slots
        if ($Data['Status'] == 'ok' || $Data['Status'] == 'available') {
            $Role = $Data['Role'];
            if (!isset($RoleInfo[$RaidId][$Role])) {
                $RoleInfo[$RaidId][$Role] = 0;
            }
            ++$NumAttends[$RaidId];
            ++$RoleInfo[$RaidId][$Role];
        }
    });
    $LastRaidId = -1;
    $RaidDataCount = count($RaidData);
    $NumRaids = 0;
    $Raids = array();
    for ($DataIdx = 0; $DataIdx < $RaidDataCount; ++$DataIdx) {
        $Data = $RaidData[$DataIdx];
        $RaidId = $Data['RaidId'];
        if ($LastRaidId != $RaidId) {
            // If no user assigned for this raid
            // or row belongs to this user
            // or it's the last entry
            // or the next entry is a different raid
            $IsCorrectUser = $Data['UserId'] == UserProxy::getInstance()->UserId;
            if ($IsCorrectUser || $Data['UserId'] == NULL || $DataIdx + 1 == $RaidDataCount || $RaidData[$DataIdx + 1]['RaidId'] != $RaidId) {
                $Status = 'notset';
                $AttendanceIndex = 0;
                $Role = '';
                $Class = '';
                $Comment = '';
                if ($IsCorrectUser) {
                    $Status = $Data['Status'];
                    $AttendanceIndex = $Status == 'unavailable' ? -1 : intval($Data['CharacterId']);
                    $Role = $Data['Role'];
                    $Class = $Data['Class'];
                    $Comment = $Data['Comment'];
                }
                $StartDate = getdate($Data['StartUTC']);
                $EndDate = getdate($Data['EndUTC']);
                $Raid = array('id' => $RaidId, 'location' => $Data['Name'], 'game' => $Data['Game'], 'stage' => $Data['Stage'], 'size' => $Data['Size'], 'startDate' => $StartDate['year'] . '-' . leadingZero10($StartDate['mon']) . '-' . leadingZero10($StartDate['mday']), 'start' => leadingZero10($StartDate['hours']) . ':' . leadingZero10($StartDate['minutes']), 'endDate' => $EndDate['year'] . '-' . leadingZero10($EndDate['mon']) . '-' . leadingZero10($EndDate['mday']), 'end' => leadingZero10($EndDate['hours']) . ':' . leadingZero10($EndDate['minutes']), 'image' => $Data['Image'], 'description' => $Data['Description'], 'status' => $Status, 'attendanceIndex' => $AttendanceIndex, 'comment' => $Comment, 'role' => $Role, 'classId' => $Class, 'slotMax' => array(), 'slotCount' => array(), 'attended' => $NumAttends[$RaidId], 'mode' => $Data['Mode']);
                $Roles = explode(':', $Data['SlotRoles']);
                $Count = explode(':', $Data['SlotCount']);
                for ($i = 0; $i < count($Roles); ++$i) {
                    $RoleId = $Roles[$i];
                    $Raid['slotMax'][$RoleId] = $Count[$i];
                    $Raid['slotCount'][$RoleId] = isset($RoleInfo[$RaidId][$RoleId]) ? $RoleInfo[$RaidId][$RoleId] : 0;
                }
                array_push($Raids, $Raid);
                $LastRaidId = $RaidId;
                ++$NumRaids;
                if ($aLimit > 0 && $NumRaids == $aLimit) {
                    break;
                }
            }
        }
    }
    $Out->pushValue('raid', $Raids);
}
function msgProfileupdate($aRequest)
{
    if (validUser()) {
        global $gGame;
        loadGameSettings();
        $UserId = UserProxy::getInstance()->UserId;
        if (validAdmin() && isset($aRequest['userId']) && $aRequest['userId'] != 0) {
            $UserId = intval($aRequest['userId']);
        }
        $Connector = Connector::getInstance();
        do {
            $Connector->beginTransaction();
            // Update password
            if (isset($aRequest['newPass']) && $aRequest['oldPass'] != '') {
                if (UserProxy::getInstance()->validateCredentials($aRequest['oldPass'])) {
                    // User authenticated with valid password
                    // change the password of the given id. ChangePassword does a check
                    // for validity (e.g. only admin may change other user's passwords)
                    $Salt = UserProxy::generateKey32();
                    $HashedPassword = NativeBinding::nativeHash($aRequest['newPass'], $Salt, 'none');
                    if (!UserProxy::changePassword($UserId, $HashedPassword, $Salt)) {
                        $Out = Out::getInstance();
                        $Out->pushError(L('PasswordLocked'));
                    }
                } else {
                    $Out = Out::getInstance();
                    $Out->pushError(L('WrongPassword'));
                }
            }
            // Update always log in
            if ($aRequest['autoAttend'] == 'true') {
                $ExistsRequest = $Connector->prepare('SELECT UserSettingId FROM `' . RP_TABLE_PREFIX . 'UserSetting` ' . 'WHERE UserId=:UserId and Name="AutoAttend" LIMIT 1');
                $ExistsRequest->bindValue(':UserId', $UserId, PDO::PARAM_INT);
                if ($ExistsRequest->fetchFirst() == null) {
                    $AttendRequest = $Connector->prepare('INSERT INTO `' . RP_TABLE_PREFIX . 'UserSetting` (UserId, Name) VALUES (:UserId, "AutoAttend")');
                    $AttendRequest->bindValue(':UserId', $UserId, PDO::PARAM_INT);
                    $AttendRequest->execute();
                }
            } else {
                $RemoveQuery = $Connector->prepare('DELETE FROM `' . RP_TABLE_PREFIX . 'UserSetting` WHERE ' . 'UserId = :UserId AND (Name = "AutoAttend") LIMIT 1');
                $RemoveQuery->bindValue(':UserId', $UserId, PDO::PARAM_INT);
                $RemoveQuery->execute();
            }
            // Update vacation settings
            $Ranges = getVacationData($aRequest);
            $VacationMessage = $aRequest['vacationMessage'] == null ? '' : requestToXML($aRequest['vacationMessage'], ENT_COMPAT, 'UTF-8');
            // Revoke ranges that have been removed
            foreach ($Ranges['revoke'] as $RevokeRange) {
                $RevokeQuery = $Connector->prepare('UPDATE `' . RP_TABLE_PREFIX . 'Raid` LEFT JOIN `' . RP_TABLE_PREFIX . 'Attendance` USING (RaidId) ' . 'SET `' . RP_TABLE_PREFIX . 'Attendance`.Status = "undecided", Comment = "" ' . 'WHERE Start >= FROM_UNIXTIME(:Start) AND Start <= FROM_UNIXTIME(:End) ' . 'AND `' . RP_TABLE_PREFIX . 'Attendance`.Status = "unavailable" AND `' . RP_TABLE_PREFIX . 'Attendance`.UserId = :UserId');
                $RevokeQuery->bindValue(':Start', max($RevokeRange[0], time()), PDO::PARAM_INT);
                $RevokeQuery->bindValue(':End', max($RevokeRange[1], time()), PDO::PARAM_INT);
                $RevokeQuery->bindValue(':UserId', $UserId, PDO::PARAM_INT);
                $RevokeQuery->execute();
            }
            // Update already affected ranges
            foreach ($Ranges['update'] as $UpdateRange) {
                $UpdateQuery = $Connector->prepare('UPDATE `' . RP_TABLE_PREFIX . 'Raid` LEFT JOIN `' . RP_TABLE_PREFIX . 'Attendance` USING(RaidId) ' . 'SET Comment = :Message ' . 'WHERE Start >= FROM_UNIXTIME(:Start) AND Start <= FROM_UNIXTIME(:End) ' . 'AND UserId = :UserId AND Status = "unavailable"');
                $UpdateQuery->bindValue(':Start', $UpdateRange[0], PDO::PARAM_INT);
                $UpdateQuery->bindValue(':End', $UpdateRange[1], PDO::PARAM_INT);
                $UpdateQuery->bindValue(':UserId', $UserId, PDO::PARAM_INT);
                $UpdateQuery->bindValue(':Message', $VacationMessage, PDO::PARAM_STR);
                $UpdateQuery->execute();
            }
            // Update/Insert new ranges
            foreach ($Ranges['new'] as $NewRange) {
                // Update all raids that already have an attendance record
                $UpdateQuery = $Connector->prepare('UPDATE `' . RP_TABLE_PREFIX . 'Raid` LEFT JOIN `' . RP_TABLE_PREFIX . 'Attendance` USING(RaidId) ' . 'SET Status = "unavailable", Comment = :Message ' . 'WHERE Start >= FROM_UNIXTIME(:Start) AND Start <= FROM_UNIXTIME(:End) ' . 'AND UserId = :UserId');
                $UpdateQuery->bindValue(':Start', $NewRange[0], PDO::PARAM_INT);
                $UpdateQuery->bindValue(':End', $NewRange[1], PDO::PARAM_INT);
                $UpdateQuery->bindValue(':UserId', intval($UserId), PDO::PARAM_INT);
                $UpdateQuery->bindValue(':Message', $VacationMessage, PDO::PARAM_STR);
                $UpdateQuery->execute();
                // Find all reaids the do not have an attendance record
                $AffectedQuery = $Connector->prepare('SELECT `' . RP_TABLE_PREFIX . 'Raid`.RaidId FROM `' . RP_TABLE_PREFIX . 'Raid` ' . 'LEFT JOIN `' . RP_TABLE_PREFIX . 'Attendance` ON (`' . RP_TABLE_PREFIX . 'Raid`.RaidId = `' . RP_TABLE_PREFIX . 'Attendance`.RaidId ' . 'AND (`' . RP_TABLE_PREFIX . 'Attendance`.UserId = :UserId OR `' . RP_TABLE_PREFIX . 'Attendance`.UserId IS NULL)) ' . 'WHERE Start >= FROM_UNIXTIME(:Start) AND Start <= FROM_UNIXTIME(:End) ' . 'AND UserId IS NULL ' . 'GROUP BY RaidId');
                $AffectedQuery->bindValue(':Start', $NewRange[0], PDO::PARAM_INT);
                $AffectedQuery->bindValue(':End', $NewRange[1], PDO::PARAM_INT);
                $AffectedQuery->bindValue(':UserId', intval($UserId), PDO::PARAM_INT);
                $AffectedQuery->loop(function ($aRaid) use(&$Connector, $UserId, $VacationMessage) {
                    // Set user to unavailable
                    $InsertQuery = $Connector->prepare('INSERT INTO `' . RP_TABLE_PREFIX . 'Attendance` ' . '(UserId, RaidId, Status, Comment) ' . 'VALUES (:UserId, :RaidId, "unavailable", :Message)');
                    $InsertQuery->bindValue(':UserId', intval($UserId), PDO::PARAM_INT);
                    $InsertQuery->bindValue(':RaidId', $aRaid['RaidId'], PDO::PARAM_INT);
                    $InsertQuery->bindValue(':Message', $VacationMessage, PDO::PARAM_STR);
                    $InsertQuery->execute();
                });
            }
            // Update user settings
            if (count($Ranges['new']) == 0 && count($Ranges['update']) == 0) {
                if (count($Ranges['revoke']) > 0) {
                    $RemoveQuery = $Connector->prepare('DELETE FROM `' . RP_TABLE_PREFIX . 'UserSetting` WHERE ' . 'UserId = :UserId AND (Name = "VacationStart" OR Name = "VacationEnd" OR Name = "VacationMessage") LIMIT 3');
                    $RemoveQuery->bindValue(':UserId', $UserId, PDO::PARAM_INT);
                    $RemoveQuery->execute();
                }
            } else {
                if ($Ranges['SettingsFound']) {
                    $UpdateQuery = $Connector->prepare('UPDATE `' . RP_TABLE_PREFIX . 'UserSetting` SET IntValue = :Start WHERE UserId = :UserId AND Name = "VacationStart" LIMIT 1;' . 'UPDATE `' . RP_TABLE_PREFIX . 'UserSetting` SET IntValue = :End WHERE UserId = :UserId AND Name = "VacationEnd" LIMIT 1;' . 'UPDATE `' . RP_TABLE_PREFIX . 'UserSetting` SET TextValue = :Message WHERE UserId = :UserId AND Name = "VacationMessage" LIMIT 1;');
                    $UpdateQuery->bindValue(':UserId', $UserId, PDO::PARAM_INT);
                    $UpdateQuery->bindValue(':Start', $aRequest['vacationStart'], PDO::PARAM_INT);
                    $UpdateQuery->bindValue(':End', $aRequest['vacationEnd'], PDO::PARAM_INT);
                    $UpdateQuery->bindValue(':Message', $VacationMessage, PDO::PARAM_STR);
                    $UpdateQuery->execute();
                } else {
                    $InsertQuery = $Connector->prepare('INSERT INTO `' . RP_TABLE_PREFIX . 'UserSetting` (IntValue, UserId, Name) VALUES (:Start, :UserId, "VacationStart");' . 'INSERT INTO `' . RP_TABLE_PREFIX . 'UserSetting` (IntValue, UserId, Name) VALUES (:End, :UserId, "VacationEnd");' . 'INSERT INTO `' . RP_TABLE_PREFIX . 'UserSetting` (TextValue, UserId, Name) VALUES (:Message, :UserId, "VacationMessage");');
                    $InsertQuery->bindValue(':UserId', $UserId, PDO::PARAM_INT);
                    $InsertQuery->bindValue(':Start', $aRequest['vacationStart'], PDO::PARAM_INT);
                    $InsertQuery->bindValue(':End', $aRequest['vacationEnd'], PDO::PARAM_INT);
                    $InsertQuery->bindValue(':Message', $VacationMessage, PDO::PARAM_STR);
                    $InsertQuery->execute();
                }
            }
            // Update characters
            $CharacterQuery = $Connector->prepare('SELECT * FROM `' . RP_TABLE_PREFIX . 'Character` WHERE UserId = :UserId AND Game = :Game ORDER BY Name');
            $CharacterQuery->bindValue(':UserId', $UserId, PDO::PARAM_INT);
            $CharacterQuery->bindValue(':Game', $gGame['GameId'], PDO::PARAM_STR);
            $ValidCharacterIds = array();
            $UpdatedCharacteIds = array();
            $CharacterQuery->loop(function ($Data) use(&$ValidCharacterIds) {
                array_push($ValidCharacterIds, $Data['CharacterId']);
            });
            $NumCharacters = isset($aRequest['charId']) && is_array($aRequest['charId']) ? count($aRequest['charId']) : 0;
            // Sanity check mainchar
            $FoundMainChar = false;
            for ($CharIndex = 0; $CharIndex < $NumCharacters; ++$CharIndex) {
                if ($aRequest['mainChar'][$CharIndex] == 'true') {
                    if ($FoundMainChar) {
                        $aRequest['mainChar'][$CharIndex] = 'false';
                    } else {
                        $FoundMainChar = true;
                    }
                }
            }
            if (!$FoundMainChar && $NumCharacters > 0) {
                $aRequest['mainChar'][0] = 'true';
            }
            // Update/insert chars
            for ($CharIndex = 0; $CharIndex < $NumCharacters; ++$CharIndex) {
                $CharId = $aRequest['charId'][$CharIndex];
                $ClassArray = $aRequest['charClass'][$CharIndex];
                $Classes = count($ClassArray) == 1 ? $ClassArray[0] : implode(':', $ClassArray);
                if ($CharId == 0) {
                    // Insert new character
                    $InsertChar = $Connector->prepare('INSERT INTO `' . RP_TABLE_PREFIX . 'Character` ' . '( UserId, Name, Game, Class, Mainchar, Role1, Role2 ) ' . 'VALUES ( :UserId, :Name, :Game, :Class, :Mainchar, :Role1, :Role2 )');
                    $InsertChar->bindValue(':UserId', $UserId, PDO::PARAM_INT);
                    $InsertChar->bindValue(':Name', requestToXML($aRequest['name'][$CharIndex], ENT_COMPAT, 'UTF-8'), PDO::PARAM_STR);
                    $InsertChar->bindValue(':Game', $gGame['GameId'], PDO::PARAM_STR);
                    $InsertChar->bindValue(':Class', $Classes, PDO::PARAM_STR);
                    $InsertChar->bindValue(':Mainchar', $aRequest['mainChar'][$CharIndex], PDO::PARAM_STR);
                    $InsertChar->bindValue(':Role1', $aRequest['role1'][$CharIndex], PDO::PARAM_STR);
                    $InsertChar->bindValue(':Role2', $aRequest['role2'][$CharIndex], PDO::PARAM_STR);
                    if (!$InsertChar->execute()) {
                        $Connector->rollBack();
                        return;
                    }
                } else {
                    if (in_array($CharId, $ValidCharacterIds)) {
                        // Update character
                        array_push($UpdatedCharacteIds, $CharId);
                        $UpdateChar = $Connector->prepare('UPDATE `' . RP_TABLE_PREFIX . 'Character` ' . 'SET Class = :Class, Mainchar = :Mainchar, Role1 = :Role1, Role2 = :Role2 ' . 'WHERE CharacterId = :CharacterId AND UserId = :UserId');
                        $UpdateChar->bindValue(':UserId', $UserId, PDO::PARAM_INT);
                        $UpdateChar->bindValue(':CharacterId', $CharId, PDO::PARAM_INT);
                        $UpdateChar->bindValue(':Class', $Classes, PDO::PARAM_STR);
                        $UpdateChar->bindValue(':Mainchar', $aRequest['mainChar'][$CharIndex], PDO::PARAM_STR);
                        $UpdateChar->bindValue(':Role1', $aRequest['role1'][$CharIndex], PDO::PARAM_STR);
                        $UpdateChar->bindValue(':Role2', $aRequest['role2'][$CharIndex], PDO::PARAM_STR);
                        if (!$UpdateChar->execute()) {
                            $Connector->rollBack();
                            return;
                        }
                    }
                }
            }
            $IdsToRemove = array_diff($ValidCharacterIds, $UpdatedCharacteIds);
            foreach ($IdsToRemove as $CharId) {
                // Remove character
                $DropChar = $Connector->prepare('DELETE FROM `' . RP_TABLE_PREFIX . 'Character` ' . 'WHERE CharacterId = :CharacterId AND UserId = :UserId');
                $DropAttendance = $Connector->prepare('DELETE FROM `' . RP_TABLE_PREFIX . 'Attendance` ' . 'WHERE CharacterId = :CharacterId AND UserId = :UserId');
                $DropChar->bindValue(':UserId', $UserId, PDO::PARAM_INT);
                $DropChar->bindValue(':CharacterId', $CharId, PDO::PARAM_INT);
                $DropAttendance->bindValue(':UserId', $UserId, PDO::PARAM_INT);
                $DropAttendance->bindValue(':CharacterId', $CharId, PDO::PARAM_INT);
                if (!$DropChar->execute()) {
                    $Connector->rollBack();
                    return;
                }
                if (!$DropAttendance->execute()) {
                    $Connector->rollBack();
                    return;
                }
            }
        } while (!$Connector->commit());
        UserProxy::getInstance()->updateCharacters();
        msgQueryProfile($aRequest);
    } else {
        $Out = Out::getInstance();
        $Out->pushError(L('AccessDenied'));
    }
}
示例#12
0
function msgRaidAttend($aRequest)
{
    if (validUser()) {
        global $gGame;
        loadGameSettings();
        $Connector = Connector::getInstance();
        $AttendanceId = intval($aRequest['attendanceId']);
        $AttendanceSubId = intval($aRequest['attendanceSubId']);
        $RaidId = intval($aRequest['raidId']);
        $UserId = intval(UserProxy::getInstance()->UserId);
        // check user/character match
        $ChangeAllowed = true;
        $RaidInfo = array();
        $Role = '';
        $Class = '';
        // Check if locked
        $LockCheckQuery = $Connector->prepare('SELECT Stage, Mode, SlotRoles, SlotCount FROM `' . RP_TABLE_PREFIX . 'Raid` WHERE RaidId = :RaidId LIMIT 1');
        $LockCheckQuery->bindValue(':RaidId', $RaidId, PDO::PARAM_INT);
        $RaidInfo = $LockCheckQuery->fetchFirst();
        if ($RaidInfo == null) {
            return;
        }
        // ### return, locked ###
        $ChangeAllowed = $RaidInfo['Stage'] == 'open';
        if ($ChangeAllowed) {
            // Check if character matches user
            if ($AttendanceId > 0) {
                $CheckQuery = $Connector->prepare('SELECT UserId, Class, Role1, Role2 FROM `' . RP_TABLE_PREFIX . 'Character` WHERE CharacterId = :CharacterId AND Game = :Game LIMIT 1');
                $CheckQuery->bindValue(':CharacterId', $AttendanceId, PDO::PARAM_INT);
                $CheckQuery->bindValue(':Game', $gGame['GameId'], PDO::PARAM_INT);
                $CharacterInfo = $CheckQuery->fetchFirst();
                if ($CharacterInfo != null) {
                    $ChangeAllowed &= $CharacterInfo['UserId'] == $UserId;
                    if ($gGame['ClassMode'] == 'multi') {
                        $Classes = explode(':', $CharacterInfo['Class']);
                        $Class = $AttendanceSubId < 0 ? $Classes[0] : $Classes[$AttendanceSubId];
                        $Role = $gGame['Classes'][$Class]['roles'][0];
                    } else {
                        $Class = $CharacterInfo['Class'];
                        $Role = $AttendanceSubId < 0 ? $CharacterInfo['Role1'] : ($AttendanceSubId == 0 ? $CharacterInfo['Role1'] : $CharacterInfo['Role2']);
                    }
                } else {
                    $ChangeAllowed = false;
                }
            }
            // update/insert new attendance data
            if ($ChangeAllowed) {
                $CheckQuery = $Connector->prepare('SELECT UserId FROM `' . RP_TABLE_PREFIX . 'Attendance` WHERE UserId = :UserId AND RaidId = :RaidId LIMIT 1');
                $CheckQuery->bindValue(':UserId', $UserId, PDO::PARAM_INT);
                $CheckQuery->bindValue(':RaidId', $RaidId, PDO::PARAM_INT);
                $CheckQuery->execute();
                $AttendQuery = null;
                $ChangeComment = isset($aRequest['comment']) && $aRequest['comment'] != '';
                if ($CheckQuery->getAffectedRows() > 0) {
                    if ($ChangeComment) {
                        $AttendQuery = $Connector->prepare('UPDATE `' . RP_TABLE_PREFIX . 'Attendance` SET ' . 'CharacterId = :CharacterId, Status = :Status, Class = :Class, Role = :Role, Comment = :Comment, LastUpdate = FROM_UNIXTIME(:Timestamp) ' . 'WHERE RaidId = :RaidId AND UserId = :UserId LIMIT 1');
                    } else {
                        $AttendQuery = $Connector->prepare('UPDATE `' . RP_TABLE_PREFIX . 'Attendance` SET ' . 'CharacterId = :CharacterId, Status = :Status, Class = :Class, Role = :Role, LastUpdate = FROM_UNIXTIME(:Timestamp) ' . 'WHERE RaidId = :RaidId AND UserId = :UserId LIMIT 1');
                    }
                } else {
                    if ($ChangeComment) {
                        $AttendQuery = $Connector->prepare('INSERT INTO `' . RP_TABLE_PREFIX . 'Attendance` ( CharacterId, UserId, RaidId, Status, Class, Role, Comment, LastUpdate ) ' . 'VALUES ( :CharacterId, :UserId, :RaidId, :Status, :Class, :Role, :Comment, FROM_UNIXTIME(:Timestamp) )');
                    } else {
                        $AttendQuery = $Connector->prepare('INSERT INTO `' . RP_TABLE_PREFIX . 'Attendance` ( CharacterId, UserId, RaidId, Status, Class, Role, Comment, LastUpdate) ' . 'VALUES ( :CharacterId, :UserId, :RaidId, :Status, :Class, :Role, "", FROM_UNIXTIME(:Timestamp) )');
                    }
                }
                // Define the status and id to set
                if ($AttendanceId == -1) {
                    $Status = 'unavailable';
                    $CharacterId = intval($aRequest['fallback']);
                } else {
                    $CharacterId = $AttendanceId;
                    switch ($RaidInfo['Mode']) {
                        case 'all':
                        case 'attend':
                            $Status = 'ok';
                            break;
                        default:
                        case 'manual':
                        case 'overbook':
                            $Status = 'available';
                            break;
                    }
                }
                // Add comment when setting absent status
                if ($ChangeComment) {
                    $Comment = requestToXML($aRequest['comment'], ENT_COMPAT, 'UTF-8');
                    $AttendQuery->bindValue(':Comment', $Comment, PDO::PARAM_STR);
                }
                $AttendQuery->bindValue(':CharacterId', $CharacterId, PDO::PARAM_INT);
                $AttendQuery->bindValue(':RaidId', intval($RaidId), PDO::PARAM_INT);
                $AttendQuery->bindValue(':UserId', intval($UserId), PDO::PARAM_INT);
                $AttendQuery->bindValue(':Status', $Status, PDO::PARAM_STR);
                $AttendQuery->bindValue(':Role', $Role, PDO::PARAM_STR);
                $AttendQuery->bindValue(':Class', $Class, PDO::PARAM_STR);
                $AttendQuery->bindValue(':Timestamp', time(), PDO::PARAM_INT);
                if ($AttendQuery->execute() && $Role != '' && $RaidInfo['Mode'] == 'attend' && $Status == 'ok') {
                    removeOverbooked($RaidId, $RaidInfo['SlotRoles'], $RaidInfo['SlotCount']);
                }
            } else {
                $Out = Out::getInstance();
                $Out->pushError(L('AccessDenied'));
            }
        } else {
            $Out = Out::getInstance();
            $Out->pushError(L('RaidLocked'));
        }
        // reload calendar
        $RaidQuery = $Connector->prepare('SELECT Start FROM `' . RP_TABLE_PREFIX . 'Raid` WHERE RaidId = :RaidId LIMIT 1');
        $RaidQuery->bindValue(':RaidId', $RaidId, PDO::PARAM_INT);
        $RaidData = $RaidQuery->fetchFirst();
        $Session = Session::get();
        $ShowMonth = isset($Session['Calendar']) && isset($Session['Calendar']['month']) ? $Session['Calendar']['month'] : intval(substr($RaidData['Start'], 5, 2));
        $ShowYear = isset($Session['Calendar']) && isset($Session['Calendar']['year']) ? $Session['Calendar']['year'] : intval(substr($RaidData['Start'], 0, 4));
        msgQueryCalendar(prepareCalRequest($ShowMonth, $ShowYear));
    } else {
        $Out = Out::getInstance();
        $Out->pushError(L('AccessDenied'));
    }
}
示例#13
0
function tryGetUserLink($UserId)
{
    $Connector = Connector::getInstance();
    $UserProxy = UserProxy::getInstance();
    $UserQuery = $Connector->prepare('Select * FROM `' . RP_TABLE_PREFIX . 'User` WHERE UserId=:UserId LIMIT 1');
    $UserQuery->bindValue(':UserId', $UserId, PDO::PARAM_INT);
    $UserData = $UserQuery->fetchFirst();
    if ($UserData == null) {
        return null;
    }
    // ### return, failed ###
    // Try to find a fitting binding
    // External binding is still set.
    // Finding the user is trivial
    if ($UserData['ExternalBinding'] != 'none') {
        return $UserProxy->getUserInfoById($UserData['ExternalBinding'], $UserData['ExternalId']);
        // ### return, success ###
    }
    // External id is still set.
    // Finding the user is trivial if there is only one binding
    if ($UserData['ExternalId'] != 0) {
        $Candidates = UserProxy::getAllUserInfosById($UserData['ExternalId']);
        if (count($Candidates) > 1) {
            // More than one binding, check the username and
            // reduce the array to username matches
            $Filtered = array();
            foreach ($Candidates as $BindingName => $UserInfo) {
                if ($UserInfo->UserName == $UserData['Login']) {
                    $Filtered[$BindingName] = $UserInfo;
                }
            }
            // If filtering was successfull, switch arrays
            if (count($Filtered) > 0) {
                $Candidates = $Filtered;
            }
        }
        // Use the first match. Having multiple matches is very unlikely as two (or more)
        // forums need to have a user with the same username AND id.
        if (count($Candidates) > 0) {
            reset($Candidates);
            list($BindingName, $UserInfo) = each($Candidates);
            // fetch the first entry
            return $UserInfo;
            // ### return, success ###
        }
    }
    // All checks failed
    // Search for user by name
    $Candidates = $UserProxy->getAllUserInfosByName($UserData['Login']);
    // Use the first match.
    // This may lead to the wrong user, but searching by name is basically wild guessing anyway.
    // Note that there is always at least one candidate with the binding 'none'.
    if (count($Candidates) > 1) {
        reset($Candidates);
        list($BindingName, $UserInfo) = each($Candidates);
        // first entry is 'none'
        list($BindingName, $UserInfo) = each($Candidates);
        // this is the first external binding
        return $UserInfo;
        // ### return, success ###
    }
    return null;
}