-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetUserCards.php
More file actions
48 lines (37 loc) · 1.14 KB
/
getUserCards.php
File metadata and controls
48 lines (37 loc) · 1.14 KB
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
<?php
require_once 'debugSettings.php';
require_once '../dbinfo/dbcred.php';
require_once 'DBSessionHandler.php';
$handler = new DBSessionHandler();
session_set_save_handler($handler);
session_start();
header('Content-Type: application/json');
if ( !isset($_SESSION["loggedin"]) || $_SESSION["loggedin"] !== true ) {
$status = "Unauthenticated User";
$response = array('error' => $status);
echo json_encode($response);
exit;
}
require_once 'CardManager.php';
require_once 'BingoCard.php';
require_once 'gameManager.php';
$cardManager = new CardManager();
$cards = $cardManager->getCards($_SESSION['email']);
if(isset($_GET['allnew']) || !$cards){
// generate 3 new cards
if($cards){
$cardManager->deleteCards($_SESSION['email']);
}
for($i = 0; $i < 3; $i++){
$newCard = new BingoCard();
$cardManager->addCard($newCard, $_SESSION['email']);
}
}
if(isset($_GET['replace'])){
if($_GET['replace'] == 1 || $_GET['replace'] == 2 || $_GET['replace'] == 3){
$cardManager->replace($_GET['replace'], $_SESSION['email']);
}
}
$cards = $cardManager->getCards($_SESSION['email']);
echo json_encode($cards);
?>