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')); } }
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')); } }