Repository navigation
Expand file tree
/
Copy pathshop.php
More file actions
199 lines (178 loc) · 6.34 KB
/
Copy pathshop.php
File metadata and controls
199 lines (178 loc) · 6.34 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
<?php
session_start();
require_once "config.php";
$prices = [2, 70, 10, 250, 150, 350, 1000, 900, 500];
if ($_SERVER["REQUEST_METHOD"] === "POST" && isset($_POST['item_index'])) {
header('Content-Type: application/json');
if (!isset($_SESSION['id'])) {
echo json_encode(["success" => false, "message" => "You must login first!"]);
exit();
}
$user_id = (int)$_SESSION['id'];
$item_index = (int)$_POST['item_index'];
if ($item_index < 0 || $item_index >= count($prices)) {
echo json_encode(["success" => false, "message" => "Unknown item."]);
exit();
}
$item_price = $prices[$item_index];
$user_role = $_SESSION['role'] ?? 'user';
if ($user_role === 'admin') {
echo json_encode(["success" => true, "new_money" => -1, "message" => "Purchase successful! (Admin Mode)"]);
exit();
}
$query = mysqli_query($conn, "SELECT money FROM users WHERE id = $user_id");
if ($query && mysqli_num_rows($query) > 0) {
$row = mysqli_fetch_assoc($query);
$current_money = (int)$row['money'];
if ($current_money < $item_price) {
echo json_encode(["success" => false, "message" => "You do not have enough clams!"]);
exit();
}
$new_money = $current_money - $item_price;
$update = mysqli_query($conn, "UPDATE users SET money = $new_money WHERE id = $user_id");
if ($update) {
$_SESSION['money'] = $new_money;
echo json_encode(["success" => true, "new_money" => $new_money, "message" => "Purchase successful!"]);
exit();
}
}
echo json_encode(["success" => false, "message" => "Database error occurred."]);
exit();
}
$money = isset($_SESSION['money']) ? (int) $_SESSION['money'] : 0;
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
<title>Document</title>
<style>
.money-value {
color: #ffffff !important;
}
</style>
<script>
window.currentUserRole = <?php echo json_encode($_SESSION['role'] ?? 'guest'); ?>;
</script>
</head>
<body>
<img class="bg-image" src="video/Omori background purple - Imgur.gif" alt="Background">
<header>
<div class="top-bar">
<a href="index.php" class="white">
<h1 class="white">OMORI SHOP</h1>
</a>
<div class="money" aria-label="Current clams">
<span class="money-value"><?php echo number_format($money); ?> clams</span>
</div>
<a href="index.php" class="white">
<button><b>Home</b></button>
</a>
<a href="shop.php" class="white">
<button><b>shop</b></button>
</a>
<a href="acc.php" class="white">
<button><b>Login</b></button>
</a>
</div>
</header>
<main class="center">
<div class="title">
<h1><b>WELCOME TO THE SHOP !</b></h1>
</div>
<br>
<div class="cent">
<div class="centrer">
<img src="video/+++++++.gif" alt="Game Image" width="60%" >
</div>
<br>
<br>
<div class="border">
<div class="black-box">
<p>Here you can find all the items you need to help you on your journey in the world of Omori</p>
<p><b>enjoy!!</b></p>
</div>
</div>
<br>
<table>
<tr>
<th>Image</th>
<th>Item name and description</th>
<th>Price</th>
<th>quantity</th>
<th>Buy</th>
</tr>
<tr>
<td><img src="img/TOFU.webp" alt="TOFU" width="100%"></td>
<td>TOFU <br>Soft cardboard, basically.Heals 5 HEART.</td>
<td>2 clams</td>
<td class="count">25</td>
<td><button class="dec" ><b>BUY</b></button></td>
</tr>
<tr>
<td><img src="img/BANANA_SMOOTHIE.webp" alt="BANANA_SMOOTHIE" width="100%"></td>
<td>BANANA SMOOTHIE <br> A little bland, but it does the job.
Heals 20 JUICE to all friends.</td>
<td>70 clams</td>
<td class="count">10</td>
<td><button class="dec"><b>BUY</b></button></td>
</tr>
<tr>
<td><img src="img/BREAD.webp" alt="BREAD" width="100%"></td>
<td>BREAD <br> A slice of life.
Heals 60 HEART.</td>
<td>10 clams</td>
<td class="count">10</td>
<td><button class="dec"><b>BUY</b></button></td>
</tr>
<tr>
<td><img src="img/TOMATO.webp" alt="TOMATO" width="100%"></td>
<td>TOMATO <br> You say tomato, I say tomato.
Heals 100 HEART and 50 JUICE.</td>
<td>250 clams</td>
<td class="count">7</td>
<td><button class="dec"><b>BUY</b></button></td>
</tr>
<tr>
<td><img src="img/TASTY_SODA.webp" alt="TASTY_SODA" width="100%"></td>
<td>TASTY SODA <br>Tasty soda for thirsty people.
Heals 50% of JUICE.</td>
<td>150 clams</td>
<td class="count">15</td>
<td><button class="dec"><b>BUY</b></button></td>
</tr>
<tr>
<td><img src="img/COOL_NOODLE.webp" alt="COOL_NOODLE" width="100%"></td>
<td>COOL NOODLE <br> It's a POOL NOODLE. But cooler.</td>
<td>350 clams</td>
<td class="count">5</td>
<td><button class="dec"><b>BUY</b></button></td>
</tr>
<tr>
<td><img src="img/RED_KNIFE.webp" alt="RED_KNIFE" width="100%"></td>
<td>RED KNIFE <br> A shiny new knife. You can see something in the blade.</td>
<td>1000 clams</td>
<td class="count">5</td>
<td><button class="dec"><b>BUY</b></button></td>
</tr>
<tr>
<td><img src="img/BASEBALL_BAT.webp" alt="BASEBALL_BAT" width="100%"></td>
<td>BASEBALL BAT <br>AUBREY's ultimate weapon.</td>
<td>900 clams</td>
<td class="count">5</td>
<td><button class="dec"><b>BUY</b></button></td>
</tr>
<tr>
<td><img src="img/FRYING_PAN.webp" alt="FRYING_PAN" width="100%"></td>
<td>FRYING PAN <br>Less effective than a microwave. SNACKS will restore more HEART in battle.</td>
<td>500 clams</td>
<td class="count">2</td>
<td><button class="dec"><b>BUY</b></button></td>
</table>
</div>
</main>
<script src="index.js"></script>
</body>
</html>