Ejemplo n.º 1
0
function msgQueryLocations($aRequest)
{
    global $gSite;
    global $gGame;
    loadGameSettings();
    $Out = Out::getInstance();
    if (validRaidlead()) {
        $Connector = Connector::getInstance();
        // Locations
        $ListLocations = $Connector->prepare('Select * FROM `' . RP_TABLE_PREFIX . 'Location` WHERE Game = :Game ORDER BY Name');
        $ListLocations->bindValue(':Game', $gGame['GameId'], PDO::PARAM_STR);
        $Locations = array();
        $ListLocations->loop(function ($Data) use(&$Locations) {
            $LocationData = array('id' => $Data['LocationId'], 'name' => $Data['Name'], 'image' => $Data['Image']);
            array_push($Locations, $LocationData);
        });
        $Out->pushValue('location', $Locations);
        // Images
        $Images = @scandir('../themes/icons/' . $gSite['Iconset'] . '/raidsmall');
        $ImageList = array();
        if ($Images != null) {
            foreach ($Images as $Image) {
                if (strripos($Image, '.png') !== false) {
                    array_push($ImageList, $Image);
                }
            }
        }
        $Out->pushValue('locationimage', $ImageList);
    } else {
        $Out->pushError(L('AccessDenied'));
    }
}
Ejemplo n.º 2
0
function msgQueryLocale($aRequest)
{
    global $gLocale;
    global $gGame;
    loadGameSettings();
    $EncodedLocale = array();
    $LocaleName = getLocaleName();
    $Flags = PHP_VERSION_ID >= 50400 ? ENT_COMPAT | ENT_XHTML : ENT_COMPAT;
    $Flags = PHP_VERSION_ID >= 50300 ? $Flags | ENT_IGNORE : $Flags;
    // Hardcoded strings
    foreach ($gLocale as $Key => $Value) {
        if ($Value != null) {
            $Encoded = getUTF8($Value);
            //htmlentities(getUTF8($Value), $Flags, 'UTF-8');
            $EncodedLocale[$Key] = $Encoded;
        }
    }
    // Game based strings
    if (isset($gGame['Locales'][$LocaleName])) {
        foreach ($gGame['Locales'][$LocaleName] as $Key => $Value) {
            if ($Value != null) {
                $Encoded = getUTF8($Value);
                //htmlentities(getUTF8($Value), $Flags, 'UTF-8');
                $EncodedLocale[$Key] = $Encoded;
            }
        }
    }
    Out::getInstance()->pushValue('locale', $EncodedLocale);
}
Ejemplo n.º 3
0
function msgQueryConfig($aRequest)
{
    global $gSite;
    global $gGame;
    $Out = Out::getInstance();
    loadGameSettings();
    $Config = array();
    $Config['AllowRegistration'] = defined('ALLOW_REGISTRATION') && ALLOW_REGISTRATION;
    // Push
    unset($gGame['Locales']);
    $Out->pushValue('site', array_merge($gSite, $Config));
    $Out->pushValue('game', $gGame);
}
Ejemplo n.º 4
0
function msgQueryCalendar($aRequest)
{
    if (validUser()) {
        global $gGame;
        loadGameSettings();
        $Out = Out::getInstance();
        $Connector = Connector::getInstance();
        $ListRaidQuery = $Connector->prepare('Select ' . RP_TABLE_PREFIX . 'Raid.*, ' . RP_TABLE_PREFIX . 'Location.*, ' . RP_TABLE_PREFIX . 'Attendance.CharacterId, ' . RP_TABLE_PREFIX . 'Attendance.UserId, ' . RP_TABLE_PREFIX . 'Attendance.Status, ' . RP_TABLE_PREFIX . 'Attendance.Class, ' . RP_TABLE_PREFIX . 'Attendance.Role, ' . RP_TABLE_PREFIX . 'Attendance.Comment, ' . 'UNIX_TIMESTAMP(' . RP_TABLE_PREFIX . 'Raid.Start) AS StartUTC, ' . 'UNIX_TIMESTAMP(' . RP_TABLE_PREFIX . 'Raid.End) AS EndUTC ' . 'FROM `' . RP_TABLE_PREFIX . 'Raid` ' . 'LEFT JOIN `' . RP_TABLE_PREFIX . 'Location` USING(LocationId) ' . 'LEFT JOIN `' . RP_TABLE_PREFIX . 'Attendance` USING (RaidId) ' . 'LEFT JOIN `' . RP_TABLE_PREFIX . 'Character` USING (CharacterId) ' . 'WHERE ' . RP_TABLE_PREFIX . 'Raid.Start >= FROM_UNIXTIME(:Start) AND ' . RP_TABLE_PREFIX . 'Raid.Start <= FROM_UNIXTIME(:End) ' . 'AND ' . RP_TABLE_PREFIX . 'Location.Game = :Game ' . 'ORDER BY ' . RP_TABLE_PREFIX . 'Raid.Start, ' . RP_TABLE_PREFIX . 'Raid.RaidId');
        // Calculate the correct start end end times
        $StartDay = getCalStartDay();
        $StartUTC = mktime(0, 0, 0, $aRequest['Month'], 1, $aRequest['Year']);
        $StartDate = getdate($StartUTC);
        if ($StartDate['wday'] != $StartDay) {
            // Calculate the first day displayed in the calendar
            $Offset = $StartDate['wday'] < $StartDay ? 7 - ($StartDay - $StartDate['wday']) : $StartDate['wday'] - $StartDay;
            $StartUTC -= 60 * 60 * 24 * $Offset;
            $StartDate = getdate($StartUTC);
        }
        // Calculate the last day displayed in the calendar
        $EndUTC = $StartUTC + 60 * 60 * 24 * 7 * 6;
        // + 6 weeks
        // Query and return
        $ListRaidQuery->bindValue(':Start', $StartUTC, PDO::PARAM_INT);
        $ListRaidQuery->bindValue(':End', intval($EndUTC), PDO::PARAM_INT);
        $ListRaidQuery->bindValue(':Game', $gGame['GameId'], PDO::PARAM_STR);
        $Session = Session::get();
        $Session['Calendar'] = array('month' => intval($aRequest['Month']), 'year' => intval($aRequest['Year']));
        $Out->pushValue('startDay', $StartDate['mday']);
        $Out->pushValue('startMonth', $StartDate['mon']);
        $Out->pushValue('startYear', $StartDate['year']);
        $Out->pushValue('startOfWeek', $StartDay);
        $Out->pushValue('displayMonth', $aRequest['Month']);
        $Out->pushValue('displayYear', $aRequest['Year']);
        parseRaidQuery($aRequest, $ListRaidQuery, 0);
    } else {
        $Out = Out::getInstance();
        $Out->pushError(L('AccessDenied'));
    }
}
Ejemplo n.º 5
0
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'));
    }
}
Ejemplo n.º 6
0
function msgQuerySettings($aRequest)
{
    if (validAdmin()) {
        global $gGame;
        loadGameSettings();
        $Out = Out::getInstance();
        $Connector = Connector::getInstance();
        // Pass through parameter
        $Out->pushValue('show', $aRequest['showPanel']);
        $Out->pushValue('syncActive', !defined('ALLOW_GROUP_SYNC') || ALLOW_GROUP_SYNC);
        // Load users
        $UserQuery = $Connector->prepare('SELECT * FROM `' . RP_TABLE_PREFIX . 'User` ORDER BY Login, `Group`');
        $Users = array();
        $UserQuery->loop(function ($Data) use(&$Users) {
            $UserData = array('id' => $Data['UserId'], 'login' => xmlentities($Data['Login'], ENT_COMPAT, 'UTF-8'), 'bindingActive' => $Data['BindingActive'], 'binding' => $Data['ExternalBinding'], 'group' => $Data['Group']);
            array_push($Users, $UserData);
        });
        $Out->pushValue('user', $Users);
        // Load settings
        $Settings = Settings::getInstance();
        $SettingsJS = array();
        Api::getPrivateToken();
        foreach ($Settings->getProperties() as $Name => $Data) {
            array_push($SettingsJS, array('name' => $Name, 'intValue' => isset($Data['IntValue']) ? $Data['IntValue'] : 0, 'textValue' => isset($Data['TextValue']) ? $Data['TextValue'] : ''));
        }
        $Out->pushValue('setting', $SettingsJS);
        // Load games
        $GameFiles = scandir('../themes/games');
        $Games = array();
        foreach ($GameFiles as $GameFileName) {
            try {
                if (substr($GameFileName, -4) === '.xml') {
                    $Game = @new SimpleXMLElement(file_get_contents('../themes/games/' . $GameFileName));
                    $SimpleGameFileName = substr($GameFileName, 0, strrpos($GameFileName, '.'));
                    if ($Game->name != '') {
                        $GameName = strval($Game->name);
                    } else {
                        $GameName = str_replace('_', ' ', $SimpleGameFileName);
                    }
                    $Groups = array();
                    foreach ($Game->groups->group as $Group) {
                        array_push($Groups, intval($Group['count']));
                    }
                    array_push($Games, array('name' => $GameName, 'family' => strval($Game->family), 'file' => $SimpleGameFileName, 'groups' => $Groups));
                }
            } catch (Exception $e) {
                $Out->pushError('Error parsing gameconfig ' . $GameFileName . ': ' . $e->getMessage());
            }
        }
        $Out->pushValue('game', $Games);
        // Load themes
        $ThemeFiles = scandir('../themes/themes');
        $Themes = array();
        foreach ($ThemeFiles as $ThemeFileName) {
            try {
                if (substr($ThemeFileName, -4) === '.xml') {
                    $Theme = @new SimpleXMLElement(file_get_contents('../themes/themes/' . $ThemeFileName));
                    $SimpleThemeFileName = substr($ThemeFileName, 0, strrpos($ThemeFileName, '.'));
                    $Family = isset($Theme->family) ? explode(',', strtolower($Theme->family)) : 'wow';
                    if ($Theme->name != '') {
                        $ThemeName = strval($Theme->name);
                    } else {
                        $ThemeName = str_replace('_', ' ', $SimpleThemeFileName);
                    }
                    array_push($Themes, array('name' => $ThemeName, 'family' => $Family, 'file' => $SimpleThemeFileName));
                }
            } catch (Exception $e) {
                $Out->pushError('Error parsing themefile ' . $ThemeFileName . ': ' . $e->getMessage());
            }
        }
        $Out->pushValue('theme', $Themes);
        // Query attendance
        $AttendanceString = 'SELECT ' . '`' . RP_TABLE_PREFIX . 'User`.UserId, ' . '`' . RP_TABLE_PREFIX . 'Character`.Name, ' . '`' . RP_TABLE_PREFIX . 'Attendance`.`Status`, ' . 'UNIX_TIMESTAMP(`' . RP_TABLE_PREFIX . 'User`.Created) AS CreatedUTC, ' . 'COUNT(`' . RP_TABLE_PREFIX . 'Raid`.RaidId) AS Count ' . 'FROM `' . RP_TABLE_PREFIX . 'User` ' . 'LEFT JOIN `' . RP_TABLE_PREFIX . 'Attendance` USING(UserId) ' . 'LEFT JOIN `' . RP_TABLE_PREFIX . 'Raid` USING(RaidId) ' . 'LEFT JOIN `' . RP_TABLE_PREFIX . 'Location` USING(LocationId) ' . 'LEFT JOIN `' . RP_TABLE_PREFIX . 'Character` ON `' . RP_TABLE_PREFIX . 'User`.UserId = `' . RP_TABLE_PREFIX . 'Character`.UserId ' . 'WHERE `' . RP_TABLE_PREFIX . 'Character`.Mainchar = "true" ' . 'AND `' . RP_TABLE_PREFIX . 'Raid`.Start > `' . RP_TABLE_PREFIX . 'User`.Created ' . 'AND `' . RP_TABLE_PREFIX . 'Raid`.Start < FROM_UNIXTIME(:Now) ' . 'AND `' . RP_TABLE_PREFIX . 'Location`.Game = :Game ' . 'AND `' . RP_TABLE_PREFIX . 'Character`.Game = :Game ' . 'GROUP BY `' . RP_TABLE_PREFIX . 'User`.UserId, `Status`';
        $Attendance = $Connector->prepare($AttendanceString);
        $Attendance->bindValue(':Now', time(), PDO::PARAM_INT);
        $Attendance->bindValue(':Game', $gGame['GameId'], PDO::PARAM_STR);
        $UserId = 0;
        $NumRaidsRemain = 0;
        $MainCharName = '';
        $StateCounts = array('undecided' => 0, 'available' => 0, 'unavailable' => 0, 'ok' => 0);
        $Attendances = array();
        $Attendance->loop(function ($Data) use(&$gGame, &$Connector, &$UserId, &$NumRaidsRemain, &$MainCharName, &$StateCounts, &$Attendances) {
            if ($UserId != $Data['UserId']) {
                if ($UserId > 0) {
                    $AttendanceData = array('id' => $UserId, 'name' => $MainCharName, 'ok' => $StateCounts['ok'], 'available' => $StateCounts['available'], 'unavailable' => $StateCounts['unavailable'], 'undecided' => $StateCounts['undecided'] + $NumRaidsRemain);
                    array_push($Attendances, $AttendanceData);
                }
                // Clear cache
                $StateCounts['ok'] = 0;
                $StateCounts['available'] = 0;
                $StateCounts['unavailable'] = 0;
                $StateCounts['undecided'] = 0;
                $NumRaidsRemain = 0;
                $UserId = $Data['UserId'];
                $MainCharName = $Data['Name'];
                // Fetch number of attendable raids
                $Raids = $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');
                $Raids->bindValue(':Now', time(), PDO::PARAM_INT);
                $Raids->bindValue(':Created', $Data['CreatedUTC'], PDO::PARAM_INT);
                $Raids->bindValue(':Game', $gGame['GameId'], PDO::PARAM_STR);
                $RaidCountData = $Raids->fetchFirst();
                $NumRaidsRemain = $RaidCountData == null ? 0 : $RaidCountData['NumberOfRaids'];
            }
            $StateCounts[$Data['Status']] += $Data['Count'];
            $NumRaidsRemain -= $Data['Count'];
        });
        // Push last user
        if ($UserId != 0) {
            $AttendanceData = array('id' => $UserId, 'name' => $MainCharName, 'ok' => $StateCounts['ok'], 'available' => $StateCounts['available'], 'unavailable' => $StateCounts['unavailable'], 'undecided' => $StateCounts['undecided'] + $NumRaidsRemain);
            array_push($Attendances, $AttendanceData);
        }
        $Out->pushValue('attendance', $Attendances);
        // Locations
        msgQueryLocations($aRequest);
    } else {
        $Out = Out::getInstance();
        $Out->pushError(L('AccessDenied'));
    }
}
Ejemplo n.º 7
0
function msgRaidCreate($aRequest)
{
    if (validRaidlead()) {
        global $gGame;
        loadGameSettings();
        $Connector = Connector::getInstance();
        $LocationId = $aRequest['locationId'];
        // Create location
        if ($LocationId == 0) {
            $NewLocationQuery = $Connector->prepare('INSERT INTO `' . RP_TABLE_PREFIX . 'Location`' . '(Game, Name, Image) VALUES (:Game, :Name, :Image)');
            $NewLocationQuery->bindValue(':Name', requestToXML($aRequest['locationName'], ENT_COMPAT, 'UTF-8'), PDO::PARAM_STR);
            $NewLocationQuery->bindValue(':Image', $aRequest['raidImage'], PDO::PARAM_STR);
            $NewLocationQuery->bindValue(':Game', $gGame['GameId'], PDO::PARAM_STR);
            if (!$NewLocationQuery->execute()) {
                return;
            }
            // ### return, location could not be created ###
            $LocationId = $Connector->lastInsertId();
        }
        // Create raid
        if ($LocationId != 0) {
            // First raid time calculation
            $StartHour = intval($aRequest['startHour']);
            $StartMinute = intval($aRequest['startMinute']);
            $StartDay = intval($aRequest['startDay']);
            $StartMonth = intval($aRequest['startMonth']);
            $StartYear = intval($aRequest['startYear']);
            $EndHour = intval($aRequest['endHour']);
            $EndMinute = intval($aRequest['endMinute']);
            $EndDay = intval($aRequest['endDay']);
            $EndMonth = intval($aRequest['endMonth']);
            $EndYear = intval($aRequest['endYear']);
            // Get users on vacation
            $UserSettingsQuery = $Connector->prepare('SELECT UserId, Name, IntValue, TextValue FROM `' . RP_TABLE_PREFIX . 'UserSetting` ' . 'WHERE Name = "VacationStart" OR Name = "VacationEnd" OR Name = "VacationMessage" ORDER BY UserId');
            $VactionUsers = array();
            $UserSettingsQuery->loop(function ($Settings) use(&$VactionUsers) {
                if (!isset($VactionUsers[$Settings['UserId']])) {
                    $VactionUsers[$Settings['UserId']] = array('Message' => '');
                }
                switch ($Settings['Name']) {
                    case 'VacationStart':
                        $VactionUsers[$Settings['UserId']]['Start'] = $Settings['IntValue'];
                        break;
                    case 'VacationEnd':
                        $VactionUsers[$Settings['UserId']]['End'] = $Settings['IntValue'];
                        break;
                    case 'VacationMessage':
                        $VactionUsers[$Settings['UserId']]['Message'] = $Settings['TextValue'];
                        break;
                    default:
                        break;
                }
            });
            // Prepare posting raids to forum
            $PostTargets = array();
            PluginRegistry::ForEachBinding(function ($PluginInstance) use(&$PostTargets) {
                if ($PluginInstance->isActive() && $PluginInstance->postRequested()) {
                    array_push($PostTargets, $PluginInstance);
                }
            });
            $LocationData = null;
            if (count($PostTargets) > 0) {
                loadSiteSettings();
                $LocationQuery = $Connector->prepare('SELECT * FROM `' . RP_TABLE_PREFIX . 'Location` WHERE LocationId = :LocationId LIMIT 1');
                $LocationQuery->bindValue(':LocationId', $LocationId, PDO::PARAM_INT);
                $LocationData = $LocationQuery->fetchFirst();
            }
            // Get opt-out list or auto attend users
            $AutoAttendUsers = array();
            if (strtolower($aRequest['mode'] == 'optout')) {
                $UserQuery = $Connector->prepare('SELECT UserId, CharacterId, Class, Role1 FROM `' . RP_TABLE_PREFIX . 'User` ' . 'LEFT JOIN `' . RP_TABLE_PREFIX . 'Character` USING(UserId) ' . 'WHERE Mainchar="true" AND Game=:Game');
                $UserQuery->bindValue(':Game', $gGame['GameId'], PDO::PARAM_STR);
                $UserQuery->loop(function ($aUser) use(&$AutoAttendUsers) {
                    array_push($AutoAttendUsers, $aUser);
                });
            } else {
                $UserQuery = $Connector->prepare('SELECT UserId, CharacterId, Class, Role1 FROM `' . RP_TABLE_PREFIX . 'UserSetting` ' . 'LEFT JOIN `' . RP_TABLE_PREFIX . 'Character` USING(UserId) ' . 'WHERE `' . RP_TABLE_PREFIX . 'UserSetting`.Name="AutoAttend" AND Mainchar="true" AND Game=:Game');
                $UserQuery->bindValue(':Game', $gGame['GameId'], PDO::PARAM_STR);
                $UserQuery->loop(function ($aUser) use(&$AutoAttendUsers) {
                    array_push($AutoAttendUsers, $aUser);
                });
            }
            // Create raids(s)
            $Repeat = max(0, intval($aRequest['repeat'])) + 1;
            // repeat at least once
            $GroupInfo = $gGame['Groups'][$aRequest['locationSize']];
            $SlotRoles = implode(':', array_keys($GroupInfo));
            $SlotCount = implode(':', $GroupInfo);
            $RaidMode = $aRequest['mode'] == 'optout' ? 'manual' : $aRequest['mode'];
            for ($rc = 0; $rc < $Repeat; ++$rc) {
                $NewRaidQuery = $Connector->prepare('INSERT INTO `' . RP_TABLE_PREFIX . 'Raid` ' . '(LocationId, Size, Start, End, Mode, Description, SlotRoles, SlotCount ) ' . 'VALUES (:LocationId, :Size, FROM_UNIXTIME(:Start), FROM_UNIXTIME(:End), :Mode, :Description, ' . ':SlotRoles, :SlotCount)');
                $StartDateTime = mktime($StartHour, $StartMinute, 0, $StartMonth, $StartDay, $StartYear);
                $EndDateTime = mktime($EndHour, $EndMinute, 0, $EndMonth, $EndDay, $EndYear);
                // Convert to UTC
                $StartDateTime += $aRequest['startOffset'] * 60;
                $EndDateTime += $aRequest['endOffset'] * 60;
                $NewRaidQuery->bindValue(':LocationId', $LocationId, PDO::PARAM_INT);
                $NewRaidQuery->bindValue(':Size', $aRequest['locationSize'], PDO::PARAM_INT);
                $NewRaidQuery->bindValue(':Start', $StartDateTime, PDO::PARAM_INT);
                $NewRaidQuery->bindValue(':End', $EndDateTime, PDO::PARAM_INT);
                $NewRaidQuery->bindValue(':Mode', $RaidMode, PDO::PARAM_STR);
                $NewRaidQuery->bindValue(':Description', requestToXML($aRequest['description'], ENT_COMPAT, 'UTF-8'), PDO::PARAM_STR);
                $NewRaidQuery->bindValue(':SlotRoles', $SlotRoles, PDO::PARAM_STR);
                $NewRaidQuery->bindValue(':SlotCount', $SlotCount, PDO::PARAM_STR);
                $NewRaidQuery->execute();
                $RaidId = $Connector->lastInsertId();
                // Attend players when mode is optout
                if (count($AutoAttendUsers > 0)) {
                    $Status = $RaidMode == 'all' || $RaidMode == 'attend' ? 'ok' : 'available';
                    foreach ($AutoAttendUsers as $User) {
                        $UserId = intval($User['UserId']);
                        if (isset($VactionUsers[$UserId]) && ($StartDateTime >= $VactionUsers[$UserId]['Start'] && $StartDateTime <= $VactionUsers[$UserId]['End'])) {
                            continue;
                            // ### continue, user is on vacation ###
                        }
                        $Classes = explode(':', $User['Class']);
                        $ClassId = $Classes[0];
                        $RoleId = $gGame['ClassMode'] == 'multi' ? $gGame['Classes'][$ClassId]['roles'][0] : $User['Role1'];
                        $AttendQuery = $Connector->prepare('INSERT INTO `' . RP_TABLE_PREFIX . 'Attendance` (UserId, RaidId, CharacterId, Class, Role, Status) ' . 'VALUES (:UserId, :RaidId, :CharId, :Class, :Role, :Status)');
                        $AttendQuery->bindValue(':UserId', $UserId, PDO::PARAM_INT);
                        $AttendQuery->bindValue(':RaidId', $RaidId, PDO::PARAM_INT);
                        $AttendQuery->bindValue(':CharId', $User['CharacterId'], PDO::PARAM_INT);
                        $AttendQuery->bindValue(':Class', $ClassId, PDO::PARAM_STR);
                        $AttendQuery->bindValue(':Role', $RoleId, PDO::PARAM_STR);
                        $AttendQuery->bindValue(':Status', $Status, PDO::PARAM_STR);
                        $AttendQuery->execute();
                    }
                    if ($RaidMode == 'attend') {
                        removeOverbooked($RaidId, $SlotRoles, $SlotCount);
                    }
                }
                // Set vacation attendances
                foreach ($VactionUsers as $UserId => $Settings) {
                    if ($StartDateTime >= $Settings['Start'] && $StartDateTime <= $Settings['End']) {
                        $AbsentQuery = $Connector->prepare('INSERT INTO `' . RP_TABLE_PREFIX . 'Attendance` (UserId, RaidId, Status, Comment) ' . 'VALUES (:UserId, :RaidId, "unavailable", :Message)');
                        $AbsentQuery->bindValue(':UserId', $UserId, PDO::PARAM_INT);
                        $AbsentQuery->bindValue(':RaidId', $RaidId, PDO::PARAM_INT);
                        $AbsentQuery->bindValue(':Message', $Settings['Message'], PDO::PARAM_STR);
                        $AbsentQuery->execute();
                    }
                }
                // Post raids to forum
                if (count($PostTargets) > 0) {
                    $RaidQuery = $Connector->prepare('SELECT * FROM `' . RP_TABLE_PREFIX . 'Raid` WHERE RaidId=:RaidId LIMIT 1');
                    $RaidQuery->bindValue(':RaidId', $RaidId, PDO::PARAM_INT);
                    $RaidData = $RaidQuery->fetchFirst();
                    $MessageData = Binding::generateMessage($RaidData, $LocationData);
                    try {
                        foreach ($PostTargets as $PluginInstance) {
                            $PluginInstance->post($MessageData['subject'], $MessageData['message']);
                        }
                    } catch (PDOException $Exception) {
                        Out::getInstance()->pushError($Exception->getMessage());
                    }
                }
                // Call plugins
                PluginRegistry::ForEachPlugin(function ($PluginInstance) use($RaidId) {
                    $PluginInstance->onRaidCreate($RaidId);
                });
                // Increment start/end
                switch ($aRequest['stride']) {
                    case 'day':
                        ++$StartDay;
                        ++$EndDay;
                        break;
                    case 'week':
                        $StartDay += 7;
                        $EndDay += 7;
                        break;
                    case 'month':
                        ++$StartMonth;
                        ++$EndMonth;
                        break;
                    default:
                    case 'once':
                        $rc = $Repeat;
                        // Force done
                        break;
                }
            }
            // reload calendar
            $Session = Session::get();
            $ShowMonth = isset($Session['Calendar']) && isset($Session['Calendar']['month']) ? $Session['Calendar']['month'] : $aRequest['month'];
            $ShowYear = isset($Session['Calendar']) && isset($Session['Calendar']['year']) ? $Session['Calendar']['year'] : $aRequest['year'];
            msgQueryCalendar(prepareCalRequest($ShowMonth, $ShowYear));
        }
    } else {
        $Out = Out::getInstance();
        $Out->pushError(L('AccessDenied'));
    }
}
Ejemplo n.º 8
0
function msgRaidupdate($aRequest)
{
    if (validRaidlead()) {
        global $gGame;
        loadGameSettings();
        $Connector = Connector::getInstance();
        // The whole update is packed into one transaction.
        // The transaction will be rolled back upon error so no half-updated
        // data is stored in the database. This requires the database to
        // support transactions.
        do {
            $Connector->beginTransaction();
            $LocationId = $aRequest['locationId'];
            // Insert new location if necessary
            if ($LocationId == 0) {
                $NewLocationQuery = $Connector->prepare('INSERT INTO `' . RP_TABLE_PREFIX . 'Location`' . '(Name, Game, Image) VALUES (:Name, :Game, :Image)');
                $NewLocationQuery->bindValue(':Name', requestToXML($aRequest['locationName'], ENT_COMPAT, 'UTF-8'), PDO::PARAM_STR);
                $NewLocationQuery->bindValue(':Game', $gGame['GameId'], PDO::PARAM_STR);
                $NewLocationQuery->bindValue(':Image', $aRequest['raidImage'], PDO::PARAM_STR);
                if (!$NewLocationQuery->execute()) {
                    $Connector->rollBack();
                    return;
                    // ### return, error ###
                }
                $LocationId = $Connector->lastInsertId();
            }
            // Update raid
            $UpdateRaidQuery = $Connector->prepare('UPDATE `' . RP_TABLE_PREFIX . 'Raid` SET ' . 'LocationId = :LocationId, Size = :Size, ' . 'Stage = :Stage, ' . 'Start = FROM_UNIXTIME(:Start), End = FROM_UNIXTIME(:End), ' . 'Description = :Description, ' . 'Mode = :Mode, ' . 'SlotRoles = :SlotRoles, SlotCount = :SlotCount ' . 'WHERE RaidId = :RaidId');
            $StartDateTime = mktime(intval($aRequest['startHour']), intval($aRequest['startMinute']), 0, intval($aRequest['startMonth']), intval($aRequest['startDay']), intval($aRequest['startYear']));
            $EndDateTime = mktime(intval($aRequest['endHour']), intval($aRequest['endMinute']), 0, intval($aRequest['endMonth']), intval($aRequest['endDay']), intval($aRequest['endYear']));
            // Convert to UTC
            $StartDateTime += $aRequest['startOffset'] * 60;
            $EndDateTime += $aRequest['endOffset'] * 60;
            $UpdateRaidQuery->bindValue(':RaidId', $aRequest['id'], PDO::PARAM_INT);
            $UpdateRaidQuery->bindValue(':LocationId', $LocationId, PDO::PARAM_INT);
            $UpdateRaidQuery->bindValue(':Stage', $aRequest['stage'], PDO::PARAM_STR);
            $UpdateRaidQuery->bindValue(':Size', $aRequest['locationSize'], PDO::PARAM_INT);
            $UpdateRaidQuery->bindValue(':Start', $StartDateTime, PDO::PARAM_INT);
            $UpdateRaidQuery->bindValue(':End', $EndDateTime, PDO::PARAM_INT);
            $UpdateRaidQuery->bindValue(':Mode', $aRequest['mode'], PDO::PARAM_STR);
            $UpdateRaidQuery->bindValue(':Description', requestToXML($aRequest['description'], ENT_COMPAT, 'UTF-8'), PDO::PARAM_STR);
            $UpdateRaidQuery->bindValue(':SlotRoles', implode(':', $aRequest['slotRoles']), PDO::PARAM_STR);
            $UpdateRaidQuery->bindValue(':SlotCount', implode(':', $aRequest['slotCount']), PDO::PARAM_STR);
            if (!$UpdateRaidQuery->execute()) {
                $Connector->rollBack();
                return;
                // ### return, error ###
            }
            // Remove the attends marked for delete.
            // Only random player attends can be removed.
            $NumRemoved = isset($aRequest['removed']) ? count($aRequest['removed']) : 0;
            for ($i = 0; $i < $NumRemoved; ++$i) {
                $RemoveSlot = $Connector->prepare('DELETE FROM `' . RP_TABLE_PREFIX . 'Attendance` ' . 'WHERE AttendanceId = :AttendanceId AND CharacterId = 0 AND UserId = 0');
                $RemoveSlot->bindValue(':AttendanceId', $aRequest['removed'][$i], PDO::PARAM_INT);
                if (!$RemoveSlot->execute()) {
                    $Connector->rollBack();
                    return;
                    // ### return, error ###
                }
            }
            // Now iterate over all role lists and update the players in it
            // Random player will be converted to 'real' player, i.e. they loose their
            // negative pseudo-id.
            foreach ($gGame['Roles'] as $Role) {
                if (isset($aRequest['role_' . $Role['id']])) {
                    $NumAttends = 0;
                    $AttendsForRole = $aRequest['role_' . $Role['id']];
                    // Attendances are passed in the form [id,status,id,status, … ]
                    // So we iterate with a stride of 2
                    for ($AttendIdx = 0; $AttendIdx < count($AttendsForRole);) {
                        $UpdateSlot = null;
                        // $Id = UserId when not having an attendance record
                        // $Id = AttendanceId for all others
                        $Id = intVal($AttendsForRole[$AttendIdx++]);
                        $Status = $AttendsForRole[$AttendIdx++];
                        $OldTimestamp = $AttendsForRole[$AttendIdx++];
                        $Flags = intVal($AttendsForRole[$AttendIdx++]);
                        if ($Status == 'undecided') {
                            continue;
                        }
                        // ### continue, skip undecided ###
                        // Get extra parameters
                        if (($Flags & PlayerFlagCharId) != 0) {
                            $CharId = intval($AttendsForRole[$AttendIdx++]);
                            $ActiveClass = $AttendsForRole[$AttendIdx++];
                        }
                        if (($Flags & PlayerFlagUserId) != 0) {
                            $UserId = intVal($AttendsForRole[$AttendIdx++]);
                        }
                        if (($Flags & PlayerFlagName) != 0) {
                            $Name = $AttendsForRole[$AttendIdx++];
                        }
                        if (($Flags & PlayerFlagComment) != 0) {
                            $Comment = $AttendsForRole[$AttendIdx++];
                        }
                        if (($Flags & PlayerFlagNew) != 0) {
                            // New entries
                            if (($Flags & PlayerFlagComment) != 0 && ($Flags & PlayerFlagUserId) != 0 && ($Flags & PlayerFlagCharId) != 0) {
                                // Undecided set-up
                                $UpdateSlot = $Connector->prepare('INSERT INTO `' . RP_TABLE_PREFIX . 'Attendance` ' . '( CharacterId, Class, UserId, RaidId, Status, Role, Comment ) ' . 'VALUES ( :CharId, :Class, :UserId, :RaidId, :Status, :Role, :Comment )');
                                $UpdateSlot->bindValue(':CharId', $CharId, PDO::PARAM_INT);
                                $UpdateSlot->bindValue(':Class', $ActiveClass, PDO::PARAM_STR);
                                $UpdateSlot->bindValue(':UserId', $UserId, PDO::PARAM_INT);
                                $UpdateSlot->bindValue(':Comment', $Comment, PDO::PARAM_STR);
                            } else {
                                if (($Flags & PlayerFlagComment) != 0 && ($Flags & PlayerFlagCharId) != 0) {
                                    // Undecied absent
                                    $UpdateSlot = $Connector->prepare('INSERT INTO `' . RP_TABLE_PREFIX . 'Attendance` ' . '( CharacterId, Class, UserId, RaidId, Status, Role, Comment ) ' . 'VALUES ( :CharId, :Class, :UserId, :RaidId, :Status, :Role, :Comment )');
                                    $UpdateSlot->bindValue(':CharId', $CharId, PDO::PARAM_INT);
                                    $UpdateSlot->bindValue(':Class', $ActiveClass, PDO::PARAM_STR);
                                    $UpdateSlot->bindValue(':UserId', $UserId, PDO::PARAM_INT);
                                    $UpdateSlot->bindValue(':Comment', $Comment, PDO::PARAM_STR);
                                } else {
                                    if (($Flags & PlayerFlagName) != 0) {
                                        // Random player. Set name.
                                        $UpdateSlot = $Connector->prepare('INSERT INTO `' . RP_TABLE_PREFIX . 'Attendance` ' . '( CharacterId, UserId, RaidId, Status, Class, Role, Comment ) ' . 'VALUES ( 0, 0, :RaidId, :Status, :Class, :Role, :Name )');
                                        $UpdateSlot->bindValue(':Name', $Name, PDO::PARAM_STR);
                                        $UpdateSlot->bindValue(':Class', '___', PDO::PARAM_STR);
                                    } else {
                                        $Out = Out::getInstance();
                                        $Out->pushError('Invalid user flags');
                                    }
                                }
                            }
                        } else {
                            // Update existing entries
                            if (($Flags & PlayerFlagComment) != 0 && ($Flags & PlayerFlagCharId) != 0) {
                                // Used when setting up an absent player
                                $UpdateSlot = $Connector->prepare('UPDATE `' . RP_TABLE_PREFIX . 'Attendance` SET ' . 'Status = :Status, CharacterId = :CharId, Class = :Class, Comment = :Comment, Role = :Role, LastUpdate = FROM_UNIXTIME(:TimestampNow) ' . 'WHERE RaidId = :RaidId AND LastUpdate = FROM_UNIXTIME(:LastUpdate) AND AttendanceId = :AttendanceId LIMIT 1');
                                $UpdateSlot->bindValue(':Comment', $Comment, PDO::PARAM_STR);
                                $UpdateSlot->bindValue(':CharId', $CharId, PDO::PARAM_INT);
                                $UpdateSlot->bindValue(':Class', $ActiveClass, PDO::PARAM_STR);
                            } else {
                                if (($Flags & PlayerFlagCharId) != 0) {
                                    // Used when changing a character
                                    $UpdateSlot = $Connector->prepare('UPDATE `' . RP_TABLE_PREFIX . 'Attendance` SET ' . 'Status = :Status, CharacterId = :CharId, Class = :Class, Role = :Role, LastUpdate = FROM_UNIXTIME(:TimestampNow) ' . 'WHERE RaidId = :RaidId AND LastUpdate = FROM_UNIXTIME(:LastUpdate) AND AttendanceId = :AttendanceId LIMIT 1');
                                    $UpdateSlot->bindValue(':CharId', $CharId, PDO::PARAM_INT);
                                    $UpdateSlot->bindValue(':Class', $ActiveClass, PDO::PARAM_STR);
                                } else {
                                    if (($Flags & PlayerFlagComment) != 0) {
                                        // Used when setting a player to absent
                                        $UpdateSlot = $Connector->prepare('UPDATE `' . RP_TABLE_PREFIX . 'Attendance` SET ' . 'Status = :Status, Comment = :Comment, Role = :Role, LastUpdate = FROM_UNIXTIME(:TimestampNow) ' . 'WHERE RaidId = :RaidId AND LastUpdate = FROM_UNIXTIME(:LastUpdate) AND AttendanceId = :AttendanceId LIMIT 1');
                                        $UpdateSlot->bindValue(':Comment', $Comment, PDO::PARAM_STR);
                                    } else {
                                        if (($Flags & PlayerFlagName) != 0) {
                                            // Used when changing the name of a random player
                                            $UpdateSlot = $Connector->prepare('UPDATE `' . RP_TABLE_PREFIX . 'Attendance` SET ' . 'Status = :Status, Role = :Role, Comment = :Name, LastUpdate = FROM_UNIXTIME(:TimestampNow) ' . 'WHERE RaidId = :RaidId AND LastUpdate = FROM_UNIXTIME(:LastUpdate) AND AttendanceId = :AttendanceId LIMIT 1');
                                            $UpdateSlot->bindValue(':Name', $Name, PDO::PARAM_STR);
                                        } else {
                                            // Existing player, update
                                            $UpdateSlot = $Connector->prepare('UPDATE `' . RP_TABLE_PREFIX . 'Attendance` SET ' . 'Status = :Status, Role = :Role, LastUpdate = FROM_UNIXTIME(:TimestampNow) ' . 'WHERE RaidId = :RaidId AND LastUpdate = FROM_UNIXTIME(:LastUpdate) AND AttendanceId = :AttendanceId LIMIT 1');
                                        }
                                    }
                                }
                            }
                            $UpdateSlot->bindValue(':AttendanceId', $Id, PDO::PARAM_INT);
                            $UpdateSlot->bindValue(':LastUpdate', $OldTimestamp, PDO::PARAM_INT);
                            $UpdateSlot->bindValue(':TimestampNow', time(), PDO::PARAM_INT);
                        }
                        $UpdateSlot->bindValue(':Status', $Status, PDO::PARAM_STR);
                        $UpdateSlot->bindValue(':RaidId', $aRequest['id'], PDO::PARAM_INT);
                        $UpdateSlot->bindValue(':Role', $Role['id'], PDO::PARAM_STR);
                        if (!$UpdateSlot->execute()) {
                            $Connector->rollBack();
                            return;
                            // ### return, error ###
                        }
                    }
                }
            }
            // Assure mode constraints
            if ($aRequest['mode'] == 'all') {
                // Mode 'all' means all players are either 'ok' or 'unavailable'
                $AttendenceQuery = $Connector->prepare('UPDATE `' . RP_TABLE_PREFIX . 'Attendance` SET Status = "ok" ' . 'WHERE RaidId = :RaidId AND Status = "available"');
                $AttendenceQuery->bindValue(':RaidId', $aRequest['id'], PDO::PARAM_INT);
                if (!$AttendenceQuery->execute()) {
                    $Connector->rollBack();
                    return;
                    // ### return, error ###
                }
            } else {
                if ($aRequest['mode'] != 'overbook') {
                    // Assure there not more 'ok' players than allowed by slot size
                    $SlotSizes = array_combine($aRequest['slotRoles'], $aRequest['slotCount']);
                    foreach ($aRequest['slotRoles'] as $RoleId) {
                        if ($SlotSizes[$RoleId] > 0) {
                            $AttendenceQuery = $Connector->prepare('SELECT AttendanceId ' . 'FROM `' . RP_TABLE_PREFIX . 'Attendance` ' . 'WHERE RaidId = :RaidId AND Status = "ok" AND Role = :RoleId ' . 'ORDER BY AttendanceId DESC LIMIT :MaxCount');
                            $AttendenceQuery->bindValue(':RaidId', $aRequest['id'], PDO::PARAM_INT);
                            $AttendenceQuery->bindValue(':RoleId', $RoleId, PDO::PARAM_STR);
                            $AttendenceQuery->bindValue(':MaxCount', $SlotSizes[$RoleId], PDO::PARAM_INT);
                            $LastAttend = $AttendenceQuery->fetchFirst();
                            if ($AttendenceQuery->getAffectedRows() == $SlotSizes[$RoleId]) {
                                // Fix the overhead
                                $FixQuery = $Connector->prepare('UPDATE `' . RP_TABLE_PREFIX . 'Attendance` SET Status = "available" ' . 'WHERE RaidId = :RaidId AND Status = "ok" AND Role = :RoleId ' . 'AND AttendanceId > :FirstId');
                                $FixQuery->bindValue(':RaidId', $aRequest['id'], PDO::PARAM_INT);
                                $FixQuery->bindValue(':RoleId', $RoleId, PDO::PARAM_STR);
                                $FixQuery->bindValue(':FirstId', $LastAttend['AttendanceId'], PDO::PARAM_INT);
                                if (!$FixQuery->execute()) {
                                    $Connector->rollBack();
                                    return;
                                    // ### return, error ###
                                }
                            }
                        }
                    }
                }
            }
        } while (!$Connector->commit());
        // Call plugins
        $RaidId = intval($aRequest['id']);
        PluginRegistry::ForEachPlugin(function ($PluginInstance) use($RaidId) {
            $PluginInstance->onRaidModify($RaidId);
        });
        // reload detailed view
        msgRaidDetail($aRequest);
    } else {
        $Out = Out::getInstance();
        $Out->pushError(L('AccessDenied'));
    }
}
Ejemplo n.º 9
0
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'));
    }
}
Ejemplo n.º 10
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'));
    }
}
Ejemplo n.º 11
0
function msgRaidDetail($aRequest)
{
    if (validUser()) {
        global $gGame;
        loadGameSettings();
        $Out = Out::getInstance();
        $Connector = Connector::getInstance();
        $Out->pushValue('show', $aRequest['showPanel']);
        $ListRaidQuery = $Connector->prepare('SELECT ' . RP_TABLE_PREFIX . 'Raid.*, ' . RP_TABLE_PREFIX . 'Location.Name AS LocationName, ' . RP_TABLE_PREFIX . 'Location.Image AS LocationImage, ' . RP_TABLE_PREFIX . 'Attendance.AttendanceId, ' . RP_TABLE_PREFIX . 'Attendance.UserId, ' . RP_TABLE_PREFIX . 'Attendance.CharacterId, ' . RP_TABLE_PREFIX . 'Attendance.Status, ' . RP_TABLE_PREFIX . 'Attendance.Role, ' . RP_TABLE_PREFIX . 'Attendance.Class AS ActiveClass, ' . RP_TABLE_PREFIX . 'Attendance.Comment, ' . 'UNIX_TIMESTAMP(' . RP_TABLE_PREFIX . 'Attendance.LastUpdate) AS LastUpdate, ' . RP_TABLE_PREFIX . 'Character.Name, ' . RP_TABLE_PREFIX . 'Character.Class, ' . RP_TABLE_PREFIX . 'Character.Mainchar, ' . RP_TABLE_PREFIX . 'Character.Role1, ' . RP_TABLE_PREFIX . 'Character.Role2, ' . 'UNIX_TIMESTAMP(' . RP_TABLE_PREFIX . 'Raid.Start) AS StartUTC, ' . 'UNIX_TIMESTAMP(' . RP_TABLE_PREFIX . 'Raid.End) AS EndUTC ' . 'FROM `' . RP_TABLE_PREFIX . 'Raid` ' . 'LEFT JOIN `' . RP_TABLE_PREFIX . 'Location` USING(LocationId) ' . 'LEFT JOIN `' . RP_TABLE_PREFIX . 'Attendance` USING(RaidId) ' . 'LEFT JOIN `' . RP_TABLE_PREFIX . 'Character` USING(CharacterId) ' . 'WHERE RaidId = :RaidId ORDER BY `' . RP_TABLE_PREFIX . 'Attendance`.AttendanceId');
        $ListRaidQuery->bindValue(':RaidId', $aRequest['id'], PDO::PARAM_INT);
        $Data = $ListRaidQuery->fetchFirstOfLoop();
        if ($Data != null) {
            $Participants = array();
            $StartDate = getdate($Data['StartUTC']);
            $EndDate = getdate($Data['EndUTC']);
            $EndTimestamp = $Data['EndUTC'];
            $Slots = array_combine(explode(':', $Data['SlotRoles']), explode(':', $Data['SlotCount']));
            $Out->pushValue('raidId', $Data['RaidId']);
            $Out->pushValue('locationid', $Data['LocationId']);
            $Out->pushValue('locationname', $Data['LocationName']);
            $Out->pushValue('stage', $Data['Stage']);
            $Out->pushValue('mode', $Data['Mode']);
            $Out->pushValue('image', $Data['LocationImage']);
            $Out->pushValue('size', $Data['Size']);
            $Out->pushValue('startDate', intval($StartDate['year']) . '-' . leadingZero10($StartDate['mon']) . '-' . leadingZero10($StartDate['mday']));
            $Out->pushValue('start', leadingZero10($StartDate['hours']) . ':' . leadingZero10($StartDate['minutes']));
            $Out->pushValue('endDate', intval($EndDate['year']) . '-' . leadingZero10($EndDate['mon']) . '-' . leadingZero10($EndDate['mday']));
            $Out->pushValue('end', leadingZero10($EndDate['hours']) . ':' . leadingZero10($EndDate['minutes']));
            $Out->pushValue('description', $Data['Description']);
            $Out->pushValue('slots', $Slots);
            $Attendees = array();
            $MaxAttendanceId = 1;
            $NumAttended = 0;
            if ($Data['UserId'] != NULL) {
                $ListRaidQuery->loop(function ($Data) use(&$gGame, &$Connector, &$MaxAttendanceId, &$Participants, &$Attendees, &$NumAttended) {
                    // Track max attendance id to give undecided players (without a comment) a distinct one.
                    $MaxAttendanceId = Max($MaxAttendanceId, $Data['AttendanceId']);
                    if ($Data['UserId'] != 0) {
                        array_push($Participants, intval($Data['UserId']));
                    }
                    if ($Data['CharacterId'] == 0) {
                        // CharacterId is 0 on random players or players that are absent
                        if ($Data['UserId'] != 0) {
                            // Fetch the mainchar of the registered player and display this
                            // character as 'absent'
                            $CharQuery = $Connector->prepare('SELECT ' . RP_TABLE_PREFIX . 'Character.*, ' . RP_TABLE_PREFIX . 'User.Login AS UserName ' . 'FROM `' . RP_TABLE_PREFIX . 'Character` LEFT JOIN `' . RP_TABLE_PREFIX . 'User` USING(UserId) ' . 'WHERE UserId = :UserId AND Game = :Game ' . 'ORDER BY Mainchar, CharacterId ASC');
                            $CharQuery->bindValue(':UserId', $Data['UserId'], PDO::PARAM_INT);
                            $CharQuery->bindValue(':Game', $gGame['GameId'], PDO::PARAM_STR);
                            $CharData = $CharQuery->fetchFirstOfLoop();
                            if ($CharData != null && $CharData['CharacterId'] != null) {
                                $Classes = explode(':', $CharData['Class']);
                                $AttendeeData = array('id' => $Data['AttendanceId'], 'hasId' => true, 'userId' => $Data['UserId'], 'timestamp' => $Data['LastUpdate'], 'charid' => $CharData['CharacterId'], 'name' => $CharData['Name'], 'mainchar' => $CharData['Mainchar'], 'classname' => $Classes, 'activeclass' => $Classes[0], 'role' => $CharData['Role1'], 'role1' => $CharData['Role1'], 'role2' => $CharData['Role2'], 'status' => $Data['Status'], 'comment' => $Data['Comment'], 'character' => array());
                                $CharQuery->loop(function ($CharData) use(&$AttendeeData) {
                                    $Character = array('id' => $CharData['CharacterId'], 'name' => $CharData['Name'], 'mainchar' => $CharData['Mainchar'], 'classname' => explode(':', $CharData['Class']), 'role1' => $CharData['Role1'], 'role2' => $CharData['Role2']);
                                    array_push($AttendeeData['character'], $Character);
                                });
                                array_push($Attendees, $AttendeeData);
                            }
                        } else {
                            // CharacterId and UserId set to 0 means 'random player'
                            $AttendeeData = array('id' => $Data['AttendanceId'], 'hasId' => true, 'userId' => 0, 'timestamp' => $Data['LastUpdate'], 'charid' => 0, 'name' => $Data['Comment'], 'mainchar' => false, 'classname' => array('___'), 'activeclass' => '___', 'role' => $Data['Role'], 'role1' => $Data['Role'], 'role2' => $Data['Role'], 'status' => $Data['Status'], 'comment' => '', 'character' => array());
                            array_push($Attendees, $AttendeeData);
                            ++$NumAttended;
                        }
                    } else {
                        // CharacterId is set
                        $AttendeeData = array('id' => $Data['AttendanceId'], 'hasId' => true, 'userId' => $Data['UserId'], 'timestamp' => $Data['LastUpdate'], 'charid' => $Data['CharacterId'], 'name' => $Data['Name'], 'mainchar' => $Data['Mainchar'], 'classname' => explode(':', $Data['Class']), 'activeclass' => $Data['ActiveClass'], 'role' => $Data['Role'], 'role1' => $Data['Role1'], 'role2' => $Data['Role2'], 'status' => $Data['Status'], 'comment' => $Data['Comment'], 'character' => array());
                        $CharQuery = $Connector->prepare('SELECT ' . RP_TABLE_PREFIX . 'Character.*, ' . RP_TABLE_PREFIX . 'User.Login AS UserName ' . 'FROM `' . RP_TABLE_PREFIX . 'User` LEFT JOIN `' . RP_TABLE_PREFIX . 'Character` USING(UserId) ' . 'WHERE UserId = :UserId AND Game = :Game ' . 'ORDER BY Mainchar, CharacterId ASC');
                        $CharQuery->bindValue(':UserId', $Data['UserId'], PDO::PARAM_INT);
                        $CharQuery->bindValue(':Game', $gGame['GameId'], PDO::PARAM_STR);
                        $CharQuery->loop(function ($CharData) use(&$AttendeeData) {
                            $Character = array('id' => $CharData['CharacterId'], 'name' => $CharData['Name'], 'mainchar' => $CharData['Mainchar'], 'classname' => explode(':', $CharData['Class']), 'role1' => $CharData['Role1'], 'role2' => $CharData['Role2']);
                            array_push($AttendeeData['character'], $Character);
                        });
                        if ($Data['Status'] == 'ok' || $Data['Status'] == 'available') {
                            ++$NumAttended;
                        }
                        array_push($Attendees, $AttendeeData);
                    }
                });
            }
            // Fetch all registered and unblocked users
            $AllUsersQuery = $Connector->prepare('SELECT ' . RP_TABLE_PREFIX . 'User.UserId ' . 'FROM `' . RP_TABLE_PREFIX . 'User` ' . 'WHERE `Group` != "none"');
            $AllUsersQuery->loop(function ($User) use(&$gGame, &$Connector, &$MaxAttendanceId, &$EndTimestamp, &$Participants, &$Attendees) {
                if (!in_array(intval($User['UserId']), $Participants)) {
                    // Users that are not registered for this raid are undecided
                    // Fetch their character data, maincharacter first
                    $CharQuery = $Connector->prepare('SELECT ' . RP_TABLE_PREFIX . 'Character.*, ' . RP_TABLE_PREFIX . 'User.Login AS UserName ' . 'FROM `' . RP_TABLE_PREFIX . 'Character` LEFT JOIN `' . RP_TABLE_PREFIX . 'User` USING(UserId) ' . 'WHERE UserId = :UserId AND Created < FROM_UNIXTIME(:RaidEnd) AND Game = :Game ' . 'ORDER BY Mainchar, CharacterId ASC');
                    $CharQuery->bindValue(':UserId', $User['UserId'], PDO::PARAM_INT);
                    $CharQuery->bindValue(':RaidEnd', $EndTimestamp, PDO::PARAM_INT);
                    $CharQuery->bindValue(':Game', $gGame['GameId'], PDO::PARAM_STR);
                    $UserData = $CharQuery->fetchFirstOfLoop();
                    if ($UserData != null) {
                        // Absent user have no attendance Id, so we need to generate one
                        // that is not in use (for this raid).
                        ++$MaxAttendanceId;
                        $Classes = explode(':', $UserData['Class']);
                        $AttendeeData = array('id' => $MaxAttendanceId, 'hasId' => false, 'userId' => $UserData['UserId'], 'timestamp' => time(), 'charid' => $UserData['CharacterId'], 'name' => $UserData['Name'], 'mainchar' => $UserData['Mainchar'], 'classname' => $Classes, 'activeclass' => $Classes[0], 'role' => $UserData['Role1'], 'role1' => $UserData['Role1'], 'role2' => $UserData['Role2'], 'status' => 'undecided', 'comment' => '', 'character' => array());
                        $CharQuery->loop(function ($UserData) use(&$AttendeeData) {
                            $Character = array('id' => $UserData['CharacterId'], 'name' => $UserData['Name'], 'mainchar' => $UserData['Mainchar'], 'classname' => explode(':', $UserData['Class']), 'role1' => $UserData['Role1'], 'role2' => $UserData['Role2']);
                            array_push($AttendeeData['character'], $Character);
                        });
                        array_push($Attendees, $AttendeeData);
                    }
                }
            });
            $Out->pushValue('attendee', $Attendees);
            $Out->pushValue('attended', $NumAttended);
            $ExportParameter = Api::normalizeArgsRaid(array('raid' => intval($aRequest['id']), 'attends' => true));
            $Out->pushValue('token', Api::getPublicToken($ExportParameter));
        }
        if (validRaidlead()) {
            msgQueryLocations($aRequest);
        }
    } else {
        $Out = Out::getInstance();
        $Out->pushError(L('AccessDenied'));
    }
}
Ejemplo n.º 12
-1
function msgRaidList($aRequest)
{
    if (validUser()) {
        global $gGame;
        loadGameSettings();
        $Out = Out::getInstance();
        $Connector = Connector::getInstance();
        // Get next 6 raids
        $NextRaidQuery = $Connector->prepare('Select ' . RP_TABLE_PREFIX . 'Raid.*, ' . RP_TABLE_PREFIX . 'Location.*, ' . RP_TABLE_PREFIX . 'Attendance.CharacterId, ' . RP_TABLE_PREFIX . 'Attendance.UserId, ' . RP_TABLE_PREFIX . 'Attendance.Status, ' . RP_TABLE_PREFIX . 'Attendance.Class, ' . RP_TABLE_PREFIX . 'Attendance.Role, ' . RP_TABLE_PREFIX . 'Attendance.Comment, ' . 'UNIX_TIMESTAMP(' . RP_TABLE_PREFIX . 'Raid.Start) AS StartUTC, ' . 'UNIX_TIMESTAMP(' . RP_TABLE_PREFIX . 'Raid.End) AS EndUTC ' . 'FROM `' . RP_TABLE_PREFIX . 'Raid` ' . 'LEFT JOIN `' . RP_TABLE_PREFIX . 'Location` USING(LocationId) ' . 'LEFT JOIN `' . RP_TABLE_PREFIX . 'Attendance` USING(RaidId) ' . 'LEFT JOIN `' . RP_TABLE_PREFIX . 'Character` USING (CharacterId) ' . 'WHERE ' . RP_TABLE_PREFIX . 'Raid.Start >= FROM_UNIXTIME(:Start) ' . 'AND ' . RP_TABLE_PREFIX . 'Location.Game = :Game ' . 'ORDER BY ' . RP_TABLE_PREFIX . 'Raid.Start, ' . RP_TABLE_PREFIX . 'Raid.RaidId');
        $NextRaidQuery->bindValue(':Start', mktime(0, 0, 0), PDO::PARAM_INT);
        $NextRaidQuery->bindValue(':Game', $gGame['GameId'], PDO::PARAM_STR);
        parseRaidQuery($aRequest, $NextRaidQuery, 6);
        // Load raid history
        $RaidHistoryQuery = $Connector->prepare('Select ' . RP_TABLE_PREFIX . 'Raid.*, ' . RP_TABLE_PREFIX . 'Location.*, ' . 'UNIX_TIMESTAMP(' . RP_TABLE_PREFIX . 'Raid.Start) AS StartUTC, ' . 'UNIX_TIMESTAMP(' . RP_TABLE_PREFIX . 'Raid.End) AS EndUTC ' . 'FROM `' . RP_TABLE_PREFIX . 'Raid` ' . 'LEFT JOIN `' . RP_TABLE_PREFIX . 'Location` USING(LocationId) ' . 'WHERE ' . RP_TABLE_PREFIX . 'Raid.Start < FROM_UNIXTIME(:Start) ' . 'AND ' . RP_TABLE_PREFIX . 'Location.Game = :Game ' . 'ORDER BY Start DESC LIMIT ' . intval($aRequest['offset']) . ', ' . intval($aRequest['count']));
        $RaidHistoryQuery->bindValue(':Start', mktime(0, 0, 0), PDO::PARAM_INT);
        $RaidHistoryQuery->bindValue(':Game', $gGame['GameId'], PDO::PARAM_STR);
        $RaidList = array();
        $RaidHistoryQuery->loop(function ($Data) use(&$RaidList) {
            $StartDate = getdate($Data['StartUTC']);
            $EndDate = getdate($Data['EndUTC']);
            $Raid = array('id' => $Data['RaidId'], 'location' => $Data['Name'], 'stage' => $Data['Stage'], 'image' => $Data['Image'], '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']));
            array_push($RaidList, $Raid);
        });
        $Out->pushValue('history', $RaidList);
    } else {
        $Out = Out::getInstance();
        $Out->pushError(L('AccessDenied'));
    }
}