mirror of
https://codeberg.org/ThisIsMiseryy/techstore
synced 2026-05-14 14:52:04 +00:00
Spostamento in cartella src per migliore organizzazione
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
session_start();
|
||||
include 'db_conf.php';
|
||||
|
||||
// Query per ottenere tutti i prodotti
|
||||
$sql = "SELECT p.ProductID, p.ProductName, c.Name AS 'CategoryName', p.Description, p.Price, p.StockQuantity, p.ImagePath FROM Products p JOIN Categories c ON p.CategoryID=c.CategoryID";
|
||||
$result = $conn->query($sql);
|
||||
|
||||
if ($result === false) {
|
||||
die("Errore nella query: " . $conn->error);
|
||||
}
|
||||
?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="it">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Il mio account - TechStore</title>
|
||||
<link rel="stylesheet" href="assets/style.css">
|
||||
<script src="assets/js/cart.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<header style="display: flex; justify-content: space-between; align-items: center; padding: 10px; background-color: #f2f2f2; border-bottom: 1px solid #ddd;">
|
||||
<div id="logo" style="font-size: 24px; font-weight: bold;"><a href="index.php"><img src="img/logo.png" alt="Logo TechStore" height="32px"></a></div>
|
||||
<div>
|
||||
<a href="cart.php"><button style="margin-left: 10px; padding: 8px 16px; background-color: #007bff; color: white; border: none; border-radius: 4px; cursor: pointer;">Carrello</button></a>
|
||||
<?php if (isset($_SESSION['name'])): ?>
|
||||
<a href="logout.php"><button style="margin-left: 10px; padding: 8px 16px; background-color: #dc3545; color: white; border: none; border-radius: 4px; cursor: pointer;">Logout</button></a>
|
||||
<span style="margin-left: 10px;">Benvenuto, <?php echo htmlspecialchars($_SESSION['name']); ?></span>
|
||||
<?php else: ?>
|
||||
<a href="login.php"><button style="margin-left: 10px; padding: 8px 16px; background-color: #28a745; color: white; border: none; border-radius: 4px; cursor: pointer;">Accesso</button></a>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<?php if (isset($_SESSION['name'])): ?>
|
||||
<div class="account-layout">
|
||||
<div class="my-sidebar">
|
||||
<ul>
|
||||
<li><a href="account.php">Il mio account</a></li>
|
||||
<li><a href="orders.php">I miei ordini</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="my-container">
|
||||
<h1>Account di <?php echo htmlspecialchars($_SESSION['name']); ?><?php if ($_SESSION['role'] == 'admin') { echo ' (Admin)'; } ?></h1>
|
||||
<p><strong>Nome completo:</strong> <?php echo htmlspecialchars($_SESSION['name']) . ' ' . htmlspecialchars($_SESSION['surname']); ?></p>
|
||||
<br>
|
||||
<a href="deleteAccount.php" style="padding: 8px 16px; background-color: #dc3545; color: white; border: none; border-radius: 4px; cursor: pointer;">Elimina account</a>
|
||||
<br><br>
|
||||
</div>
|
||||
</div>
|
||||
<?php else: ?>
|
||||
<?php header('Location: login.php'); ?>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php $conn->close(); ?>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,58 @@
|
||||
function addToCart(productId, productName, price) {
|
||||
// Leggi il carrello dal cookie
|
||||
let cart = [];
|
||||
const cookieValue = document.cookie.split('; ').find(row => row.startsWith('cart='));
|
||||
if (cookieValue) {
|
||||
cart = JSON.parse(decodeURIComponent(cookieValue.split('=')[1]));
|
||||
}
|
||||
|
||||
// Controlla se il prodotto è già nel carrello
|
||||
const existingItem = cart.find(item => item.id === productId);
|
||||
if (existingItem) {
|
||||
existingItem.quantity += 1;
|
||||
} else {
|
||||
cart.push({
|
||||
id: productId,
|
||||
name: productName,
|
||||
price: price,
|
||||
quantity: 1
|
||||
});
|
||||
}
|
||||
|
||||
// Salva il carrello nel cookie (scadenza 7 giorni)
|
||||
const date = new Date();
|
||||
date.setTime(date.getTime() + (7 * 24 * 60 * 60 * 1000));
|
||||
const expires = "expires=" + date.toUTCString();
|
||||
document.cookie = "cart=" + encodeURIComponent(JSON.stringify(cart)) + "; " + expires + "; path=/";
|
||||
|
||||
alert('Prodotto aggiunto al carrello!');
|
||||
}
|
||||
|
||||
function removeFromCart(index) {
|
||||
let cart = [];
|
||||
const cookieValue = document.cookie.split('; ').find(row => row.startsWith('cart='));
|
||||
if (cookieValue) {
|
||||
cart = JSON.parse(decodeURIComponent(cookieValue.split('=')[1]));
|
||||
}
|
||||
|
||||
cart.splice(index, 1);
|
||||
|
||||
const date = new Date();
|
||||
date.setTime(date.getTime() + (7 * 24 * 60 * 60 * 1000));
|
||||
const expires = "expires=" + date.toUTCString();
|
||||
|
||||
if (cart.length > 0) {
|
||||
document.cookie = "cart=" + encodeURIComponent(JSON.stringify(cart)) + "; " + expires + "; path=/";
|
||||
} else {
|
||||
document.cookie = "cart=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/";
|
||||
}
|
||||
|
||||
location.reload();
|
||||
}
|
||||
|
||||
function clearCart() {
|
||||
if (confirm('Sei sicuro di voler svuotare il carrello?')) {
|
||||
document.cookie = "cart=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/";
|
||||
location.reload();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,322 @@
|
||||
body{
|
||||
font-family: Arial, Helvetica, sans-serif;
|
||||
}
|
||||
.products-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
|
||||
gap: 20px;
|
||||
padding: 20px;
|
||||
}
|
||||
.product-card {
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 8px;
|
||||
padding: 16px;
|
||||
text-align: center;
|
||||
background-color: #fff;
|
||||
}
|
||||
.product-card img {
|
||||
max-width: 100%;
|
||||
height: auto;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
.product-card h3 {
|
||||
margin: 10px 0;
|
||||
font-size: 18px;
|
||||
}
|
||||
.product-card p {
|
||||
margin: 5px 0;
|
||||
color: #666;
|
||||
}
|
||||
.product-card button {
|
||||
padding: 8px 16px;
|
||||
background-color: #007bff;
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
margin-top: 10px;
|
||||
}
|
||||
.product-card button:hover {
|
||||
background-color: #0056b3;
|
||||
}
|
||||
|
||||
/* Stili per il form di login */
|
||||
form {
|
||||
max-width: 400px;
|
||||
margin: 50px auto;
|
||||
padding: 20px;
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 8px;
|
||||
background-color: #f9f9f9;
|
||||
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
form h2 {
|
||||
text-align: center;
|
||||
margin-bottom: 20px;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
form label {
|
||||
display: block;
|
||||
margin-bottom: 5px;
|
||||
font-weight: bold;
|
||||
color: #555;
|
||||
}
|
||||
|
||||
form input[type="text"],
|
||||
form input[type="password"],
|
||||
form input[type="email"] {
|
||||
width: 100%;
|
||||
padding: 10px;
|
||||
margin-bottom: 15px;
|
||||
border: 1px solid #ccc;
|
||||
border-radius: 4px;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
form button {
|
||||
width: 100%;
|
||||
padding: 10px;
|
||||
background-color: #28a745;
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
form button:hover {
|
||||
background-color: #218838;
|
||||
}
|
||||
|
||||
/* Stili per la pagina prodotto */
|
||||
.product-detail {
|
||||
max-width: 800px;
|
||||
margin: 20px auto;
|
||||
padding: 20px;
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 8px;
|
||||
background-color: #fff;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.product-detail img {
|
||||
max-width: 100%;
|
||||
height: auto;
|
||||
object-fit: contain;
|
||||
margin-bottom: 20px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.product-detail > div {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
@media (min-width: 768px) {
|
||||
.product-detail {
|
||||
flex-direction: row;
|
||||
}
|
||||
|
||||
.product-detail img {
|
||||
max-width: 40%;
|
||||
margin-bottom: 0;
|
||||
margin-right: 20px;
|
||||
}
|
||||
}
|
||||
|
||||
.img-square {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
padding-top: 100%; /* crea un quadrato perfetto */
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.img-square img {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: contain; /* o "cover" */
|
||||
}
|
||||
|
||||
/* Pagina carrello */
|
||||
.cart-container {
|
||||
max-width: 900px;
|
||||
margin: 20px auto;
|
||||
padding: 20px;
|
||||
}
|
||||
.cart-table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
margin-top: 20px;
|
||||
}
|
||||
.cart-table th, .cart-table td {
|
||||
border: 1px solid #ddd;
|
||||
padding: 12px;
|
||||
text-align: left;
|
||||
}
|
||||
.cart-table th {
|
||||
background-color: #f2f2f2;
|
||||
font-weight: bold;
|
||||
}
|
||||
.cart-table button {
|
||||
padding: 5px 10px;
|
||||
background-color: #dc3545;
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.cart-table button:hover {
|
||||
background-color: #c82333;
|
||||
}
|
||||
.cart-summary {
|
||||
margin-top: 20px;
|
||||
text-align: right;
|
||||
font-size: 18px;
|
||||
font-weight: bold;
|
||||
}
|
||||
.empty-cart {
|
||||
text-align: center;
|
||||
padding: 40px;
|
||||
font-size: 18px;
|
||||
color: #666;
|
||||
}
|
||||
.clear-cart-btn {
|
||||
padding: 10px 20px;
|
||||
background-color: #dc3545;
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
margin-top: 20px;
|
||||
}
|
||||
.clear-cart-btn:hover {
|
||||
background-color: #c82333;
|
||||
}
|
||||
.checkout-btn {
|
||||
padding: 10px 20px;
|
||||
background-color: #28a745;
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
margin-left: 10px;
|
||||
}
|
||||
.checkout-btn:hover {
|
||||
background-color: #218838;
|
||||
}
|
||||
|
||||
/* Layout pagina account */
|
||||
.account-layout {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 20px;
|
||||
max-width: 1100px;
|
||||
margin: 20px auto;
|
||||
padding: 0 20px;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.my-sidebar {
|
||||
flex: 0 0 240px;
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 8px;
|
||||
background-color: #fff;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.my-sidebar ul {
|
||||
list-style: none;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.my-sidebar li {
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.my-sidebar a {
|
||||
color: #007bff;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.my-sidebar a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.my-container {
|
||||
flex: 1 1 580px;
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 8px;
|
||||
background-color: #fff;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.account-layout {
|
||||
flex-direction: column;
|
||||
}
|
||||
.my-sidebar,
|
||||
.my-container {
|
||||
flex: 1 1 100%;
|
||||
}
|
||||
}
|
||||
|
||||
/* Stili per la pagina ordini */
|
||||
.orders-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 20px;
|
||||
}
|
||||
|
||||
.order-card {
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 8px;
|
||||
padding: 20px;
|
||||
background-color: #fff;
|
||||
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.order-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
.order-header h3 {
|
||||
margin: 0;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.order-status {
|
||||
padding: 5px 10px;
|
||||
border-radius: 4px;
|
||||
font-size: 12px;
|
||||
font-weight: bold;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.status-pending {
|
||||
background-color: #ffc107;
|
||||
color: #212529;
|
||||
}
|
||||
|
||||
.status-completed {
|
||||
background-color: #28a745;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.status-cancelled {
|
||||
background-color: #dc3545;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.order-details p {
|
||||
margin: 5px 0;
|
||||
color: #666;
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
session_start();
|
||||
?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="it">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Carrello - TechStore</title>
|
||||
<link rel="stylesheet" href="assets/style.css">
|
||||
<script src="assets/js/cart.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<header style="display: flex; justify-content: space-between; align-items: center; padding: 10px; background-color: #f2f2f2; border-bottom: 1px solid #ddd;">
|
||||
<div id="logo" style="font-size: 24px; font-weight: bold;"><a href="index.php"><img src="img/logo.png" alt="Logo TechStore" height="32px"></a></div>
|
||||
<div>
|
||||
<a href="cart.php"><button style="margin-left: 10px; padding: 8px 16px; background-color: #007bff; color: white; border: none; border-radius: 4px; cursor: pointer;">Carrello</button></a>
|
||||
<?php if (isset($_SESSION['name'])): ?>
|
||||
<a href="logout.php"><button style="margin-left: 10px; padding: 8px 16px; background-color: #dc3545; color: white; border: none; border-radius: 4px; cursor: pointer;">Logout</button></a>
|
||||
<span style="margin-left: 10px;">Benvenuto, <a href="account.php"><?php echo htmlspecialchars($_SESSION['name']); ?></a></span>
|
||||
<?php else: ?>
|
||||
<a href="login.php"><button style="margin-left: 10px; padding: 8px 16px; background-color: #28a745; color: white; border: none; border-radius: 4px; cursor: pointer;">Accesso</button></a>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div class="cart-container">
|
||||
<h1>Il tuo carrello</h1>
|
||||
|
||||
<?php
|
||||
$cart = [];
|
||||
$cartCookie = isset($_COOKIE['cart']) ? $_COOKIE['cart'] : '';
|
||||
|
||||
if ($cartCookie) {
|
||||
$cart = json_decode(urldecode($cartCookie), true);
|
||||
}
|
||||
|
||||
if (empty($cart)): ?>
|
||||
<div class="empty-cart">
|
||||
<p>Il tuo carrello è vuoto.</p>
|
||||
<a href="index.php"><button style="padding: 10px 20px; background-color: #007bff; color: white; border: none; border-radius: 4px; cursor: pointer; margin-top: 10px;">Torna ai prodotti</button></a>
|
||||
</div>
|
||||
<?php else: ?>
|
||||
<table class="cart-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Prodotto</th>
|
||||
<th>Prezzo</th>
|
||||
<th>Quantità</th>
|
||||
<th>Totale</th>
|
||||
<th>Azione</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
$grand_total = 0;
|
||||
foreach ($cart as $index => $item):
|
||||
$item_total = $item['price'] * $item['quantity'];
|
||||
$grand_total += $item_total;
|
||||
?>
|
||||
<tr>
|
||||
<td><a href="product.php?id=<?php echo $item['id']; ?>"><?php echo htmlspecialchars($item['name']); ?></a></td>
|
||||
<td>€<?php echo number_format($item['price'], 2, ',', '.'); ?></td>
|
||||
<td><?php echo $item['quantity']; ?></td>
|
||||
<td>€<?php echo number_format($item_total, 2, ',', '.'); ?></td>
|
||||
<td>
|
||||
<button onclick="removeFromCart(<?php echo $index; ?>)">Rimuovi</button>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<div class="cart-summary">
|
||||
<p>Totale: €<?php echo number_format($grand_total, 2, ',', '.'); ?></p>
|
||||
</div>
|
||||
|
||||
<div style="text-align: right; margin-top: 20px;">
|
||||
<button class="clear-cart-btn" onclick="clearCart()">Svuota carrello</button>
|
||||
<a href="checkout.php"><button class="checkout-btn">Procedi all'acquisto</button></a>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,135 @@
|
||||
<?php
|
||||
session_start();
|
||||
include 'db_conf.php';
|
||||
|
||||
// Controlla se l'utente è loggato
|
||||
if (!isset($_SESSION['id'])) {
|
||||
header('Location: login.php');
|
||||
exit();
|
||||
}
|
||||
|
||||
// Leggi il carrello dal cookie
|
||||
$cart = [];
|
||||
$cartCookie = isset($_COOKIE['cart']) ? $_COOKIE['cart'] : '';
|
||||
|
||||
if ($cartCookie) {
|
||||
$cart = json_decode(urldecode($cartCookie), true);
|
||||
}
|
||||
|
||||
// Se il carrello è vuoto, reindirizza al carrello
|
||||
if (empty($cart)) {
|
||||
header('Location: cart.php');
|
||||
exit();
|
||||
}
|
||||
|
||||
$user_id = $_SESSION['id'];
|
||||
$order_total = 0;
|
||||
$error = '';
|
||||
|
||||
// Inzia la transazione
|
||||
$conn->begin_transaction();
|
||||
|
||||
try {
|
||||
// Calcola il totale dell'ordine
|
||||
foreach ($cart as $item) {
|
||||
$order_total += $item['price'] * $item['quantity'];
|
||||
}
|
||||
|
||||
// Crea un nuovo ordine
|
||||
$sql_order = "INSERT INTO Orders (UserID, Total, Status) VALUES (?, ?, 'pending')";
|
||||
$stmt_order = $conn->prepare($sql_order);
|
||||
if (!$stmt_order) {
|
||||
throw new Exception("Errore nella preparazione della query: " . $conn->error);
|
||||
}
|
||||
|
||||
$stmt_order->bind_param("id", $user_id, $order_total);
|
||||
$stmt_order->execute();
|
||||
$order_id = $conn->insert_id;
|
||||
|
||||
// Per ogni prodotto nel carrello
|
||||
foreach ($cart as $item) {
|
||||
$product_id = $item['id'];
|
||||
$quantity = $item['quantity'];
|
||||
$price = $item['price'];
|
||||
|
||||
// Aggiungi item all'ordine
|
||||
$sql_item = "INSERT INTO OrderItems (OrderID, ProductID, Quantity, Price) VALUES (?, ?, ?, ?)";
|
||||
$stmt_item = $conn->prepare($sql_item);
|
||||
if (!$stmt_item) {
|
||||
throw new Exception("Errore nella preparazione della query: " . $conn->error);
|
||||
}
|
||||
|
||||
$stmt_item->bind_param("iiii", $order_id, $product_id, $quantity, $price);
|
||||
$stmt_item->execute();
|
||||
|
||||
// Riduci lo stock del prodotto
|
||||
$sql_stock = "UPDATE Products SET StockQuantity = StockQuantity - ? WHERE ProductID = ?";
|
||||
$stmt_stock = $conn->prepare($sql_stock);
|
||||
if (!$stmt_stock) {
|
||||
throw new Exception("Errore nella preparazione della query: " . $conn->error);
|
||||
}
|
||||
|
||||
$stmt_stock->bind_param("ii", $quantity, $product_id);
|
||||
$stmt_stock->execute();
|
||||
|
||||
$stmt_item->close();
|
||||
$stmt_stock->close();
|
||||
}
|
||||
|
||||
// Conferma la transazione
|
||||
$conn->commit();
|
||||
|
||||
// Svuota il carrello
|
||||
setcookie('cart', '', time() - 3600, '/');
|
||||
|
||||
// Mostra pagina di successo
|
||||
$success = true;
|
||||
|
||||
} catch (Exception $e) {
|
||||
// Annulla la transazione in caso di errore
|
||||
$conn->rollback();
|
||||
$error = "Errore nell'elaborazione dell'ordine: " . $e->getMessage();
|
||||
$success = false;
|
||||
}
|
||||
|
||||
$stmt_order->close();
|
||||
$conn->close();
|
||||
?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="it">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title><?php echo $success ? 'Ordine confermato' : 'Errore ordine'; ?> - TechStore</title>
|
||||
<link rel="stylesheet" href="assets/style.css">
|
||||
</head>
|
||||
<body>
|
||||
<header style="display: flex; justify-content: space-between; align-items: center; padding: 10px; background-color: #f2f2f2; border-bottom: 1px solid #ddd;">
|
||||
<div id="logo" style="font-size: 24px; font-weight: bold;"><a href="index.php"><img src="img/logo.png" alt="Logo TechStore" height="32px"></a></div>
|
||||
<div>
|
||||
<a href="cart.php"><button style="margin-left: 10px; padding: 8px 16px; background-color: #007bff; color: white; border: none; border-radius: 4px; cursor: pointer;">Carrello</button></a>
|
||||
<?php if (isset($_SESSION['name'])): ?>
|
||||
<a href="logout.php"><button style="margin-left: 10px; padding: 8px 16px; background-color: #dc3545; color: white; border: none; border-radius: 4px; cursor: pointer;">Logout</button></a>
|
||||
<span style="margin-left: 10px;">Benvenuto, <a href="account.php"><?php echo htmlspecialchars($_SESSION['name']); ?></a></span>
|
||||
<?php else: ?>
|
||||
<a href="login.php"><button style="margin-left: 10px; padding: 8px 16px; background-color: #28a745; color: white; border: none; border-radius: 4px; cursor: pointer;">Accesso</button></a>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div style="max-width: 600px; margin: 50px auto; padding: 20px; text-align: center; border: 1px solid #ddd; border-radius: 8px; background-color: #fff;">
|
||||
<?php if ($success): ?>
|
||||
<h1 style="color: #28a745;">Ordine confermato!</h1>
|
||||
<p>Il tuo ordine è stato elaborato con successo.</p>
|
||||
<p><strong>Numero ordine:</strong> #<?php echo $order_id; ?></p>
|
||||
<p><strong>Totale:</strong> €<?php echo number_format($order_total, 2, ',', '.'); ?></p>
|
||||
<a href="index.php"><button style="padding: 10px 20px; background-color: #007bff; color: white; border: none; border-radius: 4px; cursor: pointer; margin-top: 20px;">Torna alla home</button></a>
|
||||
<?php else: ?>
|
||||
<h1 style="color: #dc3545;">Errore nell'ordine</h1>
|
||||
<p><?php echo htmlspecialchars($error); ?></p>
|
||||
<a href="cart.php"><button style="padding: 10px 20px; background-color: #007bff; color: white; border: none; border-radius: 4px; cursor: pointer; margin-top: 20px;">Torna al carrello</button></a>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
// Configurazione connessione database
|
||||
$host = 'localhost';
|
||||
$username = 'techstore';
|
||||
$password = 'dioporco';
|
||||
$database = 'TechStore';
|
||||
|
||||
// Creazione connessione
|
||||
$conn = mysqli_connect($host, $username, $password, $database);
|
||||
|
||||
// Controllo connessione
|
||||
if ($conn->connect_error) {
|
||||
die("Connessione fallita: " . $conn->connect_error);
|
||||
}
|
||||
|
||||
// Opzionale: impostare charset
|
||||
$conn->set_charset("utf8");
|
||||
|
||||
// La connessione è ora pronta per essere utilizzata
|
||||
// Ricorda di chiudere la connessione quando non più necessaria: $conn->close();
|
||||
?>
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 16 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 51 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 22 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 64 KiB |
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
session_start();
|
||||
include 'db_conf.php';
|
||||
|
||||
// Query per ottenere tutti i prodotti
|
||||
$sql = "SELECT p.ProductID, p.ProductName, c.Name AS 'CategoryName', p.Description, p.Price, p.StockQuantity, p.ImagePath FROM Products p JOIN Categories c ON p.CategoryID=c.CategoryID";
|
||||
$result = $conn->query($sql);
|
||||
|
||||
if ($result === false) {
|
||||
die("Errore nella query: " . $conn->error);
|
||||
}
|
||||
?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="it">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>TechStore - Prodotti</title>
|
||||
<link rel="stylesheet" href="assets/style.css">
|
||||
<script src="assets/js/cart.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<header style="display: flex; justify-content: space-between; align-items: center; padding: 10px; background-color: #f2f2f2; border-bottom: 1px solid #ddd;">
|
||||
<div id="logo"><img src="img/logo.png" alt="Logo TechStore" height="32px"></div>
|
||||
<div>
|
||||
<a href="cart.php"><button style="margin-left: 10px; padding: 8px 16px; background-color: #007bff; color: white; border: none; border-radius: 4px; cursor: pointer;">Carrello</button></a>
|
||||
<?php if (isset($_SESSION['name'])): ?>
|
||||
<a href="logout.php"><button style="margin-left: 10px; padding: 8px 16px; background-color: #dc3545; color: white; border: none; border-radius: 4px; cursor: pointer;">Logout</button></a>
|
||||
<span style="margin-left: 10px;">Benvenuto, <a href="account.php"><?php echo htmlspecialchars($_SESSION['name']); ?></a></span>
|
||||
<?php else: ?>
|
||||
<a href="login.php"><button style="margin-left: 10px; padding: 8px 16px; background-color: #28a745; color: white; border: none; border-radius: 4px; cursor: pointer;">Accesso</button></a>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<?php if ($result->num_rows > 0): ?>
|
||||
<div class="products-grid">
|
||||
<?php while ($row = $result->fetch_assoc()): ?>
|
||||
<div class="product-card">
|
||||
<a href="product.php?id=<?php echo $row['ProductID']; ?>"><div class="img-square"><img src="img/<?php echo htmlspecialchars($row['ImagePath']); ?>" alt="Immagine prodotto"></div></a>
|
||||
<h3><?php echo "<a href='product.php?id=" . $row['ProductID'] . "'>" . htmlspecialchars($row['ProductName']) . "</a>"; ?></h3>
|
||||
<p><?php echo htmlspecialchars($row['Price']); ?>€</p>
|
||||
<button onclick="addToCart(<?php echo $row['ProductID']; ?>, '<?php echo htmlspecialchars($row['ProductName']); ?>', <?php echo $row['Price']; ?>)">Aggiungi al carrello</button>
|
||||
</div>
|
||||
<?php endwhile; ?>
|
||||
</div>
|
||||
<?php else: ?>
|
||||
<p>Nessun prodotto trovato.</p>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php $conn->close(); ?>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,64 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="it">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Login - TechStore</title>
|
||||
<link rel="stylesheet" href="assets/style.css">
|
||||
</head>
|
||||
<body>
|
||||
<?php
|
||||
session_start();
|
||||
include 'db_conf.php';
|
||||
|
||||
$error = '';
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$email = $_POST['email'];
|
||||
$password = $_POST['password'];
|
||||
|
||||
$sql = "SELECT UserID, Name, Surname, Password, Role FROM Users WHERE Email = ?";
|
||||
if ($stmt = $conn->prepare($sql)) {
|
||||
$stmt->bind_param("s", $email);
|
||||
$stmt->execute();
|
||||
$stmt->store_result();
|
||||
|
||||
if ($stmt->num_rows > 0) {
|
||||
$stmt->bind_result($user_id, $name, $surname, $hashed_password, $role);
|
||||
$stmt->fetch();
|
||||
|
||||
if (password_verify($password, $hashed_password)) {
|
||||
$_SESSION['id'] = $user_id;
|
||||
$_SESSION['name'] = $name;
|
||||
$_SESSION['surname'] = $surname;
|
||||
$_SESSION['role'] = $role;
|
||||
header('Location: index.php');
|
||||
exit();
|
||||
} else {
|
||||
$error = 'Credenziali errate.';
|
||||
}
|
||||
} else {
|
||||
$error = 'Credenziali errate.';
|
||||
}
|
||||
|
||||
$stmt->close();
|
||||
} else {
|
||||
$error = 'Errore nel database.';
|
||||
}
|
||||
}
|
||||
?>
|
||||
<form action="" method="POST">
|
||||
<h2>Login</h2>
|
||||
<label for="email">Indirizzo e-mail:</label>
|
||||
<input type="email" id="email" name="email" required><br>
|
||||
<label for="password">Password:</label>
|
||||
<input type="password" id="password" name="password" required><br>
|
||||
<?php if ($error): ?>
|
||||
<p style="color: red; text-align: center;"><?php echo htmlspecialchars($error); ?></p>
|
||||
<?php endif; ?>
|
||||
<br>
|
||||
<button type="submit">Login</button>
|
||||
<p style="text-align: center;">Non hai un account? <a href="register.php">Registrati</a></p>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
session_start();
|
||||
session_destroy();
|
||||
header('Location: index.php');
|
||||
exit();
|
||||
?>
|
||||
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
session_start();
|
||||
include 'db_conf.php';
|
||||
|
||||
// Controlla se l'utente è loggato
|
||||
if (!isset($_SESSION['id'])) {
|
||||
header('Location: login.php');
|
||||
exit();
|
||||
}
|
||||
|
||||
// Query per ottenere gli ordini dell'utente con i prodotti
|
||||
$sql = "SELECT o.OrderID, o.OrderDate, o.Total, o.Status,
|
||||
GROUP_CONCAT(p.ProductName SEPARATOR ', ') AS Products
|
||||
FROM Orders o
|
||||
LEFT JOIN OrderItems oi ON o.OrderID = oi.OrderID
|
||||
LEFT JOIN Products p ON oi.ProductID = p.ProductID
|
||||
WHERE o.UserID = ?
|
||||
GROUP BY o.OrderID
|
||||
ORDER BY o.OrderDate DESC";
|
||||
$stmt = $conn->prepare($sql);
|
||||
$stmt->bind_param("i", $_SESSION['id']);
|
||||
$stmt->execute();
|
||||
$result = $stmt->get_result();
|
||||
|
||||
if (!$result) {
|
||||
die("Errore nella query: " . $conn->error);
|
||||
}
|
||||
?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="it">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Il mio account - TechStore</title>
|
||||
<link rel="stylesheet" href="assets/style.css">
|
||||
<script src="assets/js/cart.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<header style="display: flex; justify-content: space-between; align-items: center; padding: 10px; background-color: #f2f2f2; border-bottom: 1px solid #ddd;">
|
||||
<div id="logo" style="font-size: 24px; font-weight: bold;"><a href="index.php"><img src="img/logo.png" alt="Logo TechStore" height="32px"></a></div>
|
||||
<div>
|
||||
<a href="cart.php"><button style="margin-left: 10px; padding: 8px 16px; background-color: #007bff; color: white; border: none; border-radius: 4px; cursor: pointer;">Carrello</button></a>
|
||||
<?php if (isset($_SESSION['name'])): ?>
|
||||
<a href="logout.php"><button style="margin-left: 10px; padding: 8px 16px; background-color: #dc3545; color: white; border: none; border-radius: 4px; cursor: pointer;">Logout</button></a>
|
||||
<span style="margin-left: 10px;">Benvenuto, <?php echo htmlspecialchars($_SESSION['name']); ?></span>
|
||||
<?php else: ?>
|
||||
<a href="login.php"><button style="margin-left: 10px; padding: 8px 16px; background-color: #28a745; color: white; border: none; border-radius: 4px; cursor: pointer;">Accesso</button></a>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<?php if (isset($_SESSION['name'])): ?>
|
||||
<div class="account-layout">
|
||||
<div class="my-sidebar">
|
||||
<ul>
|
||||
<li><a href="account.php">Il mio account</a></li>
|
||||
<li><a href="orders.php">I miei ordini</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="my-container">
|
||||
<h1>I miei ordini</h1>
|
||||
<?php if ($result->num_rows > 0): ?>
|
||||
<div class="orders-list">
|
||||
<?php while ($order = $result->fetch_assoc()): ?>
|
||||
<div class="order-card">
|
||||
<div class="order-header">
|
||||
<h3>Ordine #<?php echo htmlspecialchars($order['OrderID']); ?></h3>
|
||||
<span class="order-status status-<?php echo htmlspecialchars($order['Status']); ?>">
|
||||
<?php echo htmlspecialchars(ucfirst($order['Status'])); ?>
|
||||
</span>
|
||||
</div>
|
||||
<div class="order-details">
|
||||
<p><strong>Data:</strong> <?php echo date('d/m/Y H:i', strtotime($order['OrderDate'])); ?></p>
|
||||
<p><strong>Prodotti:</strong> <?php echo htmlspecialchars($order['Products']); ?></p>
|
||||
<p><strong>Totale:</strong> €<?php echo number_format($order['Total'], 2, ',', '.'); ?></p>
|
||||
</div>
|
||||
</div>
|
||||
<?php endwhile; ?>
|
||||
</div>
|
||||
<?php else: ?>
|
||||
<p>Non hai ancora effettuato ordini.</p>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php else: ?>
|
||||
<?php header('Location: login.php'); ?>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php $conn->close(); ?>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
session_start();
|
||||
include 'db_conf.php';
|
||||
|
||||
// Ottieni l'ID del prodotto dall'URL
|
||||
$product_id = isset($_GET['id']) ? (int)$_GET['id'] : 0;
|
||||
|
||||
// Query per ottenere il singolo prodotto
|
||||
$sql = "SELECT p.ProductID, p.ProductName, c.Name AS 'CategoryName', p.Description, p.Price, p.StockQuantity, p.ImagePath FROM Products p JOIN Categories c ON p.CategoryID=c.CategoryID WHERE p.ProductID = ?";
|
||||
if ($stmt = $conn->prepare($sql)) {
|
||||
$stmt->bind_param("i", $product_id);
|
||||
$stmt->execute();
|
||||
$result = $stmt->get_result();
|
||||
$product = $result->fetch_assoc();
|
||||
$stmt->close();
|
||||
} else {
|
||||
die("Errore nella query: " . $conn->error);
|
||||
}
|
||||
?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="it">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<?php if ($result->num_rows > 0): ?>
|
||||
<title><?php echo $product['ProductName']; ?> - TechStore</title>
|
||||
<?php else: ?>
|
||||
<title>Prodotto non trovato - TechStore</title>
|
||||
<?php endif; ?>
|
||||
<link rel="stylesheet" href="assets/style.css">
|
||||
<script src="assets/js/cart.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<header style="display: flex; justify-content: space-between; align-items: center; padding: 10px; background-color: #f2f2f2; border-bottom: 1px solid #ddd;">
|
||||
<div id="logo" style="font-size: 24px; font-weight: bold;"><a href="index.php"><img src="img/logo.png" alt="Logo TechStore" height="32px"></a></div>
|
||||
<div>
|
||||
<a href="cart.php"><button style="margin-left: 10px; padding: 8px 16px; background-color: #007bff; color: white; border: none; border-radius: 4px; cursor: pointer;">Carrello</button></a>
|
||||
<?php if (isset($_SESSION['name'])): ?>
|
||||
<a href="logout.php"><button style="margin-left: 10px; padding: 8px 16px; background-color: #dc3545; color: white; border: none; border-radius: 4px; cursor: pointer;">Logout</button></a>
|
||||
<span style="margin-left: 10px;">Benvenuto, <a href="account.php"><?php echo htmlspecialchars($_SESSION['name']); ?></a></span>
|
||||
<?php else: ?>
|
||||
<a href="login.php"><button style="margin-left: 10px; padding: 8px 16px; background-color: #28a745; color: white; border: none; border-radius: 4px; cursor: pointer;">Accesso</button></a>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<?php if ($product): ?>
|
||||
<div class="product-detail">
|
||||
<img src="img/<?php echo htmlspecialchars($product['ImagePath']); ?>" alt="Immagine prodotto">
|
||||
<div>
|
||||
<h1><?php echo htmlspecialchars($product['ProductName']); ?></h1>
|
||||
<p><strong>Categoria:</strong> <?php echo htmlspecialchars($product['CategoryName']); ?></p>
|
||||
<p><strong>Descrizione:</strong> <?php echo htmlspecialchars($product['Description']); ?></p>
|
||||
<p><strong>Prezzo:</strong> €<?php echo htmlspecialchars($product['Price']); ?></p>
|
||||
<p><strong>Quantità disponibile:</strong> <?php echo htmlspecialchars($product['StockQuantity']); ?></p>
|
||||
<button onclick="addToCart(<?php echo $product['ProductID']; ?>, '<?php echo htmlspecialchars($product['ProductName']); ?>', <?php echo $product['Price']; ?>)" style="padding: 10px 20px; background-color: #28a745; color: white; border: none; border-radius: 4px; cursor: pointer;">Aggiungi al carrello</button>
|
||||
</div>
|
||||
</div>
|
||||
<?php else: ?>
|
||||
<p style="text-align: center; margin: 50px;">Prodotto non trovato.</p>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php $conn->close(); ?>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
include 'db_conf.php';
|
||||
?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="it">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Registrazione - TechStore</title>
|
||||
<link rel="stylesheet" href="assets/style.css">
|
||||
</head>
|
||||
<body>
|
||||
<?php
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
if($_POST['password'] !== $_POST['confirm_password']){
|
||||
echo "<p style='color: red; text-align: center;'>Le password non corrispondono.</p>";
|
||||
}
|
||||
else{
|
||||
$sql = "INSERT INTO Users (Name, Surname, Email, Password) VALUES (?, ?, ?, ?)";
|
||||
if($stmt = $conn->prepare($sql)){
|
||||
$stmt->bind_param("ssss", $name, $surname, $email, $password);
|
||||
|
||||
$name = $_POST['name'];
|
||||
$surname = $_POST['surname'];
|
||||
$email = $_POST['email'];
|
||||
$password = password_hash($_POST['password'], PASSWORD_DEFAULT);
|
||||
$stmt->execute();
|
||||
|
||||
echo "<p style='color: green; text-align: center;'>Registrazione avvenuta con successo! <a href=\"login.php\">Accedi</a></p>";
|
||||
}
|
||||
else{
|
||||
echo "Errore: " . $conn->error;
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
<form action="" method="POST">
|
||||
<h2>Registrazione</h2>
|
||||
<label for="name">Nome:</label>
|
||||
<input type="text" id="name" name="name" required><br>
|
||||
<label for="surname">Cognome:</label>
|
||||
<input type="text" id="surname" name="surname" required><br>
|
||||
<label for="email">Indirizzo e-mail:</label>
|
||||
<input type="email" id="email" name="email" required><br>
|
||||
<label for="password">Password:</label>
|
||||
<input type="password" id="password" name="password" required><br>
|
||||
<label for="confirm_password">Conferma password:</label>
|
||||
<input type="password" id="confirm_password" name="confirm_password" required><br><br>
|
||||
<button type="submit">Registrati</button>
|
||||
<p style="text-align: center;">Hai già un account? <a href="login.php">Accedi</a></p>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user