|
| 1 | +<?php |
| 2 | + //Use same config as bot |
| 3 | + require_once("config.php"); |
| 4 | + |
| 5 | + // Establish mysql connection. |
| 6 | + $db = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); |
| 7 | + $db->set_charset('utf8mb4'); |
| 8 | + |
| 9 | + // Error connecting to db. |
| 10 | + if ($db->connect_errno) { |
| 11 | + echo("Failed to connect to Database!\n"); |
| 12 | + die("Connection Failed: " . $db->connect_error); |
| 13 | + } |
| 14 | + |
| 15 | + $sql = "SELECT raids.*, |
| 16 | + UNIX_TIMESTAMP(raids.end_time) AS ts_end, |
| 17 | + UNIX_TIMESTAMP(raids.start_time) AS ts_start, |
| 18 | + UNIX_TIMESTAMP(raids.end_time)-UNIX_TIMESTAMP(NOW()) AS t_left, |
| 19 | + pokemon.raid_level, |
| 20 | + pokemon.pokedex_id, |
| 21 | + pokemon.pokemon_name, |
| 22 | + attendance.id AS interest, |
| 23 | + SUM(CASE WHEN attendance.cancel=FALSE AND attendance.raid_done=FALSE THEN 1 ELSE 0 END) AS count, |
| 24 | + SUM(CASE WHEN attendance.cancel=FALSE and attendance.raid_done=FALSE THEN attendance.extra_mystic ELSE 0 END) AS extra_mystic, |
| 25 | + SUM(CASE WHEN attendance.cancel=FALSE and attendance.raid_done=FALSE THEN attendance.extra_valor ELSE 0 END) AS extra_valor, |
| 26 | + SUM(CASE WHEN attendance.cancel=FALSE and attendance.raid_done=FALSE THEN attendance.extra_instinct ELSE 0 END) AS extra_instinct, |
| 27 | + SUM(CASE WHEN attendance.cancel=FALSE and attendance.raid_done=FALSE THEN (attendance.extra_mystic+attendance.extra_valor+attendance.extra_instinct) ELSE 0 END) AS total_extras |
| 28 | + FROM raids |
| 29 | + LEFT JOIN pokemon ON pokemon.pokedex_id=raids.pokemon |
| 30 | + LEFT JOIN attendance ON attendance.raid_id=raids.id |
| 31 | + WHERE raids.end_time > NOW() |
| 32 | + AND raids.end_time < NOW() + INTERVAL 96 hour |
| 33 | + GROUP BY raids.gym_name |
| 34 | + ORDER BY raids.end_time ASC"; |
| 35 | + |
| 36 | + $result = $db->query($sql); |
| 37 | + |
| 38 | + if (!$result) { |
| 39 | + echo "An SQL error occured"; |
| 40 | + exit; |
| 41 | + } |
| 42 | + |
| 43 | + $rows = array(); |
| 44 | + while($raid = $result->fetch_assoc()) { |
| 45 | + $rows[] = $raid; |
| 46 | + } |
| 47 | + |
| 48 | + print json_encode($rows); |
| 49 | + |
| 50 | + |
| 51 | +?> |
0 commit comments