<?php
include 'includes/header.php';
if (isset($_GET['id'])) {
require_permission('categories_edit');
} else {
require_permission('categories_add');
}
include '../includes/db.php';
$category = ['id' => '', 'name' => ''];
$page_title = "إضافة فئة جديدة";
if (isset($_GET['id'])) {
$category_id = $_GET['id'];
$stmt = $conn->prepare("SELECT * FROM categories WHERE id = ?");
$stmt->bind_param("i", $category_id);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows === 1) {
$category = $result->fetch_assoc();
$page_title = "تعديل الفئة";
} else {
header("Location: categories.php?error=Category not found");
exit();
}
$stmt->close();
}
?>
<h3 class="fs-4 mb-3"><?= $page_title ?></h3>
<div class="row">
<div class="col-md-8 mx-auto">
<div class="glass-card p-4">
<form action="category_process.php" method="POST">
<input type="hidden" name="id" value="<?= htmlspecialchars($category['id']) ?>">
<div class="mb-3">
<label for="name" class="form-label">اسم الفئة</label>
<input type="text" class="form-control" id="name" name="name" value="<?= htmlspecialchars($category['name']) ?>" required>
</div>
<button type="submit" class="btn btn-success mt-3">حفظ</button>
<a href="categories.php" class="btn btn-secondary mt-3">إلغاء</a>
</form>
</div>
</div>
</div>
<?php include 'includes/footer.php'; ?>