Compare commits

..

No commits in common. "ai-dev" and "master" have entirely different histories.

20 changed files with 126 additions and 1153 deletions

View File

@ -1,46 +0,0 @@
<?php
session_start();
require_once __DIR__ . '/../db/config.php';
// If user is not logged in or not a super_admin, redirect to login page
if (!isset($_SESSION['user_id']) || $_SESSION['user_role'] !== 'super_admin') {
header('Location: ../login.php');
exit;
}
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$product_id = $_POST['product_id'] ?? null;
if ($product_id) {
$pdo = db();
// First, check the stock quantity
$stmt = $pdo->prepare("SELECT stock_quantity FROM products WHERE id = ?");
$stmt->execute([$product_id]);
$product = $stmt->fetch(PDO::FETCH_ASSOC);
if ($product) {
if ((int)$product['stock_quantity'] === 0) {
// Stock is 0, so it's safe to delete
$delete_stmt = $pdo->prepare("DELETE FROM products WHERE id = ?");
if ($delete_stmt->execute([$product_id])) {
$_SESSION['success_message'] = 'Product deleted successfully.';
} else {
$_SESSION['error_message'] = 'Failed to delete product.';
}
} else {
// Stock is not 0, prevent deletion
$_SESSION['error_message'] = 'Cannot delete product because it is not out of stock.';
}
} else {
$_SESSION['error_message'] = 'Product not found.';
}
} else {
$_SESSION['error_message'] = 'Invalid product ID.';
}
} else {
$_SESSION['error_message'] = 'Invalid request method.';
}
header('Location: index.php');
exit;

View File

