<?php
include 'includes/header.php';
if (isset($_GET['id'])) {
require_permission('brands_edit');
} else {
require_permission('brands_add');
}
include '../includes/db.php';
$brand = ['id' => '', 'name' => '', 'logo' => ''];
$page_title = "إضافة ماركة جديدة";
if (isset($_GET['id'])) {
$brand_id = $_GET['id'];
$stmt = $conn->prepare("SELECT * FROM brands WHERE id = ?");
$stmt->bind_param("i", $brand_id);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows === 1) {
$brand = $result->fetch_assoc();
$page_title = "تعديل الماركة";
} else {
header("Location: brands.php?error=Brand not found");
exit();
}
$stmt->close();
}
?>
<h3 class="fs-4 mb-3"><?= $page_title ?></h3>
<div class="row">
<div class="col">
<div class="glass-card p-4">
<form action="brand_process.php" method="POST" enctype="multipart/form-data">
<input type="hidden" name="id" value="<?= htmlspecialchars($brand['id']) ?>">
<div class="mb-3">
<label for="name" class="form-label">اسم الماركة</label>
<input type="text" class="form-control" id="name" name="name" value="<?= htmlspecialchars($brand['name']) ?>" required>
</div>
<div class="mb-3">
<label for="logo" class="form-label">شعار الماركة (اللوجو)</label>
<input class="form-control" type="file" id="logo" name="logo" accept="image/*">
<?php if (!empty($brand['logo'])): ?>
<div class="mt-2">
<small>اللوجو الحالي:</small>
<img src="../uploads/brands/<?= htmlspecialchars($brand['logo']) ?>" height="40" class="ms-2 rounded bg-light p-1">
<input type="hidden" name="current_logo" value="<?= htmlspecialchars($brand['logo']) ?>">
</div>
<?php endif; ?>
</div>
<button type="submit" class="btn btn-success mt-3">حفظ</button>
<a href="brands.php" class="btn btn-secondary mt-3">إلغاء</a>
</form>
</div>
</div>
</div>
<?php include 'includes/footer.php'; ?>