forked from rpiambulance/website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.get_game_info.php
105 lines (83 loc) · 3.12 KB
/
.get_game_info.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php
//header("Access-Control-Allow-Origin: *");
//header("Content-Type: application/json; charset=UTF-8");
if($_SERVER['REQUEST_METHOD'] === 'POST') {
session_id($_POST['session_id']);
session_start();
require_once ".db_config.php";
$connection = new PDO("mysql:host=$dhost;dbname=$dname", $duser, $dpassword);
$connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
if(!isset($dname)) {
$dname = 'ambulanc_web';
}
if(!isset($_POST['game_id'])) {
return;
}
$username = $_SESSION['username'];
$gameId = $_POST['game_id'];
$statement = $connection->prepare("SELECT * FROM members WHERE username=:username");
$statement->bindParam(':username', $username);
$statement->execute();
$memberInfo = $statement->fetchAll(PDO::FETCH_ASSOC)[0];
$memberId = $memberInfo['id'];
// Selecting Database
$connection->exec("USE `$dname`");
$results = array();
$sql = "SELECT *, UNIX_TIMESTAMP(start) AS start_epoch, UNIX_TIMESTAMP(end) AS end_epoch FROM games WHERE id = :gameId";
$statement=$connection->prepare($sql);
$statement->bindValue(':gameId', $gameId);
$statement->execute();
$results['game'] = $statement->fetchAll(PDO::FETCH_ASSOC)[0];
$sql = "SELECT
c.memberid,
c.position,
m.first_name,
m.last_name,
(c.memberId = :memberId) as is_viewing_member,
CONCAT(SUBSTRING(m.first_name, 1, 1), \". \", m.last_name) AS ambulance_name
FROM
games_crews c,
members m
WHERE
c.memberid = m.id AND
c.gameid = :gameId
ORDER BY
c.id ASC
";
$statement=$connection->prepare($sql);
$statement->bindValue(':gameId', $gameId);
$statement->bindValue(':memberId', $memberId);
$statement->execute();
$results['attendees'] = $statement->fetchAll(PDO::FETCH_ASSOC);
$sql = "SELECT id, position FROM games_crews WHERE memberid = :memberId AND gameid = :gameId";
$statement=$connection->prepare($sql);
$statement->bindValue(':gameId', $gameId);
$statement->bindValue(':memberId', $memberId);
$statement->execute();
$results['alreadySignedUp'] = ($statement->rowCount() > 0);
if($results['alreadySignedUp'] > 0) {
$results['currentPosition'] = $statement->fetchAll(PDO::FETCH_ASSOC)[0]['position'];
} else {
$results['currentPosition'] = null;
}
$results['eligiblePositions'] = [];
if($memberInfo['ees'] == 1) {
$results['eligiblePositions'][] = 'ees';
}
if($memberInfo['cctrainer'] == 1 || $memberInfo['crewchief'] == 1 || $memberInfo['backupcc'] == 1 || $memberInfo['firstresponsecc'] == 1) {
$results['eligiblePositions'][] = 'cc';
}
if($memberInfo['drivertrainer'] == 1 || $memberInfo['driver'] == 1 || $memberInfo['backupdriver'] == 1) {
$results['eligiblePositions'][] = 'driver';
}
if($memberInfo['attendant'] == 1 || $memberInfo['cctrainer'] == 1 || $memberInfo['crewchief'] == 1 ||
$memberInfo['backupcc'] == 1 || $memberInfo['drivertrainer'] == 1 || $memberInfo['driver'] == 1 ||
$memberInfo['backupdriver'] == 1) {
$results['eligiblePositions'][] = 'attendant';
}
$results['eligiblePositions'][] = 'observer';
$results['success'] = true;
$json=json_encode($results);
echo($json);
}
?>