« Back to History
packing_material_type.php
|
20260722_120325.php
Initial Domain Snapshot
Copy Code
<?php require_once __DIR__ . '/modules/auth/page_acl.php'; $ctx = page_require_access('packing_material_type'); $pdo = $ctx['pdo']; $company_id = (int)$ctx['company_id']; function h($s){ return htmlspecialchars((string)$s, ENT_QUOTES, 'UTF-8'); } // CSRF if (empty($_SESSION['csrf_token'])) { $_SESSION['csrf_token'] = bin2hex(random_bytes(32)); } // ================= SAVE ================= if ($_SERVER['REQUEST_METHOD'] === 'POST') { if (!hash_equals($_SESSION['csrf_token'], $_POST['csrf_token'] ?? '')) { die('Invalid CSRF token'); } $id = (int)($_POST['id'] ?? 0); $material_type = trim($_POST['material_type'] ?? ''); $simple_name = trim($_POST['simple_name'] ?? ''); $hsn_no = trim($_POST['hsn_no'] ?? ''); $quality = trim($_POST['quality'] ?? ''); $size = trim($_POST['size'] ?? ''); $uom = trim($_POST['uom'] ?? ''); $ref_pcs = (int)($_POST['ref_pcs'] ?? 0); $ref_weight = (float)($_POST['ref_weight'] ?? 0); if ($material_type !== '') { if ($id > 0) { $stmt = $pdo->prepare(" UPDATE packing_material_type SET material_type = ?, simple_name = ?, hsn_no = ?, quality = ?, size = ?, uom = ?, ref_pcs = ?, ref_weight = ? WHERE id = ? AND company_id = ? "); $stmt->execute([$material_type, $simple_name, $hsn_no, $quality, $size, $uom, $ref_pcs, $ref_weight, $id, $company_id]); } else { $stmt = $pdo->prepare(" INSERT INTO packing_material_type (company_id, material_type, simple_name, hsn_no, quality, size, uom, ref_pcs, ref_weight) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) "); $stmt->execute([$company_id, $material_type, $simple_name, $hsn_no, $quality, $size, $uom, $ref_pcs, $ref_weight]); } header("Location: " . $_SERVER['PHP_SELF']); exit; } } // ================= DELETE ================= if (isset($_GET['delete'])) { $stmt = $pdo->prepare("DELETE FROM packing_material_type WHERE id = ? AND company_id = ?"); $stmt->execute([(int)$_GET['delete'], $company_id]); header("Location: " . $_SERVER['PHP_SELF']); exit; } // ================= EDIT ================= $edit = null; if (isset($_GET['edit'])) { $stmt = $pdo->prepare("SELECT * FROM packing_material_type WHERE id = ? AND company_id = ?"); $stmt->execute([(int)$_GET['edit'], $company_id]); $edit = $stmt->fetch(PDO::FETCH_ASSOC); } // ================= LIST ================= $stmt = $pdo->prepare("SELECT * FROM packing_material_type WHERE company_id = ? ORDER BY id ASC"); $stmt->execute([$company_id]); $rows = $stmt->fetchAll(PDO::FETCH_ASSOC); require_once __DIR__ . '/partials/header.php'; ?> <div class="wrap"> <div class="d-flex justify-content-between align-items-center mb-3"> <h2 class="fw-bold m-0">Packing Material Type</h2> </div> <div class="card shadow-sm border-0 mb-4"> <div class="card-body p-3"> <form method="post" class="row g-3"> <input type="hidden" name="csrf_token" value="<?=h($_SESSION['csrf_token'])?>"> <input type="hidden" name="id" value="<?=h($edit['id'] ?? 0)?>"> <div class="col-md-4"> <label class="form-label small fw-bold">Material Type *</label> <input type="text" name="material_type" class="form-control" value="<?=h($edit['material_type'] ?? '')?>" required> </div> <div class="col-md-4"> <label class="form-label small fw-bold">Simple Name</label> <input type="text" name="simple_name" class="form-control" value="<?=h($edit['simple_name'] ?? '')?>"> </div> <div class="col-md-4"> <label class="form-label small fw-bold">HSN</label> <input type="text" name="hsn_no" class="form-control" value="<?=h($edit['hsn_no'] ?? '')?>"> </div> <div class="col-md-4"> <label class="form-label small fw-bold">Quality</label> <input type="text" name="quality" class="form-control" value="<?=h($edit['quality'] ?? '')?>"> </div> <div class="col-md-4"> <label class="form-label small fw-bold">Size</label> <input type="text" name="size" class="form-control" value="<?=h($edit['size'] ?? '')?>"> </div> <div class="col-md-4"> <label class="form-label small fw-bold">UOM</label> <input type="text" name="uom" class="form-control" value="<?=h($edit['uom'] ?? '')?>"> </div> <div class="col-md-4"> <label class="form-label small fw-bold">Ref Pcs</label> <input type="number" name="ref_pcs" class="form-control" value="<?=h($edit['ref_pcs'] ?? '')?>"> </div> <div class="col-md-4"> <label class="form-label small fw-bold">Ref Weight</label> <input type="number" step="0.001" name="ref_weight" class="form-control" value="<?=h($edit['ref_weight'] ?? '')?>"> </div> <div class="col-12 mt-3"> <button type="submit" class="btn btn-primary"><?= $edit ? 'Update' : 'Save' ?></button> <a href="<?=h($_SERVER['PHP_SELF'])?>" class="btn btn-secondary">Reset</a> </div> </form> </div> </div> <div class="card shadow-sm border-0"> <div class="card-body p-4"> <div class="table-responsive"> <table class="table table-bordered table-striped"> <thead> <tr> <th>ID</th> <th>Material Type</th> <th>Simple Name</th> <th>HSN</th> <th>Quality</th> <th>Size</th> <th>UOM</th> <th>Ref Pcs</th> <th>Ref Weight</th> <th>Action</th> </tr> </thead> <tbody> <?php if (empty($rows)): ?> <tr><td colspan="10" class="text-center">No data found</td></tr> <?php else: ?> <?php foreach ($rows as $r): ?> <tr> <td><?= $r['id'] ?></td> <td><?= h($r['material_type']) ?></td> <td><?= h($r['simple_name'] ?? '') ?></td> <td><?= h($r['hsn_no'] ?? '') ?></td> <td><?= h($r['quality']) ?></td> <td><?= h($r['size']) ?></td> <td><?= h($r['uom'] ?? '') ?></td> <td><?= h($r['ref_pcs']) ?></td> <td><?= number_format($r['ref_weight'], 3) ?></td> <td> <a href="?edit=<?=$r['id']?>" class="btn btn-sm btn-warning">Edit</a> <a href="?delete=<?=$r['id']?>" class="btn btn-sm btn-danger" onclick="return confirm('Delete?')">Delete</a> </td> </tr> <?php endforeach; ?> <?php endif; ?> </tbody> </table> </div> </div> </div> </div> <?php require_once __DIR__ . '/partials/footer.php'; ?>