function msgQueryNewRaidData($aRequest)
{
    $Out = Out::getInstance();
    if (validRaidlead()) {
        $Connector = Connector::getInstance();
        // Settings
        $NewRaidSettings = $Connector->prepare('SELECT Name, IntValue, TextValue FROM `' . RP_TABLE_PREFIX . 'Setting`');
        $IntOfInterest = array('RaidSize', 'RaidStartHour', 'RaidStartMinute', 'RaidEndHour', 'RaidEndMinute', 'StartOfWeek');
        $TextOfInterest = array('RaidMode');
        $Settings = array();
        $NewRaidSettings->loop(function ($Data) use(&$Settings, $IntOfInterest, $TextOfInterest) {
            $KeyValue = array('name' => $Data['Name'], 'value' => null);
            if (in_array($Data['Name'], $IntOfInterest)) {
                $KeyValue['value'] = $Data['IntValue'];
            } elseif (in_array($Data['Name'], $TextOfInterest)) {
                $KeyValue['value'] = $Data['TextValue'];
            }
            array_push($Settings, $KeyValue);
        });
        $Out->pushValue('setting', $Settings);
        // Locations
        msgQueryLocations($aRequest);
    } else {
        $Out->pushError(L('AccessDenied'));
    }
}
Example #2
0
     $Settings = Settings::getInstance();
     lockOldRaids($Settings["LockRaids"]["IntValue"]);
     purgeOldRaids($Settings["PurgeRaids"]["IntValue"]);
     msgRaidList($_REQUEST);
     break;
 case "raid_detail":
     msgRaidDetail($_REQUEST);
     break;
 case "raid_update":
     msgRaidupdate($_REQUEST);
     break;
 case "query_newraiddata":
     msgQueryNewRaidData($_REQUEST);
     break;
 case "query_locations":
     msgQueryLocations($_REQUEST);
     break;
 case "query_profile":
     msgQueryProfile($_REQUEST);
     break;
 case "query_settings":
     msgQuerySettings($_REQUEST);
     break;
 case "profile_update":
     msgProfileupdate($_REQUEST);
     break;
 case "comment_update":
     msgCommentupdate($_REQUEST);
     break;
 case "raid_delete":
     msgRaidDelete($_REQUEST);
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'));
    }
}
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'));
    }
}