Skip to content

Commit 4aa1084

Browse files
committed
yayaya
1 parent 234d77b commit 4aa1084

4 files changed

Lines changed: 171 additions & 54 deletions

File tree

assets/databases/table

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
tortoise glow liar spread junior notice barely trumpet valley law fox tip
2-
diet wine ivory spice industry satisfy sun silly subway prefer shiver similar
1+
flag want royal brand orbit remember focus boy delay blossom blue also
32

43
CREATE TABLE account (
54
account_id NUMBER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
@@ -30,3 +29,13 @@ CREATE TABLE cart (
3029
FOREIGN KEY (product_id) REFERENCES products(product_id),
3130
CONSTRAINT unique_account_product UNIQUE (account_id, product_id)
3231
);
32+
33+
CREATE TABLE LIBRARY (
34+
library_id NUMBER GENERATED BY DEFAULT AS IDENTITY
35+
product_Id NUMBER(8) NOT NULL,
36+
account_id NUMBER(12) NOT NULL,
37+
purchase_date TIMESTAMP WITH LOCAL TIME ZONE,
38+
FOREIGN KEY (product_id) REFERENCES products(product_id),
39+
FOREIGN KEY (account_id) REFERENCES account(account_id),
40+
CONSTRAINT unique_cart UNIQUE (account_id, product_id)
41+
);

dashboard.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
<a class="nav-link" href="features/store/store.php">Store</a>
2929
</li>
3030
<li class="nav-item">
31-
<a class="nav-link" href="#">Library</a>
31+
<a class="nav-link" href="features/library/library.php">Library</a>
3232
</li>
3333
<li class="nav-item">
3434
<?php if ($isLoggedIn): ?>

features/cart/cart.php

Lines changed: 57 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,6 @@
1-
<!DOCTYPE html>
2-
<html lang="en">
3-
<head>
4-
<meta charset="UTF-8">
5-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6-
<title>Home Page</title>
7-
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
8-
</head>
9-
<body>
10-
<?php
11-
// Start session
12-
session_start();
13-
14-
// Check if user is logged in
15-
$isLoggedIn = isset($_SESSION['username']);
16-
?>
17-
18-
<!-- Navbar -->
19-
<nav class="navbar navbar-expand-lg navbar-light">
20-
<div class="container">
21-
<a class="navbar-brand" href="#">ORON</a>
22-
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
23-
<span class="navbar-toggler-icon"></span>
24-
</button>
25-
<div class="collapse navbar-collapse" id="navbarNav">
26-
<ul class="navbar-nav ms-auto">
27-
<li class="nav-item">
28-
<a class="nav-link" href="../store/store.php">Store</a>
29-
</li>
30-
<li class="nav-item">
31-
<a class="nav-link" href="#">Library</a>
32-
</li>
33-
<li class="nav-item">
34-
<?php if ($isLoggedIn): ?>
35-
<a class="nav-link" href="../profile/profile.php"><?php echo htmlspecialchars($_SESSION['username']); ?></a>
36-
<?php else: ?>
37-
<a class="nav-link" href="../login/login.php">Profile</a>
38-
<?php endif; ?>
39-
</li>
40-
<li class="nav-item">
41-
<a class="nav-link" href="../cart/cart.php">Cart</a>
42-
</li>
43-
</ul>
44-
</div>
45-
</div>
46-
</nav>
47-
</body>
48-
</html>
49-
501
<?php
512
include '../connection/connection.php';
52-
3+
session_start();
534
if (!isset($_SESSION['account_id'])) {
545
echo "<p>You need to log in to view your cart.</p>";
556
exit();
@@ -72,6 +23,59 @@
7223
echo '<script>alert("Selected products removed successfully.");</script>';
7324
}
7425

26+
// Handle payment
27+
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['process_payment'])) {
28+
if (isset($_POST['selected_products'])) {
29+
foreach ($_POST['selected_products'] as $productToPay) {
30+
// Query untuk mendapatkan harga current_price
31+
$priceQuery = "SELECT current_price FROM products WHERE product_id = :product_id";
32+
$priceStmt = oci_parse($conn, $priceQuery);
33+
oci_bind_by_name($priceStmt, ":product_id", $productToPay);
34+
oci_execute($priceStmt);
35+
$priceRow = oci_fetch_assoc($priceStmt);
36+
$currentPrice = $priceRow['CURRENT_PRICE'];
37+
oci_free_statement($priceStmt);
38+
39+
// Jika current_price = 0, langsung masukkan ke library
40+
if ($currentPrice == 0) {
41+
// Cek apakah game sudah ada di library
42+
$checkQuery = "SELECT COUNT(*) AS GAME_COUNT FROM library WHERE account_id = :account_id AND product_id = :product_id";
43+
$checkStmt = oci_parse($conn, $checkQuery);
44+
oci_bind_by_name($checkStmt, ":account_id", $accountId);
45+
oci_bind_by_name($checkStmt, ":product_id", $productToPay);
46+
oci_execute($checkStmt);
47+
$row = oci_fetch_assoc($checkStmt);
48+
oci_free_statement($checkStmt);
49+
50+
if ($row['GAME_COUNT'] > 0) {
51+
echo '<script>alert("You already own this game.");</script>';
52+
} else {
53+
// Jika belum ada, tambahkan ke library
54+
$insertQuery = "INSERT INTO library (library_id, product_id, account_id, purchase_date)
55+
VALUES (library_seq.NEXTVAL, :product_id, :account_id, SYSTIMESTAMP)";
56+
$insertStmt = oci_parse($conn, $insertQuery);
57+
oci_bind_by_name($insertStmt, ":product_id", $productToPay);
58+
oci_bind_by_name($insertStmt, ":account_id", $accountId);
59+
oci_execute($insertStmt);
60+
oci_free_statement($insertStmt);
61+
62+
// Hapus dari keranjang
63+
$deleteQuery = "DELETE FROM cart WHERE account_id = :account_id AND product_id = :product_id";
64+
$deleteStmt = oci_parse($conn, $deleteQuery);
65+
oci_bind_by_name($deleteStmt, ":account_id", $accountId);
66+
oci_bind_by_name($deleteStmt, ":product_id", $productToPay);
67+
oci_execute($deleteStmt);
68+
oci_free_statement($deleteStmt);
69+
70+
echo '<script>alert("Free product added to your library.");</script>';
71+
}
72+
}
73+
}
74+
} else {
75+
echo '<script>alert("No products selected for payment.");</script>';
76+
}
77+
}
78+
7579
// Query untuk mendapatkan data keranjang
7680
$query = "SELECT
7781
c.cart_id,
@@ -120,14 +124,16 @@
120124
// Tombol untuk menghapus produk yang dipilih
121125
echo '<button type="submit" name="remove_selected">Remove Selected</button>';
122126

