« Back to History
pouch_master.php
|
20260722_120325.php
Initial Domain Snapshot
Copy Code
<?php error_reporting(E_ALL); ini_set('display_errors', 1); // Auth aur Context Pattern require_once __DIR__ . '/modules/auth/page_acl.php'; $ctx = page_require_access('pouch_master'); $pdo = $ctx['pdo']; $company_id = (int)$ctx['company_id']; function h($s){ return htmlspecialchars((string)$s, ENT_QUOTES, 'UTF-8'); } /* ================= SAVE / UPDATE (Delete-then-Insert) ================= */ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'save') { try { $pdo->beginTransaction(); $id = !empty($_POST['id']) ? (int)$_POST['id'] : null; // Pattern: Pehle purana record delete karein (agar ID exist karti hai) if ($id) { $del = $pdo->prepare("DELETE FROM pouch_data WHERE id = ? AND company_id = ?"); $del->execute([$id, $company_id]); } // Phir naya insert karein (Yahi aapka required pattern hai) $sql = "INSERT INTO pouch_data (id, company_id, pouch_type, pouch_size, per_bundle_qty, remark, is_active, created_at) VALUES (?, ?, ?, ?, ?, ?, ?, NOW())"; $stmt = $pdo->prepare($sql); $stmt->execute([ $id, $company_id, $_POST['pouch_type'] ?? '', $_POST['pouch_size'] ?? '', $_POST['per_bundle_qty'] ?? 0, $_POST['remark'] ?? '', 1 // Default active ]); $pdo->commit(); header("Location: pouch_master.php?msg=Saved Successfully"); exit; } catch (Exception $e) { if ($pdo->inTransaction()) $pdo->rollBack(); die("System Error: " . $e->getMessage()); } } /* ================= DATA FETCHING ================= */ $stmt = $pdo->prepare("SELECT * FROM pouch_data WHERE company_id = ? ORDER BY id DESC"); $stmt->execute([$company_id]); $pouch_list = $stmt->fetchAll(PDO::FETCH_ASSOC); ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Pouch Data Management</title> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css"> <style> body { background: #f4f7f6; } .master-card { background: white; border-radius: 12px; box-shadow: 0 4px 12px rgba(0,0,0,0.1); padding: 25px; margin-bottom: 25px; } .form-label { font-weight: 600; font-size: 0.85rem; color: #555; } .table-section { background: white; border-radius: 12px; box-shadow: 0 2px 8px rgba(0,0,0,0.05); } .btn-save { background: #2c3e50; color: white; border: none; padding: 10px 20px; } .btn-save:hover { background: #1a252f; color: white; } </style> </head> <body class="p-4"> <div class="container-fluid"> <h4 class="mb-4 text-uppercase fw-bold" style="letter-spacing: 1px;">Pouch Data Master</h4> <div class="master-card"> <form method="POST" id="pouchForm"> <input type="hidden" name="action" value="save"> <input type="hidden" name="id" id="pouch_id"> <div class="row g-3"> <div class="col-md-3"> <label class="form-label">Pouch Type</label> <input type="text" name="pouch_type" id="pouch_type" class="form-control" placeholder="e.g. Stand up, Zip" required> </div> <div class="col-md-3"> <label class="form-label">Pouch Size</label> <input type="text" name="pouch_size" id="pouch_size" class="form-control" placeholder="e.g. 10x12" required> </div> <div class="col-md-2"> <label class="form-label">Per Bundle Qty</label> <input type="number" name="per_bundle_qty" id="per_bundle_qty" class="form-control" placeholder="Qty"> </div> <div class="col-md-4"> <label class="form-label">Remark</label> <input type="text" name="remark" id="remark" class="form-control" placeholder="Additional notes"> </div> <div class="col-12 text-end mt-3"> <button type="button" onclick="resetForm()" class="btn btn-outline-secondary me-2">Clear</button> <button type="submit" class="btn btn-save px-5">Save Pouch Data</button> </div> </div> </form> </div> <div class="table-section overflow-hidden"> <table class="table table-hover align-middle mb-0"> <thead class="table-dark"> <tr> <th width="80" class="ps-4">ID</th> <th>Pouch Type</th> <th>Pouch Size</th> <th>Per Bundle Qty</th> <th>Remark</th> <th width="120" class="text-center pe-4">Action</th> </tr> </thead> <tbody> <?php if (empty($pouch_list)): ?> <tr><td colspan="6" class="text-center p-5 text-muted">No pouch data found in records.</td></tr> <?php endif; ?> <?php foreach ($pouch_list as $row): ?> <tr> <td class="ps-4">#<?= h($row['id']) ?></td> <td class="fw-bold"><?= h($row['pouch_type']) ?></td> <td><?= h($row['pouch_size']) ?></td> <td><span class="badge bg-info text-dark"><?= h($row['per_bundle_qty']) ?></span></td> <td class="small text-muted"><?= h($row['remark']) ?></td> <td class="text-center pe-4"> <button class="btn btn-sm btn-outline-primary px-3" onclick='editRow(<?= json_encode($row) ?>)'>Edit</button> </td> </tr> <?php endforeach; ?> </tbody> </table> </div> </div> <script> // Dynamic Row Addition/Edit Logic function editRow(data) { document.getElementById('pouch_id').value = data.id; document.getElementById('pouch_type').value = data.pouch_type; document.getElementById('pouch_size').value = data.pouch_size; document.getElementById('per_bundle_qty').value = data.per_bundle_qty; document.getElementById('remark').value = data.remark; window.scrollTo({ top: 0, behavior: 'smooth' }); document.getElementById('pouch_type').focus(); } function resetForm() { document.getElementById('pouchForm').reset(); document.getElementById('pouch_id').value = ''; } </script> </body> </html>