@ -1,102 +0,0 @@
<?php
session_start();
require_once __DIR__ . '/../db/config.php';
// If user is not logged in or not a super_admin, redirect to login page
if (!isset($_SESSION['user_id']) || $_SESSION['user_role'] !== 'super_admin') {
header('Location: ../login.php');
exit;
}
$product = [
'id' => '',
'name' => '',
'description' => '',
'price' => '',
'stock_quantity' => '',
'image_url' => ''
];
$pageTitle = 'Add New Product';
if (isset($_GET['id'])) {
$pageTitle = 'Edit Product';
$pdo = db();
$stmt = $pdo->prepare('SELECT * FROM products WHERE id = ?');
$stmt->execute([$_GET['id']]);
$product = $stmt->fetch(PDO::FETCH_ASSOC);
if (!$product) {
$_SESSION['error_message'] = 'Product not found.';
header('Location: index.php');
exit;
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?php echo $pageTitle; ?> - GiftShop Admin</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<div class="container">
<a class="navbar-brand" href="index.php">GiftShop Admin</a>
</div>
</nav>
<div class="container mt-4">
<div class="row">
<div class="col-lg-8 mx-auto">
<div class="d-flex justify-content-between align-items-center mb-4">
<h1><?php echo $pageTitle; ?></h1>
<a href="index.php" class="btn btn-secondary">Back to Products</a>
</div>
<div class="card">
<div class="card-body">
<form action="save_product.php" method="POST" enctype="multipart/form-data">
<?php if ($product['id']): ?>
<input type="hidden" name="id" value="<?php echo $product['id']; ?>">
<?php endif; ?>
<div class="mb-3">
<label for="name" class="form-label">Product Name</label>
<input type="text" class="form-control" id="name" name="name" value="<?php echo htmlspecialchars($product['name']); ?>" required>
</div>
<div class="mb-3">
<label for="description" class="form-label">Description</label>
<textarea class="form-control" id="description" name="description" rows="3"><?php echo htmlspecialchars($product['description']); ?></textarea>
</div>
<div class="row">
<div class="col-md-6 mb-3">
<label for="price" class="form-label">Price</label>
<input type="number" class="form-control" id="price" name="price" step="0.01" value="<?php echo htmlspecialchars($product['price']); ?>" required>
</div>
<div class="col-md-6 mb-3">
<label for="stock_quantity" class="form-label">Stock Quantity</label>
<input type="number" class="form-control" id="stock_quantity" name="stock_quantity" value="<?php echo htmlspecialchars($product['stock_quantity']); ?>" required>
</div>
</div>
<div class="mb-3">
<label for="image" class="form-label">Product Image</label>
<input type="file" class="form-control" id="image" name="image">
<?php if ($product['image_url']): ?>
<p class="form-text mt-2">Current image:</p>
<img src="../uploads/<?php echo htmlspecialchars($product['image_url']); ?>" alt="<?php echo htmlspecialchars($product['name']); ?>" style="max-width: 100px; max-height: 100px;">
<?php endif; ?>
</div>
<button type="submit" class="btn btn-primary">Save Product</button>
</form>
</div>
</div>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>

View File

@ -1,105 +0,0 @@
<?php
session_start();
require_once __DIR__ . '/../db/config.php';
// If user is not logged in or not a super_admin, redirect to login page
if (!isset($_SESSION['user_id']) || $_SESSION['user_role'] !== 'super_admin') {
header('Location: ../login.php');
exit;
}
// Fetch all products
$pdo = db();
$stmt = $pdo->query('SELECT * FROM products ORDER BY created_at DESC');
$products = $stmt->fetchAll(PDO::FETCH_ASSOC);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Admin Dashboard - GiftShop</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<div class="container">
<a class="navbar-brand" href="#">GiftShop Admin</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav ms-auto">
<li class="nav-item">
<a class="nav-link" href="logout.php">Logout</a>
</li>
</ul>
</div>
</div>
</nav>
<div class="container mt-4">
<div class="d-flex justify-content-between align-items-center mb-4">
<h1>Product Management</h1>
<a href="edit_product.php" class="btn btn-primary">
<i class="bi bi-plus-lg"></i> Add New Product
</a>
</div>
<?php if (isset($_SESSION['success_message'])): ?>
<div class="alert alert-success">
<?php echo $_SESSION['success_message']; unset($_SESSION['success_message']); ?>
</div>
<?php endif; ?>
<?php if (isset($_SESSION['error_message'])): ?>
<div class="alert alert-danger">
<?php echo $_SESSION['error_message']; unset($_SESSION['error_message']); ?>
</div>
<?php endif; ?>
<div class="card">
<div class="card-body">
<table class="table table-striped table-hover">
<thead>
<tr>
<th>Name</th>
<th>Price</th>
<th>Stock</th>
<th class="text-end">Actions</th>
</tr>
</thead>
<tbody>
<?php if (empty($products)): ?>
<tr>
<td colspan="4" class="text-center">No products found.</td>
</tr>
<?php else: ?>
<?php foreach ($products as $product): ?>
<tr>
<td><?php echo htmlspecialchars($product['name']); ?></td>
<td>$<?php echo htmlspecialchars($product['price']); ?></td>
<td><?php echo htmlspecialchars($product['stock_quantity']); ?></td>
<td class="text-end">
<a href="edit_product.php?id=<?php echo $product['id']; ?>" class="btn btn-sm btn-outline-primary">
<i class="bi bi-pencil"></i> Edit
</a>
<form action="delete_product.php" method="POST" class="d-inline" onsubmit="return confirm('Are you sure you want to delete this product?');">
<input type="hidden" name="product_id" value="<?php echo $product['id']; ?>">
<button type="submit" class="btn btn-sm btn-outline-danger" <?php if ($product['stock_quantity'] > 0) echo 'disabled'; ?>>
<i class="bi bi-trash"></i> Delete
</button>
</form>
</td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
</table>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>

View File

@ -1,6 +0,0 @@
<?php
session_start();
session_unset();
session_destroy();
header('Location: ../login.php');
exit;

View File

@ -1,90 +0,0 @@
<?php
session_start();
require_once __DIR__ . '/../db/config.php';
// If user is not logged in or not a super_admin, redirect to login page
if (!isset($_SESSION['user_id']) || $_SESSION['user_role'] !== 'super_admin') {
header('Location: ../login.php');
exit;
}
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$name = trim($_POST['name'] ?? '');
$description = trim($_POST['description'] ?? '');
$price = filter_var($_POST['price'], FILTER_VALIDATE_FLOAT);
$stock_quantity = filter_var($_POST['stock_quantity'], FILTER_VALIDATE_INT);
$id = $_POST['id'] ?? null;
// Basic validation
if (empty($name) || $price === false || $stock_quantity === false) {
$_SESSION['error_message'] = 'Please fill in all required fields correctly.';
header('Location: ' . ($_SERVER['HTTP_REFERER'] ?? 'index.php'));
exit;
}
$pdo = db();
$image_url = '';
if ($id) {
// Fetch existing product's image url
$stmt = $pdo->prepare("SELECT image_url FROM products WHERE id = ?");
$stmt->execute([$id]);
$image_url = $stmt->fetchColumn();
}
// Handle file upload
if (isset($_FILES['image']) && $_FILES['image']['error'] === UPLOAD_ERR_OK) {
$uploadDir = __DIR__ . '/../uploads/';
// Sanitize the filename
$originalName = basename($_FILES['image']['name']);
$safeName = preg_replace("/[^a-zA-Z0-9-_.]+/", "", $originalName);
$fileName = uniqid('', true) . '_' . $safeName;
$uploadFile = $uploadDir . $fileName;
// Validate file type
$imageFileType = strtolower(pathinfo($uploadFile, PATHINFO_EXTENSION));
$allowedTypes = ['jpg', 'jpeg', 'png', 'gif'];
if (!in_array($imageFileType, $allowedTypes)) {
$_SESSION['error_message'] = 'Only JPG, JPEG, PNG & GIF files are allowed.';
header('Location: ' . ($_SERVER['HTTP_REFERER'] ?? 'index.php'));
exit;
}
if (move_uploaded_file($_FILES['image']['tmp_name'], $uploadFile)) {
// Delete old image if a new one is uploaded
if ($image_url && file_exists($uploadDir . $image_url)) {
unlink($uploadDir . $image_url);
}
$image_url = $fileName;
} else {
$_SESSION['error_message'] = 'Failed to upload image.';
header('Location: ' . ($_SERVER['HTTP_REFERER'] ?? 'index.php'));
exit;
}
}
try {
if ($id) {
// Update existing product
$sql = "UPDATE products SET name = ?, description = ?, price = ?, stock_quantity = ?, image_url = ? WHERE id = ?";
$stmt = $pdo->prepare($sql);
$stmt->execute([$name, $description, $price, $stock_quantity, $image_url, $id]);
$_SESSION['success_message'] = 'Product updated successfully.';
} else {
// Insert new product
$sql = "INSERT INTO products (name, description, price, stock_quantity, image_url) VALUES (?, ?, ?, ?, ?)";
$stmt = $pdo->prepare($sql);
$stmt->execute([$name, $description, $price, $stock_quantity, $image_url]);
$_SESSION['success_message'] = 'Product added successfully.';
}
} catch (PDOException $e) {
$_SESSION['error_message'] = 'Database error. Could not save product.';
}
} else {
$_SESSION['error_message'] = 'Invalid request method.';
}
header('Location: index.php');
exit;

View File

@ -1,110 +0,0 @@
/* assets/css/custom.css */
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600;700&family=Lato:wght@400;700&display=swap');
:root {
--primary-color: #DF7E6B;
--secondary-color: #F6C390;
--background-color: #FCF8F3;
--surface-color: #FFFFFF;
--text-color: #333333;
--border-radius: 0.5rem;
}
body {
font-family: 'Lato', sans-serif;
background-color: var(--background-color);
color: var(--text-color);
}
h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6 {
font-family: 'Poppins', sans-serif;
font-weight: 600;
}
.btn-primary {
background-color: var(--primary-color);
border-color: var(--primary-color);
border-radius: var(--border-radius);
padding: 0.75rem 1.5rem;
transition: all 0.3s ease;
}
.btn-primary:hover {
opacity: 0.9;
transform: translateY(-2px);
}
.btn-secondary {
background-color: transparent;
border-color: var(--primary-color);
color: var(--primary-color);
border-radius: var(--border-radius);
padding: 0.75rem 1.5rem;
transition: all 0.3s ease;
}
.btn-secondary:hover {
background-color: var(--primary-color);
color: var(--surface-color);
}
.navbar {
transition: padding 0.3s ease-in-out, background-color 0.3s ease-in-out;
}
.navbar.scrolled {
padding-top: 0.5rem;
padding-bottom: 0.5rem;
background-color: rgba(255, 255, 255, 0.95);
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}
.navbar-brand {
font-family: 'Poppins', sans-serif;
font-weight: 700;
color: var(--primary-color) !important;
}
.hero {
padding: 6rem 0;
background-image: linear-gradient(135deg, rgba(246, 195, 144, 0.8), rgba(223, 126, 107, 0.8)), url('https://picsum.photos/seed/giftshop-hero/1600/900');
background-size: cover;
background-position: center;
color: white;
}
.hero h1 {
font-size: 3.5rem;
font-weight: 700;
}
.section-icon {
font-size: 3rem;
color: var(--primary-color);
}
.card {
border: none;
border-radius: var(--border-radius);
box-shadow: 0 4px 15px rgba(0,0,0,0.07);
transition: transform 0.3s ease, box-shadow 0.3s ease;
}
.card:hover {
transform: translateY(-5px);
box-shadow: 0 8px 25px rgba(0,0,0,0.1);
}
.testimonial-card .avatar {
width: 80px;
height: 80px;
border-radius: 50%;
object-fit: cover;
margin-top: -40px;
border: 4px solid var(--surface-color);
}
footer {
background-color: var(--surface-color);
}

View File

@ -1,64 +0,0 @@
document.addEventListener('DOMContentLoaded', function () {
const navbar = document.querySelector('.navbar');
const contactForm = document.querySelector('#contactForm');
// Navbar shrink on scroll
window.addEventListener('scroll', () => {
if (window.scrollY > 50) {
navbar.classList.add('scrolled');
} else {
navbar.classList.remove('scrolled');
}
});
// Smooth scrolling for anchor links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
const targetId = this.getAttribute('href');
const targetElement = document.querySelector(targetId);
if(targetElement){
targetElement.scrollIntoView({ behavior: 'smooth' });
}
});
});
// Basic form validation
if (contactForm) {
contactForm.addEventListener('submit', function(e) {
e.preventDefault();
let isValid = true;
const name = document.getElementById('name');
const email = document.getElementById('email');
const message = document.getElementById('message');
// Reset validation
[name, email, message].forEach(el => {
el.classList.remove('is-invalid');
});
if (name.value.trim() === '') {
name.classList.add('is-invalid');
isValid = false;
}
if (!/^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/.test(email.value)) {
email.classList.add('is-invalid');
isValid = false;
}
if (message.value.trim() === '') {
message.classList.add('is-invalid');
isValid = false;
}
if (isValid) {
// On a real site, you'd send this data to the server.
// For this demo, we'll just show a success message.
document.querySelector('#form-feedback').innerHTML = '<div class="alert alert-success">Thank you for your message! We will get back to you shortly.</div>';
contactForm.reset();
} else {
document.querySelector('#form-feedback').innerHTML = '';
}
});
}
});

