based on this (<?php // public/products/manageproducts.php… · The Chat Archive
Explore / Programming o1-mini-2024-09-12 · OpenAI WildChat-4.8M (AI2)based on this (<?php // public/products/manageproducts.php // Include the header… Save Share Download ▾ Reportbased on this (<?php
// public/products/manage_products.php
// Include the header
require_once '../../includes/header.php';
// Include authentication and database connection
require_once DIR . '/../../includes/auth.php';
require_once DIR . '/../../includes/db_connect.php';
// Initialize success and error messages
s u c c e s s = ′ ′ ; success = '';
s u ccess = ′′ ; error = '';
// Function to sanitize input data
function sanitize_input(data) {
return htmlspecialchars(trim( data));
}
// Handle Add/Edit/Delete actions
if (_SERVER['REQUEST_METHOD'] === 'POST') {
// CSRF Token Check
if (isset( _POST['csrf_token']) && P O S T [ ′ c s r f t o _SESSION['csrf_token']) {
// Add Product
if (isset( name = sanitize_input( size = sanitize_input( price = floatval( category = sanitize_input($_POST['category']);
Assistant2024-11-12 11:24 UTC Copy response
Copy first prompt
Details
Model o1-mini-2024-09-12
Provider OpenAI
Model provenance As recorded by source dataset
Turns 1 (2 messages)
Language en
Conversation date Nov 12, 2024
Added to archive Nov 16, 2026
ID 01m7h427xwn21pn70b24ee9m8aSource & license Imported from WildChat-4.8M (AI2) (source ). Imported records earn no Research Points.
Upstream record: 74adf017e973b433a0604a7e9b83bc0a
Zhao et al., WildChat: 1M ChatGPT Interaction Logs in the Wild (ICLR 2024). Contains information from WildChat-4.8M, made available under the ODC Attribution License.
License: ODC-BY-1.0
Dataset releases Not yet included in a published release.
k e n ′ ] = = = _POST['csrf_token'] === P O S T [ ′ csr f t o k e n ′ ] ===
_POST['add_product'])) {
P O S T [ ′ n a m e ′ ] ) ; _POST['name']);
P O S T [ ′ nam e ′ ]) ; P O S T [ ′ s i z e ′ ] ) ; _POST['size']);
P O S T [ ′ s i z e ′ ]) ; P O S T [ ′ p r i c e ′ ] ) ; _POST['price']);
P O S T [ ′ p r i c e ′ ]) ; // Basic validation
if (empty($name) || empty($size) || empty($price) || empty($category)) {
$error = "All fields are required.";
} else {
// Prepare and execute the insert statement
$add_sql = "INSERT INTO products (name, size, price, category) VALUES (?, ?, ?, ?)";
$stmt = $conn->prepare($add_sql);
if ($stmt) {
$stmt->bind_param("ssds", $name, $size, $price, $category);
if ($stmt->execute()) {
$success = "Product added successfully!";
// Clear POST data to prevent resubmission
$_POST = [];
} else {
$error = "Error adding product: " . $stmt->error;
}
$stmt->close();
} else {
$error = "Prepare statement failed: " . $conn->error;
}
}
}
// Edit Product
elseif (isset($_POST['edit_product'])) {
$id = intval($_POST['id']);
$name = sanitize_input($_POST['name']);
$size = sanitize_input($_POST['size']);
$price = floatval($_POST['price']);
$category = sanitize_input($_POST['category']);
// Basic validation
if (empty($name) || empty($size) || empty($price) || empty($category)) {
$error = "All fields are required.";
} else {
// Prepare and execute the update statement
$edit_sql = "UPDATE products SET name=?, size=?, price=?, category=? WHERE id=?";
$stmt = $conn->prepare($edit_sql);
if ($stmt) {
$stmt->bind_param("ssdsi", $name, $size, $price, $category, $id);
if ($stmt->execute()) {
if ($stmt->affected_rows > 0) {
$success = "Product updated successfully!";
} else {
$error = "No changes made or product not found.";
}
} else {
$error = "Error updating product: " . $stmt->error;
}
$stmt->close();
} else {
$error = "Prepare statement failed: " . $conn->error;
}
}
}
// Delete Product
elseif (isset($_POST['delete_product'])) {
$id = intval($_POST['id']);
// Check if the product is referenced in any order items
$check_sql = "SELECT COUNT(*) AS count FROM order_items WHERE product_id = ?";
$stmt = $conn->prepare($check_sql);
if ($stmt) {
$stmt->bind_param("i", $id);
if ($stmt->execute()) {
$stmt->bind_result($count);
$stmt->fetch();
$stmt->close();
if ($count > 0) {
$error = "Cannot delete product because it is associated with existing order items.";
} else {
// Proceed to delete the product
$delete_sql = "DELETE FROM products WHERE id = ?";
$stmt_del = $conn->prepare($delete_sql);
if ($stmt_del) {
$stmt_del->bind_param("i", $id);
if ($stmt_del->execute()) {
if ($stmt_del->affected_rows > 0) {
$success = "Product deleted successfully!";
} else {
$error = "No product found with the specified ID.";
}
} else {
$error = "Error deleting product: " . $stmt_del->error;
}
$stmt_del->close();
} else {
$error = "Prepare statement failed: " . $conn->error;
}
}
} else {
$error = "Execution failed: " . $stmt->error;
$stmt->close();
}
} else {
$error = "Prepare statement failed: " . $conn->error;
}
}
} else {
$error = "Invalid CSRF token.";
}
// Generate a new CSRF token for the next form
$_SESSION['csrf_token'] = bin2hex(random_bytes(32));
// Handle Search Functionality
s e a r c h q u e r y = ′ ′ ; i f ( i s s e t ( search_query = '';
if (isset( se a r c h q u er y = ′′ ; i f ( i sse t ( _GET['search'])) {
s e a r c h q u e r y = s a n i t i z e i n p u t ( search_query = sanitize_input( se a r c h q u er y = s ani t i z e i _GET['search']);
}
// Function to build query strings
function build_query(params) {
query = http_build_query(array_filter(p a r a m s , f u n c t i o n ( params, function( p a r am s , f u n c t i o n ( value) {
return value !== null;
}));
return query ? '?' . $query : '';
}
// Fetch all products with search filter
if (!empty(search_query)) {
products_sql = "SELECT * FROM products WHERE name LIKE ? OR size LIKE ? OR category LIKE ? ORDER BY name ASC";
s t m t = stmt = s t m t = conn->prepare(p r o d u c t s s q l ) ; i f ( products_sql);
if ( p r o d u c t s s q l ) ; i f ( stmt) {
l i k e s e a r c h = " like_search = "%" . l ik e s e a r c h = " search_query . "%";
s t m t − > b i n d p a r a m ( " s s s " , stmt->bind_param("sss", s t m t − > bin d p a r am ( " sss " , like_search, l i k e s e a r c h , like_search, l ik e s e a r c h , like_search);
s t m t − > e x e c u t e ( ) ; stmt->execute();
s t m t − > e x ec u t e ( ) ; products_result = stmt->get_result();
} else {
die("Prepare statement failed: " . conn->error);
}
} else {
p r o d u c t s s q l = " S E L E C T ∗ F R O M p r o d u c t s O R D E R B Y n a m e A S C " ; products_sql = "SELECT * FROM products ORDER BY name ASC";
p r o d u c t s s q l = " S E L E products_result = c o n n − > q u e r y ( conn->query( co nn − > q u er y ( products_sql);
}
?>
<!-- Google Fonts -->
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;600;700&family=Roboto:wght@400;500;700&display=swap" rel="stylesheet">
<!-- Tailwind CSS -->
<script src="https://cdn.tailwindcss.com"></script>
<!-- Heroicons for Icons -->
<script src="https://unpkg.com/heroicons@2.0.13/dist/heroicons.min.js"></script>
<!-- Font Awesome for Copy Icons -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" integrity="sha512-yH8v808og6V8bHjjLQV4UMiwK1+Tw1q6FcZW6rh9YK/F3XvNhr+lG0qMqQeE8uK8pcY7glYztk4Hyc1oCkAE1w==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<!-- Embedded Custom Styles -->
<style>
/* Custom scrollbar for better UX */
::-webkit-scrollbar {
width: 8px;
}
::-webkit-scrollbar-track {
background: #f1f5f9; /* Tailwind's gray-100 */
}
::-webkit-scrollbar-thumb {
background: #4b6584; /* Teal-500 */
border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
background: #0d9488; /* Teal-600 */
}
/* Modal transition */
.modal-enter {
transition: opacity 0.25s ease;
opacity: 0;
}
.modal-enter-active {
opacity: 1;
}
.modal-leave {
transition: opacity 0.25s ease;
opacity: 1;
}
.modal-leave-active {
opacity: 0;
}
</style>
<!-- JavaScript for Modal Handling and Copy Functionality -->
<script>
// Base URL for constructing absolute product page URLs
const baseProductURL = 'https://kaakalia.longevacare.com/public/products/product.php';
function openModal(modalId) {
document.getElementById(modalId).classList.remove('hidden');
document.getElementById(modalId).classList.add('flex');
}
function closeModal(modalId) {
document.getElementById(modalId).classList.remove('flex');
document.getElementById(modalId).classList.add('hidden');
}
// Close modal when clicking outside the modal content
window.onclick = function(event) {
var modals = document.getElementsByClassName('modal');
for(var i = 0; i < modals.length; i++) {
var modal = modals[i];
if (event.target == modal) {
modal.classList.remove('flex');
modal.classList.add('hidden');
}
}
}
// Function to copy product page URL with language parameter
function copyProductLink(id, lang) {
const productURL = `${baseProductURL}?id=${id}&lang=${lang}`;
navigator.clipboard.writeText(productURL).then(() => {
alert(lang === 'ar' ? 'تم نسخ الرابط بنجاح!' : 'Link copied successfully!');
}).catch(err => {
alert(lang === 'ar' ? 'فشل في نسخ الرابط: ' + err : 'Failed to copy the link: ' + err);
});
}
</script>
<!-- Main Container -->
<main class="container mx-auto my-8 px-4">
<!-- Display Success or Error Messages -->
<?php if (!empty($success)): ?>
<div class="bg-teal-500 text-white px-6 py-4 rounded-md mb-4">
<?= htmlspecialchars($success) ?>
</div>
<?php endif; ?>
<?php if (!empty($error)): ?>
<div class="bg-red-500 text-white px-6 py-4 rounded-md mb-4">
<?= htmlspecialchars($error) ?>
</div>
<?php endif; ?>
<!-- Add Product Form -->
<section class="bg-white shadow-md rounded-lg p-6 mb-8">
<h2 class="text-2xl font-poppins font-semibold mb-4 text-gray-800">Add New Product</h2>
<form method="POST" action="">
<!-- CSRF Token -->
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
<div class="grid grid-cols-1 md:grid-cols-4 gap-6">
<!-- Product Name -->
<div>
<label for="name" class="block text-gray-700 font-medium">Name <span class="text-red-500">*</span></label>
<input type="text" id="name" name="name" class="mt-1 p-2 w-full border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-teal-500"
value="<?= isset($_POST['name']) ? htmlspecialchars($_POST['name']) : '' ?>"
required>
</div>
<!-- Product Size -->
<div>
<label for="size" class="block text-gray-700 font-medium">Size <span class="text-red-500">*</span></label>
<input type="text" id="size" name="size" class="mt-1 p-2 w-full border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-teal-500"
value="<?= isset($_POST['size']) ? htmlspecialchars($_POST['size']) : '' ?>"
required>
</div>
<!-- Product Price -->
<div>
<label for="price" class="block text-gray-700 font-medium">Price (KD) <span class="text-red-500">*</span></label>
<input type="number" id="price" name="price" class="mt-1 p-2 w-full border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-teal-500"
step="0.01"
value="<?= isset($_POST['price']) ? htmlspecialchars($_POST['price']) : '' ?>"
required>
</div>
<!-- Product Category -->
<div>
<label for="category" class="block text-gray-700 font-medium">Category <span class="text-red-500">*</span></label>
<input type="text" id="category" name="category" class="mt-1 p-2 w-full border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-teal-500"
value="<?= isset($_POST['category']) ? htmlspecialchars($_POST['category']) : '' ?>"
required>
</div>
</div>
<!-- Submit Button -->
<div class="mt-6">
<button type="submit" name="add_product" class="bg-teal-600 text-white px-6 py-2 rounded-full hover:bg-teal-700 transition flex items-center gap-2">
<!-- Heroicons Plus Icon -->
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4v16m8-8H4" />
</svg>
Add Product
</button>
</div>
</form>
</section>
<!-- All Products List as Cards -->
<section class="bg-white shadow-md rounded-lg p-6 mb-8">
<div class="flex flex-col md:flex-row items-center justify-between mb-4">
<h2 class="text-xl font-poppins font-semibold text-gray-800">All Products</h2>
<!-- Search Form -->
<form method="GET" action="manage_products.php" class="mt-4 md:mt-0 w-full md:w-1/3 flex items-center">
<input type="text" name="search" class="flex-grow p-2 border border-gray-300 rounded-l-md focus:outline-none focus:ring-2 focus:ring-teal-500" placeholder="Search by Name, Size, or Category" value="<?= htmlspecialchars($search_query) ?>">
<button type="submit" class="bg-teal-600 text-white px-4 py-2 rounded-r-md hover:bg-teal-700 transition flex items-center">
<!-- Heroicons Search Icon -->
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z" />
</svg>
</button>
<?php if (!empty($search_query)): ?>
<a href="manage_products.php" class="ml-2 bg-red-500 text-white px-4 py-2 rounded-md hover:bg-red-600 transition flex items-center">
<!-- Heroicons Reset Icon -->
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 mr-1" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 4v5h.582a4 4 0 011.166 7.555L6 21l5.464-2.436a4 4 0 017.555 1.166V20H20V4H4z" />
</svg>
Reset
</a>
<?php endif; ?>
</form>
</div>
<!-- Products Grid -->
<div class="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-6">
<?php if ($products_result && $products_result->num_rows > 0): ?>
<?php while($product = $products_result->fetch_assoc()): ?>
<div class="bg-gray-50 rounded-lg shadow-md p-4 flex flex-col justify-between hover:bg-teal-50 transition transform hover:scale-105 relative">
<div>
<h3 class="text-lg font-poppins font-semibold text-gray-800 mb-2"><?= htmlspecialchars($product['name']) ?></h3>
<p class="text-sm text-gray-600"><strong>Size:</strong> <?= htmlspecialchars($product['size']) ?></p>
<p class="text-sm text-gray-600"><strong>Price:</strong> <?= number_format($product['price'], 2) ?> KD</p>
<p class="text-sm text-gray-600"><strong>Category:</strong> <?= htmlspecialchars($product['category']) ?></p>
</div>
<div class="mt-4 flex justify-end gap-2">
<!-- Edit Button -->
<button type="button" onclick="openModal('editModal<?= $product['id'] ?>')" class="bg-teal-600 text-white px-3 py-1 rounded-full hover:bg-teal-700 transition flex items-center" title="Edit Product">
<!-- Heroicons Edit Icon -->
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15.232 5.232l3.536 3.536M9 19l6-6M18 2H6a2 2 0 00-2 2v16a2 2 0 002 2h12a2 2 0 002-2V4a2 2 0 00-2-2z" />
</svg>
</button>
<!-- Delete Form -->
<form method="POST" action="" class="inline" onsubmit="return confirm('Are you sure you want to delete this product?');">
<!-- CSRF Token -->
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
<input type="hidden" name="id" value="<?= $product['id'] ?>">
<button type="submit" name="delete_product" class="bg-red-500 text-white px-3 py-1 rounded-full hover:bg-red-600 transition flex items-center" title="Delete Product">
<!-- Heroicons Delete Icon -->
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12" />
</svg>
</button>
</form>
</div>
</div>
<!-- Edit Modal -->
<div id="editModal<?= $product['id'] ?>" class="modal fixed inset-0 flex items-center justify-center bg-black bg-opacity-50 hidden z-50">
<div class="bg-white rounded-lg shadow-lg w-11/12 md:w-1/2 lg:w-1/3 relative">
<div class="flex justify-between items-center p-4 border-b">
<h3 class="text-xl font-poppins font-semibold text-gray-800">Edit Product</h3>
<button onclick="closeModal('editModal<?= $product['id'] ?>')" class="text-gray-500 hover:text-gray-700">
<!-- Heroicons Close Icon -->
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12" />
</svg>
</button>
</div>
<form method="POST" action="">
<!-- CSRF Token -->
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
<input type="hidden" name="id" value="<?= $product['id'] ?>">
<div class="p-4 grid grid-cols-1 gap-4">
<!-- Product Name -->
<div>
<label for="edit_name_<?= $product['id'] ?>" class="block text-gray-700 font-medium">Name <span class="text-red-500">*</span></label>
<input type="text" id="edit_name_<?= $product['id'] ?>" name="name" class="mt-1 p-2 w-full border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-teal-500"
value="<?= htmlspecialchars($product['name']) ?>"
required>
</div>
<!-- Product Size -->
<div>
<label for="edit_size_<?= $product['id'] ?>" class="block text-gray-700 font-medium">Size <span class="text-red-500">*</span></label>
<input type="text" id="edit_size_<?= $product['id'] ?>" name="size" class="mt-1 p-2 w-full border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-teal-500"
value="<?= htmlspecialchars($product['size']) ?>"
required>
</div>
<!-- Product Price -->
<div>
<label for="edit_price_<?= $product['id'] ?>" class="block text-gray-700 font-medium">Price (KD) <span class="text-red-500">*</span></label>
<input type="number" id="edit_price_<?= $product['id'] ?>" name="price" class="mt-1 p-2 w-full border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-teal-500"
step="0.01"
value="<?= htmlspecialchars($product['price']) ?>"
required>
</div>
<!-- Product Category -->
<div>
<label for="edit_category_<?= $product['id'] ?>" class="block text-gray-700 font-medium">Category <span class="text-red-500">*</span></label>
<input type="text" id="edit_category_<?= $product['id'] ?>" name="category" class="mt-1 p-2 w-full border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-teal-500"
value="<?= htmlspecialchars($product['category']) ?>"
required>
</div>
</div>
<!-- Modal Footer -->
<div class="flex justify-end p-4 border-t">
<button type="button" onclick="closeModal('editModal<?= $product['id'] ?>')" class="bg-gray-500 text-white px-4 py-2 rounded-full hover:bg-gray-600 transition mr-2">
Cancel
</button>
<button type="submit" name="edit_product" class="bg-teal-600 text-white px-4 py-2 rounded-full hover:bg-teal-700 transition flex items-center gap-2">
<!-- Heroicons Save Icon -->
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7" />
</svg>
Save Changes
</button>
</div>
</form>
</div>
</div>
<?php endwhile; ?>
<?php else: ?>
<p class="text-center text-gray-500">No products found.</p>
<?php endif; ?>
</div>
</section>
<!-- Arabic Products Section -->
<section class="bg-white p-6 rounded-lg shadow-md mb-12">
<h2 class="text-2xl font-semibold text-gray-800 mb-8">منتجاتنا</h2>
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-8">
<!-- Product 1 -->
<div class="bg-gray-50 rounded-lg shadow-lg overflow-hidden">
<img src="images/gallery1.jpg" alt="شابورة (لسان الثور)" class="w-full h-48 object-cover">
<div class="p-6">
<h3 class="text-xl font-bold text-indigo-600 mb-2">شابورة (لسان الثور)</h3>
<p class="text-gray-700 mb-4">
متوفرة بأوزان 0.5 كجم، 1 كجم، وصندوق.<br>
مقدمة في صندوق عادي أو سلة.
</p>
<div class="flex space-x-2">
<button onclick="copyProductLink(1, 'ar')" class="bg-indigo-600 text-white px-4 py-2 rounded hover:bg-indigo-700 transition flex items-center">
<i class="fas fa-copy mr-2"></i> نسخ التفاصيل
</button>
<button onclick="copyProductLink(1, 'en')" class="bg-blue-600 text-white px-4 py-2 rounded hover:bg-blue-700 transition flex items-center">
<i class="fas fa-copy mr-2"></i> Copy Details
</button>
</div>
</div>
</div>
<!-- Product 2 -->
<div class="bg-gray-50 rounded-lg shadow-lg overflow-hidden">
<img src="images/gallery2.jpg" alt="كيكة مالحة" class="w-full h-48 object-cover">
<div class="p-6">
<h3 class="text-xl font-bold text-indigo-600 mb-2">كيكة مالحة</h3>
<p class="text-gray-700 mb-4">
تحتوي على الجبن، الزعتر، الزيتون، الطماطم المجففة، والصلصة.<br>
متوفرة بأحجام كبيرة وكميات من 12، 24، و36 قطعة.<br>
<strong>التغليف:</strong> صندوق عادي أو صينية.
</p>
<div class="flex space-x-2">
<button onclick="copyProductLink(2, 'ar')" class="bg-green-600 text-white px-4 py-2 rounded hover:bg-green-700 transition flex items-center">
<i class="fas fa-copy mr-2"></i> نسخ التفاصيل
</button>
<button onclick="copyProductLink(2, 'en')" class="bg-blue-600 text-white px-4 py-2 rounded hover:bg-blue-700 transition flex items-center">
<i class="fas fa-copy mr-2"></i> Copy Details
</button>
</div>
</div>
</div>
<!-- Product 3 -->
<div class="bg-gray-50 rounded-lg shadow-lg overflow-hidden">
<img src="images/gallery3.jpg" alt="مهلبية كرنشي 🍨" class="w-full h-48 object-cover">
<div class="p-6">
<h3 class="text-xl font-bold text-indigo-600 mb-2">مهلبية كرنشي 🍨</h3>
<p class="text-gray-700 mb-4">
مهلبية باردة مع مكسرات متنوعة.<br>
متوفرة بكميات من 12 قطعة.
</p>
<div class="flex space-x-2">
<button onclick="copyProductLink(3, 'ar')" class="bg-pink-600 text-white px-4 py-2 rounded hover:bg-pink-700 transition flex items-center">
<i class="fas fa-copy mr-2"></i> نسخ التفاصيل
</button>
<button onclick="copyProductLink(3, 'en')" class="bg-blue-600 text-white px-4 py-2 rounded hover:bg-blue-700 transition flex items-center">
<i class="fas fa-copy mr-2"></i> Copy Details
</button>
</div>
</div>
</div>
<!-- Product 4 -->
<div class="bg-gray-50 rounded-lg shadow-lg overflow-hidden">
<img src="images/gallery4.jpg" alt="بوكسات المناسبات" class="w-full h-48 object-cover">
<div class="p-6">
<h3 class="text-xl font-bold text-indigo-600 mb-2">بوكسات المناسبات</h3>
<p class="text-gray-700 mb-4">
<strong>الخيارات:</strong> 35 قطعة من الكيكة المالحة (14.5 دينار كويتي) أو 33 قطعة (11 دينار كويتي).<br>
<strong>الأنماط:</strong> الحمدالله على السلامة، مبروك، زارتنا البركة.
</p>
<div class="flex space-x-2">
<button onclick="copyProductLink(4, 'ar')" class="bg-yellow-600 text-white px-4 py-2 rounded hover:bg-yellow-700 transition flex items-center">
<i class="fas fa-copy mr-2"></i> نسخ التفاصيل
</button>
<button onclick="copyProductLink(4, 'en')" class="bg-blue-600 text-white px-4 py-2 rounded hover:bg-blue-700 transition flex items-center">
<i class="fas fa-copy mr-2"></i> Copy Details
</button>
</div>
</div>
</div>
<!-- Product 5 -->
<div class="bg-gray-50 rounded-lg shadow-lg overflow-hidden">
<img src="images/gallery5.jpg" alt="تقديم في الصواني" class="w-full h-48 object-cover">
<div class="p-6">
<h3 class="text-xl font-bold text-indigo-600 mb-2">تقديم في الصواني</h3>
<p class="text-gray-700 mb-4">
خمسة منتجات نقدمها بشكل أنيق في صواني، مثالية لأي مناسبة.
</p>
<div class="flex space-x-2">
<button onclick="copyProductLink(5, 'ar')" class="bg-purple-600 text-white px-4 py-2 rounded hover:bg-purple-700 transition flex items-center">
<i class="fas fa-copy mr-2"></i> نسخ التفاصيل
</button>
<button onclick="copyProductLink(5, 'en')" class="bg-blue-600 text-white px-4 py-2 rounded hover:bg-blue-700 transition flex items-center">
<i class="fas fa-copy mr-2"></i> Copy Details
</button>
</div>
</div>
</div>
</div>
</section>
</main>
<!-- Footer -->
<footer class="bg-teal-600 text-white py-6 shadow-md">
<div class="container mx-auto text-center text-sm">
© 2024 Kaak Alia Bakery. All rights reserved.
</div>
</footer>
// Include database connection
require_once DIR . '/../../includes/db_connect.php';
// Function to sanitize input data
function sanitize_input(data) {
return htmlspecialchars(trim( data));
}
// Get 'id' and 'lang' from GET parameters
p r o d u c t i d = i s s e t ( product_id = isset( p r o d u c t i d = i sse t ( _GET['id']) ? intval(G E T [ ′ i d ′ ] ) : 0 ; _GET['id']) : 0;
G E T [ ′ i d ′ ]) : 0 ; lang = isset(G E T [ ′ l a n g ′ ] ) ? s a n i t i z e i n p u t ( _GET['lang']) ? sanitize_input( G E T [ ′ l an g ′ ])? s _GET['lang']) : 'en';
// Default to English if 'lang' is not 'ar'
if (lang !== 'ar') {
lang = 'en';
}
// Fetch product details from the database
p r o d u c t s q l = " S E L E C T ∗ F R O M p r o d u c t s W H E R E i d = ? " ; product_sql = "SELECT * FROM products WHERE id = ?";
p r o d u c t s q l = " S E L E C T ∗ F R O M p r o d u c t s W H E R E i d = ? " ; stmt = c o n n − > p r e p a r e ( conn->prepare( co nn − > p r e p a r e ( product_sql);
if (stmt) {
stmt->bind_param("i", p r o d u c t i d ) ; product_id);
p r o d u c t i d ) ; stmt->execute();
p r o d u c t r e s u l t = product_result = p r o d u c t r es u l t = stmt->get_result();
if (p r o d u c t r e s u l t − > n u m r o w s = = = 0 ) / / P r o d u c t n o t f o u n d h t t p r e s p o n s e c o d e ( 404 ) ; e c h o " P r o d u c t n o t f o u n d . " ; e x i t ( ) ; product_result->num_rows === 0) {
// Product not found
http_response_code(404);
echo "Product not found.";
exit();
}
p r o d u c product = p r o d u c t r e s u l t − > f e t c h a s s o c ( ) ; product_result->fetch_assoc();
p r o d u c t r es u l t − > f e t c h stmt->close();
} else {
// SQL error
http_response_code(500);
echo "Database error.";
exit();
}
// Define Arabic and English descriptions
$descriptions_ar = [
1 => "شابورة (لسان الثور)\nمتوفرة بأوزان 0.5 كجم، 1 كجم، وصندوق.\nمقدمة في صندوق عادي أو سلة.",
2 => "كيكة مالحة (مونكي بريد)🥮\nتحتوي على الجبن، الزعتر، الزيتون، الطماطم المجففة، والصلصة.\nمتوفرة بأحجام كبيرة وكميات من 12، 24، و36 قطعة.\nالتغليف: صندوق عادي أو صينية.",
3 => "مهلبية كرنشي 🍨\nمهلبية باردة مع مكسرات متنوعة.\nمتوفرة بكميات من 12 قطعة.",
4 => "بوكسات المناسبات\n35 قطعة من الكيكة المالحة (14.5 دينار كويتي) أو 33 قطعة (11 دينار كويتي).\nالأنماط: الحمدالله على السلامة، مبروك، زارتنا البركة.",
5 => "تقديم في الصواني\nخمسة منتجات نقدمها بشكل أنيق في صواني، مثالية لأي مناسبة."
];
$descriptions_en = [
1 => "Shaboura (Bull's Tongue)\nAvailable in weights of 0.5 kg, 1 kg, and a box.\nPresented in a regular box or basket.",
2 => "Savory Cake (Monkey Bread)🥮\nContains cheese, thyme, olives, sun-dried tomatoes, and sauce.\nAvailable in large sizes and quantities of 12, 24, and 36 pieces.\nPacking: Regular box or tray.",
3 => "Crunchy Mhallabiya 🍨\nCold Mhallabiya with assorted nuts.\nAvailable in quantities of 12 pieces.",
4 => "Event Boxes\n35 pieces of Savory Cake (14.5 Kuwaiti Dinars) or 33 pieces (11 Kuwaiti Dinars).\nStyles: Alhamdulillah on Safety, Congratulations, Visited us Brings Blessing.",
5 => "Presenting in Trays\nFive products elegantly presented in trays, perfect for any occasion."
];
// Get the description based on product ID and language
if (lang === 'ar') {
description = isset(d e s c r i p t i o n s a r [ descriptions_ar[ d escr i pt i o n s a r [ product_id]) ? d e s c r i p t i o n s a r [ descriptions_ar[ d escr i pt i o n s a r [ product_id] : "تفاصيل المنتج غير متوفرة.";
t i t l e = h t m l s p e c i a l c h a r s ( title = htmlspecialchars( t i tl e = h t m l s p ec ia l c ha r s ( product['name']) . " - كعك علياء";
} else {
d e s c r i p t i o n = i s s e t ( description = isset( d escr i pt i o n = i sse t ( descriptions_en[p r o d u c t i d ] ) ? product_id]) ? p r o d u c t i d ])? descriptions_en[p r o d u c t i d ] : " P r o d u c t d e t a i l s a r e n o t a v a i l a b l e . " ; product_id] : "Product details are not available.";
p r o d u c t i d ] : " P r o d u c t title = htmlspecialchars($product['name']) . " - Kaak Alia";
}
// Absolute URLs for images
a b s o l u t e i m a g e u r l = ′ h t t p s : / / k a a k a l i a . l o n g e v a c a r e . c o m / p u b l i c / p r o d u c t s / ′ . absolute_image_url = 'https://kaakalia.longevacare.com/public/products/' . ab so l u t e i ma g e u r l = ′ h ttp s : // k aak a l ia . l o n g e v a c a r e . co m / p u b l i c / p r o d u c t s / ′ . product['thumbnail'];
a b s o l u t e p a g e u r l = ′ h t t p s : / / k a a k a l i a . l o n g e v a c a r e . c o m / p u b l i c / p r o d u c t s / p r o d u c t . p h p ? i d = ′ . absolute_page_url = 'https://kaakalia.longevacare.com/public/products/product.php?id=' . ab so l u t e product_id . '&lang=' . $lang;
?>
<!-- Open Graph Meta Tags -->
<meta property="og:title" content="<?= $title ?>" />
<meta property="og:description" content="<?= $description ?>" />
<meta property="og:image" content="<?= $absolute_image_url ?>" />
<meta property="og:url" content="<?= $absolute_page_url ?>" />
<meta property="og:type" content="website" />
<meta property="og:locale" content="<?= $lang === 'ar' ? 'ar_AR' : 'en_US' ?>" />
<!-- Twitter Card Meta Tags (Optional) -->
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:title" content="<?= $title ?>" />
<meta name="twitter:description" content="<?= $description ?>" />
<meta name="twitter:image" content="<?= $absolute_image_url ?>" />
<!-- Google Fonts -->
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;600;700&family=Roboto:wght@400;500;700&display=swap" rel="stylesheet">
<!-- Tailwind CSS -->
<script src="https://cdn.tailwindcss.com"></script>
<!-- Heroicons for Icons -->
<script src="https://unpkg.com/heroicons@2.0.13/dist/heroicons.min.js"></script>
<!-- Font Awesome for Icons -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" integrity="sha512-yH8v808og6V8bHjjLQV4UMiwK1+Tw1q6FcZW6rh9YK/F3XvNhr+lG0qMqQeE8uK8pcY7glYztk4Hyc1oCkAE1w==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<!-- Embedded Custom Styles -->
<style>
body {
font-family: 'Roboto', sans-serif;
}
h1, h2, h3, h4, h5, h6 {
font-family: 'Poppins', sans-serif;
}
</style>
كيكة مالحة (مونكي بريد)🥮
الحجم الكبير ١٢ دك
الميني كيك ١٢ حبه اب ٦ دك
الميني كيك ٢٤ حبه اب ٩ دك
الميني كيك ٣٦ حبه اب ١٢ دك
بوكس المناسبات ٣٥ حبه اب ١٤.٥ دك
مهلبية كرنشي 🍨
١٢ حبه اب ١٢ دك
) and type full codes and make it pruduts.php is amaizng for it and show langauge English, first show araibck then enlish and type full codes and makei t amazing
Certainly! Below is a comprehensive products.php file that showcases your products in both Arabic and English. This implementation ensures a seamless user experience with responsive design using Tailwind CSS, secure PHP practices, and interactive features like copying product links in both languages.
Key Features:
Dual Language Display : Each product is presented first in Arabic, followed by its English counterpart.
Responsive Design : Utilizes Tailwind CSS to ensure the page looks great on all devices.
Interactive Copy Buttons : Users can copy product details in either language with a single click.
Clean and Organized Layout : Products are displayed in a grid format for easy navigation.
Prerequisites:
Ensure you have a database with a products table containing relevant product details.
Update the database connection settings in includes/db_connect.php.
Place product images in the public/products/ directory.
Include authentication if required (not shown in this example).
Complete products.php Code:
<?php
// public/products/products.php
// Include the header (if you have a separate header file)
require_once __DIR__ . '/../../includes/header.php';
// Include database connection
require_once __DIR__ . '/../../includes/db_connect.php';
// Function to sanitize input data
function sanitize_input($data) {
return htmlspecialchars(trim($data));
}
// Fetch all products from the database
$products_sql = "SELECT * FROM products ORDER BY name ASC";
$products_result = $conn->query($products_sql);
// Define Arabic and English descriptions if not stored in the database
$descriptions_ar = [
1 => "شابورة (لسان الثور)\nفي علبه نص كيلو 🗃 ٦ دك \nعلبة كيلو 🗃 ٨ دك \nسلة صغيرة 🧺 ٨ دك \nسلة كبيرة 🧺 ١٠ دك\nبوكس المناسبات ٣٣ حبه اب ١١ دك",
2 => "كيكة مالحة (مونكي بريد)🥮\nالحجم الكبير ١٢ دك\nالميني كيك ١٢ حبه اب ٦ دك \nالميني كيك ٢٤ حبه اب ٩ دك \nالميني كيك ٣٦ حبه اب ١٢ دك\nبوكس المناسبات ٣٥ حبه اب ١٤.٥ دك",
3 => "مهلبية كرنشي 🍨\n١٢ حبه اب ١٢ دك"
// Add more descriptions as needed
];
$descriptions_en = [
1 => "Shaboura (Bull's Tongue)\nHalf Kg Box 🗃 6 KD \nOne Kg Box 🗃 8 KD \nSmall Basket 🧺 8 KD \nLarge Basket 🧺 10 KD\nEvent Box 33 pieces, 11 KD",
2 => "Savory Cake (Monkey Bread)🥮\nLarge Size 12 KD\nMini Cake 12 pieces, 6 KD \nMini Cake 24 pieces, 9 KD \nMini Cake 36 pieces, 12 KD\nEvent Box 35 pieces, 14.5 KD",
3 => "Crunchy Mhallabiya 🍨\n12 pieces, 12 KD"
// Add more descriptions as needed
];
// Generate a new CSRF token for the forms (if needed)
if (session_status() == PHP_SESSION_NONE) {
session_start();
}
$_SESSION['csrf_token'] = bin2hex(random_bytes(32));
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Our Products - Kaak Alia Bakery</title>
<!-- Open Graph Meta Tags for SEO -->
<meta property="og:title" content="Our Products - Kaak Alia Bakery" />
<meta property="og:description" content="Explore our wide range of delicious bakery products available in multiple sizes and packaging options." />
<meta property="og:image" content="https://kaakalia.longevacare.com/public/images/og-products.jpg" />
<meta property="og:url" content="https://kaakalia.longevacare.com/public/products/products.php" />
<meta property="og:type" content="website" />
<meta property="og:locale" content="en_US" />
<!-- Twitter Card Meta Tags -->
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:title" content="Our Products - Kaak Alia Bakery" />
<meta name="twitter:description" content="Explore our wide range of delicious bakery products available in multiple sizes and packaging options." />
<meta name="twitter:image" content="https://kaakalia.longevacare.com/public/images/twitter-products.jpg" />
<!-- Google Fonts -->
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;600;700&family=Roboto:wght@400;500;700&display=swap" rel="stylesheet">
<!-- Tailwind CSS -->
<script src="https://cdn.tailwindcss.com"></script>
<!-- Font Awesome for Icons -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" integrity="sha512-yH8v808og6V8bHjjLQV4UMiwK1+Tw1q6FcZW6rh9YK/F3XvNhr+lG0qMqQeE8uK8pcY7glYztk4Hyc1oCkAE1w==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<!-- Custom Styles -->
<style>
body {
font-family: 'Roboto', sans-serif;
}
h1, h2, h3, h4, h5, h6 {
font-family: 'Poppins', sans-serif;
}
/* Custom scrollbar for better UX */
::-webkit-scrollbar {
width: 8px;
}
::-webkit-scrollbar-track {
background: #f1f5f9; /* Tailwind's gray-100 */
}
::-webkit-scrollbar-thumb {
background: #4b6584; /* Teal-500 */
border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
background: #0d9488; /* Teal-600 */
}
/* Modal transition */
.modal-enter {
transition: opacity 0.25s ease;
opacity: 0;
}
.modal-enter-active {
opacity: 1;
}
.modal-leave {
transition: opacity 0.25s ease;
opacity: 1;
}
.modal-leave-active {
opacity: 0;
}
</style>
<!-- JavaScript for Modal Handling and Copy Functionality -->
<script>
// Base URL for constructing absolute product page URLs
const baseProductURL = 'https://kaakalia.longevacare.com/public/products/product.php';
function openModal(modalId) {
document.getElementById(modalId).classList.remove('hidden');
document.getElementById(modalId).classList.add('flex');
}
function closeModal(modalId) {
document.getElementById(modalId).classList.remove('flex');
document.getElementById(modalId).classList.add('hidden');
}
// Close modal when clicking outside the modal content
window.onclick = function(event) {
var modals = document.getElementsByClassName('modal');
for(var i = 0; i < modals.length; i++) {
var modal = modals[i];
if (event.target == modal) {
modal.classList.remove('flex');
modal.classList.add('hidden');
}
}
}
// Function to copy product page URL with language parameter
function copyProductLink(id, lang) {
const productURL = `${baseProductURL}?id=${id}&lang=${lang}`;
navigator.clipboard.writeText(productURL).then(() => {
if(lang === 'ar') {
alert('تم نسخ الرابط بنجاح!');
} else {
alert('Link copied successfully!');
}
}).catch(err => {
if(lang === 'ar') {
alert('فشل في نسخ الرابط: ' + err);
} else {
alert('Failed to copy the link: ' + err);
}
});
}
</script>
</head>
<body class="bg-gray-100">
<!-- Main Container -->
<main class="container mx-auto my-8 px-4">
<!-- Page Title -->
<h1 class="text-4xl font-poppins font-bold text-center text-gray-800 mb-12">Our Products | منتجاتنا</h1>
<!-- Products Grid -->
<div class="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-8">
<?php if ($products_result && $products_result->num_rows > 0): ?>
<?php while($product = $products_result->fetch_assoc()): ?>
<div class="bg-white shadow-lg rounded-lg overflow-hidden hover:shadow-2xl transition-shadow duration-300">
<img src="https://kaakalia.longevacare.com/public/products/<?= htmlspecialchars($product['thumbnail']) ?>" alt="<?= htmlspecialchars($product['name']) ?>" class="w-full h-48 object-cover">
<div class="p-6">
<!-- Product Name -->
<h2 class="text-2xl font-poppins font-semibold text-gray-800 mb-4"><?= htmlspecialchars($product['name']) ?></h2>
<!-- Arabic Description -->
<h3 class="text-xl font-poppins font-medium text-indigo-600 mb-2">الوصف بالعربية</h3>
<p class="text-gray-700 whitespace-pre-line mb-4">
<?= nl2br(htmlspecialchars($descriptions_ar[$product['id']] ?? 'تفاصيل المنتج غير متوفرة.')) ?>
</p>
<!-- English Description -->
<h3 class="text-xl font-poppins font-medium text-indigo-600 mb-2">Description in English</h3>
<p class="text-gray-700 whitespace-pre-line mb-4">
<?= nl2br(htmlspecialchars($descriptions_en[$product['id']] ?? 'Product details are not available.')) ?>
</p>
<!-- Product Details -->
<div class="mt-4">
<p class="text-lg font-medium text-gray-800"><strong>Size:</strong> <?= htmlspecialchars($product['size']) ?></p>
<p class="text-lg font-medium text-gray-800"><strong>Price:</strong> <?= number_format($product['price'], 2) ?> KD</p>
<p class="text-lg font-medium text-gray-800"><strong>Category:</strong> <?= htmlspecialchars($product['category']) ?></p>
</div>
<!-- Action Buttons -->
<div class="mt-6 flex justify-between">
<!-- View More Button -->
<button onclick="openModal('viewModal<?= $product['id'] ?>')" class="bg-teal-600 text-white px-4 py-2 rounded-full hover:bg-teal-700 transition flex items-center">
<i class="fas fa-eye mr-2"></i> View More
</button>
<!-- Copy Links Dropdown -->
<div class="relative">
<button onclick="toggleDropdown('dropdown<?= $product['id'] ?>')" class="bg-blue-600 text-white px-4 py-2 rounded-full hover:bg-blue-700 transition flex items-center">
<i class="fas fa-copy mr-2"></i> Copy Links
</button>
<!-- Dropdown Menu -->
<div id="dropdown<?= $product['id'] ?>" class="absolute right-0 mt-2 w-40 bg-white border border-gray-200 rounded-md shadow-lg hidden z-50">
<button onclick="copyProductLink(<?= $product['id'] ?>, 'en')" class="w-full text-left px-4 py-2 hover:bg-gray-100 flex items-center">
<i class="fas fa-copy mr-2"></i> Copy English
</button>
<button onclick="copyProductLink(<?= $product['id'] ?>, 'ar')" class="w-full text-left px-4 py-2 hover:bg-gray-100 flex items-center">
<i class="fas fa-copy mr-2"></i> نسخ العربية
</button>
</div>
</div>
</div>
</div>
</div>
<!-- View More Modal -->
<div id="viewModal<?= $product['id'] ?>" class="modal fixed inset-0 flex items-center justify-center bg-black bg-opacity-50 hidden z-50">
<div class="bg-white rounded-lg shadow-lg w-11/12 md:w-3/4 lg:w-1/2 relative">
<div class="flex justify-between items-center p-4 border-b">
<h3 class="text-2xl font-poppins font-semibold text-gray-800"><?= htmlspecialchars($product['name']) ?></h3>
<button onclick="closeModal('viewModal<?= $product['id'] ?>')" class="text-gray-500 hover:text-gray-700">
<!-- Close Icon -->
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12" />
</svg>
</button>
</div>
<div class="p-6">
<img src="https://kaakalia.longevacare.com/public/products/<?= htmlspecialchars($product['thumbnail']) ?>" alt="<?= htmlspecialchars($product['name']) ?>" class="w-full h-64 object-cover rounded-lg mb-6">
<!-- Detailed Arabic Description -->
<h4 class="text-xl font-poppins font-medium text-indigo-600 mb-2">الوصف بالعربية</h4>
<p class="text-gray-700 whitespace-pre-line mb-4">
<?= nl2br(htmlspecialchars($descriptions_ar[$product['id']] ?? 'تفاصيل المنتج غير متوفرة.')) ?>
</p>
<!-- Detailed English Description -->
<h4 class="text-xl font-poppins font-medium text-indigo-600 mb-2">Detailed Description in English</h4>
<p class="text-gray-700 whitespace-pre-line mb-4">
<?= nl2br(htmlspecialchars($descriptions_en[$product['id']] ?? 'Product details are not available.')) ?>
</p>
<!-- Additional Details -->
<div class="mt-4">
<p class="text-lg font-medium text-gray-800"><strong>Size:</strong> <?= htmlspecialchars($product['size']) ?></p>
<p class="text-lg font-medium text-gray-800"><strong>Price:</strong> <?= number_format($product['price'], 2) ?> KD</p>
<p class="text-lg font-medium text-gray-800"><strong>Category:</strong> <?= htmlspecialchars($product['category']) ?></p>
</div>
</div>
<div class="flex justify-end p-4 border-t">
<button onclick="closeModal('viewModal<?= $product['id'] ?>')" class="bg-gray-500 text-white px-4 py-2 rounded-full hover:bg-gray-600 transition">
Close
</button>
</div>
</div>
</div>
<?php endwhile; ?>
<?php else: ?>
<p class="col-span-full text-center text-gray-500">No products found.</p>
<?php endif; ?>
</div>
</main>
<!-- Footer -->
<footer class="bg-teal-600 text-white py-6 shadow-md">
<div class="container mx-auto text-center text-sm">
© 2024 Kaak Alia Bakery. All rights reserved.
</div>
</footer>
<!-- JavaScript for Dropdowns -->
<script>
// Function to toggle dropdown menus
function toggleDropdown(dropdownId) {
const dropdown = document.getElementById(dropdownId);
dropdown.classList.toggle('hidden');
}
// Close all dropdowns when clicking outside
window.onclick = function(event) {
if (!event.target.matches('.bg-blue-600, .bg-blue-600 *')) {
const dropdowns = document.querySelectorAll('.dropdown-menu');
dropdowns.forEach(dropdown => {
if (!dropdown.classList.contains('hidden')) {
dropdown.classList.add('hidden');
}
});
}
}
</script>
<!-- Include Footer (if you have a separate footer file) -->
<?php require_once __DIR__ . '/../../includes/footer.php'; ?>
</body>
</html>
Explanation of the Code:
Database Connection & Fetching Products :
The script connects to the database using db_connect.php.
It fetches all products ordered by their name.
Arabic and English descriptions are defined in associative arrays. Ensure these are synchronized with your database ids.
HTML Structure :
Head Section :
Includes meta tags for SEO and social media sharing.
Links to Google Fonts, Tailwind CSS, and Font Awesome for icons.
Contains custom styles for scrollbar and modal transitions.
Body Section :
Main Container : Houses the entire content.
Page Title : Displays "Our Products | منتجاتنا".
Products Grid : Uses Tailwind's grid system to display products responsively.
For each product:
Displays the product image.
Shows the product name.
Presents Arabic and English descriptions.
Lists size, price, and category.
Includes action buttons:
View More : Opens a modal with detailed information.
Copy Links : Dropdown to copy product links in English or Arabic.
View More Modal : A hidden modal that becomes visible when "View More" is clicked. It provides expanded details about the product.
Footer : Contains the footer content with copyright.
JavaScript Functions :
Modal Handling : Functions to open and close modals.
Copy Product Links : Enables copying of product URLs with specified language parameters.
Dropdown Handling : Toggles the visibility of dropdown menus for the "Copy Links" feature.
Security Measures :
Sanitization : All data output is sanitized using htmlspecialchars to prevent XSS attacks.
CSRF Tokens : If forms are added in the future, implement CSRF protection using the generated token.
Prepared Statements : Ensure all database queries use prepared statements to prevent SQL injection.
Additional Recommendations:
Dynamic Descriptions : Consider storing both Arabic and English descriptions in your database to make content management easier.
Example Table Structure :
CREATE TABLE products (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255) NOT NULL,
size VARCHAR(100) NOT NULL,
price DECIMAL(10,2) NOT NULL,
category VARCHAR(100) NOT NULL,
thumbnail VARCHAR(255) NOT NULL,
description_ar TEXT,
description_en TEXT
);
Localization Support : Implement a language switcher to allow users to choose their preferred language rather than displaying both languages simultaneously.
Enhanced Security : Ensure that db_connect.php uses secure credentials and consider implementing additional security measures like HTTPS, secure session management, and input validation.
Performance Optimization : Optimize images for faster loading and consider implementing caching strategies for improved performance.
Accessibility : Ensure that all images have alt attributes for screen readers and that the color contrast meets accessibility standards.
Final Thoughts
This products.php file provides a solid foundation for showcasing your bakery products in both Arabic and English. Feel free to customize the design, add more interactive features, or integrate additional functionalities as per your business requirements. If you encounter any issues or need further enhancements, don't hesitate to ask!
Copy first response
n
p
u
t
(
C
T
∗
F R O M p r o d u c t s O R D E R B Y nam e A S C " ;
ani
t
i
z
e i
n
p
u
t
(
t
r
es
u
l
t
−
>
n u m r o w s ===
0 ) // P r o d u c t n o t f o u n d h tt p r es p o n s e c o d e ( 404 ) ; ec h o " P r o d u c t n o t f o u n d ." ; e x i t ( ) ;
a
ssoc
(
)
;
d
e
t
ai
l
s
a
r
e
n
o
t
a
v
ai
l
ab
l
e
."
;
p
a
g
e u
r
l
= ′
h ttp s :
// k aak a l ia . l o n g e v a c a r e . co m / p u b l i c / p r o d u c t s / p r o d u c t . p h p ? i d = ′
.
Responsive Design :
The grid system adapts to different screen sizes, ensuring optimal viewing on mobile, tablet, and desktop devices.
Modals are responsive and centered on the screen.
Accessibility & User Experience :
Interactive elements like buttons have hover effects for better user feedback.
Modals can be closed by clicking outside the content area or using the close button.