127+
// Tombol untuk memproses pembayaran
128+
echo '<button type="submit" name="process_payment">Process Payment</button>';
129+
123130
// Tombol untuk menghitung total harga berdasarkan produk yang dipilih
124131
echo '<button type="button" onclick="calculateTotal()">Calculate Total</button>';
125132
echo '</form>';
126133

127134
oci_free_statement($stid);
128135
oci_close($conn);
129136
?>
130-
131137
<!-- Tambahkan Total Harga -->
132138
<h3>Total Price: $<span id="total-price">0.00</span></h3>
133139

features/library/library.php

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>My Library</title>
7+
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
8+
</head>
9+
<body>
10+
<?php
11+
include '../connection/connection.php';
12+
session_start();
13+
14+
// Check if user is logged in
15+
$isLoggedIn = isset($_SESSION['username']);
16+
?>
17+
<nav class="navbar navbar-expand-lg navbar-light">
18+
<div class="container">
19+
<a class="navbar-brand" href="#">ORON</a>
20+
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
21+
<span class="navbar-toggler-icon"></span>
22+
</button>
23+
<div class="collapse navbar-collapse" id="navbarNav">
24+
<ul class="navbar-nav ms-auto">
25+
<li class="nav-item">
26+
<a class="nav-link" href="features/store/store.php">Store</a>
27+
</li>
28+
<li class="nav-item">
29+
<a class="nav-link" href="features/library/library.php">Library</a>
30+
</li>
31+
<li class="nav-item">
32+
<?php if ($isLoggedIn): ?>
33+
<a class="nav-link" href="features/profile/profile.php"><?php echo htmlspecialchars($_SESSION['username']); ?></a>
34+
<?php else: ?>
35+
<a class="nav-link" href="features/login/login.php">Profile</a>
36+
<?php endif; ?>
37+
</li>
38+
<li class="nav-item">
39+
<a class="nav-link" href="features/cart/cart.php">Cart</a>
40+
</li>
41+
</ul>
42+
</div>
43+
</div>
44+
</nav>
45+
<div>
46+
<table>
47+
<thead>
48+
<tr>
49+
<th>Game Name</th>
50+
<th>Purchase Date</th>
51+
</tr>
52+
</thead>
53+
<tbody>
54+
<?php
55+
56+
57+
if (!isset($_SESSION['account_id'])) {
58+
echo "<tr><td colspan='3'>Please log in to view your library.</td></tr>";
59+
exit();
60+
}
61+
62+
// Get the account_id from session
63+
$accountId = $_SESSION['account_id'];
64+
65+
// Query to get library data for the user
66+
$query = "SELECT
67+
l.library_id,
68+
p.name AS game_name,
69+
TO_CHAR(l.purchase_date, 'DD-Mon-YYYY HH24:MI') AS purchase_date
70+
FROM
71+
library l
72+
JOIN
73+
products p ON l.product_id = p.product_id
74+
WHERE
75+
l.account_id = :account_id
76+
ORDER BY
77+
l.purchase_date DESC";
78+
79+
// Prepare and execute the query
80+
$stid = oci_parse($conn, $query);
81+
oci_bind_by_name($stid, ":account_id", $accountId);
82+
oci_execute($stid);
83+
84+
// Fetch and display results
85+
while (($row = oci_fetch_array($stid, OCI_ASSOC)) != false) {
86+
echo "<tr>";
87+
echo "<td>" . htmlspecialchars($row['GAME_NAME']) . "</td>";
88+
echo "<td>" . htmlspecialchars($row['PURCHASE_DATE']) . "</td>";
89+
echo "</tr>";
90+
}
91+
92+
// If no games are found
93+
// Free resources and close connection
94+
oci_free_statement($stid);
95+
oci_close($conn);
96+
?>
97+
</tbody>
98+
</table>
99+
</div>
100+
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
101+
</body>
102+
</html>

0 commit comments

Comments
 (0)