Spaces:
Running

f3squadshop / index.html
F3squad18's picture
Viết code tạo ra một shop bán đồ, tôi là Admin, Admin có thể chỉnh sửa shop, tôi có một tài khoảng Admin tên là F3squad mật khẩu là tuongbienTuongbien14082012 mã đặc quyền là 14082012, thêm các món đồ mà tôi muốn bán, xoá các món đồ mà thôi muốn, chỉnh sửa các món dồ mà tôi muốn, shop có link là F3squadshop.com.vn, shop có tên là F3squadshop; khi mới bào shop thì sẽ có ba khung; khung bên trái là khung đăng nhập của Admin khung đăng nhập của Admin thì có 3 khung nhỏ khung 1 là tên tài khoảng khung 2 là khung mật khẩu khung 3 là khung mã đặc quyền ( chỉ có đăng nhập Admin mới có mã đặc quyền) ; khung chính giữa là khung đăng nhập của khách hàng, khung đăng nhập của khách hàng có 2 khung, khung 1 khung điền tên, khung 2 là khung điền mật khẩu; khung bên phải là khung đăng kí của khách hàng; có 3 khung, khung 1 là khung nhập tên, khung 2 là khung nhập mật khẩu, khung 3 là khung xác nhận mật khẩu.[ Khi đăng nhập xong thì vào được trang chủ shop thì màng hình của admin có phần quản trị viên trong đó có các phần bao gồm, thêm món đồ ( khi bấm vào phần thêm món đồ thì hiện ra một cái bản trong cái bản đó có phần mã sản phẩm, có phần tên sản phẩm, có phần giá mua - giá bán - số lượng), trong đó có phần lưu sản phẩm( khi bấm lưu sản phẩm thì sản phẩm được lưu và hiện ra phần trang chủ sản phẩm ); khi khách hàng đặc mua sản phẩm thì sẽ thông báo đến phần đang chờ sử lý - Initial Deployment
9d8d38b verified
Raw History Blame Contribute Delete
51.1 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>F3squadshop - Admin Panel</title> <script src="https://cdn.tailwindcss.com"></script> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css"> <style> .hidden { display: none; } .product-image { width: 100px; height: 100px; object-fit: cover; } .order-notification { animation: pulse 2s infinite; } @keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(59, 130, 246, 0.7); } 70% { box-shadow: 0 0 0 10px rgba(59, 130, 246, 0); } 100% { box-shadow: 0 0 0 0 rgba(59, 130, 246, 0); } } </style> </head> <body class="bg-gray-100"> <!-- Initial Login Screen --> <div id="initialScreen" class="container mx-auto px-4 py-8"> <div class="flex flex-col md:flex-row gap-4"> <!-- Admin Login Panel (Left) --> <div class="w-full md:w-1/3 bg-white p-6 rounded-lg shadow-md"> <h2 class="text-xl font-bold mb-4 text-blue-600">Admin Login</h2> <div class="space-y-4"> <div> <label class="block text-gray-700">Username</label> <input type="text" id="adminUsername" placeholder="Enter admin username" class="w-full px-4 py-2 border rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"> </div> <div> <label class="block text-gray-700">Password</label> <input type="password" id="adminPassword" placeholder="Enter admin password" class="w-full px-4 py-2 border rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"> </div> <div> <label class="block text-gray-700">Privilege Code</label> <input type="password" id="adminPrivilege" placeholder="Enter privilege code" class="w-full px-4 py-2 border rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"> </div> <button onclick="adminLogin()" class="w-full bg-blue-600 hover:bg-blue-700 text-white py-2 rounded-md transition duration-300"> Login as Admin </button> </div> </div> <!-- Customer Login Panel (Center) --> <div class="w-full md:w-1/3 bg-white p-6 rounded-lg shadow-md"> <h2 class="text-xl font-bold mb-4 text-green-600">Customer Login</h2> <div class="space-y-4"> <div> <label class="block text-gray-700">Username</label> <input type="text" id="customerUsername" placeholder="Enter username" class="w-full px-4 py-2 border rounded-md focus:outline-none focus:ring-2 focus:ring-green-500"> </div> <div> <label class="block text-gray-700">Password</label> <input type="password" id="customerPassword" placeholder="Enter password" class="w-full px-4 py-2 border rounded-md focus:outline-none focus:ring-2 focus:ring-green-500"> </div> <button onclick="customerLogin()" class="w-full bg-green-600 hover:bg-green-700 text-white py-2 rounded-md transition duration-300"> Login as Customer </button> </div> </div> <!-- Customer Registration Panel (Right) --> <div class="w-full md:w-1/3 bg-white p-6 rounded-lg shadow-md"> <h2 class="text-xl font-bold mb-4 text-purple-600">Customer Registration</h2> <div class="space-y-4"> <div> <label class="block text-gray-700">Username</label> <input type="text" id="regUsername" placeholder="Choose username" class="w-full px-4 py-2 border rounded-md focus:outline-none focus:ring-2 focus:ring-purple-500"> </div> <div> <label class="block text-gray-700">Password</label> <input type="password" id="regPassword" placeholder="Choose password" class="w-full px-4 py-2 border rounded-md focus:outline-none focus:ring-2 focus:ring-purple-500"> </div> <div> <label class="block text-gray-700">Confirm Password</label> <input type="password" id="regConfirmPassword" placeholder="Confirm password" class="w-full px-4 py-2 border rounded-md focus:outline-none focus:ring-2 focus:ring-purple-500"> </div> <button onclick="registerCustomer()" class="w-full bg-purple-600 hover:bg-purple-700 text-white py-2 rounded-md transition duration-300"> Register </button> </div> </div> </div> </div> <!-- Admin Dashboard --> <div id="adminDashboard" class="hidden container mx-auto px-4 py-8"> <div class="flex justify-between items-center mb-8"> <h1 class="text-3xl font-bold text-blue-600">F3squadshop Admin Panel</h1> <button onclick="logout()" class="bg-red-500 hover:bg-red-600 text-white px-4 py-2 rounded-md"> Logout <i class="fas fa-sign-out-alt ml-1"></i> </button> </div> <div class="flex flex-col md:flex-row gap-6"> <!-- Admin Navigation --> <div class="w-full md:w-1/4 bg-white p-4 rounded-lg shadow-md"> <div class="mb-6"> <h2 class="text-xl font-bold mb-2 text-gray-800">Admin Menu</h2> <div class="space-y-2"> <button onclick="showDashboard()" id="dashboardBtn" class="w-full text-left px-4 py-2 bg-blue-100 text-blue-800 rounded-md"> <i class="fas fa-tachometer-alt mr-2"></i> Dashboard </button> <button onclick="showAddProduct()" id="addProductBtn" class="w-full text-left px-4 py-2 bg-blue-100 text-blue-800 rounded-md"> <i class="fas fa-plus-circle mr-2"></i> Add Product </button> <button onclick="showManageProducts()" id="manageProductsBtn" class="w-full text-left px-4 py-2 bg-blue-100 text-blue-800 rounded-md"> <i class="fas fa-boxes mr-2"></i> Manage Products </button> <button onclick="showOrders()" id="ordersBtn" class="w-full text-left px-4 py-2 bg-blue-100 text-blue-800 rounded-md"> <i class="fas fa-clipboard-list mr-2"></i> Pending Orders <span id="orderNotificationBadge" class="hidden ml-2 bg-red-500 text-white text-xs px-2 py-1 rounded-full">0</span> </button> </div> </div> <div> <h2 class="text-xl font-bold mb-2 text-gray-800">Admin Info</h2> <div class="bg-gray-100 p-3 rounded-md"> <p><strong>Username:</strong> <span id="adminDisplayName">F3squad</span></p> <p><strong>Privilege Code:</strong> 14082012</p> </div> </div> </div> <!-- Main Content Area --> <div class="w-full md:w-3/4"> <!-- Dashboard --> <div id="dashboardContent" class="bg-white p-6 rounded-lg shadow-md"> <h2 class="text-2xl font-bold mb-4 text-blue-600">Admin Dashboard</h2> <div class="grid grid-cols-1 md:grid-cols-3 gap-4 mb-6"> <div class="bg-blue-100 p-4 rounded-lg"> <h3 class="font-bold text-blue-800">Total Products</h3> <p id="totalProducts" class="text-3xl">0</p> </div> <div class="bg-green-100 p-4 rounded-lg"> <h3 class="font-bold text-green-800">Pending Orders</h3> <p id="pendingOrders" class="text-3xl">0</p> </div> <div class="bg-purple-100 p-4 rounded-lg"> <h3 class="font-bold text-purple-800">Total Customers</h3> <p id="totalCustomers" class="text-3xl">0</p> </div> </div> <div class="bg-white border rounded-lg overflow-hidden"> <table class="min-w-full divide-y divide-gray-200"> <thead class="bg-gray-50"> <tr> <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Recent Orders</th> <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Customer</th> <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Status</th> </tr> </thead> <tbody id="recentOrdersTable" class="bg-white divide-y divide-gray-200"> <!-- Recent orders will be added here --> </tbody> </table> </div> </div> <!-- Add Product Form --> <div id="addProductContent" class="hidden bg-white p-6 rounded-lg shadow-md"> <h2 class="text-2xl font-bold mb-4 text-blue-600">Add New Product</h2> <form id="productForm" class="space-y-4"> <div class="grid grid-cols-1 md:grid-cols-2 gap-4"> <div> <label class="block text-gray-700">Product Code</label> <input type="text" id="productCode" required class="w-full px-4 py-2 border rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"> </div> <div> <label class="block text-gray-700">Product Name</label> <input type="text" id="productName" required class="w-full px-4 py-2 border rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"> </div> </div> <div class="grid grid-cols-1 md:grid-cols-3 gap-4"> <div> <label class="block text-gray-700">Purchase Price ($)</label> <input type="number" id="purchasePrice" required step="0.01" class="w-full px-4 py-2 border rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"> </div> <div> <label class="block text-gray-700">Selling Price ($)</label> <input type="number" id="sellingPrice" required step="0.01" class="w-full px-4 py-2 border rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"> </div> <div> <label class="block text-gray-700">Quantity</label> <input type="number" id="productQuantity" required class="w-full px-4 py-2 border rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"> </div> </div> <div> <label class="block text-gray-700">Product Description</label> <textarea id="productDescription" rows="3" class="w-full px-4 py-2 border rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"></textarea> </div> <div> <label class="block text-gray-700">Product Image URL</label> <input type="text" id="productImageUrl" class="w-full px-4 py-2 border rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"> </div> <div class="flex justify-end space-x-3"> <button type="button" onclick="resetProductForm()" class="px-4 py-2 bg-gray-300 rounded-md"> <i class="fas fa-eraser mr-1"></i> Reset </button> <button type="button" onclick="saveProduct()" class="px-4 py-2 bg-green-600 text-white rounded-md"> <i class="fas fa-save mr-1"></i> Save Product </button> </div> </form> </div> <!-- Manage Products --> <div id="manageProductsContent" class="hidden bg-white p-6 rounded-lg shadow-md"> <h2 class="text-2xl font-bold mb-4 text-blue-600">Manage Products</h2> <div class="mb-4"> <input type="text" id="productSearch" placeholder="Search products..." class="w-full md:w-1/3 px-4 py-2 border rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"> </div> <div class="overflow-x-auto"> <table class="min-w-full divide-y divide-gray-200"> <thead class="bg-gray-50"> <tr> <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Image</th> <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Code</th> <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Name</th> <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Price</th> <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Stock</th> <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Actions</th> </tr> </thead> <tbody id="productsTable" class="bg-white divide-y divide-gray-200"> <!-- Products will be added here --> </tbody> </table> </div> </div> <!-- Edit Product Modal --> <div id="editProductModal" class="hidden fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50"> <div class="bg-white p-6 rounded-lg shadow-lg w-full max-w-2xl"> <div class="flex justify-between items-center mb-4"> <h3 class="text-xl font-bold text-blue-600">Edit Product</h3> <button onclick="closeEditModal()" class="text-gray-500 hover:text-gray-700"> <i class="fas fa-times"></i> </button> </div> <div id="editProductForm" class="space-y-4"> <!-- Form content will be filled by JavaScript --> </div> </div> </div> <!-- Orders Management --> <div id="ordersContent" class="hidden bg-white p-6 rounded-lg shadow-md"> <h2 class="text-2xl font-bold mb-4 text-blue-600">Pending Orders</h2> <div class="overflow-x-auto"> <table class="min-w-full divide-y divide-gray-200"> <thead class="bg-gray-50"> <tr> <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Order ID</th> <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Customer</th> <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Products</th> <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Total</th> <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Status</th> <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Actions</th> </tr> </thead> <tbody id="ordersTable" class="bg-white divide-y divide-gray-200"> <!-- Orders will be added here --> </tbody> </table> </div> </div> </div> </div> </div> <!-- Customer Shop --> <div id="customerShop" class="hidden container mx-auto px-4 py-8"> <div class="flex justify-between items-center mb-8"> <h1 class="text-3xl font-bold text-green-600">Welcome to F3squadshop</h1> <div class="flex items-center space-x-3"> <span id="customerName" class="font-medium"></span> <button onclick="customerLogout()" class="bg-red-500 hover:bg-red-600 text-white px-4 py-2 rounded-md"> Logout <i class="fas fa-sign-out-alt ml-1"></i> </button> </div> </div> <div class="grid grid-cols-1 md:grid-cols-4 gap-6"> <!-- Product Display --> <div id="productsDisplay" class="grid grid-cols-1 md:grid-cols-4 gap-6 col-span-3"> <!-- Products will be displayed here --> </div> <!-- Shopping Cart --> <div class="col-span-1 bg-white p-4 rounded-lg shadow-md sticky top-4 h-fit"> <h2 class="text-xl font-bold mb-4 text-green-600">Your Cart</h2> <div id="cartItems"> <p class="text-gray-500">Your cart is empty</p> </div> <div id="cartSummary" class="mt-4 hidden"> <div class="border-t pt-3"> <div class="flex justify-between font-bold"> <span>Total:</span> <span id="cartTotal">$0.00</span> </div> <button id="checkoutBtn" class="w-full mt-4 bg-green-600 hover:bg-green-700 text-white py-2 rounded-md"> Checkout </button> </div> </div> </div> </div> </div> <script> // Data storage let products = [ { id: 1, code: "F3-001", name: "Premium Gaming Headset", purchasePrice: 45.00, sellingPrice: 89.99, quantity: 15, description: "High-quality gaming headset with surround sound", image: "https://images.unsplash.com/photo-1613040818710-7e9e7206fd3e?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=500&q=80" }, { id: 2, code: "F3-002", name: "Mechanical Keyboard", purchasePrice: 35.00, sellingPrice: 72.50, quantity: 22, description: "RGB mechanical keyboard with customizable keys", image: "https://images.unsplash.com/photo-1587829741301-dc798b83add3?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=500&q=80" } ]; let customers = [ { username: "customer1", password: "password123" }, { username: "customer2", password: "password456" } ]; let orders = []; let currentUser = null; let currentAdmin = null; let shoppingCart = []; // DOM Elements const initialScreen = document.getElementById('initialScreen'); const adminDashboard = document.getElementById('adminDashboard'); const customerShop = document.getElementById('customerShop'); // Admin elements const dashboardContent = document.getElementById('dashboardContent'); const addProductContent = document.getElementById('addProductContent'); const manageProductsContent = document.getElementById('manageProductsContent'); const ordersContent = document.getElementById('ordersContent'); const productsTable = document.getElementById('productsTable'); // Customer elements const productsDisplay = document.getElementById('productsDisplay'); const cartItems = document.getElementById('cartItems'); const cartSummary = document.getElementById('cartSummary'); const checkoutBtn = document.getElementById('checkoutBtn'); // Login functions function adminLogin() { const username = document.getElementById('adminUsername').value; const password = document.getElementById('adminPassword').value; const privilege = document.getElementById('adminPrivilege').value; if (username === 'F3squad' && password === 'tuongbienTuongbien14082012' && privilege === '14082012') { currentAdmin = username; initialScreen.classList.add('hidden'); adminDashboard.classList.remove('hidden'); document.getElementById('adminDisplayName').textContent = username; // Load admin dashboard showDashboard(); updateDashboardStats(); renderProductsTable(); renderRecentOrders(); } else { alert('Invalid admin credentials or privilege code'); } } function customerLogin() { const username = document.getElementById('customerUsername').value; const password = document.getElementById('customerPassword').value; const customer = customers.find(c => c.username === username && c.password === password); if (customer) { currentUser = username; initialScreen.classList.add('hidden'); customerShop.classList.remove('hidden'); // Update UI document.getElementById('customerName').textContent = `Welcome, ${username}`; renderProductsForCustomers(); } else { alert('Invalid customer credentials'); } } function registerCustomer() { const username = document.getElementById('regUsername').value; const password = document.getElementById('regPassword').value; const confirmPassword = document.getElementById('regConfirmPassword').value; if (!username || !password) { alert('Please enter both username and password'); return; } if (password !== confirmPassword) { alert('Passwords do not match'); return; } if (customers.some(c => c.username === username)) { alert('Username already exists'); return; } customers.push({ username, password }); alert('Registration successful! Please login.'); // Clear form document.getElementById('regUsername').value = ''; document.getElementById('regPassword').value = ''; document.getElementById('regConfirmPassword').value = ''; } function logout() { currentAdmin = null; adminDashboard.classList.add('hidden'); initialScreen.classList.remove('hidden'); } function customerLogout() { currentUser = null; customerShop.classList.add('hidden'); initialScreen.classList.remove('hidden'); shoppingCart = []; } // Admin panel navigation function showDashboard() { hideAllContents(); dashboardContent.classList.remove('hidden'); updateDashboardStats(); renderRecentOrders(); } function showAddProduct() { hideAllContents(); addProductContent.classList.remove('hidden'); } function showManageProducts() { hideAllContents(); manageProductsContent.classList.remove('hidden'); renderProductsTable(); } function showOrders() { hideAllContents(); ordersContent.classList.remove('hidden'); renderOrdersTable(); // Clear order notification document.getElementById('orderNotificationBadge').classList.add('hidden'); } function hideAllContents() { dashboardContent.classList.add('hidden'); addProductContent.classList.add('hidden'); manageProductsContent.classList.add('hidden'); ordersContent.classList.add('hidden'); } // Product management function saveProduct() { const code = document.getElementById('productCode').value; const name = document.getElementById('productName').value; const purchasePrice = parseFloat(document.getElementById('purchasePrice').value); const sellingPrice = parseFloat(document.getElementById('sellingPrice').value); const quantity = parseInt(document.getElementById('productQuantity').value); const description = document.getElementById('productDescription').value; const image = document.getElementById('productImageUrl').value; // Generate a new ID const id = products.length > 0 ? Math.max(...products.map(p => p.id)) + 1 : 1; const newProduct = { id, code, name, purchasePrice, sellingPrice, quantity, description, image: image || 'https://via.placeholder.com/150' }; products.push(newProduct); alert('Product saved successfully!'); resetProductForm(); updateDashboardStats(); renderProductsTable(); // Switch to manage products view showManageProducts(); } function resetProductForm() { document.getElementById('productForm').reset(); } function renderProductsTable() { productsTable.innerHTML = ''; products.forEach(product => { const row = document.createElement('tr'); row.className = 'hover:bg-gray-50'; row.innerHTML = ` <td class="px-6 py-4 whitespace-nowrap"> <img src="${product.image}" class="product-image rounded-md"> </td> <td class="px-6 py-4 whitespace-nowrap"> <div class="text-sm font-medium text-gray-900">${product.code}</div> </td> <td class="px-6 py-4 whitespace-nowrap"> <div class="text-sm font-medium text-gray-900">${product.name}</div> <div class="text-sm text-gray-500 truncate max-w-xs">${product.description}</div> </td> <td class="px-6 py-4 whitespace-nowrap"> <div class="text-sm font-medium text-gray-900">$${product.sellingPrice.toFixed(2)}</div> </td> <td class="px-6 py-4 whitespace-nowrap"> <span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full ${product.quantity > 5 ? 'bg-green-100 text-green-800' : 'bg-yellow-100 text-yellow-800'}"> ${product.quantity} in stock </span> </td> <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500"> <button onclick="editProduct(${product.id})" class="text-blue-600 hover:text-blue-900 mr-2"> <i class="fas fa-edit"></i> </button> <button onclick="deleteProduct(${product.id})" class="text-red-600 hover:text-red-900"> <i class="fas fa-trash-alt"></i> </button> </td> `; productsTable.appendChild(row); }); } function editProduct(productId) { const product = products.find(p => p.id === productId); if (!product) return; const editForm = document.getElementById('editProductForm'); editForm.innerHTML = ` <div class="grid grid-cols-1 md:grid-cols-2 gap-4"> <div> <label class="block text-gray-700">Product Code</label> <input type="text" id="editProductCode" value="${product.code}" required class="w-full px-4 py-2 border rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"> </div> <div> <label class="block text-gray-700">Product Name</label> <input type="text" id="editProductName" value="${product.name}" required class="w-full px-4 py-2 border rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"> </div> </div> <div class="grid grid-cols-1 md:grid-cols-3 gap-4"> <div> <label class="block text-gray-700">Purchase Price ($)</label> <input type="number" id="editPurchasePrice" value="${product.purchasePrice}" required step="0.01" class="w-full px-4 py-2 border rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"> </div> <div> <label class="block text-gray-700">Selling Price ($)</label> <input type="number" id="editSellingPrice" value="${product.sellingPrice}" required step="0.01" class="w-full px-4 py-2 border rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"> </div> <div> <label class="block text-gray-700">Quantity</label> <input type="number" id="editProductQuantity" value="${product.quantity}" required class="w-full px-4 py-2 border rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"> </div> </div> <div> <label class="block text-gray-700">Product Description</label> <textarea id="editProductDescription" rows="3" class="w-full px-4 py-2 border rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500">${product.description}</textarea> </div> <div> <label class="block text-gray-700">Product Image URL</label> <input type="text" id="editProductImageUrl" value="${product.image}" class="w-full px-4 py-2 border rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"> </div> <div class="flex justify-end space-x-3"> <button type="button" onclick="closeEditModal()" class="px-4 py-2 bg-gray-300 rounded-md"> <i class="fas fa-times mr-1"></i> Cancel </button> <button type="button" onclick="updateProduct(${productId})" class="px-4 py-2 bg-green-600 text-white rounded-md"> <i class="fas fa-save mr-1"></i> Update Product </button> </div> `; document.getElementById('editProductModal').classList.remove('hidden'); } function closeEditModal() { document.getElementById('editProductModal').classList.add('hidden'); } function updateProduct(productId) { const productIndex = products.findIndex(p => p.id === productId); if (productIndex === -1) return; products[productIndex] = { ...products[productIndex], code: document.getElementById('editProductCode').value, name: document.getElementById('editProductName').value, purchasePrice: parseFloat(document.getElementById('editPurchasePrice').value), sellingPrice: parseFloat(document.getElementById('editSellingPrice').value), quantity: parseInt(document.getElementById('editProductQuantity').value), description: document.getElementById('editProductDescription').value, image: document.getElementById('editProductImageUrl').value || 'https://via.placeholder.com/150' }; closeEditModal(); renderProductsTable(); updateDashboardStats(); // If we're on customer view, update that too if (currentUser) { renderProductsForCustomers(); } } function deleteProduct(productId) { if (confirm('Are you sure you want to delete this product?')) { products = products.filter(p => p.id !== productId); renderProductsTable(); updateDashboardStats(); // If we're on customer view, update that too if (currentUser) { renderProductsForCustomers(); } } } // Customer shop functions function renderProductsForCustomers() { productsDisplay.innerHTML = ''; if (products.length === 0) { productsDisplay.innerHTML = '<div class="col-span-4 text-center py-8"><p class="text-gray-500">No products available</p></div>'; return; } products.forEach(product => { const productCard = document.createElement('div'); productCard.className = 'bg-white rounded-lg shadow-md overflow-hidden hover:shadow-lg transition duration-300'; productCard.innerHTML = ` <div class="relative"> <img src="${product.image}" class="w-full h-48 object-cover"> ${product.quantity === 0 ? '<div class="absolute top-2 right-2 bg-red-500 text-white px-2 py-1 rounded text-xs">OUT OF STOCK</div>' : ''} </div> <div class="p-4"> <h3 class="font-bold text-lg mb-1">${product.name}</h3> <p class="text-gray-600 text-sm mb-2">${product.code}</p> <p class="font-bold text-green-600 mb-3">$${product.sellingPrice.toFixed(2)}</p> <div class="flex justify-between items-center"> <span class="text-sm ${product.quantity > 5 ? 'text-green-500' : product.quantity > 0 ? 'text-yellow-500' : 'text-red-500'}"> ${product.quantity > 0 ? `${product.quantity} available` : 'Out of stock'} </span> <button onclick="addToCart(${product.id})" class="px-3 py-1 bg-blue-600 hover:bg-blue-700 text-white rounded-md text-sm ${product.quantity === 0 ? 'opacity-50 cursor-not-allowed' : ''}" ${product.quantity === 0 ? 'disabled' : ''}> Add to Cart </button> </div> </div> `; productsDisplay.appendChild(productCard); }); } function addToCart(productId) { const product = products.find(p => p.id === productId); if (!product || product.quantity === 0) return; const existingItem = shoppingCart.find(item => item.productId === productId); if (existingItem) { // Check stock availability if (existingItem.quantity < product.quantity) { existingItem.quantity += 1; } else { alert('Cannot add more than available stock'); return; } } else { shoppingCart.push({ productId, name: product.name, price: product.sellingPrice, quantity: 1, image: product.image }); } updateCartDisplay(); } function updateCartDisplay() { cartItems.innerHTML = ''; if (shoppingCart.length === 0) { cartItems.innerHTML = '<p class="text-gray-500">Your cart is empty</p>'; cartSummary.classList.add('hidden'); return; } let total = 0; shoppingCart.forEach(item => { const cartItem = document.createElement('div'); cartItem.className = 'flex justify-between items-center py-2 border-b'; cartItem.innerHTML = ` <div class="flex items-center space-x-2"> <img src="${item.image}" class="w-10 h-10 rounded-md object-cover"> <div> <p class="text-sm font-medium">${item.name}</p> <p class="text-xs text-gray-500">$${item.price.toFixed(2)} × ${item.quantity}</p> </div> </div> <div class="flex items-center space-x-2"> <button onclick="changeQuantity(${item.productId}, -1)" class="text-gray-500 hover:text-gray-700"> <i class="fas fa-minus text-xs"></i> </button> <button onclick="changeQuantity(${item.productId}, 1)" class="text-gray-500 hover:text-gray-700"> <i class="fas fa-plus text-xs"></i> </button> <button onclick="removeFromCart(${item.productId})" class="text-red-500 hover:text-red-700 ml-2"> <i class="fas fa-trash-alt text-xs"></i> </button> </div> `; cartItems.appendChild(cartItem); total += item.price * item.quantity; }); document.getElementById('cartTotal').textContent = `$${total.toFixed(2)}`; cartSummary.classList.remove('hidden'); } function changeQuantity(productId, delta) { const cartItem = shoppingCart.find(item => item.productId === productId); if (!cartItem) return; const product = products.find(p => p.id === productId); if (!product) return; const newQuantity = cartItem.quantity + delta; if (newQuantity <= 0) { shoppingCart = shoppingCart.filter(item => item.productId !== productId); } else if (newQuantity > product.quantity) { alert('Cannot add more than available stock'); return; } else { cartItem.quantity = newQuantity; } updateCartDisplay(); } function removeFromCart(productId) { shoppingCart = shoppingCart.filter(item => item.productId !== productId); updateCartDisplay(); } // Order processing function checkout() { if (shoppingCart.length === 0) { alert('Your cart is empty'); return; } // Validate stock let outOfStockItems = []; shoppingCart.forEach(item => { const product = products.find(p => p.id === item.productId); if (product.quantity < item.quantity) { outOfStockItems.push(product.name); } }); if (outOfStockItems.length > 0) { alert(`The following items don't have enough stock: ${outOfStockItems.join(', ')}`); return; } // Create order const orderId = orders.length > 0 ? Math.max(...orders.map(o => o.id)) + 1 : 1; const orderTotal = shoppingCart.reduce((sum, item) => sum + (item.price * item.quantity), 0); const newOrder = { id: orderId, customer: currentUser, date: new Date().toISOString(), items: [...shoppingCart], total: orderTotal, status: 'pending' }; orders.push(newOrder); // Update product quantities shoppingCart.forEach(item => { const product = products.find(p => p.id === item.productId); if (product) { product.quantity -= item.quantity; } }); // Clear cart shoppingCart = []; updateCartDisplay(); renderProductsForCustomers(); alert('Order placed successfully!'); updateOrderNotification(); } function updateOrderNotification() { const pendingCount = orders.filter(o => o.status === 'pending').length; const badge = document.getElementById('orderNotificationBadge'); if (pendingCount > 0) { badge.classList.remove('hidden'); badge.textContent = pendingCount; } else { badge.classList.add('hidden'); } // Also update dashboard stats updateDashboardStats(); } // Dashboard functions function updateDashboardStats() { document.getElementById('totalProducts').textContent = products.length; document.getElementById('pendingOrders').textContent = orders.filter(o => o.status === 'pending').length; document.getElementById('totalCustomers').textContent = customers.length; if (currentAdmin) { updateOrderNotification(); } } function renderRecentOrders() { const table = document.getElementById('recentOrdersTable'); table.innerHTML = ''; const recentOrders = [...orders] .sort((a, b) => new Date(b.date) - new Date(a.date)) .slice(0, 5); if (recentOrders.length === 0) { const row = document.createElement('tr'); row.innerHTML = '<td colspan="3" class="px-6 py-4 text-center text-gray-500">No recent orders</td>'; table.appendChild(row); return; } recentOrders.forEach(order => { const row = document.createElement('tr'); row.innerHTML = ` <td class="px-6 py-4 whitespace-nowrap"> <div class="text-sm font-medium text-gray-900">Order #${order.id}</div> <div class="text-sm text-gray-500">${new Date(order.date).toLocaleString()}</div> </td> <td class="px-6 py-4 whitespace-nowrap"> <div class="text-sm font-medium text-gray-900">${order.customer}</div> </td> <td class="px-6 py-4 whitespace-nowrap"> <span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full ${order.status === 'pending' ? 'bg-yellow-100 text-yellow-800' : 'bg-green-100 text-green-800'}"> ${order.status} </span> </td> `; table.appendChild(row); }); } function renderOrdersTable() { const table = document.getElementById('ordersTable'); table.innerHTML = ''; const pendingOrders = orders.filter(o => o.status === 'pending'); if (pendingOrders.length === 0) { const row = document.createElement('tr'); row.innerHTML = '<td colspan="6" class="px-6 py-4 text-center text-gray-500">No pending orders</td>'; table.appendChild(row); return; } pendingOrders.forEach(order => { const row = document.createElement('tr'); const productsList = order.items.map(item => `${item.name} (${item.quantity} × $${item.price.toFixed(2)})` ).join(', '); row.innerHTML = ` <td class="px-6 py-4 whitespace-nowrap"> <div class="text-sm font-medium text-gray-900">#${order.id}</div> </td> <td class="px-6 py-4 whitespace-nowrap"> <div class="text-sm font-medium text-gray-900">${order.customer}</div> </td> <td class="px-6 py-4"> <div class="text-sm text-gray-900">${productsList}</div> </td> <td class="px-6 py-4 whitespace-nowrap"> <div class="text-sm font-medium text-gray-900">$${order.total.toFixed(2)}</div> </td> <td class="px-6 py-4 whitespace-nowrap"> <span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-yellow-100 text-yellow-800"> ${order.status} </span> </td> <td class="px-6 py-4 whitespace-nowrap text-right text-sm font-medium"> <button onclick="processOrder(${order.id})" class="text-green-600 hover:text-green-900"> Mark as Processed </button> </td> `; table.appendChild(row); }); } function processOrder(orderId) { const orderIndex = orders.findIndex(o => o.id === orderId); if (orderIndex !== -1) { orders[orderIndex].status = 'processed'; renderOrdersTable(); updateOrderNotification(); updateDashboardStats(); renderRecentOrders(); } } // Initialize event listeners document.addEventListener('DOMContentLoaded', function() { // Product search functionality document.getElementById('productSearch').addEventListener('input', function(e) { const searchTerm = e.target.value.toLowerCase(); const rows = document.querySelectorAll('#productsTable tr'); rows.forEach(row => { const text = row.textContent.toLowerCase(); if (text.includes(searchTerm)) { row.style.display = ''; } else { row.style.display = 'none'; } }); }); // Checkout button checkoutBtn.addEventListener('click', checkout); }); </script> <p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=F3squad18/f3squadshop" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body> </html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>F3squadshop - Admin Panel</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<style>
.hidden {
display: none;
}
.product-image {
width: 100px;
height: 100px;
object-fit: cover;
}
.order-notification {
animation: pulse 2s infinite;
}
@keyframes pulse {
0% {
box-shadow: 0 0 0 0 rgba(59, 130, 246, 0.7);
}
70% {
box-shadow: 0 0 0 10px rgba(59, 130, 246, 0);
}
100% {
box-shadow: 0 0 0 0 rgba(59, 130, 246, 0);
}
}
</style>
</head>
<body class="bg-gray-100">
<!-- Initial Login Screen -->
<div id="initialScreen" class="container mx-auto px-4 py-8">
<div class="flex flex-col md:flex-row gap-4">
<!-- Admin Login Panel (Left) -->
<div class="w-full md:w-1/3 bg-white p-6 rounded-lg shadow-md">
<h2 class="text-xl font-bold mb-4 text-blue-600">Admin Login</h2>
<div class="space-y-4">
<div>
<label class="block text-gray-700">Username</label>
<input type="text" id="adminUsername" placeholder="Enter admin username"
class="w-full px-4 py-2 border rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500">
</div>
<div>
<label class="block text-gray-700">Password</label>
<input type="password" id="adminPassword" placeholder="Enter admin password"
class="w-full px-4 py-2 border rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500">
</div>
<div>
<label class="block text-gray-700">Privilege Code</label>
<input type="password" id="adminPrivilege" placeholder="Enter privilege code"
class="w-full px-4 py-2 border rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500">
</div>
<button onclick="adminLogin()"
class="w-full bg-blue-600 hover:bg-blue-700 text-white py-2 rounded-md transition duration-300">
Login as Admin
</button>
</div>
</div>
<!-- Customer Login Panel (Center) -->
<div class="w-full md:w-1/3 bg-white p-6 rounded-lg shadow-md">
<h2 class="text-xl font-bold mb-4 text-green-600">Customer Login</h2>
<div class="space-y-4">
<div>
<label class="block text-gray-700">Username</label>
<input type="text" id="customerUsername" placeholder="Enter username"
class="w-full px-4 py-2 border rounded-md focus:outline-none focus:ring-2 focus:ring-green-500">
</div>
<div>
<label class="block text-gray-700">Password</label>
<input type="password" id="customerPassword" placeholder="Enter password"
class="w-full px-4 py-2 border rounded-md focus:outline-none focus:ring-2 focus:ring-green-500">
</div>
<button onclick="customerLogin()"
class="w-full bg-green-600 hover:bg-green-700 text-white py-2 rounded-md transition duration-300">
Login as Customer
</button>
</div>
</div>
<!-- Customer Registration Panel (Right) -->
<div class="w-full md:w-1/3 bg-white p-6 rounded-lg shadow-md">
<h2 class="text-xl font-bold mb-4 text-purple-600">Customer Registration</h2>
<div class="space-y-4">
<div>
<label class="block text-gray-700">Username</label>
<input type="text" id="regUsername" placeholder="Choose username"
class="w-full px-4 py-2 border rounded-md focus:outline-none focus:ring-2 focus:ring-purple-500">
</div>
<div>
<label class="block text-gray-700">Password</label>
<input type="password" id="regPassword" placeholder="Choose password"
class="w-full px-4 py-2 border rounded-md focus:outline-none focus:ring-2 focus:ring-purple-500">
</div>
<div>
<label class="block text-gray-700">Confirm Password</label>