Hackfut Security File Manager
Current Path:
/home/u126195517/domains/foodstamping.in/public_html/admin
home
/
u126195517
/
domains
/
foodstamping.in
/
public_html
/
admin
/
📁
..
📁
assets
📄
categories.php
(15.94 KB)
📄
get-product.php
(604 B)
📄
index.php
(7.83 KB)
📄
login.php
(4.52 KB)
📄
logout.php
(557 B)
📄
orders.php
(10.34 KB)
📄
product-action.php
(2.63 KB)
📄
product-images.php
(14.15 KB)
📄
product-save.php
(6.86 KB)
📄
product-specifications.php
(11.11 KB)
📄
products.php
(48.18 KB)
📄
reviews.php
(12.46 KB)
📄
specifications.php
(14.72 KB)
Editing: specifications.php
<?php // admin/specifications.php session_start(); require_once '../config/database.php'; if (!isset($_SESSION['admin_id'])) { header("Location: login.php"); exit(); } $database = new Database(); $db = $database->getConnection(); // Handle Actions (Add, Edit, Delete) if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['action'])) { $action = $_POST['action']; switch ($action) { case 'save': $id = $_POST['spec_id']; $name = trim($_POST['name']); $value = trim($_POST['value']); $type = $_POST['type']; $product_id = $_POST['product_id'] ?? null; if (empty($name)) { $_SESSION['message'] = "Specification name cannot be empty."; $_SESSION['message_type'] = "danger"; } else { if (empty($id)) { $query = "INSERT INTO product_specifications (product_id, spec_name, spec_value, spec_type) VALUES (:product_id, :spec_name, :spec_value, :spec_type)"; $stmt = $db->prepare($query); } else { $query = "UPDATE product_specifications SET spec_name = :spec_name, spec_value = :spec_value, spec_type = :spec_type WHERE id = :id"; $stmt = $db->prepare($query); $stmt->bindParam(':id', $id); } $stmt->bindParam(':product_id', $product_id); $stmt->bindParam(':spec_name', $name); $stmt->bindParam(':spec_value', $value); $stmt->bindParam(':spec_type', $type); if ($stmt->execute()) { $_SESSION['message'] = "Specification saved successfully!"; $_SESSION['message_type'] = "success"; } } header("Location: specifications.php"); exit(); break; case 'delete': $id = $_POST['spec_id']; $query = "DELETE FROM product_specifications WHERE id = :id"; $stmt = $db->prepare($query); $stmt->bindParam(':id', $id); if ($stmt->execute()) { $_SESSION['message'] = "Specification deleted successfully!"; $_SESSION['message_type'] = "success"; } header("Location: specifications.php"); exit(); break; } } // Fetch all specifications with product names if available $query = "SELECT ps.*, p.name AS product_name FROM product_specifications ps LEFT JOIN products p ON ps.product_id = p.id ORDER BY ps.sort_order ASC, ps.spec_name ASC"; $stmt = $db->prepare($query); $stmt->execute(); $specifications = $stmt->fetchAll(PDO::FETCH_ASSOC); // Fetch a single specification for editing if (isset($_GET['action']) && $_GET['action'] == 'get_spec' && isset($_GET['id'])) { $id = $_GET['id']; $query = "SELECT * FROM product_specifications WHERE id = :id"; $stmt = $db->prepare($query); $stmt->bindParam(':id', $id); $stmt->execute(); $spec = $stmt->fetch(PDO::FETCH_ASSOC); echo json_encode($spec); exit(); } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Manage Specifications - Admin Panel</title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css"> <link rel="stylesheet" href="https://cdn.datatables.net/1.11.5/css/dataTables.bootstrap5.min.css"> <link rel="stylesheet" href="assets/css/style.css"> <style> .sidebar { min-height: 100vh; background: #343a40; } .sidebar .nav-link { color: #fff; padding: 15px 20px; } .sidebar .nav-link:hover { background: #495057; } .sidebar .nav-link.active { background: #007bff; } .stat-card { border-radius: 10px; padding: 15px; margin-bottom: 20px; color: white; } .product-thumb { width: 50px; height: 50px; object-fit: cover; border-radius: 5px; cursor: pointer; } .badge-stock { font-size: 11px; } .action-buttons .btn { padding: 5px 10px; margin: 0 2px; } .filter-section { background: #f8f9fa; padding: 15px; border-radius: 10px; margin-bottom: 20px; } .bulk-actions { display: none; padding: 10px; background: #e9ecef; border-radius: 5px; margin-bottom: 10px; } .featured-star { color: gold; cursor: pointer; } .switch { position: relative; display: inline-block; width: 50px; height: 24px; } .switch input { opacity: 0; width: 0; height: 0; } .slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #ccc; transition: .4s; border-radius: 24px; } .slider:before { position: absolute; content: ""; height: 16px; width: 16px; left: 4px; bottom: 4px; background-color: white; transition: .4s; border-radius: 50%; } input:checked + .slider { background-color: #2196F3; } input:checked + .slider:before { transform: translateX(26px); } </style> </head> <body> <div class="container-fluid"> <div class="row"> <!-- Sidebar --> <nav class="col-md-2 d-md-block sidebar bg-dark"> <div class="position-sticky"> <h4 class="text-white p-3">Admin Panel</h4> <ul class="nav flex-column"> <li class="nav-item"><a class="nav-link" href="index.php"><i class="fas fa-tachometer-alt"></i> Dashboard</a></li> <li class="nav-item"><a class="nav-link" href="products.php"><i class="fas fa-box"></i> Products</a></li> <li class="nav-item"><a class="nav-link" href="categories.php"><i class="fas fa-tags"></i> Categories</a></li> <li class="nav-item"><a class="nav-link" href="orders.php"><i class="fas fa-shopping-cart"></i> Orders</a></li> <li class="nav-item"><a class="nav-link" href="reviews.php"><i class="fas fa-star"></i> Reviews</a></li> <li class="nav-item"><a class="nav-link active" href="specifications.php"><i class="fas fa-list"></i> Specifications</a></li> <li class="nav-item"><a class="nav-link" href="logout.php"><i class="fas fa-sign-out-alt"></i> Logout</a></li> </ul> </div> </nav> <!-- Main Content --> <main class="col-md-10 ms-sm-auto px-md-4"> <div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom"> <h1 class="h2">Manage Specifications</h1> <button type="button" class="btn btn-primary" onclick="addSpec()"> <i class="fas fa-plus"></i> Add Specification </button> </div> <?php if (isset($_SESSION['message'])): ?> <div class="alert alert-<?php echo $_SESSION['message_type']; ?> alert-dismissible fade show"> <?php echo $_SESSION['message']; unset($_SESSION['message']); unset($_SESSION['message_type']); ?> <button type="button" class="btn-close" data-bs-dismiss="alert"></button> </div> <?php endif; ?> <div class="card"> <div class="card-body"> <table id="specsTable" class="table table-hover"> <thead> <tr> <th>ID</th> <th>Product</th> <th>Specification Name</th> <th>Value</th> <th>Type</th> <th>Sort Order</th> <th>Actions</th> </tr> </thead> <tbody> <?php foreach ($specifications as $spec): ?> <tr> <td><?php echo $spec['id']; ?></td> <td><?php echo htmlspecialchars($spec['product_name'] ?? 'N/A'); ?></td> <td><strong><?php echo htmlspecialchars($spec['spec_name']); ?></strong></td> <td><?php echo htmlspecialchars($spec['spec_value']); ?></td> <td><?php echo ucfirst($spec['spec_type']); ?></td> <td><?php echo $spec['sort_order']; ?></td> <td> <button class="btn btn-sm btn-info" onclick="editSpec(<?php echo $spec['id']; ?>)"><i class="fas fa-edit"></i> Edit</button> <form action="specifications.php" method="POST" style="display:inline;" onsubmit="return confirm('Are you sure you want to delete this specification?');"> <input type="hidden" name="action" value="delete"> <input type="hidden" name="spec_id" value="<?php echo $spec['id']; ?>"> <button type="submit" class="btn btn-sm btn-danger"><i class="fas fa-trash"></i> Delete</button> </form> </td> </tr> <?php endforeach; ?> </tbody> </table> </div> </div> </main> </div> </div> <!-- Add/Edit Modal --> <div class="modal fade" id="specModal" tabindex="-1"> <div class="modal-dialog"> <div class="modal-content"> <form id="specForm" action="specifications.php" method="POST"> <div class="modal-header"> <h5 class="modal-title" id="specModalTitle">Add Specification</h5> <button type="button" class="btn-close" data-bs-dismiss="modal"></button> </div> <div class="modal-body"> <input type="hidden" name="action" value="save"> <input type="hidden" name="spec_id" id="spec_id"> <div class="mb-3"> <label for="product_id" class="form-label">Product ID (Optional)</label> <input type="number" class="form-control" name="product_id" id="product_id" placeholder="Enter product ID"> </div> <div class="mb-3"> <label for="spec_name" class="form-label">Specification Name</label> <input type="text" class="form-control" id="spec_name" name="name" required> </div> <div class="mb-3"> <label for="spec_value" class="form-label">Specification Value</label> <textarea class="form-control" id="spec_value" name="value" rows="3"></textarea> </div> <div class="mb-3"> <label for="spec_type" class="form-label">Type</label> <select class="form-select" id="spec_type" name="type"> <option value="highlight">Highlight</option> <option value="specification" selected>Specification</option> <option value="service">Service</option> </select> </div> </div> <div class="modal-footer"> <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button> <button type="submit" class="btn btn-primary">Save</button> </div> </form> </div> </div> </div> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script> <script src="https://cdn.datatables.net/1.11.5/js/jquery.dataTables.min.js"></script> <script src="https://cdn.datatables.net/1.11.5/js/dataTables.bootstrap5.min.js"></script> <script> $(document).ready(function() { $('#specsTable').DataTable({ order: [[0, 'asc']] }); }); const specModal = new bootstrap.Modal(document.getElementById('specModal')); function addSpec() { $('#specForm')[0].reset(); $('#specModalTitle').text('Add Specification'); $('#spec_id').val(''); specModal.show(); } function editSpec(id) { $.get('specifications.php', { action: 'get_spec', id: id }, function(data) { const spec = JSON.parse(data); $('#specModalTitle').text('Edit Specification'); $('#spec_id').val(spec.id); $('#product_id').val(spec.product_id); $('#spec_name').val(spec.spec_name); $('#spec_value').val(spec.spec_value); $('#spec_type').val(spec.spec_type); specModal.show(); }); } </script> </body> </html>
Upload File
Create Folder