« Back to History
rapier_maintenance_item.php
|
20260721_154033.php
Initial Bulk Import
Copy Code
<?php require_once __DIR__ . '/modules/auth/page_acl.php'; $ctx = page_require_access('rapier_maintenance_item'); $pdo = $ctx['pdo']; $company_id = (int)$ctx['company_id']; $u = $ctx['user']; require_once __DIR__ . '/partials/header.php'; $msg = ""; /* ================= SAVE ================= */ if ($_SERVER['REQUEST_METHOD'] === 'POST') { $id = (int)($_POST['id'] ?? 0); $item_name = trim($_POST['item_name'] ?? ''); $item_code = trim($_POST['item_code'] ?? ''); $description = trim($_POST['description'] ?? ''); $is_active = isset($_POST['is_active']) ? 1 : 0; if ($item_name === '') { $msg = "danger|Item Name zaroori hai"; } elseif ($id > 0) { $stm = $pdo->prepare(" UPDATE rapier_maintenance_item SET item_name=?, item_code=?, description=?, is_active=?, updated_at=NOW() WHERE id=? AND company_id=? "); $stm->execute([$item_name, $item_code, $description, $is_active, $id, $company_id]); $msg = "success|Item update ho gaya"; } else { $stm = $pdo->prepare(" INSERT INTO rapier_maintenance_item (company_id, item_name, item_code, description, is_active, created_at, updated_at) VALUES (?, ?, ?, ?, ?, NOW(), NOW()) "); $stm->execute([$company_id, $item_name, $item_code, $description, $is_active]); $msg = "success|Item add ho gaya"; } } /* ================= EDIT LOAD ================= */ $edit = null; if (isset($_GET['edit'])) { $eid = (int)$_GET['edit']; $stm = $pdo->prepare("SELECT * FROM rapier_maintenance_item WHERE id=? AND company_id=?"); $stm->execute([$eid, $company_id]); $edit = $stm->fetch(PDO::FETCH_ASSOC); } /* ================= LIST ================= */ $stm = $pdo->prepare(" SELECT * FROM rapier_maintenance_item WHERE company_id=? ORDER BY id DESC "); $stm->execute([$company_id]); $list = $stm->fetchAll(PDO::FETCH_ASSOC); ?> <div class="container-fluid py-4"> <?php if ($msg): ?> <?php [$type, $text] = explode('|', $msg, 2); ?> <div class="alert alert-<?= htmlspecialchars($type) ?> alert-dismissible fade show"> <?= htmlspecialchars($text) ?> <button type="button" class="btn-close" data-bs-dismiss="alert"></button> </div> <?php endif; ?> <div class="row"> <!-- FORM --> <div class="col-lg-4"> <div class="card shadow-sm mb-4"> <div class="card-header bg-primary text-white fw-bold"> <?= $edit ? 'Item Edit Karo' : 'Naya Item Add Karo' ?> </div> <div class="card-body"> <form method="POST"> <input type="hidden" name="id" value="<?= (int)($edit['id'] ?? 0) ?>"> <div class="mb-3"> <label class="form-label fw-semibold">Item Name <span class="text-danger">*</span></label> <input type="text" name="item_name" class="form-control" value="<?= htmlspecialchars($edit['item_name'] ?? '') ?>" required> </div> <div class="mb-3"> <label class="form-label fw-semibold">Item Code</label> <input type="text" name="item_code" class="form-control" value="<?= htmlspecialchars($edit['item_code'] ?? '') ?>"> </div> <div class="mb-3"> <label class="form-label fw-semibold">Description</label> <textarea name="description" class="form-control" rows="3"><?= htmlspecialchars($edit['description'] ?? '') ?></textarea> </div> <div class="mb-3 form-check"> <input type="checkbox" class="form-check-input" name="is_active" id="is_active" <?= ($edit['is_active'] ?? 1) ? 'checked' : '' ?>> <label class="form-check-label" for="is_active">Active</label> </div> <div class="d-flex gap-2"> <button class="btn btn-primary flex-fill"> <?= $edit ? 'Update Karo' : 'Save Karo' ?> </button> <?php if ($edit): ?> <a href="rapier_maintenance_item.php" class="btn btn-secondary">Cancel</a> <?php endif; ?> </div> </form> </div> </div> </div> <!-- TABLE --> <div class="col-lg-8"> <div class="card shadow-sm"> <div class="card-header bg-dark text-white fw-bold"> Rapier Maintenance Items </div> <div class="card-body p-0"> <div class="table-responsive"> <table class="table table-striped table-bordered mb-0"> <thead class="table-dark"> <tr> <th>#</th> <th>Item Name</th> <th>Item Code</th> <th>Description</th> <th class="text-center">Active</th> <th class="text-center" width="80">Action</th> </tr> </thead> <tbody> <?php if (empty($list)): ?> <tr> <td colspan="6" class="text-center text-muted py-3">Koi record nahi mila</td> </tr> <?php else: ?> <?php foreach ($list as $r): ?> <tr> <td><?= $r['id'] ?></td> <td><?= htmlspecialchars($r['item_name']) ?></td> <td><?= htmlspecialchars($r['item_code']) ?></td> <td><?= htmlspecialchars($r['description']) ?></td> <td class="text-center"> <?php if ($r['is_active']): ?> <span class="badge bg-success">Yes</span> <?php else: ?> <span class="badge bg-secondary">No</span> <?php endif; ?> </td> <td class="text-center"> <a href="?edit=<?= $r['id'] ?>" class="btn btn-sm btn-primary">Edit</a> </td> </tr> <?php endforeach; ?> <?php endif; ?> </tbody> </table> </div> </div> </div> </div> </div> </div>