Binary file not shown.

Before

Width:  |  Height:  |  Size: 67 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 60 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 36 KiB

View File

@ -1,206 +0,0 @@
<?php
session_start();
require_once 'db/config.php';
// Initialize basket if it doesn't exist
if (!isset($_SESSION['basket'])) {
$_SESSION['basket'] = [];
}
$pdo = db();
// Handle actions
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) {
$productId = $_POST['product_id'] ?? null;
switch ($_POST['action']) {
case 'add':
if ($productId) {
// Check if product exists and is in stock
$stmt = $pdo->prepare('SELECT name, stock_quantity FROM products WHERE id = ?');
$stmt->execute([$productId]);
$product = $stmt->fetch();
if ($product && $product['stock_quantity'] > 0) {
if (isset($_SESSION['basket'][$productId])) {
// Prevent adding more than available stock
if ($_SESSION['basket'][$productId] < $product['stock_quantity']) {
$_SESSION['basket'][$productId]++;
} else {
$_SESSION['message']['warning'] = "Cannot add more of this item. Not enough stock for " . $product['name'];
}
} else {
$_SESSION['basket'][$productId] = 1;
}
} else {
$_SESSION['message']['danger'] = "Cannot add item. Not enough stock for " . $product['name'];
}
}
break;
case 'update':
$quantity = $_POST['quantity'] ?? 1;
if ($productId && $quantity > 0) {
// Check stock
$stmt = $pdo->prepare('SELECT name, stock_quantity FROM products WHERE id = ?');
$stmt->execute([$productId]);
$product = $stmt->fetch();
if ($product && $quantity <= $product['stock_quantity']) {
$_SESSION['basket'][$productId] = (int)$quantity;
} else {
$_SESSION['message']['danger'] = "Cannot update quantity. Not enough stock for " . $product['name'];
}
} else if ($productId && $quantity <= 0) {
unset($_SESSION['basket'][$productId]);
}
break;
case 'remove':
if ($productId) {
unset($_SESSION['basket'][$productId]);
}
break;
}
// Redirect to avoid form resubmission
$redirect_url = $_POST['return_url'] ?? 'basket.php';
header('Location: ' . $redirect_url);
exit;
}
// Fetch product details for items in basket
$basketItems = [];
$totalPrice = 0;
if (!empty($_SESSION['basket'])) {
$productIds = array_keys($_SESSION['basket']);
$placeholders = implode(',', array_fill(0, count($productIds), '?'));
$stmt = $pdo->prepare("SELECT id, name, price, description, stock_quantity FROM products WHERE id IN ($placeholders)");
$stmt->execute($productIds);
$products = $stmt->fetchAll(PDO::FETCH_ASSOC | PDO::FETCH_GROUP);
foreach ($_SESSION['basket'] as $productId => $quantity) {
if (isset($products[$productId])) {
$product = $products[$productId][0];
$itemPrice = $product['price'] * $quantity;
$totalPrice += $itemPrice;
$basketItems[] = [
'id' => $productId,
'name' => $product['name'],
'price' => $product['price'],
'quantity' => $quantity,
'stock_quantity' => $product['stock_quantity'],
'total' => $itemPrice
];
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Shopping Basket - GiftShop</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
<link rel="stylesheet" href="assets/css/custom.css">
</head>
<body>
<!-- Navbar -->
<nav class="navbar navbar-expand-lg navbar-light bg-white shadow-sm">
<div class="container">
<a class="navbar-brand" href="index.php">GiftShop</a>
<div class="collapse navbar-collapse">
<ul class="navbar-nav ms-auto">
<li class="nav-item"><a class="nav-link" href="index.php#products">Products</a></li>
<li class="nav-item"><a class="nav-link" href="index.php#contact">Contact</a></li>
<li class="nav-item">
<a class="nav-link active" href="basket.php">
<i class="bi bi-cart-fill"></i> Basket (<?= array_sum($_SESSION['basket'] ?? []) ?>)
</a>
</li>
</ul>
</div>
</div>
</nav>
<!-- Main Content -->
<main class="container py-5">
<h1 class="mb-4">Your Shopping Basket</h1>
<?php if (isset($_SESSION['message'])):
foreach ($_SESSION['message'] as $type => $message):
?>
<div class="alert alert-<?= $type ?> alert-dismissible fade show" role="alert">
<?= htmlspecialchars($message) ?>
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
<?php
endforeach;
unset($_SESSION['message']);
endif;
?>
<?php if (empty($basketItems)): ?>
<div class="alert alert-info text-center">
<p class="mb-0">Your basket is empty.</p>
<a href="index.php" class="btn btn-primary mt-3">Start Shopping</a>
</div>
<?php else: ?>
<div class="row">
<div class="col-lg-8">
<div class="card">
<div class="card-body">
<?php foreach ($basketItems as $item): ?>
<div class="row align-items-center mb-3 pb-3 border-bottom">
<div class="col-md-7">
<h5><?= htmlspecialchars($item['name']) ?></h5>
<p class="text-muted mb-0">$<?= number_format($item['price'], 2) ?></p>
</div>
<div class="col-md-3">
<form action="basket.php" method="post" class="d-flex align-items-center">
<input type="hidden" name="action" value="update">
<input type="hidden" name="product_id" value="<?= $item['id'] ?>">
<input type="number" name="quantity" value="<?= $item['quantity'] ?>" min="1" max="<?= $item['stock_quantity'] ?>" class="form-control form-control-sm" style="width: 70px;" onchange="this.form.submit()">
</form>
</div>
<div class="col-md-2 text-end">
<form action="basket.php" method="post">
<input type="hidden" name="action" value="remove">
<input type="hidden" name="product_id" value="<?= $item['id'] ?>">
<button type="submit" class="btn btn-sm btn-outline-danger"><i class="bi bi-trash"></i></button>
</form>
</div>
</div>
<?php endforeach; ?>
</div>
</div>
</div>
<div class="col-lg-4">
<div class="card shadow-sm">
<div class="card-body">
<h5 class="card-title mb-3">Order Summary</h5>
<div class="d-flex justify-content-between mb-4">
<span class="h5">Total</span>
<span class="h5 text-primary">$<?= number_format($totalPrice, 2) ?></span>
</div>
<a href="#" class="btn btn-primary w-100 mb-2">Proceed to Checkout</a>
<a href="index.php" class="btn btn-outline-secondary w-100">Continue Shopping</a>
</div>
</div>
</div>
</div>
<?php endif; ?>
</main>
<!-- Footer -->
<footer class="py-4 mt-5 bg-light">
<div class="container text-center">
<p class="mb-0">&copy; <?= date("Y") ?> GiftShop. All Rights Reserved.</p>
</div>
</footer>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>

View File

@ -1,43 +0,0 @@
<?php
require_once __DIR__ . '/config.php';
try {
$pdo = db();
// Create migrations table if it doesn't exist
$pdo->exec('CREATE TABLE IF NOT EXISTS migrations (id INT AUTO_INCREMENT PRIMARY KEY, migration VARCHAR(255) NOT NULL, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP)');
// Get all executed migrations
$stmt = $pdo->query('SELECT migration FROM migrations');
$executedMigrations = $stmt ? $stmt->fetchAll(PDO::FETCH_COLUMN) : [];
// Find all migration files
$migrationFiles = glob(__DIR__ . '/migrations/*.sql') ?: [];
sort($migrationFiles);
$migrationsRun = false;
// Run pending migrations
foreach ($migrationFiles as $migrationFile) {
$migrationName = basename($migrationFile);
if (!in_array($migrationName, $executedMigrations)) {
$sql = file_get_contents($migrationFile);
if (!empty(trim($sql))) {
$pdo->exec($sql);
// Log the migration
$stmt = $pdo->prepare('INSERT INTO migrations (migration) VALUES (?)');
$stmt->execute([$migrationName]);
echo "Migration from $migrationName ran successfully.\n";
$migrationsRun = true;
}
}
}
if (!$migrationsRun) {
echo "All migrations are up to date.\n";
}
} catch (PDOException $e) {
die("DB ERROR: " . $e->getMessage());
}

View File

@ -1,7 +0,0 @@
CREATE TABLE IF NOT EXISTS users (
id INT AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(255) NOT NULL UNIQUE,
password VARCHAR(255) NOT NULL,
role VARCHAR(50) NOT NULL DEFAULT 'admin',
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

View File

@ -1,10 +0,0 @@
CREATE TABLE IF NOT EXISTS products (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255) NOT NULL,
description TEXT,
price DECIMAL(10, 2) NOT NULL,
stock_quantity INT NOT NULL DEFAULT 0,
image_url VARCHAR(255),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);

View File

@ -1 +0,0 @@
ALTER TABLE products ADD COLUMN image_url VARCHAR(255) DEFAULT NULL;

View File

@ -1,29 +0,0 @@
<?php
require_once __DIR__ . '/config.php';
try {
$pdo = db();
// Add a default admin user if one doesn't exist
$stmt = $pdo->prepare("SELECT id FROM users WHERE username = 'admin'");
$stmt->execute();
if ($stmt->fetch()) {
echo "Admin user already exists.\n";
} else {
$username = 'admin';
$password = 'password'; // You should change this!
$hashed_password = password_hash($password, PASSWORD_DEFAULT);
$role = 'super_admin';
$stmt = $pdo->prepare("INSERT INTO users (username, password, role) VALUES (:username, :password, :role)");
$stmt->bindParam(':username', $username);
$stmt->bindParam(':password', $hashed_password);
$stmt->bindParam(':role', $role);
$stmt->execute();
echo "Default admin user created with username 'admin' and password 'password'.\n";
}
} catch (PDOException $e) {
die("DB ERROR: " . $e->getMessage());
}

343
index.php
View File

@ -1,230 +1,131 @@
<?php session_start(); ?>
<!DOCTYPE html>
<?php
declare(strict_types=1);
@ini_set('display_errors', '1');
@error_reporting(E_ALL);
@date_default_timezone_set('UTC');
$phpVersion = PHP_VERSION;
$now = date('Y-m-d H:i:s');
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>GiftShop - Gifts for Every Occasion</title>
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
<!-- Bootstrap Icons -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
<!-- Google Fonts & Custom CSS -->
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>New Style</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;700&display=swap" rel="stylesheet">
<style>
:root {
--bg-color-start: #6a11cb;
--bg-color-end: #2575fc;
--text-color: #ffffff;
--card-bg-color: rgba(255, 255, 255, 0.01);
--card-border-color: rgba(255, 255, 255, 0.1);
}
body {
margin: 0;
font-family: 'Inter', sans-serif;
background: linear-gradient(45deg, var(--bg-color-start), var(--bg-color-end));
color: var(--text-color);
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
text-align: center;
overflow: hidden;
position: relative;
}
body::before {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 100 100"><path d="M-10 10L110 10M10 -10L10 110" stroke-width="1" stroke="rgba(255,255,255,0.05)"/></svg>');
animation: bg-pan 20s linear infinite;
z-index: -1;
}
@keyframes bg-pan {
0% { background-position: 0% 0%; }
100% { background-position: 100% 100%; }
}
main {
padding: 2rem;
}
.card {
background: var(--card-bg-color);
border: 1px solid var(--card-border-color);
border-radius: 16px;
padding: 2rem;
backdrop-filter: blur(20px);
-webkit-backdrop-filter: blur(20px);
box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.1);
}
.loader {
margin: 1.25rem auto 1.25rem;
width: 48px;
height: 48px;
border: 3px solid rgba(255, 255, 255, 0.25);
border-top-color: #fff;
border-radius: 50%;
animation: spin 1s linear infinite;
}
@keyframes spin {
from { transform: rotate(0deg); }
to { transform: rotate(360deg); }
}
.hint {
opacity: 0.9;
}
.sr-only {
position: absolute;
width: 1px; height: 1px;
padding: 0; margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap; border: 0;
}
h1 {
font-size: 3rem;
font-weight: 700;
margin: 0 0 1rem;
letter-spacing: -1px;
}
p {
margin: 0.5rem 0;
font-size: 1.1rem;
}
code {
background: rgba(0,0,0,0.2);
padding: 2px 6px;
border-radius: 4px;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
footer {
position: absolute;
bottom: 1rem;
font-size: 0.8rem;
opacity: 0.7;
}
</style>
</head>
<body>
<!-- Navbar -->
<nav class="navbar navbar-expand-lg navbar-light bg-transparent fixed-top">
<div class="container">
<a class="navbar-brand" href="#">GiftShop</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav ms-auto">
<li class="nav-item"><a class="nav-link" href="#products">Products</a></li>
<li class="nav-item"><a class="nav-link" href="#about">About</a></li>
<li class="nav-item"><a class="nav-link" href="#contact">Contact</a></li>
<li class="nav-item">
<a class="nav-link" href="basket.php">
<i class="bi bi-cart"></i> Basket (<?= array_sum($_SESSION['basket'] ?? []) ?>)
</a>
</li>
</ul>
<a href="#products" class="btn btn-primary ms-lg-3">Browse Catalog</a>
</div>
</div>
</nav>
<!-- Hero Section -->
<header id="home" class="hero text-center text-white">
<div class="container">
<h1 class="display-4">Gifts for Every Occasion.</h1>
<p class="lead my-4">Discover unique flowers, candies, books, and more. Perfectly packaged and delivered with care.</p>
<a href="#products" class="btn btn-primary btn-lg">Browse Catalog</a>
<a href="#contact" class="btn btn-secondary btn-lg ms-2">Contact Us</a>
</div>
</header>
<!-- Features Section -->
<section id="features" class="py-5">
<div class="container text-center">
<div class="row">
<div class="col-md-4 mb-4">
<i class="bi bi-gift section-icon mb-3"></i>
<h3>Wide Variety</h3>
<p>From fresh flowers to unique home goods, find the perfect present for anyone.</p>
</div>
<div class="col-md-4 mb-4">
<i class="bi bi-box-seam section-icon mb-3"></i>
<h3>Custom Packaging</h3>
<p>Make your gift extra special with our beautiful and creative packaging options.</p>
</div>
<div class="col-md-4 mb-4">
<i class="bi bi-truck section-icon mb-3"></i>
<h3>Fast Delivery</h3>
<p>We ensure your gifts are delivered quickly and with the utmost care across Poland.</p>
</div>
</div>
</div>
</section>
<!-- Products Section -->
<section id="products" class="py-5 bg-light">
<div class="container">
<div class="text-center mb-5">
<h2>Our Products</h2>
<p class="lead">Browse our curated collection of gifts.</p>
</div>
<?php if (isset($_SESSION['message'])):
foreach ($_SESSION['message'] as $type => $message):
?>
<div class="alert alert-<?= $type ?> alert-dismissible fade show" role="alert">
<?= htmlspecialchars($message) ?>
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
<?php
endforeach;
unset($_SESSION['message']);
endif;
?>
<div class="row">
<?php
require_once 'db/config.php';
$pdo = db();
$stmt = $pdo->query('SELECT id, name, description, price, stock_quantity, image_url FROM products ORDER BY name');
$products = $stmt->fetchAll(PDO::FETCH_ASSOC);
if ($products):
foreach ($products as $product):
?>
<div class="col-md-4 mb-4">
<div class="card h-100">
<img src="<?= htmlspecialchars($product['image_url'] ? 'uploads/' . $product['image_url'] : 'https://picsum.photos/seed/product-' . $product['id'] . '/600/400') ?>" class="card-img-top" alt="<?= htmlspecialchars($product['name']) ?>">
<div class="card-body d-flex flex-column">
<h5 class="card-title"><?= htmlspecialchars($product['name']) ?></h5>
<p class="card-text"><?= htmlspecialchars($product['description']) ?></p>
<div class="mt-auto">
<p class="h4 text-primary mb-3">$<?= number_format($product['price'], 2) ?></p>
<form action="basket.php" method="post">
<input type="hidden" name="product_id" value="<?= $product['id'] ?>">
<input type="hidden" name="action" value="add">
<input type="hidden" name="return_url" value="index.php">
<button type="submit" class="btn btn-primary w-100" <?= ($product['stock_quantity'] <= 0) ? 'disabled' : '' ?>>
<i class="bi bi-cart-plus"></i> <?= ($product['stock_quantity'] > 0) ? 'Add to Basket' : 'Out of Stock' ?>
</button>
</form>
</div>
</div>
</div>
</div>
<?php
endforeach;
else:
?>
<div class="col-12">
<p class="text-center">No products found. Please check back later!</p>
</div>
<?php endif; ?>
</div>
</div>
</section>
<!-- Testimonials Section -->
<section id="about" class="py-5">
<div class="container">
<div class="text-center mb-5">
<h2>What Our Customers Say</h2>
</div>
<div class="row">
<div class="col-md-4 mb-5">
<div class="card testimonial-card text-center p-4">
<img src="https://picsum.photos/seed/avatar1/96/96" class="avatar mx-auto" alt="Customer avatar">
<div class="card-body">
<p class="card-text fst-italic">"The most beautiful gift basket I've ever received! The quality and presentation were top-notch."</p>
<footer class="blockquote-footer mt-3">Anna K.</footer>
</div>
</div>
</div>
<div class="col-md-4 mb-5">
<div class="card testimonial-card text-center p-4">
<img src="https://picsum.photos/seed/avatar2/96/96" class="avatar mx-auto" alt="Customer avatar">
<div class="card-body">
<p class="card-text fst-italic">"Fast delivery and the flowers were so fresh. My go-to for last-minute gifts!"</p>
<footer class="blockquote-footer mt-3">Piotr Z.</footer>
</div>
</div>
</div>
<div class="col-md-4 mb-5">
<div class="card testimonial-card text-center p-4">
<img src="https://picsum.photos/seed/avatar3/96/96" class="avatar mx-auto" alt="Customer avatar">
<div class="card-body">
<p class="card-text fst-italic">"I love the unique items you can't find anywhere else. Highly recommended!"</p>
<footer class="blockquote-footer mt-3">Ewa N.</footer>
</div>
</div>
</div>
</div>
</div>
</section>
<!-- Contact Section -->
<section id="contact" class="py-5 bg-light">
<div class="container">
<div class="text-center mb-5">
<h2>Get In Touch</h2>
<p class="lead">Have a question or a special request? Let us know!</p>
</div>
<div class="row justify-content-center">
<div class="col-lg-8">
<form id="contactForm" novalidate>
<div id="form-feedback"></div>
<div class="mb-3">
<label for="name" class="form-label">Name</label>
<input type="text" class="form-control" id="name" required>
<div class="invalid-feedback">Please enter your name.</div>
</div>
<div class="mb-3">
<label for="email" class="form-label">Email</label>
<input type="email" class="form-control" id="email" required>
<div class="invalid-feedback">Please enter a valid email address.</div>
</div>
<div class="mb-3">
<label for="message" class="form-label">Message</label>
<textarea class="form-control" id="message" rows="5" required></textarea>
<div class="invalid-feedback">Please enter your message.</div>
</div>
<div class="text-center">
<button type="submit" class="btn btn-primary btn-lg">Send Message</button>
</div>
</form>
</div>
</div>
</div>
</section>
<!-- Footer -->
<footer class="py-4">
<div class="container text-center">
<p class="mb-2">&copy; <?php echo date("Y"); ?> GiftShop. All Rights Reserved.</p>
<div>
<a href="#" class="text-dark mx-2"><i class="bi bi-facebook"></i></a>
<a href="#" class="text-dark mx-2"><i class="bi bi-instagram"></i></a>
<a href="#" class="text-dark mx-2"><i class="bi bi-pinterest"></i></a>
</div>
<div class="mt-3">
<a href="login.php" class="text-muted">Admin Login</a>
<main>
<div class="card">
<h1>Analyzing your requirements and generating your website…</h1>
<div class="loader" role="status" aria-live="polite" aria-label="Applying initial changes">
<span class="sr-only">Loading…</span>
</div>
<p class="hint">Flatlogic AI is collecting your requirements and applying the first changes.</p>
<p class="hint">This page will update automatically as the plan is implemented.</p>
<p>Runtime: PHP <code><?= htmlspecialchars($phpVersion) ?></code> — UTC <code><?= htmlspecialchars($now) ?></code></p>
</div>
</main>
<footer>
Page updated: <?= htmlspecialchars($now) ?> (UTC)
</footer>
<!-- Bootstrap JS -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
<!-- Custom JS -->
<script src="assets/js/main.js?v=<?php echo time(); ?>"></script>
</body>
</html>

View File

@ -1,93 +0,0 @@
<?php
session_start();
require_once __DIR__ . '/db/config.php';
// If user is already logged in, redirect to admin dashboard
if (isset($_SESSION['user_id'])) {
header('Location: admin/index.php');
exit;
}
$error_message = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$username = $_POST['username'] ?? '';
$password = $_POST['password'] ?? '';
if (empty($username) || empty($password)) {
$error_message = 'Please enter both username and password.';
} else {
try {
$pdo = db();
$stmt = $pdo->prepare("SELECT * FROM users WHERE username = :username");
$stmt->bindParam(':username', $username);
$stmt->execute();
$user = $stmt->fetch();
if ($user && password_verify($password, $user['password'])) {
// Password is correct, start session
$_SESSION['user_id'] = $user['id'];
$_SESSION['username'] = $user['username'];
$_SESSION['user_role'] = $user['role'];
// Redirect to admin dashboard
header('Location: admin/index.php');
exit;
} else {
$error_message = 'Invalid username or password.';
}
} catch (PDOException $e) {
$error_message = 'Database error: ' . $e->getMessage();
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Admin Login - GiftShop</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="assets/css/custom.css">
<style>
body {
display: flex;
align-items: center;
justify-content: center;
min-height: 100vh;
background-color: #FCF8F3;
}
.login-card {
max-width: 400px;
width: 100%;
}
</style>
</head>
<body>
<div class="card login-card shadow-sm">
<div class="card-body p-5">
<h1 class="card-title text-center mb-4">Admin Login</h1>
<?php if ($error_message): ?>
<div class="alert alert-danger"><?php echo $error_message; ?></div>
<?php endif; ?>
<form method="POST" action="login.php">
<div class="mb-3">
<label for="username" class="form-label">Username</label>
<input type="text" class="form-control" id="username" name="username" required>
</div>
<div class="mb-3">
<label for="password" class="form-label">Password</label>
<input type="password" class="form-control" id="password" name="password" required>
</div>
<div class="d-grid">
<button type="submit" class="btn btn-primary">Login</button>
</div>
</form>
<div class="text-center mt-3">
<a href="index.php"> Back to site</a>
</div>
</div>
</div>
</body>
</html>

View File

@ -1,16 +0,0 @@
<?php
require_once __DIR__ . '/db/config.php';
try {
$pdo = db();
$stmt = $pdo->prepare("UPDATE users SET role = 'super_admin' WHERE username = 'admin'");
$stmt->execute();
if ($stmt->rowCount() > 0) {
echo "User role updated successfully. You can now log in to the admin panel. Please delete this file immediately.";
} else {
echo "Could not find the 'admin' user or the role is already 'super_admin'. Please check your database. You can delete this file.";
}
} catch (PDOException $e) {
echo "Database error: " . $e->getMessage();
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 229 KiB