🤩 File Manager - Mr.X
PHP:
8.3.33
Server:
Apache
OS:
Linux 5.14.0-611.49.1.el9_7.x86_64
User:
websparkit
Navigate
Upload:
Upload
New File
New Folder
Editing:brand-add.php
<?php $page = 'brands'; $page_title = 'Add / Edit Brand'; require_once '../includes/header.php'; $id = intval($_GET['id'] ?? 0); $brand = ['id' => 0, 'name' => '', 'slug' => '', 'description' => '', 'logo' => '', 'featured' => 0, 'status' => 1]; if ($id) { $stmt = $db->prepare("SELECT * FROM brands WHERE id = ?"); $stmt->execute([$id]); $brand = $stmt->fetch(PDO::FETCH_ASSOC); if (!$brand) { admin_set_flash('error', 'Not found'); header('Location: ' . ADMIN_PATH . 'pages/brands.php'); exit; } $page_title = 'Edit Brand'; } if ($_SERVER['REQUEST_METHOD'] == 'POST' && verify_csrf($_POST[CSRF_TOKEN_NAME] ?? '')) { $name = trim($_POST['name']); $slug = !empty($_POST['slug']) ? create_slug($_POST['slug']) : create_slug($name); $description = trim($_POST['description'] ?? ''); $featured = isset($_POST['featured']) ? 1 : 0; $status = intval($_POST['status']); $logo = $brand['logo'] ?? ''; if (isset($_FILES['logo']) && $_FILES['logo']['error'] == 0) { $new_logo = upload_image($_FILES['logo'], 'brands', $name); if ($new_logo) $logo = $new_logo; } try { if ($id) { $stmt = $db->prepare("UPDATE brands SET name=?, slug=?, description=?, logo=?, featured=?, status=? WHERE id=?"); $stmt->execute([$name, $slug, $description, $logo, $featured, $status, $id]); admin_set_flash('success', 'Brand updated'); } else { $stmt = $db->prepare("INSERT INTO brands (name, slug, description, logo, featured, status) VALUES (?, ?, ?, ?, ?, ?)"); $stmt->execute([$name, $slug, $description, $logo, $featured, $status]); admin_set_flash('success', 'Brand added'); } header('Location: ' . ADMIN_PATH . 'pages/brands.php'); exit; } catch (Exception $e) { $error = 'Failed: ' . $e->getMessage(); } } ?> <div class="admin-card"> <?php if (isset($error)): ?> <div class="alert alert-danger"><?= htmlspecialchars($error) ?></div> <?php endif; ?> <form method="POST" enctype="multipart/form-data"> <?= csrf_field() ?> <div class="row g-4"> <div class="col-md-8"> <div class="form-group-admin"> <label class="form-label-admin">Brand Name *</label> <input type="text" name="name" class="form-control-admin" required value="<?= htmlspecialchars($brand['name']) ?>"> </div> <div class="form-group-admin"> <label class="form-label-admin">Slug</label> <input type="text" name="slug" class="form-control-admin" value="<?= htmlspecialchars($brand['slug']) ?>" placeholder="auto-generated"> </div> <div class="form-group-admin"> <label class="form-label-admin">Description</label> <textarea name="description" class="form-control-admin" rows="3"><?= htmlspecialchars($brand['description'] ?? '') ?></textarea> </div> </div> <div class="col-md-4"> <div class="form-group-admin"> <label class="form-label-admin">Status</label> <select name="status" class="form-control-admin"> <option value="1" <?= $brand['status'] == 1 ? 'selected' : '' ?>>Active</option> <option value="0" <?= $brand['status'] == 0 ? 'selected' : '' ?>>Inactive</option> </select> </div> <div class="form-group-admin"> <div class="form-check"> <input class="form-check-input" type="checkbox" id="featured" name="featured" <?= $brand['featured'] ? 'checked' : '' ?>> <label class="form-check-label" for="featured">Featured Brand</label> </div> </div> <div class="form-group-admin"> <label class="form-label-admin">Logo</label> <input type="file" name="logo" class="form-control-admin" accept="image/*" data-preview="brand-preview"> <?php if ($brand['logo']): ?> <img id="brand-preview" src="<?= UPLOADS_URL ?>brands/<?= $brand['logo'] ?>" class="image-preview image-preview-lg" style="margin-top: 10px;"> <?php else: ?> <img id="brand-preview" class="image-preview image-preview-lg" style="display: none; margin-top: 10px;"> <?php endif; ?> </div> </div> </div> <hr style="margin: 30px 0;"> <div class="d-flex gap-2"> <button type="submit" class="btn-admin btn-primary-admin"> <i class="fas fa-save"></i> <?= $id ? 'Update' : 'Add' ?> </button> <a href="<?= ADMIN_PATH ?>pages/brands.php" class="btn-admin btn-secondary-admin">Cancel</a> </div> </form> </div> <?php require_once '../includes/footer.php'; ?>
Save Changes
Cancel
Create New File
Create New Folder