-- Host: 127.0.0.1:3306
-- Generation Time: Nov 12, 2024 at 08:36 AM
-- Server version: 10.11.9-MariaDB
-- PHP Version: 7.2.34
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
START TRANSACTION;
SET time_zone = "+00:00";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT /;
/!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS /;
/!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION /;
/!40101 SET NAMES utf8mb4 */;
--
-- Database: u406552082_kaakalia
--
-- Table structure for table ads
CREATE TABLE ads (
id int(11) NOT NULL,
user_id int(11) NOT NULL,
name varchar(255) NOT NULL,
ad_type enum('Post','Story') NOT NULL,
related_id int(11) NOT NULL,
budget decimal(10,2) NOT NULL,
total_spent decimal(10,2) DEFAULT 0.00,
start_date date NOT NULL,
end_date date NOT NULL,
status enum('Active','Paused','Completed') DEFAULT 'Active',
created_at datetime DEFAULT current_timestamp(),
updated_at datetime DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
--
-- Table structure for table ad_spend_logs
CREATE TABLE ad_spend_logs (
id int(11) NOT NULL,
ad_id int(11) NOT NULL,
amount decimal(10,2) NOT NULL,
spend_date datetime DEFAULT current_timestamp(),
description varchar(255) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
--
-- Table structure for table customers
CREATE TABLE customers (
id int(11) NOT NULL,
name varchar(100) NOT NULL,
contact varchar(50) DEFAULT NULL,
delivery_address text DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
--
-- Table structure for table drivers
CREATE TABLE drivers (
id int(11) NOT NULL,
name varchar(100) NOT NULL,
number varchar(15) NOT NULL,
is_star tinyint(1) DEFAULT 0
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
Assistant
--
-- Table structure for table notifications
CREATE TABLE notifications (
id int(11) NOT NULL,
user_id int(11) NOT NULL,
type enum('order','post','plan','note','ad') NOT NULL,
message varchar(255) NOT NULL,
link varchar(255) NOT NULL,
created_at datetime DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
--
-- Table structure for table orders
CREATE TABLE orders (
id int(11) NOT NULL,
customer_id int(11) NOT NULL,
status enum('Pending','In Progress','Completed','Delivered') DEFAULT 'Pending',
priority enum('Normal','Important','Quick') DEFAULT 'Normal',
order_date datetime DEFAULT current_timestamp(),
delivery_datetime datetime DEFAULT NULL,
delivery_date date DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
--
-- Table structure for table order_items
CREATE TABLE order_items (
id int(11) NOT NULL,
order_id int(11) NOT NULL,
product_id int(11) NOT NULL,
quantity int(11) NOT NULL DEFAULT 1,
packaging_preferences varchar(255) DEFAULT NULL,
discount_percentage decimal(5,2) DEFAULT 0.00,
discount_reason varchar(255) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
--
-- Table structure for table products
CREATE TABLE products (
id int(11) NOT NULL,
name varchar(100) NOT NULL,
size varchar(50) DEFAULT NULL,
price decimal(10,2) NOT NULL,
category varchar(50) DEFAULT NULL,
thumbnail varchar(255) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
--
-- Table structure for table users
CREATE TABLE users (
id int(11) NOT NULL,
username varchar(50) NOT NULL,
email varchar(100) DEFAULT NULL,
password varchar(255) NOT NULL,
role enum('admin','staff') NOT NULL,
profile_image varchar(255) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
--
-- Table structure for table workspace_notes
CREATE TABLE workspace_notes (
id int(11) NOT NULL,
user_id int(11) NOT NULL,
title varchar(255) NOT NULL,
content text NOT NULL,
created_at datetime DEFAULT current_timestamp(),
updated_at datetime DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
--
-- Table structure for table workspace_plans
CREATE TABLE workspace_plans (
id int(11) NOT NULL,
user_id int(11) NOT NULL,
title varchar(255) NOT NULL,
description text DEFAULT NULL,
audio_path varchar(255) DEFAULT NULL,
due_date datetime DEFAULT NULL,
status enum('Not Started','In Progress','Completed') DEFAULT 'Not Started',
created_at datetime DEFAULT current_timestamp(),
updated_at datetime DEFAULT current_timestamp() ON UPDATE current_timestamp(),
priority enum('Normal','Important','Critical') NOT NULL DEFAULT 'Normal'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
--
-- Table structure for table workspace_posts
CREATE TABLE workspace_posts (
id int(11) NOT NULL,
user_id int(11) NOT NULL,
platform enum('Instagram','Facebook','Twitter','Other') NOT NULL,
content text NOT NULL,
media_url varchar(255) DEFAULT NULL,
scheduled_datetime datetime DEFAULT NULL,
status enum('Scheduled','Posted','Failed') DEFAULT 'Scheduled',
created_at datetime DEFAULT current_timestamp(),
updated_at datetime DEFAULT current_timestamp() ON UPDATE current_timestamp(),
type enum('Post','Story') DEFAULT 'Post'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
ALTER TABLE ads
MODIFY id int(11) NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT for table ad_spend_logs
ALTER TABLE ad_spend_logs
MODIFY id int(11) NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT for table customers
ALTER TABLE customers
MODIFY id int(11) NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT for table drivers
ALTER TABLE drivers
MODIFY id int(11) NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT for table notifications
ALTER TABLE notifications
MODIFY id int(11) NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT for table orders
ALTER TABLE orders
MODIFY id int(11) NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT for table order_items
ALTER TABLE order_items
MODIFY id int(11) NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT for table products
ALTER TABLE products
MODIFY id int(11) NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT for table users
ALTER TABLE users
MODIFY id int(11) NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT for table workspace_notes
ALTER TABLE workspace_notes
MODIFY id int(11) NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT for table workspace_plans
ALTER TABLE workspace_plans
MODIFY id int(11) NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT for table workspace_posts
ALTER TABLE workspace_posts
MODIFY id int(11) NOT NULL AUTO_INCREMENT;
--
-- Constraints for dumped tables
--
-- Constraints for table ads
ALTER TABLE ads
ADD CONSTRAINT fk_ads_related_id FOREIGN KEY (related_id) REFERENCES workspace_posts (id) ON DELETE CASCADE,
ADD CONSTRAINT fk_ads_user_id FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE;
--
-- Constraints for table ad_spend_logs
ALTER TABLE ad_spend_logs
ADD CONSTRAINT fk_ad_spend_logs_ad_id FOREIGN KEY (ad_id) REFERENCES ads (id) ON DELETE CASCADE;
--
-- Constraints for table notifications
ALTER TABLE notifications
ADD CONSTRAINT notifications_ibfk_1 FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE;
--
-- Constraints for table orders
ALTER TABLE orders
ADD CONSTRAINT fk_orders_customer_id FOREIGN KEY (customer_id) REFERENCES customers (id) ON DELETE CASCADE ON UPDATE CASCADE,
ADD CONSTRAINT orders_ibfk_1 FOREIGN KEY (customer_id) REFERENCES customers (id) ON DELETE CASCADE;
--
-- Constraints for table order_items
ALTER TABLE order_items
ADD CONSTRAINT fk_order_items_order_id FOREIGN KEY (order_id) REFERENCES orders (id) ON DELETE CASCADE ON UPDATE CASCADE,
ADD CONSTRAINT fk_order_items_product_id FOREIGN KEY (product_id) REFERENCES products (id) ON DELETE CASCADE ON UPDATE CASCADE,
ADD CONSTRAINT order_items_ibfk_1 FOREIGN KEY (order_id) REFERENCES orders (id) ON DELETE CASCADE,
ADD CONSTRAINT order_items_ibfk_2 FOREIGN KEY (product_id) REFERENCES products (id) ON DELETE CASCADE;
--
-- Constraints for table workspace_notes
ALTER TABLE workspace_notes
ADD CONSTRAINT fk_workspace_notes_user_id FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE;
--
-- Constraints for table workspace_plans
ALTER TABLE workspace_plans
ADD CONSTRAINT fk_workspace_plans_user_id FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE;
--
-- Constraints for table workspace_posts
ALTER TABLE workspace_posts
ADD CONSTRAINT fk_workspace_posts_user_id FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE;
COMMIT;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT /;
/!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS /;
/!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;) in this codes (<?php
// public/products/manage_products.php
// Now 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
success=′′;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']) && POST[′csrftoken′]===_SESSION['csrf_token']) {
// Add Product
if (isset(_POST['add_product'])) {
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 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));
// Function to build query strings
function build_query(params) {
query = http_build_query(array_filter(params,function(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";
stmt=conn->prepare(productssql);if(stmt) {
likesearch="search_query . "%";
stmt−>bindparam("sss",like_search, likesearch,like_search);
stmt−>execute();products_result = stmt->get_result();
} else {
die("Prepare statement failed: " . conn->error);
}
} else {
productssql="SELEproducts_result = conn−>query(products_sql);
}
?>
شابورة (لسان الثور)
في علبه نص كيلو 🗃 ٦ دك
علبة كيلو 🗃 ٨ دك
سلة صغيرة 🧺 ٨ دك
سلة كبيرة 🧺 ١٠ دك
بوكس المناسبات ٣٣ حبه اب ١١ دك
<!-- Text for Product 2: كيكة مالحة -->
<p id="textProduct2">
كيكة مالحة (مونكي بريد)🥮
الحجم الكبير ١٢ دك
الميني كيك ١٢ حبه اب ٦ دك
الميني كيك ٢٤ حبه اب ٩ دك
الميني كيك ٣٦ حبه اب ١٢ دك
بوكس المناسبات ٣٥ حبه اب ١٤.٥ دك
<!-- Text for Product 3: مهلبية -->
<p id="textProduct3">
مهلبية كرنشي 🍨
١٢ حبه اب ١٢ دك
</main>
) and add make it cool design and make the path in same folder of products, and when i copy detaisl of product, copy with them copy address url, and type full codes
Certainly! Below is the updated manage_products.php file that includes the new Arabic products section as per your requirements. The new section displays products with images and details in Arabic, incorporates a copy functionality that copies both the product details and the image URL, and ensures that all design elements are cohesive and visually appealing using Tailwind CSS. Additionally, Font Awesome has been integrated for the copy icons.
Key Updates:
Added Font Awesome CDN: To utilize the copy icons, the Font Awesome library has been included in the <head> section.
Integrated Arabic Products Section: A new section titled "منتجاتنا" has been added below the "All Products" section, showcasing products with images and detailed descriptions in Arabic.
Enhanced Copy Functionality: Updated the copy buttons to copy both the product details and the image URL using JavaScript's Clipboard API.
Responsive and Cool Design: Leveraged Tailwind CSS to ensure the new section is responsive and maintains a modern, clean design consistent with the existing layout.
Located below the "All Products" section, this section showcases five products with images and detailed descriptions in Arabic.
Each product card includes an image, title, description, and a "نسخ التفاصيل" (Copy Details) button.
The "Copy Details" buttons are linked to the copyDetails JavaScript function, which handles copying both the product details and the image URL.
Copy Functionality:
The copyDetails JavaScript function takes two parameters: the ID of the hidden text containing the product details and the image URL.
When a copy button is clicked, it concatenates the product details with the full image URL and copies the combined text to the clipboard.
An alert notifies the user upon successful copying or if an error occurs.
function copyDetails(textId, imageUrl) {
const text = document.getElementById(textId).innerText;
const fullText = text + '\n' + window.location.origin + '/' + imageUrl;
navigator.clipboard.writeText(fullText).then(() => {
alert('تم نسخ التفاصيل بنجاح!');
}).catch(err => {
alert('فشل في نسخ التفاصيل: ', err);
});
}
Hidden Texts for Copying:
Beneath the Arabic products grid, hidden <p> elements contain the detailed text for each product. These texts are referenced by their respective IDs (textProduct1, textProduct2, etc.) when copying.
Each product card is designed to be visually appealing with shadows, rounded corners, and hover effects.
Additional Recommendations:
Image Optimization: Ensure that all images (gallery1.jpg, gallery2.jpg, etc.) are optimized for web use to maintain fast loading times.
Accessibility: Consider adding aria-labels or other accessibility attributes to buttons and interactive elements to enhance usability for all users.
Validation and Security: While basic validation is implemented, consider adding more robust validation and security measures depending on the application's needs.
By incorporating these updates, your manage_products.php page will now feature an attractive Arabic products section with enhanced functionality, providing a better user experience for Arabic-speaking users.