[
MAINHACK
]
Mail Test
BC
Config Scan
HOME
Create...
New File
New Folder
Viewing / Editing File: manage.php
<?php require_once '../config/database.php'; require_once '../config/functions.php'; requireAuth('manager'); // Get all products $stmt = $pdo->prepare("SELECT * FROM products ORDER BY name ASC"); $stmt->execute(); $products = $stmt->fetchAll(); $error = ''; $success = ''; // Handle product actions if ($_SERVER['REQUEST_METHOD'] === 'POST') { $action = $_POST['action'] ?? ''; if ($action === 'add_product') { $name = trim($_POST['name'] ?? ''); $unit = trim($_POST['unit'] ?? ''); $price = floatval($_POST['price'] ?? 0); $stock_quantity = floatval($_POST['stock_quantity'] ?? 0); if (!$name || !$unit || $price <= 0) { $error = 'جميع البيانات مطلوبة والسعر يجب أن يكون أكبر من صفر'; } else { try { $stmt = $pdo->prepare(" INSERT INTO products (name, unit, price, stock_quantity) VALUES (?, ?, ?, ?) "); $stmt->execute([$name, $unit, $price, $stock_quantity]); $product_id = $pdo->lastInsertId(); addAuditLog($pdo, $_SESSION['user_id'], 'create_product', 'product', $product_id, null, [ 'name' => $name, 'unit' => $unit, 'price' => $price, 'stock_quantity' => $stock_quantity ], "إضافة منتج جديد: $name"); $success = 'تم إضافة المنتج بنجاح'; } catch (Exception $e) { $error = 'خطأ في إضافة المنتج: ' . $e->getMessage(); } } } elseif ($action === 'update_product') { $product_id = $_POST['product_id'] ?? ''; $name = trim($_POST['name'] ?? ''); $unit = trim($_POST['unit'] ?? ''); $price = floatval($_POST['price'] ?? 0); $stock_quantity = floatval($_POST['stock_quantity'] ?? 0); $is_active = isset($_POST['is_active']) ? 1 : 0; if (!$product_id || !$name || !$unit || $price <= 0) { $error = 'جميع البيانات مطلوبة والسعر يجب أن يكون أكبر من صفر'; } else { try { // Get old values $stmt = $pdo->prepare("SELECT * FROM products WHERE id = ?"); $stmt->execute([$product_id]); $old_product = $stmt->fetch(); $stmt = $pdo->prepare(" UPDATE products SET name = ?, unit = ?, price = ?, stock_quantity = ?, is_active = ? WHERE id = ? "); $stmt->execute([$name, $unit, $price, $stock_quantity, $is_active, $product_id]); addAuditLog($pdo, $_SESSION['user_id'], 'update_product', 'product', $product_id, $old_product, [ 'name' => $name, 'unit' => $unit, 'price' => $price, 'stock_quantity' => $stock_quantity, 'is_active' => $is_active ], "تحديث المنتج: $name"); $success = 'تم تحديث المنتج بنجاح'; } catch (Exception $e) { $error = 'خطأ في تحديث المنتج: ' . $e->getMessage(); } } } elseif ($action === 'bulk_price_update') { $percentage = floatval($_POST['percentage'] ?? 0); $update_type = $_POST['update_type'] ?? 'increase'; if ($percentage <= 0) { $error = 'النسبة يجب أن تكون أكبر من صفر'; } else { try { $pdo->beginTransaction(); // Get all active products $stmt = $pdo->prepare("SELECT * FROM products WHERE is_active = 1"); $stmt->execute(); $all_products = $stmt->fetchAll(); foreach ($all_products as $product) { $old_price = $product['price']; $new_price = $update_type === 'increase' ? $old_price * (1 + $percentage / 100) : $old_price * (1 - $percentage / 100); $new_price = max($new_price, 0.01); // Minimum price $stmt = $pdo->prepare("UPDATE products SET price = ? WHERE id = ?"); $stmt->execute([$new_price, $product['id']]); addAuditLog($pdo, $_SESSION['user_id'], 'bulk_price_update', 'product', $product['id'], ['price' => $old_price], ['price' => $new_price], "تحديث جماعي للأسعار: {$product['name']} من $old_price إلى $new_price"); } $pdo->commit(); $success = "تم تحديث أسعار " . count($all_products) . " منتج بنجاح"; } catch (Exception $e) { $pdo->rollBack(); $error = 'خطأ في التحديث الجماعي: ' . $e->getMessage(); } } } // Refresh data if ($success) { header("Location: /products/manage.php?success=" . urlencode($success)); exit; } } if (isset($_GET['success'])) { $success = $_GET['success']; } ?> <!DOCTYPE html> <html lang="ar" dir="rtl"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>إدارة المنتجات - حسابات عربية بن فريش</title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.rtl.min.css" rel="stylesheet"> <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet"> <style> .product-card { border-radius: 15px; transition: all 0.3s ease; } .product-card:hover { transform: translateY(-2px); box-shadow: 0 4px 8px rgba(0,0,0,0.1); } .product-active { border-left: 5px solid #198754; } .product-inactive { border-left: 5px solid #dc3545; opacity: 0.7; } .bulk-update-card { background: linear-gradient(135deg, #fd7e14, #ffc107); color: white; border-radius: 15px; } </style> </head> <body class="bg-light"> <div class="container-fluid mt-4"> <div class="d-flex justify-content-between align-items-center mb-4"> <h2><i class="fas fa-box me-2"></i>إدارة المنتجات</h2> <div> <button class="btn btn-primary me-2" data-bs-toggle="modal" data-bs-target="#addProductModal"> <i class="fas fa-plus me-1"></i>منتج جديد </button> <a href="/dashboard.php" class="btn btn-outline-secondary"> <i class="fas fa-arrow-left me-1"></i>العودة </a> </div> </div> <?php if ($error): ?> <div class="alert alert-danger" role="alert"> <i class="fas fa-exclamation-triangle me-2"></i><?= htmlspecialchars($error) ?> </div> <?php endif; ?> <?php if ($success): ?> <div class="alert alert-success" role="alert"> <i class="fas fa-check-circle me-2"></i><?= htmlspecialchars($success) ?> </div> <?php endif; ?> <!-- Bulk Price Update --> <div class="bulk-update-card p-4 mb-4"> <h5 class="mb-3"><i class="fas fa-percentage me-2"></i>التحديث الجماعي للأسعار</h5> <form method="POST" class="row align-items-end"> <input type="hidden" name="action" value="bulk_price_update"> <div class="col-md-3"> <label class="form-label">النسبة المئوية</label> <input type="number" class="form-control" name="percentage" min="0.01" step="0.01" placeholder="10" required> </div> <div class="col-md-3"> <label class="form-label">نوع التحديث</label> <select class="form-select" name="update_type" required> <option value="increase">زيادة الأسعار</option> <option value="decrease">تقليل الأسعار</option> </select> </div> <div class="col-md-6"> <button type="submit" class="btn btn-light" onclick="return confirm('هل أنت متأكد من تحديث جميع أسعار المنتجات؟')"> <i class="fas fa-sync me-1"></i>تحديث جميع الأسعار </button> </div> </form> </div> <!-- Products Grid --> <div class="row"> <?php foreach ($products as $product): ?> <div class="col-md-4 mb-4"> <div class="product-card card <?= $product['is_active'] ? 'product-active' : 'product-inactive' ?>"> <div class="card-body"> <div class="d-flex justify-content-between align-items-start mb-3"> <h5 class="card-title"><?= htmlspecialchars($product['name']) ?></h5> <span class="badge bg-<?= $product['is_active'] ? 'success' : 'danger' ?>"> <?= $product['is_active'] ? 'نشط' : 'غير نشط' ?> </span> </div> <div class="row mb-3"> <div class="col-6"> <small class="text-muted">الوحدة:</small> <div><?= htmlspecialchars($product['unit']) ?></div> </div> <div class="col-6"> <small class="text-muted">السعر:</small> <div class="fw-bold text-primary"><?= formatCurrency($product['price']) ?></div> </div> </div> <div class="mb-3"> <small class="text-muted">المخزون:</small> <div class="fw-bold"><?= $product['stock_quantity'] ?> <?= htmlspecialchars($product['unit']) ?></div> </div> <div class="d-flex gap-2"> <button class="btn btn-outline-primary btn-sm flex-grow-1" data-bs-toggle="modal" data-bs-target="#editModal<?= $product['id'] ?>"> <i class="fas fa-edit me-1"></i>تعديل </button> </div> </div> </div> </div> <!-- Edit Product Modal --> <div class="modal fade" id="editModal<?= $product['id'] ?>" tabindex="-1"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <h5 class="modal-title">تعديل المنتج</h5> <button type="button" class="btn-close" data-bs-dismiss="modal"></button> </div> <form method="POST"> <div class="modal-body"> <input type="hidden" name="action" value="update_product"> <input type="hidden" name="product_id" value="<?= $product['id'] ?>"> <div class="mb-3"> <label class="form-label">اسم المنتج *</label> <input type="text" class="form-control" name="name" value="<?= htmlspecialchars($product['name']) ?>" required> </div> <div class="row"> <div class="col-md-6 mb-3"> <label class="form-label">الوحدة *</label> <input type="text" class="form-control" name="unit" value="<?= htmlspecialchars($product['unit']) ?>" required> </div> <div class="col-md-6 mb-3"> <label class="form-label">السعر *</label> <input type="number" class="form-control" name="price" value="<?= $product['price'] ?>" min="0.01" step="0.01" required> </div> </div> <div class="mb-3"> <label class="form-label">كمية المخزون</label> <input type="number" class="form-control" name="stock_quantity" value="<?= $product['stock_quantity'] ?>" min="0" step="0.01"> </div> <div class="form-check"> <input class="form-check-input" type="checkbox" name="is_active" <?= $product['is_active'] ? 'checked' : '' ?>> <label class="form-check-label">منتج نشط</label> </div> </div> <div class="modal-footer"> <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">إلغاء</button> <button type="submit" class="btn btn-primary">حفظ التغييرات</button> </div> </form> </div> </div> </div> <?php endforeach; ?> </div> </div> <!-- Add Product Modal --> <div class="modal fade" id="addProductModal" tabindex="-1"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <h5 class="modal-title">إضافة منتج جديد</h5> <button type="button" class="btn-close" data-bs-dismiss="modal"></button> </div> <form method="POST"> <div class="modal-body"> <input type="hidden" name="action" value="add_product"> <div class="mb-3"> <label class="form-label">اسم المنتج *</label> <input type="text" class="form-control" name="name" required> </div> <div class="row"> <div class="col-md-6 mb-3"> <label class="form-label">الوحدة *</label> <input type="text" class="form-control" name="unit" placeholder="كيلو، قطعة، علبة..." required> </div> <div class="col-md-6 mb-3"> <label class="form-label">السعر *</label> <input type="number" class="form-control" name="price" min="0.01" step="0.01" required> </div> </div> <div class="mb-3"> <label class="form-label">كمية المخزون الأولية</label> <input type="number" class="form-control" name="stock_quantity" min="0" step="0.01" value="0"> </div> </div> <div class="modal-footer"> <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">إلغاء</button> <button type="submit" class="btn btn-primary">إضافة المنتج</button> </div> </form> </div> </div> </div> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script> </body> </html>
Save Changes
Cancel / Back
Close ×
Server Info
Hostname: premium320.web-hosting.com
Server IP: 66.29.153.54
PHP Version: 8.2.29
Server Software: LiteSpeed
System: Linux premium320.web-hosting.com 4.18.0-553.50.1.lve.el8.x86_64 #1 SMP Thu Apr 17 19:10:24 UTC 2025 x86_64
HDD Total: 97.87 GB
HDD Free: 76.87 GB
Domains on IP: N/A (Requires external lookup)
System Features
Safe Mode:
Off
disable_functions:
None
allow_url_fopen:
On
allow_url_include:
Off
magic_quotes_gpc:
Off
register_globals:
Off
open_basedir:
None
cURL:
Enabled
ZipArchive:
Enabled
MySQLi:
Enabled
PDO:
Enabled
wget:
Yes
curl (cmd):
Yes
perl:
Yes
python:
Yes (py3)
gcc:
Yes
pkexec:
No
git:
Yes
User Info
Username: aoneqssk
User ID (UID): 1285
Group ID (GID): 1290
Script Owner UID: 1285
Current Dir Owner: 1285