This repository was archived by the owner on Nov 3, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.php
More file actions
108 lines (62 loc) · 2.02 KB
/
api.php
File metadata and controls
108 lines (62 loc) · 2.02 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
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
106
107
108
<?php
session_start();
$dbConnection = new Mongo();
//$dbConnection = new Mongo();
$users = $dbConnection->playability->users;
$unplayed = $dbConnection->playability->unplayed;
$unbeaten = $dbConnection->playability->unbeaten;
$beaten = $dbConnection->playability->beaten;
$abandoned = $dbConnection->playability->abandoned;
$quips = $dbConnection->playability->quips;
$action = $_POST['action'];
//session_start();
function getGames($type, $category) {
$games = '';
foreach ($type as $game) {
$name = $game['name'];
$platform = $game['platform'];
$note = $game['note'];
$games .= " <li>" . $name . " <a href=\"remove.php?id=" . $game['_id'] . "&category=" . $category . "\"><span class='deleteButton'>✖</span></a> <span>" . $platform . "</span><span>" . $note . "</span></li>";
echo $games;
}
}
if($action == 'add'){
if(addGame()){
echo "success";
}else{
echo "fail";
};
};
if($action == 'remove'){
if(removeGame()){
echo "success";
}else{
echo "fail";
};
};
if($action == 'read'){
getGames($_POST['type'], $_POST['category']);
};
function addGame(){
global $dbConnection;
$name = Trim(stripslashes($_POST['name']));
$platform = Trim(stripslashes($_POST['platform']));
$note = Trim(stripslashes($_POST['note']));
$category = $_POST['category'];
$user = $_SESSION['username'];
$game = iterator_to_array($dbConnection->playability->$category->find(array('name'=>$name, 'user'=>$user)));
if(!empty($game)){
return false;
};
$dbConnection->playability->$category->insert(array('name' => $name, 'platform' => $platform, 'note' => $note, 'user' => $user));
return true;
};
function removeGame(){
global $dbConnection;
$name = Trim(stripslashes($_POST['name']));
$category = $_POST['category'];
$user = $_SESSION['username'];
$dbConnection->playability->$category->remove(array('name' => $name, 'user' => $user));
return true;
};
?>