|
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 | | - |
50 | 1 | <?php |
51 | 2 | include '../connection/connection.php'; |
52 | | - |
| 3 | +session_start(); |
53 | 4 | if (!isset($_SESSION['account_id'])) { |
54 | 5 | echo "<p>You need to log in to view your cart.</p>"; |
55 | 6 | exit(); |
|
72 | 23 | echo '<script>alert("Selected products removed successfully.");</script>'; |
73 | 24 | } |
74 | 25 |
|
| 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 | + |
75 | 79 | // Query untuk mendapatkan data keranjang |
76 | 80 | $query = "SELECT |
77 | 81 | c.cart_id, |
|
120 | 124 | // Tombol untuk menghapus produk yang dipilih |
121 | 125 | echo '<button type="submit" name="remove_selected">Remove Selected</button>'; |
122 | 126 |
|
| 127 | +// Tombol untuk memproses pembayaran |
| 128 | +echo '<button type="submit" name="process_payment">Process Payment</button>'; |
| 129 | + |
123 | 130 | // Tombol untuk menghitung total harga berdasarkan produk yang dipilih |
124 | 131 | echo '<button type="button" onclick="calculateTotal()">Calculate Total</button>'; |
125 | 132 | echo '</form>'; |
126 | 133 |
|
127 | 134 | oci_free_statement($stid); |
128 | 135 | oci_close($conn); |
129 | 136 | ?> |
130 | | - |
131 | 137 | <!-- Tambahkan Total Harga --> |
132 | 138 | <h3>Total Price: $<span id="total-price">0.00</span></h3> |
133 | 139 |
|
|
0 commit comments