-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsell.php
55 lines (39 loc) · 958 Bytes
/
sell.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
<?php
session_start();
require_once "storage/UserStorage.php";
require_once "storage/CardStorage.php";
require_once "auth.php";
$userStorage = new UserStorage();
$cardStorage = new CardStorage();
if (!$auth->is_authenticated()) {
header('Location: index.php');
exit();
}
$id = isset($_GET["id"]) ? $_GET["id"] : '';
if (empty($id)) {
header("Location: index.php");
exit();
}
//Id of card to sell
$id = $_GET["id"];
//Find card by card id
$card = $cardStorage->findById($id);
//Handle if not found
if (empty($id)) {
header('Location: index.php');
exit();
}
//Get current user
$uid = $auth->authenticated_user()["id"];
$user = $userStorage->findById($uid);
//Update credits
$user["credits"] += $card["price"] * 0.9;
//DOESNT WORK FOR SOME REASON
$userStorage->update($uid, $user);
//Give card to admin
$card["owner"] = "admin";
//Update card
$cardStorage->update($id, $card);
header('Location: account.php');
exit();
?>