function msgCommentupdate($aRequest)
{
    if (validUser()) {
        $Connector = Connector::getInstance();
        $RaidId = intval($aRequest['raidId']);
        $UserId = UserProxy::getInstance()->UserId;
        $CheckQuery = $Connector->prepare('SELECT UserId FROM `' . RP_TABLE_PREFIX . 'Attendance` WHERE UserId = :UserId AND RaidId = :RaidId LIMIT 1');
        $CheckQuery->bindValue(':UserId', $UserId, PDO::PARAM_INT);
        $CheckQuery->bindValue(':RaidId', $RaidId, PDO::PARAM_INT);
        if ($CheckQuery->execute()) {
            $UpdateQuery = null;
            if ($CheckQuery->getAffectedRows() > 0) {
                $UpdateQuery = $Connector->prepare('UPDATE `' . RP_TABLE_PREFIX . 'Attendance` ' . 'SET comment = :Comment, LastUpdate = FROM_UNIXTIME(:Timestamp) ' . 'WHERE RaidId = :RaidId AND UserId = :UserId LIMIT 1');
                $UpdateQuery->bindValue(':Timestamp', time(), PDO::PARAM_INT);
            } else {
                $UpdateQuery = $Connector->prepare('INSERT INTO `' . RP_TABLE_PREFIX . 'Attendance` ( CharacterId, UserId, RaidId, Status, Role, Comment ) ' . 'VALUES ( :CharacterId, :UserId, :RaidId, :Status, :Role, :Comment )');
                $UpdateQuery->bindValue(':CharacterId', 0, PDO::PARAM_INT);
                $UpdateQuery->bindValue(':Role', '', PDO::PARAM_STR);
                $UpdateQuery->bindValue(':Status', 'undecided', PDO::PARAM_STR);
            }
            $UpdateQuery->bindValue(':RaidId', $RaidId, PDO::PARAM_INT);
            $UpdateQuery->bindValue(':UserId', $UserId, PDO::PARAM_INT);
            $UpdateQuery->bindValue(':Comment', requestToXML($aRequest['comment'], ENT_COMPAT, 'UTF-8'), PDO::PARAM_STR);
            $UpdateQuery->execute();
        }
        // reload calendar
        $RaidQuery = $Connector->prepare('SELECT Start FROM `' . RP_TABLE_PREFIX . 'Raid` WHERE RaidId = :RaidId LIMIT 1');
        $RaidQuery->bindValue(':RaidId', $RaidId, PDO::PARAM_INT);
        $RaidData = $RaidQuery->fetchFirst();
        $Session = Session::get();
        $ShowMonth = isset($Session['Calendar']) && isset($Session['Calendar']['month']) ? $Session['Calendar']['month'] : intval(substr($RaidData['Start'], 5, 2));
        $ShowYear = isset($Session['Calendar']) && isset($Session['Calendar']['year']) ? $Session['Calendar']['year'] : intval(substr($RaidData['Start'], 0, 4));
        msgQueryCalendar(prepareCalRequest($ShowMonth, $ShowYear));
    } else {
        $Out = Out::getInstance();
        $Out->pushError(L('AccessDenied'));
    }
}
function msgRaidDelete($aRequest)
{
    if (validRaidlead()) {
        $Connector = Connector::getInstance();
        // Call plugins
        $RaidId = intval($aRequest['id']);
        PluginRegistry::ForEachPlugin(function ($PluginInstance) use($RaidId) {
            $PluginInstance->onRaidRemove($RaidId);
        });
        do {
            // Delete raid
            $Connector->beginTransaction();
            $DeleteRaidQuery = $Connector->prepare('DELETE FROM `' . RP_TABLE_PREFIX . 'Raid` WHERE RaidId = :RaidId LIMIT 1');
            $DeleteRaidQuery->bindValue(':RaidId', $aRequest['id'], PDO::PARAM_INT);
            if (!$DeleteRaidQuery->execute()) {
                $Connector->rollBack();
                return;
                // ### return, error ###
            }
            // Delete attendance
            $DeleteAttendanceQuery = $Connector->prepare('DELETE FROM `' . RP_TABLE_PREFIX . 'Attendance` WHERE RaidId = :RaidId');
            $DeleteAttendanceQuery->bindValue(':RaidId', $aRequest['id'], PDO::PARAM_INT);
            if (!$DeleteAttendanceQuery->execute()) {
                $Connector->rollBack();
                return;
                // ### return, error ###
            }
        } while (!$Connector->commit());
        $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'));
    }
}
Exemple #3
0
     msgLogin($_REQUEST);
     break;
 case "logout":
     msgLogout($_REQUEST);
     break;
 case "raid_attend":
     msgRaidAttend($_REQUEST);
     break;
 case "raid_create":
     msgRaidCreate($_REQUEST);
     break;
 case "query_calendar":
     $Settings = Settings::getInstance();
     lockOldRaids($Settings["LockRaids"]["IntValue"]);
     purgeOldRaids($Settings["PurgeRaids"]["IntValue"]);
     msgQueryCalendar($_REQUEST);
     break;
 case "raid_list":
     $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);
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'));
    }
}
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'));
    }
}